]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/sysbus.h
qdev: move helper function to monitor/misc
[mirror_qemu.git] / include / hw / sysbus.h
CommitLineData
aae9460e 1#ifndef HW_SYSBUS_H
175de524 2#define HW_SYSBUS_H
aae9460e
PB
3
4/* Devices attached directly to the main system bus. */
5
a27bd6c7 6#include "hw/qdev-core.h"
022c62cb 7#include "exec/memory.h"
aae9460e 8
f40070c3 9#define QDEV_MAX_MMIO 32
c646f74f 10#define QDEV_MAX_PIO 32
aae9460e 11
0d936928 12#define TYPE_SYSTEM_BUS "System"
00c2275c 13#define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS)
0d936928 14
aae9460e 15typedef struct SysBusDevice SysBusDevice;
aae9460e 16
999e12bb
AL
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
ce724398
HT
25/**
26 * SysBusDeviceClass:
ce724398
HT
27 *
28 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
29 * classes overriding it are not required to invoke its implementation.
30 */
b5917219
PC
31
32#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
33
999e12bb 34typedef struct SysBusDeviceClass {
ce724398 35 /*< private >*/
999e12bb 36 DeviceClass parent_class;
0b336b3b
LE
37
38 /*
39 * Let the sysbus device format its own non-PIO, non-MMIO unit address.
40 *
41 * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
42 * yet instances of it would like to distinguish themselves, in
43 * OpenFirmware device paths, from other instances of the same class on the
44 * sysbus. For that end we expose this callback.
45 *
46 * The implementation is not supposed to change *@dev, or incur other
47 * observable change.
48 *
49 * The function returns a dynamically allocated string. On error, NULL
50 * should be returned; the unit address portion of the OFW node will be
51 * omitted then. (This is not considered a fatal error.)
52 */
53 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
715ca691 54 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
999e12bb
AL
55} SysBusDeviceClass;
56
aae9460e 57struct SysBusDevice {
b67964d7
AF
58 /*< private >*/
59 DeviceState parent_obj;
60 /*< public >*/
61
aae9460e
PB
62 int num_mmio;
63 struct {
a8170e5e 64 hwaddr addr;
ec3bb837 65 MemoryRegion *memory;
aae9460e 66 } mmio[QDEV_MAX_MMIO];
c646f74f 67 int num_pio;
89a80e74 68 uint32_t pio[QDEV_MAX_PIO];
aae9460e
PB
69};
70
4f01a637 71typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
eb572280 72
750ecd44 73void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
46c305ef 74MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
aae9460e
PB
75void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
76void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
89a80e74 77void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
aae9460e
PB
78
79
b7973186 80bool sysbus_has_irq(SysBusDevice *dev, int n);
471a9bc1 81bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
aae9460e 82void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
b7973186
AG
83bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
84qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
a8170e5e 85void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
7feb640c 86void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
a1ff8ae0 87 int priority);
90c20e1e 88void sysbus_mmio_unmap(SysBusDevice *dev, int n);
a8170e5e 89void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
2b985d9c 90 MemoryRegion *mem);
62ec4832 91MemoryRegion *sysbus_address_space(SysBusDevice *dev);
aae9460e 92
046f370f
TH
93/**
94 * sysbus_init_child_obj:
95 * @parent: The parent object
96 * @childname: Used as name of the "child<>" property in the parent
97 * @child: A pointer to the memory to be used for the object.
98 * @childsize: The maximum size available at @child for the object.
99 * @childtype: The name of the type of the object to instantiate.
100 *
101 * This function will initialize an object and attach it to the main system
102 * bus. The memory for the object should have already been allocated. The
103 * object will then be added as child to the given parent. The returned object
104 * has a reference count of 1 (for the "child<...>" property from the parent),
105 * so the object will be finalized automatically when the parent gets removed.
106 */
107void sysbus_init_child_obj(Object *parent, const char *childname, void *child,
108 size_t childsize, const char *childtype);
109
eb572280
AG
110/* Call func for every dynamically created sysbus device in the system */
111void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
112
aae9460e
PB
113/* Legacy helper function for creating devices. */
114DeviceState *sysbus_create_varargs(const char *name,
a8170e5e 115 hwaddr addr, ...);
7e83a77f 116
aae9460e 117static inline DeviceState *sysbus_create_simple(const char *name,
a8170e5e 118 hwaddr addr,
aae9460e
PB
119 qemu_irq irq)
120{
121 return sysbus_create_varargs(name, addr, irq, NULL);
122}
123
4912371f 124
175de524 125#endif /* HW_SYSBUS_H */