1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef __ASM_SH_IO_H
21#define __ASM_SH_IO_H
22
23#ifdef __KERNEL__
24
25#include <linux/types.h>
26#include <asm/byteorder.h>
27
28
29
30
31
32
33#define __arch_getb(a) (*(volatile unsigned char *)(a))
34#define __arch_getw(a) (*(volatile unsigned short *)(a))
35#define __arch_getl(a) (*(volatile unsigned int *)(a))
36
37#define __arch_putb(v, a) (*(volatile unsigned char *)(a) = (v))
38#define __arch_putw(v, a) (*(volatile unsigned short *)(a) = (v))
39#define __arch_putl(v, a) (*(volatile unsigned int *)(a) = (v))
40
41extern void __raw_writesb(unsigned int addr, const void *data, int bytelen);
42extern void __raw_writesw(unsigned int addr, const void *data, int wordlen);
43extern void __raw_writesl(unsigned int addr, const void *data, int longlen);
44
45extern void __raw_readsb(unsigned int addr, void *data, int bytelen);
46extern void __raw_readsw(unsigned int addr, void *data, int wordlen);
47extern void __raw_readsl(unsigned int addr, void *data, int longlen);
48
49#define __raw_writeb(v, a) __arch_putb(v, a)
50#define __raw_writew(v, a) __arch_putw(v, a)
51#define __raw_writel(v, a) __arch_putl(v, a)
52
53#define __raw_readb(a) __arch_getb(a)
54#define __raw_readw(a) __arch_getw(a)
55#define __raw_readl(a) __arch_getl(a)
56
57
58
59
60
61
62#define __raw_base_writeb(val, base, off) __arch_base_putb(val, base, off)
63#define __raw_base_writew(val, base, off) __arch_base_putw(val, base, off)
64#define __raw_base_writel(val, base, off) __arch_base_putl(val, base, off)
65
66#define __raw_base_readb(base, off) __arch_base_getb(base, off)
67#define __raw_base_readw(base, off) __arch_base_getw(base, off)
68#define __raw_base_readl(base, off) __arch_base_getl(base, off)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84#define outb(v, p) __raw_writeb(v, p)
85#define outw(v, p) __raw_writew(cpu_to_le16(v), p)
86#define outl(v, p) __raw_writel(cpu_to_le32(v), p)
87
88#define inb(p) ({ unsigned int __v = __raw_readb(p); __v; })
89#define inw(p) ({ unsigned int __v = __le16_to_cpu(__raw_readw(p)); __v; })
90#define inl(p) ({ unsigned int __v = __le32_to_cpu(__raw_readl(p)); __v; })
91
92#define outsb(p, d, l) __raw_writesb(p, d, l)
93#define outsw(p, d, l) __raw_writesw(p, d, l)
94#define outsl(p, d, l) __raw_writesl(p, d, l)
95
96#define insb(p, d, l) __raw_readsb(p, d, l)
97#define insw(p, d, l) __raw_readsw(p, d, l)
98#define insl(p, d, l) __raw_readsl(p, d, l)
99
100#define outb_p(val, port) outb((val), (port))
101#define outw_p(val, port) outw((val), (port))
102#define outl_p(val, port) outl((val), (port))
103#define inb_p(port) inb((port))
104#define inw_p(port) inw((port))
105#define inl_p(port) inl((port))
106
107#define outsb_p(port, from, len) outsb(port, from, len)
108#define outsw_p(port, from, len) outsw(port, from, len)
109#define outsl_p(port, from, len) outsl(port, from, len)
110#define insb_p(port, to, len) insb(port, to, len)
111#define insw_p(port, to, len) insw(port, to, len)
112#define insl_p(port, to, len) insl(port, to, len)
113
114
115#define out_8(port, val) outb(val, port)
116#define out_le16(port, val) outw(val, port)
117#define out_le32(port, val) outl(val, port)
118#define in_8(port) inb(port)
119#define in_le16(port) inw(port)
120#define in_le32(port) inl(port)
121
122
123
124
125
126
127
128extern void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle);
129extern void consistent_free(void *vaddr, size_t size, dma_addr_t handle);
130extern void consistent_sync(void *vaddr, size_t size, int rw);
131
132
133
134
135extern void _memcpy_fromio(void *, unsigned long, size_t);
136extern void _memcpy_toio(unsigned long, const void *, size_t);
137extern void _memset_io(unsigned long, int, size_t);
138
139
140
141
142
143
144#ifdef __mem_pci
145
146#define readb(c) ({ unsigned int __v = __raw_readb(__mem_pci(c)); __v; })
147#define readw(c)\
148 ({ unsigned int __v = le16_to_cpu(__raw_readw(__mem_pci(c))); __v; })
149#define readl(c)\
150 ({ unsigned int __v = le32_to_cpu(__raw_readl(__mem_pci(c))); __v; })
151
152#define writeb(v, c) __raw_writeb(v, __mem_pci(c))
153#define writew(v, c) __raw_writew(cpu_to_le16(v), __mem_pci(c))
154#define writel(v, c) __raw_writel(cpu_to_le32(v), __mem_pci(c))
155
156#define memset_io(c, v, l) _memset_io(__mem_pci(c), (v), (l))
157#define memcpy_fromio(a, c, l) _memcpy_fromio((a), __mem_pci(c), (l))
158#define memcpy_toio(c, a, l) _memcpy_toio(__mem_pci(c), (a), (l))
159
160#define eth_io_copy_and_sum(s, c, l, b) \
161 eth_copy_and_sum((s), __mem_pci(c), (l), (b))
162
163static inline int
164check_signature(unsigned long io_addr, const unsigned char *signature,
165 int length)
166{
167 int retval = 0;
168 do {
169 if (readb(io_addr) != *signature)
170 goto out;
171 io_addr++;
172 signature++;
173 length--;
174 } while (length);
175 retval = 1;
176out:
177 return retval;
178}
179
180#elif !defined(readb)
181
182#define readb(addr) __raw_readb(addr)
183#define readw(addr) __raw_readw(addr)
184#define readl(addr) __raw_readl(addr)
185#define writeb(v, addr) __raw_writeb(v, addr)
186#define writew(v, addr) __raw_writew(v, addr)
187#define writel(v, addr) __raw_writel(v, addr)
188
189#define check_signature(io, sig, len) (0)
190
191#endif
192
193static inline void sync(void)
194{
195}
196
197
198
199
200
201
202
203
204
205#define clrbits(type, addr, clear) \
206 out_##type((addr), in_##type(addr) & ~(clear))
207
208#define setbits(type, addr, set) \
209 out_##type((addr), in_##type(addr) | (set))
210
211#define clrsetbits(type, addr, clear, set) \
212 out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
213
214#define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
215#define setbits_be32(addr, set) setbits(be32, addr, set)
216#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
217
218#define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
219#define setbits_le32(addr, set) setbits(le32, addr, set)
220#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
221
222#define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
223#define setbits_be16(addr, set) setbits(be16, addr, set)
224#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
225
226#define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
227#define setbits_le16(addr, set) setbits(le16, addr, set)
228#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
229
230#define clrbits_8(addr, clear) clrbits(8, addr, clear)
231#define setbits_8(addr, set) setbits(8, addr, set)
232#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
233
234#include <asm-generic/io.h>
235
236#endif
237#endif
238