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