U-Boot's shared i.MX6 identification code reads PERIPHBASE + 0x4 on
MCIMX6UL-EVK. The first private peripheral page is currently unmapped,
so that access causes a data abort before the console is ready.

The Cortex-A15 and Cortex-A7 TRMs describe errors for reserved
accesses, while the related GIC-400 TRM documents RAZ/WI. Follow
the behaviour relied on by existing U-Boot on i.MX6 boards and
log these accesses as guest errors. Keep the reserved page in the
private peripheral device.

A U-Boot fix has been posted:
<[email protected]>

Reference: GIC-400 TRM (ARM DDI 0471B), section 3.1 and 3.2
https://documentation-service.arm.com/static/5e8f15e27100066a414f7424

Signed-off-by: Bin Meng <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>


---

(no changes since v4)

Changes in v4:
- Replace the reserved-page child device with a MemoryRegion
- Log reserved reads and writes as guest errors
- Explain the RAZ/WI compatibility choice and reference the U-Boot fix

Changes in v3:
- New

 include/hw/cpu/a15mpcore.h |  1 +
 hw/cpu/a15mpcore.c         | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/hw/cpu/a15mpcore.h b/include/hw/cpu/a15mpcore.h
index 138f491c22..7b5269d626 100644
--- a/include/hw/cpu/a15mpcore.h
+++ b/include/hw/cpu/a15mpcore.h
@@ -38,6 +38,7 @@ struct A15MPPrivState {
     uint32_t num_irq;
     MemoryRegion container;
 
+    MemoryRegion reserved;
     GICState gic;
 };
 
diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
index 28cda55ccf..f0e8b276b3 100644
--- a/hw/cpu/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "qemu/log.h"
 #include "qemu/module.h"
 #include "hw/cpu/a15mpcore.h"
 #include "hw/core/cpu.h"
@@ -28,6 +29,28 @@
 #include "system/kvm.h"
 #include "target/arm/gtimer.h"
 
+static uint64_t a15mp_reserved_read(void *opaque, hwaddr offset, unsigned size)
+{
+    qemu_log_mask(LOG_GUEST_ERROR,
+                  "%s: read from reserved offset 0x%" HWADDR_PRIx "\n",
+                  __func__, offset);
+    return 0;
+}
+
+static void a15mp_reserved_write(void *opaque, hwaddr offset, uint64_t value,
+                                 unsigned size)
+{
+    qemu_log_mask(LOG_GUEST_ERROR,
+                  "%s: write to reserved offset 0x%" HWADDR_PRIx "\n",
+                  __func__, offset);
+}
+
+static const MemoryRegionOps a15mp_reserved_ops = {
+    .read = a15mp_reserved_read,
+    .write = a15mp_reserved_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 static void a15mp_priv_set_irq(void *opaque, int irq, int level)
 {
     A15MPPrivState *s = (A15MPPrivState *)opaque;
@@ -43,6 +66,8 @@ static void a15mp_priv_initfn(Object *obj)
     memory_region_init(&s->container, obj, "a15mp-priv-container", 0x8000);
     sysbus_init_mmio(sbd, &s->container);
 
+    memory_region_init_io(&s->reserved, obj, &a15mp_reserved_ops, s,
+                          "a15mp-reserved", 0x1000);
     object_initialize_child(obj, "gic", &s->gic, gic_class_name());
     qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
 }
@@ -130,7 +155,14 @@ static void a15mp_priv_realize(DeviceState *dev, Error 
**errp)
      *  0x5400-0x55ff -- GIC virtual interface control for CPU 2
      *  0x5600-0x57ff -- GIC virtual interface control for CPU 3
      *  0x6000-0x7fff -- GIC virtual CPU interface
+     *
+     * The Cortex-A15 TRM specifies a bus error for reserved accesses, and
+     * the Cortex-A7 TRM says they can abort. The GIC-400 TRM instead
+     * specifies RAZ/WI. Existing U-Boot code on i.MX6 boards relies on
+     * these accesses completing without an abort, so use RAZ/WI here
+     * for compatibility and log the invalid guest accesses.
      */
+    memory_region_add_subregion(&s->container, 0, &s->reserved);
     memory_region_add_subregion(&s->container, 0x1000,
                                 sysbus_mmio_get_region(busdev, 0));
     memory_region_add_subregion(&s->container, 0x2000,
-- 
2.53.0


Reply via email to