- Separate out show_stack changes into own patch.
[linux-flexiantxendom0-3.2.10.git] / include / asm-ia64 / io.h
1 #ifndef _ASM_IA64_IO_H
2 #define _ASM_IA64_IO_H
3
4 /*
5  * This file contains the definitions for the emulated IO instructions
6  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
7  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
8  * versions of the single-IO instructions (inb_p/inw_p/..).
9  *
10  * This file is not meant to be obfuscating: it's just complicated to
11  * (a) handle it all in a way that makes gcc able to optimize it as
12  * well as possible and (b) trying to avoid writing the same thing
13  * over and over again with slight variations and possibly making a
14  * mistake somewhere.
15  *
16  * Copyright (C) 1998-2003 Hewlett-Packard Co
17  *      David Mosberger-Tang <davidm@hpl.hp.com>
18  * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
19  * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
20  */
21
22 /* We don't use IO slowdowns on the ia64, but.. */
23 #define __SLOW_DOWN_IO  do { } while (0)
24 #define SLOW_DOWN_IO    do { } while (0)
25
26 #define __IA64_UNCACHED_OFFSET  0xc000000000000000      /* region 6 */
27
28 /*
29  * The legacy I/O space defined by the ia64 architecture supports only 65536 ports, but
30  * large machines may have multiple other I/O spaces so we can't place any a priori limit
31  * on IO_SPACE_LIMIT.  These additional spaces are described in ACPI.
32  */
33 #define IO_SPACE_LIMIT          0xffffffffffffffffUL
34
35 #define MAX_IO_SPACES                   16
36 #define IO_SPACE_BITS                   24
37 #define IO_SPACE_SIZE                   (1UL << IO_SPACE_BITS)
38
39 #define IO_SPACE_NR(port)               ((port) >> IO_SPACE_BITS)
40 #define IO_SPACE_BASE(space)            ((space) << IO_SPACE_BITS)
41 #define IO_SPACE_PORT(port)             ((port) & (IO_SPACE_SIZE - 1))
42
43 #define IO_SPACE_SPARSE_ENCODING(p)     ((((p) >> 2) << 12) | (p & 0xfff))
44
45 struct io_space {
46         unsigned long mmio_base;        /* base in MMIO space */
47         int sparse;
48 };
49
50 extern struct io_space io_space[];
51 extern unsigned int num_io_spaces;
52
53 # ifdef __KERNEL__
54
55 #include <asm/machvec.h>
56 #include <asm/page.h>
57 #include <asm/system.h>
58
59 /*
60  * Change virtual addresses to physical addresses and vv.
61  */
62 static inline unsigned long
63 virt_to_phys (volatile void *address)
64 {
65         return (unsigned long) address - PAGE_OFFSET;
66 }
67
68 static inline void*
69 phys_to_virt (unsigned long address)
70 {
71         return (void *) (address + PAGE_OFFSET);
72 }
73
74 /*
75  * The following two macros are deprecated and scheduled for removal.
76  * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
77  */
78 #define bus_to_virt     phys_to_virt
79 #define virt_to_bus     virt_to_phys
80 #define page_to_bus     page_to_phys
81
82 # endif /* KERNEL */
83
84 /*
85  * Memory fence w/accept.  This should never be used in code that is
86  * not IA-64 specific.
87  */
88 #define __ia64_mf_a()   __asm__ __volatile__ ("mf.a" ::: "memory")
89
90 static inline const unsigned long
91 __ia64_get_io_port_base (void)
92 {
93         extern unsigned long ia64_iobase;
94
95         return ia64_iobase;
96 }
97
98 static inline void*
99 __ia64_mk_io_addr (unsigned long port)
100 {
101         struct io_space *space;
102         unsigned long offset;
103
104         space = &io_space[IO_SPACE_NR(port)];
105         port = IO_SPACE_PORT(port);
106         if (space->sparse)
107                 offset = IO_SPACE_SPARSE_ENCODING(port);
108         else
109                 offset = port;
110
111         return (void *) (space->mmio_base | offset);
112 }
113
114 #define __ia64_inb      ___ia64_inb
115 #define __ia64_inw      ___ia64_inw
116 #define __ia64_inl      ___ia64_inl
117 #define __ia64_outb     ___ia64_outb
118 #define __ia64_outw     ___ia64_outw
119 #define __ia64_outl     ___ia64_outl
120 #define __ia64_readb    ___ia64_readb
121 #define __ia64_readw    ___ia64_readw
122 #define __ia64_readl    ___ia64_readl
123 #define __ia64_readq    ___ia64_readq
124 #define __ia64_writeb   ___ia64_writeb
125 #define __ia64_writew   ___ia64_writew
126 #define __ia64_writel   ___ia64_writel
127 #define __ia64_writeq   ___ia64_writeq
128
129 /*
130  * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
131  * that the access has completed before executing other I/O accesses.  Since we're doing
132  * the accesses through an uncachable (UC) translation, the CPU will execute them in
133  * program order.  However, we still need to tell the compiler not to shuffle them around
134  * during optimization, which is why we use "volatile" pointers.
135  */
136
137 static inline unsigned int
138 ___ia64_inb (unsigned long port)
139 {
140         volatile unsigned char *addr = __ia64_mk_io_addr(port);
141         unsigned char ret;
142
143         ret = *addr;
144         __ia64_mf_a();
145         return ret;
146 }
147
148 static inline unsigned int
149 ___ia64_inw (unsigned long port)
150 {
151         volatile unsigned short *addr = __ia64_mk_io_addr(port);
152         unsigned short ret;
153
154         ret = *addr;
155         __ia64_mf_a();
156         return ret;
157 }
158
159 static inline unsigned int
160 ___ia64_inl (unsigned long port)
161 {
162         volatile unsigned int *addr = __ia64_mk_io_addr(port);
163         unsigned int ret;
164
165         ret = *addr;
166         __ia64_mf_a();
167         return ret;
168 }
169
170 static inline void
171 ___ia64_outb (unsigned char val, unsigned long port)
172 {
173         volatile unsigned char *addr = __ia64_mk_io_addr(port);
174
175         *addr = val;
176         __ia64_mf_a();
177 }
178
179 static inline void
180 ___ia64_outw (unsigned short val, unsigned long port)
181 {
182         volatile unsigned short *addr = __ia64_mk_io_addr(port);
183
184         *addr = val;
185         __ia64_mf_a();
186 }
187
188 static inline void
189 ___ia64_outl (unsigned int val, unsigned long port)
190 {
191         volatile unsigned int *addr = __ia64_mk_io_addr(port);
192
193         *addr = val;
194         __ia64_mf_a();
195 }
196
197 static inline void
198 __insb (unsigned long port, void *dst, unsigned long count)
199 {
200         unsigned char *dp = dst;
201
202         while (count--)
203                 *dp++ = platform_inb(port);
204 }
205
206 static inline void
207 __insw (unsigned long port, void *dst, unsigned long count)
208 {
209         unsigned short *dp = dst;
210
211         while (count--)
212                 *dp++ = platform_inw(port);
213 }
214
215 static inline void
216 __insl (unsigned long port, void *dst, unsigned long count)
217 {
218         unsigned int *dp = dst;
219
220         while (count--)
221                 *dp++ = platform_inl(port);
222 }
223
224 static inline void
225 __outsb (unsigned long port, const void *src, unsigned long count)
226 {
227         const unsigned char *sp = src;
228
229         while (count--)
230                 platform_outb(*sp++, port);
231 }
232
233 static inline void
234 __outsw (unsigned long port, const void *src, unsigned long count)
235 {
236         const unsigned short *sp = src;
237
238         while (count--)
239                 platform_outw(*sp++, port);
240 }
241
242 static inline void
243 __outsl (unsigned long port, void *src, unsigned long count)
244 {
245         const unsigned int *sp = src;
246
247         while (count--)
248                 platform_outl(*sp++, port);
249 }
250
251 /*
252  * Unfortunately, some platforms are broken and do not follow the IA-64 architecture
253  * specification regarding legacy I/O support.  Thus, we have to make these operations
254  * platform dependent...
255  */
256 #define __inb           platform_inb
257 #define __inw           platform_inw
258 #define __inl           platform_inl
259 #define __outb          platform_outb
260 #define __outw          platform_outw
261 #define __outl          platform_outl
262
263 #define inb(p)          __inb(p)
264 #define inw(p)          __inw(p)
265 #define inl(p)          __inl(p)
266 #define insb(p,d,c)     __insb(p,d,c)
267 #define insw(p,d,c)     __insw(p,d,c)
268 #define insl(p,d,c)     __insl(p,d,c)
269 #define outb(v,p)       __outb(v,p)
270 #define outw(v,p)       __outw(v,p)
271 #define outl(v,p)       __outl(v,p)
272 #define outsb(p,s,c)    __outsb(p,s,c)
273 #define outsw(p,s,c)    __outsw(p,s,c)
274 #define outsl(p,s,c)    __outsl(p,s,c)
275
276 /*
277  * The address passed to these functions are ioremap()ped already.
278  *
279  * We need these to be machine vectors since some platforms don't provide
280  * DMA coherence via PIO reads (PCI drivers and the spec imply that this is
281  * a good idea).  Writes are ok though for all existing ia64 platforms (and
282  * hopefully it'll stay that way).
283  */
284 static inline unsigned char
285 ___ia64_readb (void *addr)
286 {
287         return *(volatile unsigned char *)addr;
288 }
289
290 static inline unsigned short
291 ___ia64_readw (void *addr)
292 {
293         return *(volatile unsigned short *)addr;
294 }
295
296 static inline unsigned int
297 ___ia64_readl (void *addr)
298 {
299         return *(volatile unsigned int *) addr;
300 }
301
302 static inline unsigned long
303 ___ia64_readq (void *addr)
304 {
305         return *(volatile unsigned long *) addr;
306 }
307
308 static inline void
309 __writeb (unsigned char val, void *addr)
310 {
311         *(volatile unsigned char *) addr = val;
312 }
313
314 static inline void
315 __writew (unsigned short val, void *addr)
316 {
317         *(volatile unsigned short *) addr = val;
318 }
319
320 static inline void
321 __writel (unsigned int val, void *addr)
322 {
323         *(volatile unsigned int *) addr = val;
324 }
325
326 static inline void
327 __writeq (unsigned long val, void *addr)
328 {
329         *(volatile unsigned long *) addr = val;
330 }
331
332 #define __readb         platform_readb
333 #define __readw         platform_readw
334 #define __readl         platform_readl
335 #define __readq         platform_readq
336
337 #define readb(a)        __readb((void *)(a))
338 #define readw(a)        __readw((void *)(a))
339 #define readl(a)        __readl((void *)(a))
340 #define readq(a)        __readq((void *)(a))
341 #define __raw_readb     readb
342 #define __raw_readw     readw
343 #define __raw_readl     readl
344 #define __raw_readq     readq
345 #define writeb(v,a)     __writeb((v), (void *) (a))
346 #define writew(v,a)     __writew((v), (void *) (a))
347 #define writel(v,a)     __writel((v), (void *) (a))
348 #define writeq(v,a)     __writeq((v), (void *) (a))
349 #define __raw_writeb    writeb
350 #define __raw_writew    writew
351 #define __raw_writel    writel
352 #define __raw_writeq    writeq
353
354 #ifndef inb_p
355 # define inb_p          inb
356 #endif
357 #ifndef inw_p
358 # define inw_p          inw
359 #endif
360 #ifndef inl_p
361 # define inl_p          inl
362 #endif
363
364 #ifndef outb_p
365 # define outb_p         outb
366 #endif
367 #ifndef outw_p
368 # define outw_p         outw
369 #endif
370 #ifndef outl_p
371 # define outl_p         outl
372 #endif
373
374 /*
375  * An "address" in IO memory space is not clearly either an integer or a pointer. We will
376  * accept both, thus the casts.
377  *
378  * On ia-64, we access the physical I/O memory space through the uncached kernel region.
379  */
380 static inline void *
381 ioremap (unsigned long offset, unsigned long size)
382 {
383         return (void *) (__IA64_UNCACHED_OFFSET | (offset));
384 }
385
386 static inline void
387 iounmap (void *addr)
388 {
389 }
390
391 #define ioremap_nocache(o,s)    ioremap(o,s)
392
393 # ifdef __KERNEL__
394
395 /*
396  * String version of IO memory access ops:
397  */
398 extern void __ia64_memcpy_fromio (void *, unsigned long, long);
399 extern void __ia64_memcpy_toio (unsigned long, void *, long);
400 extern void __ia64_memset_c_io (unsigned long, unsigned long, long);
401
402 #define memcpy_fromio(to,from,len) \
403   __ia64_memcpy_fromio((to),(unsigned long)(from),(len))
404 #define memcpy_toio(to,from,len) \
405   __ia64_memcpy_toio((unsigned long)(to),(from),(len))
406 #define memset_io(addr,c,len) \
407   __ia64_memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
408
409
410 #define dma_cache_inv(_start,_size)             do { } while (0)
411 #define dma_cache_wback(_start,_size)           do { } while (0)
412 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
413
414 # endif /* __KERNEL__ */
415
416 #endif /* _ASM_IA64_IO_H */