1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Generic I/O port emulation.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
7 #ifndef __ASM_GENERIC_IO_H
8 #define __ASM_GENERIC_IO_H
10 #include <asm/page.h> /* I/O is all done through memory accesses */
11 #include <linux/string.h> /* for memset() and memcpy() */
12 #include <linux/sizes.h>
13 #include <linux/types.h>
14 #include <linux/instruction_pointer.h>
16 #ifdef CONFIG_GENERIC_IOMAP
17 #include <asm-generic/iomap.h>
20 #include <asm/mmiowb.h>
21 #include <asm-generic/pci_iomap.h>
24 #define __io_br() barrier()
27 /* prevent prefetching of coherent DMA data ahead of a dma-complete */
30 #define __io_ar(v) rmb()
32 #define __io_ar(v) barrier()
36 /* flush writes to coherent DMA data before possibly triggering a DMA read */
39 #define __io_bw() wmb()
41 #define __io_bw() barrier()
45 /* serialize device access against a spin_unlock, usually handled there. */
47 #define __io_aw() mmiowb_set_pending()
51 #define __io_pbw() __io_bw()
55 #define __io_paw() __io_aw()
59 #define __io_pbr() __io_br()
63 #define __io_par(v) __io_ar(v)
67 * "__DISABLE_TRACE_MMIO__" flag can be used to disable MMIO tracing for
68 * specific kernel drivers in case of excessive/unwanted logging.
70 * Usage: Add a #define flag at the beginning of the driver file.
71 * Ex: #define __DISABLE_TRACE_MMIO__
75 #if IS_ENABLED(CONFIG_TRACE_MMIO_ACCESS) && !(defined(__DISABLE_TRACE_MMIO__))
76 #include <linux/tracepoint-defs.h>
78 DECLARE_TRACEPOINT(rwmmio_write
);
79 DECLARE_TRACEPOINT(rwmmio_post_write
);
80 DECLARE_TRACEPOINT(rwmmio_read
);
81 DECLARE_TRACEPOINT(rwmmio_post_read
);
83 void log_write_mmio(u64 val
, u8 width
, volatile void __iomem
*addr
,
84 unsigned long caller_addr
, unsigned long caller_addr0
);
85 void log_post_write_mmio(u64 val
, u8 width
, volatile void __iomem
*addr
,
86 unsigned long caller_addr
, unsigned long caller_addr0
);
87 void log_read_mmio(u8 width
, const volatile void __iomem
*addr
,
88 unsigned long caller_addr
, unsigned long caller_addr0
);
89 void log_post_read_mmio(u64 val
, u8 width
, const volatile void __iomem
*addr
,
90 unsigned long caller_addr
, unsigned long caller_addr0
);
94 static inline void log_write_mmio(u64 val
, u8 width
, volatile void __iomem
*addr
,
95 unsigned long caller_addr
, unsigned long caller_addr0
) {}
96 static inline void log_post_write_mmio(u64 val
, u8 width
, volatile void __iomem
*addr
,
97 unsigned long caller_addr
, unsigned long caller_addr0
) {}
98 static inline void log_read_mmio(u8 width
, const volatile void __iomem
*addr
,
99 unsigned long caller_addr
, unsigned long caller_addr0
) {}
100 static inline void log_post_read_mmio(u64 val
, u8 width
, const volatile void __iomem
*addr
,
101 unsigned long caller_addr
, unsigned long caller_addr0
) {}
103 #endif /* CONFIG_TRACE_MMIO_ACCESS */
106 * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
108 * On some architectures memory mapped IO needs to be accessed differently.
109 * On the simple architectures, we just read/write the memory location
114 #define __raw_readb __raw_readb
115 static inline u8
__raw_readb(const volatile void __iomem
*addr
)
117 return *(const volatile u8 __force
*)addr
;
122 #define __raw_readw __raw_readw
123 static inline u16
__raw_readw(const volatile void __iomem
*addr
)
125 return *(const volatile u16 __force
*)addr
;
130 #define __raw_readl __raw_readl
131 static inline u32
__raw_readl(const volatile void __iomem
*addr
)
133 return *(const volatile u32 __force
*)addr
;
139 #define __raw_readq __raw_readq
140 static inline u64
__raw_readq(const volatile void __iomem
*addr
)
142 return *(const volatile u64 __force
*)addr
;
145 #endif /* CONFIG_64BIT */
148 #define __raw_writeb __raw_writeb
149 static inline void __raw_writeb(u8 value
, volatile void __iomem
*addr
)
151 *(volatile u8 __force
*)addr
= value
;
156 #define __raw_writew __raw_writew
157 static inline void __raw_writew(u16 value
, volatile void __iomem
*addr
)
159 *(volatile u16 __force
*)addr
= value
;
164 #define __raw_writel __raw_writel
165 static inline void __raw_writel(u32 value
, volatile void __iomem
*addr
)
167 *(volatile u32 __force
*)addr
= value
;
173 #define __raw_writeq __raw_writeq
174 static inline void __raw_writeq(u64 value
, volatile void __iomem
*addr
)
176 *(volatile u64 __force
*)addr
= value
;
179 #endif /* CONFIG_64BIT */
182 * {read,write}{b,w,l,q}() access little endian memory and return result in
188 static inline u8
readb(const volatile void __iomem
*addr
)
192 log_read_mmio(8, addr
, _THIS_IP_
, _RET_IP_
);
194 val
= __raw_readb(addr
);
196 log_post_read_mmio(val
, 8, addr
, _THIS_IP_
, _RET_IP_
);
203 static inline u16
readw(const volatile void __iomem
*addr
)
207 log_read_mmio(16, addr
, _THIS_IP_
, _RET_IP_
);
209 val
= __le16_to_cpu((__le16 __force
)__raw_readw(addr
));
211 log_post_read_mmio(val
, 16, addr
, _THIS_IP_
, _RET_IP_
);
218 static inline u32
readl(const volatile void __iomem
*addr
)
222 log_read_mmio(32, addr
, _THIS_IP_
, _RET_IP_
);
224 val
= __le32_to_cpu((__le32 __force
)__raw_readl(addr
));
226 log_post_read_mmio(val
, 32, addr
, _THIS_IP_
, _RET_IP_
);
234 static inline u64
readq(const volatile void __iomem
*addr
)
238 log_read_mmio(64, addr
, _THIS_IP_
, _RET_IP_
);
240 val
= __le64_to_cpu((__le64 __force
)__raw_readq(addr
));
242 log_post_read_mmio(val
, 64, addr
, _THIS_IP_
, _RET_IP_
);
246 #endif /* CONFIG_64BIT */
249 #define writeb writeb
250 static inline void writeb(u8 value
, volatile void __iomem
*addr
)
252 log_write_mmio(value
, 8, addr
, _THIS_IP_
, _RET_IP_
);
254 __raw_writeb(value
, addr
);
256 log_post_write_mmio(value
, 8, addr
, _THIS_IP_
, _RET_IP_
);
261 #define writew writew
262 static inline void writew(u16 value
, volatile void __iomem
*addr
)
264 log_write_mmio(value
, 16, addr
, _THIS_IP_
, _RET_IP_
);
266 __raw_writew((u16 __force
)cpu_to_le16(value
), addr
);
268 log_post_write_mmio(value
, 16, addr
, _THIS_IP_
, _RET_IP_
);
273 #define writel writel
274 static inline void writel(u32 value
, volatile void __iomem
*addr
)
276 log_write_mmio(value
, 32, addr
, _THIS_IP_
, _RET_IP_
);
278 __raw_writel((u32 __force
)__cpu_to_le32(value
), addr
);
280 log_post_write_mmio(value
, 32, addr
, _THIS_IP_
, _RET_IP_
);
286 #define writeq writeq
287 static inline void writeq(u64 value
, volatile void __iomem
*addr
)
289 log_write_mmio(value
, 64, addr
, _THIS_IP_
, _RET_IP_
);
291 __raw_writeq((u64 __force
)__cpu_to_le64(value
), addr
);
293 log_post_write_mmio(value
, 64, addr
, _THIS_IP_
, _RET_IP_
);
296 #endif /* CONFIG_64BIT */
299 * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
300 * are not guaranteed to provide ordering against spinlocks or memory
303 #ifndef readb_relaxed
304 #define readb_relaxed readb_relaxed
305 static inline u8
readb_relaxed(const volatile void __iomem
*addr
)
309 log_read_mmio(8, addr
, _THIS_IP_
, _RET_IP_
);
310 val
= __raw_readb(addr
);
311 log_post_read_mmio(val
, 8, addr
, _THIS_IP_
, _RET_IP_
);
316 #ifndef readw_relaxed
317 #define readw_relaxed readw_relaxed
318 static inline u16
readw_relaxed(const volatile void __iomem
*addr
)
322 log_read_mmio(16, addr
, _THIS_IP_
, _RET_IP_
);
323 val
= __le16_to_cpu((__le16 __force
)__raw_readw(addr
));
324 log_post_read_mmio(val
, 16, addr
, _THIS_IP_
, _RET_IP_
);
329 #ifndef readl_relaxed
330 #define readl_relaxed readl_relaxed
331 static inline u32
readl_relaxed(const volatile void __iomem
*addr
)
335 log_read_mmio(32, addr
, _THIS_IP_
, _RET_IP_
);
336 val
= __le32_to_cpu((__le32 __force
)__raw_readl(addr
));
337 log_post_read_mmio(val
, 32, addr
, _THIS_IP_
, _RET_IP_
);
342 #if defined(readq) && !defined(readq_relaxed)
343 #define readq_relaxed readq_relaxed
344 static inline u64
readq_relaxed(const volatile void __iomem
*addr
)
348 log_read_mmio(64, addr
, _THIS_IP_
, _RET_IP_
);
349 val
= __le64_to_cpu((__le64 __force
)__raw_readq(addr
));
350 log_post_read_mmio(val
, 64, addr
, _THIS_IP_
, _RET_IP_
);
355 #ifndef writeb_relaxed
356 #define writeb_relaxed writeb_relaxed
357 static inline void writeb_relaxed(u8 value
, volatile void __iomem
*addr
)
359 log_write_mmio(value
, 8, addr
, _THIS_IP_
, _RET_IP_
);
360 __raw_writeb(value
, addr
);
361 log_post_write_mmio(value
, 8, addr
, _THIS_IP_
, _RET_IP_
);
365 #ifndef writew_relaxed
366 #define writew_relaxed writew_relaxed
367 static inline void writew_relaxed(u16 value
, volatile void __iomem
*addr
)
369 log_write_mmio(value
, 16, addr
, _THIS_IP_
, _RET_IP_
);
370 __raw_writew((u16 __force
)cpu_to_le16(value
), addr
);
371 log_post_write_mmio(value
, 16, addr
, _THIS_IP_
, _RET_IP_
);
375 #ifndef writel_relaxed
376 #define writel_relaxed writel_relaxed
377 static inline void writel_relaxed(u32 value
, volatile void __iomem
*addr
)
379 log_write_mmio(value
, 32, addr
, _THIS_IP_
, _RET_IP_
);
380 __raw_writel((u32 __force
)__cpu_to_le32(value
), addr
);
381 log_post_write_mmio(value
, 32, addr
, _THIS_IP_
, _RET_IP_
);
385 #if defined(writeq) && !defined(writeq_relaxed)
386 #define writeq_relaxed writeq_relaxed
387 static inline void writeq_relaxed(u64 value
, volatile void __iomem
*addr
)
389 log_write_mmio(value
, 64, addr
, _THIS_IP_
, _RET_IP_
);
390 __raw_writeq((u64 __force
)__cpu_to_le64(value
), addr
);
391 log_post_write_mmio(value
, 64, addr
, _THIS_IP_
, _RET_IP_
);
396 * {read,write}s{b,w,l,q}() repeatedly access the same memory address in
397 * native endianness in 8-, 16-, 32- or 64-bit chunks (@count times).
400 #define readsb readsb
401 static inline void readsb(const volatile void __iomem
*addr
, void *buffer
,
408 u8 x
= __raw_readb(addr
);
416 #define readsw readsw
417 static inline void readsw(const volatile void __iomem
*addr
, void *buffer
,
424 u16 x
= __raw_readw(addr
);
432 #define readsl readsl
433 static inline void readsl(const volatile void __iomem
*addr
, void *buffer
,
440 u32 x
= __raw_readl(addr
);
449 #define readsq readsq
450 static inline void readsq(const volatile void __iomem
*addr
, void *buffer
,
457 u64 x
= __raw_readq(addr
);
463 #endif /* CONFIG_64BIT */
466 #define writesb writesb
467 static inline void writesb(volatile void __iomem
*addr
, const void *buffer
,
471 const u8
*buf
= buffer
;
474 __raw_writeb(*buf
++, addr
);
481 #define writesw writesw
482 static inline void writesw(volatile void __iomem
*addr
, const void *buffer
,
486 const u16
*buf
= buffer
;
489 __raw_writew(*buf
++, addr
);
496 #define writesl writesl
497 static inline void writesl(volatile void __iomem
*addr
, const void *buffer
,
501 const u32
*buf
= buffer
;
504 __raw_writel(*buf
++, addr
);
512 #define writesq writesq
513 static inline void writesq(volatile void __iomem
*addr
, const void *buffer
,
517 const u64
*buf
= buffer
;
520 __raw_writeq(*buf
++, addr
);
525 #endif /* CONFIG_64BIT */
528 #define PCI_IOBASE ((void __iomem *)0)
531 #ifndef IO_SPACE_LIMIT
532 #define IO_SPACE_LIMIT 0xffff
536 * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be
537 * implemented on hardware that needs an additional delay for I/O accesses to
541 #if !defined(inb) && !defined(_inb)
543 #ifdef CONFIG_HAS_IOPORT
544 static inline u8
_inb(unsigned long addr
)
549 val
= __raw_readb(PCI_IOBASE
+ addr
);
554 u8
_inb(unsigned long addr
)
555 __compiletime_error("inb()) requires CONFIG_HAS_IOPORT");
559 #if !defined(inw) && !defined(_inw)
561 #ifdef CONFIG_HAS_IOPORT
562 static inline u16
_inw(unsigned long addr
)
567 val
= __le16_to_cpu((__le16 __force
)__raw_readw(PCI_IOBASE
+ addr
));
572 u16
_inw(unsigned long addr
)
573 __compiletime_error("inw() requires CONFIG_HAS_IOPORT");
577 #if !defined(inl) && !defined(_inl)
579 #ifdef CONFIG_HAS_IOPORT
580 static inline u32
_inl(unsigned long addr
)
585 val
= __le32_to_cpu((__le32 __force
)__raw_readl(PCI_IOBASE
+ addr
));
590 u32
_inl(unsigned long addr
)
591 __compiletime_error("inl() requires CONFIG_HAS_IOPORT");
595 #if !defined(outb) && !defined(_outb)
597 #ifdef CONFIG_HAS_IOPORT
598 static inline void _outb(u8 value
, unsigned long addr
)
601 __raw_writeb(value
, PCI_IOBASE
+ addr
);
605 void _outb(u8 value
, unsigned long addr
)
606 __compiletime_error("outb() requires CONFIG_HAS_IOPORT");
610 #if !defined(outw) && !defined(_outw)
612 #ifdef CONFIG_HAS_IOPORT
613 static inline void _outw(u16 value
, unsigned long addr
)
616 __raw_writew((u16 __force
)cpu_to_le16(value
), PCI_IOBASE
+ addr
);
620 void _outw(u16 value
, unsigned long addr
)
621 __compiletime_error("outw() requires CONFIG_HAS_IOPORT");
625 #if !defined(outl) && !defined(_outl)
627 #ifdef CONFIG_HAS_IOPORT
628 static inline void _outl(u32 value
, unsigned long addr
)
631 __raw_writel((u32 __force
)cpu_to_le32(value
), PCI_IOBASE
+ addr
);
635 void _outl(u32 value
, unsigned long addr
)
636 __compiletime_error("outl() requires CONFIG_HAS_IOPORT");
640 #include <linux/logic_pio.h>
668 static inline u8
inb_p(unsigned long addr
)
676 static inline u16
inw_p(unsigned long addr
)
684 static inline u32
inl_p(unsigned long addr
)
691 #define outb_p outb_p
692 static inline void outb_p(u8 value
, unsigned long addr
)
699 #define outw_p outw_p
700 static inline void outw_p(u16 value
, unsigned long addr
)
707 #define outl_p outl_p
708 static inline void outl_p(u32 value
, unsigned long addr
)
715 * {in,out}s{b,w,l}{,_p}() are variants of the above that repeatedly access a
716 * single I/O port multiple times.
721 #ifdef CONFIG_HAS_IOPORT
722 static inline void insb(unsigned long addr
, void *buffer
, unsigned int count
)
724 readsb(PCI_IOBASE
+ addr
, buffer
, count
);
727 void insb(unsigned long addr
, void *buffer
, unsigned int count
)
728 __compiletime_error("insb() requires HAS_IOPORT");
734 #ifdef CONFIG_HAS_IOPORT
735 static inline void insw(unsigned long addr
, void *buffer
, unsigned int count
)
737 readsw(PCI_IOBASE
+ addr
, buffer
, count
);
740 void insw(unsigned long addr
, void *buffer
, unsigned int count
)
741 __compiletime_error("insw() requires HAS_IOPORT");
747 #ifdef CONFIG_HAS_IOPORT
748 static inline void insl(unsigned long addr
, void *buffer
, unsigned int count
)
750 readsl(PCI_IOBASE
+ addr
, buffer
, count
);
753 void insl(unsigned long addr
, void *buffer
, unsigned int count
)
754 __compiletime_error("insl() requires HAS_IOPORT");
760 #ifdef CONFIG_HAS_IOPORT
761 static inline void outsb(unsigned long addr
, const void *buffer
,
764 writesb(PCI_IOBASE
+ addr
, buffer
, count
);
767 void outsb(unsigned long addr
, const void *buffer
, unsigned int count
)
768 __compiletime_error("outsb() requires HAS_IOPORT");
774 #ifdef CONFIG_HAS_IOPORT
775 static inline void outsw(unsigned long addr
, const void *buffer
,
778 writesw(PCI_IOBASE
+ addr
, buffer
, count
);
781 void outsw(unsigned long addr
, const void *buffer
, unsigned int count
)
782 __compiletime_error("outsw() requires HAS_IOPORT");
788 #ifdef CONFIG_HAS_IOPORT
789 static inline void outsl(unsigned long addr
, const void *buffer
,
792 writesl(PCI_IOBASE
+ addr
, buffer
, count
);
795 void outsl(unsigned long addr
, const void *buffer
, unsigned int count
)
796 __compiletime_error("outsl() requires HAS_IOPORT");
801 #define insb_p insb_p
802 static inline void insb_p(unsigned long addr
, void *buffer
, unsigned int count
)
804 insb(addr
, buffer
, count
);
809 #define insw_p insw_p
810 static inline void insw_p(unsigned long addr
, void *buffer
, unsigned int count
)
812 insw(addr
, buffer
, count
);
817 #define insl_p insl_p
818 static inline void insl_p(unsigned long addr
, void *buffer
, unsigned int count
)
820 insl(addr
, buffer
, count
);
825 #define outsb_p outsb_p
826 static inline void outsb_p(unsigned long addr
, const void *buffer
,
829 outsb(addr
, buffer
, count
);
834 #define outsw_p outsw_p
835 static inline void outsw_p(unsigned long addr
, const void *buffer
,
838 outsw(addr
, buffer
, count
);
843 #define outsl_p outsl_p
844 static inline void outsl_p(unsigned long addr
, const void *buffer
,
847 outsl(addr
, buffer
, count
);
851 #ifndef CONFIG_GENERIC_IOMAP
853 #define ioread8 ioread8
854 static inline u8
ioread8(const volatile void __iomem
*addr
)
861 #define ioread16 ioread16
862 static inline u16
ioread16(const volatile void __iomem
*addr
)
869 #define ioread32 ioread32
870 static inline u32
ioread32(const volatile void __iomem
*addr
)
878 #define ioread64 ioread64
879 static inline u64
ioread64(const volatile void __iomem
*addr
)
884 #endif /* CONFIG_64BIT */
887 #define iowrite8 iowrite8
888 static inline void iowrite8(u8 value
, volatile void __iomem
*addr
)
895 #define iowrite16 iowrite16
896 static inline void iowrite16(u16 value
, volatile void __iomem
*addr
)
903 #define iowrite32 iowrite32
904 static inline void iowrite32(u32 value
, volatile void __iomem
*addr
)
912 #define iowrite64 iowrite64
913 static inline void iowrite64(u64 value
, volatile void __iomem
*addr
)
918 #endif /* CONFIG_64BIT */
921 #define ioread16be ioread16be
922 static inline u16
ioread16be(const volatile void __iomem
*addr
)
924 return swab16(readw(addr
));
929 #define ioread32be ioread32be
930 static inline u32
ioread32be(const volatile void __iomem
*addr
)
932 return swab32(readl(addr
));
938 #define ioread64be ioread64be
939 static inline u64
ioread64be(const volatile void __iomem
*addr
)
941 return swab64(readq(addr
));
944 #endif /* CONFIG_64BIT */
947 #define iowrite16be iowrite16be
948 static inline void iowrite16be(u16 value
, void volatile __iomem
*addr
)
950 writew(swab16(value
), addr
);
955 #define iowrite32be iowrite32be
956 static inline void iowrite32be(u32 value
, volatile void __iomem
*addr
)
958 writel(swab32(value
), addr
);
964 #define iowrite64be iowrite64be
965 static inline void iowrite64be(u64 value
, volatile void __iomem
*addr
)
967 writeq(swab64(value
), addr
);
970 #endif /* CONFIG_64BIT */
973 #define ioread8_rep ioread8_rep
974 static inline void ioread8_rep(const volatile void __iomem
*addr
, void *buffer
,
977 readsb(addr
, buffer
, count
);
982 #define ioread16_rep ioread16_rep
983 static inline void ioread16_rep(const volatile void __iomem
*addr
,
984 void *buffer
, unsigned int count
)
986 readsw(addr
, buffer
, count
);
991 #define ioread32_rep ioread32_rep
992 static inline void ioread32_rep(const volatile void __iomem
*addr
,
993 void *buffer
, unsigned int count
)
995 readsl(addr
, buffer
, count
);
1000 #ifndef ioread64_rep
1001 #define ioread64_rep ioread64_rep
1002 static inline void ioread64_rep(const volatile void __iomem
*addr
,
1003 void *buffer
, unsigned int count
)
1005 readsq(addr
, buffer
, count
);
1008 #endif /* CONFIG_64BIT */
1010 #ifndef iowrite8_rep
1011 #define iowrite8_rep iowrite8_rep
1012 static inline void iowrite8_rep(volatile void __iomem
*addr
,
1016 writesb(addr
, buffer
, count
);
1020 #ifndef iowrite16_rep
1021 #define iowrite16_rep iowrite16_rep
1022 static inline void iowrite16_rep(volatile void __iomem
*addr
,
1026 writesw(addr
, buffer
, count
);
1030 #ifndef iowrite32_rep
1031 #define iowrite32_rep iowrite32_rep
1032 static inline void iowrite32_rep(volatile void __iomem
*addr
,
1036 writesl(addr
, buffer
, count
);
1041 #ifndef iowrite64_rep
1042 #define iowrite64_rep iowrite64_rep
1043 static inline void iowrite64_rep(volatile void __iomem
*addr
,
1047 writesq(addr
, buffer
, count
);
1050 #endif /* CONFIG_64BIT */
1051 #endif /* CONFIG_GENERIC_IOMAP */
1055 #define __io_virt(x) ((void __force *)(x))
1058 * Change virtual addresses to physical addresses and vv.
1059 * These are pretty trivial
1061 #ifndef virt_to_phys
1062 #define virt_to_phys virt_to_phys
1063 static inline unsigned long virt_to_phys(volatile void *address
)
1065 return __pa((unsigned long)address
);
1069 #ifndef phys_to_virt
1070 #define phys_to_virt phys_to_virt
1071 static inline void *phys_to_virt(unsigned long address
)
1073 return __va(address
);
1078 * DOC: ioremap() and ioremap_*() variants
1080 * Architectures with an MMU are expected to provide ioremap() and iounmap()
1081 * themselves or rely on GENERIC_IOREMAP. For NOMMU architectures we provide
1082 * a default nop-op implementation that expect that the physical address used
1083 * for MMIO are already marked as uncached, and can be used as kernel virtual
1086 * ioremap_wc() and ioremap_wt() can provide more relaxed caching attributes
1087 * for specific drivers if the architecture choses to implement them. If they
1088 * are not implemented we fall back to plain ioremap. Conversely, ioremap_np()
1089 * can provide stricter non-posted write semantics if the architecture
1094 #define ioremap ioremap
1095 static inline void __iomem
*ioremap(phys_addr_t offset
, size_t size
)
1097 return (void __iomem
*)(unsigned long)offset
;
1102 #define iounmap iounmap
1103 static inline void iounmap(volatile void __iomem
*addr
)
1107 #elif defined(CONFIG_GENERIC_IOREMAP)
1108 #include <linux/pgtable.h>
1110 void __iomem
*generic_ioremap_prot(phys_addr_t phys_addr
, size_t size
,
1113 void __iomem
*ioremap_prot(phys_addr_t phys_addr
, size_t size
,
1114 unsigned long prot
);
1115 void iounmap(volatile void __iomem
*addr
);
1116 void generic_iounmap(volatile void __iomem
*addr
);
1119 #define ioremap ioremap
1120 static inline void __iomem
*ioremap(phys_addr_t addr
, size_t size
)
1122 /* _PAGE_IOREMAP needs to be supplied by the architecture */
1123 return ioremap_prot(addr
, size
, _PAGE_IOREMAP
);
1126 #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */
1129 #define ioremap_wc ioremap
1133 #define ioremap_wt ioremap
1137 * ioremap_uc is special in that we do require an explicit architecture
1138 * implementation. In general you do not want to use this function in a
1139 * driver and use plain ioremap, which is uncached by default. Similarly
1140 * architectures should not implement it unless they have a very good
1144 #define ioremap_uc ioremap_uc
1145 static inline void __iomem
*ioremap_uc(phys_addr_t offset
, size_t size
)
1152 * ioremap_np needs an explicit architecture implementation, as it
1153 * requests stronger semantics than regular ioremap(). Portable drivers
1154 * should instead use one of the higher-level abstractions, like
1155 * devm_ioremap_resource(), to choose the correct variant for any given
1156 * device and bus. Portable drivers with a good reason to want non-posted
1157 * write semantics should always provide an ioremap() fallback in case
1158 * ioremap_np() is not available.
1161 #define ioremap_np ioremap_np
1162 static inline void __iomem
*ioremap_np(phys_addr_t offset
, size_t size
)
1168 #ifdef CONFIG_HAS_IOPORT_MAP
1169 #ifndef CONFIG_GENERIC_IOMAP
1171 #define ioport_map ioport_map
1172 static inline void __iomem
*ioport_map(unsigned long port
, unsigned int nr
)
1174 port
&= IO_SPACE_LIMIT
;
1175 return (port
> MMIO_UPPER_LIMIT
) ? NULL
: PCI_IOBASE
+ port
;
1177 #define ARCH_HAS_GENERIC_IOPORT_MAP
1180 #ifndef ioport_unmap
1181 #define ioport_unmap ioport_unmap
1182 static inline void ioport_unmap(void __iomem
*p
)
1186 #else /* CONFIG_GENERIC_IOMAP */
1187 extern void __iomem
*ioport_map(unsigned long port
, unsigned int nr
);
1188 extern void ioport_unmap(void __iomem
*p
);
1189 #endif /* CONFIG_GENERIC_IOMAP */
1190 #endif /* CONFIG_HAS_IOPORT_MAP */
1192 #ifndef CONFIG_GENERIC_IOMAP
1194 #define ARCH_WANTS_GENERIC_PCI_IOUNMAP
1198 #ifndef xlate_dev_mem_ptr
1199 #define xlate_dev_mem_ptr xlate_dev_mem_ptr
1200 static inline void *xlate_dev_mem_ptr(phys_addr_t addr
)
1206 #ifndef unxlate_dev_mem_ptr
1207 #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
1208 static inline void unxlate_dev_mem_ptr(phys_addr_t phys
, void *addr
)
1215 * memset_io Set a range of I/O memory to a constant value
1216 * @addr: The beginning of the I/O-memory range to set
1217 * @val: The value to set the memory to
1218 * @count: The number of bytes to set
1220 * Set a range of I/O memory to a given value.
1222 void memset_io(volatile void __iomem
*addr
, int val
, size_t count
);
1225 #ifndef memcpy_fromio
1227 * memcpy_fromio Copy a block of data from I/O memory
1228 * @dst: The (RAM) destination for the copy
1229 * @src: The (I/O memory) source for the data
1230 * @count: The number of bytes to copy
1232 * Copy a block of data from I/O memory.
1234 void memcpy_fromio(void *dst
, const volatile void __iomem
*src
, size_t count
);
1239 * memcpy_toio Copy a block of data into I/O memory
1240 * @dst: The (I/O memory) destination for the copy
1241 * @src: The (RAM) source for the data
1242 * @count: The number of bytes to copy
1244 * Copy a block of data to I/O memory.
1246 void memcpy_toio(volatile void __iomem
*dst
, const void *src
, size_t count
);
1249 extern int devmem_is_allowed(unsigned long pfn
);
1251 #endif /* __KERNEL__ */
1253 #endif /* __ASM_GENERIC_IO_H */