Commit 782dbd23fd for qemu.org

commit 782dbd23fd100ed6cbd822da092ba92fffbe38c1
Author: Jamin Lin <jamin_lin@aspeedtech.com>
Date:   Mon Oct 12 06:44:47 2026 +0000

    hw/misc/unimp: Add create_unimplemented_devices() helper

    Several boards and SoCs create many unimplemented devices. Each of them
    uses its own structure and helper to describe and map these devices.

    Add an UnimplementedDeviceConfig structure and a
    create_unimplemented_devices() helper. The helper creates an
    unimplemented device for each entry of a table, adds it as a QOM child
    of the parent object, and maps it in a memory region container with
    the given priority. The table is terminated by an empty entry.

    Suggested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
    Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Tested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Reviewed-by: Cédric Le Goater <clg@redhat.com>
    Link: https://lore.kernel.org/qemu-devel/20261012064445.2571633-2-jamin_lin@aspeedtech.com
    Signed-off-by: Cédric Le Goater <clg@redhat.com>

diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c
index 521b84bf20..4c8dcbdff3 100644
--- a/hw/misc/unimp.c
+++ b/hw/misc/unimp.c
@@ -96,3 +96,23 @@ static void unimp_register_types(void)
 }

 type_init(unimp_register_types)
+
+void create_unimplemented_devices(Object *parentobj, MemoryRegion *container,
+                                  const UnimplementedDeviceConfig *devconfigs)
+{
+    const UnimplementedDeviceConfig *cfg;
+
+    for (cfg = devconfigs; cfg->qom_name; cfg++) {
+        DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);
+        SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+
+        object_property_add_child(parentobj, cfg->qom_name, OBJECT(dev));
+        qdev_prop_set_string(dev, "name", cfg->region_name);
+        qdev_prop_set_uint64(dev, "size", cfg->size);
+        sysbus_realize_and_unref(sbd, &error_fatal);
+
+        memory_region_add_subregion_overlap(container, cfg->offset,
+                                            sysbus_mmio_get_region(sbd, 0),
+                                            cfg->priority);
+    }
+}
diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h
index 77a5077511..073575159d 100644
--- a/include/hw/misc/unimp.h
+++ b/include/hw/misc/unimp.h
@@ -25,6 +25,27 @@ struct UnimplementedDeviceState {
     uint64_t size;
 };

+typedef struct UnimplementedDeviceConfig {
+    const char *qom_name;
+    const char *region_name;
+    uint64_t offset;
+    uint64_t size;
+    int priority;
+} UnimplementedDeviceConfig;
+
+/**
+ * create_unimplemented_devices:
+ * @parentobj: the parent object
+ * @container: a #MemoryRegion within which @addr is a relative address
+ * @devconfigs: NULL terminated array of #UnimplementedDeviceConfig
+ *
+ * For each entries in @devconfigs, create a TYPE_UNIMPLEMENTED_DEVICE
+ * and mmap it in @container at UnimplementedDeviceConfig::offset.
+ * @container is expected to be a QOM child of @parentobj.
+ */
+void create_unimplemented_devices(Object *parentobj, MemoryRegion *container,
+                                  const UnimplementedDeviceConfig *devconfigs);
+
 /**
  * create_unimplemented_device: create and map a dummy device
  * @name: name of the device for debug logging