* [Qemu-devel] [RFC PATCH] hw/misc/unimp: Add create_unimplemented_subregion_device()
@ 2018-05-28 6:11 Philippe Mathieu-Daudé
2018-05-29 15:08 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-05-28 6:11 UTC (permalink / raw)
To: Peter Maydell, Richard Henderson
Cc: Philippe Mathieu-Daudé, qemu-devel, Alex Bennée,
Alexey Korolev, Paolo Bonzini
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.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
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(-)
diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h
index 2a291ca42d..7ae1ace885 100644
--- a/include/hw/misc/unimp.h
+++ b/include/hw/misc/unimp.h
@@ -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
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] hw/misc/unimp: Add create_unimplemented_subregion_device()
2018-05-28 6:11 [Qemu-devel] [RFC PATCH] hw/misc/unimp: Add create_unimplemented_subregion_device() Philippe Mathieu-Daudé
@ 2018-05-29 15:08 ` Peter Maydell
2018-05-29 16:43 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2018-05-29 15:08 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Richard Henderson, QEMU Developers, Alex Bennée,
Alexey Korolev, Paolo Bonzini
On 28 May 2018 at 07:11, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> 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.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] hw/misc/unimp: Add create_unimplemented_subregion_device()
2018-05-29 15:08 ` Peter Maydell
@ 2018-05-29 16:43 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-05-29 16:43 UTC (permalink / raw)
To: Peter Maydell
Cc: Richard Henderson, QEMU Developers, Alex Bennée,
Alexey Korolev, Paolo Bonzini
On 05/29/2018 12:08 PM, Peter Maydell wrote:
> On 28 May 2018 at 07:11, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>> 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.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> 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.
OK.
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-29 16:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-28 6:11 [Qemu-devel] [RFC PATCH] hw/misc/unimp: Add create_unimplemented_subregion_device() Philippe Mathieu-Daudé
2018-05-29 15:08 ` Peter Maydell
2018-05-29 16:43 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).