1#ifndef HW_ISA_H
2#define HW_ISA_H
3
4
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
27static 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
46struct IsaDma {
47 Object parent;
48};
49
50typedef enum {
51 ISADMA_TRANSFER_VERIFY,
52 ISADMA_TRANSFER_READ,
53 ISADMA_TRANSFER_WRITE,
54 ISADMA_TRANSFER_ILLEGAL,
55} IsaDmaTransferMode;
56
57typedef int (*IsaDmaTransferHandler)(void *opaque, int nchan, int pos,
58 int size);
59
60typedef 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
75typedef struct ISADeviceClass {
76 DeviceClass parent_class;
77} ISADeviceClass;
78
79struct ISABus {
80
81 BusState parent_obj;
82
83
84 MemoryRegion *address_space;
85 MemoryRegion *address_space_io;
86 qemu_irq *irqs;
87 IsaDma *dma[2];
88};
89
90struct ISADevice {
91
92 DeviceState parent_obj;
93
94
95 uint32_t isairq[2];
96 int nirqs;
97 int ioport_id;
98};
99
100ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
101 MemoryRegion *address_space_io, Error **errp);
102void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
103qemu_irq isa_get_irq(ISADevice *dev, int isairq);
104void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
105void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq);
106void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
107IsaDma *isa_get_dma(ISABus *bus, int nchan);
108MemoryRegion *isa_address_space(ISADevice *dev);
109MemoryRegion *isa_address_space_io(ISADevice *dev);
110ISADevice *isa_create(ISABus *bus, const char *name);
111ISADevice *isa_try_create(ISABus *bus, const char *name);
112ISADevice *isa_create_simple(ISABus *bus, const char *name);
113
114ISADevice *isa_vga_init(ISABus *bus);
115
116
117
118
119
120
121
122
123
124
125
126void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143void isa_register_portio_list(ISADevice *dev,
144 PortioList *piolist,
145 uint16_t start,
146 const MemoryRegionPortio *portio,
147 void *opaque, const char *name);
148
149static inline ISABus *isa_bus_from_device(ISADevice *d)
150{
151 return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
152}
153
154#endif
155