This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-x86_64 / mach-xen / asm / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 #include <linux/config.h>
5 #include <asm/fixmap.h>
6
7 /*
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/..).
12  *
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
17  * mistake somewhere.
18  */
19
20 /*
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.
24  *
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)
27  *
28  *              Linus
29  */
30
31  /*
32   *  Bit simplified and optimized by Jan Hubicka
33   *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
34   *
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>
38   */
39
40 #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
41
42 #ifdef REALLY_SLOW_IO
43 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
44 #else
45 #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
46 #endif
47
48 /*
49  * Talk about misusing macros..
50  */
51 #define __OUT1(s,x) \
52 static inline void out##s(unsigned x value, unsigned short port) {
53
54 #define __OUT2(s,s1,s2) \
55 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
56
57 #define __OUT(s,s1,x) \
58 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
59 __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \
60
61 #define __IN1(s) \
62 static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
63
64 #define __IN2(s,s1,s2) \
65 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
66
67 #define __IN(s,s1,i...) \
68 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
69 __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
70
71 #define __INS(s) \
72 static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
73 { __asm__ __volatile__ ("rep ; ins" #s \
74 : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
75
76 #define __OUTS(s) \
77 static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
78 { __asm__ __volatile__ ("rep ; outs" #s \
79 : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
80
81 #define RETURN_TYPE unsigned char
82 __IN(b,"")
83 #undef RETURN_TYPE
84 #define RETURN_TYPE unsigned short
85 __IN(w,"")
86 #undef RETURN_TYPE
87 #define RETURN_TYPE unsigned int
88 __IN(l,"")
89 #undef RETURN_TYPE
90
91 __OUT(b,"b",char)
92 __OUT(w,"w",short)
93 __OUT(l,,int)
94
95 __INS(b)
96 __INS(w)
97 __INS(l)
98
99 __OUTS(b)
100 __OUTS(w)
101 __OUTS(l)
102
103 #define IO_SPACE_LIMIT 0xffff
104
105 #if defined(__KERNEL__) && __x86_64__
106
107 #include <linux/vmalloc.h>
108
109 #ifndef __i386__
110 /*
111  * Change virtual addresses to physical addresses and vv.
112  * These are pretty trivial
113  */
114 static inline unsigned long virt_to_phys(volatile void * address)
115 {
116         return __pa(address);
117 }
118
119 static inline void * phys_to_virt(unsigned long address)
120 {
121         return __va(address);
122 }
123
124 #define virt_to_bus(_x) phys_to_machine(__pa(_x))
125 #define bus_to_virt(_x) __va(machine_to_phys(_x))
126 #endif
127
128 /*
129  * Change "struct page" to physical address.
130  */
131 #define page_to_pseudophys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
132 #define page_to_phys(page)       (phys_to_machine(page_to_pseudophys(page)))
133 #define page_to_bus(page)        (phys_to_machine(page_to_pseudophys(page)))
134
135 #define bio_to_pseudophys(bio)   (page_to_pseudophys(bio_page((bio))) + \
136                                   (unsigned long) bio_offset((bio)))
137 #define bvec_to_pseudophys(bv)   (page_to_pseudophys((bv)->bv_page) + \
138                                   (unsigned long) (bv)->bv_offset)
139
140 #define BIOVEC_PHYS_MERGEABLE(vec1, vec2)       \
141         (((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2))) && \
142          ((bvec_to_pseudophys((vec1)) + (vec1)->bv_len) == \
143           bvec_to_pseudophys((vec2))))
144
145 #include <asm-generic/iomap.h>
146
147 extern void __iomem *__ioremap(unsigned long offset, unsigned long size, unsigned long flags);
148
149 static inline void __iomem * ioremap (unsigned long offset, unsigned long size)
150 {
151         return __ioremap(offset, size, 0);
152 }
153
154 extern void *early_ioremap(unsigned long addr, unsigned long size);
155 extern void early_iounmap(void *addr, unsigned long size);
156
157 /*
158  * This one maps high address device memory and turns off caching for that area.
159  * it's useful if some control registers are in such an area and write combining
160  * or read caching is not desirable:
161  */
162 extern void __iomem * ioremap_nocache (unsigned long offset, unsigned long size);
163 extern void iounmap(volatile void __iomem *addr);
164
165 /*
166  * ISA I/O bus memory addresses are 1:1 with the physical address.
167  */
168
169 #define isa_virt_to_bus(_x) isa_virt_to_bus_is_UNSUPPORTED->x
170 #define isa_page_to_bus(_x) isa_page_to_bus_is_UNSUPPORTED->x
171 #define isa_bus_to_virt(_x) (void *)(__fix_to_virt(FIX_ISAMAP_BEGIN) + (_x))
172
173 /*
174  * However PCI ones are not necessarily 1:1 and therefore these interfaces
175  * are forbidden in portable PCI drivers.
176  *
177  * Allow them on x86 for legacy drivers, though.
178  */
179 #define virt_to_bus(_x) phys_to_machine(__pa(_x))
180 #define bus_to_virt(_x) __va(machine_to_phys(_x))
181
182 /*
183  * readX/writeX() are used to access memory mapped devices. On some
184  * architectures the memory mapped IO stuff needs to be accessed
185  * differently. On the x86 architecture, we just read/write the
186  * memory location directly.
187  */
188
189 static inline __u8 __readb(const volatile void __iomem *addr)
190 {
191         return *(__force volatile __u8 *)addr;
192 }
193 static inline __u16 __readw(const volatile void __iomem *addr)
194 {
195         return *(__force volatile __u16 *)addr;
196 }
197 static __always_inline __u32 __readl(const volatile void __iomem *addr)
198 {
199         return *(__force volatile __u32 *)addr;
200 }
201 static inline __u64 __readq(const volatile void __iomem *addr)
202 {
203         return *(__force volatile __u64 *)addr;
204 }
205 #define readb(x) __readb(x)
206 #define readw(x) __readw(x)
207 #define readl(x) __readl(x)
208 #define readq(x) __readq(x)
209 #define readb_relaxed(a) readb(a)
210 #define readw_relaxed(a) readw(a)
211 #define readl_relaxed(a) readl(a)
212 #define readq_relaxed(a) readq(a)
213 #define __raw_readb readb
214 #define __raw_readw readw
215 #define __raw_readl readl
216 #define __raw_readq readq
217
218 #define mmiowb()
219
220 static inline void __writel(__u32 b, volatile void __iomem *addr)
221 {
222         *(__force volatile __u32 *)addr = b;
223 }
224 static inline void __writeq(__u64 b, volatile void __iomem *addr)
225 {
226         *(__force volatile __u64 *)addr = b;
227 }
228 static inline void __writeb(__u8 b, volatile void __iomem *addr)
229 {
230         *(__force volatile __u8 *)addr = b;
231 }
232 static inline void __writew(__u16 b, volatile void __iomem *addr)
233 {
234         *(__force volatile __u16 *)addr = b;
235 }
236 #define writeq(val,addr) __writeq((val),(addr))
237 #define writel(val,addr) __writel((val),(addr))
238 #define writew(val,addr) __writew((val),(addr))
239 #define writeb(val,addr) __writeb((val),(addr))
240 #define __raw_writeb writeb
241 #define __raw_writew writew
242 #define __raw_writel writel
243 #define __raw_writeq writeq
244
245 void __memcpy_fromio(void*,unsigned long,unsigned);
246 void __memcpy_toio(unsigned long,const void*,unsigned);
247
248 static inline void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned len)
249 {
250         __memcpy_fromio(to,(unsigned long)from,len);
251 }
252 static inline void memcpy_toio(volatile void __iomem *to, const void *from, unsigned len)
253 {
254         __memcpy_toio((unsigned long)to,from,len);
255 }
256
257 void memset_io(volatile void __iomem *a, int b, size_t c);
258
259 /*
260  * ISA space is 'always mapped' on a typical x86 system, no need to
261  * explicitly ioremap() it. The fact that the ISA IO space is mapped
262  * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
263  * are physical addresses. The following constant pointer can be
264  * used as the IO-area pointer (it can be iounmapped as well, so the
265  * analogy with PCI is quite large):
266  */
267 #define __ISA_IO_base ((char __iomem *)(fix_to_virt(FIX_ISAMAP_BEGIN)))
268
269 /*
270  * Again, x86-64 does not require mem IO specific function.
271  */
272
273 #define eth_io_copy_and_sum(a,b,c,d)            eth_copy_and_sum((a),(void *)(b),(c),(d))
274
275 /**
276  *      check_signature         -       find BIOS signatures
277  *      @io_addr: mmio address to check 
278  *      @signature:  signature block
279  *      @length: length of signature
280  *
281  *      Perform a signature comparison with the mmio address io_addr. This
282  *      address should have been obtained by ioremap.
283  *      Returns 1 on a match.
284  */
285  
286 static inline int check_signature(void __iomem *io_addr,
287         const unsigned char *signature, int length)
288 {
289         int retval = 0;
290         do {
291                 if (readb(io_addr) != *signature)
292                         goto out;
293                 io_addr++;
294                 signature++;
295                 length--;
296         } while (length);
297         retval = 1;
298 out:
299         return retval;
300 }
301
302 /* Nothing to do */
303
304 #define dma_cache_inv(_start,_size)             do { } while (0)
305 #define dma_cache_wback(_start,_size)           do { } while (0)
306 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
307
308 #define flush_write_buffers() 
309
310 extern int iommu_bio_merge;
311 #define BIO_VMERGE_BOUNDARY iommu_bio_merge
312
313 /*
314  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
315  * access
316  */
317 #define xlate_dev_mem_ptr(p)    __va(p)
318
319 /*
320  * Convert a virtual cached pointer to an uncached pointer
321  */
322 #define xlate_dev_kmem_ptr(p)   p
323
324 #endif /* __KERNEL__ */
325
326 #define ARCH_HAS_DEV_MEM
327
328 #endif