WIP FPC-III support
[linux/fpc-iii.git] / arch / ia64 / include / asm / io.h
blob3d666a11a2def370dc8f7e57bab9b9da6c78dcb8
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_IA64_IO_H
3 #define _ASM_IA64_IO_H
5 /*
6 * This file contains the definitions for the emulated IO instructions
7 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
8 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
9 * versions of the single-IO instructions (inb_p/inw_p/..).
11 * This file is not meant to be obfuscating: it's just complicated to
12 * (a) handle it all in a way that makes gcc able to optimize it as
13 * well as possible and (b) trying to avoid writing the same thing
14 * over and over again with slight variations and possibly making a
15 * mistake somewhere.
17 * Copyright (C) 1998-2003 Hewlett-Packard Co
18 * David Mosberger-Tang <davidm@hpl.hp.com>
19 * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
20 * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
23 #include <asm/unaligned.h>
24 #include <asm/early_ioremap.h>
26 /* We don't use IO slowdowns on the ia64, but.. */
27 #define __SLOW_DOWN_IO do { } while (0)
28 #define SLOW_DOWN_IO do { } while (0)
30 #define __IA64_UNCACHED_OFFSET RGN_BASE(RGN_UNCACHED)
33 * The legacy I/O space defined by the ia64 architecture supports only 65536 ports, but
34 * large machines may have multiple other I/O spaces so we can't place any a priori limit
35 * on IO_SPACE_LIMIT. These additional spaces are described in ACPI.
37 #define IO_SPACE_LIMIT 0xffffffffffffffffUL
39 #define MAX_IO_SPACES_BITS 8
40 #define MAX_IO_SPACES (1UL << MAX_IO_SPACES_BITS)
41 #define IO_SPACE_BITS 24
42 #define IO_SPACE_SIZE (1UL << IO_SPACE_BITS)
44 #define IO_SPACE_NR(port) ((port) >> IO_SPACE_BITS)
45 #define IO_SPACE_BASE(space) ((space) << IO_SPACE_BITS)
46 #define IO_SPACE_PORT(port) ((port) & (IO_SPACE_SIZE - 1))
48 #define IO_SPACE_SPARSE_ENCODING(p) ((((p) >> 2) << 12) | ((p) & 0xfff))
50 struct io_space {
51 unsigned long mmio_base; /* base in MMIO space */
52 int sparse;
55 extern struct io_space io_space[];
56 extern unsigned int num_io_spaces;
58 # ifdef __KERNEL__
61 * All MMIO iomem cookies are in region 6; anything less is a PIO cookie:
62 * 0xCxxxxxxxxxxxxxxx MMIO cookie (return from ioremap)
63 * 0x000000001SPPPPPP PIO cookie (S=space number, P..P=port)
65 * ioread/writeX() uses the leading 1 in PIO cookies (PIO_OFFSET) to catch
66 * code that uses bare port numbers without the prerequisite pci_iomap().
68 #define PIO_OFFSET (1UL << (MAX_IO_SPACES_BITS + IO_SPACE_BITS))
69 #define PIO_MASK (PIO_OFFSET - 1)
70 #define PIO_RESERVED __IA64_UNCACHED_OFFSET
71 #define HAVE_ARCH_PIO_SIZE
73 #include <asm/intrinsics.h>
74 #include <asm/page.h>
75 #include <asm-generic/iomap.h>
78 * Change virtual addresses to physical addresses and vv.
80 static inline unsigned long
81 virt_to_phys (volatile void *address)
83 return (unsigned long) address - PAGE_OFFSET;
85 #define virt_to_phys virt_to_phys
87 static inline void*
88 phys_to_virt (unsigned long address)
90 return (void *) (address + PAGE_OFFSET);
92 #define phys_to_virt phys_to_virt
94 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
95 extern u64 kern_mem_attribute (unsigned long phys_addr, unsigned long size);
96 extern int valid_phys_addr_range (phys_addr_t addr, size_t count); /* efi.c */
97 extern int valid_mmap_phys_addr_range (unsigned long pfn, size_t count);
100 * The following two macros are deprecated and scheduled for removal.
101 * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
103 #define bus_to_virt phys_to_virt
104 #define virt_to_bus virt_to_phys
105 #define page_to_bus page_to_phys
107 # endif /* KERNEL */
110 * Memory fence w/accept. This should never be used in code that is
111 * not IA-64 specific.
113 #define __ia64_mf_a() ia64_mfa()
115 static inline void*
116 __ia64_mk_io_addr (unsigned long port)
118 struct io_space *space;
119 unsigned long offset;
121 space = &io_space[IO_SPACE_NR(port)];
122 port = IO_SPACE_PORT(port);
123 if (space->sparse)
124 offset = IO_SPACE_SPARSE_ENCODING(port);
125 else
126 offset = port;
128 return (void *) (space->mmio_base | offset);
132 * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
133 * that the access has completed before executing other I/O accesses. Since we're doing
134 * the accesses through an uncachable (UC) translation, the CPU will execute them in
135 * program order. However, we still need to tell the compiler not to shuffle them around
136 * during optimization, which is why we use "volatile" pointers.
139 #define inb inb
140 static inline unsigned int inb(unsigned long port)
142 volatile unsigned char *addr = __ia64_mk_io_addr(port);
143 unsigned char ret;
145 ret = *addr;
146 __ia64_mf_a();
147 return ret;
150 #define inw inw
151 static inline unsigned int inw(unsigned long port)
153 volatile unsigned short *addr = __ia64_mk_io_addr(port);
154 unsigned short ret;
156 ret = *addr;
157 __ia64_mf_a();
158 return ret;
161 #define inl inl
162 static inline unsigned int inl(unsigned long port)
164 volatile unsigned int *addr = __ia64_mk_io_addr(port);
165 unsigned int ret;
167 ret = *addr;
168 __ia64_mf_a();
169 return ret;
172 #define outb outb
173 static inline void outb(unsigned char val, unsigned long port)
175 volatile unsigned char *addr = __ia64_mk_io_addr(port);
177 *addr = val;
178 __ia64_mf_a();
181 #define outw outw
182 static inline void outw(unsigned short val, unsigned long port)
184 volatile unsigned short *addr = __ia64_mk_io_addr(port);
186 *addr = val;
187 __ia64_mf_a();
190 #define outl outl
191 static inline void outl(unsigned int val, unsigned long port)
193 volatile unsigned int *addr = __ia64_mk_io_addr(port);
195 *addr = val;
196 __ia64_mf_a();
199 #define insb insb
200 static inline void insb(unsigned long port, void *dst, unsigned long count)
202 unsigned char *dp = dst;
204 while (count--)
205 *dp++ = inb(port);
208 #define insw insw
209 static inline void insw(unsigned long port, void *dst, unsigned long count)
211 unsigned short *dp = dst;
213 while (count--)
214 put_unaligned(inw(port), dp++);
217 #define insl insl
218 static inline void insl(unsigned long port, void *dst, unsigned long count)
220 unsigned int *dp = dst;
222 while (count--)
223 put_unaligned(inl(port), dp++);
226 #define outsb outsb
227 static inline void outsb(unsigned long port, const void *src,
228 unsigned long count)
230 const unsigned char *sp = src;
232 while (count--)
233 outb(*sp++, port);
236 #define outsw outsw
237 static inline void outsw(unsigned long port, const void *src,
238 unsigned long count)
240 const unsigned short *sp = src;
242 while (count--)
243 outw(get_unaligned(sp++), port);
246 #define outsl outsl
247 static inline void outsl(unsigned long port, const void *src,
248 unsigned long count)
250 const unsigned int *sp = src;
252 while (count--)
253 outl(get_unaligned(sp++), port);
256 # ifdef __KERNEL__
258 extern void __iomem * ioremap(unsigned long offset, unsigned long size);
259 extern void __iomem * ioremap_uc(unsigned long offset, unsigned long size);
260 extern void iounmap (volatile void __iomem *addr);
261 static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size)
263 return ioremap(phys_addr, size);
265 #define ioremap ioremap
266 #define ioremap_cache ioremap_cache
267 #define ioremap_uc ioremap_uc
268 #define iounmap iounmap
271 * String version of IO memory access ops:
273 extern void memcpy_fromio(void *dst, const volatile void __iomem *src, long n);
274 extern void memcpy_toio(volatile void __iomem *dst, const void *src, long n);
275 extern void memset_io(volatile void __iomem *s, int c, long n);
277 #define memcpy_fromio memcpy_fromio
278 #define memcpy_toio memcpy_toio
279 #define memset_io memset_io
280 #define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
281 #define xlate_dev_mem_ptr xlate_dev_mem_ptr
282 #include <asm-generic/io.h>
283 #undef PCI_IOBASE
285 # endif /* __KERNEL__ */
287 #endif /* _ASM_IA64_IO_H */