1aae9460eSPaul Brook #ifndef HW_SYSBUS_H 2aae9460eSPaul Brook #define HW_SYSBUS_H 1 3aae9460eSPaul Brook 4aae9460eSPaul Brook /* Devices attached directly to the main system bus. */ 5aae9460eSPaul Brook 683c9f4caSPaolo Bonzini #include "hw/qdev.h" 7022c62cbSPaolo Bonzini #include "exec/memory.h" 8aae9460eSPaul Brook 9f40070c3SBlue Swirl #define QDEV_MAX_MMIO 32 10c646f74fSGleb Natapov #define QDEV_MAX_PIO 32 11aae9460eSPaul Brook 120d936928SAnthony Liguori #define TYPE_SYSTEM_BUS "System" 13*00c2275cSGonglei #define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS) 140d936928SAnthony Liguori 15aae9460eSPaul Brook typedef struct SysBusDevice SysBusDevice; 16aae9460eSPaul Brook 17999e12bbSAnthony Liguori #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 18999e12bbSAnthony Liguori #define SYS_BUS_DEVICE(obj) \ 19999e12bbSAnthony Liguori OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE) 20999e12bbSAnthony Liguori #define SYS_BUS_DEVICE_CLASS(klass) \ 21999e12bbSAnthony Liguori OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE) 22999e12bbSAnthony Liguori #define SYS_BUS_DEVICE_GET_CLASS(obj) \ 23999e12bbSAnthony Liguori OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE) 24999e12bbSAnthony Liguori 25ce724398SHu Tao /** 26ce724398SHu Tao * SysBusDeviceClass: 27ce724398SHu Tao * @init: Callback function invoked when the #DeviceState.realized property 28ce724398SHu Tao * is changed to %true. Deprecated, new types inheriting directly from 29ce724398SHu Tao * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf 30ce724398SHu Tao * types should consult their respective parent type. 31ce724398SHu Tao * 32ce724398SHu Tao * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 33ce724398SHu Tao * classes overriding it are not required to invoke its implementation. 34ce724398SHu Tao */ 35b5917219SPeter Crosthwaite 36b5917219SPeter Crosthwaite #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq" 37b5917219SPeter Crosthwaite 38999e12bbSAnthony Liguori typedef struct SysBusDeviceClass { 39ce724398SHu Tao /*< private >*/ 40999e12bbSAnthony Liguori DeviceClass parent_class; 41ce724398SHu Tao /*< public >*/ 42999e12bbSAnthony Liguori 43999e12bbSAnthony Liguori int (*init)(SysBusDevice *dev); 44999e12bbSAnthony Liguori } SysBusDeviceClass; 45999e12bbSAnthony Liguori 46aae9460eSPaul Brook struct SysBusDevice { 47b67964d7SAndreas Färber /*< private >*/ 48b67964d7SAndreas Färber DeviceState parent_obj; 49b67964d7SAndreas Färber /*< public >*/ 50b67964d7SAndreas Färber 51aae9460eSPaul Brook int num_mmio; 52aae9460eSPaul Brook struct { 53a8170e5eSAvi Kivity hwaddr addr; 54ec3bb837SAvi Kivity MemoryRegion *memory; 55aae9460eSPaul Brook } mmio[QDEV_MAX_MMIO]; 56c646f74fSGleb Natapov int num_pio; 57c646f74fSGleb Natapov pio_addr_t pio[QDEV_MAX_PIO]; 58aae9460eSPaul Brook }; 59aae9460eSPaul Brook 60750ecd44SAvi Kivity void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 6146c305efSPeter Maydell MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 62aae9460eSPaul Brook void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 63aae9460eSPaul Brook void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 64c646f74fSGleb Natapov void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size); 65aae9460eSPaul Brook 66aae9460eSPaul Brook 67aae9460eSPaul Brook void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 68a8170e5eSAvi Kivity void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 697feb640cSAlexey Korolev void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 70a1ff8ae0SMarcel Apfelbaum int priority); 71a8170e5eSAvi Kivity void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 722b985d9cSAvi Kivity MemoryRegion *mem); 7362ec4832SAvi Kivity MemoryRegion *sysbus_address_space(SysBusDevice *dev); 74aae9460eSPaul Brook 75aae9460eSPaul Brook /* Legacy helper function for creating devices. */ 76aae9460eSPaul Brook DeviceState *sysbus_create_varargs(const char *name, 77a8170e5eSAvi Kivity hwaddr addr, ...); 784912371fSBlue Swirl DeviceState *sysbus_try_create_varargs(const char *name, 79a8170e5eSAvi Kivity hwaddr addr, ...); 80aae9460eSPaul Brook static inline DeviceState *sysbus_create_simple(const char *name, 81a8170e5eSAvi Kivity hwaddr addr, 82aae9460eSPaul Brook qemu_irq irq) 83aae9460eSPaul Brook { 84aae9460eSPaul Brook return sysbus_create_varargs(name, addr, irq, NULL); 85aae9460eSPaul Brook } 86aae9460eSPaul Brook 874912371fSBlue Swirl static inline DeviceState *sysbus_try_create_simple(const char *name, 88a8170e5eSAvi Kivity hwaddr addr, 894912371fSBlue Swirl qemu_irq irq) 904912371fSBlue Swirl { 914912371fSBlue Swirl return sysbus_try_create_varargs(name, addr, irq, NULL); 924912371fSBlue Swirl } 934912371fSBlue Swirl 94aae9460eSPaul Brook #endif /* !HW_SYSBUS_H */ 95