io.h 8.0 KB

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