4 #include <linux/string.h>
5 #include <linux/compiler.h>
8 * This file contains the definitions for the x86 IO instructions
9 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
10 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
11 * versions of the single-IO instructions (inb_p/inw_p/..).
13 * This file is not meant to be obfuscating: it's just complicated
14 * to (a) handle it all in a way that makes gcc able to optimize it
15 * as well as possible and (b) trying to avoid writing the same thing
16 * over and over again with slight variations and possibly making a
21 * Thanks to James van Artsdalen for a better timing-fix than
22 * the two short jumps: using outb's to a nonexistent port seems
23 * to guarantee better timings even on fast machines.
25 * On the other hand, I'd like to be sure of a non-existent port:
26 * I feel a bit unsafe about using 0x80 (should be safe, though)
32 * Bit simplified and optimized by Jan Hubicka
33 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
35 * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
36 * isa_read[wl] and isa_write[wl] fixed
37 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
40 #define IO_SPACE_LIMIT 0xffff
42 #define XQUAD_PORTIO_BASE 0xfe400000
43 #define XQUAD_PORTIO_QUAD 0x40000 /* 256k per quad. */
47 #include <asm-generic/iomap.h>
49 #include <linux/vmalloc.h>
52 * Convert a virtual cached pointer to an uncached pointer
54 #define xlate_dev_kmem_ptr(p) p
57 * virt_to_phys - map virtual addresses to physical
58 * @address: address to remap
60 * The returned physical address is the physical (CPU) mapping for
61 * the memory address given. It is only valid to use this function on
62 * addresses directly mapped or allocated via kmalloc.
64 * This function does not give bus mappings for DMA transfers. In
65 * almost all conceivable cases a device driver should not be using
69 static inline unsigned long virt_to_phys(volatile void *address)
75 * phys_to_virt - map physical address to virtual
76 * @address: address to remap
78 * The returned virtual address is a current CPU mapping for
79 * the memory address given. It is only valid to use this function on
80 * addresses that have a kernel mapping
82 * This function does not handle bus mappings for DMA transfers. In
83 * almost all conceivable cases a device driver should not be using
87 static inline void *phys_to_virt(unsigned long address)
93 * Change "struct page" to physical address.
95 #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
98 * ioremap - map bus memory into CPU space
99 * @offset: bus address of the memory
100 * @size: size of the resource to map
102 * ioremap performs a platform specific sequence of operations to
103 * make bus memory CPU accessible via the readb/readw/readl/writeb/
104 * writew/writel functions and the other mmio helpers. The returned
105 * address is not guaranteed to be usable directly as a virtual
108 * If the area you are trying to map is a PCI BAR you should have a
109 * look at pci_iomap().
111 extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
112 extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
115 * The default ioremap() behavior is non-cached:
117 static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
119 return ioremap_nocache(offset, size);
122 extern void iounmap(volatile void __iomem *addr);
125 * ISA I/O bus memory addresses are 1:1 with the physical address.
127 #define isa_virt_to_bus virt_to_phys
128 #define isa_page_to_bus page_to_phys
129 #define isa_bus_to_virt phys_to_virt
132 * However PCI ones are not necessarily 1:1 and therefore these interfaces
133 * are forbidden in portable PCI drivers.
135 * Allow them on x86 for legacy drivers, though.
137 #define virt_to_bus virt_to_phys
138 #define bus_to_virt phys_to_virt
141 memset_io(volatile void __iomem *addr, unsigned char val, int count)
143 memset((void __force *)addr, val, count);
147 memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
149 __memcpy(dst, (const void __force *)src, count);
153 memcpy_toio(volatile void __iomem *dst, const void *src, int count)
155 __memcpy((void __force *)dst, src, count);
159 * ISA space is 'always mapped' on a typical x86 system, no need to
160 * explicitly ioremap() it. The fact that the ISA IO space is mapped
161 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
162 * are physical addresses. The following constant pointer can be
163 * used as the IO-area pointer (it can be iounmapped as well, so the
164 * analogy with PCI is quite large):
166 #define __ISA_IO_base ((char __iomem *)(PAGE_OFFSET))
171 * This needed for two cases
172 * 1. Out of order aware processors
173 * 2. Accidentally out of order processors (PPro errata #51)
176 #if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE)
178 static inline void flush_write_buffers(void)
180 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
185 #define flush_write_buffers() do { } while (0)
189 #endif /* __KERNEL__ */
191 extern void native_io_delay(void);
193 extern int io_delay_type;
194 extern void io_delay_init(void);
196 #if defined(CONFIG_PARAVIRT)
197 #include <asm/paravirt.h>
200 static inline void slow_down_io(void)
203 #ifdef REALLY_SLOW_IO
212 #define __BUILDIO(bwl, bw, type) \
213 static inline void out##bwl(unsigned type value, int port) \
215 out##bwl##_local(value, port); \
218 static inline unsigned type in##bwl(int port) \
220 return in##bwl##_local(port); \
223 #define BUILDIO(bwl, bw, type) \
224 static inline void out##bwl##_local(unsigned type value, int port) \
226 asm volatile("out" #bwl " %" #bw "0, %w1" \
227 : : "a"(value), "Nd"(port)); \
230 static inline unsigned type in##bwl##_local(int port) \
232 unsigned type value; \
233 asm volatile("in" #bwl " %w1, %" #bw "0" \
234 : "=a"(value) : "Nd"(port)); \
238 static inline void out##bwl##_local_p(unsigned type value, int port) \
240 out##bwl##_local(value, port); \
244 static inline unsigned type in##bwl##_local_p(int port) \
246 unsigned type value = in##bwl##_local(port); \
251 __BUILDIO(bwl, bw, type) \
253 static inline void out##bwl##_p(unsigned type value, int port) \
255 out##bwl(value, port); \
259 static inline unsigned type in##bwl##_p(int port) \
261 unsigned type value = in##bwl(port); \
266 static inline void outs##bwl(int port, const void *addr, unsigned long count) \
268 asm volatile("rep; outs" #bwl \
269 : "+S"(addr), "+c"(count) : "d"(port)); \
272 static inline void ins##bwl(int port, void *addr, unsigned long count) \
274 asm volatile("rep; ins" #bwl \
275 : "+D"(addr), "+c"(count) : "d"(port)); \