Sysbus device generic QAPI plug support
v5 cover Sysbus device generic QAPI plug support
Hi all,
This series is about enabling to plug sysbus devices with device_add QAPI command. I've put RFC because, there are several options and I would like to know if you think the current version is ok to be added in qemu.
Right now only a few sysbus device can be plugged using "-device" CLI option and a custom plugging mechanism. A machine defines a list of allowed/supported sysbus devices and provides some code to handle the plug. For example, it sets up the memory map and irq connections.
In order to configure a machine from scratch with qapi, we want to cold plug sysbus devices to the _none_ machine with qapi commands without requiring the machine to provide some specific per-device support.
There are mostly 2 options (option 1 is in these patches). Note that in any case this only applies to "user-creatable" device.
+ Option 1: Use the current plug mechanism by allowing any sysbus device, without adding handle code in the machine.
+ Option 2: Add a boolean flag in the machine to allow to plug any sysbus device. We can additionally differentiate the sysbus devices requiring the legacy plug mechanism (with a flag, for example) and the others.
The setup of the memory map and irq connections is not related to the option choice above. We planned to rely on qapi commands to do these operations. A new _sysbus-mmio-map_ command is proposed in this series to setup the mapping. Irqs can already be connected using the _qom-set_ command.
Alternatively we could probably add parameters/properties to device_add to handle the memory map, but it looks more complicated to achieve.
Based-on: <[email protected]>
( QAPI support for device cold-plug )
Note that it does not stricly require this to be merged, but this series does not make much sense without the ability to cold plug with device_add first.
Thanks for your feedback,
--
Damien
Damien Hedde (3):
none-machine: allow cold plugging sysbus devices softmmu/memory: add memory_region_try_add_subregion function add sysbus-mmio-map qapi command
qapi/qdev.json | 31 ++++++++++++++++++++++++++ include/exec/memory.h | 22 +++++++++++++++++++ hw/core/null-machine.c | 4 ++++ hw/core/sysbus.c | 49 ++++++++++++++++++++++++++++++++++++++++++ softmmu/memory.c | 26 ++++++++++++++-------- 5 files changed, 123 insertions(+), 9 deletions(-)
Signature · 1 line
2.36.1
RFC PATCH v5 1/3 none-machine: allow cold plugging sysbus devices
Allow plugging any sysbus device on this machine (the sysbus devices still need to be 'user-creatable').
This commit is needed to use the 'none' machine as a base, and subsequently to dynamically populate it with sysbus devices using qapi commands.
Note that this only concern cold-plug: sysbus devices can not be hot-plugged because the sysbus bus does not support it.
---
v5:
+ fix commit message (Philippe)
--- hw/core/null-machine.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/core/null-machine.c +4 -0
@@ -16,6 +16,7 @@#include "hw/boards.h" #include "exec/address-spaces.h" #include "hw/core/cpu.h" +#include "hw/sysbus.h" static void machine_none_init (MachineState *mch) {
@@ -54,6 +55,9 @@ static void machine_none_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_sdcard =1 ; + +/* allow cold plugging any any "user-creatable" sysbus device */ +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_SYS_BUS_DEVICE ); }DEFINE_MACHINE ("none" , machine_none_machine_init)
Signature · 1 line
2.36.1
RFC PATCH v5 2/3 softmmu/memory: add memory_region_try_add_subregion function
In reply to Damien HeddeIt allows adding a subregion to a memory region with error handling. Like memory_region_add_subregion_overlap(), it handles priority as well. Apart from the error handling, the behavior is the same. It can be used to do the simple memory_region_add_subregion() (with no overlap) by setting the priority parameter to 0.
This commit is a preparation to further use of this function in the context of qapi command which needs error handling support.
---
v5:
+ rebase, new callsite
--- include/exec/memory.h | 22 ++++++++++++++++++++++ softmmu/memory.c | 26 +++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-)
include/exec/memory.h +22 -0
@@ -2215,6 +2215,28 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,MemoryRegion *subregion, int priority); +/** +* memory_region_try_add_subregion: Add a subregion to a container +* with error handling. +* +* Behaves like memory_region_add_subregion_overlap(), but errors are +* reported if the subregion cannot be added. +* +* @mr: the region to contain the new subregion; must be a container +* initialized with memory_region_init(). +* @offset: the offset relative to @mr where @subregion is added. +* @subregion: the subregion to be added. +* @priority: used for resolving overlaps; highest priority wins. +* @errp: pointer to Error*, to store an error if it happens. +* +* Returns: True in case of success, false otherwise. +*/ +bool memory_region_try_add_subregion (MemoryRegion *mr, +hwaddr offset, +MemoryRegion *subregion, +int priority, +Error **errp); +/** * memory_region_get_ram_addr: Get the ram address associated with a memory * region
softmmu/memory.c +17 -9
@@ -2541,27 +2541,34 @@ done:memory_region_transaction_commit (); } -static void memory_region_add_subregion_common (MemoryRegion *mr, -hwaddr offset, -MemoryRegion *subregion) +bool memory_region_try_add_subregion (MemoryRegion *mr, +hwaddr offset, +MemoryRegion *subregion, +int priority, +Error **errp) {MemoryRegion *alias; -assert (!subregion->container); +if (subregion->container) { +error_setg (errp,"The memory region is already in another region" ); +return false; + } + + subregion->priority = priority; subregion->container = mr;for (alias = subregion->alias; alias; alias = alias->alias) { alias->mapped_via_alias++; } subregion->addr = offset;memory_region_update_container_subregions (subregion); +return true; }void memory_region_add_subregion (MemoryRegion *mr,hwaddr offset,MemoryRegion *subregion) { - subregion->priority =0 ; -memory_region_add_subregion_common (mr, offset, subregion); +memory_region_try_add_subregion (mr, offset, subregion,0 , &error_abort); } void memory_region_add_subregion_overlap(MemoryRegion *mr,
@@ -2569,8 +2576,8 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,MemoryRegion *subregion, int priority) { - subregion->priority = priority; -memory_region_add_subregion_common (mr, offset, subregion); +memory_region_try_add_subregion (mr ,offset ,subregion ,priority , + &error_abort); } void memory_region_del_subregion(MemoryRegion *mr,
@@ -2626,7 +2633,8 @@ static void memory_region_readd_subregion(MemoryRegion *mr)memory_region_transaction_begin ();memory_region_ref (mr);memory_region_del_subregion (container, mr); -memory_region_add_subregion_common (container, mr->addr, mr); +memory_region_try_add_subregion (container, mr->addr, mr, mr->priority, + &error_abort);memory_region_unref (mr);memory_region_transaction_commit (); }
Signature · 1 line
2.36.1
RFC PATCH v5 3/3 add sysbus-mmio-map qapi command
In reply to Damien HeddeThis command allows to map an mmio region of sysbus device onto the system memory. Its behavior mimics the sysbus_mmio_map() function apart from the automatic unmap (the C function unmaps the region if it is already mapped).
For the qapi function we consider it is an error to try to map an already mapped function. If unmapping is required, it is probably better to add a sysbus-mmio-unmap command.
This command is still experimental (hence the 'unstable' feature), as it is related to the sysbus device creation through qapi commands.
This command is required to be able to dynamically build a machine from scratch as there is no qapi-way of doing a memory mapping.
---
Cc: Alistair Francis <[email protected]>
v5:
+ bump version to 7.1
v4:
+ integrate priority parameter
+ use 'unstable' feature flag instead of 'x-' prefix
+ bump version to 7.0
+ dropped Alistair's reviewed-by as a consequence
--- qapi/qdev.json | 31 ++++++++++++++++++++++++++++++ hw/core/sysbus.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)
qapi/qdev.json +31 -0
@@ -160,3 +160,34 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @sysbus-mmio-map: +# +# Map a sysbus device mmio onto the main system bus. +# +# @device: the device's QOM path +# +# @mmio: The mmio number to be mapped (defaults to 0). +# +# @addr: The base address for the mapping. +# +# @priority: The priority of the mapping (defaults to 0). +# +# Features: +# @unstable: Command is meant to map sysbus devices +# while in preconfig mode. +# +# Since: 7.1 +# +# Returns: Nothing on success +# +## + +{ 'command': 'sysbus-mmio-map', + 'data': { 'device': 'str', + '*mmio': 'uint8', + 'addr': 'uint64', + '*priority': 'int32' }, + 'features': ['unstable'], + 'allow-preconfig' : true }
hw/core/sysbus.c +49 -0
61 lines not on this page · raw message
Signature · 1 line
2.36.1
Quoted 52 lines · Damien Hedde
Hi all,
This series is about enabling to plug sysbus devices with
device_addQAPI command. I've put RFC because, there are several options and I would like to know if you think the current version is ok to be added in qemu.Right now only a few sysbus device can be plugged using "-device" CLI option and a custom plugging mechanism. A machine defines a list of allowed/supported sysbus devices and provides some code to handle the plug. For example, it sets up the memory map and irq connections.
In order to configure a machine from scratch with qapi, we want to cold plug sysbus devices to the _none_ machine with qapi commands without requiring the machine to provide some specific per-device support.
There are mostly 2 options (option 1 is in these patches). Note that in any case this only applies to "user-creatable" device.
+ Option 1: Use the current plug mechanism by allowing any sysbus device, without adding handle code in the machine.
+ Option 2: Add a boolean flag in the machine to allow to plug any sysbus device. We can additionally differentiate the sysbus devices requiring the legacy plug mechanism (with a flag, for example) and the others.
The setup of the memory map and irq connections is not related to the option choice above. We planned to rely on qapi commands to do these operations. A new _sysbus-mmio-map_ command is proposed in this series to setup the mapping. Irqs can already be connected using the _qom-set_ command.
Alternatively we could probably add parameters/properties todevice_addto handle the memory map, but it looks more complicated to achieve.Based-on: <[email protected]>
( QAPI support for device cold-plug )
Note that it does not stricly require this to be merged, but this series does not make much sense without the ability to cold plug withdevice_addfirst.Thanks for your feedback,
--
DamienDamien Hedde (3):
none-machine: allow cold plugging sysbus devices softmmu/memory: addmemory_region_try_add_subregionfunction add sysbus-mmio-map qapi command
Quoted 6 lines
qapi/qdev.json | 31 ++++++++++++++++++++++++++ include/exec/memory.h | 22 +++++++++++++++++++ hw/core/null-machine.c | 4 ++++ hw/core/sysbus.c | 49 ++++++++++++++++++++++++++++++++++++++++++ softmmu/memory.c | 26 ++++++++++++++-------- 5 files changed, 123 insertions(+), 9 deletions(-)
Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between TYPE_DEVICE and TYPE_SYS_BUS_DEVICE anymore, and whether it makes sense to keep TYPE_SYS_BUS_DEVICE long term.
No objection to the concept of being able to plug devices into the none machine, but I'm wondering if the "sysbus-mmio-map" QAPI command should be a generic "device-map" instead so that the concept of SYS_BUS_DEVICE doesn't leak into QAPI.
Can you give a bit more detail as to the sequence of QMP transactions that would be used to map a SYS_BUS_DEVICE with this series applied? I'm particularly interested to understand how SYS_BUS_DEVICEs are identified, and how their memory regions and gpios are enumerated by the client to enable it to generate the final "sysbus-mmio-map" and "qom-set" commands.
ATB,
Mark.
Quoted 54 lines · Mark Cave-Ayland
Quoted 52 lines · Damien Hedde
Hi all,
This series is about enabling to plug sysbus devices with
device_addQAPI command. I've put RFC because, there are several options and I would like to know if you think the current version is ok to be added in qemu.Right now only a few sysbus device can be plugged using "-device" CLI option and a custom plugging mechanism. A machine defines a list of allowed/supported sysbus devices and provides some code to handle the plug. For example, it sets up the memory map and irq connections.
In order to configure a machine from scratch with qapi, we want to cold plug sysbus devices to the _none_ machine with qapi commands without requiring the machine to provide some specific per-device support.
There are mostly 2 options (option 1 is in these patches). Note that in any case this only applies to "user-creatable" device.
+ Option 1: Use the current plug mechanism by allowing any sysbus device, without adding handle code in the machine.
+ Option 2: Add a boolean flag in the machine to allow to plug any sysbus device. We can additionally differentiate the sysbus devices requiring the legacy plug mechanism (with a flag, for example) and the others.
The setup of the memory map and irq connections is not related to the option choice above. We planned to rely on qapi commands to do these operations. A new _sysbus-mmio-map_ command is proposed in this series to setup the mapping. Irqs can already be connected using the _qom-set_ command.
Alternatively we could probably add parameters/properties todevice_addto handle the memory map, but it looks more complicated to achieve.Based-on: <[email protected]> ( QAPI support for device cold-plug )
Note that it does not stricly require this to be merged, but this series does not make much sense without the ability to cold plug withdevice_addfirst.Thanks for your feedback,
Signature · 6 lines
Damien Damien Hedde (3): none-machine: allow cold plugging sysbus devices softmmu/memory: add memory_region_try_add_subregion function add sysbus-mmio-map qapi command
Quoted 8 lines
Quoted 6 lines
qapi/qdev.json | 31 ++++++++++++++++++++++++++ include/exec/memory.h | 22 +++++++++++++++++++
hw/core/null-machine.c| 4 ++++
hw/core/sysbus.c | 49 ++++++++++++++++++++++++++++++++++++++++++ softmmu/memory.c | 26 ++++++++++++++--------5 files changed, 123 insertions(+), 9 deletions(-)Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between
TYPE_DEVICEandTYPE_SYS_BUS_DEVICEanymore, and whether it makes sense to keepTYPE_SYS_BUS_DEVICElong term.
On QAPI/CLI level there is a huge difference since TYPE_SYS_BUS_DEVICE is the only subtype of TYPE_DEVICE which is subject to special treatment. It prevents to plug a sysbus device which has not be allowed by code and that's what I want to get rid of (or workaround by allowing all of them).
Quoted 2 lines
No objection to the concept of being able to plug devices into the none machine, but I'm wondering if the "sysbus-mmio-map" QAPI command should be a generic "device-map" instead so that the concept of
SYS_BUS_DEVICEdoesn't leak into QAPI.
It is possible to change this command to a more generic command if people feel better with it.
Instead of providing a mmio index we just need to provide an argument to identify the memory region in the device (by it's name/path maybe ?).
Quoted 2 lines
Can you give a bit more detail as to the sequence of QMP transactions that would be used to map a
SYS_BUS_DEVICEwith this series applied? I'm particularly interested to understand howSYS_BUS_DEVICEsare identified, and how their memory regions and gpios are enumerated by the client to enable it to generate the final "sysbus-mmio-map" and "qom-set" commands.
Here's a typical example of commands to create and connect an uart (here "plic" is the id of the interrupt controller created before):
Quoted 6 lines
device_adddriver=ibex-uart id=uart chardev=serial0 sysbus-mmio-map device=uart addr=1073741824
qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1] qom-set path=uart property=sysbus-irq[1] value=plic/unnamed-gpio-in[2] qom-set path=uart property=sysbus-irq[2] value=plic/unnamed-gpio-in[3] qom-set path=uart property=sysbus-irq[3] value=plic/unnamed-gpio-in[4]
This comes from one of my example here (it needs more patches than this series): https://github.com/GreenSocs/qemu-qmp-machines/blob/master/riscv-opentitan/machine.qmp
I'm note sure what you mean by identification and enumeration. I do not do any introspection and rely on knowing which mmio or irq index corresponds to what. The "id" in device_add allows to reference the device in following commands.
Thanks,
--
Damien
Quoted 7 lines · Damien Hedde
Quoted 5 lines · Mark Cave-Ayland
Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between
TYPE_DEVICEandTYPE_SYS_BUS_DEVICEanymore, and whether it makes sense to keepTYPE_SYS_BUS_DEVICElong term.
Quoted 5 lines
On QAPI/CLI level there is a huge difference since
TYPE_SYS_BUS_DEVICEis the only subtype ofTYPE_DEVICEwhich is subject to special treatment. It prevents to plug a sysbus device which has not be allowed by code and that's what I want to get rid of (or workaround by allowing all of them).
Yes, but the fact that TYPE_SYS_BUS_DEVICE is a special subclass is an accident of history. At some point we really ought to tidy this up so that any TYPE_DEVICE can have MMIO regions and IRQs, and get rid of the subclass entirely. This isn't trivial, for reasons including problems with reset handling, but I would prefer it if we didn't bake "sysbus is special" into places like the QMP commands.
More generally, I don't think that the correct answer to "is this device OK to cold-plug via commandline and QMP is "is it a sysbus device?". I don't know what the right way to identify cold-pluggable devices is but I suspect it needs to be more complicated.
Quoted 4 lines
I'm note sure what you mean by identification and enumeration. I do not do any introspection and rely on knowing which mmio or irq index corresponds to what. The "id" in
device_addallows to reference the device in following commands.
This is then baking in a device's choices of MMIO region ordering and arrangement and its IRQ numbering into a user-facing ABI. I can't say I'm very keen on that -- it would block us from being able to do a variety of refactorings and cleanups.
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
Quoted 5 lines · Mark Cave-Ayland
Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between
TYPE_DEVICEandTYPE_SYS_BUS_DEVICEanymore, and whether it makes sense to keepTYPE_SYS_BUS_DEVICElong term.Quoted 5 lines
On QAPI/CLI level there is a huge difference since
TYPE_SYS_BUS_DEVICEis the only subtype ofTYPE_DEVICEwhich is subject to special treatment. It prevents to plug a sysbus device which has not be allowed by code and that's what I want to get rid of (or workaround by allowing all of them).Yes, but the fact that
TYPE_SYS_BUS_DEVICEis a special subclass is an accident of history. At some point we really ought to tidy this up so that anyTYPE_DEVICEcan have MMIO regions and IRQs, and get rid of the subclass entirely. This isn't trivial, for reasons including problems with reset handling, but I would prefer it if we didn't bake "sysbus is special" into places like the QMP commands.
Quoted 4 lines
More generally, I don't think that the correct answer to "is this device OK to cold-plug via commandline and QMP is "is it a sysbus device?". I don't know what the right way to identify cold-pluggable devices is but I suspect it needs to be more complicated.
"sysbus is special" is already into the QMP commands.
Right now, any user-creatable device (but sysbus devices) can be cold-plugged by CLI using "-device". The checks are basically:
+ does this device is "user-creatable" ?
+ do realize succeed ? (check device properties and handle bus connection)
So basically this is down to the bus realize mechanism to deal with any non-trivial constraint.
Concretely "user-creatable" means cold-pluggable by CLI.
And the reason why it cannot be done by QMP is because QMP commands are not possible at that time (the based-on series fix that).
For sysbus device, it is the same but there is an additional check to verify that the device is present in the machine allow list.
Quoted 6 lines
Quoted 5 lines
I'm note sure what you mean by identification and enumeration. I do not do any introspection and rely on knowing which mmio or irq index corresponds to what. The "id" in
device_addallows to reference the device in following commands.
Quoted 6 lines
This is then baking in a device's choices of MMIO region ordering and arrangement and its IRQ numbering into a user-facing ABI. I can't say I'm very keen on that -- it would block us from being able to do a variety of refactorings and cleanups.
It's the same for any device property, we make a choice that is exposed to the user.
Whether this is done at TYPE_DEVICE or TYPE_SYS_BUS_DEVICE level does not change anything to that matter. We could, for example, choose to follow the order/name convention used in device tree specs if the issue is having no rules. That would probably ease any fdt generation from a device qemu model.
That does not prevent us to make change after. Right now, this would be accessible only if using the _none_ machine and with '-preconfig' experimental and using the _none_ machine. So I don't think we have to follow some deprecation policy.
What would you consider a starting point to allow that kind of plug ?
--
Damien
Quoted 14 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
Quoted 5 lines · Mark Cave-Ayland
Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between
TYPE_DEVICEandTYPE_SYS_BUS_DEVICEanymore, and whether it makes sense to keepTYPE_SYS_BUS_DEVICElong term.Quoted 5 lines
On QAPI/CLI level there is a huge difference since
TYPE_SYS_BUS_DEVICEis the only subtype ofTYPE_DEVICEwhich is subject to special treatment. It prevents to plug a sysbus device which has not be allowed by code and that's what I want to get rid of (or workaround by allowing all of them).
Quoted 7 lines
Yes, but the fact that
TYPE_SYS_BUS_DEVICEis a special subclass is an accident of history. At some point we really ought to tidy this up so that anyTYPE_DEVICEcan have MMIO regions and IRQs, and get rid of the subclass entirely. This isn't trivial, for reasons including problems with reset handling, but I would prefer it if we didn't bake "sysbus is special" into places like the QMP commands.
Right, and in fact we can already do this today using QOM regardless of whether something is a SysBusDevice or not. As an example here is the output of qemu-system-sparc's "info qom-tree" for the slavio_misc device:
/device[20] (slavio_misc)
/configuration[0] (memory-region)
/diagnostic[0] (memory-region)
/leds[0] (memory-region)
/misc-system-functions[0] (memory-region)
/modem[0] (memory-region)
/software-powerdown-control[0] (memory-region)
/system-control[0] (memory-region)
/unnamed-gpio-in[0] (irq)Now imagine that I instantiate a device with qdev_new():
DeviceState *dev = qdev_new("slavio_misc");I can obtain a reference to the "configuration" memory-region using something like:
MemoryRegion *config_mr = MEMORY_REGION(object_resolve_path_component(
OBJECT(dev), "configuration[0]"));and for the IRQ I can do either:
qemu_irq *irq = IRQ(object_resolve_path_component(
OBJECT(dev), "unnamed-gpio-in[0]"));or simply:
qemu_irq *irq = qdev_get_gpio_in(dev, 0);
Maybe for simplicity we could even add a qdev wrapper function to obtain a reference for memory regions similar to qdev gpios i.e. qdev_get_mmio(dev, "configuration", 0) based upon the above example?
Now from the monitor we can already enumerate this information using qom-list if we have the QOM path:
(qemu) qom-list /machine/unattached/device[20]
type (string)
parent_bus (link<bus>)
hotplugged (bool)
hotpluggable (bool)
realized (bool)
diagnostic[0] (child<memory-region>)
unnamed-gpio-in[0] (child<irq>)
modem[0] (child<memory-region>)
leds[0] (child<memory-region>)
misc-system-functions[0] (child<memory-region>)
sysbus-irq[1] (link<irq>)
sysbus-irq[0] (link<irq>)
system-control[0] (child<memory-region>)
configuration[0] (child<memory-region>)
software-powerdown-control[0] (child<memory-region>)From this I think we're missing just 2 things: i) a method to look up properties from a device id which can be used to facilitate introspection, and ii) a function to map a memory region from a device (similar to Damien's patch). Those could be something like:
device_list <id>
- looks up the QOM path for device "id" and calls qom-list on the result
device_map <id> <mr> <offset> [<parent_mr>]
- map device "id" region named mr at given offset. If parent_mr is unspecified, assume it is the root address space (get_system_memory()).
It may also be worth adding a device_connect wrapper to simplify your qom-set example:
device_connect <out-id> <out-irq> <in-id> <in-irq>
The only thing I see here that SYS_BUS_DEVICE offers that we don't have is the ability to restrict which memory regions/irqs are available for mapping - but does this matter if we have introspection and don't mind addressing everything by name?
Quoted 4 lines
More generally, I don't think that the correct answer to "is this device OK to cold-plug via commandline and QMP is "is it a sysbus device?". I don't know what the right way to identify cold-pluggable devices is but I suspect it needs to be more complicated.
I think that connecting devices like this can only work if there is no additional bus logic, in which case could we say a device is cold-pluggable if it has no bus specified, or the bus is the root sysbus?
Quoted 10 lines
Quoted 4 lines
I'm note sure what you mean by identification and enumeration. I do not do any introspection and rely on knowing which mmio or irq index corresponds to what. The "id" in
device_addallows to reference the device in following commands.This is then baking in a device's choices of MMIO region ordering and arrangement and its IRQ numbering into a user-facing ABI. I can't say I'm very keen on that -- it would block us from being able to do a variety of refactorings and cleanups.
Absolutely agree. The main reason we need something like qom-find-device-path is because QOM paths are not stable: there are a large number of legacy devices still out there, and QOMifying them often changes the QOM paths and child object ordering.
ATB,
Mark.
Quoted 75 lines · Mark Cave-Ayland
Quoted 14 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
Quoted 5 lines · Mark Cave-Ayland
Sorry for coming late into this series, however one of the things I've been thinking about a lot recently is that with the advent of QOM and qdev, is there really any distinction between
TYPE_DEVICEandTYPE_SYS_BUS_DEVICEanymore, and whether it makes sense to keepTYPE_SYS_BUS_DEVICElong term.Quoted 5 lines
On QAPI/CLI level there is a huge difference since
TYPE_SYS_BUS_DEVICEis the only subtype ofTYPE_DEVICEwhich is subject to special treatment. It prevents to plug a sysbus device which has not be allowed by code and that's what I want to get rid of (or workaround by allowing all of them).Quoted 7 lines
Yes, but the fact that
TYPE_SYS_BUS_DEVICEis a special subclass is an accident of history. At some point we really ought to tidy this up so that anyTYPE_DEVICEcan have MMIO regions and IRQs, and get rid of the subclass entirely. This isn't trivial, for reasons including problems with reset handling, but I would prefer it if we didn't bake "sysbus is special" into places like the QMP commands.Right, and in fact we can already do this today using QOM regardless of whether something is a SysBusDevice or not. As an example here is the output of qemu-system-sparc's "info qom-tree" for the
slavio_miscdevice:/device[20] (
slavio_misc) /configuration[0] (memory-region) /diagnostic[0] (memory-region) /leds[0] (memory-region) /misc-system-functions[0] (memory-region) /modem[0] (memory-region) /software-powerdown-control[0] (memory-region) /system-control[0] (memory-region) /unnamed-gpio-in[0] (irq)Now imagine that I instantiate a device with
qdev_new():DeviceState *dev =
qdev_new("slavio_misc");I can obtain a reference to the "configuration" memory-region using something like:
MemoryRegion
*config_mr=MEMORY_REGION(object_resolve_path_component( OBJECT(dev), "configuration[0]"));and for the IRQ I can do either:
qemu_irq*irq =IRQ(object_resolve_path_component( OBJECT(dev), "unnamed-gpio-in[0]"));or simply:
qemu_irq*irq =qdev_get_gpio_in(dev, 0);Maybe for simplicity we could even add a qdev wrapper function to obtain a reference for memory regions similar to qdev gpios i.e.
qdev_get_mmio(dev, "configuration", 0)based upon the above example?Now from the monitor we can already enumerate this information using qom-list if we have the QOM path:
(qemu) qom-list /machine/unattached/device[20] type (string)
parent_bus(link<bus>)
hotplugged (bool)
hotpluggable (bool)
realized (bool)
diagnostic[0] (child<memory-region>) unnamed-gpio-in[0] (child<irq>)
modem[0] (child<memory-region>)
leds[0] (child<memory-region>) misc-system-functions[0] (child<memory-region>) sysbus-irq[1] (link<irq>)
sysbus-irq[0] (link<irq>)
system-control[0] (child<memory-region>) configuration[0] (child<memory-region>) software-powerdown-control[0] (child<memory-region>)
Quoted 6 lines
From this I think we're missing just 2 things: i) a method to look up
properties from a device id which can be used to facilitate introspection, and ii) a function to map a memory region from a device (similar to Damien's patch). Those could be something like:
device_list<id>
- looks up the QOM path for device "id" and calls qom-list on the
result
You can already do qom_list <id>.
It works with non-absolute qom path too (if there is only 1 match for the relative path in the qom tree). In your example qom-list device[20] probably works too.
Quoted 11 lines
device_map<id> <mr> <offset> [<parent_mr>]
- map device "id" region named mr at given offset. Ifparent_mris unspecified, assume it is the root address space
(get_system_memory()).It may also be worth adding a
device_connectwrapper to simplify your qom-set example:
device_connect<out-id> <out-irq> <in-id> <in-irq>The only thing I see here that
SYS_BUS_DEVICEoffers that we don't have is the ability to restrict which memory regions/irqs are available for mapping - but does this matter if we have introspection and don't mind addressing everything by name?
TYPE_SYS_BUS_DEVICE also comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic into TYPE_DEVICE, we will still miss that. The bus is needed to handle the reset. For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.
If we end up putting in TYPE_DEVICE support for mmios, interrupts and some way to do the bus reset. What would be the difference between the current TYPE_SYS_BUS_DEVICE ?
Quoted 19 lines
Quoted 5 lines
More generally, I don't think that the correct answer to "is this device OK to cold-plug via commandline and QMP is "is it a sysbus device?". I don't know what the right way to identify cold-pluggable devices is but I suspect it needs to be more complicated.
I think that connecting devices like this can only work if there is no additional bus logic, in which case could we say a device is cold-pluggable if it has no bus specified, or the bus is the root sysbus?
Quoted 10 lines
Quoted 4 lines
I'm note sure what you mean by identification and enumeration. I do not do any introspection and rely on knowing which mmio or irq index corresponds to what. The "id" in
device_addallows to reference the device in following commands.This is then baking in a device's choices of MMIO region ordering and arrangement and its IRQ numbering into a user-facing ABI. I can't say I'm very keen on that -- it would block us from being able to do a variety of refactorings and cleanups.
Quoted 6 lines
Absolutely agree. The main reason we need something like qom-find-device-path is because QOM paths are not stable: there are a large number of legacy devices still out there, and QOMifying them often changes the QOM paths and child object ordering.
ATB,
Mark.
--
Damien
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.
Yes, the missing reset support in TYPE_DEVICE is a design flaw that we really should try to address.
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?
There would be none, and the idea would be to get rid of TYPE_SYS_BUS_DEVICE entirely...
-- PMM
Quoted 12 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.
Quoted 7 lines
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...
Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
Quoted 3 lines
device_adddriver=ibex-uart id=uart chardev=serial0 sysbus-mmio-map device=uart addr=1073741824
qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICE or TYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.
Thanks,
Damien
Quoted 10 lines · Damien Hedde
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.
Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.
I think the easiest way to handle this would be just after calling dc->realize; if the device has bus == NULL and dc->reset != NULL then manually call qemu_register_reset() for dc->reset. In a qdev world dc->reset is intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children.
Quoted 7 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
Quoted 3 lines
device_adddriver=ibex-uart id=uart chardev=serial0 sysbus-mmio-map device=uart addr=1073741824
qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.
Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "device_map" which is effectively a wrapper around memory_region_add_subregion(). Do we also want a "device_unmap"? We should consider allow mapping to other memory regions other than the system root.
- A monitor command such as "device_connect" which can be used to simplify your IRQ wiring, perhaps also with a "device_disconnect"?
- An outline of the monitor commands showing the complete workflow from introspection of a device to mapping its memory region(s) and connecting its gpios
Does that give you enough information to come up with a more detailed proposal?
ATB,
Mark.
Quoted 12 lines · Mark Cave-Ayland
Quoted 10 lines · Damien Hedde
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.
I'm a bit afraid calling qemu_register_reset() outside dc->realize might modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?
Quoted 11 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 22 lines
Quoted 8 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
>
device_adddriver=ibex-uart id=uart chardev=serial0
> sysbus-mmio-map device=uart addr=1073741824
> qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper around
memory_region_add_subregion(). Do we also want a "device_unmap"? We
should
consider allow mapping to other memory regions other than the system
root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ
wiring, perhaps also with a "device_disconnect"?
Quoted 6 lines
- An outline of the monitor commands showing the complete workflow from introspection
of a device to mapping its memory region(s) and connecting its gpiosDoes that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a device_connect or a device_map.
My question was more about the workflow which does not rely on issuing a single 'device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base type TYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.
Thanks,
Damien
Quoted 13 lines · Damien Hedde
Quoted 12 lines · Mark Cave-Ayland
Quoted 10 lines · Damien Hedde
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.I'm a bit afraid calling
qemu_register_reset()outsidedc->realizemight modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?
If you take a look at "info qtree" then that will show you all devices that are attached to a bus i.e. ones where bus is not NULL.
Quoted 34 lines
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 21 lines
Quoted 8 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
>
device_adddriver=ibex-uart id=uart chardev=serial0
> sysbus-mmio-map device=uart addr=1073741824
> qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper aroundmemory_region_add_subregion(). Do we also want a "device_unmap"? We should consider allow mapping to other memory regions other than the system root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ wiring, perhaps also with a "device_disconnect"?- An outline of the monitor commands showing the complete workflow from introspection of a device to mapping its memory region(s) and connecting its gpios
Quoted 6 lines
Quoted 2 lines
Does that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a
device_connector adevice_map.My question was more about the workflow which does not rely on issuing a single '
device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base typeTYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.
I'm not sure I understand what you are saying here? Can you give an example?
ATB,
Mark.
Quoted 61 lines · Mark Cave-Ayland
Quoted 13 lines · Damien Hedde
Quoted 12 lines · Mark Cave-Ayland
Quoted 10 lines · Damien Hedde
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.I'm a bit afraid calling
qemu_register_reset()outsidedc->realizemight modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?If you take a look at "info qtree" then that will show you all devices that are attached to a bus i.e. ones where bus is not NULL.
Quoted 37 lines
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 24 lines
Quoted 8 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
>
device_adddriver=ibex-uart id=uart chardev=serial0
> sysbus-mmio-map device=uart addr=1073741824
> qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper around
memory_region_add_subregion(). Do we also want a "device_unmap"? We should consider allow mapping to other memory regions other than the system root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ
wiring, perhaps also with a "device_disconnect"?- An outline of the monitor commands showing the complete workflow from introspection
of a device to mapping its memory region(s) and connecting its gpios
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Does that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a
device_connector adevice_map.My question was more about the workflow which does not rely on issuing a single '
device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base typeTYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.I'm not sure I understand what you are saying here? Can you give an example?
There are 2 possible workflows:
1. several commands
Quoted 3 lines
device_add...device_map...device_connect...
2. single command
Quoted 1 line
device_add... map={...} connect={...}
The 2nd one is more like how we connect devices with '-device': all is done at once. But if this is supposed to apply to TYPE_DEVICE (versus TYPE_SYS_BUS_DEVICE), it becomes IMHO hard to prevent using them on devices where it does not makes sense (for example: a virtio or pci device for which everything is already handled).
--
Damien
Quoted 119 lines · Damien Hedde
Quoted 101 lines · Mark Cave-Ayland
Quoted 27 lines · Damien Hedde
Quoted 19 lines · Mark Cave-Ayland
Quoted 14 lines · Damien Hedde
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will
still miss that. The bus is needed to handle the reset. For devices created in machine init code, we have the option to do it in
the machine reset handler. But for user created device, this is an issue.Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.Quoted 6 lines
I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.Quoted 3 lines
I'm a bit afraid calling
qemu_register_reset()outsidedc->realizemight modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?If you take a look at "info qtree" then that will show you all devices that are attached to a bus i.e. ones where bus is not NULL.
Quoted 65 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the
currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Quoted 7 lines
Quoted 2 lines
Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 33 lines
Quoted 6 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
Quoted 8 lines
>
device_adddriver=ibex-uart id=uart chardev=serial0 > sysbus-mmio-map device=uart addr=1073741824 > qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper around
memory_region_add_subregion(). Do we also want a "device_unmap"? We should
consider allow mapping to other memory regions other than the system root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ
wiring, perhaps also with a "device_disconnect"?Quoted 7 lines
- An outline of the monitor commands showing the complete workflow from introspection
of a device to mapping its memory region(s) and connecting its gpiosDoes that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a
device_connector adevice_map.Quoted 8 lines
Quoted 5 lines
My question was more about the workflow which does not rely on issuing a single '
device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base typeTYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.I'm not sure I understand what you are saying here? Can you give an example?
There are 2 possible workflows:
1. several commandsQuoted 3 lines
device_add...device_map...device_connect...
Quoted 8 lines
2. single command
Quoted 1 line
device_add... map={...} connect={...}The 2nd one is more like how we connect devices with '-device': all is done at once. But if this is supposed to apply to
TYPE_DEVICE(versusTYPE_SYS_BUS_DEVICE), it becomes IMHO hard to prevent using them on devices where it does not makes sense (for example: a virtio or pci device for which everything is already handled).
Can't we flag devices for which map/connect is supported in the device class somehow?
Signature · 3 lines
Thanks, David / dhildenb
Quoted 123 lines · David Hildenbrand
Quoted 122 lines · Damien Hedde
Quoted 101 lines · Mark Cave-Ayland
Quoted 27 lines · Damien Hedde
Quoted 19 lines · Mark Cave-Ayland
Quoted 14 lines · Damien Hedde
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will
still miss that. The bus is needed to handle the reset. For devices created in machine init code, we have the option to do it in
the machine reset handler. But for user created device, this is an issue.Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.Quoted 6 lines
I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.Quoted 3 lines
I'm a bit afraid calling
qemu_register_reset()outsidedc->realizemight modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?If you take a look at "info qtree" then that will show you all devices that are attached to a bus i.e. ones where bus is not NULL.
Quoted 65 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the
currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Quoted 7 lines
Quoted 2 lines
Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 33 lines
Quoted 6 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
Quoted 8 lines
>
device_adddriver=ibex-uart id=uart chardev=serial0 > sysbus-mmio-map device=uart addr=1073741824 > qom-set path=uart property=sysbus-irq[0]
value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper around
memory_region_add_subregion(). Do we also want a "device_unmap"?
We should
consider allow mapping to other memory regions other than the
system root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ
wiring, perhaps also with a "device_disconnect"?Quoted 7 lines
- An outline of the monitor commands showing the complete workflow from introspection
of a device to mapping its memory region(s) and connecting its gpiosDoes that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a
device_connector adevice_map.Quoted 8 lines
Quoted 5 lines
My question was more about the workflow which does not rely on issuing a single '
device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base typeTYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.I'm not sure I understand what you are saying here? Can you give an example?
There are 2 possible workflows:
1. several commandsQuoted 3 lines
device_add...device_map...device_connect...2. single command
Quoted 1 line
device_add... map={...} connect={...}
Quoted 8 lines
Quoted 5 lines
The 2nd one is more like how we connect devices with '-device': all is done at once. But if this is supposed to apply to
TYPE_DEVICE(versusTYPE_SYS_BUS_DEVICE), it becomes IMHO hard to prevent using them on devices where it does not makes sense (for example: a virtio or pci device for which everything is already handled).Can't we flag devices for which map/connect is supported in the device class somehow?
I don't think we actually need to do this: if someone is using the monitor to wire/rewire or map/remap a device in an invalid way then ultimately that is their choice.
However given that this is a new feature, we can initially restrict it to SYS_BUS_DEVICEs before expanding it out to a generic DEVICE later once the feature has been proved. The key part for me is to try and do it in a way that such a change won't require future changes to the monitor client.
ATB,
Mark.
Quoted 71 lines · Damien Hedde
Quoted 59 lines · Mark Cave-Ayland
Quoted 13 lines · Damien Hedde
Quoted 12 lines · Mark Cave-Ayland
Quoted 10 lines · Damien Hedde
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Damien Hedde
TYPE_SYS_BUS_DEVICEalso comes with reset support.
If a device is on not on any bus it is not reached by the root sysbus reset which propagates to every device (and other sub-buses). Even if we move all the mmio/sysbus-irq logic intoTYPE_DEVICE, we will still miss that. The bus is needed to handle the reset.
For devices created in machine init code, we have the option to do it in the machine reset handler. But for user created device, this is an issue.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Yes, the missing reset support in
TYPE_DEVICEis a design flaw that we really should try to address.I think the easiest way to handle this would be just after calling
dc->realize; if the device has bus == NULL anddc->reset!= NULL then manually callqemu_register_reset()fordc->reset. In a qdev worlddc->resetis intended to be a bus-level reset, but I can't see an issue with manual registration for individual devices in this way, particularly as there are no reset ordering guarantees for sysbus.I'm a bit afraid calling
qemu_register_reset()outsidedc->realizemight modify the behavior for existing devices. Does any device end up having a non-NULL bus right now when using "-device" CLI ?If you take a look at "info qtree" then that will show you all devices that are attached to a bus i.e. ones where bus is not NULL.
Quoted 35 lines
Quoted 10 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
If we end up putting in
TYPE_DEVICEsupport for mmios, interrupts and some way to do the bus reset. What would be the difference between the currentTYPE_SYS_BUS_DEVICE?There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICEentirely...Do you expect the bus object to disappear in the process (bus-less system) or transforming the sysbus into a ~TYPE_BUS thing ?
I'd probably lean towards removing sysbus completely since in real life devices can exist outside of a bus. If a device needs a bus then it should already be modelled in QEMU, and anything that requires a hierarchy can already be represented via QOM children
For me, a "memory bus" is a bus. But I understand in QEMU, this is modeled by a memory region and we do not want to represent it anymore by a qdev/qbus hierarchy.
Quoted 22 lines
Quoted 8 lines
Assuming we manage to sort out this does cold plugging using the following scenario looks ok ? (regarding having to issue one command to create the device AND some commands to handle memory-region and interrupt lines)
>
device_adddriver=ibex-uart id=uart chardev=serial0
> sysbus-mmio-map device=uart addr=1073741824
> qom-set path=uart property=sysbus-irq[0] value=plic/unnamed-gpio-in[1]
TYPE_DEVICEorTYPE_SYS_BUS_DEVICE, my goal is still to be able to cold-plug a "ibex-uart" define its memory map and choose which irq I wire where.Anyhow getting back on topic: my main objection here is that you're adding a command "sysbus-mmio-map" when we don't want the concept of SysBusDevice to be exposed outside of QEMU at all. Referring back to my last email I think we should extend the device concept in the monitor to handle the additional functionality perhaps along the lines of:
- A monitor command such as "
device_map" which is effectively a wrapper aroundmemory_region_add_subregion(). Do we also want a "device_unmap"? We should consider allow mapping to other memory regions other than the system root.- A monitor command such as "
device_connect" which can be used to simplify your IRQ wiring, perhaps also with a "device_disconnect"?- An outline of the monitor commands showing the complete workflow from introspection
of a device to mapping its memory region(s) and connecting its gpiosQuoted 8 lines
Quoted 6 lines
Quoted 2 lines
Does that give you enough information to come up with a more detailed proposal?
Yes. Sorry for being not clear enough. I did not wanted to insist on specific command names. I've no issues regarding the modifications you request about having a
device_connector adevice_map.My question was more about the workflow which does not rely on issuing a single '
device_add' command handling mapping/connection using parameters. Note that since we are talking supporting of map/connect for the base typeTYPE_DEVICE, I don't really see how we could have parameters for these without impacting subtypes.I'm not sure I understand what you are saying here? Can you give an example?
There are 2 possible workflows:
1. several commands
Quoted 8 lines
Quoted 3 lines
device_add...device_map...device_connect...2. single command
Quoted 1 line
device_add... map={...} connect={...}The 2nd one is more like how we connect devices with '-device': all is done at once. But if this is supposed to apply to
TYPE_DEVICE(versusTYPE_SYS_BUS_DEVICE), it becomes IMHO hard to prevent using them on devices where it does not makes sense (for example: a virtio or pci device for which everything is already handled).
My initial feeling is that 1) is the better approach, since you can report errors at each stage. Once you have the id for a specific device you can them attempt to device_map it, reporting an error if there is a region overlap. Similarly for device_connect can you report an error if the input gpio is already connected.
ATB,
Mark.