io.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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/compiler.h>
  24. #include <asm/raw_io.h>
  25. #include <asm/virtconvert.h>
  26. #include <asm-generic/iomap.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 u32 __iomem *isa_itl(unsigned long addr)
  129. {
  130. switch(ISA_TYPE)
  131. {
  132. #ifdef CONFIG_AMIGA_PCMCIA
  133. case AG_ISA: return (u32 __iomem *)AG_ISA_IO_W(addr);
  134. #endif
  135. default: return 0; /* avoid warnings, just in case */
  136. }
  137. }
  138. static inline u8 __iomem *isa_mtb(unsigned long addr)
  139. {
  140. switch(ISA_TYPE)
  141. {
  142. #ifdef CONFIG_Q40
  143. case Q40_ISA: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
  144. #endif
  145. #ifdef CONFIG_GG2
  146. case GG2_ISA: return (u8 __iomem *)GG2_ISA_MEM_B(addr);
  147. #endif
  148. #ifdef CONFIG_AMIGA_PCMCIA
  149. case AG_ISA: return (u8 __iomem *)addr;
  150. #endif
  151. default: return NULL; /* avoid warnings, just in case */
  152. }
  153. }
  154. static inline u16 __iomem *isa_mtw(unsigned long addr)
  155. {
  156. switch(ISA_TYPE)
  157. {
  158. #ifdef CONFIG_Q40
  159. case Q40_ISA: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
  160. #endif
  161. #ifdef CONFIG_GG2
  162. case GG2_ISA: return (u16 __iomem *)GG2_ISA_MEM_W(addr);
  163. #endif
  164. #ifdef CONFIG_AMIGA_PCMCIA
  165. case AG_ISA: return (u16 __iomem *)addr;
  166. #endif
  167. default: return NULL; /* avoid warnings, just in case */
  168. }
  169. }
  170. #define isa_inb(port) in_8(isa_itb(port))
  171. #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
  172. #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
  173. #define isa_outb(val,port) out_8(isa_itb(port),(val))
  174. #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
  175. #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
  176. #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
  177. #define isa_readw(p) \
  178. (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
  179. : in_le16(isa_mtw((unsigned long)(p))))
  180. #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
  181. #define isa_writew(val,p) \
  182. (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
  183. : out_le16(isa_mtw((unsigned long)(p)),(val)))
  184. static inline void isa_delay(void)
  185. {
  186. switch(ISA_TYPE)
  187. {
  188. #ifdef CONFIG_Q40
  189. case Q40_ISA: isa_outb(0,0x80); break;
  190. #endif
  191. #ifdef CONFIG_GG2
  192. case GG2_ISA: break;
  193. #endif
  194. #ifdef CONFIG_AMIGA_PCMCIA
  195. case AG_ISA: break;
  196. #endif
  197. default: break; /* avoid warnings */
  198. }
  199. }
  200. #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
  201. #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
  202. #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
  203. #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
  204. #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
  205. #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
  206. #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
  207. #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
  208. #define isa_insw(port, buf, nr) \
  209. (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  210. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  211. #define isa_outsw(port, buf, nr) \
  212. (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  213. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  214. #define isa_insl(port, buf, nr) \
  215. (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
  216. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  217. #define isa_outsl(port, buf, nr) \
  218. (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
  219. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  220. #endif /* CONFIG_ISA */
  221. #if defined(CONFIG_ISA) && !defined(CONFIG_PCI)
  222. #define inb isa_inb
  223. #define inb_p isa_inb_p
  224. #define outb isa_outb
  225. #define outb_p isa_outb_p
  226. #define inw isa_inw
  227. #define inw_p isa_inw_p
  228. #define outw isa_outw
  229. #define outw_p isa_outw_p
  230. #define inl isa_inl
  231. #define inl_p isa_inl_p
  232. #define outl isa_outl
  233. #define outl_p isa_outl_p
  234. #define insb isa_insb
  235. #define insw isa_insw
  236. #define insl isa_insl
  237. #define outsb isa_outsb
  238. #define outsw isa_outsw
  239. #define outsl isa_outsl
  240. #define readb isa_readb
  241. #define readw isa_readw
  242. #define writeb isa_writeb
  243. #define writew isa_writew
  244. #endif /* CONFIG_ISA */
  245. #if defined(CONFIG_PCI)
  246. #define readl(addr) in_le32(addr)
  247. #define writel(val,addr) out_le32((addr),(val))
  248. /* those can be defined for both ISA and PCI - it won't work though */
  249. #define readb(addr) in_8(addr)
  250. #define readw(addr) in_le16(addr)
  251. #define writeb(val,addr) out_8((addr),(val))
  252. #define writew(val,addr) out_le16((addr),(val))
  253. #define readb_relaxed(addr) readb(addr)
  254. #define readw_relaxed(addr) readw(addr)
  255. #define readl_relaxed(addr) readl(addr)
  256. #ifndef CONFIG_ISA
  257. #define inb(port) in_8(port)
  258. #define outb(val,port) out_8((port),(val))
  259. #define inw(port) in_le16(port)
  260. #define outw(val,port) out_le16((port),(val))
  261. #define inl(port) in_le32(port)
  262. #define outl(val,port) out_le32((port),(val))
  263. #else
  264. /*
  265. * kernel with both ISA and PCI compiled in, those have
  266. * conflicting defs for in/out. Simply consider port < 1024
  267. * ISA and everything else PCI. read,write not defined
  268. * in this case
  269. */
  270. #define inb(port) ((port)<1024 ? isa_inb(port) : in_8(port))
  271. #define inb_p(port) ((port)<1024 ? isa_inb_p(port) : in_8(port))
  272. #define inw(port) ((port)<1024 ? isa_inw(port) : in_le16(port))
  273. #define inw_p(port) ((port)<1024 ? isa_inw_p(port) : in_le16(port))
  274. #define inl(port) ((port)<1024 ? isa_inl(port) : in_le32(port))
  275. #define inl_p(port) ((port)<1024 ? isa_inl_p(port) : in_le32(port))
  276. #define outb(val,port) ((port)<1024 ? isa_outb((val),(port)) : out_8((port),(val)))
  277. #define outb_p(val,port) ((port)<1024 ? isa_outb_p((val),(port)) : out_8((port),(val)))
  278. #define outw(val,port) ((port)<1024 ? isa_outw((val),(port)) : out_le16((port),(val)))
  279. #define outw_p(val,port) ((port)<1024 ? isa_outw_p((val),(port)) : out_le16((port),(val)))
  280. #define outl(val,port) ((port)<1024 ? isa_outl((val),(port)) : out_le32((port),(val)))
  281. #define outl_p(val,port) ((port)<1024 ? isa_outl_p((val),(port)) : out_le32((port),(val)))
  282. #endif
  283. #endif /* CONFIG_PCI */
  284. #if !defined(CONFIG_ISA) && !defined(CONFIG_PCI)
  285. /*
  286. * We need to define dummy functions for GENERIC_IOMAP support.
  287. */
  288. #define inb(port) 0xff
  289. #define inb_p(port) 0xff
  290. #define outb(val,port) ((void)0)
  291. #define outb_p(val,port) ((void)0)
  292. #define inw(port) 0xffff
  293. #define outw(val,port) ((void)0)
  294. #define inl(port) 0xffffffffUL
  295. #define outl(val,port) ((void)0)
  296. #define insb(port,buf,nr) ((void)0)
  297. #define outsb(port,buf,nr) ((void)0)
  298. #define insw(port,buf,nr) ((void)0)
  299. #define outsw(port,buf,nr) ((void)0)
  300. #define insl(port,buf,nr) ((void)0)
  301. #define outsl(port,buf,nr) ((void)0)
  302. /*
  303. * These should be valid on any ioremap()ed region
  304. */
  305. #define readb(addr) in_8(addr)
  306. #define writeb(val,addr) out_8((addr),(val))
  307. #define readw(addr) in_le16(addr)
  308. #define writew(val,addr) out_le16((addr),(val))
  309. #endif
  310. #if !defined(CONFIG_PCI)
  311. #define readl(addr) in_le32(addr)
  312. #define writel(val,addr) out_le32((addr),(val))
  313. #endif
  314. #define mmiowb()
  315. static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
  316. {
  317. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  318. }
  319. static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
  320. {
  321. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  322. }
  323. static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
  324. unsigned long size)
  325. {
  326. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  327. }
  328. static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
  329. unsigned long size)
  330. {
  331. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  332. }
  333. /* m68k caches aren't DMA coherent */
  334. extern void dma_cache_wback_inv(unsigned long start, unsigned long size);
  335. extern void dma_cache_wback(unsigned long start, unsigned long size);
  336. extern void dma_cache_inv(unsigned long start, unsigned long size);
  337. static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
  338. {
  339. __builtin_memset((void __force *) addr, val, count);
  340. }
  341. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  342. {
  343. __builtin_memcpy(dst, (void __force *) src, count);
  344. }
  345. static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  346. {
  347. __builtin_memcpy((void __force *) dst, src, count);
  348. }
  349. #ifndef CONFIG_SUN3
  350. #define IO_SPACE_LIMIT 0xffff
  351. #else
  352. #define IO_SPACE_LIMIT 0x0fffffff
  353. #endif
  354. #endif /* __KERNEL__ */
  355. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  356. /*
  357. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  358. * access
  359. */
  360. #define xlate_dev_mem_ptr(p) __va(p)
  361. /*
  362. * Convert a virtual cached pointer to an uncached pointer
  363. */
  364. #define xlate_dev_kmem_ptr(p) p
  365. #endif /* _IO_H */