io.h 10 KB

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