blob: bf8204de3a487714db10014d9876da0730ef8070 [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Howells739d8752018-03-08 09:48:46 +00002/* Generic I/O port emulation.
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00003 *
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00006 */
7#ifndef __ASM_GENERIC_IO_H
8#define __ASM_GENERIC_IO_H
9
10#include <asm/page.h> /* I/O is all done through memory accesses */
Thierry Reding9216efa2014-10-01 15:20:33 +020011#include <linux/string.h> /* for memset() and memcpy() */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000012#include <linux/types.h>
13
14#ifdef CONFIG_GENERIC_IOMAP
15#include <asm-generic/iomap.h>
16#endif
17
Will Deacon60ca1e52019-02-22 12:59:59 +000018#include <asm/mmiowb.h>
Michael S. Tsirkin66eab4d2011-11-24 20:45:20 +020019#include <asm-generic/pci_iomap.h>
20
Sinan Kaya64e2c672018-04-05 09:09:09 -040021#ifndef __io_br
22#define __io_br() barrier()
23#endif
24
25/* prevent prefetching of coherent DMA data ahead of a dma-complete */
26#ifndef __io_ar
27#ifdef rmb
Will Deaconabbbbc82019-02-22 18:04:52 +000028#define __io_ar(v) rmb()
Sinan Kaya64e2c672018-04-05 09:09:09 -040029#else
Will Deaconabbbbc82019-02-22 18:04:52 +000030#define __io_ar(v) barrier()
Sinan Kaya64e2c672018-04-05 09:09:09 -040031#endif
32#endif
33
34/* flush writes to coherent DMA data before possibly triggering a DMA read */
35#ifndef __io_bw
36#ifdef wmb
37#define __io_bw() wmb()
38#else
39#define __io_bw() barrier()
40#endif
41#endif
42
43/* serialize device access against a spin_unlock, usually handled there. */
44#ifndef __io_aw
Will Deacon60ca1e52019-02-22 12:59:59 +000045#define __io_aw() mmiowb_set_pending()
Sinan Kaya64e2c672018-04-05 09:09:09 -040046#endif
47
48#ifndef __io_pbw
49#define __io_pbw() __io_bw()
50#endif
51
52#ifndef __io_paw
53#define __io_paw() __io_aw()
54#endif
55
56#ifndef __io_pbr
57#define __io_pbr() __io_br()
58#endif
59
60#ifndef __io_par
Will Deaconabbbbc82019-02-22 18:04:52 +000061#define __io_par(v) __io_ar(v)
Sinan Kaya64e2c672018-04-05 09:09:09 -040062#endif
63
64
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000065/*
Thierry Reding9216efa2014-10-01 15:20:33 +020066 * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
67 *
68 * On some architectures memory mapped IO needs to be accessed differently.
69 * On the simple architectures, we just read/write the memory location
70 * directly.
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000071 */
Thierry Reding9216efa2014-10-01 15:20:33 +020072
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040073#ifndef __raw_readb
Thierry Reding9216efa2014-10-01 15:20:33 +020074#define __raw_readb __raw_readb
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000075static inline u8 __raw_readb(const volatile void __iomem *addr)
76{
Thierry Reding9216efa2014-10-01 15:20:33 +020077 return *(const volatile u8 __force *)addr;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000078}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040079#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000080
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040081#ifndef __raw_readw
Thierry Reding9216efa2014-10-01 15:20:33 +020082#define __raw_readw __raw_readw
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000083static inline u16 __raw_readw(const volatile void __iomem *addr)
84{
Thierry Reding9216efa2014-10-01 15:20:33 +020085 return *(const volatile u16 __force *)addr;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000086}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040087#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000088
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040089#ifndef __raw_readl
Thierry Reding9216efa2014-10-01 15:20:33 +020090#define __raw_readl __raw_readl
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000091static inline u32 __raw_readl(const volatile void __iomem *addr)
92{
Thierry Reding9216efa2014-10-01 15:20:33 +020093 return *(const volatile u32 __force *)addr;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000094}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -040095#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +000096
Thierry Reding9216efa2014-10-01 15:20:33 +020097#ifdef CONFIG_64BIT
98#ifndef __raw_readq
99#define __raw_readq __raw_readq
100static inline u64 __raw_readq(const volatile void __iomem *addr)
101{
102 return *(const volatile u64 __force *)addr;
103}
104#endif
105#endif /* CONFIG_64BIT */
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100106
Thierry Reding9216efa2014-10-01 15:20:33 +0200107#ifndef __raw_writeb
108#define __raw_writeb __raw_writeb
109static inline void __raw_writeb(u8 value, volatile void __iomem *addr)
110{
111 *(volatile u8 __force *)addr = value;
112}
113#endif
114
115#ifndef __raw_writew
116#define __raw_writew __raw_writew
117static inline void __raw_writew(u16 value, volatile void __iomem *addr)
118{
119 *(volatile u16 __force *)addr = value;
120}
121#endif
122
123#ifndef __raw_writel
124#define __raw_writel __raw_writel
125static inline void __raw_writel(u32 value, volatile void __iomem *addr)
126{
127 *(volatile u32 __force *)addr = value;
128}
129#endif
130
131#ifdef CONFIG_64BIT
132#ifndef __raw_writeq
133#define __raw_writeq __raw_writeq
134static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
135{
136 *(volatile u64 __force *)addr = value;
137}
138#endif
139#endif /* CONFIG_64BIT */
140
141/*
142 * {read,write}{b,w,l,q}() access little endian memory and return result in
143 * native endianness.
144 */
145
146#ifndef readb
147#define readb readb
148static inline u8 readb(const volatile void __iomem *addr)
149{
Sinan Kaya032d59e2018-04-05 09:09:10 -0400150 u8 val;
151
152 __io_br();
153 val = __raw_readb(addr);
Will Deaconabbbbc82019-02-22 18:04:52 +0000154 __io_ar(val);
Sinan Kaya032d59e2018-04-05 09:09:10 -0400155 return val;
Thierry Reding9216efa2014-10-01 15:20:33 +0200156}
157#endif
158
159#ifndef readw
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100160#define readw readw
161static inline u16 readw(const volatile void __iomem *addr)
162{
Sinan Kaya032d59e2018-04-05 09:09:10 -0400163 u16 val;
164
165 __io_br();
166 val = __le16_to_cpu(__raw_readw(addr));
Will Deaconabbbbc82019-02-22 18:04:52 +0000167 __io_ar(val);
Sinan Kaya032d59e2018-04-05 09:09:10 -0400168 return val;
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100169}
Thierry Reding9216efa2014-10-01 15:20:33 +0200170#endif
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100171
Thierry Reding9216efa2014-10-01 15:20:33 +0200172#ifndef readl
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100173#define readl readl
174static inline u32 readl(const volatile void __iomem *addr)
175{
Sinan Kaya032d59e2018-04-05 09:09:10 -0400176 u32 val;
177
178 __io_br();
179 val = __le32_to_cpu(__raw_readl(addr));
Will Deaconabbbbc82019-02-22 18:04:52 +0000180 __io_ar(val);
Sinan Kaya032d59e2018-04-05 09:09:10 -0400181 return val;
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100182}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400183#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000184
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000185#ifdef CONFIG_64BIT
Thierry Reding9216efa2014-10-01 15:20:33 +0200186#ifndef readq
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100187#define readq readq
188static inline u64 readq(const volatile void __iomem *addr)
189{
Sinan Kaya032d59e2018-04-05 09:09:10 -0400190 u64 val;
191
192 __io_br();
193 val = __le64_to_cpu(__raw_readq(addr));
Will Deaconabbbbc82019-02-22 18:04:52 +0000194 __io_ar(val);
Sinan Kaya032d59e2018-04-05 09:09:10 -0400195 return val;
Heiko Carstens7292e7e2013-01-07 14:17:23 +0100196}
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000197#endif
Jan Glaubercd248342012-11-29 12:50:30 +0100198#endif /* CONFIG_64BIT */
199
Thierry Reding9216efa2014-10-01 15:20:33 +0200200#ifndef writeb
201#define writeb writeb
202static inline void writeb(u8 value, volatile void __iomem *addr)
203{
Sinan Kaya755bd042018-04-05 09:09:11 -0400204 __io_bw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200205 __raw_writeb(value, addr);
Sinan Kaya755bd042018-04-05 09:09:11 -0400206 __io_aw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200207}
GuanXuetao7dc59bd2011-02-22 19:06:43 +0800208#endif
209
Thierry Reding9216efa2014-10-01 15:20:33 +0200210#ifndef writew
211#define writew writew
212static inline void writew(u16 value, volatile void __iomem *addr)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000213{
Sinan Kaya755bd042018-04-05 09:09:11 -0400214 __io_bw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200215 __raw_writew(cpu_to_le16(value), addr);
Sinan Kaya755bd042018-04-05 09:09:11 -0400216 __io_aw();
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000217}
Thierry Reding9216efa2014-10-01 15:20:33 +0200218#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000219
Thierry Reding9216efa2014-10-01 15:20:33 +0200220#ifndef writel
221#define writel writel
222static inline void writel(u32 value, volatile void __iomem *addr)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000223{
Sinan Kaya755bd042018-04-05 09:09:11 -0400224 __io_bw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200225 __raw_writel(__cpu_to_le32(value), addr);
Sinan Kaya755bd042018-04-05 09:09:11 -0400226 __io_aw();
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000227}
Thierry Reding9216efa2014-10-01 15:20:33 +0200228#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000229
Thierry Reding9216efa2014-10-01 15:20:33 +0200230#ifdef CONFIG_64BIT
231#ifndef writeq
232#define writeq writeq
233static inline void writeq(u64 value, volatile void __iomem *addr)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000234{
Sinan Kaya755bd042018-04-05 09:09:11 -0400235 __io_bw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200236 __raw_writeq(__cpu_to_le64(value), addr);
Sinan Kaya755bd042018-04-05 09:09:11 -0400237 __io_aw();
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000238}
Thierry Reding9216efa2014-10-01 15:20:33 +0200239#endif
240#endif /* CONFIG_64BIT */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000241
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200242/*
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100243 * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
244 * are not guaranteed to provide ordering against spinlocks or memory
245 * accesses.
246 */
247#ifndef readb_relaxed
Sinan Kaya8875c552018-04-06 14:02:45 -0400248#define readb_relaxed readb_relaxed
249static inline u8 readb_relaxed(const volatile void __iomem *addr)
250{
251 return __raw_readb(addr);
252}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100253#endif
254
255#ifndef readw_relaxed
Sinan Kaya8875c552018-04-06 14:02:45 -0400256#define readw_relaxed readw_relaxed
257static inline u16 readw_relaxed(const volatile void __iomem *addr)
258{
259 return __le16_to_cpu(__raw_readw(addr));
260}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100261#endif
262
263#ifndef readl_relaxed
Sinan Kaya8875c552018-04-06 14:02:45 -0400264#define readl_relaxed readl_relaxed
265static inline u32 readl_relaxed(const volatile void __iomem *addr)
266{
267 return __le32_to_cpu(__raw_readl(addr));
268}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100269#endif
270
Robin Murphye5112672016-04-26 11:38:20 +0100271#if defined(readq) && !defined(readq_relaxed)
Sinan Kaya8875c552018-04-06 14:02:45 -0400272#define readq_relaxed readq_relaxed
273static inline u64 readq_relaxed(const volatile void __iomem *addr)
274{
275 return __le64_to_cpu(__raw_readq(addr));
276}
Will Deacon9439eb32013-09-03 10:44:00 +0100277#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000278
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100279#ifndef writeb_relaxed
Sinan Kayaa71e7c42018-04-06 14:02:46 -0400280#define writeb_relaxed writeb_relaxed
281static inline void writeb_relaxed(u8 value, volatile void __iomem *addr)
282{
283 __raw_writeb(value, addr);
284}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100285#endif
286
287#ifndef writew_relaxed
Sinan Kayaa71e7c42018-04-06 14:02:46 -0400288#define writew_relaxed writew_relaxed
289static inline void writew_relaxed(u16 value, volatile void __iomem *addr)
290{
291 __raw_writew(cpu_to_le16(value), addr);
292}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100293#endif
294
295#ifndef writel_relaxed
Sinan Kayaa71e7c42018-04-06 14:02:46 -0400296#define writel_relaxed writel_relaxed
297static inline void writel_relaxed(u32 value, volatile void __iomem *addr)
298{
299 __raw_writel(__cpu_to_le32(value), addr);
300}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100301#endif
302
Robin Murphye5112672016-04-26 11:38:20 +0100303#if defined(writeq) && !defined(writeq_relaxed)
Sinan Kayaa71e7c42018-04-06 14:02:46 -0400304#define writeq_relaxed writeq_relaxed
305static inline void writeq_relaxed(u64 value, volatile void __iomem *addr)
306{
307 __raw_writeq(__cpu_to_le64(value), addr);
308}
Arnd Bergmann1c8d2962014-11-11 19:55:45 +0100309#endif
310
311/*
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200312 * {read,write}s{b,w,l,q}() repeatedly access the same memory address in
313 * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times).
314 */
315#ifndef readsb
316#define readsb readsb
317static inline void readsb(const volatile void __iomem *addr, void *buffer,
318 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000319{
320 if (count) {
321 u8 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200322
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000323 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200324 u8 x = __raw_readb(addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000325 *buf++ = x;
326 } while (--count);
327 }
328}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400329#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000330
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200331#ifndef readsw
332#define readsw readsw
333static inline void readsw(const volatile void __iomem *addr, void *buffer,
334 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000335{
336 if (count) {
337 u16 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200338
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000339 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200340 u16 x = __raw_readw(addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000341 *buf++ = x;
342 } while (--count);
343 }
344}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400345#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000346
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200347#ifndef readsl
348#define readsl readsl
349static inline void readsl(const volatile void __iomem *addr, void *buffer,
350 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000351{
352 if (count) {
353 u32 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200354
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000355 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200356 u32 x = __raw_readl(addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000357 *buf++ = x;
358 } while (--count);
359 }
360}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400361#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000362
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200363#ifdef CONFIG_64BIT
364#ifndef readsq
365#define readsq readsq
366static inline void readsq(const volatile void __iomem *addr, void *buffer,
367 unsigned int count)
368{
369 if (count) {
370 u64 *buf = buffer;
371
372 do {
373 u64 x = __raw_readq(addr);
374 *buf++ = x;
375 } while (--count);
376 }
377}
378#endif
379#endif /* CONFIG_64BIT */
380
381#ifndef writesb
382#define writesb writesb
383static inline void writesb(volatile void __iomem *addr, const void *buffer,
384 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000385{
386 if (count) {
387 const u8 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200388
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000389 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200390 __raw_writeb(*buf++, addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000391 } while (--count);
392 }
393}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400394#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000395
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200396#ifndef writesw
397#define writesw writesw
398static inline void writesw(volatile void __iomem *addr, const void *buffer,
399 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000400{
401 if (count) {
402 const u16 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200403
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000404 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200405 __raw_writew(*buf++, addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000406 } while (--count);
407 }
408}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400409#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000410
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200411#ifndef writesl
412#define writesl writesl
413static inline void writesl(volatile void __iomem *addr, const void *buffer,
414 unsigned int count)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000415{
416 if (count) {
417 const u32 *buf = buffer;
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200418
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000419 do {
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200420 __raw_writel(*buf++, addr);
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000421 } while (--count);
422 }
423}
Mike Frysinger35dbc0e2010-10-18 03:09:39 -0400424#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000425
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200426#ifdef CONFIG_64BIT
427#ifndef writesq
428#define writesq writesq
429static inline void writesq(volatile void __iomem *addr, const void *buffer,
430 unsigned int count)
431{
432 if (count) {
433 const u64 *buf = buffer;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000434
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200435 do {
436 __raw_writeq(*buf++, addr);
437 } while (--count);
438 }
439}
440#endif
441#endif /* CONFIG_64BIT */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000442
Thierry Reding9216efa2014-10-01 15:20:33 +0200443#ifndef PCI_IOBASE
444#define PCI_IOBASE ((void __iomem *)0)
445#endif
446
GuanXuetao7dc59bd2011-02-22 19:06:43 +0800447#ifndef IO_SPACE_LIMIT
448#define IO_SPACE_LIMIT 0xffff
449#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000450
Zhichang Yuan031e3602018-03-15 02:15:50 +0800451#include <linux/logic_pio.h>
452
Thierry Reding9216efa2014-10-01 15:20:33 +0200453/*
454 * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be
455 * implemented on hardware that needs an additional delay for I/O accesses to
456 * take effect.
457 */
458
459#ifndef inb
460#define inb inb
461static inline u8 inb(unsigned long addr)
462{
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400463 u8 val;
464
465 __io_pbr();
466 val = __raw_readb(PCI_IOBASE + addr);
Will Deaconabbbbc82019-02-22 18:04:52 +0000467 __io_par(val);
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400468 return val;
Thierry Reding9216efa2014-10-01 15:20:33 +0200469}
470#endif
471
472#ifndef inw
473#define inw inw
474static inline u16 inw(unsigned long addr)
475{
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400476 u16 val;
477
478 __io_pbr();
479 val = __le16_to_cpu(__raw_readw(PCI_IOBASE + addr));
Will Deaconabbbbc82019-02-22 18:04:52 +0000480 __io_par(val);
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400481 return val;
Thierry Reding9216efa2014-10-01 15:20:33 +0200482}
483#endif
484
485#ifndef inl
486#define inl inl
487static inline u32 inl(unsigned long addr)
488{
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400489 u32 val;
490
491 __io_pbr();
492 val = __le32_to_cpu(__raw_readl(PCI_IOBASE + addr));
Will Deaconabbbbc82019-02-22 18:04:52 +0000493 __io_par(val);
Sinan Kaya87fe2d52018-04-05 09:09:13 -0400494 return val;
Thierry Reding9216efa2014-10-01 15:20:33 +0200495}
496#endif
497
498#ifndef outb
499#define outb outb
500static inline void outb(u8 value, unsigned long addr)
501{
Sinan Kayaa7851aa2018-04-05 09:09:12 -0400502 __io_pbw();
503 __raw_writeb(value, PCI_IOBASE + addr);
504 __io_paw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200505}
506#endif
507
508#ifndef outw
509#define outw outw
510static inline void outw(u16 value, unsigned long addr)
511{
Sinan Kayaa7851aa2018-04-05 09:09:12 -0400512 __io_pbw();
513 __raw_writew(cpu_to_le16(value), PCI_IOBASE + addr);
514 __io_paw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200515}
516#endif
517
518#ifndef outl
519#define outl outl
520static inline void outl(u32 value, unsigned long addr)
521{
Sinan Kayaa7851aa2018-04-05 09:09:12 -0400522 __io_pbw();
523 __raw_writel(cpu_to_le32(value), PCI_IOBASE + addr);
524 __io_paw();
Thierry Reding9216efa2014-10-01 15:20:33 +0200525}
526#endif
527
528#ifndef inb_p
529#define inb_p inb_p
530static inline u8 inb_p(unsigned long addr)
531{
532 return inb(addr);
533}
534#endif
535
536#ifndef inw_p
537#define inw_p inw_p
538static inline u16 inw_p(unsigned long addr)
539{
540 return inw(addr);
541}
542#endif
543
544#ifndef inl_p
545#define inl_p inl_p
546static inline u32 inl_p(unsigned long addr)
547{
548 return inl(addr);
549}
550#endif
551
552#ifndef outb_p
553#define outb_p outb_p
554static inline void outb_p(u8 value, unsigned long addr)
555{
556 outb(value, addr);
557}
558#endif
559
560#ifndef outw_p
561#define outw_p outw_p
562static inline void outw_p(u16 value, unsigned long addr)
563{
564 outw(value, addr);
565}
566#endif
567
568#ifndef outl_p
569#define outl_p outl_p
570static inline void outl_p(u32 value, unsigned long addr)
571{
572 outl(value, addr);
573}
574#endif
575
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200576/*
577 * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a
578 * single I/O port multiple times.
579 */
580
581#ifndef insb
582#define insb insb
583static inline void insb(unsigned long addr, void *buffer, unsigned int count)
584{
585 readsb(PCI_IOBASE + addr, buffer, count);
586}
587#endif
588
589#ifndef insw
590#define insw insw
591static inline void insw(unsigned long addr, void *buffer, unsigned int count)
592{
593 readsw(PCI_IOBASE + addr, buffer, count);
594}
595#endif
596
597#ifndef insl
598#define insl insl
599static inline void insl(unsigned long addr, void *buffer, unsigned int count)
600{
601 readsl(PCI_IOBASE + addr, buffer, count);
602}
603#endif
604
605#ifndef outsb
606#define outsb outsb
607static inline void outsb(unsigned long addr, const void *buffer,
608 unsigned int count)
609{
610 writesb(PCI_IOBASE + addr, buffer, count);
611}
612#endif
613
614#ifndef outsw
615#define outsw outsw
616static inline void outsw(unsigned long addr, const void *buffer,
617 unsigned int count)
618{
619 writesw(PCI_IOBASE + addr, buffer, count);
620}
621#endif
622
623#ifndef outsl
624#define outsl outsl
625static inline void outsl(unsigned long addr, const void *buffer,
626 unsigned int count)
627{
628 writesl(PCI_IOBASE + addr, buffer, count);
629}
630#endif
631
632#ifndef insb_p
633#define insb_p insb_p
634static inline void insb_p(unsigned long addr, void *buffer, unsigned int count)
635{
636 insb(addr, buffer, count);
637}
638#endif
639
640#ifndef insw_p
641#define insw_p insw_p
642static inline void insw_p(unsigned long addr, void *buffer, unsigned int count)
643{
644 insw(addr, buffer, count);
645}
646#endif
647
648#ifndef insl_p
649#define insl_p insl_p
650static inline void insl_p(unsigned long addr, void *buffer, unsigned int count)
651{
652 insl(addr, buffer, count);
653}
654#endif
655
656#ifndef outsb_p
657#define outsb_p outsb_p
658static inline void outsb_p(unsigned long addr, const void *buffer,
659 unsigned int count)
660{
661 outsb(addr, buffer, count);
662}
663#endif
664
665#ifndef outsw_p
666#define outsw_p outsw_p
667static inline void outsw_p(unsigned long addr, const void *buffer,
668 unsigned int count)
669{
670 outsw(addr, buffer, count);
671}
672#endif
673
674#ifndef outsl_p
675#define outsl_p outsl_p
676static inline void outsl_p(unsigned long addr, const void *buffer,
677 unsigned int count)
678{
679 outsl(addr, buffer, count);
680}
681#endif
682
Thierry Reding9216efa2014-10-01 15:20:33 +0200683#ifndef CONFIG_GENERIC_IOMAP
684#ifndef ioread8
685#define ioread8 ioread8
686static inline u8 ioread8(const volatile void __iomem *addr)
687{
688 return readb(addr);
689}
690#endif
691
692#ifndef ioread16
693#define ioread16 ioread16
694static inline u16 ioread16(const volatile void __iomem *addr)
695{
696 return readw(addr);
697}
698#endif
699
700#ifndef ioread32
701#define ioread32 ioread32
702static inline u32 ioread32(const volatile void __iomem *addr)
703{
704 return readl(addr);
705}
706#endif
707
Horia Geantă9e44fb12016-05-19 18:10:56 +0300708#ifdef CONFIG_64BIT
709#ifndef ioread64
710#define ioread64 ioread64
711static inline u64 ioread64(const volatile void __iomem *addr)
712{
713 return readq(addr);
714}
715#endif
716#endif /* CONFIG_64BIT */
717
Thierry Reding9216efa2014-10-01 15:20:33 +0200718#ifndef iowrite8
719#define iowrite8 iowrite8
720static inline void iowrite8(u8 value, volatile void __iomem *addr)
721{
722 writeb(value, addr);
723}
724#endif
725
726#ifndef iowrite16
727#define iowrite16 iowrite16
728static inline void iowrite16(u16 value, volatile void __iomem *addr)
729{
730 writew(value, addr);
731}
732#endif
733
734#ifndef iowrite32
735#define iowrite32 iowrite32
736static inline void iowrite32(u32 value, volatile void __iomem *addr)
737{
738 writel(value, addr);
739}
740#endif
741
Horia Geantă9e44fb12016-05-19 18:10:56 +0300742#ifdef CONFIG_64BIT
743#ifndef iowrite64
744#define iowrite64 iowrite64
745static inline void iowrite64(u64 value, volatile void __iomem *addr)
746{
747 writeq(value, addr);
748}
749#endif
750#endif /* CONFIG_64BIT */
751
Thierry Reding9216efa2014-10-01 15:20:33 +0200752#ifndef ioread16be
753#define ioread16be ioread16be
754static inline u16 ioread16be(const volatile void __iomem *addr)
755{
Horia Geantă7a1aedb2016-05-19 18:10:43 +0300756 return swab16(readw(addr));
Thierry Reding9216efa2014-10-01 15:20:33 +0200757}
758#endif
759
760#ifndef ioread32be
761#define ioread32be ioread32be
762static inline u32 ioread32be(const volatile void __iomem *addr)
763{
Horia Geantă7a1aedb2016-05-19 18:10:43 +0300764 return swab32(readl(addr));
Thierry Reding9216efa2014-10-01 15:20:33 +0200765}
766#endif
767
Horia Geantă9e44fb12016-05-19 18:10:56 +0300768#ifdef CONFIG_64BIT
769#ifndef ioread64be
770#define ioread64be ioread64be
771static inline u64 ioread64be(const volatile void __iomem *addr)
772{
773 return swab64(readq(addr));
774}
775#endif
776#endif /* CONFIG_64BIT */
777
Thierry Reding9216efa2014-10-01 15:20:33 +0200778#ifndef iowrite16be
779#define iowrite16be iowrite16be
780static inline void iowrite16be(u16 value, void volatile __iomem *addr)
781{
Horia Geantă7a1aedb2016-05-19 18:10:43 +0300782 writew(swab16(value), addr);
Thierry Reding9216efa2014-10-01 15:20:33 +0200783}
784#endif
785
786#ifndef iowrite32be
787#define iowrite32be iowrite32be
788static inline void iowrite32be(u32 value, volatile void __iomem *addr)
789{
Horia Geantă7a1aedb2016-05-19 18:10:43 +0300790 writel(swab32(value), addr);
Thierry Reding9216efa2014-10-01 15:20:33 +0200791}
792#endif
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200793
Horia Geantă9e44fb12016-05-19 18:10:56 +0300794#ifdef CONFIG_64BIT
795#ifndef iowrite64be
796#define iowrite64be iowrite64be
797static inline void iowrite64be(u64 value, volatile void __iomem *addr)
798{
799 writeq(swab64(value), addr);
800}
801#endif
802#endif /* CONFIG_64BIT */
803
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200804#ifndef ioread8_rep
805#define ioread8_rep ioread8_rep
806static inline void ioread8_rep(const volatile void __iomem *addr, void *buffer,
807 unsigned int count)
808{
809 readsb(addr, buffer, count);
810}
811#endif
812
813#ifndef ioread16_rep
814#define ioread16_rep ioread16_rep
815static inline void ioread16_rep(const volatile void __iomem *addr,
816 void *buffer, unsigned int count)
817{
818 readsw(addr, buffer, count);
819}
820#endif
821
822#ifndef ioread32_rep
823#define ioread32_rep ioread32_rep
824static inline void ioread32_rep(const volatile void __iomem *addr,
825 void *buffer, unsigned int count)
826{
827 readsl(addr, buffer, count);
828}
829#endif
830
Horia Geantă9e44fb12016-05-19 18:10:56 +0300831#ifdef CONFIG_64BIT
832#ifndef ioread64_rep
833#define ioread64_rep ioread64_rep
834static inline void ioread64_rep(const volatile void __iomem *addr,
835 void *buffer, unsigned int count)
836{
837 readsq(addr, buffer, count);
838}
839#endif
840#endif /* CONFIG_64BIT */
841
Thierry Reding9ab3a7a2014-07-04 13:07:57 +0200842#ifndef iowrite8_rep
843#define iowrite8_rep iowrite8_rep
844static inline void iowrite8_rep(volatile void __iomem *addr,
845 const void *buffer,
846 unsigned int count)
847{
848 writesb(addr, buffer, count);
849}
850#endif
851
852#ifndef iowrite16_rep
853#define iowrite16_rep iowrite16_rep
854static inline void iowrite16_rep(volatile void __iomem *addr,
855 const void *buffer,
856 unsigned int count)
857{
858 writesw(addr, buffer, count);
859}
860#endif
861
862#ifndef iowrite32_rep
863#define iowrite32_rep iowrite32_rep
864static inline void iowrite32_rep(volatile void __iomem *addr,
865 const void *buffer,
866 unsigned int count)
867{
868 writesl(addr, buffer, count);
869}
870#endif
Horia Geantă9e44fb12016-05-19 18:10:56 +0300871
872#ifdef CONFIG_64BIT
873#ifndef iowrite64_rep
874#define iowrite64_rep iowrite64_rep
875static inline void iowrite64_rep(volatile void __iomem *addr,
876 const void *buffer,
877 unsigned int count)
878{
879 writesq(addr, buffer, count);
880}
881#endif
882#endif /* CONFIG_64BIT */
Thierry Reding9216efa2014-10-01 15:20:33 +0200883#endif /* CONFIG_GENERIC_IOMAP */
884
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000885#ifdef __KERNEL__
886
887#include <linux/vmalloc.h>
Thierry Reding9216efa2014-10-01 15:20:33 +0200888#define __io_virt(x) ((void __force *)(x))
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000889
890#ifndef CONFIG_GENERIC_IOMAP
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000891struct pci_dev;
Jan Glaubercd248342012-11-29 12:50:30 +0100892extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
893
894#ifndef pci_iounmap
Thierry Reding9216efa2014-10-01 15:20:33 +0200895#define pci_iounmap pci_iounmap
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000896static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
897{
898}
Jan Glaubercd248342012-11-29 12:50:30 +0100899#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000900#endif /* CONFIG_GENERIC_IOMAP */
901
902/*
903 * Change virtual addresses to physical addresses and vv.
904 * These are pretty trivial
905 */
Jan Glaubercd248342012-11-29 12:50:30 +0100906#ifndef virt_to_phys
Thierry Reding9216efa2014-10-01 15:20:33 +0200907#define virt_to_phys virt_to_phys
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000908static inline unsigned long virt_to_phys(volatile void *address)
909{
910 return __pa((unsigned long)address);
911}
Thierry Reding9216efa2014-10-01 15:20:33 +0200912#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000913
Thierry Reding9216efa2014-10-01 15:20:33 +0200914#ifndef phys_to_virt
915#define phys_to_virt phys_to_virt
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000916static inline void *phys_to_virt(unsigned long address)
917{
918 return __va(address);
919}
Jan Glaubercd248342012-11-29 12:50:30 +0100920#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000921
Luis R. Rodriguez8c7ea502015-07-09 17:28:16 -0700922/**
923 * DOC: ioremap() and ioremap_*() variants
924 *
925 * If you have an IOMMU your architecture is expected to have both ioremap()
926 * and iounmap() implemented otherwise the asm-generic helpers will provide a
927 * direct mapping.
928 *
929 * There are ioremap_*() call variants, if you have no IOMMU we naturally will
930 * default to direct mapping for all of them, you can override these defaults.
931 * If you have an IOMMU you are highly encouraged to provide your own
932 * ioremap variant implementation as there currently is no safe architecture
933 * agnostic default. To avoid possible improper behaviour default asm-generic
934 * ioremap_*() variants all return NULL when an IOMMU is available. If you've
935 * defined your own ioremap_*() variant you must then declare your own
936 * ioremap_*() variant as defined to itself to avoid the default NULL return.
937 */
Christoph Hellwige9713392019-08-13 07:53:05 +0200938#ifndef CONFIG_MMU
Luis R. Rodriguez8c7ea502015-07-09 17:28:16 -0700939
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000940/*
941 * Change "struct page" to physical address.
Jonas Bonnf1ecc692011-07-02 17:17:35 +0200942 *
943 * This implementation is for the no-MMU case only... if you have an MMU
944 * you'll need to provide your own definitions.
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000945 */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000946
Thierry Reding9216efa2014-10-01 15:20:33 +0200947#ifndef ioremap
948#define ioremap ioremap
949static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
950{
951 return (void __iomem *)(unsigned long)offset;
952}
953#endif
954
Greentime Hub3ada9d2017-11-22 18:57:46 +0800955#ifndef iounmap
956#define iounmap iounmap
957
958static inline void iounmap(void __iomem *addr)
959{
960}
961#endif
962#endif /* CONFIG_MMU */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000963#ifndef ioremap_nocache
Greentime Hub3ada9d2017-11-22 18:57:46 +0800964void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
Thierry Reding9216efa2014-10-01 15:20:33 +0200965#define ioremap_nocache ioremap_nocache
966static inline void __iomem *ioremap_nocache(phys_addr_t offset, size_t size)
967{
968 return ioremap(offset, size);
969}
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000970#endif
971
972#ifndef ioremap_wc
Thierry Reding9216efa2014-10-01 15:20:33 +0200973#define ioremap_wc ioremap_wc
974static inline void __iomem *ioremap_wc(phys_addr_t offset, size_t size)
975{
976 return ioremap_nocache(offset, size);
977}
Arnd Bergmann3f7e2122009-05-13 22:56:35 +0000978#endif
979
Toshi Kanid8382702015-06-04 18:55:15 +0200980#ifndef ioremap_wt
981#define ioremap_wt ioremap_wt
982static inline void __iomem *ioremap_wt(phys_addr_t offset, size_t size)
983{
984 return ioremap_nocache(offset, size);
985}
986#endif
987
Christoph Hellwige9713392019-08-13 07:53:05 +0200988/*
989 * ioremap_uc is special in that we do require an explicit architecture
990 * implementation. In general you do not want to use this function in a
991 * driver and use plain ioremap, which is uncached by default. Similarly
992 * architectures should not implement it unless they have a very good
993 * reason.
994 */
995#ifndef ioremap_uc
996#define ioremap_uc ioremap_uc
997static inline void __iomem *ioremap_uc(phys_addr_t offset, size_t size)
998{
999 return NULL;
1000}
1001#endif
1002
Uwe Kleine-Königce816fa2014-04-07 15:39:19 -07001003#ifdef CONFIG_HAS_IOPORT_MAP
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001004#ifndef CONFIG_GENERIC_IOMAP
Thierry Reding9216efa2014-10-01 15:20:33 +02001005#ifndef ioport_map
1006#define ioport_map ioport_map
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001007static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
1008{
Andrew Murray500dd2322018-09-13 13:48:27 +01001009 port &= IO_SPACE_LIMIT;
1010 return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001011}
Thierry Reding9216efa2014-10-01 15:20:33 +02001012#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001013
Thierry Reding9216efa2014-10-01 15:20:33 +02001014#ifndef ioport_unmap
1015#define ioport_unmap ioport_unmap
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001016static inline void ioport_unmap(void __iomem *p)
1017{
1018}
Thierry Reding9216efa2014-10-01 15:20:33 +02001019#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001020#else /* CONFIG_GENERIC_IOMAP */
1021extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
1022extern void ioport_unmap(void __iomem *p);
1023#endif /* CONFIG_GENERIC_IOMAP */
Uwe Kleine-Königce816fa2014-04-07 15:39:19 -07001024#endif /* CONFIG_HAS_IOPORT_MAP */
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001025
Andy Shevchenkoeabc2a72017-06-30 20:09:33 +03001026/*
1027 * Convert a virtual cached pointer to an uncached pointer
1028 */
Michael Holzheu576ebd72013-05-21 16:08:22 +02001029#ifndef xlate_dev_kmem_ptr
Thierry Reding9216efa2014-10-01 15:20:33 +02001030#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
1031static inline void *xlate_dev_kmem_ptr(void *addr)
1032{
1033 return addr;
1034}
Michael Holzheu576ebd72013-05-21 16:08:22 +02001035#endif
Thierry Reding9216efa2014-10-01 15:20:33 +02001036
Michael Holzheu576ebd72013-05-21 16:08:22 +02001037#ifndef xlate_dev_mem_ptr
Thierry Reding9216efa2014-10-01 15:20:33 +02001038#define xlate_dev_mem_ptr xlate_dev_mem_ptr
1039static inline void *xlate_dev_mem_ptr(phys_addr_t addr)
1040{
1041 return __va(addr);
1042}
1043#endif
1044
1045#ifndef unxlate_dev_mem_ptr
1046#define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
1047static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
1048{
1049}
Michael Holzheu576ebd72013-05-21 16:08:22 +02001050#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001051
James Hoganc93d0312012-11-23 16:13:05 +00001052#ifdef CONFIG_VIRT_TO_BUS
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001053#ifndef virt_to_bus
Thierry Reding9216efa2014-10-01 15:20:33 +02001054static inline unsigned long virt_to_bus(void *address)
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001055{
Thierry Reding9216efa2014-10-01 15:20:33 +02001056 return (unsigned long)address;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001057}
1058
1059static inline void *bus_to_virt(unsigned long address)
1060{
Thierry Reding9216efa2014-10-01 15:20:33 +02001061 return (void *)address;
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001062}
1063#endif
James Hoganc93d0312012-11-23 16:13:05 +00001064#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001065
Jan Glaubercd248342012-11-29 12:50:30 +01001066#ifndef memset_io
Thierry Reding9216efa2014-10-01 15:20:33 +02001067#define memset_io memset_io
Andy Shevchenkoc2327da2017-06-30 20:09:32 +03001068/**
1069 * memset_io Set a range of I/O memory to a constant value
1070 * @addr: The beginning of the I/O-memory range to set
1071 * @val: The value to set the memory to
1072 * @count: The number of bytes to set
1073 *
1074 * Set a range of I/O memory to a given value.
1075 */
Thierry Reding9216efa2014-10-01 15:20:33 +02001076static inline void memset_io(volatile void __iomem *addr, int value,
1077 size_t size)
1078{
1079 memset(__io_virt(addr), value, size);
1080}
Jan Glaubercd248342012-11-29 12:50:30 +01001081#endif
1082
1083#ifndef memcpy_fromio
Thierry Reding9216efa2014-10-01 15:20:33 +02001084#define memcpy_fromio memcpy_fromio
Andy Shevchenkoc2327da2017-06-30 20:09:32 +03001085/**
1086 * memcpy_fromio Copy a block of data from I/O memory
1087 * @dst: The (RAM) destination for the copy
1088 * @src: The (I/O memory) source for the data
1089 * @count: The number of bytes to copy
1090 *
1091 * Copy a block of data from I/O memory.
1092 */
Thierry Reding9216efa2014-10-01 15:20:33 +02001093static inline void memcpy_fromio(void *buffer,
1094 const volatile void __iomem *addr,
1095 size_t size)
1096{
1097 memcpy(buffer, __io_virt(addr), size);
1098}
Jan Glaubercd248342012-11-29 12:50:30 +01001099#endif
Thierry Reding9216efa2014-10-01 15:20:33 +02001100
Jan Glaubercd248342012-11-29 12:50:30 +01001101#ifndef memcpy_toio
Thierry Reding9216efa2014-10-01 15:20:33 +02001102#define memcpy_toio memcpy_toio
Andy Shevchenkoc2327da2017-06-30 20:09:32 +03001103/**
1104 * memcpy_toio Copy a block of data into I/O memory
1105 * @dst: The (I/O memory) destination for the copy
1106 * @src: The (RAM) source for the data
1107 * @count: The number of bytes to copy
1108 *
1109 * Copy a block of data to I/O memory.
1110 */
Thierry Reding9216efa2014-10-01 15:20:33 +02001111static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
1112 size_t size)
1113{
1114 memcpy(__io_virt(addr), buffer, size);
1115}
Jan Glaubercd248342012-11-29 12:50:30 +01001116#endif
Arnd Bergmann3f7e2122009-05-13 22:56:35 +00001117
1118#endif /* __KERNEL__ */
1119
1120#endif /* __ASM_GENERIC_IO_H */