io.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #ifndef __ASM_SH_IO_H
  2. #define __ASM_SH_IO_H
  3. /*
  4. * Convention:
  5. * read{b,w,l}/write{b,w,l} are for PCI,
  6. * while in{b,w,l}/out{b,w,l} are for ISA
  7. * These may (will) be platform specific function.
  8. * In addition we have 'pausing' versions: in{b,w,l}_p/out{b,w,l}_p
  9. * and 'string' versions: ins{b,w,l}/outs{b,w,l}
  10. * For read{b,w,l} and write{b,w,l} there are also __raw versions, which
  11. * do not have a memory barrier after them.
  12. *
  13. * In addition, we have
  14. * ctrl_in{b,w,l}/ctrl_out{b,w,l} for SuperH specific I/O.
  15. * which are processor specific.
  16. */
  17. /*
  18. * We follow the Alpha convention here:
  19. * __inb expands to an inline function call (which calls via the mv)
  20. * _inb is a real function call (note ___raw fns are _ version of __raw)
  21. * inb by default expands to _inb, but the machine specific code may
  22. * define it to __inb if it chooses.
  23. */
  24. #include <asm/cache.h>
  25. #include <asm/system.h>
  26. #include <asm/addrspace.h>
  27. #include <asm/machvec.h>
  28. #include <linux/config.h>
  29. /*
  30. * Depending on which platform we are running on, we need different
  31. * I/O functions.
  32. */
  33. #ifdef __KERNEL__
  34. /*
  35. * Since boards are able to define their own set of I/O routines through
  36. * their respective machine vector, we always wrap through the mv.
  37. *
  38. * Also, in the event that a board hasn't provided its own definition for
  39. * a given routine, it will be wrapped to generic code at run-time.
  40. */
  41. # define __inb(p) sh_mv.mv_inb((p))
  42. # define __inw(p) sh_mv.mv_inw((p))
  43. # define __inl(p) sh_mv.mv_inl((p))
  44. # define __outb(x,p) sh_mv.mv_outb((x),(p))
  45. # define __outw(x,p) sh_mv.mv_outw((x),(p))
  46. # define __outl(x,p) sh_mv.mv_outl((x),(p))
  47. # define __inb_p(p) sh_mv.mv_inb_p((p))
  48. # define __inw_p(p) sh_mv.mv_inw_p((p))
  49. # define __inl_p(p) sh_mv.mv_inl_p((p))
  50. # define __outb_p(x,p) sh_mv.mv_outb_p((x),(p))
  51. # define __outw_p(x,p) sh_mv.mv_outw_p((x),(p))
  52. # define __outl_p(x,p) sh_mv.mv_outl_p((x),(p))
  53. # define __insb(p,b,c) sh_mv.mv_insb((p), (b), (c))
  54. # define __insw(p,b,c) sh_mv.mv_insw((p), (b), (c))
  55. # define __insl(p,b,c) sh_mv.mv_insl((p), (b), (c))
  56. # define __outsb(p,b,c) sh_mv.mv_outsb((p), (b), (c))
  57. # define __outsw(p,b,c) sh_mv.mv_outsw((p), (b), (c))
  58. # define __outsl(p,b,c) sh_mv.mv_outsl((p), (b), (c))
  59. # define __readb(a) sh_mv.mv_readb((a))
  60. # define __readw(a) sh_mv.mv_readw((a))
  61. # define __readl(a) sh_mv.mv_readl((a))
  62. # define __writeb(v,a) sh_mv.mv_writeb((v),(a))
  63. # define __writew(v,a) sh_mv.mv_writew((v),(a))
  64. # define __writel(v,a) sh_mv.mv_writel((v),(a))
  65. # define __ioremap(a,s) sh_mv.mv_ioremap((a), (s))
  66. # define __iounmap(a) sh_mv.mv_iounmap((a))
  67. # define __isa_port2addr(a) sh_mv.mv_isa_port2addr(a)
  68. # define inb __inb
  69. # define inw __inw
  70. # define inl __inl
  71. # define outb __outb
  72. # define outw __outw
  73. # define outl __outl
  74. # define inb_p __inb_p
  75. # define inw_p __inw_p
  76. # define inl_p __inl_p
  77. # define outb_p __outb_p
  78. # define outw_p __outw_p
  79. # define outl_p __outl_p
  80. # define insb __insb
  81. # define insw __insw
  82. # define insl __insl
  83. # define outsb __outsb
  84. # define outsw __outsw
  85. # define outsl __outsl
  86. # define __raw_readb __readb
  87. # define __raw_readw __readw
  88. # define __raw_readl __readl
  89. # define __raw_writeb __writeb
  90. # define __raw_writew __writew
  91. # define __raw_writel __writel
  92. /*
  93. * The platform header files may define some of these macros to use
  94. * the inlined versions where appropriate. These macros may also be
  95. * redefined by userlevel programs.
  96. */
  97. #ifdef __raw_readb
  98. # define readb(a) ({ unsigned long r_ = __raw_readb((unsigned long)a); mb(); r_; })
  99. #endif
  100. #ifdef __raw_readw
  101. # define readw(a) ({ unsigned long r_ = __raw_readw((unsigned long)a); mb(); r_; })
  102. #endif
  103. #ifdef __raw_readl
  104. # define readl(a) ({ unsigned long r_ = __raw_readl((unsigned long)a); mb(); r_; })
  105. #endif
  106. #ifdef __raw_writeb
  107. # define writeb(v,a) ({ __raw_writeb((v),(unsigned long)(a)); mb(); })
  108. #endif
  109. #ifdef __raw_writew
  110. # define writew(v,a) ({ __raw_writew((v),(unsigned long)(a)); mb(); })
  111. #endif
  112. #ifdef __raw_writel
  113. # define writel(v,a) ({ __raw_writel((v),(unsigned long)(a)); mb(); })
  114. #endif
  115. #define readb_relaxed(a) readb(a)
  116. #define readw_relaxed(a) readw(a)
  117. #define readl_relaxed(a) readl(a)
  118. #define mmiowb()
  119. /*
  120. * If the platform has PC-like I/O, this function converts the offset into
  121. * an address.
  122. */
  123. static __inline__ unsigned long isa_port2addr(unsigned long offset)
  124. {
  125. return __isa_port2addr(offset);
  126. }
  127. /*
  128. * This function provides a method for the generic case where a board-specific
  129. * isa_port2addr simply needs to return the port + some arbitrary port base.
  130. *
  131. * We use this at board setup time to implicitly set the port base, and
  132. * as a result, we can use the generic isa_port2addr.
  133. */
  134. static inline void __set_io_port_base(unsigned long pbase)
  135. {
  136. extern unsigned long generic_io_base;
  137. generic_io_base = pbase;
  138. }
  139. #define isa_readb(a) readb(isa_port2addr(a))
  140. #define isa_readw(a) readw(isa_port2addr(a))
  141. #define isa_readl(a) readl(isa_port2addr(a))
  142. #define isa_writeb(b,a) writeb(b,isa_port2addr(a))
  143. #define isa_writew(w,a) writew(w,isa_port2addr(a))
  144. #define isa_writel(l,a) writel(l,isa_port2addr(a))
  145. #define isa_memset_io(a,b,c) \
  146. memset((void *)(isa_port2addr((unsigned long)a)),(b),(c))
  147. #define isa_memcpy_fromio(a,b,c) \
  148. memcpy((a),(void *)(isa_port2addr((unsigned long)(b))),(c))
  149. #define isa_memcpy_toio(a,b,c) \
  150. memcpy((void *)(isa_port2addr((unsigned long)(a))),(b),(c))
  151. /* We really want to try and get these to memcpy etc */
  152. extern void memcpy_fromio(void *, unsigned long, unsigned long);
  153. extern void memcpy_toio(unsigned long, const void *, unsigned long);
  154. extern void memset_io(unsigned long, int, unsigned long);
  155. /* SuperH on-chip I/O functions */
  156. static __inline__ unsigned char ctrl_inb(unsigned long addr)
  157. {
  158. return *(volatile unsigned char*)addr;
  159. }
  160. static __inline__ unsigned short ctrl_inw(unsigned long addr)
  161. {
  162. return *(volatile unsigned short*)addr;
  163. }
  164. static __inline__ unsigned int ctrl_inl(unsigned long addr)
  165. {
  166. return *(volatile unsigned long*)addr;
  167. }
  168. static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
  169. {
  170. *(volatile unsigned char*)addr = b;
  171. }
  172. static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
  173. {
  174. *(volatile unsigned short*)addr = b;
  175. }
  176. static __inline__ void ctrl_outl(unsigned int b, unsigned long addr)
  177. {
  178. *(volatile unsigned long*)addr = b;
  179. }
  180. #define IO_SPACE_LIMIT 0xffffffff
  181. /*
  182. * Change virtual addresses to physical addresses and vv.
  183. * These are trivial on the 1:1 Linux/SuperH mapping
  184. */
  185. static __inline__ unsigned long virt_to_phys(volatile void * address)
  186. {
  187. return PHYSADDR(address);
  188. }
  189. static __inline__ void * phys_to_virt(unsigned long address)
  190. {
  191. return (void *)P1SEGADDR(address);
  192. }
  193. #define virt_to_bus virt_to_phys
  194. #define bus_to_virt phys_to_virt
  195. #define page_to_bus page_to_phys
  196. /*
  197. * readX/writeX() are used to access memory mapped devices. On some
  198. * architectures the memory mapped IO stuff needs to be accessed
  199. * differently. On the x86 architecture, we just read/write the
  200. * memory location directly.
  201. *
  202. * On SH, we have the whole physical address space mapped at all times
  203. * (as MIPS does), so "ioremap()" and "iounmap()" do not need to do
  204. * anything. (This isn't true for all machines but we still handle
  205. * these cases with wired TLB entries anyway ...)
  206. *
  207. * We cheat a bit and always return uncachable areas until we've fixed
  208. * the drivers to handle caching properly.
  209. */
  210. static __inline__ void * ioremap(unsigned long offset, unsigned long size)
  211. {
  212. return __ioremap(offset, size);
  213. }
  214. static __inline__ void iounmap(void *addr)
  215. {
  216. return __iounmap(addr);
  217. }
  218. #define ioremap_nocache(off,size) ioremap(off,size)
  219. static __inline__ int check_signature(unsigned long io_addr,
  220. const unsigned char *signature, int length)
  221. {
  222. int retval = 0;
  223. do {
  224. if (readb(io_addr) != *signature)
  225. goto out;
  226. io_addr++;
  227. signature++;
  228. length--;
  229. } while (length);
  230. retval = 1;
  231. out:
  232. return retval;
  233. }
  234. /*
  235. * The caches on some architectures aren't dma-coherent and have need to
  236. * handle this in software. There are three types of operations that
  237. * can be applied to dma buffers.
  238. *
  239. * - dma_cache_wback_inv(start, size) makes caches and RAM coherent by
  240. * writing the content of the caches back to memory, if necessary.
  241. * The function also invalidates the affected part of the caches as
  242. * necessary before DMA transfers from outside to memory.
  243. * - dma_cache_inv(start, size) invalidates the affected parts of the
  244. * caches. Dirty lines of the caches may be written back or simply
  245. * be discarded. This operation is necessary before dma operations
  246. * to the memory.
  247. * - dma_cache_wback(start, size) writes back any dirty lines but does
  248. * not invalidate the cache. This can be used before DMA reads from
  249. * memory,
  250. */
  251. #define dma_cache_wback_inv(_start,_size) \
  252. __flush_purge_region(_start,_size)
  253. #define dma_cache_inv(_start,_size) \
  254. __flush_invalidate_region(_start,_size)
  255. #define dma_cache_wback(_start,_size) \
  256. __flush_wback_region(_start,_size)
  257. /*
  258. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  259. * access
  260. */
  261. #define xlate_dev_mem_ptr(p) __va(p)
  262. /*
  263. * Convert a virtual cached pointer to an uncached pointer
  264. */
  265. #define xlate_dev_kmem_ptr(p) p
  266. #endif /* __KERNEL__ */
  267. #endif /* __ASM_SH_IO_H */