Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
David Howells | 739d875 | 2018-03-08 09:48:46 +0000 | [diff] [blame] | 2 | /* Generic I/O port emulation. |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | #ifndef __ASM_GENERIC_IO_H |
| 8 | #define __ASM_GENERIC_IO_H |
| 9 | |
| 10 | #include <asm/page.h> /* I/O is all done through memory accesses */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 11 | #include <linux/string.h> /* for memset() and memcpy() */ |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 12 | #include <linux/types.h> |
| 13 | |
| 14 | #ifdef CONFIG_GENERIC_IOMAP |
| 15 | #include <asm-generic/iomap.h> |
| 16 | #endif |
| 17 | |
Will Deacon | 60ca1e5 | 2019-02-22 12:59:59 +0000 | [diff] [blame] | 18 | #include <asm/mmiowb.h> |
Michael S. Tsirkin | 66eab4d | 2011-11-24 20:45:20 +0200 | [diff] [blame] | 19 | #include <asm-generic/pci_iomap.h> |
| 20 | |
Sinan Kaya | 64e2c67 | 2018-04-05 09:09:09 -0400 | [diff] [blame] | 21 | #ifndef __io_br |
| 22 | #define __io_br() barrier() |
| 23 | #endif |
| 24 | |
| 25 | /* prevent prefetching of coherent DMA data ahead of a dma-complete */ |
| 26 | #ifndef __io_ar |
| 27 | #ifdef rmb |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 28 | #define __io_ar(v) rmb() |
Sinan Kaya | 64e2c67 | 2018-04-05 09:09:09 -0400 | [diff] [blame] | 29 | #else |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 30 | #define __io_ar(v) barrier() |
Sinan Kaya | 64e2c67 | 2018-04-05 09:09:09 -0400 | [diff] [blame] | 31 | #endif |
| 32 | #endif |
| 33 | |
| 34 | /* flush writes to coherent DMA data before possibly triggering a DMA read */ |
| 35 | #ifndef __io_bw |
| 36 | #ifdef wmb |
| 37 | #define __io_bw() wmb() |
| 38 | #else |
| 39 | #define __io_bw() barrier() |
| 40 | #endif |
| 41 | #endif |
| 42 | |
| 43 | /* serialize device access against a spin_unlock, usually handled there. */ |
| 44 | #ifndef __io_aw |
Will Deacon | 60ca1e5 | 2019-02-22 12:59:59 +0000 | [diff] [blame] | 45 | #define __io_aw() mmiowb_set_pending() |
Sinan Kaya | 64e2c67 | 2018-04-05 09:09:09 -0400 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | #ifndef __io_pbw |
| 49 | #define __io_pbw() __io_bw() |
| 50 | #endif |
| 51 | |
| 52 | #ifndef __io_paw |
| 53 | #define __io_paw() __io_aw() |
| 54 | #endif |
| 55 | |
| 56 | #ifndef __io_pbr |
| 57 | #define __io_pbr() __io_br() |
| 58 | #endif |
| 59 | |
| 60 | #ifndef __io_par |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 61 | #define __io_par(v) __io_ar(v) |
Sinan Kaya | 64e2c67 | 2018-04-05 09:09:09 -0400 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 65 | /* |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 66 | * __raw_{read,write}{b,w,l,q}() access memory in native endianness. |
| 67 | * |
| 68 | * On some architectures memory mapped IO needs to be accessed differently. |
| 69 | * On the simple architectures, we just read/write the memory location |
| 70 | * directly. |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 71 | */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 72 | |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 73 | #ifndef __raw_readb |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 74 | #define __raw_readb __raw_readb |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 75 | static inline u8 __raw_readb(const volatile void __iomem *addr) |
| 76 | { |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 77 | return *(const volatile u8 __force *)addr; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 78 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 79 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 80 | |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 81 | #ifndef __raw_readw |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 82 | #define __raw_readw __raw_readw |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 83 | static inline u16 __raw_readw(const volatile void __iomem *addr) |
| 84 | { |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 85 | return *(const volatile u16 __force *)addr; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 86 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 87 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 88 | |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 89 | #ifndef __raw_readl |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 90 | #define __raw_readl __raw_readl |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 91 | static inline u32 __raw_readl(const volatile void __iomem *addr) |
| 92 | { |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 93 | return *(const volatile u32 __force *)addr; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 94 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 95 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 96 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_64BIT |
| 98 | #ifndef __raw_readq |
| 99 | #define __raw_readq __raw_readq |
| 100 | static inline u64 __raw_readq(const volatile void __iomem *addr) |
| 101 | { |
| 102 | return *(const volatile u64 __force *)addr; |
| 103 | } |
| 104 | #endif |
| 105 | #endif /* CONFIG_64BIT */ |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 106 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 107 | #ifndef __raw_writeb |
| 108 | #define __raw_writeb __raw_writeb |
| 109 | static inline void __raw_writeb(u8 value, volatile void __iomem *addr) |
| 110 | { |
| 111 | *(volatile u8 __force *)addr = value; |
| 112 | } |
| 113 | #endif |
| 114 | |
| 115 | #ifndef __raw_writew |
| 116 | #define __raw_writew __raw_writew |
| 117 | static inline void __raw_writew(u16 value, volatile void __iomem *addr) |
| 118 | { |
| 119 | *(volatile u16 __force *)addr = value; |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | #ifndef __raw_writel |
| 124 | #define __raw_writel __raw_writel |
| 125 | static inline void __raw_writel(u32 value, volatile void __iomem *addr) |
| 126 | { |
| 127 | *(volatile u32 __force *)addr = value; |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | #ifdef CONFIG_64BIT |
| 132 | #ifndef __raw_writeq |
| 133 | #define __raw_writeq __raw_writeq |
| 134 | static inline void __raw_writeq(u64 value, volatile void __iomem *addr) |
| 135 | { |
| 136 | *(volatile u64 __force *)addr = value; |
| 137 | } |
| 138 | #endif |
| 139 | #endif /* CONFIG_64BIT */ |
| 140 | |
| 141 | /* |
| 142 | * {read,write}{b,w,l,q}() access little endian memory and return result in |
| 143 | * native endianness. |
| 144 | */ |
| 145 | |
| 146 | #ifndef readb |
| 147 | #define readb readb |
| 148 | static inline u8 readb(const volatile void __iomem *addr) |
| 149 | { |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 150 | u8 val; |
| 151 | |
| 152 | __io_br(); |
| 153 | val = __raw_readb(addr); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 154 | __io_ar(val); |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 155 | return val; |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 156 | } |
| 157 | #endif |
| 158 | |
| 159 | #ifndef readw |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 160 | #define readw readw |
| 161 | static inline u16 readw(const volatile void __iomem *addr) |
| 162 | { |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 163 | u16 val; |
| 164 | |
| 165 | __io_br(); |
| 166 | val = __le16_to_cpu(__raw_readw(addr)); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 167 | __io_ar(val); |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 168 | return val; |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 169 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 170 | #endif |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 171 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 172 | #ifndef readl |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 173 | #define readl readl |
| 174 | static inline u32 readl(const volatile void __iomem *addr) |
| 175 | { |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 176 | u32 val; |
| 177 | |
| 178 | __io_br(); |
| 179 | val = __le32_to_cpu(__raw_readl(addr)); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 180 | __io_ar(val); |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 181 | return val; |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 182 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 183 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 184 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 185 | #ifdef CONFIG_64BIT |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 186 | #ifndef readq |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 187 | #define readq readq |
| 188 | static inline u64 readq(const volatile void __iomem *addr) |
| 189 | { |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 190 | u64 val; |
| 191 | |
| 192 | __io_br(); |
| 193 | val = __le64_to_cpu(__raw_readq(addr)); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 194 | __io_ar(val); |
Sinan Kaya | 032d59e | 2018-04-05 09:09:10 -0400 | [diff] [blame] | 195 | return val; |
Heiko Carstens | 7292e7e | 2013-01-07 14:17:23 +0100 | [diff] [blame] | 196 | } |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 197 | #endif |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 198 | #endif /* CONFIG_64BIT */ |
| 199 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 200 | #ifndef writeb |
| 201 | #define writeb writeb |
| 202 | static inline void writeb(u8 value, volatile void __iomem *addr) |
| 203 | { |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 204 | __io_bw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 205 | __raw_writeb(value, addr); |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 206 | __io_aw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 207 | } |
GuanXuetao | 7dc59bd | 2011-02-22 19:06:43 +0800 | [diff] [blame] | 208 | #endif |
| 209 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 210 | #ifndef writew |
| 211 | #define writew writew |
| 212 | static inline void writew(u16 value, volatile void __iomem *addr) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 213 | { |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 214 | __io_bw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 215 | __raw_writew(cpu_to_le16(value), addr); |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 216 | __io_aw(); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 217 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 218 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 219 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 220 | #ifndef writel |
| 221 | #define writel writel |
| 222 | static inline void writel(u32 value, volatile void __iomem *addr) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 223 | { |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 224 | __io_bw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 225 | __raw_writel(__cpu_to_le32(value), addr); |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 226 | __io_aw(); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 227 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 228 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 229 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 230 | #ifdef CONFIG_64BIT |
| 231 | #ifndef writeq |
| 232 | #define writeq writeq |
| 233 | static inline void writeq(u64 value, volatile void __iomem *addr) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 234 | { |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 235 | __io_bw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 236 | __raw_writeq(__cpu_to_le64(value), addr); |
Sinan Kaya | 755bd04 | 2018-04-05 09:09:11 -0400 | [diff] [blame] | 237 | __io_aw(); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 238 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 239 | #endif |
| 240 | #endif /* CONFIG_64BIT */ |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 241 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 242 | /* |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 243 | * {read,write}{b,w,l,q}_relaxed() are like the regular version, but |
| 244 | * are not guaranteed to provide ordering against spinlocks or memory |
| 245 | * accesses. |
| 246 | */ |
| 247 | #ifndef readb_relaxed |
Sinan Kaya | 8875c55 | 2018-04-06 14:02:45 -0400 | [diff] [blame] | 248 | #define readb_relaxed readb_relaxed |
| 249 | static inline u8 readb_relaxed(const volatile void __iomem *addr) |
| 250 | { |
| 251 | return __raw_readb(addr); |
| 252 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 253 | #endif |
| 254 | |
| 255 | #ifndef readw_relaxed |
Sinan Kaya | 8875c55 | 2018-04-06 14:02:45 -0400 | [diff] [blame] | 256 | #define readw_relaxed readw_relaxed |
| 257 | static inline u16 readw_relaxed(const volatile void __iomem *addr) |
| 258 | { |
| 259 | return __le16_to_cpu(__raw_readw(addr)); |
| 260 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 261 | #endif |
| 262 | |
| 263 | #ifndef readl_relaxed |
Sinan Kaya | 8875c55 | 2018-04-06 14:02:45 -0400 | [diff] [blame] | 264 | #define readl_relaxed readl_relaxed |
| 265 | static inline u32 readl_relaxed(const volatile void __iomem *addr) |
| 266 | { |
| 267 | return __le32_to_cpu(__raw_readl(addr)); |
| 268 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 269 | #endif |
| 270 | |
Robin Murphy | e511267 | 2016-04-26 11:38:20 +0100 | [diff] [blame] | 271 | #if defined(readq) && !defined(readq_relaxed) |
Sinan Kaya | 8875c55 | 2018-04-06 14:02:45 -0400 | [diff] [blame] | 272 | #define readq_relaxed readq_relaxed |
| 273 | static inline u64 readq_relaxed(const volatile void __iomem *addr) |
| 274 | { |
| 275 | return __le64_to_cpu(__raw_readq(addr)); |
| 276 | } |
Will Deacon | 9439eb3 | 2013-09-03 10:44:00 +0100 | [diff] [blame] | 277 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 278 | |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 279 | #ifndef writeb_relaxed |
Sinan Kaya | a71e7c4 | 2018-04-06 14:02:46 -0400 | [diff] [blame] | 280 | #define writeb_relaxed writeb_relaxed |
| 281 | static inline void writeb_relaxed(u8 value, volatile void __iomem *addr) |
| 282 | { |
| 283 | __raw_writeb(value, addr); |
| 284 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 285 | #endif |
| 286 | |
| 287 | #ifndef writew_relaxed |
Sinan Kaya | a71e7c4 | 2018-04-06 14:02:46 -0400 | [diff] [blame] | 288 | #define writew_relaxed writew_relaxed |
| 289 | static inline void writew_relaxed(u16 value, volatile void __iomem *addr) |
| 290 | { |
| 291 | __raw_writew(cpu_to_le16(value), addr); |
| 292 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 293 | #endif |
| 294 | |
| 295 | #ifndef writel_relaxed |
Sinan Kaya | a71e7c4 | 2018-04-06 14:02:46 -0400 | [diff] [blame] | 296 | #define writel_relaxed writel_relaxed |
| 297 | static inline void writel_relaxed(u32 value, volatile void __iomem *addr) |
| 298 | { |
| 299 | __raw_writel(__cpu_to_le32(value), addr); |
| 300 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 301 | #endif |
| 302 | |
Robin Murphy | e511267 | 2016-04-26 11:38:20 +0100 | [diff] [blame] | 303 | #if defined(writeq) && !defined(writeq_relaxed) |
Sinan Kaya | a71e7c4 | 2018-04-06 14:02:46 -0400 | [diff] [blame] | 304 | #define writeq_relaxed writeq_relaxed |
| 305 | static inline void writeq_relaxed(u64 value, volatile void __iomem *addr) |
| 306 | { |
| 307 | __raw_writeq(__cpu_to_le64(value), addr); |
| 308 | } |
Arnd Bergmann | 1c8d296 | 2014-11-11 19:55:45 +0100 | [diff] [blame] | 309 | #endif |
| 310 | |
| 311 | /* |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 312 | * {read,write}s{b,w,l,q}() repeatedly access the same memory address in |
| 313 | * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times). |
| 314 | */ |
| 315 | #ifndef readsb |
| 316 | #define readsb readsb |
| 317 | static inline void readsb(const volatile void __iomem *addr, void *buffer, |
| 318 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 319 | { |
| 320 | if (count) { |
| 321 | u8 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 322 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 323 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 324 | u8 x = __raw_readb(addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 325 | *buf++ = x; |
| 326 | } while (--count); |
| 327 | } |
| 328 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 329 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 330 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 331 | #ifndef readsw |
| 332 | #define readsw readsw |
| 333 | static inline void readsw(const volatile void __iomem *addr, void *buffer, |
| 334 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 335 | { |
| 336 | if (count) { |
| 337 | u16 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 338 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 339 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 340 | u16 x = __raw_readw(addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 341 | *buf++ = x; |
| 342 | } while (--count); |
| 343 | } |
| 344 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 345 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 346 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 347 | #ifndef readsl |
| 348 | #define readsl readsl |
| 349 | static inline void readsl(const volatile void __iomem *addr, void *buffer, |
| 350 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 351 | { |
| 352 | if (count) { |
| 353 | u32 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 354 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 355 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 356 | u32 x = __raw_readl(addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 357 | *buf++ = x; |
| 358 | } while (--count); |
| 359 | } |
| 360 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 361 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 362 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 363 | #ifdef CONFIG_64BIT |
| 364 | #ifndef readsq |
| 365 | #define readsq readsq |
| 366 | static inline void readsq(const volatile void __iomem *addr, void *buffer, |
| 367 | unsigned int count) |
| 368 | { |
| 369 | if (count) { |
| 370 | u64 *buf = buffer; |
| 371 | |
| 372 | do { |
| 373 | u64 x = __raw_readq(addr); |
| 374 | *buf++ = x; |
| 375 | } while (--count); |
| 376 | } |
| 377 | } |
| 378 | #endif |
| 379 | #endif /* CONFIG_64BIT */ |
| 380 | |
| 381 | #ifndef writesb |
| 382 | #define writesb writesb |
| 383 | static inline void writesb(volatile void __iomem *addr, const void *buffer, |
| 384 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 385 | { |
| 386 | if (count) { |
| 387 | const u8 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 388 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 389 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 390 | __raw_writeb(*buf++, addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 391 | } while (--count); |
| 392 | } |
| 393 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 394 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 395 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 396 | #ifndef writesw |
| 397 | #define writesw writesw |
| 398 | static inline void writesw(volatile void __iomem *addr, const void *buffer, |
| 399 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 400 | { |
| 401 | if (count) { |
| 402 | const u16 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 403 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 404 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 405 | __raw_writew(*buf++, addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 406 | } while (--count); |
| 407 | } |
| 408 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 409 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 410 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 411 | #ifndef writesl |
| 412 | #define writesl writesl |
| 413 | static inline void writesl(volatile void __iomem *addr, const void *buffer, |
| 414 | unsigned int count) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 415 | { |
| 416 | if (count) { |
| 417 | const u32 *buf = buffer; |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 418 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 419 | do { |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 420 | __raw_writel(*buf++, addr); |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 421 | } while (--count); |
| 422 | } |
| 423 | } |
Mike Frysinger | 35dbc0e | 2010-10-18 03:09:39 -0400 | [diff] [blame] | 424 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 425 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 426 | #ifdef CONFIG_64BIT |
| 427 | #ifndef writesq |
| 428 | #define writesq writesq |
| 429 | static inline void writesq(volatile void __iomem *addr, const void *buffer, |
| 430 | unsigned int count) |
| 431 | { |
| 432 | if (count) { |
| 433 | const u64 *buf = buffer; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 434 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 435 | do { |
| 436 | __raw_writeq(*buf++, addr); |
| 437 | } while (--count); |
| 438 | } |
| 439 | } |
| 440 | #endif |
| 441 | #endif /* CONFIG_64BIT */ |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 442 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 443 | #ifndef PCI_IOBASE |
| 444 | #define PCI_IOBASE ((void __iomem *)0) |
| 445 | #endif |
| 446 | |
GuanXuetao | 7dc59bd | 2011-02-22 19:06:43 +0800 | [diff] [blame] | 447 | #ifndef IO_SPACE_LIMIT |
| 448 | #define IO_SPACE_LIMIT 0xffff |
| 449 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 450 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 451 | /* |
| 452 | * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be |
| 453 | * implemented on hardware that needs an additional delay for I/O accesses to |
| 454 | * take effect. |
| 455 | */ |
| 456 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 457 | #if !defined(inb) && !defined(_inb) |
| 458 | #define _inb _inb |
Stafford Horne | 214ba35 | 2020-07-26 12:11:54 +0900 | [diff] [blame] | 459 | static inline u8 _inb(unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 460 | { |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 461 | u8 val; |
| 462 | |
| 463 | __io_pbr(); |
| 464 | val = __raw_readb(PCI_IOBASE + addr); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 465 | __io_par(val); |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 466 | return val; |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 467 | } |
| 468 | #endif |
| 469 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 470 | #if !defined(inw) && !defined(_inw) |
| 471 | #define _inw _inw |
| 472 | static inline u16 _inw(unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 473 | { |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 474 | u16 val; |
| 475 | |
| 476 | __io_pbr(); |
| 477 | val = __le16_to_cpu(__raw_readw(PCI_IOBASE + addr)); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 478 | __io_par(val); |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 479 | return val; |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 480 | } |
| 481 | #endif |
| 482 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 483 | #if !defined(inl) && !defined(_inl) |
| 484 | #define _inl _inl |
Stafford Horne | 214ba35 | 2020-07-26 12:11:54 +0900 | [diff] [blame] | 485 | static inline u32 _inl(unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 486 | { |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 487 | u32 val; |
| 488 | |
| 489 | __io_pbr(); |
| 490 | val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr)); |
Will Deacon | abbbbc8 | 2019-02-22 18:04:52 +0000 | [diff] [blame] | 491 | __io_par(val); |
Sinan Kaya | 87fe2d5 | 2018-04-05 09:09:13 -0400 | [diff] [blame] | 492 | return val; |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 493 | } |
| 494 | #endif |
| 495 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 496 | #if !defined(outb) && !defined(_outb) |
| 497 | #define _outb _outb |
| 498 | static inline void _outb(u8 value, unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 499 | { |
Sinan Kaya | a7851aa | 2018-04-05 09:09:12 -0400 | [diff] [blame] | 500 | __io_pbw(); |
| 501 | __raw_writeb(value, PCI_IOBASE + addr); |
| 502 | __io_paw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 503 | } |
| 504 | #endif |
| 505 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 506 | #if !defined(outw) && !defined(_outw) |
| 507 | #define _outw _outw |
| 508 | static inline void _outw(u16 value, unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 509 | { |
Sinan Kaya | a7851aa | 2018-04-05 09:09:12 -0400 | [diff] [blame] | 510 | __io_pbw(); |
| 511 | __raw_writew(cpu_to_le16(value), PCI_IOBASE + addr); |
| 512 | __io_paw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 513 | } |
| 514 | #endif |
| 515 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 516 | #if !defined(outl) && !defined(_outl) |
| 517 | #define _outl _outl |
| 518 | static inline void _outl(u32 value, unsigned long addr) |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 519 | { |
Sinan Kaya | a7851aa | 2018-04-05 09:09:12 -0400 | [diff] [blame] | 520 | __io_pbw(); |
| 521 | __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr); |
| 522 | __io_paw(); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 523 | } |
| 524 | #endif |
| 525 | |
John Garry | f009c89 | 2020-03-28 00:06:12 +0800 | [diff] [blame] | 526 | #include <linux/logic_pio.h> |
| 527 | |
| 528 | #ifndef inb |
| 529 | #define inb _inb |
| 530 | #endif |
| 531 | |
| 532 | #ifndef inw |
| 533 | #define inw _inw |
| 534 | #endif |
| 535 | |
| 536 | #ifndef inl |
| 537 | #define inl _inl |
| 538 | #endif |
| 539 | |
| 540 | #ifndef outb |
| 541 | #define outb _outb |
| 542 | #endif |
| 543 | |
| 544 | #ifndef outw |
| 545 | #define outw _outw |
| 546 | #endif |
| 547 | |
| 548 | #ifndef outl |
| 549 | #define outl _outl |
| 550 | #endif |
| 551 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 552 | #ifndef inb_p |
| 553 | #define inb_p inb_p |
| 554 | static inline u8 inb_p(unsigned long addr) |
| 555 | { |
| 556 | return inb(addr); |
| 557 | } |
| 558 | #endif |
| 559 | |
| 560 | #ifndef inw_p |
| 561 | #define inw_p inw_p |
| 562 | static inline u16 inw_p(unsigned long addr) |
| 563 | { |
| 564 | return inw(addr); |
| 565 | } |
| 566 | #endif |
| 567 | |
| 568 | #ifndef inl_p |
| 569 | #define inl_p inl_p |
| 570 | static inline u32 inl_p(unsigned long addr) |
| 571 | { |
| 572 | return inl(addr); |
| 573 | } |
| 574 | #endif |
| 575 | |
| 576 | #ifndef outb_p |
| 577 | #define outb_p outb_p |
| 578 | static inline void outb_p(u8 value, unsigned long addr) |
| 579 | { |
| 580 | outb(value, addr); |
| 581 | } |
| 582 | #endif |
| 583 | |
| 584 | #ifndef outw_p |
| 585 | #define outw_p outw_p |
| 586 | static inline void outw_p(u16 value, unsigned long addr) |
| 587 | { |
| 588 | outw(value, addr); |
| 589 | } |
| 590 | #endif |
| 591 | |
| 592 | #ifndef outl_p |
| 593 | #define outl_p outl_p |
| 594 | static inline void outl_p(u32 value, unsigned long addr) |
| 595 | { |
| 596 | outl(value, addr); |
| 597 | } |
| 598 | #endif |
| 599 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 600 | /* |
| 601 | * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a |
| 602 | * single I/O port multiple times. |
| 603 | */ |
| 604 | |
| 605 | #ifndef insb |
| 606 | #define insb insb |
| 607 | static inline void insb(unsigned long addr, void *buffer, unsigned int count) |
| 608 | { |
| 609 | readsb(PCI_IOBASE + addr, buffer, count); |
| 610 | } |
| 611 | #endif |
| 612 | |
| 613 | #ifndef insw |
| 614 | #define insw insw |
| 615 | static inline void insw(unsigned long addr, void *buffer, unsigned int count) |
| 616 | { |
| 617 | readsw(PCI_IOBASE + addr, buffer, count); |
| 618 | } |
| 619 | #endif |
| 620 | |
| 621 | #ifndef insl |
| 622 | #define insl insl |
| 623 | static inline void insl(unsigned long addr, void *buffer, unsigned int count) |
| 624 | { |
| 625 | readsl(PCI_IOBASE + addr, buffer, count); |
| 626 | } |
| 627 | #endif |
| 628 | |
| 629 | #ifndef outsb |
| 630 | #define outsb outsb |
| 631 | static inline void outsb(unsigned long addr, const void *buffer, |
| 632 | unsigned int count) |
| 633 | { |
| 634 | writesb(PCI_IOBASE + addr, buffer, count); |
| 635 | } |
| 636 | #endif |
| 637 | |
| 638 | #ifndef outsw |
| 639 | #define outsw outsw |
| 640 | static inline void outsw(unsigned long addr, const void *buffer, |
| 641 | unsigned int count) |
| 642 | { |
| 643 | writesw(PCI_IOBASE + addr, buffer, count); |
| 644 | } |
| 645 | #endif |
| 646 | |
| 647 | #ifndef outsl |
| 648 | #define outsl outsl |
| 649 | static inline void outsl(unsigned long addr, const void *buffer, |
| 650 | unsigned int count) |
| 651 | { |
| 652 | writesl(PCI_IOBASE + addr, buffer, count); |
| 653 | } |
| 654 | #endif |
| 655 | |
| 656 | #ifndef insb_p |
| 657 | #define insb_p insb_p |
| 658 | static inline void insb_p(unsigned long addr, void *buffer, unsigned int count) |
| 659 | { |
| 660 | insb(addr, buffer, count); |
| 661 | } |
| 662 | #endif |
| 663 | |
| 664 | #ifndef insw_p |
| 665 | #define insw_p insw_p |
| 666 | static inline void insw_p(unsigned long addr, void *buffer, unsigned int count) |
| 667 | { |
| 668 | insw(addr, buffer, count); |
| 669 | } |
| 670 | #endif |
| 671 | |
| 672 | #ifndef insl_p |
| 673 | #define insl_p insl_p |
| 674 | static inline void insl_p(unsigned long addr, void *buffer, unsigned int count) |
| 675 | { |
| 676 | insl(addr, buffer, count); |
| 677 | } |
| 678 | #endif |
| 679 | |
| 680 | #ifndef outsb_p |
| 681 | #define outsb_p outsb_p |
| 682 | static inline void outsb_p(unsigned long addr, const void *buffer, |
| 683 | unsigned int count) |
| 684 | { |
| 685 | outsb(addr, buffer, count); |
| 686 | } |
| 687 | #endif |
| 688 | |
| 689 | #ifndef outsw_p |
| 690 | #define outsw_p outsw_p |
| 691 | static inline void outsw_p(unsigned long addr, const void *buffer, |
| 692 | unsigned int count) |
| 693 | { |
| 694 | outsw(addr, buffer, count); |
| 695 | } |
| 696 | #endif |
| 697 | |
| 698 | #ifndef outsl_p |
| 699 | #define outsl_p outsl_p |
| 700 | static inline void outsl_p(unsigned long addr, const void *buffer, |
| 701 | unsigned int count) |
| 702 | { |
| 703 | outsl(addr, buffer, count); |
| 704 | } |
| 705 | #endif |
| 706 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 707 | #ifndef CONFIG_GENERIC_IOMAP |
| 708 | #ifndef ioread8 |
| 709 | #define ioread8 ioread8 |
| 710 | static inline u8 ioread8(const volatile void __iomem *addr) |
| 711 | { |
| 712 | return readb(addr); |
| 713 | } |
| 714 | #endif |
| 715 | |
| 716 | #ifndef ioread16 |
| 717 | #define ioread16 ioread16 |
| 718 | static inline u16 ioread16(const volatile void __iomem *addr) |
| 719 | { |
| 720 | return readw(addr); |
| 721 | } |
| 722 | #endif |
| 723 | |
| 724 | #ifndef ioread32 |
| 725 | #define ioread32 ioread32 |
| 726 | static inline u32 ioread32(const volatile void __iomem *addr) |
| 727 | { |
| 728 | return readl(addr); |
| 729 | } |
| 730 | #endif |
| 731 | |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 732 | #ifdef CONFIG_64BIT |
| 733 | #ifndef ioread64 |
| 734 | #define ioread64 ioread64 |
| 735 | static inline u64 ioread64(const volatile void __iomem *addr) |
| 736 | { |
| 737 | return readq(addr); |
| 738 | } |
| 739 | #endif |
| 740 | #endif /* CONFIG_64BIT */ |
| 741 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 742 | #ifndef iowrite8 |
| 743 | #define iowrite8 iowrite8 |
| 744 | static inline void iowrite8(u8 value, volatile void __iomem *addr) |
| 745 | { |
| 746 | writeb(value, addr); |
| 747 | } |
| 748 | #endif |
| 749 | |
| 750 | #ifndef iowrite16 |
| 751 | #define iowrite16 iowrite16 |
| 752 | static inline void iowrite16(u16 value, volatile void __iomem *addr) |
| 753 | { |
| 754 | writew(value, addr); |
| 755 | } |
| 756 | #endif |
| 757 | |
| 758 | #ifndef iowrite32 |
| 759 | #define iowrite32 iowrite32 |
| 760 | static inline void iowrite32(u32 value, volatile void __iomem *addr) |
| 761 | { |
| 762 | writel(value, addr); |
| 763 | } |
| 764 | #endif |
| 765 | |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 766 | #ifdef CONFIG_64BIT |
| 767 | #ifndef iowrite64 |
| 768 | #define iowrite64 iowrite64 |
| 769 | static inline void iowrite64(u64 value, volatile void __iomem *addr) |
| 770 | { |
| 771 | writeq(value, addr); |
| 772 | } |
| 773 | #endif |
| 774 | #endif /* CONFIG_64BIT */ |
| 775 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 776 | #ifndef ioread16be |
| 777 | #define ioread16be ioread16be |
| 778 | static inline u16 ioread16be(const volatile void __iomem *addr) |
| 779 | { |
Horia Geantă | 7a1aedb | 2016-05-19 18:10:43 +0300 | [diff] [blame] | 780 | return swab16(readw(addr)); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 781 | } |
| 782 | #endif |
| 783 | |
| 784 | #ifndef ioread32be |
| 785 | #define ioread32be ioread32be |
| 786 | static inline u32 ioread32be(const volatile void __iomem *addr) |
| 787 | { |
Horia Geantă | 7a1aedb | 2016-05-19 18:10:43 +0300 | [diff] [blame] | 788 | return swab32(readl(addr)); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 789 | } |
| 790 | #endif |
| 791 | |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 792 | #ifdef CONFIG_64BIT |
| 793 | #ifndef ioread64be |
| 794 | #define ioread64be ioread64be |
| 795 | static inline u64 ioread64be(const volatile void __iomem *addr) |
| 796 | { |
| 797 | return swab64(readq(addr)); |
| 798 | } |
| 799 | #endif |
| 800 | #endif /* CONFIG_64BIT */ |
| 801 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 802 | #ifndef iowrite16be |
| 803 | #define iowrite16be iowrite16be |
| 804 | static inline void iowrite16be(u16 value, void volatile __iomem *addr) |
| 805 | { |
Horia Geantă | 7a1aedb | 2016-05-19 18:10:43 +0300 | [diff] [blame] | 806 | writew(swab16(value), addr); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 807 | } |
| 808 | #endif |
| 809 | |
| 810 | #ifndef iowrite32be |
| 811 | #define iowrite32be iowrite32be |
| 812 | static inline void iowrite32be(u32 value, volatile void __iomem *addr) |
| 813 | { |
Horia Geantă | 7a1aedb | 2016-05-19 18:10:43 +0300 | [diff] [blame] | 814 | writel(swab32(value), addr); |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 815 | } |
| 816 | #endif |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 817 | |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 818 | #ifdef CONFIG_64BIT |
| 819 | #ifndef iowrite64be |
| 820 | #define iowrite64be iowrite64be |
| 821 | static inline void iowrite64be(u64 value, volatile void __iomem *addr) |
| 822 | { |
| 823 | writeq(swab64(value), addr); |
| 824 | } |
| 825 | #endif |
| 826 | #endif /* CONFIG_64BIT */ |
| 827 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 828 | #ifndef ioread8_rep |
| 829 | #define ioread8_rep ioread8_rep |
| 830 | static inline void ioread8_rep(const volatile void __iomem *addr, void *buffer, |
| 831 | unsigned int count) |
| 832 | { |
| 833 | readsb(addr, buffer, count); |
| 834 | } |
| 835 | #endif |
| 836 | |
| 837 | #ifndef ioread16_rep |
| 838 | #define ioread16_rep ioread16_rep |
| 839 | static inline void ioread16_rep(const volatile void __iomem *addr, |
| 840 | void *buffer, unsigned int count) |
| 841 | { |
| 842 | readsw(addr, buffer, count); |
| 843 | } |
| 844 | #endif |
| 845 | |
| 846 | #ifndef ioread32_rep |
| 847 | #define ioread32_rep ioread32_rep |
| 848 | static inline void ioread32_rep(const volatile void __iomem *addr, |
| 849 | void *buffer, unsigned int count) |
| 850 | { |
| 851 | readsl(addr, buffer, count); |
| 852 | } |
| 853 | #endif |
| 854 | |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 855 | #ifdef CONFIG_64BIT |
| 856 | #ifndef ioread64_rep |
| 857 | #define ioread64_rep ioread64_rep |
| 858 | static inline void ioread64_rep(const volatile void __iomem *addr, |
| 859 | void *buffer, unsigned int count) |
| 860 | { |
| 861 | readsq(addr, buffer, count); |
| 862 | } |
| 863 | #endif |
| 864 | #endif /* CONFIG_64BIT */ |
| 865 | |
Thierry Reding | 9ab3a7a | 2014-07-04 13:07:57 +0200 | [diff] [blame] | 866 | #ifndef iowrite8_rep |
| 867 | #define iowrite8_rep iowrite8_rep |
| 868 | static inline void iowrite8_rep(volatile void __iomem *addr, |
| 869 | const void *buffer, |
| 870 | unsigned int count) |
| 871 | { |
| 872 | writesb(addr, buffer, count); |
| 873 | } |
| 874 | #endif |
| 875 | |
| 876 | #ifndef iowrite16_rep |
| 877 | #define iowrite16_rep iowrite16_rep |
| 878 | static inline void iowrite16_rep(volatile void __iomem *addr, |
| 879 | const void *buffer, |
| 880 | unsigned int count) |
| 881 | { |
| 882 | writesw(addr, buffer, count); |
| 883 | } |
| 884 | #endif |
| 885 | |
| 886 | #ifndef iowrite32_rep |
| 887 | #define iowrite32_rep iowrite32_rep |
| 888 | static inline void iowrite32_rep(volatile void __iomem *addr, |
| 889 | const void *buffer, |
| 890 | unsigned int count) |
| 891 | { |
| 892 | writesl(addr, buffer, count); |
| 893 | } |
| 894 | #endif |
Horia Geantă | 9e44fb1 | 2016-05-19 18:10:56 +0300 | [diff] [blame] | 895 | |
| 896 | #ifdef CONFIG_64BIT |
| 897 | #ifndef iowrite64_rep |
| 898 | #define iowrite64_rep iowrite64_rep |
| 899 | static inline void iowrite64_rep(volatile void __iomem *addr, |
| 900 | const void *buffer, |
| 901 | unsigned int count) |
| 902 | { |
| 903 | writesq(addr, buffer, count); |
| 904 | } |
| 905 | #endif |
| 906 | #endif /* CONFIG_64BIT */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 907 | #endif /* CONFIG_GENERIC_IOMAP */ |
| 908 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 909 | #ifdef __KERNEL__ |
| 910 | |
| 911 | #include <linux/vmalloc.h> |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 912 | #define __io_virt(x) ((void __force *)(x)) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 913 | |
| 914 | #ifndef CONFIG_GENERIC_IOMAP |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 915 | struct pci_dev; |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 916 | extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max); |
| 917 | |
| 918 | #ifndef pci_iounmap |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 919 | #define pci_iounmap pci_iounmap |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 920 | static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p) |
| 921 | { |
| 922 | } |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 923 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 924 | #endif /* CONFIG_GENERIC_IOMAP */ |
| 925 | |
| 926 | /* |
| 927 | * Change virtual addresses to physical addresses and vv. |
| 928 | * These are pretty trivial |
| 929 | */ |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 930 | #ifndef virt_to_phys |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 931 | #define virt_to_phys virt_to_phys |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 932 | static inline unsigned long virt_to_phys(volatile void *address) |
| 933 | { |
| 934 | return __pa((unsigned long)address); |
| 935 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 936 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 937 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 938 | #ifndef phys_to_virt |
| 939 | #define phys_to_virt phys_to_virt |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 940 | static inline void *phys_to_virt(unsigned long address) |
| 941 | { |
| 942 | return __va(address); |
| 943 | } |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 944 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 945 | |
Luis R. Rodriguez | 8c7ea50 | 2015-07-09 17:28:16 -0700 | [diff] [blame] | 946 | /** |
| 947 | * DOC: ioremap() and ioremap_*() variants |
| 948 | * |
Christoph Hellwig | 97c9801 | 2019-08-11 14:53:20 +0200 | [diff] [blame] | 949 | * Architectures with an MMU are expected to provide ioremap() and iounmap() |
Christoph Hellwig | 80b0ca9 | 2019-08-13 11:24:04 +0200 | [diff] [blame] | 950 | * themselves or rely on GENERIC_IOREMAP. For NOMMU architectures we provide |
| 951 | * a default nop-op implementation that expect that the physical address used |
| 952 | * for MMIO are already marked as uncached, and can be used as kernel virtual |
| 953 | * addresses. |
Luis R. Rodriguez | 8c7ea50 | 2015-07-09 17:28:16 -0700 | [diff] [blame] | 954 | * |
Christoph Hellwig | 97c9801 | 2019-08-11 14:53:20 +0200 | [diff] [blame] | 955 | * ioremap_wc() and ioremap_wt() can provide more relaxed caching attributes |
| 956 | * for specific drivers if the architecture choses to implement them. If they |
| 957 | * are not implemented we fall back to plain ioremap. |
Luis R. Rodriguez | 8c7ea50 | 2015-07-09 17:28:16 -0700 | [diff] [blame] | 958 | */ |
Christoph Hellwig | e971339 | 2019-08-13 07:53:05 +0200 | [diff] [blame] | 959 | #ifndef CONFIG_MMU |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 960 | #ifndef ioremap |
| 961 | #define ioremap ioremap |
| 962 | static inline void __iomem *ioremap(phys_addr_t offset, size_t size) |
| 963 | { |
| 964 | return (void __iomem *)(unsigned long)offset; |
| 965 | } |
| 966 | #endif |
| 967 | |
Greentime Hu | b3ada9d | 2017-11-22 18:57:46 +0800 | [diff] [blame] | 968 | #ifndef iounmap |
| 969 | #define iounmap iounmap |
Greentime Hu | b3ada9d | 2017-11-22 18:57:46 +0800 | [diff] [blame] | 970 | static inline void iounmap(void __iomem *addr) |
| 971 | { |
| 972 | } |
| 973 | #endif |
Christoph Hellwig | 80b0ca9 | 2019-08-13 11:24:04 +0200 | [diff] [blame] | 974 | #elif defined(CONFIG_GENERIC_IOREMAP) |
Mike Rapoport | ca5999f | 2020-06-08 21:32:38 -0700 | [diff] [blame] | 975 | #include <linux/pgtable.h> |
Christoph Hellwig | 80b0ca9 | 2019-08-13 11:24:04 +0200 | [diff] [blame] | 976 | |
| 977 | void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); |
| 978 | void iounmap(volatile void __iomem *addr); |
| 979 | |
| 980 | static inline void __iomem *ioremap(phys_addr_t addr, size_t size) |
| 981 | { |
| 982 | /* _PAGE_IOREMAP needs to be supplied by the architecture */ |
| 983 | return ioremap_prot(addr, size, _PAGE_IOREMAP); |
| 984 | } |
| 985 | #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */ |
Christoph Hellwig | 97c9801 | 2019-08-11 14:53:20 +0200 | [diff] [blame] | 986 | |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 987 | #ifndef ioremap_wc |
Christoph Hellwig | d092a87 | 2019-10-16 08:09:38 +0200 | [diff] [blame] | 988 | #define ioremap_wc ioremap |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 989 | #endif |
| 990 | |
Toshi Kani | d838270 | 2015-06-04 18:55:15 +0200 | [diff] [blame] | 991 | #ifndef ioremap_wt |
Christoph Hellwig | d092a87 | 2019-10-16 08:09:38 +0200 | [diff] [blame] | 992 | #define ioremap_wt ioremap |
Toshi Kani | d838270 | 2015-06-04 18:55:15 +0200 | [diff] [blame] | 993 | #endif |
| 994 | |
Christoph Hellwig | e971339 | 2019-08-13 07:53:05 +0200 | [diff] [blame] | 995 | /* |
| 996 | * ioremap_uc is special in that we do require an explicit architecture |
| 997 | * implementation. In general you do not want to use this function in a |
| 998 | * driver and use plain ioremap, which is uncached by default. Similarly |
| 999 | * architectures should not implement it unless they have a very good |
| 1000 | * reason. |
| 1001 | */ |
| 1002 | #ifndef ioremap_uc |
| 1003 | #define ioremap_uc ioremap_uc |
| 1004 | static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size) |
| 1005 | { |
| 1006 | return NULL; |
| 1007 | } |
| 1008 | #endif |
| 1009 | |
Uwe Kleine-König | ce816fa | 2014-04-07 15:39:19 -0700 | [diff] [blame] | 1010 | #ifdef CONFIG_HAS_IOPORT_MAP |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1011 | #ifndef CONFIG_GENERIC_IOMAP |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1012 | #ifndef ioport_map |
| 1013 | #define ioport_map ioport_map |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1014 | static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) |
| 1015 | { |
Andrew Murray | 500dd232 | 2018-09-13 13:48:27 +0100 | [diff] [blame] | 1016 | port &= IO_SPACE_LIMIT; |
| 1017 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1018 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1019 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1020 | |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1021 | #ifndef ioport_unmap |
| 1022 | #define ioport_unmap ioport_unmap |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1023 | static inline void ioport_unmap(void __iomem *p) |
| 1024 | { |
| 1025 | } |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1026 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1027 | #else /* CONFIG_GENERIC_IOMAP */ |
| 1028 | extern void __iomem *ioport_map(unsigned long port, unsigned int nr); |
| 1029 | extern void ioport_unmap(void __iomem *p); |
| 1030 | #endif /* CONFIG_GENERIC_IOMAP */ |
Uwe Kleine-König | ce816fa | 2014-04-07 15:39:19 -0700 | [diff] [blame] | 1031 | #endif /* CONFIG_HAS_IOPORT_MAP */ |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1032 | |
Andy Shevchenko | eabc2a7 | 2017-06-30 20:09:33 +0300 | [diff] [blame] | 1033 | /* |
| 1034 | * Convert a virtual cached pointer to an uncached pointer |
| 1035 | */ |
Michael Holzheu | 576ebd7 | 2013-05-21 16:08:22 +0200 | [diff] [blame] | 1036 | #ifndef xlate_dev_kmem_ptr |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1037 | #define xlate_dev_kmem_ptr xlate_dev_kmem_ptr |
| 1038 | static inline void *xlate_dev_kmem_ptr(void *addr) |
| 1039 | { |
| 1040 | return addr; |
| 1041 | } |
Michael Holzheu | 576ebd7 | 2013-05-21 16:08:22 +0200 | [diff] [blame] | 1042 | #endif |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1043 | |
Michael Holzheu | 576ebd7 | 2013-05-21 16:08:22 +0200 | [diff] [blame] | 1044 | #ifndef xlate_dev_mem_ptr |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1045 | #define xlate_dev_mem_ptr xlate_dev_mem_ptr |
| 1046 | static inline void *xlate_dev_mem_ptr(phys_addr_t addr) |
| 1047 | { |
| 1048 | return __va(addr); |
| 1049 | } |
| 1050 | #endif |
| 1051 | |
| 1052 | #ifndef unxlate_dev_mem_ptr |
| 1053 | #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr |
| 1054 | static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr) |
| 1055 | { |
| 1056 | } |
Michael Holzheu | 576ebd7 | 2013-05-21 16:08:22 +0200 | [diff] [blame] | 1057 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1058 | |
James Hogan | c93d031 | 2012-11-23 16:13:05 +0000 | [diff] [blame] | 1059 | #ifdef CONFIG_VIRT_TO_BUS |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1060 | #ifndef virt_to_bus |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1061 | static inline unsigned long virt_to_bus(void *address) |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1062 | { |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1063 | return (unsigned long)address; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | static inline void *bus_to_virt(unsigned long address) |
| 1067 | { |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1068 | return (void *)address; |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1069 | } |
| 1070 | #endif |
James Hogan | c93d031 | 2012-11-23 16:13:05 +0000 | [diff] [blame] | 1071 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1072 | |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 1073 | #ifndef memset_io |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1074 | #define memset_io memset_io |
Andy Shevchenko | c2327da | 2017-06-30 20:09:32 +0300 | [diff] [blame] | 1075 | /** |
| 1076 | * memset_io Set a range of I/O memory to a constant value |
| 1077 | * @addr: The beginning of the I/O-memory range to set |
| 1078 | * @val: The value to set the memory to |
| 1079 | * @count: The number of bytes to set |
| 1080 | * |
| 1081 | * Set a range of I/O memory to a given value. |
| 1082 | */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1083 | static inline void memset_io(volatile void __iomem *addr, int value, |
| 1084 | size_t size) |
| 1085 | { |
| 1086 | memset(__io_virt(addr), value, size); |
| 1087 | } |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 1088 | #endif |
| 1089 | |
| 1090 | #ifndef memcpy_fromio |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1091 | #define memcpy_fromio memcpy_fromio |
Andy Shevchenko | c2327da | 2017-06-30 20:09:32 +0300 | [diff] [blame] | 1092 | /** |
| 1093 | * memcpy_fromio Copy a block of data from I/O memory |
| 1094 | * @dst: The (RAM) destination for the copy |
| 1095 | * @src: The (I/O memory) source for the data |
| 1096 | * @count: The number of bytes to copy |
| 1097 | * |
| 1098 | * Copy a block of data from I/O memory. |
| 1099 | */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1100 | static inline void memcpy_fromio(void *buffer, |
| 1101 | const volatile void __iomem *addr, |
| 1102 | size_t size) |
| 1103 | { |
| 1104 | memcpy(buffer, __io_virt(addr), size); |
| 1105 | } |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 1106 | #endif |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1107 | |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 1108 | #ifndef memcpy_toio |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1109 | #define memcpy_toio memcpy_toio |
Andy Shevchenko | c2327da | 2017-06-30 20:09:32 +0300 | [diff] [blame] | 1110 | /** |
| 1111 | * memcpy_toio Copy a block of data into I/O memory |
| 1112 | * @dst: The (I/O memory) destination for the copy |
| 1113 | * @src: The (RAM) source for the data |
| 1114 | * @count: The number of bytes to copy |
| 1115 | * |
| 1116 | * Copy a block of data to I/O memory. |
| 1117 | */ |
Thierry Reding | 9216efa | 2014-10-01 15:20:33 +0200 | [diff] [blame] | 1118 | static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer, |
| 1119 | size_t size) |
| 1120 | { |
| 1121 | memcpy(__io_virt(addr), buffer, size); |
| 1122 | } |
Jan Glauber | cd24834 | 2012-11-29 12:50:30 +0100 | [diff] [blame] | 1123 | #endif |
Arnd Bergmann | 3f7e212 | 2009-05-13 22:56:35 +0000 | [diff] [blame] | 1124 | |
| 1125 | #endif /* __KERNEL__ */ |
| 1126 | |
| 1127 | #endif /* __ASM_GENERIC_IO_H */ |