mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-14 22:44:27 +08:00
e31cf2f4ca
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>
203 lines
4.9 KiB
C
203 lines
4.9 KiB
C
/*
|
|
* Functions for ST-RAM allocations
|
|
*
|
|
* Copyright 1994-97 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
|
*
|
|
* 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/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/kdev_t.h>
|
|
#include <linux/major.h>
|
|
#include <linux/init.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/memblock.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/module.h>
|
|
#include <linux/ioport.h>
|
|
|
|
#include <asm/setup.h>
|
|
#include <asm/machdep.h>
|
|
#include <asm/page.h>
|
|
#include <asm/atarihw.h>
|
|
#include <asm/atari_stram.h>
|
|
#include <asm/io.h>
|
|
|
|
|
|
/*
|
|
* The ST-RAM allocator allocates memory from a pool of reserved ST-RAM of
|
|
* configurable size, set aside on ST-RAM init.
|
|
* As long as this pool is not exhausted, allocation of real ST-RAM can be
|
|
* guaranteed.
|
|
*/
|
|
|
|
/* set if kernel is in ST-RAM */
|
|
static int kernel_in_stram;
|
|
|
|
static struct resource stram_pool = {
|
|
.name = "ST-RAM Pool"
|
|
};
|
|
|
|
static unsigned long pool_size = 1024*1024;
|
|
|
|
static unsigned long stram_virt_offset;
|
|
|
|
static int __init atari_stram_setup(char *arg)
|
|
{
|
|
if (!MACH_IS_ATARI)
|
|
return 0;
|
|
|
|
pool_size = memparse(arg, NULL);
|
|
return 0;
|
|
}
|
|
|
|
early_param("stram_pool", atari_stram_setup);
|
|
|
|
|
|
/*
|
|
* This init function is called very early by atari/config.c
|
|
* It initializes some internal variables needed for stram_alloc()
|
|
*/
|
|
void __init atari_stram_init(void)
|
|
{
|
|
int i;
|
|
|
|
/*
|
|
* determine whether kernel code resides in ST-RAM
|
|
* (then ST-RAM is the first memory block at virtual 0x0)
|
|
*/
|
|
kernel_in_stram = (m68k_memory[0].addr == 0);
|
|
|
|
for (i = 0; i < m68k_num_memory; ++i) {
|
|
if (m68k_memory[i].addr == 0) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
/* Should never come here! (There is always ST-Ram!) */
|
|
panic("atari_stram_init: no ST-RAM found!");
|
|
}
|
|
|
|
|
|
/*
|
|
* This function is called from setup_arch() to reserve the pages needed for
|
|
* ST-RAM management, if the kernel resides in ST-RAM.
|
|
*/
|
|
void __init atari_stram_reserve_pages(void *start_mem)
|
|
{
|
|
if (kernel_in_stram) {
|
|
pr_debug("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
|
|
stram_pool.start = (resource_size_t)memblock_alloc_low(pool_size,
|
|
PAGE_SIZE);
|
|
if (!stram_pool.start)
|
|
panic("%s: Failed to allocate %lu bytes align=%lx\n",
|
|
__func__, pool_size, PAGE_SIZE);
|
|
|
|
stram_pool.end = stram_pool.start + pool_size - 1;
|
|
request_resource(&iomem_resource, &stram_pool);
|
|
stram_virt_offset = 0;
|
|
pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
|
|
pool_size, &stram_pool);
|
|
pr_debug("atari_stram pool: stram_virt_offset = %lx\n",
|
|
stram_virt_offset);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* This function is called as arch initcall to reserve the pages needed for
|
|
* ST-RAM management, if the kernel does not reside in ST-RAM.
|
|
*/
|
|
int __init atari_stram_map_pages(void)
|
|
{
|
|
if (!kernel_in_stram) {
|
|
/*
|
|
* Skip page 0, as the fhe first 2 KiB are supervisor-only!
|
|
*/
|
|
pr_debug("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
|
|
stram_pool.start = PAGE_SIZE;
|
|
stram_pool.end = stram_pool.start + pool_size - 1;
|
|
request_resource(&iomem_resource, &stram_pool);
|
|
stram_virt_offset = (unsigned long) ioremap(stram_pool.start,
|
|
resource_size(&stram_pool)) - stram_pool.start;
|
|
pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
|
|
pool_size, &stram_pool);
|
|
pr_debug("atari_stram pool: stram_virt_offset = %lx\n",
|
|
stram_virt_offset);
|
|
}
|
|
return 0;
|
|
}
|
|
arch_initcall(atari_stram_map_pages);
|
|
|
|
|
|
void *atari_stram_to_virt(unsigned long phys)
|
|
{
|
|
return (void *)(phys + stram_virt_offset);
|
|
}
|
|
EXPORT_SYMBOL(atari_stram_to_virt);
|
|
|
|
|
|
unsigned long atari_stram_to_phys(void *virt)
|
|
{
|
|
return (unsigned long)(virt - stram_virt_offset);
|
|
}
|
|
EXPORT_SYMBOL(atari_stram_to_phys);
|
|
|
|
|
|
void *atari_stram_alloc(unsigned long size, const char *owner)
|
|
{
|
|
struct resource *res;
|
|
int error;
|
|
|
|
pr_debug("atari_stram_alloc: allocate %lu bytes\n", size);
|
|
|
|
/* round up */
|
|
size = PAGE_ALIGN(size);
|
|
|
|
res = kzalloc(sizeof(struct resource), GFP_KERNEL);
|
|
if (!res)
|
|
return NULL;
|
|
|
|
res->name = owner;
|
|
error = allocate_resource(&stram_pool, res, size, 0, UINT_MAX,
|
|
PAGE_SIZE, NULL, NULL);
|
|
if (error < 0) {
|
|
pr_err("atari_stram_alloc: allocate_resource() failed %d!\n",
|
|
error);
|
|
kfree(res);
|
|
return NULL;
|
|
}
|
|
|
|
pr_debug("atari_stram_alloc: returning %pR\n", res);
|
|
return atari_stram_to_virt(res->start);
|
|
}
|
|
EXPORT_SYMBOL(atari_stram_alloc);
|
|
|
|
|
|
void atari_stram_free(void *addr)
|
|
{
|
|
unsigned long start = atari_stram_to_phys(addr);
|
|
struct resource *res;
|
|
unsigned long size;
|
|
|
|
res = lookup_resource(&stram_pool, start);
|
|
if (!res) {
|
|
pr_err("atari_stram_free: trying to free nonexistent region "
|
|
"at %p\n", addr);
|
|
return;
|
|
}
|
|
|
|
size = resource_size(res);
|
|
pr_debug("atari_stram_free: free %lu bytes at %p\n", size, addr);
|
|
release_resource(res);
|
|
kfree(res);
|
|
}
|
|
EXPORT_SYMBOL(atari_stram_free);
|