io.h 7.4 KB

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