1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
24baa9922SRussell King /*
34baa9922SRussell King * arch/arm/include/asm/io.h
44baa9922SRussell King *
54baa9922SRussell King * Copyright (C) 1996-2000 Russell King
64baa9922SRussell King *
74baa9922SRussell King * Modifications:
84baa9922SRussell King * 16-Sep-1996 RMK Inlined the inx/outx functions & optimised for both
94baa9922SRussell King * constant addresses and variable addresses.
104baa9922SRussell King * 04-Dec-1997 RMK Moved a lot of this stuff to the new architecture
114baa9922SRussell King * specific IO header files.
124baa9922SRussell King * 27-Mar-1999 PJB Second parameter of memcpy_toio is const..
134baa9922SRussell King * 04-Apr-1999 PJB Added check_signature.
144baa9922SRussell King * 12-Dec-1999 RMK More cleanups
154baa9922SRussell King * 18-Jun-2000 RMK Removed virt_to_* and friends definitions
164baa9922SRussell King * 05-Oct-2004 BJD Moved memory string functions to use void __iomem
174baa9922SRussell King */
184baa9922SRussell King #ifndef __ASM_ARM_IO_H
194baa9922SRussell King #define __ASM_ARM_IO_H
204baa9922SRussell King
214baa9922SRussell King #ifdef __KERNEL__
224baa9922SRussell King
237ddfe625SRussell King #include <linux/string.h>
244baa9922SRussell King #include <linux/types.h>
254baa9922SRussell King #include <asm/byteorder.h>
26*a9ff6961SLinus Walleij #include <asm/page.h>
27e5bfb72cSMichael S. Tsirkin #include <asm-generic/pci_iomap.h>
284baa9922SRussell King
294baa9922SRussell King /*
304baa9922SRussell King * ISA I/O bus memory addresses are 1:1 with the physical address.
314baa9922SRussell King */
324baa9922SRussell King #define isa_virt_to_bus virt_to_phys
334baa9922SRussell King #define isa_bus_to_virt phys_to_virt
344baa9922SRussell King
354baa9922SRussell King /*
36c5ca95b5SEzequiel Garcia * Atomic MMIO-wide IO modify
37c5ca95b5SEzequiel Garcia */
38c5ca95b5SEzequiel Garcia extern void atomic_io_modify(void __iomem *reg, u32 mask, u32 set);
39c5ca95b5SEzequiel Garcia extern void atomic_io_modify_relaxed(void __iomem *reg, u32 mask, u32 set);
40c5ca95b5SEzequiel Garcia
41c5ca95b5SEzequiel Garcia /*
424baa9922SRussell King * Generic IO read/write. These perform native-endian accesses. Note
434baa9922SRussell King * that some architectures will want to re-define __raw_{read,write}w.
444baa9922SRussell King */
4584c4d3a6SThierry Reding void __raw_writesb(volatile void __iomem *addr, const void *data, int bytelen);
4684c4d3a6SThierry Reding void __raw_writesw(volatile void __iomem *addr, const void *data, int wordlen);
4784c4d3a6SThierry Reding void __raw_writesl(volatile void __iomem *addr, const void *data, int longlen);
484baa9922SRussell King
4984c4d3a6SThierry Reding void __raw_readsb(const volatile void __iomem *addr, void *data, int bytelen);
5084c4d3a6SThierry Reding void __raw_readsw(const volatile void __iomem *addr, void *data, int wordlen);
5184c4d3a6SThierry Reding void __raw_readsl(const volatile void __iomem *addr, void *data, int longlen);
524baa9922SRussell King
53195bbcacSWill Deacon #if __LINUX_ARM_ARCH__ < 6
54195bbcacSWill Deacon /*
55195bbcacSWill Deacon * Half-word accesses are problematic with RiscPC due to limitations of
56195bbcacSWill Deacon * the bus. Rather than special-case the machine, just let the compiler
57195bbcacSWill Deacon * generate the access for CPUs prior to ARMv6.
58195bbcacSWill Deacon */
594baa9922SRussell King #define __raw_readw(a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
60195bbcacSWill Deacon #define __raw_writew(v,a) ((void)(__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v)))
61195bbcacSWill Deacon #else
62195bbcacSWill Deacon /*
63195bbcacSWill Deacon * When running under a hypervisor, we want to avoid I/O accesses with
64195bbcacSWill Deacon * writeback addressing modes as these incur a significant performance
65195bbcacSWill Deacon * overhead (the address generation must be emulated in software).
66195bbcacSWill Deacon */
6784c4d3a6SThierry Reding #define __raw_writew __raw_writew
__raw_writew(u16 val,volatile void __iomem * addr)68195bbcacSWill Deacon static inline void __raw_writew(u16 val, volatile void __iomem *addr)
69195bbcacSWill Deacon {
70195bbcacSWill Deacon asm volatile("strh %1, %0"
715bb5d66dSPeter Hurley : : "Q" (*(volatile u16 __force *)addr), "r" (val));
72195bbcacSWill Deacon }
73195bbcacSWill Deacon
7484c4d3a6SThierry Reding #define __raw_readw __raw_readw
__raw_readw(const volatile void __iomem * addr)75195bbcacSWill Deacon static inline u16 __raw_readw(const volatile void __iomem *addr)
76195bbcacSWill Deacon {
77195bbcacSWill Deacon u16 val;
785bb5d66dSPeter Hurley asm volatile("ldrh %0, %1"
795bb5d66dSPeter Hurley : "=r" (val)
805bb5d66dSPeter Hurley : "Q" (*(volatile u16 __force *)addr));
81195bbcacSWill Deacon return val;
82195bbcacSWill Deacon }
83195bbcacSWill Deacon #endif
84195bbcacSWill Deacon
8584c4d3a6SThierry Reding #define __raw_writeb __raw_writeb
__raw_writeb(u8 val,volatile void __iomem * addr)86195bbcacSWill Deacon static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
87195bbcacSWill Deacon {
88195bbcacSWill Deacon asm volatile("strb %1, %0"
895bb5d66dSPeter Hurley : : "Qo" (*(volatile u8 __force *)addr), "r" (val));
90195bbcacSWill Deacon }
91195bbcacSWill Deacon
9284c4d3a6SThierry Reding #define __raw_writel __raw_writel
__raw_writel(u32 val,volatile void __iomem * addr)93195bbcacSWill Deacon static inline void __raw_writel(u32 val, volatile void __iomem *addr)
94195bbcacSWill Deacon {
95195bbcacSWill Deacon asm volatile("str %1, %0"
965bb5d66dSPeter Hurley : : "Qo" (*(volatile u32 __force *)addr), "r" (val));
97195bbcacSWill Deacon }
98195bbcacSWill Deacon
9984c4d3a6SThierry Reding #define __raw_readb __raw_readb
__raw_readb(const volatile void __iomem * addr)100195bbcacSWill Deacon static inline u8 __raw_readb(const volatile void __iomem *addr)
101195bbcacSWill Deacon {
102195bbcacSWill Deacon u8 val;
1035bb5d66dSPeter Hurley asm volatile("ldrb %0, %1"
1045bb5d66dSPeter Hurley : "=r" (val)
1055bb5d66dSPeter Hurley : "Qo" (*(volatile u8 __force *)addr));
106195bbcacSWill Deacon return val;
107195bbcacSWill Deacon }
108195bbcacSWill Deacon
10984c4d3a6SThierry Reding #define __raw_readl __raw_readl
__raw_readl(const volatile void __iomem * addr)110195bbcacSWill Deacon static inline u32 __raw_readl(const volatile void __iomem *addr)
111195bbcacSWill Deacon {
112195bbcacSWill Deacon u32 val;
1135bb5d66dSPeter Hurley asm volatile("ldr %0, %1"
1145bb5d66dSPeter Hurley : "=r" (val)
1155bb5d66dSPeter Hurley : "Qo" (*(volatile u32 __force *)addr));
116195bbcacSWill Deacon return val;
117195bbcacSWill Deacon }
1184baa9922SRussell King
1194baa9922SRussell King /*
1204baa9922SRussell King * Architecture ioremap implementation.
1214baa9922SRussell King */
1224baa9922SRussell King #define MT_DEVICE 0
1234baa9922SRussell King #define MT_DEVICE_NONSHARED 1
1244baa9922SRussell King #define MT_DEVICE_CACHED 2
125db5b7169SRussell King #define MT_DEVICE_WC 3
1264baa9922SRussell King /*
127db5b7169SRussell King * types 4 onwards can be found in asm/mach/map.h and are undefined
1284baa9922SRussell King * for ioremap
1294baa9922SRussell King */
1304baa9922SRussell King
1314baa9922SRussell King /*
1324baa9922SRussell King * __arm_ioremap takes CPU physical address.
1334baa9922SRussell King * __arm_ioremap_pfn takes a Page Frame Number and an offset into that page
13431aa8fd6SRussell King * The _caller variety takes a __builtin_return_address(0) value for
13531aa8fd6SRussell King * /proc/vmalloc to use - and should only be used in non-inline functions.
1364baa9922SRussell King */
1379b97173eSLaura Abbott extern void __iomem *__arm_ioremap_caller(phys_addr_t, size_t, unsigned int,
13831aa8fd6SRussell King void *);
1394baa9922SRussell King extern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int);
1409b97173eSLaura Abbott extern void __iomem *__arm_ioremap_exec(phys_addr_t, size_t, bool cached);
141b8bc0e50SRussell King (Oracle) void __arm_iomem_set_ro(void __iomem *ptr, size_t size);
1424fe7ef3aSRob Herring
1439b97173eSLaura Abbott extern void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t,
1444fe7ef3aSRob Herring unsigned int, void *);
1454baa9922SRussell King
1464baa9922SRussell King /*
1474baa9922SRussell King * Bad read/write accesses...
1484baa9922SRussell King */
1494baa9922SRussell King extern void __readwrite_bug(const char *fn);
1504baa9922SRussell King
1514baa9922SRussell King /*
1520560cf5aSRussell King * A typesafe __io() helper
1530560cf5aSRussell King */
__typesafe_io(unsigned long addr)1540560cf5aSRussell King static inline void __iomem *__typesafe_io(unsigned long addr)
1550560cf5aSRussell King {
1560560cf5aSRussell King return (void __iomem *)addr;
1570560cf5aSRussell King }
1580560cf5aSRussell King
1596f6f6a70SRob Herring #define IOMEM(x) ((void __force __iomem *)(x))
1606f6f6a70SRob Herring
161c1928022SRussell King /* IO barriers */
162c1928022SRussell King #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
1639f97da78SDavid Howells #include <asm/barrier.h>
164c1928022SRussell King #define __iormb() rmb()
165c1928022SRussell King #define __iowmb() wmb()
166c1928022SRussell King #else
167c1928022SRussell King #define __iormb() do { } while (0)
168c1928022SRussell King #define __iowmb() do { } while (0)
169c1928022SRussell King #endif
170c1928022SRussell King
171c2794437SRob Herring /* PCI fixed i/o mapping */
172c2794437SRob Herring #define PCI_IO_VIRT_BASE 0xfee00000
173dad13e3cSLiviu Dudau #define PCI_IOBASE ((void __iomem *)PCI_IO_VIRT_BASE)
174c2794437SRob Herring
175645b3026SArnd Bergmann #if defined(CONFIG_PCI) || IS_ENABLED(CONFIG_PCMCIA)
1761c8c3cf0SThomas Petazzoni void pci_ioremap_set_mem_type(int mem_type);
1771c8c3cf0SThomas Petazzoni #else
pci_ioremap_set_mem_type(int mem_type)1781c8c3cf0SThomas Petazzoni static inline void pci_ioremap_set_mem_type(int mem_type) {}
1791c8c3cf0SThomas Petazzoni #endif
1801c8c3cf0SThomas Petazzoni
181bc02973aSPali Rohár struct resource;
182bc02973aSPali Rohár
183bc02973aSPali Rohár #define pci_remap_iospace pci_remap_iospace
184bc02973aSPali Rohár int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
185bc02973aSPali Rohár
1860560cf5aSRussell King /*
187b9cdbe6eSLorenzo Pieralisi * PCI configuration space mapping function.
188b9cdbe6eSLorenzo Pieralisi *
189b9cdbe6eSLorenzo Pieralisi * The PCI specification does not allow configuration write
190b9cdbe6eSLorenzo Pieralisi * transactions to be posted. Add an arch specific
191b9cdbe6eSLorenzo Pieralisi * pci_remap_cfgspace() definition that is implemented
192b9cdbe6eSLorenzo Pieralisi * through strongly ordered memory mappings.
193b9cdbe6eSLorenzo Pieralisi */
194b9cdbe6eSLorenzo Pieralisi #define pci_remap_cfgspace pci_remap_cfgspace
195b9cdbe6eSLorenzo Pieralisi void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size);
196b9cdbe6eSLorenzo Pieralisi /*
1974baa9922SRussell King * Now, pick up the machine-defined IO definitions
1984baa9922SRussell King */
199c334bc15SRob Herring #ifdef CONFIG_NEED_MACH_IO_H
200a09e64fbSRussell King #include <mach/io.h>
201c334bc15SRob Herring #else
202645b3026SArnd Bergmann #if IS_ENABLED(CONFIG_PCMCIA) || defined(CONFIG_PCI)
203645b3026SArnd Bergmann #define IO_SPACE_LIMIT ((resource_size_t)0xfffff)
20404e1c838SRussell King #else
20504e1c838SRussell King #define IO_SPACE_LIMIT ((resource_size_t)0)
20604e1c838SRussell King #endif
207645b3026SArnd Bergmann #define __io(a) __typesafe_io(PCI_IO_VIRT_BASE + ((a) & IO_SPACE_LIMIT))
20804e1c838SRussell King #endif
20904e1c838SRussell King
21004e1c838SRussell King /*
2114baa9922SRussell King * IO port access primitives
2124baa9922SRussell King * -------------------------
2134baa9922SRussell King *
2144baa9922SRussell King * The ARM doesn't have special IO access instructions; all IO is memory
2154baa9922SRussell King * mapped. Note that these are defined to perform little endian accesses
2164baa9922SRussell King * only. Their primary purpose is to access PCI and ISA peripherals.
2174baa9922SRussell King *
2184baa9922SRussell King * Note that for a big endian machine, this implies that the following
2194baa9922SRussell King * big endian mode connectivity is in place, as described by numerous
2204baa9922SRussell King * ARM documents:
2214baa9922SRussell King *
2224baa9922SRussell King * PCI: D0-D7 D8-D15 D16-D23 D24-D31
2234baa9922SRussell King * ARM: D24-D31 D16-D23 D8-D15 D0-D7
2244baa9922SRussell King *
2254baa9922SRussell King * The machine specific io.h include defines __io to translate an "IO"
2264baa9922SRussell King * address to a memory address.
2274baa9922SRussell King *
2284baa9922SRussell King * Note that we prevent GCC re-ordering or caching values in expressions
2294baa9922SRussell King * by introducing sequence points into the in*() definitions. Note that
2304baa9922SRussell King * __raw_* do not guarantee this behaviour.
2314baa9922SRussell King *
2324baa9922SRussell King * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
2334baa9922SRussell King */
2344baa9922SRussell King #ifdef __io
235c1928022SRussell King #define outb(v,p) ({ __iowmb(); __raw_writeb(v,__io(p)); })
236c1928022SRussell King #define outw(v,p) ({ __iowmb(); __raw_writew((__force __u16) \
237c1928022SRussell King cpu_to_le16(v),__io(p)); })
238c1928022SRussell King #define outl(v,p) ({ __iowmb(); __raw_writel((__force __u32) \
239c1928022SRussell King cpu_to_le32(v),__io(p)); })
2404baa9922SRussell King
241c1928022SRussell King #define inb(p) ({ __u8 __v = __raw_readb(__io(p)); __iormb(); __v; })
2424baa9922SRussell King #define inw(p) ({ __u16 __v = le16_to_cpu((__force __le16) \
243c1928022SRussell King __raw_readw(__io(p))); __iormb(); __v; })
2444baa9922SRussell King #define inl(p) ({ __u32 __v = le32_to_cpu((__force __le32) \
245c1928022SRussell King __raw_readl(__io(p))); __iormb(); __v; })
2464baa9922SRussell King
2474baa9922SRussell King #define outsb(p,d,l) __raw_writesb(__io(p),d,l)
2484baa9922SRussell King #define outsw(p,d,l) __raw_writesw(__io(p),d,l)
2494baa9922SRussell King #define outsl(p,d,l) __raw_writesl(__io(p),d,l)
2504baa9922SRussell King
2514baa9922SRussell King #define insb(p,d,l) __raw_readsb(__io(p),d,l)
2524baa9922SRussell King #define insw(p,d,l) __raw_readsw(__io(p),d,l)
2534baa9922SRussell King #define insl(p,d,l) __raw_readsl(__io(p),d,l)
2544baa9922SRussell King #endif
2554baa9922SRussell King
2564baa9922SRussell King /*
2574baa9922SRussell King * String version of IO memory access ops:
2584baa9922SRussell King */
2594baa9922SRussell King extern void _memcpy_fromio(void *, const volatile void __iomem *, size_t);
2604baa9922SRussell King extern void _memcpy_toio(volatile void __iomem *, const void *, size_t);
2614baa9922SRussell King extern void _memset_io(volatile void __iomem *, int, size_t);
2624baa9922SRussell King
2634baa9922SRussell King /*
2644baa9922SRussell King * Memory access primitives
2654baa9922SRussell King * ------------------------
2664baa9922SRussell King *
2674baa9922SRussell King * These perform PCI memory accesses via an ioremap region. They don't
2684baa9922SRussell King * take an address as such, but a cookie.
2694baa9922SRussell King *
27079a3bd89SAndrew F. Davis * Again, these are defined to perform little endian accesses. See the
2714baa9922SRussell King * IO port primitives for more information.
2724baa9922SRussell King */
2735621caacSRob Herring #ifndef readl
2745621caacSRob Herring #define readb_relaxed(c) ({ u8 __r = __raw_readb(c); __r; })
275b0c1264fSOlof Johansson #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
2765621caacSRob Herring __raw_readw(c)); __r; })
277b0c1264fSOlof Johansson #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
2785621caacSRob Herring __raw_readl(c)); __r; })
279e936771aSCatalin Marinas
280af06bb9fSRussell King #define writeb_relaxed(v,c) __raw_writeb(v,c)
281af06bb9fSRussell King #define writew_relaxed(v,c) __raw_writew((__force u16) cpu_to_le16(v),c)
282af06bb9fSRussell King #define writel_relaxed(v,c) __raw_writel((__force u32) cpu_to_le32(v),c)
283e936771aSCatalin Marinas
284b92b3612SRussell King #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
285b92b3612SRussell King #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
286b92b3612SRussell King #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
287b92b3612SRussell King
288b92b3612SRussell King #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
289b92b3612SRussell King #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
290b92b3612SRussell King #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
291b92b3612SRussell King
2925621caacSRob Herring #define readsb(p,d,l) __raw_readsb(p,d,l)
2935621caacSRob Herring #define readsw(p,d,l) __raw_readsw(p,d,l)
2945621caacSRob Herring #define readsl(p,d,l) __raw_readsl(p,d,l)
2954baa9922SRussell King
2965621caacSRob Herring #define writesb(p,d,l) __raw_writesb(p,d,l)
2975621caacSRob Herring #define writesw(p,d,l) __raw_writesw(p,d,l)
2985621caacSRob Herring #define writesl(p,d,l) __raw_writesl(p,d,l)
2994baa9922SRussell King
3007ddfe625SRussell King #ifndef __ARMBE__
memset_io(volatile void __iomem * dst,unsigned c,size_t count)3017ddfe625SRussell King static inline void memset_io(volatile void __iomem *dst, unsigned c,
3027ddfe625SRussell King size_t count)
3037ddfe625SRussell King {
3041bd46782SRussell King extern void mmioset(void *, unsigned int, size_t);
3051bd46782SRussell King mmioset((void __force *)dst, c, count);
3067ddfe625SRussell King }
3077ddfe625SRussell King #define memset_io(dst,c,count) memset_io(dst,c,count)
3087ddfe625SRussell King
memcpy_fromio(void * to,const volatile void __iomem * from,size_t count)3097ddfe625SRussell King static inline void memcpy_fromio(void *to, const volatile void __iomem *from,
3107ddfe625SRussell King size_t count)
3117ddfe625SRussell King {
3121bd46782SRussell King extern void mmiocpy(void *, const void *, size_t);
3131bd46782SRussell King mmiocpy(to, (const void __force *)from, count);
3147ddfe625SRussell King }
3157ddfe625SRussell King #define memcpy_fromio(to,from,count) memcpy_fromio(to,from,count)
3167ddfe625SRussell King
memcpy_toio(volatile void __iomem * to,const void * from,size_t count)3177ddfe625SRussell King static inline void memcpy_toio(volatile void __iomem *to, const void *from,
3187ddfe625SRussell King size_t count)
3197ddfe625SRussell King {
3201bd46782SRussell King extern void mmiocpy(void *, const void *, size_t);
3211bd46782SRussell King mmiocpy((void __force *)to, from, count);
3227ddfe625SRussell King }
3237ddfe625SRussell King #define memcpy_toio(to,from,count) memcpy_toio(to,from,count)
3247ddfe625SRussell King
3257ddfe625SRussell King #else
3265621caacSRob Herring #define memset_io(c,v,l) _memset_io(c,(v),(l))
3275621caacSRob Herring #define memcpy_fromio(a,c,l) _memcpy_fromio((a),c,(l))
3285621caacSRob Herring #define memcpy_toio(c,a,l) _memcpy_toio(c,(a),(l))
3297ddfe625SRussell King #endif
3304baa9922SRussell King
3315621caacSRob Herring #endif /* readl */
3324baa9922SRussell King
3334baa9922SRussell King /*
334ac5e2f17SRussell King * ioremap() and friends.
3354baa9922SRussell King *
336ac5e2f17SRussell King * ioremap() takes a resource address, and size. Due to the ARM memory
337ac5e2f17SRussell King * types, it is important to use the correct ioremap() function as each
338ac5e2f17SRussell King * mapping has specific properties.
3394baa9922SRussell King *
340ac5e2f17SRussell King * Function Memory type Cacheability Cache hint
341ac5e2f17SRussell King * ioremap() Device n/a n/a
342ac5e2f17SRussell King * ioremap_cache() Normal Writeback Read allocate
343ac5e2f17SRussell King * ioremap_wc() Normal Non-cacheable n/a
344ac5e2f17SRussell King * ioremap_wt() Normal Non-cacheable n/a
345ac5e2f17SRussell King *
346ac5e2f17SRussell King * All device mappings have the following properties:
347ac5e2f17SRussell King * - no access speculation
348ac5e2f17SRussell King * - no repetition (eg, on return from an exception)
349ac5e2f17SRussell King * - number, order and size of accesses are maintained
350ac5e2f17SRussell King * - unaligned accesses are "unpredictable"
351ac5e2f17SRussell King * - writes may be delayed before they hit the endpoint device
352ac5e2f17SRussell King *
353ac5e2f17SRussell King * All normal memory mappings have the following properties:
354ac5e2f17SRussell King * - reads can be repeated with no side effects
355ac5e2f17SRussell King * - repeated reads return the last value written
356ac5e2f17SRussell King * - reads can fetch additional locations without side effects
357ac5e2f17SRussell King * - writes can be repeated (in certain cases) with no side effects
358ac5e2f17SRussell King * - writes can be merged before accessing the target
359ac5e2f17SRussell King * - unaligned accesses can be supported
360ac5e2f17SRussell King * - ordering is not guaranteed without explicit dependencies or barrier
361ac5e2f17SRussell King * instructions
362ac5e2f17SRussell King * - writes may be delayed before they hit the endpoint memory
363ac5e2f17SRussell King *
364ac5e2f17SRussell King * The cache hint is only a performance hint: CPUs may alias these hints.
365ac5e2f17SRussell King * Eg, a CPU not implementing read allocate but implementing write allocate
366ac5e2f17SRussell King * will provide a write allocate mapping instead.
3674baa9922SRussell King */
36820a1080dSRussell King void __iomem *ioremap(resource_size_t res_cookie, size_t size);
36920a1080dSRussell King #define ioremap ioremap
37020a1080dSRussell King
3719ab9e4fcSArd Biesheuvel /*
3729ab9e4fcSArd Biesheuvel * Do not use ioremap_cache for mapping memory. Use memremap instead.
3739ab9e4fcSArd Biesheuvel */
37420a1080dSRussell King void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size);
37520a1080dSRussell King #define ioremap_cache ioremap_cache
37620a1080dSRussell King
37720a1080dSRussell King void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
37820a1080dSRussell King #define ioremap_wc ioremap_wc
37920a1080dSRussell King #define ioremap_wt ioremap_wc
38020a1080dSRussell King
381d803336aSKefeng Wang void iounmap(volatile void __iomem *io_addr);
38220a1080dSRussell King #define iounmap iounmap
3834baa9922SRussell King
3849ab9e4fcSArd Biesheuvel void *arch_memremap_wb(phys_addr_t phys_addr, size_t size);
3859ab9e4fcSArd Biesheuvel #define arch_memremap_wb arch_memremap_wb
3869ab9e4fcSArd Biesheuvel
3874baa9922SRussell King /*
38884c4d3a6SThierry Reding * io{read,write}{16,32}be() macros
3894baa9922SRussell King */
39084c4d3a6SThierry Reding #define ioread16be(p) ({ __u16 __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
39184c4d3a6SThierry Reding #define ioread32be(p) ({ __u32 __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
3924baa9922SRussell King
393af06bb9fSRussell King #define iowrite16be(v,p) ({ __iowmb(); __raw_writew((__force __u16)cpu_to_be16(v), p); })
394af06bb9fSRussell King #define iowrite32be(v,p) ({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
39506901bd8SArnd Bergmann
39684c4d3a6SThierry Reding #ifndef ioport_map
39784c4d3a6SThierry Reding #define ioport_map ioport_map
3984baa9922SRussell King extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
39984c4d3a6SThierry Reding #endif
40084c4d3a6SThierry Reding #ifndef ioport_unmap
40184c4d3a6SThierry Reding #define ioport_unmap ioport_unmap
4024baa9922SRussell King extern void ioport_unmap(void __iomem *addr);
4034baa9922SRussell King #endif
4044baa9922SRussell King
4054baa9922SRussell King struct pci_dev;
4064baa9922SRussell King
40784c4d3a6SThierry Reding #define pci_iounmap pci_iounmap
4084baa9922SRussell King extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
4094baa9922SRussell King
4104baa9922SRussell King /*
41184c4d3a6SThierry Reding * Convert a physical pointer to a virtual kernel pointer for /dev/mem
41284c4d3a6SThierry Reding * access
41384c4d3a6SThierry Reding */
41484c4d3a6SThierry Reding #define xlate_dev_mem_ptr(p) __va(p)
41584c4d3a6SThierry Reding
41684c4d3a6SThierry Reding #include <asm-generic/io.h>
41784c4d3a6SThierry Reding
4184baa9922SRussell King #ifdef CONFIG_MMU
4194baa9922SRussell King #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
4207e6735c3SCyril Chemparathy extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
4214baa9922SRussell King extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
422260364d1SMike Rapoport extern bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
423260364d1SMike Rapoport unsigned long flags);
424260364d1SMike Rapoport #define arch_memremap_can_ram_remap arch_memremap_can_ram_remap
4254baa9922SRussell King #endif
4264baa9922SRussell King
4274baa9922SRussell King /*
4284baa9922SRussell King * Register ISA memory and port locations for glibc iopl/inb/outb
4294baa9922SRussell King * emulation.
4304baa9922SRussell King */
4314baa9922SRussell King extern void register_isa_ports(unsigned int mmio, unsigned int io,
4324baa9922SRussell King unsigned int io_shift);
4334baa9922SRussell King
4344baa9922SRussell King #endif /* __KERNEL__ */
4354baa9922SRussell King #endif /* __ASM_ARM_IO_H */
436