io_64.h 4.5 KB

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