Skip to contentSkip to conversation

xen/arm: Add support for Huawei hip04-d01 platform

PATCH Superseded Frediano Ziglio 3 participants 26 messages Nov 3, 2014 – Nov 4, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

This set of patches add Xen support for hip04-d01 platform (see https://wiki.linaro.org/Boards/D01 for details).

The patch "xen/arm: Move vGIC registers on Hip04 platform" is actually a workaround and should have in the future a proper implementation in Xen (unfortunately not straightforward to do it).

Changes from v1:
- style (Julien Grall);
- make gicv2_send_SGI faster (Julien Grall);
- cleanup correctly if hip04_smp_init fails (Julien Grall);
- remove quirks using compatibility (Ian Campbell);
- other minor suggestions by Julien Grall.

#1 lore raw

PATCH v2 1/7 xen/device_tree: Add new helper to read arrays from a DTB

From: Zoltan Kiss <[email protected]>

---
 xen/common/device_tree.c      | 13 ++++++++++---
 xen/include/xen/device_tree.h | 11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
xen/common/device_tree.c +10 -3
index f72b2e9..1a886c0 100644
@@ -160,14 +160,21 @@ const void *dt_get_property(const struct dt_device_node *np,
 bool_t dt_property_read_u32(const struct dt_device_node *np,
                          const char *name, u32 *out_value)
 {
-    u32 len;
+    return dt_property_read_u32_array(np, name, out_value, 1);
+}
+
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value, u16 out_len)
+{
+    u32 len, i;
     const __be32 *val;
 
     val = dt_get_property(np, name, &len);
-    if ( !val || len < sizeof(*out_value) )
+    if ( !val || len < sizeof(*out_value) * out_len )
         return 0;
 
-    *out_value = be32_to_cpup(val);
+    for ( i = 0; i < out_len; i++, val++ )
+        out_value[i] = be32_to_cpup(val);
 
     return 1;
 }
xen/include/xen/device_tree.h +11 -0
index 08db8bc..629bfb2 100644
@@ -346,6 +346,17 @@ const struct dt_property *dt_find_property(const struct dt_device_node *np,
 bool_t dt_property_read_u32(const struct dt_device_node *np,
                             const char *name, u32 *out_value);
 /**
+ * dt_property_read_u32_array - Helper to read a u32 array property.
+ * @np: node to get the value
+ * @name: name of the property
+ * @out_value: pointer to return value
+ * @out_len: length of the array
+ *
+ * Return true if get the desired value.
+ */
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value, u16 out_len);
+/**
  * dt_property_read_u64 - Helper to read a u64 property.
  * @np: node to get the value
  * @name: name of the property
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v2 1/7] xen/device_tree: Add new helper to read arrays from a DTB

Hi Frediano,

Quoted 3 lines · Frediano Ziglio

From: Zoltan Kiss <[email protected]>

You forgot to keep my reviewed-by from the last version.

Regards,

Quoted 57 lines
---
 xen/common/device_tree.c      | 13 ++++++++++---
 xen/include/xen/device_tree.h | 11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
xen/common/device_tree.c +10 -3
index f72b2e9..1a886c0 100644
@@ -160,14 +160,21 @@ const void *dt_get_property(const struct dt_device_node *np,
 bool_t dt_property_read_u32(const struct dt_device_node *np,
                          const char *name, u32 *out_value)
 {
-    u32 len;
+    return dt_property_read_u32_array(np, name, out_value, 1);
+}
+
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value, u16 out_len)
+{
+    u32 len, i;
     const __be32 *val;
 
     val = dt_get_property(np, name, &len);
-    if ( !val || len < sizeof(*out_value) )
+    if ( !val || len < sizeof(*out_value) * out_len )
         return 0;
 
-    *out_value = be32_to_cpup(val);
+    for ( i = 0; i < out_len; i++, val++ )
+        out_value[i] = be32_to_cpup(val);
 
     return 1;
 }
xen/include/xen/device_tree.h +11 -0
index 08db8bc..629bfb2 100644
@@ -346,6 +346,17 @@ const struct dt_property *dt_find_property(const struct dt_device_node *np,
 bool_t dt_property_read_u32(const struct dt_device_node *np,
                             const char *name, u32 *out_value);
 /**
+ * dt_property_read_u32_array - Helper to read a u32 array property.
+ * @np: node to get the value
+ * @name: name of the property
+ * @out_value: pointer to return value
+ * @out_len: length of the array
+ *
+ * Return true if get the desired value.
+ */
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value, u16 out_len);
+/**
  * dt_property_read_u64 - Helper to read a u64 property.
  * @np: node to get the value
  * @name: name of the property
Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH v2 1/7] xen/device_tree: Add new helper to read arrays from a DTB

Quoted 12 lines

Hi Frediano,

Quoted 3 lines · Frediano Ziglio

From: Zoltan Kiss <[email protected]>

You forgot to keep my reviewed-by from the last version.

Regards,

You sent two mails, on first you add your reviewed-by but on the next one you put some comments so I though your reviewed-by was not valid anymore

Frediano

Quoted 63 lines

xen/common/device_tree.c

Quoted 6 lines
---
 xen/common/device_tree.c      | 13 ++++++++++---
 xen/include/xen/device_tree.h | 11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
xen/common/device_tree.c +0 -0

index

Quoted 5 lines

f72b2e9..1a886c0 100644

xen/common/device_tree.c +0 -0
@@ -160,14 +160,21 @@ const void *dt_get_property(const struct

dt_device_node *np, bool_t dt_property_read_u32(const struct

dt_device_node *np,

Quoted 26 lines
                          const char *name, u32 *out_value)  {
xen/common/device_tree.c +9 -3
-    u32 len;
+    return dt_property_read_u32_array(np, name, out_value, 1); }
+
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value,
+u16 out_len) {
+    u32 len, i;
     const __be32 *val;
 
     val = dt_get_property(np, name, &len);
-    if ( !val || len < sizeof(*out_value) )
+    if ( !val || len < sizeof(*out_value) * out_len )
         return 0;
 
-    *out_value = be32_to_cpup(val);
+    for ( i = 0; i < out_len; i++, val++ )
+        out_value[i] = be32_to_cpup(val);
 
     return 1;
 }
(quoted diff) +0 -0

b/xen/include/xen/device_tree.h index 08db8bc..629bfb2 100644

xen/include/xen/device_tree.h +0 -0
@@ -346,6 +346,17 @@ const struct dt_property *dt_find_property(const
Quoted 1 line

struct dt_device_node *np, bool_t dt_property_read_u32(const struct

dt_device_node *np,

Quoted 11 lines
                             const char *name, u32 *out_value);

/**
+ * dt_property_read_u32_array - Helper to read a u32 array property.
+ * @np: node to get the value
+ * @name: name of the property
+ * @out_value: pointer to return value
+ * @out_len: length of the array
+ *
+ * Return true if get the desired value.
+ */

xen/include/xen/device_tree.h const struct dt_property *dt_find_property(const struct dt_device_node *np, · line 362

Quoted 7 lines
xen/include/xen/device_tree.h +4 -0
+bool_t dt_property_read_u32_array(const struct dt_device_node *np,
+                                  const char *name, u32 *out_value,
+u16 out_len);
+/**
  * dt_property_read_u64 - Helper to read a u64 property.
  * @np: node to get the value
  * @name: name of the property

--
Julien Grall

Reviewed-by
#4 lore raw

Re: [PATCH v2 1/7] xen/device_tree: Add new helper to read arrays from a DTB

Quoted 6 lines · Frediano Ziglio
Quoted 6 lines

Hi Frediano,

Quoted 2 lines · Frediano Ziglio

From: Zoltan Kiss <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

You forgot to keep my reviewed-by from the last version.

Regards,

You sent two mails, on first you add your reviewed-by but on the next one you put some comments so I though your reviewed-by was not valid anymore

Fair enough. I tend to keep Reviewed-by/Acked-by for minors changes such as coding style.

Anyway:

Regards,

Signature · 1 line
Julien Grall
#5 lore raw

PATCH v2 2/7 xen/arm: Implement hip04-d01 platform

In reply to Frediano Ziglio

Add this new platform to Xen.
This platform requires specific code to initialize CPUs.

---
 xen/arch/arm/platforms/Makefile |   1 +
 xen/arch/arm/platforms/hip04.c  | 308 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 309 insertions(+)
 create mode 100644 xen/arch/arm/platforms/hip04.c
xen/arch/arm/platforms/Makefile +1 -0
index 8f47c16..d0b2d99 100644
@@ -5,4 +5,5 @@ obj-$(CONFIG_ARM_32) += midway.o
 obj-$(CONFIG_ARM_32) += omap5.o
 obj-$(CONFIG_ARM_32) += sunxi.o
 obj-$(CONFIG_ARM_64) += seattle.o
+obj-$(CONFIG_ARM_32) += hip04.o
 obj-$(CONFIG_ARM_64) += xgene-storm.o
xen/arch/arm/platforms/hip04.c new file +308 -0

308 lines not on this page · raw message

Signature · 1 line
1.9.1
#6 lore raw

Re: [PATCH v2 2/7] xen/arm: Implement hip04-d01 platform

Hi Frediano,

Quoted 2 lines · Frediano Ziglio

Add this new platform to Xen.
This platform requires specific code to initialize CPUs.

I guess your platform doesn't support PSCI?

xen/arch/arm/platforms/hip04.c line 67

Quoted 9 lines

---

xen/arch/arm/platforms/hip04.c new file +6 -0
+static void hip04_reset(void)
+{
+    unsigned long data;
+
+    if ( !gb2 )
+        return;

gb2 will never be NULL. Xen will panic if the initialization callback failed.

xen/arch/arm/platforms/hip04.c line 80

Quoted 13 lines
xen/arch/arm/platforms/hip04.c new file +13 -0
+
+    data = readl_relaxed(gb2);
+    writel_relaxed(data & ~0x4000000u, gb2);
+
+    mdelay(10);
+}
+
+static void hip04_set_snoop_filter(unsigned int cluster, unsigned int on)
+{
+    unsigned long data;
+
+    if ( !fabric )
+        return;

Ditto.

[..]

xen/arch/arm/platforms/hip04.c line 149

Quoted 8 lines
xen/arch/arm/platforms/hip04.c new file +8 -0
+static void __init hip04_iounmap(void __iomem **p)
+{
+    if ( *p )
+    {
+        iounmap(*p);
+        *p = NULL;
+    }
+}

What is used for? Should not iounmap enough?

Regards,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH v2 2/7] xen/arm: Implement hip04-d01 platform

Quoted 9 lines

Hi Frediano,

Quoted 2 lines · Frediano Ziglio

Add this new platform to Xen.
This platform requires specific code to initialize CPUs.

I guess your platform doesn't support PSCI?

No, there is no PSCI support.

Quoted 22 lines

xen/arch/arm/platforms/hip04.c line 67

Quoted 9 lines

---

xen/arch/arm/platforms/hip04.c new file +6 -0
+static void hip04_reset(void)
+{
+    unsigned long data;
+
+    if ( !gb2 )
+        return;

gb2 will never be NULL. Xen will panic if the initialization callback failed.

xen/arch/arm/platforms/hip04.c

Quoted 8 lines
xen/arch/arm/platforms/hip04.c new file +8 -0
+
+    data = readl_relaxed(gb2);
+    writel_relaxed(data & ~0x4000000u, gb2);
+
+    mdelay(10);
+}
+
+static void hip04_set_snoop_filter(unsigned int cluster, unsigned

int

Quoted 8 lines

xen/arch/arm/platforms/hip04.c line 80

Quoted 5 lines
xen/arch/arm/platforms/hip04.c new file +5 -0
+on) {
+    unsigned long data;
+
+    if ( !fabric )
+        return;

Ditto.

Done

Quoted 13 lines

[..]

xen/arch/arm/platforms/hip04.c line 149

Quoted 7 lines
xen/arch/arm/platforms/hip04.c new file +7 -0
+static void __init hip04_iounmap(void __iomem **p) {
+    if ( *p )
+    {
+        iounmap(*p);
+        *p = NULL;
+    }
+}

What is used for? Should not iounmap enough?

I just like to clear pointers after freeing them.

Frediano

#8 lore raw

Re: [PATCH v2 2/7] xen/arm: Implement hip04-d01 platform

Quoted 14 lines · Frediano Ziglio
Quoted 13 lines

[..]

xen/arch/arm/platforms/hip04.c line 149

Quoted 7 lines
xen/arch/arm/platforms/hip04.c new file +7 -0
+static void __init hip04_iounmap(void __iomem **p) {
+    if ( *p )
+    {
+        iounmap(*p);
+        *p = NULL;
+    }
+}

What is used for? Should not iounmap enough?

Quoted 1 line

I just like to clear pointers after freeing them.

It's not really useful :).

If you really want to keep the *p = NULL. This could be simplify into:

hip04_iounmap(....)
{
iounmap(*p);
*p = NULL;
}

This is because iounmap takes care of NULL pointer.

Regards,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH v2 2/7] xen/arm: Implement hip04-d01 platform

Quoted 15 lines · Frediano Ziglio
Quoted 14 lines
Quoted 13 lines

[..]

xen/arch/arm/platforms/hip04.c line 149

Quoted 7 lines
xen/arch/arm/platforms/hip04.c new file +7 -0
+static void __init hip04_iounmap(void __iomem **p) {
+    if ( *p )
+    {
+        iounmap(*p);
+        *p = NULL;
+    }
+}

What is used for? Should not iounmap enough?

Quoted 4 lines
Quoted 1 line

I just like to clear pointers after freeing them.

It's not really useful :).

Just paranoia :)
Never liked dandling pointers.

Quoted 10 lines

If you really want to keep the *p = NULL. This could be simplify into:

hip04_iounmap(....)

{
   iounmap(*p);
   *p = NULL;
}

This is because iounmap takes care of NULL pointer.

Are you sure? I looked at code and is not a simple vm_free call, it does some mapping even if address is NULL.

Regards,
Frediano

#10 lore raw

Re: [PATCH v2 2/7] xen/arm: Implement hip04-d01 platform

Quoted 8 lines · Frediano Ziglio
Quoted 8 lines

If you really want to keep the *p = NULL. This could be simplify into:

hip04_iounmap(....)

{
   iounmap(*p);
   *p = NULL;
}
Quoted 4 lines
Quoted 2 lines

This is because iounmap takes care of NULL pointer.

Are you sure? I looked at code and is not a simple vm_free call, it does some mapping even if address is NULL.

Yes, vm_size(va) will return 0 and destroy_xen_mappings won't unmap anything because start == end.

I agree that an explicit check in vunmap would be nice.

Regards,

Signature · 1 line
Julien Grall
#11 lore raw

PATCH v2 3/7 xen/arm: Make gic-v2 code handle hip04-d01 platform

In reply to Frediano Ziglio

The GIC in this platform is mainly compatible with the standard GICv2 beside:
- ITARGET is extended to 16 bit to support 16 CPUs;
- SGI mask is extended to support 16 CPUs;
- maximum supported interrupt is 510.

---
 xen/arch/arm/gic-v2.c     | 89 +++++++++++++++++++++++++++++++++++++++--------
 xen/arch/arm/gic.c        |  3 +-
 xen/include/asm-arm/gic.h |  4 ++-
 3 files changed, 80 insertions(+), 16 deletions(-)
xen/arch/arm/gic-v2.c +75 -14
index faad1ff..9461fe3 100644
@@ -79,16 +79,23 @@ static struct gic_info gicv2_info;
  * logical CPU numbering. Let's use mapping as returned by the GIC
  * itself
  */
-static DEFINE_PER_CPU(u8, gic_cpu_id);
+static DEFINE_PER_CPU(u16, gic_cpu_id);
 
 /* Maximum cpu interface per GIC */
-#define NR_GIC_CPU_IF 8
+static unsigned int nr_gic_cpu_if = 8;
+static unsigned int gicd_sgi_target_shift = GICD_SGI_TARGET_SHIFT;
+static unsigned int gic_cpu_mask = 0xff;
 
 static inline void writeb_gicd(uint8_t val, unsigned int offset)
 {
     writeb_relaxed(val, gicv2.map_dbase + offset);
 }
 
+static inline void writew_gicd(uint16_t val, unsigned int offset)
+{
+    writew_relaxed(val, gicv2.map_dbase + offset);
+}
+
 static inline void writel_gicd(uint32_t val, unsigned int offset)
 {
     writel_relaxed(val, gicv2.map_dbase + offset);
@@ -132,7 +139,7 @@ static unsigned int gicv2_cpu_mask(const cpumask_t *cpumask)
     cpumask_and(&possible_mask, cpumask, &cpu_possible_map);
     for_each_cpu( cpu, &possible_mask )
     {
-        ASSERT(cpu < NR_GIC_CPU_IF);
+        ASSERT(cpu < nr_gic_cpu_if);
         mask |= per_cpu(gic_cpu_id, cpu);
     }
 
@@ -203,6 +210,15 @@ static unsigned int gicv2_read_irq(void)
     return (readl_gicc(GICC_IAR) & GICC_IA_IRQ);
 }
 
+/* Set target CPU mask (RAZ/WI on uniprocessor) */
+static void gicv2_set_irq_mask(int irq, unsigned int mask)
+{
+    if ( nr_gic_cpu_if == 16 )
+        writew_gicd(mask, GICD_ITARGETSR + irq * 2);
+    else
+        writeb_gicd(mask, GICD_ITARGETSR + irq);
+}
+
 /*
  * needs to be called with a valid cpu_mask, ie each cpu in the mask has
  * already called gic_cpu_init
@@ -230,7 +246,7 @@ static void gicv2_set_irq_properties(struct irq_desc *desc,
     writel_gicd(cfg, GICD_ICFGR + (irq / 16) * 4);
 
     /* Set target CPU mask (RAZ/WI on uniprocessor) */
-    writeb_gicd(mask, GICD_ITARGETSR + irq);
+    gicv2_set_irq_mask(irq, mask);
     /* Set priority */
     writeb_gicd(priority, GICD_IPRIORITYR + irq);
 
@@ -244,16 +260,21 @@ static void __init gicv2_dist_init(void)
     uint32_t gic_cpus;
     int i;
 
-    cpumask = readl_gicd(GICD_ITARGETSR) & 0xff;
-    cpumask |= cpumask << 8;
-    cpumask |= cpumask << 16;
+    cpumask = readl_gicd(GICD_ITARGETSR) & gic_cpu_mask;
 
     /* Disable the distributor */
     writel_gicd(0, GICD_CTLR);
 
     type = readl_gicd(GICD_TYPER);
     gicv2_info.nr_lines = 32 * ((type & GICD_TYPE_LINES) + 1);
-    gic_cpus = 1 + ((type & GICD_TYPE_CPUS) >> 5);
+    if ( nr_gic_cpu_if == 16 )
+    {
+        gic_cpus = 16;
+    }
+    else
+    {
+        gic_cpus = 1 + ((type & GICD_TYPE_CPUS) >> 5);
+    }
     printk("GICv2: %d lines, %d cpu%s%s (IID %8.8x).\n",
            gicv2_info.nr_lines, gic_cpus, (gic_cpus == 1) ? "" : "s",
            (type & GICD_TYPE_SEC) ? ", secure" : "",
@@ -264,8 +285,19 @@ static void __init gicv2_dist_init(void)
         writel_gicd(0x0, GICD_ICFGR + (i / 16) * 4);
 
     /* Route all global IRQs to this CPU */
-    for ( i = 32; i < gicv2_info.nr_lines; i += 4 )
-        writel_gicd(cpumask, GICD_ITARGETSR + (i / 4) * 4);
+    if ( nr_gic_cpu_if == 16 )
+    {
+        cpumask |= cpumask << 16;
+        for ( i = 32; i < gicv2_info.nr_lines; i += 2 )
+            writel_gicd(cpumask, GICD_ITARGETSR + (i / 2) * 4);
+    }
+    else
+    {
+        cpumask |= cpumask << 8;
+        cpumask |= cpumask << 16;
+        for ( i = 32; i < gicv2_info.nr_lines; i += 4 )
+            writel_gicd(cpumask, GICD_ITARGETSR + (i / 4) * 4);
+    }
 
     /* Default priority for global interrupts */
     for ( i = 32; i < gicv2_info.nr_lines; i += 4 )
@@ -285,7 +317,7 @@ static void __cpuinit gicv2_cpu_init(void)
 {
     int i;
 
-    this_cpu(gic_cpu_id) = readl_gicd(GICD_ITARGETSR) & 0xff;
+    this_cpu(gic_cpu_id) = readl_gicd(GICD_ITARGETSR) & gic_cpu_mask;
 
     /* The first 32 interrupts (PPI and SGI) are banked per-cpu, so
      * even though they are controlled with GICD registers, they must
@@ -366,7 +398,7 @@ static void gicv2_send_SGI(enum gic_sgi sgi, enum gic_sgi_mode irqmode,
         cpumask_and(&online_mask, cpu_mask, &cpu_online_map);
         mask = gicv2_cpu_mask(&online_mask);
         writel_gicd(GICD_SGI_TARGET_LIST |
-                    (mask << GICD_SGI_TARGET_SHIFT) | sgi,
+                    (mask << gicd_sgi_target_shift) | sgi,
                     GICD_SGIR);
         break;
     default:
@@ -581,7 +613,7 @@ static void gicv2_irq_set_affinity(struct irq_desc *desc, const cpumask_t *cpu_m
     mask = gicv2_cpu_mask(cpu_mask);
 
     /* Set target CPU mask (RAZ/WI on uniprocessor) */
-    writeb_gicd(mask, GICD_ITARGETSR + desc->irq);
+    gicv2_set_irq_mask(desc->irq, mask);
 
     spin_unlock(&gicv2.lock);
 }
@@ -684,12 +716,19 @@ const static struct gic_hw_operations gicv2_ops = {
 };
 
 /* Set up the GIC */
-static int __init gicv2_init(struct dt_device_node *node, const void *data)
+static int __init gicv2_init_common(struct dt_device_node *node, const void *data, bool hip04)
 {
     int res;
 
     dt_device_set_used_by(node, DOMID_XEN);
 
+    if ( hip04 )
+    {
+        nr_gic_cpu_if = 16;
+        gicd_sgi_target_shift = 8;
+        gic_cpu_mask = 0xffff;
+    }
+
     res = dt_device_get_address(node, 0, &gicv2.dbase, NULL);
     if ( res || !gicv2.dbase || (gicv2.dbase & ~PAGE_MASK) )
         panic("GICv2: Cannot find a valid address for the distributor");
@@ -764,6 +803,16 @@ static int __init gicv2_init(struct dt_device_node *node, const void *data)
     return 0;
 }
 
+static int __init gicv2_init(struct dt_device_node *node, const void *data)
+{
+    return gicv2_init_common(node, data, false);
+}
+
+static int __init hip04_gicv2_init(struct dt_device_node *node, const void *data)
+{
+    return gicv2_init_common(node, data, true);
+}
+
 static const char * const gicv2_dt_compat[] __initconst =
 {
     DT_COMPAT_GIC_CORTEX_A15,
@@ -777,6 +826,18 @@ DT_DEVICE_START(gicv2, "GICv2:", DEVICE_GIC)
         .init = gicv2_init,
 DT_DEVICE_END
 
+static const char * const hip04_gicv2_dt_compat[] __initconst =
+{
+    DT_COMPAT_GIC_HIP04,
+    NULL
+};
+
+DT_DEVICE_START(hip04_gicv2, "GICv2:", DEVICE_GIC)
+        .compatible = hip04_gicv2_dt_compat,
+        .init = hip04_gicv2_init,
+DT_DEVICE_END
+
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/gic.c +2 -1
index 70d10d6..8050a65 100644
@@ -563,12 +563,13 @@ static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi)
 void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)
 {
     unsigned int irq;
+    unsigned int max_irq = gic_hw_ops->info->nr_lines;
 
     do  {
         /* Reading IRQ will ACK it */
         irq = gic_hw_ops->read_irq();
 
-        if ( likely(irq >= 16 && irq < 1021) )
+        if ( likely(irq >= 16 && irq < max_irq) )
         {
             local_irq_enable();
             do_IRQ(regs, irq, is_fiq);
xen/include/asm-arm/gic.h +3 -1
index 187dc46..5adb628 100644
@@ -155,10 +155,12 @@
 #define DT_COMPAT_GIC_400            "arm,gic-400"
 #define DT_COMPAT_GIC_CORTEX_A15     "arm,cortex-a15-gic"
 #define DT_COMPAT_GIC_CORTEX_A7      "arm,cortex-a7-gic"
+#define DT_COMPAT_GIC_HIP04          "hisilicon,hip04-gic"
 
 #define DT_MATCH_GIC_V2 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A15), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A7), \
-                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_400)
+                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_400), \
+                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_HIP04)
 
 #define DT_COMPAT_GIC_V3             "arm,gic-v3"
 
Signature · 1 line
1.9.1
#12 lore raw

Re: [PATCH v2 3/7] xen/arm: Make gic-v2 code handle hip04-d01 platform

Quoted 54 lines · Frediano Ziglio

The GIC in this platform is mainly compatible with the standard GICv2 beside:
- ITARGET is extended to 16 bit to support 16 CPUs;
- SGI mask is extended to support 16 CPUs;
- maximum supported interrupt is 510.

---
 xen/arch/arm/gic-v2.c     | 89 +++++++++++++++++++++++++++++++++++++++--------
 xen/arch/arm/gic.c        |  3 +-
 xen/include/asm-arm/gic.h |  4 ++-
 3 files changed, 80 insertions(+), 16 deletions(-)
xen/arch/arm/gic-v2.c +10 -3
index faad1ff..9461fe3 100644
@@ -79,16 +79,23 @@ static struct gic_info gicv2_info;
  * logical CPU numbering. Let's use mapping as returned by the GIC
  * itself
  */
-static DEFINE_PER_CPU(u8, gic_cpu_id);
+static DEFINE_PER_CPU(u16, gic_cpu_id);
 
 /* Maximum cpu interface per GIC */
-#define NR_GIC_CPU_IF 8
+static unsigned int nr_gic_cpu_if = 8;
+static unsigned int gicd_sgi_target_shift = GICD_SGI_TARGET_SHIFT;
+static unsigned int gic_cpu_mask = 0xff;
 
 static inline void writeb_gicd(uint8_t val, unsigned int offset)
 {
     writeb_relaxed(val, gicv2.map_dbase + offset);
 }
 
+static inline void writew_gicd(uint16_t val, unsigned int offset)
+{
+    writew_relaxed(val, gicv2.map_dbase + offset);
+}
+
 static inline void writel_gicd(uint32_t val, unsigned int offset)
 {
     writel_relaxed(val, gicv2.map_dbase + offset);
@@ -132,7 +139,7 @@ static unsigned int gicv2_cpu_mask(const cpumask_t *cpumask)
     cpumask_and(&possible_mask, cpumask, &cpu_possible_map);
     for_each_cpu( cpu, &possible_mask )
     {
-        ASSERT(cpu < NR_GIC_CPU_IF);
+        ASSERT(cpu < nr_gic_cpu_if);
         mask |= per_cpu(gic_cpu_id, cpu);
     }
 

xen/arch/arm/gic-v2.c static unsigned int gicv2_read_irq(void) · line 216

Quoted 7 lines
xen/arch/arm/gic-v2.c +4 -0
@@ -203,6 +210,15 @@ static unsigned int gicv2_read_irq(void)
     return (readl_gicc(GICC_IAR) & GICC_IA_IRQ);
 }
 
+/* Set target CPU mask (RAZ/WI on uniprocessor) */
+static void gicv2_set_irq_mask(int irq, unsigned int mask)
+{
+    if ( nr_gic_cpu_if == 16 )

This check is very confusing, and even more in patch #5.

Code executed under this check describes your platform and not a generic 16-CPU support (actually there is no spec for it).

I would introduce a new boolean or hide this check in a macro.

Quoted 6 lines
xen/arch/arm/gic.c +0 -0
index 70d10d6..8050a65 100644
@@ -563,12 +563,13 @@ static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi)
 void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)

xen/arch/arm/gic.c static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) · line 572

Quoted 10 lines
xen/arch/arm/gic.c +2 -1
 {
     unsigned int irq;
+    unsigned int max_irq = gic_hw_ops->info->nr_lines;
 
     do  {
         /* Reading IRQ will ACK it */
         irq = gic_hw_ops->read_irq();
 
-        if ( likely(irq >= 16 && irq < 1021) )
+        if ( likely(irq >= 16 && irq < max_irq) )

On the previous version I've asked that need to explain in the commit message why this change is valid.

Regards,

Signature · 1 line
Julien Grall
#13 lore raw

Re: [PATCH v2 3/7] xen/arm: Make gic-v2 code handle hip04-d01 platform

Quoted 58 lines · Julien Grall
Quoted 57 lines · Frediano Ziglio

The GIC in this platform is mainly compatible with the standard GICv2 beside:
- ITARGET is extended to 16 bit to support 16 CPUs;
- SGI mask is extended to support 16 CPUs;
- maximum supported interrupt is 510.

---
 xen/arch/arm/gic-v2.c     | 89 +++++++++++++++++++++++++++++++++++++++--------
 xen/arch/arm/gic.c        |  3 +-
 xen/include/asm-arm/gic.h |  4 ++-
 3 files changed, 80 insertions(+), 16 deletions(-)
xen/arch/arm/gic-v2.c +10 -3
index faad1ff..9461fe3 100644
@@ -79,16 +79,23 @@ static struct gic_info gicv2_info;
  * logical CPU numbering. Let's use mapping as returned by the GIC
  * itself
  */
-static DEFINE_PER_CPU(u8, gic_cpu_id);
+static DEFINE_PER_CPU(u16, gic_cpu_id);
 
 /* Maximum cpu interface per GIC */
-#define NR_GIC_CPU_IF 8
+static unsigned int nr_gic_cpu_if = 8;
+static unsigned int gicd_sgi_target_shift = GICD_SGI_TARGET_SHIFT;
+static unsigned int gic_cpu_mask = 0xff;
 
 static inline void writeb_gicd(uint8_t val, unsigned int offset)
 {
     writeb_relaxed(val, gicv2.map_dbase + offset);
 }
 
+static inline void writew_gicd(uint16_t val, unsigned int offset)
+{
+    writew_relaxed(val, gicv2.map_dbase + offset);
+}
+
 static inline void writel_gicd(uint32_t val, unsigned int offset)
 {
     writel_relaxed(val, gicv2.map_dbase + offset);
@@ -132,7 +139,7 @@ static unsigned int gicv2_cpu_mask(const cpumask_t *cpumask)
     cpumask_and(&possible_mask, cpumask, &cpu_possible_map);
     for_each_cpu( cpu, &possible_mask )
     {
-        ASSERT(cpu < NR_GIC_CPU_IF);
+        ASSERT(cpu < nr_gic_cpu_if);
         mask |= per_cpu(gic_cpu_id, cpu);
     }
 
@@ -203,6 +210,15 @@ static unsigned int gicv2_read_irq(void)
     return (readl_gicc(GICC_IAR) & GICC_IA_IRQ);
 }
 
Quoted 6 lines

xen/arch/arm/gic-v2.c static unsigned int gicv2_read_irq(void) · line 216

Quoted 4 lines
xen/arch/arm/gic-v2.c +4 -0
+/* Set target CPU mask (RAZ/WI on uniprocessor) */
+static void gicv2_set_irq_mask(int irq, unsigned int mask)
+{
+    if ( nr_gic_cpu_if == 16 )

This check is very confusing, and even more in patch #5.

Sorry, I meant #7.

Quoted 27 lines

Code executed under this check describes your platform and not a generic 16-CPU support (actually there is no spec for it).

I would introduce a new boolean or hide this check in a macro.

Quoted 6 lines
xen/arch/arm/gic.c +0 -0
index 70d10d6..8050a65 100644
@@ -563,12 +563,13 @@ static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi)
 void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)

xen/arch/arm/gic.c static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) · line 572

Quoted 10 lines
xen/arch/arm/gic.c +2 -1
 {
     unsigned int irq;
+    unsigned int max_irq = gic_hw_ops->info->nr_lines;
 
     do  {
         /* Reading IRQ will ACK it */
         irq = gic_hw_ops->read_irq();
 
-        if ( likely(irq >= 16 && irq < 1021) )
+        if ( likely(irq >= 16 && irq < max_irq) )

On the previous version I've asked that need to explain in the commit message why this change is valid.

Regards,

Signature · 1 line
Julien Grall
#14 lore raw

Re: [PATCH v2 3/7] xen/arm: Make gic-v2 code handle hip04-d01 platform

In reply to Julien Grall
Quoted 59 lines · Frediano Ziglio
Quoted 10 lines

The GIC in this platform is mainly compatible with the standard GICv2 beside:
- ITARGET is extended to 16 bit to support 16 CPUs;
- SGI mask is extended to support 16 CPUs;
- maximum supported interrupt is 510.

---
 xen/arch/arm/gic-v2.c     | 89

+++++++++++++++++++++++++++++++++++++++--------

Quoted 39 lines
 xen/arch/arm/gic.c        |  3 +-
 xen/include/asm-arm/gic.h |  4 ++-
 3 files changed, 80 insertions(+), 16 deletions(-)
xen/arch/arm/gic-v2.c index renamed from xen/arch/arm/gic-v2.c +0 -0

faad1ff..9461fe3 100644

xen/arch/arm/gic-v2.c +8 -3
@@ -79,16 +79,23 @@ static struct gic_info gicv2_info;
  * logical CPU numbering. Let's use mapping as returned by the GIC
  * itself
  */
-static DEFINE_PER_CPU(u8, gic_cpu_id);
+static DEFINE_PER_CPU(u16, gic_cpu_id);
 
 /* Maximum cpu interface per GIC */
-#define NR_GIC_CPU_IF 8
+static unsigned int nr_gic_cpu_if = 8; static unsigned int
+gicd_sgi_target_shift = GICD_SGI_TARGET_SHIFT; static unsigned int
+gic_cpu_mask = 0xff;
 
 static inline void writeb_gicd(uint8_t val, unsigned int offset)  {
     writeb_relaxed(val, gicv2.map_dbase + offset);  }
 
+static inline void writew_gicd(uint16_t val, unsigned int offset) {
+    writew_relaxed(val, gicv2.map_dbase + offset); }
+
 static inline void writel_gicd(uint32_t val, unsigned int offset)  {
     writel_relaxed(val, gicv2.map_dbase + offset); @@ -132,7 +139,7
 @@ static unsigned int gicv2_cpu_mask(const cpumask_t *cpumask)
     cpumask_and(&possible_mask, cpumask, &cpu_possible_map);
     for_each_cpu( cpu, &possible_mask )
     {
-        ASSERT(cpu < NR_GIC_CPU_IF);
+        ASSERT(cpu < nr_gic_cpu_if);
         mask |= per_cpu(gic_cpu_id, cpu);
     }

xen/arch/arm/gic-v2.c static unsigned int gicv2_read_irq(void) · line 214

Quoted 5 lines
xen/arch/arm/gic-v2.c +3 -0
@@ -203,6 +210,15 @@ static unsigned int gicv2_read_irq(void)
     return (readl_gicc(GICC_IAR) & GICC_IA_IRQ);  }
 
+/* Set target CPU mask (RAZ/WI on uniprocessor) */ static void
+gicv2_set_irq_mask(int irq, unsigned int mask) {
+    if ( nr_gic_cpu_if == 16 )

This check is very confusing, and even more in patch #5.

Quoted 5 lines

Code executed under this check describes your platform and not a generic 16-CPU support (actually there is no spec for it).

I would introduce a new boolean or hide this check in a macro.

In some cases is not so terrible, as it's the only 16-bit implementation and as it's assuming ITARGETSR is 16 bit instead of 8. In other cases (like the compatible cases) I fully agree.

I agree a macro should be enough. Something like is_hip04() sounds ok?

Quoted 14 lines
Quoted 14 lines
xen/arch/arm/gic.c index renamed from xen/arch/arm/gic.c +0 -0

70d10d6..8050a65 100644

xen/arch/arm/gic.c +0 -0
@@ -563,12 +563,13 @@ static void do_sgi(struct cpu_user_regs *regs,

enum gic_sgi sgi) void gic_interrupt(struct cpu_user_regs *regs, int

is_fiq)  {
     unsigned int irq;

+ unsigned int max_irq = gic_hw_ops->info->nr_lines;

     do  {
         /* Reading IRQ will ACK it */
         irq = gic_hw_ops->read_irq();
Quoted 6 lines

xen/arch/arm/gic.c static void do_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) · line 572

Quoted 2 lines
xen/arch/arm/gic.c +1 -1
-        if ( likely(irq >= 16 && irq < 1021) )
+        if ( likely(irq >= 16 && irq < max_irq) )

On the previous version I've asked that need to explain in the commit message why this change is valid.

Regards,
Frediano

#15 lore raw

Re: [PATCH v2 3/7] xen/arm: Make gic-v2 code handle hip04-d01 platform

In reply to Frediano Ziglio
Quoted 5 lines · Frediano Ziglio

/* Set up the GIC */

xen/arch/arm/gic-v2.c +1 -1
-static int __init gicv2_init(struct dt_device_node *node, const void *data)
+static int __init gicv2_init_common(struct dt_device_node *node, const void *data, bool hip04)
 {
     int res;

xen/arch/arm/gic-v2.c const static struct gic_hw_operations gicv2_ops = { · line 731

Quoted 10 lines
xen/arch/arm/gic-v2.c +7 -0
 
     dt_device_set_used_by(node, DOMID_XEN);
 
+    if ( hip04 )
+    {
+        nr_gic_cpu_if = 16;
+        gicd_sgi_target_shift = 8;
+        gic_cpu_mask = 0xffff;
+    }
+

And this could be moved in hip04_gicv2_init. So there is no need of adding a boolean to the arguments.

Signature · 1 line
Julien Grall
#16 lore raw

PATCH v2 4/7 xen/arm: Add support for DTBs with strange names of Hip04 GICv2

In reply to Frediano Ziglio

This name can appear in some Linux kernel repos. Not very fortunate, but to avoid others spending an hour to spot that few characters difference it worth to work around it.

---
 xen/arch/arm/gic-v2.c     | 1 +
 xen/include/asm-arm/gic.h | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
xen/arch/arm/gic-v2.c +1 -0
index 9461fe3..04e1850 100644
@@ -829,6 +829,7 @@ DT_DEVICE_END
 static const char * const hip04_gicv2_dt_compat[] __initconst =
 {
     DT_COMPAT_GIC_HIP04,
+    DT_COMPAT_GIC_HIP04_2,
     NULL
 };
 
xen/include/asm-arm/gic.h +3 -1
index 5adb628..3d2b3db 100644
@@ -156,11 +156,13 @@
 #define DT_COMPAT_GIC_CORTEX_A15     "arm,cortex-a15-gic"
 #define DT_COMPAT_GIC_CORTEX_A7      "arm,cortex-a7-gic"
 #define DT_COMPAT_GIC_HIP04          "hisilicon,hip04-gic"
+#define DT_COMPAT_GIC_HIP04_2        "hisilicon,hip04-intc"
 
 #define DT_MATCH_GIC_V2 DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A15), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_CORTEX_A7), \
                         DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_400), \
-                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_HIP04)
+                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_HIP04), \
+                        DT_MATCH_COMPATIBLE(DT_COMPAT_GIC_HIP04_2)
 
 #define DT_COMPAT_GIC_V3             "arm,gic-v3"
 
Signature · 1 line
1.9.1
#17 lore raw

PATCH v2 5/7 xen/arm: handle GICH register changes for hip04-d01 platform

In reply to Frediano Ziglio

The GICH in this platform is mainly compatible with the standard GICv2 beside APR and LR register offsets.

---
 xen/arch/arm/gic-v2.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
xen/arch/arm/gic-v2.c +17 -10
index 04e1850..411b104 100644
@@ -61,6 +61,9 @@
 #define GICH_V2_VMCR_PRIORITY_MASK   0x1f
 #define GICH_V2_VMCR_PRIORITY_SHIFT  27
 
+#define HIP04_GICH_APR  0x70
+#define HIP04_GICH_LR   0x80
+
 /* Global state */
 static struct {
     paddr_t dbase;            /* Address of distributor registers */
@@ -85,6 +88,8 @@ static DEFINE_PER_CPU(u16, gic_cpu_id);
 static unsigned int nr_gic_cpu_if = 8;
 static unsigned int gicd_sgi_target_shift = GICD_SGI_TARGET_SHIFT;
 static unsigned int gic_cpu_mask = 0xff;
+static unsigned int gich_apr = GICH_APR;
+static unsigned int gich_lr = GICH_LR;
 
 static inline void writeb_gicd(uint8_t val, unsigned int offset)
 {
@@ -155,9 +160,9 @@ static void gicv2_save_state(struct vcpu *v)
      * accessed simultaneously by another pCPU.
      */
     for ( i = 0; i < gicv2_info.nr_lrs; i++ )
-        v->arch.gic.v2.lr[i] = readl_gich(GICH_LR + i * 4);
+        v->arch.gic.v2.lr[i] = readl_gich(gich_lr + i * 4);
 
-    v->arch.gic.v2.apr = readl_gich(GICH_APR);
+    v->arch.gic.v2.apr = readl_gich(gich_apr);
     v->arch.gic.v2.vmcr = readl_gich(GICH_VMCR);
     /* Disable until next VCPU scheduled */
     writel_gich(0, GICH_HCR);
@@ -168,9 +173,9 @@ static void gicv2_restore_state(const struct vcpu *v)
     int i;
 
     for ( i = 0; i < gicv2_info.nr_lrs; i++ )
-        writel_gich(v->arch.gic.v2.lr[i], GICH_LR + i * 4);
+        writel_gich(v->arch.gic.v2.lr[i], gich_lr + i * 4);
 
-    writel_gich(v->arch.gic.v2.apr, GICH_APR);
+    writel_gich(v->arch.gic.v2.apr, gich_apr);
     writel_gich(v->arch.gic.v2.vmcr, GICH_VMCR);
     writel_gich(GICH_HCR_EN, GICH_HCR);
 }
@@ -183,7 +188,7 @@ static void gicv2_dump_state(const struct vcpu *v)
     {
         for ( i = 0; i < gicv2_info.nr_lrs; i++ )
             printk("   HW_LR[%d]=%x\n", i,
-                   readl_gich(GICH_LR + i * 4));
+                   readl_gich(gich_lr + i * 4));
     }
     else
     {
@@ -437,12 +442,12 @@ static void gicv2_update_lr(int lr, const struct pending_irq *p,
                             << GICH_V2_LR_PHYSICAL_SHIFT);
     }
 
-    writel_gich(lr_reg, GICH_LR + lr * 4);
+    writel_gich(lr_reg, gich_lr + lr * 4);
 }
 
 static void gicv2_clear_lr(int lr)
 {
-    writel_gich(0, GICH_LR + lr * 4);
+    writel_gich(0, gich_lr + lr * 4);
 }
 
 static int gicv2v_setup(struct domain *d)
@@ -492,7 +497,7 @@ static void gicv2_read_lr(int lr, struct gic_lr *lr_reg)
 {
     uint32_t lrv;
 
-    lrv          = readl_gich(GICH_LR + lr * 4);
+    lrv          = readl_gich(gich_lr + lr * 4);
     lr_reg->pirq = (lrv >> GICH_V2_LR_PHYSICAL_SHIFT) & GICH_V2_LR_PHYSICAL_MASK;
     lr_reg->virq = (lrv >> GICH_V2_LR_VIRTUAL_SHIFT) & GICH_V2_LR_VIRTUAL_MASK;
     lr_reg->priority = (lrv >> GICH_V2_LR_PRIORITY_SHIFT) & GICH_V2_LR_PRIORITY_MASK;
@@ -515,7 +520,7 @@ static void gicv2_write_lr(int lr, const struct gic_lr *lr_reg)
                                        << GICH_V2_LR_HW_SHIFT)  |
           ((uint32_t)(lr_reg->grp & GICH_V2_LR_GRP_MASK) << GICH_V2_LR_GRP_SHIFT) );
 
-    writel_gich(lrv, GICH_LR + lr * 4);
+    writel_gich(lrv, gich_lr + lr * 4);
 }
 
 static void gicv2_hcr_status(uint32_t flag, bool_t status)
@@ -538,7 +543,7 @@ static unsigned int gicv2_read_vmcr_priority(void)
 
 static unsigned int gicv2_read_apr(int apr_reg)
 {
-   return readl_gich(GICH_APR);
+   return readl_gich(gich_apr);
 }
 
 static void gicv2_irq_enable(struct irq_desc *desc)
@@ -727,6 +732,8 @@ static int __init gicv2_init_common(struct dt_device_node *node, const void *dat
         nr_gic_cpu_if = 16;
         gicd_sgi_target_shift = 8;
         gic_cpu_mask = 0xffff;
+        gich_apr = HIP04_GICH_APR;
+        gich_lr = HIP04_GICH_LR;
     }
 
     res = dt_device_get_address(node, 0, &gicv2.dbase, NULL);
Signature · 1 line
1.9.1
#18 lore raw

PATCH v2 6/7 xen/arm: Force domains to use normal GICv2 driver on Hip04 platform

In reply to Frediano Ziglio

Until vGIC support is not implemented and tested, this will prevent guest kernels to use their Hip04 driver, or crash when they don't have any.

---
 xen/arch/arm/gic-v2.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/gic-v2.c +6 -0
index 411b104..cea9edc 100644
@@ -639,6 +639,12 @@ static int gicv2_make_dt_node(const struct domain *d,
         return -FDT_ERR_XEN(ENOENT);
     }
 
+    if ( nr_gic_cpu_if == 16 )
+    {
+        compatible = DT_COMPAT_GIC_CORTEX_A15;
+        len = strlen((char*) compatible) + 1;
+    }
+
     res = fdt_begin_node(fdt, "interrupt-controller");
     if ( res )
         return res;
Signature · 1 line
1.9.1
#19 lore raw

Re: [PATCH v2 6/7] xen/arm: Force domains to use normal GICv2 driver on Hip04 platform

Hi Frediano,

FYI, this is only force DOM0 to use the normal GICv2 drivers. I.e the title of this patch is wrong.

Do you have any plan to support hi-silicon vGIC in Xen? This would allow guest running with more than 8 cores.

Regards,

Quoted 27 lines · Frediano Ziglio

Until vGIC support is not implemented and tested, this will prevent guest kernels to use their Hip04 driver, or crash when they don't have any.

---
 xen/arch/arm/gic-v2.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/gic-v2.c +6 -0
index 411b104..cea9edc 100644
@@ -639,6 +639,12 @@ static int gicv2_make_dt_node(const struct domain *d,
         return -FDT_ERR_XEN(ENOENT);
     }
 
+    if ( nr_gic_cpu_if == 16 )
+    {
+        compatible = DT_COMPAT_GIC_CORTEX_A15;
+        len = strlen((char*) compatible) + 1;
+    }
+
     res = fdt_begin_node(fdt, "interrupt-controller");
     if ( res )
         return res;
Signature · 1 line
Julien Grall
#20 lore raw

Re: [PATCH v2 6/7] xen/arm: Force domains to use normal GICv2 driver on Hip04 platform

Quoted 11 lines

Hi Frediano,

FYI, this is only force DOM0 to use the normal GICv2 drivers. I.e the title of this patch is wrong.

Do you have any plan to support hi-silicon vGIC in Xen? This would allow guest running with more than 8 cores.

Regards,

Actually there's no plan to do it.

Frediano

Quoted 34 lines · Frediano Ziglio
Quoted 2 lines

Until vGIC support is not implemented and tested, this will prevent guest kernels to use their Hip04 driver, or crash when they don't

have

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct

Quoted 12 lines

any.

---
 xen/arch/arm/gic-v2.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/arm/gic-v2.c index renamed from xen/arch/arm/gic-v2.c +0 -0

411b104..cea9edc 100644

xen/arch/arm/gic-v2.c +0 -0
@@ -639,6 +639,12 @@ static int gicv2_make_dt_node(const struct

domain *d,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 650

Quoted 13 lines
xen/arch/arm/gic-v2.c +6 -0
         return -FDT_ERR_XEN(ENOENT);
     }
 
+    if ( nr_gic_cpu_if == 16 )
+    {
+        compatible = DT_COMPAT_GIC_CORTEX_A15;
+        len = strlen((char*) compatible) + 1;
+    }
+
     res = fdt_begin_node(fdt, "interrupt-controller");
     if ( res )
         return res;

--
Julien Grall

#21 lore raw

PATCH v2 7/7 xen/arm: Move vGIC registers on Hip04 platform

In reply to Frediano Ziglio
---
 xen/arch/arm/gic-v2.c     | 15 +++++++++++++--
 xen/include/asm-arm/gic.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v2.c +13 -2
index cea9edc..eb8cc19 100644
@@ -669,8 +669,19 @@ static int gicv2_make_dt_node(const struct domain *d,
         return -FDT_ERR_XEN(ENOMEM);
 
     tmp = new_cells;
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+
+    if ( nr_gic_cpu_if == 16 )
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase - HIP04_VGIC_REG_OFFSET,
+                     PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase - HIP04_VGIC_REG_OFFSET,
+                     PAGE_SIZE * 2);
+    }
+    else
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+    }
 
     res = fdt_property(fdt, "reg", new_cells, len);
     xfree(new_cells);
xen/include/asm-arm/gic.h +2 -0
index 3d2b3db..5af8201 100644
@@ -147,6 +147,8 @@
 #define GICH_LR_PENDING         1
 #define GICH_LR_ACTIVE          2
 
+#define HIP04_VGIC_REG_OFFSET   0xe0000000
+
 #ifndef __ASSEMBLY__
 #include <xen/device_tree.h>
 #include <xen/irq.h>
Signature · 1 line
1.9.1
#22 lore raw

Re: [PATCH v2 7/7] xen/arm: Move vGIC registers on Hip04 platform

Hi Frediano,

Quoted 38 lines · Frediano Ziglio
---
 xen/arch/arm/gic-v2.c     | 15 +++++++++++++--
 xen/include/asm-arm/gic.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v2.c +13 -2
index cea9edc..eb8cc19 100644
@@ -669,8 +669,19 @@ static int gicv2_make_dt_node(const struct domain *d,
         return -FDT_ERR_XEN(ENOMEM);
 
     tmp = new_cells;
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+
+    if ( nr_gic_cpu_if == 16 )
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase - HIP04_VGIC_REG_OFFSET,
+                     PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase - HIP04_VGIC_REG_OFFSET,
+                     PAGE_SIZE * 2);
+    }
+    else
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+    }
 
     res = fdt_property(fdt, "reg", new_cells, len);
     xfree(new_cells);
xen/include/asm-arm/gic.h +0 -0
index 3d2b3db..5af8201 100644

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

Quoted 5 lines
xen/include/asm-arm/gic.h +2 -0
@@ -147,6 +147,8 @@
 #define GICH_LR_PENDING         1
 #define GICH_LR_ACTIVE          2
 
+#define HIP04_VGIC_REG_OFFSET   0xe0000000
+

Please move this define in gic-v2.c. The header gic.h should only contains value that needs to be shared with the vgic and/or the other GIC drivers.

Also, where does come from the offset? Any pointer to the documentation?

Regards,

Signature · 1 line
Julien Grall
#23 lore raw

Re: [PATCH v2 7/7] xen/arm: Move vGIC registers on Hip04 platform

Quoted 48 lines

Hi Frediano,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct

Quoted 12 lines · Frediano Ziglio
---
 xen/arch/arm/gic-v2.c     | 15 +++++++++++++--
 xen/include/asm-arm/gic.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v2.c index renamed from xen/arch/arm/gic-v2.c +0 -0

cea9edc..eb8cc19 100644

xen/arch/arm/gic-v2.c +0 -0
@@ -669,8 +669,19 @@ static int gicv2_make_dt_node(const struct

domain *d,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d,

Quoted 9 lines
xen/arch/arm/gic-v2.c +4 -2
         return -FDT_ERR_XEN(ENOMEM);
 
     tmp = new_cells;
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+
+    if ( nr_gic_cpu_if == 16 )
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase -

HIP04_VGIC_REG_OFFSET,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct · line 677

Quoted 2 lines
xen/arch/arm/gic-v2.c +2 -0
+                     PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase -

HIP04_VGIC_REG_OFFSET,

Quoted 18 lines
xen/arch/arm/gic-v2.c +7 -0
+                     PAGE_SIZE * 2);
+    }
+    else
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+    }
 
     res = fdt_property(fdt, "reg", new_cells, len);
     xfree(new_cells);
xen/include/asm-arm/gic.h +0 -0
index 3d2b3db..5af8201 100644
@@ -147,6 +147,8 @@
 #define GICH_LR_PENDING         1
 #define GICH_LR_ACTIVE          2
 
Quoted 9 lines

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

Quoted 2 lines
xen/include/asm-arm/gic.h +2 -0
+#define HIP04_VGIC_REG_OFFSET   0xe0000000
+

Please move this define in gic-v2.c. The header gic.h should only contains value that needs to be shared with the vgic and/or the other GIC drivers.

Also, where does come from the offset? Any pointer to the documentation?

Well,
I think I already sent a mail for this problem but got no reply (or I missed it).

The problem came from how the DTB is in Linux and how Xen override devices in the DTB.

On Linux I have

/ {
...

       soc {
                /* It's a 32-bit SoC. */
                #address-cells = <1>;
                #size-cells = <1>;
                compatible = "simple-bus";
                interrupt-parent = <&gic>;
                ranges = <0 0 0xe0000000 0x10000000>;

                gic: interrupt-controller@c01000 {
                        compatible = "hisilicon,hip04-intc";
                        #interrupt-cells = <3>;
                        #address-cells = <0>;
                        interrupt-controller;
                        interrupts = <1 9 0xf04>;

                        reg = <0xc01000 0x1000>, <0xc02000 0x1000>,
                              <0xc04000 0x2000>, <0xc06000 0x2000>;
                };

...

So the address of controller is 0xec01000 (see ranges in /soc and reg in /soc/interrupt-controller@c01000).

Now Xen compute address as 0xec01000 (which is fine) but then when it has to provide a virtual gic it just replace the gic entry with one with reg with 0xec01000 not taking into account the range is putting the reg into. This lead kernel to think the address is 0xe0000000+0xec01000 instead of 0xe00000000+0xc01000. Now... the DTB from Linux is perfectly legal but Xen does not handle it properly. I mostly consider this as a temporary workaround (I wrote a small comment on first version).

About solution to this there are different options:
- put gic always in the root to to have full range without any offset;
- fix reg according to range. This however could lead to extend the range;
- remove all ranges (and fix all devices' reg) to have always no offsets.

Regards,
Frediano

#24 lore raw

Re: [PATCH v2 7/7] xen/arm: Move vGIC registers on Hip04 platform

Quoted 87 lines · Frediano Ziglio
Quoted 48 lines

Hi Frediano,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct

Quoted 12 lines · Frediano Ziglio
---
 xen/arch/arm/gic-v2.c     | 15 +++++++++++++--
 xen/include/asm-arm/gic.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v2.c index renamed from xen/arch/arm/gic-v2.c +0 -0

cea9edc..eb8cc19 100644

xen/arch/arm/gic-v2.c +0 -0
@@ -669,8 +669,19 @@ static int gicv2_make_dt_node(const struct

domain *d,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d,

Quoted 9 lines
xen/arch/arm/gic-v2.c +4 -2
         return -FDT_ERR_XEN(ENOMEM);
 
     tmp = new_cells;
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+
+    if ( nr_gic_cpu_if == 16 )
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase -

HIP04_VGIC_REG_OFFSET,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct · line 677

Quoted 2 lines
xen/arch/arm/gic-v2.c +2 -0
+                     PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase -

HIP04_VGIC_REG_OFFSET,

Quoted 18 lines
xen/arch/arm/gic-v2.c +7 -0
+                     PAGE_SIZE * 2);
+    }
+    else
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+    }
 
     res = fdt_property(fdt, "reg", new_cells, len);
     xfree(new_cells);
xen/include/asm-arm/gic.h +0 -0
index 3d2b3db..5af8201 100644
@@ -147,6 +147,8 @@
 #define GICH_LR_PENDING         1
 #define GICH_LR_ACTIVE          2
 
Quoted 9 lines

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

Quoted 2 lines
xen/include/asm-arm/gic.h +2 -0
+#define HIP04_VGIC_REG_OFFSET   0xe0000000
+

Please move this define in gic-v2.c. The header gic.h should only contains value that needs to be shared with the vgic and/or the other GIC drivers.

Also, where does come from the offset? Any pointer to the documentation?

Well,
I think I already sent a mail for this problem but got no reply (or I missed it).

The problem came from how the DTB is in Linux and how Xen override devices in the DTB.

On Linux I have

/ {
...

       soc {
                /* It's a 32-bit SoC. */
                #address-cells = <1>;
                #size-cells = <1>;
                compatible = "simple-bus";
                interrupt-parent = <&gic>;
                ranges = <0 0 0xe0000000 0x10000000>;

                gic: interrupt-controller@c01000 {
                        compatible = "hisilicon,hip04-intc";
                        #interrupt-cells = <3>;
                        #address-cells = <0>;
                        interrupt-controller;
                        interrupts = <1 9 0xf04>;

                        reg = <0xc01000 0x1000>, <0xc02000 0x1000>,
                              <0xc04000 0x2000>, <0xc06000 0x2000>;
                };

...

Quoted 8 lines

So the address of controller is 0xec01000 (see ranges in /soc and reg in /soc/interrupt-controller@c01000).

Now Xen compute address as 0xec01000 (which is fine) but then when it has to provide a virtual gic it just replace the gic entry with one with reg with 0xec01000 not taking into account the range is putting the reg into. This lead kernel to think the address is 0xe0000000+0xec01000 instead of 0xe00000000+0xc01000. Now... the DTB from Linux is perfectly legal but Xen does not handle it properly. I mostly consider this as a temporary workaround (I wrote a small comment on first version).

About solution to this there are different options:
- put gic always in the root to to have full range without any offset;
- fix reg according to range. This however could lead to extend the range;
- remove all ranges (and fix all devices' reg) to have always no offsets.

- Propagate the host GICC register value literally over, having mapping the GICV there. i.e. don't translate the value which is written to the DT.

None of the other options sound very good to me.

Ian.

#25 lore raw

Re: [PATCH v2 7/7] xen/arm: Move vGIC registers on Hip04 platform

Quoted 112 lines · Frediano Ziglio
Quoted 29 lines
Quoted 29 lines

Hi Frediano,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct

Quoted 12 lines · Frediano Ziglio
---
 xen/arch/arm/gic-v2.c     | 15 +++++++++++++--
 xen/include/asm-arm/gic.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v2.c index renamed from xen/arch/arm/gic-v2.c +0 -0

cea9edc..eb8cc19 100644

xen/arch/arm/gic-v2.c +0 -0
@@ -669,8 +669,19 @@ static int gicv2_make_dt_node(const struct

domain *d,

xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d,

Quoted 9 lines
xen/arch/arm/gic-v2.c +4 -2
         return -FDT_ERR_XEN(ENOMEM);
 
     tmp = new_cells;
-    dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
-    dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE * 2);
+
+    if ( nr_gic_cpu_if == 16 )
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase -

HIP04_VGIC_REG_OFFSET,

Quoted 2 lines
xen/arch/arm/gic-v2.c +2 -0
+                     PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase -
Quoted 7 lines
Quoted 7 lines

HIP04_VGIC_REG_OFFSET,

Quoted 6 lines
xen/arch/arm/gic-v2.c +6 -0
+                     PAGE_SIZE * 2);
+    }
+    else
+    {
+        dt_set_range(&tmp, node, d->arch.vgic.dbase, PAGE_SIZE);
+        dt_set_range(&tmp, node, d->arch.vgic.cbase, PAGE_SIZE *

2);

Quoted 5 lines
Quoted 5 lines

xen/include/asm-

Quoted 5 lines
xen/arch/arm/gic-v2.c +1 -0
+    }
 
     res = fdt_property(fdt, "reg", new_cells, len);
     xfree(new_cells);
xen/include/asm- renamed from xen/include/asm-arm/gic.h +0 -0

arm/gic.h

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

index 3d2b3db..5af8201 100644

xen/include/asm-arm/gic.h +0 -0
@@ -147,6 +147,8 @@
 #define GICH_LR_PENDING         1
 #define GICH_LR_ACTIVE          2
 
Quoted 8 lines
Quoted 8 lines

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

Quoted 2 lines
xen/include/asm-arm/gic.h +2 -0
+#define HIP04_VGIC_REG_OFFSET   0xe0000000
+

Please move this define in gic-v2.c. The header gic.h should only contains value that needs to be shared with the vgic and/or the other GIC drivers.

Also, where does come from the offset? Any pointer to the

documentation?

Quoted 4 lines
Quoted 1 line

Well,
I think I already sent a mail for this problem but got no reply (or

I missed it).

Quoted 2 lines

The problem came from how the DTB is in Linux and how Xen override

devices in the DTB.

Quoted 23 lines

On Linux I have

/ {
...

       soc {
                /* It's a 32-bit SoC. */
                #address-cells = <1>;
                #size-cells = <1>;
                compatible = "simple-bus";
                interrupt-parent = <&gic>;
                ranges = <0 0 0xe0000000 0x10000000>;

                gic: interrupt-controller@c01000 {
                        compatible = "hisilicon,hip04-intc";
                        #interrupt-cells = <3>;
                        #address-cells = <0>;
                        interrupt-controller;
                        interrupts = <1 9 0xf04>;

                        reg = <0xc01000 0x1000>, <0xc02000 0x1000>,
                              <0xc04000 0x2000>, <0xc06000 0x2000>;
                };
Quoted 3 lines

...

So the address of controller is 0xec01000 (see ranges in /soc and reg

in /soc/interrupt-controller@c01000).

Quoted 2 lines

Now Xen compute address as 0xec01000 (which is fine) but then when it

has to provide a virtual gic it just replace the gic entry with one with reg with 0xec01000 not taking into account the range is putting the reg into. This lead kernel to think the address is 0xe0000000+0xec01000 instead of 0xe00000000+0xc01000. Now... the DTB from Linux is perfectly legal but Xen does not handle it properly. I mostly consider this as a temporary workaround (I wrote a small comment on first version).

Quoted 6 lines

About solution to this there are different options:
- put gic always in the root to to have full range without any offset;
- fix reg according to range. This however could lead to extend the range;
- remove all ranges (and fix all devices' reg) to have always no

offsets.

Quoted 7 lines

- Propagate the host GICC register value literally over, having mapping the GICV there. i.e. don't translate the value which is written to the DT.

None of the other options sound very good to me.

Ian.

Yes,
You are right, KISS rule apply!

Implemented and working correctly.

Regards,
Frediano