root / ioport.c @ a8a00822
History | View | Annotate | Download (12.3 kB)
1 | 32993977 | Isaku Yamahata | /*
|
---|---|---|---|
2 | 32993977 | Isaku Yamahata | * QEMU System Emulator
|
3 | 32993977 | Isaku Yamahata | *
|
4 | 32993977 | Isaku Yamahata | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | 32993977 | Isaku Yamahata | *
|
6 | 32993977 | Isaku Yamahata | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 32993977 | Isaku Yamahata | * of this software and associated documentation files (the "Software"), to deal
|
8 | 32993977 | Isaku Yamahata | * in the Software without restriction, including without limitation the rights
|
9 | 32993977 | Isaku Yamahata | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 32993977 | Isaku Yamahata | * copies of the Software, and to permit persons to whom the Software is
|
11 | 32993977 | Isaku Yamahata | * furnished to do so, subject to the following conditions:
|
12 | 32993977 | Isaku Yamahata | *
|
13 | 32993977 | Isaku Yamahata | * The above copyright notice and this permission notice shall be included in
|
14 | 32993977 | Isaku Yamahata | * all copies or substantial portions of the Software.
|
15 | 32993977 | Isaku Yamahata | *
|
16 | 32993977 | Isaku Yamahata | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 32993977 | Isaku Yamahata | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 32993977 | Isaku Yamahata | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 32993977 | Isaku Yamahata | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 32993977 | Isaku Yamahata | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 32993977 | Isaku Yamahata | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 32993977 | Isaku Yamahata | * THE SOFTWARE.
|
23 | 32993977 | Isaku Yamahata | */
|
24 | 32993977 | Isaku Yamahata | /*
|
25 | 32993977 | Isaku Yamahata | * splitted out ioport related stuffs from vl.c.
|
26 | 32993977 | Isaku Yamahata | */
|
27 | 32993977 | Isaku Yamahata | |
28 | 32993977 | Isaku Yamahata | #include "ioport.h" |
29 | bd3c9aa5 | Prerna Saxena | #include "trace.h" |
30 | 6bf9fd43 | Avi Kivity | #include "memory.h" |
31 | 32993977 | Isaku Yamahata | |
32 | 32993977 | Isaku Yamahata | /***********************************************************/
|
33 | 32993977 | Isaku Yamahata | /* IO Port */
|
34 | 32993977 | Isaku Yamahata | |
35 | 32993977 | Isaku Yamahata | //#define DEBUG_UNUSED_IOPORT
|
36 | 32993977 | Isaku Yamahata | //#define DEBUG_IOPORT
|
37 | 32993977 | Isaku Yamahata | |
38 | fc7083b5 | Isaku Yamahata | #ifdef DEBUG_UNUSED_IOPORT
|
39 | fc7083b5 | Isaku Yamahata | # define LOG_UNUSED_IOPORT(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) |
40 | fc7083b5 | Isaku Yamahata | #else
|
41 | fc7083b5 | Isaku Yamahata | # define LOG_UNUSED_IOPORT(fmt, ...) do{ } while (0) |
42 | fc7083b5 | Isaku Yamahata | #endif
|
43 | fc7083b5 | Isaku Yamahata | |
44 | 32993977 | Isaku Yamahata | #ifdef DEBUG_IOPORT
|
45 | 32993977 | Isaku Yamahata | # define LOG_IOPORT(...) qemu_log_mask(CPU_LOG_IOPORT, ## __VA_ARGS__) |
46 | 32993977 | Isaku Yamahata | #else
|
47 | 32993977 | Isaku Yamahata | # define LOG_IOPORT(...) do { } while (0) |
48 | 32993977 | Isaku Yamahata | #endif
|
49 | 32993977 | Isaku Yamahata | |
50 | 32993977 | Isaku Yamahata | /* XXX: use a two level table to limit memory usage */
|
51 | 32993977 | Isaku Yamahata | |
52 | 32993977 | Isaku Yamahata | static void *ioport_opaque[MAX_IOPORTS]; |
53 | 32993977 | Isaku Yamahata | static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; |
54 | 32993977 | Isaku Yamahata | static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; |
55 | 32993977 | Isaku Yamahata | |
56 | 32993977 | Isaku Yamahata | static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl;
|
57 | 32993977 | Isaku Yamahata | static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel;
|
58 | 32993977 | Isaku Yamahata | |
59 | 32993977 | Isaku Yamahata | static uint32_t ioport_read(int index, uint32_t address) |
60 | 32993977 | Isaku Yamahata | { |
61 | 1dde6fcc | Blue Swirl | static IOPortReadFunc * const default_func[3] = { |
62 | 32993977 | Isaku Yamahata | default_ioport_readb, |
63 | 32993977 | Isaku Yamahata | default_ioport_readw, |
64 | 32993977 | Isaku Yamahata | default_ioport_readl |
65 | 32993977 | Isaku Yamahata | }; |
66 | 32993977 | Isaku Yamahata | IOPortReadFunc *func = ioport_read_table[index][address]; |
67 | 32993977 | Isaku Yamahata | if (!func)
|
68 | 32993977 | Isaku Yamahata | func = default_func[index]; |
69 | 32993977 | Isaku Yamahata | return func(ioport_opaque[address], address);
|
70 | 32993977 | Isaku Yamahata | } |
71 | 32993977 | Isaku Yamahata | |
72 | 32993977 | Isaku Yamahata | static void ioport_write(int index, uint32_t address, uint32_t data) |
73 | 32993977 | Isaku Yamahata | { |
74 | 1dde6fcc | Blue Swirl | static IOPortWriteFunc * const default_func[3] = { |
75 | 32993977 | Isaku Yamahata | default_ioport_writeb, |
76 | 32993977 | Isaku Yamahata | default_ioport_writew, |
77 | 32993977 | Isaku Yamahata | default_ioport_writel |
78 | 32993977 | Isaku Yamahata | }; |
79 | 32993977 | Isaku Yamahata | IOPortWriteFunc *func = ioport_write_table[index][address]; |
80 | 32993977 | Isaku Yamahata | if (!func)
|
81 | 32993977 | Isaku Yamahata | func = default_func[index]; |
82 | 32993977 | Isaku Yamahata | func(ioport_opaque[address], address, data); |
83 | 32993977 | Isaku Yamahata | } |
84 | 32993977 | Isaku Yamahata | |
85 | 32993977 | Isaku Yamahata | static uint32_t default_ioport_readb(void *opaque, uint32_t address) |
86 | 32993977 | Isaku Yamahata | { |
87 | fc7083b5 | Isaku Yamahata | LOG_UNUSED_IOPORT("unused inb: port=0x%04"PRIx32"\n", address); |
88 | 32993977 | Isaku Yamahata | return 0xff; |
89 | 32993977 | Isaku Yamahata | } |
90 | 32993977 | Isaku Yamahata | |
91 | 32993977 | Isaku Yamahata | static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) |
92 | 32993977 | Isaku Yamahata | { |
93 | fc7083b5 | Isaku Yamahata | LOG_UNUSED_IOPORT("unused outb: port=0x%04"PRIx32" data=0x%02"PRIx32"\n", |
94 | fc7083b5 | Isaku Yamahata | address, data); |
95 | 32993977 | Isaku Yamahata | } |
96 | 32993977 | Isaku Yamahata | |
97 | 32993977 | Isaku Yamahata | /* default is to make two byte accesses */
|
98 | 32993977 | Isaku Yamahata | static uint32_t default_ioport_readw(void *opaque, uint32_t address) |
99 | 32993977 | Isaku Yamahata | { |
100 | 32993977 | Isaku Yamahata | uint32_t data; |
101 | 32993977 | Isaku Yamahata | data = ioport_read(0, address);
|
102 | d56dd6cf | Isaku Yamahata | address = (address + 1) & IOPORTS_MASK;
|
103 | 32993977 | Isaku Yamahata | data |= ioport_read(0, address) << 8; |
104 | 32993977 | Isaku Yamahata | return data;
|
105 | 32993977 | Isaku Yamahata | } |
106 | 32993977 | Isaku Yamahata | |
107 | 32993977 | Isaku Yamahata | static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) |
108 | 32993977 | Isaku Yamahata | { |
109 | 32993977 | Isaku Yamahata | ioport_write(0, address, data & 0xff); |
110 | d56dd6cf | Isaku Yamahata | address = (address + 1) & IOPORTS_MASK;
|
111 | 32993977 | Isaku Yamahata | ioport_write(0, address, (data >> 8) & 0xff); |
112 | 32993977 | Isaku Yamahata | } |
113 | 32993977 | Isaku Yamahata | |
114 | 32993977 | Isaku Yamahata | static uint32_t default_ioport_readl(void *opaque, uint32_t address) |
115 | 32993977 | Isaku Yamahata | { |
116 | fc7083b5 | Isaku Yamahata | LOG_UNUSED_IOPORT("unused inl: port=0x%04"PRIx32"\n", address); |
117 | 32993977 | Isaku Yamahata | return 0xffffffff; |
118 | 32993977 | Isaku Yamahata | } |
119 | 32993977 | Isaku Yamahata | |
120 | 32993977 | Isaku Yamahata | static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) |
121 | 32993977 | Isaku Yamahata | { |
122 | fc7083b5 | Isaku Yamahata | LOG_UNUSED_IOPORT("unused outl: port=0x%04"PRIx32" data=0x%02"PRIx32"\n", |
123 | fc7083b5 | Isaku Yamahata | address, data); |
124 | 32993977 | Isaku Yamahata | } |
125 | 32993977 | Isaku Yamahata | |
126 | 23e0affd | Isaku Yamahata | static int ioport_bsize(int size, int *bsize) |
127 | 23e0affd | Isaku Yamahata | { |
128 | 23e0affd | Isaku Yamahata | if (size == 1) { |
129 | 23e0affd | Isaku Yamahata | *bsize = 0;
|
130 | 23e0affd | Isaku Yamahata | } else if (size == 2) { |
131 | 23e0affd | Isaku Yamahata | *bsize = 1;
|
132 | 23e0affd | Isaku Yamahata | } else if (size == 4) { |
133 | 23e0affd | Isaku Yamahata | *bsize = 2;
|
134 | 23e0affd | Isaku Yamahata | } else {
|
135 | 23e0affd | Isaku Yamahata | return -1; |
136 | 23e0affd | Isaku Yamahata | } |
137 | 23e0affd | Isaku Yamahata | return 0; |
138 | 23e0affd | Isaku Yamahata | } |
139 | 23e0affd | Isaku Yamahata | |
140 | 32993977 | Isaku Yamahata | /* size is the word size in byte */
|
141 | c227f099 | Anthony Liguori | int register_ioport_read(pio_addr_t start, int length, int size, |
142 | 32993977 | Isaku Yamahata | IOPortReadFunc *func, void *opaque)
|
143 | 32993977 | Isaku Yamahata | { |
144 | 32993977 | Isaku Yamahata | int i, bsize;
|
145 | 32993977 | Isaku Yamahata | |
146 | 23e0affd | Isaku Yamahata | if (ioport_bsize(size, &bsize)) {
|
147 | 32993977 | Isaku Yamahata | hw_error("register_ioport_read: invalid size");
|
148 | 32993977 | Isaku Yamahata | return -1; |
149 | 32993977 | Isaku Yamahata | } |
150 | bf3fb0e1 | Avi Kivity | for(i = start; i < start + length; ++i) {
|
151 | 32993977 | Isaku Yamahata | ioport_read_table[bsize][i] = func; |
152 | 32993977 | Isaku Yamahata | if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) |
153 | f66a99d7 | Andreas Fรคrber | hw_error("register_ioport_read: invalid opaque for address 0x%x",
|
154 | f66a99d7 | Andreas Fรคrber | i); |
155 | 32993977 | Isaku Yamahata | ioport_opaque[i] = opaque; |
156 | 32993977 | Isaku Yamahata | } |
157 | 32993977 | Isaku Yamahata | return 0; |
158 | 32993977 | Isaku Yamahata | } |
159 | 32993977 | Isaku Yamahata | |
160 | 32993977 | Isaku Yamahata | /* size is the word size in byte */
|
161 | c227f099 | Anthony Liguori | int register_ioport_write(pio_addr_t start, int length, int size, |
162 | 32993977 | Isaku Yamahata | IOPortWriteFunc *func, void *opaque)
|
163 | 32993977 | Isaku Yamahata | { |
164 | 32993977 | Isaku Yamahata | int i, bsize;
|
165 | 32993977 | Isaku Yamahata | |
166 | 23e0affd | Isaku Yamahata | if (ioport_bsize(size, &bsize)) {
|
167 | 32993977 | Isaku Yamahata | hw_error("register_ioport_write: invalid size");
|
168 | 32993977 | Isaku Yamahata | return -1; |
169 | 32993977 | Isaku Yamahata | } |
170 | bf3fb0e1 | Avi Kivity | for(i = start; i < start + length; ++i) {
|
171 | 32993977 | Isaku Yamahata | ioport_write_table[bsize][i] = func; |
172 | 32993977 | Isaku Yamahata | if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque) |
173 | f66a99d7 | Andreas Fรคrber | hw_error("register_ioport_write: invalid opaque for address 0x%x",
|
174 | f66a99d7 | Andreas Fรคrber | i); |
175 | 32993977 | Isaku Yamahata | ioport_opaque[i] = opaque; |
176 | 32993977 | Isaku Yamahata | } |
177 | 32993977 | Isaku Yamahata | return 0; |
178 | 32993977 | Isaku Yamahata | } |
179 | 32993977 | Isaku Yamahata | |
180 | acd1c812 | Avi Kivity | static uint32_t ioport_readb_thunk(void *opaque, uint32_t addr) |
181 | acd1c812 | Avi Kivity | { |
182 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
183 | acd1c812 | Avi Kivity | uint64_t data; |
184 | acd1c812 | Avi Kivity | |
185 | acd1c812 | Avi Kivity | ioport->ops->read(ioport, addr - ioport->base, 1, &data);
|
186 | acd1c812 | Avi Kivity | return data;
|
187 | acd1c812 | Avi Kivity | } |
188 | acd1c812 | Avi Kivity | |
189 | acd1c812 | Avi Kivity | static uint32_t ioport_readw_thunk(void *opaque, uint32_t addr) |
190 | acd1c812 | Avi Kivity | { |
191 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
192 | acd1c812 | Avi Kivity | uint64_t data; |
193 | acd1c812 | Avi Kivity | |
194 | acd1c812 | Avi Kivity | ioport->ops->read(ioport, addr - ioport->base, 2, &data);
|
195 | acd1c812 | Avi Kivity | return data;
|
196 | acd1c812 | Avi Kivity | } |
197 | acd1c812 | Avi Kivity | |
198 | acd1c812 | Avi Kivity | static uint32_t ioport_readl_thunk(void *opaque, uint32_t addr) |
199 | acd1c812 | Avi Kivity | { |
200 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
201 | acd1c812 | Avi Kivity | uint64_t data; |
202 | acd1c812 | Avi Kivity | |
203 | acd1c812 | Avi Kivity | ioport->ops->read(ioport, addr - ioport->base, 4, &data);
|
204 | acd1c812 | Avi Kivity | return data;
|
205 | acd1c812 | Avi Kivity | } |
206 | acd1c812 | Avi Kivity | |
207 | acd1c812 | Avi Kivity | static void ioport_writeb_thunk(void *opaque, uint32_t addr, uint32_t data) |
208 | acd1c812 | Avi Kivity | { |
209 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
210 | acd1c812 | Avi Kivity | |
211 | acd1c812 | Avi Kivity | ioport->ops->write(ioport, addr - ioport->base, 1, data);
|
212 | acd1c812 | Avi Kivity | } |
213 | acd1c812 | Avi Kivity | |
214 | acd1c812 | Avi Kivity | static void ioport_writew_thunk(void *opaque, uint32_t addr, uint32_t data) |
215 | acd1c812 | Avi Kivity | { |
216 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
217 | acd1c812 | Avi Kivity | |
218 | acd1c812 | Avi Kivity | ioport->ops->write(ioport, addr - ioport->base, 2, data);
|
219 | acd1c812 | Avi Kivity | } |
220 | acd1c812 | Avi Kivity | |
221 | acd1c812 | Avi Kivity | static void ioport_writel_thunk(void *opaque, uint32_t addr, uint32_t data) |
222 | acd1c812 | Avi Kivity | { |
223 | acd1c812 | Avi Kivity | IORange *ioport = opaque; |
224 | acd1c812 | Avi Kivity | |
225 | acd1c812 | Avi Kivity | ioport->ops->write(ioport, addr - ioport->base, 4, data);
|
226 | acd1c812 | Avi Kivity | } |
227 | acd1c812 | Avi Kivity | |
228 | acd1c812 | Avi Kivity | void ioport_register(IORange *ioport)
|
229 | acd1c812 | Avi Kivity | { |
230 | acd1c812 | Avi Kivity | register_ioport_read(ioport->base, ioport->len, 1,
|
231 | acd1c812 | Avi Kivity | ioport_readb_thunk, ioport); |
232 | acd1c812 | Avi Kivity | register_ioport_read(ioport->base, ioport->len, 2,
|
233 | acd1c812 | Avi Kivity | ioport_readw_thunk, ioport); |
234 | acd1c812 | Avi Kivity | register_ioport_read(ioport->base, ioport->len, 4,
|
235 | acd1c812 | Avi Kivity | ioport_readl_thunk, ioport); |
236 | acd1c812 | Avi Kivity | register_ioport_write(ioport->base, ioport->len, 1,
|
237 | acd1c812 | Avi Kivity | ioport_writeb_thunk, ioport); |
238 | acd1c812 | Avi Kivity | register_ioport_write(ioport->base, ioport->len, 2,
|
239 | acd1c812 | Avi Kivity | ioport_writew_thunk, ioport); |
240 | acd1c812 | Avi Kivity | register_ioport_write(ioport->base, ioport->len, 4,
|
241 | acd1c812 | Avi Kivity | ioport_writel_thunk, ioport); |
242 | acd1c812 | Avi Kivity | } |
243 | acd1c812 | Avi Kivity | |
244 | c227f099 | Anthony Liguori | void isa_unassign_ioport(pio_addr_t start, int length) |
245 | 32993977 | Isaku Yamahata | { |
246 | 32993977 | Isaku Yamahata | int i;
|
247 | 32993977 | Isaku Yamahata | |
248 | 32993977 | Isaku Yamahata | for(i = start; i < start + length; i++) {
|
249 | 6141dbfe | Paolo Bonzini | ioport_read_table[0][i] = NULL; |
250 | 6141dbfe | Paolo Bonzini | ioport_read_table[1][i] = NULL; |
251 | 6141dbfe | Paolo Bonzini | ioport_read_table[2][i] = NULL; |
252 | 32993977 | Isaku Yamahata | |
253 | 6141dbfe | Paolo Bonzini | ioport_write_table[0][i] = NULL; |
254 | 6141dbfe | Paolo Bonzini | ioport_write_table[1][i] = NULL; |
255 | 6141dbfe | Paolo Bonzini | ioport_write_table[2][i] = NULL; |
256 | 32993977 | Isaku Yamahata | |
257 | 32993977 | Isaku Yamahata | ioport_opaque[i] = NULL;
|
258 | 32993977 | Isaku Yamahata | } |
259 | 32993977 | Isaku Yamahata | } |
260 | 32993977 | Isaku Yamahata | |
261 | 6141dbfe | Paolo Bonzini | bool isa_is_ioport_assigned(pio_addr_t start)
|
262 | 6141dbfe | Paolo Bonzini | { |
263 | 6141dbfe | Paolo Bonzini | return (ioport_read_table[0][start] || ioport_write_table[0][start] || |
264 | 6141dbfe | Paolo Bonzini | ioport_read_table[1][start] || ioport_write_table[1][start] || |
265 | 6141dbfe | Paolo Bonzini | ioport_read_table[2][start] || ioport_write_table[2][start]); |
266 | 6141dbfe | Paolo Bonzini | } |
267 | 6141dbfe | Paolo Bonzini | |
268 | 32993977 | Isaku Yamahata | /***********************************************************/
|
269 | 32993977 | Isaku Yamahata | |
270 | c227f099 | Anthony Liguori | void cpu_outb(pio_addr_t addr, uint8_t val)
|
271 | 32993977 | Isaku Yamahata | { |
272 | 07323531 | Isaku Yamahata | LOG_IOPORT("outb: %04"FMT_pioaddr" %02"PRIx8"\n", addr, val); |
273 | bd3c9aa5 | Prerna Saxena | trace_cpu_out(addr, val); |
274 | 32993977 | Isaku Yamahata | ioport_write(0, addr, val);
|
275 | 32993977 | Isaku Yamahata | } |
276 | 32993977 | Isaku Yamahata | |
277 | c227f099 | Anthony Liguori | void cpu_outw(pio_addr_t addr, uint16_t val)
|
278 | 32993977 | Isaku Yamahata | { |
279 | 07323531 | Isaku Yamahata | LOG_IOPORT("outw: %04"FMT_pioaddr" %04"PRIx16"\n", addr, val); |
280 | bd3c9aa5 | Prerna Saxena | trace_cpu_out(addr, val); |
281 | 32993977 | Isaku Yamahata | ioport_write(1, addr, val);
|
282 | 32993977 | Isaku Yamahata | } |
283 | 32993977 | Isaku Yamahata | |
284 | c227f099 | Anthony Liguori | void cpu_outl(pio_addr_t addr, uint32_t val)
|
285 | 32993977 | Isaku Yamahata | { |
286 | 07323531 | Isaku Yamahata | LOG_IOPORT("outl: %04"FMT_pioaddr" %08"PRIx32"\n", addr, val); |
287 | bd3c9aa5 | Prerna Saxena | trace_cpu_out(addr, val); |
288 | 32993977 | Isaku Yamahata | ioport_write(2, addr, val);
|
289 | 32993977 | Isaku Yamahata | } |
290 | 32993977 | Isaku Yamahata | |
291 | c227f099 | Anthony Liguori | uint8_t cpu_inb(pio_addr_t addr) |
292 | 32993977 | Isaku Yamahata | { |
293 | 07323531 | Isaku Yamahata | uint8_t val; |
294 | 32993977 | Isaku Yamahata | val = ioport_read(0, addr);
|
295 | bd3c9aa5 | Prerna Saxena | trace_cpu_in(addr, val); |
296 | 07323531 | Isaku Yamahata | LOG_IOPORT("inb : %04"FMT_pioaddr" %02"PRIx8"\n", addr, val); |
297 | 32993977 | Isaku Yamahata | return val;
|
298 | 32993977 | Isaku Yamahata | } |
299 | 32993977 | Isaku Yamahata | |
300 | c227f099 | Anthony Liguori | uint16_t cpu_inw(pio_addr_t addr) |
301 | 32993977 | Isaku Yamahata | { |
302 | 07323531 | Isaku Yamahata | uint16_t val; |
303 | 32993977 | Isaku Yamahata | val = ioport_read(1, addr);
|
304 | bd3c9aa5 | Prerna Saxena | trace_cpu_in(addr, val); |
305 | 07323531 | Isaku Yamahata | LOG_IOPORT("inw : %04"FMT_pioaddr" %04"PRIx16"\n", addr, val); |
306 | 32993977 | Isaku Yamahata | return val;
|
307 | 32993977 | Isaku Yamahata | } |
308 | 32993977 | Isaku Yamahata | |
309 | c227f099 | Anthony Liguori | uint32_t cpu_inl(pio_addr_t addr) |
310 | 32993977 | Isaku Yamahata | { |
311 | 07323531 | Isaku Yamahata | uint32_t val; |
312 | 32993977 | Isaku Yamahata | val = ioport_read(2, addr);
|
313 | bd3c9aa5 | Prerna Saxena | trace_cpu_in(addr, val); |
314 | 07323531 | Isaku Yamahata | LOG_IOPORT("inl : %04"FMT_pioaddr" %08"PRIx32"\n", addr, val); |
315 | 32993977 | Isaku Yamahata | return val;
|
316 | 32993977 | Isaku Yamahata | } |
317 | 6bf9fd43 | Avi Kivity | |
318 | 6bf9fd43 | Avi Kivity | void portio_list_init(PortioList *piolist,
|
319 | 6bf9fd43 | Avi Kivity | const MemoryRegionPortio *callbacks,
|
320 | 6bf9fd43 | Avi Kivity | void *opaque, const char *name) |
321 | 6bf9fd43 | Avi Kivity | { |
322 | 6bf9fd43 | Avi Kivity | unsigned n = 0; |
323 | 6bf9fd43 | Avi Kivity | |
324 | 6bf9fd43 | Avi Kivity | while (callbacks[n].size) {
|
325 | 6bf9fd43 | Avi Kivity | ++n; |
326 | 6bf9fd43 | Avi Kivity | } |
327 | 6bf9fd43 | Avi Kivity | |
328 | 6bf9fd43 | Avi Kivity | piolist->ports = callbacks; |
329 | 6bf9fd43 | Avi Kivity | piolist->nr = 0;
|
330 | 6bf9fd43 | Avi Kivity | piolist->regions = g_new0(MemoryRegion *, n); |
331 | 6bf9fd43 | Avi Kivity | piolist->address_space = NULL;
|
332 | 6bf9fd43 | Avi Kivity | piolist->opaque = opaque; |
333 | 6bf9fd43 | Avi Kivity | piolist->name = name; |
334 | 6bf9fd43 | Avi Kivity | } |
335 | 6bf9fd43 | Avi Kivity | |
336 | 6bf9fd43 | Avi Kivity | void portio_list_destroy(PortioList *piolist)
|
337 | 6bf9fd43 | Avi Kivity | { |
338 | 6bf9fd43 | Avi Kivity | g_free(piolist->regions); |
339 | 6bf9fd43 | Avi Kivity | } |
340 | 6bf9fd43 | Avi Kivity | |
341 | 6bf9fd43 | Avi Kivity | static void portio_list_add_1(PortioList *piolist, |
342 | 6bf9fd43 | Avi Kivity | const MemoryRegionPortio *pio_init,
|
343 | 6bf9fd43 | Avi Kivity | unsigned count, unsigned start, |
344 | 6bf9fd43 | Avi Kivity | unsigned off_low, unsigned off_high) |
345 | 6bf9fd43 | Avi Kivity | { |
346 | 6bf9fd43 | Avi Kivity | MemoryRegionPortio *pio; |
347 | 6bf9fd43 | Avi Kivity | MemoryRegionOps *ops; |
348 | 6bf9fd43 | Avi Kivity | MemoryRegion *region; |
349 | 6bf9fd43 | Avi Kivity | unsigned i;
|
350 | 6bf9fd43 | Avi Kivity | |
351 | 6bf9fd43 | Avi Kivity | /* Copy the sub-list and null-terminate it. */
|
352 | 6bf9fd43 | Avi Kivity | pio = g_new(MemoryRegionPortio, count + 1);
|
353 | 6bf9fd43 | Avi Kivity | memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count);
|
354 | 6bf9fd43 | Avi Kivity | memset(pio + count, 0, sizeof(MemoryRegionPortio)); |
355 | 6bf9fd43 | Avi Kivity | |
356 | 6bf9fd43 | Avi Kivity | /* Adjust the offsets to all be zero-based for the region. */
|
357 | 6bf9fd43 | Avi Kivity | for (i = 0; i < count; ++i) { |
358 | 6bf9fd43 | Avi Kivity | pio[i].offset -= off_low; |
359 | 6bf9fd43 | Avi Kivity | } |
360 | 6bf9fd43 | Avi Kivity | |
361 | 6bf9fd43 | Avi Kivity | ops = g_new0(MemoryRegionOps, 1);
|
362 | 6bf9fd43 | Avi Kivity | ops->old_portio = pio; |
363 | 6bf9fd43 | Avi Kivity | |
364 | 6bf9fd43 | Avi Kivity | region = g_new(MemoryRegion, 1);
|
365 | 6bf9fd43 | Avi Kivity | memory_region_init_io(region, ops, piolist->opaque, piolist->name, |
366 | 6bf9fd43 | Avi Kivity | off_high - off_low); |
367 | 6bf9fd43 | Avi Kivity | memory_region_set_offset(region, start + off_low); |
368 | 6bf9fd43 | Avi Kivity | memory_region_add_subregion(piolist->address_space, |
369 | 6bf9fd43 | Avi Kivity | start + off_low, region); |
370 | 6bf9fd43 | Avi Kivity | piolist->regions[piolist->nr++] = region; |
371 | 6bf9fd43 | Avi Kivity | } |
372 | 6bf9fd43 | Avi Kivity | |
373 | 6bf9fd43 | Avi Kivity | void portio_list_add(PortioList *piolist,
|
374 | 6bf9fd43 | Avi Kivity | MemoryRegion *address_space, |
375 | 6bf9fd43 | Avi Kivity | uint32_t start) |
376 | 6bf9fd43 | Avi Kivity | { |
377 | 6bf9fd43 | Avi Kivity | const MemoryRegionPortio *pio, *pio_start = piolist->ports;
|
378 | 6bf9fd43 | Avi Kivity | unsigned int off_low, off_high, off_last, count; |
379 | 6bf9fd43 | Avi Kivity | |
380 | 6bf9fd43 | Avi Kivity | piolist->address_space = address_space; |
381 | 6bf9fd43 | Avi Kivity | |
382 | 6bf9fd43 | Avi Kivity | /* Handle the first entry specially. */
|
383 | 6bf9fd43 | Avi Kivity | off_last = off_low = pio_start->offset; |
384 | 6bf9fd43 | Avi Kivity | off_high = off_low + pio_start->len; |
385 | 6bf9fd43 | Avi Kivity | count = 1;
|
386 | 6bf9fd43 | Avi Kivity | |
387 | 6bf9fd43 | Avi Kivity | for (pio = pio_start + 1; pio->size != 0; pio++, count++) { |
388 | 6bf9fd43 | Avi Kivity | /* All entries must be sorted by offset. */
|
389 | 6bf9fd43 | Avi Kivity | assert(pio->offset >= off_last); |
390 | 6bf9fd43 | Avi Kivity | off_last = pio->offset; |
391 | 6bf9fd43 | Avi Kivity | |
392 | 6bf9fd43 | Avi Kivity | /* If we see a hole, break the region. */
|
393 | 6bf9fd43 | Avi Kivity | if (off_last > off_high) {
|
394 | 6bf9fd43 | Avi Kivity | portio_list_add_1(piolist, pio_start, count, start, off_low, |
395 | 6bf9fd43 | Avi Kivity | off_high); |
396 | 6bf9fd43 | Avi Kivity | /* ... and start collecting anew. */
|
397 | 6bf9fd43 | Avi Kivity | pio_start = pio; |
398 | 6bf9fd43 | Avi Kivity | off_low = off_last; |
399 | 6bf9fd43 | Avi Kivity | off_high = off_low + pio->len; |
400 | 6bf9fd43 | Avi Kivity | count = 0;
|
401 | 6bf9fd43 | Avi Kivity | } else if (off_last + pio->len > off_high) { |
402 | 6bf9fd43 | Avi Kivity | off_high = off_last + pio->len; |
403 | 6bf9fd43 | Avi Kivity | } |
404 | 6bf9fd43 | Avi Kivity | } |
405 | 6bf9fd43 | Avi Kivity | |
406 | 6bf9fd43 | Avi Kivity | /* There will always be an open sub-list. */
|
407 | 6bf9fd43 | Avi Kivity | portio_list_add_1(piolist, pio_start, count, start, off_low, off_high); |
408 | 6bf9fd43 | Avi Kivity | } |
409 | 6bf9fd43 | Avi Kivity | |
410 | 6bf9fd43 | Avi Kivity | void portio_list_del(PortioList *piolist)
|
411 | 6bf9fd43 | Avi Kivity | { |
412 | 6bf9fd43 | Avi Kivity | MemoryRegion *mr; |
413 | 6bf9fd43 | Avi Kivity | unsigned i;
|
414 | 6bf9fd43 | Avi Kivity | |
415 | 6bf9fd43 | Avi Kivity | for (i = 0; i < piolist->nr; ++i) { |
416 | 6bf9fd43 | Avi Kivity | mr = piolist->regions[i]; |
417 | 6bf9fd43 | Avi Kivity | memory_region_del_subregion(piolist->address_space, mr); |
418 | 6bf9fd43 | Avi Kivity | memory_region_destroy(mr); |
419 | 6bf9fd43 | Avi Kivity | g_free((MemoryRegionOps *)mr->ops); |
420 | 6bf9fd43 | Avi Kivity | g_free(mr); |
421 | 6bf9fd43 | Avi Kivity | piolist->regions[i] = NULL;
|
422 | 6bf9fd43 | Avi Kivity | } |
423 | 6bf9fd43 | Avi Kivity | } |