mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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 versions if there's arch specific handling in its ioremap_prot(), ioremap() or iounmap(). This change will simplify implementation by removing duplicated code with generic_ioremap_prot() and generic_iounmap(), and has the equivalent functioality as before. Here, add wrapper functions ioremap_prot() and iounmap() for ia64's special operation when ioremap() and iounmap(). Link: https://lkml.kernel.org/r/20230706154520.11257-9-bhe@redhat.com Signed-off-by: Baoquan He <bhe@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Brian Cain <bcain@quicinc.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Chris Zankel <chris@zankel.net> Cc: David Laight <David.Laight@ACULAB.COM> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Helge Deller <deller@gmx.de> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Jonas Bonn <jonas@southpole.se> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Niklas Schnelle <schnelle@linux.ibm.com> Cc: Rich Felker <dalias@libc.org> Cc: Stafford Horne <shorne@gmail.com> 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>
94 lines
2.5 KiB
C
94 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* (c) Copyright 2006, 2007 Hewlett-Packard Development Company, L.P.
|
|
* Bjorn Helgaas <bjorn.helgaas@hp.com>
|
|
*/
|
|
|
|
#include <linux/compiler.h>
|
|
#include <linux/module.h>
|
|
#include <linux/efi.h>
|
|
#include <linux/io.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <asm/io.h>
|
|
#include <asm/meminit.h>
|
|
|
|
static inline void __iomem *
|
|
__ioremap_uc(unsigned long phys_addr)
|
|
{
|
|
return (void __iomem *) (__IA64_UNCACHED_OFFSET | phys_addr);
|
|
}
|
|
|
|
void __iomem *
|
|
early_ioremap (unsigned long phys_addr, unsigned long size)
|
|
{
|
|
u64 attr;
|
|
attr = kern_mem_attribute(phys_addr, size);
|
|
if (attr & EFI_MEMORY_WB)
|
|
return (void __iomem *) phys_to_virt(phys_addr);
|
|
return __ioremap_uc(phys_addr);
|
|
}
|
|
|
|
void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
|
|
unsigned long flags)
|
|
{
|
|
u64 attr;
|
|
unsigned long gran_base, gran_size;
|
|
unsigned long page_base;
|
|
|
|
/*
|
|
* For things in kern_memmap, we must use the same attribute
|
|
* as the rest of the kernel. For more details, see
|
|
* Documentation/arch/ia64/aliasing.rst.
|
|
*/
|
|
attr = kern_mem_attribute(phys_addr, size);
|
|
if (attr & EFI_MEMORY_WB)
|
|
return (void __iomem *) phys_to_virt(phys_addr);
|
|
else if (attr & EFI_MEMORY_UC)
|
|
return __ioremap_uc(phys_addr);
|
|
|
|
/*
|
|
* Some chipsets don't support UC access to memory. If
|
|
* WB is supported for the whole granule, we prefer that.
|
|
*/
|
|
gran_base = GRANULEROUNDDOWN(phys_addr);
|
|
gran_size = GRANULEROUNDUP(phys_addr + size) - gran_base;
|
|
if (efi_mem_attribute(gran_base, gran_size) & EFI_MEMORY_WB)
|
|
return (void __iomem *) phys_to_virt(phys_addr);
|
|
|
|
/*
|
|
* WB is not supported for the whole granule, so we can't use
|
|
* the region 7 identity mapping. If we can safely cover the
|
|
* area with kernel page table mappings, we can use those
|
|
* instead.
|
|
*/
|
|
page_base = phys_addr & PAGE_MASK;
|
|
size = PAGE_ALIGN(phys_addr + size) - page_base;
|
|
if (efi_mem_attribute(page_base, size) & EFI_MEMORY_WB)
|
|
return generic_ioremap_prot(phys_addr, size, __pgprot(flags));
|
|
|
|
return __ioremap_uc(phys_addr);
|
|
}
|
|
EXPORT_SYMBOL(ioremap_prot);
|
|
|
|
void __iomem *
|
|
ioremap_uc(unsigned long phys_addr, unsigned long size)
|
|
{
|
|
if (kern_mem_attribute(phys_addr, size) & EFI_MEMORY_WB)
|
|
return NULL;
|
|
|
|
return __ioremap_uc(phys_addr);
|
|
}
|
|
EXPORT_SYMBOL(ioremap_uc);
|
|
|
|
void
|
|
early_iounmap (volatile void __iomem *addr, unsigned long size)
|
|
{
|
|
}
|
|
|
|
void iounmap(volatile void __iomem *addr)
|
|
{
|
|
if (REGION_NUMBER(addr) == RGN_GATE)
|
|
vunmap((void *) ((unsigned long) addr & PAGE_MASK));
|
|
}
|
|
EXPORT_SYMBOL(iounmap);
|