18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  arch/arm/include/asm/io.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 1996-2000 Russell King
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Modifications:
88c2ecf20Sopenharmony_ci *  16-Sep-1996	RMK	Inlined the inx/outx functions & optimised for both
98c2ecf20Sopenharmony_ci *			constant addresses and variable addresses.
108c2ecf20Sopenharmony_ci *  04-Dec-1997	RMK	Moved a lot of this stuff to the new architecture
118c2ecf20Sopenharmony_ci *			specific IO header files.
128c2ecf20Sopenharmony_ci *  27-Mar-1999	PJB	Second parameter of memcpy_toio is const..
138c2ecf20Sopenharmony_ci *  04-Apr-1999	PJB	Added check_signature.
148c2ecf20Sopenharmony_ci *  12-Dec-1999	RMK	More cleanups
158c2ecf20Sopenharmony_ci *  18-Jun-2000 RMK	Removed virt_to_* and friends definitions
168c2ecf20Sopenharmony_ci *  05-Oct-2004 BJD     Moved memory string functions to use void __iomem
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#ifndef __ASM_ARM_IO_H
198c2ecf20Sopenharmony_ci#define __ASM_ARM_IO_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifdef __KERNEL__
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <linux/string.h>
248c2ecf20Sopenharmony_ci#include <linux/types.h>
258c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
268c2ecf20Sopenharmony_ci#include <asm/memory.h>
278c2ecf20Sopenharmony_ci#include <asm-generic/pci_iomap.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * ISA I/O bus memory addresses are 1:1 with the physical address.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#define isa_virt_to_bus virt_to_phys
338c2ecf20Sopenharmony_ci#define isa_bus_to_virt phys_to_virt
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * Atomic MMIO-wide IO modify
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ciextern void atomic_io_modify(void __iomem *reg, u32 mask, u32 set);
398c2ecf20Sopenharmony_ciextern void atomic_io_modify_relaxed(void __iomem *reg, u32 mask, u32 set);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Generic IO read/write.  These perform native-endian accesses.  Note
438c2ecf20Sopenharmony_ci * that some architectures will want to re-define __raw_{read,write}w.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_civoid __raw_writesb(volatile void __iomem *addr, const void *data, int bytelen);
468c2ecf20Sopenharmony_civoid __raw_writesw(volatile void __iomem *addr, const void *data, int wordlen);
478c2ecf20Sopenharmony_civoid __raw_writesl(volatile void __iomem *addr, const void *data, int longlen);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_civoid __raw_readsb(const volatile void __iomem *addr, void *data, int bytelen);
508c2ecf20Sopenharmony_civoid __raw_readsw(const volatile void __iomem *addr, void *data, int wordlen);
518c2ecf20Sopenharmony_civoid __raw_readsl(const volatile void __iomem *addr, void *data, int longlen);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#if __LINUX_ARM_ARCH__ < 6
548c2ecf20Sopenharmony_ci/*
558c2ecf20Sopenharmony_ci * Half-word accesses are problematic with RiscPC due to limitations of
568c2ecf20Sopenharmony_ci * the bus. Rather than special-case the machine, just let the compiler
578c2ecf20Sopenharmony_ci * generate the access for CPUs prior to ARMv6.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci#define __raw_readw(a)         (__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
608c2ecf20Sopenharmony_ci#define __raw_writew(v,a)      ((void)(__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v)))
618c2ecf20Sopenharmony_ci#else
628c2ecf20Sopenharmony_ci/*
638c2ecf20Sopenharmony_ci * When running under a hypervisor, we want to avoid I/O accesses with
648c2ecf20Sopenharmony_ci * writeback addressing modes as these incur a significant performance
658c2ecf20Sopenharmony_ci * overhead (the address generation must be emulated in software).
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_ci#define __raw_writew __raw_writew
688c2ecf20Sopenharmony_cistatic inline void __raw_writew(u16 val, volatile void __iomem *addr)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	asm volatile("strh %1, %0"
718c2ecf20Sopenharmony_ci		     : : "Q" (*(volatile u16 __force *)addr), "r" (val));
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define __raw_readw __raw_readw
758c2ecf20Sopenharmony_cistatic inline u16 __raw_readw(const volatile void __iomem *addr)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	u16 val;
788c2ecf20Sopenharmony_ci	asm volatile("ldrh %0, %1"
798c2ecf20Sopenharmony_ci		     : "=r" (val)
808c2ecf20Sopenharmony_ci		     : "Q" (*(volatile u16 __force *)addr));
818c2ecf20Sopenharmony_ci	return val;
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci#endif
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define __raw_writeb __raw_writeb
868c2ecf20Sopenharmony_cistatic inline void __raw_writeb(u8 val, volatile void __iomem *addr)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	asm volatile("strb %1, %0"
898c2ecf20Sopenharmony_ci		     : : "Qo" (*(volatile u8 __force *)addr), "r" (val));
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define __raw_writel __raw_writel
938c2ecf20Sopenharmony_cistatic inline void __raw_writel(u32 val, volatile void __iomem *addr)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	asm volatile("str %1, %0"
968c2ecf20Sopenharmony_ci		     : : "Qo" (*(volatile u32 __force *)addr), "r" (val));
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define __raw_readb __raw_readb
1008c2ecf20Sopenharmony_cistatic inline u8 __raw_readb(const volatile void __iomem *addr)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	u8 val;
1038c2ecf20Sopenharmony_ci	asm volatile("ldrb %0, %1"
1048c2ecf20Sopenharmony_ci		     : "=r" (val)
1058c2ecf20Sopenharmony_ci		     : "Qo" (*(volatile u8 __force *)addr));
1068c2ecf20Sopenharmony_ci	return val;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define __raw_readl __raw_readl
1108c2ecf20Sopenharmony_cistatic inline u32 __raw_readl(const volatile void __iomem *addr)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	u32 val;
1138c2ecf20Sopenharmony_ci	asm volatile("ldr %0, %1"
1148c2ecf20Sopenharmony_ci		     : "=r" (val)
1158c2ecf20Sopenharmony_ci		     : "Qo" (*(volatile u32 __force *)addr));
1168c2ecf20Sopenharmony_ci	return val;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/*
1208c2ecf20Sopenharmony_ci * Architecture ioremap implementation.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define MT_DEVICE		0
1238c2ecf20Sopenharmony_ci#define MT_DEVICE_NONSHARED	1
1248c2ecf20Sopenharmony_ci#define MT_DEVICE_CACHED	2
1258c2ecf20Sopenharmony_ci#define MT_DEVICE_WC		3
1268c2ecf20Sopenharmony_ci/*
1278c2ecf20Sopenharmony_ci * types 4 onwards can be found in asm/mach/map.h and are undefined
1288c2ecf20Sopenharmony_ci * for ioremap
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/*
1328c2ecf20Sopenharmony_ci * __arm_ioremap takes CPU physical address.
1338c2ecf20Sopenharmony_ci * __arm_ioremap_pfn takes a Page Frame Number and an offset into that page
1348c2ecf20Sopenharmony_ci * The _caller variety takes a __builtin_return_address(0) value for
1358c2ecf20Sopenharmony_ci * /proc/vmalloc to use - and should only be used in non-inline functions.
1368c2ecf20Sopenharmony_ci */
1378c2ecf20Sopenharmony_ciextern void __iomem *__arm_ioremap_caller(phys_addr_t, size_t, unsigned int,
1388c2ecf20Sopenharmony_ci	void *);
1398c2ecf20Sopenharmony_ciextern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int);
1408c2ecf20Sopenharmony_ciextern void __iomem *__arm_ioremap_exec(phys_addr_t, size_t, bool cached);
1418c2ecf20Sopenharmony_ciextern void __iounmap(volatile void __iomem *addr);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciextern void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t,
1448c2ecf20Sopenharmony_ci	unsigned int, void *);
1458c2ecf20Sopenharmony_ciextern void (*arch_iounmap)(volatile void __iomem *);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/*
1488c2ecf20Sopenharmony_ci * Bad read/write accesses...
1498c2ecf20Sopenharmony_ci */
1508c2ecf20Sopenharmony_ciextern void __readwrite_bug(const char *fn);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * A typesafe __io() helper
1548c2ecf20Sopenharmony_ci */
1558c2ecf20Sopenharmony_cistatic inline void __iomem *__typesafe_io(unsigned long addr)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	return (void __iomem *)addr;
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define IOMEM(x)	((void __force __iomem *)(x))
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* IO barriers */
1638c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
1648c2ecf20Sopenharmony_ci#include <asm/barrier.h>
1658c2ecf20Sopenharmony_ci#define __iormb()		rmb()
1668c2ecf20Sopenharmony_ci#define __iowmb()		wmb()
1678c2ecf20Sopenharmony_ci#else
1688c2ecf20Sopenharmony_ci#define __iormb()		do { } while (0)
1698c2ecf20Sopenharmony_ci#define __iowmb()		do { } while (0)
1708c2ecf20Sopenharmony_ci#endif
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* PCI fixed i/o mapping */
1738c2ecf20Sopenharmony_ci#define PCI_IO_VIRT_BASE	0xfee00000
1748c2ecf20Sopenharmony_ci#define PCI_IOBASE		((void __iomem *)PCI_IO_VIRT_BASE)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#if defined(CONFIG_PCI)
1778c2ecf20Sopenharmony_civoid pci_ioremap_set_mem_type(int mem_type);
1788c2ecf20Sopenharmony_ci#else
1798c2ecf20Sopenharmony_cistatic inline void pci_ioremap_set_mem_type(int mem_type) {}
1808c2ecf20Sopenharmony_ci#endif
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciextern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/*
1858c2ecf20Sopenharmony_ci * PCI configuration space mapping function.
1868c2ecf20Sopenharmony_ci *
1878c2ecf20Sopenharmony_ci * The PCI specification does not allow configuration write
1888c2ecf20Sopenharmony_ci * transactions to be posted. Add an arch specific
1898c2ecf20Sopenharmony_ci * pci_remap_cfgspace() definition that is implemented
1908c2ecf20Sopenharmony_ci * through strongly ordered memory mappings.
1918c2ecf20Sopenharmony_ci */
1928c2ecf20Sopenharmony_ci#define pci_remap_cfgspace pci_remap_cfgspace
1938c2ecf20Sopenharmony_civoid __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size);
1948c2ecf20Sopenharmony_ci/*
1958c2ecf20Sopenharmony_ci * Now, pick up the machine-defined IO definitions
1968c2ecf20Sopenharmony_ci */
1978c2ecf20Sopenharmony_ci#ifdef CONFIG_NEED_MACH_IO_H
1988c2ecf20Sopenharmony_ci#include <mach/io.h>
1998c2ecf20Sopenharmony_ci#elif defined(CONFIG_PCI)
2008c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT	((resource_size_t)0xfffff)
2018c2ecf20Sopenharmony_ci#define __io(a)		__typesafe_io(PCI_IO_VIRT_BASE + ((a) & IO_SPACE_LIMIT))
2028c2ecf20Sopenharmony_ci#else
2038c2ecf20Sopenharmony_ci#define __io(a)		__typesafe_io((a) & IO_SPACE_LIMIT)
2048c2ecf20Sopenharmony_ci#endif
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/*
2078c2ecf20Sopenharmony_ci * This is the limit of PC card/PCI/ISA IO space, which is by default
2088c2ecf20Sopenharmony_ci * 64K if we have PC card, PCI or ISA support.  Otherwise, default to
2098c2ecf20Sopenharmony_ci * zero to prevent ISA/PCI drivers claiming IO space (and potentially
2108c2ecf20Sopenharmony_ci * oopsing.)
2118c2ecf20Sopenharmony_ci *
2128c2ecf20Sopenharmony_ci * Only set this larger if you really need inb() et.al. to operate over
2138c2ecf20Sopenharmony_ci * a larger address space.  Note that SOC_COMMON ioremaps each sockets
2148c2ecf20Sopenharmony_ci * IO space area, and so inb() et.al. must be defined to operate as per
2158c2ecf20Sopenharmony_ci * readb() et.al. on such platforms.
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci#ifndef IO_SPACE_LIMIT
2188c2ecf20Sopenharmony_ci#if defined(CONFIG_PCMCIA_SOC_COMMON) || defined(CONFIG_PCMCIA_SOC_COMMON_MODULE)
2198c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT ((resource_size_t)0xffffffff)
2208c2ecf20Sopenharmony_ci#elif defined(CONFIG_PCI) || defined(CONFIG_ISA) || defined(CONFIG_PCCARD)
2218c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT ((resource_size_t)0xffff)
2228c2ecf20Sopenharmony_ci#else
2238c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT ((resource_size_t)0)
2248c2ecf20Sopenharmony_ci#endif
2258c2ecf20Sopenharmony_ci#endif
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci/*
2288c2ecf20Sopenharmony_ci *  IO port access primitives
2298c2ecf20Sopenharmony_ci *  -------------------------
2308c2ecf20Sopenharmony_ci *
2318c2ecf20Sopenharmony_ci * The ARM doesn't have special IO access instructions; all IO is memory
2328c2ecf20Sopenharmony_ci * mapped.  Note that these are defined to perform little endian accesses
2338c2ecf20Sopenharmony_ci * only.  Their primary purpose is to access PCI and ISA peripherals.
2348c2ecf20Sopenharmony_ci *
2358c2ecf20Sopenharmony_ci * Note that for a big endian machine, this implies that the following
2368c2ecf20Sopenharmony_ci * big endian mode connectivity is in place, as described by numerous
2378c2ecf20Sopenharmony_ci * ARM documents:
2388c2ecf20Sopenharmony_ci *
2398c2ecf20Sopenharmony_ci *    PCI:  D0-D7   D8-D15 D16-D23 D24-D31
2408c2ecf20Sopenharmony_ci *    ARM: D24-D31 D16-D23  D8-D15  D0-D7
2418c2ecf20Sopenharmony_ci *
2428c2ecf20Sopenharmony_ci * The machine specific io.h include defines __io to translate an "IO"
2438c2ecf20Sopenharmony_ci * address to a memory address.
2448c2ecf20Sopenharmony_ci *
2458c2ecf20Sopenharmony_ci * Note that we prevent GCC re-ordering or caching values in expressions
2468c2ecf20Sopenharmony_ci * by introducing sequence points into the in*() definitions.  Note that
2478c2ecf20Sopenharmony_ci * __raw_* do not guarantee this behaviour.
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
2508c2ecf20Sopenharmony_ci */
2518c2ecf20Sopenharmony_ci#ifdef __io
2528c2ecf20Sopenharmony_ci#define outb(v,p)	({ __iowmb(); __raw_writeb(v,__io(p)); })
2538c2ecf20Sopenharmony_ci#define outw(v,p)	({ __iowmb(); __raw_writew((__force __u16) \
2548c2ecf20Sopenharmony_ci					cpu_to_le16(v),__io(p)); })
2558c2ecf20Sopenharmony_ci#define outl(v,p)	({ __iowmb(); __raw_writel((__force __u32) \
2568c2ecf20Sopenharmony_ci					cpu_to_le32(v),__io(p)); })
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci#define inb(p)	({ __u8 __v = __raw_readb(__io(p)); __iormb(); __v; })
2598c2ecf20Sopenharmony_ci#define inw(p)	({ __u16 __v = le16_to_cpu((__force __le16) \
2608c2ecf20Sopenharmony_ci			__raw_readw(__io(p))); __iormb(); __v; })
2618c2ecf20Sopenharmony_ci#define inl(p)	({ __u32 __v = le32_to_cpu((__force __le32) \
2628c2ecf20Sopenharmony_ci			__raw_readl(__io(p))); __iormb(); __v; })
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#define outsb(p,d,l)		__raw_writesb(__io(p),d,l)
2658c2ecf20Sopenharmony_ci#define outsw(p,d,l)		__raw_writesw(__io(p),d,l)
2668c2ecf20Sopenharmony_ci#define outsl(p,d,l)		__raw_writesl(__io(p),d,l)
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci#define insb(p,d,l)		__raw_readsb(__io(p),d,l)
2698c2ecf20Sopenharmony_ci#define insw(p,d,l)		__raw_readsw(__io(p),d,l)
2708c2ecf20Sopenharmony_ci#define insl(p,d,l)		__raw_readsl(__io(p),d,l)
2718c2ecf20Sopenharmony_ci#endif
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci/*
2748c2ecf20Sopenharmony_ci * String version of IO memory access ops:
2758c2ecf20Sopenharmony_ci */
2768c2ecf20Sopenharmony_ciextern void _memcpy_fromio(void *, const volatile void __iomem *, size_t);
2778c2ecf20Sopenharmony_ciextern void _memcpy_toio(volatile void __iomem *, const void *, size_t);
2788c2ecf20Sopenharmony_ciextern void _memset_io(volatile void __iomem *, int, size_t);
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci/*
2818c2ecf20Sopenharmony_ci *  Memory access primitives
2828c2ecf20Sopenharmony_ci *  ------------------------
2838c2ecf20Sopenharmony_ci *
2848c2ecf20Sopenharmony_ci * These perform PCI memory accesses via an ioremap region.  They don't
2858c2ecf20Sopenharmony_ci * take an address as such, but a cookie.
2868c2ecf20Sopenharmony_ci *
2878c2ecf20Sopenharmony_ci * Again, these are defined to perform little endian accesses.  See the
2888c2ecf20Sopenharmony_ci * IO port primitives for more information.
2898c2ecf20Sopenharmony_ci */
2908c2ecf20Sopenharmony_ci#ifndef readl
2918c2ecf20Sopenharmony_ci#define readb_relaxed(c) ({ u8  __r = __raw_readb(c); __r; })
2928c2ecf20Sopenharmony_ci#define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
2938c2ecf20Sopenharmony_ci					__raw_readw(c)); __r; })
2948c2ecf20Sopenharmony_ci#define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
2958c2ecf20Sopenharmony_ci					__raw_readl(c)); __r; })
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci#define writeb_relaxed(v,c)	__raw_writeb(v,c)
2988c2ecf20Sopenharmony_ci#define writew_relaxed(v,c)	__raw_writew((__force u16) cpu_to_le16(v),c)
2998c2ecf20Sopenharmony_ci#define writel_relaxed(v,c)	__raw_writel((__force u32) cpu_to_le32(v),c)
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci#define readb(c)		({ u8  __v = readb_relaxed(c); __iormb(); __v; })
3028c2ecf20Sopenharmony_ci#define readw(c)		({ u16 __v = readw_relaxed(c); __iormb(); __v; })
3038c2ecf20Sopenharmony_ci#define readl(c)		({ u32 __v = readl_relaxed(c); __iormb(); __v; })
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define writeb(v,c)		({ __iowmb(); writeb_relaxed(v,c); })
3068c2ecf20Sopenharmony_ci#define writew(v,c)		({ __iowmb(); writew_relaxed(v,c); })
3078c2ecf20Sopenharmony_ci#define writel(v,c)		({ __iowmb(); writel_relaxed(v,c); })
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci#define readsb(p,d,l)		__raw_readsb(p,d,l)
3108c2ecf20Sopenharmony_ci#define readsw(p,d,l)		__raw_readsw(p,d,l)
3118c2ecf20Sopenharmony_ci#define readsl(p,d,l)		__raw_readsl(p,d,l)
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci#define writesb(p,d,l)		__raw_writesb(p,d,l)
3148c2ecf20Sopenharmony_ci#define writesw(p,d,l)		__raw_writesw(p,d,l)
3158c2ecf20Sopenharmony_ci#define writesl(p,d,l)		__raw_writesl(p,d,l)
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#ifndef __ARMBE__
3188c2ecf20Sopenharmony_cistatic inline void memset_io(volatile void __iomem *dst, unsigned c,
3198c2ecf20Sopenharmony_ci	size_t count)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	extern void mmioset(void *, unsigned int, size_t);
3228c2ecf20Sopenharmony_ci	mmioset((void __force *)dst, c, count);
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci#define memset_io(dst,c,count) memset_io(dst,c,count)
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cistatic inline void memcpy_fromio(void *to, const volatile void __iomem *from,
3278c2ecf20Sopenharmony_ci	size_t count)
3288c2ecf20Sopenharmony_ci{
3298c2ecf20Sopenharmony_ci	extern void mmiocpy(void *, const void *, size_t);
3308c2ecf20Sopenharmony_ci	mmiocpy(to, (const void __force *)from, count);
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci#define memcpy_fromio(to,from,count) memcpy_fromio(to,from,count)
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic inline void memcpy_toio(volatile void __iomem *to, const void *from,
3358c2ecf20Sopenharmony_ci	size_t count)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	extern void mmiocpy(void *, const void *, size_t);
3388c2ecf20Sopenharmony_ci	mmiocpy((void __force *)to, from, count);
3398c2ecf20Sopenharmony_ci}
3408c2ecf20Sopenharmony_ci#define memcpy_toio(to,from,count) memcpy_toio(to,from,count)
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci#else
3438c2ecf20Sopenharmony_ci#define memset_io(c,v,l)	_memset_io(c,(v),(l))
3448c2ecf20Sopenharmony_ci#define memcpy_fromio(a,c,l)	_memcpy_fromio((a),c,(l))
3458c2ecf20Sopenharmony_ci#define memcpy_toio(c,a,l)	_memcpy_toio(c,(a),(l))
3468c2ecf20Sopenharmony_ci#endif
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci#endif	/* readl */
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/*
3518c2ecf20Sopenharmony_ci * ioremap() and friends.
3528c2ecf20Sopenharmony_ci *
3538c2ecf20Sopenharmony_ci * ioremap() takes a resource address, and size.  Due to the ARM memory
3548c2ecf20Sopenharmony_ci * types, it is important to use the correct ioremap() function as each
3558c2ecf20Sopenharmony_ci * mapping has specific properties.
3568c2ecf20Sopenharmony_ci *
3578c2ecf20Sopenharmony_ci * Function		Memory type	Cacheability	Cache hint
3588c2ecf20Sopenharmony_ci * ioremap()		Device		n/a		n/a
3598c2ecf20Sopenharmony_ci * ioremap_cache()	Normal		Writeback	Read allocate
3608c2ecf20Sopenharmony_ci * ioremap_wc()		Normal		Non-cacheable	n/a
3618c2ecf20Sopenharmony_ci * ioremap_wt()		Normal		Non-cacheable	n/a
3628c2ecf20Sopenharmony_ci *
3638c2ecf20Sopenharmony_ci * All device mappings have the following properties:
3648c2ecf20Sopenharmony_ci * - no access speculation
3658c2ecf20Sopenharmony_ci * - no repetition (eg, on return from an exception)
3668c2ecf20Sopenharmony_ci * - number, order and size of accesses are maintained
3678c2ecf20Sopenharmony_ci * - unaligned accesses are "unpredictable"
3688c2ecf20Sopenharmony_ci * - writes may be delayed before they hit the endpoint device
3698c2ecf20Sopenharmony_ci *
3708c2ecf20Sopenharmony_ci * All normal memory mappings have the following properties:
3718c2ecf20Sopenharmony_ci * - reads can be repeated with no side effects
3728c2ecf20Sopenharmony_ci * - repeated reads return the last value written
3738c2ecf20Sopenharmony_ci * - reads can fetch additional locations without side effects
3748c2ecf20Sopenharmony_ci * - writes can be repeated (in certain cases) with no side effects
3758c2ecf20Sopenharmony_ci * - writes can be merged before accessing the target
3768c2ecf20Sopenharmony_ci * - unaligned accesses can be supported
3778c2ecf20Sopenharmony_ci * - ordering is not guaranteed without explicit dependencies or barrier
3788c2ecf20Sopenharmony_ci *   instructions
3798c2ecf20Sopenharmony_ci * - writes may be delayed before they hit the endpoint memory
3808c2ecf20Sopenharmony_ci *
3818c2ecf20Sopenharmony_ci * The cache hint is only a performance hint: CPUs may alias these hints.
3828c2ecf20Sopenharmony_ci * Eg, a CPU not implementing read allocate but implementing write allocate
3838c2ecf20Sopenharmony_ci * will provide a write allocate mapping instead.
3848c2ecf20Sopenharmony_ci */
3858c2ecf20Sopenharmony_civoid __iomem *ioremap(resource_size_t res_cookie, size_t size);
3868c2ecf20Sopenharmony_ci#define ioremap ioremap
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci/*
3898c2ecf20Sopenharmony_ci * Do not use ioremap_cache for mapping memory. Use memremap instead.
3908c2ecf20Sopenharmony_ci */
3918c2ecf20Sopenharmony_civoid __iomem *ioremap_cache(resource_size_t res_cookie, size_t size);
3928c2ecf20Sopenharmony_ci#define ioremap_cache ioremap_cache
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_civoid __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
3958c2ecf20Sopenharmony_ci#define ioremap_wc ioremap_wc
3968c2ecf20Sopenharmony_ci#define ioremap_wt ioremap_wc
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_civoid iounmap(volatile void __iomem *iomem_cookie);
3998c2ecf20Sopenharmony_ci#define iounmap iounmap
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_civoid *arch_memremap_wb(phys_addr_t phys_addr, size_t size);
4028c2ecf20Sopenharmony_ci#define arch_memremap_wb arch_memremap_wb
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/*
4058c2ecf20Sopenharmony_ci * io{read,write}{16,32}be() macros
4068c2ecf20Sopenharmony_ci */
4078c2ecf20Sopenharmony_ci#define ioread16be(p)		({ __u16 __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
4088c2ecf20Sopenharmony_ci#define ioread32be(p)		({ __u32 __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci#define iowrite16be(v,p)	({ __iowmb(); __raw_writew((__force __u16)cpu_to_be16(v), p); })
4118c2ecf20Sopenharmony_ci#define iowrite32be(v,p)	({ __iowmb(); __raw_writel((__force __u32)cpu_to_be32(v), p); })
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci#ifndef ioport_map
4148c2ecf20Sopenharmony_ci#define ioport_map ioport_map
4158c2ecf20Sopenharmony_ciextern void __iomem *ioport_map(unsigned long port, unsigned int nr);
4168c2ecf20Sopenharmony_ci#endif
4178c2ecf20Sopenharmony_ci#ifndef ioport_unmap
4188c2ecf20Sopenharmony_ci#define ioport_unmap ioport_unmap
4198c2ecf20Sopenharmony_ciextern void ioport_unmap(void __iomem *addr);
4208c2ecf20Sopenharmony_ci#endif
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_cistruct pci_dev;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define pci_iounmap pci_iounmap
4258c2ecf20Sopenharmony_ciextern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci/*
4288c2ecf20Sopenharmony_ci * Convert a physical pointer to a virtual kernel pointer for /dev/mem
4298c2ecf20Sopenharmony_ci * access
4308c2ecf20Sopenharmony_ci */
4318c2ecf20Sopenharmony_ci#define xlate_dev_mem_ptr(p)	__va(p)
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci/*
4348c2ecf20Sopenharmony_ci * Convert a virtual cached pointer to an uncached pointer
4358c2ecf20Sopenharmony_ci */
4368c2ecf20Sopenharmony_ci#define xlate_dev_kmem_ptr(p)	p
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci#include <asm-generic/io.h>
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU
4418c2ecf20Sopenharmony_ci#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
4428c2ecf20Sopenharmony_ciextern int valid_phys_addr_range(phys_addr_t addr, size_t size);
4438c2ecf20Sopenharmony_ciextern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
4448c2ecf20Sopenharmony_ciextern int devmem_is_allowed(unsigned long pfn);
4458c2ecf20Sopenharmony_ciextern bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
4468c2ecf20Sopenharmony_ci					unsigned long flags);
4478c2ecf20Sopenharmony_ci#define arch_memremap_can_ram_remap arch_memremap_can_ram_remap
4488c2ecf20Sopenharmony_ci#endif
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/*
4518c2ecf20Sopenharmony_ci * Register ISA memory and port locations for glibc iopl/inb/outb
4528c2ecf20Sopenharmony_ci * emulation.
4538c2ecf20Sopenharmony_ci */
4548c2ecf20Sopenharmony_ciextern void register_isa_ports(unsigned int mmio, unsigned int io,
4558c2ecf20Sopenharmony_ci			       unsigned int io_shift);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci#endif	/* __KERNEL__ */
4588c2ecf20Sopenharmony_ci#endif	/* __ASM_ARM_IO_H */
459