xref: /linux/include/asm-generic/io.h (revision b3ada9d0)
13f7e212dSArnd Bergmann /* Generic I/O port emulation, based on MN10300 code
23f7e212dSArnd Bergmann  *
33f7e212dSArnd Bergmann  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
43f7e212dSArnd Bergmann  * Written by David Howells (dhowells@redhat.com)
53f7e212dSArnd Bergmann  *
63f7e212dSArnd Bergmann  * This program is free software; you can redistribute it and/or
73f7e212dSArnd Bergmann  * modify it under the terms of the GNU General Public Licence
83f7e212dSArnd Bergmann  * as published by the Free Software Foundation; either version
93f7e212dSArnd Bergmann  * 2 of the Licence, or (at your option) any later version.
103f7e212dSArnd Bergmann  */
113f7e212dSArnd Bergmann #ifndef __ASM_GENERIC_IO_H
123f7e212dSArnd Bergmann #define __ASM_GENERIC_IO_H
133f7e212dSArnd Bergmann 
143f7e212dSArnd Bergmann #include <asm/page.h> /* I/O is all done through memory accesses */
159216efafSThierry Reding #include <linux/string.h> /* for memset() and memcpy() */
163f7e212dSArnd Bergmann #include <linux/types.h>
173f7e212dSArnd Bergmann 
183f7e212dSArnd Bergmann #ifdef CONFIG_GENERIC_IOMAP
193f7e212dSArnd Bergmann #include <asm-generic/iomap.h>
203f7e212dSArnd Bergmann #endif
213f7e212dSArnd Bergmann 
2266eab4dfSMichael S. Tsirkin #include <asm-generic/pci_iomap.h>
2366eab4dfSMichael S. Tsirkin 
2435dbc0e0SMike Frysinger #ifndef mmiowb
253f7e212dSArnd Bergmann #define mmiowb() do {} while (0)
2635dbc0e0SMike Frysinger #endif
273f7e212dSArnd Bergmann 
283f7e212dSArnd Bergmann /*
299216efafSThierry Reding  * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
309216efafSThierry Reding  *
319216efafSThierry Reding  * On some architectures memory mapped IO needs to be accessed differently.
329216efafSThierry Reding  * On the simple architectures, we just read/write the memory location
339216efafSThierry Reding  * directly.
343f7e212dSArnd Bergmann  */
359216efafSThierry Reding 
3635dbc0e0SMike Frysinger #ifndef __raw_readb
379216efafSThierry Reding #define __raw_readb __raw_readb
383f7e212dSArnd Bergmann static inline u8 __raw_readb(const volatile void __iomem *addr)
393f7e212dSArnd Bergmann {
403f7e212dSArnd Bergmann 	return *(const volatile u8 __force *)addr;
413f7e212dSArnd Bergmann }
4235dbc0e0SMike Frysinger #endif
433f7e212dSArnd Bergmann 
4435dbc0e0SMike Frysinger #ifndef __raw_readw
459216efafSThierry Reding #define __raw_readw __raw_readw
463f7e212dSArnd Bergmann static inline u16 __raw_readw(const volatile void __iomem *addr)
473f7e212dSArnd Bergmann {
483f7e212dSArnd Bergmann 	return *(const volatile u16 __force *)addr;
493f7e212dSArnd Bergmann }
5035dbc0e0SMike Frysinger #endif
513f7e212dSArnd Bergmann 
5235dbc0e0SMike Frysinger #ifndef __raw_readl
539216efafSThierry Reding #define __raw_readl __raw_readl
543f7e212dSArnd Bergmann static inline u32 __raw_readl(const volatile void __iomem *addr)
553f7e212dSArnd Bergmann {
563f7e212dSArnd Bergmann 	return *(const volatile u32 __force *)addr;
573f7e212dSArnd Bergmann }
5835dbc0e0SMike Frysinger #endif
593f7e212dSArnd Bergmann 
603f7e212dSArnd Bergmann #ifdef CONFIG_64BIT
61cd248341SJan Glauber #ifndef __raw_readq
629216efafSThierry Reding #define __raw_readq __raw_readq
633f7e212dSArnd Bergmann static inline u64 __raw_readq(const volatile void __iomem *addr)
643f7e212dSArnd Bergmann {
653f7e212dSArnd Bergmann 	return *(const volatile u64 __force *)addr;
663f7e212dSArnd Bergmann }
67cd248341SJan Glauber #endif
689216efafSThierry Reding #endif /* CONFIG_64BIT */
69cd248341SJan Glauber 
709216efafSThierry Reding #ifndef __raw_writeb
719216efafSThierry Reding #define __raw_writeb __raw_writeb
729216efafSThierry Reding static inline void __raw_writeb(u8 value, volatile void __iomem *addr)
739216efafSThierry Reding {
749216efafSThierry Reding 	*(volatile u8 __force *)addr = value;
759216efafSThierry Reding }
769216efafSThierry Reding #endif
779216efafSThierry Reding 
789216efafSThierry Reding #ifndef __raw_writew
799216efafSThierry Reding #define __raw_writew __raw_writew
809216efafSThierry Reding static inline void __raw_writew(u16 value, volatile void __iomem *addr)
819216efafSThierry Reding {
829216efafSThierry Reding 	*(volatile u16 __force *)addr = value;
839216efafSThierry Reding }
849216efafSThierry Reding #endif
859216efafSThierry Reding 
869216efafSThierry Reding #ifndef __raw_writel
879216efafSThierry Reding #define __raw_writel __raw_writel
889216efafSThierry Reding static inline void __raw_writel(u32 value, volatile void __iomem *addr)
899216efafSThierry Reding {
909216efafSThierry Reding 	*(volatile u32 __force *)addr = value;
919216efafSThierry Reding }
929216efafSThierry Reding #endif
939216efafSThierry Reding 
949216efafSThierry Reding #ifdef CONFIG_64BIT
959216efafSThierry Reding #ifndef __raw_writeq
969216efafSThierry Reding #define __raw_writeq __raw_writeq
979216efafSThierry Reding static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
989216efafSThierry Reding {
999216efafSThierry Reding 	*(volatile u64 __force *)addr = value;
1009216efafSThierry Reding }
1019216efafSThierry Reding #endif
1029216efafSThierry Reding #endif /* CONFIG_64BIT */
1039216efafSThierry Reding 
1049216efafSThierry Reding /*
1059216efafSThierry Reding  * {read,write}{b,w,l,q}() access little endian memory and return result in
1069216efafSThierry Reding  * native endianness.
1079216efafSThierry Reding  */
1089216efafSThierry Reding 
1099216efafSThierry Reding #ifndef readb
1109216efafSThierry Reding #define readb readb
1119216efafSThierry Reding static inline u8 readb(const volatile void __iomem *addr)
1129216efafSThierry Reding {
1139216efafSThierry Reding 	return __raw_readb(addr);
1149216efafSThierry Reding }
1159216efafSThierry Reding #endif
1169216efafSThierry Reding 
1179216efafSThierry Reding #ifndef readw
1189216efafSThierry Reding #define readw readw
1199216efafSThierry Reding static inline u16 readw(const volatile void __iomem *addr)
1209216efafSThierry Reding {
1219216efafSThierry Reding 	return __le16_to_cpu(__raw_readw(addr));
1229216efafSThierry Reding }
1239216efafSThierry Reding #endif
1249216efafSThierry Reding 
1259216efafSThierry Reding #ifndef readl
1269216efafSThierry Reding #define readl readl
1279216efafSThierry Reding static inline u32 readl(const volatile void __iomem *addr)
1289216efafSThierry Reding {
1299216efafSThierry Reding 	return __le32_to_cpu(__raw_readl(addr));
1309216efafSThierry Reding }
1319216efafSThierry Reding #endif
1329216efafSThierry Reding 
1339216efafSThierry Reding #ifdef CONFIG_64BIT
1349216efafSThierry Reding #ifndef readq
1357292e7e0SHeiko Carstens #define readq readq
1367292e7e0SHeiko Carstens static inline u64 readq(const volatile void __iomem *addr)
1377292e7e0SHeiko Carstens {
1387292e7e0SHeiko Carstens 	return __le64_to_cpu(__raw_readq(addr));
1397292e7e0SHeiko Carstens }
1403f7e212dSArnd Bergmann #endif
141cd248341SJan Glauber #endif /* CONFIG_64BIT */
142cd248341SJan Glauber 
1439216efafSThierry Reding #ifndef writeb
1449216efafSThierry Reding #define writeb writeb
1459216efafSThierry Reding static inline void writeb(u8 value, volatile void __iomem *addr)
1469216efafSThierry Reding {
1479216efafSThierry Reding 	__raw_writeb(value, addr);
1489216efafSThierry Reding }
1497dc59bddSGuanXuetao #endif
1507dc59bddSGuanXuetao 
1519216efafSThierry Reding #ifndef writew
1529216efafSThierry Reding #define writew writew
1539216efafSThierry Reding static inline void writew(u16 value, volatile void __iomem *addr)
1543f7e212dSArnd Bergmann {
1559216efafSThierry Reding 	__raw_writew(cpu_to_le16(value), addr);
1563f7e212dSArnd Bergmann }
1579216efafSThierry Reding #endif
1583f7e212dSArnd Bergmann 
1599216efafSThierry Reding #ifndef writel
1609216efafSThierry Reding #define writel writel
1619216efafSThierry Reding static inline void writel(u32 value, volatile void __iomem *addr)
1623f7e212dSArnd Bergmann {
1639216efafSThierry Reding 	__raw_writel(__cpu_to_le32(value), addr);
1643f7e212dSArnd Bergmann }
1659216efafSThierry Reding #endif
1663f7e212dSArnd Bergmann 
1679216efafSThierry Reding #ifdef CONFIG_64BIT
1689216efafSThierry Reding #ifndef writeq
1699216efafSThierry Reding #define writeq writeq
1709216efafSThierry Reding static inline void writeq(u64 value, volatile void __iomem *addr)
1713f7e212dSArnd Bergmann {
1729216efafSThierry Reding 	__raw_writeq(__cpu_to_le64(value), addr);
1733f7e212dSArnd Bergmann }
1749216efafSThierry Reding #endif
1759216efafSThierry Reding #endif /* CONFIG_64BIT */
1763f7e212dSArnd Bergmann 
1779ab3a7a0SThierry Reding /*
1781c8d2969SArnd Bergmann  * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
1791c8d2969SArnd Bergmann  * are not guaranteed to provide ordering against spinlocks or memory
1801c8d2969SArnd Bergmann  * accesses.
1811c8d2969SArnd Bergmann  */
1821c8d2969SArnd Bergmann #ifndef readb_relaxed
1831c8d2969SArnd Bergmann #define readb_relaxed readb
1841c8d2969SArnd Bergmann #endif
1851c8d2969SArnd Bergmann 
1861c8d2969SArnd Bergmann #ifndef readw_relaxed
1871c8d2969SArnd Bergmann #define readw_relaxed readw
1881c8d2969SArnd Bergmann #endif
1891c8d2969SArnd Bergmann 
1901c8d2969SArnd Bergmann #ifndef readl_relaxed
1911c8d2969SArnd Bergmann #define readl_relaxed readl
1921c8d2969SArnd Bergmann #endif
1931c8d2969SArnd Bergmann 
194e511267bSRobin Murphy #if defined(readq) && !defined(readq_relaxed)
1959439eb3aSWill Deacon #define readq_relaxed readq
1969439eb3aSWill Deacon #endif
1973f7e212dSArnd Bergmann 
1981c8d2969SArnd Bergmann #ifndef writeb_relaxed
1991c8d2969SArnd Bergmann #define writeb_relaxed writeb
2001c8d2969SArnd Bergmann #endif
2011c8d2969SArnd Bergmann 
2021c8d2969SArnd Bergmann #ifndef writew_relaxed
2031c8d2969SArnd Bergmann #define writew_relaxed writew
2041c8d2969SArnd Bergmann #endif
2051c8d2969SArnd Bergmann 
2061c8d2969SArnd Bergmann #ifndef writel_relaxed
2071c8d2969SArnd Bergmann #define writel_relaxed writel
2081c8d2969SArnd Bergmann #endif
2091c8d2969SArnd Bergmann 
210e511267bSRobin Murphy #if defined(writeq) && !defined(writeq_relaxed)
2111c8d2969SArnd Bergmann #define writeq_relaxed writeq
2121c8d2969SArnd Bergmann #endif
2131c8d2969SArnd Bergmann 
2141c8d2969SArnd Bergmann /*
2159ab3a7a0SThierry Reding  * {read,write}s{b,w,l,q}() repeatedly access the same memory address in
2169ab3a7a0SThierry Reding  * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times).
2179ab3a7a0SThierry Reding  */
2189ab3a7a0SThierry Reding #ifndef readsb
2199ab3a7a0SThierry Reding #define readsb readsb
2209ab3a7a0SThierry Reding static inline void readsb(const volatile void __iomem *addr, void *buffer,
2219ab3a7a0SThierry Reding 			  unsigned int count)
2223f7e212dSArnd Bergmann {
2233f7e212dSArnd Bergmann 	if (count) {
2243f7e212dSArnd Bergmann 		u8 *buf = buffer;
2259ab3a7a0SThierry Reding 
2263f7e212dSArnd Bergmann 		do {
2279ab3a7a0SThierry Reding 			u8 x = __raw_readb(addr);
2283f7e212dSArnd Bergmann 			*buf++ = x;
2293f7e212dSArnd Bergmann 		} while (--count);
2303f7e212dSArnd Bergmann 	}
2313f7e212dSArnd Bergmann }
23235dbc0e0SMike Frysinger #endif
2333f7e212dSArnd Bergmann 
2349ab3a7a0SThierry Reding #ifndef readsw
2359ab3a7a0SThierry Reding #define readsw readsw
2369ab3a7a0SThierry Reding static inline void readsw(const volatile void __iomem *addr, void *buffer,
2379ab3a7a0SThierry Reding 			  unsigned int count)
2383f7e212dSArnd Bergmann {
2393f7e212dSArnd Bergmann 	if (count) {
2403f7e212dSArnd Bergmann 		u16 *buf = buffer;
2419ab3a7a0SThierry Reding 
2423f7e212dSArnd Bergmann 		do {
2439ab3a7a0SThierry Reding 			u16 x = __raw_readw(addr);
2443f7e212dSArnd Bergmann 			*buf++ = x;
2453f7e212dSArnd Bergmann 		} while (--count);
2463f7e212dSArnd Bergmann 	}
2473f7e212dSArnd Bergmann }
24835dbc0e0SMike Frysinger #endif
2493f7e212dSArnd Bergmann 
2509ab3a7a0SThierry Reding #ifndef readsl
2519ab3a7a0SThierry Reding #define readsl readsl
2529ab3a7a0SThierry Reding static inline void readsl(const volatile void __iomem *addr, void *buffer,
2539ab3a7a0SThierry Reding 			  unsigned int count)
2543f7e212dSArnd Bergmann {
2553f7e212dSArnd Bergmann 	if (count) {
2563f7e212dSArnd Bergmann 		u32 *buf = buffer;
2579ab3a7a0SThierry Reding 
2583f7e212dSArnd Bergmann 		do {
2599ab3a7a0SThierry Reding 			u32 x = __raw_readl(addr);
2603f7e212dSArnd Bergmann 			*buf++ = x;
2613f7e212dSArnd Bergmann 		} while (--count);
2623f7e212dSArnd Bergmann 	}
2633f7e212dSArnd Bergmann }
26435dbc0e0SMike Frysinger #endif
2653f7e212dSArnd Bergmann 
2669ab3a7a0SThierry Reding #ifdef CONFIG_64BIT
2679ab3a7a0SThierry Reding #ifndef readsq
2689ab3a7a0SThierry Reding #define readsq readsq
2699ab3a7a0SThierry Reding static inline void readsq(const volatile void __iomem *addr, void *buffer,
2709ab3a7a0SThierry Reding 			  unsigned int count)
2719ab3a7a0SThierry Reding {
2729ab3a7a0SThierry Reding 	if (count) {
2739ab3a7a0SThierry Reding 		u64 *buf = buffer;
2749ab3a7a0SThierry Reding 
2759ab3a7a0SThierry Reding 		do {
2769ab3a7a0SThierry Reding 			u64 x = __raw_readq(addr);
2779ab3a7a0SThierry Reding 			*buf++ = x;
2789ab3a7a0SThierry Reding 		} while (--count);
2799ab3a7a0SThierry Reding 	}
2809ab3a7a0SThierry Reding }
2819ab3a7a0SThierry Reding #endif
2829ab3a7a0SThierry Reding #endif /* CONFIG_64BIT */
2839ab3a7a0SThierry Reding 
2849ab3a7a0SThierry Reding #ifndef writesb
2859ab3a7a0SThierry Reding #define writesb writesb
2869ab3a7a0SThierry Reding static inline void writesb(volatile void __iomem *addr, const void *buffer,
2879ab3a7a0SThierry Reding 			   unsigned int count)
2883f7e212dSArnd Bergmann {
2893f7e212dSArnd Bergmann 	if (count) {
2903f7e212dSArnd Bergmann 		const u8 *buf = buffer;
2919ab3a7a0SThierry Reding 
2923f7e212dSArnd Bergmann 		do {
2939ab3a7a0SThierry Reding 			__raw_writeb(*buf++, addr);
2943f7e212dSArnd Bergmann 		} while (--count);
2953f7e212dSArnd Bergmann 	}
2963f7e212dSArnd Bergmann }
29735dbc0e0SMike Frysinger #endif
2983f7e212dSArnd Bergmann 
2999ab3a7a0SThierry Reding #ifndef writesw
3009ab3a7a0SThierry Reding #define writesw writesw
3019ab3a7a0SThierry Reding static inline void writesw(volatile void __iomem *addr, const void *buffer,
3029ab3a7a0SThierry Reding 			   unsigned int count)
3033f7e212dSArnd Bergmann {
3043f7e212dSArnd Bergmann 	if (count) {
3053f7e212dSArnd Bergmann 		const u16 *buf = buffer;
3069ab3a7a0SThierry Reding 
3073f7e212dSArnd Bergmann 		do {
3089ab3a7a0SThierry Reding 			__raw_writew(*buf++, addr);
3093f7e212dSArnd Bergmann 		} while (--count);
3103f7e212dSArnd Bergmann 	}
3113f7e212dSArnd Bergmann }
31235dbc0e0SMike Frysinger #endif
3133f7e212dSArnd Bergmann 
3149ab3a7a0SThierry Reding #ifndef writesl
3159ab3a7a0SThierry Reding #define writesl writesl
3169ab3a7a0SThierry Reding static inline void writesl(volatile void __iomem *addr, const void *buffer,
3179ab3a7a0SThierry Reding 			   unsigned int count)
3183f7e212dSArnd Bergmann {
3193f7e212dSArnd Bergmann 	if (count) {
3203f7e212dSArnd Bergmann 		const u32 *buf = buffer;
3219ab3a7a0SThierry Reding 
3223f7e212dSArnd Bergmann 		do {
3239ab3a7a0SThierry Reding 			__raw_writel(*buf++, addr);
3243f7e212dSArnd Bergmann 		} while (--count);
3253f7e212dSArnd Bergmann 	}
3263f7e212dSArnd Bergmann }
32735dbc0e0SMike Frysinger #endif
3283f7e212dSArnd Bergmann 
3299ab3a7a0SThierry Reding #ifdef CONFIG_64BIT
3309ab3a7a0SThierry Reding #ifndef writesq
3319ab3a7a0SThierry Reding #define writesq writesq
3329ab3a7a0SThierry Reding static inline void writesq(volatile void __iomem *addr, const void *buffer,
3339ab3a7a0SThierry Reding 			   unsigned int count)
3349ab3a7a0SThierry Reding {
3359ab3a7a0SThierry Reding 	if (count) {
3369ab3a7a0SThierry Reding 		const u64 *buf = buffer;
3373f7e212dSArnd Bergmann 
3389ab3a7a0SThierry Reding 		do {
3399ab3a7a0SThierry Reding 			__raw_writeq(*buf++, addr);
3409ab3a7a0SThierry Reding 		} while (--count);
3419ab3a7a0SThierry Reding 	}
3429ab3a7a0SThierry Reding }
3439ab3a7a0SThierry Reding #endif
3449ab3a7a0SThierry Reding #endif /* CONFIG_64BIT */
3453f7e212dSArnd Bergmann 
3469216efafSThierry Reding #ifndef PCI_IOBASE
3479216efafSThierry Reding #define PCI_IOBASE ((void __iomem *)0)
3489216efafSThierry Reding #endif
3499216efafSThierry Reding 
3507dc59bddSGuanXuetao #ifndef IO_SPACE_LIMIT
3517dc59bddSGuanXuetao #define IO_SPACE_LIMIT 0xffff
3527dc59bddSGuanXuetao #endif
3533f7e212dSArnd Bergmann 
3549216efafSThierry Reding /*
3559216efafSThierry Reding  * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be
3569216efafSThierry Reding  * implemented on hardware that needs an additional delay for I/O accesses to
3579216efafSThierry Reding  * take effect.
3589216efafSThierry Reding  */
3599216efafSThierry Reding 
3609216efafSThierry Reding #ifndef inb
3619216efafSThierry Reding #define inb inb
3629216efafSThierry Reding static inline u8 inb(unsigned long addr)
3639216efafSThierry Reding {
3649216efafSThierry Reding 	return readb(PCI_IOBASE + addr);
3659216efafSThierry Reding }
3669216efafSThierry Reding #endif
3679216efafSThierry Reding 
3689216efafSThierry Reding #ifndef inw
3699216efafSThierry Reding #define inw inw
3709216efafSThierry Reding static inline u16 inw(unsigned long addr)
3719216efafSThierry Reding {
3729216efafSThierry Reding 	return readw(PCI_IOBASE + addr);
3739216efafSThierry Reding }
3749216efafSThierry Reding #endif
3759216efafSThierry Reding 
3769216efafSThierry Reding #ifndef inl
3779216efafSThierry Reding #define inl inl
3789216efafSThierry Reding static inline u32 inl(unsigned long addr)
3799216efafSThierry Reding {
3809216efafSThierry Reding 	return readl(PCI_IOBASE + addr);
3819216efafSThierry Reding }
3829216efafSThierry Reding #endif
3839216efafSThierry Reding 
3849216efafSThierry Reding #ifndef outb
3859216efafSThierry Reding #define outb outb
3869216efafSThierry Reding static inline void outb(u8 value, unsigned long addr)
3879216efafSThierry Reding {
3889216efafSThierry Reding 	writeb(value, PCI_IOBASE + addr);
3899216efafSThierry Reding }
3909216efafSThierry Reding #endif
3919216efafSThierry Reding 
3929216efafSThierry Reding #ifndef outw
3939216efafSThierry Reding #define outw outw
3949216efafSThierry Reding static inline void outw(u16 value, unsigned long addr)
3959216efafSThierry Reding {
3969216efafSThierry Reding 	writew(value, PCI_IOBASE + addr);
3979216efafSThierry Reding }
3989216efafSThierry Reding #endif
3999216efafSThierry Reding 
4009216efafSThierry Reding #ifndef outl
4019216efafSThierry Reding #define outl outl
4029216efafSThierry Reding static inline void outl(u32 value, unsigned long addr)
4039216efafSThierry Reding {
4049216efafSThierry Reding 	writel(value, PCI_IOBASE + addr);
4059216efafSThierry Reding }
4069216efafSThierry Reding #endif
4079216efafSThierry Reding 
4089216efafSThierry Reding #ifndef inb_p
4099216efafSThierry Reding #define inb_p inb_p
4109216efafSThierry Reding static inline u8 inb_p(unsigned long addr)
4119216efafSThierry Reding {
4129216efafSThierry Reding 	return inb(addr);
4139216efafSThierry Reding }
4149216efafSThierry Reding #endif
4159216efafSThierry Reding 
4169216efafSThierry Reding #ifndef inw_p
4179216efafSThierry Reding #define inw_p inw_p
4189216efafSThierry Reding static inline u16 inw_p(unsigned long addr)
4199216efafSThierry Reding {
4209216efafSThierry Reding 	return inw(addr);
4219216efafSThierry Reding }
4229216efafSThierry Reding #endif
4239216efafSThierry Reding 
4249216efafSThierry Reding #ifndef inl_p
4259216efafSThierry Reding #define inl_p inl_p
4269216efafSThierry Reding static inline u32 inl_p(unsigned long addr)
4279216efafSThierry Reding {
4289216efafSThierry Reding 	return inl(addr);
4299216efafSThierry Reding }
4309216efafSThierry Reding #endif
4319216efafSThierry Reding 
4329216efafSThierry Reding #ifndef outb_p
4339216efafSThierry Reding #define outb_p outb_p
4349216efafSThierry Reding static inline void outb_p(u8 value, unsigned long addr)
4359216efafSThierry Reding {
4369216efafSThierry Reding 	outb(value, addr);
4379216efafSThierry Reding }
4389216efafSThierry Reding #endif
4399216efafSThierry Reding 
4409216efafSThierry Reding #ifndef outw_p
4419216efafSThierry Reding #define outw_p outw_p
4429216efafSThierry Reding static inline void outw_p(u16 value, unsigned long addr)
4439216efafSThierry Reding {
4449216efafSThierry Reding 	outw(value, addr);
4459216efafSThierry Reding }
4469216efafSThierry Reding #endif
4479216efafSThierry Reding 
4489216efafSThierry Reding #ifndef outl_p
4499216efafSThierry Reding #define outl_p outl_p
4509216efafSThierry Reding static inline void outl_p(u32 value, unsigned long addr)
4519216efafSThierry Reding {
4529216efafSThierry Reding 	outl(value, addr);
4539216efafSThierry Reding }
4549216efafSThierry Reding #endif
4559216efafSThierry Reding 
4569ab3a7a0SThierry Reding /*
4579ab3a7a0SThierry Reding  * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a
4589ab3a7a0SThierry Reding  * single I/O port multiple times.
4599ab3a7a0SThierry Reding  */
4609ab3a7a0SThierry Reding 
4619ab3a7a0SThierry Reding #ifndef insb
4629ab3a7a0SThierry Reding #define insb insb
4639ab3a7a0SThierry Reding static inline void insb(unsigned long addr, void *buffer, unsigned int count)
4649ab3a7a0SThierry Reding {
4659ab3a7a0SThierry Reding 	readsb(PCI_IOBASE + addr, buffer, count);
4669ab3a7a0SThierry Reding }
4679ab3a7a0SThierry Reding #endif
4689ab3a7a0SThierry Reding 
4699ab3a7a0SThierry Reding #ifndef insw
4709ab3a7a0SThierry Reding #define insw insw
4719ab3a7a0SThierry Reding static inline void insw(unsigned long addr, void *buffer, unsigned int count)
4729ab3a7a0SThierry Reding {
4739ab3a7a0SThierry Reding 	readsw(PCI_IOBASE + addr, buffer, count);
4749ab3a7a0SThierry Reding }
4759ab3a7a0SThierry Reding #endif
4769ab3a7a0SThierry Reding 
4779ab3a7a0SThierry Reding #ifndef insl
4789ab3a7a0SThierry Reding #define insl insl
4799ab3a7a0SThierry Reding static inline void insl(unsigned long addr, void *buffer, unsigned int count)
4809ab3a7a0SThierry Reding {
4819ab3a7a0SThierry Reding 	readsl(PCI_IOBASE + addr, buffer, count);
4829ab3a7a0SThierry Reding }
4839ab3a7a0SThierry Reding #endif
4849ab3a7a0SThierry Reding 
4859ab3a7a0SThierry Reding #ifndef outsb
4869ab3a7a0SThierry Reding #define outsb outsb
4879ab3a7a0SThierry Reding static inline void outsb(unsigned long addr, const void *buffer,
4889ab3a7a0SThierry Reding 			 unsigned int count)
4899ab3a7a0SThierry Reding {
4909ab3a7a0SThierry Reding 	writesb(PCI_IOBASE + addr, buffer, count);
4919ab3a7a0SThierry Reding }
4929ab3a7a0SThierry Reding #endif
4939ab3a7a0SThierry Reding 
4949ab3a7a0SThierry Reding #ifndef outsw
4959ab3a7a0SThierry Reding #define outsw outsw
4969ab3a7a0SThierry Reding static inline void outsw(unsigned long addr, const void *buffer,
4979ab3a7a0SThierry Reding 			 unsigned int count)
4989ab3a7a0SThierry Reding {
4999ab3a7a0SThierry Reding 	writesw(PCI_IOBASE + addr, buffer, count);
5009ab3a7a0SThierry Reding }
5019ab3a7a0SThierry Reding #endif
5029ab3a7a0SThierry Reding 
5039ab3a7a0SThierry Reding #ifndef outsl
5049ab3a7a0SThierry Reding #define outsl outsl
5059ab3a7a0SThierry Reding static inline void outsl(unsigned long addr, const void *buffer,
5069ab3a7a0SThierry Reding 			 unsigned int count)
5079ab3a7a0SThierry Reding {
5089ab3a7a0SThierry Reding 	writesl(PCI_IOBASE + addr, buffer, count);
5099ab3a7a0SThierry Reding }
5109ab3a7a0SThierry Reding #endif
5119ab3a7a0SThierry Reding 
5129ab3a7a0SThierry Reding #ifndef insb_p
5139ab3a7a0SThierry Reding #define insb_p insb_p
5149ab3a7a0SThierry Reding static inline void insb_p(unsigned long addr, void *buffer, unsigned int count)
5159ab3a7a0SThierry Reding {
5169ab3a7a0SThierry Reding 	insb(addr, buffer, count);
5179ab3a7a0SThierry Reding }
5189ab3a7a0SThierry Reding #endif
5199ab3a7a0SThierry Reding 
5209ab3a7a0SThierry Reding #ifndef insw_p
5219ab3a7a0SThierry Reding #define insw_p insw_p
5229ab3a7a0SThierry Reding static inline void insw_p(unsigned long addr, void *buffer, unsigned int count)
5239ab3a7a0SThierry Reding {
5249ab3a7a0SThierry Reding 	insw(addr, buffer, count);
5259ab3a7a0SThierry Reding }
5269ab3a7a0SThierry Reding #endif
5279ab3a7a0SThierry Reding 
5289ab3a7a0SThierry Reding #ifndef insl_p
5299ab3a7a0SThierry Reding #define insl_p insl_p
5309ab3a7a0SThierry Reding static inline void insl_p(unsigned long addr, void *buffer, unsigned int count)
5319ab3a7a0SThierry Reding {
5329ab3a7a0SThierry Reding 	insl(addr, buffer, count);
5339ab3a7a0SThierry Reding }
5349ab3a7a0SThierry Reding #endif
5359ab3a7a0SThierry Reding 
5369ab3a7a0SThierry Reding #ifndef outsb_p
5379ab3a7a0SThierry Reding #define outsb_p outsb_p
5389ab3a7a0SThierry Reding static inline void outsb_p(unsigned long addr, const void *buffer,
5399ab3a7a0SThierry Reding 			   unsigned int count)
5409ab3a7a0SThierry Reding {
5419ab3a7a0SThierry Reding 	outsb(addr, buffer, count);
5429ab3a7a0SThierry Reding }
5439ab3a7a0SThierry Reding #endif
5449ab3a7a0SThierry Reding 
5459ab3a7a0SThierry Reding #ifndef outsw_p
5469ab3a7a0SThierry Reding #define outsw_p outsw_p
5479ab3a7a0SThierry Reding static inline void outsw_p(unsigned long addr, const void *buffer,
5489ab3a7a0SThierry Reding 			   unsigned int count)
5499ab3a7a0SThierry Reding {
5509ab3a7a0SThierry Reding 	outsw(addr, buffer, count);
5519ab3a7a0SThierry Reding }
5529ab3a7a0SThierry Reding #endif
5539ab3a7a0SThierry Reding 
5549ab3a7a0SThierry Reding #ifndef outsl_p
5559ab3a7a0SThierry Reding #define outsl_p outsl_p
5569ab3a7a0SThierry Reding static inline void outsl_p(unsigned long addr, const void *buffer,
5579ab3a7a0SThierry Reding 			   unsigned int count)
5589ab3a7a0SThierry Reding {
5599ab3a7a0SThierry Reding 	outsl(addr, buffer, count);
5609ab3a7a0SThierry Reding }
5619ab3a7a0SThierry Reding #endif
5629ab3a7a0SThierry Reding 
5639216efafSThierry Reding #ifndef CONFIG_GENERIC_IOMAP
5649216efafSThierry Reding #ifndef ioread8
5659216efafSThierry Reding #define ioread8 ioread8
5669216efafSThierry Reding static inline u8 ioread8(const volatile void __iomem *addr)
5679216efafSThierry Reding {
5689216efafSThierry Reding 	return readb(addr);
5699216efafSThierry Reding }
5709216efafSThierry Reding #endif
5719216efafSThierry Reding 
5729216efafSThierry Reding #ifndef ioread16
5739216efafSThierry Reding #define ioread16 ioread16
5749216efafSThierry Reding static inline u16 ioread16(const volatile void __iomem *addr)
5759216efafSThierry Reding {
5769216efafSThierry Reding 	return readw(addr);
5779216efafSThierry Reding }
5789216efafSThierry Reding #endif
5799216efafSThierry Reding 
5809216efafSThierry Reding #ifndef ioread32
5819216efafSThierry Reding #define ioread32 ioread32
5829216efafSThierry Reding static inline u32 ioread32(const volatile void __iomem *addr)
5839216efafSThierry Reding {
5849216efafSThierry Reding 	return readl(addr);
5859216efafSThierry Reding }
5869216efafSThierry Reding #endif
5879216efafSThierry Reding 
5889e44fb18SHoria Geantă #ifdef CONFIG_64BIT
5899e44fb18SHoria Geantă #ifndef ioread64
5909e44fb18SHoria Geantă #define ioread64 ioread64
5919e44fb18SHoria Geantă static inline u64 ioread64(const volatile void __iomem *addr)
5929e44fb18SHoria Geantă {
5939e44fb18SHoria Geantă 	return readq(addr);
5949e44fb18SHoria Geantă }
5959e44fb18SHoria Geantă #endif
5969e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
5979e44fb18SHoria Geantă 
5989216efafSThierry Reding #ifndef iowrite8
5999216efafSThierry Reding #define iowrite8 iowrite8
6009216efafSThierry Reding static inline void iowrite8(u8 value, volatile void __iomem *addr)
6019216efafSThierry Reding {
6029216efafSThierry Reding 	writeb(value, addr);
6039216efafSThierry Reding }
6049216efafSThierry Reding #endif
6059216efafSThierry Reding 
6069216efafSThierry Reding #ifndef iowrite16
6079216efafSThierry Reding #define iowrite16 iowrite16
6089216efafSThierry Reding static inline void iowrite16(u16 value, volatile void __iomem *addr)
6099216efafSThierry Reding {
6109216efafSThierry Reding 	writew(value, addr);
6119216efafSThierry Reding }
6129216efafSThierry Reding #endif
6139216efafSThierry Reding 
6149216efafSThierry Reding #ifndef iowrite32
6159216efafSThierry Reding #define iowrite32 iowrite32
6169216efafSThierry Reding static inline void iowrite32(u32 value, volatile void __iomem *addr)
6179216efafSThierry Reding {
6189216efafSThierry Reding 	writel(value, addr);
6199216efafSThierry Reding }
6209216efafSThierry Reding #endif
6219216efafSThierry Reding 
6229e44fb18SHoria Geantă #ifdef CONFIG_64BIT
6239e44fb18SHoria Geantă #ifndef iowrite64
6249e44fb18SHoria Geantă #define iowrite64 iowrite64
6259e44fb18SHoria Geantă static inline void iowrite64(u64 value, volatile void __iomem *addr)
6269e44fb18SHoria Geantă {
6279e44fb18SHoria Geantă 	writeq(value, addr);
6289e44fb18SHoria Geantă }
6299e44fb18SHoria Geantă #endif
6309e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
6319e44fb18SHoria Geantă 
6329216efafSThierry Reding #ifndef ioread16be
6339216efafSThierry Reding #define ioread16be ioread16be
6349216efafSThierry Reding static inline u16 ioread16be(const volatile void __iomem *addr)
6359216efafSThierry Reding {
6367a1aedbaSHoria Geantă 	return swab16(readw(addr));
6379216efafSThierry Reding }
6389216efafSThierry Reding #endif
6399216efafSThierry Reding 
6409216efafSThierry Reding #ifndef ioread32be
6419216efafSThierry Reding #define ioread32be ioread32be
6429216efafSThierry Reding static inline u32 ioread32be(const volatile void __iomem *addr)
6439216efafSThierry Reding {
6447a1aedbaSHoria Geantă 	return swab32(readl(addr));
6459216efafSThierry Reding }
6469216efafSThierry Reding #endif
6479216efafSThierry Reding 
6489e44fb18SHoria Geantă #ifdef CONFIG_64BIT
6499e44fb18SHoria Geantă #ifndef ioread64be
6509e44fb18SHoria Geantă #define ioread64be ioread64be
6519e44fb18SHoria Geantă static inline u64 ioread64be(const volatile void __iomem *addr)
6529e44fb18SHoria Geantă {
6539e44fb18SHoria Geantă 	return swab64(readq(addr));
6549e44fb18SHoria Geantă }
6559e44fb18SHoria Geantă #endif
6569e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
6579e44fb18SHoria Geantă 
6589216efafSThierry Reding #ifndef iowrite16be
6599216efafSThierry Reding #define iowrite16be iowrite16be
6609216efafSThierry Reding static inline void iowrite16be(u16 value, void volatile __iomem *addr)
6619216efafSThierry Reding {
6627a1aedbaSHoria Geantă 	writew(swab16(value), addr);
6639216efafSThierry Reding }
6649216efafSThierry Reding #endif
6659216efafSThierry Reding 
6669216efafSThierry Reding #ifndef iowrite32be
6679216efafSThierry Reding #define iowrite32be iowrite32be
6689216efafSThierry Reding static inline void iowrite32be(u32 value, volatile void __iomem *addr)
6699216efafSThierry Reding {
6707a1aedbaSHoria Geantă 	writel(swab32(value), addr);
6719216efafSThierry Reding }
6729216efafSThierry Reding #endif
6739ab3a7a0SThierry Reding 
6749e44fb18SHoria Geantă #ifdef CONFIG_64BIT
6759e44fb18SHoria Geantă #ifndef iowrite64be
6769e44fb18SHoria Geantă #define iowrite64be iowrite64be
6779e44fb18SHoria Geantă static inline void iowrite64be(u64 value, volatile void __iomem *addr)
6789e44fb18SHoria Geantă {
6799e44fb18SHoria Geantă 	writeq(swab64(value), addr);
6809e44fb18SHoria Geantă }
6819e44fb18SHoria Geantă #endif
6829e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
6839e44fb18SHoria Geantă 
6849ab3a7a0SThierry Reding #ifndef ioread8_rep
6859ab3a7a0SThierry Reding #define ioread8_rep ioread8_rep
6869ab3a7a0SThierry Reding static inline void ioread8_rep(const volatile void __iomem *addr, void *buffer,
6879ab3a7a0SThierry Reding 			       unsigned int count)
6889ab3a7a0SThierry Reding {
6899ab3a7a0SThierry Reding 	readsb(addr, buffer, count);
6909ab3a7a0SThierry Reding }
6919ab3a7a0SThierry Reding #endif
6929ab3a7a0SThierry Reding 
6939ab3a7a0SThierry Reding #ifndef ioread16_rep
6949ab3a7a0SThierry Reding #define ioread16_rep ioread16_rep
6959ab3a7a0SThierry Reding static inline void ioread16_rep(const volatile void __iomem *addr,
6969ab3a7a0SThierry Reding 				void *buffer, unsigned int count)
6979ab3a7a0SThierry Reding {
6989ab3a7a0SThierry Reding 	readsw(addr, buffer, count);
6999ab3a7a0SThierry Reding }
7009ab3a7a0SThierry Reding #endif
7019ab3a7a0SThierry Reding 
7029ab3a7a0SThierry Reding #ifndef ioread32_rep
7039ab3a7a0SThierry Reding #define ioread32_rep ioread32_rep
7049ab3a7a0SThierry Reding static inline void ioread32_rep(const volatile void __iomem *addr,
7059ab3a7a0SThierry Reding 				void *buffer, unsigned int count)
7069ab3a7a0SThierry Reding {
7079ab3a7a0SThierry Reding 	readsl(addr, buffer, count);
7089ab3a7a0SThierry Reding }
7099ab3a7a0SThierry Reding #endif
7109ab3a7a0SThierry Reding 
7119e44fb18SHoria Geantă #ifdef CONFIG_64BIT
7129e44fb18SHoria Geantă #ifndef ioread64_rep
7139e44fb18SHoria Geantă #define ioread64_rep ioread64_rep
7149e44fb18SHoria Geantă static inline void ioread64_rep(const volatile void __iomem *addr,
7159e44fb18SHoria Geantă 				void *buffer, unsigned int count)
7169e44fb18SHoria Geantă {
7179e44fb18SHoria Geantă 	readsq(addr, buffer, count);
7189e44fb18SHoria Geantă }
7199e44fb18SHoria Geantă #endif
7209e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
7219e44fb18SHoria Geantă 
7229ab3a7a0SThierry Reding #ifndef iowrite8_rep
7239ab3a7a0SThierry Reding #define iowrite8_rep iowrite8_rep
7249ab3a7a0SThierry Reding static inline void iowrite8_rep(volatile void __iomem *addr,
7259ab3a7a0SThierry Reding 				const void *buffer,
7269ab3a7a0SThierry Reding 				unsigned int count)
7279ab3a7a0SThierry Reding {
7289ab3a7a0SThierry Reding 	writesb(addr, buffer, count);
7299ab3a7a0SThierry Reding }
7309ab3a7a0SThierry Reding #endif
7319ab3a7a0SThierry Reding 
7329ab3a7a0SThierry Reding #ifndef iowrite16_rep
7339ab3a7a0SThierry Reding #define iowrite16_rep iowrite16_rep
7349ab3a7a0SThierry Reding static inline void iowrite16_rep(volatile void __iomem *addr,
7359ab3a7a0SThierry Reding 				 const void *buffer,
7369ab3a7a0SThierry Reding 				 unsigned int count)
7379ab3a7a0SThierry Reding {
7389ab3a7a0SThierry Reding 	writesw(addr, buffer, count);
7399ab3a7a0SThierry Reding }
7409ab3a7a0SThierry Reding #endif
7419ab3a7a0SThierry Reding 
7429ab3a7a0SThierry Reding #ifndef iowrite32_rep
7439ab3a7a0SThierry Reding #define iowrite32_rep iowrite32_rep
7449ab3a7a0SThierry Reding static inline void iowrite32_rep(volatile void __iomem *addr,
7459ab3a7a0SThierry Reding 				 const void *buffer,
7469ab3a7a0SThierry Reding 				 unsigned int count)
7479ab3a7a0SThierry Reding {
7489ab3a7a0SThierry Reding 	writesl(addr, buffer, count);
7499ab3a7a0SThierry Reding }
7509ab3a7a0SThierry Reding #endif
7519e44fb18SHoria Geantă 
7529e44fb18SHoria Geantă #ifdef CONFIG_64BIT
7539e44fb18SHoria Geantă #ifndef iowrite64_rep
7549e44fb18SHoria Geantă #define iowrite64_rep iowrite64_rep
7559e44fb18SHoria Geantă static inline void iowrite64_rep(volatile void __iomem *addr,
7569e44fb18SHoria Geantă 				 const void *buffer,
7579e44fb18SHoria Geantă 				 unsigned int count)
7589e44fb18SHoria Geantă {
7599e44fb18SHoria Geantă 	writesq(addr, buffer, count);
7609e44fb18SHoria Geantă }
7619e44fb18SHoria Geantă #endif
7629e44fb18SHoria Geantă #endif /* CONFIG_64BIT */
7639216efafSThierry Reding #endif /* CONFIG_GENERIC_IOMAP */
7649216efafSThierry Reding 
7653f7e212dSArnd Bergmann #ifdef __KERNEL__
7663f7e212dSArnd Bergmann 
7673f7e212dSArnd Bergmann #include <linux/vmalloc.h>
7683f7e212dSArnd Bergmann #define __io_virt(x) ((void __force *)(x))
7693f7e212dSArnd Bergmann 
7703f7e212dSArnd Bergmann #ifndef CONFIG_GENERIC_IOMAP
7713f7e212dSArnd Bergmann struct pci_dev;
772cd248341SJan Glauber extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
773cd248341SJan Glauber 
774cd248341SJan Glauber #ifndef pci_iounmap
7759216efafSThierry Reding #define pci_iounmap pci_iounmap
7763f7e212dSArnd Bergmann static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
7773f7e212dSArnd Bergmann {
7783f7e212dSArnd Bergmann }
779cd248341SJan Glauber #endif
7803f7e212dSArnd Bergmann #endif /* CONFIG_GENERIC_IOMAP */
7813f7e212dSArnd Bergmann 
7823f7e212dSArnd Bergmann /*
7833f7e212dSArnd Bergmann  * Change virtual addresses to physical addresses and vv.
7843f7e212dSArnd Bergmann  * These are pretty trivial
7853f7e212dSArnd Bergmann  */
786cd248341SJan Glauber #ifndef virt_to_phys
7879216efafSThierry Reding #define virt_to_phys virt_to_phys
7883f7e212dSArnd Bergmann static inline unsigned long virt_to_phys(volatile void *address)
7893f7e212dSArnd Bergmann {
7903f7e212dSArnd Bergmann 	return __pa((unsigned long)address);
7913f7e212dSArnd Bergmann }
7929216efafSThierry Reding #endif
7933f7e212dSArnd Bergmann 
7949216efafSThierry Reding #ifndef phys_to_virt
7959216efafSThierry Reding #define phys_to_virt phys_to_virt
7963f7e212dSArnd Bergmann static inline void *phys_to_virt(unsigned long address)
7973f7e212dSArnd Bergmann {
7983f7e212dSArnd Bergmann 	return __va(address);
7993f7e212dSArnd Bergmann }
800cd248341SJan Glauber #endif
8013f7e212dSArnd Bergmann 
8028c7ea50cSLuis R. Rodriguez /**
8038c7ea50cSLuis R. Rodriguez  * DOC: ioremap() and ioremap_*() variants
8048c7ea50cSLuis R. Rodriguez  *
8058c7ea50cSLuis R. Rodriguez  * If you have an IOMMU your architecture is expected to have both ioremap()
8068c7ea50cSLuis R. Rodriguez  * and iounmap() implemented otherwise the asm-generic helpers will provide a
8078c7ea50cSLuis R. Rodriguez  * direct mapping.
8088c7ea50cSLuis R. Rodriguez  *
8098c7ea50cSLuis R. Rodriguez  * There are ioremap_*() call variants, if you have no IOMMU we naturally will
8108c7ea50cSLuis R. Rodriguez  * default to direct mapping for all of them, you can override these defaults.
8118c7ea50cSLuis R. Rodriguez  * If you have an IOMMU you are highly encouraged to provide your own
8128c7ea50cSLuis R. Rodriguez  * ioremap variant implementation as there currently is no safe architecture
8138c7ea50cSLuis R. Rodriguez  * agnostic default. To avoid possible improper behaviour default asm-generic
8148c7ea50cSLuis R. Rodriguez  * ioremap_*() variants all return NULL when an IOMMU is available. If you've
8158c7ea50cSLuis R. Rodriguez  * defined your own ioremap_*() variant you must then declare your own
8168c7ea50cSLuis R. Rodriguez  * ioremap_*() variant as defined to itself to avoid the default NULL return.
8178c7ea50cSLuis R. Rodriguez  */
8188c7ea50cSLuis R. Rodriguez 
8198c7ea50cSLuis R. Rodriguez #ifdef CONFIG_MMU
8208c7ea50cSLuis R. Rodriguez 
8218c7ea50cSLuis R. Rodriguez #ifndef ioremap_uc
8228c7ea50cSLuis R. Rodriguez #define ioremap_uc ioremap_uc
8238c7ea50cSLuis R. Rodriguez static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size)
8248c7ea50cSLuis R. Rodriguez {
8258c7ea50cSLuis R. Rodriguez 	return NULL;
8268c7ea50cSLuis R. Rodriguez }
8278c7ea50cSLuis R. Rodriguez #endif
8288c7ea50cSLuis R. Rodriguez 
8298c7ea50cSLuis R. Rodriguez #else /* !CONFIG_MMU */
8308c7ea50cSLuis R. Rodriguez 
8313f7e212dSArnd Bergmann /*
8323f7e212dSArnd Bergmann  * Change "struct page" to physical address.
833f1ecc698SJonas Bonn  *
834f1ecc698SJonas Bonn  * This implementation is for the no-MMU case only... if you have an MMU
835f1ecc698SJonas Bonn  * you'll need to provide your own definitions.
8363f7e212dSArnd Bergmann  */
8379216efafSThierry Reding 
8389216efafSThierry Reding #ifndef ioremap
8399216efafSThierry Reding #define ioremap ioremap
8409216efafSThierry Reding static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
8413f7e212dSArnd Bergmann {
8423f7e212dSArnd Bergmann 	return (void __iomem *)(unsigned long)offset;
8433f7e212dSArnd Bergmann }
8449216efafSThierry Reding #endif
8453f7e212dSArnd Bergmann 
8469216efafSThierry Reding #ifndef __ioremap
8479216efafSThierry Reding #define __ioremap __ioremap
8489216efafSThierry Reding static inline void __iomem *__ioremap(phys_addr_t offset, size_t size,
8499216efafSThierry Reding 				      unsigned long flags)
8509216efafSThierry Reding {
8519216efafSThierry Reding 	return ioremap(offset, size);
8529216efafSThierry Reding }
8539216efafSThierry Reding #endif
8543f7e212dSArnd Bergmann 
855*b3ada9d0SGreentime Hu #ifndef iounmap
856*b3ada9d0SGreentime Hu #define iounmap iounmap
857*b3ada9d0SGreentime Hu 
858*b3ada9d0SGreentime Hu static inline void iounmap(void __iomem *addr)
859*b3ada9d0SGreentime Hu {
860*b3ada9d0SGreentime Hu }
861*b3ada9d0SGreentime Hu #endif
862*b3ada9d0SGreentime Hu #endif /* CONFIG_MMU */
8633f7e212dSArnd Bergmann #ifndef ioremap_nocache
864*b3ada9d0SGreentime Hu void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
8659216efafSThierry Reding #define ioremap_nocache ioremap_nocache
8669216efafSThierry Reding static inline void __iomem *ioremap_nocache(phys_addr_t offset, size_t size)
8679216efafSThierry Reding {
8689216efafSThierry Reding 	return ioremap(offset, size);
8699216efafSThierry Reding }
8703f7e212dSArnd Bergmann #endif
8713f7e212dSArnd Bergmann 
872e4b6be33SLuis R. Rodriguez #ifndef ioremap_uc
873e4b6be33SLuis R. Rodriguez #define ioremap_uc ioremap_uc
874e4b6be33SLuis R. Rodriguez static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size)
875e4b6be33SLuis R. Rodriguez {
876e4b6be33SLuis R. Rodriguez 	return ioremap_nocache(offset, size);
877e4b6be33SLuis R. Rodriguez }
878e4b6be33SLuis R. Rodriguez #endif
879e4b6be33SLuis R. Rodriguez 
8803f7e212dSArnd Bergmann #ifndef ioremap_wc
8819216efafSThierry Reding #define ioremap_wc ioremap_wc
8829216efafSThierry Reding static inline void __iomem *ioremap_wc(phys_addr_t offset, size_t size)
8839216efafSThierry Reding {
8849216efafSThierry Reding 	return ioremap_nocache(offset, size);
8859216efafSThierry Reding }
8863f7e212dSArnd Bergmann #endif
8873f7e212dSArnd Bergmann 
888d838270eSToshi Kani #ifndef ioremap_wt
889d838270eSToshi Kani #define ioremap_wt ioremap_wt
890d838270eSToshi Kani static inline void __iomem *ioremap_wt(phys_addr_t offset, size_t size)
891d838270eSToshi Kani {
892d838270eSToshi Kani 	return ioremap_nocache(offset, size);
893d838270eSToshi Kani }
894d838270eSToshi Kani #endif
895d838270eSToshi Kani 
896ce816fa8SUwe Kleine-König #ifdef CONFIG_HAS_IOPORT_MAP
8973f7e212dSArnd Bergmann #ifndef CONFIG_GENERIC_IOMAP
8989216efafSThierry Reding #ifndef ioport_map
8999216efafSThierry Reding #define ioport_map ioport_map
9003f7e212dSArnd Bergmann static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
9013f7e212dSArnd Bergmann {
902112eeaa7SLiviu Dudau 	return PCI_IOBASE + (port & IO_SPACE_LIMIT);
9033f7e212dSArnd Bergmann }
9049216efafSThierry Reding #endif
9053f7e212dSArnd Bergmann 
9069216efafSThierry Reding #ifndef ioport_unmap
9079216efafSThierry Reding #define ioport_unmap ioport_unmap
9083f7e212dSArnd Bergmann static inline void ioport_unmap(void __iomem *p)
9093f7e212dSArnd Bergmann {
9103f7e212dSArnd Bergmann }
9119216efafSThierry Reding #endif
9123f7e212dSArnd Bergmann #else /* CONFIG_GENERIC_IOMAP */
9133f7e212dSArnd Bergmann extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
9143f7e212dSArnd Bergmann extern void ioport_unmap(void __iomem *p);
9153f7e212dSArnd Bergmann #endif /* CONFIG_GENERIC_IOMAP */
916ce816fa8SUwe Kleine-König #endif /* CONFIG_HAS_IOPORT_MAP */
9173f7e212dSArnd Bergmann 
918eabc2a7cSAndy Shevchenko /*
919eabc2a7cSAndy Shevchenko  * Convert a virtual cached pointer to an uncached pointer
920eabc2a7cSAndy Shevchenko  */
921576ebd74SMichael Holzheu #ifndef xlate_dev_kmem_ptr
9229216efafSThierry Reding #define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
9239216efafSThierry Reding static inline void *xlate_dev_kmem_ptr(void *addr)
9249216efafSThierry Reding {
9259216efafSThierry Reding 	return addr;
9269216efafSThierry Reding }
927576ebd74SMichael Holzheu #endif
9289216efafSThierry Reding 
929576ebd74SMichael Holzheu #ifndef xlate_dev_mem_ptr
9309216efafSThierry Reding #define xlate_dev_mem_ptr xlate_dev_mem_ptr
9319216efafSThierry Reding static inline void *xlate_dev_mem_ptr(phys_addr_t addr)
9329216efafSThierry Reding {
9339216efafSThierry Reding 	return __va(addr);
9349216efafSThierry Reding }
9359216efafSThierry Reding #endif
9369216efafSThierry Reding 
9379216efafSThierry Reding #ifndef unxlate_dev_mem_ptr
9389216efafSThierry Reding #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
9399216efafSThierry Reding static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
9409216efafSThierry Reding {
9419216efafSThierry Reding }
942576ebd74SMichael Holzheu #endif
9433f7e212dSArnd Bergmann 
944c93d0312SJames Hogan #ifdef CONFIG_VIRT_TO_BUS
9453f7e212dSArnd Bergmann #ifndef virt_to_bus
9469216efafSThierry Reding static inline unsigned long virt_to_bus(void *address)
9473f7e212dSArnd Bergmann {
9489216efafSThierry Reding 	return (unsigned long)address;
9493f7e212dSArnd Bergmann }
9503f7e212dSArnd Bergmann 
9513f7e212dSArnd Bergmann static inline void *bus_to_virt(unsigned long address)
9523f7e212dSArnd Bergmann {
9533f7e212dSArnd Bergmann 	return (void *)address;
9543f7e212dSArnd Bergmann }
9553f7e212dSArnd Bergmann #endif
956c93d0312SJames Hogan #endif
9573f7e212dSArnd Bergmann 
958cd248341SJan Glauber #ifndef memset_io
9599216efafSThierry Reding #define memset_io memset_io
960c2327da0SAndy Shevchenko /**
961c2327da0SAndy Shevchenko  * memset_io	Set a range of I/O memory to a constant value
962c2327da0SAndy Shevchenko  * @addr:	The beginning of the I/O-memory range to set
963c2327da0SAndy Shevchenko  * @val:	The value to set the memory to
964c2327da0SAndy Shevchenko  * @count:	The number of bytes to set
965c2327da0SAndy Shevchenko  *
966c2327da0SAndy Shevchenko  * Set a range of I/O memory to a given value.
967c2327da0SAndy Shevchenko  */
9689216efafSThierry Reding static inline void memset_io(volatile void __iomem *addr, int value,
9699216efafSThierry Reding 			     size_t size)
9709216efafSThierry Reding {
9719216efafSThierry Reding 	memset(__io_virt(addr), value, size);
9729216efafSThierry Reding }
973cd248341SJan Glauber #endif
974cd248341SJan Glauber 
975cd248341SJan Glauber #ifndef memcpy_fromio
9769216efafSThierry Reding #define memcpy_fromio memcpy_fromio
977c2327da0SAndy Shevchenko /**
978c2327da0SAndy Shevchenko  * memcpy_fromio	Copy a block of data from I/O memory
979c2327da0SAndy Shevchenko  * @dst:		The (RAM) destination for the copy
980c2327da0SAndy Shevchenko  * @src:		The (I/O memory) source for the data
981c2327da0SAndy Shevchenko  * @count:		The number of bytes to copy
982c2327da0SAndy Shevchenko  *
983c2327da0SAndy Shevchenko  * Copy a block of data from I/O memory.
984c2327da0SAndy Shevchenko  */
9859216efafSThierry Reding static inline void memcpy_fromio(void *buffer,
9869216efafSThierry Reding 				 const volatile void __iomem *addr,
9879216efafSThierry Reding 				 size_t size)
9889216efafSThierry Reding {
9899216efafSThierry Reding 	memcpy(buffer, __io_virt(addr), size);
9909216efafSThierry Reding }
991cd248341SJan Glauber #endif
9929216efafSThierry Reding 
993cd248341SJan Glauber #ifndef memcpy_toio
9949216efafSThierry Reding #define memcpy_toio memcpy_toio
995c2327da0SAndy Shevchenko /**
996c2327da0SAndy Shevchenko  * memcpy_toio		Copy a block of data into I/O memory
997c2327da0SAndy Shevchenko  * @dst:		The (I/O memory) destination for the copy
998c2327da0SAndy Shevchenko  * @src:		The (RAM) source for the data
999c2327da0SAndy Shevchenko  * @count:		The number of bytes to copy
1000c2327da0SAndy Shevchenko  *
1001c2327da0SAndy Shevchenko  * Copy a block of data to I/O memory.
1002c2327da0SAndy Shevchenko  */
10039216efafSThierry Reding static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
10049216efafSThierry Reding 			       size_t size)
10059216efafSThierry Reding {
10069216efafSThierry Reding 	memcpy(__io_virt(addr), buffer, size);
10079216efafSThierry Reding }
1008cd248341SJan Glauber #endif
10093f7e212dSArnd Bergmann 
10103f7e212dSArnd Bergmann #endif /* __KERNEL__ */
10113f7e212dSArnd Bergmann 
10123f7e212dSArnd Bergmann #endif /* __ASM_GENERIC_IO_H */
1013