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#include "qom/object.h"
9
10#define QDEV_MAX_MMIO 32
11#define QDEV_MAX_PIO 32
12
13#define TYPE_SYSTEM_BUS "System"
14DECLARE_INSTANCE_CHECKER(BusState, SYSTEM_BUS,
15 TYPE_SYSTEM_BUS)
16
17
18#define TYPE_SYS_BUS_DEVICE "sys-bus-device"
19OBJECT_DECLARE_TYPE(SysBusDevice, SysBusDeviceClass,
20 SYS_BUS_DEVICE)
21
22
23
24
25
26
27
28
29#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
30
31struct SysBusDeviceClass {
32
33 DeviceClass parent_class;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
51 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
52};
53
54struct SysBusDevice {
55
56 DeviceState parent_obj;
57
58
59 int num_mmio;
60 struct {
61 hwaddr addr;
62 MemoryRegion *memory;
63 } mmio[QDEV_MAX_MMIO];
64 int num_pio;
65 uint32_t pio[QDEV_MAX_PIO];
66};
67
68typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
69
70void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
71MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
72void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
73void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
74void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
75
76
77bool sysbus_has_irq(SysBusDevice *dev, int n);
78bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
79void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
80bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
81qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
82void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
83void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
84 int priority);
85void sysbus_mmio_unmap(SysBusDevice *dev, int n);
86void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
87 MemoryRegion *mem);
88MemoryRegion *sysbus_address_space(SysBusDevice *dev);
89
90bool sysbus_realize(SysBusDevice *dev, Error **errp);
91bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp);
92
93
94void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
95
96
97DeviceState *sysbus_create_varargs(const char *name,
98 hwaddr addr, ...);
99
100static inline DeviceState *sysbus_create_simple(const char *name,
101 hwaddr addr,
102 qemu_irq irq)
103{
104 return sysbus_create_varargs(name, addr, irq, NULL);
105}
106
107#endif
108