import of upstream 2.4.34.4 from kernel.org
[linux-2.4.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-2002 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 /*
115  * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
116  * that the access has completed before executing other I/O accesses.  Since we're doing
117  * the accesses through an uncachable (UC) translation, the CPU will execute them in
118  * program order.  However, we still need to tell the compiler not to shuffle them around
119  * during optimization, which is why we use "volatile" pointers.
120  */
121
122 static inline unsigned int
123 __ia64_inb (unsigned long port)
124 {
125         volatile unsigned char *addr = __ia64_mk_io_addr(port);
126         unsigned char ret;
127
128         ret = *addr;
129         __ia64_mf_a();
130         return ret;
131 }
132
133 static inline unsigned int
134 __ia64_inw (unsigned long port)
135 {
136         volatile unsigned short *addr = __ia64_mk_io_addr(port);
137         unsigned short ret;
138
139         ret = *addr;
140         __ia64_mf_a();
141         return ret;
142 }
143
144 static inline unsigned int
145 __ia64_inl (unsigned long port)
146 {
147         volatile unsigned int *addr = __ia64_mk_io_addr(port);
148         unsigned int ret;
149
150         ret = *addr;
151         __ia64_mf_a();
152         return ret;
153 }
154
155 static inline void
156 __ia64_outb (unsigned char val, unsigned long port)
157 {
158         volatile unsigned char *addr = __ia64_mk_io_addr(port);
159
160         *addr = val;
161         __ia64_mf_a();
162 }
163
164 static inline void
165 __ia64_outw (unsigned short val, unsigned long port)
166 {
167         volatile unsigned short *addr = __ia64_mk_io_addr(port);
168
169         *addr = val;
170         __ia64_mf_a();
171 }
172
173 static inline void
174 __ia64_outl (unsigned int val, unsigned long port)
175 {
176         volatile unsigned int *addr = __ia64_mk_io_addr(port);
177
178         *addr = val;
179         __ia64_mf_a();
180 }
181
182 static inline void
183 __insb (unsigned long port, void *dst, unsigned long count)
184 {
185         unsigned char *dp = dst;
186
187         if (platform_inb == __ia64_inb) {
188                 volatile unsigned char *addr = __ia64_mk_io_addr(port);
189
190                 __ia64_mf_a();
191                 while (count--)
192                         *dp++ = *addr;
193                 __ia64_mf_a();
194         } else
195                 while (count--)
196                         *dp++ = platform_inb(port);
197         return;
198 }
199
200 static inline void
201 __insw (unsigned long port, void *dst, unsigned long count)
202 {
203         unsigned short *dp = dst;
204
205         if (platform_inw == __ia64_inw) {
206                 volatile unsigned short *addr = __ia64_mk_io_addr(port);
207
208                 __ia64_mf_a();
209                 while (count--)
210                         *dp++ = *addr;
211                 __ia64_mf_a();
212         } else
213                 while (count--)
214                         *dp++ = platform_inw(port);
215         return;
216 }
217
218 static inline void
219 __insl (unsigned long port, void *dst, unsigned long count)
220 {
221         unsigned int *dp = dst;
222
223         if (platform_inl == __ia64_inl) {
224                 volatile unsigned int *addr = __ia64_mk_io_addr(port);
225
226                 __ia64_mf_a();
227                 while (count--)
228                         *dp++ = *addr;
229                 __ia64_mf_a();
230         } else
231                 while (count--)
232                         *dp++ = platform_inl(port);
233         return;
234 }
235
236 static inline void
237 __outsb (unsigned long port, const void *src, unsigned long count)
238 {
239         const unsigned char *sp = src;
240
241         if (platform_outb == __ia64_outb) {
242                 volatile unsigned char *addr = __ia64_mk_io_addr(port);
243
244                 while (count--)
245                         *addr = *sp++;
246                 __ia64_mf_a();
247         } else
248                 while (count--)
249                         platform_outb(*sp++, port);
250         return;
251 }
252
253 static inline void
254 __outsw (unsigned long port, const void *src, unsigned long count)
255 {
256         const unsigned short *sp = src;
257
258         if (platform_outw == __ia64_outw) {
259                 volatile unsigned short *addr = __ia64_mk_io_addr(port);
260
261                 while (count--)
262                         *addr = *sp++;
263                 __ia64_mf_a();
264         } else
265                 while (count--)
266                         platform_outw(*sp++, port);
267         return;
268 }
269
270 static inline void
271 __outsl (unsigned long port, void *src, unsigned long count)
272 {
273         const unsigned int *sp = src;
274
275         if (platform_outl == __ia64_outl) {
276                 volatile unsigned int *addr = __ia64_mk_io_addr(port);
277
278                 while (count--)
279                         *addr = *sp++;
280                 __ia64_mf_a();
281         } else
282                 while (count--)
283                         platform_outl(*sp++, port);
284         return;
285 }
286
287 /*
288  * Unfortunately, some platforms are broken and do not follow the IA-64 architecture
289  * specification regarding legacy I/O support.  Thus, we have to make these operations
290  * platform dependent...
291  */
292 #define __inb           platform_inb
293 #define __inw           platform_inw
294 #define __inl           platform_inl
295 #define __outb          platform_outb
296 #define __outw          platform_outw
297 #define __outl          platform_outl
298
299 #define inb(p)          __inb(p)
300 #define inw(p)          __inw(p)
301 #define inl(p)          __inl(p)
302 #define insb(p,d,c)     __insb(p,d,c)
303 #define insw(p,d,c)     __insw(p,d,c)
304 #define insl(p,d,c)     __insl(p,d,c)
305 #define outb(v,p)       __outb(v,p)
306 #define outw(v,p)       __outw(v,p)
307 #define outl(v,p)       __outl(v,p)
308 #define outsb(p,s,c)    __outsb(p,s,c)
309 #define outsw(p,s,c)    __outsw(p,s,c)
310 #define outsl(p,s,c)    __outsl(p,s,c)
311
312 /*
313  * The address passed to these functions are ioremap()ped already.
314  */
315 static inline unsigned char
316 __readb (void *addr)
317 {
318         return *(volatile unsigned char *)addr;
319 }
320
321 static inline unsigned short
322 __readw (void *addr)
323 {
324         return *(volatile unsigned short *)addr;
325 }
326
327 static inline unsigned int
328 __readl (void *addr)
329 {
330         return *(volatile unsigned int *) addr;
331 }
332
333 static inline unsigned long
334 __readq (void *addr)
335 {
336         return *(volatile unsigned long *) addr;
337 }
338
339 static inline void
340 __writeb (unsigned char val, void *addr)
341 {
342         *(volatile unsigned char *) addr = val;
343 }
344
345 static inline void
346 __writew (unsigned short val, void *addr)
347 {
348         *(volatile unsigned short *) addr = val;
349 }
350
351 static inline void
352 __writel (unsigned int val, void *addr)
353 {
354         *(volatile unsigned int *) addr = val;
355 }
356
357 static inline void
358 __writeq (unsigned long val, void *addr)
359 {
360         *(volatile unsigned long *) addr = val;
361 }
362
363 #define readb(a)        __readb((void *)(a))
364 #define readw(a)        __readw((void *)(a))
365 #define readl(a)        __readl((void *)(a))
366 #define readq(a)        __readq((void *)(a))
367 #define __raw_readb     readb
368 #define __raw_readw     readw
369 #define __raw_readl     readl
370 #define __raw_readq     readq
371 #define writeb(v,a)     __writeb((v), (void *) (a))
372 #define writew(v,a)     __writew((v), (void *) (a))
373 #define writel(v,a)     __writel((v), (void *) (a))
374 #define writeq(v,a)     __writeq((v), (void *) (a))
375 #define __raw_writeb    writeb
376 #define __raw_writew    writew
377 #define __raw_writel    writel
378 #define __raw_writeq    writeq
379
380 #ifndef inb_p
381 # define inb_p          inb
382 #endif
383 #ifndef inw_p
384 # define inw_p          inw
385 #endif
386 #ifndef inl_p
387 # define inl_p          inl
388 #endif
389
390 #ifndef outb_p
391 # define outb_p         outb
392 #endif
393 #ifndef outw_p
394 # define outw_p         outw
395 #endif
396 #ifndef outl_p
397 # define outl_p         outl
398 #endif
399
400 /*
401  * An "address" in IO memory space is not clearly either an integer or a pointer. We will
402  * accept both, thus the casts.
403  *
404  * On ia-64, we access the physical I/O memory space through the uncached kernel region.
405  */
406 static inline void *
407 ioremap (unsigned long offset, unsigned long size)
408 {
409         return (void *) (__IA64_UNCACHED_OFFSET | (offset));
410 }
411
412 static inline void
413 iounmap (void *addr)
414 {
415 }
416
417 #define ioremap_nocache(o,s)    ioremap(o,s)
418
419 # ifdef __KERNEL__
420
421 /*
422  * String version of IO memory access ops:
423  */
424 extern void __ia64_memcpy_fromio (void *, unsigned long, long);
425 extern void __ia64_memcpy_toio (unsigned long, void *, long);
426 extern void __ia64_memset_c_io (unsigned long, unsigned long, long);
427
428 #define memcpy_fromio(to,from,len) \
429   __ia64_memcpy_fromio((to),(unsigned long)(from),(len))
430 #define memcpy_toio(to,from,len) \
431   __ia64_memcpy_toio((unsigned long)(to),(from),(len))
432 #define memset_io(addr,c,len) \
433   __ia64_memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
434
435
436 #define dma_cache_inv(_start,_size)             do { } while (0)
437 #define dma_cache_wback(_start,_size)           do { } while (0)
438 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
439
440 # endif /* __KERNEL__ */
441
442 #endif /* _ASM_IA64_IO_H */