io.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #ifndef _ASM_IO_H
  2. #define _ASM_IO_H
  3. #include <compiler.h>
  4. /*
  5. * This file contains the definitions for the x86 IO instructions
  6. * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  7. * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  8. * versions of the single-IO instructions (inb_p/inw_p/..).
  9. *
  10. * This file is not meant to be obfuscating: it's just complicated
  11. * to (a) handle it all in a way that makes gcc able to optimize it
  12. * as well as possible and (b) trying to avoid writing the same thing
  13. * over and over again with slight variations and possibly making a
  14. * mistake somewhere.
  15. */
  16. /*
  17. * Thanks to James van Artsdalen for a better timing-fix than
  18. * the two short jumps: using outb's to a nonexistent port seems
  19. * to guarantee better timings even on fast machines.
  20. *
  21. * On the other hand, I'd like to be sure of a non-existent port:
  22. * I feel a bit unsafe about using 0x80 (should be safe, though)
  23. *
  24. * Linus
  25. */
  26. /*
  27. * Bit simplified and optimized by Jan Hubicka
  28. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
  29. *
  30. * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
  31. * isa_read[wl] and isa_write[wl] fixed
  32. * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  33. */
  34. #define IO_SPACE_LIMIT 0xffff
  35. #include <asm/types.h>
  36. #ifdef __KERNEL__
  37. /*
  38. * readX/writeX() are used to access memory mapped devices. On some
  39. * architectures the memory mapped IO stuff needs to be accessed
  40. * differently. On the x86 architecture, we just read/write the
  41. * memory location directly.
  42. */
  43. #define readb(addr) (*(volatile unsigned char *) (addr))
  44. #define readw(addr) (*(volatile unsigned short *) (addr))
  45. #define readl(addr) (*(volatile unsigned int *) (addr))
  46. #define __raw_readb readb
  47. #define __raw_readw readw
  48. #define __raw_readl readl
  49. #define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
  50. #define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
  51. #define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
  52. #define __raw_writeb writeb
  53. #define __raw_writew writew
  54. #define __raw_writel writel
  55. #define memset_io(a,b,c) memset((a),(b),(c))
  56. #define memcpy_fromio(a,b,c) memcpy((a),(b),(c))
  57. #define memcpy_toio(a,b,c) memcpy((a),(b),(c))
  58. /*
  59. * ISA space is 'always mapped' on a typical x86 system, no need to
  60. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  61. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  62. * are physical addresses. The following constant pointer can be
  63. * used as the IO-area pointer (it can be iounmapped as well, so the
  64. * analogy with PCI is quite large):
  65. */
  66. #define isa_readb(a) readb((a))
  67. #define isa_readw(a) readw((a))
  68. #define isa_readl(a) readl((a))
  69. #define isa_writeb(b,a) writeb(b,(a))
  70. #define isa_writew(w,a) writew(w,(a))
  71. #define isa_writel(l,a) writel(l,(a))
  72. #define isa_memset_io(a,b,c) memset_io((a),(b),(c))
  73. #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c))
  74. #define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c))
  75. static inline int check_signature(unsigned long io_addr,
  76. const unsigned char *signature, int length)
  77. {
  78. int retval = 0;
  79. do {
  80. if (readb(io_addr) != *signature)
  81. goto out;
  82. io_addr++;
  83. signature++;
  84. length--;
  85. } while (length);
  86. retval = 1;
  87. out:
  88. return retval;
  89. }
  90. /**
  91. * isa_check_signature - find BIOS signatures
  92. * @io_addr: mmio address to check
  93. * @signature: signature block
  94. * @length: length of signature
  95. *
  96. * Perform a signature comparison with the ISA mmio address io_addr.
  97. * Returns 1 on a match.
  98. *
  99. * This function is deprecated. New drivers should use ioremap and
  100. * check_signature.
  101. */
  102. static inline int isa_check_signature(unsigned long io_addr,
  103. const unsigned char *signature, int length)
  104. {
  105. int retval = 0;
  106. do {
  107. if (isa_readb(io_addr) != *signature)
  108. goto out;
  109. io_addr++;
  110. signature++;
  111. length--;
  112. } while (length);
  113. retval = 1;
  114. out:
  115. return retval;
  116. }
  117. #endif /* __KERNEL__ */
  118. #ifdef SLOW_IO_BY_JUMPING
  119. #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
  120. #else
  121. #define __SLOW_DOWN_IO "\noutb %%al,$0xed"
  122. #endif
  123. #ifdef REALLY_SLOW_IO
  124. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
  125. #else
  126. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
  127. #endif
  128. /*
  129. * Talk about misusing macros..
  130. */
  131. #define __OUT1(s,x) \
  132. static inline void out##s(unsigned x value, unsigned short port) {
  133. #define __OUT2(s,s1,s2) \
  134. __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
  135. #define __OUT(s,s1,x) \
  136. __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
  137. __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
  138. #define __IN1(s) \
  139. static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
  140. #define __IN2(s,s1,s2) \
  141. __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
  142. #define __IN(s,s1,i...) \
  143. __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
  144. __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
  145. #define __INS(s) \
  146. static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
  147. { __asm__ __volatile__ ("rep ; ins" #s \
  148. : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  149. #define __OUTS(s) \
  150. static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
  151. { __asm__ __volatile__ ("rep ; outs" #s \
  152. : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  153. #define RETURN_TYPE unsigned char
  154. __IN(b,"")
  155. #undef RETURN_TYPE
  156. #define RETURN_TYPE unsigned short
  157. __IN(w,"")
  158. #undef RETURN_TYPE
  159. #define RETURN_TYPE unsigned int
  160. __IN(l,"")
  161. #undef RETURN_TYPE
  162. __OUT(b,"b",char)
  163. __OUT(w,"w",short)
  164. __OUT(l,,int)
  165. __INS(b)
  166. __INS(w)
  167. __INS(l)
  168. __OUTS(b)
  169. __OUTS(w)
  170. __OUTS(l)
  171. static inline void sync(void)
  172. {
  173. }
  174. /*
  175. * Given a physical address and a length, return a virtual address
  176. * that can be used to access the memory range with the caching
  177. * properties specified by "flags".
  178. */
  179. #define MAP_NOCACHE (0)
  180. #define MAP_WRCOMBINE (0)
  181. #define MAP_WRBACK (0)
  182. #define MAP_WRTHROUGH (0)
  183. static inline void *
  184. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  185. {
  186. return (void *)(uintptr_t)paddr;
  187. }
  188. /*
  189. * Take down a mapping set up by map_physmem().
  190. */
  191. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  192. {
  193. }
  194. static inline phys_addr_t virt_to_phys(void * vaddr)
  195. {
  196. return (phys_addr_t)(uintptr_t)(vaddr);
  197. }
  198. /*
  199. * TODO: The kernel offers some more advanced versions of barriers, it might
  200. * have some advantages to use them instead of the simple one here.
  201. */
  202. #define dmb() __asm__ __volatile__ ("" : : : "memory")
  203. #define __iormb() dmb()
  204. #define __iowmb() dmb()
  205. #endif