qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

sysbus: New sysbus_realize(), sysbus_realize_and_unref()

Sysbus devices almost always plug into the main system bus.
qdev_create() even has a convenience feature to make that easy: a null
bus argument gets replaced by the main system bus. qdev_realize() and
qdev_realize_and_unref() do the same.

We can do better. Provide convenience wrappers around qdev_realize()
and qdev_realize_and_unref() that don't take a @bus argument. They
always pass the main system bus.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-45-armbru@redhat.com>

+15 -3
+12 -2
hw/core/sysbus.c
··· 217 217 * from being set to NULL to break the normal init/realize 218 218 * of some devices. 219 219 */ 220 - static void sysbus_realize(DeviceState *dev, Error **errp) 220 + static void sysbus_device_realize(DeviceState *dev, Error **errp) 221 221 { 222 222 } 223 223 ··· 248 248 } 249 249 va_end(va); 250 250 return dev; 251 + } 252 + 253 + bool sysbus_realize(SysBusDevice *dev, Error **errp) 254 + { 255 + return qdev_realize(DEVICE(dev), sysbus_get_default(), errp); 256 + } 257 + 258 + bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp) 259 + { 260 + return qdev_realize_and_unref(DEVICE(dev), sysbus_get_default(), errp); 251 261 } 252 262 253 263 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent) ··· 301 311 static void sysbus_device_class_init(ObjectClass *klass, void *data) 302 312 { 303 313 DeviceClass *k = DEVICE_CLASS(klass); 304 - k->realize = sysbus_realize; 314 + k->realize = sysbus_device_realize; 305 315 k->bus_type = TYPE_SYSTEM_BUS; 306 316 /* 307 317 * device_add plugs devices into a suitable bus. For "real" buses,
+3 -1
include/hw/sysbus.h
··· 90 90 MemoryRegion *mem); 91 91 MemoryRegion *sysbus_address_space(SysBusDevice *dev); 92 92 93 + bool sysbus_realize(SysBusDevice *dev, Error **errp); 94 + bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp); 95 + 93 96 /** 94 97 * sysbus_init_child_obj: 95 98 * @parent: The parent object ··· 120 123 { 121 124 return sysbus_create_varargs(name, addr, irq, NULL); 122 125 } 123 - 124 126 125 127 #endif /* HW_SYSBUS_H */