sysbus.h 3.1 KB
Newer Older
P
Paul Brook 已提交
1 2 3 4 5 6
#ifndef HW_SYSBUS_H
#define HW_SYSBUS_H 1

/* Devices attached directly to the main system bus.  */

#include "qdev.h"
7
#include "memory.h"
P
Paul Brook 已提交
8

B
Blue Swirl 已提交
9
#define QDEV_MAX_MMIO 32
10
#define QDEV_MAX_PIO 32
11
#define QDEV_MAX_IRQ 256
P
Paul Brook 已提交
12 13

typedef struct SysBusDevice SysBusDevice;
A
Anthony Liguori 已提交
14
typedef void (*mmio_mapfunc)(SysBusDevice *dev, target_phys_addr_t addr);
P
Paul Brook 已提交
15 16 17 18 19 20 21 22

struct SysBusDevice {
    DeviceState qdev;
    int num_irq;
    qemu_irq irqs[QDEV_MAX_IRQ];
    qemu_irq *irqp[QDEV_MAX_IRQ];
    int num_mmio;
    struct {
A
Anthony Liguori 已提交
23 24
        target_phys_addr_t addr;
        target_phys_addr_t size;
P
Paul Brook 已提交
25
        mmio_mapfunc cb;
26
        mmio_mapfunc unmap;
B
Blue Swirl 已提交
27
        ram_addr_t iofunc;
28
        MemoryRegion *memory;
P
Paul Brook 已提交
29
    } mmio[QDEV_MAX_MMIO];
30 31
    int num_pio;
    pio_addr_t pio[QDEV_MAX_PIO];
P
Paul Brook 已提交
32 33
};

34
typedef int (*sysbus_initfn)(SysBusDevice *dev);
P
Paul Brook 已提交
35 36 37 38 39

/* Macros to compensate for lack of type inheritance in C.  */
#define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
#define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)

P
Paul Brook 已提交
40 41 42 43 44
typedef struct {
    DeviceInfo qdev;
    sysbus_initfn init;
} SysBusDeviceInfo;

P
Paul Brook 已提交
45
void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init);
46
void sysbus_register_withprop(SysBusDeviceInfo *info);
P
Paul Brook 已提交
47
void *sysbus_new(void);
B
Blue Swirl 已提交
48 49
void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size,
                      ram_addr_t iofunc);
50 51
void sysbus_init_mmio_cb2(SysBusDevice *dev,
                          mmio_mapfunc cb, mmio_mapfunc unmap);
52
void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory);
P
Paul Brook 已提交
53 54
void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
55
void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
P
Paul Brook 已提交
56 57 58


void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
A
Anthony Liguori 已提交
59
void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
60 61
void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
                       MemoryRegion *mem);
62 63
void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
                               MemoryRegion *mem, unsigned priority);
64 65 66 67
void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
                   MemoryRegion *mem);
void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
P
Paul Brook 已提交
68 69 70

/* Legacy helper function for creating devices.  */
DeviceState *sysbus_create_varargs(const char *name,
A
Anthony Liguori 已提交
71
                                 target_phys_addr_t addr, ...);
72 73
DeviceState *sysbus_try_create_varargs(const char *name,
                                       target_phys_addr_t addr, ...);
P
Paul Brook 已提交
74
static inline DeviceState *sysbus_create_simple(const char *name,
A
Anthony Liguori 已提交
75
                                              target_phys_addr_t addr,
P
Paul Brook 已提交
76 77 78 79 80
                                              qemu_irq irq)
{
    return sysbus_create_varargs(name, addr, irq, NULL);
}

81 82 83 84 85 86 87
static inline DeviceState *sysbus_try_create_simple(const char *name,
                                                    target_phys_addr_t addr,
                                                    qemu_irq irq)
{
    return sysbus_try_create_varargs(name, addr, irq, NULL);
}

P
Paul Brook 已提交
88
#endif /* !HW_SYSBUS_H */