Skip to contentSkip to conversation

hw/misc/unimp: Add create_unimplemented_subregion_device()

RFC PATCH In review Philippe Mathieu-Daudé 2 participants 3 messages May 28, 2018 – May 29, 2018

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 hw/misc/unimp: Add create_unimplemented_subregion_device()

The create_unimplemented_device() function is very useful to register unimplemented devices to the SysBus 'absolute' address.

Some devices are modelled as container of memory subregions, the subregions being mmio-mapped relatively to the container base address.

With these container devices, the current create_unimplemented_device() does not work.
Add a function to remove the current limitation, and allow containerized devices to use the helpful UnimplementedDevice.

---
I don't like the function name much, I first tried with create_unimplemented_device_mr() :( Would it be cleaner renaming current create_unimplemented_device() -> create_unimplemented_sysbus_device()?

Also, is this useful to have this code inlined?

---
 include/hw/misc/unimp.h | 42 +++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)
include/hw/misc/unimp.h +36 -6
index 2a291ca42d..7ae1ace885 100644
@@ -23,9 +23,12 @@ typedef struct {
 } UnimplementedDeviceState;
 
 /**
- * create_unimplemented_device: create and map a dummy device
+ * create_unimplemented_subregion_device: create and map a dummy device
+ *
+ * @mr: the #MemoryRegion to contain the new device.
  * @name: name of the device for debug logging
- * @base: base address of the device's MMIO region
+ * @addr: base address of the device's MMIO region, or
+ *        offset relative to @mr where the device is added.
  * @size: size of the device's MMIO region
  *
  * This utility function creates and maps an instance of unimplemented-device,
@@ -35,9 +38,10 @@ typedef struct {
  * use it to cover a large region and then map other devices on top of it
  * if necessary.
  */
-static inline void create_unimplemented_device(const char *name,
-                                               hwaddr base,
-                                               hwaddr size)
+static inline void create_unimplemented_subregion_device(MemoryRegion *mr,
+                                                         const char *name,
+                                                         hwaddr addr,
+                                                         hwaddr size)
 {
     DeviceState *dev = qdev_create(NULL, TYPE_UNIMPLEMENTED_DEVICE);
 
@@ -45,7 +49,33 @@ static inline void create_unimplemented_device(const char *name,
     qdev_prop_set_uint64(dev, "size", size);
     qdev_init_nofail(dev);
 
-    sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, base, -1000);
+    if (mr) {
+        MemoryRegion *submr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+        memory_region_add_subregion_overlap(mr, addr, submr, -1000);
+    } else {
+        sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, addr, -1000);
+    }
+}
+
+/**
+ * create_unimplemented_device: create and map a dummy SysBus device
+ *
+ * @name: name of the device for debug logging
+ * @base: base address of the device's MMIO region
+ * @size: size of the device's MMIO region
+ *
+ * This utility function creates and maps an instance of unimplemented-device,
+ * which is a dummy device which simply logs all guest accesses to
+ * it via the qemu_log LOG_UNIMP debug log.
+ * The device is mapped at priority -1000, which means that you can
+ * use it to cover a large region and then map other devices on top of it
+ * if necessary.
+ */
+static inline void create_unimplemented_device(const char *name,
+                                               hwaddr base,
+                                               hwaddr size)
+{
+    create_unimplemented_subregion_device(NULL, name, base, size);
 }
 
 #endif
Signature · 1 line
2.17.0
#1 lore raw
Quoted 12 lines · Philippe Mathieu-Daudé

The create_unimplemented_device() function is very useful to register unimplemented devices to the SysBus 'absolute' address.

Some devices are modelled as container of memory subregions, the subregions being mmio-mapped relatively to the container base address.

With these container devices, the current create_unimplemented_device() does not work.
Add a function to remove the current limitation, and allow containerized devices to use the helpful UnimplementedDevice.

Quoted 7 lines

---
I don't like the function name much, I first tried with create_unimplemented_device_mr() :( Would it be cleaner renaming current create_unimplemented_device() -> create_unimplemented_sysbus_device()?

Also, is this useful to have this code inlined?

My experience has been that devices that want to map the unimplemented device into some other container probably also want to do in-place initialization rather than using qdev_create() -- eg hw/arm/iotkit.c which directly creates TYPE_UNIMPLEMENTED_DEVICEs which are embedded in its state struct.

It was always the intention that you can create a TYPE_UNIMPLEMENTED_DEVICE directly; create_unimplemented_device() is just a convenience wrapper.

I'm not opposed to having another convenience wrapper here; but I'm not sure this is the right API for one (ie if it would be used in very many places).

thanks
-- PMM

#2 lore raw
Quoted 28 lines · Peter Maydell
Quoted 12 lines · Philippe Mathieu-Daudé

The create_unimplemented_device() function is very useful to register unimplemented devices to the SysBus 'absolute' address.

Some devices are modelled as container of memory subregions, the subregions being mmio-mapped relatively to the container base address.

With these container devices, the current create_unimplemented_device() does not work.
Add a function to remove the current limitation, and allow containerized devices to use the helpful UnimplementedDevice.

Quoted 7 lines

---
I don't like the function name much, I first tried with create_unimplemented_device_mr() :( Would it be cleaner renaming current create_unimplemented_device() -> create_unimplemented_sysbus_device()?

Also, is this useful to have this code inlined?

My experience has been that devices that want to map the unimplemented device into some other container probably also want to do in-place initialization rather than using qdev_create() -- eg hw/arm/iotkit.c which directly creates TYPE_UNIMPLEMENTED_DEVICEs which are embedded in its state struct.

Quoted 3 lines

It was always the intention that you can create a TYPE_UNIMPLEMENTED_DEVICE directly; create_unimplemented_device() is just a convenience wrapper.

OK.

Quoted 3 lines

I'm not opposed to having another convenience wrapper here; but I'm not sure this is the right API for one (ie if it would be used in very many places).

Fair enough.

Thanks,

Phil.