io_mm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. #if defined(CONFIG_PCI) && defined(CONFIG_COLDFIRE)
  51. #define HAVE_ARCH_PIO_SIZE
  52. #define PIO_OFFSET 0
  53. #define PIO_MASK 0xffff
  54. #define PIO_RESERVED 0x10000
  55. u8 mcf_pci_inb(u32 addr);
  56. u16 mcf_pci_inw(u32 addr);
  57. u32 mcf_pci_inl(u32 addr);
  58. void mcf_pci_insb(u32 addr, u8 *buf, u32 len);
  59. void mcf_pci_insw(u32 addr, u16 *buf, u32 len);
  60. void mcf_pci_insl(u32 addr, u32 *buf, u32 len);
  61. void mcf_pci_outb(u8 v, u32 addr);
  62. void mcf_pci_outw(u16 v, u32 addr);
  63. void mcf_pci_outl(u32 v, u32 addr);
  64. void mcf_pci_outsb(u32 addr, const u8 *buf, u32 len);
  65. void mcf_pci_outsw(u32 addr, const u16 *buf, u32 len);
  66. void mcf_pci_outsl(u32 addr, const u32 *buf, u32 len);
  67. #define inb mcf_pci_inb
  68. #define inb_p mcf_pci_inb
  69. #define inw mcf_pci_inw
  70. #define inw_p mcf_pci_inw
  71. #define inl mcf_pci_inl
  72. #define inl_p mcf_pci_inl
  73. #define insb mcf_pci_insb
  74. #define insw mcf_pci_insw
  75. #define insl mcf_pci_insl
  76. #define outb mcf_pci_outb
  77. #define outb_p mcf_pci_outb
  78. #define outw mcf_pci_outw
  79. #define outw_p mcf_pci_outw
  80. #define outl mcf_pci_outl
  81. #define outl_p mcf_pci_outl
  82. #define outsb mcf_pci_outsb
  83. #define outsw mcf_pci_outsw
  84. #define outsl mcf_pci_outsl
  85. #define readb(addr) in_8(addr)
  86. #define writeb(v, addr) out_8((addr), (v))
  87. #define readw(addr) in_le16(addr)
  88. #define writew(v, addr) out_le16((addr), (v))
  89. #elif defined(CONFIG_ISA)
  90. #if MULTI_ISA == 0
  91. #undef MULTI_ISA
  92. #endif
  93. #define ISA_TYPE_Q40 (1)
  94. #define ISA_TYPE_AG (2)
  95. #if defined(CONFIG_Q40) && !defined(MULTI_ISA)
  96. #define ISA_TYPE ISA_TYPE_Q40
  97. #define ISA_SEX 0
  98. #endif
  99. #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA)
  100. #define ISA_TYPE ISA_TYPE_AG
  101. #define ISA_SEX 1
  102. #endif
  103. #ifdef MULTI_ISA
  104. extern int isa_type;
  105. extern int isa_sex;
  106. #define ISA_TYPE isa_type
  107. #define ISA_SEX isa_sex
  108. #endif
  109. /*
  110. * define inline addr translation functions. Normally only one variant will
  111. * be compiled in so the case statement will be optimised away
  112. */
  113. static inline u8 __iomem *isa_itb(unsigned long addr)
  114. {
  115. switch(ISA_TYPE)
  116. {
  117. #ifdef CONFIG_Q40
  118. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr);
  119. #endif
  120. #ifdef CONFIG_AMIGA_PCMCIA
  121. case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr);
  122. #endif
  123. default: return NULL; /* avoid warnings, just in case */
  124. }
  125. }
  126. static inline u16 __iomem *isa_itw(unsigned long addr)
  127. {
  128. switch(ISA_TYPE)
  129. {
  130. #ifdef CONFIG_Q40
  131. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr);
  132. #endif
  133. #ifdef CONFIG_AMIGA_PCMCIA
  134. case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr);
  135. #endif
  136. default: return NULL; /* avoid warnings, just in case */
  137. }
  138. }
  139. static inline u32 __iomem *isa_itl(unsigned long addr)
  140. {
  141. switch(ISA_TYPE)
  142. {
  143. #ifdef CONFIG_AMIGA_PCMCIA
  144. case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr);
  145. #endif
  146. default: return 0; /* avoid warnings, just in case */
  147. }
  148. }
  149. static inline u8 __iomem *isa_mtb(unsigned long addr)
  150. {
  151. switch(ISA_TYPE)
  152. {
  153. #ifdef CONFIG_Q40
  154. case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr);
  155. #endif
  156. #ifdef CONFIG_AMIGA_PCMCIA
  157. case ISA_TYPE_AG: return (u8 __iomem *)addr;
  158. #endif
  159. default: return NULL; /* avoid warnings, just in case */
  160. }
  161. }
  162. static inline u16 __iomem *isa_mtw(unsigned long addr)
  163. {
  164. switch(ISA_TYPE)
  165. {
  166. #ifdef CONFIG_Q40
  167. case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr);
  168. #endif
  169. #ifdef CONFIG_AMIGA_PCMCIA
  170. case ISA_TYPE_AG: return (u16 __iomem *)addr;
  171. #endif
  172. default: return NULL; /* avoid warnings, just in case */
  173. }
  174. }
  175. #define isa_inb(port) in_8(isa_itb(port))
  176. #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port)))
  177. #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port)))
  178. #define isa_outb(val,port) out_8(isa_itb(port),(val))
  179. #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val)))
  180. #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val)))
  181. #define isa_readb(p) in_8(isa_mtb((unsigned long)(p)))
  182. #define isa_readw(p) \
  183. (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \
  184. : in_le16(isa_mtw((unsigned long)(p))))
  185. #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val))
  186. #define isa_writew(val,p) \
  187. (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \
  188. : out_le16(isa_mtw((unsigned long)(p)),(val)))
  189. static inline void isa_delay(void)
  190. {
  191. switch(ISA_TYPE)
  192. {
  193. #ifdef CONFIG_Q40
  194. case ISA_TYPE_Q40: isa_outb(0,0x80); break;
  195. #endif
  196. #ifdef CONFIG_AMIGA_PCMCIA
  197. case ISA_TYPE_AG: break;
  198. #endif
  199. default: break; /* avoid warnings */
  200. }
  201. }
  202. #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;})
  203. #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();})
  204. #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;})
  205. #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();})
  206. #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;})
  207. #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();})
  208. #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr))
  209. #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr))
  210. #define isa_insw(port, buf, nr) \
  211. (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \
  212. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  213. #define isa_outsw(port, buf, nr) \
  214. (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \
  215. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)))
  216. #define isa_insl(port, buf, nr) \
  217. (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \
  218. raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  219. #define isa_outsl(port, buf, nr) \
  220. (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \
  221. raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
  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. #else /* CONFIG_ISA */
  245. /*
  246. * We need to define dummy functions for GENERIC_IOMAP support.
  247. */
  248. #define inb(port) 0xff
  249. #define inb_p(port) 0xff
  250. #define outb(val,port) ((void)0)
  251. #define outb_p(val,port) ((void)0)
  252. #define inw(port) 0xffff
  253. #define inw_p(port) 0xffff
  254. #define outw(val,port) ((void)0)
  255. #define outw_p(val,port) ((void)0)
  256. #define inl(port) 0xffffffffUL
  257. #define inl_p(port) 0xffffffffUL
  258. #define outl(val,port) ((void)0)
  259. #define outl_p(val,port) ((void)0)
  260. #define insb(port,buf,nr) ((void)0)
  261. #define outsb(port,buf,nr) ((void)0)
  262. #define insw(port,buf,nr) ((void)0)
  263. #define outsw(port,buf,nr) ((void)0)
  264. #define insl(port,buf,nr) ((void)0)
  265. #define outsl(port,buf,nr) ((void)0)
  266. /*
  267. * These should be valid on any ioremap()ed region
  268. */
  269. #define readb(addr) in_8(addr)
  270. #define writeb(val,addr) out_8((addr),(val))
  271. #define readw(addr) in_le16(addr)
  272. #define writew(val,addr) out_le16((addr),(val))
  273. #endif /* CONFIG_ISA */
  274. #define readl(addr) in_le32(addr)
  275. #define writel(val,addr) out_le32((addr),(val))
  276. #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr))
  277. #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr))
  278. #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr))
  279. #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr))
  280. #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr))
  281. #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr))
  282. #define mmiowb()
  283. static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
  284. {
  285. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  286. }
  287. static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size)
  288. {
  289. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  290. }
  291. static inline void __iomem *ioremap_writethrough(unsigned long physaddr,
  292. unsigned long size)
  293. {
  294. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  295. }
  296. static inline void __iomem *ioremap_fullcache(unsigned long physaddr,
  297. unsigned long size)
  298. {
  299. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  300. }
  301. static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
  302. {
  303. __builtin_memset((void __force *) addr, val, count);
  304. }
  305. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  306. {
  307. __builtin_memcpy(dst, (void __force *) src, count);
  308. }
  309. static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  310. {
  311. __builtin_memcpy((void __force *) dst, src, count);
  312. }
  313. #ifndef CONFIG_SUN3
  314. #define IO_SPACE_LIMIT 0xffff
  315. #else
  316. #define IO_SPACE_LIMIT 0x0fffffff
  317. #endif
  318. #endif /* __KERNEL__ */
  319. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  320. /*
  321. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  322. * access
  323. */
  324. #define xlate_dev_mem_ptr(p) __va(p)
  325. /*
  326. * Convert a virtual cached pointer to an uncached pointer
  327. */
  328. #define xlate_dev_kmem_ptr(p) p
  329. #define ioport_map(port, nr) ((void __iomem *)(port))
  330. #endif /* _IO_H */