mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
Add device listener interface
The Xen ioreq-server API, introduced in Xen 4.5, requires that PCI device models explicitly register with Xen for config space accesses. This patch adds a listener interface into qdev-core which can be used by the Xen interface code to monitor for arrival and departure of PCI devices. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
74acb99737
commit
707ff80021
3 changed files with 64 additions and 0 deletions
|
@ -189,6 +189,56 @@ int qdev_init(DeviceState *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static QTAILQ_HEAD(device_listeners, DeviceListener) device_listeners
|
||||
= QTAILQ_HEAD_INITIALIZER(device_listeners);
|
||||
|
||||
enum ListenerDirection { Forward, Reverse };
|
||||
|
||||
#define DEVICE_LISTENER_CALL(_callback, _direction, _args...) \
|
||||
do { \
|
||||
DeviceListener *_listener; \
|
||||
\
|
||||
switch (_direction) { \
|
||||
case Forward: \
|
||||
QTAILQ_FOREACH(_listener, &device_listeners, link) { \
|
||||
if (_listener->_callback) { \
|
||||
_listener->_callback(_listener, ##_args); \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
case Reverse: \
|
||||
QTAILQ_FOREACH_REVERSE(_listener, &device_listeners, \
|
||||
device_listeners, link) { \
|
||||
if (_listener->_callback) { \
|
||||
_listener->_callback(_listener, ##_args); \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
default: \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int device_listener_add(DeviceState *dev, void *opaque)
|
||||
{
|
||||
DEVICE_LISTENER_CALL(realize, Forward, dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void device_listener_register(DeviceListener *listener)
|
||||
{
|
||||
QTAILQ_INSERT_TAIL(&device_listeners, listener, link);
|
||||
|
||||
qbus_walk_children(sysbus_get_default(), NULL, NULL, device_listener_add,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
void device_listener_unregister(DeviceListener *listener)
|
||||
{
|
||||
QTAILQ_REMOVE(&device_listeners, listener, link);
|
||||
}
|
||||
|
||||
static void device_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
DeviceClass *dc = DEVICE_GET_CLASS(dev);
|
||||
|
@ -994,6 +1044,8 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
DEVICE_LISTENER_CALL(realize, Forward, dev);
|
||||
|
||||
hotplug_ctrl = qdev_get_hotplug_handler(dev);
|
||||
if (hotplug_ctrl) {
|
||||
hotplug_handler_plug(hotplug_ctrl, dev, &local_err);
|
||||
|
@ -1035,6 +1087,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
|
|||
dc->unrealize(dev, local_errp);
|
||||
}
|
||||
dev->pending_deleted_event = true;
|
||||
DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
|
||||
}
|
||||
|
||||
if (local_err != NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue