blob: acfbcfba52945115be6dae4a534085d2f912005f [file] [log] [blame]
Paul Brookaae94602009-05-14 22:35:06 +01001#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"
Avi Kivityec3bb832011-07-26 14:26:21 +03007#include "memory.h"
Paul Brookaae94602009-05-14 22:35:06 +01008
Blue Swirlf40070c2009-07-12 19:21:36 +00009#define QDEV_MAX_MMIO 32
Gleb Natapovc646f742010-12-08 13:35:00 +020010#define QDEV_MAX_PIO 32
Evgeny Voevodinea0e6842012-01-17 02:08:19 +010011#define QDEV_MAX_IRQ 512
Paul Brookaae94602009-05-14 22:35:06 +010012
Anthony Liguori0d936922012-05-02 09:00:20 +020013#define TYPE_SYSTEM_BUS "System"
14#define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
15
Paul Brookaae94602009-05-14 22:35:06 +010016typedef struct SysBusDevice SysBusDevice;
Paul Brookaae94602009-05-14 22:35:06 +010017
Anthony Liguori999e12b2012-01-24 13:12:29 -060018#define TYPE_SYS_BUS_DEVICE "sys-bus-device"
19#define SYS_BUS_DEVICE(obj) \
20 OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE)
21#define SYS_BUS_DEVICE_CLASS(klass) \
22 OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE)
23#define SYS_BUS_DEVICE_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE)
25
26typedef struct SysBusDeviceClass {
27 DeviceClass parent_class;
28
29 int (*init)(SysBusDevice *dev);
30} SysBusDeviceClass;
31
Paul Brookaae94602009-05-14 22:35:06 +010032struct SysBusDevice {
33 DeviceState qdev;
34 int num_irq;
35 qemu_irq irqs[QDEV_MAX_IRQ];
36 qemu_irq *irqp[QDEV_MAX_IRQ];
37 int num_mmio;
38 struct {
Anthony Liguoric227f092009-10-01 16:12:16 -050039 target_phys_addr_t addr;
Avi Kivityec3bb832011-07-26 14:26:21 +030040 MemoryRegion *memory;
Paul Brookaae94602009-05-14 22:35:06 +010041 } mmio[QDEV_MAX_MMIO];
Gleb Natapovc646f742010-12-08 13:35:00 +020042 int num_pio;
43 pio_addr_t pio[QDEV_MAX_PIO];
Paul Brookaae94602009-05-14 22:35:06 +010044};
45
Paul Brookaae94602009-05-14 22:35:06 +010046/* Macros to compensate for lack of type inheritance in C. */
47#define sysbus_from_qdev(dev) ((SysBusDevice *)(dev))
48#define FROM_SYSBUS(type, dev) DO_UPCAST(type, busdev, dev)
49
Paul Brookaae94602009-05-14 22:35:06 +010050void *sysbus_new(void);
Avi Kivity750ecd42011-11-27 11:38:10 +020051void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
Peter Maydell46c305e2011-08-28 16:22:17 +000052MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
Paul Brookaae94602009-05-14 22:35:06 +010053void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
54void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
Gleb Natapovc646f742010-12-08 13:35:00 +020055void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
Paul Brookaae94602009-05-14 22:35:06 +010056
57
58void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
Anthony Liguoric227f092009-10-01 16:12:16 -050059void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
Avi Kivity2b985d92011-07-24 17:12:11 +030060void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
61 MemoryRegion *mem);
Avi Kivityd40b2af2011-07-25 15:02:17 +030062void sysbus_add_memory_overlap(SysBusDevice *dev, target_phys_addr_t addr,
63 MemoryRegion *mem, unsigned priority);
Avi Kivity2b985d92011-07-24 17:12:11 +030064void sysbus_del_memory(SysBusDevice *dev, MemoryRegion *mem);
65void sysbus_add_io(SysBusDevice *dev, target_phys_addr_t addr,
66 MemoryRegion *mem);
67void sysbus_del_io(SysBusDevice *dev, MemoryRegion *mem);
Avi Kivity62ec4832011-12-08 15:57:34 +020068MemoryRegion *sysbus_address_space(SysBusDevice *dev);
Paul Brookaae94602009-05-14 22:35:06 +010069
70/* Legacy helper function for creating devices. */
71DeviceState *sysbus_create_varargs(const char *name,
Anthony Liguoric227f092009-10-01 16:12:16 -050072 target_phys_addr_t addr, ...);
Blue Swirl49123712011-02-05 14:34:56 +000073DeviceState *sysbus_try_create_varargs(const char *name,
74 target_phys_addr_t addr, ...);
Paul Brookaae94602009-05-14 22:35:06 +010075static inline DeviceState *sysbus_create_simple(const char *name,
Anthony Liguoric227f092009-10-01 16:12:16 -050076 target_phys_addr_t addr,
Paul Brookaae94602009-05-14 22:35:06 +010077 qemu_irq irq)
78{
79 return sysbus_create_varargs(name, addr, irq, NULL);
80}
81
Blue Swirl49123712011-02-05 14:34:56 +000082static inline DeviceState *sysbus_try_create_simple(const char *name,
83 target_phys_addr_t addr,
84 qemu_irq irq)
85{
86 return sysbus_try_create_varargs(name, addr, irq, NULL);
87}
88
Paul Brookaae94602009-05-14 22:35:06 +010089#endif /* !HW_SYSBUS_H */