11199692d8
Change signature of free_reserved_area() according to Russell King's suggestion to fix following build warnings: arch/arm/mm/init.c: In function 'mem_init': arch/arm/mm/init.c:603:2: warning: passing argument 1 of 'free_reserved_area' makes integer from pointer without a cast [enabled by default] free_reserved_area(__va(PHYS_PFN_OFFSET), swapper_pg_dir, 0, NULL); ^ In file included from include/linux/mman.h:4:0, from arch/arm/mm/init.c:15: include/linux/mm.h:1301:22: note: expected 'long unsigned int' but argument is of type 'void *' extern unsigned long free_reserved_area(unsigned long start, unsigned long end, mm/page_alloc.c: In function 'free_reserved_area': >> mm/page_alloc.c:5134:3: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast [enabled by default] In file included from arch/mips/include/asm/page.h:49:0, from include/linux/mmzone.h:20, from include/linux/gfp.h:4, from include/linux/mm.h:8, from mm/page_alloc.c:18: arch/mips/include/asm/io.h:119:29: note: expected 'const volatile void *' but argument is of type 'long unsigned int' mm/page_alloc.c: In function 'free_area_init_nodes': mm/page_alloc.c:5030:34: warning: array subscript is below array bounds [-Warray-bounds] Also address some minor code review comments. Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Reported-by: Arnd Bergmann <arnd@arndb.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: <sworddragon2@aol.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chris Metcalf <cmetcalf@tilera.com> Cc: David Howells <dhowells@redhat.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jeremy Fitzhardinge <jeremy@goop.org> Cc: Jianguo Wu <wujianguo@huawei.com> Cc: Joonsoo Kim <js1304@gmail.com> Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Michel Lespinasse <walken@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@redhat.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Tang Chen <tangchen@cn.fujitsu.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Wen Congyang <wency@cn.fujitsu.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Yinghai Lu <yinghai@kernel.org> Cc: Russell King <rmk@arm.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
225 lines
5.1 KiB
C
225 lines
5.1 KiB
C
/*
|
|
* 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.
|
|
*
|
|
* 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>
|
|
#include <linux/bootmem.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/mman.h>
|
|
#include <linux/nodemask.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include <asm/bootparam.h>
|
|
#include <asm/page.h>
|
|
#include <asm/sections.h>
|
|
|
|
/*
|
|
* mem_reserve(start, end, must_exist)
|
|
*
|
|
* Reserve some memory from the memory pool.
|
|
*
|
|
* Parameters:
|
|
* start Start of region,
|
|
* end End of region,
|
|
* must_exist Must exist in memory pool.
|
|
*
|
|
* Returns:
|
|
* 0 (memory area couldn't be mapped)
|
|
* -1 (success)
|
|
*/
|
|
|
|
int __init mem_reserve(unsigned long start, unsigned long end, int must_exist)
|
|
{
|
|
int i;
|
|
|
|
if (start == end)
|
|
return 0;
|
|
|
|
start = start & PAGE_MASK;
|
|
end = PAGE_ALIGN(end);
|
|
|
|
for (i = 0; i < sysmem.nr_banks; i++)
|
|
if (start < sysmem.bank[i].end
|
|
&& end >= sysmem.bank[i].start)
|
|
break;
|
|
|
|
if (i == sysmem.nr_banks) {
|
|
if (must_exist)
|
|
printk (KERN_WARNING "mem_reserve: [0x%0lx, 0x%0lx) "
|
|
"not in any region!\n", start, end);
|
|
return 0;
|
|
}
|
|
|
|
if (start > sysmem.bank[i].start) {
|
|
if (end < sysmem.bank[i].end) {
|
|
/* split entry */
|
|
if (sysmem.nr_banks >= SYSMEM_BANKS_MAX)
|
|
panic("meminfo overflow\n");
|
|
sysmem.bank[sysmem.nr_banks].start = end;
|
|
sysmem.bank[sysmem.nr_banks].end = sysmem.bank[i].end;
|
|
sysmem.nr_banks++;
|
|
}
|
|
sysmem.bank[i].end = start;
|
|
|
|
} else if (end < sysmem.bank[i].end) {
|
|
sysmem.bank[i].start = end;
|
|
|
|
} else {
|
|
/* remove entry */
|
|
sysmem.nr_banks--;
|
|
sysmem.bank[i].start = sysmem.bank[sysmem.nr_banks].start;
|
|
sysmem.bank[i].end = sysmem.bank[sysmem.nr_banks].end;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
/*
|
|
* Initialize the bootmem system and give it all the memory we have available.
|
|
*/
|
|
|
|
void __init bootmem_init(void)
|
|
{
|
|
unsigned long pfn;
|
|
unsigned long bootmap_start, bootmap_size;
|
|
int i;
|
|
|
|
max_low_pfn = max_pfn = 0;
|
|
min_low_pfn = ~0;
|
|
|
|
for (i=0; i < sysmem.nr_banks; i++) {
|
|
pfn = PAGE_ALIGN(sysmem.bank[i].start) >> PAGE_SHIFT;
|
|
if (pfn < min_low_pfn)
|
|
min_low_pfn = pfn;
|
|
pfn = PAGE_ALIGN(sysmem.bank[i].end - 1) >> PAGE_SHIFT;
|
|
if (pfn > max_pfn)
|
|
max_pfn = pfn;
|
|
}
|
|
|
|
if (min_low_pfn > max_pfn)
|
|
panic("No memory found!\n");
|
|
|
|
max_low_pfn = max_pfn < MAX_MEM_PFN >> PAGE_SHIFT ?
|
|
max_pfn : MAX_MEM_PFN >> PAGE_SHIFT;
|
|
|
|
/* Find an area to use for the bootmem bitmap. */
|
|
|
|
bootmap_size = bootmem_bootmap_pages(max_low_pfn - min_low_pfn);
|
|
bootmap_size <<= PAGE_SHIFT;
|
|
bootmap_start = ~0;
|
|
|
|
for (i=0; i<sysmem.nr_banks; i++)
|
|
if (sysmem.bank[i].end - sysmem.bank[i].start >= bootmap_size) {
|
|
bootmap_start = sysmem.bank[i].start;
|
|
break;
|
|
}
|
|
|
|
if (bootmap_start == ~0UL)
|
|
panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
|
|
|
|
/* Reserve the bootmem bitmap area */
|
|
|
|
mem_reserve(bootmap_start, bootmap_start + bootmap_size, 1);
|
|
bootmap_size = init_bootmem_node(NODE_DATA(0),
|
|
bootmap_start >> PAGE_SHIFT,
|
|
min_low_pfn,
|
|
max_low_pfn);
|
|
|
|
/* Add all remaining memory pieces into the bootmem map */
|
|
|
|
for (i=0; i<sysmem.nr_banks; i++)
|
|
free_bootmem(sysmem.bank[i].start,
|
|
sysmem.bank[i].end - sysmem.bank[i].start);
|
|
|
|
}
|
|
|
|
|
|
void __init zones_init(void)
|
|
{
|
|
unsigned long zones_size[MAX_NR_ZONES];
|
|
int i;
|
|
|
|
/* All pages are DMA-able, so we put them all in the DMA zone. */
|
|
|
|
zones_size[ZONE_DMA] = max_low_pfn - ARCH_PFN_OFFSET;
|
|
for (i = 1; i < MAX_NR_ZONES; i++)
|
|
zones_size[i] = 0;
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
zones_size[ZONE_HIGHMEM] = max_pfn - max_low_pfn;
|
|
#endif
|
|
|
|
free_area_init_node(0, zones_size, ARCH_PFN_OFFSET, NULL);
|
|
}
|
|
|
|
/*
|
|
* Initialize memory pages.
|
|
*/
|
|
|
|
void __init mem_init(void)
|
|
{
|
|
unsigned long codesize, reservedpages, datasize, initsize;
|
|
unsigned long highmemsize, tmp, ram;
|
|
|
|
max_mapnr = num_physpages = max_low_pfn - ARCH_PFN_OFFSET;
|
|
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
|
|
highmemsize = 0;
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
#error HIGHGMEM not implemented in init.c
|
|
#endif
|
|
|
|
totalram_pages += free_all_bootmem();
|
|
|
|
reservedpages = ram = 0;
|
|
for (tmp = 0; tmp < max_mapnr; tmp++) {
|
|
ram++;
|
|
if (PageReserved(mem_map+tmp))
|
|
reservedpages++;
|
|
}
|
|
|
|
codesize = (unsigned long) _etext - (unsigned long) _stext;
|
|
datasize = (unsigned long) _edata - (unsigned long) _sdata;
|
|
initsize = (unsigned long) __init_end - (unsigned long) __init_begin;
|
|
|
|
printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, "
|
|
"%ldk data, %ldk init %ldk highmem)\n",
|
|
nr_free_pages() << (PAGE_SHIFT-10),
|
|
ram << (PAGE_SHIFT-10),
|
|
codesize >> 10,
|
|
reservedpages << (PAGE_SHIFT-10),
|
|
datasize >> 10,
|
|
initsize >> 10,
|
|
highmemsize >> 10);
|
|
}
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
extern int initrd_is_mapped;
|
|
|
|
void free_initrd_mem(unsigned long start, unsigned long end)
|
|
{
|
|
if (initrd_is_mapped)
|
|
free_reserved_area((void *)start, (void *)end, 0, "initrd");
|
|
}
|
|
#endif
|
|
|
|
void free_initmem(void)
|
|
{
|
|
free_initmem_default(0);
|
|
}
|