io.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #ifndef __ASM_AVR32_IO_H
  2. #define __ASM_AVR32_IO_H
  3. #include <linux/string.h>
  4. #ifdef __KERNEL__
  5. #include <asm/addrspace.h>
  6. #include <asm/byteorder.h>
  7. /* virt_to_phys will only work when address is in P1 or P2 */
  8. static __inline__ unsigned long virt_to_phys(volatile void *address)
  9. {
  10. return PHYSADDR(address);
  11. }
  12. static __inline__ void * phys_to_virt(unsigned long address)
  13. {
  14. return (void *)P1SEGADDR(address);
  15. }
  16. #define cached_to_phys(addr) ((unsigned long)PHYSADDR(addr))
  17. #define uncached_to_phys(addr) ((unsigned long)PHYSADDR(addr))
  18. #define phys_to_cached(addr) ((void *)P1SEGADDR(addr))
  19. #define phys_to_uncached(addr) ((void *)P2SEGADDR(addr))
  20. /*
  21. * Generic IO read/write. These perform native-endian accesses. Note
  22. * that some architectures will want to re-define __raw_{read,write}w.
  23. */
  24. extern void __raw_writesb(unsigned int addr, const void *data, int bytelen);
  25. extern void __raw_writesw(unsigned int addr, const void *data, int wordlen);
  26. extern void __raw_writesl(unsigned int addr, const void *data, int longlen);
  27. extern void __raw_readsb(unsigned int addr, void *data, int bytelen);
  28. extern void __raw_readsw(unsigned int addr, void *data, int wordlen);
  29. extern void __raw_readsl(unsigned int addr, void *data, int longlen);
  30. static inline void writeb(unsigned char b, volatile void __iomem *addr)
  31. {
  32. *(volatile unsigned char __force *)addr = b;
  33. }
  34. static inline void writew(unsigned short b, volatile void __iomem *addr)
  35. {
  36. *(volatile unsigned short __force *)addr = b;
  37. }
  38. static inline void writel(unsigned int b, volatile void __iomem *addr)
  39. {
  40. *(volatile unsigned int __force *)addr = b;
  41. }
  42. #define __raw_writeb writeb
  43. #define __raw_writew writew
  44. #define __raw_writel writel
  45. static inline unsigned char readb(const volatile void __iomem *addr)
  46. {
  47. return *(const volatile unsigned char __force *)addr;
  48. }
  49. static inline unsigned short readw(const volatile void __iomem *addr)
  50. {
  51. return *(const volatile unsigned short __force *)addr;
  52. }
  53. static inline unsigned int readl(const volatile void __iomem *addr)
  54. {
  55. return *(const volatile unsigned int __force *)addr;
  56. }
  57. #define __raw_readb readb
  58. #define __raw_readw readw
  59. #define __raw_readl readl
  60. #define writesb(p, d, l) __raw_writesb((unsigned int)p, d, l)
  61. #define writesw(p, d, l) __raw_writesw((unsigned int)p, d, l)
  62. #define writesl(p, d, l) __raw_writesl((unsigned int)p, d, l)
  63. #define readsb(p, d, l) __raw_readsb((unsigned int)p, d, l)
  64. #define readsw(p, d, l) __raw_readsw((unsigned int)p, d, l)
  65. #define readsl(p, d, l) __raw_readsl((unsigned int)p, d, l)
  66. /*
  67. * io{read,write}{8,16,32} macros in both le (for PCI style consumers) and native be
  68. */
  69. #ifndef ioread8
  70. #define ioread8(p) ({ unsigned int __v = __raw_readb(p); __v; })
  71. #define ioread16(p) ({ unsigned int __v = le16_to_cpu(__raw_readw(p)); __v; })
  72. #define ioread16be(p) ({ unsigned int __v = be16_to_cpu(__raw_readw(p)); __v; })
  73. #define ioread32(p) ({ unsigned int __v = le32_to_cpu(__raw_readl(p)); __v; })
  74. #define ioread32be(p) ({ unsigned int __v = be32_to_cpu(__raw_readl(p)); __v; })
  75. #define iowrite8(v,p) __raw_writeb(v, p)
  76. #define iowrite16(v,p) __raw_writew(cpu_to_le16(v), p)
  77. #define iowrite16be(v,p) __raw_writew(cpu_to_be16(v), p)
  78. #define iowrite32(v,p) __raw_writel(cpu_to_le32(v), p)
  79. #define iowrite32be(v,p) __raw_writel(cpu_to_be32(v), p)
  80. #define ioread8_rep(p,d,c) __raw_readsb(p,d,c)
  81. #define ioread16_rep(p,d,c) __raw_readsw(p,d,c)
  82. #define ioread32_rep(p,d,c) __raw_readsl(p,d,c)
  83. #define iowrite8_rep(p,s,c) __raw_writesb(p,s,c)
  84. #define iowrite16_rep(p,s,c) __raw_writesw(p,s,c)
  85. #define iowrite32_rep(p,s,c) __raw_writesl(p,s,c)
  86. #endif
  87. /*
  88. * These two are only here because ALSA _thinks_ it needs them...
  89. */
  90. static inline void memcpy_fromio(void * to, const volatile void __iomem *from,
  91. unsigned long count)
  92. {
  93. char *p = to;
  94. while (count) {
  95. count--;
  96. *p = readb(from);
  97. p++;
  98. from++;
  99. }
  100. }
  101. static inline void memcpy_toio(volatile void __iomem *to, const void * from,
  102. unsigned long count)
  103. {
  104. const char *p = from;
  105. while (count) {
  106. count--;
  107. writeb(*p, to);
  108. p++;
  109. to++;
  110. }
  111. }
  112. static inline void memset_io(volatile void __iomem *addr, unsigned char val,
  113. unsigned long count)
  114. {
  115. memset((void __force *)addr, val, count);
  116. }
  117. /*
  118. * Bad read/write accesses...
  119. */
  120. extern void __readwrite_bug(const char *fn);
  121. #define IO_SPACE_LIMIT 0xffffffff
  122. /* Convert I/O port address to virtual address */
  123. #define __io(p) ((void __iomem *)phys_to_uncached(p))
  124. /*
  125. * IO port access primitives
  126. * -------------------------
  127. *
  128. * The AVR32 doesn't have special IO access instructions; all IO is memory
  129. * mapped. Note that these are defined to perform little endian accesses
  130. * only. Their primary purpose is to access PCI and ISA peripherals.
  131. *
  132. * Note that for a big endian machine, this implies that the following
  133. * big endian mode connectivity is in place.
  134. *
  135. * The machine specific io.h include defines __io to translate an "IO"
  136. * address to a memory address.
  137. *
  138. * Note that we prevent GCC re-ordering or caching values in expressions
  139. * by introducing sequence points into the in*() definitions. Note that
  140. * __raw_* do not guarantee this behaviour.
  141. *
  142. * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
  143. */
  144. #define outb(v, p) __raw_writeb(v, __io(p))
  145. #define outw(v, p) __raw_writew(cpu_to_le16(v), __io(p))
  146. #define outl(v, p) __raw_writel(cpu_to_le32(v), __io(p))
  147. #define inb(p) __raw_readb(__io(p))
  148. #define inw(p) le16_to_cpu(__raw_readw(__io(p)))
  149. #define inl(p) le32_to_cpu(__raw_readl(__io(p)))
  150. static inline void __outsb(unsigned long port, void *addr, unsigned int count)
  151. {
  152. while (count--) {
  153. outb(*(u8 *)addr, port);
  154. addr++;
  155. }
  156. }
  157. static inline void __insb(unsigned long port, void *addr, unsigned int count)
  158. {
  159. while (count--) {
  160. *(u8 *)addr = inb(port);
  161. addr++;
  162. }
  163. }
  164. static inline void __outsw(unsigned long port, void *addr, unsigned int count)
  165. {
  166. while (count--) {
  167. outw(*(u16 *)addr, port);
  168. addr += 2;
  169. }
  170. }
  171. static inline void __insw(unsigned long port, void *addr, unsigned int count)
  172. {
  173. while (count--) {
  174. *(u16 *)addr = inw(port);
  175. addr += 2;
  176. }
  177. }
  178. static inline void __outsl(unsigned long port, void *addr, unsigned int count)
  179. {
  180. while (count--) {
  181. outl(*(u32 *)addr, port);
  182. addr += 4;
  183. }
  184. }
  185. static inline void __insl(unsigned long port, void *addr, unsigned int count)
  186. {
  187. while (count--) {
  188. *(u32 *)addr = inl(port);
  189. addr += 4;
  190. }
  191. }
  192. #define outsb(port, addr, count) __outsb(port, addr, count)
  193. #define insb(port, addr, count) __insb(port, addr, count)
  194. #define outsw(port, addr, count) __outsw(port, addr, count)
  195. #define insw(port, addr, count) __insw(port, addr, count)
  196. #define outsl(port, addr, count) __outsl(port, addr, count)
  197. #define insl(port, addr, count) __insl(port, addr, count)
  198. extern void __iomem *__ioremap(unsigned long offset, size_t size,
  199. unsigned long flags);
  200. extern void __iounmap(void __iomem *addr);
  201. /*
  202. * ioremap - map bus memory into CPU space
  203. * @offset bus address of the memory
  204. * @size size of the resource to map
  205. *
  206. * ioremap performs a platform specific sequence of operations to make
  207. * bus memory CPU accessible via the readb/.../writel functions and
  208. * the other mmio helpers. The returned address is not guaranteed to
  209. * be usable directly as a virtual address.
  210. */
  211. #define ioremap(offset, size) \
  212. __ioremap((offset), (size), 0)
  213. #define iounmap(addr) \
  214. __iounmap(addr)
  215. #define cached(addr) P1SEGADDR(addr)
  216. #define uncached(addr) P2SEGADDR(addr)
  217. #define virt_to_bus virt_to_phys
  218. #define bus_to_virt phys_to_virt
  219. #define page_to_bus page_to_phys
  220. #define bus_to_page phys_to_page
  221. #define dma_cache_wback_inv(_start, _size) \
  222. flush_dcache_region(_start, _size)
  223. #define dma_cache_inv(_start, _size) \
  224. invalidate_dcache_region(_start, _size)
  225. #define dma_cache_wback(_start, _size) \
  226. clean_dcache_region(_start, _size)
  227. /*
  228. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  229. * access
  230. */
  231. #define xlate_dev_mem_ptr(p) __va(p)
  232. /*
  233. * Convert a virtual cached pointer to an uncached pointer
  234. */
  235. #define xlate_dev_kmem_ptr(p) p
  236. #endif /* __KERNEL__ */
  237. #endif /* __ASM_AVR32_IO_H */