mirror of
https://github.com/torvalds/linux.git
synced 2026-11-25 07:52:34 +00: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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Cain <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Greentime Hu <[email protected]>
Cc: Greg Ungerer <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Guo Ren <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Ley Foon Tan <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Nick Hu <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: Russell King <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Thomas Bogendoerfer <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Vincent Chen <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
181 lines
4.0 KiB
C
181 lines
4.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* memory.c: PROM library functions for acquiring/using memory descriptors
|
|
* given to us from the ARCS firmware.
|
|
*
|
|
* Copyright (C) 1996 by David S. Miller
|
|
* Copyright (C) 1999, 2000, 2001 by Ralf Baechle
|
|
* Copyright (C) 1999, 2000 by Silicon Graphics, Inc.
|
|
*
|
|
* PROM library functions for acquiring/using memory descriptors given to us
|
|
* from the ARCS firmware. This is only used when CONFIG_ARC_MEMORY is set
|
|
* because on some machines like SGI IP27 the ARC memory configuration data
|
|
* completely bogus and alternate easier to use mechanisms are available.
|
|
*/
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/memblock.h>
|
|
#include <linux/swap.h>
|
|
|
|
#include <asm/sgialib.h>
|
|
#include <asm/page.h>
|
|
#include <asm/bootinfo.h>
|
|
|
|
#undef DEBUG
|
|
|
|
#define MAX_PROM_MEM 5
|
|
static phys_addr_t prom_mem_base[MAX_PROM_MEM] __initdata;
|
|
static phys_addr_t prom_mem_size[MAX_PROM_MEM] __initdata;
|
|
static unsigned int nr_prom_mem __initdata;
|
|
|
|
/*
|
|
* For ARC firmware memory functions the unit of meassuring memory is always
|
|
* a 4k page of memory
|
|
*/
|
|
#define ARC_PAGE_SHIFT 12
|
|
|
|
struct linux_mdesc * __init ArcGetMemoryDescriptor(struct linux_mdesc *Current)
|
|
{
|
|
return (struct linux_mdesc *) ARC_CALL1(get_mdesc, Current);
|
|
}
|
|
|
|
#ifdef DEBUG /* convenient for debugging */
|
|
static char *arcs_mtypes[8] = {
|
|
"Exception Block",
|
|
"ARCS Romvec Page",
|
|
"Free/Contig RAM",
|
|
"Generic Free RAM",
|
|
"Bad Memory",
|
|
"Standalone Program Pages",
|
|
"ARCS Temp Storage Area",
|
|
"ARCS Permanent Storage Area"
|
|
};
|
|
|
|
static char *arc_mtypes[8] = {
|
|
"Exception Block",
|
|
"SystemParameterBlock",
|
|
"FreeMemory",
|
|
"Bad Memory",
|
|
"LoadedProgram",
|
|
"FirmwareTemporary",
|
|
"FirmwarePermanent",
|
|
"FreeContiguous"
|
|
};
|
|
#define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
|
|
: arc_mtypes[a.arc]
|
|
#endif
|
|
|
|
static inline int memtype_classify_arcs(union linux_memtypes type)
|
|
{
|
|
switch (type.arcs) {
|
|
case arcs_fcontig:
|
|
case arcs_free:
|
|
return BOOT_MEM_RAM;
|
|
case arcs_atmp:
|
|
return BOOT_MEM_ROM_DATA;
|
|
case arcs_eblock:
|
|
case arcs_rvpage:
|
|
case arcs_bmem:
|
|
case arcs_prog:
|
|
case arcs_aperm:
|
|
return BOOT_MEM_RESERVED;
|
|
default:
|
|
BUG();
|
|
}
|
|
while(1); /* Nuke warning. */
|
|
}
|
|
|
|
static inline int memtype_classify_arc(union linux_memtypes type)
|
|
{
|
|
switch (type.arc) {
|
|
case arc_free:
|
|
case arc_fcontig:
|
|
return BOOT_MEM_RAM;
|
|
case arc_atmp:
|
|
return BOOT_MEM_ROM_DATA;
|
|
case arc_eblock:
|
|
case arc_rvpage:
|
|
case arc_bmem:
|
|
case arc_prog:
|
|
case arc_aperm:
|
|
return BOOT_MEM_RESERVED;
|
|
default:
|
|
BUG();
|
|
}
|
|
while(1); /* Nuke warning. */
|
|
}
|
|
|
|
static int __init prom_memtype_classify(union linux_memtypes type)
|
|
{
|
|
if (prom_flags & PROM_FLAG_ARCS) /* SGI is ``different'' ... */
|
|
return memtype_classify_arcs(type);
|
|
|
|
return memtype_classify_arc(type);
|
|
}
|
|
|
|
void __weak __init prom_meminit(void)
|
|
{
|
|
struct linux_mdesc *p;
|
|
|
|
#ifdef DEBUG
|
|
int i = 0;
|
|
|
|
printk("ARCS MEMORY DESCRIPTOR dump:\n");
|
|
p = ArcGetMemoryDescriptor(PROM_NULL_MDESC);
|
|
while(p) {
|
|
printk("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
|
|
i, p, p->base, p->pages, mtypes(p->type));
|
|
p = ArcGetMemoryDescriptor(p);
|
|
i++;
|
|
}
|
|
#endif
|
|
|
|
nr_prom_mem = 0;
|
|
p = PROM_NULL_MDESC;
|
|
while ((p = ArcGetMemoryDescriptor(p))) {
|
|
unsigned long base, size;
|
|
long type;
|
|
|
|
base = p->base << ARC_PAGE_SHIFT;
|
|
size = p->pages << ARC_PAGE_SHIFT;
|
|
type = prom_memtype_classify(p->type);
|
|
|
|
add_memory_region(base, size, type);
|
|
|
|
if (type == BOOT_MEM_ROM_DATA) {
|
|
if (nr_prom_mem >= 5) {
|
|
pr_err("Too many ROM DATA regions");
|
|
continue;
|
|
}
|
|
prom_mem_base[nr_prom_mem] = base;
|
|
prom_mem_size[nr_prom_mem] = size;
|
|
nr_prom_mem++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void __weak __init prom_cleanup(void)
|
|
{
|
|
}
|
|
|
|
void __weak __init prom_free_prom_memory(void)
|
|
{
|
|
int i;
|
|
|
|
if (prom_flags & PROM_FLAG_DONT_FREE_TEMP)
|
|
return;
|
|
|
|
for (i = 0; i < nr_prom_mem; i++) {
|
|
free_init_pages("prom memory",
|
|
prom_mem_base[i], prom_mem_base[i] + prom_mem_size[i]);
|
|
}
|
|
/*
|
|
* at this point it isn't safe to call PROM functions
|
|
* give platforms a way to do PROM cleanups
|
|
*/
|
|
prom_cleanup();
|
|
}
|