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" 8db1015e9SEduardo 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" 148110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(BusState, SYSTEM_BUS, 158110fa1dSEduardo Habkost TYPE_SYSTEM_BUS) 160d09e41aSPaolo Bonzini 170d09e41aSPaolo Bonzini 180d09e41aSPaolo Bonzini #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 19*c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(SysBusDevice, SysBusDeviceClass, 20*c821774aSEduardo Habkost sys_bus_device, SYS_BUS_DEVICE) 210d09e41aSPaolo Bonzini 22ce724398SHu Tao /** 23ce724398SHu Tao * SysBusDeviceClass: 24ce724398SHu Tao * 25ce724398SHu Tao * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 26ce724398SHu Tao * classes overriding it are not required to invoke its implementation. 27ce724398SHu Tao */ 28b5917219SPeter Crosthwaite 29b5917219SPeter Crosthwaite #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq" 30b5917219SPeter Crosthwaite 31db1015e9SEduardo Habkost struct SysBusDeviceClass { 32ce724398SHu Tao /*< private >*/ 330d09e41aSPaolo Bonzini DeviceClass parent_class; 340b336b3bSLaszlo Ersek 350b336b3bSLaszlo Ersek /* 360b336b3bSLaszlo Ersek * Let the sysbus device format its own non-PIO, non-MMIO unit address. 370b336b3bSLaszlo Ersek * 380b336b3bSLaszlo Ersek * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources, 390b336b3bSLaszlo Ersek * yet instances of it would like to distinguish themselves, in 400b336b3bSLaszlo Ersek * OpenFirmware device paths, from other instances of the same class on the 410b336b3bSLaszlo Ersek * sysbus. For that end we expose this callback. 420b336b3bSLaszlo Ersek * 430b336b3bSLaszlo Ersek * The implementation is not supposed to change *@dev, or incur other 440b336b3bSLaszlo Ersek * observable change. 450b336b3bSLaszlo Ersek * 460b336b3bSLaszlo Ersek * The function returns a dynamically allocated string. On error, NULL 470b336b3bSLaszlo Ersek * should be returned; the unit address portion of the OFW node will be 480b336b3bSLaszlo Ersek * omitted then. (This is not considered a fatal error.) 490b336b3bSLaszlo Ersek */ 500b336b3bSLaszlo Ersek char *(*explicit_ofw_unit_address)(const SysBusDevice *dev); 51715ca691SEric Auger void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq); 52db1015e9SEduardo Habkost }; 530d09e41aSPaolo Bonzini 540d09e41aSPaolo Bonzini struct SysBusDevice { 55b67964d7SAndreas Färber /*< private >*/ 56b67964d7SAndreas Färber DeviceState parent_obj; 57b67964d7SAndreas Färber /*< public >*/ 58b67964d7SAndreas Färber 590d09e41aSPaolo Bonzini int num_mmio; 600d09e41aSPaolo Bonzini struct { 610d09e41aSPaolo Bonzini hwaddr addr; 620d09e41aSPaolo Bonzini MemoryRegion *memory; 630d09e41aSPaolo Bonzini } mmio[QDEV_MAX_MMIO]; 640d09e41aSPaolo Bonzini int num_pio; 6589a80e74SPaolo Bonzini uint32_t pio[QDEV_MAX_PIO]; 660d09e41aSPaolo Bonzini }; 670d09e41aSPaolo Bonzini 684f01a637SDavid Gibson typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); 69eb572280SAlexander Graf 700d09e41aSPaolo Bonzini void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 710d09e41aSPaolo Bonzini MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 720d09e41aSPaolo Bonzini void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 730d09e41aSPaolo Bonzini void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 7489a80e74SPaolo Bonzini void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size); 750d09e41aSPaolo Bonzini 760d09e41aSPaolo Bonzini 77b7973186SAlexander Graf bool sysbus_has_irq(SysBusDevice *dev, int n); 78471a9bc1SAlexander Graf bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n); 790d09e41aSPaolo Bonzini void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 80b7973186SAlexander Graf bool sysbus_is_irq_connected(SysBusDevice *dev, int n); 81b7973186SAlexander Graf qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n); 820d09e41aSPaolo Bonzini void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 830d09e41aSPaolo Bonzini void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 84a1ff8ae0SMarcel Apfelbaum int priority); 8590c20e1eSCédric Le Goater void sysbus_mmio_unmap(SysBusDevice *dev, int n); 860d09e41aSPaolo Bonzini void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 870d09e41aSPaolo Bonzini MemoryRegion *mem); 880d09e41aSPaolo Bonzini MemoryRegion *sysbus_address_space(SysBusDevice *dev); 890d09e41aSPaolo Bonzini 90496a8525SMarkus Armbruster bool sysbus_realize(SysBusDevice *dev, Error **errp); 91496a8525SMarkus Armbruster bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp); 92496a8525SMarkus Armbruster 93eb572280SAlexander Graf /* Call func for every dynamically created sysbus device in the system */ 94eb572280SAlexander Graf void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); 95eb572280SAlexander Graf 960d09e41aSPaolo Bonzini /* Legacy helper function for creating devices. */ 970d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name, 980d09e41aSPaolo Bonzini hwaddr addr, ...); 997e83a77fSMarc-André Lureau 1000d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name, 1010d09e41aSPaolo Bonzini hwaddr addr, 1020d09e41aSPaolo Bonzini qemu_irq irq) 1030d09e41aSPaolo Bonzini { 1040d09e41aSPaolo Bonzini return sysbus_create_varargs(name, addr, irq, NULL); 1050d09e41aSPaolo Bonzini } 1060d09e41aSPaolo Bonzini 107175de524SMarkus Armbruster #endif /* HW_SYSBUS_H */ 108