Revision acd1c812
b/ioport.c | ||
---|---|---|
174 | 174 |
return 0; |
175 | 175 |
} |
176 | 176 |
|
177 |
static uint32_t ioport_readb_thunk(void *opaque, uint32_t addr) |
|
178 |
{ |
|
179 |
IORange *ioport = opaque; |
|
180 |
uint64_t data; |
|
181 |
|
|
182 |
ioport->ops->read(ioport, addr - ioport->base, 1, &data); |
|
183 |
return data; |
|
184 |
} |
|
185 |
|
|
186 |
static uint32_t ioport_readw_thunk(void *opaque, uint32_t addr) |
|
187 |
{ |
|
188 |
IORange *ioport = opaque; |
|
189 |
uint64_t data; |
|
190 |
|
|
191 |
ioport->ops->read(ioport, addr - ioport->base, 2, &data); |
|
192 |
return data; |
|
193 |
} |
|
194 |
|
|
195 |
static uint32_t ioport_readl_thunk(void *opaque, uint32_t addr) |
|
196 |
{ |
|
197 |
IORange *ioport = opaque; |
|
198 |
uint64_t data; |
|
199 |
|
|
200 |
ioport->ops->read(ioport, addr - ioport->base, 4, &data); |
|
201 |
return data; |
|
202 |
} |
|
203 |
|
|
204 |
static void ioport_writeb_thunk(void *opaque, uint32_t addr, uint32_t data) |
|
205 |
{ |
|
206 |
IORange *ioport = opaque; |
|
207 |
|
|
208 |
ioport->ops->write(ioport, addr - ioport->base, 1, data); |
|
209 |
} |
|
210 |
|
|
211 |
static void ioport_writew_thunk(void *opaque, uint32_t addr, uint32_t data) |
|
212 |
{ |
|
213 |
IORange *ioport = opaque; |
|
214 |
|
|
215 |
ioport->ops->write(ioport, addr - ioport->base, 2, data); |
|
216 |
} |
|
217 |
|
|
218 |
static void ioport_writel_thunk(void *opaque, uint32_t addr, uint32_t data) |
|
219 |
{ |
|
220 |
IORange *ioport = opaque; |
|
221 |
|
|
222 |
ioport->ops->write(ioport, addr - ioport->base, 4, data); |
|
223 |
} |
|
224 |
|
|
225 |
void ioport_register(IORange *ioport) |
|
226 |
{ |
|
227 |
register_ioport_read(ioport->base, ioport->len, 1, |
|
228 |
ioport_readb_thunk, ioport); |
|
229 |
register_ioport_read(ioport->base, ioport->len, 2, |
|
230 |
ioport_readw_thunk, ioport); |
|
231 |
register_ioport_read(ioport->base, ioport->len, 4, |
|
232 |
ioport_readl_thunk, ioport); |
|
233 |
register_ioport_write(ioport->base, ioport->len, 1, |
|
234 |
ioport_writeb_thunk, ioport); |
|
235 |
register_ioport_write(ioport->base, ioport->len, 2, |
|
236 |
ioport_writew_thunk, ioport); |
|
237 |
register_ioport_write(ioport->base, ioport->len, 4, |
|
238 |
ioport_writel_thunk, ioport); |
|
239 |
} |
|
240 |
|
|
177 | 241 |
void isa_unassign_ioport(pio_addr_t start, int length) |
178 | 242 |
{ |
179 | 243 |
int i; |
b/ioport.h | ||
---|---|---|
25 | 25 |
#define IOPORT_H |
26 | 26 |
|
27 | 27 |
#include "qemu-common.h" |
28 |
#include "iorange.h" |
|
28 | 29 |
|
29 | 30 |
typedef uint32_t pio_addr_t; |
30 | 31 |
#define FMT_pioaddr PRIx32 |
... | ... | |
36 | 37 |
typedef void (IOPortWriteFunc)(void *opaque, uint32_t address, uint32_t data); |
37 | 38 |
typedef uint32_t (IOPortReadFunc)(void *opaque, uint32_t address); |
38 | 39 |
|
40 |
void ioport_register(IORange *iorange); |
|
39 | 41 |
int register_ioport_read(pio_addr_t start, int length, int size, |
40 | 42 |
IOPortReadFunc *func, void *opaque); |
41 | 43 |
int register_ioport_write(pio_addr_t start, int length, int size, |
b/iorange.h | ||
---|---|---|
1 |
#ifndef IORANGE_H |
|
2 |
#define IORANGE_H |
|
3 |
|
|
4 |
#include <stdint.h> |
|
5 |
|
|
6 |
typedef struct IORange IORange; |
|
7 |
typedef struct IORangeOps IORangeOps; |
|
8 |
|
|
9 |
struct IORangeOps { |
|
10 |
void (*read)(IORange *iorange, uint64_t offset, unsigned width, |
|
11 |
uint64_t *data); |
|
12 |
void (*write)(IORange *iorange, uint64_t offset, unsigned width, |
|
13 |
uint64_t data); |
|
14 |
}; |
|
15 |
|
|
16 |
struct IORange { |
|
17 |
const IORangeOps *ops; |
|
18 |
uint64_t base; |
|
19 |
uint64_t len; |
|
20 |
}; |
|
21 |
|
|
22 |
static inline void iorange_init(IORange *iorange, const IORangeOps *ops, |
|
23 |
uint64_t base, uint64_t len) |
|
24 |
{ |
|
25 |
iorange->ops = ops; |
|
26 |
iorange->base = base; |
|
27 |
iorange->len = len; |
|
28 |
} |
|
29 |
|
|
30 |
#endif |
Also available in: Unified diff