License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/parisc/mm/init.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
* Copyright 1999 SuSE GmbH
|
|
|
|
* changed by Philipp Rumpf
|
|
|
|
* Copyright 1999 Philipp Rumpf (prumpf@tux.org)
|
|
|
|
* Copyright 2004 Randolph Chung (tausq@debian.org)
|
2007-01-28 21:58:52 +08:00
|
|
|
* Copyright 2006-2007 Helge Deller (deller@gmx.de)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bootmem.h>
|
2016-10-07 22:50:21 +08:00
|
|
|
#include <linux/memblock.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/initrd.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/nodemask.h> /* for node_online_map */
|
2016-04-01 20:29:48 +08:00
|
|
|
#include <linux/pagemap.h> /* for release_pages */
|
2015-11-07 06:36:01 +08:00
|
|
|
#include <linux/compat.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/pgalloc.h>
|
2006-10-15 04:10:44 +08:00
|
|
|
#include <asm/pgtable.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/tlb.h>
|
|
|
|
#include <asm/pdc_chassis.h>
|
|
|
|
#include <asm/mmzone.h>
|
2006-07-01 19:36:30 +08:00
|
|
|
#include <asm/sections.h>
|
2015-11-07 06:36:01 +08:00
|
|
|
#include <asm/msgbuf.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
extern int data_start;
|
2013-12-01 05:07:51 +08:00
|
|
|
extern void parisc_kernel_start(void); /* Kernel entry point in head.S */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-04-15 06:45:54 +08:00
|
|
|
#if CONFIG_PGTABLE_LEVELS == 3
|
2012-05-03 17:02:57 +08:00
|
|
|
/* NOTE: This layout exactly conforms to the hybrid L2/L3 page table layout
|
|
|
|
* with the first pmd adjacent to the pgd and below it. gcc doesn't actually
|
|
|
|
* guarantee that global objects will be laid out in memory in the same order
|
|
|
|
* as the order of declaration, so put these in different sections and use
|
|
|
|
* the linker script to order them. */
|
|
|
|
pmd_t pmd0[PTRS_PER_PMD] __attribute__ ((__section__ (".data..vm0.pmd"), aligned(PAGE_SIZE)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__ ((__section__ (".data..vm0.pgd"), aligned(PAGE_SIZE)));
|
|
|
|
pte_t pg0[PT_INITIAL * PTRS_PER_PTE] __attribute__ ((__section__ (".data..vm0.pte"), aligned(PAGE_SIZE)));
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_DISCONTIGMEM
|
2006-01-11 09:35:03 +08:00
|
|
|
struct node_map_data node_data[MAX_NUMNODES] __read_mostly;
|
2013-06-06 04:50:01 +08:00
|
|
|
signed char pfnnid_map[PFNNID_MAP_MAX] __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct resource data_resource = {
|
|
|
|
.name = "Kernel data",
|
2016-01-27 04:57:22 +08:00
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource code_resource = {
|
|
|
|
.name = "Kernel code",
|
2016-01-27 04:57:22 +08:00
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource pdcdata_resource = {
|
|
|
|
.name = "PDC data (Page Zero)",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0x9ff,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_MEM,
|
|
|
|
};
|
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
static struct resource sysram_resources[MAX_PHYSMEM_RANGES] __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* The following array is initialized from the firmware specific
|
|
|
|
* information retrieved in kernel/inventory.c.
|
|
|
|
*/
|
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
physmem_range_t pmem_ranges[MAX_PHYSMEM_RANGES] __read_mostly;
|
|
|
|
int npmem_ranges __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
/*
|
|
|
|
* get_memblock() allocates pages via memblock.
|
|
|
|
* We can't use memblock_find_in_range(0, KERNEL_INITIAL_SIZE) here since it
|
|
|
|
* doesn't allocate from bottom to top which is needed because we only created
|
|
|
|
* the initial mapping up to KERNEL_INITIAL_SIZE in the assembly bootup code.
|
|
|
|
*/
|
|
|
|
static void * __init get_memblock(unsigned long size)
|
|
|
|
{
|
|
|
|
static phys_addr_t search_addr __initdata;
|
|
|
|
phys_addr_t phys;
|
|
|
|
|
|
|
|
if (!search_addr)
|
|
|
|
search_addr = PAGE_ALIGN(__pa((unsigned long) &_end));
|
|
|
|
search_addr = ALIGN(search_addr, size);
|
|
|
|
while (!memblock_is_region_memory(search_addr, size) ||
|
|
|
|
memblock_is_region_reserved(search_addr, size)) {
|
|
|
|
search_addr += size;
|
|
|
|
}
|
|
|
|
phys = search_addr;
|
|
|
|
|
|
|
|
if (phys)
|
|
|
|
memblock_reserve(phys, size);
|
|
|
|
else
|
|
|
|
panic("get_memblock() failed.\n");
|
|
|
|
|
2016-10-12 02:40:02 +08:00
|
|
|
memset(__va(phys), 0, size);
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
return __va(phys);
|
|
|
|
}
|
|
|
|
|
2007-01-28 21:58:52 +08:00
|
|
|
#ifdef CONFIG_64BIT
|
2005-04-17 06:20:36 +08:00
|
|
|
#define MAX_MEM (~0UL)
|
2007-01-28 21:58:52 +08:00
|
|
|
#else /* !CONFIG_64BIT */
|
2005-04-17 06:20:36 +08:00
|
|
|
#define MAX_MEM (3584U*1024U*1024U)
|
2007-01-28 21:58:52 +08:00
|
|
|
#endif /* !CONFIG_64BIT */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
static unsigned long mem_limit __read_mostly = MAX_MEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void __init mem_limit_func(void)
|
|
|
|
{
|
|
|
|
char *cp, *end;
|
|
|
|
unsigned long limit;
|
|
|
|
|
|
|
|
/* We need this before __setup() functions are called */
|
|
|
|
|
|
|
|
limit = MAX_MEM;
|
2007-02-12 16:54:16 +08:00
|
|
|
for (cp = boot_command_line; *cp; ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (memcmp(cp, "mem=", 4) == 0) {
|
|
|
|
cp += 4;
|
|
|
|
limit = memparse(cp, &end);
|
|
|
|
if (end != cp)
|
|
|
|
break;
|
|
|
|
cp = end;
|
|
|
|
} else {
|
|
|
|
while (*cp != ' ' && *cp)
|
|
|
|
++cp;
|
|
|
|
while (*cp == ' ')
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (limit < mem_limit)
|
|
|
|
mem_limit = limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_GAP (0x40000000UL >> PAGE_SHIFT)
|
|
|
|
|
|
|
|
static void __init setup_bootmem(void)
|
|
|
|
{
|
|
|
|
unsigned long mem_max;
|
|
|
|
#ifndef CONFIG_DISCONTIGMEM
|
|
|
|
physmem_range_t pmem_holes[MAX_PHYSMEM_RANGES - 1];
|
|
|
|
int npmem_holes;
|
|
|
|
#endif
|
|
|
|
int i, sysram_resource_count;
|
|
|
|
|
|
|
|
disable_sr_hashing(); /* Turn off space register hashing */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the ranges. Since the number of ranges is typically
|
|
|
|
* small, and performance is not an issue here, just do
|
|
|
|
* a simple insertion sort.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 1; i < npmem_ranges; i++) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = i; j > 0; j--) {
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
if (pmem_ranges[j-1].start_pfn <
|
|
|
|
pmem_ranges[j].start_pfn) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = pmem_ranges[j-1].start_pfn;
|
|
|
|
pmem_ranges[j-1].start_pfn = pmem_ranges[j].start_pfn;
|
|
|
|
pmem_ranges[j].start_pfn = tmp;
|
|
|
|
tmp = pmem_ranges[j-1].pages;
|
|
|
|
pmem_ranges[j-1].pages = pmem_ranges[j].pages;
|
|
|
|
pmem_ranges[j].pages = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISCONTIGMEM
|
|
|
|
/*
|
|
|
|
* Throw out ranges that are too far apart (controlled by
|
|
|
|
* MAX_GAP).
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 1; i < npmem_ranges; i++) {
|
|
|
|
if (pmem_ranges[i].start_pfn -
|
|
|
|
(pmem_ranges[i-1].start_pfn +
|
|
|
|
pmem_ranges[i-1].pages) > MAX_GAP) {
|
|
|
|
npmem_ranges = i;
|
|
|
|
printk("Large gap in memory detected (%ld pages). "
|
|
|
|
"Consider turning on CONFIG_DISCONTIGMEM\n",
|
|
|
|
pmem_ranges[i].start_pfn -
|
|
|
|
(pmem_ranges[i-1].start_pfn +
|
|
|
|
pmem_ranges[i-1].pages));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
/* Print the memory ranges */
|
|
|
|
pr_info("Memory Ranges:\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
for (i = 0; i < npmem_ranges; i++) {
|
|
|
|
struct resource *res = &sysram_resources[i];
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
size = (pmem_ranges[i].pages << PAGE_SHIFT);
|
|
|
|
start = (pmem_ranges[i].start_pfn << PAGE_SHIFT);
|
|
|
|
pr_info("%2d) Start 0x%016lx End 0x%016lx Size %6ld MB\n",
|
|
|
|
i, start, start + (size - 1), size >> 20);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
/* request memory resource */
|
2005-04-17 06:20:36 +08:00
|
|
|
res->name = "System RAM";
|
2016-10-07 22:50:21 +08:00
|
|
|
res->start = start;
|
|
|
|
res->end = start + size - 1;
|
2016-01-27 04:57:22 +08:00
|
|
|
res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
|
2005-04-17 06:20:36 +08:00
|
|
|
request_resource(&iomem_resource, res);
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
sysram_resource_count = npmem_ranges;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* For 32 bit kernels we limit the amount of memory we can
|
|
|
|
* support, in order to preserve enough kernel address space
|
|
|
|
* for other purposes. For 64 bit kernels we don't normally
|
|
|
|
* limit the memory, but this mechanism can be used to
|
|
|
|
* artificially limit the amount of memory (and it is written
|
|
|
|
* to work with multiple memory ranges).
|
|
|
|
*/
|
|
|
|
|
|
|
|
mem_limit_func(); /* check for "mem=" argument */
|
|
|
|
|
|
|
|
mem_max = 0;
|
|
|
|
for (i = 0; i < npmem_ranges; i++) {
|
|
|
|
unsigned long rsize;
|
|
|
|
|
|
|
|
rsize = pmem_ranges[i].pages << PAGE_SHIFT;
|
|
|
|
if ((mem_max + rsize) > mem_limit) {
|
|
|
|
printk(KERN_WARNING "Memory truncated to %ld MB\n", mem_limit >> 20);
|
|
|
|
if (mem_max == mem_limit)
|
|
|
|
npmem_ranges = i;
|
|
|
|
else {
|
|
|
|
pmem_ranges[i].pages = (mem_limit >> PAGE_SHIFT)
|
|
|
|
- (mem_max >> PAGE_SHIFT);
|
|
|
|
npmem_ranges = i + 1;
|
|
|
|
mem_max = mem_limit;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mem_max += rsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "Total Memory: %ld MB\n",mem_max >> 20);
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISCONTIGMEM
|
|
|
|
/* Merge the ranges, keeping track of the holes */
|
|
|
|
|
|
|
|
{
|
|
|
|
unsigned long end_pfn;
|
|
|
|
unsigned long hole_pages;
|
|
|
|
|
|
|
|
npmem_holes = 0;
|
|
|
|
end_pfn = pmem_ranges[0].start_pfn + pmem_ranges[0].pages;
|
|
|
|
for (i = 1; i < npmem_ranges; i++) {
|
|
|
|
|
|
|
|
hole_pages = pmem_ranges[i].start_pfn - end_pfn;
|
|
|
|
if (hole_pages) {
|
|
|
|
pmem_holes[npmem_holes].start_pfn = end_pfn;
|
|
|
|
pmem_holes[npmem_holes++].pages = hole_pages;
|
|
|
|
end_pfn += hole_pages;
|
|
|
|
}
|
|
|
|
end_pfn += pmem_ranges[i].pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
pmem_ranges[0].pages = end_pfn - pmem_ranges[0].start_pfn;
|
|
|
|
npmem_ranges = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISCONTIGMEM
|
|
|
|
for (i = 0; i < MAX_PHYSMEM_RANGES; i++) {
|
|
|
|
memset(NODE_DATA(i), 0, sizeof(pg_data_t));
|
|
|
|
}
|
|
|
|
memset(pfnnid_map, 0xff, sizeof(pfnnid_map));
|
|
|
|
|
2011-04-21 10:27:13 +08:00
|
|
|
for (i = 0; i < npmem_ranges; i++) {
|
|
|
|
node_set_state(i, N_NORMAL_MEMORY);
|
2005-04-17 06:20:36 +08:00
|
|
|
node_set_online(i);
|
2011-04-21 10:27:13 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and free the full range of memory in each range.
|
|
|
|
*/
|
|
|
|
|
|
|
|
max_pfn = 0;
|
|
|
|
for (i = 0; i < npmem_ranges; i++) {
|
|
|
|
unsigned long start_pfn;
|
|
|
|
unsigned long npages;
|
2016-10-07 22:50:21 +08:00
|
|
|
unsigned long start;
|
|
|
|
unsigned long size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
start_pfn = pmem_ranges[i].start_pfn;
|
|
|
|
npages = pmem_ranges[i].pages;
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
start = start_pfn << PAGE_SHIFT;
|
|
|
|
size = npages << PAGE_SHIFT;
|
|
|
|
|
|
|
|
/* add system RAM memblock */
|
|
|
|
memblock_add(start, size);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((start_pfn + npages) > max_pfn)
|
|
|
|
max_pfn = start_pfn + npages;
|
|
|
|
}
|
|
|
|
|
2006-01-11 09:47:57 +08:00
|
|
|
/* IOMMU is always used to access "high mem" on those boxes
|
|
|
|
* that can support enough mem that a PCI device couldn't
|
|
|
|
* directly DMA to any physical addresses.
|
|
|
|
* ISA DMA support will need to revisit this.
|
|
|
|
*/
|
|
|
|
max_low_pfn = max_pfn;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* reserve PAGE0 pdc memory, kernel text/data/bss & bootmap */
|
|
|
|
|
|
|
|
#define PDC_CONSOLE_IO_IODC_SIZE 32768
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
memblock_reserve(0UL, (unsigned long)(PAGE0->mem_free +
|
|
|
|
PDC_CONSOLE_IO_IODC_SIZE));
|
|
|
|
memblock_reserve(__pa(KERNEL_BINARY_TEXT_START),
|
|
|
|
(unsigned long)(_end - KERNEL_BINARY_TEXT_START));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifndef CONFIG_DISCONTIGMEM
|
|
|
|
|
|
|
|
/* reserve the holes */
|
|
|
|
|
|
|
|
for (i = 0; i < npmem_holes; i++) {
|
2016-10-07 22:50:21 +08:00
|
|
|
memblock_reserve((pmem_holes[i].start_pfn << PAGE_SHIFT),
|
|
|
|
(pmem_holes[i].pages << PAGE_SHIFT));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
if (initrd_start) {
|
|
|
|
printk(KERN_INFO "initrd: %08lx-%08lx\n", initrd_start, initrd_end);
|
|
|
|
if (__pa(initrd_start) < mem_max) {
|
|
|
|
unsigned long initrd_reserve;
|
|
|
|
|
|
|
|
if (__pa(initrd_end) > mem_max) {
|
|
|
|
initrd_reserve = mem_max - __pa(initrd_start);
|
|
|
|
} else {
|
|
|
|
initrd_reserve = initrd_end - initrd_start;
|
|
|
|
}
|
|
|
|
initrd_below_start_ok = 1;
|
|
|
|
printk(KERN_INFO "initrd: reserving %08lx-%08lx (mem_max %08lx)\n", __pa(initrd_start), __pa(initrd_start) + initrd_reserve, mem_max);
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
memblock_reserve(__pa(initrd_start), initrd_reserve);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
data_resource.start = virt_to_phys(&data_start);
|
2006-08-14 08:39:48 +08:00
|
|
|
data_resource.end = virt_to_phys(_end) - 1;
|
|
|
|
code_resource.start = virt_to_phys(_text);
|
2005-04-17 06:20:36 +08:00
|
|
|
code_resource.end = virt_to_phys(&data_start)-1;
|
|
|
|
|
|
|
|
/* We don't know which region the kernel will be in, so try
|
|
|
|
* all of them.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sysram_resource_count; i++) {
|
|
|
|
struct resource *res = &sysram_resources[i];
|
|
|
|
request_resource(res, &code_resource);
|
|
|
|
request_resource(res, &data_resource);
|
|
|
|
}
|
|
|
|
request_resource(&sysram_resources[0], &pdcdata_resource);
|
2017-05-12 04:24:15 +08:00
|
|
|
|
|
|
|
/* Initialize Page Deallocation Table (PDT) and check for bad memory. */
|
|
|
|
pdc_pdt_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-01 05:07:51 +08:00
|
|
|
static int __init parisc_text_address(unsigned long vaddr)
|
|
|
|
{
|
|
|
|
static unsigned long head_ptr __initdata;
|
|
|
|
|
|
|
|
if (!head_ptr)
|
|
|
|
head_ptr = PAGE_MASK & (unsigned long)
|
|
|
|
dereference_function_descriptor(&parisc_kernel_start);
|
|
|
|
|
|
|
|
return core_kernel_text(vaddr) || vaddr == head_ptr;
|
|
|
|
}
|
|
|
|
|
2011-04-15 07:25:21 +08:00
|
|
|
static void __init map_pages(unsigned long start_vaddr,
|
|
|
|
unsigned long start_paddr, unsigned long size,
|
|
|
|
pgprot_t pgprot, int force)
|
|
|
|
{
|
|
|
|
pgd_t *pg_dir;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pg_table;
|
|
|
|
unsigned long end_paddr;
|
|
|
|
unsigned long start_pmd;
|
|
|
|
unsigned long start_pte;
|
|
|
|
unsigned long tmp1;
|
|
|
|
unsigned long tmp2;
|
|
|
|
unsigned long address;
|
|
|
|
unsigned long vaddr;
|
|
|
|
unsigned long ro_start;
|
|
|
|
unsigned long ro_end;
|
2015-11-22 07:07:44 +08:00
|
|
|
unsigned long kernel_end;
|
2011-04-15 07:25:21 +08:00
|
|
|
|
|
|
|
ro_start = __pa((unsigned long)_text);
|
|
|
|
ro_end = __pa((unsigned long)&data_start);
|
2015-11-22 07:07:44 +08:00
|
|
|
kernel_end = __pa((unsigned long)&_end);
|
2011-04-15 07:25:21 +08:00
|
|
|
|
|
|
|
end_paddr = start_paddr + size;
|
|
|
|
|
|
|
|
pg_dir = pgd_offset_k(start_vaddr);
|
|
|
|
|
|
|
|
#if PTRS_PER_PMD == 1
|
|
|
|
start_pmd = 0;
|
|
|
|
#else
|
|
|
|
start_pmd = ((start_vaddr >> PMD_SHIFT) & (PTRS_PER_PMD - 1));
|
|
|
|
#endif
|
|
|
|
start_pte = ((start_vaddr >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
|
|
|
|
|
|
|
|
address = start_paddr;
|
|
|
|
vaddr = start_vaddr;
|
|
|
|
while (address < end_paddr) {
|
|
|
|
#if PTRS_PER_PMD == 1
|
|
|
|
pmd = (pmd_t *)__pa(pg_dir);
|
|
|
|
#else
|
|
|
|
pmd = (pmd_t *)pgd_address(*pg_dir);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pmd is physical at this point
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!pmd) {
|
2016-10-07 22:50:21 +08:00
|
|
|
pmd = (pmd_t *) get_memblock(PAGE_SIZE << PMD_ORDER);
|
2011-04-15 07:25:21 +08:00
|
|
|
pmd = (pmd_t *) __pa(pmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
pgd_populate(NULL, pg_dir, __va(pmd));
|
|
|
|
#endif
|
|
|
|
pg_dir++;
|
|
|
|
|
|
|
|
/* now change pmd to kernel virtual addresses */
|
|
|
|
|
|
|
|
pmd = (pmd_t *)__va(pmd) + start_pmd;
|
|
|
|
for (tmp1 = start_pmd; tmp1 < PTRS_PER_PMD; tmp1++, pmd++) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pg_table is physical at this point
|
|
|
|
*/
|
|
|
|
|
|
|
|
pg_table = (pte_t *)pmd_address(*pmd);
|
|
|
|
if (!pg_table) {
|
2016-10-07 22:50:21 +08:00
|
|
|
pg_table = (pte_t *) get_memblock(PAGE_SIZE);
|
2011-04-15 07:25:21 +08:00
|
|
|
pg_table = (pte_t *) __pa(pg_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
pmd_populate_kernel(NULL, pmd, __va(pg_table));
|
|
|
|
|
|
|
|
/* now change pg_table to kernel virtual addresses */
|
|
|
|
|
|
|
|
pg_table = (pte_t *) __va(pg_table) + start_pte;
|
|
|
|
for (tmp2 = start_pte; tmp2 < PTRS_PER_PTE; tmp2++, pg_table++) {
|
|
|
|
pte_t pte;
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
pte = __mk_pte(address, pgprot);
|
2015-11-22 07:07:44 +08:00
|
|
|
else if (parisc_text_address(vaddr)) {
|
2011-04-15 07:25:21 +08:00
|
|
|
pte = __mk_pte(address, PAGE_KERNEL_EXEC);
|
2015-11-22 07:07:44 +08:00
|
|
|
if (address >= ro_start && address < kernel_end)
|
|
|
|
pte = pte_mkhuge(pte);
|
|
|
|
}
|
2011-04-15 07:25:21 +08:00
|
|
|
else
|
|
|
|
#if defined(CONFIG_PARISC_PAGE_SIZE_4KB)
|
2015-11-22 07:07:44 +08:00
|
|
|
if (address >= ro_start && address < ro_end) {
|
|
|
|
pte = __mk_pte(address, PAGE_KERNEL_EXEC);
|
|
|
|
pte = pte_mkhuge(pte);
|
|
|
|
} else
|
2011-04-15 07:25:21 +08:00
|
|
|
#endif
|
2015-11-22 07:07:44 +08:00
|
|
|
{
|
2011-04-15 07:25:21 +08:00
|
|
|
pte = __mk_pte(address, pgprot);
|
2015-11-22 07:07:44 +08:00
|
|
|
if (address >= ro_start && address < kernel_end)
|
|
|
|
pte = pte_mkhuge(pte);
|
|
|
|
}
|
2011-04-15 07:25:21 +08:00
|
|
|
|
2018-10-13 04:37:46 +08:00
|
|
|
if (address >= end_paddr)
|
|
|
|
break;
|
2011-04-15 07:25:21 +08:00
|
|
|
|
|
|
|
set_pte(pg_table, pte);
|
|
|
|
|
|
|
|
address += PAGE_SIZE;
|
|
|
|
vaddr += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
start_pte = 0;
|
|
|
|
|
|
|
|
if (address >= end_paddr)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
start_pmd = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 04:38:22 +08:00
|
|
|
void __init set_kernel_text_rw(int enable_read_write)
|
|
|
|
{
|
|
|
|
unsigned long start = (unsigned long)_stext;
|
|
|
|
unsigned long end = (unsigned long)_etext;
|
|
|
|
|
|
|
|
map_pages(start, __pa(start), end-start,
|
|
|
|
PAGE_KERNEL_RWX, enable_read_write ? 1:0);
|
|
|
|
|
|
|
|
/* force the kernel to see the new TLB entries */
|
|
|
|
__flush_tlb_range(0, start, end);
|
|
|
|
|
|
|
|
/* dump old cached instructions */
|
|
|
|
flush_icache_range(start, end);
|
|
|
|
}
|
|
|
|
|
2018-04-21 05:23:37 +08:00
|
|
|
void __ref free_initmem(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-05 10:53:47 +08:00
|
|
|
unsigned long init_begin = (unsigned long)__init_begin;
|
|
|
|
unsigned long init_end = (unsigned long)__init_end;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-04-15 07:25:21 +08:00
|
|
|
/* The init text pages are marked R-X. We have to
|
|
|
|
* flush the icache and mark them RW-
|
|
|
|
*
|
|
|
|
* This is tricky, because map_pages is in the init section.
|
|
|
|
* Do a dummy remap of the data section first (the data
|
|
|
|
* section is already PAGE_KERNEL) to pull in the TLB entries
|
|
|
|
* for map_kernel */
|
|
|
|
map_pages(init_begin, __pa(init_begin), init_end - init_begin,
|
|
|
|
PAGE_KERNEL_RWX, 1);
|
|
|
|
/* now remap at PAGE_KERNEL since the TLB is pre-primed to execute
|
|
|
|
* map_pages */
|
|
|
|
map_pages(init_begin, __pa(init_begin), init_end - init_begin,
|
|
|
|
PAGE_KERNEL, 1);
|
|
|
|
|
|
|
|
/* force the kernel to see the new TLB entries */
|
|
|
|
__flush_tlb_range(0, init_begin, init_end);
|
2015-11-22 07:07:44 +08:00
|
|
|
|
2011-04-15 07:25:21 +08:00
|
|
|
/* finally dump all the instructions which were cached, since the
|
|
|
|
* pages are no-longer executable */
|
2009-04-05 10:53:47 +08:00
|
|
|
flush_icache_range(init_begin, init_end);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-11-22 07:07:44 +08:00
|
|
|
free_initmem_default(POISON_FREE_INITMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* set up a new led state on systems shipped LED State panel */
|
|
|
|
pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE);
|
|
|
|
}
|
|
|
|
|
2006-01-14 04:21:06 +08:00
|
|
|
|
2017-02-07 08:31:58 +08:00
|
|
|
#ifdef CONFIG_STRICT_KERNEL_RWX
|
2006-01-14 04:21:06 +08:00
|
|
|
void mark_rodata_ro(void)
|
|
|
|
{
|
|
|
|
/* rodata memory was already mapped with KERNEL_RO access rights by
|
|
|
|
pagetable_init() and map_pages(). No need to do additional stuff here */
|
|
|
|
printk (KERN_INFO "Write protecting the kernel read-only data: %luk\n",
|
2006-07-01 19:36:30 +08:00
|
|
|
(unsigned long)(__end_rodata - __start_rodata) >> 10);
|
2006-01-14 04:21:06 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Just an arbitrary offset to serve as a "hole" between mapping areas
|
|
|
|
* (between top of physical memory and a potential pcxl dma mapping
|
|
|
|
* area, and below the vmalloc mapping area).
|
|
|
|
*
|
|
|
|
* The current 32K value just means that there will be a 32K "hole"
|
|
|
|
* between mapping areas. That means that any out-of-bounds memory
|
|
|
|
* accesses will hopefully be caught. The vmalloc() routines leaves
|
|
|
|
* a hole of 4kB between each vmalloced area for the same reason.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Leave room for gateway page expansion */
|
|
|
|
#if KERNEL_MAP_START < GATEWAY_PAGE_SIZE
|
|
|
|
#error KERNEL_MAP_START is in gateway reserved region
|
|
|
|
#endif
|
|
|
|
#define MAP_START (KERNEL_MAP_START)
|
|
|
|
|
|
|
|
#define VM_MAP_OFFSET (32*1024)
|
|
|
|
#define SET_MAP_OFFSET(x) ((void *)(((unsigned long)(x) + VM_MAP_OFFSET) \
|
|
|
|
& ~(VM_MAP_OFFSET-1)))
|
|
|
|
|
2009-09-28 11:26:01 +08:00
|
|
|
void *parisc_vmalloc_start __read_mostly;
|
|
|
|
EXPORT_SYMBOL(parisc_vmalloc_start);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PA11
|
2006-01-11 09:35:03 +08:00
|
|
|
unsigned long pcxl_dma_start __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
2015-11-07 06:36:01 +08:00
|
|
|
/* Do sanity checks on IPC (compat) structures */
|
|
|
|
BUILD_BUG_ON(sizeof(struct ipc64_perm) != 48);
|
|
|
|
#ifndef CONFIG_64BIT
|
|
|
|
BUILD_BUG_ON(sizeof(struct semid64_ds) != 80);
|
|
|
|
BUILD_BUG_ON(sizeof(struct msqid64_ds) != 104);
|
|
|
|
BUILD_BUG_ON(sizeof(struct shmid64_ds) != 104);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
BUILD_BUG_ON(sizeof(struct compat_ipc64_perm) != sizeof(struct ipc64_perm));
|
|
|
|
BUILD_BUG_ON(sizeof(struct compat_semid64_ds) != 80);
|
|
|
|
BUILD_BUG_ON(sizeof(struct compat_msqid64_ds) != 104);
|
|
|
|
BUILD_BUG_ON(sizeof(struct compat_shmid64_ds) != 104);
|
|
|
|
#endif
|
|
|
|
|
parisc: fix usage of 32bit PTE page table entries on 32bit kernels
This patch fixes a long outstanding bug on 32bit parisc linux kernels
which prevented us from using 32bit PTE table entries (instead of 64bit
entries of which 32bit were unused).
The problem was caused by this assembler statement in the L2_ptep
macro in arch/parisc/kernel/entry.S:447:
EXTR \va,31-ASM_PGDIR_SHIFT,ASM_BITS_PER_PGD,\index
which expanded to
extrw,u r8,9,11,r1
and which has undefined behavior since the length value (11) extends
beyond the leftmost bit (11-1 > 9).
Interestingly PA2.0 processors seem to don't care and just zero-extend
the value, while PA1.1 processors don't.
Fix this problem by detecting an address space overflow with ASM_BITS_PER_PGD
and adjusting it accordingly. To prevent such problems in the future,
some compile time sanity checks in arch/parisc/mm/init.c were added.
Since the page table now only consumes half of it's old size, we can
use the freed memory to harmonize 32- and 64bit kernels and let both
map 16MB for the initial page table.
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
2009-01-19 02:16:16 +08:00
|
|
|
/* Do sanity checks on page table constants */
|
|
|
|
BUILD_BUG_ON(PTE_ENTRY_SIZE != sizeof(pte_t));
|
|
|
|
BUILD_BUG_ON(PMD_ENTRY_SIZE != sizeof(pmd_t));
|
|
|
|
BUILD_BUG_ON(PGD_ENTRY_SIZE != sizeof(pgd_t));
|
|
|
|
BUILD_BUG_ON(PAGE_SHIFT + BITS_PER_PTE + BITS_PER_PMD + BITS_PER_PGD
|
|
|
|
> BITS_PER_LONG);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
high_memory = __va((max_pfn << PAGE_SHIFT));
|
2013-07-04 06:04:31 +08:00
|
|
|
set_max_mapnr(page_to_pfn(virt_to_page(high_memory - 1)) + 1);
|
2013-07-04 06:03:24 +08:00
|
|
|
free_all_bootmem();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PA11
|
2018-06-19 15:04:53 +08:00
|
|
|
if (boot_cpu_data.cpu_type == pcxl2 || boot_cpu_data.cpu_type == pcxl) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pcxl_dma_start = (unsigned long)SET_MAP_OFFSET(MAP_START);
|
2009-09-28 11:26:01 +08:00
|
|
|
parisc_vmalloc_start = SET_MAP_OFFSET(pcxl_dma_start
|
|
|
|
+ PCXL_DMA_MAP_SIZE);
|
2018-06-19 15:04:53 +08:00
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2018-06-19 15:04:53 +08:00
|
|
|
parisc_vmalloc_start = SET_MAP_OFFSET(MAP_START);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-04 06:04:07 +08:00
|
|
|
mem_init_print_info(NULL);
|
2018-01-13 05:57:15 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Do not expose the virtual kernel memory layout to userspace.
|
|
|
|
* But keep code for debugging purposes.
|
|
|
|
*/
|
2006-10-15 04:10:44 +08:00
|
|
|
printk("virtual kernel memory layout:\n"
|
2018-01-03 03:42:59 +08:00
|
|
|
" vmalloc : 0x%px - 0x%px (%4ld MB)\n"
|
|
|
|
" memory : 0x%px - 0x%px (%4ld MB)\n"
|
|
|
|
" .init : 0x%px - 0x%px (%4ld kB)\n"
|
|
|
|
" .data : 0x%px - 0x%px (%4ld kB)\n"
|
|
|
|
" .text : 0x%px - 0x%px (%4ld kB)\n",
|
2006-10-15 04:10:44 +08:00
|
|
|
|
|
|
|
(void*)VMALLOC_START, (void*)VMALLOC_END,
|
|
|
|
(VMALLOC_END - VMALLOC_START) >> 20,
|
|
|
|
|
|
|
|
__va(0), high_memory,
|
|
|
|
((unsigned long)high_memory - (unsigned long)__va(0)) >> 20,
|
|
|
|
|
2006-10-17 08:34:00 +08:00
|
|
|
__init_begin, __init_end,
|
|
|
|
((unsigned long)__init_end - (unsigned long)__init_begin) >> 10,
|
2006-10-15 04:10:44 +08:00
|
|
|
|
2006-10-17 08:34:00 +08:00
|
|
|
_etext, _edata,
|
|
|
|
((unsigned long)_edata - (unsigned long)_etext) >> 10,
|
2006-10-15 04:10:44 +08:00
|
|
|
|
2006-10-17 08:34:00 +08:00
|
|
|
_text, _etext,
|
|
|
|
((unsigned long)_etext - (unsigned long)_text) >> 10);
|
2006-10-15 04:10:44 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
unsigned long *empty_zero_page __read_mostly;
|
2008-05-26 13:54:35 +08:00
|
|
|
EXPORT_SYMBOL(empty_zero_page);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pagetable_init() sets up the page tables
|
|
|
|
*
|
|
|
|
* Note that gateway_init() places the Linux gateway page at page 0.
|
|
|
|
* Since gateway pages cannot be dereferenced this has the desirable
|
|
|
|
* side effect of trapping those pesky NULL-reference errors in the
|
|
|
|
* kernel.
|
|
|
|
*/
|
|
|
|
static void __init pagetable_init(void)
|
|
|
|
{
|
|
|
|
int range;
|
|
|
|
|
|
|
|
/* Map each physical memory range to its kernel vaddr */
|
|
|
|
|
|
|
|
for (range = 0; range < npmem_ranges; range++) {
|
|
|
|
unsigned long start_paddr;
|
|
|
|
unsigned long end_paddr;
|
|
|
|
unsigned long size;
|
|
|
|
|
|
|
|
start_paddr = pmem_ranges[range].start_pfn << PAGE_SHIFT;
|
|
|
|
size = pmem_ranges[range].pages << PAGE_SHIFT;
|
2015-11-22 07:07:44 +08:00
|
|
|
end_paddr = start_paddr + size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
map_pages((unsigned long)__va(start_paddr), start_paddr,
|
2011-04-15 07:25:21 +08:00
|
|
|
size, PAGE_KERNEL, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
if (initrd_end && initrd_end > mem_limit) {
|
2006-01-14 04:21:06 +08:00
|
|
|
printk(KERN_INFO "initrd: mapping %08lx-%08lx\n", initrd_start, initrd_end);
|
2005-04-17 06:20:36 +08:00
|
|
|
map_pages(initrd_start, __pa(initrd_start),
|
2011-04-15 07:25:21 +08:00
|
|
|
initrd_end - initrd_start, PAGE_KERNEL, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-07 22:50:21 +08:00
|
|
|
empty_zero_page = get_memblock(PAGE_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __init gateway_init(void)
|
|
|
|
{
|
|
|
|
unsigned long linux_gateway_page_addr;
|
|
|
|
/* FIXME: This is 'const' in order to trick the compiler
|
|
|
|
into not treating it as DP-relative data. */
|
|
|
|
extern void * const linux_gateway_page;
|
|
|
|
|
|
|
|
linux_gateway_page_addr = LINUX_GATEWAY_ADDR & PAGE_MASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup Linux Gateway page.
|
|
|
|
*
|
|
|
|
* The Linux gateway page will reside in kernel space (on virtual
|
|
|
|
* page 0), so it doesn't need to be aliased into user space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
map_pages(linux_gateway_page_addr, __pa(&linux_gateway_page),
|
2011-04-15 07:25:21 +08:00
|
|
|
PAGE_SIZE, PAGE_GATEWAY, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init paging_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
setup_bootmem();
|
|
|
|
pagetable_init();
|
|
|
|
gateway_init();
|
|
|
|
flush_cache_all_local(); /* start with known state */
|
2006-01-11 09:47:49 +08:00
|
|
|
flush_tlb_all_local(NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < npmem_ranges; i++) {
|
2006-09-26 14:31:10 +08:00
|
|
|
unsigned long zones_size[MAX_NR_ZONES] = { 0, };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:43:12 +08:00
|
|
|
zones_size[ZONE_NORMAL] = pmem_ranges[i].pages;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DISCONTIGMEM
|
|
|
|
/* Need to initialize the pfnnid_map before we can initialize
|
|
|
|
the zone */
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
for (j = (pmem_ranges[i].start_pfn >> PFNNID_SHIFT);
|
|
|
|
j <= ((pmem_ranges[i].start_pfn + pmem_ranges[i].pages) >> PFNNID_SHIFT);
|
|
|
|
j++) {
|
|
|
|
pfnnid_map[j] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-24 12:27:20 +08:00
|
|
|
free_area_init_node(i, zones_size,
|
2005-04-17 06:20:36 +08:00
|
|
|
pmem_ranges[i].start_pfn, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PA20
|
|
|
|
|
|
|
|
/*
|
2007-05-12 03:42:34 +08:00
|
|
|
* Currently, all PA20 chips have 18 bit protection IDs, which is the
|
2005-04-17 06:20:36 +08:00
|
|
|
* limiting factor (space ids are 32 bits).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NR_SPACE_IDS 262144
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
2007-05-12 03:42:34 +08:00
|
|
|
* Currently we have a one-to-one relationship between space IDs and
|
|
|
|
* protection IDs. Older parisc chips (PCXS, PCXT, PCXL, PCXL2) only
|
|
|
|
* support 15 bit protection IDs, so that is the limiting factor.
|
|
|
|
* PCXT' has 18 bit protection IDs, but only 16 bit spaceids, so it's
|
2005-04-17 06:20:36 +08:00
|
|
|
* probably not worth the effort for a special case here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NR_SPACE_IDS 32768
|
|
|
|
|
|
|
|
#endif /* !CONFIG_PA20 */
|
|
|
|
|
|
|
|
#define RECYCLE_THRESHOLD (NR_SPACE_IDS / 2)
|
|
|
|
#define SID_ARRAY_SIZE (NR_SPACE_IDS / (8 * sizeof(long)))
|
|
|
|
|
|
|
|
static unsigned long space_id[SID_ARRAY_SIZE] = { 1 }; /* disallow space 0 */
|
|
|
|
static unsigned long dirty_space_id[SID_ARRAY_SIZE];
|
|
|
|
static unsigned long space_id_index;
|
|
|
|
static unsigned long free_space_ids = NR_SPACE_IDS - 1;
|
|
|
|
static unsigned long dirty_space_ids = 0;
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(sid_lock);
|
|
|
|
|
|
|
|
unsigned long alloc_sid(void)
|
|
|
|
{
|
|
|
|
unsigned long index;
|
|
|
|
|
|
|
|
spin_lock(&sid_lock);
|
|
|
|
|
|
|
|
if (free_space_ids == 0) {
|
|
|
|
if (dirty_space_ids != 0) {
|
|
|
|
spin_unlock(&sid_lock);
|
|
|
|
flush_tlb_all(); /* flush_tlb_all() calls recycle_sids() */
|
|
|
|
spin_lock(&sid_lock);
|
|
|
|
}
|
2006-04-21 04:40:23 +08:00
|
|
|
BUG_ON(free_space_ids == 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free_space_ids--;
|
|
|
|
|
|
|
|
index = find_next_zero_bit(space_id, NR_SPACE_IDS, space_id_index);
|
|
|
|
space_id[index >> SHIFT_PER_LONG] |= (1L << (index & (BITS_PER_LONG - 1)));
|
|
|
|
space_id_index = index;
|
|
|
|
|
|
|
|
spin_unlock(&sid_lock);
|
|
|
|
|
|
|
|
return index << SPACEID_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_sid(unsigned long spaceid)
|
|
|
|
{
|
|
|
|
unsigned long index = spaceid >> SPACEID_SHIFT;
|
|
|
|
unsigned long *dirty_space_offset;
|
|
|
|
|
|
|
|
dirty_space_offset = dirty_space_id + (index >> SHIFT_PER_LONG);
|
|
|
|
index &= (BITS_PER_LONG - 1);
|
|
|
|
|
|
|
|
spin_lock(&sid_lock);
|
|
|
|
|
2006-04-21 04:40:23 +08:00
|
|
|
BUG_ON(*dirty_space_offset & (1L << index)); /* attempt to free space id twice */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*dirty_space_offset |= (1L << index);
|
|
|
|
dirty_space_ids++;
|
|
|
|
|
|
|
|
spin_unlock(&sid_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static void get_dirty_sids(unsigned long *ndirtyptr,unsigned long *dirty_array)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* NOTE: sid_lock must be held upon entry */
|
|
|
|
|
|
|
|
*ndirtyptr = dirty_space_ids;
|
|
|
|
if (dirty_space_ids != 0) {
|
|
|
|
for (i = 0; i < SID_ARRAY_SIZE; i++) {
|
|
|
|
dirty_array[i] = dirty_space_id[i];
|
|
|
|
dirty_space_id[i] = 0;
|
|
|
|
}
|
|
|
|
dirty_space_ids = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void recycle_sids(unsigned long ndirty,unsigned long *dirty_array)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* NOTE: sid_lock must be held upon entry */
|
|
|
|
|
|
|
|
if (ndirty != 0) {
|
|
|
|
for (i = 0; i < SID_ARRAY_SIZE; i++) {
|
|
|
|
space_id[i] ^= dirty_array[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free_space_ids += ndirty;
|
|
|
|
space_id_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_SMP */
|
|
|
|
|
|
|
|
static void recycle_sids(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* NOTE: sid_lock must be held upon entry */
|
|
|
|
|
|
|
|
if (dirty_space_ids != 0) {
|
|
|
|
for (i = 0; i < SID_ARRAY_SIZE; i++) {
|
|
|
|
space_id[i] ^= dirty_space_id[i];
|
|
|
|
dirty_space_id[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_space_ids += dirty_space_ids;
|
|
|
|
dirty_space_ids = 0;
|
|
|
|
space_id_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flush_tlb_all() calls recycle_sids(), since whenever the entire tlb is
|
|
|
|
* purged, we can safely reuse the space ids that were released but
|
|
|
|
* not flushed from the tlb.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
static unsigned long recycle_ndirty;
|
|
|
|
static unsigned long recycle_dirty_array[SID_ARRAY_SIZE];
|
2006-04-21 04:40:23 +08:00
|
|
|
static unsigned int recycle_inuse;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void flush_tlb_all(void)
|
|
|
|
{
|
|
|
|
int do_recycle;
|
|
|
|
|
2013-05-11 05:24:01 +08:00
|
|
|
__inc_irq_stat(irq_tlb_count);
|
2005-04-17 06:20:36 +08:00
|
|
|
do_recycle = 0;
|
|
|
|
spin_lock(&sid_lock);
|
|
|
|
if (dirty_space_ids > RECYCLE_THRESHOLD) {
|
2006-04-21 04:40:23 +08:00
|
|
|
BUG_ON(recycle_inuse); /* FIXME: Use a semaphore/wait queue here */
|
2005-04-17 06:20:36 +08:00
|
|
|
get_dirty_sids(&recycle_ndirty,recycle_dirty_array);
|
|
|
|
recycle_inuse++;
|
|
|
|
do_recycle++;
|
|
|
|
}
|
|
|
|
spin_unlock(&sid_lock);
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(flush_tlb_all_local, NULL, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (do_recycle) {
|
|
|
|
spin_lock(&sid_lock);
|
|
|
|
recycle_sids(recycle_ndirty,recycle_dirty_array);
|
|
|
|
recycle_inuse = 0;
|
|
|
|
spin_unlock(&sid_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void flush_tlb_all(void)
|
|
|
|
{
|
2013-05-11 05:24:01 +08:00
|
|
|
__inc_irq_stat(irq_tlb_count);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&sid_lock);
|
2006-01-11 09:47:49 +08:00
|
|
|
flush_tlb_all_local(NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
recycle_sids();
|
|
|
|
spin_unlock(&sid_lock);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
void free_initrd_mem(unsigned long start, unsigned long end)
|
|
|
|
{
|
2013-07-04 06:04:07 +08:00
|
|
|
free_reserved_area((void *)start, (void *)end, -1, "initrd");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|