xref: /openbmc/qemu/include/hw/isa/isa.h (revision 4a09d0bb)
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.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_int(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 struct IsaDma {
47     Object parent;
48 };
49 
50 typedef enum {
51     ISADMA_TRANSFER_VERIFY,
52     ISADMA_TRANSFER_READ,
53     ISADMA_TRANSFER_WRITE,
54     ISADMA_TRANSFER_ILLEGAL,
55 } IsaDmaTransferMode;
56 
57 typedef int (*IsaDmaTransferHandler)(void *opaque, int nchan, int pos,
58                                      int size);
59 
60 typedef struct IsaDmaClass {
61     InterfaceClass parent;
62 
63     IsaDmaTransferMode (*get_transfer_mode)(IsaDma *obj, int nchan);
64     bool (*has_autoinitialization)(IsaDma *obj, int nchan);
65     int (*read_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len);
66     int (*write_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len);
67     void (*hold_DREQ)(IsaDma *obj, int nchan);
68     void (*release_DREQ)(IsaDma *obj, int nchan);
69     void (*schedule)(IsaDma *obj);
70     void (*register_channel)(IsaDma *obj, int nchan,
71                              IsaDmaTransferHandler transfer_handler,
72                              void *opaque);
73 } IsaDmaClass;
74 
75 typedef struct ISADeviceClass {
76     DeviceClass parent_class;
77 } ISADeviceClass;
78 
79 struct ISABus {
80     /*< private >*/
81     BusState parent_obj;
82     /*< public >*/
83 
84     MemoryRegion *address_space;
85     MemoryRegion *address_space_io;
86     qemu_irq *irqs;
87     IsaDma *dma[2];
88 };
89 
90 struct ISADevice {
91     /*< private >*/
92     DeviceState parent_obj;
93     /*< public >*/
94 
95     uint32_t isairq[2];
96     int nirqs;
97     int ioport_id;
98 };
99 
100 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
101                     MemoryRegion *address_space_io, Error **errp);
102 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
103 qemu_irq isa_get_irq(ISADevice *dev, int isairq);
104 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
105 void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq);
106 void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
107 IsaDma *isa_get_dma(ISABus *bus, int nchan);
108 MemoryRegion *isa_address_space(ISADevice *dev);
109 MemoryRegion *isa_address_space_io(ISADevice *dev);
110 ISADevice *isa_create(ISABus *bus, const char *name);
111 ISADevice *isa_try_create(ISABus *bus, const char *name);
112 ISADevice *isa_create_simple(ISABus *bus, const char *name);
113 
114 ISADevice *isa_vga_init(ISABus *bus);
115 
116 /**
117  * isa_register_ioport: Install an I/O port region on the ISA bus.
118  *
119  * Register an I/O port region via memory_region_add_subregion
120  * inside the ISA I/O address space.
121  *
122  * @dev: the ISADevice against which these are registered; may be NULL.
123  * @io: the #MemoryRegion being registered.
124  * @start: the base I/O port.
125  */
126 void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
127 
128 /**
129  * isa_register_portio_list: Initialize a set of ISA io ports
130  *
131  * Several ISA devices have many dis-joint I/O ports.  Worse, these I/O
132  * ports can be interleaved with I/O ports from other devices.  This
133  * function makes it easy to create multiple MemoryRegions for a single
134  * device and use the legacy portio routines.
135  *
136  * @dev: the ISADevice against which these are registered; may be NULL.
137  * @piolist: the PortioList associated with the io ports
138  * @start: the base I/O port against which the portio->offset is applied.
139  * @portio: the ports, sorted by offset.
140  * @opaque: passed into the portio callbacks.
141  * @name: passed into memory_region_init_io.
142  */
143 void isa_register_portio_list(ISADevice *dev,
144                               PortioList *piolist,
145                               uint16_t start,
146                               const MemoryRegionPortio *portio,
147                               void *opaque, const char *name);
148 
149 static inline ISABus *isa_bus_from_device(ISADevice *d)
150 {
151     return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
152 }
153 
154 /* i8257.c */
155 void DMA_init(ISABus *bus, int high_page_enable);
156 #endif
157