io.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. /*
  146. * CONFIG_HPPA_IOREMAP is the magic flag to enable or disable real ioremap()
  147. * functionality. It's currently disabled because it may not work on some
  148. * machines.
  149. */
  150. #ifdef CONFIG_HPPA_IOREMAP
  151. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  152. {
  153. return (*(volatile unsigned char __force *) (addr));
  154. }
  155. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  156. {
  157. return *(volatile unsigned short __force *) addr;
  158. }
  159. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  160. {
  161. return *(volatile unsigned int __force *) addr;
  162. }
  163. static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
  164. {
  165. return *(volatile unsigned long long __force *) addr;
  166. }
  167. static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
  168. {
  169. *(volatile unsigned char __force *) addr = b;
  170. }
  171. static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
  172. {
  173. *(volatile unsigned short __force *) addr = b;
  174. }
  175. static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
  176. {
  177. *(volatile unsigned int __force *) addr = b;
  178. }
  179. static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
  180. {
  181. *(volatile unsigned long long __force *) addr = b;
  182. }
  183. #else /* !CONFIG_HPPA_IOREMAP */
  184. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  185. {
  186. __raw_check_addr(addr);
  187. return gsc_readb((unsigned long) addr);
  188. }
  189. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  190. {
  191. __raw_check_addr(addr);
  192. return gsc_readw((unsigned long) addr);
  193. }
  194. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  195. {
  196. __raw_check_addr(addr);
  197. return gsc_readl((unsigned long) addr);
  198. }
  199. static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
  200. {
  201. __raw_check_addr(addr);
  202. return gsc_readq((unsigned long) addr);
  203. }
  204. static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
  205. {
  206. __raw_check_addr(addr);
  207. gsc_writeb(b, (unsigned long) addr);
  208. }
  209. static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
  210. {
  211. __raw_check_addr(addr);
  212. gsc_writew(b, (unsigned long) addr);
  213. }
  214. static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
  215. {
  216. __raw_check_addr(addr);
  217. gsc_writel(b, (unsigned long) addr);
  218. }
  219. static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
  220. {
  221. __raw_check_addr(addr);
  222. gsc_writeq(b, (unsigned long) addr);
  223. }
  224. #endif /* !CONFIG_HPPA_IOREMAP */
  225. /* readb can never be const, so use __fswab instead of le*_to_cpu */
  226. #define readb(addr) __raw_readb(addr)
  227. #define readw(addr) __fswab16(__raw_readw(addr))
  228. #define readl(addr) __fswab32(__raw_readl(addr))
  229. #define readq(addr) __fswab64(__raw_readq(addr))
  230. #define writeb(b, addr) __raw_writeb(b, addr)
  231. #define writew(b, addr) __raw_writew(cpu_to_le16(b), addr)
  232. #define writel(b, addr) __raw_writel(cpu_to_le32(b), addr)
  233. #define writeq(b, addr) __raw_writeq(cpu_to_le64(b), addr)
  234. #define readb_relaxed(addr) readb(addr)
  235. #define readw_relaxed(addr) readw(addr)
  236. #define readl_relaxed(addr) readl(addr)
  237. #define readq_relaxed(addr) readq(addr)
  238. #define mmiowb() do { } while (0)
  239. void memset_io(volatile void __iomem *addr, unsigned char val, int count);
  240. void memcpy_fromio(void *dst, const volatile void __iomem *src, int count);
  241. void memcpy_toio(volatile void __iomem *dst, const void *src, int count);
  242. /*
  243. * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
  244. * just copy it. The net code will then do the checksum later. Presently
  245. * only used by some shared memory 8390 Ethernet cards anyway.
  246. */
  247. #define eth_io_copy_and_sum(skb,src,len,unused) \
  248. memcpy_fromio((skb)->data,(src),(len))
  249. /* Port-space IO */
  250. #define inb_p inb
  251. #define inw_p inw
  252. #define inl_p inl
  253. #define outb_p outb
  254. #define outw_p outw
  255. #define outl_p outl
  256. extern unsigned char eisa_in8(unsigned short port);
  257. extern unsigned short eisa_in16(unsigned short port);
  258. extern unsigned int eisa_in32(unsigned short port);
  259. extern void eisa_out8(unsigned char data, unsigned short port);
  260. extern void eisa_out16(unsigned short data, unsigned short port);
  261. extern void eisa_out32(unsigned int data, unsigned short port);
  262. #if defined(CONFIG_PCI)
  263. extern unsigned char inb(int addr);
  264. extern unsigned short inw(int addr);
  265. extern unsigned int inl(int addr);
  266. extern void outb(unsigned char b, int addr);
  267. extern void outw(unsigned short b, int addr);
  268. extern void outl(unsigned int b, int addr);
  269. #elif defined(CONFIG_EISA)
  270. #define inb eisa_in8
  271. #define inw eisa_in16
  272. #define inl eisa_in32
  273. #define outb eisa_out8
  274. #define outw eisa_out16
  275. #define outl eisa_out32
  276. #else
  277. static inline char inb(unsigned long addr)
  278. {
  279. BUG();
  280. return -1;
  281. }
  282. static inline short inw(unsigned long addr)
  283. {
  284. BUG();
  285. return -1;
  286. }
  287. static inline int inl(unsigned long addr)
  288. {
  289. BUG();
  290. return -1;
  291. }
  292. #define outb(x, y) BUG()
  293. #define outw(x, y) BUG()
  294. #define outl(x, y) BUG()
  295. #endif
  296. /*
  297. * String versions of in/out ops:
  298. */
  299. extern void insb (unsigned long port, void *dst, unsigned long count);
  300. extern void insw (unsigned long port, void *dst, unsigned long count);
  301. extern void insl (unsigned long port, void *dst, unsigned long count);
  302. extern void outsb (unsigned long port, const void *src, unsigned long count);
  303. extern void outsw (unsigned long port, const void *src, unsigned long count);
  304. extern void outsl (unsigned long port, const void *src, unsigned long count);
  305. /* IO Port space is : BBiiii where BB is HBA number. */
  306. #define IO_SPACE_LIMIT 0x00ffffff
  307. #define dma_cache_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  308. #define dma_cache_wback(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  309. #define dma_cache_wback_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
  310. /* PA machines have an MM I/O space from 0xf0000000-0xffffffff in 32
  311. * bit mode and from 0xfffffffff0000000-0xfffffffffffffff in 64 bit
  312. * mode (essentially just sign extending. This macro takes in a 32
  313. * bit I/O address (still with the leading f) and outputs the correct
  314. * value for either 32 or 64 bit mode */
  315. #define F_EXTEND(x) ((unsigned long)((x) | (0xffffffff00000000ULL)))
  316. #include <asm-generic/iomap.h>
  317. /*
  318. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  319. * access
  320. */
  321. #define xlate_dev_mem_ptr(p) __va(p)
  322. /*
  323. * Convert a virtual cached pointer to an uncached pointer
  324. */
  325. #define xlate_dev_kmem_ptr(p) p
  326. #endif