1 /* io.h: FRV I/O operations
2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * This gets interesting when talking to the PCI bus - the CPU is in big endian
12 * mode, the PCI bus is little endian and the hardware in the middle can do
13 * byte swapping
14 */
15 #ifndef _ASM_IO_H
16 #define _ASM_IO_H
17
18 #ifdef __KERNEL__
19
20 #define ARCH_HAS_IOREMAP_WT
21
22 #include <linux/types.h>
23 #include <asm/virtconvert.h>
24 #include <asm/string.h>
25 #include <asm/mb-regs.h>
26 #include <asm-generic/pci_iomap.h>
27 #include <linux/delay.h>
28
29 /*
30 * swap functions are sometimes needed to interface little-endian hardware
31 */
32
_swapw(unsigned short v)33 static inline unsigned short _swapw(unsigned short v)
34 {
35 return ((v << 8) | (v >> 8));
36 }
37
_swapl(unsigned long v)38 static inline unsigned long _swapl(unsigned long v)
39 {
40 return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
41 }
42
43 //#define __iormb() asm volatile("membar")
44 //#define __iowmb() asm volatile("membar")
45
__raw_readb(const volatile void __iomem * addr)46 static inline u8 __raw_readb(const volatile void __iomem *addr)
47 {
48 return __builtin_read8((volatile void __iomem *)addr);
49 }
50
__raw_readw(const volatile void __iomem * addr)51 static inline u16 __raw_readw(const volatile void __iomem *addr)
52 {
53 return __builtin_read16((volatile void __iomem *)addr);
54 }
55
__raw_readl(const volatile void __iomem * addr)56 static inline u32 __raw_readl(const volatile void __iomem *addr)
57 {
58 return __builtin_read32((volatile void __iomem *)addr);
59 }
60
61 #define __raw_writeb(datum, addr) __builtin_write8(addr, datum)
62 #define __raw_writew(datum, addr) __builtin_write16(addr, datum)
63 #define __raw_writel(datum, addr) __builtin_write32(addr, datum)
64
io_outsb(unsigned int addr,const void * buf,int len)65 static inline void io_outsb(unsigned int addr, const void *buf, int len)
66 {
67 unsigned long __ioaddr = (unsigned long) addr;
68 const uint8_t *bp = buf;
69
70 while (len--)
71 __builtin_write8((volatile void __iomem *) __ioaddr, *bp++);
72 }
73
io_outsw(unsigned int addr,const void * buf,int len)74 static inline void io_outsw(unsigned int addr, const void *buf, int len)
75 {
76 unsigned long __ioaddr = (unsigned long) addr;
77 const uint16_t *bp = buf;
78
79 while (len--)
80 __builtin_write16((volatile void __iomem *) __ioaddr, (*bp++));
81 }
82
83 extern void __outsl_ns(unsigned int addr, const void *buf, int len);
84 extern void __outsl_sw(unsigned int addr, const void *buf, int len);
__outsl(unsigned int addr,const void * buf,int len,int swap)85 static inline void __outsl(unsigned int addr, const void *buf, int len, int swap)
86 {
87 unsigned long __ioaddr = (unsigned long) addr;
88
89 if (!swap)
90 __outsl_ns(__ioaddr, buf, len);
91 else
92 __outsl_sw(__ioaddr, buf, len);
93 }
94
io_insb(unsigned long addr,void * buf,int len)95 static inline void io_insb(unsigned long addr, void *buf, int len)
96 {
97 uint8_t *bp = buf;
98
99 while (len--)
100 *bp++ = __builtin_read8((volatile void __iomem *) addr);
101 }
102
io_insw(unsigned long addr,void * buf,int len)103 static inline void io_insw(unsigned long addr, void *buf, int len)
104 {
105 uint16_t *bp = buf;
106
107 while (len--)
108 *bp++ = __builtin_read16((volatile void __iomem *) addr);
109 }
110
111 extern void __insl_ns(unsigned long addr, void *buf, int len);
112 extern void __insl_sw(unsigned long addr, void *buf, int len);
__insl(unsigned long addr,void * buf,int len,int swap)113 static inline void __insl(unsigned long addr, void *buf, int len, int swap)
114 {
115 if (!swap)
116 __insl_ns(addr, buf, len);
117 else
118 __insl_sw(addr, buf, len);
119 }
120
121 #define mmiowb() mb()
122
123 /*
124 * make the short names macros so specific devices
125 * can override them as required
126 */
127
memset_io(volatile void __iomem * addr,unsigned char val,int count)128 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
129 {
130 memset((void __force *) addr, val, count);
131 }
132
memcpy_fromio(void * dst,const volatile void __iomem * src,int count)133 static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
134 {
135 memcpy(dst, (void __force *) src, count);
136 }
137
memcpy_toio(volatile void __iomem * dst,const void * src,int count)138 static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
139 {
140 memcpy((void __force *) dst, src, count);
141 }
142
inb(unsigned long addr)143 static inline uint8_t inb(unsigned long addr)
144 {
145 return __builtin_read8((void __iomem *)addr);
146 }
147
inw(unsigned long addr)148 static inline uint16_t inw(unsigned long addr)
149 {
150 uint16_t ret = __builtin_read16((void __iomem *)addr);
151
152 if (__is_PCI_IO(addr))
153 ret = _swapw(ret);
154
155 return ret;
156 }
157
inl(unsigned long addr)158 static inline uint32_t inl(unsigned long addr)
159 {
160 uint32_t ret = __builtin_read32((void __iomem *)addr);
161
162 if (__is_PCI_IO(addr))
163 ret = _swapl(ret);
164
165 return ret;
166 }
167
outb(uint8_t datum,unsigned long addr)168 static inline void outb(uint8_t datum, unsigned long addr)
169 {
170 __builtin_write8((void __iomem *)addr, datum);
171 }
172
outw(uint16_t datum,unsigned long addr)173 static inline void outw(uint16_t datum, unsigned long addr)
174 {
175 if (__is_PCI_IO(addr))
176 datum = _swapw(datum);
177 __builtin_write16((void __iomem *)addr, datum);
178 }
179
outl(uint32_t datum,unsigned long addr)180 static inline void outl(uint32_t datum, unsigned long addr)
181 {
182 if (__is_PCI_IO(addr))
183 datum = _swapl(datum);
184 __builtin_write32((void __iomem *)addr, datum);
185 }
186
187 #define inb_p(addr) inb(addr)
188 #define inw_p(addr) inw(addr)
189 #define inl_p(addr) inl(addr)
190 #define outb_p(x,addr) outb(x,addr)
191 #define outw_p(x,addr) outw(x,addr)
192 #define outl_p(x,addr) outl(x,addr)
193
194 #define outsb(a,b,l) io_outsb(a,b,l)
195 #define outsw(a,b,l) io_outsw(a,b,l)
196 #define outsl(a,b,l) __outsl(a,b,l,0)
197
198 #define insb(a,b,l) io_insb(a,b,l)
199 #define insw(a,b,l) io_insw(a,b,l)
200 #define insl(a,b,l) __insl(a,b,l,0)
201
202 #define IO_SPACE_LIMIT 0xffffffff
203
readb(const volatile void __iomem * addr)204 static inline uint8_t readb(const volatile void __iomem *addr)
205 {
206 return __builtin_read8((__force void volatile __iomem *) addr);
207 }
208
readw(const volatile void __iomem * addr)209 static inline uint16_t readw(const volatile void __iomem *addr)
210 {
211 uint16_t ret = __builtin_read16((__force void volatile __iomem *)addr);
212
213 if (__is_PCI_MEM(addr))
214 ret = _swapw(ret);
215 return ret;
216 }
217
readl(const volatile void __iomem * addr)218 static inline uint32_t readl(const volatile void __iomem *addr)
219 {
220 uint32_t ret = __builtin_read32((__force void volatile __iomem *)addr);
221
222 if (__is_PCI_MEM(addr))
223 ret = _swapl(ret);
224
225 return ret;
226 }
227
228 #define readb_relaxed readb
229 #define readw_relaxed readw
230 #define readl_relaxed readl
231
writeb(uint8_t datum,volatile void __iomem * addr)232 static inline void writeb(uint8_t datum, volatile void __iomem *addr)
233 {
234 __builtin_write8(addr, datum);
235 if (__is_PCI_MEM(addr))
236 __flush_PCI_writes();
237 }
238
writew(uint16_t datum,volatile void __iomem * addr)239 static inline void writew(uint16_t datum, volatile void __iomem *addr)
240 {
241 if (__is_PCI_MEM(addr))
242 datum = _swapw(datum);
243
244 __builtin_write16(addr, datum);
245 if (__is_PCI_MEM(addr))
246 __flush_PCI_writes();
247 }
248
writel(uint32_t datum,volatile void __iomem * addr)249 static inline void writel(uint32_t datum, volatile void __iomem *addr)
250 {
251 if (__is_PCI_MEM(addr))
252 datum = _swapl(datum);
253
254 __builtin_write32(addr, datum);
255 if (__is_PCI_MEM(addr))
256 __flush_PCI_writes();
257 }
258
259 #define writeb_relaxed writeb
260 #define writew_relaxed writew
261 #define writel_relaxed writel
262
263 /* Values for nocacheflag and cmode */
264 #define IOMAP_FULL_CACHING 0
265 #define IOMAP_NOCACHE_SER 1
266 #define IOMAP_NOCACHE_NONSER 2
267 #define IOMAP_WRITETHROUGH 3
268
269 extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
270
ioremap(unsigned long physaddr,unsigned long size)271 static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
272 {
273 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
274 }
275
ioremap_nocache(unsigned long physaddr,unsigned long size)276 static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
277 {
278 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
279 }
280
ioremap_wt(unsigned long physaddr,unsigned long size)281 static inline void __iomem *ioremap_wt(unsigned long physaddr, unsigned long size)
282 {
283 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
284 }
285
ioremap_fullcache(unsigned long physaddr,unsigned long size)286 static inline void __iomem *ioremap_fullcache(unsigned long physaddr, unsigned long size)
287 {
288 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
289 }
290
291 #define ioremap_wc ioremap_nocache
292 #define ioremap_uc ioremap_nocache
293
294 extern void iounmap(void volatile __iomem *addr);
295
ioport_map(unsigned long port,unsigned int nr)296 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
297 {
298 return (void __iomem *) port;
299 }
300
ioport_unmap(void __iomem * p)301 static inline void ioport_unmap(void __iomem *p)
302 {
303 }
304
flush_write_buffers(void)305 static inline void flush_write_buffers(void)
306 {
307 __asm__ __volatile__ ("membar" : : :"memory");
308 }
309
310 /*
311 * do appropriate I/O accesses for token type
312 */
ioread8(void __iomem * p)313 static inline unsigned int ioread8(void __iomem *p)
314 {
315 return __builtin_read8(p);
316 }
317
ioread16(void __iomem * p)318 static inline unsigned int ioread16(void __iomem *p)
319 {
320 uint16_t ret = __builtin_read16(p);
321 if (__is_PCI_addr(p))
322 ret = _swapw(ret);
323 return ret;
324 }
325
ioread32(void __iomem * p)326 static inline unsigned int ioread32(void __iomem *p)
327 {
328 uint32_t ret = __builtin_read32(p);
329 if (__is_PCI_addr(p))
330 ret = _swapl(ret);
331 return ret;
332 }
333
iowrite8(u8 val,void __iomem * p)334 static inline void iowrite8(u8 val, void __iomem *p)
335 {
336 __builtin_write8(p, val);
337 if (__is_PCI_MEM(p))
338 __flush_PCI_writes();
339 }
340
iowrite16(u16 val,void __iomem * p)341 static inline void iowrite16(u16 val, void __iomem *p)
342 {
343 if (__is_PCI_addr(p))
344 val = _swapw(val);
345 __builtin_write16(p, val);
346 if (__is_PCI_MEM(p))
347 __flush_PCI_writes();
348 }
349
iowrite32(u32 val,void __iomem * p)350 static inline void iowrite32(u32 val, void __iomem *p)
351 {
352 if (__is_PCI_addr(p))
353 val = _swapl(val);
354 __builtin_write32(p, val);
355 if (__is_PCI_MEM(p))
356 __flush_PCI_writes();
357 }
358
359 #define ioread16be(addr) be16_to_cpu(ioread16(addr))
360 #define ioread32be(addr) be32_to_cpu(ioread32(addr))
361 #define iowrite16be(v, addr) iowrite16(cpu_to_be16(v), (addr))
362 #define iowrite32be(v, addr) iowrite32(cpu_to_be32(v), (addr))
363
ioread8_rep(void __iomem * p,void * dst,unsigned long count)364 static inline void ioread8_rep(void __iomem *p, void *dst, unsigned long count)
365 {
366 io_insb((unsigned long) p, dst, count);
367 }
368
ioread16_rep(void __iomem * p,void * dst,unsigned long count)369 static inline void ioread16_rep(void __iomem *p, void *dst, unsigned long count)
370 {
371 io_insw((unsigned long) p, dst, count);
372 }
373
ioread32_rep(void __iomem * p,void * dst,unsigned long count)374 static inline void ioread32_rep(void __iomem *p, void *dst, unsigned long count)
375 {
376 __insl_ns((unsigned long) p, dst, count);
377 }
378
iowrite8_rep(void __iomem * p,const void * src,unsigned long count)379 static inline void iowrite8_rep(void __iomem *p, const void *src, unsigned long count)
380 {
381 io_outsb((unsigned long) p, src, count);
382 }
383
iowrite16_rep(void __iomem * p,const void * src,unsigned long count)384 static inline void iowrite16_rep(void __iomem *p, const void *src, unsigned long count)
385 {
386 io_outsw((unsigned long) p, src, count);
387 }
388
iowrite32_rep(void __iomem * p,const void * src,unsigned long count)389 static inline void iowrite32_rep(void __iomem *p, const void *src, unsigned long count)
390 {
391 __outsl_ns((unsigned long) p, src, count);
392 }
393
394 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
395 struct pci_dev;
pci_iounmap(struct pci_dev * dev,void __iomem * p)396 static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
397 {
398 }
399
400
401 /*
402 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
403 * access
404 */
405 #define xlate_dev_mem_ptr(p) __va(p)
406
407 /*
408 * Convert a virtual cached pointer to an uncached pointer
409 */
410 #define xlate_dev_kmem_ptr(p) p
411
412 #endif /* __KERNEL__ */
413
414 #endif /* _ASM_IO_H */
415