// SPDX-License-Identifier: GPL-2.0-only /* * linux/arch/arm/mm/ioremap.c * * Re-map IO memory to kernel address space so that we can access it. * * (C) Copyright 1995 1996 Linus Torvalds * * Hacked for ARM by Phil Blundell <philb@gnu.org> * Hacked to allow all architectures to build, and various cleanups * by Russell King * * This allows a driver to remap an arbitrary region of bus memory into * virtual space. One should *only* use readl, writel, memcpy_toio and * so on with such remapped areas. * * Because the ARM only has a 32-bit address space we can't address the * whole of the (physical) PCI space at once. PCI huge-mode addressing * allows us to circumvent this restriction by splitting PCI space into * two 2GB chunks and mapping only one at a time into processor memory. * We use MMU protection domains to trap any attempt to access the bank * that is not currently mapped. (This isn't fully implemented yet.)
*/ #include <linux/module.h> #include <linux/errno.h> #include <linux/kasan.h> #include <linux/mm.h> #include <linux/vmalloc.h> #include <linux/io.h> #include <linux/sizes.h> #include <linux/memblock.h>
void __check_vmalloc_seq(struct mm_struct *mm)
{ int seq;
do {
seq = atomic_read_acquire(&init_mm.context.vmalloc_seq);
memcpy_pgd(mm, VMALLOC_START, VMALLOC_END); if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { unsignedlong start =
arm_kasan_mem_to_shadow(VMALLOC_START); unsignedlong end =
arm_kasan_mem_to_shadow(VMALLOC_END);
memcpy_pgd(mm, start, end);
} /* * Use a store-release so that other CPUs that observe the * counter's new value are guaranteed to see the results of the * memcpy as well.
*/
atomic_set_release(&mm->context.vmalloc_seq, seq);
} while (seq != atomic_read(&init_mm.context.vmalloc_seq));
}
#if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE) /* * Section support is unsafe on SMP - If you iounmap and ioremap a region, * the other CPUs will not see this change until their next context switch. * Meanwhile, (eg) if an interrupt comes in on one of those other CPUs * which requires the new ioremap'd region to be referenced, the CPU will * reference the _old_ region. * * Note that get_vm_area_caller() allocates a guard 4K page, so we need to * mask the size back to 1MB aligned or we will overflow in the loop below.
*/ staticvoid unmap_area_sections(unsignedlong virt, unsignedlong size)
{ unsignedlong addr = virt, end = virt + (size & ~(SZ_1M - 1));
pmd_t *pmdp = pmd_off_k(addr);
do {
pmd_t pmd = *pmdp;
if (!pmd_none(pmd)) { /* * Clear the PMD from the page table, and * increment the vmalloc sequence so others * notice this change. * * Note: this is still racy on SMP machines.
*/
pmd_clear(pmdp);
atomic_inc_return_release(&init_mm.context.vmalloc_seq);
/* * Free the page table, if there was one.
*/ if ((pmd_val(pmd) & PMD_TYPE_MASK) == PMD_TYPE_TABLE)
pte_free_kernel(&init_mm, pmd_page_vaddr(pmd));
}
/* * Remove and free any PTE-based mapping, and * sync the current kernel mapping.
*/
unmap_area_sections(virt, size); do { unsignedlong super_pmd_val, i;
/* * Don't allow RAM to be mapped with mismatched attributes - this * causes problems with ARMv6+
*/ if (WARN_ON(memblock_is_map_memory(PFN_PHYS(pfn)) &&
mtype != MT_MEMORY_RW)) return NULL;
area = get_vm_area_caller(size, VM_IOREMAP, caller); if (!area) return NULL;
addr = (unsignedlong)area->addr;
area->phys_addr = paddr;
/* * Remap an arbitrary physical address space into the kernel virtual * address space. Needed when the kernel wants to access high addresses * directly. * * NOTE! We need to allow non-page-aligned mappings too: we will obviously * have to convert them into an offset in a page-aligned mapping, but the * caller shouldn't need to know that small detail.
*/ void __iomem *
__arm_ioremap_pfn(unsignedlong pfn, unsignedlong offset, size_t size, unsignedint mtype)
{ return __arm_ioremap_pfn_caller(pfn, offset, size, mtype,
__builtin_return_address(0));
}
EXPORT_SYMBOL(__arm_ioremap_pfn);
/* * Remap an arbitrary physical address space into the kernel virtual * address space as memory. Needed when the kernel wants to execute * code in external memory. This is needed for reprogramming source * clocks that would affect normal memory for example. Please see * CONFIG_GENERIC_ALLOCATOR for allocating external memory.
*/ void __iomem *
__arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
{ unsignedint mtype;
if (cached)
mtype = MT_MEMORY_RWX; else
mtype = MT_MEMORY_RWX_NONCACHED;
/* * If this is a section based mapping we need to handle it * specially as the VM subsystem does not know how to handle * such a beast.
*/ if (vm && (vm->flags & VM_ARM_SECTION_MAPPING))
unmap_area_sections((unsignedlong)vm->addr, vm->size);
} #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.