io.h 6.1 KB

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