2019-08-20 14:07:17 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
|
|
|
|
#include <mm/mmu_decl.h>
|
|
|
|
|
|
|
|
void __iomem *ioremap_wt(phys_addr_t addr, unsigned long size)
|
|
|
|
{
|
|
|
|
pgprot_t prot = pgprot_cached_wthru(PAGE_KERNEL);
|
|
|
|
|
|
|
|
return __ioremap_caller(addr, size, prot, __builtin_return_address(0));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ioremap_wt);
|
|
|
|
|
|
|
|
void __iomem *
|
|
|
|
__ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *caller)
|
|
|
|
{
|
2019-08-20 14:07:18 +00:00
|
|
|
unsigned long v;
|
2019-08-20 14:07:19 +00:00
|
|
|
phys_addr_t p, offset;
|
2019-08-20 14:07:17 +00:00
|
|
|
int err;
|
|
|
|
|
2023-07-06 15:45:18 +00:00
|
|
|
/*
|
|
|
|
* If the address lies within the first 16 MB, assume it's in ISA
|
|
|
|
* memory space
|
|
|
|
*/
|
|
|
|
if (addr < SZ_16M)
|
|
|
|
addr += _ISA_MEM_BASE;
|
|
|
|
|
2019-08-20 14:07:17 +00:00
|
|
|
/*
|
|
|
|
* Choose an address to map it to.
|
|
|
|
* Once the vmalloc system is running, we use it.
|
|
|
|
* Before then, we use space going down from IOREMAP_TOP
|
|
|
|
* (ioremap_bot records where we're up to).
|
|
|
|
*/
|
|
|
|
p = addr & PAGE_MASK;
|
2019-08-20 14:07:19 +00:00
|
|
|
offset = addr & ~PAGE_MASK;
|
2019-08-20 14:07:17 +00:00
|
|
|
size = PAGE_ALIGN(addr + size) - p;
|
|
|
|
|
|
|
|
#ifndef CONFIG_CRASH_DUMP
|
|
|
|
/*
|
|
|
|
* Don't allow anybody to remap normal RAM that we're using.
|
|
|
|
* mem_init() sets high_memory so only do the check after that.
|
|
|
|
*/
|
|
|
|
if (slab_is_available() && p <= virt_to_phys(high_memory - 1) &&
|
|
|
|
page_is_ram(__phys_to_pfn(p))) {
|
|
|
|
pr_warn("%s(): phys addr 0x%llx is RAM lr %ps\n", __func__,
|
|
|
|
(unsigned long long)p, __builtin_return_address(0));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is it already mapped? Perhaps overlapped by a previous
|
|
|
|
* mapping.
|
|
|
|
*/
|
|
|
|
v = p_block_mapped(p);
|
|
|
|
if (v)
|
2019-08-20 14:07:20 +00:00
|
|
|
return (void __iomem *)v + offset;
|
2019-08-20 14:07:17 +00:00
|
|
|
|
2019-08-20 14:07:20 +00:00
|
|
|
if (slab_is_available())
|
2023-07-06 15:45:18 +00:00
|
|
|
return generic_ioremap_prot(addr, size, prot);
|
2019-08-20 14:07:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Should check if it is a candidate for a BAT mapping
|
|
|
|
*/
|
2019-09-12 13:49:44 +00:00
|
|
|
pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller);
|
2019-08-20 14:07:17 +00:00
|
|
|
|
2021-04-19 10:47:26 +00:00
|
|
|
err = early_ioremap_range(ioremap_bot - size - PAGE_SIZE, p, size, prot);
|
2019-08-20 14:07:19 +00:00
|
|
|
if (err)
|
2019-08-20 14:07:17 +00:00
|
|
|
return NULL;
|
2021-04-19 10:47:26 +00:00
|
|
|
ioremap_bot -= size + PAGE_SIZE;
|
2019-08-20 14:07:17 +00:00
|
|
|
|
2019-08-20 14:07:20 +00:00
|
|
|
return (void __iomem *)ioremap_bot + offset;
|
2019-08-20 14:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void iounmap(volatile void __iomem *addr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If mapped by BATs then there is nothing to do.
|
|
|
|
* Calling vfree() generates a benign warning.
|
|
|
|
*/
|
|
|
|
if (v_block_mapped((unsigned long)addr))
|
|
|
|
return;
|
|
|
|
|
2023-07-06 15:45:18 +00:00
|
|
|
generic_iounmap(addr);
|
2019-08-20 14:07:17 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(iounmap);
|