io.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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/readX/writeX should not be used by any driver unless it does
  11. * ISA or PCI 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 PCI and ISA I/O
  15. * readX(),writeX() are for PCI memory
  16. * isa_readX(),isa_writeX() are for ISA memory
  17. *
  18. * moved mem{cpy,set}_*io inside CONFIG_PCI
  19. */
  20. #ifndef _IO_H
  21. #define _IO_H
  22. #ifdef __KERNEL__
  23. #include <linux/config.h>
  24. #include <asm/raw_io.h>
  25. #include <asm/virtconvert.h>
  26. #ifdef CONFIG_ATARI
  27. #include <asm/atarihw.h>
  28. #endif
  29. /*
  30. * IO/MEM definitions for various ISA bridges
  31. */
  32. #ifdef CONFIG_Q40
  33. #define q40_isa_io_base 0xff400000
  34. #define q40_isa_mem_base 0xff800000
  35. #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
  36. #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
  37. #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
  38. #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
  39. #define MULTI_ISA 0
  40. #endif /* Q40 */
  41. /* GG-II Zorro to ISA bridge */
  42. #ifdef CONFIG_GG2
  43. extern unsigned long gg2_isa_base;
  44. #define GG2_ISA_IO_B(ioaddr) (gg2_isa_base+1+((unsigned long)(ioaddr)*4))
  45. #define GG2_ISA_IO_W(ioaddr) (gg2_isa_base+ ((unsigned long)(ioaddr)*4))
  46. #define GG2_ISA_MEM_B(madr) (gg2_isa_base+1+(((unsigned long)(madr)*4) & 0xfffff))
  47. #define GG2_ISA_MEM_W(madr) (gg2_isa_base+ (((unsigned long)(madr)*4) & 0xfffff))
  48. #ifndef MULTI_ISA
  49. #define MULTI_ISA 0
  50. #else
  51. #undef MULTI_ISA
  52. #define MULTI_ISA 1
  53. #endif
  54. #endif /* GG2 */
  55. #ifdef CONFIG_AMIGA_PCMCIA
  56. #include <asm/amigayle.h>
  57. #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
  58. #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
  59. #ifndef MULTI_ISA
  60. #define MULTI_ISA 0
  61. #else
  62. #undef MULTI_ISA
  63. #define MULTI_ISA 1
  64. #endif
  65. #endif /* AMIGA_PCMCIA */
  66. #ifdef CONFIG_ISA
  67. #if MULTI_ISA == 0
  68. #undef MULTI_ISA
  69. #endif
  70. #define Q40_ISA (1)
  71. #define GG2_ISA (2)
  72. #define AG_ISA (3)
  73. #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
  74. #define ISA_TYPE Q40_ISA
  75. #define ISA_SEX 0
  76. #endif
  77. #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
  78. #define ISA_TYPE AG_ISA
  79. #define ISA_SEX 1
  80. #endif
  81. #if defined(CONFIG_GG2) && !defined(MULTI_ISA)
  82. #define ISA_TYPE GG2_ISA
  83. #define ISA_SEX 0
  84. #endif
  85. #ifdef MULTI_ISA
  86. extern int isa_type;
  87. extern int isa_sex;
  88. #define ISA_TYPE isa_type
  89. #define ISA_SEX isa_sex
  90. #endif
  91. /*
  92. * define inline addr translation functions. Normally only one variant will
  93. * be compiled in so the case statement will be optimised away
  94. */
  95. static inline u8 *isa_itb(unsigned long addr)
  96. {
  97. switch(ISA_TYPE)
  98. {
  99. #ifdef CONFIG_Q40
  100. case Q40_ISA: return (u8 *)Q40_ISA_IO_B(addr);
  101. #endif
  102. #ifdef CONFIG_GG2
  103. case GG2_ISA: return (u8 *)GG2_ISA_IO_B(addr);
  104. #endif
  105. #ifdef CONFIG_AMIGA_PCMCIA
  106. case AG_ISA: return (u8 *)AG_ISA_IO_B(addr);
  107. #endif
  108. default: return 0; /* avoid warnings, just in case */
  109. }
  110. }
  111. static inline u16 *isa_itw(unsigned long addr)
  112. {
  113. switch(ISA_TYPE)
  114. {
  115. #ifdef CONFIG_Q40
  116. case Q40_ISA: return (u16 *)Q40_ISA_IO_W(addr);
  117. #endif
  118. #ifdef CONFIG_GG2
  119. case GG2_ISA: return (u16 *)GG2_ISA_IO_W(addr);
  120. #endif
  121. #ifdef CONFIG_AMIGA_PCMCIA
  122. case AG_ISA: return (u16 *)AG_ISA_IO_W(addr);
  123. #endif
  124. default: return 0; /* avoid warnings, just in case */
  125. }
  126. }
  127. static inline u8 *isa_mtb(unsigned long addr)
  128. {
  129. switch(ISA_TYPE)
  130. {
  131. #ifdef CONFIG_Q40
  132. case Q40_ISA: return (u8 *)Q40_ISA_MEM_B(addr);
  133. #endif
  134. #ifdef CONFIG_GG2
  135. case GG2_ISA: return (u8 *)GG2_ISA_MEM_B(addr);
  136. #endif
  137. #ifdef CONFIG_AMIGA_PCMCIA
  138. case AG_ISA: return (u8 *)addr;
  139. #endif
  140. default: return 0; /* avoid warnings, just in case */
  141. }
  142. }
  143. static inline u16 *isa_mtw(unsigned long addr)
  144. {
  145. switch(ISA_TYPE)
  146. {
  147. #ifdef CONFIG_Q40
  148. case Q40_ISA: return (u16 *)Q40_ISA_MEM_W(addr);
  149. #endif
  150. #ifdef CONFIG_GG2
  151. case GG2_ISA: return (u16 *)GG2_ISA_MEM_W(addr);
  152. #endif
  153. #ifdef CONFIG_AMIGA_PCMCIA
  154. case AG_ISA: return (u16 *)addr;
  155. #endif
  156. default: return 0; /* avoid warnings, just in case */
  157. }
  158. }
  159. #define isa_inb(port) in_8(isa_itb(port))
  160. #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
  161. #define isa_outb(val,port) out_8(isa_itb(port),(val))
  162. #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
  163. #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
  164. #define isa_readw(p) \
  165. (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
  166. : in_le16(isa_mtw((unsigned long)(p))))
  167. #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
  168. #define isa_writew(val,p) \
  169. (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
  170. : out_le16(isa_mtw((unsigned long)(p)),(val)))
  171. static inline void isa_delay(void)
  172. {
  173. switch(ISA_TYPE)
  174. {
  175. #ifdef CONFIG_Q40
  176. case Q40_ISA: isa_outb(0,0x80); break;
  177. #endif
  178. #ifdef CONFIG_GG2
  179. case GG2_ISA: break;
  180. #endif
  181. #ifdef CONFIG_AMIGA_PCMCIA
  182. case AG_ISA: break;
  183. #endif
  184. default: break; /* avoid warnings */
  185. }
  186. }
  187. #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
  188. #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
  189. #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
  190. #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
  191. #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
  192. #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
  193. #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
  194. #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
  195. #define isa_insw(port, buf, nr) \
  196. (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  197. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  198. #define isa_outsw(port, buf, nr) \
  199. (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  200. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  201. #endif /* CONFIG_ISA */
  202. #if defined(CONFIG_ISA) && !defined(CONFIG_PCI)
  203. #define inb isa_inb
  204. #define inb_p isa_inb_p
  205. #define outb isa_outb
  206. #define outb_p isa_outb_p
  207. #define inw isa_inw
  208. #define inw_p isa_inw_p
  209. #define outw isa_outw
  210. #define outw_p isa_outw_p
  211. #define inl isa_inw
  212. #define inl_p isa_inw_p
  213. #define outl isa_outw
  214. #define outl_p isa_outw_p
  215. #define insb isa_insb
  216. #define insw isa_insw
  217. #define outsb isa_outsb
  218. #define outsw isa_outsw
  219. #define readb isa_readb
  220. #define readw isa_readw
  221. #define writeb isa_writeb
  222. #define writew isa_writew
  223. #endif /* CONFIG_ISA */
  224. #if defined(CONFIG_PCI)
  225. #define inl(port) in_le32(port)
  226. #define outl(val,port) out_le32((port),(val))
  227. #define readl(addr) in_le32(addr)
  228. #define writel(val,addr) out_le32((addr),(val))
  229. /* those can be defined for both ISA and PCI - it won't work though */
  230. #define readb(addr) in_8(addr)
  231. #define readw(addr) in_le16(addr)
  232. #define writeb(val,addr) out_8((addr),(val))
  233. #define writew(val,addr) out_le16((addr),(val))
  234. #define readb_relaxed(addr) readb(addr)
  235. #define readw_relaxed(addr) readw(addr)
  236. #define readl_relaxed(addr) readl(addr)
  237. #ifndef CONFIG_ISA
  238. #define inb(port) in_8(port)
  239. #define outb(val,port) out_8((port),(val))
  240. #define inw(port) in_le16(port)
  241. #define outw(val,port) out_le16((port),(val))
  242. #else
  243. /*
  244. * kernel with both ISA and PCI compiled in, those have
  245. * conflicting defs for in/out. Simply consider port < 1024
  246. * ISA and everything else PCI. read,write not defined
  247. * in this case
  248. */
  249. #define inb(port) ((port)<1024 ? isa_inb(port) : in_8(port))
  250. #define inb_p(port) ((port)<1024 ? isa_inb_p(port) : in_8(port))
  251. #define inw(port) ((port)<1024 ? isa_inw(port) : in_le16(port))
  252. #define inw_p(port) ((port)<1024 ? isa_inw_p(port) : in_le16(port))
  253. #define inl(port) ((port)<1024 ? isa_inl(port) : in_le32(port))
  254. #define inl_p(port) ((port)<1024 ? isa_inl_p(port) : in_le32(port))
  255. #define outb(val,port) ((port)<1024 ? isa_outb((val),(port)) : out_8((port),(val)))
  256. #define outb_p(val,port) ((port)<1024 ? isa_outb_p((val),(port)) : out_8((port),(val)))
  257. #define outw(val,port) ((port)<1024 ? isa_outw((val),(port)) : out_le16((port),(val)))
  258. #define outw_p(val,port) ((port)<1024 ? isa_outw_p((val),(port)) : out_le16((port),(val)))
  259. #define outl(val,port) ((port)<1024 ? isa_outl((val),(port)) : out_le32((port),(val)))
  260. #define outl_p(val,port) ((port)<1024 ? isa_outl_p((val),(port)) : out_le32((port),(val)))
  261. #endif
  262. #endif /* CONFIG_PCI */
  263. #if !defined(CONFIG_ISA) && !defined(CONFIG_PCI) && defined(CONFIG_HP300)
  264. /*
  265. * We need to define dummy functions otherwise drivers/serial/8250.c doesn't link
  266. */
  267. #define inb(port) 0xff
  268. #define inb_p(port) 0xff
  269. #define outb(val,port) do { } while (0)
  270. #define outb_p(val,port) do { } while (0)
  271. /*
  272. * These should be valid on any ioremap()ed region
  273. */
  274. #define readb(addr) in_8(addr)
  275. #define writeb(val,addr) out_8((addr),(val))
  276. #define readl(addr) in_le32(addr)
  277. #define writel(val,addr) out_le32((addr),(val))
  278. #endif
  279. #define mmiowb()
  280. static inline void *ioremap(unsigned long physaddr, unsigned long size)
  281. {
  282. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  283. }
  284. static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
  285. {
  286. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  287. }
  288. static inline void *ioremap_writethrough(unsigned long physaddr,
  289. unsigned long size)
  290. {
  291. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  292. }
  293. static inline void *ioremap_fullcache(unsigned long physaddr,
  294. unsigned long size)
  295. {
  296. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  297. }
  298. /* m68k caches aren't DMA coherent */
  299. extern void dma_cache_wback_inv(unsigned long start, unsigned long size);
  300. extern void dma_cache_wback(unsigned long start, unsigned long size);
  301. extern void dma_cache_inv(unsigned long start, unsigned long size);
  302. #ifndef CONFIG_SUN3
  303. #define IO_SPACE_LIMIT 0xffff
  304. #else
  305. #define IO_SPACE_LIMIT 0x0fffffff
  306. #endif
  307. #endif /* __KERNEL__ */
  308. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  309. /*
  310. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  311. * access
  312. */
  313. #define xlate_dev_mem_ptr(p) __va(p)
  314. /*
  315. * Convert a virtual cached pointer to an uncached pointer
  316. */
  317. #define xlate_dev_kmem_ptr(p) p
  318. #endif /* _IO_H */