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"
19c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(SysBusDevice, SysBusDeviceClass,
20*30b5707cSEduardo Habkost 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);
850d09e41aSPaolo Bonzini
86496a8525SMarkus Armbruster bool sysbus_realize(SysBusDevice *dev, Error **errp);
87496a8525SMarkus Armbruster bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp);
88496a8525SMarkus Armbruster
89eb572280SAlexander Graf /* Call func for every dynamically created sysbus device in the system */
90eb572280SAlexander Graf void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
91eb572280SAlexander Graf
920d09e41aSPaolo Bonzini /* Legacy helper function for creating devices. */
930d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name,
940d09e41aSPaolo Bonzini hwaddr addr, ...);
957e83a77fSMarc-André Lureau
sysbus_create_simple(const char * name,hwaddr addr,qemu_irq irq)960d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name,
970d09e41aSPaolo Bonzini hwaddr addr,
980d09e41aSPaolo Bonzini qemu_irq irq)
990d09e41aSPaolo Bonzini {
1000d09e41aSPaolo Bonzini return sysbus_create_varargs(name, addr, irq, NULL);
1010d09e41aSPaolo Bonzini }
1020d09e41aSPaolo Bonzini
103175de524SMarkus Armbruster #endif /* HW_SYSBUS_H */
104