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 11ea0e6841SEvgeny Voevodin #define QDEV_MAX_IRQ 512 12aae9460eSPaul Brook 130d936928SAnthony Liguori #define TYPE_SYSTEM_BUS "System" 140d936928SAnthony Liguori #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS) 150d936928SAnthony Liguori 16aae9460eSPaul Brook typedef struct SysBusDevice SysBusDevice; 17aae9460eSPaul Brook 18999e12bbSAnthony Liguori #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 19999e12bbSAnthony Liguori #define SYS_BUS_DEVICE(obj) \ 20999e12bbSAnthony Liguori OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE) 21999e12bbSAnthony Liguori #define SYS_BUS_DEVICE_CLASS(klass) \ 22999e12bbSAnthony Liguori OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE) 23999e12bbSAnthony Liguori #define SYS_BUS_DEVICE_GET_CLASS(obj) \ 24999e12bbSAnthony Liguori OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE) 25999e12bbSAnthony Liguori 26*ce724398SHu Tao /** 27*ce724398SHu Tao * SysBusDeviceClass: 28*ce724398SHu Tao * @init: Callback function invoked when the #DeviceState.realized property 29*ce724398SHu Tao * is changed to %true. Deprecated, new types inheriting directly from 30*ce724398SHu Tao * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf 31*ce724398SHu Tao * types should consult their respective parent type. 32*ce724398SHu Tao * 33*ce724398SHu Tao * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 34*ce724398SHu Tao * classes overriding it are not required to invoke its implementation. 35*ce724398SHu Tao */ 36999e12bbSAnthony Liguori typedef struct SysBusDeviceClass { 37*ce724398SHu Tao /*< private >*/ 38999e12bbSAnthony Liguori DeviceClass parent_class; 39*ce724398SHu Tao /*< public >*/ 40999e12bbSAnthony Liguori 41999e12bbSAnthony Liguori int (*init)(SysBusDevice *dev); 42999e12bbSAnthony Liguori } SysBusDeviceClass; 43999e12bbSAnthony Liguori 44aae9460eSPaul Brook struct SysBusDevice { 45aae9460eSPaul Brook DeviceState qdev; 46aae9460eSPaul Brook int num_irq; 47aae9460eSPaul Brook qemu_irq irqs[QDEV_MAX_IRQ]; 48aae9460eSPaul Brook qemu_irq *irqp[QDEV_MAX_IRQ]; 49aae9460eSPaul Brook int num_mmio; 50aae9460eSPaul Brook struct { 51a8170e5eSAvi Kivity hwaddr addr; 52ec3bb837SAvi Kivity MemoryRegion *memory; 53aae9460eSPaul Brook } mmio[QDEV_MAX_MMIO]; 54c646f74fSGleb Natapov int num_pio; 55c646f74fSGleb Natapov pio_addr_t pio[QDEV_MAX_PIO]; 56aae9460eSPaul Brook }; 57aae9460eSPaul Brook 58aae9460eSPaul Brook /* Macros to compensate for lack of type inheritance in C. */ 59aae9460eSPaul Brook #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev) 60aae9460eSPaul Brook 61aae9460eSPaul Brook void *sysbus_new(void); 62750ecd44SAvi Kivity void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 6346c305efSPeter Maydell MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 64aae9460eSPaul Brook void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 65aae9460eSPaul Brook void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 66c646f74fSGleb Natapov void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size); 67aae9460eSPaul Brook 68aae9460eSPaul Brook 69aae9460eSPaul Brook void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 70a8170e5eSAvi Kivity void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 717feb640cSAlexey Korolev void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 727feb640cSAlexey Korolev unsigned priority); 73a8170e5eSAvi Kivity void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 742b985d9cSAvi Kivity MemoryRegion *mem); 752b985d9cSAvi Kivity void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem); 7662ec4832SAvi Kivity MemoryRegion *sysbus_address_space(SysBusDevice *dev); 77aae9460eSPaul Brook 78aae9460eSPaul Brook /* Legacy helper function for creating devices. */ 79aae9460eSPaul Brook DeviceState *sysbus_create_varargs(const char *name, 80a8170e5eSAvi Kivity hwaddr addr, ...); 814912371fSBlue Swirl DeviceState *sysbus_try_create_varargs(const char *name, 82a8170e5eSAvi Kivity hwaddr addr, ...); 83aae9460eSPaul Brook static inline DeviceState *sysbus_create_simple(const char *name, 84a8170e5eSAvi Kivity hwaddr addr, 85aae9460eSPaul Brook qemu_irq irq) 86aae9460eSPaul Brook { 87aae9460eSPaul Brook return sysbus_create_varargs(name, addr, irq, NULL); 88aae9460eSPaul Brook } 89aae9460eSPaul Brook 904912371fSBlue Swirl static inline DeviceState *sysbus_try_create_simple(const char *name, 91a8170e5eSAvi Kivity hwaddr addr, 924912371fSBlue Swirl qemu_irq irq) 934912371fSBlue Swirl { 944912371fSBlue Swirl return sysbus_try_create_varargs(name, addr, irq, NULL); 954912371fSBlue Swirl } 964912371fSBlue Swirl 97aae9460eSPaul Brook #endif /* !HW_SYSBUS_H */ 98