]> git.proxmox.com Git - qemu.git/blob - include/hw/sysbus.h
Merge remote-tracking branch 'afaerber/tags/qom-cpu-for-anthony' into staging
[qemu.git] / include / hw / sysbus.h
1 #ifndef HW_SYSBUS_H
2 #define HW_SYSBUS_H 1
3
4 /* Devices attached directly to the main system bus. */
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 #define QDEV_MAX_IRQ 512
12
13 #define TYPE_SYSTEM_BUS "System"
14 #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
15
16 typedef struct SysBusDevice SysBusDevice;
17
18 #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
19 #define SYS_BUS_DEVICE(obj) \
20 OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
21 #define SYS_BUS_DEVICE_CLASS(klass) \
22 OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
23 #define SYS_BUS_DEVICE_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
25
26 /**
27 * SysBusDeviceClass:
28 * @init: Callback function invoked when the #DeviceState.realized property
29 * is changed to %true. Deprecated, new types inheriting directly from
30 * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf
31 * types should consult their respective parent type.
32 *
33 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived
34 * classes overriding it are not required to invoke its implementation.
35 */
36 typedef struct SysBusDeviceClass {
37 /*< private >*/
38 DeviceClass parent_class;
39 /*< public >*/
40
41 int (*init)(SysBusDevice *dev);
42 } SysBusDeviceClass;
43
44 struct SysBusDevice {
45 DeviceState qdev;
46 int num_irq;
47 qemu_irq irqs[QDEV_MAX_IRQ];
48 qemu_irq *irqp[QDEV_MAX_IRQ];
49 int num_mmio;
50 struct {
51 hwaddr addr;
52 MemoryRegion *memory;
53 } mmio[QDEV_MAX_MMIO];
54 int num_pio;
55 pio_addr_t pio[QDEV_MAX_PIO];
56 };
57
58 /* Macros to compensate for lack of type inheritance in C. */
59 #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
60
61 void *sysbus_new(void);
62 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
63 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
64 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
65 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
66 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
67
68
69 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
70 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
71 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
72 unsigned priority);
73 void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
74 MemoryRegion *mem);
75 void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
76 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
77
78 /* Legacy helper function for creating devices. */
79 DeviceState *sysbus_create_varargs(const char *name,
80 hwaddr addr, ...);
81 DeviceState *sysbus_try_create_varargs(const char *name,
82 hwaddr addr, ...);
83 static inline DeviceState *sysbus_create_simple(const char *name,
84 hwaddr addr,
85 qemu_irq irq)
86 {
87 return sysbus_create_varargs(name, addr, irq, NULL);
88 }
89
90 static inline DeviceState *sysbus_try_create_simple(const char *name,
91 hwaddr addr,
92 qemu_irq irq)
93 {
94 return sysbus_try_create_varargs(name, addr, irq, NULL);
95 }
96
97 #endif /* !HW_SYSBUS_H */