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