Skip to content

Commit 1518562

Browse files
committed
qdev: Support marking individual buses as 'full'
By default, QEMU will allow devices to be plugged into a bus up to the bus class's device count limit. If the user creates a device on the command line or via the monitor and doesn't explicitly specify the bus to plug it in, QEMU will plug it into the first non-full bus that it finds. This is fine in most cases, but some machines have multiple buses of a given type, some of which are dedicated to on-board devices and some of which have an externally exposed connector for user-pluggable devices. One example is I2C buses. Provide a new function qbus_mark_full() so that a machine model can mark this kind of "internal only" bus as 'full' after it has created all the devices that should be plugged into that bus. The "find a non-full bus" algorithm will then skip the internal-only bus when looking for a place to plug in user-created devices. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-id: [email protected]
1 parent bc7edcc commit 1518562

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

include/hw/qdev-core.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct BusState {
264264
HotplugHandler *hotplug_handler;
265265
int max_index;
266266
bool realized;
267+
bool full;
267268
int num_children;
268269

269270
/*
@@ -798,6 +799,29 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
798799
return bus->hotplug_handler;
799800
}
800801

802+
/**
803+
* qbus_mark_full: Mark this bus as full, so no more devices can be attached
804+
* @bus: Bus to mark as full
805+
*
806+
* By default, QEMU will allow devices to be plugged into a bus up
807+
* to the bus class's device count limit. Calling this function
808+
* marks a particular bus as full, so that no more devices can be
809+
* plugged into it. In particular this means that the bus will not
810+
* be considered as a candidate for plugging in devices created by
811+
* the user on the commandline or via the monitor.
812+
* If a machine has multiple buses of a given type, such as I2C,
813+
* where some of those buses in the real hardware are used only for
814+
* internal devices and some are exposed via expansion ports, you
815+
* can use this function to mark the internal-only buses as full
816+
* after you have created all their internal devices. Then user
817+
* created devices will appear on the expansion-port bus where
818+
* guest software expects them.
819+
*/
820+
static inline void qbus_mark_full(BusState *bus)
821+
{
822+
bus->full = true;
823+
}
824+
801825
void device_listener_register(DeviceListener *listener);
802826
void device_listener_unregister(DeviceListener *listener);
803827

softmmu/qdev-monitor.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
435435

436436
static inline bool qbus_is_full(BusState *bus)
437437
{
438-
BusClass *bus_class = BUS_GET_CLASS(bus);
438+
BusClass *bus_class;
439+
440+
if (bus->full) {
441+
return true;
442+
}
443+
bus_class = BUS_GET_CLASS(bus);
439444
return bus_class->max_dev && bus->num_children >= bus_class->max_dev;
440445
}
441446

0 commit comments

Comments
 (0)