2009-03-27 21:25:29 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2008 Michal Simek <monstr@monstr.eu>
|
|
|
|
* Copyright (C) 2006 Atmark Techno, Inc.
|
|
|
|
*
|
|
|
|
* 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/bootmem.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
2010-07-12 12:36:09 +08:00
|
|
|
#include <linux/memblock.h>
|
2009-03-27 21:25:29 +08:00
|
|
|
#include <linux/mm.h> /* mem_init */
|
|
|
|
#include <linux/initrd.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/pfn.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/slab.h>
|
2009-03-27 21:25:29 +08:00
|
|
|
#include <linux/swap.h>
|
2011-09-22 23:22:55 +08:00
|
|
|
#include <linux/export.h>
|
2009-03-27 21:25:29 +08:00
|
|
|
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/tlb.h>
|
2011-12-15 21:33:32 +08:00
|
|
|
#include <asm/fixmap.h>
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2010-01-20 22:17:08 +08:00
|
|
|
/* Use for MMU and noMMU because of PCI generic code */
|
|
|
|
int mem_init_done;
|
|
|
|
|
2009-05-26 22:30:12 +08:00
|
|
|
#ifndef CONFIG_MMU
|
2009-03-27 21:25:29 +08:00
|
|
|
unsigned int __page_offset;
|
2009-05-02 05:48:15 +08:00
|
|
|
EXPORT_SYMBOL(__page_offset);
|
2009-05-26 22:30:12 +08:00
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
|
2009-03-27 21:25:29 +08:00
|
|
|
char *klimit = _end;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the bootmem system and give it all the memory we
|
|
|
|
* have available.
|
|
|
|
*/
|
2009-05-26 22:30:12 +08:00
|
|
|
unsigned long memory_start;
|
2009-07-23 14:23:53 +08:00
|
|
|
EXPORT_SYMBOL(memory_start);
|
2009-05-26 22:30:12 +08:00
|
|
|
unsigned long memory_size;
|
2010-05-13 18:11:42 +08:00
|
|
|
EXPORT_SYMBOL(memory_size);
|
2011-12-19 20:46:35 +08:00
|
|
|
unsigned long lowmem_size;
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
pte_t *kmap_pte;
|
|
|
|
EXPORT_SYMBOL(kmap_pte);
|
|
|
|
pgprot_t kmap_prot;
|
|
|
|
EXPORT_SYMBOL(kmap_prot);
|
|
|
|
|
|
|
|
static inline pte_t *virt_to_kpte(unsigned long vaddr)
|
|
|
|
{
|
|
|
|
return pte_offset_kernel(pmd_offset(pgd_offset_k(vaddr),
|
|
|
|
vaddr), vaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init highmem_init(void)
|
|
|
|
{
|
|
|
|
pr_debug("%x\n", (u32)PKMAP_BASE);
|
|
|
|
map_page(PKMAP_BASE, 0, 0); /* XXX gross */
|
|
|
|
pkmap_page_table = virt_to_kpte(PKMAP_BASE);
|
|
|
|
|
|
|
|
kmap_pte = virt_to_kpte(__fix_to_virt(FIX_KMAP_BEGIN));
|
|
|
|
kmap_prot = PAGE_KERNEL;
|
|
|
|
}
|
|
|
|
|
2013-07-04 06:04:02 +08:00
|
|
|
static void highmem_setup(void)
|
2011-12-15 22:02:37 +08:00
|
|
|
{
|
|
|
|
unsigned long pfn;
|
|
|
|
|
|
|
|
for (pfn = max_low_pfn; pfn < max_pfn; ++pfn) {
|
|
|
|
struct page *page = pfn_to_page(pfn);
|
|
|
|
|
|
|
|
/* FIXME not sure about */
|
2013-07-04 06:04:02 +08:00
|
|
|
if (!memblock_is_reserved(pfn << PAGE_SHIFT))
|
|
|
|
free_highmem_page(page);
|
2011-12-15 22:02:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HIGHMEM */
|
|
|
|
|
2009-03-27 21:25:29 +08:00
|
|
|
/*
|
|
|
|
* paging_init() sets up the page tables - in fact we've already done this.
|
|
|
|
*/
|
|
|
|
static void __init paging_init(void)
|
|
|
|
{
|
|
|
|
unsigned long zones_size[MAX_NR_ZONES];
|
2011-12-15 21:33:32 +08:00
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/* Setup fixmaps */
|
|
|
|
for (idx = 0; idx < __end_of_fixed_addresses; idx++)
|
|
|
|
clear_fixmap(idx);
|
|
|
|
#endif
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2009-05-18 09:22:40 +08:00
|
|
|
/* Clean every zones */
|
|
|
|
memset(zones_size, 0, sizeof(zones_size));
|
|
|
|
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
highmem_init();
|
|
|
|
|
|
|
|
zones_size[ZONE_DMA] = max_low_pfn;
|
|
|
|
zones_size[ZONE_HIGHMEM] = max_pfn;
|
|
|
|
#else
|
2011-12-19 20:46:35 +08:00
|
|
|
zones_size[ZONE_DMA] = max_pfn;
|
2011-12-15 22:02:37 +08:00
|
|
|
#endif
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2011-12-15 22:47:16 +08:00
|
|
|
/* We don't have holes in memory map */
|
|
|
|
free_area_init_nodes(zones_size);
|
2009-03-27 21:25:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init setup_memory(void)
|
|
|
|
{
|
2010-08-04 12:13:06 +08:00
|
|
|
struct memblock_region *reg;
|
|
|
|
|
2009-05-26 22:30:12 +08:00
|
|
|
#ifndef CONFIG_MMU
|
2009-03-27 21:25:29 +08:00
|
|
|
u32 kernel_align_start, kernel_align_size;
|
|
|
|
|
|
|
|
/* Find main memory where is the kernel */
|
2010-08-04 12:13:06 +08:00
|
|
|
for_each_memblock(memory, reg) {
|
|
|
|
memory_start = (u32)reg->base;
|
2011-12-19 20:46:35 +08:00
|
|
|
lowmem_size = reg->size;
|
2009-03-27 21:25:29 +08:00
|
|
|
if ((memory_start <= (u32)_text) &&
|
2011-12-19 20:46:35 +08:00
|
|
|
((u32)_text <= (memory_start + lowmem_size - 1))) {
|
|
|
|
memory_size = lowmem_size;
|
2009-03-27 21:25:29 +08:00
|
|
|
PAGE_OFFSET = memory_start;
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_info("%s: Main mem: 0x%x, size 0x%08x\n",
|
|
|
|
__func__, (u32) memory_start,
|
2011-12-19 20:46:35 +08:00
|
|
|
(u32) memory_size);
|
2009-03-27 21:25:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 20:46:35 +08:00
|
|
|
if (!memory_start || !memory_size) {
|
|
|
|
panic("%s: Missing memory setting 0x%08x, size=0x%08x\n",
|
|
|
|
__func__, (u32) memory_start, (u32) memory_size);
|
2009-03-27 21:25:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reservation of region where is the kernel */
|
|
|
|
kernel_align_start = PAGE_DOWN((u32)_text);
|
|
|
|
/* ALIGN can be remove because _end in vmlinux.lds.S is align */
|
|
|
|
kernel_align_size = PAGE_UP((u32)klimit) - kernel_align_start;
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_info("%s: kernel addr:0x%08x-0x%08x size=0x%08x\n",
|
2009-03-27 21:25:29 +08:00
|
|
|
__func__, kernel_align_start, kernel_align_start
|
|
|
|
+ kernel_align_size, kernel_align_size);
|
2011-12-19 20:46:35 +08:00
|
|
|
memblock_reserve(kernel_align_start, kernel_align_size);
|
2009-05-26 22:30:12 +08:00
|
|
|
#endif
|
2009-03-27 21:25:29 +08:00
|
|
|
/*
|
|
|
|
* Kernel:
|
|
|
|
* start: base phys address of kernel - page align
|
|
|
|
* end: base phys address of kernel - page align
|
|
|
|
*
|
|
|
|
* min_low_pfn - the first page (mm/bootmem.c - node_boot_start)
|
|
|
|
* max_low_pfn
|
|
|
|
* max_mapnr - the first unused page (mm/bootmem.c - node_low_pfn)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* memory start is from the kernel end (aligned) to higher addr */
|
|
|
|
min_low_pfn = memory_start >> PAGE_SHIFT; /* minimum for allocation */
|
|
|
|
/* RAM is assumed contiguous */
|
2013-07-04 06:04:02 +08:00
|
|
|
max_mapnr = memory_size >> PAGE_SHIFT;
|
2011-12-19 20:46:35 +08:00
|
|
|
max_low_pfn = ((u64)memory_start + (u64)lowmem_size) >> PAGE_SHIFT;
|
|
|
|
max_pfn = ((u64)memory_start + (u64)memory_size) >> PAGE_SHIFT;
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_info("%s: max_mapnr: %#lx\n", __func__, max_mapnr);
|
|
|
|
pr_info("%s: min_low_pfn: %#lx\n", __func__, min_low_pfn);
|
|
|
|
pr_info("%s: max_low_pfn: %#lx\n", __func__, max_low_pfn);
|
|
|
|
pr_info("%s: max_pfn: %#lx\n", __func__, max_pfn);
|
2009-03-27 21:25:29 +08:00
|
|
|
|
2011-12-15 22:47:16 +08:00
|
|
|
/* Add active regions with valid PFNs */
|
|
|
|
for_each_memblock(memory, reg) {
|
|
|
|
unsigned long start_pfn, end_pfn;
|
|
|
|
|
|
|
|
start_pfn = memblock_region_memory_base_pfn(reg);
|
|
|
|
end_pfn = memblock_region_memory_end_pfn(reg);
|
|
|
|
memblock_set_node(start_pfn << PAGE_SHIFT,
|
2014-01-22 07:49:26 +08:00
|
|
|
(end_pfn - start_pfn) << PAGE_SHIFT,
|
|
|
|
&memblock.memory, 0);
|
2011-12-15 22:47:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX need to clip this if using highmem? */
|
|
|
|
sparse_memory_present_with_active_regions(0);
|
|
|
|
|
2009-03-27 21:25:29 +08:00
|
|
|
paging_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
void free_initrd_mem(unsigned long start, unsigned long end)
|
|
|
|
{
|
2013-07-04 06:02:51 +08:00
|
|
|
free_reserved_area((void *)start, (void *)end, -1, "initrd");
|
2009-03-27 21:25:29 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void free_initmem(void)
|
|
|
|
{
|
2013-07-04 06:02:51 +08:00
|
|
|
free_initmem_default(-1);
|
2009-03-27 21:25:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init mem_init(void)
|
|
|
|
{
|
2011-12-19 20:46:35 +08:00
|
|
|
high_memory = (void *)__va(memory_start + lowmem_size - 1);
|
|
|
|
|
2009-03-27 21:25:29 +08:00
|
|
|
/* this will put all memory onto the freelists */
|
2018-10-31 06:09:30 +08:00
|
|
|
memblock_free_all();
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
2013-07-04 06:04:02 +08:00
|
|
|
highmem_setup();
|
2011-12-15 22:02:37 +08:00
|
|
|
#endif
|
|
|
|
|
2013-07-04 06:04:02 +08:00
|
|
|
mem_init_print_info(NULL);
|
2011-12-19 20:47:03 +08:00
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
pr_info("Kernel virtual memory layout:\n");
|
|
|
|
pr_info(" * 0x%08lx..0x%08lx : fixmap\n", FIXADDR_START, FIXADDR_TOP);
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n",
|
|
|
|
PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP));
|
|
|
|
#endif /* CONFIG_HIGHMEM */
|
2011-12-19 20:47:03 +08:00
|
|
|
pr_info(" * 0x%08lx..0x%08lx : early ioremap\n",
|
|
|
|
ioremap_bot, ioremap_base);
|
|
|
|
pr_info(" * 0x%08lx..0x%08lx : vmalloc & ioremap\n",
|
|
|
|
(unsigned long)VMALLOC_START, VMALLOC_END);
|
|
|
|
#endif
|
2009-05-26 22:30:12 +08:00
|
|
|
mem_init_done = 1;
|
2009-03-27 21:25:29 +08:00
|
|
|
}
|
|
|
|
|
2009-05-26 22:30:12 +08:00
|
|
|
#ifndef CONFIG_MMU
|
2010-01-20 22:17:08 +08:00
|
|
|
int page_is_ram(unsigned long pfn)
|
|
|
|
{
|
|
|
|
return __range_ok(pfn, 0);
|
|
|
|
}
|
2009-05-26 22:30:12 +08:00
|
|
|
#else
|
|
|
|
int page_is_ram(unsigned long pfn)
|
|
|
|
{
|
|
|
|
return pfn < max_low_pfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for command-line options that affect what MMU_init will do.
|
|
|
|
*/
|
|
|
|
static void mm_cmdline_setup(void)
|
|
|
|
{
|
|
|
|
unsigned long maxmem = 0;
|
|
|
|
char *p = cmd_line;
|
|
|
|
|
|
|
|
/* Look for mem= option on command line */
|
|
|
|
p = strstr(cmd_line, "mem=");
|
|
|
|
if (p) {
|
|
|
|
p += 4;
|
|
|
|
maxmem = memparse(p, &p);
|
|
|
|
if (maxmem && memory_size > maxmem) {
|
|
|
|
memory_size = maxmem;
|
2010-09-11 15:07:06 +08:00
|
|
|
memblock.memory.regions[0].size = memory_size;
|
2009-05-26 22:30:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MMU_init_hw does the chip-specific initialization of the MMU hardware.
|
|
|
|
*/
|
|
|
|
static void __init mmu_init_hw(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Zone Protection Register (ZPR) defines how protection will
|
|
|
|
* be applied to every page which is a member of a given zone. At
|
|
|
|
* present, we utilize only two of the zones.
|
|
|
|
* The zone index bits (of ZSEL) in the PTE are used for software
|
|
|
|
* indicators, except the LSB. For user access, zone 1 is used,
|
|
|
|
* for kernel access, zone 0 is used. We set all but zone 1
|
|
|
|
* to zero, allowing only kernel access as indicated in the PTE.
|
|
|
|
* For zone 1, we set a 01 binary (a value of 10 will not work)
|
|
|
|
* to allow user access as indicated in the PTE. This also allows
|
|
|
|
* kernel access as indicated in the PTE.
|
|
|
|
*/
|
|
|
|
__asm__ __volatile__ ("ori r11, r0, 0x10000000;" \
|
|
|
|
"mts rzpr, r11;"
|
|
|
|
: : : "r11");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MMU_init sets up the basic memory mappings for the kernel,
|
|
|
|
* including both RAM and possibly some I/O regions,
|
|
|
|
* and sets up the page tables and the MMU hardware ready to go.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* called from head.S */
|
|
|
|
asmlinkage void __init mmu_init(void)
|
|
|
|
{
|
|
|
|
unsigned int kstart, ksize;
|
|
|
|
|
2010-07-12 12:36:09 +08:00
|
|
|
if (!memblock.reserved.cnt) {
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_emerg("Error memory count\n");
|
2009-05-26 22:30:12 +08:00
|
|
|
machine_restart(NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-08 23:41:38 +08:00
|
|
|
if ((u32) memblock.memory.regions[0].size < 0x400000) {
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_emerg("Memory must be greater than 4MB\n");
|
2009-05-26 22:30:12 +08:00
|
|
|
machine_restart(NULL);
|
|
|
|
}
|
2010-02-08 23:41:38 +08:00
|
|
|
|
|
|
|
if ((u32) memblock.memory.regions[0].size < kernel_tlb) {
|
2012-12-27 17:40:38 +08:00
|
|
|
pr_emerg("Kernel size is greater than memory node\n");
|
2010-02-08 23:41:38 +08:00
|
|
|
machine_restart(NULL);
|
|
|
|
}
|
|
|
|
|
2009-05-26 22:30:12 +08:00
|
|
|
/* Find main memory where the kernel is */
|
2010-09-11 15:07:06 +08:00
|
|
|
memory_start = (u32) memblock.memory.regions[0].base;
|
2011-12-19 20:46:35 +08:00
|
|
|
lowmem_size = memory_size = (u32) memblock.memory.regions[0].size;
|
|
|
|
|
|
|
|
if (lowmem_size > CONFIG_LOWMEM_SIZE) {
|
|
|
|
lowmem_size = CONFIG_LOWMEM_SIZE;
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifndef CONFIG_HIGHMEM
|
2011-12-19 20:46:35 +08:00
|
|
|
memory_size = lowmem_size;
|
2011-12-15 22:02:37 +08:00
|
|
|
#endif
|
2011-12-19 20:46:35 +08:00
|
|
|
}
|
2009-05-26 22:30:12 +08:00
|
|
|
|
|
|
|
mm_cmdline_setup(); /* FIXME parse args from command line - not used */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map out the kernel text/data/bss from the available physical
|
|
|
|
* memory.
|
|
|
|
*/
|
|
|
|
kstart = __pa(CONFIG_KERNEL_START); /* kernel start */
|
|
|
|
/* kernel size */
|
|
|
|
ksize = PAGE_ALIGN(((u32)_end - (u32)CONFIG_KERNEL_START));
|
2010-07-12 12:36:09 +08:00
|
|
|
memblock_reserve(kstart, ksize);
|
2009-05-26 22:30:12 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_BLK_DEV_INITRD)
|
|
|
|
/* Remove the init RAM disk from the available memory. */
|
2013-05-02 21:53:51 +08:00
|
|
|
if (initrd_start) {
|
|
|
|
unsigned long size;
|
|
|
|
size = initrd_end - initrd_start;
|
2013-02-07 22:12:24 +08:00
|
|
|
memblock_reserve(__virt_to_phys(initrd_start), size);
|
2013-05-02 21:53:51 +08:00
|
|
|
}
|
2009-05-26 22:30:12 +08:00
|
|
|
#endif /* CONFIG_BLK_DEV_INITRD */
|
|
|
|
|
|
|
|
/* Initialize the MMU hardware */
|
|
|
|
mmu_init_hw();
|
|
|
|
|
|
|
|
/* Map in all of RAM starting at CONFIG_KERNEL_START */
|
|
|
|
mapin_ram();
|
|
|
|
|
2011-12-15 21:33:32 +08:00
|
|
|
/* Extend vmalloc and ioremap area as big as possible */
|
2011-12-15 22:02:37 +08:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
ioremap_base = ioremap_bot = PKMAP_BASE;
|
|
|
|
#else
|
2011-12-15 21:33:32 +08:00
|
|
|
ioremap_base = ioremap_bot = FIXADDR_START;
|
2011-12-15 22:02:37 +08:00
|
|
|
#endif
|
2011-12-15 21:33:32 +08:00
|
|
|
|
2009-05-26 22:30:12 +08:00
|
|
|
/* Initialize the context management stuff */
|
|
|
|
mmu_context_init();
|
2011-12-19 20:46:35 +08:00
|
|
|
|
|
|
|
/* Shortly after that, the entire linear mapping will be available */
|
|
|
|
/* This will also cause that unflatten device tree will be allocated
|
|
|
|
* inside 768MB limit */
|
|
|
|
memblock_set_current_limit(memory_start + lowmem_size - 1);
|
2009-05-26 22:30:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is only called until mem_init is done. */
|
|
|
|
void __init *early_get_page(void)
|
|
|
|
{
|
2018-03-09 23:54:07 +08:00
|
|
|
/*
|
|
|
|
* Mem start + kernel_tlb -> here is limit
|
|
|
|
* because of mem mapping from head.S
|
|
|
|
*/
|
|
|
|
return __va(memblock_alloc_base(PAGE_SIZE, PAGE_SIZE,
|
|
|
|
memory_start + kernel_tlb));
|
2009-05-26 22:30:12 +08:00
|
|
|
}
|
2010-01-15 00:03:49 +08:00
|
|
|
|
2010-01-20 22:17:08 +08:00
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
|
2016-08-03 05:03:33 +08:00
|
|
|
void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
|
2010-01-15 00:03:49 +08:00
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
if (mem_init_done)
|
|
|
|
p = kzalloc(size, mask);
|
|
|
|
else {
|
2018-10-31 06:09:09 +08:00
|
|
|
p = memblock_alloc(size, 0);
|
2010-01-15 00:03:49 +08:00
|
|
|
if (p)
|
|
|
|
memset(p, 0, size);
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|