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