io.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #ifndef _ASM_IO_H
  2. #define _ASM_IO_H
  3. #include <linux/config.h>
  4. #include <linux/types.h>
  5. #include <asm/pgtable.h>
  6. extern unsigned long parisc_vmerge_boundary;
  7. extern unsigned long parisc_vmerge_max_size;
  8. #define BIO_VMERGE_BOUNDARY parisc_vmerge_boundary
  9. #define BIO_VMERGE_MAX_SIZE parisc_vmerge_max_size
  10. #define virt_to_phys(a) ((unsigned long)__pa(a))
  11. #define phys_to_virt(a) __va(a)
  12. #define virt_to_bus virt_to_phys
  13. #define bus_to_virt phys_to_virt
  14. /*
  15. * Memory mapped I/O
  16. *
  17. * readX()/writeX() do byteswapping and take an ioremapped address
  18. * __raw_readX()/__raw_writeX() don't byteswap and take an ioremapped address.
  19. * gsc_*() don't byteswap and operate on physical addresses;
  20. * eg dev->hpa or 0xfee00000.
  21. */
  22. static inline unsigned char gsc_readb(unsigned long addr)
  23. {
  24. long flags;
  25. unsigned char ret;
  26. __asm__ __volatile__(
  27. " rsm 2,%0\n"
  28. " ldbx 0(%2),%1\n"
  29. " mtsm %0\n"
  30. : "=&r" (flags), "=r" (ret) : "r" (addr) );
  31. return ret;
  32. }
  33. static inline unsigned short gsc_readw(unsigned long addr)
  34. {
  35. long flags;
  36. unsigned short ret;
  37. __asm__ __volatile__(
  38. " rsm 2,%0\n"
  39. " ldhx 0(%2),%1\n"
  40. " mtsm %0\n"
  41. : "=&r" (flags), "=r" (ret) : "r" (addr) );
  42. return ret;
  43. }
  44. static inline unsigned int gsc_readl(unsigned long addr)
  45. {
  46. u32 ret;
  47. __asm__ __volatile__(
  48. " ldwax 0(%1),%0\n"
  49. : "=r" (ret) : "r" (addr) );
  50. return ret;
  51. }
  52. static inline unsigned long long gsc_readq(unsigned long addr)
  53. {
  54. unsigned long long ret;
  55. #ifdef __LP64__
  56. __asm__ __volatile__(
  57. " ldda 0(%1),%0\n"
  58. : "=r" (ret) : "r" (addr) );
  59. #else
  60. /* two reads may have side effects.. */
  61. ret = ((u64) gsc_readl(addr)) << 32;
  62. ret |= gsc_readl(addr+4);
  63. #endif
  64. return ret;
  65. }
  66. static inline void gsc_writeb(unsigned char val, unsigned long addr)
  67. {
  68. long flags;
  69. __asm__ __volatile__(
  70. " rsm 2,%0\n"
  71. " stbs %1,0(%2)\n"
  72. " mtsm %0\n"
  73. : "=&r" (flags) : "r" (val), "r" (addr) );
  74. }
  75. static inline void gsc_writew(unsigned short val, unsigned long addr)
  76. {
  77. long flags;
  78. __asm__ __volatile__(
  79. " rsm 2,%0\n"
  80. " sths %1,0(%2)\n"
  81. " mtsm %0\n"
  82. : "=&r" (flags) : "r" (val), "r" (addr) );
  83. }
  84. static inline void gsc_writel(unsigned int val, unsigned long addr)
  85. {
  86. __asm__ __volatile__(
  87. " stwas %0,0(%1)\n"
  88. : : "r" (val), "r" (addr) );
  89. }
  90. static inline void gsc_writeq(unsigned long long val, unsigned long addr)
  91. {
  92. #ifdef __LP64__
  93. __asm__ __volatile__(
  94. " stda %0,0(%1)\n"
  95. : : "r" (val), "r" (addr) );
  96. #else
  97. /* two writes may have side effects.. */
  98. gsc_writel(val >> 32, addr);
  99. gsc_writel(val, addr+4);
  100. #endif
  101. }
  102. /*
  103. * The standard PCI ioremap interfaces
  104. */
  105. extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
  106. extern inline void __iomem * ioremap(unsigned long offset, unsigned long size)
  107. {
  108. return __ioremap(offset, size, 0);
  109. }
  110. /*
  111. * This one maps high address device memory and turns off caching for that area.
  112. * it's useful if some control registers are in such an area and write combining
  113. * or read caching is not desirable:
  114. */
  115. extern inline void * ioremap_nocache(unsigned long offset, unsigned long size)
  116. {
  117. return __ioremap(offset, size, _PAGE_NO_CACHE /* _PAGE_PCD */);
  118. }
  119. extern void iounmap(void __iomem *addr);
  120. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  121. {
  122. return (*(volatile unsigned char __force *) (addr));
  123. }
  124. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  125. {
  126. return *(volatile unsigned short __force *) addr;
  127. }
  128. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  129. {
  130. return *(volatile unsigned int __force *) addr;
  131. }
  132. static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
  133. {
  134. return *(volatile unsigned long long __force *) addr;
  135. }
  136. static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
  137. {
  138. *(volatile unsigned char __force *) addr = b;
  139. }
  140. static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
  141. {
  142. *(volatile unsigned short __force *) addr = b;
  143. }
  144. static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
  145. {
  146. *(volatile unsigned int __force *) addr = b;
  147. }
  148. static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
  149. {
  150. *(volatile unsigned long long __force *) addr = b;
  151. }
  152. /* readb can never be const, so use __fswab instead of le*_to_cpu */
  153. #define readb(addr) __raw_readb(addr)
  154. #define readw(addr) __fswab16(__raw_readw(addr))
  155. #define readl(addr) __fswab32(__raw_readl(addr))
  156. #define readq(addr) __fswab64(__raw_readq(addr))
  157. #define writeb(b, addr) __raw_writeb(b, addr)
  158. #define writew(b, addr) __raw_writew(cpu_to_le16(b), addr)
  159. #define writel(b, addr) __raw_writel(cpu_to_le32(b), addr)
  160. #define writeq(b, addr) __raw_writeq(cpu_to_le64(b), addr)
  161. #define readb_relaxed(addr) readb(addr)
  162. #define readw_relaxed(addr) readw(addr)
  163. #define readl_relaxed(addr) readl(addr)
  164. #define readq_relaxed(addr) readq(addr)
  165. #define mmiowb() do { } while (0)
  166. void memset_io(volatile void __iomem *addr, unsigned char val, int count);
  167. void memcpy_fromio(void *dst, const volatile void __iomem *src, int count);
  168. void memcpy_toio(volatile void __iomem *dst, const void *src, int count);
  169. /*
  170. * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
  171. * just copy it. The net code will then do the checksum later. Presently
  172. * only used by some shared memory 8390 Ethernet cards anyway.
  173. */
  174. #define eth_io_copy_and_sum(skb,src,len,unused) \
  175. memcpy_fromio((skb)->data,(src),(len))
  176. /* Port-space IO */
  177. #define inb_p inb
  178. #define inw_p inw
  179. #define inl_p inl
  180. #define outb_p outb
  181. #define outw_p outw
  182. #define outl_p outl
  183. extern unsigned char eisa_in8(unsigned short port);
  184. extern unsigned short eisa_in16(unsigned short port);
  185. extern unsigned int eisa_in32(unsigned short port);
  186. extern void eisa_out8(unsigned char data, unsigned short port);
  187. extern void eisa_out16(unsigned short data, unsigned short port);
  188. extern void eisa_out32(unsigned int data, unsigned short port);
  189. #if defined(CONFIG_PCI)
  190. extern unsigned char inb(int addr);
  191. extern unsigned short inw(int addr);
  192. extern unsigned int inl(int addr);
  193. extern void outb(unsigned char b, int addr);
  194. extern void outw(unsigned short b, int addr);
  195. extern void outl(unsigned int b, int addr);
  196. #elif defined(CONFIG_EISA)
  197. #define inb eisa_in8
  198. #define inw eisa_in16
  199. #define inl eisa_in32
  200. #define outb eisa_out8
  201. #define outw eisa_out16
  202. #define outl eisa_out32
  203. #else
  204. static inline char inb(unsigned long addr)
  205. {
  206. BUG();
  207. return -1;
  208. }
  209. static inline short inw(unsigned long addr)
  210. {
  211. BUG();
  212. return -1;
  213. }
  214. static inline int inl(unsigned long addr)
  215. {
  216. BUG();
  217. return -1;
  218. }
  219. #define outb(x, y) BUG()
  220. #define outw(x, y) BUG()
  221. #define outl(x, y) BUG()
  222. #endif
  223. /*
  224. * String versions of in/out ops:
  225. */
  226. extern void insb (unsigned long port, void *dst, unsigned long count);
  227. extern void insw (unsigned long port, void *dst, unsigned long count);
  228. extern void insl (unsigned long port, void *dst, unsigned long count);
  229. extern void outsb (unsigned long port, const void *src, unsigned long count);
  230. extern void outsw (unsigned long port, const void *src, unsigned long count);
  231. extern void outsl (unsigned long port, const void *src, unsigned long count);
  232. /* IO Port space is : BBiiii where BB is HBA number. */
  233. #define IO_SPACE_LIMIT 0x00ffffff
  234. #define dma_cache_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  235. #define dma_cache_wback(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  236. #define dma_cache_wback_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  237. /* PA machines have an MM I/O space from 0xf0000000-0xffffffff in 32
  238. * bit mode and from 0xfffffffff0000000-0xfffffffffffffff in 64 bit
  239. * mode (essentially just sign extending. This macro takes in a 32
  240. * bit I/O address (still with the leading f) and outputs the correct
  241. * value for either 32 or 64 bit mode */
  242. #define F_EXTEND(x) ((unsigned long)((x) | (0xffffffff00000000ULL)))
  243. #include <asm-generic/iomap.h>
  244. /*
  245. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  246. * access
  247. */
  248. #define xlate_dev_mem_ptr(p) __va(p)
  249. /*
  250. * Convert a virtual cached pointer to an uncached pointer
  251. */
  252. #define xlate_dev_kmem_ptr(p) p
  253. #endif