io_mm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/include/asm-m68k/io.h
  4. *
  5. * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other
  6. * IO access
  7. * - added Q40 support
  8. * - added skeleton for GG-II and Amiga PCMCIA
  9. * 2/3/01 RZ: - moved a few more defs into raw_io.h
  10. *
  11. * inX/outX should not be used by any driver unless it does
  12. * ISA access. Other drivers should use function defined in raw_io.h
  13. * or define its own macros on top of these.
  14. *
  15. * inX(),outX() are for ISA I/O
  16. * isa_readX(),isa_writeX() are for ISA memory
  17. */
  18. #ifndef _M68K_IO_MM_H
  19. #define _M68K_IO_MM_H
  20. #ifdef __KERNEL__
  21. #include <linux/compiler.h>
  22. #include <asm/raw_io.h>
  23. #include <asm/virtconvert.h>
  24. #include <asm/kmap.h>
  25. #include <asm-generic/iomap.h>
  26. #ifdef CONFIG_ATARI
  27. #define atari_readb raw_inb
  28. #define atari_writeb raw_outb
  29. #define atari_inb_p raw_inb
  30. #define atari_outb_p raw_outb
  31. #endif
  32. /*
  33. * IO/MEM definitions for various ISA bridges
  34. */
  35. #ifdef CONFIG_Q40
  36. #define q40_isa_io_base 0xff400000
  37. #define q40_isa_mem_base 0xff800000
  38. #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr)))
  39. #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr)))
  40. #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr)))
  41. #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr)))
  42. #define MULTI_ISA 0
  43. #endif /* Q40 */
  44. #ifdef CONFIG_AMIGA_PCMCIA
  45. #include <asm/amigayle.h>
  46. #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) )
  47. #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) )
  48. #ifndef MULTI_ISA
  49. #define MULTI_ISA 0
  50. #else
  51. #undef MULTI_ISA
  52. #define MULTI_ISA 1
  53. #endif
  54. #endif /* AMIGA_PCMCIA */
  55. #ifdef CONFIG_ATARI_ROM_ISA
  56. #define enec_isa_read_base 0xfffa0000
  57. #define enec_isa_write_base 0xfffb0000
  58. #define ENEC_ISA_IO_B(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
  59. #define ENEC_ISA_IO_W(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9))
  60. #define ENEC_ISA_MEM_B(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
  61. #define ENEC_ISA_MEM_W(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9))
  62. #ifndef MULTI_ISA
  63. #define MULTI_ISA 0
  64. #else
  65. #undef MULTI_ISA
  66. #define MULTI_ISA 1
  67. #endif
  68. #endif /* ATARI_ROM_ISA */
  69. #if defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA)
  70. #if MULTI_ISA == 0
  71. #undef MULTI_ISA
  72. #endif
  73. #define ISA_TYPE_Q40 (1)
  74. #define ISA_TYPE_AG (2)
  75. #define ISA_TYPE_ENEC (3)
  76. #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
  77. #define ISA_TYPE ISA_TYPE_Q40
  78. #define ISA_SEX 0
  79. #endif
  80. #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
  81. #define ISA_TYPE ISA_TYPE_AG
  82. #define ISA_SEX 1
  83. #endif
  84. #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA)
  85. #define ISA_TYPE ISA_TYPE_ENEC
  86. #define ISA_SEX 0
  87. #endif
  88. #ifdef MULTI_ISA
  89. extern int isa_type;
  90. extern int isa_sex;
  91. #define ISA_TYPE isa_type
  92. #define ISA_SEX isa_sex
  93. #endif
  94. /*
  95. * define inline addr translation functions. Normally only one variant will
  96. * be compiled in so the case statement will be optimised away
  97. */
  98. static inline u8 __iomem *isa_itb(unsigned long addr)
  99. {
  100. switch(ISA_TYPE)
  101. {
  102. #ifdef CONFIG_Q40
  103. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
  104. #endif
  105. #ifdef CONFIG_AMIGA_PCMCIA
  106. case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
  107. #endif
  108. #ifdef CONFIG_ATARI_ROM_ISA
  109. case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr);
  110. #endif
  111. default: return NULL; /* avoid warnings, just in case */
  112. }
  113. }
  114. static inline u16 __iomem *isa_itw(unsigned long addr)
  115. {
  116. switch(ISA_TYPE)
  117. {
  118. #ifdef CONFIG_Q40
  119. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
  120. #endif
  121. #ifdef CONFIG_AMIGA_PCMCIA
  122. case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
  123. #endif
  124. #ifdef CONFIG_ATARI_ROM_ISA
  125. case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr);
  126. #endif
  127. default: return NULL; /* avoid warnings, just in case */
  128. }
  129. }
  130. static inline u32 __iomem *isa_itl(unsigned long addr)
  131. {
  132. switch(ISA_TYPE)
  133. {
  134. #ifdef CONFIG_AMIGA_PCMCIA
  135. case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
  136. #endif
  137. default: return 0; /* avoid warnings, just in case */
  138. }
  139. }
  140. static inline u8 __iomem *isa_mtb(unsigned long addr)
  141. {
  142. switch(ISA_TYPE)
  143. {
  144. #ifdef CONFIG_Q40
  145. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
  146. #endif
  147. #ifdef CONFIG_AMIGA_PCMCIA
  148. case ISA_TYPE_AG: return (u8 __iomem *)addr;
  149. #endif
  150. #ifdef CONFIG_ATARI_ROM_ISA
  151. case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr);
  152. #endif
  153. default: return NULL; /* avoid warnings, just in case */
  154. }
  155. }
  156. static inline u16 __iomem *isa_mtw(unsigned long addr)
  157. {
  158. switch(ISA_TYPE)
  159. {
  160. #ifdef CONFIG_Q40
  161. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
  162. #endif
  163. #ifdef CONFIG_AMIGA_PCMCIA
  164. case ISA_TYPE_AG: return (u16 __iomem *)addr;
  165. #endif
  166. #ifdef CONFIG_ATARI_ROM_ISA
  167. case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr);
  168. #endif
  169. default: return NULL; /* avoid warnings, just in case */
  170. }
  171. }
  172. #define isa_inb(port) in_8(isa_itb(port))
  173. #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
  174. #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
  175. #define isa_outb(val,port) out_8(isa_itb(port),(val))
  176. #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
  177. #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
  178. #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
  179. #define isa_readw(p) \
  180. (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
  181. : in_le16(isa_mtw((unsigned long)(p))))
  182. #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
  183. #define isa_writew(val,p) \
  184. (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
  185. : out_le16(isa_mtw((unsigned long)(p)),(val)))
  186. #ifdef CONFIG_ATARI_ROM_ISA
  187. #define isa_rom_inb(port) rom_in_8(isa_itb(port))
  188. #define isa_rom_inw(port) \
  189. (ISA_SEX ? rom_in_be16(isa_itw(port)) \
  190. : rom_in_le16(isa_itw(port)))
  191. #define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val))
  192. #define isa_rom_outw(val, port) \
  193. (ISA_SEX ? rom_out_be16(isa_itw(port), (val)) \
  194. : rom_out_le16(isa_itw(port), (val)))
  195. #define isa_rom_readb(p) rom_in_8(isa_mtb((unsigned long)(p)))
  196. #define isa_rom_readw(p) \
  197. (ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p))) \
  198. : rom_in_le16(isa_mtw((unsigned long)(p))))
  199. #define isa_rom_readw_swap(p) \
  200. (ISA_SEX ? rom_in_le16(isa_mtw((unsigned long)(p))) \
  201. : rom_in_be16(isa_mtw((unsigned long)(p))))
  202. #define isa_rom_readw_raw(p) rom_in_be16(isa_mtw((unsigned long)(p)))
  203. #define isa_rom_writeb(val, p) rom_out_8(isa_mtb((unsigned long)(p)), (val))
  204. #define isa_rom_writew(val, p) \
  205. (ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val)) \
  206. : rom_out_le16(isa_mtw((unsigned long)(p)), (val)))
  207. #define isa_rom_writew_swap(val, p) \
  208. (ISA_SEX ? rom_out_le16(isa_mtw((unsigned long)(p)), (val)) \
  209. : rom_out_be16(isa_mtw((unsigned long)(p)), (val)))
  210. #define isa_rom_writew_raw(val, p) rom_out_be16(isa_mtw((unsigned long)(p)), (val))
  211. #endif /* CONFIG_ATARI_ROM_ISA */
  212. static inline void isa_delay(void)
  213. {
  214. switch(ISA_TYPE)
  215. {
  216. #ifdef CONFIG_Q40
  217. case ISA_TYPE_Q40: isa_outb(0,0x80); break;
  218. #endif
  219. #ifdef CONFIG_AMIGA_PCMCIA
  220. case ISA_TYPE_AG: break;
  221. #endif
  222. #ifdef CONFIG_ATARI_ROM_ISA
  223. case ISA_TYPE_ENEC: break;
  224. #endif
  225. default: break; /* avoid warnings */
  226. }
  227. }
  228. #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
  229. #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
  230. #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
  231. #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
  232. #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
  233. #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
  234. #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
  235. #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
  236. #define isa_insw(port, buf, nr) \
  237. (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  238. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  239. #define isa_outsw(port, buf, nr) \
  240. (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  241. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  242. #define isa_insl(port, buf, nr) \
  243. (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
  244. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  245. #define isa_outsl(port, buf, nr) \
  246. (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
  247. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  248. #ifdef CONFIG_ATARI_ROM_ISA
  249. #define isa_rom_inb_p(p) ({ u8 _v = isa_rom_inb(p); isa_delay(); _v; })
  250. #define isa_rom_inw_p(p) ({ u16 _v = isa_rom_inw(p); isa_delay(); _v; })
  251. #define isa_rom_outb_p(v, p) ({ isa_rom_outb((v), (p)); isa_delay(); })
  252. #define isa_rom_outw_p(v, p) ({ isa_rom_outw((v), (p)); isa_delay(); })
  253. #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr))
  254. #define isa_rom_insw(port, buf, nr) \
  255. (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  256. raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  257. #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr))
  258. #define isa_rom_outsw(port, buf, nr) \
  259. (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  260. raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  261. #endif /* CONFIG_ATARI_ROM_ISA */
  262. #endif /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */
  263. #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA)
  264. #define inb isa_inb
  265. #define inb_p isa_inb_p
  266. #define outb isa_outb
  267. #define outb_p isa_outb_p
  268. #define inw isa_inw
  269. #define inw_p isa_inw_p
  270. #define outw isa_outw
  271. #define outw_p isa_outw_p
  272. #define inl isa_inl
  273. #define inl_p isa_inl_p
  274. #define outl isa_outl
  275. #define outl_p isa_outl_p
  276. #define insb isa_insb
  277. #define insw isa_insw
  278. #define insl isa_insl
  279. #define outsb isa_outsb
  280. #define outsw isa_outsw
  281. #define outsl isa_outsl
  282. #define readb isa_readb
  283. #define readw isa_readw
  284. #define writeb isa_writeb
  285. #define writew isa_writew
  286. #endif /* CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */
  287. #ifdef CONFIG_ATARI_ROM_ISA
  288. /*
  289. * kernel with both ROM port ISA and IDE compiled in, those have
  290. * conflicting defs for in/out. Simply consider port < 1024
  291. * ROM port ISA and everything else regular ISA for IDE. read,write defined
  292. * below.
  293. */
  294. #define inb(port) ((port) < 1024 ? isa_rom_inb(port) : in_8(port))
  295. #define inb_p(port) ((port) < 1024 ? isa_rom_inb_p(port) : in_8(port))
  296. #define inw(port) ((port) < 1024 ? isa_rom_inw(port) : in_le16(port))
  297. #define inw_p(port) ((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port))
  298. #define inl isa_inl
  299. #define inl_p isa_inl_p
  300. #define outb(val, port) ((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val)))
  301. #define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val)))
  302. #define outw(val, port) ((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val)))
  303. #define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val)))
  304. #define outl isa_outl
  305. #define outl_p isa_outl_p
  306. #define insb(port, buf, nr) ((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr)))
  307. #define insw(port, buf, nr) ((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr)))
  308. #define insl isa_insl
  309. #define outsb(port, buf, nr) ((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr)))
  310. #define outsw(port, buf, nr) ((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr)))
  311. #define outsl isa_outsl
  312. #define readb(addr) in_8(addr)
  313. #define writeb(val, addr) out_8((addr), (val))
  314. #define readw(addr) in_le16(addr)
  315. #define writew(val, addr) out_le16((addr), (val))
  316. #endif /* CONFIG_ATARI_ROM_ISA */
  317. #define readl(addr) in_le32(addr)
  318. #define writel(val,addr) out_le32((addr),(val))
  319. #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr))
  320. #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr))
  321. #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr))
  322. #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr))
  323. #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr))
  324. #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr))
  325. #ifndef CONFIG_SUN3
  326. #define IO_SPACE_LIMIT 0xffff
  327. #else
  328. #define IO_SPACE_LIMIT 0x0fffffff
  329. #endif
  330. #endif /* __KERNEL__ */
  331. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  332. /*
  333. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  334. * access
  335. */
  336. #define xlate_dev_mem_ptr(p) __va(p)
  337. #define readb_relaxed(addr) readb(addr)
  338. #define readw_relaxed(addr) readw(addr)
  339. #define readl_relaxed(addr) readl(addr)
  340. #define writeb_relaxed(b, addr) writeb(b, addr)
  341. #define writew_relaxed(b, addr) writew(b, addr)
  342. #define writel_relaxed(b, addr) writel(b, addr)
  343. #endif /* _M68K_IO_MM_H */