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