xref: /openbmc/qemu/include/hw/sysbus.h (revision eb5722801c84f23428c50e2336d02e400ce55deb)
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 
120d09e41aSPaolo Bonzini #define TYPE_SYSTEM_BUS "System"
130d09e41aSPaolo Bonzini #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
140d09e41aSPaolo Bonzini 
150d09e41aSPaolo Bonzini typedef struct SysBusDevice SysBusDevice;
160d09e41aSPaolo Bonzini 
170d09e41aSPaolo Bonzini #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
180d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE(obj) \
190d09e41aSPaolo Bonzini      OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
200d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_CLASS(klass) \
210d09e41aSPaolo Bonzini      OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
220d09e41aSPaolo Bonzini #define SYS_BUS_DEVICE_GET_CLASS(obj) \
230d09e41aSPaolo Bonzini      OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
240d09e41aSPaolo Bonzini 
25ce724398SHu Tao /**
26ce724398SHu Tao  * SysBusDeviceClass:
27ce724398SHu Tao  * @init: Callback function invoked when the #DeviceState.realized property
28ce724398SHu Tao  * is changed to %true. Deprecated, new types inheriting directly from
29ce724398SHu Tao  * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
30ce724398SHu Tao  * types should consult their respective parent type.
31ce724398SHu Tao  *
32ce724398SHu Tao  * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
33ce724398SHu Tao  * classes overriding it are not required to invoke its implementation.
34ce724398SHu Tao  */
35b5917219SPeter Crosthwaite 
36b5917219SPeter Crosthwaite #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
37b5917219SPeter Crosthwaite 
380d09e41aSPaolo Bonzini typedef struct SysBusDeviceClass {
39ce724398SHu Tao     /*< private >*/
400d09e41aSPaolo Bonzini     DeviceClass parent_class;
41ce724398SHu Tao     /*< public >*/
420d09e41aSPaolo Bonzini 
430d09e41aSPaolo Bonzini     int (*init)(SysBusDevice *dev);
440d09e41aSPaolo Bonzini } SysBusDeviceClass;
450d09e41aSPaolo Bonzini 
460d09e41aSPaolo Bonzini struct SysBusDevice {
47b67964d7SAndreas Färber     /*< private >*/
48b67964d7SAndreas Färber     DeviceState parent_obj;
49b67964d7SAndreas Färber     /*< public >*/
50b67964d7SAndreas Färber 
510d09e41aSPaolo Bonzini     int num_mmio;
520d09e41aSPaolo Bonzini     struct {
530d09e41aSPaolo Bonzini         hwaddr addr;
540d09e41aSPaolo Bonzini         MemoryRegion *memory;
550d09e41aSPaolo Bonzini     } mmio[QDEV_MAX_MMIO];
560d09e41aSPaolo Bonzini     int num_pio;
570d09e41aSPaolo Bonzini     pio_addr_t pio[QDEV_MAX_PIO];
580d09e41aSPaolo Bonzini };
590d09e41aSPaolo Bonzini 
60*eb572280SAlexander Graf typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
61*eb572280SAlexander Graf 
620d09e41aSPaolo Bonzini void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
630d09e41aSPaolo Bonzini MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
640d09e41aSPaolo Bonzini void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
650d09e41aSPaolo Bonzini void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
660d09e41aSPaolo Bonzini void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
670d09e41aSPaolo Bonzini 
680d09e41aSPaolo Bonzini 
690d09e41aSPaolo Bonzini void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
700d09e41aSPaolo Bonzini void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
710d09e41aSPaolo Bonzini void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
72a1ff8ae0SMarcel Apfelbaum                              int priority);
730d09e41aSPaolo Bonzini void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
740d09e41aSPaolo Bonzini                    MemoryRegion *mem);
750d09e41aSPaolo Bonzini MemoryRegion *sysbus_address_space(SysBusDevice *dev);
760d09e41aSPaolo Bonzini 
77*eb572280SAlexander Graf /* Call func for every dynamically created sysbus device in the system */
78*eb572280SAlexander Graf void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
79*eb572280SAlexander Graf 
800d09e41aSPaolo Bonzini /* Legacy helper function for creating devices.  */
810d09e41aSPaolo Bonzini DeviceState *sysbus_create_varargs(const char *name,
820d09e41aSPaolo Bonzini                                  hwaddr addr, ...);
830d09e41aSPaolo Bonzini DeviceState *sysbus_try_create_varargs(const char *name,
840d09e41aSPaolo Bonzini                                        hwaddr addr, ...);
850d09e41aSPaolo Bonzini static inline DeviceState *sysbus_create_simple(const char *name,
860d09e41aSPaolo Bonzini                                               hwaddr addr,
870d09e41aSPaolo Bonzini                                               qemu_irq irq)
880d09e41aSPaolo Bonzini {
890d09e41aSPaolo Bonzini     return sysbus_create_varargs(name, addr, irq, NULL);
900d09e41aSPaolo Bonzini }
910d09e41aSPaolo Bonzini 
920d09e41aSPaolo Bonzini static inline DeviceState *sysbus_try_create_simple(const char *name,
930d09e41aSPaolo Bonzini                                                     hwaddr addr,
940d09e41aSPaolo Bonzini                                                     qemu_irq irq)
950d09e41aSPaolo Bonzini {
960d09e41aSPaolo Bonzini     return sysbus_try_create_varargs(name, addr, irq, NULL);
970d09e41aSPaolo Bonzini }
980d09e41aSPaolo Bonzini 
990d09e41aSPaolo Bonzini #endif /* !HW_SYSBUS_H */
100