io_64.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef _ASM_X86_IO_64_H
  2. #define _ASM_X86_IO_64_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. #ifdef __KERNEL__
  34. #include <asm-generic/iomap.h>
  35. #include <linux/vmalloc.h>
  36. /*
  37. * Convert a virtual cached pointer to an uncached pointer
  38. */
  39. #define xlate_dev_kmem_ptr(p) p
  40. void memset_io(volatile void __iomem *a, int b, size_t c);
  41. void __memcpy_fromio(void *, unsigned long, unsigned);
  42. static inline void memcpy_fromio(void *to, const volatile void __iomem *from,
  43. unsigned len)
  44. {
  45. __memcpy_fromio(to, (unsigned long)from, len);
  46. }
  47. void __memcpy_toio(unsigned long, const void *, unsigned);
  48. static inline void memcpy_toio(volatile void __iomem *to, const void *from,
  49. unsigned len)
  50. {
  51. __memcpy_toio((unsigned long)to, from, len);
  52. }
  53. /*
  54. * ISA space is 'always mapped' on a typical x86 system, no need to
  55. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  56. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  57. * are physical addresses. The following constant pointer can be
  58. * used as the IO-area pointer (it can be iounmapped as well, so the
  59. * analogy with PCI is quite large):
  60. */
  61. #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
  62. /*
  63. * Cache management
  64. *
  65. * This needed for two cases
  66. * 1. Out of order aware processors
  67. * 2. Accidentally out of order processors (PPro errata #51)
  68. */
  69. #define flush_write_buffers() do { } while (0)
  70. #endif /* __KERNEL__ */
  71. extern void native_io_delay(void);
  72. extern int io_delay_type;
  73. extern void io_delay_init(void);
  74. #if defined(CONFIG_PARAVIRT)
  75. #include <asm/paravirt.h>
  76. #else
  77. static inline void slow_down_io(void)
  78. {
  79. native_io_delay();
  80. #ifdef REALLY_SLOW_IO
  81. native_io_delay();
  82. native_io_delay();
  83. native_io_delay();
  84. #endif
  85. }
  86. #endif
  87. /*
  88. * Talk about misusing macros..
  89. */
  90. #define __OUT1(s, x) \
  91. static inline void out##s(unsigned x value, unsigned short port) {
  92. #define __OUT2(s, s1, s2) \
  93. asm volatile ("out" #s " %" s1 "0,%" s2 "1"
  94. #ifndef REALLY_SLOW_IO
  95. #define REALLY_SLOW_IO
  96. #define UNSET_REALLY_SLOW_IO
  97. #endif
  98. #define __OUT(s, s1, x) \
  99. __OUT1(s, x) __OUT2(s, s1, "w") : : "a" (value), "Nd" (port)); \
  100. } \
  101. __OUT1(s##_p, x) __OUT2(s, s1, "w") : : "a" (value), "Nd" (port)); \
  102. slow_down_io(); \
  103. }
  104. #define __IN1(s) \
  105. static inline RETURN_TYPE in##s(unsigned short port) \
  106. { \
  107. RETURN_TYPE _v;
  108. #define __IN2(s, s1, s2) \
  109. asm volatile ("in" #s " %" s2 "1,%" s1 "0"
  110. #define __IN(s, s1, i...) \
  111. __IN1(s) __IN2(s, s1, "w") : "=a" (_v) : "Nd" (port), ##i); \
  112. return _v; \
  113. } \
  114. __IN1(s##_p) __IN2(s, s1, "w") : "=a" (_v) : "Nd" (port), ##i); \
  115. slow_down_io(); \
  116. return _v; }
  117. #ifdef UNSET_REALLY_SLOW_IO
  118. #undef REALLY_SLOW_IO
  119. #endif
  120. #define __INS(s) \
  121. static inline void ins##s(unsigned short port, void *addr, \
  122. unsigned long count) \
  123. { \
  124. asm volatile ("rep ; ins" #s \
  125. : "=D" (addr), "=c" (count) \
  126. : "d" (port), "0" (addr), "1" (count)); \
  127. }
  128. #define __OUTS(s) \
  129. static inline void outs##s(unsigned short port, const void *addr, \
  130. unsigned long count) \
  131. { \
  132. asm volatile ("rep ; outs" #s \
  133. : "=S" (addr), "=c" (count) \
  134. : "d" (port), "0" (addr), "1" (count)); \
  135. }
  136. #define RETURN_TYPE unsigned char
  137. __IN(b, "")
  138. #undef RETURN_TYPE
  139. #define RETURN_TYPE unsigned short
  140. __IN(w, "")
  141. #undef RETURN_TYPE
  142. #define RETURN_TYPE unsigned int
  143. __IN(l, "")
  144. #undef RETURN_TYPE
  145. __OUT(b, "b", char)
  146. __OUT(w, "w", short)
  147. __OUT(l, , int)
  148. __INS(b)
  149. __INS(w)
  150. __INS(l)
  151. __OUTS(b)
  152. __OUTS(w)
  153. __OUTS(l)
  154. #endif /* _ASM_X86_IO_64_H */