io_mm.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * linux/include/asm-m68k/io.h
  3. *
  4. * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other
  5. * IO access
  6. * - added Q40 support
  7. * - added skeleton for GG-II and Amiga PCMCIA
  8. * 2/3/01 RZ: - moved a few more defs into raw_io.h
  9. *
  10. * inX/outX should not be used by any driver unless it does
  11. * ISA access. Other drivers should use function defined in raw_io.h
  12. * or define its own macros on top of these.
  13. *
  14. * inX(),outX() are for ISA I/O
  15. * isa_readX(),isa_writeX() are for ISA memory
  16. */
  17. #ifndef _IO_H
  18. #define _IO_H
  19. #ifdef __KERNEL__
  20. #include <linux/compiler.h>
  21. #include <asm/raw_io.h>
  22. #include <asm/virtconvert.h>
  23. #include <asm-generic/iomap.h>
  24. #ifdef CONFIG_ATARI
  25. #include <asm/atarihw.h>
  26. #endif
  27. /*
  28. * IO/MEM definitions for various ISA bridges
  29. */
  30. #ifdef CONFIG_Q40
  31. #define q40_isa_io_base 0xff400000
  32. #define q40_isa_mem_base 0xff800000
  33. #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
  34. #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
  35. #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
  36. #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
  37. #define MULTI_ISA 0
  38. #endif /* Q40 */
  39. #ifdef CONFIG_AMIGA_PCMCIA
  40. #include <asm/amigayle.h>
  41. #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
  42. #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
  43. #ifndef MULTI_ISA
  44. #define MULTI_ISA 0
  45. #else
  46. #undef MULTI_ISA
  47. #define MULTI_ISA 1
  48. #endif
  49. #endif /* AMIGA_PCMCIA */
  50. #ifdef CONFIG_ISA
  51. #if MULTI_ISA == 0
  52. #undef MULTI_ISA
  53. #endif
  54. #define ISA_TYPE_Q40 (1)
  55. #define ISA_TYPE_AG (2)
  56. #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
  57. #define ISA_TYPE ISA_TYPE_Q40
  58. #define ISA_SEX 0
  59. #endif
  60. #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
  61. #define ISA_TYPE ISA_TYPE_AG
  62. #define ISA_SEX 1
  63. #endif
  64. #ifdef MULTI_ISA
  65. extern int isa_type;
  66. extern int isa_sex;
  67. #define ISA_TYPE isa_type
  68. #define ISA_SEX isa_sex
  69. #endif
  70. /*
  71. * define inline addr translation functions. Normally only one variant will
  72. * be compiled in so the case statement will be optimised away
  73. */
  74. static inline u8 __iomem *isa_itb(unsigned long addr)
  75. {
  76. switch(ISA_TYPE)
  77. {
  78. #ifdef CONFIG_Q40
  79. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
  80. #endif
  81. #ifdef CONFIG_AMIGA_PCMCIA
  82. case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
  83. #endif
  84. default: return NULL; /* avoid warnings, just in case */
  85. }
  86. }
  87. static inline u16 __iomem *isa_itw(unsigned long addr)
  88. {
  89. switch(ISA_TYPE)
  90. {
  91. #ifdef CONFIG_Q40
  92. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
  93. #endif
  94. #ifdef CONFIG_AMIGA_PCMCIA
  95. case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
  96. #endif
  97. default: return NULL; /* avoid warnings, just in case */
  98. }
  99. }
  100. static inline u32 __iomem *isa_itl(unsigned long addr)
  101. {
  102. switch(ISA_TYPE)
  103. {
  104. #ifdef CONFIG_AMIGA_PCMCIA
  105. case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
  106. #endif
  107. default: return 0; /* avoid warnings, just in case */
  108. }
  109. }
  110. static inline u8 __iomem *isa_mtb(unsigned long addr)
  111. {
  112. switch(ISA_TYPE)
  113. {
  114. #ifdef CONFIG_Q40
  115. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
  116. #endif
  117. #ifdef CONFIG_AMIGA_PCMCIA
  118. case ISA_TYPE_AG: return (u8 __iomem *)addr;
  119. #endif
  120. default: return NULL; /* avoid warnings, just in case */
  121. }
  122. }
  123. static inline u16 __iomem *isa_mtw(unsigned long addr)
  124. {
  125. switch(ISA_TYPE)
  126. {
  127. #ifdef CONFIG_Q40
  128. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
  129. #endif
  130. #ifdef CONFIG_AMIGA_PCMCIA
  131. case ISA_TYPE_AG: return (u16 __iomem *)addr;
  132. #endif
  133. default: return NULL; /* avoid warnings, just in case */
  134. }
  135. }
  136. #define isa_inb(port) in_8(isa_itb(port))
  137. #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
  138. #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
  139. #define isa_outb(val,port) out_8(isa_itb(port),(val))
  140. #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
  141. #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
  142. #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
  143. #define isa_readw(p) \
  144. (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
  145. : in_le16(isa_mtw((unsigned long)(p))))
  146. #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
  147. #define isa_writew(val,p) \
  148. (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
  149. : out_le16(isa_mtw((unsigned long)(p)),(val)))
  150. static inline void isa_delay(void)
  151. {
  152. switch(ISA_TYPE)
  153. {
  154. #ifdef CONFIG_Q40
  155. case ISA_TYPE_Q40: isa_outb(0,0x80); break;
  156. #endif
  157. #ifdef CONFIG_AMIGA_PCMCIA
  158. case ISA_TYPE_AG: break;
  159. #endif
  160. default: break; /* avoid warnings */
  161. }
  162. }
  163. #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
  164. #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
  165. #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
  166. #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
  167. #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
  168. #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
  169. #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
  170. #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
  171. #define isa_insw(port, buf, nr) \
  172. (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  173. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  174. #define isa_outsw(port, buf, nr) \
  175. (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  176. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  177. #define isa_insl(port, buf, nr) \
  178. (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
  179. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  180. #define isa_outsl(port, buf, nr) \
  181. (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
  182. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  183. #define inb isa_inb
  184. #define inb_p isa_inb_p
  185. #define outb isa_outb
  186. #define outb_p isa_outb_p
  187. #define inw isa_inw
  188. #define inw_p isa_inw_p
  189. #define outw isa_outw
  190. #define outw_p isa_outw_p
  191. #define inl isa_inl
  192. #define inl_p isa_inl_p
  193. #define outl isa_outl
  194. #define outl_p isa_outl_p
  195. #define insb isa_insb
  196. #define insw isa_insw
  197. #define insl isa_insl
  198. #define outsb isa_outsb
  199. #define outsw isa_outsw
  200. #define outsl isa_outsl
  201. #define readb isa_readb
  202. #define readw isa_readw
  203. #define writeb isa_writeb
  204. #define writew isa_writew
  205. #else /* CONFIG_ISA */
  206. /*
  207. * We need to define dummy functions for GENERIC_IOMAP support.
  208. */
  209. #define inb(port) 0xff
  210. #define inb_p(port) 0xff
  211. #define outb(val,port) ((void)0)
  212. #define outb_p(val,port) ((void)0)
  213. #define inw(port) 0xffff
  214. #define inw_p(port) 0xffff
  215. #define outw(val,port) ((void)0)
  216. #define outw_p(val,port) ((void)0)
  217. #define inl(port) 0xffffffffUL
  218. #define inl_p(port) 0xffffffffUL
  219. #define outl(val,port) ((void)0)
  220. #define outl_p(val,port) ((void)0)
  221. #define insb(port,buf,nr) ((void)0)
  222. #define outsb(port,buf,nr) ((void)0)
  223. #define insw(port,buf,nr) ((void)0)
  224. #define outsw(port,buf,nr) ((void)0)
  225. #define insl(port,buf,nr) ((void)0)
  226. #define outsl(port,buf,nr) ((void)0)
  227. /*
  228. * These should be valid on any ioremap()ed region
  229. */
  230. #define readb(addr) in_8(addr)
  231. #define writeb(val,addr) out_8((addr),(val))
  232. #define readw(addr) in_le16(addr)
  233. #define writew(val,addr) out_le16((addr),(val))
  234. #endif /* CONFIG_ISA */
  235. #define readl(addr) in_le32(addr)
  236. #define writel(val,addr) out_le32((addr),(val))
  237. #define mmiowb()
  238. static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
  239. {
  240. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  241. }
  242. static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
  243. {
  244. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  245. }
  246. static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
  247. unsigned long size)
  248. {
  249. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  250. }
  251. static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
  252. unsigned long size)
  253. {
  254. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  255. }
  256. static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
  257. {
  258. __builtin_memset((void __force *) addr, val, count);
  259. }
  260. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  261. {
  262. __builtin_memcpy(dst, (void __force *) src, count);
  263. }
  264. static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  265. {
  266. __builtin_memcpy((void __force *) dst, src, count);
  267. }
  268. #ifndef CONFIG_SUN3
  269. #define IO_SPACE_LIMIT 0xffff
  270. #else
  271. #define IO_SPACE_LIMIT 0x0fffffff
  272. #endif
  273. #endif /* __KERNEL__ */
  274. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  275. /*
  276. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  277. * access
  278. */
  279. #define xlate_dev_mem_ptr(p) __va(p)
  280. /*
  281. * Convert a virtual cached pointer to an uncached pointer
  282. */
  283. #define xlate_dev_kmem_ptr(p) p
  284. #endif /* _IO_H */