1b4d0d230SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2739d875dSDavid Howells /* Generic I/O port emulation. 33f7e212dSArnd Bergmann * 43f7e212dSArnd Bergmann * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 53f7e212dSArnd Bergmann * Written by David Howells (dhowells@redhat.com) 63f7e212dSArnd Bergmann */ 73f7e212dSArnd Bergmann #ifndef __ASM_GENERIC_IO_H 83f7e212dSArnd Bergmann #define __ASM_GENERIC_IO_H 93f7e212dSArnd Bergmann 103f7e212dSArnd Bergmann #include <asm/page.h> /* I/O is all done through memory accesses */ 119216efafSThierry Reding #include <linux/string.h> /* for memset() and memcpy() */ 123f7e212dSArnd Bergmann #include <linux/types.h> 133f7e212dSArnd Bergmann 143f7e212dSArnd Bergmann #ifdef CONFIG_GENERIC_IOMAP 153f7e212dSArnd Bergmann #include <asm-generic/iomap.h> 163f7e212dSArnd Bergmann #endif 173f7e212dSArnd Bergmann 1860ca1e5aSWill Deacon #include <asm/mmiowb.h> 1966eab4dfSMichael S. Tsirkin #include <asm-generic/pci_iomap.h> 2066eab4dfSMichael S. Tsirkin 2164e2c673SSinan Kaya #ifndef __io_br 2264e2c673SSinan Kaya #define __io_br() barrier() 2364e2c673SSinan Kaya #endif 2464e2c673SSinan Kaya 2564e2c673SSinan Kaya /* prevent prefetching of coherent DMA data ahead of a dma-complete */ 2664e2c673SSinan Kaya #ifndef __io_ar 2764e2c673SSinan Kaya #ifdef rmb 28abbbbc83SWill Deacon #define __io_ar(v) rmb() 2964e2c673SSinan Kaya #else 30abbbbc83SWill Deacon #define __io_ar(v) barrier() 3164e2c673SSinan Kaya #endif 3264e2c673SSinan Kaya #endif 3364e2c673SSinan Kaya 3464e2c673SSinan Kaya /* flush writes to coherent DMA data before possibly triggering a DMA read */ 3564e2c673SSinan Kaya #ifndef __io_bw 3664e2c673SSinan Kaya #ifdef wmb 3764e2c673SSinan Kaya #define __io_bw() wmb() 3864e2c673SSinan Kaya #else 3964e2c673SSinan Kaya #define __io_bw() barrier() 4064e2c673SSinan Kaya #endif 4164e2c673SSinan Kaya #endif 4264e2c673SSinan Kaya 4364e2c673SSinan Kaya /* serialize device access against a spin_unlock, usually handled there. */ 4464e2c673SSinan Kaya #ifndef __io_aw 4560ca1e5aSWill Deacon #define __io_aw() mmiowb_set_pending() 4664e2c673SSinan Kaya #endif 4764e2c673SSinan Kaya 4864e2c673SSinan Kaya #ifndef __io_pbw 4964e2c673SSinan Kaya #define __io_pbw() __io_bw() 5064e2c673SSinan Kaya #endif 5164e2c673SSinan Kaya 5264e2c673SSinan Kaya #ifndef __io_paw 5364e2c673SSinan Kaya #define __io_paw() __io_aw() 5464e2c673SSinan Kaya #endif 5564e2c673SSinan Kaya 5664e2c673SSinan Kaya #ifndef __io_pbr 5764e2c673SSinan Kaya #define __io_pbr() __io_br() 5864e2c673SSinan Kaya #endif 5964e2c673SSinan Kaya 6064e2c673SSinan Kaya #ifndef __io_par 61abbbbc83SWill Deacon #define __io_par(v) __io_ar(v) 6264e2c673SSinan Kaya #endif 6364e2c673SSinan Kaya 6464e2c673SSinan Kaya 653f7e212dSArnd Bergmann /* 669216efafSThierry Reding * __raw_{read,write}{b,w,l,q}() access memory in native endianness. 679216efafSThierry Reding * 689216efafSThierry Reding * On some architectures memory mapped IO needs to be accessed differently. 699216efafSThierry Reding * On the simple architectures, we just read/write the memory location 709216efafSThierry Reding * directly. 713f7e212dSArnd Bergmann */ 729216efafSThierry Reding 7335dbc0e0SMike Frysinger #ifndef __raw_readb 749216efafSThierry Reding #define __raw_readb __raw_readb 753f7e212dSArnd Bergmann static inline u8 __raw_readb(const volatile void __iomem *addr) 763f7e212dSArnd Bergmann { 773f7e212dSArnd Bergmann return *(const volatile u8 __force *)addr; 783f7e212dSArnd Bergmann } 7935dbc0e0SMike Frysinger #endif 803f7e212dSArnd Bergmann 8135dbc0e0SMike Frysinger #ifndef __raw_readw 829216efafSThierry Reding #define __raw_readw __raw_readw 833f7e212dSArnd Bergmann static inline u16 __raw_readw(const volatile void __iomem *addr) 843f7e212dSArnd Bergmann { 853f7e212dSArnd Bergmann return *(const volatile u16 __force *)addr; 863f7e212dSArnd Bergmann } 8735dbc0e0SMike Frysinger #endif 883f7e212dSArnd Bergmann 8935dbc0e0SMike Frysinger #ifndef __raw_readl 909216efafSThierry Reding #define __raw_readl __raw_readl 913f7e212dSArnd Bergmann static inline u32 __raw_readl(const volatile void __iomem *addr) 923f7e212dSArnd Bergmann { 933f7e212dSArnd Bergmann return *(const volatile u32 __force *)addr; 943f7e212dSArnd Bergmann } 9535dbc0e0SMike Frysinger #endif 963f7e212dSArnd Bergmann 973f7e212dSArnd Bergmann #ifdef CONFIG_64BIT 98cd248341SJan Glauber #ifndef __raw_readq 999216efafSThierry Reding #define __raw_readq __raw_readq 1003f7e212dSArnd Bergmann static inline u64 __raw_readq(const volatile void __iomem *addr) 1013f7e212dSArnd Bergmann { 1023f7e212dSArnd Bergmann return *(const volatile u64 __force *)addr; 1033f7e212dSArnd Bergmann } 104cd248341SJan Glauber #endif 1059216efafSThierry Reding #endif /* CONFIG_64BIT */ 106cd248341SJan Glauber 1079216efafSThierry Reding #ifndef __raw_writeb 1089216efafSThierry Reding #define __raw_writeb __raw_writeb 1099216efafSThierry Reding static inline void __raw_writeb(u8 value, volatile void __iomem *addr) 1109216efafSThierry Reding { 1119216efafSThierry Reding *(volatile u8 __force *)addr = value; 1129216efafSThierry Reding } 1139216efafSThierry Reding #endif 1149216efafSThierry Reding 1159216efafSThierry Reding #ifndef __raw_writew 1169216efafSThierry Reding #define __raw_writew __raw_writew 1179216efafSThierry Reding static inline void __raw_writew(u16 value, volatile void __iomem *addr) 1189216efafSThierry Reding { 1199216efafSThierry Reding *(volatile u16 __force *)addr = value; 1209216efafSThierry Reding } 1219216efafSThierry Reding #endif 1229216efafSThierry Reding 1239216efafSThierry Reding #ifndef __raw_writel 1249216efafSThierry Reding #define __raw_writel __raw_writel 1259216efafSThierry Reding static inline void __raw_writel(u32 value, volatile void __iomem *addr) 1269216efafSThierry Reding { 1279216efafSThierry Reding *(volatile u32 __force *)addr = value; 1289216efafSThierry Reding } 1299216efafSThierry Reding #endif 1309216efafSThierry Reding 1319216efafSThierry Reding #ifdef CONFIG_64BIT 1329216efafSThierry Reding #ifndef __raw_writeq 1339216efafSThierry Reding #define __raw_writeq __raw_writeq 1349216efafSThierry Reding static inline void __raw_writeq(u64 value, volatile void __iomem *addr) 1359216efafSThierry Reding { 1369216efafSThierry Reding *(volatile u64 __force *)addr = value; 1379216efafSThierry Reding } 1389216efafSThierry Reding #endif 1399216efafSThierry Reding #endif /* CONFIG_64BIT */ 1409216efafSThierry Reding 1419216efafSThierry Reding /* 1429216efafSThierry Reding * {read,write}{b,w,l,q}() access little endian memory and return result in 1439216efafSThierry Reding * native endianness. 1449216efafSThierry Reding */ 1459216efafSThierry Reding 1469216efafSThierry Reding #ifndef readb 1479216efafSThierry Reding #define readb readb 1489216efafSThierry Reding static inline u8 readb(const volatile void __iomem *addr) 1499216efafSThierry Reding { 150032d59e1SSinan Kaya u8 val; 151032d59e1SSinan Kaya 152032d59e1SSinan Kaya __io_br(); 153032d59e1SSinan Kaya val = __raw_readb(addr); 154abbbbc83SWill Deacon __io_ar(val); 155032d59e1SSinan Kaya return val; 1569216efafSThierry Reding } 1579216efafSThierry Reding #endif 1589216efafSThierry Reding 1599216efafSThierry Reding #ifndef readw 1609216efafSThierry Reding #define readw readw 1619216efafSThierry Reding static inline u16 readw(const volatile void __iomem *addr) 1629216efafSThierry Reding { 163032d59e1SSinan Kaya u16 val; 164032d59e1SSinan Kaya 165032d59e1SSinan Kaya __io_br(); 166032d59e1SSinan Kaya val = __le16_to_cpu(__raw_readw(addr)); 167abbbbc83SWill Deacon __io_ar(val); 168032d59e1SSinan Kaya return val; 1699216efafSThierry Reding } 1709216efafSThierry Reding #endif 1719216efafSThierry Reding 1729216efafSThierry Reding #ifndef readl 1739216efafSThierry Reding #define readl readl 1749216efafSThierry Reding static inline u32 readl(const volatile void __iomem *addr) 1759216efafSThierry Reding { 176032d59e1SSinan Kaya u32 val; 177032d59e1SSinan Kaya 178032d59e1SSinan Kaya __io_br(); 179032d59e1SSinan Kaya val = __le32_to_cpu(__raw_readl(addr)); 180abbbbc83SWill Deacon __io_ar(val); 181032d59e1SSinan Kaya return val; 1829216efafSThierry Reding } 1839216efafSThierry Reding #endif 1849216efafSThierry Reding 1859216efafSThierry Reding #ifdef CONFIG_64BIT 1869216efafSThierry Reding #ifndef readq 1877292e7e0SHeiko Carstens #define readq readq 1887292e7e0SHeiko Carstens static inline u64 readq(const volatile void __iomem *addr) 1897292e7e0SHeiko Carstens { 190032d59e1SSinan Kaya u64 val; 191032d59e1SSinan Kaya 192032d59e1SSinan Kaya __io_br(); 193032d59e1SSinan Kaya val = __le64_to_cpu(__raw_readq(addr)); 194abbbbc83SWill Deacon __io_ar(val); 195032d59e1SSinan Kaya return val; 1967292e7e0SHeiko Carstens } 1973f7e212dSArnd Bergmann #endif 198cd248341SJan Glauber #endif /* CONFIG_64BIT */ 199cd248341SJan Glauber 2009216efafSThierry Reding #ifndef writeb 2019216efafSThierry Reding #define writeb writeb 2029216efafSThierry Reding static inline void writeb(u8 value, volatile void __iomem *addr) 2039216efafSThierry Reding { 204755bd04aSSinan Kaya __io_bw(); 2059216efafSThierry Reding __raw_writeb(value, addr); 206755bd04aSSinan Kaya __io_aw(); 2079216efafSThierry Reding } 2087dc59bddSGuanXuetao #endif 2097dc59bddSGuanXuetao 2109216efafSThierry Reding #ifndef writew 2119216efafSThierry Reding #define writew writew 2129216efafSThierry Reding static inline void writew(u16 value, volatile void __iomem *addr) 2133f7e212dSArnd Bergmann { 214755bd04aSSinan Kaya __io_bw(); 2159216efafSThierry Reding __raw_writew(cpu_to_le16(value), addr); 216755bd04aSSinan Kaya __io_aw(); 2173f7e212dSArnd Bergmann } 2189216efafSThierry Reding #endif 2193f7e212dSArnd Bergmann 2209216efafSThierry Reding #ifndef writel 2219216efafSThierry Reding #define writel writel 2229216efafSThierry Reding static inline void writel(u32 value, volatile void __iomem *addr) 2233f7e212dSArnd Bergmann { 224755bd04aSSinan Kaya __io_bw(); 2259216efafSThierry Reding __raw_writel(__cpu_to_le32(value), addr); 226755bd04aSSinan Kaya __io_aw(); 2273f7e212dSArnd Bergmann } 2289216efafSThierry Reding #endif 2293f7e212dSArnd Bergmann 2309216efafSThierry Reding #ifdef CONFIG_64BIT 2319216efafSThierry Reding #ifndef writeq 2329216efafSThierry Reding #define writeq writeq 2339216efafSThierry Reding static inline void writeq(u64 value, volatile void __iomem *addr) 2343f7e212dSArnd Bergmann { 235755bd04aSSinan Kaya __io_bw(); 2369216efafSThierry Reding __raw_writeq(__cpu_to_le64(value), addr); 237755bd04aSSinan Kaya __io_aw(); 2383f7e212dSArnd Bergmann } 2399216efafSThierry Reding #endif 2409216efafSThierry Reding #endif /* CONFIG_64BIT */ 2413f7e212dSArnd Bergmann 2429ab3a7a0SThierry Reding /* 2431c8d2969SArnd Bergmann * {read,write}{b,w,l,q}_relaxed() are like the regular version, but 2441c8d2969SArnd Bergmann * are not guaranteed to provide ordering against spinlocks or memory 2451c8d2969SArnd Bergmann * accesses. 2461c8d2969SArnd Bergmann */ 2471c8d2969SArnd Bergmann #ifndef readb_relaxed 2488875c554SSinan Kaya #define readb_relaxed readb_relaxed 2498875c554SSinan Kaya static inline u8 readb_relaxed(const volatile void __iomem *addr) 2508875c554SSinan Kaya { 2518875c554SSinan Kaya return __raw_readb(addr); 2528875c554SSinan Kaya } 2531c8d2969SArnd Bergmann #endif 2541c8d2969SArnd Bergmann 2551c8d2969SArnd Bergmann #ifndef readw_relaxed 2568875c554SSinan Kaya #define readw_relaxed readw_relaxed 2578875c554SSinan Kaya static inline u16 readw_relaxed(const volatile void __iomem *addr) 2588875c554SSinan Kaya { 2598875c554SSinan Kaya return __le16_to_cpu(__raw_readw(addr)); 2608875c554SSinan Kaya } 2611c8d2969SArnd Bergmann #endif 2621c8d2969SArnd Bergmann 2631c8d2969SArnd Bergmann #ifndef readl_relaxed 2648875c554SSinan Kaya #define readl_relaxed readl_relaxed 2658875c554SSinan Kaya static inline u32 readl_relaxed(const volatile void __iomem *addr) 2668875c554SSinan Kaya { 2678875c554SSinan Kaya return __le32_to_cpu(__raw_readl(addr)); 2688875c554SSinan Kaya } 2691c8d2969SArnd Bergmann #endif 2701c8d2969SArnd Bergmann 271e511267bSRobin Murphy #if defined(readq) && !defined(readq_relaxed) 2728875c554SSinan Kaya #define readq_relaxed readq_relaxed 2738875c554SSinan Kaya static inline u64 readq_relaxed(const volatile void __iomem *addr) 2748875c554SSinan Kaya { 2758875c554SSinan Kaya return __le64_to_cpu(__raw_readq(addr)); 2768875c554SSinan Kaya } 2779439eb3aSWill Deacon #endif 2783f7e212dSArnd Bergmann 2791c8d2969SArnd Bergmann #ifndef writeb_relaxed 280a71e7c44SSinan Kaya #define writeb_relaxed writeb_relaxed 281a71e7c44SSinan Kaya static inline void writeb_relaxed(u8 value, volatile void __iomem *addr) 282a71e7c44SSinan Kaya { 283a71e7c44SSinan Kaya __raw_writeb(value, addr); 284a71e7c44SSinan Kaya } 2851c8d2969SArnd Bergmann #endif 2861c8d2969SArnd Bergmann 2871c8d2969SArnd Bergmann #ifndef writew_relaxed 288a71e7c44SSinan Kaya #define writew_relaxed writew_relaxed 289a71e7c44SSinan Kaya static inline void writew_relaxed(u16 value, volatile void __iomem *addr) 290a71e7c44SSinan Kaya { 291a71e7c44SSinan Kaya __raw_writew(cpu_to_le16(value), addr); 292a71e7c44SSinan Kaya } 2931c8d2969SArnd Bergmann #endif 2941c8d2969SArnd Bergmann 2951c8d2969SArnd Bergmann #ifndef writel_relaxed 296a71e7c44SSinan Kaya #define writel_relaxed writel_relaxed 297a71e7c44SSinan Kaya static inline void writel_relaxed(u32 value, volatile void __iomem *addr) 298a71e7c44SSinan Kaya { 299a71e7c44SSinan Kaya __raw_writel(__cpu_to_le32(value), addr); 300a71e7c44SSinan Kaya } 3011c8d2969SArnd Bergmann #endif 3021c8d2969SArnd Bergmann 303e511267bSRobin Murphy #if defined(writeq) && !defined(writeq_relaxed) 304a71e7c44SSinan Kaya #define writeq_relaxed writeq_relaxed 305a71e7c44SSinan Kaya static inline void writeq_relaxed(u64 value, volatile void __iomem *addr) 306a71e7c44SSinan Kaya { 307a71e7c44SSinan Kaya __raw_writeq(__cpu_to_le64(value), addr); 308a71e7c44SSinan Kaya } 3091c8d2969SArnd Bergmann #endif 3101c8d2969SArnd Bergmann 3111c8d2969SArnd Bergmann /* 3129ab3a7a0SThierry Reding * {read,write}s{b,w,l,q}() repeatedly access the same memory address in 3139ab3a7a0SThierry Reding * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times). 3149ab3a7a0SThierry Reding */ 3159ab3a7a0SThierry Reding #ifndef readsb 3169ab3a7a0SThierry Reding #define readsb readsb 3179ab3a7a0SThierry Reding static inline void readsb(const volatile void __iomem *addr, void *buffer, 3189ab3a7a0SThierry Reding unsigned int count) 3193f7e212dSArnd Bergmann { 3203f7e212dSArnd Bergmann if (count) { 3213f7e212dSArnd Bergmann u8 *buf = buffer; 3229ab3a7a0SThierry Reding 3233f7e212dSArnd Bergmann do { 3249ab3a7a0SThierry Reding u8 x = __raw_readb(addr); 3253f7e212dSArnd Bergmann *buf++ = x; 3263f7e212dSArnd Bergmann } while (--count); 3273f7e212dSArnd Bergmann } 3283f7e212dSArnd Bergmann } 32935dbc0e0SMike Frysinger #endif 3303f7e212dSArnd Bergmann 3319ab3a7a0SThierry Reding #ifndef readsw 3329ab3a7a0SThierry Reding #define readsw readsw 3339ab3a7a0SThierry Reding static inline void readsw(const volatile void __iomem *addr, void *buffer, 3349ab3a7a0SThierry Reding unsigned int count) 3353f7e212dSArnd Bergmann { 3363f7e212dSArnd Bergmann if (count) { 3373f7e212dSArnd Bergmann u16 *buf = buffer; 3389ab3a7a0SThierry Reding 3393f7e212dSArnd Bergmann do { 3409ab3a7a0SThierry Reding u16 x = __raw_readw(addr); 3413f7e212dSArnd Bergmann *buf++ = x; 3423f7e212dSArnd Bergmann } while (--count); 3433f7e212dSArnd Bergmann } 3443f7e212dSArnd Bergmann } 34535dbc0e0SMike Frysinger #endif 3463f7e212dSArnd Bergmann 3479ab3a7a0SThierry Reding #ifndef readsl 3489ab3a7a0SThierry Reding #define readsl readsl 3499ab3a7a0SThierry Reding static inline void readsl(const volatile void __iomem *addr, void *buffer, 3509ab3a7a0SThierry Reding unsigned int count) 3513f7e212dSArnd Bergmann { 3523f7e212dSArnd Bergmann if (count) { 3533f7e212dSArnd Bergmann u32 *buf = buffer; 3549ab3a7a0SThierry Reding 3553f7e212dSArnd Bergmann do { 3569ab3a7a0SThierry Reding u32 x = __raw_readl(addr); 3573f7e212dSArnd Bergmann *buf++ = x; 3583f7e212dSArnd Bergmann } while (--count); 3593f7e212dSArnd Bergmann } 3603f7e212dSArnd Bergmann } 36135dbc0e0SMike Frysinger #endif 3623f7e212dSArnd Bergmann 3639ab3a7a0SThierry Reding #ifdef CONFIG_64BIT 3649ab3a7a0SThierry Reding #ifndef readsq 3659ab3a7a0SThierry Reding #define readsq readsq 3669ab3a7a0SThierry Reding static inline void readsq(const volatile void __iomem *addr, void *buffer, 3679ab3a7a0SThierry Reding unsigned int count) 3689ab3a7a0SThierry Reding { 3699ab3a7a0SThierry Reding if (count) { 3709ab3a7a0SThierry Reding u64 *buf = buffer; 3719ab3a7a0SThierry Reding 3729ab3a7a0SThierry Reding do { 3739ab3a7a0SThierry Reding u64 x = __raw_readq(addr); 3749ab3a7a0SThierry Reding *buf++ = x; 3759ab3a7a0SThierry Reding } while (--count); 3769ab3a7a0SThierry Reding } 3779ab3a7a0SThierry Reding } 3789ab3a7a0SThierry Reding #endif 3799ab3a7a0SThierry Reding #endif /* CONFIG_64BIT */ 3809ab3a7a0SThierry Reding 3819ab3a7a0SThierry Reding #ifndef writesb 3829ab3a7a0SThierry Reding #define writesb writesb 3839ab3a7a0SThierry Reding static inline void writesb(volatile void __iomem *addr, const void *buffer, 3849ab3a7a0SThierry Reding unsigned int count) 3853f7e212dSArnd Bergmann { 3863f7e212dSArnd Bergmann if (count) { 3873f7e212dSArnd Bergmann const u8 *buf = buffer; 3889ab3a7a0SThierry Reding 3893f7e212dSArnd Bergmann do { 3909ab3a7a0SThierry Reding __raw_writeb(*buf++, addr); 3913f7e212dSArnd Bergmann } while (--count); 3923f7e212dSArnd Bergmann } 3933f7e212dSArnd Bergmann } 39435dbc0e0SMike Frysinger #endif 3953f7e212dSArnd Bergmann 3969ab3a7a0SThierry Reding #ifndef writesw 3979ab3a7a0SThierry Reding #define writesw writesw 3989ab3a7a0SThierry Reding static inline void writesw(volatile void __iomem *addr, const void *buffer, 3999ab3a7a0SThierry Reding unsigned int count) 4003f7e212dSArnd Bergmann { 4013f7e212dSArnd Bergmann if (count) { 4023f7e212dSArnd Bergmann const u16 *buf = buffer; 4039ab3a7a0SThierry Reding 4043f7e212dSArnd Bergmann do { 4059ab3a7a0SThierry Reding __raw_writew(*buf++, addr); 4063f7e212dSArnd Bergmann } while (--count); 4073f7e212dSArnd Bergmann } 4083f7e212dSArnd Bergmann } 40935dbc0e0SMike Frysinger #endif 4103f7e212dSArnd Bergmann 4119ab3a7a0SThierry Reding #ifndef writesl 4129ab3a7a0SThierry Reding #define writesl writesl 4139ab3a7a0SThierry Reding static inline void writesl(volatile void __iomem *addr, const void *buffer, 4149ab3a7a0SThierry Reding unsigned int count) 4153f7e212dSArnd Bergmann { 4163f7e212dSArnd Bergmann if (count) { 4173f7e212dSArnd Bergmann const u32 *buf = buffer; 4189ab3a7a0SThierry Reding 4193f7e212dSArnd Bergmann do { 4209ab3a7a0SThierry Reding __raw_writel(*buf++, addr); 4213f7e212dSArnd Bergmann } while (--count); 4223f7e212dSArnd Bergmann } 4233f7e212dSArnd Bergmann } 42435dbc0e0SMike Frysinger #endif 4253f7e212dSArnd Bergmann 4269ab3a7a0SThierry Reding #ifdef CONFIG_64BIT 4279ab3a7a0SThierry Reding #ifndef writesq 4289ab3a7a0SThierry Reding #define writesq writesq 4299ab3a7a0SThierry Reding static inline void writesq(volatile void __iomem *addr, const void *buffer, 4309ab3a7a0SThierry Reding unsigned int count) 4319ab3a7a0SThierry Reding { 4329ab3a7a0SThierry Reding if (count) { 4339ab3a7a0SThierry Reding const u64 *buf = buffer; 4343f7e212dSArnd Bergmann 4359ab3a7a0SThierry Reding do { 4369ab3a7a0SThierry Reding __raw_writeq(*buf++, addr); 4379ab3a7a0SThierry Reding } while (--count); 4389ab3a7a0SThierry Reding } 4399ab3a7a0SThierry Reding } 4409ab3a7a0SThierry Reding #endif 4419ab3a7a0SThierry Reding #endif /* CONFIG_64BIT */ 4423f7e212dSArnd Bergmann 4439216efafSThierry Reding #ifndef PCI_IOBASE 4449216efafSThierry Reding #define PCI_IOBASE ((void __iomem *)0) 4459216efafSThierry Reding #endif 4469216efafSThierry Reding 4477dc59bddSGuanXuetao #ifndef IO_SPACE_LIMIT 4487dc59bddSGuanXuetao #define IO_SPACE_LIMIT 0xffff 4497dc59bddSGuanXuetao #endif 4503f7e212dSArnd Bergmann 451031e3601SZhichang Yuan #include <linux/logic_pio.h> 452031e3601SZhichang Yuan 4539216efafSThierry Reding /* 4549216efafSThierry Reding * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be 4559216efafSThierry Reding * implemented on hardware that needs an additional delay for I/O accesses to 4569216efafSThierry Reding * take effect. 4579216efafSThierry Reding */ 4589216efafSThierry Reding 4599216efafSThierry Reding #ifndef inb 4609216efafSThierry Reding #define inb inb 4619216efafSThierry Reding static inline u8 inb(unsigned long addr) 4629216efafSThierry Reding { 46387fe2d54SSinan Kaya u8 val; 46487fe2d54SSinan Kaya 46587fe2d54SSinan Kaya __io_pbr(); 46687fe2d54SSinan Kaya val = __raw_readb(PCI_IOBASE + addr); 467abbbbc83SWill Deacon __io_par(val); 46887fe2d54SSinan Kaya return val; 4699216efafSThierry Reding } 4709216efafSThierry Reding #endif 4719216efafSThierry Reding 4729216efafSThierry Reding #ifndef inw 4739216efafSThierry Reding #define inw inw 4749216efafSThierry Reding static inline u16 inw(unsigned long addr) 4759216efafSThierry Reding { 47687fe2d54SSinan Kaya u16 val; 47787fe2d54SSinan Kaya 47887fe2d54SSinan Kaya __io_pbr(); 47987fe2d54SSinan Kaya val = __le16_to_cpu(__raw_readw(PCI_IOBASE + addr)); 480abbbbc83SWill Deacon __io_par(val); 48187fe2d54SSinan Kaya return val; 4829216efafSThierry Reding } 4839216efafSThierry Reding #endif 4849216efafSThierry Reding 4859216efafSThierry Reding #ifndef inl 4869216efafSThierry Reding #define inl inl 4879216efafSThierry Reding static inline u32 inl(unsigned long addr) 4889216efafSThierry Reding { 48987fe2d54SSinan Kaya u32 val; 49087fe2d54SSinan Kaya 49187fe2d54SSinan Kaya __io_pbr(); 49287fe2d54SSinan Kaya val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr)); 493abbbbc83SWill Deacon __io_par(val); 49487fe2d54SSinan Kaya return val; 4959216efafSThierry Reding } 4969216efafSThierry Reding #endif 4979216efafSThierry Reding 4989216efafSThierry Reding #ifndef outb 4999216efafSThierry Reding #define outb outb 5009216efafSThierry Reding static inline void outb(u8 value, unsigned long addr) 5019216efafSThierry Reding { 502a7851aa5SSinan Kaya __io_pbw(); 503a7851aa5SSinan Kaya __raw_writeb(value, PCI_IOBASE + addr); 504a7851aa5SSinan Kaya __io_paw(); 5059216efafSThierry Reding } 5069216efafSThierry Reding #endif 5079216efafSThierry Reding 5089216efafSThierry Reding #ifndef outw 5099216efafSThierry Reding #define outw outw 5109216efafSThierry Reding static inline void outw(u16 value, unsigned long addr) 5119216efafSThierry Reding { 512a7851aa5SSinan Kaya __io_pbw(); 513a7851aa5SSinan Kaya __raw_writew(cpu_to_le16(value), PCI_IOBASE + addr); 514a7851aa5SSinan Kaya __io_paw(); 5159216efafSThierry Reding } 5169216efafSThierry Reding #endif 5179216efafSThierry Reding 5189216efafSThierry Reding #ifndef outl 5199216efafSThierry Reding #define outl outl 5209216efafSThierry Reding static inline void outl(u32 value, unsigned long addr) 5219216efafSThierry Reding { 522a7851aa5SSinan Kaya __io_pbw(); 523a7851aa5SSinan Kaya __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr); 524a7851aa5SSinan Kaya __io_paw(); 5259216efafSThierry Reding } 5269216efafSThierry Reding #endif 5279216efafSThierry Reding 5289216efafSThierry Reding #ifndef inb_p 5299216efafSThierry Reding #define inb_p inb_p 5309216efafSThierry Reding static inline u8 inb_p(unsigned long addr) 5319216efafSThierry Reding { 5329216efafSThierry Reding return inb(addr); 5339216efafSThierry Reding } 5349216efafSThierry Reding #endif 5359216efafSThierry Reding 5369216efafSThierry Reding #ifndef inw_p 5379216efafSThierry Reding #define inw_p inw_p 5389216efafSThierry Reding static inline u16 inw_p(unsigned long addr) 5399216efafSThierry Reding { 5409216efafSThierry Reding return inw(addr); 5419216efafSThierry Reding } 5429216efafSThierry Reding #endif 5439216efafSThierry Reding 5449216efafSThierry Reding #ifndef inl_p 5459216efafSThierry Reding #define inl_p inl_p 5469216efafSThierry Reding static inline u32 inl_p(unsigned long addr) 5479216efafSThierry Reding { 5489216efafSThierry Reding return inl(addr); 5499216efafSThierry Reding } 5509216efafSThierry Reding #endif 5519216efafSThierry Reding 5529216efafSThierry Reding #ifndef outb_p 5539216efafSThierry Reding #define outb_p outb_p 5549216efafSThierry Reding static inline void outb_p(u8 value, unsigned long addr) 5559216efafSThierry Reding { 5569216efafSThierry Reding outb(value, addr); 5579216efafSThierry Reding } 5589216efafSThierry Reding #endif 5599216efafSThierry Reding 5609216efafSThierry Reding #ifndef outw_p 5619216efafSThierry Reding #define outw_p outw_p 5629216efafSThierry Reding static inline void outw_p(u16 value, unsigned long addr) 5639216efafSThierry Reding { 5649216efafSThierry Reding outw(value, addr); 5659216efafSThierry Reding } 5669216efafSThierry Reding #endif 5679216efafSThierry Reding 5689216efafSThierry Reding #ifndef outl_p 5699216efafSThierry Reding #define outl_p outl_p 5709216efafSThierry Reding static inline void outl_p(u32 value, unsigned long addr) 5719216efafSThierry Reding { 5729216efafSThierry Reding outl(value, addr); 5739216efafSThierry Reding } 5749216efafSThierry Reding #endif 5759216efafSThierry Reding 5769ab3a7a0SThierry Reding /* 5779ab3a7a0SThierry Reding * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a 5789ab3a7a0SThierry Reding * single I/O port multiple times. 5799ab3a7a0SThierry Reding */ 5809ab3a7a0SThierry Reding 5819ab3a7a0SThierry Reding #ifndef insb 5829ab3a7a0SThierry Reding #define insb insb 5839ab3a7a0SThierry Reding static inline void insb(unsigned long addr, void *buffer, unsigned int count) 5849ab3a7a0SThierry Reding { 5859ab3a7a0SThierry Reding readsb(PCI_IOBASE + addr, buffer, count); 5869ab3a7a0SThierry Reding } 5879ab3a7a0SThierry Reding #endif 5889ab3a7a0SThierry Reding 5899ab3a7a0SThierry Reding #ifndef insw 5909ab3a7a0SThierry Reding #define insw insw 5919ab3a7a0SThierry Reding static inline void insw(unsigned long addr, void *buffer, unsigned int count) 5929ab3a7a0SThierry Reding { 5939ab3a7a0SThierry Reding readsw(PCI_IOBASE + addr, buffer, count); 5949ab3a7a0SThierry Reding } 5959ab3a7a0SThierry Reding #endif 5969ab3a7a0SThierry Reding 5979ab3a7a0SThierry Reding #ifndef insl 5989ab3a7a0SThierry Reding #define insl insl 5999ab3a7a0SThierry Reding static inline void insl(unsigned long addr, void *buffer, unsigned int count) 6009ab3a7a0SThierry Reding { 6019ab3a7a0SThierry Reding readsl(PCI_IOBASE + addr, buffer, count); 6029ab3a7a0SThierry Reding } 6039ab3a7a0SThierry Reding #endif 6049ab3a7a0SThierry Reding 6059ab3a7a0SThierry Reding #ifndef outsb 6069ab3a7a0SThierry Reding #define outsb outsb 6079ab3a7a0SThierry Reding static inline void outsb(unsigned long addr, const void *buffer, 6089ab3a7a0SThierry Reding unsigned int count) 6099ab3a7a0SThierry Reding { 6109ab3a7a0SThierry Reding writesb(PCI_IOBASE + addr, buffer, count); 6119ab3a7a0SThierry Reding } 6129ab3a7a0SThierry Reding #endif 6139ab3a7a0SThierry Reding 6149ab3a7a0SThierry Reding #ifndef outsw 6159ab3a7a0SThierry Reding #define outsw outsw 6169ab3a7a0SThierry Reding static inline void outsw(unsigned long addr, const void *buffer, 6179ab3a7a0SThierry Reding unsigned int count) 6189ab3a7a0SThierry Reding { 6199ab3a7a0SThierry Reding writesw(PCI_IOBASE + addr, buffer, count); 6209ab3a7a0SThierry Reding } 6219ab3a7a0SThierry Reding #endif 6229ab3a7a0SThierry Reding 6239ab3a7a0SThierry Reding #ifndef outsl 6249ab3a7a0SThierry Reding #define outsl outsl 6259ab3a7a0SThierry Reding static inline void outsl(unsigned long addr, const void *buffer, 6269ab3a7a0SThierry Reding unsigned int count) 6279ab3a7a0SThierry Reding { 6289ab3a7a0SThierry Reding writesl(PCI_IOBASE + addr, buffer, count); 6299ab3a7a0SThierry Reding } 6309ab3a7a0SThierry Reding #endif 6319ab3a7a0SThierry Reding 6329ab3a7a0SThierry Reding #ifndef insb_p 6339ab3a7a0SThierry Reding #define insb_p insb_p 6349ab3a7a0SThierry Reding static inline void insb_p(unsigned long addr, void *buffer, unsigned int count) 6359ab3a7a0SThierry Reding { 6369ab3a7a0SThierry Reding insb(addr, buffer, count); 6379ab3a7a0SThierry Reding } 6389ab3a7a0SThierry Reding #endif 6399ab3a7a0SThierry Reding 6409ab3a7a0SThierry Reding #ifndef insw_p 6419ab3a7a0SThierry Reding #define insw_p insw_p 6429ab3a7a0SThierry Reding static inline void insw_p(unsigned long addr, void *buffer, unsigned int count) 6439ab3a7a0SThierry Reding { 6449ab3a7a0SThierry Reding insw(addr, buffer, count); 6459ab3a7a0SThierry Reding } 6469ab3a7a0SThierry Reding #endif 6479ab3a7a0SThierry Reding 6489ab3a7a0SThierry Reding #ifndef insl_p 6499ab3a7a0SThierry Reding #define insl_p insl_p 6509ab3a7a0SThierry Reding static inline void insl_p(unsigned long addr, void *buffer, unsigned int count) 6519ab3a7a0SThierry Reding { 6529ab3a7a0SThierry Reding insl(addr, buffer, count); 6539ab3a7a0SThierry Reding } 6549ab3a7a0SThierry Reding #endif 6559ab3a7a0SThierry Reding 6569ab3a7a0SThierry Reding #ifndef outsb_p 6579ab3a7a0SThierry Reding #define outsb_p outsb_p 6589ab3a7a0SThierry Reding static inline void outsb_p(unsigned long addr, const void *buffer, 6599ab3a7a0SThierry Reding unsigned int count) 6609ab3a7a0SThierry Reding { 6619ab3a7a0SThierry Reding outsb(addr, buffer, count); 6629ab3a7a0SThierry Reding } 6639ab3a7a0SThierry Reding #endif 6649ab3a7a0SThierry Reding 6659ab3a7a0SThierry Reding #ifndef outsw_p 6669ab3a7a0SThierry Reding #define outsw_p outsw_p 6679ab3a7a0SThierry Reding static inline void outsw_p(unsigned long addr, const void *buffer, 6689ab3a7a0SThierry Reding unsigned int count) 6699ab3a7a0SThierry Reding { 6709ab3a7a0SThierry Reding outsw(addr, buffer, count); 6719ab3a7a0SThierry Reding } 6729ab3a7a0SThierry Reding #endif 6739ab3a7a0SThierry Reding 6749ab3a7a0SThierry Reding #ifndef outsl_p 6759ab3a7a0SThierry Reding #define outsl_p outsl_p 6769ab3a7a0SThierry Reding static inline void outsl_p(unsigned long addr, const void *buffer, 6779ab3a7a0SThierry Reding unsigned int count) 6789ab3a7a0SThierry Reding { 6799ab3a7a0SThierry Reding outsl(addr, buffer, count); 6809ab3a7a0SThierry Reding } 6819ab3a7a0SThierry Reding #endif 6829ab3a7a0SThierry Reding 6839216efafSThierry Reding #ifndef CONFIG_GENERIC_IOMAP 6849216efafSThierry Reding #ifndef ioread8 6859216efafSThierry Reding #define ioread8 ioread8 6869216efafSThierry Reding static inline u8 ioread8(const volatile void __iomem *addr) 6879216efafSThierry Reding { 6889216efafSThierry Reding return readb(addr); 6899216efafSThierry Reding } 6909216efafSThierry Reding #endif 6919216efafSThierry Reding 6929216efafSThierry Reding #ifndef ioread16 6939216efafSThierry Reding #define ioread16 ioread16 6949216efafSThierry Reding static inline u16 ioread16(const volatile void __iomem *addr) 6959216efafSThierry Reding { 6969216efafSThierry Reding return readw(addr); 6979216efafSThierry Reding } 6989216efafSThierry Reding #endif 6999216efafSThierry Reding 7009216efafSThierry Reding #ifndef ioread32 7019216efafSThierry Reding #define ioread32 ioread32 7029216efafSThierry Reding static inline u32 ioread32(const volatile void __iomem *addr) 7039216efafSThierry Reding { 7049216efafSThierry Reding return readl(addr); 7059216efafSThierry Reding } 7069216efafSThierry Reding #endif 7079216efafSThierry Reding 7089e44fb18SHoria Geantă #ifdef CONFIG_64BIT 7099e44fb18SHoria Geantă #ifndef ioread64 7109e44fb18SHoria Geantă #define ioread64 ioread64 7119e44fb18SHoria Geantă static inline u64 ioread64(const volatile void __iomem *addr) 7129e44fb18SHoria Geantă { 7139e44fb18SHoria Geantă return readq(addr); 7149e44fb18SHoria Geantă } 7159e44fb18SHoria Geantă #endif 7169e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 7179e44fb18SHoria Geantă 7189216efafSThierry Reding #ifndef iowrite8 7199216efafSThierry Reding #define iowrite8 iowrite8 7209216efafSThierry Reding static inline void iowrite8(u8 value, volatile void __iomem *addr) 7219216efafSThierry Reding { 7229216efafSThierry Reding writeb(value, addr); 7239216efafSThierry Reding } 7249216efafSThierry Reding #endif 7259216efafSThierry Reding 7269216efafSThierry Reding #ifndef iowrite16 7279216efafSThierry Reding #define iowrite16 iowrite16 7289216efafSThierry Reding static inline void iowrite16(u16 value, volatile void __iomem *addr) 7299216efafSThierry Reding { 7309216efafSThierry Reding writew(value, addr); 7319216efafSThierry Reding } 7329216efafSThierry Reding #endif 7339216efafSThierry Reding 7349216efafSThierry Reding #ifndef iowrite32 7359216efafSThierry Reding #define iowrite32 iowrite32 7369216efafSThierry Reding static inline void iowrite32(u32 value, volatile void __iomem *addr) 7379216efafSThierry Reding { 7389216efafSThierry Reding writel(value, addr); 7399216efafSThierry Reding } 7409216efafSThierry Reding #endif 7419216efafSThierry Reding 7429e44fb18SHoria Geantă #ifdef CONFIG_64BIT 7439e44fb18SHoria Geantă #ifndef iowrite64 7449e44fb18SHoria Geantă #define iowrite64 iowrite64 7459e44fb18SHoria Geantă static inline void iowrite64(u64 value, volatile void __iomem *addr) 7469e44fb18SHoria Geantă { 7479e44fb18SHoria Geantă writeq(value, addr); 7489e44fb18SHoria Geantă } 7499e44fb18SHoria Geantă #endif 7509e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 7519e44fb18SHoria Geantă 7529216efafSThierry Reding #ifndef ioread16be 7539216efafSThierry Reding #define ioread16be ioread16be 7549216efafSThierry Reding static inline u16 ioread16be(const volatile void __iomem *addr) 7559216efafSThierry Reding { 7567a1aedbaSHoria Geantă return swab16(readw(addr)); 7579216efafSThierry Reding } 7589216efafSThierry Reding #endif 7599216efafSThierry Reding 7609216efafSThierry Reding #ifndef ioread32be 7619216efafSThierry Reding #define ioread32be ioread32be 7629216efafSThierry Reding static inline u32 ioread32be(const volatile void __iomem *addr) 7639216efafSThierry Reding { 7647a1aedbaSHoria Geantă return swab32(readl(addr)); 7659216efafSThierry Reding } 7669216efafSThierry Reding #endif 7679216efafSThierry Reding 7689e44fb18SHoria Geantă #ifdef CONFIG_64BIT 7699e44fb18SHoria Geantă #ifndef ioread64be 7709e44fb18SHoria Geantă #define ioread64be ioread64be 7719e44fb18SHoria Geantă static inline u64 ioread64be(const volatile void __iomem *addr) 7729e44fb18SHoria Geantă { 7739e44fb18SHoria Geantă return swab64(readq(addr)); 7749e44fb18SHoria Geantă } 7759e44fb18SHoria Geantă #endif 7769e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 7779e44fb18SHoria Geantă 7789216efafSThierry Reding #ifndef iowrite16be 7799216efafSThierry Reding #define iowrite16be iowrite16be 7809216efafSThierry Reding static inline void iowrite16be(u16 value, void volatile __iomem *addr) 7819216efafSThierry Reding { 7827a1aedbaSHoria Geantă writew(swab16(value), addr); 7839216efafSThierry Reding } 7849216efafSThierry Reding #endif 7859216efafSThierry Reding 7869216efafSThierry Reding #ifndef iowrite32be 7879216efafSThierry Reding #define iowrite32be iowrite32be 7889216efafSThierry Reding static inline void iowrite32be(u32 value, volatile void __iomem *addr) 7899216efafSThierry Reding { 7907a1aedbaSHoria Geantă writel(swab32(value), addr); 7919216efafSThierry Reding } 7929216efafSThierry Reding #endif 7939ab3a7a0SThierry Reding 7949e44fb18SHoria Geantă #ifdef CONFIG_64BIT 7959e44fb18SHoria Geantă #ifndef iowrite64be 7969e44fb18SHoria Geantă #define iowrite64be iowrite64be 7979e44fb18SHoria Geantă static inline void iowrite64be(u64 value, volatile void __iomem *addr) 7989e44fb18SHoria Geantă { 7999e44fb18SHoria Geantă writeq(swab64(value), addr); 8009e44fb18SHoria Geantă } 8019e44fb18SHoria Geantă #endif 8029e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 8039e44fb18SHoria Geantă 8049ab3a7a0SThierry Reding #ifndef ioread8_rep 8059ab3a7a0SThierry Reding #define ioread8_rep ioread8_rep 8069ab3a7a0SThierry Reding static inline void ioread8_rep(const volatile void __iomem *addr, void *buffer, 8079ab3a7a0SThierry Reding unsigned int count) 8089ab3a7a0SThierry Reding { 8099ab3a7a0SThierry Reding readsb(addr, buffer, count); 8109ab3a7a0SThierry Reding } 8119ab3a7a0SThierry Reding #endif 8129ab3a7a0SThierry Reding 8139ab3a7a0SThierry Reding #ifndef ioread16_rep 8149ab3a7a0SThierry Reding #define ioread16_rep ioread16_rep 8159ab3a7a0SThierry Reding static inline void ioread16_rep(const volatile void __iomem *addr, 8169ab3a7a0SThierry Reding void *buffer, unsigned int count) 8179ab3a7a0SThierry Reding { 8189ab3a7a0SThierry Reding readsw(addr, buffer, count); 8199ab3a7a0SThierry Reding } 8209ab3a7a0SThierry Reding #endif 8219ab3a7a0SThierry Reding 8229ab3a7a0SThierry Reding #ifndef ioread32_rep 8239ab3a7a0SThierry Reding #define ioread32_rep ioread32_rep 8249ab3a7a0SThierry Reding static inline void ioread32_rep(const volatile void __iomem *addr, 8259ab3a7a0SThierry Reding void *buffer, unsigned int count) 8269ab3a7a0SThierry Reding { 8279ab3a7a0SThierry Reding readsl(addr, buffer, count); 8289ab3a7a0SThierry Reding } 8299ab3a7a0SThierry Reding #endif 8309ab3a7a0SThierry Reding 8319e44fb18SHoria Geantă #ifdef CONFIG_64BIT 8329e44fb18SHoria Geantă #ifndef ioread64_rep 8339e44fb18SHoria Geantă #define ioread64_rep ioread64_rep 8349e44fb18SHoria Geantă static inline void ioread64_rep(const volatile void __iomem *addr, 8359e44fb18SHoria Geantă void *buffer, unsigned int count) 8369e44fb18SHoria Geantă { 8379e44fb18SHoria Geantă readsq(addr, buffer, count); 8389e44fb18SHoria Geantă } 8399e44fb18SHoria Geantă #endif 8409e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 8419e44fb18SHoria Geantă 8429ab3a7a0SThierry Reding #ifndef iowrite8_rep 8439ab3a7a0SThierry Reding #define iowrite8_rep iowrite8_rep 8449ab3a7a0SThierry Reding static inline void iowrite8_rep(volatile void __iomem *addr, 8459ab3a7a0SThierry Reding const void *buffer, 8469ab3a7a0SThierry Reding unsigned int count) 8479ab3a7a0SThierry Reding { 8489ab3a7a0SThierry Reding writesb(addr, buffer, count); 8499ab3a7a0SThierry Reding } 8509ab3a7a0SThierry Reding #endif 8519ab3a7a0SThierry Reding 8529ab3a7a0SThierry Reding #ifndef iowrite16_rep 8539ab3a7a0SThierry Reding #define iowrite16_rep iowrite16_rep 8549ab3a7a0SThierry Reding static inline void iowrite16_rep(volatile void __iomem *addr, 8559ab3a7a0SThierry Reding const void *buffer, 8569ab3a7a0SThierry Reding unsigned int count) 8579ab3a7a0SThierry Reding { 8589ab3a7a0SThierry Reding writesw(addr, buffer, count); 8599ab3a7a0SThierry Reding } 8609ab3a7a0SThierry Reding #endif 8619ab3a7a0SThierry Reding 8629ab3a7a0SThierry Reding #ifndef iowrite32_rep 8639ab3a7a0SThierry Reding #define iowrite32_rep iowrite32_rep 8649ab3a7a0SThierry Reding static inline void iowrite32_rep(volatile void __iomem *addr, 8659ab3a7a0SThierry Reding const void *buffer, 8669ab3a7a0SThierry Reding unsigned int count) 8679ab3a7a0SThierry Reding { 8689ab3a7a0SThierry Reding writesl(addr, buffer, count); 8699ab3a7a0SThierry Reding } 8709ab3a7a0SThierry Reding #endif 8719e44fb18SHoria Geantă 8729e44fb18SHoria Geantă #ifdef CONFIG_64BIT 8739e44fb18SHoria Geantă #ifndef iowrite64_rep 8749e44fb18SHoria Geantă #define iowrite64_rep iowrite64_rep 8759e44fb18SHoria Geantă static inline void iowrite64_rep(volatile void __iomem *addr, 8769e44fb18SHoria Geantă const void *buffer, 8779e44fb18SHoria Geantă unsigned int count) 8789e44fb18SHoria Geantă { 8799e44fb18SHoria Geantă writesq(addr, buffer, count); 8809e44fb18SHoria Geantă } 8819e44fb18SHoria Geantă #endif 8829e44fb18SHoria Geantă #endif /* CONFIG_64BIT */ 8839216efafSThierry Reding #endif /* CONFIG_GENERIC_IOMAP */ 8849216efafSThierry Reding 8853f7e212dSArnd Bergmann #ifdef __KERNEL__ 8863f7e212dSArnd Bergmann 8873f7e212dSArnd Bergmann #include <linux/vmalloc.h> 8883f7e212dSArnd Bergmann #define __io_virt(x) ((void __force *)(x)) 8893f7e212dSArnd Bergmann 8903f7e212dSArnd Bergmann #ifndef CONFIG_GENERIC_IOMAP 8913f7e212dSArnd Bergmann struct pci_dev; 892cd248341SJan Glauber extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max); 893cd248341SJan Glauber 894cd248341SJan Glauber #ifndef pci_iounmap 8959216efafSThierry Reding #define pci_iounmap pci_iounmap 8963f7e212dSArnd Bergmann static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p) 8973f7e212dSArnd Bergmann { 8983f7e212dSArnd Bergmann } 899cd248341SJan Glauber #endif 9003f7e212dSArnd Bergmann #endif /* CONFIG_GENERIC_IOMAP */ 9013f7e212dSArnd Bergmann 9023f7e212dSArnd Bergmann /* 9033f7e212dSArnd Bergmann * Change virtual addresses to physical addresses and vv. 9043f7e212dSArnd Bergmann * These are pretty trivial 9053f7e212dSArnd Bergmann */ 906cd248341SJan Glauber #ifndef virt_to_phys 9079216efafSThierry Reding #define virt_to_phys virt_to_phys 9083f7e212dSArnd Bergmann static inline unsigned long virt_to_phys(volatile void *address) 9093f7e212dSArnd Bergmann { 9103f7e212dSArnd Bergmann return __pa((unsigned long)address); 9113f7e212dSArnd Bergmann } 9129216efafSThierry Reding #endif 9133f7e212dSArnd Bergmann 9149216efafSThierry Reding #ifndef phys_to_virt 9159216efafSThierry Reding #define phys_to_virt phys_to_virt 9163f7e212dSArnd Bergmann static inline void *phys_to_virt(unsigned long address) 9173f7e212dSArnd Bergmann { 9183f7e212dSArnd Bergmann return __va(address); 9193f7e212dSArnd Bergmann } 920cd248341SJan Glauber #endif 9213f7e212dSArnd Bergmann 9228c7ea50cSLuis R. Rodriguez /** 9238c7ea50cSLuis R. Rodriguez * DOC: ioremap() and ioremap_*() variants 9248c7ea50cSLuis R. Rodriguez * 92597c9801aSChristoph Hellwig * Architectures with an MMU are expected to provide ioremap() and iounmap() 92680b0ca98SChristoph Hellwig * themselves or rely on GENERIC_IOREMAP. For NOMMU architectures we provide 92780b0ca98SChristoph Hellwig * a default nop-op implementation that expect that the physical address used 92880b0ca98SChristoph Hellwig * for MMIO are already marked as uncached, and can be used as kernel virtual 92980b0ca98SChristoph Hellwig * addresses. 9308c7ea50cSLuis R. Rodriguez * 93197c9801aSChristoph Hellwig * ioremap_wc() and ioremap_wt() can provide more relaxed caching attributes 93297c9801aSChristoph Hellwig * for specific drivers if the architecture choses to implement them. If they 93397c9801aSChristoph Hellwig * are not implemented we fall back to plain ioremap. 9348c7ea50cSLuis R. Rodriguez */ 935e9713395SChristoph Hellwig #ifndef CONFIG_MMU 9369216efafSThierry Reding #ifndef ioremap 9379216efafSThierry Reding #define ioremap ioremap 9389216efafSThierry Reding static inline void __iomem *ioremap(phys_addr_t offset, size_t size) 9393f7e212dSArnd Bergmann { 9403f7e212dSArnd Bergmann return (void __iomem *)(unsigned long)offset; 9413f7e212dSArnd Bergmann } 9429216efafSThierry Reding #endif 9433f7e212dSArnd Bergmann 944b3ada9d0SGreentime Hu #ifndef iounmap 945b3ada9d0SGreentime Hu #define iounmap iounmap 946b3ada9d0SGreentime Hu static inline void iounmap(void __iomem *addr) 947b3ada9d0SGreentime Hu { 948b3ada9d0SGreentime Hu } 949b3ada9d0SGreentime Hu #endif 95080b0ca98SChristoph Hellwig #elif defined(CONFIG_GENERIC_IOREMAP) 95180b0ca98SChristoph Hellwig #include <asm/pgtable.h> 95280b0ca98SChristoph Hellwig 95380b0ca98SChristoph Hellwig void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); 95480b0ca98SChristoph Hellwig void iounmap(volatile void __iomem *addr); 95580b0ca98SChristoph Hellwig 95680b0ca98SChristoph Hellwig static inline void __iomem *ioremap(phys_addr_t addr, size_t size) 95780b0ca98SChristoph Hellwig { 95880b0ca98SChristoph Hellwig /* _PAGE_IOREMAP needs to be supplied by the architecture */ 95980b0ca98SChristoph Hellwig return ioremap_prot(addr, size, _PAGE_IOREMAP); 96080b0ca98SChristoph Hellwig } 96180b0ca98SChristoph Hellwig #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */ 96297c9801aSChristoph Hellwig 9633f7e212dSArnd Bergmann #ifndef ioremap_nocache 964d092a870SChristoph Hellwig #define ioremap_nocache ioremap 9653f7e212dSArnd Bergmann #endif 9663f7e212dSArnd Bergmann 9673f7e212dSArnd Bergmann #ifndef ioremap_wc 968d092a870SChristoph Hellwig #define ioremap_wc ioremap 9693f7e212dSArnd Bergmann #endif 9703f7e212dSArnd Bergmann 971d838270eSToshi Kani #ifndef ioremap_wt 972d092a870SChristoph Hellwig #define ioremap_wt ioremap 973d838270eSToshi Kani #endif 974d838270eSToshi Kani 975e9713395SChristoph Hellwig /* 976e9713395SChristoph Hellwig * ioremap_uc is special in that we do require an explicit architecture 977e9713395SChristoph Hellwig * implementation. In general you do not want to use this function in a 978e9713395SChristoph Hellwig * driver and use plain ioremap, which is uncached by default. Similarly 979e9713395SChristoph Hellwig * architectures should not implement it unless they have a very good 980e9713395SChristoph Hellwig * reason. 981e9713395SChristoph Hellwig */ 982e9713395SChristoph Hellwig #ifndef ioremap_uc 983e9713395SChristoph Hellwig #define ioremap_uc ioremap_uc 984e9713395SChristoph Hellwig static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size) 985e9713395SChristoph Hellwig { 986e9713395SChristoph Hellwig return NULL; 987e9713395SChristoph Hellwig } 988e9713395SChristoph Hellwig #endif 989e9713395SChristoph Hellwig 990ce816fa8SUwe Kleine-König #ifdef CONFIG_HAS_IOPORT_MAP 9913f7e212dSArnd Bergmann #ifndef CONFIG_GENERIC_IOMAP 9929216efafSThierry Reding #ifndef ioport_map 9939216efafSThierry Reding #define ioport_map ioport_map 9943f7e212dSArnd Bergmann static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) 9953f7e212dSArnd Bergmann { 996500dd232SAndrew Murray port &= IO_SPACE_LIMIT; 997500dd232SAndrew Murray return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port; 9983f7e212dSArnd Bergmann } 9999216efafSThierry Reding #endif 10003f7e212dSArnd Bergmann 10019216efafSThierry Reding #ifndef ioport_unmap 10029216efafSThierry Reding #define ioport_unmap ioport_unmap 10033f7e212dSArnd Bergmann static inline void ioport_unmap(void __iomem *p) 10043f7e212dSArnd Bergmann { 10053f7e212dSArnd Bergmann } 10069216efafSThierry Reding #endif 10073f7e212dSArnd Bergmann #else /* CONFIG_GENERIC_IOMAP */ 10083f7e212dSArnd Bergmann extern void __iomem *ioport_map(unsigned long port, unsigned int nr); 10093f7e212dSArnd Bergmann extern void ioport_unmap(void __iomem *p); 10103f7e212dSArnd Bergmann #endif /* CONFIG_GENERIC_IOMAP */ 1011ce816fa8SUwe Kleine-König #endif /* CONFIG_HAS_IOPORT_MAP */ 10123f7e212dSArnd Bergmann 1013eabc2a7cSAndy Shevchenko /* 1014eabc2a7cSAndy Shevchenko * Convert a virtual cached pointer to an uncached pointer 1015eabc2a7cSAndy Shevchenko */ 1016576ebd74SMichael Holzheu #ifndef xlate_dev_kmem_ptr 10179216efafSThierry Reding #define xlate_dev_kmem_ptr xlate_dev_kmem_ptr 10189216efafSThierry Reding static inline void *xlate_dev_kmem_ptr(void *addr) 10199216efafSThierry Reding { 10209216efafSThierry Reding return addr; 10219216efafSThierry Reding } 1022576ebd74SMichael Holzheu #endif 10239216efafSThierry Reding 1024576ebd74SMichael Holzheu #ifndef xlate_dev_mem_ptr 10259216efafSThierry Reding #define xlate_dev_mem_ptr xlate_dev_mem_ptr 10269216efafSThierry Reding static inline void *xlate_dev_mem_ptr(phys_addr_t addr) 10279216efafSThierry Reding { 10289216efafSThierry Reding return __va(addr); 10299216efafSThierry Reding } 10309216efafSThierry Reding #endif 10319216efafSThierry Reding 10329216efafSThierry Reding #ifndef unxlate_dev_mem_ptr 10339216efafSThierry Reding #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr 10349216efafSThierry Reding static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr) 10359216efafSThierry Reding { 10369216efafSThierry Reding } 1037576ebd74SMichael Holzheu #endif 10383f7e212dSArnd Bergmann 1039c93d0312SJames Hogan #ifdef CONFIG_VIRT_TO_BUS 10403f7e212dSArnd Bergmann #ifndef virt_to_bus 10419216efafSThierry Reding static inline unsigned long virt_to_bus(void *address) 10423f7e212dSArnd Bergmann { 10439216efafSThierry Reding return (unsigned long)address; 10443f7e212dSArnd Bergmann } 10453f7e212dSArnd Bergmann 10463f7e212dSArnd Bergmann static inline void *bus_to_virt(unsigned long address) 10473f7e212dSArnd Bergmann { 10483f7e212dSArnd Bergmann return (void *)address; 10493f7e212dSArnd Bergmann } 10503f7e212dSArnd Bergmann #endif 1051c93d0312SJames Hogan #endif 10523f7e212dSArnd Bergmann 1053cd248341SJan Glauber #ifndef memset_io 10549216efafSThierry Reding #define memset_io memset_io 1055c2327da0SAndy Shevchenko /** 1056c2327da0SAndy Shevchenko * memset_io Set a range of I/O memory to a constant value 1057c2327da0SAndy Shevchenko * @addr: The beginning of the I/O-memory range to set 1058c2327da0SAndy Shevchenko * @val: The value to set the memory to 1059c2327da0SAndy Shevchenko * @count: The number of bytes to set 1060c2327da0SAndy Shevchenko * 1061c2327da0SAndy Shevchenko * Set a range of I/O memory to a given value. 1062c2327da0SAndy Shevchenko */ 10639216efafSThierry Reding static inline void memset_io(volatile void __iomem *addr, int value, 10649216efafSThierry Reding size_t size) 10659216efafSThierry Reding { 10669216efafSThierry Reding memset(__io_virt(addr), value, size); 10679216efafSThierry Reding } 1068cd248341SJan Glauber #endif 1069cd248341SJan Glauber 1070cd248341SJan Glauber #ifndef memcpy_fromio 10719216efafSThierry Reding #define memcpy_fromio memcpy_fromio 1072c2327da0SAndy Shevchenko /** 1073c2327da0SAndy Shevchenko * memcpy_fromio Copy a block of data from I/O memory 1074c2327da0SAndy Shevchenko * @dst: The (RAM) destination for the copy 1075c2327da0SAndy Shevchenko * @src: The (I/O memory) source for the data 1076c2327da0SAndy Shevchenko * @count: The number of bytes to copy 1077c2327da0SAndy Shevchenko * 1078c2327da0SAndy Shevchenko * Copy a block of data from I/O memory. 1079c2327da0SAndy Shevchenko */ 10809216efafSThierry Reding static inline void memcpy_fromio(void *buffer, 10819216efafSThierry Reding const volatile void __iomem *addr, 10829216efafSThierry Reding size_t size) 10839216efafSThierry Reding { 10849216efafSThierry Reding memcpy(buffer, __io_virt(addr), size); 10859216efafSThierry Reding } 1086cd248341SJan Glauber #endif 10879216efafSThierry Reding 1088cd248341SJan Glauber #ifndef memcpy_toio 10899216efafSThierry Reding #define memcpy_toio memcpy_toio 1090c2327da0SAndy Shevchenko /** 1091c2327da0SAndy Shevchenko * memcpy_toio Copy a block of data into I/O memory 1092c2327da0SAndy Shevchenko * @dst: The (I/O memory) destination for the copy 1093c2327da0SAndy Shevchenko * @src: The (RAM) source for the data 1094c2327da0SAndy Shevchenko * @count: The number of bytes to copy 1095c2327da0SAndy Shevchenko * 1096c2327da0SAndy Shevchenko * Copy a block of data to I/O memory. 1097c2327da0SAndy Shevchenko */ 10989216efafSThierry Reding static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer, 10999216efafSThierry Reding size_t size) 11009216efafSThierry Reding { 11019216efafSThierry Reding memcpy(__io_virt(addr), buffer, size); 11029216efafSThierry Reding } 1103cd248341SJan Glauber #endif 11043f7e212dSArnd Bergmann 11053f7e212dSArnd Bergmann #endif /* __KERNEL__ */ 11063f7e212dSArnd Bergmann 11073f7e212dSArnd Bergmann #endif /* __ASM_GENERIC_IO_H */ 1108