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" 14*8110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(BusState, SYSTEM_BUS, 15*8110fa1dSEduardo Habkost TYPE_SYSTEM_BUS) 160d09e41aSPaolo Bonzini 170d09e41aSPaolo Bonzini typedef struct SysBusDevice SysBusDevice; 180d09e41aSPaolo Bonzini 190d09e41aSPaolo Bonzini #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 20db1015e9SEduardo Habkost typedef struct SysBusDeviceClass SysBusDeviceClass; 21*8110fa1dSEduardo Habkost DECLARE_OBJ_CHECKERS(SysBusDevice, SysBusDeviceClass, 22*8110fa1dSEduardo Habkost SYS_BUS_DEVICE, TYPE_SYS_BUS_DEVICE) 230d09e41aSPaolo Bonzini 24ce724398SHu Tao /** 25ce724398SHu Tao * SysBusDeviceClass: 26ce724398SHu Tao * 27ce724398SHu Tao * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 28ce724398SHu Tao * classes overriding it are not required to invoke its implementation. 29ce724398SHu Tao */ 30b5917219SPeter Crosthwaite 31b5917219SPeter Crosthwaite #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq" 32b5917219SPeter Crosthwaite 33db1015e9SEduardo Habkost struct SysBusDeviceClass { 34ce724398SHu Tao /*< private >*/ 350d09e41aSPaolo Bonzini DeviceClass parent_class; 360b336b3bSLaszlo Ersek 370b336b3bSLaszlo Ersek /* 380b336b3bSLaszlo Ersek * Let the sysbus device format its own non-PIO, non-MMIO unit address. 390b336b3bSLaszlo Ersek * 400b336b3bSLaszlo Ersek * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources, 410b336b3bSLaszlo Ersek * yet instances of it would like to distinguish themselves, in 420b336b3bSLaszlo Ersek * OpenFirmware device paths, from other instances of the same class on the 430b336b3bSLaszlo Ersek * sysbus. For that end we expose this callback. 440b336b3bSLaszlo Ersek * 450b336b3bSLaszlo Ersek * The implementation is not supposed to change *@dev, or incur other 460b336b3bSLaszlo Ersek * observable change. 470b336b3bSLaszlo Ersek * 480b336b3bSLaszlo Ersek * The function returns a dynamically allocated string. On error, NULL 490b336b3bSLaszlo Ersek * should be returned; the unit address portion of the OFW node will be 500b336b3bSLaszlo Ersek * omitted then. (This is not considered a fatal error.) 510b336b3bSLaszlo Ersek */ 520b336b3bSLaszlo Ersek char *(*explicit_ofw_unit_address)(const SysBusDevice *dev); 53715ca691SEric Auger void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq); 54db1015e9SEduardo Habkost }; 550d09e41aSPaolo Bonzini 560d09e41aSPaolo Bonzini struct SysBusDevice { 57b67964d7SAndreas Färber /*< private >*/ 58b67964d7SAndreas Färber DeviceState parent_obj; 59b67964d7SAndreas Färber /*< public >*/ 60b67964d7SAndreas Färber 610d09e41aSPaolo Bonzini int num_mmio; 620d09e41aSPaolo Bonzini struct { 630d09e41aSPaolo Bonzini hwaddr addr; 640d09e41aSPaolo Bonzini MemoryRegion *memory; 650d09e41aSPaolo Bonzini } mmio[QDEV_MAX_MMIO]; 660d09e41aSPaolo Bonzini int num_pio; 6789a80e74SPaolo Bonzini uint32_t pio[QDEV_MAX_PIO]; 680d09e41aSPaolo Bonzini }; 690d09e41aSPaolo Bonzini 704f01a637SDavid Gibson typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); 71eb572280SAlexander Graf 720d09e41aSPaolo Bonzini void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 730d09e41aSPaolo Bonzini MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 740d09e41aSPaolo Bonzini void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 750d09e41aSPaolo Bonzini void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 7689a80e74SPaolo Bonzini void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size); 770d09e41aSPaolo Bonzini 780d09e41aSPaolo Bonzini 79b7973186SAlexander Graf bool sysbus_has_irq(SysBusDevice *dev, int n); 80471a9bc1SAlexander Graf bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n); 810d09e41aSPaolo Bonzini void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 82b7973186SAlexander Graf bool sysbus_is_irq_connected(SysBusDevice *dev, int n); 83b7973186SAlexander Graf qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n); 840d09e41aSPaolo Bonzini void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 850d09e41aSPaolo Bonzini void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 86a1ff8ae0SMarcel Apfelbaum int priority); 8790c20e1eSCédric Le Goater void sysbus_mmio_unmap(SysBusDevice *dev, int n); 880d09e41aSPaolo Bonzini void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 890d09e41aSPaolo Bonzini MemoryRegion *mem); 900d09e41aSPaolo Bonzini MemoryRegion *sysbus_address_space(SysBusDevice *dev); 910d09e41aSPaolo Bonzini 92496a8525SMarkus Armbruster bool sysbus_realize(SysBusDevice *dev, Error **errp); 93496a8525SMarkus Armbruster bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp); 94496a8525SMarkus Armbruster 95eb572280SAlexander Graf /* Call func for every dynamically created sysbus device in the system */ 96eb572280SAlexander Graf void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); 97eb572280SAlexander Graf 980d09e41aSPaolo Bonzini /* Legacy helper function for creating devices. */ 990d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name, 1000d09e41aSPaolo Bonzini hwaddr addr, ...); 1017e83a77fSMarc-André Lureau 1020d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name, 1030d09e41aSPaolo Bonzini hwaddr addr, 1040d09e41aSPaolo Bonzini qemu_irq irq) 1050d09e41aSPaolo Bonzini { 1060d09e41aSPaolo Bonzini return sysbus_create_varargs(name, addr, irq, NULL); 1070d09e41aSPaolo Bonzini } 1080d09e41aSPaolo Bonzini 109175de524SMarkus Armbruster #endif /* HW_SYSBUS_H */ 110