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-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>
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
35 #define MAX_IO_SPACES 16
36 #define IO_SPACE_BITS 24
37 #define IO_SPACE_SIZE (1UL << IO_SPACE_BITS)
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))
43 #define IO_SPACE_SPARSE_ENCODING(p) ((((p) >> 2) << 12) | (p & 0xfff))
46 unsigned long mmio_base; /* base in MMIO space */
50 extern struct io_space io_space[];
51 extern unsigned int num_io_spaces;
55 #include <asm/machvec.h>
57 #include <asm/system.h>
60 * Change virtual addresses to physical addresses and vv.
62 static inline unsigned long
63 virt_to_phys (volatile void *address)
65 return (unsigned long) address - PAGE_OFFSET;
69 phys_to_virt (unsigned long address)
71 return (void *) (address + PAGE_OFFSET);
75 * The following two macros are deprecated and scheduled for removal.
76 * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
78 #define bus_to_virt phys_to_virt
79 #define virt_to_bus virt_to_phys
80 #define page_to_bus page_to_phys
85 * Memory fence w/accept. This should never be used in code that is
88 #define __ia64_mf_a() __asm__ __volatile__ ("mf.a" ::: "memory")
90 static inline const unsigned long
91 __ia64_get_io_port_base (void)
93 extern unsigned long ia64_iobase;
99 __ia64_mk_io_addr (unsigned long port)
101 struct io_space *space;
102 unsigned long offset;
104 space = &io_space[IO_SPACE_NR(port)];
105 port = IO_SPACE_PORT(port);
107 offset = IO_SPACE_SPARSE_ENCODING(port);
111 return (void *) (space->mmio_base | offset);
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
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.
137 static inline unsigned int
138 ___ia64_inb (unsigned long port)
140 volatile unsigned char *addr = __ia64_mk_io_addr(port);
148 static inline unsigned int
149 ___ia64_inw (unsigned long port)
151 volatile unsigned short *addr = __ia64_mk_io_addr(port);
159 static inline unsigned int
160 ___ia64_inl (unsigned long port)
162 volatile unsigned int *addr = __ia64_mk_io_addr(port);
171 ___ia64_outb (unsigned char val, unsigned long port)
173 volatile unsigned char *addr = __ia64_mk_io_addr(port);
180 ___ia64_outw (unsigned short val, unsigned long port)
182 volatile unsigned short *addr = __ia64_mk_io_addr(port);
189 ___ia64_outl (unsigned int val, unsigned long port)
191 volatile unsigned int *addr = __ia64_mk_io_addr(port);
198 __insb (unsigned long port, void *dst, unsigned long count)
200 unsigned char *dp = dst;
203 *dp++ = platform_inb(port);
207 __insw (unsigned long port, void *dst, unsigned long count)
209 unsigned short *dp = dst;
212 *dp++ = platform_inw(port);
216 __insl (unsigned long port, void *dst, unsigned long count)
218 unsigned int *dp = dst;
221 *dp++ = platform_inl(port);
225 __outsb (unsigned long port, const void *src, unsigned long count)
227 const unsigned char *sp = src;
230 platform_outb(*sp++, port);
234 __outsw (unsigned long port, const void *src, unsigned long count)
236 const unsigned short *sp = src;
239 platform_outw(*sp++, port);
243 __outsl (unsigned long port, void *src, unsigned long count)
245 const unsigned int *sp = src;
248 platform_outl(*sp++, port);
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...
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
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)
277 * The address passed to these functions are ioremap()ped already.
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).
284 static inline unsigned char
285 ___ia64_readb (void *addr)
287 return *(volatile unsigned char *)addr;
290 static inline unsigned short
291 ___ia64_readw (void *addr)
293 return *(volatile unsigned short *)addr;
296 static inline unsigned int
297 ___ia64_readl (void *addr)
299 return *(volatile unsigned int *) addr;
302 static inline unsigned long
303 ___ia64_readq (void *addr)
305 return *(volatile unsigned long *) addr;
309 __writeb (unsigned char val, void *addr)
311 *(volatile unsigned char *) addr = val;
315 __writew (unsigned short val, void *addr)
317 *(volatile unsigned short *) addr = val;
321 __writel (unsigned int val, void *addr)
323 *(volatile unsigned int *) addr = val;
327 __writeq (unsigned long val, void *addr)
329 *(volatile unsigned long *) addr = val;
332 #define __readb platform_readb
333 #define __readw platform_readw
334 #define __readl platform_readl
335 #define __readq platform_readq
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
375 * An "address" in IO memory space is not clearly either an integer or a pointer. We will
376 * accept both, thus the casts.
378 * On ia-64, we access the physical I/O memory space through the uncached kernel region.
381 ioremap (unsigned long offset, unsigned long size)
383 return (void *) (__IA64_UNCACHED_OFFSET | (offset));
391 #define ioremap_nocache(o,s) ioremap(o,s)
396 * String version of IO memory access ops:
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);
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))
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)
414 # endif /* __KERNEL__ */
416 #endif /* _ASM_IA64_IO_H */