Skip to contentSkip to conversation

xen/arm: Add GICv3 support

PATCH Superseded [email protected] 4 participants 38 messages Jul 11, 2014 – Jul 23, 2014

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 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 GICv3 patches as v7 series are posted here.

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

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 (5):
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             | 1262 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/gic.c                |    6 +
 xen/arch/arm/setup.c              |    5 +-
 xen/arch/arm/traps.c              |   15 +
 xen/arch/arm/vgic-v2.c            |    8 +-
 xen/arch/arm/vgic-v3.c            |  954 ++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |   12 +
 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 |  166 +++++
 xen/include/asm-arm/processor.h   |   19 +-
 xen/include/asm-arm/sysregs.h     |    3 +
 xen/include/asm-arm/vgic.h        |   16 +-
 xen/include/xen/lib.h             |    2 +
 18 files changed, 2546 insertions(+), 55 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 v7 1/5 xen/arm: Add support for GIC v3

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.

GICv3 driver uses macros for size values similar to kernel's include/linux/sizes.h file. Introduces required macros in lib.h

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

---
v7: Fixed wrong check for irq number in gicv3_set_irq_properties.
Introduced panic during cpu_init on wrong priority bits.

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

---
 xen/arch/arm/Makefile             |    1 +
 xen/arch/arm/gic-v3.c             | 1177 +++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/domain.h      |    8 +
 xen/include/asm-arm/gic.h         |   20 +
 xen/include/asm-arm/gic_v3_defs.h |  159 +++++
 xen/include/asm-arm/processor.h   |   14 +
 xen/include/xen/lib.h             |    2 +
 7 files changed, 1381 insertions(+)
xen/arch/arm/Makefile +1 -0
index 20f59f4..1684c09 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 +1177 -0

1,177 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..d5a2fcf 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_MATCH_GIC_V3_STRING1      "arm,gic-v3"
+
+#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_MATCH_GIC_V3_STRING1);
+
+/*
+ * 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 +159 -0

159 lines not on this page · raw message

xen/include/asm-arm/processor.h +14 -0
index bdfff4e..ccaa9da 100644
@@ -17,6 +17,20 @@
 #define MPIDR_HWID_MASK     _AC(0xffffff,U)
 #define MPIDR_INVALID       (~MPIDR_HWID_MASK)
 
+/*
+ * Macros to extract affinity level. picked from kernel
+ */
+
+#define MPIDR_LEVEL_BITS_SHIFT  3
+#define MPIDR_LEVEL_BITS        (1 << MPIDR_LEVEL_BITS_SHIFT)
+#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/xen/lib.h +2 -0
index e81b80e..7aef378 100644
@@ -67,6 +67,8 @@ do {                                                            \
 
 #define reserve_bootmem(_p,_l) ((void)0)
 
+#define SZ_64K  0x00010000
+
 struct domain;
 
 void cmdline_parse(const char *cmdline);
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

+static inline void gicv3_restore_lrs(int nr_lrs, const struct vcpu *v)

Other similar functions you have here use gicv3.nr_foo directly.

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

Quoted 3 lines
xen/arch/arm/gic-v3.c new file +3 -0
+    case 1:
+        WRITE_SYSREG(v->arch.gic.v3.lr[0], ICH_LR0_EL2);
+         break;

Nit: whitespace.

Quoted 19 lines
xen/arch/arm/gic-v3.c new file +19 -0
+static void gicv3_save_state(struct vcpu *v)
+{
+
+    /* No need for spinlocks here because interrupts are disabled around
+     * this call and it only accesses struct vcpu fields that cannot be
+     * accessed simultaneously by another pCPU.
+     *
+     * Make sure all stores to the GIC via the memory mapped interface
+     * are now visible to the system register interface
+     */
+    dsb(sy);
+    gicv3_save_lrs(gicv3_info.nr_lrs, v);
+    save_aprn_regs(&v->arch.gic);
+    v->arch.gic.v3.vmcr = READ_SYSREG32(ICH_VMCR_EL2);
+    v->arch.gic.v3.sre_el1 = READ_SYSREG32(ICC_SRE_EL1);
+}
+
+static void gicv3_restore_state(const struct vcpu *v)
+{

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+    WRITE_SYSREG32(v->arch.gic.v3.sre_el1, ICC_SRE_EL1);
+    WRITE_SYSREG32(v->arch.gic.v3.vmcr, ICH_VMCR_EL2);
+    restore_aprn_regs(&v->arch.gic);
+    gicv3_restore_lrs(gicv3_info.nr_lrs, v);
+
+    /*
+     * Make sure all stores are visible the GIC
+     */
+    dsb(sy);
+}

A reference to Section 4.8.17 of the GICv3 spec alongside these functions would be very useful.

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

Quoted 6 lines
xen/arch/arm/gic-v3.c new file +6 -0
+static void __cpuinit gicv3_hyp_disable(void)
+{
+    uint32_t vtr;
+
+    vtr = READ_SYSREG32(ICH_HCR_EL2);
+    vtr &= ~0x1;

Please can you add a define for this value, or reuse GICH_HCR_EN if ICH_HCR_EL2 is compatible with GICv2 GICH_HCR.

Also calling the temporary vtr is confusing, ICH_VTR_EL2 is a different register.

Quoted 4 lines
xen/arch/arm/gic-v3.c new file +4 -0
+static u16 gicv3_compute_target_list(int *base_cpu, const struct cpumask *mask,
+                                     uint64_t cluster_id)
+{
+    int cpu = *base_cpu;

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+    uint64_t mpidr = cpu_logical_map(cpu);
+    u16 tlist = 0;
+
+    while ( cpu < nr_cpu_ids )
+    {
+        /*
+         * If we ever get a cluster of more than 16 CPUs, just
+         * scream and skip that CPU.
+         */
+        if ( (mpidr & 0xff) >= 16 )

MPIPDR_EFF0_MASK if that's what this is, and at least once more in this function.

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

Quoted 3 lines
xen/arch/arm/gic-v3.c new file +3 -0
+        {
+            dprintk(XENLOG_WARNING, "GICv3:Cluster with more than 16's cpus\n");
+            goto out;

Please validate this and complain in gicv3_init not every time we send an SGI.

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+static void gicv3_send_sgi(enum gic_sgi sgi, enum gic_sgi_mode mode,
+                           const cpumask_t *cpumask)
+{
+    int cpu = 0;
+    uint64_t val;
+
+    for_each_cpu(cpu, cpumask)
+    {
+        /* Mask lower 8 bits. It represent cpu in affinity level 0 */
+        uint64_t cluster_id = cpu_logical_map(cpu) & ~0xffUL;

Use MPIDR_AFF0_MASK not 0xff.

Quoted 15 lines
xen/include/asm-arm/gic_v3_defs.h new file +9 -0
new file mode 100644
index 0000000..1c32e0c
 
+#ifndef __ASM_ARM_GIC_V3_DEFS_H__
+#define __ASM_ARM_GIC_V3_DEFS_H__
+
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)
Quoted 2 lines

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

xen/include/xen/lib.h do { \ · line 70

Quoted 9 lines
xen/include/xen/lib.h +1 -0
index e81b80e..7aef378 100644
@@ -67,6 +67,8 @@ do {                                                            \
 
 #define reserve_bootmem(_p,_l) ((void)0)
 
+#define SZ_64K  0x00010000

This was already discussed in v6.

Ian.

#3 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 20 lines · Ian Campbell
Quoted 5 lines · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:
xen/arch/arm/gic-v3.c new file +5 -0
+static inline void gicv3_restore_lrs(int nr_lrs, const struct vcpu *v)
+static u16 gicv3_compute_target_list(int *base_cpu, const struct cpumask *mask,
+                                     uint64_t cluster_id)
+{
+    int cpu = *base_cpu;

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+    uint64_t mpidr = cpu_logical_map(cpu);
+    u16 tlist = 0;
+
+    while ( cpu < nr_cpu_ids )
+    {
+        /*
+         * If we ever get a cluster of more than 16 CPUs, just
+         * scream and skip that CPU.
+         */
+        if ( (mpidr & 0xff) >= 16 )

MPIPDR_EFF0_MASK if that's what this is, and at least once more in this function.

Quoted 7 lines

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

Quoted 3 lines
xen/arch/arm/gic-v3.c new file +3 -0
+        {
+            dprintk(XENLOG_WARNING, "GICv3:Cluster with more than 16's cpus\n");
+            goto out;

Please validate this and complain in gicv3_init not every time we send an SGI.

We can move this check to gicv3_populate_rdist() which is called
for each cpu.
However we will miss check on mpidr value. But being MPIDR value which does not change it should be ok to remove this check

Quoted 11 lines
Quoted 8 lines
xen/include/asm-arm/gic_v3_defs.h new file +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Regards
Vijay

#4 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 12 lines · Vijay Kilari
Quoted 11 lines
Quoted 8 lines
xen/include/asm-arm/gic_v3_defs.h new file +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Those value are GICV3 specific. If you drop the prefix we won't know what are their purpose...

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 14 lines · Julien Grall
Quoted 12 lines · Vijay Kilari
Quoted 11 lines
Quoted 8 lines
xen/include/asm-arm/gic_v3_defs.h new file +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 5 lines
Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Those value are GICV3 specific. If you drop the prefix we won't know what are their purpose...

I'm not so sure that's the case. We will know it is the value to use for GICD_PIDR0 for any GIC which includes that register, which is at least v3 and v4 right now. Calling it V3 is equally misleading as leaving it out.

Given that we've decided to share the #defines across versions I think we should leave the prefix off. The alternative is to make sure everything is prefixed and to duplicate the definitions for each version, which is an approach we previously moved away from I think, I don't see a strong reason to go back on that decision now.

Ian.

#6 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 21 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 12 lines · Vijay Kilari
Quoted 11 lines
Quoted 8 lines
xen/include/asm-arm/gic_v3_defs.h new file +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 5 lines
Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Those value are GICV3 specific. If you drop the prefix we won't know what are their purpose...

Quoted 9 lines

I'm not so sure that's the case. We will know it is the value to use for GICD_PIDR0 for any GIC which includes that register, which is at least v3 and v4 right now. Calling it V3 is equally misleading as leaving it out.
Given that we've decided to share the #defines across versions I think we should leave the prefix off. The alternative is to make sure everything is prefixed and to duplicate the definitions for each version, which is an approach we previously moved away from I think, I don't see a strong reason to go back on that decision now.

On GICv2, this field is called ICPIDR0 (same register offset) and is equal to 0x90.

If those values are only used for the vgic v3 driver, then they should live in the c files and not in the common header.

Regards,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 44 lines · Julien Grall
Quoted 29 lines · Ian Campbell
Quoted 18 lines · Julien Grall
Quoted 15 lines · Vijay Kilari
Quoted 13 lines
Quoted 9 lines
xen/include/asm-arm/gic_v3_defs.h new file +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 7 lines
Quoted 3 lines

GICV3 is prefixed for indicating that there are values not the addresses.
In anycase I will remove GICV3 prefixes and postfix _VAL

Those value are GICV3 specific. If you drop the prefix we won't know what are their purpose...

Quoted 9 lines

I'm not so sure that's the case. We will know it is the value to use for GICD_PIDR0 for any GIC which includes that register, which is at least v3 and v4 right now. Calling it V3 is equally misleading as leaving it out.
Given that we've decided to share the #defines across versions I think we should leave the prefix off. The alternative is to make sure everything is prefixed and to duplicate the definitions for each version, which is an approach we previously moved away from I think, I don't see a strong reason to go back on that decision now.

Quoted 5 lines

On GICv2, this field is called ICPIDR0 (same register offset) and is equal to 0x90.

If those values are only used for the vgic v3 driver, then they should live in the c files and not in the common header.

These PIDR values(not all) are used by both vgic-v3 and gicv3 driver. So those are kept in common header file.

I plan to keep all defines without GICV3 prefix and add V3 specific one GICD_PIDR2_ARCH_V3_VAL

 #define GICD_PIDR0_VAL               (0x92)
 #define GICD_PIDR1_VAL               (0xb4)
-#define GICD_PIDR2_ARCH_VAL          (0x30)
+#define GICD_PIDR2_ARCH_V3_VAL       (0x3)
 #define GICD_PIDR2_VAL               (0x3b)
 #define GICD_PIDR4_VAL               (0x04)
 #define GICD_PIDR2_ARCH_MASK         (0xf0)
+#define GICD_PIDR2_ARCH_SHIFT        (4)
 #define GICR_PIDR0_VAL               (0x93)
 #define GICR_PIDR1_VAL               GICD_PIDR1_VAL
-#define GICR_PIDR2_ARCH_VAL          GICD_PIDR2_ARCH_VAL
+#define GICR_PIDR2_ARCH_V3_VAL       GICD_PIDR2_ARCH_V3_VAL
 #define GICR_PIDR2_VAL               GICD_PIDR2_VAL
 #define GICR_PIDR4_VAL               GICD_PIDR4_VAL
 #define GICR_PIDR2_ARCH_MASK         GICD_PIDR2_ARCH_MASK
+#define GICR_PIDR2_ARCH_SHIFT        GICD_PIDR2_ARCH_SHIFT
#8 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 45 lines · Vijay Kilari
Quoted 44 lines · Julien Grall
Quoted 38 lines · Ian Campbell
Quoted 18 lines · Julien Grall
Quoted 15 lines · Vijay Kilari
Quoted 13 lines
Quoted 9 lines
(quoted diff) +6 -0
+/*
+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 7 lines
Quoted 3 lines

GICV3 is prefixed for indicating that there are values not the addresses.
In anycase I will remove GICV3 prefixes and postfix _VAL

Those value are GICV3 specific. If you drop the prefix we won't know what are their purpose...

I'm not so sure that's the case. We will know it is the value to use for GICD_PIDR0 for any GIC which includes that register, which is at least v3 and v4 right now. Calling it V3 is equally misleading as leaving it out.
Given that we've decided to share the #defines across versions I think we should leave the prefix off. The alternative is to make sure everything is prefixed and to duplicate the definitions for each version, which is an approach we previously moved away from I think, I don't see a strong reason to go back on that decision now.

Quoted 8 lines
Quoted 5 lines

On GICv2, this field is called ICPIDR0 (same register offset) and is equal to 0x90.

If those values are only used for the vgic v3 driver, then they should live in the c files and not in the common header.

These PIDR values(not all) are used by both vgic-v3 and gicv3 driver. So those are kept in common header file.

I think all that should be in the header file are the usual masks and offsets used to decode the register and specific names defines to match against. e.g. for PIDR2:

        #define GICD_PIDR2_ARCH_REV_OFFSET (4)
        #define GICD_PIDR2_ARCH_REV_MASK    (0xf << GICD_PIDR2_ARCH_REV_OFFSET)
        #define GICD_PIDR2_USES_JEP_MASK    0x08
        #define GICD_PIDR2_JEP_ID_MASK      0x07
        ...

The gic code should use these to extract things it needs.

It would normally be OK to also define:

        #define GICD_PIDR2_ARCH_GICV1 1
        #define GICD_PIDR2_ARCH_GICV2 2
        #define GICD_PIDR2_ARCH_GICV3 3

to compare against, but in this case since there is a 1:1 correspondence there doesn't seem to be much point.

The vgic code might use these to construct a value, or might have a local define or constant with a suitable comment.

Ian.

#9 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

In reply to Vijay Kilari
Quoted 25 lines · Vijay Kilari
Quoted 24 lines · Ian Campbell
Quoted 5 lines · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:
xen/arch/arm/gic-v3.c new file +5 -0
+static inline void gicv3_restore_lrs(int nr_lrs, const struct vcpu *v)
+static u16 gicv3_compute_target_list(int *base_cpu, const struct cpumask *mask,
+                                     uint64_t cluster_id)
+{
+    int cpu = *base_cpu;

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+    uint64_t mpidr = cpu_logical_map(cpu);
+    u16 tlist = 0;
+
+    while ( cpu < nr_cpu_ids )
+    {
+        /*
+         * If we ever get a cluster of more than 16 CPUs, just
+         * scream and skip that CPU.
+         */
+        if ( (mpidr & 0xff) >= 16 )

MPIPDR_EFF0_MASK if that's what this is, and at least once more in this function.

Quoted 3 lines
xen/arch/arm/gic-v3.c new file +3 -0
+        {
+            dprintk(XENLOG_WARNING, "GICv3:Cluster with more than 16's cpus\n");
+            goto out;
Quoted 8 lines
Quoted 3 lines

Please validate this and complain in gicv3_init not every time we send an SGI.

We can move this check to gicv3_populate_rdist() which is called
for each cpu.
However we will miss check on mpidr value. But being MPIDR value which does not change it should be ok to remove this check

Why isn't mpidr available at that point?

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

xen/include/asm-arm/gic_v3_defs.h new file +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

You mean the value used when emulating a read, I think?

Ian.

#10 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 30 lines · Ian Campbell
Quoted 29 lines · Vijay Kilari
Quoted 27 lines · Ian Campbell
Quoted 5 lines · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:
xen/arch/arm/gic-v3.c new file +5 -0
+static inline void gicv3_restore_lrs(int nr_lrs, const struct vcpu *v)
+static u16 gicv3_compute_target_list(int *base_cpu, const struct cpumask *mask,
+                                     uint64_t cluster_id)
+{
+    int cpu = *base_cpu;

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

Quoted 10 lines
xen/arch/arm/gic-v3.c new file +10 -0
+    uint64_t mpidr = cpu_logical_map(cpu);
+    u16 tlist = 0;
+
+    while ( cpu < nr_cpu_ids )
+    {
+        /*
+         * If we ever get a cluster of more than 16 CPUs, just
+         * scream and skip that CPU.
+         */
+        if ( (mpidr & 0xff) >= 16 )

MPIPDR_EFF0_MASK if that's what this is, and at least once more in this function.

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

Quoted 3 lines
xen/arch/arm/gic-v3.c new file +3 -0
+        {
+            dprintk(XENLOG_WARNING, "GICv3:Cluster with more than 16's cpus\n");
+            goto out;

Please validate this and complain in gicv3_init not every time we send an SGI.

Quoted 6 lines
Quoted 4 lines

We can move this check to gicv3_populate_rdist() which is called
for each cpu.
However we will miss check on mpidr value. But being MPIDR value which does not change it should be ok to remove this check

Why isn't mpidr available at that point?

I mean check of mpidr value is not done here
(gicv3_compute_target_list()) to skip and
jump to out lable on wrong value of mpidr.

I have added following in gicv3_populate_rdist()

static int __init gicv3_populate_rdist(void)

{
    int i;
    uint32_t aff;
    uint32_t reg;
    uint64_t typer;
    uint64_t mpidr = cpu_logical_map(smp_processor_id());

+ /*
+ * If we ever get a cluster of more than 16 CPUs, just scream.
+ */
+ if ( (mpidr & 0xff) >= 16 )
+ dprintk(XENLOG_WARNING, "GICv3:Cluster with more than 16's cpus\n");

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

xen/include/asm-arm/gic_v3_defs.h new file +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 4 lines
Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

You mean the value used when emulating a read, I think?

Yes, it is used in gicv3 driver for checking presence of re-distributor
and also in vgicv3 for emulating read.

#11 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 12 lines · Vijay Kilari
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

xen/include/asm-arm/gic_v3_defs.h new file +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

You mean the value used when emulating a read, I think?

Yes, it is used in gicv3 driver for checking presence of re-distributor

In the phsyical h/w? That sounds wrong. 0x92 is just one possible value of this register (and the spec says it should be 0x94...). I don't see you using this #define in that way anywhere though so perhaps I've misunderstood.

Quoted 1 line

and also in vgicv3 for emulating read.

I wonder if we should instead propagate the underlying hardware value?

#12 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 16 lines · Ian Campbell
Quoted 15 lines · Vijay Kilari
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

xen/include/asm-arm/gic_v3_defs.h new file +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

You mean the value used when emulating a read, I think?

Yes, it is used in gicv3 driver for checking presence of re-distributor

In the phsyical h/w? That sounds wrong. 0x92 is just one possible value of this register (and the spec says it should be 0x94...). I don't see you using this #define in that way anywhere though so perhaps I've misunderstood.

I am using 20.0 version. which specifies 0x92 for ARM implementations of GICv3. May be other vendors can use different value. So it is better propagate hw value for emulation

GICD_PIDR0:
Bits [7:0]. Bits [7:0] of the ARM-defined DevID field. This field is 0x92 in
ARM implementations of a GICv3 or later Distributor.

In any case, GICD_PIDR0 is not used by gicv3 driver. GICD_PIDR2 & GICR_PIDR2 are
used where check is made on ARCH_REV [7:4]

Quoted 4 lines
Quoted 2 lines

and also in vgicv3 for emulating read.

I wonder if we should instead propagate the underlying hardware value?

Yes,we can propagate hardware value.

#13 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 38 lines · Vijay Kilari
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Vijay Kilari
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

(quoted diff) +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

You mean the value used when emulating a read, I think?

Yes, it is used in gicv3 driver for checking presence of re-distributor

In the phsyical h/w? That sounds wrong. 0x92 is just one possible value of this register (and the spec says it should be 0x94...). I don't see you using this #define in that way anywhere though so perhaps I've misunderstood.

I am using 20.0 version. which specifies 0x92 for ARM implementations of GICv3. May be other vendors can use different value. So it is better propagate hw value for emulation

GICD_PIDR0:
Bits [7:0]. Bits [7:0] of the ARM-defined DevID field. This field is 0x92 in
ARM implementations of a GICv3 or later Distributor.

In any case, GICD_PIDR0 is not used by gicv3 driver. GICD_PIDR2 & GICR_PIDR2 are
used where check is made on ARCH_REV [7:4]

Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

and also in vgicv3 for emulating read.

I wonder if we should instead propagate the underlying hardware value?

Yes,we can propagate hardware value.

I don't think we should propagate the hardware value. We may emulate a different distributor than the hardware one. In this case, implementation defined register won't work as expected by the kernel.

Regards,

Signature · 1 line
Julien Grall
#14 lore raw

Re: [PATCH v7 1/5] xen/arm: Add support for GIC v3

Quoted 42 lines · Julien Grall
Quoted 40 lines · Vijay Kilari
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Vijay Kilari
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines

+ * Additional registers defined in GIC v3.
+ * Common GICD registers are defined in gic.h
+ */

(quoted diff) +2 -0
+
+#define GICD_STATUSR                 (0x010)

[...][
+#define GICV3_GICD_PIDR0 (0x92)

What is the distinction between variables with GIC[DR]_ prefixes and those with GICV3_GIC[DR]_ ones?

GICV3 is prefixed for indicating that there are values not the addresses. In anycase I will remove GICV3 prefixes and postfix _VAL

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

You mean the value used when emulating a read, I think?

Yes, it is used in gicv3 driver for checking presence of re-distributor

In the phsyical h/w? That sounds wrong. 0x92 is just one possible value of this register (and the spec says it should be 0x94...). I don't see you using this #define in that way anywhere though so perhaps I've misunderstood.

I am using 20.0 version. which specifies 0x92 for ARM implementations of GICv3. May be other vendors can use different value. So it is better propagate hw value for emulation

GICD_PIDR0:
Bits [7:0]. Bits [7:0] of the ARM-defined DevID field. This field is 0x92 in
ARM implementations of a GICv3 or later Distributor.

In any case, GICD_PIDR0 is not used by gicv3 driver. GICD_PIDR2 & GICR_PIDR2 are
used where check is made on ARCH_REV [7:4]

Quoted 3 lines
Quoted 2 lines

and also in vgicv3 for emulating read.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I wonder if we should instead propagate the underlying hardware value?

Yes,we can propagate hardware value.

I don't think we should propagate the hardware value. We may emulate a different distributor than the hardware one. In this case, implementation defined register won't work as expected by the kernel.

Then we need to either get our own ID assigned (hard, I expect) or commit to emulating whichever hardware we choose to expose. I don't think emulating the ARM h/w would be a bad choice.

Ian.

#15 lore raw

PATCH v7 2/5 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)

---
v7: Fixed coding style.
v6: Removed byte read access for IROUTERN register.

---
 xen/arch/arm/Makefile      |    1 +
 xen/arch/arm/vgic-v2.c     |    8 +-
 xen/arch/arm/vgic-v3.c     |  902 ++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c        |    5 +
 xen/include/asm-arm/vgic.h |   13 +-
 5 files changed, 924 insertions(+), 5 deletions(-)
xen/arch/arm/Makefile +1 -0
index 1684c09..ba61e58 100644
@@ -28,6 +28,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 +4 -4
index 2102e43..d65146a 100644
@@ -133,7 +133,7 @@ static int vgic_v2_distr_mmio_read(struct vcpu *v, mmio_info_t *info)
         if ( rank == NULL) goto read_as_zero;
 
         vgic_lock_rank(v, rank);
-        *r = rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
+        *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);
@@ -361,10 +361,10 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
         if ( rank == NULL) goto write_ignore;
         vgic_lock_rank(v, rank);
         if ( dabt.size == DABT_WORD )
-            rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
+            rank->v2.itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR,
                                           DABT_WORD)] = *r;
         else
-            vgic_byte_write(&rank->itargets[REG_RANK_INDEX(8,
+            vgic_byte_write(&rank->v2.itargets[REG_RANK_INDEX(8,
                        gicd_reg - GICD_ITARGETSR, DABT_WORD)], *r, gicd_reg);
         vgic_unlock_rank(v, rank);
         return 1;
@@ -466,7 +466,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))
xen/arch/arm/vgic-v3.c new file +902 -0

902 lines not on this page · raw message

xen/arch/arm/vgic.c +5 -0
index d223db4..3647497 100644
@@ -69,6 +69,11 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        vgic_v3_init(d);
+        break;
+#endif
     case GIC_V2:
         if ( vgic_v2_init(d) )
             return -ENODEV;
xen/include/asm-arm/vgic.h +12 -1
index 19eed7e..f580b78 100644
@@ -83,7 +83,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 {
@@ -110,6 +117,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;
@@ -159,6 +169,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 v7 2/5] xen/arm: Add virtual GICv3 support

Hi Vijay,

xen/arch/arm/vgic-v3.c line 561

Quoted 13 lines · On 07/11/2014 01:51 PM, [email protected] wrote:
xen/arch/arm/vgic-v3.c new file +13 -0
+static int vgic_v3_rdistr_mmio_read(struct vcpu *v, mmio_info_t *info)
+{
+    uint32_t offset;
+
+    offset = info->gpa & (v->domain->arch.vgic.rdist_stride - 1);
+
+    if ( offset < SZ_64K )
+        return __vgic_v3_rdistr_rd_mmio_read(v, info, offset);
+    else  if ( (offset >= SZ_64K) && (offset < 2 * SZ_64K) )
+        return vgic_v3_rdistr_sgi_mmio_read(v, info, (offset - SZ_64K));
+    else
+        gdprintk(XENLOG_WARNING, "vGICv3: vGICR: unknown gpa read address \
+                  %"PRIpaddr"\n", info->gpa);

I though I already said that on a previous version...

This is wrong, when you use

     "foo\
         base\n"

The compiler will concatenate the 2 strings without remove the tab/space on the second one. So you will print smth like:

"foo base\n"

You have to use

	"foo"

"base\n"

The remark is the same on various place within this file.

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

Quoted 11 lines
xen/arch/arm/vgic.c +3 -0
index d223db4..3647497 100644
@@ -69,6 +69,11 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        vgic_v3_init(d);

You forgot to check the return value of vgic_v3_init.

Regards,

Signature · 1 line
Julien Grall
#17 lore raw

Re: [PATCH v7 2/5] xen/arm: Add virtual GICv3 support

In reply to [email protected]

On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:
Apart from the things Julien mentioned this looks good to me. One quick question:

[...]

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

Quoted 13 lines
xen/arch/arm/vgic.c +5 -0
index d223db4..3647497 100644
@@ -69,6 +69,11 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        vgic_v3_init(d);
+        break;
+#endif

With the first patch applied we will run guests on GICv3 with GICv2 emulation. Is that expected to work (assuming suitable h/w support)?

My expectation was that this wasn't enabled by this series, which is fine, I'm just wondering if it does just happen to work...

Ian.

#18 lore raw

Re: [PATCH v7 2/5] xen/arm: Add virtual GICv3 support

Quoted 22 lines · Ian Campbell

On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:
Apart from the things Julien mentioned this looks good to me. One quick question:

[...]

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

Quoted 13 lines
xen/arch/arm/vgic.c +5 -0
index d223db4..3647497 100644
@@ -69,6 +69,11 @@ int domain_vgic_init(struct domain *d)
 
     switch ( gic_hw_version() )
     {
+#ifdef CONFIG_ARM_64
+    case GIC_V3:
+        vgic_v3_init(d);
+        break;
+#endif

With the first patch applied we will run guests on GICv3 with GICv2 emulation. Is that expected to work (assuming suitable h/w support)?

Quoted 2 lines

My expectation was that this wasn't enabled by this series, which is fine, I'm just wondering if it does just happen to work...

Yes, this series does not support guests with GICv2. This was known
limitation.

#19 lore raw

PATCH v7 3/5 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       |   80 ++++++++++++++++++++++++++++++++++++++++++-
 xen/arch/arm/gic.c          |    6 ++++
 xen/include/asm-arm/gic.h   |    8 +++--
 5 files changed, 144 insertions(+), 48 deletions(-)
xen/arch/arm/domain_build.c +2 -45
index 8c850ca..40e83f3 100644
@@ -526,9 +526,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;
 
     /*
@@ -543,48 +540,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;
 
@@ -805,6 +761,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 +79 -1

104 lines not on this page · raw message

xen/arch/arm/gic.c +6 -0
index c0d70b8..38aa7b5 100644
@@ -616,6 +616,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 +6 -2
index d5a2fcf..51a0a26 100644
@@ -158,9 +158,9 @@
 #define DT_MATCH_GIC_V2 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A15), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A7)
 
-#define DT_MATCH_GIC_V3_STRING1      "arm,gic-v3"
+#define DT_COMPAT_GIC_V3             "arm,gic-v3"
 
-#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_MATCH_GIC_V3_STRING1);
+#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_V3)
 
 /*
  * GICv3 registers that needs to be saved/restored
@@ -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
Acked-by on v7 3/5
#20 lore raw

Re: [PATCH v7 3/5] xen/arm: Update Dom0 GIC dt node with GICv3 information

Quoted 8 lines · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

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.

I think this patch represents a bisection hazard, since the previous patch will have enabled gic v3 for dom0 but it is not described until this patch is applied. I think that's a tricky one to resolve so I propose we ignore it so long as systems with GICv2 work fine at each step, which I think should be the case.

xen/include/asm-arm/gic.h line 163

Quoted 13 lines
xen/include/asm-arm/gic.h +2 -2
index d5a2fcf..51a0a26 100644
@@ -158,9 +158,9 @@
 #define DT_MATCH_GIC_V2 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A15), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A7)
 
-#define DT_MATCH_GIC_V3_STRING1      "arm,gic-v3"
+#define DT_COMPAT_GIC_V3             "arm,gic-v3"
 
-#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_MATCH_GIC_V3_STRING1);
+#define DT_MATCH_GIC_V3 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_V3)

Ideally you would fold these renamings into the earlier patch which introduced these in the first place.

Ian.

#21 lore raw

PATCH v7 4/5 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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +52 -0

64 lines not on this page · raw message

xen/arch/arm/vgic.c +7 -0
index 3647497..e15d509 100644
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    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 1c32e0c..b94ba20 100644
@@ -147,6 +147,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 b00871c..48ea498 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 f580b78..63ecfa1 100644
@@ -98,6 +98,8 @@ struct vgic_ops {
     int (*vcpu_init)(struct vcpu *v);
     /* Domain specific initialization of vGIC */
     int (*domain_init)(struct domain *d);
+    /* vGIC sysreg emulation */
+    int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
 };
 
 /* Number of ranks of interrupt registers for a domain */
@@ -165,6 +167,7 @@ extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq);
 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 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
#22 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Hi Vijay,

Quoted 132 lines · On 07/11/2014 01:51 PM, [email protected] wrote:

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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +52 -0
index 2bf0e7c..feee486 100644
@@ -834,6 +834,57 @@ write_ignore_64:
     return 1;
 }
 
+static int vgicv3_to_sgi(struct vcpu *v, register_t sgir)
+{
+    int virq;
+    int irqmode;
+    enum gic_sgi_mode sgi_mode;
+    unsigned long vcpu_mask = 0;
+
+    irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
+    virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
+    vcpu_mask = sgir & ICH_SGI_TARGETLIST_MASK;
+
+    /* Map GIC sgi value to enum value */
+    switch ( irqmode )
+    {
+    case ICH_SGI_TARGET_LIST:
+        sgi_mode = SGI_TARGET_LIST;
+        break;
+    case ICH_SGI_TARGET_OTHERS:
+        sgi_mode = SGI_TARGET_OTHERS;
+        break;
+    default:
+        BUG();
+    }
+
+    return vgic_to_sgi(v, sgir, sgi_mode, virq, vcpu_mask);
+}
+
+static int vgicv3_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+    struct hsr_sysreg sysreg = hsr.sysreg;
+    register_t *r = select_user_reg(regs, sysreg.reg);
+
+    ASSERT (hsr.ec == HSR_EC_SYSREG);
+
+    switch ( hsr.bits & HSR_SYSREG_REGS_MASK )
+    {
+    case HSR_SYSREG_ICC_SGI1R_EL1:
+        /* WO */
+        if ( !sysreg.read )
+            return vgicv3_to_sgi(v, *r);
+        else
+        {
+            gdprintk(XENLOG_WARNING, "Reading SGI1R_EL1 - WO register\n");
+            return 0;
+        }
+    default:
+        return 0;
+    }
+}
+
 static const struct mmio_handler_ops vgic_rdistr_mmio_handler = {
     .read_handler  = vgic_v3_rdistr_mmio_read,
     .write_handler = vgic_v3_rdistr_mmio_write,
@@ -884,6 +935,7 @@ static int vgicv3_domain_init(struct domain *d)
 static const struct vgic_ops v3_ops = {
     .vcpu_init   = vgicv3_vcpu_init,
     .domain_init = vgicv3_domain_init,
+    .emulate_sysreg  = vgicv3_emulate_sysreg,
 };
 
 int vgic_v3_init(struct domain *d)
xen/arch/arm/vgic.c +0 -0
index 3647497..e15d509 100644

xen/arch/arm/vgic.c out: · line 352

Quoted 10 lines
xen/arch/arm/vgic.c +7 -0
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    return v->domain->arch.vgic.handler->emulate_sysreg(regs, hsr);
+}
+

You didn't implement emulate_sysreg for vgic-v2. If the GICv3 is misprogrammed, Xen will segfault...

Please either implement emulate_sysreg on vgic-v2 by return 1 or check that the function is not NULL.

Regards,

Signature · 1 line
Julien Grall
#23 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 8 lines · Julien Grall
Quoted 8 lines
xen/arch/arm/vgic.c +0 -0
index 3647497..e15d509 100644
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
Quoted 10 lines

xen/arch/arm/vgic.c out: · line 352

Quoted 7 lines
xen/arch/arm/vgic.c +7 -0
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    return v->domain->arch.vgic.handler->emulate_sysreg(regs, hsr);
+}
+

You didn't implement emulate_sysreg for vgic-v2. If the GICv3 is misprogrammed, Xen will segfault...

Which isn't all that different to the BUG_ON(!->emulate_sysreg) which I would be in favour of, since misprogramming the GIC is a coding error...

Ian.

#24 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 20 lines · Ian Campbell
Quoted 8 lines · Julien Grall
Quoted 8 lines
xen/arch/arm/vgic.c +0 -0
index 3647497..e15d509 100644
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
Quoted 10 lines

xen/arch/arm/vgic.c out: · line 352

Quoted 7 lines
xen/arch/arm/vgic.c +7 -0
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    return v->domain->arch.vgic.handler->emulate_sysreg(regs, hsr);
+}
+

You didn't implement emulate_sysreg for vgic-v2. If the GICv3 is misprogrammed, Xen will segfault...

Quoted 2 lines

Which isn't all that different to the BUG_ON(!->emulate_sysreg) which I would be in favour of, since misprogramming the GIC is a coding error...

I expect this function to be called often (everytime the guest is sending an SGI), so adding BUG_ON(!->emulate_sysreg) will "slow down" the emulation.

Implementing the callback emulate_sysreg for vgic-v2 and adding BUG inside would be another solution.

Regards,

Signature · 1 line
Julien Grall
#25 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 21 lines · Julien Grall
Quoted 20 lines · Ian Campbell
Quoted 18 lines · Julien Grall
Quoted 5 lines
xen/arch/arm/vgic.c +0 -0
index 3647497..e15d509 100644

xen/arch/arm/vgic.c out: · line 352

Quoted 10 lines
xen/arch/arm/vgic.c +7 -0
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    return v->domain->arch.vgic.handler->emulate_sysreg(regs, hsr);
+}
+

You didn't implement emulate_sysreg for vgic-v2. If the GICv3 is misprogrammed, Xen will segfault...

Quoted 6 lines
Quoted 2 lines

Which isn't all that different to the BUG_ON(!->emulate_sysreg) which I would be in favour of, since misprogramming the GIC is a coding error...

I expect this function to be called often (everytime the guest is sending an SGI), so adding BUG_ON(!->emulate_sysreg) will "slow down" the emulation.

Then use ASSERT which are in debug builds only.

Ian.

#26 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

In reply to [email protected]
Quoted 77 lines · On Fri, 11 Jul 2014, [email protected] wrote:

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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +12 -0
index 2bf0e7c..feee486 100644
@@ -834,6 +834,57 @@ write_ignore_64:
     return 1;
 }
 
+static int vgicv3_to_sgi(struct vcpu *v, register_t sgir)
+{
+    int virq;
+    int irqmode;
+    enum gic_sgi_mode sgi_mode;
+    unsigned long vcpu_mask = 0;
+
+    irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
+    virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
+    vcpu_mask = sgir & ICH_SGI_TARGETLIST_MASK;
+
+    /* Map GIC sgi value to enum value */

xen/arch/arm/vgic-v3.c write_ignore_64: · line 858

Quoted 10 lines
xen/arch/arm/vgic-v3.c +10 -0
+    switch ( irqmode )
+    {
+    case ICH_SGI_TARGET_LIST:
+        sgi_mode = SGI_TARGET_LIST;
+        break;
+    case ICH_SGI_TARGET_OTHERS:
+        sgi_mode = SGI_TARGET_OTHERS;
+        break;
+    default:
+        BUG();

You haven't addressed my previous comments (or replied to them if you disagree):

http://marc.info/?l=xen-devel&m=140259344723979
http://marc.info/?l=xen-devel&m=140259388524231

Quoted 114 lines
xen/arch/arm/vgic-v3.c +30 -0
+    }
+
+    return vgic_to_sgi(v, sgir, sgi_mode, virq, vcpu_mask);
+}
+
+static int vgicv3_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+    struct hsr_sysreg sysreg = hsr.sysreg;
+    register_t *r = select_user_reg(regs, sysreg.reg);
+
+    ASSERT (hsr.ec == HSR_EC_SYSREG);
+
+    switch ( hsr.bits & HSR_SYSREG_REGS_MASK )
+    {
+    case HSR_SYSREG_ICC_SGI1R_EL1:
+        /* WO */
+        if ( !sysreg.read )
+            return vgicv3_to_sgi(v, *r);
+        else
+        {
+            gdprintk(XENLOG_WARNING, "Reading SGI1R_EL1 - WO register\n");
+            return 0;
+        }
+    default:
+        return 0;
+    }
+}
+
 static const struct mmio_handler_ops vgic_rdistr_mmio_handler = {
     .read_handler  = vgic_v3_rdistr_mmio_read,
     .write_handler = vgic_v3_rdistr_mmio_write,
@@ -884,6 +935,7 @@ static int vgicv3_domain_init(struct domain *d)
 static const struct vgic_ops v3_ops = {
     .vcpu_init   = vgicv3_vcpu_init,
     .domain_init = vgicv3_domain_init,
+    .emulate_sysreg  = vgicv3_emulate_sysreg,
 };
 
 int vgic_v3_init(struct domain *d)
xen/arch/arm/vgic.c +7 -0
index 3647497..e15d509 100644
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    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 1c32e0c..b94ba20 100644
@@ -147,6 +147,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 b00871c..48ea498 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 f580b78..63ecfa1 100644
@@ -98,6 +98,8 @@ struct vgic_ops {
     int (*vcpu_init)(struct vcpu *v);
     /* Domain specific initialization of vGIC */
     int (*domain_init)(struct domain *d);
+    /* vGIC sysreg emulation */
+    int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
 };
 
 /* Number of ranks of interrupt registers for a domain */
@@ -165,6 +167,7 @@ extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq);
 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 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
#27 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 92 lines · Stefano Stabellini
Quoted 77 lines · On Fri, 11 Jul 2014, [email protected] wrote:

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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +12 -0
index 2bf0e7c..feee486 100644
@@ -834,6 +834,57 @@ write_ignore_64:
     return 1;
 }
 
+static int vgicv3_to_sgi(struct vcpu *v, register_t sgir)
+{
+    int virq;
+    int irqmode;
+    enum gic_sgi_mode sgi_mode;
+    unsigned long vcpu_mask = 0;
+
+    irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
+    virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
+    vcpu_mask = sgir & ICH_SGI_TARGETLIST_MASK;
+
+    /* Map GIC sgi value to enum value */

xen/arch/arm/vgic-v3.c write_ignore_64: · line 858

Quoted 10 lines
xen/arch/arm/vgic-v3.c +10 -0
+    switch ( irqmode )
+    {
+    case ICH_SGI_TARGET_LIST:
+        sgi_mode = SGI_TARGET_LIST;
+        break;
+    case ICH_SGI_TARGET_OTHERS:
+        sgi_mode = SGI_TARGET_OTHERS;
+        break;
+    default:
+        BUG();

You haven't addressed my previous comments (or replied to them if you disagree):

Quoted 1 line

http://marc.info/?l=xen-devel&m=140259344723979

OK. A warning and return 0 will address the issue

Quoted 1 line

http://marc.info/?l=xen-devel&m=140259388524231

OK. I will take care in next version

Quoted 116 lines
Quoted 116 lines
xen/arch/arm/vgic-v3.c +30 -0
+    }
+
+    return vgic_to_sgi(v, sgir, sgi_mode, virq, vcpu_mask);
+}
+
+static int vgicv3_emulate_sysreg(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+    struct hsr_sysreg sysreg = hsr.sysreg;
+    register_t *r = select_user_reg(regs, sysreg.reg);
+
+    ASSERT (hsr.ec == HSR_EC_SYSREG);
+
+    switch ( hsr.bits & HSR_SYSREG_REGS_MASK )
+    {
+    case HSR_SYSREG_ICC_SGI1R_EL1:
+        /* WO */
+        if ( !sysreg.read )
+            return vgicv3_to_sgi(v, *r);
+        else
+        {
+            gdprintk(XENLOG_WARNING, "Reading SGI1R_EL1 - WO register\n");
+            return 0;
+        }
+    default:
+        return 0;
+    }
+}
+
 static const struct mmio_handler_ops vgic_rdistr_mmio_handler = {
     .read_handler  = vgic_v3_rdistr_mmio_read,
     .write_handler = vgic_v3_rdistr_mmio_write,
@@ -884,6 +935,7 @@ static int vgicv3_domain_init(struct domain *d)
 static const struct vgic_ops v3_ops = {
     .vcpu_init   = vgicv3_vcpu_init,
     .domain_init = vgicv3_domain_init,
+    .emulate_sysreg  = vgicv3_emulate_sysreg,
 };
 
 int vgic_v3_init(struct domain *d)
xen/arch/arm/vgic.c +7 -0
index 3647497..e15d509 100644
@@ -343,6 +343,13 @@ out:
         smp_send_event_check_mask(cpumask_of(v->processor));
 }
 
+int vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)
+{
+    struct vcpu *v = current;
+
+    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 1c32e0c..b94ba20 100644
@@ -147,6 +147,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 b00871c..48ea498 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 -1
index f580b78..63ecfa1 100644
@@ -98,6 +98,8 @@ struct vgic_ops {
     int (*vcpu_init)(struct vcpu *v);
     /* Domain specific initialization of vGIC */
     int (*domain_init)(struct domain *d);
+    /* vGIC sysreg emulation */
+    int (*emulate_sysreg)(struct cpu_user_regs *regs, union hsr hsr);
 };
 
 /* Number of ranks of interrupt registers for a domain */
@@ -165,6 +167,7 @@ extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq);
 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 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);
--

1.7.9.5

#28 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 94 lines · Vijay Kilari
Quoted 92 lines · Stefano Stabellini
Quoted 77 lines · On Fri, 11 Jul 2014, [email protected] wrote:

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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +12 -0
index 2bf0e7c..feee486 100644
@@ -834,6 +834,57 @@ write_ignore_64:
     return 1;
 }
 
+static int vgicv3_to_sgi(struct vcpu *v, register_t sgir)
+{
+    int virq;
+    int irqmode;
+    enum gic_sgi_mode sgi_mode;
+    unsigned long vcpu_mask = 0;
+
+    irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
+    virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
+    vcpu_mask = sgir & ICH_SGI_TARGETLIST_MASK;
+
+    /* Map GIC sgi value to enum value */

xen/arch/arm/vgic-v3.c write_ignore_64: · line 858

Quoted 10 lines
xen/arch/arm/vgic-v3.c +10 -0
+    switch ( irqmode )
+    {
+    case ICH_SGI_TARGET_LIST:
+        sgi_mode = SGI_TARGET_LIST;
+        break;
+    case ICH_SGI_TARGET_OTHERS:
+        sgi_mode = SGI_TARGET_OTHERS;
+        break;
+    default:
+        BUG();

You haven't addressed my previous comments (or replied to them if you disagree):

Quoted 5 lines
Quoted 1 line

http://marc.info/?l=xen-devel&m=140259344723979

OK. A warning and return 0 will address the issue

Quoted 1 line

http://marc.info/?l=xen-devel&m=140259388524231

SGI's are injected at Rdist-0 level. So affinity 1,2,3 levels are ignored Do we still need a comment?

#29 lore raw

Re: [PATCH v7 4/5] xen/arm: add SGI handling for GICv3

Quoted 95 lines · Vijay Kilari
Quoted 94 lines · Vijay Kilari
Quoted 92 lines · Stefano Stabellini
Quoted 77 lines · On Fri, 11 Jul 2014, [email protected] wrote:

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.

---
v7: - Introduced callback for sysreg emulation
- Removed unused parameter in inject_undef_exception()
- Use inject_undef64_exception for reporting sysreg handling failure

v6: - Removed forward declaration of vgic_to_sgi() in vgic-v3.c
- Used vgic callback for SGI handling
- Alignment changes

---
 xen/arch/arm/traps.c              |   15 +++++++++++
 xen/arch/arm/vgic-v3.c            |   52 +++++++++++++++++++++++++++++++++++++
 xen/arch/arm/vgic.c               |    7 +++++
 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, 87 insertions(+)
xen/arch/arm/traps.c +15 -0
index 686d8b7..775bef1 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
@@ -1641,6 +1642,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 +12 -0
index 2bf0e7c..feee486 100644
@@ -834,6 +834,57 @@ write_ignore_64:
     return 1;
 }
 
+static int vgicv3_to_sgi(struct vcpu *v, register_t sgir)
+{
+    int virq;
+    int irqmode;
+    enum gic_sgi_mode sgi_mode;
+    unsigned long vcpu_mask = 0;
+
+    irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
+    virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
+    vcpu_mask = sgir & ICH_SGI_TARGETLIST_MASK;
+
+    /* Map GIC sgi value to enum value */

xen/arch/arm/vgic-v3.c write_ignore_64: · line 858

Quoted 10 lines
xen/arch/arm/vgic-v3.c +10 -0
+    switch ( irqmode )
+    {
+    case ICH_SGI_TARGET_LIST:
+        sgi_mode = SGI_TARGET_LIST;
+        break;
+    case ICH_SGI_TARGET_OTHERS:
+        sgi_mode = SGI_TARGET_OTHERS;
+        break;
+    default:
+        BUG();

You haven't addressed my previous comments (or replied to them if you disagree):

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

http://marc.info/?l=xen-devel&m=140259344723979

OK. A warning and return 0 will address the issue

Quoted 1 line

http://marc.info/?l=xen-devel&m=140259388524231

SGI's are injected at Rdist-0 level. So affinity 1,2,3 levels are ignored Do we still need a comment?

I couldn't hurt

#30 lore raw

PATCH v7 5/5 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

---
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  |    5 ++---
 4 files changed, 13 insertions(+), 5 deletions(-)
xen/arch/arm/gic-v3.c +7 -0
index 5ec5305..492fd54 100644
@@ -38,6 +38,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;
@@ -1135,6 +1136,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, "Platform does not support GICv3\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 78dc7f5..6a90c81 100644
@@ -100,9 +100,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" : "");
 
     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..bd84c57 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(gicv3) == 1)
 #endif
 
 #define cpu_feature32(c, feat)         ((c)->pfr32.feat)
xen/include/asm-arm/processor.h +2 -3
index ccaa9da..0188800 100644
@@ -188,9 +188,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 __res1;
+            unsigned long gicv3:4; /* GIC support */
+            unsigned long __res0:36;
         };
     } pfr64;
 
Signature · 1 line
1.7.9.5
#31 lore raw

Re: [PATCH v7 5/5] xen/arm: check for GICv3 platform support

On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

This all looks good apart from:

xen/include/asm-arm/processor.h struct cpuinfo_arm { · line 192

Quoted 9 lines
xen/include/asm-arm/processor.h +2 -3
@@ -188,9 +188,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 __res1;
+            unsigned long gicv3:4; /* GIC support */
+            unsigned long __res0:36;

Please leave __res1 alone. so:
unsigned long simd:4; /* Advanced SIMD */

-           unsigned long __res0:8;
+           unsigned long __res0:4;
+           unsigned long gic:4; /* GIC support */
            unsigned long __res1;

Also note that in the ARMv8 this field is just called "gic", so I have done the same, please do it that way otherwise when gic vN adds a new sysreg we'll just have to rename the field.

Ian

#32 lore raw
In reply to [email protected]
Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

Add GICv3 support for arm64 platform.

I get lots of:
{standard input}:1476: Error: unknown or missing system register name at operand 1 -- `msr ICH_VMCR_EL2,x1'

I'm using:

$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)

Do you have a pointer to a toolchain which can build this stuff?

Ian.

#33 lore raw
Quoted 11 lines · Ian Campbell
Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

Add GICv3 support for arm64 platform.

I get lots of:
{standard input}:1476: Error: unknown or missing system register name at operand 1 -- `msr ICH_VMCR_EL2,x1'

I'm using:

$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)

Do you have a pointer to a toolchain which can build this stuff?

I am using our internal toolchain based on GCC version 4.7

Regards
Vijay

#34 lore raw
Quoted 7 lines · Vijay Kilari
Quoted 6 lines · Ian Campbell
Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

Add GICv3 support for arm64 platform.

I get lots of:
{standard input}:1476: Error: unknown or missing system register name at operand 1 -- `msr ICH_VMCR_EL2,x1'

Quoted 7 lines
Quoted 5 lines

I'm using:

$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)

Do you have a pointer to a toolchain which can build this stuff?

I am using our internal toolchain based on GCC version 4.7

OK. We really ought to find some publicly available toolchain before accepting this code. Or else we need to make gic v3 functionality depend on the toolstack, which would suck.

I'm going to see if the Linaro 4.9 gcc will do it.

Ian.

#35 lore raw
Quoted 14 lines · Ian Campbell
Quoted 13 lines · Vijay Kilari
Quoted 11 lines · Ian Campbell
Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

Add GICv3 support for arm64 platform.

I get lots of:
{standard input}:1476: Error: unknown or missing system register name at operand 1 -- `msr ICH_VMCR_EL2,x1'

I'm using:

$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)

Do you have a pointer to a toolchain which can build this stuff?

Quoted 7 lines
Quoted 1 line

I am using our internal toolchain based on GCC version 4.7

OK. We really ought to find some publicly available toolchain before accepting this code. Or else we need to make gic v3 functionality depend on the toolstack, which would suck.

I'm going to see if the Linaro 4.9 gcc will do it.

Sadly not.

Mark Rutland pointed me to the workaround which Linux uses:
https://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/tree/include/linux/irqchip/arm-gic-v3.h?h=gicv3/base&id=1545387f2ca2e51f5ccd3ed764348ee41e15c02f#n143

Which AFAICT works with at least Linaro's gcc 4.8 and 4.9. So I think we'll have to go down this route.

Please could you make sure that this series compiles with the gcc from either http://releases.linaro.org/14.04/components/toolchain/binaries
or
http://releases.linaro.org/14.06/components/toolchain/binaries

Presumably this will mostly be a case of adding the defines to xen/include/asm-arm/sysregs.h.

Thanks,
Ian.

#36 lore raw
Quoted 31 lines · Ian Campbell
Quoted 14 lines · Ian Campbell
Quoted 13 lines · Vijay Kilari
Quoted 11 lines · Ian Campbell
Quoted 1 line · On Fri, 2014-07-11 at 18:21 +0530, [email protected] wrote:

Add GICv3 support for arm64 platform.

I get lots of:
{standard input}:1476: Error: unknown or missing system register name at operand 1 -- `msr ICH_VMCR_EL2,x1'

I'm using:

$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (crosstool-NG linaro-1.13.1-4.8-2014.04 - Linaro GCC 4.8-2014.04) 4.8.3 20140401 (prerelease)

Do you have a pointer to a toolchain which can build this stuff?

Quoted 7 lines
Quoted 1 line

I am using our internal toolchain based on GCC version 4.7

OK. We really ought to find some publicly available toolchain before accepting this code. Or else we need to make gic v3 functionality depend on the toolstack, which would suck.

I'm going to see if the Linaro 4.9 gcc will do it.

Sadly not.

Mark Rutland pointed me to the workaround which Linux uses:
https://git.kernel.org/cgit/linux/kernel/git/maz/arm-platforms.git/tree/include/linux/irqchip/arm-gic-v3.h?h=gicv3/base&id=1545387f2ca2e51f5ccd3ed764348ee41e15c02f#n143

Which AFAICT works with at least Linaro's gcc 4.8 and 4.9. So I think we'll have to go down this route.

Quoted 7 lines

Please could you make sure that this series compiles with the gcc from either http://releases.linaro.org/14.04/components/toolchain/binaries
or
http://releases.linaro.org/14.06/components/toolchain/binaries

Presumably this will mostly be a case of adding the defines to xen/include/asm-arm/sysregs.h.

After adding assembler aliases to GIC sysregs similar to Mark's workaround,
I observed that existing READ_SYSREG{32,64} and WRITE_SYSREG{32,64} macros does not replace the assembler aliases. Instead register names are kept as it is.

However {READ,WRITE}_SYSREG macros works because these macros are again replaced with {READ,WRITE}_SYSREG64 macro. So pre-processor will replace the sys register name with assembler alias when replacing {READ,WRITE}_SYSREG macro with {READ,WRITE}_SYSREG64 macro

I propose to change existing READ_SYSREG{32,64} and WRITE_SYSREG{32,64} macros

+#define __stringyfy(x) #x
/* Access to system registers */

 #define READ_SYSREG32(name) ({                          \
     uint32_t _r;                                        \
-    asm volatile("mrs  %0, "#name : "=r" (_r));         \
+    asm volatile("mrs  %0, "__stringyfy(name) : "=r" (_r));         \
     _r; })
 #define WRITE_SYSREG32(v, name) do {                    \
     uint32_t _r = v;                                    \
-    asm volatile("msr "#name", %0" : : "r" (_r));       \

+ asm volatile("msr "__stringyfy(name)", %0" : : "r" (_r)); \
} while (0)

 #define WRITE_SYSREG64(v, name) do {                    \
     uint64_t _r = v;                                    \
-    asm volatile("msr "#name", %0" : : "r" (_r));       \
+    asm volatile("msr "__stringyfy(name)", %0" : : "r" (_r));       \
 } while (0)
 #define READ_SYSREG64(name) ({                          \
     uint64_t _r;                                        \
-    asm volatile("mrs  %0, "#name : "=r" (_r));         \
+    asm volatile("mrs  %0, "__stringyfy(name) : "=r" (_r));         \
     _r; })

May be __stringyfy macro can be added to separate header file similar to kernel?

Regards
Vijay

#37 lore raw
Quoted 4 lines · Vijay Kilari

I propose to change existing READ_SYSREG{32,64} and WRITE_SYSREG{32,64} macros

+#define __stringyfy(x) #x

Please use <xen/stringify.h>

Quoted 24 lines

/* Access to system registers */

 #define READ_SYSREG32(name) ({                          \
     uint32_t _r;                                        \
(quoted diff) +4 -4
-    asm volatile("mrs  %0, "#name : "=r" (_r));         \
+    asm volatile("mrs  %0, "__stringyfy(name) : "=r" (_r));         \
     _r; })
 #define WRITE_SYSREG32(v, name) do {                    \
     uint32_t _r = v;                                    \
-    asm volatile("msr "#name", %0" : : "r" (_r));       \
+    asm volatile("msr "__stringyfy(name)", %0" : : "r" (_r));       \
 } while (0)
 
 #define WRITE_SYSREG64(v, name) do {                    \
     uint64_t _r = v;                                    \
-    asm volatile("msr "#name", %0" : : "r" (_r));       \
+    asm volatile("msr "__stringyfy(name)", %0" : : "r" (_r));       \
 } while (0)
 #define READ_SYSREG64(name) ({                          \
     uint64_t _r;                                        \
-    asm volatile("mrs  %0, "#name : "=r" (_r));         \
+    asm volatile("mrs  %0, "__stringyfy(name) : "=r" (_r));         \
     _r; })
Quoted 2 lines

May be __stringyfy macro can be added to separate header file similar to kernel?

Heh, I should read to the end ;-)

The change looks fine in principal, please do it in a patch of its own.

Ian.