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
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);
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.
122 static inline unsigned int
123 __ia64_inb (unsigned long port)
125 volatile unsigned char *addr = __ia64_mk_io_addr(port);
133 static inline unsigned int
134 __ia64_inw (unsigned long port)
136 volatile unsigned short *addr = __ia64_mk_io_addr(port);
144 static inline unsigned int
145 __ia64_inl (unsigned long port)
147 volatile unsigned int *addr = __ia64_mk_io_addr(port);
156 __ia64_outb (unsigned char val, unsigned long port)
158 volatile unsigned char *addr = __ia64_mk_io_addr(port);
165 __ia64_outw (unsigned short val, unsigned long port)
167 volatile unsigned short *addr = __ia64_mk_io_addr(port);
174 __ia64_outl (unsigned int val, unsigned long port)
176 volatile unsigned int *addr = __ia64_mk_io_addr(port);
183 __insb (unsigned long port, void *dst, unsigned long count)
185 unsigned char *dp = dst;
187 if (platform_inb == __ia64_inb) {
188 volatile unsigned char *addr = __ia64_mk_io_addr(port);
196 *dp++ = platform_inb(port);
201 __insw (unsigned long port, void *dst, unsigned long count)
203 unsigned short *dp = dst;
205 if (platform_inw == __ia64_inw) {
206 volatile unsigned short *addr = __ia64_mk_io_addr(port);
214 *dp++ = platform_inw(port);
219 __insl (unsigned long port, void *dst, unsigned long count)
221 unsigned int *dp = dst;
223 if (platform_inl == __ia64_inl) {
224 volatile unsigned int *addr = __ia64_mk_io_addr(port);
232 *dp++ = platform_inl(port);
237 __outsb (unsigned long port, const void *src, unsigned long count)
239 const unsigned char *sp = src;
241 if (platform_outb == __ia64_outb) {
242 volatile unsigned char *addr = __ia64_mk_io_addr(port);
249 platform_outb(*sp++, port);
254 __outsw (unsigned long port, const void *src, unsigned long count)
256 const unsigned short *sp = src;
258 if (platform_outw == __ia64_outw) {
259 volatile unsigned short *addr = __ia64_mk_io_addr(port);
266 platform_outw(*sp++, port);
271 __outsl (unsigned long port, void *src, unsigned long count)
273 const unsigned int *sp = src;
275 if (platform_outl == __ia64_outl) {
276 volatile unsigned int *addr = __ia64_mk_io_addr(port);
283 platform_outl(*sp++, port);
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...
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
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)
313 * The address passed to these functions are ioremap()ped already.
315 static inline unsigned char
318 return *(volatile unsigned char *)addr;
321 static inline unsigned short
324 return *(volatile unsigned short *)addr;
327 static inline unsigned int
330 return *(volatile unsigned int *) addr;
333 static inline unsigned long
336 return *(volatile unsigned long *) addr;
340 __writeb (unsigned char val, void *addr)
342 *(volatile unsigned char *) addr = val;
346 __writew (unsigned short val, void *addr)
348 *(volatile unsigned short *) addr = val;
352 __writel (unsigned int val, void *addr)
354 *(volatile unsigned int *) addr = val;
358 __writeq (unsigned long val, void *addr)
360 *(volatile unsigned long *) addr = val;
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
401 * An "address" in IO memory space is not clearly either an integer or a pointer. We will
402 * accept both, thus the casts.
404 * On ia-64, we access the physical I/O memory space through the uncached kernel region.
407 ioremap (unsigned long offset, unsigned long size)
409 return (void *) (__IA64_UNCACHED_OFFSET | (offset));
417 #define ioremap_nocache(o,s) ioremap(o,s)
422 * String version of IO memory access ops:
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);
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))
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)
440 # endif /* __KERNEL__ */
442 #endif /* _ASM_IA64_IO_H */