1 #ifndef HW_ISA_H 2 #define HW_ISA_H 3 4 /* ISA bus */ 5 6 #include "exec/memory.h" 7 #include "exec/ioport.h" 8 #include "hw/qdev-core.h" 9 #include "qom/object.h" 10 11 #define ISA_NUM_IRQS 16 12 13 #define TYPE_ISA_DEVICE "isa-device" 14 OBJECT_DECLARE_TYPE(ISADevice, ISADeviceClass, ISA_DEVICE) 15 16 #define TYPE_ISA_BUS "ISA" 17 OBJECT_DECLARE_SIMPLE_TYPE(ISABus, ISA_BUS) 18 19 #define TYPE_APPLE_SMC "isa-applesmc" 20 #define APPLESMC_MAX_DATA_LENGTH 32 21 #define APPLESMC_PROP_IO_BASE "iobase" 22 23 static inline uint16_t applesmc_port(void) 24 { 25 Object *obj = object_resolve_path_type("", TYPE_APPLE_SMC, NULL); 26 27 if (obj) { 28 return object_property_get_uint(obj, APPLESMC_PROP_IO_BASE, NULL); 29 } 30 return 0; 31 } 32 33 #define TYPE_ISADMA "isa-dma" 34 35 typedef struct IsaDmaClass IsaDmaClass; 36 DECLARE_CLASS_CHECKERS(IsaDmaClass, ISADMA, 37 TYPE_ISADMA) 38 #define ISADMA(obj) \ 39 INTERFACE_CHECK(IsaDma, (obj), TYPE_ISADMA) 40 41 typedef enum { 42 ISADMA_TRANSFER_VERIFY, 43 ISADMA_TRANSFER_READ, 44 ISADMA_TRANSFER_WRITE, 45 ISADMA_TRANSFER_ILLEGAL, 46 } IsaDmaTransferMode; 47 48 typedef int (*IsaDmaTransferHandler)(void *opaque, int nchan, int pos, 49 int size); 50 51 struct IsaDmaClass { 52 InterfaceClass parent; 53 54 bool (*has_autoinitialization)(IsaDma *obj, int nchan); 55 int (*read_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len); 56 int (*write_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len); 57 void (*hold_DREQ)(IsaDma *obj, int nchan); 58 void (*release_DREQ)(IsaDma *obj, int nchan); 59 void (*schedule)(IsaDma *obj); 60 void (*register_channel)(IsaDma *obj, int nchan, 61 IsaDmaTransferHandler transfer_handler, 62 void *opaque); 63 }; 64 65 struct ISADeviceClass { 66 DeviceClass parent_class; 67 }; 68 69 struct ISABus { 70 /*< private >*/ 71 BusState parent_obj; 72 /*< public >*/ 73 74 MemoryRegion *address_space; 75 MemoryRegion *address_space_io; 76 qemu_irq *irqs; 77 IsaDma *dma[2]; 78 }; 79 80 struct ISADevice { 81 /*< private >*/ 82 DeviceState parent_obj; 83 /*< public >*/ 84 85 int ioport_id; 86 }; 87 88 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space, 89 MemoryRegion *address_space_io, Error **errp); 90 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs); 91 qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq); 92 void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq); 93 void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16); 94 IsaDma *isa_get_dma(ISABus *bus, int nchan); 95 MemoryRegion *isa_address_space(ISADevice *dev); 96 MemoryRegion *isa_address_space_io(ISADevice *dev); 97 ISADevice *isa_new(const char *name); 98 ISADevice *isa_try_new(const char *name); 99 bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp); 100 ISADevice *isa_create_simple(ISABus *bus, const char *name); 101 102 ISADevice *isa_vga_init(ISABus *bus); 103 void isa_build_aml(ISABus *bus, Aml *scope); 104 105 /** 106 * isa_register_ioport: Install an I/O port region on the ISA bus. 107 * 108 * Register an I/O port region via memory_region_add_subregion 109 * inside the ISA I/O address space. 110 * 111 * @dev: the ISADevice against which these are registered; may be NULL. 112 * @io: the #MemoryRegion being registered. 113 * @start: the base I/O port. 114 */ 115 void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start); 116 117 /** 118 * isa_register_portio_list: Initialize a set of ISA io ports 119 * 120 * Several ISA devices have many dis-joint I/O ports. Worse, these I/O 121 * ports can be interleaved with I/O ports from other devices. This 122 * function makes it easy to create multiple MemoryRegions for a single 123 * device and use the legacy portio routines. 124 * 125 * @dev: the ISADevice against which these are registered; may be NULL. 126 * @piolist: the PortioList associated with the io ports 127 * @start: the base I/O port against which the portio->offset is applied. 128 * @portio: the ports, sorted by offset. 129 * @opaque: passed into the portio callbacks. 130 * @name: passed into memory_region_init_io. 131 * 132 * Returns: 0 on success, negative error code otherwise (e.g. if the 133 * ISA bus is not available) 134 */ 135 int isa_register_portio_list(ISADevice *dev, 136 PortioList *piolist, 137 uint16_t start, 138 const MemoryRegionPortio *portio, 139 void *opaque, const char *name); 140 141 static inline ISABus *isa_bus_from_device(ISADevice *d) 142 { 143 return ISA_BUS(qdev_get_parent_bus(DEVICE(d))); 144 } 145 146 #define TYPE_PIIX4_PCI_DEVICE "piix4-isa" 147 148 #endif 149