io_32.h 5.0 KB

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