1#ifndef _ASM_IO_H
2#define _ASM_IO_H
3
4#include <linux/string.h>
5#include <linux/compiler.h>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#define IO_SPACE_LIMIT 0xffff
41
42#define XQUAD_PORTIO_BASE 0xfe400000
43#define XQUAD_PORTIO_QUAD 0x40000
44
45#ifdef __KERNEL__
46
47#include <asm-generic/iomap.h>
48
49#include <linux/vmalloc.h>
50
51
52
53
54#define xlate_dev_kmem_ptr(p) p
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69static inline unsigned long virt_to_phys(volatile void *address)
70{
71 return __pa(address);
72}
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87static inline void *phys_to_virt(unsigned long address)
88{
89 return __va(address);
90}
91
92
93
94
95#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
112extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
113
114
115
116
117static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
118{
119 return ioremap_nocache(offset, size);
120}
121
122extern void iounmap(volatile void __iomem *addr);
123
124
125
126
127
128
129extern void early_ioremap_init(void);
130extern void early_ioremap_clear(void);
131extern void early_ioremap_reset(void);
132extern void *early_ioremap(unsigned long offset, unsigned long size);
133extern void early_iounmap(void *addr, unsigned long size);
134extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
135
136
137
138
139#define isa_virt_to_bus virt_to_phys
140#define isa_page_to_bus page_to_phys
141#define isa_bus_to_virt phys_to_virt
142
143
144
145
146
147
148
149#define virt_to_bus virt_to_phys
150#define bus_to_virt phys_to_virt
151
152
153
154
155
156
157
158
159static inline unsigned char readb(const volatile void __iomem *addr)
160{
161 return *(volatile unsigned char __force *)addr;
162}
163
164static inline unsigned short readw(const volatile void __iomem *addr)
165{
166 return *(volatile unsigned short __force *)addr;
167}
168
169static inline unsigned int readl(const volatile void __iomem *addr)
170{
171 return *(volatile unsigned int __force *) addr;
172}
173
174#define readb_relaxed(addr) readb(addr)
175#define readw_relaxed(addr) readw(addr)
176#define readl_relaxed(addr) readl(addr)
177#define __raw_readb readb
178#define __raw_readw readw
179#define __raw_readl readl
180
181static inline void writeb(unsigned char b, volatile void __iomem *addr)
182{
183 *(volatile unsigned char __force *)addr = b;
184}
185
186static inline void writew(unsigned short b, volatile void __iomem *addr)
187{
188 *(volatile unsigned short __force *)addr = b;
189}
190
191static inline void writel(unsigned int b, volatile void __iomem *addr)
192{
193 *(volatile unsigned int __force *)addr = b;
194}
195#define __raw_writeb writeb
196#define __raw_writew writew
197#define __raw_writel writel
198
199#define mmiowb()
200
201static inline void
202memset_io(volatile void __iomem *addr, unsigned char val, int count)
203{
204 memset((void __force *)addr, val, count);
205}
206
207static inline void
208memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
209{
210 __memcpy(dst, (const void __force *)src, count);
211}
212
213static inline void
214memcpy_toio(volatile void __iomem *dst, const void *src, int count)
215{
216 __memcpy((void __force *)dst, src, count);
217}
218
219
220
221
222
223
224
225
226
227#define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
228
229
230
231
232
233
234
235
236
237#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
238
239static inline void flush_write_buffers(void)
240{
241 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
242}
243
244#else
245
246#define flush_write_buffers() do { } while (0)
247
248#endif
249
250#endif
251
252extern void native_io_delay(void);
253
254extern int io_delay_type;
255extern void io_delay_init(void);
256
257#if defined(CONFIG_PARAVIRT)
258#include <asm/paravirt.h>
259#else
260
261static inline void slow_down_io(void)
262{
263 native_io_delay();
264#ifdef REALLY_SLOW_IO
265 native_io_delay();
266 native_io_delay();
267 native_io_delay();
268#endif
269}
270
271#endif
272
273#define __BUILDIO(bwl, bw, type) \
274static inline void out##bwl(unsigned type value, int port) \
275{ \
276 out##bwl##_local(value, port); \
277} \
278 \
279static inline unsigned type in##bwl(int port) \
280{ \
281 return in##bwl##_local(port); \
282}
283
284#define BUILDIO(bwl, bw, type) \
285static inline void out##bwl##_local(unsigned type value, int port) \
286{ \
287 asm volatile("out" #bwl " %" #bw "0, %w1" \
288 : : "a"(value), "Nd"(port)); \
289} \
290 \
291static inline unsigned type in##bwl##_local(int port) \
292{ \
293 unsigned type value; \
294 asm volatile("in" #bwl " %w1, %" #bw "0" \
295 : "=a"(value) : "Nd"(port)); \
296 return value; \
297} \
298 \
299static inline void out##bwl##_local_p(unsigned type value, int port) \
300{ \
301 out##bwl##_local(value, port); \
302 slow_down_io(); \
303} \
304 \
305static inline unsigned type in##bwl##_local_p(int port) \
306{ \
307 unsigned type value = in##bwl##_local(port); \
308 slow_down_io(); \
309 return value; \
310} \
311 \
312__BUILDIO(bwl, bw, type) \
313 \
314static inline void out##bwl##_p(unsigned type value, int port) \
315{ \
316 out##bwl(value, port); \
317 slow_down_io(); \
318} \
319 \
320static inline unsigned type in##bwl##_p(int port) \
321{ \
322 unsigned type value = in##bwl(port); \
323 slow_down_io(); \
324 return value; \
325} \
326 \
327static inline void outs##bwl(int port, const void *addr, unsigned long count) \
328{ \
329 asm volatile("rep; outs" #bwl \
330 : "+S"(addr), "+c"(count) : "d"(port)); \
331} \
332 \
333static inline void ins##bwl(int port, void *addr, unsigned long count) \
334{ \
335 asm volatile("rep; ins" #bwl \
336 : "+D"(addr), "+c"(count) : "d"(port)); \
337}
338
339BUILDIO(b, b, char)
340BUILDIO(w, w, short)
341BUILDIO(l, , int)
342
343#endif
344