Merge branch 'for-next/ioremap' into for-next/core
* for-next/ioremap: arm64: Add HAVE_IOREMAP_PROT support arm64: mm: Convert to GENERIC_IOREMAP mm: ioremap: Add ioremap/iounmap_allowed() mm: ioremap: Setup phys_addr of struct vm_struct mm: ioremap: Use more sensible name in ioremap_prot() ARM: mm: kill unused runtime hook arch_iounmap()
This commit is contained in:
commit
84d8857af4
|
@ -9,7 +9,7 @@
|
|||
| alpha: | TODO |
|
||||
| arc: | ok |
|
||||
| arm: | TODO |
|
||||
| arm64: | TODO |
|
||||
| arm64: | ok |
|
||||
| csky: | TODO |
|
||||
| hexagon: | TODO |
|
||||
| ia64: | TODO |
|
||||
|
|
|
@ -139,11 +139,9 @@ extern void __iomem *__arm_ioremap_caller(phys_addr_t, size_t, unsigned int,
|
|||
extern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int);
|
||||
extern void __iomem *__arm_ioremap_exec(phys_addr_t, size_t, bool cached);
|
||||
void __arm_iomem_set_ro(void __iomem *ptr, size_t size);
|
||||
extern void __iounmap(volatile void __iomem *addr);
|
||||
|
||||
extern void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t,
|
||||
unsigned int, void *);
|
||||
extern void (*arch_iounmap)(volatile void __iomem *);
|
||||
|
||||
/*
|
||||
* Bad read/write accesses...
|
||||
|
@ -380,7 +378,7 @@ void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size);
|
|||
#define ioremap_wc ioremap_wc
|
||||
#define ioremap_wt ioremap_wc
|
||||
|
||||
void iounmap(volatile void __iomem *iomem_cookie);
|
||||
void iounmap(volatile void __iomem *io_addr);
|
||||
#define iounmap iounmap
|
||||
|
||||
void *arch_memremap_wb(phys_addr_t phys_addr, size_t size);
|
||||
|
|
|
@ -418,7 +418,7 @@ void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
|
|||
__builtin_return_address(0));
|
||||
}
|
||||
|
||||
void __iounmap(volatile void __iomem *io_addr)
|
||||
void iounmap(volatile void __iomem *io_addr)
|
||||
{
|
||||
void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);
|
||||
struct static_vm *svm;
|
||||
|
@ -446,13 +446,6 @@ void __iounmap(volatile void __iomem *io_addr)
|
|||
|
||||
vunmap(addr);
|
||||
}
|
||||
|
||||
void (*arch_iounmap)(volatile void __iomem *) = __iounmap;
|
||||
|
||||
void iounmap(volatile void __iomem *cookie)
|
||||
{
|
||||
arch_iounmap(cookie);
|
||||
}
|
||||
EXPORT_SYMBOL(iounmap);
|
||||
|
||||
#if defined(CONFIG_PCI) || IS_ENABLED(CONFIG_PCMCIA)
|
||||
|
|
|
@ -230,14 +230,7 @@ void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
|
|||
return (void *)phys_addr;
|
||||
}
|
||||
|
||||
void __iounmap(volatile void __iomem *addr)
|
||||
{
|
||||
}
|
||||
EXPORT_SYMBOL(__iounmap);
|
||||
|
||||
void (*arch_iounmap)(volatile void __iomem *);
|
||||
|
||||
void iounmap(volatile void __iomem *addr)
|
||||
void iounmap(volatile void __iomem *io_addr)
|
||||
{
|
||||
}
|
||||
EXPORT_SYMBOL(iounmap);
|
||||
|
|
|
@ -126,6 +126,7 @@ config ARM64
|
|||
select GENERIC_CPU_VULNERABILITIES
|
||||
select GENERIC_EARLY_IOREMAP
|
||||
select GENERIC_IDLE_POLL_SETUP
|
||||
select GENERIC_IOREMAP
|
||||
select GENERIC_IRQ_IPI
|
||||
select GENERIC_IRQ_PROBE
|
||||
select GENERIC_IRQ_SHOW
|
||||
|
@ -188,6 +189,7 @@ config ARM64
|
|||
select HAVE_FUNCTION_GRAPH_TRACER
|
||||
select HAVE_GCC_PLUGINS
|
||||
select HAVE_HW_BREAKPOINT if PERF_EVENTS
|
||||
select HAVE_IOREMAP_PROT
|
||||
select HAVE_IRQ_TIME_ACCOUNTING
|
||||
select HAVE_KVM
|
||||
select HAVE_NMI
|
||||
|
|
|
@ -163,13 +163,16 @@ extern void __memset_io(volatile void __iomem *, int, size_t);
|
|||
/*
|
||||
* I/O memory mapping functions.
|
||||
*/
|
||||
extern void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot);
|
||||
extern void iounmap(volatile void __iomem *addr);
|
||||
extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
|
||||
|
||||
#define ioremap(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
|
||||
#define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC))
|
||||
#define ioremap_np(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRnE))
|
||||
bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot);
|
||||
#define ioremap_allowed ioremap_allowed
|
||||
|
||||
#define _PAGE_IOREMAP PROT_DEVICE_nGnRE
|
||||
|
||||
#define ioremap_wc(addr, size) \
|
||||
ioremap_prot((addr), (size), PROT_NORMAL_NC)
|
||||
#define ioremap_np(addr, size) \
|
||||
ioremap_prot((addr), (size), PROT_DEVICE_nGnRnE)
|
||||
|
||||
/*
|
||||
* io{read,write}{16,32,64}be() macros
|
||||
|
@ -184,6 +187,15 @@ extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
|
|||
|
||||
#include <asm-generic/io.h>
|
||||
|
||||
#define ioremap_cache ioremap_cache
|
||||
static inline void __iomem *ioremap_cache(phys_addr_t addr, size_t size)
|
||||
{
|
||||
if (pfn_is_map_memory(__phys_to_pfn(addr)))
|
||||
return (void __iomem *)__phys_to_virt(addr);
|
||||
|
||||
return ioremap_prot(addr, size, PROT_NORMAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* More restrictive address range checking than the default implementation
|
||||
* (PHYS_OFFSET and PHYS_MASK taken into account).
|
||||
|
|
|
@ -427,6 +427,16 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
|
|||
return clear_pte_bit(pte, __pgprot(PTE_SWP_EXCLUSIVE));
|
||||
}
|
||||
|
||||
/*
|
||||
* Select all bits except the pfn
|
||||
*/
|
||||
static inline pgprot_t pte_pgprot(pte_t pte)
|
||||
{
|
||||
unsigned long pfn = pte_pfn(pte);
|
||||
|
||||
return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NUMA_BALANCING
|
||||
/*
|
||||
* See the comment in include/linux/pgtable.h
|
||||
|
|
|
@ -351,7 +351,7 @@ void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size)
|
|||
prot = __acpi_get_writethrough_mem_attribute();
|
||||
}
|
||||
}
|
||||
return __ioremap(phys, size, prot);
|
||||
return ioremap_prot(phys, size, pgprot_val(prot));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -100,16 +100,6 @@ int pud_huge(pud_t pud)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Select all bits except the pfn
|
||||
*/
|
||||
static inline pgprot_t pte_pgprot(pte_t pte)
|
||||
{
|
||||
unsigned long pfn = pte_pfn(pte);
|
||||
|
||||
return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
|
||||
}
|
||||
|
||||
static int find_num_contig(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep, size_t *pgsize)
|
||||
{
|
||||
|
|
|
@ -1,97 +1,23 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Based on arch/arm/mm/ioremap.c
|
||||
*
|
||||
* (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
|
||||
* Copyright (C) 2012 ARM Ltd.
|
||||
*/
|
||||
|
||||
#include <linux/export.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/io.h>
|
||||
|
||||
#include <asm/fixmap.h>
|
||||
#include <asm/tlbflush.h>
|
||||
|
||||
static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
|
||||
pgprot_t prot, void *caller)
|
||||
bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot)
|
||||
{
|
||||
unsigned long last_addr;
|
||||
unsigned long offset = phys_addr & ~PAGE_MASK;
|
||||
int err;
|
||||
unsigned long addr;
|
||||
struct vm_struct *area;
|
||||
unsigned long last_addr = phys_addr + size - 1;
|
||||
|
||||
/*
|
||||
* Page align the mapping address and size, taking account of any
|
||||
* offset.
|
||||
*/
|
||||
phys_addr &= PAGE_MASK;
|
||||
size = PAGE_ALIGN(size + offset);
|
||||
/* Don't allow outside PHYS_MASK */
|
||||
if (last_addr & ~PHYS_MASK)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Don't allow wraparound, zero size or outside PHYS_MASK.
|
||||
*/
|
||||
last_addr = phys_addr + size - 1;
|
||||
if (!size || last_addr < phys_addr || (last_addr & ~PHYS_MASK))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Don't allow RAM to be mapped.
|
||||
*/
|
||||
/* Don't allow RAM to be mapped. */
|
||||
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
area = get_vm_area_caller(size, VM_IOREMAP, caller);
|
||||
if (!area)
|
||||
return NULL;
|
||||
addr = (unsigned long)area->addr;
|
||||
area->phys_addr = phys_addr;
|
||||
|
||||
err = ioremap_page_range(addr, addr + size, phys_addr, prot);
|
||||
if (err) {
|
||||
vunmap((void *)addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void __iomem *)(offset + addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot)
|
||||
{
|
||||
return __ioremap_caller(phys_addr, size, prot,
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
EXPORT_SYMBOL(__ioremap);
|
||||
|
||||
void iounmap(volatile void __iomem *io_addr)
|
||||
{
|
||||
unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
|
||||
|
||||
/*
|
||||
* We could get an address outside vmalloc range in case
|
||||
* of ioremap_cache() reusing a RAM mapping.
|
||||
*/
|
||||
if (is_vmalloc_addr((void *)addr))
|
||||
vunmap((void *)addr);
|
||||
}
|
||||
EXPORT_SYMBOL(iounmap);
|
||||
|
||||
void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
|
||||
{
|
||||
/* For normal memory we already have a cacheable mapping. */
|
||||
if (pfn_is_map_memory(__phys_to_pfn(phys_addr)))
|
||||
return (void __iomem *)__phys_to_virt(phys_addr);
|
||||
|
||||
return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
EXPORT_SYMBOL(ioremap_cache);
|
||||
|
||||
/*
|
||||
* Must be called after early_fixmap_init
|
||||
*/
|
||||
|
|
|
@ -964,7 +964,34 @@ static inline void iounmap(volatile void __iomem *addr)
|
|||
#elif defined(CONFIG_GENERIC_IOREMAP)
|
||||
#include <linux/pgtable.h>
|
||||
|
||||
void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot);
|
||||
/*
|
||||
* Arch code can implement the following two hooks when using GENERIC_IOREMAP
|
||||
* ioremap_allowed() return a bool,
|
||||
* - true means continue to remap
|
||||
* - false means skip remap and return directly
|
||||
* iounmap_allowed() return a bool,
|
||||
* - true means continue to vunmap
|
||||
* - false means skip vunmap and return directly
|
||||
*/
|
||||
#ifndef ioremap_allowed
|
||||
#define ioremap_allowed ioremap_allowed
|
||||
static inline bool ioremap_allowed(phys_addr_t phys_addr, size_t size,
|
||||
unsigned long prot)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef iounmap_allowed
|
||||
#define iounmap_allowed iounmap_allowed
|
||||
static inline bool iounmap_allowed(void *addr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
|
||||
unsigned long prot);
|
||||
void iounmap(volatile void __iomem *addr);
|
||||
|
||||
static inline void __iomem *ioremap(phys_addr_t addr, size_t size)
|
||||
|
|
26
mm/ioremap.c
26
mm/ioremap.c
|
@ -11,29 +11,35 @@
|
|||
#include <linux/io.h>
|
||||
#include <linux/export.h>
|
||||
|
||||
void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot)
|
||||
void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
|
||||
unsigned long prot)
|
||||
{
|
||||
unsigned long offset, vaddr;
|
||||
phys_addr_t last_addr;
|
||||
struct vm_struct *area;
|
||||
|
||||
/* Disallow wrap-around or zero size */
|
||||
last_addr = addr + size - 1;
|
||||
if (!size || last_addr < addr)
|
||||
last_addr = phys_addr + size - 1;
|
||||
if (!size || last_addr < phys_addr)
|
||||
return NULL;
|
||||
|
||||
/* Page-align mappings */
|
||||
offset = addr & (~PAGE_MASK);
|
||||
addr -= offset;
|
||||
offset = phys_addr & (~PAGE_MASK);
|
||||
phys_addr -= offset;
|
||||
size = PAGE_ALIGN(size + offset);
|
||||
|
||||
if (!ioremap_allowed(phys_addr, size, prot))
|
||||
return NULL;
|
||||
|
||||
area = get_vm_area_caller(size, VM_IOREMAP,
|
||||
__builtin_return_address(0));
|
||||
if (!area)
|
||||
return NULL;
|
||||
vaddr = (unsigned long)area->addr;
|
||||
area->phys_addr = phys_addr;
|
||||
|
||||
if (ioremap_page_range(vaddr, vaddr + size, addr, __pgprot(prot))) {
|
||||
if (ioremap_page_range(vaddr, vaddr + size, phys_addr,
|
||||
__pgprot(prot))) {
|
||||
free_vm_area(area);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -44,6 +50,12 @@ EXPORT_SYMBOL(ioremap_prot);
|
|||
|
||||
void iounmap(volatile void __iomem *addr)
|
||||
{
|
||||
vunmap((void *)((unsigned long)addr & PAGE_MASK));
|
||||
void *vaddr = (void *)((unsigned long)addr & PAGE_MASK);
|
||||
|
||||
if (!iounmap_allowed(vaddr))
|
||||
return;
|
||||
|
||||
if (is_vmalloc_addr(vaddr))
|
||||
vunmap(vaddr);
|
||||
}
|
||||
EXPORT_SYMBOL(iounmap);
|
||||
|
|
Loading…
Reference in New Issue