io.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. * These two are only here because ALSA _thinks_ it needs them...
  68. */
  69. static inline void memcpy_fromio(void * to, const volatile void __iomem *from,
  70. unsigned long count)
  71. {
  72. char *p = to;
  73. while (count) {
  74. count--;
  75. *p = readb(from);
  76. p++;
  77. from++;
  78. }
  79. }
  80. static inline void memcpy_toio(volatile void __iomem *to, const void * from,
  81. unsigned long count)
  82. {
  83. const char *p = from;
  84. while (count) {
  85. count--;
  86. writeb(*p, to);
  87. p++;
  88. to++;
  89. }
  90. }
  91. static inline void memset_io(volatile void __iomem *addr, unsigned char val,
  92. unsigned long count)
  93. {
  94. memset((void __force *)addr, val, count);
  95. }
  96. /*
  97. * Bad read/write accesses...
  98. */
  99. extern void __readwrite_bug(const char *fn);
  100. #define IO_SPACE_LIMIT 0xffffffff
  101. /* Convert I/O port address to virtual address */
  102. #define __io(p) ((void __iomem *)phys_to_uncached(p))
  103. /*
  104. * IO port access primitives
  105. * -------------------------
  106. *
  107. * The AVR32 doesn't have special IO access instructions; all IO is memory
  108. * mapped. Note that these are defined to perform little endian accesses
  109. * only. Their primary purpose is to access PCI and ISA peripherals.
  110. *
  111. * Note that for a big endian machine, this implies that the following
  112. * big endian mode connectivity is in place.
  113. *
  114. * The machine specific io.h include defines __io to translate an "IO"
  115. * address to a memory address.
  116. *
  117. * Note that we prevent GCC re-ordering or caching values in expressions
  118. * by introducing sequence points into the in*() definitions. Note that
  119. * __raw_* do not guarantee this behaviour.
  120. *
  121. * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
  122. */
  123. #define outb(v, p) __raw_writeb(v, __io(p))
  124. #define outw(v, p) __raw_writew(cpu_to_le16(v), __io(p))
  125. #define outl(v, p) __raw_writel(cpu_to_le32(v), __io(p))
  126. #define inb(p) __raw_readb(__io(p))
  127. #define inw(p) le16_to_cpu(__raw_readw(__io(p)))
  128. #define inl(p) le32_to_cpu(__raw_readl(__io(p)))
  129. static inline void __outsb(unsigned long port, void *addr, unsigned int count)
  130. {
  131. while (count--) {
  132. outb(*(u8 *)addr, port);
  133. addr++;
  134. }
  135. }
  136. static inline void __insb(unsigned long port, void *addr, unsigned int count)
  137. {
  138. while (count--) {
  139. *(u8 *)addr = inb(port);
  140. addr++;
  141. }
  142. }
  143. static inline void __outsw(unsigned long port, void *addr, unsigned int count)
  144. {
  145. while (count--) {
  146. outw(*(u16 *)addr, port);
  147. addr += 2;
  148. }
  149. }
  150. static inline void __insw(unsigned long port, void *addr, unsigned int count)
  151. {
  152. while (count--) {
  153. *(u16 *)addr = inw(port);
  154. addr += 2;
  155. }
  156. }
  157. static inline void __outsl(unsigned long port, void *addr, unsigned int count)
  158. {
  159. while (count--) {
  160. outl(*(u32 *)addr, port);
  161. addr += 4;
  162. }
  163. }
  164. static inline void __insl(unsigned long port, void *addr, unsigned int count)
  165. {
  166. while (count--) {
  167. *(u32 *)addr = inl(port);
  168. addr += 4;
  169. }
  170. }
  171. #define outsb(port, addr, count) __outsb(port, addr, count)
  172. #define insb(port, addr, count) __insb(port, addr, count)
  173. #define outsw(port, addr, count) __outsw(port, addr, count)
  174. #define insw(port, addr, count) __insw(port, addr, count)
  175. #define outsl(port, addr, count) __outsl(port, addr, count)
  176. #define insl(port, addr, count) __insl(port, addr, count)
  177. extern void __iomem *__ioremap(unsigned long offset, size_t size,
  178. unsigned long flags);
  179. extern void __iounmap(void __iomem *addr);
  180. /*
  181. * ioremap - map bus memory into CPU space
  182. * @offset bus address of the memory
  183. * @size size of the resource to map
  184. *
  185. * ioremap performs a platform specific sequence of operations to make
  186. * bus memory CPU accessible via the readb/.../writel functions and
  187. * the other mmio helpers. The returned address is not guaranteed to
  188. * be usable directly as a virtual address.
  189. */
  190. #define ioremap(offset, size) \
  191. __ioremap((offset), (size), 0)
  192. #define iounmap(addr) \
  193. __iounmap(addr)
  194. #define cached(addr) P1SEGADDR(addr)
  195. #define uncached(addr) P2SEGADDR(addr)
  196. #define virt_to_bus virt_to_phys
  197. #define bus_to_virt phys_to_virt
  198. #define page_to_bus page_to_phys
  199. #define bus_to_page phys_to_page
  200. #define dma_cache_wback_inv(_start, _size) \
  201. flush_dcache_region(_start, _size)
  202. #define dma_cache_inv(_start, _size) \
  203. invalidate_dcache_region(_start, _size)
  204. #define dma_cache_wback(_start, _size) \
  205. clean_dcache_region(_start, _size)
  206. /*
  207. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  208. * access
  209. */
  210. #define xlate_dev_mem_ptr(p) __va(p)
  211. /*
  212. * Convert a virtual cached pointer to an uncached pointer
  213. */
  214. #define xlate_dev_kmem_ptr(p) p
  215. #endif /* __KERNEL__ */
  216. #endif /* __ASM_AVR32_IO_H */