mirror of
https://github.com/torvalds/linux.git
synced 2025-11-08 04:30:00 +02:00
Patch series "mm: consolidate definitions of page table accessors", v2.
The low level page table accessors (pXY_index(), pXY_offset()) are
duplicated across all architectures and sometimes more than once. For
instance, we have 31 definition of pgd_offset() for 25 supported
architectures.
Most of these definitions are actually identical and typically it boils
down to, e.g.
static inline unsigned long pmd_index(unsigned long address)
{
return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
}
static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
{
return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
}
These definitions can be shared among 90% of the arches provided
XYZ_SHIFT, PTRS_PER_XYZ and xyz_page_vaddr() are defined.
For architectures that really need a custom version there is always
possibility to override the generic version with the usual ifdefs magic.
These patches introduce include/linux/pgtable.h that replaces
include/asm-generic/pgtable.h and add the definitions of the page table
accessors to the new header.
This patch (of 12):
The linux/mm.h header includes <asm/pgtable.h> to allow inlining of the
functions involving page table manipulations, e.g. pte_alloc() and
pmd_alloc(). So, there is no point to explicitly include <asm/pgtable.h>
in the files that include <linux/mm.h>.
The include statements in such cases are remove with a simple loop:
for f in $(git grep -l "include <linux/mm.h>") ; do
sed -i -e '/include <asm\/pgtable.h>/ d' $f
done
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Cc: Mark Salter <msalter@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nick Hu <nickhu@andestech.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Rich Felker <dalias@libc.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vincent Chen <deanbo422@gmail.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Link: http://lkml.kernel.org/r/20200514170327.31389-1-rppt@kernel.org
Link: http://lkml.kernel.org/r/20200514170327.31389-2-rppt@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
194 lines
4.8 KiB
C
194 lines
4.8 KiB
C
/*
|
|
* arch/sh/mm/cache-sh7705.c
|
|
*
|
|
* Copyright (C) 1999, 2000 Niibe Yutaka
|
|
* Copyright (C) 2004 Alex Song
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/threads.h>
|
|
#include <asm/addrspace.h>
|
|
#include <asm/page.h>
|
|
#include <asm/processor.h>
|
|
#include <asm/cache.h>
|
|
#include <asm/io.h>
|
|
#include <linux/uaccess.h>
|
|
#include <asm/pgalloc.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/cacheflush.h>
|
|
|
|
/*
|
|
* The 32KB cache on the SH7705 suffers from the same synonym problem
|
|
* as SH4 CPUs
|
|
*/
|
|
static inline void cache_wback_all(void)
|
|
{
|
|
unsigned long ways, waysize, addrstart;
|
|
|
|
ways = current_cpu_data.dcache.ways;
|
|
waysize = current_cpu_data.dcache.sets;
|
|
waysize <<= current_cpu_data.dcache.entry_shift;
|
|
|
|
addrstart = CACHE_OC_ADDRESS_ARRAY;
|
|
|
|
do {
|
|
unsigned long addr;
|
|
|
|
for (addr = addrstart;
|
|
addr < addrstart + waysize;
|
|
addr += current_cpu_data.dcache.linesz) {
|
|
unsigned long data;
|
|
int v = SH_CACHE_UPDATED | SH_CACHE_VALID;
|
|
|
|
data = __raw_readl(addr);
|
|
|
|
if ((data & v) == v)
|
|
__raw_writel(data & ~v, addr);
|
|
|
|
}
|
|
|
|
addrstart += current_cpu_data.dcache.way_incr;
|
|
} while (--ways);
|
|
}
|
|
|
|
/*
|
|
* Write back the range of D-cache, and purge the I-cache.
|
|
*
|
|
* Called from kernel/module.c:sys_init_module and routine for a.out format.
|
|
*/
|
|
static void sh7705_flush_icache_range(void *args)
|
|
{
|
|
struct flusher_data *data = args;
|
|
unsigned long start, end;
|
|
|
|
start = data->addr1;
|
|
end = data->addr2;
|
|
|
|
__flush_wback_region((void *)start, end - start);
|
|
}
|
|
|
|
/*
|
|
* Writeback&Invalidate the D-cache of the page
|
|
*/
|
|
static void __flush_dcache_page(unsigned long phys)
|
|
{
|
|
unsigned long ways, waysize, addrstart;
|
|
unsigned long flags;
|
|
|
|
phys |= SH_CACHE_VALID;
|
|
|
|
/*
|
|
* Here, phys is the physical address of the page. We check all the
|
|
* tags in the cache for those with the same page number as this page
|
|
* (by masking off the lowest 2 bits of the 19-bit tag; these bits are
|
|
* derived from the offset within in the 4k page). Matching valid
|
|
* entries are invalidated.
|
|
*
|
|
* Since 2 bits of the cache index are derived from the virtual page
|
|
* number, knowing this would reduce the number of cache entries to be
|
|
* searched by a factor of 4. However this function exists to deal with
|
|
* potential cache aliasing, therefore the optimisation is probably not
|
|
* possible.
|
|
*/
|
|
local_irq_save(flags);
|
|
jump_to_uncached();
|
|
|
|
ways = current_cpu_data.dcache.ways;
|
|
waysize = current_cpu_data.dcache.sets;
|
|
waysize <<= current_cpu_data.dcache.entry_shift;
|
|
|
|
addrstart = CACHE_OC_ADDRESS_ARRAY;
|
|
|
|
do {
|
|
unsigned long addr;
|
|
|
|
for (addr = addrstart;
|
|
addr < addrstart + waysize;
|
|
addr += current_cpu_data.dcache.linesz) {
|
|
unsigned long data;
|
|
|
|
data = __raw_readl(addr) & (0x1ffffC00 | SH_CACHE_VALID);
|
|
if (data == phys) {
|
|
data &= ~(SH_CACHE_VALID | SH_CACHE_UPDATED);
|
|
__raw_writel(data, addr);
|
|
}
|
|
}
|
|
|
|
addrstart += current_cpu_data.dcache.way_incr;
|
|
} while (--ways);
|
|
|
|
back_to_cached();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Write back & invalidate the D-cache of the page.
|
|
* (To avoid "alias" issues)
|
|
*/
|
|
static void sh7705_flush_dcache_page(void *arg)
|
|
{
|
|
struct page *page = arg;
|
|
struct address_space *mapping = page_mapping_file(page);
|
|
|
|
if (mapping && !mapping_mapped(mapping))
|
|
clear_bit(PG_dcache_clean, &page->flags);
|
|
else
|
|
__flush_dcache_page(__pa(page_address(page)));
|
|
}
|
|
|
|
static void sh7705_flush_cache_all(void *args)
|
|
{
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
jump_to_uncached();
|
|
|
|
cache_wback_all();
|
|
back_to_cached();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Write back and invalidate I/D-caches for the page.
|
|
*
|
|
* ADDRESS: Virtual Address (U0 address)
|
|
*/
|
|
static void sh7705_flush_cache_page(void *args)
|
|
{
|
|
struct flusher_data *data = args;
|
|
unsigned long pfn = data->addr2;
|
|
|
|
__flush_dcache_page(pfn << PAGE_SHIFT);
|
|
}
|
|
|
|
/*
|
|
* This is called when a page-cache page is about to be mapped into a
|
|
* user process' address space. It offers an opportunity for a
|
|
* port to ensure d-cache/i-cache coherency if necessary.
|
|
*
|
|
* Not entirely sure why this is necessary on SH3 with 32K cache but
|
|
* without it we get occasional "Memory fault" when loading a program.
|
|
*/
|
|
static void sh7705_flush_icache_page(void *page)
|
|
{
|
|
__flush_purge_region(page_address(page), PAGE_SIZE);
|
|
}
|
|
|
|
void __init sh7705_cache_init(void)
|
|
{
|
|
local_flush_icache_range = sh7705_flush_icache_range;
|
|
local_flush_dcache_page = sh7705_flush_dcache_page;
|
|
local_flush_cache_all = sh7705_flush_cache_all;
|
|
local_flush_cache_mm = sh7705_flush_cache_all;
|
|
local_flush_cache_dup_mm = sh7705_flush_cache_all;
|
|
local_flush_cache_range = sh7705_flush_cache_all;
|
|
local_flush_cache_page = sh7705_flush_cache_page;
|
|
local_flush_icache_page = sh7705_flush_icache_page;
|
|
}
|