Skip to contentSkip to conversation

xen/arm: Add support for Broadcom 7445D0 A15 platform.

PATCH Superseded Jon Fraser 2 participants 2 messages Sep 30, 2014 – Oct 1, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jon Fraser

author
#0 lore raw

PATCH 3/3 xen/arm: Add support for Broadcom 7445D0 A15 platform.

This code supports the Broadcom 7445D0 32-bit A15 based platform.

---
 xen/arch/arm/platforms/Makefile |   1 +
 xen/arch/arm/platforms/brcm.c   | 326 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 327 insertions(+)
 create mode 100644 xen/arch/arm/platforms/brcm.c
xen/arch/arm/platforms/Makefile +1 -0
index 680364f..3b92dde 100644
@@ -1,4 +1,5 @@
 obj-y += vexpress.o
+obj-$(CONFIG_ARM_32) += brcm.o
 obj-$(CONFIG_ARM_32) += exynos5.o
 obj-$(CONFIG_ARM_32) += midway.o
 obj-$(CONFIG_ARM_32) += omap5.o
xen/arch/arm/platforms/brcm.c new file +326 -0

326 lines not on this page · raw message

Signature · 1 line
1.9.0.138.g2de3478
#1 lore raw

Hello Jon,

xen/arch/arm/platforms/brcm.c line 41

Quoted 8 lines · Jon Fraser
xen/arch/arm/platforms/brcm.c new file +8 -0
+static u32 brcm_boot_continuation_pc;
+
+static struct brcm_plat_regs regs;
+
+static int brcm_get_dt_node(char *compat_str, struct dt_device_node **dn,
+                             u32 *reg_base)
+{
+    struct dt_device_node *node;

You don't modify the node so:

const struct dt_device_node *node;

xen/arch/arm/platforms/brcm.c line 53

Quoted 12 lines
xen/arch/arm/platforms/brcm.c new file +12 -0
+    u64 reg_base_64;
+    u64 size;
+    int rc;
+
+    node = dt_find_compatible_node(NULL, NULL, compat_str);
+    if ( !node )
+    {
+        dprintk(XENLOG_ERR, "%s: missing \"%s\" node\n", __func__, compat_str);
+        return -ENOENT;
+    }
+
+    rc = dt_device_get_address(node, 0, &reg_base_64, &size);

You can pass NULL instead of &size as you don't use the variable within the function and dt_device_get_address is able to cope with NULL.

xen/arch/arm/platforms/brcm.c line 64

Quoted 11 lines
xen/arch/arm/platforms/brcm.c new file +11 -0
+    if ( rc )
+    {
+        dprintk(XENLOG_ERR, "%s: missing \"reg\" prop\n", __func__);
+        return rc;
+    }
+
+    if ( dn )
+        *dn = node;
+
+    if ( reg_base )
+        *reg_base = (u32)(reg_base_64 & 0xffffffff);

I don't think the cast is useful here.

xen/arch/arm/platforms/brcm.c line 72

Quoted 8 lines
xen/arch/arm/platforms/brcm.c new file +8 -0
+
+    return 0;
+}
+
+static int brcm_populate_plat_regs(void)
+{
+    int rc, failed;
+    struct dt_device_node *node;

const struct dt_device_node *node;

Quoted 6 lines
xen/arch/arm/platforms/brcm.c new file +6 -0
+    u32 reg_base;
+    u32 val;
+
+    rc = brcm_get_dt_node("brcm,brcmstb-cpu-biu-ctrl", &node, &reg_base);
+    if ( rc )
+        return rc;

xen/arch/arm/platforms/brcm.c line 88

Quoted 10 lines
xen/arch/arm/platforms/brcm.c new file +10 -0
+
+    failed = 0;
+
+    if ( dt_property_read_u32(node, "cpu-reset-config-reg", &val) )
+        regs.hif_cpu_reset_config = reg_base + val;
+    else
+    {
+        dprintk(XENLOG_ERR, "Missing property \"cpu-reset-config-reg\"\n");
+        failed = 1;
+    }

I would invert the way to do it:

if ( !dt_property_read_u32(...) )
{
dprintk(XENLOG_ERR, ...);
goto err; /* Or return -ENOENT */
}

regs.hif_cpu_reset_config = reg_base + val;

It's easier to read as we know this is an error case and we don't need to continue checking the other properties.

xen/arch/arm/platforms/brcm.c line 96

Quoted 8 lines
xen/arch/arm/platforms/brcm.c new file +8 -0
+
+    if ( dt_property_read_u32(node, "cpu0-pwr-zone-ctrl-reg", &val) )
+        regs.cpu0_pwr_zone_ctrl = reg_base + val;
+    else
+    {
+        dprintk(XENLOG_ERR, "Missing property \"cpu0-pwr-zone-ctrl-reg\"\n");
+        failed = 1;
+    }

ditto

xen/arch/arm/platforms/brcm.c line 104

Quoted 7 lines
xen/arch/arm/platforms/brcm.c new file +7 -0
+    if ( dt_property_read_u32(node, "scratch-reg", &val) )
+        regs.scratch_reg = reg_base + val;
+    else
+    {
+        dprintk(XENLOG_ERR, "Missing property \"scratch-reg\"\n");
+        failed = 1;
+    }

ditto

Quoted 1 line

+ rc = brcm_get_dt_node("brcm,brcmstb-hif-continuation", &node, &reg_base);

You doesn't seem to use the variable "node" within the function. I would either drop the argument in brcm_get_dt_node or pass NULL.

Quoted 20 lines
xen/arch/arm/platforms/brcm.c new file +20 -0
+    if ( rc )
+        return rc;
+
+    regs.hif_boot_continuation = reg_base;
+
+    if ( failed )
+        return -ENOENT;
+
+    dprintk(XENLOG_INFO, "hif_cpu_reset_config  : %08xh\n",
+                    regs.hif_cpu_reset_config);
+    dprintk(XENLOG_INFO, "cpu0_pwr_zone_ctrl    : %08xh\n",
+                    regs.cpu0_pwr_zone_ctrl);
+    dprintk(XENLOG_INFO, "hif_boot_continuation : %08xh\n",
+                    regs.hif_boot_continuation);
+    dprintk(XENLOG_INFO, "scratch_reg : %08xh\n",
+                    regs.scratch_reg);
+
+    return 0;
+}
+

xen/arch/arm/platforms/brcm.c line 136

Quoted 10 lines
xen/arch/arm/platforms/brcm.c new file +10 -0
+#define ZONE_PWR_UP_REQ   (1 << 10)
+#define ZONE_PWR_ON_STATE (1 << 26)
+
+static int brcm_cpu_power_on(int cpu)
+{
+    u32 tmp;
+    void __iomem *va, *pwr_ctl;
+    unsigned int timeout;
+
+    ASSERT ( cpu < NR_CPUS );

This ASSERT is not useful, cpu will always be < NR_CPUS and we already have a check earlier (see smp_init_cpus).

xen/arch/arm/platforms/brcm.c line 139

Quoted 3 lines
xen/arch/arm/platforms/brcm.c new file +3 -0
+    dprintk(XENLOG_ERR, "%s: Power on cpu %d\n", __func__, cpu);
+
+    va = ioremap_nocache(regs.cpu0_pwr_zone_ctrl, NR_CPUS * sizeof(u32));

Using NR_CPUS is buggy here, the value could be very big as Xen is compiled for multiple platform. Don't you need to map only 1 CPUs?

You could do smth like:

ioremap_nocache(regs.cpu0_ ... + (cpu * sizeof(u32)), sizeof(u32));

xen/arch/arm/platforms/brcm.c line 148

Quoted 9 lines
xen/arch/arm/platforms/brcm.c new file +9 -0
+
+    if ( !va )
+    {
+        dprintk(XENLOG_ERR, "%s: Unable to map \"cpu0_pwr_zone_ctrl\"\n",
+                        __func__);
+        return -EFAULT;
+    }
+
+    pwr_ctl = va + (cpu * sizeof(u32) );

spurious white space before the closing brace.

Quoted 10 lines
xen/arch/arm/platforms/brcm.c new file +10 -0
+
+    /* request core power on */
+    tmp = readl(pwr_ctl);
+    tmp |= ZONE_PWR_UP_REQ;
+    writel(tmp, pwr_ctl);
+
+    /*
+     * Wait for the cpu to power on.
+     * Wait a max of 10 msec.
+     */

xen/arch/arm/platforms/brcm.c line 168

Quoted 10 lines
xen/arch/arm/platforms/brcm.c new file +10 -0
+    timeout = 10;
+    tmp = readl(pwr_ctl);
+
+    while ( !(tmp & ZONE_PWR_ON_STATE) )
+    {
+        if ( timeout-- == 0 )
+            break;
+
+        mdelay(1);
+    }

Hmmm, you read the value once before the loop and you never read again. Didn't you forget the readl in the loop?

[..]

xen/arch/arm/platforms/brcm.c line 211

Quoted 6 lines
xen/arch/arm/platforms/brcm.c new file +6 -0
+static int brcm_set_boot_continuation(u32 cpu, u32 pc)
+{
+    u32 __iomem *reg, index;
+    dprintk(XENLOG_INFO, "%s: cpu %d pc 0x%x\n", __func__, cpu, pc);
+
+    ASSERT (cpu < NR_CPUS);

ditto for the ASSERT.

xen/arch/arm/platforms/brcm.c line 214

Quoted 3 lines
xen/arch/arm/platforms/brcm.c new file +3 -0
+
+    reg = ioremap_nocache(regs.hif_boot_continuation,
+                          NR_CPUS * 2 * sizeof(u32));

dittor for NR_CPUS.

xen/arch/arm/platforms/brcm.c line 222

Quoted 8 lines
xen/arch/arm/platforms/brcm.c new file +8 -0
+    if ( !reg )
+    {
+        dprintk(XENLOG_ERR, "%s: Unable to map \"hif_boot_continuation\"\n",
+                __func__);
+        return -EFAULT;
+    }
+
+    index = cpu * 2;

Did you miss a * sizeof(u32) here?

xen/arch/arm/platforms/brcm.c line 234

Quoted 11 lines
xen/arch/arm/platforms/brcm.c new file +11 -0
+    writel(0, reg + index);
+    writel(pc, reg + index + 1);
+
+    iounmap(reg);
+
+    return 0;
+}
+
+static int brcm_cpu_up(int cpu)
+{
+    u32  rc;

int rc;

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    ASSERT (cpu < NR_CPUS);

ditto for the ASSERT.

Quoted 2 lines
(quoted diff) +2 -0
+static int __init brcm_smp_init(void)
+{

[..]

xen/arch/arm/platforms/brcm.c line 279

Quoted 2 lines
xen/arch/arm/platforms/brcm.c new file +2 -0
+    dprintk(XENLOG_INFO, "%s: target_pc 0x%x boot continuation pc 0x%x\n",
+        __func__, target_pc, brcm_boot_continuation_pc);

NIT: The second line is not correctly aligned.

xen/arch/arm/platforms/brcm.c line 284

Quoted 5 lines
xen/arch/arm/platforms/brcm.c new file +5 -0
+
+    return 0;
+}
+
+static int brcm_init(void)

This callback is only used during Xen initialization so:

static __init ...

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+    return brcm_populate_plat_regs();

I guess this would be the same for brcm_populate_plat_regs?

Quoted 15 lines
xen/arch/arm/platforms/brcm.c new file +15 -0
+}
+
+static int brcm_specific_mapping(struct domain *d)
+{
+    return 0;
+}
+
+static void brcm_reset(void)
+{
+}
+
+static uint32_t brcm_quirks(void)
+{
+    return 0;
+}

[..]

Quoted 1 line

+PLATFORM_START(brcm, "Broadcom B15")

[..]

xen/arch/arm/platforms/brcm.c line 316

Quoted 3 lines
xen/arch/arm/platforms/brcm.c new file +3 -0
+    .quirks         = brcm_quirks,
+    .reset          = brcm_reset,
+    .specific_mapping    = brcm_specific_mapping,

Those functions don't contain code. You can remove them for the platform description.

Quoted 1 line

+PLATFORM_END

Regards,

Signature · 1 line
Julien Grall