Skip to contentSkip to conversation

xen/arm: gic-v2: Detect automatically aliased GIC 400

PATCH In review Julien Grall 2 participants 13 messages Oct 8, 2015 – Oct 23, 2015

lore
Share & tools
lore
#0 lore raw

v4 cover xen/arm: gic-v2: Detect automatically aliased GIC 400

Hi all,

Only patch #3 is related to the subject of the cover letter. The rest is clean up of code I looked while I was working on this series. Though, patch #1 is a new bug fix I noticed between v3 and v4.

Sincerely yours,

Julien Grall (4):
xen/arm: vgic-v2: Report the correct GICC size to the guest xen/arm: gic: Check the size of the CPU and vCPU interface retrieved
from DT
xen/arm: gic-v2: Automatically detect aliased GIC400 xen/arm: platform: Drop the quirks callback

 xen/arch/arm/gic-hip04.c             | 12 ++---
 xen/arch/arm/gic-v2.c                | 90 ++++++++++++++++++++++++++++--------
 xen/arch/arm/gic-v3.c                | 23 +++++++--
 xen/arch/arm/platform.c              | 10 ----
 xen/arch/arm/platforms/xgene-storm.c |  6 ---
 xen/arch/arm/vgic-v2.c               | 49 ++++++++++++--------
 xen/include/asm-arm/gic.h            |  1 +
 xen/include/asm-arm/platform.h       | 14 ------
 xen/include/asm-arm/vgic.h           |  3 +-
 xen/include/public/arch-arm.h        |  2 +-
 10 files changed, 128 insertions(+), 82 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v4 1/4 xen/arm: vgic-v2: Report the correct GICC size to the guest

The GICv2 DT node is usually used by the guest to know the address/size of the regions (GICD, GICC...) to map into their virtual memory.

While the GICv2 spec requires the size of the GICC to be 8KB, we correctly do an 8KB stage-2 mapping but errornously report 256 in the device tree (based on GUEST_GICC_SIZE).

I bet we didn't see any issue so far because all the registers except GICC_DIR lives in the first 256 bytes of the GICC region and all the guest I have seen so far are driving the GIC with GICC_CTLR.EIOmode = 0.

---
This patch is a good candidate to backport for Xen 4.6 - 4.4. Without it a guest relying on the DT can't use GICC_DIR.

Changes in v4:
- Patch added

---
 xen/include/public/arch-arm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/arch-arm.h +1 -1
index 9a96401..3c365f3 100644
@@ -397,7 +397,7 @@ typedef uint64_t xen_callback_t;
 #define GUEST_GICD_BASE   0x03001000ULL
 #define GUEST_GICD_SIZE   0x00001000ULL
 #define GUEST_GICC_BASE   0x03002000ULL
-#define GUEST_GICC_SIZE   0x00000100ULL
+#define GUEST_GICC_SIZE   0x00002000ULL
 
 /* vGIC v3 mappings */
 #define GUEST_GICV3_GICD_BASE      0x03001000ULL
Signature · 1 line
2.1.4
Acked-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] xen/arm: vgic-v2: Report the correct GICC size to the guest

Quoted 6 lines · Julien Grall

The GICv2 DT node is usually used by the guest to know the address/size of the regions (GICD, GICC...) to map into their virtual memory.

While the GICv2 spec requires the size of the GICC to be 8KB, we correctly do an 8KB stage-2 mapping but errornously report 256 in the device tree (based on GUEST_GICC_SIZE).

"erroneously"

Quoted 3 lines

I bet we didn't see any issue so far because all the registers except GICC_DIR lives in the first 256 bytes of the GICC region and all the guest

"guests"

Quoted 4 lines

I have seen so far are driving the GIC with GICC_CTLR.EIOmode = 0.

(typo's fixable on commit).

Quoted 3 lines

---
This patch is a good candidate to backport for Xen 4.6 - 4.4. Without it a guest relying on the DT can't use GICC_DIR.

Noted, but just to check: This patch (and none of the other fixes in this series) are all which are required for a guest to be able to use GICC_DIR, right?

#3 lore raw

Re: [PATCH v4 1/4] xen/arm: vgic-v2: Report the correct GICC size to the guest

Hi Ian,

Quoted 16 lines · Ian Campbell
Quoted 6 lines · Julien Grall

The GICv2 DT node is usually used by the guest to know the address/size of the regions (GICD, GICC...) to map into their virtual memory.

While the GICv2 spec requires the size of the GICC to be 8KB, we correctly do an 8KB stage-2 mapping but errornously report 256 in the device tree (based on GUEST_GICC_SIZE).

"erroneously"

Quoted 3 lines

I bet we didn't see any issue so far because all the registers except GICC_DIR lives in the first 256 bytes of the GICC region and all the guest

"guests"

Quoted 8 lines
Quoted 4 lines

I have seen so far are driving the GIC with GICC_CTLR.EIOmode = 0.

(typo's fixable on commit).

Thank you!

Quoted 7 lines
Quoted 3 lines

---
This patch is a good candidate to backport for Xen 4.6 - 4.4. Without it a guest relying on the DT can't use GICC_DIR.

Noted, but just to check: This patch (and none of the other fixes in this series) are all which are required for a guest to be able to use GICC_DIR, right?

Correct. BTW, I forgot to mention that this patch may not apply cleanly on Xen 4.4 as rearranged the guest memory address space in Xen 4.5.

Regards,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v4 1/4] xen/arm: vgic-v2: Report the correct GICC size to the guest

Quoted 36 lines · Julien Grall

Hi Ian,

Quoted 18 lines · Ian Campbell
Quoted 7 lines · Julien Grall

The GICv2 DT node is usually used by the guest to know the address/size
of the regions (GICD, GICC...) to map into their virtual memory.

While the GICv2 spec requires the size of the GICC to be 8KB, we correctly do an 8KB stage-2 mapping but errornously report 256 in the device tree (based on GUEST_GICC_SIZE).

"erroneously"

Quoted 4 lines

I bet we didn't see any issue so far because all the registers except GICC_DIR lives in the first 256 bytes of the GICC region and all the guest

"guests"

Quoted 8 lines
Quoted 4 lines

I have seen so far are driving the GIC with GICC_CTLR.EIOmode = 0.

(typo's fixable on commit).

Thank you!

Quoted 4 lines
Quoted 3 lines

---
This patch is a good candidate to backport for Xen 4.6 - 4.4. Without it a guest relying on the DT can't use GICC_DIR.

Quoted 8 lines
Quoted 5 lines

Noted, but just to check: This patch (and none of the other fixes in this
series) are all which are required for a guest to be able to use GICC_DIR,
right?

Correct. BTW, I forgot to mention that this patch may not apply cleanly on Xen 4.4 as rearranged the guest memory address space in Xen 4.5.

I'd be inclined not to bother with it for 4.4 at this juncture then.

Ian.

#5 lore raw

Re: [PATCH v4 1/4] xen/arm: vgic-v2: Report the correct GICC size to the guest

Quoted 43 lines · Ian Campbell
Quoted 42 lines · Julien Grall

Hi Ian,

Quoted 18 lines · Ian Campbell
Quoted 7 lines · Julien Grall

The GICv2 DT node is usually used by the guest to know the address/size
of the regions (GICD, GICC...) to map into their virtual memory.

While the GICv2 spec requires the size of the GICC to be 8KB, we correctly do an 8KB stage-2 mapping but errornously report 256 in the device tree (based on GUEST_GICC_SIZE).

"erroneously"

Quoted 4 lines

I bet we didn't see any issue so far because all the registers except GICC_DIR lives in the first 256 bytes of the GICC region and all the guest

"guests"

Quoted 8 lines
Quoted 4 lines

I have seen so far are driving the GIC with GICC_CTLR.EIOmode = 0.

(typo's fixable on commit).

Thank you!

Quoted 9 lines
Quoted 3 lines

---
This patch is a good candidate to backport for Xen 4.6 - 4.4. Without it a guest relying on the DT can't use GICC_DIR.

Noted, but just to check: This patch (and none of the other fixes in this
series) are all which are required for a guest to be able to use GICC_DIR,
right?

Quoted 4 lines
Quoted 2 lines

Correct. BTW, I forgot to mention that this patch may not apply cleanly on Xen 4.4 as rearranged the guest memory address space in Xen 4.5.

I'd be inclined not to bother with it for 4.4 at this juncture then.

I'm fine with that.

Regards,

Signature · 1 line
Julien Grall
#6 lore raw

PATCH v4 2/4 xen/arm: gic: Check the size of the CPU and vCPU interface retrieved from DT

In reply to Julien Grall

The size of the CPU interface will used in a follow-up patch to map the region in Xen memory.

Based on GICv2 spec, the CPU interface should at least be 8KB, although most of the platform we are supporting use incorrectly the GICv1 size (i.e 4KB) in their DT. Only warn and update the size to avoid any breakage on these platforms.

Furthermore, Xen is relying on the fact that the Virtual CPU interface been at least 8KB. As in reality the Virtual CPU interface matches the CPU interface, check that the 2 interfaces have the same size.

For GICv3, vGICv2 is only available for guest. So we only need to check that the GICV is at least 8KB.

---
Cc: Zoltan Kiss <[email protected]>

I haven't done any change in the gic-hip04 driver. I will let the maintainers doing it if they feel it's necessary.

The check on the CPU interface size has not been modified because if we really want to check the validity of it, we would have to check at least SZ_4K, SZ_8K and SZ_128K. Although I'm not sure if there is other possible values.

Changes in v4:
- Only check the GICV size is at least 8KB to support GICv2 on GICv3
- Panic if the sizes of GICC and GICV are different when initializing the GICv2 driver
- Update warning in gicv2_init
- Update commit message

Changes in v3:
- Shorten the error messages
- Typo

Changes in v2:
- Fix typoes in the commit message
- Fix typoes in warning messages
- Avoid to split string literally in the middle of the sentence, so grep still works.
- csize should be checked against vsize and not vbase!

---
 xen/arch/arm/gic-v2.c | 31 +++++++++++++++++++++++++++----
 xen/arch/arm/gic-v3.c | 19 +++++++++++++++++--
 2 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/arm/gic-v2.c +27 -4
index 5841e59..48155cb 100644
@@ -617,14 +617,16 @@ static hw_irq_controller gicv2_guest_irq_type = {
 static int __init gicv2_init(void)
 {
     int res;
-    paddr_t hbase, dbase, cbase, vbase;
+    paddr_t hbase, dbase;
+    paddr_t cbase, csize;
+    paddr_t vbase, vsize;
     const struct dt_device_node *node = gicv2_info.node;
 
     res = dt_device_get_address(node, 0, &dbase, NULL);
     if ( res )
         panic("GICv2: Cannot find a valid address for the distributor");
 
-    res = dt_device_get_address(node, 1, &cbase, NULL);
+    res = dt_device_get_address(node, 1, &cbase, &csize);
     if ( res )
         panic("GICv2: Cannot find a valid address for the CPU");
 
@@ -632,7 +634,7 @@ static int __init gicv2_init(void)
     if ( res )
         panic("GICv2: Cannot find a valid address for the hypervisor");
 
-    res = dt_device_get_address(node, 3, &vbase, NULL);
+    res = dt_device_get_address(node, 3, &vbase, &vsize);
     if ( res )
         panic("GICv2: Cannot find a valid address for the virtual CPU");
 
@@ -641,7 +643,28 @@ static int __init gicv2_init(void)
         panic("GICv2: Cannot find the maintenance IRQ");
     gicv2_info.maintenance_irq = res;
 
-    /* TODO: Add check on distributor, cpu size */
+    /* TODO: Add check on distributor */
+
+    /*
+     * The GICv2 CPU interface should at least be 8KB. Although, most of the DT
+     * doesn't correctly set it and use the GICv1 CPU interface size (i.e 4KB).
+     * Warn and then fixup.
+     */
+    if ( csize < SZ_8K )
+    {
+        printk(XENLOG_WARNING "GICv2: WARNING: "
+               "The GICC size is too small: %#"PRIx64" expected %#x\n",
+               csize, SZ_8K);
+        csize = SZ_8K;
+    }
+
+    /*
+     * Check if the CPU interface and virtual CPU interface have the
+     * same size.
+     */
+    if ( csize != vsize )
+        panic("GICv2: Sizes of GICC (%#"PRIpaddr") and GICV (%#"PRIpaddr") don't match\n",
+               csize, vsize);
 
     printk("GICv2 initialization:\n"
               "        gic_dist_addr=%"PRIpaddr"\n"
xen/arch/arm/gic-v3.c +17 -2
index 957c6e0..fe0654f 100644
@@ -1143,7 +1143,8 @@ static void __init gicv3_init_v2(const struct dt_device_node *node,
                                  paddr_t dbase)
 {
     int res;
-    paddr_t cbase, vbase;
+    paddr_t cbase;
+    paddr_t vbase, vsize;
 
     /*
      * For GICv3 supporting GICv2, GICC and GICV base address will be
@@ -1155,10 +1156,24 @@ static void __init gicv3_init_v2(const struct dt_device_node *node,
         return;
 
     res = dt_device_get_address(node, 1 + gicv3.rdist_count + 2,
-                                &vbase, NULL);
+                                &vbase, &vsize);
     if ( res )
         return;
 
+    /*
+     * We emulate a vGICv2 using a GIC CPU interface of GUEST_GICC_SIZE.
+     * So only support GICv2 on GICv3 when the virtuaL CPU interface is
+     * at least GUEST_GICC_SIZE.
+     */
+    if ( vsize < GUEST_GICC_SIZE )
+    {
+        printk(XENLOG_WARNING
+               "GICv3: WARNING: Not enabling support for GICv2 compat mode.\n"
+               "Size of GICV (%#"PRIpaddr") must at least be %#llx.\n",
+               vsize, GUEST_GICC_SIZE);
+        return;
+    }
+
     printk("GICv3 compatible with GICv2 cbase %#"PRIpaddr" vbase %#"PRIpaddr"\n",
            cbase, vbase);
 
Signature · 1 line
2.1.4
Acked-by on v4 2/4
#7 lore raw

Re: [PATCH v4 2/4] xen/arm: gic: Check the size of the CPU and vCPU interface retrieved from DT

Quoted 1 line · Julien Grall

The size of the CPU interface will used in a follow-up patch to map the

                                    ^be
Quoted 9 lines

region in Xen memory.

Based on GICv2 spec, the CPU interface should at least be 8KB, although most of the platform we are supporting use incorrectly the GICv1 size (i.e 4KB) in their DT. Only warn and update the size to avoid any breakage on these platforms.

Furthermore, Xen is relying on the fact that the Virtual CPU interface been at least 8KB. As in reality the Virtual CPU interface matches the

s/been/is/

xen/arch/arm/gic-v2.c static int __init gicv2_init(void) · line 650

Quoted 5 lines
xen/arch/arm/gic-v2.c +5 -0
+    /* TODO: Add check on distributor */
+
+    /*
+     * The GICv2 CPU interface should at least be 8KB. Although, most of the DT
+     * doesn't correctly set it and use the GICv1 CPU interface size (i.e 4KB).

don't

xen/arch/arm/gic-v3.c static void __init gicv3_init_v2(const struct dt_device_node *node, · line 1165

Quoted 7 lines
xen/arch/arm/gic-v3.c +4 -0
+                                &vbase, &vsize);
     if ( res )
         return;
 
+    /*
+     * We emulate a vGICv2 using a GIC CPU interface of GUEST_GICC_SIZE.
+     * So only support GICv2 on GICv3 when the virtuaL CPU interface is

s/L/l/

Apart from the typos:

#8 lore raw

PATCH v4 3/4 xen/arm: gic-v2: Automatically detect aliased GIC400

In reply to Julien Grall

We are currently using a per-platform quirk to know if the 2 4KB region of the GIC CPU interface are each aligned to 64KB. Although, it may be possible to have different layout on a same platform (depending on the firmware version).

Rather than having a quirk it's possible to detect by reading the GIC memory. This patch is based from the Linux commit "irqchip/GIC: Add workaround for aliased GIC400" [1].

Take the opportunity to clean up the GICv2 of code which was only required because of the quirk.

Note that none of the platform using the gic-hip04 were actually using the quirk, so the code has been dropped. I will let the maintainers decide whether it's relevant or not to add proper detection for aliased GIC for this hardware.

[1] commit 12e14066f4835f5ee1ca795f0309415b54c067a9
Author: Marc Zyngier <[email protected]>
Date: Sun Sep 13 12:14:31 2015 +0100

irqchip/GIC: Add workaround for aliased GIC400

The GICv2 architecture mandates that the two 4kB GIC regions are contiguous, and on two separate physical pages (so that access to the second page can be trapped by a hypervisor). This doesn't work very well when PAGE_SIZE is 64kB.

A relatively common hack^Wway to work around this is to alias each 4kB region over its own 64kB page. Of course in this case, the base address you want to use is not really the begining of the region, but base + 60kB (so that you get a contiguous 8kB region over two distinct pages).

Normally, this would be described in DT with a new property, but some HW is already out there, and the firmware makes sure that it will override whatever you put in the GIC node. Duh. And of course, said firmware source code is not available, despite being based on u-boot.

The workaround is to detect the case where the CPU interface size is set to 128kB, and verify the aliasing by checking that the ID register for GIC400 (which is the only GIC wired this way so far) is the same at base and base + 0xF000. In this case, we update the GIC base address and let it roll.

And if you feel slightly sick by looking at this, rest assured that I do too...

---
Cc: Zoltan Kiss <[email protected]>

Changes in v4:
- Initialize aliased_offset to 0 when GICv2 is not aliased. I'm not sure why GCC didn't spot this uninitiliazed value...
- Use GUEST_GICC_SIZE rather than 8KB but ensure it's always 8KB.
- With those changes remove Ian's acked-by

Changes in v3:
- Add Ian's acked-by

Changes in v2:
- Drop XXX for gic-v3 and gic-hip04 as won't support aliased GIC
- Fix typoes

---
 xen/arch/arm/gic-hip04.c             | 12 +++-----
 xen/arch/arm/gic-v2.c                | 59 ++++++++++++++++++++++++++----------
 xen/arch/arm/gic-v3.c                |  6 ++--
 xen/arch/arm/platforms/xgene-storm.c |  6 ----
 xen/arch/arm/vgic-v2.c               | 49 +++++++++++++++++++-----------
 xen/include/asm-arm/gic.h            |  1 +
 xen/include/asm-arm/platform.h       |  6 ----
 xen/include/asm-arm/vgic.h           |  3 +-
 8 files changed, 84 insertions(+), 58 deletions(-)
xen/arch/arm/gic-hip04.c +4 -8
index e8cdcd4..310f35a 100644
@@ -631,14 +631,14 @@ static hw_irq_controller hip04gic_guest_irq_type = {
 static int __init hip04gic_init(void)
 {
     int res;
-    paddr_t hbase, dbase, cbase, vbase;
+    paddr_t hbase, dbase, cbase, csize, vbase;
     const struct dt_device_node *node = gicv2_info.node;
 
     res = dt_device_get_address(node, 0, &dbase, NULL);
     if ( res )
         panic("GIC-HIP04: Cannot find a valid address for the distributor");
 
-    res = dt_device_get_address(node, 1, &cbase, NULL);
+    res = dt_device_get_address(node, 1, &cbase, &csize);
     if ( res )
         panic("GIC-HIP04: Cannot find a valid address for the CPU");
 
@@ -675,11 +675,7 @@ static int __init hip04gic_init(void)
         panic("GIC-HIP04: Failed to ioremap for GIC distributor\n");
 
     gicv2.map_cbase[0] = ioremap_nocache(cbase, PAGE_SIZE);
-
-    if ( platform_has_quirk(PLATFORM_QUIRK_GIC_64K_STRIDE) )
-        gicv2.map_cbase[1] = ioremap_nocache(cbase + SZ_64K, PAGE_SIZE);
-    else
-        gicv2.map_cbase[1] = ioremap_nocache(cbase + PAGE_SIZE, PAGE_SIZE);
+    gicv2.map_cbase[1] = ioremap_nocache(cbase + PAGE_SIZE, PAGE_SIZE);
 
     if ( !gicv2.map_cbase[0] || !gicv2.map_cbase[1] )
         panic("GIC-HIP04: Failed to ioremap for GIC CPU interface\n");
@@ -688,7 +684,7 @@ static int __init hip04gic_init(void)
     if ( !gicv2.map_hbase )
         panic("GIC-HIP04: Failed to ioremap for GIC Virtual interface\n");
 
-    vgic_v2_setup_hw(dbase, cbase, vbase);
+    vgic_v2_setup_hw(dbase, cbase, csize, vbase, 0);
 
     /* Global settings: interrupt distributor */
     spin_lock_init(&gicv2.lock);
xen/arch/arm/gic-v2.c +43 -16

99 lines not on this page · raw message

xen/arch/arm/gic-v3.c +3 -3
index fe0654f..396d134 100644
@@ -1143,7 +1143,7 @@ static void __init gicv3_init_v2(const struct dt_device_node *node,
                                  paddr_t dbase)
 {
     int res;
-    paddr_t cbase;
+    paddr_t cbase, csize;
     paddr_t vbase, vsize;
 
     /*
@@ -1151,7 +1151,7 @@ static void __init gicv3_init_v2(const struct dt_device_node *node,
      * provided.
      */
     res = dt_device_get_address(node, 1 + gicv3.rdist_count,
-                                &cbase, NULL);
+                                &cbase, &csize);
     if ( res )
         return;
 
@@ -1177,7 +1177,7 @@ static void __init gicv3_init_v2(const struct dt_device_node *node,
     printk("GICv3 compatible with GICv2 cbase %#"PRIpaddr" vbase %#"PRIpaddr"\n",
            cbase, vbase);
 
-    vgic_v2_setup_hw(dbase, cbase, vbase);
+    vgic_v2_setup_hw(dbase, cbase, csize, vbase, 0);
 }
 
 /* Set up the GIC */
xen/arch/arm/platforms/xgene-storm.c +0 -6
index 8b05ed5..70cb655 100644
@@ -68,11 +68,6 @@ static void __init xgene_check_pirq_eoi(void)
               "Please upgrade your firmware to the latest version");
 }
 
-static uint32_t xgene_storm_quirks(void)
-{
-    return PLATFORM_QUIRK_GIC_64K_STRIDE;
-}
-
 static void xgene_storm_reset(void)
 {
     void __iomem *addr;
@@ -122,7 +117,6 @@ PLATFORM_START(xgene_storm, "APM X-GENE STORM")
     .compatible = xgene_storm_dt_compat,
     .init = xgene_storm_init,
     .reset = xgene_storm_reset,
-    .quirks = xgene_storm_quirks,
 PLATFORM_END
 
 /*
xen/arch/arm/vgic-v2.c +31 -18

89 lines not on this page · raw message

xen/include/asm-arm/gic.h +1 -0
index 6d53f97..0116481 100644
@@ -76,6 +76,7 @@
 #define GICC_HPPIR      (0x0018)
 #define GICC_APR        (0x00D0)
 #define GICC_NSAPR      (0x00E0)
+#define GICC_IIDR       (0x00FC)
 #define GICC_DIR        (0x1000)
 
 #define GICH_HCR        (0x00)
xen/include/asm-arm/platform.h +0 -6
index b8fc5ac..5e462ac 100644
@@ -39,12 +39,6 @@ struct platform_desc {
     const struct dt_device_match *blacklist_dev;
 };
 
-/*
- * Quirk for platforms where the 4K GIC register ranges are placed at
- * 64K stride.
- */
-#define PLATFORM_QUIRK_GIC_64K_STRIDE (1 << 0)
-
 void __init platform_init(void);
 int __init platform_init_time(void);
 int __init platform_specific_mapping(struct domain *d);
xen/include/asm-arm/vgic.h +2 -1
index ba74d0f..cb51a9e 100644
@@ -248,7 +248,8 @@ static inline int vgic_allocate_spi(struct domain *d)
 
 extern void vgic_free_virq(struct domain *d, unsigned int virq);
 
-void vgic_v2_setup_hw(paddr_t dbase, paddr_t cbase, paddr_t vbase);
+void vgic_v2_setup_hw(paddr_t dbase, paddr_t cbase, paddr_t csize,
+                      paddr_t vbase, uint32_t aliased_offset);
 
 #ifdef HAS_GICV3
 struct rdist_region;
Signature · 1 line
2.1.4
Acked-by on v4 3/4
#9 lore raw

Re: [PATCH v4 3/4] xen/arm: gic-v2: Automatically detect aliased GIC400

Quoted 59 lines · Julien Grall

We are currently using a per-platform quirk to know if the 2 4KB region of
the GIC CPU interface are each aligned to 64KB. Although, it may be possible to have different layout on a same platform (depending on the firmware version).

Rather than having a quirk it's possible to detect by reading the GIC memory. This patch is based from the Linux commit "irqchip/GIC: Add workaround
for aliased GIC400" [1].

Take the opportunity to clean up the GICv2 of code which was only required because of the quirk.

Note that none of the platform using the gic-hip04 were actually using the quirk, so the code has been dropped. I will let the maintainers decide whether it's relevant or not to add proper detection for aliased GIC for this hardware.

[1] commit 12e14066f4835f5ee1ca795f0309415b54c067a9
Author: Marc Zyngier <[email protected]>
Date: Sun Sep 13 12:14:31 2015 +0100

irqchip/GIC: Add workaround for aliased GIC400

The GICv2 architecture mandates that the two 4kB GIC regions are contiguous, and on two separate physical pages (so that access to the second page can be trapped by a hypervisor). This doesn't work very well when PAGE_SIZE is 64kB.

A relatively common hack^Wway to work around this is to alias each 4kB region over its own 64kB page. Of course in this case, the base address you want to use is not really the begining of the region, but base + 60kB (so that you get a contiguous 8kB region over two distinct pages).

Normally, this would be described in DT with a new property, but some HW is already out there, and the firmware makes sure that it will override whatever you put in the GIC node. Duh. And of
course,
said firmware source code is not available, despite being based on u-boot.

The workaround is to detect the case where the CPU interface size is set to 128kB, and verify the aliasing by checking that the ID register for GIC400 (which is the only GIC wired this way so far) is the same at base and base + 0xF000. In this case, we update the GIC base address and let it roll.

And if you feel slightly sick by looking at this, rest assured that I do too...

Quoted 4 lines

[email protected]

#10 lore raw

PATCH v4 4/4 xen/arm: platform: Drop the quirks callback

In reply to Julien Grall

All the quirks has been replaced by proper detection. Lets drop the callback and hope that no one will need new quirks.

At the same time, remove the definition platform_dom0_evtchn_ppi with is not used any more.

---
Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/platform.c        | 10 ----------
 xen/include/asm-arm/platform.h |  8 --------
 2 files changed, 18 deletions(-)
xen/arch/arm/platform.c +0 -10
index 0af6d57..b0bfaa9 100644
@@ -127,16 +127,6 @@ void platform_poweroff(void)
         platform->poweroff();
 }
 
-bool_t platform_has_quirk(uint32_t quirk)
-{
-    uint32_t quirks = 0;
-
-    if ( platform && platform->quirks )
-        quirks = platform->quirks();
-
-    return !!(quirks & quirk);
-}
-
 bool_t platform_device_is_blacklisted(const struct dt_device_node *node)
 {
     const struct dt_device_match *blacklist = NULL;
xen/include/asm-arm/platform.h +0 -8
index 5e462ac..f97315d 100644
@@ -27,12 +27,6 @@ struct platform_desc {
     /* Platform power-off */
     void (*poweroff)(void);
     /*
-     * Platform quirks
-     * Defined has a function because a platform can support multiple
-     * board with different quirk on each
-     */
-    uint32_t (*quirks)(void);
-    /*
      * Platform blacklist devices
      * List of devices which must not pass-through to a guest
      */
@@ -48,9 +42,7 @@ int platform_cpu_up(int cpu);
 #endif
 void platform_reset(void);
 void platform_poweroff(void);
-bool_t platform_has_quirk(uint32_t quirk);
 bool_t platform_device_is_blacklisted(const struct dt_device_node *node);
-unsigned int platform_dom0_evtchn_ppi(void);
 
 #define PLATFORM_START(_name, _namestr)                         \
 static const struct platform_desc  __plat_desc_##_name __used   \
Signature · 1 line
2.1.4
#11 lore raw

Re: [PATCH v4 4/4] xen/arm: platform: Drop the quirks callback

Quoted 1 line · Julien Grall

All the quirks has been replaced by proper detection. Lets drop the

have

Quoted 3 lines

callback and hope that no one will need new quirks.

At the same time, remove the definition platform_dom0_evtchn_ppi with is

^of which

Quoted 63 lines

not used any more.

---
Changes in v2:
- Add Ian's acked-by

---
 xen/arch/arm/platform.c        | 10 ----------
 xen/include/asm-arm/platform.h |  8 --------
 2 files changed, 18 deletions(-)
xen/arch/arm/platform.c +0 -10
index 0af6d57..b0bfaa9 100644
@@ -127,16 +127,6 @@ void platform_poweroff(void)
         platform->poweroff();
 }
 
-bool_t platform_has_quirk(uint32_t quirk)
-{
-    uint32_t quirks = 0;
-
-    if ( platform && platform->quirks )
-        quirks = platform->quirks();
-
-    return !!(quirks & quirk);
-}
-
 bool_t platform_device_is_blacklisted(const struct dt_device_node *node)
 {
     const struct dt_device_match *blacklist = NULL;
xen/include/asm renamed from xen/include/asm-arm/platform.h +0 -1
-arm/platform.h

index 5e462ac..f97315d 100644

xen/include/asm-arm/platform.h +0 -8
@@ -27,12 +27,6 @@ struct platform_desc {
     /* Platform power-off */
     void (*poweroff)(void);
     /*
-     * Platform quirks
-     * Defined has a function because a platform can support multiple
-     * board with different quirk on each
-     */
-    uint32_t (*quirks)(void);
-    /*
      * Platform blacklist devices
      * List of devices which must not pass-through to a guest
      */
@@ -48,9 +42,7 @@ int platform_cpu_up(int cpu);
 #endif
 void platform_reset(void);
 void platform_poweroff(void);
-bool_t platform_has_quirk(uint32_t quirk);
 bool_t platform_device_is_blacklisted(const struct dt_device_node
 *node);
-unsigned int platform_dom0_evtchn_ppi(void);
 
 #define PLATFORM_START(_name, _namestr)                         \

static const struct platform_desc __plat_desc_##_name __used \

#12 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

Hi all,

Only patch #3 is related to the subject of the cover letter. The rest is clean
up of code I looked while I was working on this series. Though, patch #1 is a
new bug fix I noticed between v3 and v4.

I fixed the typos I mentioned in my review and have now committed all four.