1
2
3
4
5
6
7
8
9
10
11#ifndef _ASM_IO_H
12#define _ASM_IO_H
13
14#include <asm/page.h>
15#include <asm/cpu-regs.h>
16#include <asm/cacheflush.h>
17#include <asm-generic/pci_iomap.h>
18
19#define mmiowb() do {} while (0)
20
21
22
23
24
25
26
27
28static inline u8 readb(const volatile void __iomem *addr)
29{
30 return *(const volatile u8 *) addr;
31}
32
33static inline u16 readw(const volatile void __iomem *addr)
34{
35 return *(const volatile u16 *) addr;
36}
37
38static inline u32 readl(const volatile void __iomem *addr)
39{
40 return *(const volatile u32 *) addr;
41}
42
43#define __raw_readb readb
44#define __raw_readw readw
45#define __raw_readl readl
46
47#define readb_relaxed readb
48#define readw_relaxed readw
49#define readl_relaxed readl
50
51static inline void writeb(u8 b, volatile void __iomem *addr)
52{
53 *(volatile u8 *) addr = b;
54}
55
56static inline void writew(u16 b, volatile void __iomem *addr)
57{
58 *(volatile u16 *) addr = b;
59}
60
61static inline void writel(u32 b, volatile void __iomem *addr)
62{
63 *(volatile u32 *) addr = b;
64}
65
66#define __raw_writeb writeb
67#define __raw_writew writew
68#define __raw_writel writel
69
70
71
72
73
74static inline u8 inb_local(unsigned long addr)
75{
76 return readb((volatile void __iomem *) addr);
77}
78
79static inline void outb_local(u8 b, unsigned long addr)
80{
81 return writeb(b, (volatile void __iomem *) addr);
82}
83
84static inline u8 inb(unsigned long addr)
85{
86 return readb((volatile void __iomem *) addr);
87}
88
89static inline u16 inw(unsigned long addr)
90{
91 return readw((volatile void __iomem *) addr);
92}
93
94static inline u32 inl(unsigned long addr)
95{
96 return readl((volatile void __iomem *) addr);
97}
98
99static inline void outb(u8 b, unsigned long addr)
100{
101 return writeb(b, (volatile void __iomem *) addr);
102}
103
104static inline void outw(u16 b, unsigned long addr)
105{
106 return writew(b, (volatile void __iomem *) addr);
107}
108
109static inline void outl(u32 b, unsigned long addr)
110{
111 return writel(b, (volatile void __iomem *) addr);
112}
113
114#define inb_p(addr) inb(addr)
115#define inw_p(addr) inw(addr)
116#define inl_p(addr) inl(addr)
117#define outb_p(x, addr) outb((x), (addr))
118#define outw_p(x, addr) outw((x), (addr))
119#define outl_p(x, addr) outl((x), (addr))
120
121static inline void insb(unsigned long addr, void *buffer, int count)
122{
123 if (count) {
124 u8 *buf = buffer;
125 do {
126 u8 x = inb(addr);
127 *buf++ = x;
128 } while (--count);
129 }
130}
131
132static inline void insw(unsigned long addr, void *buffer, int count)
133{
134 if (count) {
135 u16 *buf = buffer;
136 do {
137 u16 x = inw(addr);
138 *buf++ = x;
139 } while (--count);
140 }
141}
142
143static inline void insl(unsigned long addr, void *buffer, int count)
144{
145 if (count) {
146 u32 *buf = buffer;
147 do {
148 u32 x = inl(addr);
149 *buf++ = x;
150 } while (--count);
151 }
152}
153
154static inline void outsb(unsigned long addr, const void *buffer, int count)
155{
156 if (count) {
157 const u8 *buf = buffer;
158 do {
159 outb(*buf++, addr);
160 } while (--count);
161 }
162}
163
164static inline void outsw(unsigned long addr, const void *buffer, int count)
165{
166 if (count) {
167 const u16 *buf = buffer;
168 do {
169 outw(*buf++, addr);
170 } while (--count);
171 }
172}
173
174extern void __outsl(unsigned long addr, const void *buffer, int count);
175static inline void outsl(unsigned long addr, const void *buffer, int count)
176{
177 if ((unsigned long) buffer & 0x3)
178 return __outsl(addr, buffer, count);
179
180 if (count) {
181 const u32 *buf = buffer;
182 do {
183 outl(*buf++, addr);
184 } while (--count);
185 }
186}
187
188#define ioread8(addr) readb(addr)
189#define ioread16(addr) readw(addr)
190#define ioread32(addr) readl(addr)
191
192#define iowrite8(v, addr) writeb((v), (addr))
193#define iowrite16(v, addr) writew((v), (addr))
194#define iowrite32(v, addr) writel((v), (addr))
195
196#define ioread8_rep(p, dst, count) \
197 insb((unsigned long) (p), (dst), (count))
198#define ioread16_rep(p, dst, count) \
199 insw((unsigned long) (p), (dst), (count))
200#define ioread32_rep(p, dst, count) \
201 insl((unsigned long) (p), (dst), (count))
202
203#define iowrite8_rep(p, src, count) \
204 outsb((unsigned long) (p), (src), (count))
205#define iowrite16_rep(p, src, count) \
206 outsw((unsigned long) (p), (src), (count))
207#define iowrite32_rep(p, src, count) \
208 outsl((unsigned long) (p), (src), (count))
209
210#define readsb(p, dst, count) \
211 insb((unsigned long) (p), (dst), (count))
212#define readsw(p, dst, count) \
213 insw((unsigned long) (p), (dst), (count))
214#define readsl(p, dst, count) \
215 insl((unsigned long) (p), (dst), (count))
216
217#define writesb(p, src, count) \
218 outsb((unsigned long) (p), (src), (count))
219#define writesw(p, src, count) \
220 outsw((unsigned long) (p), (src), (count))
221#define writesl(p, src, count) \
222 outsl((unsigned long) (p), (src), (count))
223
224#define IO_SPACE_LIMIT 0xffffffff
225
226#ifdef __KERNEL__
227
228#include <linux/vmalloc.h>
229#define __io_virt(x) ((void *) (x))
230
231
232struct pci_dev;
233static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
234{
235}
236
237
238
239
240
241static inline unsigned long virt_to_phys(volatile void *address)
242{
243 return __pa(address);
244}
245
246static inline void *phys_to_virt(unsigned long address)
247{
248 return __va(address);
249}
250
251
252
253
254static inline void __iomem *__ioremap(unsigned long offset, unsigned long size,
255 unsigned long flags)
256{
257 return (void __iomem *) offset;
258}
259
260static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
261{
262 return (void __iomem *)(offset & ~0x20000000);
263}
264
265
266
267
268
269
270static inline void __iomem *ioremap_nocache(unsigned long offset, unsigned long size)
271{
272 return (void __iomem *) (offset | 0x20000000);
273}
274
275#define ioremap_wc ioremap_nocache
276
277static inline void iounmap(void __iomem *addr)
278{
279}
280
281static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
282{
283 return (void __iomem *) port;
284}
285
286static inline void ioport_unmap(void __iomem *p)
287{
288}
289
290#define xlate_dev_kmem_ptr(p) ((void *) (p))
291#define xlate_dev_mem_ptr(p) ((void *) (p))
292
293
294
295
296static inline unsigned long virt_to_bus(volatile void *address)
297{
298 return ((unsigned long) address) & ~0x20000000;
299}
300
301static inline void *bus_to_virt(unsigned long address)
302{
303 return (void *) address;
304}
305
306#define page_to_bus page_to_phys
307
308#define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
309#define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
310#define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
311
312#endif
313
314#endif
315