Skip to contentSkip to conversation

xen/arm: Add GICv3 support

PATCH Superseded [email protected] 4 participants 25 messages Sep 4, 2014 – Sep 9, 2014

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover xen/arm: Add GICv3 support

From: Vijaya Kumar K <[email protected]>

Add GICv3 support for arm64 platform.

Quoted 1 line

From v6 version, this patch series is split into v6a and v6.

All the GICv2 and VGIC code refactoring patches of v6a are merged.

The v8 version of GICv3 patches are posted here.

Tested with ARM64 simulator with multicore core
and booted Dom0 kernel.

Major changes in v9:
- Rebased on top of Stephano's patches in staging branch
- Added 2 more fixes for generic GICv2 code to make it generic for GICV3
- Fixed alignment
- Removed unsed PIDR2 macros

Major changes in v8:
- Introduced assembler aliases for GIC system registers to be able to compile with Linaro toolchain
- Few PIDRn macros definitions are moved to vgic-v3.c
- Introduced 2 more patches. Patch 1 for introducing sizes.h file and Patch 2 for {READ,WRITE}_SYSREG macro changes

Major changes in v7:
- Introduced vgic callback to handle sysreg emulation
- Coding style fixes
- undef64_exception instead of undef_exception for sysreg error

Major changes in v6:
- Added read_apr() to read ICH_APRn in GICv3
- Added asserts
- PIDR2 check for architecture value
- Remove update_cpu_lr_mask call
- Changed parameter ordering for gicv3_send_sgi()
- Save and restore ICC_SRE_EL1 register
- Computed cpumask in gicv3_send_sgi() function

Major changes in v5:
- Introduced new patch for checking platform capability for gicv3
- Introduced more patches for vgic clean up and code movement
- Added synchronization barriers and clean up in GICv3 driver
- Rebase on top of master branch + remotes/origin/no_maintenance_interrupts-v8 patch set
- Code base available in github
git clone https://github.com/vijaykilari/Xen-GICv3.git
- Fixed comments and coding style

Major changes in v4:
- Changed io handlers to take mmio address and size as parameters
- ioremap is used instead of fixmap to map GICv2 address space. Removed /4 in GICv2 register definitions
- vGIC driver now uses register size to calculate IRQ rank
- GICv2 LR register definitions are declared locally in GICv2 driver
- GICR & GICD common register handling in vgic-v3 driver are segregated in one common function
- irq_hw_controller definition is managed in GICv2 and GICv3 drivers
- Made irq_ops const
- GIC DT node is updated in respective drivers
- Comments and coding style fixes
- Rebased on remotes/origin/no_maintenance_interrupts-v8 + Julien's patch set

Major changes in v3:
- Moved io.h from xen/arch/arm to xen/include/asm-arm and renamed as mmio.h
- Made all the io handlers as domain specific and removed check handlers. Instead address and size are passed
- Cleaned up sgi handling functions in V2 gic driver and made generic
- Removed unused parameters in do_sgi call
- VGIC driver is chosen based on GIC driver initialized
- Implemented SGI handling for GICv3 to boot multicore
- Missing coding style fixes
- Rebased to remotes/origin/no_maintenance_interrupts-v6 branch of Stephano's unstable tree

Major Changes in v2:
- Added per domain io handler
- Use device api to initialize gic driver
- Avoid use of void pointer to access common data
- Moved vgic address information data from domain.h
- Coding style

Vijaya Kumar K (7):
xen/arm: move itargets initialization to vgic-v2 xen/arm: fallback to vcpu 0 if get_target_vcpu handler not exists xen/arm: Add support for GIC v3
xen/arm: Add virtual GICv3 support
xen/arm: Update Dom0 GIC dt node with GICv3 information xen/arm: add SGI handling for GICv3
xen/arm: check for GICv3 platform support

 xen/arch/arm/Makefile             |    2 +
 xen/arch/arm/domain_build.c       |   47 +-
 xen/arch/arm/gic-v2.c             |   51 ++
 xen/arch/arm/gic-v3.c             | 1285 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic.c                |    6 +
 xen/arch/arm/setup.c              |    5 +-
 xen/arch/arm/traps.c              |   15 +
 xen/arch/arm/vgic-v2.c            |   26 +-
 xen/arch/arm/vgic-v3.c            |  988 ++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |   37 +-
 xen/include/asm-arm/cpufeature.h  |    1 +
 xen/include/asm-arm/domain.h      |    8 +
 xen/include/asm-arm/gic.h         |   24 +
 xen/include/asm-arm/gic_v3_defs.h |  161 +++++
 xen/include/asm-arm/processor.h   |   17 +-
 xen/include/asm-arm/sysregs.h     |   56 ++
 xen/include/asm-arm/vgic.h        |   16 +-
 17 files changed, 2676 insertions(+), 69 deletions(-)
 create mode 100644 xen/arch/arm/gic-v3.c
 create mode 100644 xen/arch/arm/vgic-v3.c
 create mode 100644 xen/include/asm-arm/gic_v3_defs.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v9 1/7 xen/arm: move itargets initialization to vgic-v2

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

---
 xen/arch/arm/vgic-v2.c |    7 +++++++
 xen/arch/arm/vgic.c    |    6 ------
 2 files changed, 7 insertions(+), 6 deletions(-)
xen/arch/arm/vgic-v2.c +7 -0
index f57dbf9..54751b6 100644
@@ -538,6 +538,13 @@ static int vgic_v2_vcpu_init(struct vcpu *v)
 
 static int vgic_v2_domain_init(struct domain *d)
 {
+    int i;
+
+    /* By default deliver to CPU0 */
+    for ( i = 0; i < DOMAIN_NR_RANKS(d); i++ )
+        memset(d->arch.vgic.shared_irqs[i].itargets, 0x1,
+               sizeof(d->arch.vgic.shared_irqs[i].itargets));
+
     /* We rely on gicv_setup() to initialize dbase(vGIC distributor base) */
     register_mmio_handler(d, &vgic_v2_distr_mmio_handler, d->arch.vgic.dbase,
                           PAGE_SIZE);
xen/arch/arm/vgic.c +0 -6
index 17b3b6d..6b41dbf 100644
@@ -96,13 +96,7 @@ int domain_vgic_init(struct domain *d)
         INIT_LIST_HEAD(&d->arch.vgic.pending_irqs[i].lr_queue);
     }
     for (i=0; i<DOMAIN_NR_RANKS(d); i++)
-    {
         spin_lock_init(&d->arch.vgic.shared_irqs[i].lock);
-        /* By default deliver to CPU0 */
-        memset(d->arch.vgic.shared_irqs[i].itargets,
-               0x1,
-               sizeof(d->arch.vgic.shared_irqs[i].itargets));
-    }
 
     d->arch.vgic.handler->domain_init(d);
 
Signature · 1 line
1.7.9.5
Acked-by on v9 1/7
#2 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

Quoted 6 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

Quoted 43 lines
 xen/arch/arm/vgic-v2.c |    7 +++++++
 xen/arch/arm/vgic.c    |    6 ------
 2 files changed, 7 insertions(+), 6 deletions(-)
xen/arch/arm/vgic-v2.c +7 -0
index f57dbf9..54751b6 100644
@@ -538,6 +538,13 @@ static int vgic_v2_vcpu_init(struct vcpu *v)
 
 static int vgic_v2_domain_init(struct domain *d)
 {
+    int i;
+
+    /* By default deliver to CPU0 */
+    for ( i = 0; i < DOMAIN_NR_RANKS(d); i++ )
+        memset(d->arch.vgic.shared_irqs[i].itargets, 0x1,
+               sizeof(d->arch.vgic.shared_irqs[i].itargets));
+
     /* We rely on gicv_setup() to initialize dbase(vGIC distributor base) */
     register_mmio_handler(d, &vgic_v2_distr_mmio_handler, d->arch.vgic.dbase,
                           PAGE_SIZE);
xen/arch/arm/vgic.c +0 -6
index 17b3b6d..6b41dbf 100644
@@ -96,13 +96,7 @@ int domain_vgic_init(struct domain *d)
         INIT_LIST_HEAD(&d->arch.vgic.pending_irqs[i].lr_queue);
     }
     for (i=0; i<DOMAIN_NR_RANKS(d); i++)
-    {
         spin_lock_init(&d->arch.vgic.shared_irqs[i].lock);
-        /* By default deliver to CPU0 */
-        memset(d->arch.vgic.shared_irqs[i].itargets,
-               0x1,
-               sizeof(d->arch.vgic.shared_irqs[i].itargets));
-    }
 
     d->arch.vgic.handler->domain_init(d);
 
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

Quoted 9 lines · Stefano Stabellini
Quoted 6 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

I've applied this one.

For the rest of the series it seems there is an outstanding comment on #2 but the rest people seem ok with, although I'd like Stefano to confirm his ack for #3 and #4 before applying.

Ian.

#4 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

Hi Ian,

Quoted 9 lines · Ian Campbell
Quoted 8 lines · Stefano Stabellini
Quoted 6 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

Quoted 7 lines
Quoted 1 line

I've applied this one.

For the rest of the series it seems there is an outstanding comment on #2 but the rest people seem ok with, although I'd like Stefano to confirm his ack for #3 and #4 before applying.

I will send next version (v10) today with issues that I reported yesterday on generic vgic code.

#5 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

In reply to Ian Campbell
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Stefano Stabellini
Quoted 6 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

Quoted 7 lines
Quoted 1 line

I've applied this one.

For the rest of the series it seems there is an outstanding comment on #2 but the rest people seem ok with, although I'd like Stefano to confirm his ack for #3 and #4 before applying.

I have a few comments on patch #4 after the v10 changes.

Reviewed-by on v9 1/7
#6 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

In reply to [email protected]

Hi Vijay,

Quoted 4 lines · On 04/09/14 06:15, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

It's a bit confusing that you move the field in the union in a later patch #4 and not now.

Anyway:

Regards,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH v9 1/7] xen/arm: move itargets initialization to vgic-v2

Quoted 4 lines · Julien Grall

Hi Vijay,

Quoted 1 line · On 04/09/14 06:15, [email protected] wrote:
Quoted 8 lines
Quoted 4 lines

From: Vijaya Kumar K <[email protected]>

itarget registers are GIC version specific. So move initialization of these registers to vgic-v2 driver.

It's a bit confusing that you move the field in the union in a later patch #4 and not now.

This patch is to take care of missing changes arising from Stefano's patch series.

Quoted 9 lines

Anyway:

Regards,

--
Julien Grall

#8 lore raw

PATCH v9 2/7 xen/arm: fallback to vcpu 0 if get_target_vcpu handler not exists

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

if get_target_vcpu handler is not implemented. Fallback to vcpu0 target.

This patch helps to be compatible with GICV3 driver which does not implement this handler.

---
 xen/arch/arm/vgic.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/arch/arm/vgic.c +13 -3
index 6b41dbf..129b1b5 100644
@@ -155,7 +155,11 @@ struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq)
     unsigned long flags;
 
     vgic_lock_rank(v, rank, flags);
-    v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+    if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+    else
+        v_target = d->vcpu[0];
+
     vgic_unlock_rank(v, rank, flags);
     return v_target;
 }
@@ -230,7 +234,10 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+            v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        else
+            v_target = d->vcpu[0];
         p = irq_to_pending(v_target, irq);
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
         gic_remove_from_queues(v_target, irq);
@@ -256,7 +263,10 @@ void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+            v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        else
+            v_target = d->vcpu[0];
         p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
         spin_lock_irqsave(&v_target->arch.vgic.lock, flags);
Signature · 1 line
1.7.9.5
#9 lore raw

Re: [PATCH v9 2/7] xen/arm: fallback to vcpu 0 if get_target_vcpu handler not exists

Quoted 9 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

if get_target_vcpu handler is not implemented. Fallback to vcpu0 target.

This patch helps to be compatible with GICV3 driver which does not implement this handler.

I think it would be better to implement a simple get_target_vcpu function that always returns vcpu0 on gicv3.

Quoted 47 lines
 xen/arch/arm/vgic.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/arch/arm/vgic.c +13 -3
index 6b41dbf..129b1b5 100644
@@ -155,7 +155,11 @@ struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq)
     unsigned long flags;
 
     vgic_lock_rank(v, rank, flags);
-    v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+    if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+    else
+        v_target = d->vcpu[0];
+
     vgic_unlock_rank(v, rank, flags);
     return v_target;
 }
@@ -230,7 +234,10 @@ void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+            v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        else
+            v_target = d->vcpu[0];
         p = irq_to_pending(v_target, irq);
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
         gic_remove_from_queues(v_target, irq);
@@ -256,7 +263,10 @@ void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        if ( d->arch.vgic.handler->get_target_vcpu != NULL )
+            v_target = d->arch.vgic.handler->get_target_vcpu(v, irq);
+        else
+            v_target = d->vcpu[0];
         p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
         spin_lock_irqsave(&v_target->arch.vgic.lock, flags);
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v9 3/7 xen/arm: Add support for GIC v3

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

Add support for GIC v3 specification System register access(SRE) is enabled to access cpu and virtual interface registers based on kernel GICv3 driver.

This patch adds only basic v3 support.
Does not support Interrupt Translation support (ITS)

---
v9: - ICC_IAR1_EL1 holds only IRQ number. Do not mask the value
- Remove unused PIDR2 JEP register definitions
- Change {GICR,GICD}_PIDR2_ARCH_REV_SHIFT to {GICR,GICD}_PIDR2_ARCH_REV_OFFSET
- Remove duplicate MPIDR_LEVEL_BITS define
- Implemented gicv3_set_irq_affinity similar to gic v2
- make access to desc->status flags atomic
v8: - Introduced assembler aliases for GIC system registers
- Removed usage of lib.h for adding size macro, instead used sizes.h
- Renamed PIDR macros
- Removed check for number of cpus in cluster in gicv3_send_sgi() and instead check is added in gicv3_populate_rdist()
- Added comments and fixed coding style
- Removed nr_lrs parameter in gicv3_{restore,save}_lrs()
- Rename GICV3 compat strings.
v7: - Fixed wrong check for irq number in gicv3_set_irq_properties.
- Introduced panic during cpu_init on wrong priority bits.
v6: - Added read_apr() to read ICH_APRn in GICv3
- Added asserts
- PIDR2 check for architecture valu
- Remove update_cpu_lr_mask call
- Changed parameter ordering for gicv3_send_sgi()
- Save and restore ICC_SRE_EL1 registers

---
 xen/arch/arm/Makefile             |    1 +
 xen/arch/arm/gic-v3.c             | 1200 +++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/domain.h      |    8 +
 xen/include/asm-arm/gic.h         |   20 +
 xen/include/asm-arm/gic_v3_defs.h |  154 +++++
 xen/include/asm-arm/processor.h   |   13 +
 xen/include/asm-arm/sysregs.h     |   53 ++
 7 files changed, 1449 insertions(+)
xen/arch/arm/Makefile +1 -0
index c13206f..33765f6 100644
@@ -11,6 +11,7 @@ obj-y += domctl.o
 obj-y += sysctl.o
 obj-y += domain_build.o
 obj-y += gic.o gic-v2.o
+obj-$(CONFIG_ARM_64) += gic-v3.o
 obj-y += io.o
 obj-y += irq.o
 obj-y += kernel.o
xen/arch/arm/gic-v3.c new file +1200 -0

1,200 lines not on this page · raw message

xen/include/asm-arm/domain.h +8 -0
index 32d0554..787e93c 100644
@@ -99,6 +99,14 @@ struct arch_domain
         /* Base address for guest GIC */
         paddr_t dbase; /* Distributor base address */
         paddr_t cbase; /* CPU base address */
+#ifdef CONFIG_ARM_64
+        /* GIC V3 addressing */
+        paddr_t dbase_size; /* Distributor base size */
+        paddr_t rbase[MAX_RDIST_COUNT];      /* Re-Distributor base address */
+        paddr_t rbase_size[MAX_RDIST_COUNT]; /* Re-Distributor size */
+        uint32_t rdist_stride;               /* Re-Distributor stride */
+        int rdist_count;                     /* No. of Re-Distributors */
+#endif
     } vgic;
 
     struct vuart {
xen/include/asm-arm/gic.h +20 -0
index a0c07bf..c4daf5b 100644
@@ -18,6 +18,10 @@
 #ifndef __ASM_ARM_GIC_H__
 #define __ASM_ARM_GIC_H__
 
+#define NR_GIC_LOCAL_IRQS  NR_LOCAL_IRQS
+#define NR_GIC_SGI         16
+#define MAX_RDIST_COUNT    4
+
 #define GICD_CTLR       (0x000)
 #define GICD_TYPER      (0x004)
 #define GICD_IIDR       (0x008)
@@ -154,6 +158,20 @@
 #define DT_MATCH_GIC_V2 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A15), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A7)
 
+#define DT_COMPAT_GIC_V3             "arm,gic-v3"
+
+#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_V3)
+
+/*
+ * GICv3 registers that needs to be saved/restored
+ */
+struct gic_v3 {
+    uint32_t hcr, vmcr, sre_el1;
+    uint32_t apr0[4];
+    uint32_t apr1[4];
+    uint64_t lr[16];
+};
+
 /*
  * GICv2 register that needs to be saved/restored
  * on VCPU context switch
@@ -170,6 +188,7 @@ struct gic_v2 {
  */
 union gic_state_data {
     struct gic_v2 v2;
+    struct gic_v3 v3;
 };
 
 /*
@@ -189,6 +208,7 @@ struct gic_lr {
 
 enum gic_version {
     GIC_V2,
+    GIC_V3,
 };
 
 extern enum gic_version gic_hw_version(void);
xen/include/asm-arm/gic_v3_defs.h new file +154 -0

154 lines not on this page · raw message

xen/include/asm-arm/processor.h +13 -0
index 33ef385..d83f593 100644
@@ -20,6 +20,19 @@
 #define AFFINITY_MASK(level)    ~((_AC(0x1,U) << ((level) * MPIDR_LEVEL_BITS)) - 1)
 
 
+/*
+ * Macros to extract affinity level. picked from kernel
+ */
+
+#define MPIDR_LEVEL_BITS_SHIFT  3
+#define MPIDR_LEVEL_MASK        ((1 << MPIDR_LEVEL_BITS) - 1)
+
+#define MPIDR_LEVEL_SHIFT(level) \
+         (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
+
+#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
+         ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
+
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    _AC(0x80000000,U)
 #define TTBCR_N_MASK _AC(0x07,U)
xen/include/asm-arm/sysregs.h +53 -0

59 lines not on this page · raw message

Signature · 1 line
1.7.9.5
Acked-by on v9 3/7
#11 lore raw

Re: [PATCH v9 3/7] xen/arm: Add support for GIC v3

Quoted 10 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add support for GIC v3 specification System register access(SRE) is enabled to access cpu and virtual interface registers based on kernel GICv3 driver.

This patch adds only basic v3 support.
Does not support Interrupt Translation support (ITS)

[...]

xen/arch/arm/gic-v3.c line 1022

Quoted 13 lines
xen/arch/arm/gic-v3.c new file +13 -0
+static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
+{
+    unsigned int cpu;
+    uint64_t affinity;
+
+    ASSERT(!cpumask_empty(mask));
+
+    spin_lock(&gicv3.lock);
+
+    cpu = gicv3_get_cpu_from_mask(mask);
+    affinity = gicv3_mpidr_to_affinity(cpu);
+    /* Make sure we don't broadcast the interrupt */
+    affinity &= ~GICD_IROUTER_SPI_MODE_ANY;

I would like an ASSERT(affinity != 0);

Other than that:

#12 lore raw

Re: [PATCH v9 3/7] xen/arm: Add support for GIC v3

Quoted 14 lines · Stefano Stabellini
Quoted 10 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add support for GIC v3 specification System register access(SRE) is enabled to access cpu and virtual interface registers based on kernel GICv3 driver.

This patch adds only basic v3 support.
Does not support Interrupt Translation support (ITS)

[...]

Quoted 15 lines

xen/arch/arm/gic-v3.c line 1022

Quoted 13 lines
xen/arch/arm/gic-v3.c new file +13 -0
+static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
+{
+    unsigned int cpu;
+    uint64_t affinity;
+
+    ASSERT(!cpumask_empty(mask));
+
+    spin_lock(&gicv3.lock);
+
+    cpu = gicv3_get_cpu_from_mask(mask);
+    affinity = gicv3_mpidr_to_affinity(cpu);
+    /* Make sure we don't broadcast the interrupt */
+    affinity &= ~GICD_IROUTER_SPI_MODE_ANY;

I would like an ASSERT(affinity != 0);

Should the v2 code do the same then?

There is no way that this value can be controlled by the guest then?

Quoted 5 lines

Other than that:

#13 lore raw

Re: [PATCH v9 3/7] xen/arm: Add support for GIC v3

Quoted 15 lines · Ian Campbell
Quoted 14 lines · Stefano Stabellini
Quoted 10 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add support for GIC v3 specification System register access(SRE) is enabled to access cpu and virtual interface registers based on kernel GICv3 driver.

This patch adds only basic v3 support.
Does not support Interrupt Translation support (ITS)

[...]

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/gic-v3.c new file +7 -0
+static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
+{
+    unsigned int cpu;
+    uint64_t affinity;
+
+    ASSERT(!cpumask_empty(mask));
+
Quoted 8 lines

xen/arch/arm/gic-v3.c line 1022

Quoted 6 lines
xen/arch/arm/gic-v3.c new file +6 -0
+    spin_lock(&gicv3.lock);
+
+    cpu = gicv3_get_cpu_from_mask(mask);
+    affinity = gicv3_mpidr_to_affinity(cpu);
+    /* Make sure we don't broadcast the interrupt */
+    affinity &= ~GICD_IROUTER_SPI_MODE_ANY;

I would like an ASSERT(affinity != 0);

affinity 0 is also valid value for cpu0

Quoted 12 lines

Should the v2 code do the same then?

There is no way that this value can be controlled by the guest then?

Quoted 5 lines

Other than that:

#14 lore raw

Re: [PATCH v9 3/7] xen/arm: Add support for GIC v3

In reply to Ian Campbell
Quoted 31 lines · Ian Campbell
Quoted 14 lines · Stefano Stabellini
Quoted 10 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add support for GIC v3 specification System register access(SRE) is enabled to access cpu and virtual interface registers based on kernel GICv3 driver.

This patch adds only basic v3 support.
Does not support Interrupt Translation support (ITS)

[...]

Quoted 15 lines

xen/arch/arm/gic-v3.c line 1022

Quoted 13 lines
xen/arch/arm/gic-v3.c new file +13 -0
+static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
+{
+    unsigned int cpu;
+    uint64_t affinity;
+
+    ASSERT(!cpumask_empty(mask));
+
+    spin_lock(&gicv3.lock);
+
+    cpu = gicv3_get_cpu_from_mask(mask);
+    affinity = gicv3_mpidr_to_affinity(cpu);
+    /* Make sure we don't broadcast the interrupt */
+    affinity &= ~GICD_IROUTER_SPI_MODE_ANY;

I would like an ASSERT(affinity != 0);

Quoted 3 lines

Should the v2 code do the same then?

There is no way that this value can be controlled by the guest then?

Vijaya is right on this one: the check would be wrong on GICv3 as affinity == 0 means cpu0.

Quoted 7 lines
Quoted 5 lines

Other than that:

#15 lore raw

PATCH v9 4/7 xen/arm: Add virtual GICv3 support

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

Add virtual GICv3 driver support.
Also, with this patch vgic_irq_rank structure is modified to hold GICv2 GICD_TARGET and GICv3 GICD_ROUTER registers under union.

This patch adds only basic GICv3 support. Does not support Interrupt Translation support (ITS)

---
v9: - Use 128K mask to compute GICR register offset if stride
is not set
- Fix alignment errors in vgic-v2.c
- Updated vgic_{lock,unlock}_rank
v8: - Fixed printk coding styles
- Moved GICD_PIDRn and GICR_PIDRn macros to vgic-v3.c from header file
- Check is made on return value of vgic_v3_init()
v7: Fixed coding style.
v6: Removed byte read access for IROUTERN register.

---
 xen/arch/arm/Makefile      |    1 +
 xen/arch/arm/vgic-v2.c     |   23 +-
 xen/arch/arm/vgic-v3.c     |  934 ++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c        |    6 +
 xen/include/asm-arm/vgic.h |   13 +-
 5 files changed, 964 insertions(+), 13 deletions(-)
xen/arch/arm/Makefile +1 -0
index 33765f6..e557cac 100644
@@ -29,6 +29,7 @@ obj-y += smp.o
 obj-y += shutdown.o
 obj-y += traps.o
 obj-y += vgic.o vgic-v2.o
+obj-$(CONFIG_ARM_64) += vgic-v3.o
 obj-y += vtimer.o
 obj-y += vuart.o
 obj-y += hvm.o
xen/arch/arm/vgic-v2.c +11 -12
index 54751b6..90057a0 100644
@@ -132,10 +132,9 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info)
         if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width;
         rank = vgic_rank_offset(v, 8, gicd_reg - GICD_ITARGETSR, DABT_WORD);
         if ( rank == NULL) goto read_as_zero;
-
         vgic_lock_rank(v, rank, flags);
-        *r = rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
-                                           DABT_WORD)];
+        *r = rank->v2.itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
+                                              DABT_WORD)];
         if ( dabt.size == DABT_BYTE )
             *r = vgic_byte_read(*r, dabt.sign, gicd_reg);
         vgic_unlock_rank(v, rank, flags);
@@ -390,7 +389,7 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
             struct vcpu *v_target, *v_old;
 
             new_target = i % 8;
-            old_target_mask = vgic_byte_read(rank->itargets[REG_RANK_INDEX(8,
+            old_target_mask = vgic_byte_read(rank->v2.itargets[REG_RANK_INDEX(8,
                                              gicd_reg - GICD_ITARGETSR, DABT_WORD)], 0, i/8);
             old_target = find_first_bit(&old_target_mask, 8);
 
@@ -404,11 +403,11 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
             i += 8 - new_target;
         }
         if ( dabt.size == DABT_WORD )
-            rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
-                                          DABT_WORD)] = target;
+            rank->v2.itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
+                                             DABT_WORD)] = target;
         else
-            vgic_byte_write(&rank->itargets[REG_RANK_INDEX(8,
-                       gicd_reg - GICD_ITARGETSR, DABT_WORD)], target, gicd_reg);
+            vgic_byte_write(&rank->v2.itargets[REG_RANK_INDEX(8,
+                      gicd_reg - GICD_ITARGETSR, DABT_WORD)], target, gicd_reg);
         vgic_unlock_rank(v, rank, flags);
         return 1;
     }
@@ -511,7 +510,7 @@ static struct vcpu *vgic_v2_get_target_vcpu(struct vcpu *v, unsigned int irq)
     struct vgic_irq_rank *rank = vgic_rank_irq(v, irq);
     ASSERT(spin_is_locked(&rank->lock));
 
-    target = vgic_byte_read(rank->itargets[(irq%32)/4], 0, irq % 4);
+    target = vgic_byte_read(rank->v2.itargets[(irq%32)/4], 0, irq % 4);
     /* 1-N SPI should be delivered as pending to all the vcpus in the
      * mask, but here we just return the first vcpu for simplicity and
      * because it would be too slow to do otherwise. */
@@ -527,7 +526,7 @@ static int vgic_v2_vcpu_init(struct vcpu *v)
 
     /* For SGI and PPI the target is always this CPU */
     for ( i = 0 ; i < 8 ; i++ )
-        v->arch.vgic.private_irqs->itargets[i] =
+        v->arch.vgic.private_irqs->v2.itargets[i] =
               (1<<(v->vcpu_id+0))
             | (1<<(v->vcpu_id+8))
             | (1<<(v->vcpu_id+16))
@@ -542,8 +541,8 @@ static int vgic_v2_domain_init(struct domain *d)
 
     /* By default deliver to CPU0 */
     for ( i = 0; i < DOMAIN_NR_RANKS(d); i++ )
-        memset(d->arch.vgic.shared_irqs[i].itargets, 0x1,
-               sizeof(d->arch.vgic.shared_irqs[i].itargets));
+        memset(d->arch.vgic.shared_irqs[i].v2.itargets, 0x1,
+               sizeof(d->arch.vgic.shared_irqs[i].v2.itargets));
 
     /* We rely on gicv_setup() to initialize dbase(vGIC distributor base) */
     register_mmio_handler(d, &vgic_v2_distr_mmio_handler, d->arch.vgic.dbase,
xen/arch/arm/vgic-v3.c new file +934 -0

934 lines not on this page · raw message

xen/arch/arm/vgic.c +6 -0
index 129b1b5..cf3834e 100644
@@ -69,6 +69,12 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        if ( vgic_v3_init(d) )
+           return -ENODEV;
+        break;
+#endif
     case GIC_V2:
         if ( vgic_v2_init(d) )
             return -ENODEV;
xen/include/asm-arm/vgic.h +12 -1
index 338ba03..923e97e 100644
@@ -88,7 +88,14 @@ struct vgic_irq_rank {
     uint32_t ienable, iactive, ipend, pendsgi;
     uint32_t icfg[2];
     uint32_t ipriority[8];
-    uint32_t itargets[8];
+    union {
+        struct {
+            uint32_t itargets[8];
+        }v2;
+        struct {
+            uint64_t irouter[32];
+        }v3;
+    };
 };
 
 struct vgic_ops {
@@ -118,6 +125,9 @@ static inline int REG_RANK_NR(int b, uint32_t n)
 {
     switch ( b )
     {
+    case 64: return n >> 6;
+    case 32: return n >> 5;
+    case 16: return n >> 4;
     case 8: return n >> 3;
     case 4: return n >> 2;
     case 2: return n >> 1;
@@ -170,6 +180,7 @@ extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
 int vgic_v2_init(struct domain *d);
+int vgic_v3_init(struct domain *d);
 
 extern int vcpu_vgic_free(struct vcpu *v);
 extern int vgic_to_sgi(struct vcpu *v, register_t sgir,
Signature · 1 line
1.7.9.5
#16 lore raw

Re: [PATCH v9 4/7] xen/arm: Add virtual GICv3 support

Quoted 27 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add virtual GICv3 driver support.
Also, with this patch vgic_irq_rank structure is modified to hold GICv2 GICD_TARGET and GICv3 GICD_ROUTER registers under union.

This patch adds only basic GICv3 support. Does not support Interrupt Translation support (ITS)

---
v9: - Use 128K mask to compute GICR register offset if stride
is not set
- Fix alignment errors in vgic-v2.c
- Updated vgic_{lock,unlock}_rank
v8: - Fixed printk coding styles
- Moved GICD_PIDRn and GICR_PIDRn macros to vgic-v3.c from header file
- Check is made on return value of vgic_v3_init()
v7: Fixed coding style.
v6: Removed byte read access for IROUTERN register.

xen/arch/arm/vgic.c +0 -0
index 129b1b5..cf3834e 100644

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d) · line 77

Quoted 9 lines
xen/arch/arm/vgic.c +6 -0
@@ -69,6 +69,12 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        if ( vgic_v3_init(d) )
+           return -ENODEV;
+        break;
+#endif

Why the #ifdef?

#17 lore raw

Re: [PATCH v9 4/7] xen/arm: Add virtual GICv3 support

Hi Stefano,

Quoted 29 lines · Stefano Stabellini
Quoted 28 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add virtual GICv3 driver support.
Also, with this patch vgic_irq_rank structure is modified to hold GICv2 GICD_TARGET and GICv3 GICD_ROUTER registers under union.

This patch adds only basic GICv3 support. Does not support Interrupt Translation support (ITS)

---
v9: - Use 128K mask to compute GICR register offset if stride
is not set
- Fix alignment errors in vgic-v2.c
- Updated vgic_{lock,unlock}_rank
v8: - Fixed printk coding styles
- Moved GICD_PIDRn and GICR_PIDRn macros to vgic-v3.c from header file
- Check is made on return value of vgic_v3_init()
v7: Fixed coding style.
v6: Removed byte read access for IROUTERN register.

xen/arch/arm/vgic.c +0 -0
index 129b1b5..cf3834e 100644
@@ -69,6 +69,12 @@ int domain_vgic_init(struct domain *d)
 
Quoted 10 lines

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d) · line 77

Quoted 8 lines
xen/arch/arm/vgic.c +6 -0
      switch ( gic_hw_version() )
      {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        if ( vgic_v3_init(d) )
+           return -ENODEV;
+        break;
+#endif

Why the #ifdef?

AFAIK, GICv3 is only supported on ARMv8 platform. Hence it's only compiled for this platform.

The #ifdef looks good to me.

Regards,

Signature · 1 line
Julien Grall
#18 lore raw

Re: [PATCH v9 4/7] xen/arm: Add virtual GICv3 support

Quoted 43 lines · Julien Grall

Hi Stefano,

Quoted 29 lines · Stefano Stabellini
Quoted 28 lines · On Thu, 4 Sep 2014, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

Add virtual GICv3 driver support.
Also, with this patch vgic_irq_rank structure is modified to hold GICv2 GICD_TARGET and GICv3 GICD_ROUTER registers under union.

This patch adds only basic GICv3 support. Does not support Interrupt Translation support (ITS)

---
v9: - Use 128K mask to compute GICR register offset if stride
is not set
- Fix alignment errors in vgic-v2.c
- Updated vgic_{lock,unlock}_rank
v8: - Fixed printk coding styles
- Moved GICD_PIDRn and GICR_PIDRn macros to vgic-v3.c from header file
- Check is made on return value of vgic_v3_init()
v7: Fixed coding style.
v6: Removed byte read access for IROUTERN register.

xen/arch/arm/vgic.c +0 -0
index 129b1b5..cf3834e 100644
@@ -69,6 +69,12 @@ int domain_vgic_init(struct domain *d)
 
Quoted 10 lines

xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d) · line 77

Quoted 8 lines
xen/arch/arm/vgic.c +6 -0
      switch ( gic_hw_version() )
      {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        if ( vgic_v3_init(d) )
+           return -ENODEV;
+        break;
+#endif

Why the #ifdef?

Quoted 4 lines

AFAIK, GICv3 is only supported on ARMv8 platform. Hence it's only compiled for this platform.

The #ifdef looks good to me.

You are right, in that case I don't have any other comments on the patch.

#19 lore raw

Re: [PATCH v9 4/7] xen/arm: Add virtual GICv3 support

Quoted 2 lines · Stefano Stabellini

You are right, in that case I don't have any other comments on the patch.

Is that an Ack?

#21 lore raw

PATCH v9 5/7 xen/arm: Update Dom0 GIC dt node with GICv3 information

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

Update GIC device tree node for DOM0 with GICv3 information. GIC hw specfic device tree information is moved to respective GIC driver.

---
 xen/arch/arm/domain_build.c |   47 ++------------------------
 xen/arch/arm/gic-v2.c       |   51 ++++++++++++++++++++++++++++
 xen/arch/arm/gic-v3.c       |   78 +++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic.c          |    6 ++++
 xen/include/asm-arm/gic.h   |    4 +++
 5 files changed, 141 insertions(+), 45 deletions(-)
xen/arch/arm/domain_build.c +2 -45
index 51d793a..333fbad 100644
@@ -777,9 +777,6 @@ static int make_gic_node(const struct domain *d, void *fdt,
                          const struct dt_device_node *node)
 {
     const struct dt_device_node *gic = dt_interrupt_controller;
-    const void *compatible = NULL;
-    u32 len;
-    __be32 *new_cells, *tmp;
     int res = 0;
 
     /*
@@ -794,48 +791,7 @@ static int make_gic_node(const struct domain *d, void *fdt,
 
     DPRINT("Create gic node\n");
 
-    compatible = dt_get_property(gic, "compatible", &len);
-    if ( !compatible )
-    {
-        dprintk(XENLOG_ERR, "Can't find compatible property for the gic node\n");
-        return -FDT_ERR_XEN(ENOENT);
-    }
-
-    res = fdt_begin_node(fdt, "interrupt-controller");
-    if ( res )
-        return res;
-
-    res = fdt_property(fdt, "compatible", compatible, len);
-    if ( res )
-        return res;
-
-    res = fdt_property_cell(fdt, "#interrupt-cells", 3);
-    if ( res )
-        return res;
-
-    res = fdt_property(fdt, "interrupt-controller", NULL, 0);
-
-    if ( res )
-        return res;
-
-    len = dt_cells_to_size(dt_n_addr_cells(node) + dt_n_size_cells(node));
-    len *= 2; /* GIC has two memory regions: Distributor + CPU interface */
-    new_cells = xzalloc_bytes(len);
-    if ( new_cells == NULL )
-        return -FDT_ERR_XEN(ENOMEM);
-
-    tmp = new_cells;
-    DPRINT("  Set Distributor Base 0x%"PRIpaddr"-0x%"PRIpaddr"\n",
-           d->arch.vgic.dbase, d->arch.vgic.dbase + PAGE_SIZE - 1);
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-
-    DPRINT("  Set Cpu Base 0x%"PRIpaddr"-0x%"PRIpaddr"\n",
-           d->arch.vgic.cbase, d->arch.vgic.cbase + (PAGE_SIZE * 2) - 1);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
-
-    res = fdt_property(fdt, "reg", new_cells, len);
-    xfree(new_cells);
-
+    res = gic_make_node(d, node, fdt);
     if ( res )
         return res;
 
@@ -1057,6 +1013,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,
     static const struct dt_device_match gic_matches[] __initconst =
     {
         DT_MATCH_GIC_V2,
+        DT_MATCH_GIC_V3,
         { /* sentinel */ },
     };
     static const struct dt_device_match timer_matches[] __initconst =
xen/arch/arm/gic-v2.c +51 -0

69 lines not on this page · raw message

xen/arch/arm/gic-v3.c +78 -0

96 lines not on this page · raw message

xen/arch/arm/gic.c +6 -0
index 6611ba0..70d10d6 100644
@@ -625,6 +625,12 @@ void __cpuinit init_maintenance_interrupt(void)
                 "irq-maintenance", NULL);
 }
 
+int gic_make_node(const struct domain *d,const struct dt_device_node *node,
+                   void *fdt)
+{
+    return gic_hw_ops->make_dt_node(d, node, fdt);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/gic.h +4 -0
index c4daf5b..51a0a26 100644
@@ -336,9 +336,13 @@ struct gic_hw_operations {
     unsigned int (*read_apr)(int apr_reg);
     /* Secondary CPU init */
     int (*secondary_init)(void);
+    int (*make_dt_node)(const struct domain *d,
+                        const struct dt_device_node *node, void *fdt);
 };
 
 void register_gic_ops(const struct gic_hw_operations *ops);
+int gic_make_node(const struct domain *d,const struct dt_device_node *node,
+                  void *fdt);
 
 #endif /* __ASSEMBLY__ */
 #endif
Signature · 1 line
1.7.9.5
#22 lore raw

PATCH v9 6/7 xen/arm: add SGI handling for GICv3

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

In ARMv8, write to ICC_SGI1R_EL1 register raises trap to EL2. Handle the trap and inject SGI to vcpu.

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   54 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    9 +++++++
 xen/include/asm-arm/gic_v3_defs.h |    7 +++++
 xen/include/asm-arm/sysregs.h     |    3 +++
 xen/include/asm-arm/vgic.h        |    3 +++
 6 files changed, 91 insertions(+)
xen/arch/arm/traps.c +15 -0
index 019991f..25fa8a0 100644
@@ -41,6 +41,7 @@
 #include "decode.h"
 #include "vtimer.h"
 #include <asm/gic.h>
+#include <asm/vgic.h>
 
 /* The base of the stack must always be double-word aligned, which means
  * that both the kernel half of struct cpu_user_regs (which is pushed in
@@ -1743,6 +1744,20 @@ static void do_sysreg(struct cpu_user_regs *regs,
             domain_crash_synchronous();
         }
         break;
+    case HSR_SYSREG_ICC_SGI1R_EL1:
+        if ( !vgic_emulate(regs, hsr) )
+        {
+            dprintk(XENLOG_WARNING,
+                    "failed emulation of sysreg ICC_SGI1R_EL1 access\n");
+            inject_undef64_exception(regs, hsr.len);
+        }
+        break;
+    case HSR_SYSREG_ICC_SGI0R_EL1:
+    case HSR_SYSREG_ICC_ASGI1R_EL1:
+        /* TBD: Implement to support secure grp0/1 SGI forwarding */
+        dprintk(XENLOG_WARNING,
+                "Emulation of sysreg ICC_SGI0R_EL1/ASGI1R_EL1 not supported\n");
+        inject_undef64_exception(regs, hsr.len);
     default:
  bad_sysreg:
         {
xen/arch/arm/vgic-v3.c +54 -0

66 lines not on this page · raw message

xen/arch/arm/vgic.c +9 -0
index cf3834e..6aada9c 100644
@@ -441,6 +441,15 @@ void arch_evtchn_inject(struct vcpu *v)
     vgic_vcpu_inject_irq(v, v->domain->arch.evtchn_irq);
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+ 
+    ASSERT(v->domain->arch.vgic.handler->emulate_sysreg != NULL);
+
+    return v->domain->arch.vgic.handler->emulate_sysreg(regs, hsr);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-arm/gic_v3_defs.h +7 -0
index 6c8ff26..13adb53 100644
@@ -142,6 +142,13 @@
 #define GICH_VMCR_PRIORITY_MASK      0xff
 #define GICH_VMCR_PRIORITY_SHIFT     24
 
+#define ICH_SGI_IRQMODE_SHIFT        40
+#define ICH_SGI_IRQMODE_MASK         0x1
+#define ICH_SGI_TARGET_OTHERS        1
+#define ICH_SGI_TARGET_LIST          0
+#define ICH_SGI_IRQ_SHIFT            24
+#define ICH_SGI_IRQ_MASK             0xf
+#define ICH_SGI_TARGETLIST_MASK      0xffff
 #endif /* __ASM_ARM_GIC_V3_DEFS_H__ */
 
 /*
xen/include/asm-arm/sysregs.h +3 -0
index b4616ac..169b7ac 100644
@@ -78,6 +78,9 @@
 #define HSR_SYSREG_PMINTENCLR_EL1 HSR_SYSREG(3,0,c9,c14,2)
 #define HSR_SYSREG_MAIR_EL1       HSR_SYSREG(3,0,c10,c2,0)
 #define HSR_SYSREG_AMAIR_EL1      HSR_SYSREG(3,0,c10,c3,0)
+#define HSR_SYSREG_ICC_SGI1R_EL1  HSR_SYSREG(3,0,c12,c11,5)
+#define HSR_SYSREG_ICC_ASGI1R_EL1 HSR_SYSREG(3,1,c12,c11,6)
+#define HSR_SYSREG_ICC_SGI0R_EL1  HSR_SYSREG(3,2,c12,c11,7)
 #define HSR_SYSREG_CONTEXTIDR_EL1 HSR_SYSREG(3,0,c13,c0,1)
 
 #define HSR_SYSREG_PMCR_EL0       HSR_SYSREG(3,3,c9,c12,0)
xen/include/asm-arm/vgic.h +3 -0
index 923e97e..9ad1add 100644
@@ -106,6 +106,8 @@ struct vgic_ops {
     /* Get the target vcpu for a given virq. The rank lock is already taken
      * when calling this. */
     struct vcpu *(*get_target_vcpu)(struct vcpu *v, unsigned int irq);
+    /* vGIC sysreg emulation */
+    int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
 };
 
 /* Number of ranks of interrupt registers for a domain */
@@ -176,6 +178,7 @@ extern void vgic_clear_pending_irqs(struct vcpu *v);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, int b, int n, int s);
 extern struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq);
+extern int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr);
 extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n);
 extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops);
Signature · 1 line
1.7.9.5
#23 lore raw

PATCH v9 7/7 xen/arm: check for GICv3 platform support

In reply to [email protected]

From: Vijaya Kumar K <[email protected]>

ID_AA64PFR0_EL1 register provides information about GIC support. Check for this register in GICv3 driver.

Also print GICv3 support information in boot log

---
v9: - Correct error message
v8: - Rearranged prf64 structure member variables
v7: - return -ENODEV on lack GICv3 platform support instead of
panic

---
 xen/arch/arm/gic-v3.c            |    7 +++++++
 xen/arch/arm/setup.c             |    5 +++--
 xen/include/asm-arm/cpufeature.h |    1 +
 xen/include/asm-arm/processor.h  |    4 ++--
 4 files changed, 13 insertions(+), 4 deletions(-)
xen/arch/arm/gic-v3.c +7 -0
index ca450f9..5465b88 100644
@@ -39,6 +39,7 @@
 #include <asm/device.h>
 #include <asm/gic.h>
 #include <asm/gic_v3_defs.h>
+#include <asm/cpufeature.h>
 
 struct rdist_region {
     paddr_t base;
@@ -1158,6 +1159,12 @@ static int __init gicv3_init(struct dt_device_node *node, const void *data)
     int res, i;
     uint32_t reg;
 
+    if ( !cpu_has_gicv3 )
+    {
+        dprintk(XENLOG_ERR, "GICv3: driver requests system register support\n");
+        return -ENODEV;
+    }
+
     dt_device_set_used_by(node, DOMID_XEN);
 
     res = dt_device_get_address(node, 0, &gicv3.dbase, &gicv3.dbase_size);
xen/arch/arm/setup.c +3 -2
index ddaef7e..2e80b5a 100644
@@ -103,9 +103,10 @@ static void __init processor_id(void)
            cpu_has_el2_32 ? "64+32" : cpu_has_el2_64 ? "64" : "No",
            cpu_has_el1_32 ? "64+32" : cpu_has_el1_64 ? "64" : "No",
            cpu_has_el0_32 ? "64+32" : cpu_has_el0_64 ? "64" : "No");
-    printk("    Extensions:%s%s\n",
+    printk("    Extensions:%s%s%s\n",
            cpu_has_fp ? " FloatingPoint" : "",
-           cpu_has_simd ? " AdvancedSIMD" : "");
+           cpu_has_simd ? " AdvancedSIMD" : "",
+           cpu_has_gicv3 ? " GICv3-SysReg" : "");
 
     printk("  Debug Features: %016"PRIx64" %016"PRIx64"\n",
            boot_cpu_data.dbg64.bits[0], boot_cpu_data.dbg64.bits[1]);
xen/include/asm-arm/cpufeature.h +1 -0
index 1d2c9c7..aec9173 100644
@@ -15,6 +15,7 @@
 #define cpu_has_el3_64    (boot_cpu_feature64(el3) >= 1)
 #define cpu_has_fp        (boot_cpu_feature64(fp) == 0)
 #define cpu_has_simd      (boot_cpu_feature64(simd) == 0)
+#define cpu_has_gicv3     (boot_cpu_feature64(gic) == 1)
 #endif
 
 #define cpu_feature32(c, feat)         ((c)->pfr32.feat)
xen/include/asm-arm/processor.h +2 -2
index d83f593..1993af7 100644
@@ -250,8 +250,8 @@ struct cpuinfo_arm {
             unsigned long el3:4;
             unsigned long fp:4;   /* Floating Point */
             unsigned long simd:4; /* Advanced SIMD */
-            unsigned long __res0:8;
-
+            unsigned long gic:4;  /* GIC support */
+            unsigned long __res0:4;
             unsigned long __res1;
         };
     } pfr64;
Signature · 1 line
1.7.9.5
Acked-by on v9 7/7
#24 lore raw

Re: [PATCH v9 7/7] xen/arm: check for GICv3 platform support

Quoted 8 lines · On Thu, 2014-09-04 at 18:45 +0530, [email protected] wrote:

From: Vijaya Kumar K <[email protected]>

ID_AA64PFR0_EL1 register provides information about GIC support. Check for this register in GICv3 driver.

Also print GICv3 support information in boot log

Quoted 1 line

+ dprintk(XENLOG_ERR, "GICv3: driver requests system register support\n");

Did you mean "requires"?

Ian.