Statistics
| Branch: | Revision:

root / hw / sysbus.h @ 46c305ef

History | View | Annotate | Download (2.7 kB)

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 256
12

    
13
typedef struct SysBusDevice SysBusDevice;
14
typedef void (*mmio_mapfunc)(SysBusDevice *dev, target_phys_addr_t addr);
15

    
16
struct SysBusDevice {
17
    DeviceState qdev;
18
    int num_irq;
19
    qemu_irq irqs[QDEV_MAX_IRQ];
20
    qemu_irq *irqp[QDEV_MAX_IRQ];
21
    int num_mmio;
22
    struct {
23
        target_phys_addr_t addr;
24
        target_phys_addr_t size;
25
        mmio_mapfunc cb;
26
        mmio_mapfunc unmap;
27
        ram_addr_t iofunc;
28
        MemoryRegion *memory;
29
    } mmio[QDEV_MAX_MMIO];
30
    int num_pio;
31
    pio_addr_t pio[QDEV_MAX_PIO];
32
};
33

    
34
typedef int (*sysbus_initfn)(SysBusDevice *dev);
35

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

    
40
typedef struct {
41
    DeviceInfo qdev;
42
    sysbus_initfn init;
43
} SysBusDeviceInfo;
44

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

    
58

    
59
void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
60
void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
61

    
62
/* Legacy helper function for creating devices.  */
63
DeviceState *sysbus_create_varargs(const char *name,
64
                                 target_phys_addr_t addr, ...);
65
DeviceState *sysbus_try_create_varargs(const char *name,
66
                                       target_phys_addr_t addr, ...);
67
static inline DeviceState *sysbus_create_simple(const char *name,
68
                                              target_phys_addr_t addr,
69
                                              qemu_irq irq)
70
{
71
    return sysbus_create_varargs(name, addr, irq, NULL);
72
}
73

    
74
static inline DeviceState *sysbus_try_create_simple(const char *name,
75
                                                    target_phys_addr_t addr,
76
                                                    qemu_irq irq)
77
{
78
    return sysbus_try_create_varargs(name, addr, irq, NULL);
79
}
80

    
81
#endif /* !HW_SYSBUS_H */