io_32.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _ASM_X86_IO_32_H
  2. #define _ASM_X86_IO_32_H
  3. #include <linux/string.h>
  4. #include <linux/compiler.h>
  5. /*
  6. * This file contains the definitions for the x86 IO instructions
  7. * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  8. * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  9. * versions of the single-IO instructions (inb_p/inw_p/..).
  10. *
  11. * This file is not meant to be obfuscating: it's just complicated
  12. * to (a) handle it all in a way that makes gcc able to optimize it
  13. * as well as possible and (b) trying to avoid writing the same thing
  14. * over and over again with slight variations and possibly making a
  15. * mistake somewhere.
  16. */
  17. /*
  18. * Thanks to James van Artsdalen for a better timing-fix than
  19. * the two short jumps: using outb's to a nonexistent port seems
  20. * to guarantee better timings even on fast machines.
  21. *
  22. * On the other hand, I'd like to be sure of a non-existent port:
  23. * I feel a bit unsafe about using 0x80 (should be safe, though)
  24. *
  25. * Linus
  26. */
  27. /*
  28. * Bit simplified and optimized by Jan Hubicka
  29. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
  30. *
  31. * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
  32. * isa_read[wl] and isa_write[wl] fixed
  33. * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  34. */
  35. #ifdef __KERNEL__
  36. #include <asm-generic/iomap.h>
  37. #include <linux/vmalloc.h>
  38. /*
  39. * Convert a virtual cached pointer to an uncached pointer
  40. */
  41. #define xlate_dev_kmem_ptr(p) p
  42. static inline void
  43. memset_io(volatile void __iomem *addr, unsigned char val, int count)
  44. {
  45. memset((void __force *)addr, val, count);
  46. }
  47. static inline void
  48. memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  49. {
  50. __memcpy(dst, (const void __force *)src, count);
  51. }
  52. static inline void
  53. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  54. {
  55. __memcpy((void __force *)dst, src, count);
  56. }
  57. /*
  58. * ISA space is 'always mapped' on a typical x86 system, no need to
  59. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  60. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  61. * are physical addresses. The following constant pointer can be
  62. * used as the IO-area pointer (it can be iounmapped as well, so the
  63. * analogy with PCI is quite large):
  64. */
  65. #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
  66. /*
  67. * Cache management
  68. *
  69. * This needed for two cases
  70. * 1. Out of order aware processors
  71. * 2. Accidentally out of order processors (PPro errata #51)
  72. */
  73. #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
  74. static inline void flush_write_buffers(void)
  75. {
  76. asm volatile("lock; addl $0,0(%%esp)": : :"memory");
  77. }
  78. #else
  79. #define flush_write_buffers() do { } while (0)
  80. #endif
  81. #endif /* __KERNEL__ */
  82. extern void native_io_delay(void);
  83. extern int io_delay_type;
  84. extern void io_delay_init(void);
  85. #if defined(CONFIG_PARAVIRT)
  86. #include <asm/paravirt.h>
  87. #else
  88. static inline void slow_down_io(void)
  89. {
  90. native_io_delay();
  91. #ifdef REALLY_SLOW_IO
  92. native_io_delay();
  93. native_io_delay();
  94. native_io_delay();
  95. #endif
  96. }
  97. #endif
  98. #define __BUILDIO(bwl, bw, type) \
  99. static inline void out##bwl(unsigned type value, int port) \
  100. { \
  101. out##bwl##_local(value, port); \
  102. } \
  103. \
  104. static inline unsigned type in##bwl(int port) \
  105. { \
  106. return in##bwl##_local(port); \
  107. }
  108. #define BUILDIO(bwl, bw, type) \
  109. static inline void out##bwl##_local(unsigned type value, int port) \
  110. { \
  111. asm volatile("out" #bwl " %" #bw "0, %w1" \
  112. : : "a"(value), "Nd"(port)); \
  113. } \
  114. \
  115. static inline unsigned type in##bwl##_local(int port) \
  116. { \
  117. unsigned type value; \
  118. asm volatile("in" #bwl " %w1, %" #bw "0" \
  119. : "=a"(value) : "Nd"(port)); \
  120. return value; \
  121. } \
  122. \
  123. static inline void out##bwl##_local_p(unsigned type value, int port) \
  124. { \
  125. out##bwl##_local(value, port); \
  126. slow_down_io(); \
  127. } \
  128. \
  129. static inline unsigned type in##bwl##_local_p(int port) \
  130. { \
  131. unsigned type value = in##bwl##_local(port); \
  132. slow_down_io(); \
  133. return value; \
  134. } \
  135. \
  136. __BUILDIO(bwl, bw, type) \
  137. \
  138. static inline void out##bwl##_p(unsigned type value, int port) \
  139. { \
  140. out##bwl(value, port); \
  141. slow_down_io(); \
  142. } \
  143. \
  144. static inline unsigned type in##bwl##_p(int port) \
  145. { \
  146. unsigned type value = in##bwl(port); \
  147. slow_down_io(); \
  148. return value; \
  149. } \
  150. \
  151. static inline void outs##bwl(int port, const void *addr, unsigned long count) \
  152. { \
  153. asm volatile("rep; outs" #bwl \
  154. : "+S"(addr), "+c"(count) : "d"(port)); \
  155. } \
  156. \
  157. static inline void ins##bwl(int port, void *addr, unsigned long count) \
  158. { \
  159. asm volatile("rep; ins" #bwl \
  160. : "+D"(addr), "+c"(count) : "d"(port)); \
  161. }
  162. BUILDIO(b, b, char)
  163. BUILDIO(w, w, short)
  164. BUILDIO(l, , int)
  165. #endif /* _ASM_X86_IO_32_H */