io_64.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. #define IO_SPACE_LIMIT 0xffff
  117. #if defined(__KERNEL__) && defined(__x86_64__)
  118. #include <linux/vmalloc.h>
  119. #ifndef __i386__
  120. /*
  121. * Change virtual addresses to physical addresses and vv.
  122. * These are pretty trivial
  123. */
  124. static inline unsigned long virt_to_phys(volatile void *address)
  125. {
  126. return __pa(address);
  127. }
  128. static inline void *phys_to_virt(unsigned long address)
  129. {
  130. return __va(address);
  131. }
  132. #endif
  133. /*
  134. * Change "struct page" to physical address.
  135. */
  136. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  137. #include <asm-generic/iomap.h>
  138. extern void *early_ioremap(unsigned long addr, unsigned long size);
  139. extern void early_iounmap(void *addr, unsigned long size);
  140. /*
  141. * This one maps high address device memory and turns off caching for that area.
  142. * it's useful if some control registers are in such an area and write combining
  143. * or read caching is not desirable:
  144. */
  145. extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
  146. extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
  147. extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
  148. unsigned long prot_val);
  149. /*
  150. * The default ioremap() behavior is non-cached:
  151. */
  152. static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
  153. {
  154. return ioremap_nocache(offset, size);
  155. }
  156. extern void iounmap(volatile void __iomem *addr);
  157. extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
  158. /*
  159. * ISA I/O bus memory addresses are 1:1 with the physical address.
  160. */
  161. #define isa_virt_to_bus virt_to_phys
  162. #define isa_page_to_bus page_to_phys
  163. #define isa_bus_to_virt phys_to_virt
  164. /*
  165. * However PCI ones are not necessarily 1:1 and therefore these interfaces
  166. * are forbidden in portable PCI drivers.
  167. *
  168. * Allow them on x86 for legacy drivers, though.
  169. */
  170. #define virt_to_bus virt_to_phys
  171. #define bus_to_virt phys_to_virt
  172. void __memcpy_fromio(void *, unsigned long, unsigned);
  173. void __memcpy_toio(unsigned long, const void *, unsigned);
  174. static inline void memcpy_fromio(void *to, const volatile void __iomem *from,
  175. unsigned len)
  176. {
  177. __memcpy_fromio(to, (unsigned long)from, len);
  178. }
  179. static inline void memcpy_toio(volatile void __iomem *to, const void *from,
  180. unsigned len)
  181. {
  182. __memcpy_toio((unsigned long)to, from, len);
  183. }
  184. void memset_io(volatile void __iomem *a, int b, size_t c);
  185. /*
  186. * ISA space is 'always mapped' on a typical x86 system, no need to
  187. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  188. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  189. * are physical addresses. The following constant pointer can be
  190. * used as the IO-area pointer (it can be iounmapped as well, so the
  191. * analogy with PCI is quite large):
  192. */
  193. #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
  194. #define flush_write_buffers()
  195. #define BIO_VMERGE_BOUNDARY iommu_bio_merge
  196. /*
  197. * Convert a virtual cached pointer to an uncached pointer
  198. */
  199. #define xlate_dev_kmem_ptr(p) p
  200. #endif /* __KERNEL__ */
  201. #endif /* ASM_X86__IO_64_H */