mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-13 14:04:05 +08:00
0b1f77e74b
Patch series "mm: ioremap: Convert architectures to take GENERIC_IOREMAP way", v8. Motivation and implementation: ============================== Currently, many architecutres have't taken the standard GENERIC_IOREMAP way to implement ioremap_prot(), iounmap(), and ioremap_xx(), but make these functions specifically under each arch's folder. Those cause many duplicated code of ioremap() and iounmap(). In this patchset, firstly introduce generic_ioremap_prot() and generic_iounmap() to extract the generic code for GENERIC_IOREMAP. By taking GENERIC_IOREMAP method, the generic generic_ioremap_prot(), generic_iounmap(), and their generic wrapper ioremap_prot(), ioremap() and iounmap() are all visible and available to arch. Arch needs to provide wrapper functions to override the generic version if there's arch specific handling in its corresponding ioremap_prot(), ioremap() or iounmap(). With these changes, duplicated ioremap/iounmap() code uder ARCH-es are removed, and the equivalent functioality is kept as before. Background info: ================ 1) The converting more architectures to take GENERIC_IOREMAP way is suggested by Christoph in below discussion: https://lore.kernel.org/all/Yp7h0Jv6vpgt6xdZ@infradead.org/T/#u 2) In the previous v1 to v3, it's basically further action after arm64 has converted to GENERIC_IOREMAP way in below patchset. It's done by adding hook ioremap_allowed() and iounmap_allowed() in ARCH to add ARCH specific handling the middle of ioremap_prot() and iounmap(). [PATCH v5 0/6] arm64: Cleanup ioremap() and support ioremap_prot() https://lore.kernel.org/all/20220607125027.44946-1-wangkefeng.wang@huawei.com/T/#u Later, during v3 reviewing, Christophe Leroy suggested to introduce generic_ioremap_prot() and generic_iounmap() to generic codes, and ARCH can provide wrapper function ioremap_prot(), ioremap() or iounmap() if needed. Christophe made a RFC patchset as below to specially demonstrate his idea. This is what v4 and now v5 is doing. [RFC PATCH 0/8] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way https://lore.kernel.org/all/cover.1665568707.git.christophe.leroy@csgroup.eu/T/#u Testing: ======== In v8, I only applied this patchset onto the latest linus's tree to build and run on arm64 and s390. This patch (of 19): Let's use '#define ioremap_xx' and "#ifdef ioremap_xx" instead. To remove defined ARCH_HAS_IOREMAP_xx macros in <asm/io.h> of each ARCH, the ARCH's own ioremap_wc|wt|np definition need be above "#include <asm-generic/iomap.h>. Otherwise the redefinition error would be seen during compiling. So the relevant adjustments are made to avoid compiling error: loongarch: - doesn't include <asm-generic/iomap.h>, defining ARCH_HAS_IOREMAP_WC is redundant, so simply remove it. m68k: - selected GENERIC_IOMAP, <asm-generic/iomap.h> has been added in <asm-generic/io.h>, and <asm/kmap.h> is included above <asm-generic/iomap.h>, so simply remove ARCH_HAS_IOREMAP_WT defining. mips: - move "#include <asm-generic/iomap.h>" below ioremap_wc definition in <asm/io.h> powerpc: - remove "#include <asm-generic/iomap.h>" in <asm/io.h> because it's duplicated with the one in <asm-generic/io.h>, let's rely on the latter. x86: - selected GENERIC_IOMAP, remove #include <asm-generic/iomap.h> in the middle of <asm/io.h>. Let's rely on <asm-generic/io.h>. Link: https://lkml.kernel.org/r/20230706154520.11257-2-bhe@redhat.com Signed-off-by: Baoquan He <bhe@redhat.com> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: David Laight <David.Laight@ACULAB.COM> Cc: Helge Deller <deller@gmx.de> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Niklas Schnelle <schnelle@linux.ibm.com> Cc: Stafford Horne <shorne@gmail.com> Cc: Brian Cain <bcain@quicinc.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Chris Zankel <chris@zankel.net> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Jonas Bonn <jonas@southpole.se> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Rich Felker <dalias@libc.org> Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
116 lines
3.9 KiB
C
116 lines
3.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __GENERIC_IO_H
|
|
#define __GENERIC_IO_H
|
|
|
|
#include <linux/linkage.h>
|
|
#include <asm/byteorder.h>
|
|
|
|
/*
|
|
* These are the "generic" interfaces for doing new-style
|
|
* memory-mapped or PIO accesses. Architectures may do
|
|
* their own arch-optimized versions, these just act as
|
|
* wrappers around the old-style IO register access functions:
|
|
* read[bwl]/write[bwl]/in[bwl]/out[bwl]
|
|
*
|
|
* Don't include this directly, include it from <asm/io.h>.
|
|
*/
|
|
|
|
/*
|
|
* Read/write from/to an (offsettable) iomem cookie. It might be a PIO
|
|
* access or a MMIO access, these functions don't care. The info is
|
|
* encoded in the hardware mapping set up by the mapping functions
|
|
* (or the cookie itself, depending on implementation and hw).
|
|
*
|
|
* The generic routines just encode the PIO/MMIO as part of the
|
|
* cookie, and coldly assume that the MMIO IO mappings are not
|
|
* in the low address range. Architectures for which this is not
|
|
* true can't use this generic implementation.
|
|
*/
|
|
extern unsigned int ioread8(const void __iomem *);
|
|
extern unsigned int ioread16(const void __iomem *);
|
|
extern unsigned int ioread16be(const void __iomem *);
|
|
extern unsigned int ioread32(const void __iomem *);
|
|
extern unsigned int ioread32be(const void __iomem *);
|
|
#ifdef CONFIG_64BIT
|
|
extern u64 ioread64(const void __iomem *);
|
|
extern u64 ioread64be(const void __iomem *);
|
|
#endif
|
|
|
|
#ifdef readq
|
|
#define ioread64_lo_hi ioread64_lo_hi
|
|
#define ioread64_hi_lo ioread64_hi_lo
|
|
#define ioread64be_lo_hi ioread64be_lo_hi
|
|
#define ioread64be_hi_lo ioread64be_hi_lo
|
|
extern u64 ioread64_lo_hi(const void __iomem *addr);
|
|
extern u64 ioread64_hi_lo(const void __iomem *addr);
|
|
extern u64 ioread64be_lo_hi(const void __iomem *addr);
|
|
extern u64 ioread64be_hi_lo(const void __iomem *addr);
|
|
#endif
|
|
|
|
extern void iowrite8(u8, void __iomem *);
|
|
extern void iowrite16(u16, void __iomem *);
|
|
extern void iowrite16be(u16, void __iomem *);
|
|
extern void iowrite32(u32, void __iomem *);
|
|
extern void iowrite32be(u32, void __iomem *);
|
|
#ifdef CONFIG_64BIT
|
|
extern void iowrite64(u64, void __iomem *);
|
|
extern void iowrite64be(u64, void __iomem *);
|
|
#endif
|
|
|
|
#ifdef writeq
|
|
#define iowrite64_lo_hi iowrite64_lo_hi
|
|
#define iowrite64_hi_lo iowrite64_hi_lo
|
|
#define iowrite64be_lo_hi iowrite64be_lo_hi
|
|
#define iowrite64be_hi_lo iowrite64be_hi_lo
|
|
extern void iowrite64_lo_hi(u64 val, void __iomem *addr);
|
|
extern void iowrite64_hi_lo(u64 val, void __iomem *addr);
|
|
extern void iowrite64be_lo_hi(u64 val, void __iomem *addr);
|
|
extern void iowrite64be_hi_lo(u64 val, void __iomem *addr);
|
|
#endif
|
|
|
|
/*
|
|
* "string" versions of the above. Note that they
|
|
* use native byte ordering for the accesses (on
|
|
* the assumption that IO and memory agree on a
|
|
* byte order, and CPU byteorder is irrelevant).
|
|
*
|
|
* They do _not_ update the port address. If you
|
|
* want MMIO that copies stuff laid out in MMIO
|
|
* memory across multiple ports, use "memcpy_toio()"
|
|
* and friends.
|
|
*/
|
|
extern void ioread8_rep(const void __iomem *port, void *buf, unsigned long count);
|
|
extern void ioread16_rep(const void __iomem *port, void *buf, unsigned long count);
|
|
extern void ioread32_rep(const void __iomem *port, void *buf, unsigned long count);
|
|
|
|
extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
|
|
extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
|
|
extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
|
|
|
|
#ifdef CONFIG_HAS_IOPORT_MAP
|
|
/* Create a virtual mapping cookie for an IO port range */
|
|
extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
|
|
extern void ioport_unmap(void __iomem *);
|
|
#endif
|
|
|
|
#ifndef ioremap_wc
|
|
#define ioremap_wc ioremap
|
|
#endif
|
|
|
|
#ifndef ioremap_wt
|
|
#define ioremap_wt ioremap
|
|
#endif
|
|
|
|
#ifndef ioremap_np
|
|
/* See the comment in asm-generic/io.h about ioremap_np(). */
|
|
#define ioremap_np ioremap_np
|
|
static inline void __iomem *ioremap_np(phys_addr_t offset, size_t size)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
#include <asm-generic/pci_iomap.h>
|
|
|
|
#endif
|