]> git.proxmox.com Git - mirror_qemu.git/blob - hw/sysbus.h
Merge branch 'for-upstream' of git://repo.or.cz/qemu/agraf
[mirror_qemu.git] / 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 "qdev.h"
7 #include "memory.h"
8
9 #define QDEV_MAX_MMIO 32
10 #define QDEV_MAX_PIO 32
11 #define QDEV_MAX_IRQ 512
12
13 typedef struct SysBusDevice SysBusDevice;
14
15 #define TYPE_SYS_BUS_DEVICE "sys-bus-device"
16 #define SYS_BUS_DEVICE(obj) \
17 OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
18 #define SYS_BUS_DEVICE_CLASS(klass) \
19 OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
20 #define SYS_BUS_DEVICE_GET_CLASS(obj) \
21 OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
22
23 typedef struct SysBusDeviceClass {
24 DeviceClass parent_class;
25
26 int (*init)(SysBusDevice *dev);
27 } SysBusDeviceClass;
28
29 struct SysBusDevice {
30 DeviceState qdev;
31 int num_irq;
32 qemu_irq irqs[QDEV_MAX_IRQ];
33 qemu_irq *irqp[QDEV_MAX_IRQ];
34 int num_mmio;
35 struct {
36 target_phys_addr_t addr;
37 MemoryRegion *memory;
38 } mmio[QDEV_MAX_MMIO];
39 int num_pio;
40 pio_addr_t pio[QDEV_MAX_PIO];
41 };
42
43 /* Macros to compensate for lack of type inheritance in C. */
44 #define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
45 #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
46
47 void *sysbus_new(void);
48 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
49 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
50 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
51 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
52 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
53
54
55 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
56 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
57 void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
58 MemoryRegion *mem);
59 void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
60 MemoryRegion *mem, unsigned priority);
61 void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
62 void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
63 MemoryRegion *mem);
64 void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
65 MemoryRegion *sysbus_address_space(SysBusDevice *dev);
66
67 /* Legacy helper function for creating devices. */
68 DeviceState *sysbus_create_varargs(const char *name,
69 target_phys_addr_t addr, ...);
70 DeviceState *sysbus_try_create_varargs(const char *name,
71 target_phys_addr_t addr, ...);
72 static inline DeviceState *sysbus_create_simple(const char *name,
73 target_phys_addr_t addr,
74 qemu_irq irq)
75 {
76 return sysbus_create_varargs(name, addr, irq, NULL);
77 }
78
79 static inline DeviceState *sysbus_try_create_simple(const char *name,
80 target_phys_addr_t addr,
81 qemu_irq irq)
82 {
83 return sysbus_try_create_varargs(name, addr, irq, NULL);
84 }
85
86 #endif /* !HW_SYSBUS_H */