io.h 8.8 KB

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