io.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. #ifdef __KERNEL__
  18. #include <linux/config.h>
  19. #include <asm/virtconvert.h>
  20. #include <asm/string.h>
  21. #include <asm/mb-regs.h>
  22. #include <linux/delay.h>
  23. /*
  24. * swap functions are sometimes needed to interface little-endian hardware
  25. */
  26. static inline unsigned short _swapw(unsigned short v)
  27. {
  28. return ((v << 8) | (v >> 8));
  29. }
  30. static inline unsigned long _swapl(unsigned long v)
  31. {
  32. return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
  33. }
  34. //#define __iormb() asm volatile("membar")
  35. //#define __iowmb() asm volatile("membar")
  36. #define __raw_readb(addr) __builtin_read8((void *) (addr))
  37. #define __raw_readw(addr) __builtin_read16((void *) (addr))
  38. #define __raw_readl(addr) __builtin_read32((void *) (addr))
  39. #define __raw_writeb(datum, addr) __builtin_write8((void *) (addr), datum)
  40. #define __raw_writew(datum, addr) __builtin_write16((void *) (addr), datum)
  41. #define __raw_writel(datum, addr) __builtin_write32((void *) (addr), datum)
  42. static inline void io_outsb(unsigned int addr, const void *buf, int len)
  43. {
  44. unsigned long __ioaddr = (unsigned long) addr;
  45. const uint8_t *bp = buf;
  46. while (len--)
  47. __builtin_write8((volatile void __iomem *) __ioaddr, *bp++);
  48. }
  49. static inline void io_outsw(unsigned int addr, const void *buf, int len)
  50. {
  51. unsigned long __ioaddr = (unsigned long) addr;
  52. const uint16_t *bp = buf;
  53. while (len--)
  54. __builtin_write16((volatile void __iomem *) __ioaddr, (*bp++));
  55. }
  56. extern void __outsl_ns(unsigned int addr, const void *buf, int len);
  57. extern void __outsl_sw(unsigned int addr, const void *buf, int len);
  58. static inline void __outsl(unsigned int addr, const void *buf, int len, int swap)
  59. {
  60. unsigned long __ioaddr = (unsigned long) addr;
  61. if (!swap)
  62. __outsl_ns(__ioaddr, buf, len);
  63. else
  64. __outsl_sw(__ioaddr, buf, len);
  65. }
  66. static inline void io_insb(unsigned long addr, void *buf, int len)
  67. {
  68. uint8_t *bp = buf;
  69. while (len--)
  70. *bp++ = __builtin_read8((volatile void __iomem *) addr);
  71. }
  72. static inline void io_insw(unsigned long addr, void *buf, int len)
  73. {
  74. uint16_t *bp = buf;
  75. while (len--)
  76. *bp++ = __builtin_read16((volatile void __iomem *) addr);
  77. }
  78. extern void __insl_ns(unsigned long addr, void *buf, int len);
  79. extern void __insl_sw(unsigned long addr, void *buf, int len);
  80. static inline void __insl(unsigned long addr, void *buf, int len, int swap)
  81. {
  82. if (!swap)
  83. __insl_ns(addr, buf, len);
  84. else
  85. __insl_sw(addr, buf, len);
  86. }
  87. /*
  88. * make the short names macros so specific devices
  89. * can override them as required
  90. */
  91. static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
  92. {
  93. memset((void __force *) addr, val, count);
  94. }
  95. static inline void memcpy_fromio(void *dst, volatile void __iomem *src, int count)
  96. {
  97. memcpy(dst, (void __force *) src, count);
  98. }
  99. static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  100. {
  101. memcpy((void __force *) dst, src, count);
  102. }
  103. static inline uint8_t inb(unsigned long addr)
  104. {
  105. return __builtin_read8((void *)addr);
  106. }
  107. static inline uint16_t inw(unsigned long addr)
  108. {
  109. uint16_t ret = __builtin_read16((void *)addr);
  110. if (__is_PCI_IO(addr))
  111. ret = _swapw(ret);
  112. return ret;
  113. }
  114. static inline uint32_t inl(unsigned long addr)
  115. {
  116. uint32_t ret = __builtin_read32((void *)addr);
  117. if (__is_PCI_IO(addr))
  118. ret = _swapl(ret);
  119. return ret;
  120. }
  121. static inline void outb(uint8_t datum, unsigned long addr)
  122. {
  123. __builtin_write8((void *)addr, datum);
  124. }
  125. static inline void outw(uint16_t datum, unsigned long addr)
  126. {
  127. if (__is_PCI_IO(addr))
  128. datum = _swapw(datum);
  129. __builtin_write16((void *)addr, datum);
  130. }
  131. static inline void outl(uint32_t datum, unsigned long addr)
  132. {
  133. if (__is_PCI_IO(addr))
  134. datum = _swapl(datum);
  135. __builtin_write32((void *)addr, datum);
  136. }
  137. #define inb_p(addr) inb(addr)
  138. #define inw_p(addr) inw(addr)
  139. #define inl_p(addr) inl(addr)
  140. #define outb_p(x,addr) outb(x,addr)
  141. #define outw_p(x,addr) outw(x,addr)
  142. #define outl_p(x,addr) outl(x,addr)
  143. #define outsb(a,b,l) io_outsb(a,b,l)
  144. #define outsw(a,b,l) io_outsw(a,b,l)
  145. #define outsl(a,b,l) __outsl(a,b,l,0)
  146. #define insb(a,b,l) io_insb(a,b,l)
  147. #define insw(a,b,l) io_insw(a,b,l)
  148. #define insl(a,b,l) __insl(a,b,l,0)
  149. #define IO_SPACE_LIMIT 0xffffffff
  150. static inline uint8_t readb(const volatile void __iomem *addr)
  151. {
  152. return __builtin_read8((volatile uint8_t __force *) addr);
  153. }
  154. static inline uint16_t readw(const volatile void __iomem *addr)
  155. {
  156. uint16_t ret = __builtin_read16((volatile uint16_t __force *)addr);
  157. if (__is_PCI_MEM(addr))
  158. ret = _swapw(ret);
  159. return ret;
  160. }
  161. static inline uint32_t readl(const volatile void __iomem *addr)
  162. {
  163. uint32_t ret = __builtin_read32((volatile uint32_t __force *)addr);
  164. if (__is_PCI_MEM(addr))
  165. ret = _swapl(ret);
  166. return ret;
  167. }
  168. static inline void writeb(uint8_t datum, volatile void __iomem *addr)
  169. {
  170. __builtin_write8((volatile uint8_t __force *) addr, datum);
  171. if (__is_PCI_MEM(addr))
  172. __flush_PCI_writes();
  173. }
  174. static inline void writew(uint16_t datum, volatile void __iomem *addr)
  175. {
  176. if (__is_PCI_MEM(addr))
  177. datum = _swapw(datum);
  178. __builtin_write16((volatile uint16_t __force *) addr, datum);
  179. if (__is_PCI_MEM(addr))
  180. __flush_PCI_writes();
  181. }
  182. static inline void writel(uint32_t datum, volatile void __iomem *addr)
  183. {
  184. if (__is_PCI_MEM(addr))
  185. datum = _swapl(datum);
  186. __builtin_write32((volatile uint32_t __force *) addr, datum);
  187. if (__is_PCI_MEM(addr))
  188. __flush_PCI_writes();
  189. }
  190. /* Values for nocacheflag and cmode */
  191. #define IOMAP_FULL_CACHING 0
  192. #define IOMAP_NOCACHE_SER 1
  193. #define IOMAP_NOCACHE_NONSER 2
  194. #define IOMAP_WRITETHROUGH 3
  195. extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
  196. extern void __iounmap(void __iomem *addr, unsigned long size);
  197. static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
  198. {
  199. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  200. }
  201. static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
  202. {
  203. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  204. }
  205. static inline void __iomem *ioremap_writethrough(unsigned long physaddr, unsigned long size)
  206. {
  207. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  208. }
  209. static inline void __iomem *ioremap_fullcache(unsigned long physaddr, unsigned long size)
  210. {
  211. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  212. }
  213. extern void iounmap(void __iomem *addr);
  214. static inline void flush_write_buffers(void)
  215. {
  216. __asm__ __volatile__ ("membar" : : :"memory");
  217. }
  218. /*
  219. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  220. * access
  221. */
  222. #define xlate_dev_mem_ptr(p) __va(p)
  223. /*
  224. * Convert a virtual cached pointer to an uncached pointer
  225. */
  226. #define xlate_dev_kmem_ptr(p) p
  227. #endif /* __KERNEL__ */
  228. #endif /* _ASM_IO_H */