All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
@ 2022-05-24 13:48 Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices Damien Hedde
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Damien Hedde @ 2022-05-24 13:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell

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: <20220519153402.41540-1-damien.hedde@greensocs.com>
    ( 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(-)

-- 
2.36.1



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices
  2022-05-24 13:48 [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Damien Hedde
@ 2022-05-24 13:48 ` Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 2/3] softmmu/memory: add memory_region_try_add_subregion function Damien Hedde
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Damien Hedde @ 2022-05-24 13:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell

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.

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---

v5:
  + fix commit message (Philippe)
---
 hw/core/null-machine.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c
index f586a4bef5..21bc2aca23 100644
--- a/hw/core/null-machine.c
+++ b/hw/core/null-machine.c
@@ -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)
-- 
2.36.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [RFC PATCH v5 2/3] softmmu/memory: add memory_region_try_add_subregion function
  2022-05-24 13:48 [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices Damien Hedde
@ 2022-05-24 13:48 ` Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 3/3] add sysbus-mmio-map qapi command Damien Hedde
  2022-05-24 17:44 ` [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Mark Cave-Ayland
  3 siblings, 0 replies; 19+ messages in thread
From: Damien Hedde @ 2022-05-24 13:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell

It 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.

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
v5:
 + rebase, new callsite

---
 include/exec/memory.h | 22 ++++++++++++++++++++++
 softmmu/memory.c      | 26 +++++++++++++++++---------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index f1c19451bc..36f2e86be5 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -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
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 7ba2048836..5ea4000830 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -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();
     }
-- 
2.36.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [RFC PATCH v5 3/3] add sysbus-mmio-map qapi command
  2022-05-24 13:48 [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices Damien Hedde
  2022-05-24 13:48 ` [RFC PATCH v5 2/3] softmmu/memory: add memory_region_try_add_subregion function Damien Hedde
@ 2022-05-24 13:48 ` Damien Hedde
  2022-05-24 17:44 ` [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Mark Cave-Ayland
  3 siblings, 0 replies; 19+ messages in thread
From: Damien Hedde @ 2022-05-24 13:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Damien Hedde, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell

This 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.

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
Cc: Alistair Francis <alistair.francis@wdc.com>

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(+)

diff --git a/qapi/qdev.json b/qapi/qdev.json
index 2e2de41499..787d1ebf81 100644
--- a/qapi/qdev.json
+++ b/qapi/qdev.json
@@ -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 }
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 05c1da3d31..df1f1f43a5 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -23,6 +23,7 @@
 #include "hw/sysbus.h"
 #include "monitor/monitor.h"
 #include "exec/address-spaces.h"
+#include "qapi/qapi-commands-qdev.h"
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *sysbus_get_fw_dev_path(DeviceState *dev);
@@ -154,6 +155,54 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
     }
 }
 
+void qmp_sysbus_mmio_map(const char *device,
+                         bool has_mmio, uint8_t mmio,
+                         uint64_t addr,
+                         bool has_priority, int32_t priority,
+                         Error **errp)
+{
+    Object *obj = object_resolve_path_type(device, TYPE_SYS_BUS_DEVICE, NULL);
+    SysBusDevice *dev;
+
+    if (phase_get() != PHASE_MACHINE_INITIALIZED) {
+        error_setg(errp, "The command is permitted only when "
+                         "the machine is in initialized phase");
+        return;
+    }
+
+    if (obj == NULL) {
+        error_setg(errp, "Device '%s' not found", device);
+        return;
+    }
+    dev = SYS_BUS_DEVICE(obj);
+
+    if (!has_mmio) {
+        mmio = 0;
+    }
+    if (!has_priority) {
+        priority = 0;
+    }
+
+    if (mmio >= dev->num_mmio) {
+        error_setg(errp, "MMIO index '%u' does not exist in '%s'",
+                   mmio, device);
+        return;
+    }
+
+    if (dev->mmio[mmio].addr != (hwaddr)-1) {
+        error_setg(errp, "MMIO index '%u' is already mapped", mmio);
+        return;
+    }
+
+    if (!memory_region_try_add_subregion(get_system_memory(), addr,
+                                         dev->mmio[mmio].memory, priority,
+                                         errp)) {
+        return;
+    }
+
+    dev->mmio[mmio].addr = addr;
+}
+
 void sysbus_mmio_unmap(SysBusDevice *dev, int n)
 {
     assert(n >= 0 && n < dev->num_mmio);
-- 
2.36.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-24 13:48 [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Damien Hedde
                   ` (2 preceding siblings ...)
  2022-05-24 13:48 ` [RFC PATCH v5 3/3] add sysbus-mmio-map qapi command Damien Hedde
@ 2022-05-24 17:44 ` Mark Cave-Ayland
  2022-05-25  9:51   ` Damien Hedde
  3 siblings, 1 reply; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-05-24 17:44 UTC (permalink / raw)
  To: Damien Hedde, qemu-devel
  Cc: Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell

On 24/05/2022 14:48, Damien Hedde wrote:

> 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: <20220519153402.41540-1-damien.hedde@greensocs.com>
>      ( 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(-)

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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-24 17:44 ` [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Mark Cave-Ayland
@ 2022-05-25  9:51   ` Damien Hedde
  2022-05-25 11:45     ` Peter Maydell
  0 siblings, 1 reply; 19+ messages in thread
From: Damien Hedde @ 2022-05-25  9:51 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel
  Cc: Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, Peter Maydell



On 5/24/22 19:44, Mark Cave-Ayland wrote:
> On 24/05/2022 14:48, Damien Hedde wrote:
> 
>> 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: <20220519153402.41540-1-damien.hedde@greensocs.com>
>>      ( 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(-)
> 
> 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.

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).

> 
> 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.

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 ?).

> 
> 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.

Here's a typical example of commands to create and connect an uart (here 
"plic" is the id of the interrupt controller created before):
 > device_add driver=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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-25  9:51   ` Damien Hedde
@ 2022-05-25 11:45     ` Peter Maydell
  2022-05-25 13:32       ` Damien Hedde
  2022-05-25 19:20       ` Mark Cave-Ayland
  0 siblings, 2 replies; 19+ messages in thread
From: Peter Maydell @ 2022-05-25 11:45 UTC (permalink / raw)
  To: Damien Hedde
  Cc: Mark Cave-Ayland, qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster

On Wed, 25 May 2022 at 10:51, Damien Hedde <damien.hedde@greensocs.com> wrote:
> On 5/24/22 19:44, Mark Cave-Ayland wrote:
> > 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.
>
> 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).

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.

> 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.

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-25 11:45     ` Peter Maydell
@ 2022-05-25 13:32       ` Damien Hedde
  2022-05-25 19:20       ` Mark Cave-Ayland
  1 sibling, 0 replies; 19+ messages in thread
From: Damien Hedde @ 2022-05-25 13:32 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Mark Cave-Ayland, qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster

On 5/25/22 13:45, Peter Maydell wrote:
> On Wed, 25 May 2022 at 10:51, Damien Hedde <damien.hedde@greensocs.com> wrote:
>> On 5/24/22 19:44, Mark Cave-Ayland wrote:
>>> 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.
>>
>> 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).
> 
> 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.

"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.

> 
>> 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.
> 
> 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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-25 11:45     ` Peter Maydell
  2022-05-25 13:32       ` Damien Hedde
@ 2022-05-25 19:20       ` Mark Cave-Ayland
  2022-05-30  9:50         ` Damien Hedde
  1 sibling, 1 reply; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-05-25 19:20 UTC (permalink / raw)
  To: Peter Maydell, Damien Hedde
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster

On 25/05/2022 12:45, Peter Maydell wrote:

> On Wed, 25 May 2022 at 10:51, Damien Hedde <damien.hedde@greensocs.com> wrote:
>> On 5/24/22 19:44, Mark Cave-Ayland wrote:
>>> 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.
>>
>> 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).
> 
> 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.

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?

> 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?

>> 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.
> 
> 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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-25 19:20       ` Mark Cave-Ayland
@ 2022-05-30  9:50         ` Damien Hedde
  2022-05-30 10:25           ` Peter Maydell
  0 siblings, 1 reply; 19+ messages in thread
From: Damien Hedde @ 2022-05-30  9:50 UTC (permalink / raw)
  To: Mark Cave-Ayland, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton


On 5/25/22 21:20, Mark Cave-Ayland wrote:
> On 25/05/2022 12:45, Peter Maydell wrote:
> 
>> On Wed, 25 May 2022 at 10:51, Damien Hedde 
>> <damien.hedde@greensocs.com> wrote:
>>> On 5/24/22 19:44, Mark Cave-Ayland wrote:
>>>> 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.
>>>
>>> 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).
>>
>> 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.
> 
> 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

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.

> 
>     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?

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 ?

> 
>> 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?
> 
>>> 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.
>>
>> 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.
--
Damien


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-30  9:50         ` Damien Hedde
@ 2022-05-30 10:25           ` Peter Maydell
  2022-05-30 14:05             ` Damien Hedde
  0 siblings, 1 reply; 19+ messages in thread
From: Peter Maydell @ 2022-05-30 10:25 UTC (permalink / raw)
  To: Damien Hedde
  Cc: Mark Cave-Ayland, qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On Mon, 30 May 2022 at 10:50, Damien Hedde <damien.hedde@greensocs.com> wrote:
> 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.

Yes, the missing reset support in TYPE_DEVICE is a design
flaw that we really should try to address.

> 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 ?

There would be none, and the idea would be to get rid of
TYPE_SYS_BUS_DEVICE entirely...

-- PMM


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-30 10:25           ` Peter Maydell
@ 2022-05-30 14:05             ` Damien Hedde
  2022-05-31  8:00               ` Mark Cave-Ayland
  0 siblings, 1 reply; 19+ messages in thread
From: Damien Hedde @ 2022-05-30 14:05 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Mark Cave-Ayland, qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton


On 5/30/22 12:25, Peter Maydell wrote:
> On Mon, 30 May 2022 at 10:50, Damien Hedde <damien.hedde@greensocs.com> wrote:
>> 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.
> 
> Yes, the missing reset support in TYPE_DEVICE is a design
> flaw that we really should try to address.
> 
>> 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 ?
> 
> There would be none, and the idea would be to get rid of
> TYPE_SYS_BUS_DEVICE entirely...
> 

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)

 > device_add driver=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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-30 14:05             ` Damien Hedde
@ 2022-05-31  8:00               ` Mark Cave-Ayland
  2022-05-31  9:22                 ` Damien Hedde
  0 siblings, 1 reply; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-05-31  8:00 UTC (permalink / raw)
  To: Damien Hedde, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On 30/05/2022 15:05, Damien Hedde wrote:

> On 5/30/22 12:25, Peter Maydell wrote:
>> On Mon, 30 May 2022 at 10:50, Damien Hedde <damien.hedde@greensocs.com> wrote:
>>> 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.
>>
>> Yes, the missing reset support in TYPE_DEVICE is 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.

>>> 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 ?
>>
>> There would be none, and the idea would be to get rid of
>> TYPE_SYS_BUS_DEVICE entirely...
>>
> 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.

> 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_add driver=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.

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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-31  8:00               ` Mark Cave-Ayland
@ 2022-05-31  9:22                 ` Damien Hedde
  2022-05-31 20:43                   ` Mark Cave-Ayland
  0 siblings, 1 reply; 19+ messages in thread
From: Damien Hedde @ 2022-05-31  9:22 UTC (permalink / raw)
  To: Mark Cave-Ayland, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton



On 5/31/22 10:00, Mark Cave-Ayland wrote:
> On 30/05/2022 15:05, Damien Hedde wrote:
> 
>> On 5/30/22 12:25, Peter Maydell wrote:
>>> On Mon, 30 May 2022 at 10:50, Damien Hedde 
>>> <damien.hedde@greensocs.com> wrote:
>>>> 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.
>>>
>>> Yes, the missing reset support in TYPE_DEVICE is 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.

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 ?

> 
>>>> 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 ?
>>>
>>> There would be none, and the idea would be to get rid of
>>> TYPE_SYS_BUS_DEVICE entirely...
>>>
>> 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.

> 
>> 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_add driver=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.
> 
> 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?
> 

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-31  9:22                 ` Damien Hedde
@ 2022-05-31 20:43                   ` Mark Cave-Ayland
  2022-06-01  8:39                     ` Damien Hedde
  0 siblings, 1 reply; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-05-31 20:43 UTC (permalink / raw)
  To: Damien Hedde, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On 31/05/2022 10:22, Damien Hedde wrote:

> On 5/31/22 10:00, Mark Cave-Ayland wrote:
>> On 30/05/2022 15:05, Damien Hedde wrote:
>>
>>> On 5/30/22 12:25, Peter Maydell wrote:
>>>> On Mon, 30 May 2022 at 10:50, Damien Hedde <damien.hedde@greensocs.com> wrote:
>>>>> 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.
>>>>
>>>> Yes, the missing reset support in TYPE_DEVICE is 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.
> 
> 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 ?

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.

>>>>> 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 ?
>>>>
>>>> There would be none, and the idea would be to get rid of
>>>> TYPE_SYS_BUS_DEVICE entirely...
>>>>
>>> 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.
> 
>>
>>> 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_add driver=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.
>>
>> 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?
>>
> 
> 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.

I'm not sure I understand what you are saying here? Can you give an example?


ATB,

Mark.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-05-31 20:43                   ` Mark Cave-Ayland
@ 2022-06-01  8:39                     ` Damien Hedde
  2022-06-01  9:07                       ` David Hildenbrand
  2022-06-01 10:36                       ` Mark Cave-Ayland
  0 siblings, 2 replies; 19+ messages in thread
From: Damien Hedde @ 2022-06-01  8:39 UTC (permalink / raw)
  To: Mark Cave-Ayland, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton



On 5/31/22 22:43, Mark Cave-Ayland wrote:
> On 31/05/2022 10:22, Damien Hedde wrote:
> 
>> On 5/31/22 10:00, Mark Cave-Ayland wrote:
>>> On 30/05/2022 15:05, Damien Hedde wrote:
>>>
>>>> On 5/30/22 12:25, Peter Maydell wrote:
>>>>> On Mon, 30 May 2022 at 10:50, Damien Hedde 
>>>>> <damien.hedde@greensocs.com> wrote:
>>>>>> 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.
>>>>>
>>>>> Yes, the missing reset support in TYPE_DEVICE is 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.
>>
>> 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 ?
> 
> 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.
> 
>>>>>> 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 ?
>>>>>
>>>>> There would be none, and the idea would be to get rid of
>>>>> TYPE_SYS_BUS_DEVICE entirely...
>>>>>
>>>> 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.
>>
>>>
>>>> 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_add driver=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.
>>>
>>> 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?
>>>
>>
>> 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.
> 
> I'm not sure I understand what you are saying here? Can you give an 
> example?

There are 2 possible workflows:
1. several commands
 > device_add ...
 > device_map ...
 > device_connect ...

2. single command
 > 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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-06-01  8:39                     ` Damien Hedde
@ 2022-06-01  9:07                       ` David Hildenbrand
  2022-06-01 10:45                         ` Mark Cave-Ayland
  2022-06-01 10:36                       ` Mark Cave-Ayland
  1 sibling, 1 reply; 19+ messages in thread
From: David Hildenbrand @ 2022-06-01  9:07 UTC (permalink / raw)
  To: Damien Hedde, Mark Cave-Ayland, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	Alistair Francis, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Paolo Bonzini, Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On 01.06.22 10:39, Damien Hedde wrote:
> 
> 
> On 5/31/22 22:43, Mark Cave-Ayland wrote:
>> On 31/05/2022 10:22, Damien Hedde wrote:
>>
>>> On 5/31/22 10:00, Mark Cave-Ayland wrote:
>>>> On 30/05/2022 15:05, Damien Hedde wrote:
>>>>
>>>>> On 5/30/22 12:25, Peter Maydell wrote:
>>>>>> On Mon, 30 May 2022 at 10:50, Damien Hedde 
>>>>>> <damien.hedde@greensocs.com> wrote:
>>>>>>> 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.
>>>>>>
>>>>>> Yes, the missing reset support in TYPE_DEVICE is 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.
>>>
>>> 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 ?
>>
>> 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.
>>
>>>>>>> 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 ?
>>>>>>
>>>>>> There would be none, and the idea would be to get rid of
>>>>>> TYPE_SYS_BUS_DEVICE entirely...
>>>>>>
>>>>> 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.
>>>
>>>>
>>>>> 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_add driver=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.
>>>>
>>>> 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?
>>>>
>>>
>>> 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.
>>
>> I'm not sure I understand what you are saying here? Can you give an 
>> example?
> 
> There are 2 possible workflows:
> 1. several commands
>  > device_add ...
>  > device_map ...
>  > device_connect ...
> 
> 2. single command
>  > 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).

Can't we flag devices for which map/connect is supported in the device
class somehow?


-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-06-01  8:39                     ` Damien Hedde
  2022-06-01  9:07                       ` David Hildenbrand
@ 2022-06-01 10:36                       ` Mark Cave-Ayland
  1 sibling, 0 replies; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-06-01 10:36 UTC (permalink / raw)
  To: Damien Hedde, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	David Hildenbrand, Alistair Francis, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Paolo Bonzini,
	Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On 01/06/2022 09:39, Damien Hedde wrote:

> On 5/31/22 22:43, Mark Cave-Ayland wrote:
>> On 31/05/2022 10:22, Damien Hedde wrote:
>>
>>> On 5/31/22 10:00, Mark Cave-Ayland wrote:
>>>> On 30/05/2022 15:05, Damien Hedde wrote:
>>>>
>>>>> On 5/30/22 12:25, Peter Maydell wrote:
>>>>>> On Mon, 30 May 2022 at 10:50, Damien Hedde <damien.hedde@greensocs.com> wrote:
>>>>>>> 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.
>>>>>>
>>>>>> Yes, the missing reset support in TYPE_DEVICE is 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.
>>>
>>> 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 ?
>>
>> 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.
>>
>>>>>>> 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 ?
>>>>>>
>>>>>> There would be none, and the idea would be to get rid of
>>>>>> TYPE_SYS_BUS_DEVICE entirely...
>>>>>>
>>>>> 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.
>>>
>>>>
>>>>> 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_add driver=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.
>>>>
>>>> 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?
>>>>
>>>
>>> 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.
>>
>> I'm not sure I understand what you are saying here? Can you give an example?
> 
> There are 2 possible workflows:
> 1. several commands
>  > device_add ...
>  > device_map ...
>  > device_connect ...
> 
> 2. single command
>  > 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).

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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support
  2022-06-01  9:07                       ` David Hildenbrand
@ 2022-06-01 10:45                         ` Mark Cave-Ayland
  0 siblings, 0 replies; 19+ messages in thread
From: Mark Cave-Ayland @ 2022-06-01 10:45 UTC (permalink / raw)
  To: David Hildenbrand, Damien Hedde, Peter Maydell
  Cc: qemu-devel, Philippe Mathieu-Daudé,
	Alistair Francis, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
	Paolo Bonzini, Daniel P. Berrangé,
	Peter Xu, Eric Blake, Markus Armbruster, edgar E. Iglesias,
	Mark Burton

On 01/06/2022 10:07, David Hildenbrand wrote:

> On 01.06.22 10:39, Damien Hedde wrote:
>>
>>
>> On 5/31/22 22:43, Mark Cave-Ayland wrote:
>>> On 31/05/2022 10:22, Damien Hedde wrote:
>>>
>>>> On 5/31/22 10:00, Mark Cave-Ayland wrote:
>>>>> On 30/05/2022 15:05, Damien Hedde wrote:
>>>>>
>>>>>> On 5/30/22 12:25, Peter Maydell wrote:
>>>>>>> On Mon, 30 May 2022 at 10:50, Damien Hedde
>>>>>>> <damien.hedde@greensocs.com> wrote:
>>>>>>>> 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.
>>>>>>>
>>>>>>> Yes, the missing reset support in TYPE_DEVICE is 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.
>>>>
>>>> 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 ?
>>>
>>> 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.
>>>
>>>>>>>> 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 ?
>>>>>>>
>>>>>>> There would be none, and the idea would be to get rid of
>>>>>>> TYPE_SYS_BUS_DEVICE entirely...
>>>>>>>
>>>>>> 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.
>>>>
>>>>>
>>>>>> 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_add driver=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.
>>>>>
>>>>> 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?
>>>>>
>>>>
>>>> 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.
>>>
>>> I'm not sure I understand what you are saying here? Can you give an
>>> example?
>>
>> There are 2 possible workflows:
>> 1. several commands
>>   > device_add ...
>>   > device_map ...
>>   > device_connect ...
>>
>> 2. single command
>>   > 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).
> 
> 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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-06-01 11:21 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 13:48 [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Damien Hedde
2022-05-24 13:48 ` [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices Damien Hedde
2022-05-24 13:48 ` [RFC PATCH v5 2/3] softmmu/memory: add memory_region_try_add_subregion function Damien Hedde
2022-05-24 13:48 ` [RFC PATCH v5 3/3] add sysbus-mmio-map qapi command Damien Hedde
2022-05-24 17:44 ` [RFC PATCH v5 0/3] Sysbus device generic QAPI plug support Mark Cave-Ayland
2022-05-25  9:51   ` Damien Hedde
2022-05-25 11:45     ` Peter Maydell
2022-05-25 13:32       ` Damien Hedde
2022-05-25 19:20       ` Mark Cave-Ayland
2022-05-30  9:50         ` Damien Hedde
2022-05-30 10:25           ` Peter Maydell
2022-05-30 14:05             ` Damien Hedde
2022-05-31  8:00               ` Mark Cave-Ayland
2022-05-31  9:22                 ` Damien Hedde
2022-05-31 20:43                   ` Mark Cave-Ayland
2022-06-01  8:39                     ` Damien Hedde
2022-06-01  9:07                       ` David Hildenbrand
2022-06-01 10:45                         ` Mark Cave-Ayland
2022-06-01 10:36                       ` Mark Cave-Ayland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.