]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/sysbus.h
xen, gfx passthrough: retrieve VGA BIOS to work
[mirror_qemu.git] / include / hw / sysbus.h
CommitLineData
aae9460e
PB
1#ifndef HW_SYSBUS_H
2#define HW_SYSBUS_H 1
3
4/* Devices attached directly to the main system bus. */
5
83c9f4ca 6#include "hw/qdev.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:
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 */
b5917219
PC
35
36#define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq"
37
999e12bb 38typedef struct SysBusDeviceClass {
ce724398 39 /*< private >*/
999e12bb 40 DeviceClass parent_class;
ce724398 41 /*< public >*/
999e12bb
AL
42
43 int (*init)(SysBusDevice *dev);
0b336b3b
LE
44
45 /*
46 * Let the sysbus device format its own non-PIO, non-MMIO unit address.
47 *
48 * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources,
49 * yet instances of it would like to distinguish themselves, in
50 * OpenFirmware device paths, from other instances of the same class on the
51 * sysbus. For that end we expose this callback.
52 *
53 * The implementation is not supposed to change *@dev, or incur other
54 * observable change.
55 *
56 * The function returns a dynamically allocated string. On error, NULL
57 * should be returned; the unit address portion of the OFW node will be
58 * omitted then. (This is not considered a fatal error.)
59 */
60 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev);
715ca691 61 void (*connect_irq_notifier)(SysBusDevice *dev, qemu_irq irq);
999e12bb
AL
62} SysBusDeviceClass;
63
aae9460e 64struct SysBusDevice {
b67964d7
AF
65 /*< private >*/
66 DeviceState parent_obj;
67 /*< public >*/
68
aae9460e
PB
69 int num_mmio;
70 struct {
a8170e5e 71 hwaddr addr;
ec3bb837 72 MemoryRegion *memory;
aae9460e 73 } mmio[QDEV_MAX_MMIO];
c646f74f
GN
74 int num_pio;
75 pio_addr_t pio[QDEV_MAX_PIO];
aae9460e
PB
76};
77
eb572280
AG
78typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
79
750ecd44 80void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
46c305ef 81MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
aae9460e
PB
82void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
83void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
c646f74f 84void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
aae9460e
PB
85
86
b7973186 87bool sysbus_has_irq(SysBusDevice *dev, int n);
471a9bc1 88bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
aae9460e 89void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
b7973186
AG
90bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
91qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
a8170e5e 92void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
7feb640c 93void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
a1ff8ae0 94 int priority);
a8170e5e 95void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
2b985d9c 96 MemoryRegion *mem);
62ec4832 97MemoryRegion *sysbus_address_space(SysBusDevice *dev);
aae9460e 98
eb572280
AG
99/* Call func for every dynamically created sysbus device in the system */
100void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque);
101
aae9460e
PB
102/* Legacy helper function for creating devices. */
103DeviceState *sysbus_create_varargs(const char *name,
a8170e5e 104 hwaddr addr, ...);
4912371f 105DeviceState *sysbus_try_create_varargs(const char *name,
a8170e5e 106 hwaddr addr, ...);
aae9460e 107static inline DeviceState *sysbus_create_simple(const char *name,
a8170e5e 108 hwaddr addr,
aae9460e
PB
109 qemu_irq irq)
110{
111 return sysbus_create_varargs(name, addr, irq, NULL);
112}
113
4912371f 114static inline DeviceState *sysbus_try_create_simple(const char *name,
a8170e5e 115 hwaddr addr,
4912371f
BS
116 qemu_irq irq)
117{
118 return sysbus_try_create_varargs(name, addr, irq, NULL);
119}
120
aae9460e 121#endif /* !HW_SYSBUS_H */