1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef _IOHELPER_H
27#define _IOHELPER_H
28
29typedef u8 (read_reg_func)(void *hwp, u8 offset);
30 typedef void (write_reg_func)(void *hwp, u8 offset, u8 value);
31 typedef void (fifo_func)(void *hwp, u8 offset, u8 *datap, int size);
32
33 struct _ioport {
34 u32 port;
35 u32 ale;
36 };
37
38#define IOFUNC_IO(name, hws, ap) \
39 static u8 Read##name##_IO(void *p, u8 off) { \
40 struct hws *hw = p; \
41 return inb(hw->ap.port + off); \
42 } \
43 static void Write##name##_IO(void *p, u8 off, u8 val) { \
44 struct hws *hw = p; \
45 outb(val, hw->ap.port + off); \
46 } \
47 static void ReadFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
48 struct hws *hw = p; \
49 insb(hw->ap.port + off, dp, size); \
50 } \
51 static void WriteFiFo##name##_IO(void *p, u8 off, u8 *dp, int size) { \
52 struct hws *hw = p; \
53 outsb(hw->ap.port + off, dp, size); \
54 }
55
56#define IOFUNC_IND(name, hws, ap) \
57 static u8 Read##name##_IND(void *p, u8 off) { \
58 struct hws *hw = p; \
59 outb(off, hw->ap.ale); \
60 return inb(hw->ap.port); \
61 } \
62 static void Write##name##_IND(void *p, u8 off, u8 val) { \
63 struct hws *hw = p; \
64 outb(off, hw->ap.ale); \
65 outb(val, hw->ap.port); \
66 } \
67 static void ReadFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
68 struct hws *hw = p; \
69 outb(off, hw->ap.ale); \
70 insb(hw->ap.port, dp, size); \
71 } \
72 static void WriteFiFo##name##_IND(void *p, u8 off, u8 *dp, int size) { \
73 struct hws *hw = p; \
74 outb(off, hw->ap.ale); \
75 outsb(hw->ap.port, dp, size); \
76 }
77
78#define IOFUNC_MEMIO(name, hws, typ, adr) \
79 static u8 Read##name##_MIO(void *p, u8 off) { \
80 struct hws *hw = p; \
81 return readb(((typ *)hw->adr) + off); \
82 } \
83 static void Write##name##_MIO(void *p, u8 off, u8 val) { \
84 struct hws *hw = p; \
85 writeb(val, ((typ *)hw->adr) + off); \
86 } \
87 static void ReadFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
88 struct hws *hw = p; \
89 while (size--) \
90 *dp++ = readb(((typ *)hw->adr) + off); \
91 } \
92 static void WriteFiFo##name##_MIO(void *p, u8 off, u8 *dp, int size) { \
93 struct hws *hw = p; \
94 while (size--) \
95 writeb(*dp++, ((typ *)hw->adr) + off); \
96 }
97
98#define ASSIGN_FUNC(typ, name, dest) do { \
99 dest.read_reg = &Read##name##_##typ; \
100 dest.write_reg = &Write##name##_##typ; \
101 dest.read_fifo = &ReadFiFo##name##_##typ; \
102 dest.write_fifo = &WriteFiFo##name##_##typ; \
103 } while (0)
104#define ASSIGN_FUNC_IPAC(typ, target) do { \
105 ASSIGN_FUNC(typ, ISAC, target.isac); \
106 ASSIGN_FUNC(typ, IPAC, target); \
107 } while (0)
108
109#endif
110