@@ -29,6 +29,13 @@ typedef enum DeviceCategory {
DEVICE_CATEGORY_MAX
} DeviceCategory;
+
+typedef enum DeviceCreationPriority {
+ DEVICE_PRIO_NORMAL,
+ DEVICE_PRIO_BRIDGE,
+ DEVICE_PRIO_HOSTBRIDGE
+} DeviceCreationPriority;
+
typedef int (*qdev_initfn)(DeviceState *dev);
typedef int (*qdev_event)(DeviceState *dev);
typedef void (*qdev_resetfn)(DeviceState *dev);
@@ -139,6 +146,12 @@ typedef struct DeviceClass {
qdev_initfn init; /* TODO remove, once users are converted to realize */
qdev_event exit; /* TODO remove, once users are converted to unrealize */
const char *bus_type;
+
+ /*
+ * Some devices need to be created before others. Devices with higher
+ * priority will be created first.
+ */
+ DeviceCreationPriority creation_priority;
} DeviceClass;
typedef struct NamedGPIOList NamedGPIOList;
@@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
+int qdev_device_get_priority(QemuOpts *opts, Error **errp);
#endif
@@ -626,6 +626,25 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
return dev;
}
+int qdev_device_get_priority(QemuOpts *opts, Error **errp)
+{
+ DeviceClass *dc;
+ const char *driver;
+
+ driver = qemu_opt_get(opts, "driver");
+ if (!driver) {
+ error_setg(errp, QERR_MISSING_PARAMETER, "driver");
+ return -1;
+ }
+
+ /* find driver */
+ dc = qdev_get_device_class(&driver, errp);
+ if (!dc) {
+ return -1;
+ }
+
+ return dc->creation_priority;
+}
#define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)
static void qbus_print(Monitor *mon, BusState *bus, int indent);
Some devices need to be created before others. Add a flag to DeviceClass and the means to query it. Signed-off-by: Marcel Apfelbaum <marcel@redhat.com> --- include/hw/qdev-core.h | 13 +++++++++++++ include/monitor/qdev.h | 1 + qdev-monitor.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+)