10d09e41aSPaolo Bonzini #ifndef HW_SYSBUS_H 2175de524SMarkus Armbruster #define HW_SYSBUS_H 30d09e41aSPaolo Bonzini 40d09e41aSPaolo Bonzini /* Devices attached directly to the main system bus. */ 50d09e41aSPaolo Bonzini 6a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 70d09e41aSPaolo Bonzini #include "exec/memory.h" 8*db1015e9SEduardo Habkost #include "qom/object.h" 90d09e41aSPaolo Bonzini 100d09e41aSPaolo Bonzini #define QDEV_MAX_MMIO 32 110d09e41aSPaolo Bonzini #define QDEV_MAX_PIO 32 120d09e41aSPaolo Bonzini 130d09e41aSPaolo Bonzini #define TYPE_SYSTEM_BUS "System" 1400c2275cSGonglei #define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS) 150d09e41aSPaolo Bonzini 160d09e41aSPaolo Bonzini typedef struct SysBusDevice SysBusDevice; 170d09e41aSPaolo Bonzini 180d09e41aSPaolo Bonzini #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 19*db1015e9SEduardo Habkost typedef struct SysBusDeviceClass SysBusDeviceClass; 200d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE(obj) \ 210d09e41aSPaolo Bonzini OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE) 220d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_CLASS(klass) \ 230d09e41aSPaolo Bonzini OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE) 240d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_GET_CLASS(obj) \ 250d09e41aSPaolo Bonzini OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE) 260d09e41aSPaolo Bonzini 27ce724398SHu Tao /** 28ce724398SHu Tao * SysBusDeviceClass: 29ce724398SHu Tao * 30ce724398SHu Tao * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 31ce724398SHu Tao * classes overriding it are not required to invoke its implementation. 32ce724398SHu Tao */ 33b5917219SPeter Crosthwaite 34b5917219SPeter Crosthwaite #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq" 35b5917219SPeter Crosthwaite 36*db1015e9SEduardo Habkost struct SysBusDeviceClass { 37ce724398SHu Tao /*< private >*/ 380d09e41aSPaolo Bonzini DeviceClass parent_class; 390b336b3bSLaszlo Ersek 400b336b3bSLaszlo Ersek /* 410b336b3bSLaszlo Ersek * Let the sysbus device format its own non-PIO, non-MMIO unit address. 420b336b3bSLaszlo Ersek * 430b336b3bSLaszlo Ersek * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources, 440b336b3bSLaszlo Ersek * yet instances of it would like to distinguish themselves, in 450b336b3bSLaszlo Ersek * OpenFirmware device paths, from other instances of the same class on the 460b336b3bSLaszlo Ersek * sysbus. For that end we expose this callback. 470b336b3bSLaszlo Ersek * 480b336b3bSLaszlo Ersek * The implementation is not supposed to change *@dev, or incur other 490b336b3bSLaszlo Ersek * observable change. 500b336b3bSLaszlo Ersek * 510b336b3bSLaszlo Ersek * The function returns a dynamically allocated string. On error, NULL 520b336b3bSLaszlo Ersek * should be returned; the unit address portion of the OFW node will be 530b336b3bSLaszlo Ersek * omitted then. (This is not considered a fatal error.) 540b336b3bSLaszlo Ersek */ 550b336b3bSLaszlo Ersek char *(*explicit_ofw_unit_address)(const SysBusDevice *dev); 56715ca691SEric Auger void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq); 57*db1015e9SEduardo Habkost }; 580d09e41aSPaolo Bonzini 590d09e41aSPaolo Bonzini struct SysBusDevice { 60b67964d7SAndreas Färber /*< private >*/ 61b67964d7SAndreas Färber DeviceState parent_obj; 62b67964d7SAndreas Färber /*< public >*/ 63b67964d7SAndreas Färber 640d09e41aSPaolo Bonzini int num_mmio; 650d09e41aSPaolo Bonzini struct { 660d09e41aSPaolo Bonzini hwaddr addr; 670d09e41aSPaolo Bonzini MemoryRegion *memory; 680d09e41aSPaolo Bonzini } mmio[QDEV_MAX_MMIO]; 690d09e41aSPaolo Bonzini int num_pio; 7089a80e74SPaolo Bonzini uint32_t pio[QDEV_MAX_PIO]; 710d09e41aSPaolo Bonzini }; 720d09e41aSPaolo Bonzini 734f01a637SDavid Gibson typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); 74eb572280SAlexander Graf 750d09e41aSPaolo Bonzini void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 760d09e41aSPaolo Bonzini MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 770d09e41aSPaolo Bonzini void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 780d09e41aSPaolo Bonzini void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 7989a80e74SPaolo Bonzini void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size); 800d09e41aSPaolo Bonzini 810d09e41aSPaolo Bonzini 82b7973186SAlexander Graf bool sysbus_has_irq(SysBusDevice *dev, int n); 83471a9bc1SAlexander Graf bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n); 840d09e41aSPaolo Bonzini void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 85b7973186SAlexander Graf bool sysbus_is_irq_connected(SysBusDevice *dev, int n); 86b7973186SAlexander Graf qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n); 870d09e41aSPaolo Bonzini void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 880d09e41aSPaolo Bonzini void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 89a1ff8ae0SMarcel Apfelbaum int priority); 9090c20e1eSCédric Le Goater void sysbus_mmio_unmap(SysBusDevice *dev, int n); 910d09e41aSPaolo Bonzini void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 920d09e41aSPaolo Bonzini MemoryRegion *mem); 930d09e41aSPaolo Bonzini MemoryRegion *sysbus_address_space(SysBusDevice *dev); 940d09e41aSPaolo Bonzini 95496a8525SMarkus Armbruster bool sysbus_realize(SysBusDevice *dev, Error **errp); 96496a8525SMarkus Armbruster bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp); 97496a8525SMarkus Armbruster 98eb572280SAlexander Graf /* Call func for every dynamically created sysbus device in the system */ 99eb572280SAlexander Graf void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); 100eb572280SAlexander Graf 1010d09e41aSPaolo Bonzini /* Legacy helper function for creating devices. */ 1020d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name, 1030d09e41aSPaolo Bonzini hwaddr addr, ...); 1047e83a77fSMarc-André Lureau 1050d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name, 1060d09e41aSPaolo Bonzini hwaddr addr, 1070d09e41aSPaolo Bonzini qemu_irq irq) 1080d09e41aSPaolo Bonzini { 1090d09e41aSPaolo Bonzini return sysbus_create_varargs(name, addr, irq, NULL); 1100d09e41aSPaolo Bonzini } 1110d09e41aSPaolo Bonzini 112175de524SMarkus Armbruster #endif /* HW_SYSBUS_H */ 113