xref: /openbmc/qemu/include/hw/sysbus.h (revision a1ff8ae0666ffcbe78ae7e28812dd30db6bb7131)
10d09e41aSPaolo Bonzini #ifndef HW_SYSBUS_H
20d09e41aSPaolo Bonzini #define HW_SYSBUS_H 1
30d09e41aSPaolo Bonzini 
40d09e41aSPaolo Bonzini /* Devices attached directly to the main system bus.  */
50d09e41aSPaolo Bonzini 
60d09e41aSPaolo Bonzini #include "hw/qdev.h"
70d09e41aSPaolo Bonzini #include "exec/memory.h"
80d09e41aSPaolo Bonzini 
90d09e41aSPaolo Bonzini #define QDEV_MAX_MMIO 32
100d09e41aSPaolo Bonzini #define QDEV_MAX_PIO 32
110d09e41aSPaolo Bonzini #define QDEV_MAX_IRQ 512
120d09e41aSPaolo Bonzini 
130d09e41aSPaolo Bonzini #define TYPE_SYSTEM_BUS "System"
140d09e41aSPaolo Bonzini #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
150d09e41aSPaolo Bonzini 
160d09e41aSPaolo Bonzini typedef struct SysBusDevice SysBusDevice;
170d09e41aSPaolo Bonzini 
180d09e41aSPaolo Bonzini #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
190d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE(obj) \
200d09e41aSPaolo Bonzini      OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
210d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_CLASS(klass) \
220d09e41aSPaolo Bonzini      OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
230d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_GET_CLASS(obj) \
240d09e41aSPaolo Bonzini      OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
250d09e41aSPaolo Bonzini 
26ce724398SHu Tao /**
27ce724398SHu Tao  * SysBusDeviceClass:
28ce724398SHu Tao  * @init: Callback function invoked when the #DeviceState.realized property
29ce724398SHu Tao  * is changed to %true. Deprecated, new types inheriting directly from
30ce724398SHu Tao  * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
31ce724398SHu Tao  * types should consult their respective parent type.
32ce724398SHu Tao  *
33ce724398SHu Tao  * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
34ce724398SHu Tao  * classes overriding it are not required to invoke its implementation.
35ce724398SHu Tao  */
360d09e41aSPaolo Bonzini typedef struct SysBusDeviceClass {
37ce724398SHu Tao     /*< private >*/
380d09e41aSPaolo Bonzini     DeviceClass parent_class;
39ce724398SHu Tao     /*< public >*/
400d09e41aSPaolo Bonzini 
410d09e41aSPaolo Bonzini     int (*init)(SysBusDevice *dev);
420d09e41aSPaolo Bonzini } SysBusDeviceClass;
430d09e41aSPaolo Bonzini 
440d09e41aSPaolo Bonzini struct SysBusDevice {
45b67964d7SAndreas Färber     /*< private >*/
46b67964d7SAndreas Färber     DeviceState parent_obj;
47b67964d7SAndreas Färber     /*< public >*/
48b67964d7SAndreas Färber 
490d09e41aSPaolo Bonzini     int num_irq;
500d09e41aSPaolo Bonzini     qemu_irq irqs[QDEV_MAX_IRQ];
510d09e41aSPaolo Bonzini     qemu_irq *irqp[QDEV_MAX_IRQ];
520d09e41aSPaolo Bonzini     int num_mmio;
530d09e41aSPaolo Bonzini     struct {
540d09e41aSPaolo Bonzini         hwaddr addr;
550d09e41aSPaolo Bonzini         MemoryRegion *memory;
560d09e41aSPaolo Bonzini     } mmio[QDEV_MAX_MMIO];
570d09e41aSPaolo Bonzini     int num_pio;
580d09e41aSPaolo Bonzini     pio_addr_t pio[QDEV_MAX_PIO];
590d09e41aSPaolo Bonzini };
600d09e41aSPaolo Bonzini 
610d09e41aSPaolo Bonzini void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
620d09e41aSPaolo Bonzini MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
630d09e41aSPaolo Bonzini void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
640d09e41aSPaolo Bonzini void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
650d09e41aSPaolo Bonzini void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
660d09e41aSPaolo Bonzini 
670d09e41aSPaolo Bonzini 
680d09e41aSPaolo Bonzini void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
690d09e41aSPaolo Bonzini void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
700d09e41aSPaolo Bonzini void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
71*a1ff8ae0SMarcel Apfelbaum                              int priority);
720d09e41aSPaolo Bonzini void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
730d09e41aSPaolo Bonzini                    MemoryRegion *mem);
740d09e41aSPaolo Bonzini void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
750d09e41aSPaolo Bonzini MemoryRegion *sysbus_address_space(SysBusDevice *dev);
760d09e41aSPaolo Bonzini 
770d09e41aSPaolo Bonzini /* Legacy helper function for creating devices.  */
780d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name,
790d09e41aSPaolo Bonzini                                  hwaddr addr, ...);
800d09e41aSPaolo Bonzini DeviceState *sysbus_try_create_varargs(const char *name,
810d09e41aSPaolo Bonzini                                        hwaddr addr, ...);
820d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name,
830d09e41aSPaolo Bonzini                                               hwaddr addr,
840d09e41aSPaolo Bonzini                                               qemu_irq irq)
850d09e41aSPaolo Bonzini {
860d09e41aSPaolo Bonzini     return sysbus_create_varargs(name, addr, irq, NULL);
870d09e41aSPaolo Bonzini }
880d09e41aSPaolo Bonzini 
890d09e41aSPaolo Bonzini static inline DeviceState *sysbus_try_create_simple(const char *name,
900d09e41aSPaolo Bonzini                                                     hwaddr addr,
910d09e41aSPaolo Bonzini                                                     qemu_irq irq)
920d09e41aSPaolo Bonzini {
930d09e41aSPaolo Bonzini     return sysbus_try_create_varargs(name, addr, irq, NULL);
940d09e41aSPaolo Bonzini }
950d09e41aSPaolo Bonzini 
960d09e41aSPaolo Bonzini #endif /* !HW_SYSBUS_H */
97