1#ifndef HW_SYSBUS_H
2#define HW_SYSBUS_H 1
3
4
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(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 int (*init)(SysBusDevice *dev);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
61 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
62} SysBusDeviceClass;
63
64struct SysBusDevice {
65
66 DeviceState parent_obj;
67
68
69 int num_mmio;
70 struct {
71 hwaddr addr;
72 MemoryRegion *memory;
73 } mmio[QDEV_MAX_MMIO];
74 int num_pio;
75 pio_addr_t pio[QDEV_MAX_PIO];
76};
77
78typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
79
80void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
81MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
82void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
83void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
84void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
85
86
87bool sysbus_has_irq(SysBusDevice *dev, int n);
88bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
89void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
90bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
91qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
92void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
93void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
94 int priority);
95void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
96 MemoryRegion *mem);
97MemoryRegion *sysbus_address_space(SysBusDevice *dev);
98
99
100void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
101
102
103DeviceState *sysbus_create_varargs(const char *name,
104 hwaddr addr, ...);
105DeviceState *sysbus_try_create_varargs(const char *name,
106 hwaddr addr, ...);
107static inline DeviceState *sysbus_create_simple(const char *name,
108 hwaddr addr,
109 qemu_irq irq)
110{
111 return sysbus_create_varargs(name, addr, irq, NULL);
112}
113
114static inline DeviceState *sysbus_try_create_simple(const char *name,
115 hwaddr addr,
116 qemu_irq irq)
117{
118 return sysbus_try_create_varargs(name, addr, irq, NULL);
119}
120
121#endif
122