2005-06-24 12:01:24 +07:00
|
|
|
/*
|
|
|
|
* arch/xtensa/mm/init.c
|
|
|
|
*
|
|
|
|
* Derived from MIPS, PPC.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 - 2005 Tensilica Inc.
|
2016-04-26 02:08:20 +07:00
|
|
|
* Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
|
2005-06-24 12:01:24 +07:00
|
|
|
*
|
|
|
|
* Chris Zankel <chris@zankel.net>
|
|
|
|
* Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
|
|
|
|
* Marc Gauthier
|
|
|
|
* Kevin Chea
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
2018-10-31 05:09:49 +07: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 15:04:11 +07:00
|
|
|
#include <linux/gfp.h>
|
2014-02-04 05:17:09 +07:00
|
|
|
#include <linux/highmem.h>
|
2005-06-24 12:01:24 +07:00
|
|
|
#include <linux/swap.h>
|
2007-08-23 00:14:51 +07:00
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/nodemask.h>
|
|
|
|
#include <linux/mm.h>
|
2016-07-19 04:37:05 +07:00
|
|
|
#include <linux/of_fdt.h>
|
2016-04-26 02:08:52 +07:00
|
|
|
#include <linux/dma-contiguous.h>
|
2005-06-24 12:01:24 +07:00
|
|
|
|
|
|
|
#include <asm/bootparam.h>
|
|
|
|
#include <asm/page.h>
|
2012-06-21 02:52:59 +07:00
|
|
|
#include <asm/sections.h>
|
2014-03-23 06:17:43 +07:00
|
|
|
#include <asm/sysmem.h>
|
|
|
|
|
2005-06-24 12:01:24 +07:00
|
|
|
/*
|
2014-01-31 08:38:21 +07:00
|
|
|
* Initialize the bootmem system and give it all low memory we have available.
|
2005-06-24 12:01:24 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
void __init bootmem_init(void)
|
|
|
|
{
|
2016-04-26 02:08:20 +07:00
|
|
|
/* Reserve all memory below PHYS_OFFSET, as memory
|
2014-10-04 06:46:34 +07:00
|
|
|
* accounting doesn't work for pages below that address.
|
|
|
|
*
|
2016-04-26 02:08:20 +07:00
|
|
|
* If PHYS_OFFSET is zero reserve page at address 0:
|
2014-10-04 06:46:34 +07:00
|
|
|
* successfull allocations should never return NULL.
|
|
|
|
*/
|
2016-04-26 02:08:20 +07:00
|
|
|
if (PHYS_OFFSET)
|
|
|
|
memblock_reserve(0, PHYS_OFFSET);
|
2014-10-04 06:46:34 +07:00
|
|
|
else
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_reserve(0, 1);
|
2014-10-04 06:46:34 +07:00
|
|
|
|
2016-07-19 04:37:05 +07:00
|
|
|
early_init_fdt_scan_reserved_mem();
|
2005-06-24 12:01:24 +07:00
|
|
|
|
2016-04-26 02:08:20 +07:00
|
|
|
if (!memblock_phys_mem_size())
|
2005-06-24 12:01:24 +07:00
|
|
|
panic("No memory found!\n");
|
|
|
|
|
2016-04-26 02:08:20 +07:00
|
|
|
min_low_pfn = PFN_UP(memblock_start_of_DRAM());
|
|
|
|
min_low_pfn = max(min_low_pfn, PFN_UP(PHYS_OFFSET));
|
|
|
|
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
|
2016-04-12 01:14:17 +07:00
|
|
|
max_low_pfn = min(max_pfn, MAX_LOW_PFN);
|
2005-06-24 12:01:24 +07:00
|
|
|
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
|
2016-04-26 02:08:52 +07:00
|
|
|
dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
|
2005-06-24 12:01:24 +07:00
|
|
|
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_dump_all();
|
2005-06-24 12:01:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-04 22:21:31 +07:00
|
|
|
void __init zones_init(void)
|
2005-06-24 12:01:24 +07:00
|
|
|
{
|
|
|
|
/* All pages are DMA-able, so we put them all in the DMA zone. */
|
2014-02-04 05:17:09 +07:00
|
|
|
unsigned long zones_size[MAX_NR_ZONES] = {
|
2018-10-15 01:13:04 +07:00
|
|
|
[ZONE_NORMAL] = max_low_pfn - ARCH_PFN_OFFSET,
|
2005-06-24 12:01:24 +07:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2014-02-04 05:17:09 +07:00
|
|
|
[ZONE_HIGHMEM] = max_pfn - max_low_pfn,
|
2005-06-24 12:01:24 +07:00
|
|
|
#endif
|
2014-02-04 05:17:09 +07:00
|
|
|
};
|
2009-03-04 22:21:30 +07:00
|
|
|
free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
|
2005-06-24 12:01:24 +07:00
|
|
|
}
|
|
|
|
|
2018-02-14 06:31:05 +07:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
static void __init free_area_high(unsigned long pfn, unsigned long end)
|
|
|
|
{
|
|
|
|
for (; pfn < end; pfn++)
|
|
|
|
free_highmem_page(pfn_to_page(pfn));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init free_highpages(void)
|
|
|
|
{
|
|
|
|
unsigned long max_low = max_low_pfn;
|
|
|
|
struct memblock_region *mem, *res;
|
|
|
|
|
|
|
|
reset_all_zones_managed_pages();
|
|
|
|
/* set highmem page free */
|
|
|
|
for_each_memblock(memory, mem) {
|
|
|
|
unsigned long start = memblock_region_memory_base_pfn(mem);
|
|
|
|
unsigned long end = memblock_region_memory_end_pfn(mem);
|
|
|
|
|
|
|
|
/* Ignore complete lowmem entries */
|
|
|
|
if (end <= max_low)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (memblock_is_nomap(mem))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Truncate partial highmem entries */
|
|
|
|
if (start < max_low)
|
|
|
|
start = max_low;
|
|
|
|
|
|
|
|
/* Find and exclude any reserved regions */
|
|
|
|
for_each_memblock(reserved, res) {
|
|
|
|
unsigned long res_start, res_end;
|
|
|
|
|
|
|
|
res_start = memblock_region_reserved_base_pfn(res);
|
|
|
|
res_end = memblock_region_reserved_end_pfn(res);
|
|
|
|
|
|
|
|
if (res_end < start)
|
|
|
|
continue;
|
|
|
|
if (res_start < start)
|
|
|
|
res_start = start;
|
|
|
|
if (res_start > end)
|
|
|
|
res_start = end;
|
|
|
|
if (res_end > end)
|
|
|
|
res_end = end;
|
|
|
|
if (res_start != start)
|
|
|
|
free_area_high(start, res_start);
|
|
|
|
start = res_end;
|
|
|
|
if (start == end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And now free anything which remains */
|
|
|
|
if (start < end)
|
|
|
|
free_area_high(start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void __init free_highpages(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-06-24 12:01:24 +07:00
|
|
|
/*
|
|
|
|
* Initialize memory pages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
2018-02-14 06:31:05 +07:00
|
|
|
free_highpages();
|
2005-06-24 12:01:24 +07:00
|
|
|
|
2014-02-04 05:17:09 +07:00
|
|
|
max_mapnr = max_pfn - ARCH_PFN_OFFSET;
|
|
|
|
high_memory = (void *)__va(max_low_pfn << PAGE_SHIFT);
|
|
|
|
|
2018-10-31 05:09:30 +07:00
|
|
|
memblock_free_all();
|
2005-06-24 12:01:24 +07:00
|
|
|
|
2013-07-04 05:04:20 +07:00
|
|
|
mem_init_print_info(NULL);
|
2014-02-04 05:17:09 +07:00
|
|
|
pr_info("virtual kernel memory layout:\n"
|
2017-12-04 04:28:52 +07:00
|
|
|
#ifdef CONFIG_KASAN
|
|
|
|
" kasan : 0x%08lx - 0x%08lx (%5lu MB)\n"
|
|
|
|
#endif
|
2017-12-04 10:09:41 +07:00
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
" vmalloc : 0x%08lx - 0x%08lx (%5lu MB)\n"
|
|
|
|
#endif
|
2014-02-04 05:17:09 +07:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
" pkmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
|
|
|
" fixmap : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
2014-10-04 06:50:33 +07:00
|
|
|
#endif
|
2017-12-11 11:15:37 +07:00
|
|
|
" lowmem : 0x%08lx - 0x%08lx (%5lu MB)\n"
|
|
|
|
" .text : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
|
|
|
" .rodata : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
|
|
|
" .data : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
|
|
|
" .init : 0x%08lx - 0x%08lx (%5lu kB)\n"
|
|
|
|
" .bss : 0x%08lx - 0x%08lx (%5lu kB)\n",
|
2017-12-04 04:28:52 +07:00
|
|
|
#ifdef CONFIG_KASAN
|
|
|
|
KASAN_SHADOW_START, KASAN_SHADOW_START + KASAN_SHADOW_SIZE,
|
|
|
|
KASAN_SHADOW_SIZE >> 20,
|
|
|
|
#endif
|
2017-12-04 10:09:41 +07:00
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
VMALLOC_START, VMALLOC_END,
|
|
|
|
(VMALLOC_END - VMALLOC_START) >> 20,
|
2014-02-04 05:17:09 +07:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
|
|
|
|
(LAST_PKMAP*PAGE_SIZE) >> 10,
|
|
|
|
FIXADDR_START, FIXADDR_TOP,
|
|
|
|
(FIXADDR_TOP - FIXADDR_START) >> 10,
|
|
|
|
#endif
|
|
|
|
PAGE_OFFSET, PAGE_OFFSET +
|
|
|
|
(max_low_pfn - min_low_pfn) * PAGE_SIZE,
|
2014-10-04 06:50:33 +07:00
|
|
|
#else
|
|
|
|
min_low_pfn * PAGE_SIZE, max_low_pfn * PAGE_SIZE,
|
|
|
|
#endif
|
2017-12-11 11:15:37 +07:00
|
|
|
((max_low_pfn - min_low_pfn) * PAGE_SIZE) >> 20,
|
|
|
|
(unsigned long)_text, (unsigned long)_etext,
|
|
|
|
(unsigned long)(_etext - _text) >> 10,
|
|
|
|
(unsigned long)__start_rodata, (unsigned long)_sdata,
|
|
|
|
(unsigned long)(_sdata - __start_rodata) >> 10,
|
|
|
|
(unsigned long)_sdata, (unsigned long)_edata,
|
|
|
|
(unsigned long)(_edata - _sdata) >> 10,
|
|
|
|
(unsigned long)__init_begin, (unsigned long)__init_end,
|
|
|
|
(unsigned long)(__init_end - __init_begin) >> 10,
|
|
|
|
(unsigned long)__bss_start, (unsigned long)__bss_stop,
|
|
|
|
(unsigned long)(__bss_stop - __bss_start) >> 10);
|
2005-06-24 12:01:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
extern int initrd_is_mapped;
|
|
|
|
|
|
|
|
void free_initrd_mem(unsigned long start, unsigned long end)
|
|
|
|
{
|
2013-04-30 05:06:55 +07:00
|
|
|
if (initrd_is_mapped)
|
2013-07-04 05:02:51 +07:00
|
|
|
free_reserved_area((void *)start, (void *)end, -1, "initrd");
|
2005-06-24 12:01:24 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void free_initmem(void)
|
|
|
|
{
|
2013-07-04 05:02:51 +07:00
|
|
|
free_initmem_default(-1);
|
2005-06-24 12:01:24 +07:00
|
|
|
}
|
2014-03-22 00:04:40 +07:00
|
|
|
|
|
|
|
static void __init parse_memmap_one(char *p)
|
|
|
|
{
|
|
|
|
char *oldp;
|
|
|
|
unsigned long start_at, mem_size;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
oldp = p;
|
|
|
|
mem_size = memparse(p, &p);
|
|
|
|
if (p == oldp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (*p) {
|
|
|
|
case '@':
|
|
|
|
start_at = memparse(p + 1, &p);
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_add(start_at, mem_size);
|
2014-03-22 00:04:40 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '$':
|
|
|
|
start_at = memparse(p + 1, &p);
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_reserve(start_at, mem_size);
|
2014-03-22 00:04:40 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
2016-04-26 02:08:20 +07:00
|
|
|
memblock_reserve(mem_size, -mem_size);
|
2014-03-22 00:04:40 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pr_warn("Unrecognized memmap syntax: %s\n", p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init parse_memmap_opt(char *str)
|
|
|
|
{
|
|
|
|
while (str) {
|
|
|
|
char *k = strchr(str, ',');
|
|
|
|
|
|
|
|
if (k)
|
|
|
|
*k++ = 0;
|
|
|
|
|
|
|
|
parse_memmap_one(str);
|
|
|
|
str = k;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("memmap", parse_memmap_opt);
|