Statistics
| Branch: | Revision:

root / hw / sysbus.h @ bf3bc4c4

History | View | Annotate | Download (3 kB)

1 aae9460e Paul Brook
#ifndef HW_SYSBUS_H
2 aae9460e Paul Brook
#define HW_SYSBUS_H 1
3 aae9460e Paul Brook
4 aae9460e Paul Brook
/* Devices attached directly to the main system bus.  */
5 aae9460e Paul Brook
6 aae9460e Paul Brook
#include "qdev.h"
7 ec3bb837 Avi Kivity
#include "memory.h"
8 aae9460e Paul Brook
9 f40070c3 Blue Swirl
#define QDEV_MAX_MMIO 32
10 c646f74f Gleb Natapov
#define QDEV_MAX_PIO 32
11 ea0e6841 Evgeny Voevodin
#define QDEV_MAX_IRQ 512
12 aae9460e Paul Brook
13 0d936928 Anthony Liguori
#define TYPE_SYSTEM_BUS "System"
14 0d936928 Anthony Liguori
#define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
15 0d936928 Anthony Liguori
16 aae9460e Paul Brook
typedef struct SysBusDevice SysBusDevice;
17 aae9460e Paul Brook
18 999e12bb Anthony Liguori
#define TYPE_SYS_BUS_DEVICE "sys-bus-device"
19 999e12bb Anthony Liguori
#define SYS_BUS_DEVICE(obj) \
20 999e12bb Anthony Liguori
     OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
21 999e12bb Anthony Liguori
#define SYS_BUS_DEVICE_CLASS(klass) \
22 999e12bb Anthony Liguori
     OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
23 999e12bb Anthony Liguori
#define SYS_BUS_DEVICE_GET_CLASS(obj) \
24 999e12bb Anthony Liguori
     OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
25 999e12bb Anthony Liguori
26 999e12bb Anthony Liguori
typedef struct SysBusDeviceClass {
27 999e12bb Anthony Liguori
    DeviceClass parent_class;
28 999e12bb Anthony Liguori
29 999e12bb Anthony Liguori
    int (*init)(SysBusDevice *dev);
30 999e12bb Anthony Liguori
} SysBusDeviceClass;
31 999e12bb Anthony Liguori
32 aae9460e Paul Brook
struct SysBusDevice {
33 aae9460e Paul Brook
    DeviceState qdev;
34 aae9460e Paul Brook
    int num_irq;
35 aae9460e Paul Brook
    qemu_irq irqs[QDEV_MAX_IRQ];
36 aae9460e Paul Brook
    qemu_irq *irqp[QDEV_MAX_IRQ];
37 aae9460e Paul Brook
    int num_mmio;
38 aae9460e Paul Brook
    struct {
39 a8170e5e Avi Kivity
        hwaddr addr;
40 ec3bb837 Avi Kivity
        MemoryRegion *memory;
41 aae9460e Paul Brook
    } mmio[QDEV_MAX_MMIO];
42 c646f74f Gleb Natapov
    int num_pio;
43 c646f74f Gleb Natapov
    pio_addr_t pio[QDEV_MAX_PIO];
44 aae9460e Paul Brook
};
45 aae9460e Paul Brook
46 aae9460e Paul Brook
/* Macros to compensate for lack of type inheritance in C.  */
47 aae9460e Paul Brook
#define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
48 aae9460e Paul Brook
#define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
49 aae9460e Paul Brook
50 aae9460e Paul Brook
void *sysbus_new(void);
51 750ecd44 Avi Kivity
void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
52 46c305ef Peter Maydell
MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
53 aae9460e Paul Brook
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
54 aae9460e Paul Brook
void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
55 c646f74f Gleb Natapov
void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
56 aae9460e Paul Brook
57 aae9460e Paul Brook
58 aae9460e Paul Brook
void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
59 a8170e5e Avi Kivity
void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
60 a8170e5e Avi Kivity
void sysbus_add_memory(SysBusDevice *dev, hwaddr addr,
61 2b985d9c Avi Kivity
                       MemoryRegion *mem);
62 a8170e5e Avi Kivity
void sysbus_add_memory_overlap(SysBusDevice *dev, hwaddr addr,
63 d40b2af8 Avi Kivity
                               MemoryRegion *mem, unsigned priority);
64 2b985d9c Avi Kivity
void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
65 a8170e5e Avi Kivity
void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
66 2b985d9c Avi Kivity
                   MemoryRegion *mem);
67 2b985d9c Avi Kivity
void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
68 62ec4832 Avi Kivity
MemoryRegion *sysbus_address_space(SysBusDevice *dev);
69 aae9460e Paul Brook
70 aae9460e Paul Brook
/* Legacy helper function for creating devices.  */
71 aae9460e Paul Brook
DeviceState *sysbus_create_varargs(const char *name,
72 a8170e5e Avi Kivity
                                 hwaddr addr, ...);
73 4912371f Blue Swirl
DeviceState *sysbus_try_create_varargs(const char *name,
74 a8170e5e Avi Kivity
                                       hwaddr addr, ...);
75 aae9460e Paul Brook
static inline DeviceState *sysbus_create_simple(const char *name,
76 a8170e5e Avi Kivity
                                              hwaddr addr,
77 aae9460e Paul Brook
                                              qemu_irq irq)
78 aae9460e Paul Brook
{
79 aae9460e Paul Brook
    return sysbus_create_varargs(name, addr, irq, NULL);
80 aae9460e Paul Brook
}
81 aae9460e Paul Brook
82 4912371f Blue Swirl
static inline DeviceState *sysbus_try_create_simple(const char *name,
83 a8170e5e Avi Kivity
                                                    hwaddr addr,
84 4912371f Blue Swirl
                                                    qemu_irq irq)
85 4912371f Blue Swirl
{
86 4912371f Blue Swirl
    return sysbus_try_create_varargs(name, addr, irq, NULL);
87 4912371f Blue Swirl
}
88 4912371f Blue Swirl
89 aae9460e Paul Brook
#endif /* !HW_SYSBUS_H */