1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/arm/include/asm/io.h
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 1996-2000 Russell King
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Modifications:
8*4882a593Smuzhiyun * 16-Sep-1996 RMK Inlined the inx/outx functions & optimised for both
9*4882a593Smuzhiyun * constant addresses and variable addresses.
10*4882a593Smuzhiyun * 04-Dec-1997 RMK Moved a lot of this stuff to the new architecture
11*4882a593Smuzhiyun * specific IO header files.
12*4882a593Smuzhiyun * 27-Mar-1999 PJB Second parameter of memcpy_toio is const..
13*4882a593Smuzhiyun * 04-Apr-1999 PJB Added check_signature.
14*4882a593Smuzhiyun * 12-Dec-1999 RMK More cleanups
15*4882a593Smuzhiyun * 18-Jun-2000 RMK Removed virt_to_* and friends definitions
16*4882a593Smuzhiyun * 05-Oct-2004 BJD Moved memory string functions to use void __iomem
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun #ifndef __ASM_ARM_IO_H
19*4882a593Smuzhiyun #define __ASM_ARM_IO_H
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #ifdef __KERNEL__
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #include <linux/string.h>
24*4882a593Smuzhiyun #include <linux/types.h>
25*4882a593Smuzhiyun #include <asm/byteorder.h>
26*4882a593Smuzhiyun #include <asm/memory.h>
27*4882a593Smuzhiyun #include <asm-generic/pci_iomap.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun * ISA I/O bus memory addresses are 1:1 with the physical address.
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun #define isa_virt_to_bus virt_to_phys
33*4882a593Smuzhiyun #define isa_bus_to_virt phys_to_virt
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /*
36*4882a593Smuzhiyun * Atomic MMIO-wide IO modify
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun extern void atomic_io_modify(void __iomem *reg, u32 mask, u32 set);
39*4882a593Smuzhiyun extern void atomic_io_modify_relaxed(void __iomem *reg, u32 mask, u32 set);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /*
42*4882a593Smuzhiyun * Generic IO read/write. These perform native-endian accesses. Note
43*4882a593Smuzhiyun * that some architectures will want to re-define __raw_{read,write}w.
44*4882a593Smuzhiyun */
45*4882a593Smuzhiyun void __raw_writesb(volatile void __iomem *addr, const void *data, int bytelen);
46*4882a593Smuzhiyun void __raw_writesw(volatile void __iomem *addr, const void *data, int wordlen);
47*4882a593Smuzhiyun void __raw_writesl(volatile void __iomem *addr, const void *data, int longlen);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun void __raw_readsb(const volatile void __iomem *addr, void *data, int bytelen);
50*4882a593Smuzhiyun void __raw_readsw(const volatile void __iomem *addr, void *data, int wordlen);
51*4882a593Smuzhiyun void __raw_readsl(const volatile void __iomem *addr, void *data, int longlen);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #if __LINUX_ARM_ARCH__ < 6
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun * Half-word accesses are problematic with RiscPC due to limitations of
56*4882a593Smuzhiyun * the bus. Rather than special-case the machine, just let the compiler
57*4882a593Smuzhiyun * generate the access for CPUs prior to ARMv6.
58*4882a593Smuzhiyun */
59*4882a593Smuzhiyun #define __raw_readw(a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
60*4882a593Smuzhiyun #define __raw_writew(v,a) ((void)(__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v)))
61*4882a593Smuzhiyun #else
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun * When running under a hypervisor, we want to avoid I/O accesses with
64*4882a593Smuzhiyun * writeback addressing modes as these incur a significant performance
65*4882a593Smuzhiyun * overhead (the address generation must be emulated in software).
66*4882a593Smuzhiyun */
67*4882a593Smuzhiyun #define __raw_writew __raw_writew
__raw_writew(u16 val,volatile void __iomem * addr)68*4882a593Smuzhiyun static inline void __raw_writew(u16 val, volatile void __iomem *addr)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun asm volatile("strh %1, %0"
71*4882a593Smuzhiyun : : "Q" (*(volatile u16 __force *)addr), "r" (val));
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define __raw_readw __raw_readw
__raw_readw(const volatile void __iomem * addr)75*4882a593Smuzhiyun static inline u16 __raw_readw(const volatile void __iomem *addr)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun u16 val;
78*4882a593Smuzhiyun asm volatile("ldrh %0, %1"
79*4882a593Smuzhiyun : "=r" (val)
80*4882a593Smuzhiyun : "Q" (*(volatile u16 __force *)addr));
81*4882a593Smuzhiyun return val;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun #endif
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun #define __raw_writeb __raw_writeb
__raw_writeb(u8 val,volatile void __iomem * addr)86*4882a593Smuzhiyun static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun asm volatile("strb %1, %0"
89*4882a593Smuzhiyun : : "Qo" (*(volatile u8 __force *)addr), "r" (val));
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun #define __raw_writel __raw_writel
__raw_writel(u32 val,volatile void __iomem * addr)93*4882a593Smuzhiyun static inline void __raw_writel(u32 val, volatile void __iomem *addr)
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun asm volatile("str %1, %0"
96*4882a593Smuzhiyun : : "Qo" (*(volatile u32 __force *)addr), "r" (val));
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun #define __raw_readb __raw_readb
__raw_readb(const volatile void __iomem * addr)100*4882a593Smuzhiyun static inline u8 __raw_readb(const volatile void __iomem *addr)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun u8 val;
103*4882a593Smuzhiyun asm volatile("ldrb %0, %1"
104*4882a593Smuzhiyun : "=r" (val)
105*4882a593Smuzhiyun : "Qo" (*(volatile u8 __force *)addr));
106*4882a593Smuzhiyun return val;
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #define __raw_readl __raw_readl
__raw_readl(const volatile void __iomem * addr)110*4882a593Smuzhiyun static inline u32 __raw_readl(const volatile void __iomem *addr)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun u32 val;
113*4882a593Smuzhiyun asm volatile("ldr %0, %1"
114*4882a593Smuzhiyun : "=r" (val)
115*4882a593Smuzhiyun : "Qo" (*(volatile u32 __force *)addr));
116*4882a593Smuzhiyun return val;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /*
120*4882a593Smuzhiyun * Architecture ioremap implementation.
121*4882a593Smuzhiyun */
122*4882a593Smuzhiyun #define MT_DEVICE 0
123*4882a593Smuzhiyun #define MT_DEVICE_NONSHARED 1
124*4882a593Smuzhiyun #define MT_DEVICE_CACHED 2
125*4882a593Smuzhiyun #define MT_DEVICE_WC 3
126*4882a593Smuzhiyun /*
127*4882a593Smuzhiyun * types 4 onwards can be found in asm/mach/map.h and are undefined
128*4882a593Smuzhiyun * for ioremap
129*4882a593Smuzhiyun */
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun /*
132*4882a593Smuzhiyun * __arm_ioremap takes CPU physical address.
133*4882a593Smuzhiyun * __arm_ioremap_pfn takes a Page Frame Number and an offset into that page
134*4882a593Smuzhiyun * The _caller variety takes a __builtin_return_address(0) value for
135*4882a593Smuzhiyun * /proc/vmalloc to use - and should only be used in non-inline functions.
136*4882a593Smuzhiyun */
137*4882a593Smuzhiyun extern void __iomem *__arm_ioremap_caller(phys_addr_t, size_t, unsigned int,
138*4882a593Smuzhiyun void *);
139*4882a593Smuzhiyun extern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int);
140*4882a593Smuzhiyun extern void __iomem *__arm_ioremap_exec(phys_addr_t, size_t, bool cached);
141*4882a593Smuzhiyun extern void __iounmap(volatile void __iomem *addr);
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun extern void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t,
144*4882a593Smuzhiyun unsigned int, void *);
145*4882a593Smuzhiyun extern void (*arch_iounmap)(volatile void __iomem *);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /*
148*4882a593Smuzhiyun * Bad read/write accesses...
149*4882a593Smuzhiyun */
150*4882a593Smuzhiyun extern void __readwrite_bug(const char *fn);
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun /*
153*4882a593Smuzhiyun * A typesafe __io() helper
154*4882a593Smuzhiyun */
__typesafe_io(unsigned long addr)155*4882a593Smuzhiyun static inline void __iomem *__typesafe_io(unsigned long addr)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun return (void __iomem *)addr;
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun #define IOMEM(x) ((void __force __iomem *)(x))
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /* IO barriers */
163*4882a593Smuzhiyun #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
164*4882a593Smuzhiyun #include <asm/barrier.h>
165*4882a593Smuzhiyun #define __iormb() rmb()
166*4882a593Smuzhiyun #define __iowmb() wmb()
167*4882a593Smuzhiyun #else
168*4882a593Smuzhiyun #define __iormb() do { } while (0)
169*4882a593Smuzhiyun #define __iowmb() do { } while (0)
170*4882a593Smuzhiyun #endif
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun /* PCI fixed i/o mapping */
173*4882a593Smuzhiyun #define PCI_IO_VIRT_BASE 0xfee00000
174*4882a593Smuzhiyun #define PCI_IOBASE ((void __iomem *)PCI_IO_VIRT_BASE)
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun #if defined(CONFIG_PCI)
177*4882a593Smuzhiyun void pci_ioremap_set_mem_type(int mem_type);
178*4882a593Smuzhiyun #else
pci_ioremap_set_mem_type(int mem_type)179*4882a593Smuzhiyun static inline void pci_ioremap_set_mem_type(int mem_type) {}
180*4882a593Smuzhiyun #endif
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun extern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr);
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun /*
185*4882a593Smuzhiyun * PCI configuration space mapping function.
186*4882a593Smuzhiyun *
187*4882a593Smuzhiyun * The PCI specification does not allow configuration write
188*4882a593Smuzhiyun * transactions to be posted. Add an arch specific
189*4882a593Smuzhiyun * pci_remap_cfgspace() definition that is implemented
190*4882a593Smuzhiyun * through strongly ordered memory mappings.
191*4882a593Smuzhiyun */
192*4882a593Smuzhiyun #define pci_remap_cfgspace pci_remap_cfgspace
193*4882a593Smuzhiyun void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size);
194*4882a593Smuzhiyun /*
195*4882a593Smuzhiyun * Now, pick up the machine-defined IO definitions
196*4882a593Smuzhiyun */
197*4882a593Smuzhiyun #ifdef CONFIG_NEED_MACH_IO_H
198*4882a593Smuzhiyun #include <mach/io.h>
199*4882a593Smuzhiyun #elif defined(CONFIG_PCI)
200*4882a593Smuzhiyun #define IO_SPACE_LIMIT ((resource_size_t)0xfffff)
201*4882a593Smuzhiyun #define __io(a) __typesafe_io(PCI_IO_VIRT_BASE + ((a) & IO_SPACE_LIMIT))
202*4882a593Smuzhiyun #else
203*4882a593Smuzhiyun #define __io(a) __typesafe_io((a) & IO_SPACE_LIMIT)
204*4882a593Smuzhiyun #endif
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /*
207*4882a593Smuzhiyun * This is the limit of PC card/PCI/ISA IO space, which is by default
208*4882a593Smuzhiyun * 64K if we have PC card, PCI or ISA support. Otherwise, default to
209*4882a593Smuzhiyun * zero to prevent ISA/PCI drivers claiming IO space (and potentially
210*4882a593Smuzhiyun * oopsing.)
211*4882a593Smuzhiyun *
212*4882a593Smuzhiyun * Only set this larger if you really need inb() et.al. to operate over
213*4882a593Smuzhiyun * a larger address space. Note that SOC_COMMON ioremaps each sockets
214*4882a593Smuzhiyun * IO space area, and so inb() et.al. must be defined to operate as per
215*4882a593Smuzhiyun * readb() et.al. on such platforms.
216*4882a593Smuzhiyun */
217*4882a593Smuzhiyun #ifndef IO_SPACE_LIMIT
218*4882a593Smuzhiyun #if defined(CONFIG_PCMCIA_SOC_COMMON) || defined(CONFIG_PCMCIA_SOC_COMMON_MODULE)
219*4882a593Smuzhiyun #define IO_SPACE_LIMIT ((resource_size_t)0xffffffff)
220*4882a593Smuzhiyun #elif defined(CONFIG_PCI) || defined(CONFIG_ISA) || defined(CONFIG_PCCARD)
221*4882a593Smuzhiyun #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
222*4882a593Smuzhiyun #else
223*4882a593Smuzhiyun #define IO_SPACE_LIMIT ((resource_size_t)0)
224*4882a593Smuzhiyun #endif
225*4882a593Smuzhiyun #endif
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun /*
228*4882a593Smuzhiyun * IO port access primitives
229*4882a593Smuzhiyun * -------------------------
230*4882a593Smuzhiyun *
231*4882a593Smuzhiyun * The ARM doesn't have special IO access instructions; all IO is memory
232*4882a593Smuzhiyun * mapped. Note that these are defined to perform little endian accesses
233*4882a593Smuzhiyun * only. Their primary purpose is to access PCI and ISA peripherals.
234*4882a593Smuzhiyun *
235*4882a593Smuzhiyun * Note that for a big endian machine, this implies that the following
236*4882a593Smuzhiyun * big endian mode connectivity is in place, as described by numerous
237*4882a593Smuzhiyun * ARM documents:
238*4882a593Smuzhiyun *
239*4882a593Smuzhiyun * PCI: D0-D7 D8-D15 D16-D23 D24-D31
240*4882a593Smuzhiyun * ARM: D24-D31 D16-D23 D8-D15 D0-D7
241*4882a593Smuzhiyun *
242*4882a593Smuzhiyun * The machine specific io.h include defines __io to translate an "IO"
243*4882a593Smuzhiyun * address to a memory address.
244*4882a593Smuzhiyun *
245*4882a593Smuzhiyun * Note that we prevent GCC re-ordering or caching values in expressions
246*4882a593Smuzhiyun * by introducing sequence points into the in*() definitions. Note that
247*4882a593Smuzhiyun * __raw_* do not guarantee this behaviour.
248*4882a593Smuzhiyun *
249*4882a593Smuzhiyun * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
250*4882a593Smuzhiyun */
251*4882a593Smuzhiyun #ifdef __io
252*4882a593Smuzhiyun #define outb(v,p) ({ __iowmb(); __raw_writeb(v,__io(p)); })
253*4882a593Smuzhiyun #define outw(v,p) ({ __iowmb(); __raw_writew((__force __u16) \
254*4882a593Smuzhiyun cpu_to_le16(v),__io(p)); })
255*4882a593Smuzhiyun #define outl(v,p) ({ __iowmb(); __raw_writel((__force __u32) \
256*4882a593Smuzhiyun cpu_to_le32(v),__io(p)); })
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun #define inb(p) ({ __u8 __v = __raw_readb(__io(p)); __iormb(); __v; })
259*4882a593Smuzhiyun #define inw(p) ({ __u16 __v = le16_to_cpu((__force __le16) \
260*4882a593Smuzhiyun __raw_readw(__io(p))); __iormb(); __v; })
261*4882a593Smuzhiyun #define inl(p) ({ __u32 __v = le32_to_cpu((__force __le32) \
262*4882a593Smuzhiyun __raw_readl(__io(p))); __iormb(); __v; })
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun #define outsb(p,d,l) __raw_writesb(__io(p),d,l)
265*4882a593Smuzhiyun #define outsw(p,d,l) __raw_writesw(__io(p),d,l)
266*4882a593Smuzhiyun #define outsl(p,d,l) __raw_writesl(__io(p),d,l)
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun #define insb(p,d,l) __raw_readsb(__io(p),d,l)
269*4882a593Smuzhiyun #define insw(p,d,l) __raw_readsw(__io(p),d,l)
270*4882a593Smuzhiyun #define insl(p,d,l) __raw_readsl(__io(p),d,l)
271*4882a593Smuzhiyun #endif
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun /*
274*4882a593Smuzhiyun * String version of IO memory access ops:
275*4882a593Smuzhiyun */
276*4882a593Smuzhiyun extern void _memcpy_fromio(void *, const volatile void __iomem *, size_t);
277*4882a593Smuzhiyun extern void _memcpy_toio(volatile void __iomem *, const void *, size_t);
278*4882a593Smuzhiyun extern void _memset_io(volatile void __iomem *, int, size_t);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /*
281*4882a593Smuzhiyun * Memory access primitives
282*4882a593Smuzhiyun * ------------------------
283*4882a593Smuzhiyun *
284*4882a593Smuzhiyun * These perform PCI memory accesses via an ioremap region. They don't
285*4882a593Smuzhiyun * take an address as such, but a cookie.
286*4882a593Smuzhiyun *
287*4882a593Smuzhiyun * Again, these are defined to perform little endian accesses. See the
288*4882a593Smuzhiyun * IO port primitives for more information.
289*4882a593Smuzhiyun */
290*4882a593Smuzhiyun #ifndef readl
291*4882a593Smuzhiyun #define readb_relaxed(c) ({ u8 __r = __raw_readb(c); __r; })
292*4882a593Smuzhiyun #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
293*4882a593Smuzhiyun __raw_readw(c)); __r; })
294*4882a593Smuzhiyun #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
295*4882a593Smuzhiyun __raw_readl(c)); __r; })
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun #define writeb_relaxed(v,c) __raw_writeb(v,c)
298*4882a593Smuzhiyun #define writew_relaxed(v,c) __raw_writew((__force u16) cpu_to_le16(v),c)
299*4882a593Smuzhiyun #define writel_relaxed(v,c) __raw_writel((__force u32) cpu_to_le32(v),c)
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
302*4882a593Smuzhiyun #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
303*4882a593Smuzhiyun #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
306*4882a593Smuzhiyun #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
307*4882a593Smuzhiyun #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun #define readsb(p,d,l) __raw_readsb(p,d,l)
310*4882a593Smuzhiyun #define readsw(p,d,l) __raw_readsw(p,d,l)
311*4882a593Smuzhiyun #define readsl(p,d,l) __raw_readsl(p,d,l)
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun #define writesb(p,d,l) __raw_writesb(p,d,l)
314*4882a593Smuzhiyun #define writesw(p,d,l) __raw_writesw(p,d,l)
315*4882a593Smuzhiyun #define writesl(p,d,l) __raw_writesl(p,d,l)
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun #ifndef __ARMBE__
memset_io(volatile void __iomem * dst,unsigned c,size_t count)318*4882a593Smuzhiyun static inline void memset_io(volatile void __iomem *dst, unsigned c,
319*4882a593Smuzhiyun size_t count)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun extern void mmioset(void *, unsigned int, size_t);
322*4882a593Smuzhiyun mmioset((void __force *)dst, c, count);
323*4882a593Smuzhiyun }
324*4882a593Smuzhiyun #define memset_io(dst,c,count) memset_io(dst,c,count)
325*4882a593Smuzhiyun
memcpy_fromio(void * to,const volatile void __iomem * from,size_t count)326*4882a593Smuzhiyun static inline void memcpy_fromio(void *to, const volatile void __iomem *from,
327*4882a593Smuzhiyun size_t count)
328*4882a593Smuzhiyun {
329*4882a593Smuzhiyun extern void mmiocpy(void *, const void *, size_t);
330*4882a593Smuzhiyun mmiocpy(to, (const void __force *)from, count);
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun #define memcpy_fromio(to,from,count) memcpy_fromio(to,from,count)
333*4882a593Smuzhiyun
memcpy_toio(volatile void __iomem * to,const void * from,size_t count)334*4882a593Smuzhiyun static inline void memcpy_toio(volatile void __iomem *to, const void *from,
335*4882a593Smuzhiyun size_t count)
336*4882a593Smuzhiyun {
337*4882a593Smuzhiyun extern void mmiocpy(void *, const void *, size_t);
338*4882a593Smuzhiyun mmiocpy((void __force *)to, from, count);
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun #define memcpy_toio(to,from,count) memcpy_toio(to,from,count)
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun #else
343*4882a593Smuzhiyun #define memset_io(c,v,l) _memset_io(c,(v),(l))
344*4882a593Smuzhiyun #define memcpy_fromio(a,c,l) _memcpy_fromio((a),c,(l))
345*4882a593Smuzhiyun #define memcpy_toio(c,a,l) _memcpy_toio(c,(a),(l))
346*4882a593Smuzhiyun #endif
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun #endif /* readl */
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /*
351*4882a593Smuzhiyun * ioremap() and friends.
352*4882a593Smuzhiyun *
353*4882a593Smuzhiyun * ioremap() takes a resource address, and size. Due to the ARM memory
354*4882a593Smuzhiyun * types, it is important to use the correct ioremap() function as each
355*4882a593Smuzhiyun * mapping has specific properties.
356*4882a593Smuzhiyun *
357*4882a593Smuzhiyun * Function Memory type Cacheability Cache hint
358*4882a593Smuzhiyun * ioremap() Device n/a n/a
359*4882a593Smuzhiyun * ioremap_cache() Normal Writeback Read allocate
360*4882a593Smuzhiyun * ioremap_wc() Normal Non-cacheable n/a
361*4882a593Smuzhiyun * ioremap_wt() Normal Non-cacheable n/a
362*4882a593Smuzhiyun *
363*4882a593Smuzhiyun * All device mappings have the following properties:
364*4882a593Smuzhiyun * - no access speculation
365*4882a593Smuzhiyun * - no repetition (eg, on return from an exception)
366*4882a593Smuzhiyun * - number, order and size of accesses are maintained
367*4882a593Smuzhiyun * - unaligned accesses are "unpredictable"
368*4882a593Smuzhiyun * - writes may be delayed before they hit the endpoint device
369*4882a593Smuzhiyun *
370*4882a593Smuzhiyun * All normal memory mappings have the following properties:
371*4882a593Smuzhiyun * - reads can be repeated with no side effects
372*4882a593Smuzhiyun * - repeated reads return the last value written
373*4882a593Smuzhiyun * - reads can fetch additional locations without side effects
374*4882a593Smuzhiyun * - writes can be repeated (in certain cases) with no side effects
375*4882a593Smuzhiyun * - writes can be merged before accessing the target
376*4882a593Smuzhiyun * - unaligned accesses can be supported
377*4882a593Smuzhiyun * - ordering is not guaranteed without explicit dependencies or barrier
378*4882a593Smuzhiyun * instructions
379*4882a593Smuzhiyun * - writes may be delayed before they hit the endpoint memory
380*4882a593Smuzhiyun *
381*4882a593Smuzhiyun * The cache hint is only a performance hint: CPUs may alias these hints.
382*4882a593Smuzhiyun * Eg, a CPU not implementing read allocate but implementing write allocate
383*4882a593Smuzhiyun * will provide a write allocate mapping instead.
384*4882a593Smuzhiyun */
385*4882a593Smuzhiyun void __iomem *ioremap(resource_size_t res_cookie, size_t size);
386*4882a593Smuzhiyun #define ioremap ioremap
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun /*
389*4882a593Smuzhiyun * Do not use ioremap_cache for mapping memory. Use memremap instead.
390*4882a593Smuzhiyun */
391*4882a593Smuzhiyun void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size);
392*4882a593Smuzhiyun #define ioremap_cache ioremap_cache
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
395*4882a593Smuzhiyun #define ioremap_wc ioremap_wc
396*4882a593Smuzhiyun #define ioremap_wt ioremap_wc
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun void iounmap(volatile void __iomem *iomem_cookie);
399*4882a593Smuzhiyun #define iounmap iounmap
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun void *arch_memremap_wb(phys_addr_t phys_addr, size_t size);
402*4882a593Smuzhiyun #define arch_memremap_wb arch_memremap_wb
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun /*
405*4882a593Smuzhiyun * io{read,write}{16,32}be() macros
406*4882a593Smuzhiyun */
407*4882a593Smuzhiyun #define ioread16be(p) ({ __u16 __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
408*4882a593Smuzhiyun #define ioread32be(p) ({ __u32 __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun #define iowrite16be(v,p) ({ __iowmb(); __raw_writew((__force __u16)cpu_to_be16(v), p); })
411*4882a593Smuzhiyun #define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun #ifndef ioport_map
414*4882a593Smuzhiyun #define ioport_map ioport_map
415*4882a593Smuzhiyun extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
416*4882a593Smuzhiyun #endif
417*4882a593Smuzhiyun #ifndef ioport_unmap
418*4882a593Smuzhiyun #define ioport_unmap ioport_unmap
419*4882a593Smuzhiyun extern void ioport_unmap(void __iomem *addr);
420*4882a593Smuzhiyun #endif
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun struct pci_dev;
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun #define pci_iounmap pci_iounmap
425*4882a593Smuzhiyun extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun /*
428*4882a593Smuzhiyun * Convert a physical pointer to a virtual kernel pointer for /dev/mem
429*4882a593Smuzhiyun * access
430*4882a593Smuzhiyun */
431*4882a593Smuzhiyun #define xlate_dev_mem_ptr(p) __va(p)
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun /*
434*4882a593Smuzhiyun * Convert a virtual cached pointer to an uncached pointer
435*4882a593Smuzhiyun */
436*4882a593Smuzhiyun #define xlate_dev_kmem_ptr(p) p
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun #include <asm-generic/io.h>
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun #ifdef CONFIG_MMU
441*4882a593Smuzhiyun #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
442*4882a593Smuzhiyun extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
443*4882a593Smuzhiyun extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
444*4882a593Smuzhiyun extern int devmem_is_allowed(unsigned long pfn);
445*4882a593Smuzhiyun extern bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
446*4882a593Smuzhiyun unsigned long flags);
447*4882a593Smuzhiyun #define arch_memremap_can_ram_remap arch_memremap_can_ram_remap
448*4882a593Smuzhiyun #endif
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Register ISA memory and port locations for glibc iopl/inb/outb
452*4882a593Smuzhiyun * emulation.
453*4882a593Smuzhiyun */
454*4882a593Smuzhiyun extern void register_isa_ports(unsigned int mmio, unsigned int io,
455*4882a593Smuzhiyun unsigned int io_shift);
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun #endif /* __KERNEL__ */
458*4882a593Smuzhiyun #endif /* __ASM_ARM_IO_H */
459