sysbus: add creation function that may fail
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
parent
86d864140b
commit
4912371fc3
31
hw/sysbus.c
31
hw/sysbus.c
@ -173,6 +173,37 @@ DeviceState *sysbus_create_varargs(const char *name,
|
||||
return dev;
|
||||
}
|
||||
|
||||
DeviceState *sysbus_try_create_varargs(const char *name,
|
||||
target_phys_addr_t addr, ...)
|
||||
{
|
||||
DeviceState *dev;
|
||||
SysBusDevice *s;
|
||||
va_list va;
|
||||
qemu_irq irq;
|
||||
int n;
|
||||
|
||||
dev = qdev_try_create(NULL, name);
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
s = sysbus_from_qdev(dev);
|
||||
qdev_init_nofail(dev);
|
||||
if (addr != (target_phys_addr_t)-1) {
|
||||
sysbus_mmio_map(s, 0, addr);
|
||||
}
|
||||
va_start(va, addr);
|
||||
n = 0;
|
||||
while (1) {
|
||||
irq = va_arg(va, qemu_irq);
|
||||
if (!irq) {
|
||||
break;
|
||||
}
|
||||
sysbus_connect_irq(s, n, irq);
|
||||
n++;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
|
||||
{
|
||||
SysBusDevice *s = sysbus_from_qdev(dev);
|
||||
|
@ -57,6 +57,8 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
|
||||
/* Legacy helper function for creating devices. */
|
||||
DeviceState *sysbus_create_varargs(const char *name,
|
||||
target_phys_addr_t addr, ...);
|
||||
DeviceState *sysbus_try_create_varargs(const char *name,
|
||||
target_phys_addr_t addr, ...);
|
||||
static inline DeviceState *sysbus_create_simple(const char *name,
|
||||
target_phys_addr_t addr,
|
||||
qemu_irq irq)
|
||||
@ -64,4 +66,11 @@ static inline DeviceState *sysbus_create_simple(const char *name,
|
||||
return sysbus_create_varargs(name, addr, irq, NULL);
|
||||
}
|
||||
|
||||
static inline DeviceState *sysbus_try_create_simple(const char *name,
|
||||
target_phys_addr_t addr,
|
||||
qemu_irq irq)
|
||||
{
|
||||
return sysbus_try_create_varargs(name, addr, irq, NULL);
|
||||
}
|
||||
|
||||
#endif /* !HW_SYSBUS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user