1#ifndef HW_SYSBUS_H
2#define HW_SYSBUS_H
3
4
5
6#include "hw/qdev-core.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(BusState, (obj), TYPE_SYSTEM_BUS)
14
15typedef 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
27
28
29
30
31
32
33
34
35
36#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
37
38typedef struct SysBusDeviceClass {
39
40 DeviceClass parent_class;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
58 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
59} SysBusDeviceClass;
60
61struct SysBusDevice {
62
63 DeviceState parent_obj;
64
65
66 int num_mmio;
67 struct {
68 hwaddr addr;
69 MemoryRegion *memory;
70 } mmio[QDEV_MAX_MMIO];
71 int num_pio;
72 uint32_t pio[QDEV_MAX_PIO];
73};
74
75typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
76
77void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
78MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
79void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
80void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
81void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
82
83
84bool sysbus_has_irq(SysBusDevice *dev, int n);
85bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
86void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
87bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
88qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
89void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
90void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
91 int priority);
92void sysbus_mmio_unmap(SysBusDevice *dev, int n);
93void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
94 MemoryRegion *mem);
95MemoryRegion *sysbus_address_space(SysBusDevice *dev);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111void sysbus_init_child_obj(Object *parent, const char *childname, void *child,
112 size_t childsize, const char *childtype);
113
114
115void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
116
117
118DeviceState *sysbus_create_varargs(const char *name,
119 hwaddr addr, ...);
120DeviceState *sysbus_try_create_varargs(const char *name,
121 hwaddr addr, ...);
122static inline DeviceState *sysbus_create_simple(const char *name,
123 hwaddr addr,
124 qemu_irq irq)
125{
126 return sysbus_create_varargs(name, addr, irq, NULL);
127}
128
129static inline DeviceState *sysbus_try_create_simple(const char *name,
130 hwaddr addr,
131 qemu_irq irq)
132{
133 return sysbus_try_create_varargs(name, addr, irq, NULL);
134}
135
136#endif
137