xref: /openbmc/qemu/include/hw/sysbus.h (revision 228aa992)
1 #ifndef HW_SYSBUS_H
2 #define HW_SYSBUS_H 1
3 
4 /* Devices attached directly to the main system bus.  */
5 
6 #include "hw/qdev.h"
7 #include "exec/memory.h"
8 
9 #define QDEV_MAX_MMIO 32
10 #define QDEV_MAX_PIO 32
11 
12 #define TYPE_SYSTEM_BUS "System"
13 #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
14 
15 typedef struct SysBusDevice SysBusDevice;
16 
17 #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
18 #define SYS_BUS_DEVICE(obj) \
19      OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
20 #define SYS_BUS_DEVICE_CLASS(klass) \
21      OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
22 #define SYS_BUS_DEVICE_GET_CLASS(obj) \
23      OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
24 
25 /**
26  * SysBusDeviceClass:
27  * @init: Callback function invoked when the #DeviceState.realized property
28  * is changed to %true. Deprecated, new types inheriting directly from
29  * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
30  * types should consult their respective parent type.
31  *
32  * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
33  * classes overriding it are not required to invoke its implementation.
34  */
35 
36 #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
37 
38 typedef struct SysBusDeviceClass {
39     /*< private >*/
40     DeviceClass parent_class;
41     /*< public >*/
42 
43     int (*init)(SysBusDevice *dev);
44 } SysBusDeviceClass;
45 
46 struct SysBusDevice {
47     /*< private >*/
48     DeviceState parent_obj;
49     /*< public >*/
50 
51     int num_mmio;
52     struct {
53         hwaddr addr;
54         MemoryRegion *memory;
55     } mmio[QDEV_MAX_MMIO];
56     int num_pio;
57     pio_addr_t pio[QDEV_MAX_PIO];
58 };
59 
60 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
61 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
62 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
63 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
64 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
65 
66 
67 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
68 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
69 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
70                              int priority);
71 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
72                    MemoryRegion *mem);
73 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
74 
75 /* Legacy helper function for creating devices.  */
76 DeviceState *sysbus_create_varargs(const char *name,
77                                  hwaddr addr, ...);
78 DeviceState *sysbus_try_create_varargs(const char *name,
79                                        hwaddr addr, ...);
80 static inline DeviceState *sysbus_create_simple(const char *name,
81                                               hwaddr addr,
82                                               qemu_irq irq)
83 {
84     return sysbus_create_varargs(name, addr, irq, NULL);
85 }
86 
87 static inline DeviceState *sysbus_try_create_simple(const char *name,
88                                                     hwaddr addr,
89                                                     qemu_irq irq)
90 {
91     return sysbus_try_create_varargs(name, addr, irq, NULL);
92 }
93 
94 #endif /* !HW_SYSBUS_H */
95