1 #ifndef HW_SYSBUS_H
2 #define HW_SYSBUS_H 1
3
4 /* Devices attached directly to the main system bus. */
5
6 #include "exec/hwaddr.h"
7 #include "hw/qdev.h"
8
9 #define QDEV_MAX_MMIO 5
10 #define QDEV_MAX_IRQ 32
11
12 typedef struct SysBusDevice SysBusDevice;
13 typedef void (*mmio_mapfunc)(SysBusDevice *dev, hwaddr addr);
14
15 struct SysBusDevice {
16 DeviceState qdev;
17 int num_irq;
18 qemu_irq irqs[QDEV_MAX_IRQ];
19 qemu_irq *irqp[QDEV_MAX_IRQ];
20 int num_mmio;
21 struct {
22 hwaddr addr;
23 hwaddr size;
24 mmio_mapfunc cb;
25 int iofunc;
26 } mmio[QDEV_MAX_MMIO];
27 };
28
29 typedef void (*sysbus_initfn)(SysBusDevice *dev);
30
31 /* Macros to compensate for lack of type inheritance in C. */
32 #define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
33 #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
34
35 typedef struct {
36 DeviceInfo qdev;
37 sysbus_initfn init;
38 } SysBusDeviceInfo;
39
40 void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init);
41 void sysbus_register_withprop(SysBusDeviceInfo *info);
42 void *sysbus_new(void);
43 void sysbus_init_mmio(SysBusDevice *dev, hwaddr size, int iofunc);
44 void sysbus_init_mmio_cb(SysBusDevice *dev, hwaddr size,
45 mmio_mapfunc cb);
46 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
47 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
48
49
50 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
51 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
52
53 /* Legacy helper function for creating devices. */
54 DeviceState *sysbus_create_varargs(const char *name,
55 hwaddr addr, ...);
sysbus_create_simple(const char * name,hwaddr addr,qemu_irq irq)56 static inline DeviceState *sysbus_create_simple(const char *name,
57 hwaddr addr,
58 qemu_irq irq)
59 {
60 return sysbus_create_varargs(name, addr, irq, NULL);
61 }
62
63 #endif /* !HW_SYSBUS_H */
64