We have to be able to plug our platform bus into an existing system somehow. To achieve this, we add a sysbus <-> platbus bridge device that maps an arbitrary number of IRQ lines to a self-contained linear platform IRQ range.
It also provides a memory region that is the parent region for all platform devices that get created below this bus. Signed-off-by: Alexander Graf <ag...@suse.de> --- hw/platbus/bridge.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/platbus/bridge.h | 32 +++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 hw/platbus/bridge.c create mode 100644 include/hw/platbus/bridge.h diff --git a/hw/platbus/bridge.c b/hw/platbus/bridge.c new file mode 100644 index 0000000..356d254 --- /dev/null +++ b/hw/platbus/bridge.c @@ -0,0 +1,64 @@ +/* + * Sysbus to Platform bus bridge device + * + * Copyright 2013 Freescale Semiconductor, Inc. + * + * Authors: Alexander Graf, <ag...@suse.de> + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This bridge device allows you to plug a platform bus into your existing + * system bus. + */ + +#include "qemu-common.h" +#include "hw/platbus/bridge.h" + +static void platbus_bridge_realize(DeviceState *dev, Error **errp) +{ + SysBusDevice *d = SYS_BUS_DEVICE(dev); + PlatBusBridgeState *s = PLATBUS_BRIDGE(dev); + int i; + + /* Create platform bus */ + qbus_create_inplace(&s->bus.parent_obj, TYPE_PLAT_BUS, dev, NULL); + + /* Wire up all platbus IRQs to sysbus IRQs. */ + for (i = 0; i < s->nr_irqs; i++) { + sysbus_init_irq(d, &s->bus.irqs[i]); + platbus_add_irq(&s->bus, i); + } + + /* Advertise our platbus memory hole to sysbus. Through this a guest OS + can access platbus devices */ + sysbus_init_mmio(d, &s->bus.mem); +} + +static Property platbus_bridge_properties[] = { + DEFINE_PROP_UINT32("nr_irqs", PlatBusBridgeState, nr_irqs, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void serial_platbus_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + dc->props = platbus_bridge_properties; + dc->realize = platbus_bridge_realize; +} + +static const TypeInfo platbus_bridge_type_info = { + .name = TYPE_PLATBUS_BRIDGE, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(PlatBusBridgeState), + .class_init = serial_platbus_class_init, +}; + +static void platbus_bridge_register_types(void) +{ + type_register_static(&platbus_bridge_type_info); +} + +type_init(platbus_bridge_register_types) diff --git a/include/hw/platbus/bridge.h b/include/hw/platbus/bridge.h new file mode 100644 index 0000000..4d31fcb --- /dev/null +++ b/include/hw/platbus/bridge.h @@ -0,0 +1,32 @@ +/* + * Generic platform bus with dynamic IRQ and IO placement + * + * Copyright 2013 Freescale Semiconductor, Inc. + * + * Authors: Alexander Graf, <ag...@suse.de> + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef QEMU_HW_PLATBUS_BRIDGE_H +#define QEMU_HW_PLATBUS_BRIDGE_H + +#include "platbus.h" +#include "hw/sysbus.h" + +#define TYPE_PLATBUS_BRIDGE "platbus-bridge" +#define PLATBUS_BRIDGE(obj) OBJECT_CHECK(PlatBusBridgeState, (obj), TYPE_PLATBUS_BRIDGE) + +typedef struct PlatBusBridgeState { + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + + PlatBusState bus; + uint32_t nr_irqs; +} PlatBusBridgeState; + +#endif /* !QEMU_HW_PLATBUS_BRIDGE_H */ -- 1.8.1.4