root / rwhandler.c @ 049f7adb
History | View | Annotate | Download (2.6 kB)
1 |
#include "rwhandler.h" |
---|---|
2 |
#include "ioport.h" |
3 |
#include "cpu-all.h" |
4 |
|
5 |
#if !defined(CONFIG_USER_ONLY)
|
6 |
|
7 |
#define RWHANDLER_WRITE(name, len, type) \
|
8 |
static void name(void *opaque, type addr, uint32_t value) \ |
9 |
{\ |
10 |
struct ReadWriteHandler *handler = opaque;\
|
11 |
handler->write(handler, addr, value, len);\ |
12 |
} |
13 |
|
14 |
#define RWHANDLER_READ(name, len, type) \
|
15 |
static uint32_t name(void *opaque, type addr) \ |
16 |
{ \ |
17 |
struct ReadWriteHandler *handler = opaque; \
|
18 |
return handler->read(handler, addr, len); \
|
19 |
} |
20 |
|
21 |
RWHANDLER_WRITE(cpu_io_memory_simple_writeb, 1, target_phys_addr_t);
|
22 |
RWHANDLER_READ(cpu_io_memory_simple_readb, 1, target_phys_addr_t);
|
23 |
RWHANDLER_WRITE(cpu_io_memory_simple_writew, 2, target_phys_addr_t);
|
24 |
RWHANDLER_READ(cpu_io_memory_simple_readw, 2, target_phys_addr_t);
|
25 |
RWHANDLER_WRITE(cpu_io_memory_simple_writel, 4, target_phys_addr_t);
|
26 |
RWHANDLER_READ(cpu_io_memory_simple_readl, 4, target_phys_addr_t);
|
27 |
|
28 |
static CPUWriteMemoryFunc * const cpu_io_memory_simple_write[] = { |
29 |
&cpu_io_memory_simple_writeb, |
30 |
&cpu_io_memory_simple_writew, |
31 |
&cpu_io_memory_simple_writel, |
32 |
}; |
33 |
|
34 |
static CPUReadMemoryFunc * const cpu_io_memory_simple_read[] = { |
35 |
&cpu_io_memory_simple_readb, |
36 |
&cpu_io_memory_simple_readw, |
37 |
&cpu_io_memory_simple_readl, |
38 |
}; |
39 |
|
40 |
int cpu_register_io_memory_simple(struct ReadWriteHandler *handler) |
41 |
{ |
42 |
if (!handler->read || !handler->write) {
|
43 |
return -1; |
44 |
} |
45 |
return cpu_register_io_memory(cpu_io_memory_simple_read,
|
46 |
cpu_io_memory_simple_write, |
47 |
handler); |
48 |
} |
49 |
|
50 |
RWHANDLER_WRITE(ioport_simple_writeb, 1, uint32_t);
|
51 |
RWHANDLER_READ(ioport_simple_readb, 1, uint32_t);
|
52 |
RWHANDLER_WRITE(ioport_simple_writew, 2, uint32_t);
|
53 |
RWHANDLER_READ(ioport_simple_readw, 2, uint32_t);
|
54 |
RWHANDLER_WRITE(ioport_simple_writel, 4, uint32_t);
|
55 |
RWHANDLER_READ(ioport_simple_readl, 4, uint32_t);
|
56 |
|
57 |
int register_ioport_simple(ReadWriteHandler* handler,
|
58 |
pio_addr_t start, int length, int size) |
59 |
{ |
60 |
IOPortWriteFunc *write; |
61 |
IOPortReadFunc *read; |
62 |
int r;
|
63 |
switch (size) {
|
64 |
case 1: |
65 |
write = ioport_simple_writeb; |
66 |
read = ioport_simple_readb; |
67 |
break;
|
68 |
case 2: |
69 |
write = ioport_simple_writew; |
70 |
read = ioport_simple_readw; |
71 |
break;
|
72 |
default:
|
73 |
write = ioport_simple_writel; |
74 |
read = ioport_simple_readl; |
75 |
} |
76 |
if (handler->write) {
|
77 |
r = register_ioport_write(start, length, size, write, handler); |
78 |
if (r < 0) { |
79 |
return r;
|
80 |
} |
81 |
} |
82 |
if (handler->read) {
|
83 |
r = register_ioport_read(start, length, size, read, handler); |
84 |
if (r < 0) { |
85 |
return r;
|
86 |
} |
87 |
} |
88 |
return 0; |
89 |
} |
90 |
|
91 |
#endif
|