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