]> Git Repo - qemu.git/blob - hw/sysbus.h
e3b4c915b5f50ab2b4eac84965233856474192a3
[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 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         mmio_mapfunc cb;
25         mmio_mapfunc unmap;
26         MemoryRegion *memory;
27     } mmio[QDEV_MAX_MMIO];
28     int num_pio;
29     pio_addr_t pio[QDEV_MAX_PIO];
30 };
31
32 typedef int (*sysbus_initfn)(SysBusDevice *dev);
33
34 /* Macros to compensate for lack of type inheritance in C.  */
35 #define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
36 #define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
37
38 typedef struct {
39     DeviceInfo qdev;
40     sysbus_initfn init;
41 } SysBusDeviceInfo;
42
43 void sysbus_register_dev(const char *name, size_t size, sysbus_initfn init);
44 void sysbus_register_withprop(SysBusDeviceInfo *info);
45 void *sysbus_new(void);
46 void sysbus_init_mmio_cb2(SysBusDevice *dev,
47                           mmio_mapfunc cb, mmio_mapfunc unmap);
48 void sysbus_init_mmio_region(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
66 /* Legacy helper function for creating devices.  */
67 DeviceState *sysbus_create_varargs(const char *name,
68                                  target_phys_addr_t addr, ...);
69 DeviceState *sysbus_try_create_varargs(const char *name,
70                                        target_phys_addr_t addr, ...);
71 static inline DeviceState *sysbus_create_simple(const char *name,
72                                               target_phys_addr_t addr,
73                                               qemu_irq irq)
74 {
75     return sysbus_create_varargs(name, addr, irq, NULL);
76 }
77
78 static inline DeviceState *sysbus_try_create_simple(const char *name,
79                                                     target_phys_addr_t addr,
80                                                     qemu_irq irq)
81 {
82     return sysbus_try_create_varargs(name, addr, irq, NULL);
83 }
84
85 #endif /* !HW_SYSBUS_H */
This page took 0.018498 seconds and 2 git commands to generate.