io_32.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /**
  45. * virt_to_phys - map virtual addresses to physical
  46. * @address: address to remap
  47. *
  48. * The returned physical address is the physical (CPU) mapping for
  49. * the memory address given. It is only valid to use this function on
  50. * addresses directly mapped or allocated via kmalloc.
  51. *
  52. * This function does not give bus mappings for DMA transfers. In
  53. * almost all conceivable cases a device driver should not be using
  54. * this function
  55. */
  56. static inline unsigned long virt_to_phys(volatile void *address)
  57. {
  58. return __pa(address);
  59. }
  60. /**
  61. * phys_to_virt - map physical address to virtual
  62. * @address: address to remap
  63. *
  64. * The returned virtual address is a current CPU mapping for
  65. * the memory address given. It is only valid to use this function on
  66. * addresses that have a kernel mapping
  67. *
  68. * This function does not handle bus mappings for DMA transfers. In
  69. * almost all conceivable cases a device driver should not be using
  70. * this function
  71. */
  72. static inline void *phys_to_virt(unsigned long address)
  73. {
  74. return __va(address);
  75. }
  76. /*
  77. * Change "struct page" to physical address.
  78. */
  79. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  80. /**
  81. * ioremap - map bus memory into CPU space
  82. * @offset: bus address of the memory
  83. * @size: size of the resource to map
  84. *
  85. * ioremap performs a platform specific sequence of operations to
  86. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  87. * writew/writel functions and the other mmio helpers. The returned
  88. * address is not guaranteed to be usable directly as a virtual
  89. * address.
  90. *
  91. * If the area you are trying to map is a PCI BAR you should have a
  92. * look at pci_iomap().
  93. */
  94. extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
  95. extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
  96. extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
  97. unsigned long prot_val);
  98. /*
  99. * The default ioremap() behavior is non-cached:
  100. */
  101. static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
  102. {
  103. return ioremap_nocache(offset, size);
  104. }
  105. extern void iounmap(volatile void __iomem *addr);
  106. /*
  107. * ISA I/O bus memory addresses are 1:1 with the physical address.
  108. */
  109. #define isa_virt_to_bus virt_to_phys
  110. #define isa_page_to_bus page_to_phys
  111. #define isa_bus_to_virt phys_to_virt
  112. /*
  113. * However PCI ones are not necessarily 1:1 and therefore these interfaces
  114. * are forbidden in portable PCI drivers.
  115. *
  116. * Allow them on x86 for legacy drivers, though.
  117. */
  118. #define virt_to_bus virt_to_phys
  119. #define bus_to_virt phys_to_virt
  120. static inline void
  121. memset_io(volatile void __iomem *addr, unsigned char val, int count)
  122. {
  123. memset((void __force *)addr, val, count);
  124. }
  125. static inline void
  126. memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
  127. {
  128. __memcpy(dst, (const void __force *)src, count);
  129. }
  130. static inline void
  131. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  132. {
  133. __memcpy((void __force *)dst, src, count);
  134. }
  135. /*
  136. * ISA space is 'always mapped' on a typical x86 system, no need to
  137. * explicitly ioremap() it. The fact that the ISA IO space is mapped
  138. * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
  139. * are physical addresses. The following constant pointer can be
  140. * used as the IO-area pointer (it can be iounmapped as well, so the
  141. * analogy with PCI is quite large):
  142. */
  143. #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
  144. /*
  145. * Cache management
  146. *
  147. * This needed for two cases
  148. * 1. Out of order aware processors
  149. * 2. Accidentally out of order processors (PPro errata #51)
  150. */
  151. #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
  152. static inline void flush_write_buffers(void)
  153. {
  154. asm volatile("lock; addl $0,0(%%esp)": : :"memory");
  155. }
  156. #else
  157. #define flush_write_buffers() do { } while (0)
  158. #endif
  159. #endif /* __KERNEL__ */
  160. extern void native_io_delay(void);
  161. extern int io_delay_type;
  162. extern void io_delay_init(void);
  163. #if defined(CONFIG_PARAVIRT)
  164. #include <asm/paravirt.h>
  165. #else
  166. static inline void slow_down_io(void)
  167. {
  168. native_io_delay();
  169. #ifdef REALLY_SLOW_IO
  170. native_io_delay();
  171. native_io_delay();
  172. native_io_delay();
  173. #endif
  174. }
  175. #endif
  176. #define __BUILDIO(bwl, bw, type) \
  177. static inline void out##bwl(unsigned type value, int port) \
  178. { \
  179. out##bwl##_local(value, port); \
  180. } \
  181. \
  182. static inline unsigned type in##bwl(int port) \
  183. { \
  184. return in##bwl##_local(port); \
  185. }
  186. #define BUILDIO(bwl, bw, type) \
  187. static inline void out##bwl##_local(unsigned type value, int port) \
  188. { \
  189. asm volatile("out" #bwl " %" #bw "0, %w1" \
  190. : : "a"(value), "Nd"(port)); \
  191. } \
  192. \
  193. static inline unsigned type in##bwl##_local(int port) \
  194. { \
  195. unsigned type value; \
  196. asm volatile("in" #bwl " %w1, %" #bw "0" \
  197. : "=a"(value) : "Nd"(port)); \
  198. return value; \
  199. } \
  200. \
  201. static inline void out##bwl##_local_p(unsigned type value, int port) \
  202. { \
  203. out##bwl##_local(value, port); \
  204. slow_down_io(); \
  205. } \
  206. \
  207. static inline unsigned type in##bwl##_local_p(int port) \
  208. { \
  209. unsigned type value = in##bwl##_local(port); \
  210. slow_down_io(); \
  211. return value; \
  212. } \
  213. \
  214. __BUILDIO(bwl, bw, type) \
  215. \
  216. static inline void out##bwl##_p(unsigned type value, int port) \
  217. { \
  218. out##bwl(value, port); \
  219. slow_down_io(); \
  220. } \
  221. \
  222. static inline unsigned type in##bwl##_p(int port) \
  223. { \
  224. unsigned type value = in##bwl(port); \
  225. slow_down_io(); \
  226. return value; \
  227. } \
  228. \
  229. static inline void outs##bwl(int port, const void *addr, unsigned long count) \
  230. { \
  231. asm volatile("rep; outs" #bwl \
  232. : "+S"(addr), "+c"(count) : "d"(port)); \
  233. } \
  234. \
  235. static inline void ins##bwl(int port, void *addr, unsigned long count) \
  236. { \
  237. asm volatile("rep; ins" #bwl \
  238. : "+D"(addr), "+c"(count) : "d"(port)); \
  239. }
  240. BUILDIO(b, b, char)
  241. BUILDIO(w, w, short)
  242. BUILDIO(l, , int)
  243. #endif /* _ASM_X86_IO_32_H */