io_32.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #define IO_SPACE_LIMIT 0xffff
  36. #define XQUAD_PORTIO_BASE 0xfe400000
  37. #define XQUAD_PORTIO_QUAD 0x40000 /* 256k per quad. */
  38. #ifdef __KERNEL__
  39. #include <asm-generic/iomap.h>
  40. #include <linux/vmalloc.h>
  41. /*
  42. * Convert a virtual cached pointer to an uncached pointer
  43. */
  44. #define xlate_dev_kmem_ptr(p) p
  45. static inline void
  46. memset_io(volatile void __iomem *addr, unsigned char val, int count)
  47. {
  48. memset((void __force *)addr, val, count);
  49. }
  50. static inline void
  51. memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  52. {
  53. __memcpy(dst, (const void __force *)src, count);
  54. }
  55. static inline void
  56. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  57. {
  58. __memcpy((void __force *)dst, src, count);
  59. }
  60. /*
  61. * ISA space is 'always mapped' on a typical x86 system, no need to
  62. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  63. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  64. * are physical addresses. The following constant pointer can be
  65. * used as the IO-area pointer (it can be iounmapped as well, so the
  66. * analogy with PCI is quite large):
  67. */
  68. #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
  69. /*
  70. * Cache management
  71. *
  72. * This needed for two cases
  73. * 1. Out of order aware processors
  74. * 2. Accidentally out of order processors (PPro errata #51)
  75. */
  76. #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
  77. static inline void flush_write_buffers(void)
  78. {
  79. asm volatile("lock; addl $0,0(%%esp)": : :"memory");
  80. }
  81. #else
  82. #define flush_write_buffers() do { } while (0)
  83. #endif
  84. #endif /* __KERNEL__ */
  85. extern void native_io_delay(void);
  86. extern int io_delay_type;
  87. extern void io_delay_init(void);
  88. #if defined(CONFIG_PARAVIRT)
  89. #include <asm/paravirt.h>
  90. #else
  91. static inline void slow_down_io(void)
  92. {
  93. native_io_delay();
  94. #ifdef REALLY_SLOW_IO
  95. native_io_delay();
  96. native_io_delay();
  97. native_io_delay();
  98. #endif
  99. }
  100. #endif
  101. #define __BUILDIO(bwl, bw, type) \
  102. static inline void out##bwl(unsigned type value, int port) \
  103. { \
  104. out##bwl##_local(value, port); \
  105. } \
  106. \
  107. static inline unsigned type in##bwl(int port) \
  108. { \
  109. return in##bwl##_local(port); \
  110. }
  111. #define BUILDIO(bwl, bw, type) \
  112. static inline void out##bwl##_local(unsigned type value, int port) \
  113. { \
  114. asm volatile("out" #bwl " %" #bw "0, %w1" \
  115. : : "a"(value), "Nd"(port)); \
  116. } \
  117. \
  118. static inline unsigned type in##bwl##_local(int port) \
  119. { \
  120. unsigned type value; \
  121. asm volatile("in" #bwl " %w1, %" #bw "0" \
  122. : "=a"(value) : "Nd"(port)); \
  123. return value; \
  124. } \
  125. \
  126. static inline void out##bwl##_local_p(unsigned type value, int port) \
  127. { \
  128. out##bwl##_local(value, port); \
  129. slow_down_io(); \
  130. } \
  131. \
  132. static inline unsigned type in##bwl##_local_p(int port) \
  133. { \
  134. unsigned type value = in##bwl##_local(port); \
  135. slow_down_io(); \
  136. return value; \
  137. } \
  138. \
  139. __BUILDIO(bwl, bw, type) \
  140. \
  141. static inline void out##bwl##_p(unsigned type value, int port) \
  142. { \
  143. out##bwl(value, port); \
  144. slow_down_io(); \
  145. } \
  146. \
  147. static inline unsigned type in##bwl##_p(int port) \
  148. { \
  149. unsigned type value = in##bwl(port); \
  150. slow_down_io(); \
  151. return value; \
  152. } \
  153. \
  154. static inline void outs##bwl(int port, const void *addr, unsigned long count) \
  155. { \
  156. asm volatile("rep; outs" #bwl \
  157. : "+S"(addr), "+c"(count) : "d"(port)); \
  158. } \
  159. \
  160. static inline void ins##bwl(int port, void *addr, unsigned long count) \
  161. { \
  162. asm volatile("rep; ins" #bwl \
  163. : "+D"(addr), "+c"(count) : "d"(port)); \
  164. }
  165. BUILDIO(b, b, char)
  166. BUILDIO(w, w, short)
  167. BUILDIO(l, , int)
  168. #endif /* _ASM_X86_IO_32_H */