io_64.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef _ASM_X86_IO_64_H
  2. #define _ASM_X86_IO_64_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, size_t count)
  44. {
  45. memset((void __force *)addr, val, count);
  46. }
  47. static inline void
  48. memcpy_fromio(void *dst, const volatile void __iomem *src, size_t 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, size_t 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. static inline void flush_write_buffers(void)
  74. {
  75. #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
  76. asm volatile("lock; addl $0,0(%%esp)": : :"memory");
  77. #endif
  78. }
  79. #endif /* __KERNEL__ */
  80. extern void native_io_delay(void);
  81. extern int io_delay_type;
  82. extern void io_delay_init(void);
  83. #if defined(CONFIG_PARAVIRT)
  84. #include <asm/paravirt.h>
  85. #else
  86. static inline void slow_down_io(void)
  87. {
  88. native_io_delay();
  89. #ifdef REALLY_SLOW_IO
  90. native_io_delay();
  91. native_io_delay();
  92. native_io_delay();
  93. #endif
  94. }
  95. #endif
  96. #define BUILDIO(bwl, bw, type) \
  97. static inline void out##bwl(unsigned type value, int port) \
  98. { \
  99. asm volatile("out" #bwl " %" #bw "0, %w1" \
  100. : : "a"(value), "Nd"(port)); \
  101. } \
  102. \
  103. static inline unsigned type in##bwl(int port) \
  104. { \
  105. unsigned type value; \
  106. asm volatile("in" #bwl " %w1, %" #bw "0" \
  107. : "=a"(value) : "Nd"(port)); \
  108. return value; \
  109. } \
  110. \
  111. static inline void out##bwl##_p(unsigned type value, int port) \
  112. { \
  113. out##bwl(value, port); \
  114. slow_down_io(); \
  115. } \
  116. \
  117. static inline unsigned type in##bwl##_p(int port) \
  118. { \
  119. unsigned type value = in##bwl(port); \
  120. slow_down_io(); \
  121. return value; \
  122. } \
  123. \
  124. static inline void outs##bwl(int port, const void *addr, unsigned long count) \
  125. { \
  126. asm volatile("rep; outs" #bwl \
  127. : "+S"(addr), "+c"(count) : "d"(port)); \
  128. } \
  129. \
  130. static inline void ins##bwl(int port, void *addr, unsigned long count) \
  131. { \
  132. asm volatile("rep; ins" #bwl \
  133. : "+D"(addr), "+c"(count) : "d"(port)); \
  134. }
  135. BUILDIO(b, b, char)
  136. BUILDIO(w, w, short)
  137. BUILDIO(l, , int)
  138. #endif /* _ASM_X86_IO_64_H */