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