1 #ifndef HW_SYSBUS_H 2 #define HW_SYSBUS_H 1 3 4 /* Devices attached directly to the main system bus. */ 5 6 #include "hw/qdev.h" 7 #include "exec/memory.h" 8 9 #define QDEV_MAX_MMIO 32 10 #define QDEV_MAX_PIO 32 11 12 #define TYPE_SYSTEM_BUS "System" 13 #define SYSTEM_BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_SYSTEM_BUS) 14 15 typedef struct SysBusDevice SysBusDevice; 16 17 #define TYPE_SYS_BUS_DEVICE "sys-bus-device" 18 #define SYS_BUS_DEVICE(obj) \ 19 OBJECT_CHECK(SysBusDevice, (obj), TYPE_SYS_BUS_DEVICE) 20 #define SYS_BUS_DEVICE_CLASS(klass) \ 21 OBJECT_CLASS_CHECK(SysBusDeviceClass, (klass), TYPE_SYS_BUS_DEVICE) 22 #define SYS_BUS_DEVICE_GET_CLASS(obj) \ 23 OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE) 24 25 /** 26 * SysBusDeviceClass: 27 * @init: Callback function invoked when the #DeviceState.realized property 28 * is changed to %true. Deprecated, new types inheriting directly from 29 * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf 30 * types should consult their respective parent type. 31 * 32 * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived 33 * classes overriding it are not required to invoke its implementation. 34 */ 35 36 #define SYSBUS_DEVICE_GPIO_IRQ "sysbus-irq" 37 38 typedef struct SysBusDeviceClass { 39 /*< private >*/ 40 DeviceClass parent_class; 41 /*< public >*/ 42 43 int (*init)(SysBusDevice *dev); 44 45 /* 46 * Let the sysbus device format its own non-PIO, non-MMIO unit address. 47 * 48 * Sometimes a class of SysBusDevices has neither MMIO nor PIO resources, 49 * yet instances of it would like to distinguish themselves, in 50 * OpenFirmware device paths, from other instances of the same class on the 51 * sysbus. For that end we expose this callback. 52 * 53 * The implementation is not supposed to change *@dev, or incur other 54 * observable change. 55 * 56 * The function returns a dynamically allocated string. On error, NULL 57 * should be returned; the unit address portion of the OFW node will be 58 * omitted then. (This is not considered a fatal error.) 59 */ 60 char *(*explicit_ofw_unit_address)(const SysBusDevice *dev); 61 } SysBusDeviceClass; 62 63 struct SysBusDevice { 64 /*< private >*/ 65 DeviceState parent_obj; 66 /*< public >*/ 67 68 int num_mmio; 69 struct { 70 hwaddr addr; 71 MemoryRegion *memory; 72 } mmio[QDEV_MAX_MMIO]; 73 int num_pio; 74 pio_addr_t pio[QDEV_MAX_PIO]; 75 }; 76 77 typedef int FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); 78 79 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory); 80 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n); 81 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p); 82 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target); 83 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size); 84 85 86 bool sysbus_has_irq(SysBusDevice *dev, int n); 87 bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n); 88 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq); 89 bool sysbus_is_irq_connected(SysBusDevice *dev, int n); 90 qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n); 91 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr); 92 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr, 93 int priority); 94 void sysbus_add_io(SysBusDevice *dev, hwaddr addr, 95 MemoryRegion *mem); 96 MemoryRegion *sysbus_address_space(SysBusDevice *dev); 97 98 /* Call func for every dynamically created sysbus device in the system */ 99 void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc *func, void *opaque); 100 101 /* Legacy helper function for creating devices. */ 102 DeviceState *sysbus_create_varargs(const char *name, 103 hwaddr addr, ...); 104 DeviceState *sysbus_try_create_varargs(const char *name, 105 hwaddr addr, ...); 106 static inline DeviceState *sysbus_create_simple(const char *name, 107 hwaddr addr, 108 qemu_irq irq) 109 { 110 return sysbus_create_varargs(name, addr, irq, NULL); 111 } 112 113 static inline DeviceState *sysbus_try_create_simple(const char *name, 114 hwaddr addr, 115 qemu_irq irq) 116 { 117 return sysbus_try_create_varargs(name, addr, irq, NULL); 118 } 119 120 #endif /* !HW_SYSBUS_H */ 121