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/..).
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
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>
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)
26 #define __IA64_UNCACHED_OFFSET 0xc000000000000000 /* region 6 */
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.
33 #define IO_SPACE_LIMIT 0xffffffffffffffffUL
37 #include <asm/machvec.h>
39 #include <asm/system.h>
42 * Change virtual addresses to physical addresses and vv.
44 static inline unsigned long
45 virt_to_phys (volatile void *address)
47 return (unsigned long) address - PAGE_OFFSET;
51 phys_to_virt (unsigned long address)
53 return (void *) (address + PAGE_OFFSET);
57 * The following two macros are deprecated and scheduled for removal.
58 * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
60 #define bus_to_virt phys_to_virt
61 #define virt_to_bus virt_to_phys
62 #define page_to_bus page_to_phys
67 * Memory fence w/accept. This should never be used in code that is
70 #define __ia64_mf_a() __asm__ __volatile__ ("mf.a" ::: "memory")
72 static inline const unsigned long
73 __ia64_get_io_port_base (void)
75 extern unsigned long ia64_iobase;
81 __ia64_mk_io_addr (unsigned long port)
83 const unsigned long io_base = __ia64_get_io_port_base();
86 addr = io_base | ((port >> 2) << 12) | (port & 0xfff);
91 * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
92 * that the access has completed before executing other I/O accesses. Since we're doing
93 * the accesses through an uncachable (UC) translation, the CPU will execute them in
94 * program order. However, we still need to tell the compiler not to shuffle them around
95 * during optimization, which is why we use "volatile" pointers.
98 static inline unsigned int
99 __ia64_inb (unsigned long port)
101 volatile unsigned char *addr = __ia64_mk_io_addr(port);
109 static inline unsigned int
110 __ia64_inw (unsigned long port)
112 volatile unsigned short *addr = __ia64_mk_io_addr(port);
120 static inline unsigned int
121 __ia64_inl (unsigned long port)
123 volatile unsigned int *addr = __ia64_mk_io_addr(port);
132 __ia64_outb (unsigned char val, unsigned long port)
134 volatile unsigned char *addr = __ia64_mk_io_addr(port);
141 __ia64_outw (unsigned short val, unsigned long port)
143 volatile unsigned short *addr = __ia64_mk_io_addr(port);
150 __ia64_outl (unsigned int val, unsigned long port)
152 volatile unsigned int *addr = __ia64_mk_io_addr(port);
159 __insb (unsigned long port, void *dst, unsigned long count)
161 unsigned char *dp = dst;
163 if (platform_inb == __ia64_inb) {
164 volatile unsigned char *addr = __ia64_mk_io_addr(port);
172 *dp++ = platform_inb(port);
177 __insw (unsigned long port, void *dst, unsigned long count)
179 unsigned short *dp = dst;
181 if (platform_inw == __ia64_inw) {
182 volatile unsigned short *addr = __ia64_mk_io_addr(port);
190 *dp++ = platform_inw(port);
195 __insl (unsigned long port, void *dst, unsigned long count)
197 unsigned int *dp = dst;
199 if (platform_inl == __ia64_inl) {
200 volatile unsigned int *addr = __ia64_mk_io_addr(port);
208 *dp++ = platform_inl(port);
213 __outsb (unsigned long port, const void *src, unsigned long count)
215 const unsigned char *sp = src;
217 if (platform_outb == __ia64_outb) {
218 volatile unsigned char *addr = __ia64_mk_io_addr(port);
225 platform_outb(*sp++, port);
230 __outsw (unsigned long port, const void *src, unsigned long count)
232 const unsigned short *sp = src;
234 if (platform_outw == __ia64_outw) {
235 volatile unsigned short *addr = __ia64_mk_io_addr(port);
242 platform_outw(*sp++, port);
247 __outsl (unsigned long port, void *src, unsigned long count)
249 const unsigned int *sp = src;
251 if (platform_outl == __ia64_outl) {
252 volatile unsigned int *addr = __ia64_mk_io_addr(port);
259 platform_outl(*sp++, port);
264 * Unfortunately, some platforms are broken and do not follow the IA-64 architecture
265 * specification regarding legacy I/O support. Thus, we have to make these operations
266 * platform dependent...
268 #define __inb platform_inb
269 #define __inw platform_inw
270 #define __inl platform_inl
271 #define __outb platform_outb
272 #define __outw platform_outw
273 #define __outl platform_outl
275 #define inb(p) __inb(p)
276 #define inw(p) __inw(p)
277 #define inl(p) __inl(p)
278 #define insb(p,d,c) __insb(p,d,c)
279 #define insw(p,d,c) __insw(p,d,c)
280 #define insl(p,d,c) __insl(p,d,c)
281 #define outb(v,p) __outb(v,p)
282 #define outw(v,p) __outw(v,p)
283 #define outl(v,p) __outl(v,p)
284 #define outsb(p,s,c) __outsb(p,s,c)
285 #define outsw(p,s,c) __outsw(p,s,c)
286 #define outsl(p,s,c) __outsl(p,s,c)
289 * The address passed to these functions are ioremap()ped already.
291 static inline unsigned char
294 return *(volatile unsigned char *)addr;
297 static inline unsigned short
300 return *(volatile unsigned short *)addr;
303 static inline unsigned int
306 return *(volatile unsigned int *) addr;
309 static inline unsigned long
312 return *(volatile unsigned long *) addr;
316 __writeb (unsigned char val, void *addr)
318 *(volatile unsigned char *) addr = val;
322 __writew (unsigned short val, void *addr)
324 *(volatile unsigned short *) addr = val;
328 __writel (unsigned int val, void *addr)
330 *(volatile unsigned int *) addr = val;
334 __writeq (unsigned long val, void *addr)
336 *(volatile unsigned long *) addr = val;
339 #define readb(a) __readb((void *)(a))
340 #define readw(a) __readw((void *)(a))
341 #define readl(a) __readl((void *)(a))
342 #define readq(a) __readq((void *)(a))
343 #define __raw_readb readb
344 #define __raw_readw readw
345 #define __raw_readl readl
346 #define __raw_readq readq
347 #define writeb(v,a) __writeb((v), (void *) (a))
348 #define writew(v,a) __writew((v), (void *) (a))
349 #define writel(v,a) __writel((v), (void *) (a))
350 #define writeq(v,a) __writeq((v), (void *) (a))
351 #define __raw_writeb writeb
352 #define __raw_writew writew
353 #define __raw_writel writel
354 #define __raw_writeq writeq
377 * An "address" in IO memory space is not clearly either an integer or a pointer. We will
378 * accept both, thus the casts.
380 * On ia-64, we access the physical I/O memory space through the uncached kernel region.
383 ioremap (unsigned long offset, unsigned long size)
385 return (void *) (__IA64_UNCACHED_OFFSET | (offset));
393 #define ioremap_nocache(o,s) ioremap(o,s)
398 * String version of IO memory access ops:
400 extern void __ia64_memcpy_fromio (void *, unsigned long, long);
401 extern void __ia64_memcpy_toio (unsigned long, void *, long);
402 extern void __ia64_memset_c_io (unsigned long, unsigned long, long);
404 #define memcpy_fromio(to,from,len) \
405 __ia64_memcpy_fromio((to),(unsigned long)(from),(len))
406 #define memcpy_toio(to,from,len) \
407 __ia64_memcpy_toio((unsigned long)(to),(from),(len))
408 #define memset_io(addr,c,len) \
409 __ia64_memset_c_io((unsigned long)(addr),0x0101010101010101UL*(u8)(c),(len))
412 #define dma_cache_inv(_start,_size) do { } while (0)
413 #define dma_cache_wback(_start,_size) do { } while (0)
414 #define dma_cache_wback_inv(_start,_size) do { } while (0)
416 # endif /* __KERNEL__ */
418 #endif /* _ASM_IA64_IO_H */