[PATCH] macio: Add unimp region for debugging

BALATON Zoltan posted 1 patch 6 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240520101007.A25A34E602E@zero.eik.bme.hu
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
hw/misc/Kconfig       | 1 +
hw/misc/macio/macio.c | 9 +++++++++
2 files changed, 10 insertions(+)
[PATCH] macio: Add unimp region for debugging
Posted by BALATON Zoltan 6 months, 1 week ago
The macio device has a container mmio region that embeds several other
devices. Some of these devices are not implemented but because of the
container region, the unassigned memory traces don't catch accesses to
these. To help debugging, add an unimplemented-device covering the
container region to get logs when the guest accesses unassigned areas.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
Here's a patch that should help getting logs for unimplemented registers
in macio with -d unimp which may help finding out where the writes go and
what needs to be implemented.

 hw/misc/Kconfig       | 1 +
 hw/misc/macio/macio.c | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index 1e08785b83..4197a786d6 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -66,6 +66,7 @@ config MACIO
     select MAC_DBDMA
     select MAC_NVRAM
     select MOS6522
+    select UNIMP
 
 config IVSHMEM_DEVICE
     bool
diff --git a/hw/misc/macio/macio.c b/hw/misc/macio/macio.c
index 3f449f91c0..43b683c294 100644
--- a/hw/misc/macio/macio.c
+++ b/hw/misc/macio/macio.c
@@ -34,6 +34,7 @@
 #include "hw/char/escc.h"
 #include "hw/misc/macio/macio.h"
 #include "hw/intc/heathrow_pic.h"
+#include "hw/misc/unimp.h"
 #include "trace.h"
 
 #define ESCC_CLOCK 3686400
@@ -94,6 +95,14 @@ static bool macio_common_realize(PCIDevice *d, Error **errp)
 {
     MacIOState *s = MACIO(d);
     SysBusDevice *sbd;
+    DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);
+
+    qdev_prop_set_string(dev, "name", "macio-unimp");
+    qdev_prop_set_uint64(dev, "size", memory_region_size(&s->bar));
+    sbd = SYS_BUS_DEVICE(dev);
+    sysbus_realize_and_unref(sbd, &error_fatal);
+    memory_region_add_subregion_overlap(&s->bar, 0,
+                                        sysbus_mmio_get_region(sbd, 0), -1000);
 
     if (!qdev_realize(DEVICE(&s->dbdma), BUS(&s->macio_bus), errp)) {
         return false;
-- 
2.30.9