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 RGN_BASE(RGN_UNCACHED)
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_BITS 4
36 #define MAX_IO_SPACES (1UL << MAX_IO_SPACES_BITS)
37 #define IO_SPACE_BITS 24
38 #define IO_SPACE_SIZE (1UL << IO_SPACE_BITS)
40 #define IO_SPACE_NR(port) ((port) >> IO_SPACE_BITS)
41 #define IO_SPACE_BASE(space) ((space) << IO_SPACE_BITS)
42 #define IO_SPACE_PORT(port) ((port) & (IO_SPACE_SIZE - 1))
44 #define IO_SPACE_SPARSE_ENCODING(p) ((((p) >> 2) << 12) | ((p) & 0xfff))
47 unsigned long mmio_base; /* base in MMIO space */
51 extern struct io_space io_space[];
52 extern unsigned int num_io_spaces;
57 * All MMIO iomem cookies are in region 6; anything less is a PIO cookie:
58 * 0xCxxxxxxxxxxxxxxx MMIO cookie (return from ioremap)
59 * 0x000000001SPPPPPP PIO cookie (S=space number, P..P=port)
61 * ioread/writeX() uses the leading 1 in PIO cookies (PIO_OFFSET) to catch
62 * code that uses bare port numbers without the prerequisite pci_iomap().
64 #define PIO_OFFSET (1UL << (MAX_IO_SPACES_BITS + IO_SPACE_BITS))
65 #define PIO_MASK (PIO_OFFSET - 1)
66 #define PIO_RESERVED __IA64_UNCACHED_OFFSET
67 #define HAVE_ARCH_PIO_SIZE
69 #include <asm/intrinsics.h>
70 #include <asm/machvec.h>
72 #include <asm/system.h>
73 #include <asm-generic/iomap.h>
76 * Change virtual addresses to physical addresses and vv.
78 static inline unsigned long
79 virt_to_phys (volatile void *address)
81 return (unsigned long) address - PAGE_OFFSET;
85 phys_to_virt (unsigned long address)
87 return (void *) (address + PAGE_OFFSET);
90 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
91 extern int valid_phys_addr_range (unsigned long addr, size_t *count); /* efi.c */
94 * The following two macros are deprecated and scheduled for removal.
95 * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
97 #define bus_to_virt phys_to_virt
98 #define virt_to_bus virt_to_phys
99 #define page_to_bus page_to_phys
104 * Memory fence w/accept. This should never be used in code that is
105 * not IA-64 specific.
107 #define __ia64_mf_a() ia64_mfa()
110 * ___ia64_mmiowb - I/O write barrier
112 * Ensure ordering of I/O space writes. This will make sure that writes
113 * following the barrier will arrive after all previous writes. For most
114 * ia64 platforms, this is a simple 'mf.a' instruction.
116 * See Documentation/DocBook/deviceiobook.tmpl for more information.
118 static inline void ___ia64_mmiowb(void)
124 __ia64_mk_io_addr (unsigned long port)
126 struct io_space *space;
127 unsigned long offset;
129 space = &io_space[IO_SPACE_NR(port)];
130 port = IO_SPACE_PORT(port);
132 offset = IO_SPACE_SPARSE_ENCODING(port);
136 return (void *) (space->mmio_base | offset);
139 #define __ia64_inb ___ia64_inb
140 #define __ia64_inw ___ia64_inw
141 #define __ia64_inl ___ia64_inl
142 #define __ia64_outb ___ia64_outb
143 #define __ia64_outw ___ia64_outw
144 #define __ia64_outl ___ia64_outl
145 #define __ia64_readb ___ia64_readb
146 #define __ia64_readw ___ia64_readw
147 #define __ia64_readl ___ia64_readl
148 #define __ia64_readq ___ia64_readq
149 #define __ia64_readb_relaxed ___ia64_readb
150 #define __ia64_readw_relaxed ___ia64_readw
151 #define __ia64_readl_relaxed ___ia64_readl
152 #define __ia64_readq_relaxed ___ia64_readq
153 #define __ia64_writeb ___ia64_writeb
154 #define __ia64_writew ___ia64_writew
155 #define __ia64_writel ___ia64_writel
156 #define __ia64_writeq ___ia64_writeq
157 #define __ia64_mmiowb ___ia64_mmiowb
160 * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
161 * that the access has completed before executing other I/O accesses. Since we're doing
162 * the accesses through an uncachable (UC) translation, the CPU will execute them in
163 * program order. However, we still need to tell the compiler not to shuffle them around
164 * during optimization, which is why we use "volatile" pointers.
167 static inline unsigned int
168 ___ia64_inb (unsigned long port)
170 volatile unsigned char *addr = __ia64_mk_io_addr(port);
178 static inline unsigned int
179 ___ia64_inw (unsigned long port)
181 volatile unsigned short *addr = __ia64_mk_io_addr(port);
189 static inline unsigned int
190 ___ia64_inl (unsigned long port)
192 volatile unsigned int *addr = __ia64_mk_io_addr(port);
201 ___ia64_outb (unsigned char val, unsigned long port)
203 volatile unsigned char *addr = __ia64_mk_io_addr(port);
210 ___ia64_outw (unsigned short val, unsigned long port)
212 volatile unsigned short *addr = __ia64_mk_io_addr(port);
219 ___ia64_outl (unsigned int val, unsigned long port)
221 volatile unsigned int *addr = __ia64_mk_io_addr(port);
228 __insb (unsigned long port, void *dst, unsigned long count)
230 unsigned char *dp = dst;
233 *dp++ = platform_inb(port);
237 __insw (unsigned long port, void *dst, unsigned long count)
239 unsigned short *dp = dst;
242 *dp++ = platform_inw(port);
246 __insl (unsigned long port, void *dst, unsigned long count)
248 unsigned int *dp = dst;
251 *dp++ = platform_inl(port);
255 __outsb (unsigned long port, const void *src, unsigned long count)
257 const unsigned char *sp = src;
260 platform_outb(*sp++, port);
264 __outsw (unsigned long port, const void *src, unsigned long count)
266 const unsigned short *sp = src;
269 platform_outw(*sp++, port);
273 __outsl (unsigned long port, const void *src, unsigned long count)
275 const unsigned int *sp = src;
278 platform_outl(*sp++, port);
282 * Unfortunately, some platforms are broken and do not follow the IA-64 architecture
283 * specification regarding legacy I/O support. Thus, we have to make these operations
284 * platform dependent...
286 #define __inb platform_inb
287 #define __inw platform_inw
288 #define __inl platform_inl
289 #define __outb platform_outb
290 #define __outw platform_outw
291 #define __outl platform_outl
292 #define __mmiowb platform_mmiowb
294 #define inb(p) __inb(p)
295 #define inw(p) __inw(p)
296 #define inl(p) __inl(p)
297 #define insb(p,d,c) __insb(p,d,c)
298 #define insw(p,d,c) __insw(p,d,c)
299 #define insl(p,d,c) __insl(p,d,c)
300 #define outb(v,p) __outb(v,p)
301 #define outw(v,p) __outw(v,p)
302 #define outl(v,p) __outl(v,p)
303 #define outsb(p,s,c) __outsb(p,s,c)
304 #define outsw(p,s,c) __outsw(p,s,c)
305 #define outsl(p,s,c) __outsl(p,s,c)
306 #define mmiowb() __mmiowb()
309 * The address passed to these functions are ioremap()ped already.
311 * We need these to be machine vectors since some platforms don't provide
312 * DMA coherence via PIO reads (PCI drivers and the spec imply that this is
313 * a good idea). Writes are ok though for all existing ia64 platforms (and
314 * hopefully it'll stay that way).
316 static inline unsigned char
317 ___ia64_readb (const volatile void __iomem *addr)
319 return *(volatile unsigned char __force *)addr;
322 static inline unsigned short
323 ___ia64_readw (const volatile void __iomem *addr)
325 return *(volatile unsigned short __force *)addr;
328 static inline unsigned int
329 ___ia64_readl (const volatile void __iomem *addr)
331 return *(volatile unsigned int __force *) addr;
334 static inline unsigned long
335 ___ia64_readq (const volatile void __iomem *addr)
337 return *(volatile unsigned long __force *) addr;
341 __writeb (unsigned char val, volatile void __iomem *addr)
343 *(volatile unsigned char __force *) addr = val;
347 __writew (unsigned short val, volatile void __iomem *addr)
349 *(volatile unsigned short __force *) addr = val;
353 __writel (unsigned int val, volatile void __iomem *addr)
355 *(volatile unsigned int __force *) addr = val;
359 __writeq (unsigned long val, volatile void __iomem *addr)
361 *(volatile unsigned long __force *) addr = val;
364 #define __readb platform_readb
365 #define __readw platform_readw
366 #define __readl platform_readl
367 #define __readq platform_readq
368 #define __readb_relaxed platform_readb_relaxed
369 #define __readw_relaxed platform_readw_relaxed
370 #define __readl_relaxed platform_readl_relaxed
371 #define __readq_relaxed platform_readq_relaxed
373 #define readb(a) __readb((a))
374 #define readw(a) __readw((a))
375 #define readl(a) __readl((a))
376 #define readq(a) __readq((a))
377 #define readb_relaxed(a) __readb_relaxed((a))
378 #define readw_relaxed(a) __readw_relaxed((a))
379 #define readl_relaxed(a) __readl_relaxed((a))
380 #define readq_relaxed(a) __readq_relaxed((a))
381 #define __raw_readb readb
382 #define __raw_readw readw
383 #define __raw_readl readl
384 #define __raw_readq readq
385 #define __raw_readb_relaxed readb_relaxed
386 #define __raw_readw_relaxed readw_relaxed
387 #define __raw_readl_relaxed readl_relaxed
388 #define __raw_readq_relaxed readq_relaxed
389 #define writeb(v,a) __writeb((v), (a))
390 #define writew(v,a) __writew((v), (a))
391 #define writel(v,a) __writel((v), (a))
392 #define writeq(v,a) __writeq((v), (a))
393 #define __raw_writeb writeb
394 #define __raw_writew writew
395 #define __raw_writel writel
396 #define __raw_writeq writeq
419 * An "address" in IO memory space is not clearly either an integer or a pointer. We will
420 * accept both, thus the casts.
422 * On ia-64, we access the physical I/O memory space through the uncached kernel region.
424 static inline void __iomem *
425 ioremap (unsigned long offset, unsigned long size)
427 return (void __iomem *) (__IA64_UNCACHED_OFFSET | (offset));
431 iounmap (volatile void __iomem *addr)
435 #define ioremap_nocache(o,s) ioremap(o,s)
440 * String version of IO memory access ops:
442 extern void memcpy_fromio(void *dst, const volatile void __iomem *src, long n);
443 extern void memcpy_toio(volatile void __iomem *dst, const void *src, long n);
444 extern void memset_io(volatile void __iomem *s, int c, long n);
446 #define dma_cache_inv(_start,_size) do { } while (0)
447 #define dma_cache_wback(_start,_size) do { } while (0)
448 #define dma_cache_wback_inv(_start,_size) do { } while (0)
450 # endif /* __KERNEL__ */
453 * Enabling BIO_VMERGE_BOUNDARY forces us to turn off I/O MMU bypassing. It is said that
454 * BIO-level virtual merging can give up to 4% performance boost (not verified for ia64).
455 * On the other hand, we know that I/O MMU bypassing gives ~8% performance improvement on
456 * SPECweb-like workloads on zx1-based machines. Thus, for now we favor I/O MMU bypassing
457 * over BIO-level virtual merging.
459 extern unsigned long ia64_max_iommu_merge_mask;
461 #define BIO_VMERGE_BOUNDARY 0
464 * It makes no sense at all to have this BIO_VMERGE_BOUNDARY macro here. Should be
465 * replaced by dma_merge_mask() or something of that sort. Note: the only way
466 * BIO_VMERGE_BOUNDARY is used is to mask off bits. Effectively, our definition gets
469 * addr & ((ia64_max_iommu_merge_mask + 1) - 1) == (addr & ia64_max_iommu_vmerge_mask)
471 * which is precisely what we want.
473 #define BIO_VMERGE_BOUNDARY (ia64_max_iommu_merge_mask + 1)
476 #endif /* _ASM_IA64_IO_H */