io.h 11 KB

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