4 * Copyright (C) 2007 OpenWrt.org
6 * Based on arch/mips/mm/init.c
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
10 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/bootmem.h>
27 #include <linux/init.h>
28 #include <linux/initrd.h>
30 #include <linux/module.h>
31 #include <linux/pfn.h>
32 #include <linux/proc_fs.h>
33 #include <linux/string.h>
34 #include <linux/swap.h>
36 #include <asm/bootinfo.h>
38 #include <asm/sections.h>
40 #include <asm/mips-boards/prom.h>
42 #warning FIXME: use sdram control regs and/or autodetection
43 static int __init memsize(void)
47 char cmdline[CL_SIZE], *ptr;
49 /* Check the command line first for a memsize directive */
50 strcpy(cmdline, arcs_cmdline);
51 ptr = strstr(cmdline, "memsize=");
52 if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
53 ptr = strstr(ptr, " memsize=");
56 result = memparse(ptr + 8, &ptr);
58 /* otherwise look in the environment */
59 memsize_str = prom_getenv("memsize");
61 prom_printf("memsize not set in boot prom, set to default (8Mb)\n");
64 result = simple_strtol(memsize_str, NULL, 0);
71 extern unsigned long __initramfs_start, __initramfs_end;
73 #ifdef CONFIG_NEED_MULTIPLE_NODES
74 static bootmem_data_t node_bootmem_data;
75 pg_data_t __node_data[1] = {
77 .bdata = &node_bootmem_data
80 EXPORT_SYMBOL(__node_data);
82 unsigned long max_mapnr;
84 EXPORT_SYMBOL(max_mapnr);
85 EXPORT_SYMBOL(mem_map);
87 static unsigned long setup_zero_pages(void)
89 unsigned int order = 3;
93 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
95 panic("Oh boy, that early out of memory?");
97 page = virt_to_page(empty_zero_page);
98 split_page(page, order);
99 while (page < virt_to_page(empty_zero_page + (PAGE_SIZE << order))) {
100 SetPageReserved(page);
104 size = PAGE_SIZE << order;
105 zero_page_mask = (size - 1) & PAGE_MASK;
110 extern void pagetable_init(void);
112 void __init paging_init(void)
114 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
118 zones_size[ZONE_DMA] = max_low_pfn - min_low_pfn;
120 free_area_init_node(0, NODE_DATA(0), zones_size, ARCH_PFN_OFFSET, NULL);
123 static struct kcore_list kcore_mem, kcore_vmalloc;
125 void __init mem_init(void)
127 unsigned long codesize, reservedpages, datasize, initsize;
128 unsigned long tmp, ram;
129 unsigned long kernel_start, kernel_end;
131 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
132 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
133 for (tmp = min_low_pfn + 1; tmp < kernel_start; tmp++) {
134 ClearPageReserved(pfn_to_page(tmp));
135 init_page_count(pfn_to_page(tmp));
136 free_page((unsigned long)__va(tmp << PAGE_SHIFT));
139 totalram_pages += free_all_bootmem();
140 totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */
142 reservedpages = ram = 0;
143 for (tmp = min_low_pfn; tmp <= max_low_pfn; tmp++) {
145 if (PageReserved(pfn_to_page(tmp)))
146 if ((tmp < kernel_start) || (tmp > kernel_end))
151 codesize = (unsigned long) &_etext - (unsigned long) &_text;
152 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
153 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
155 kclist_add(&kcore_mem, __va(min_low_pfn),
156 (max_low_pfn - min_low_pfn) << PAGE_SHIFT);
157 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
158 VMALLOC_END - VMALLOC_START);
160 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
161 "%ldk reserved, %ldk data, %ldk init)\n",
162 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
163 ram << (PAGE_SHIFT-10),
165 reservedpages << (PAGE_SHIFT-10),
171 void __init prom_meminit(void)
173 #ifdef CONFIG_NEED_MULTIPLE_NODES
174 unsigned long kernel_start, kernel_end;
175 unsigned long pages, free_pages;
176 unsigned long bootmap_size;
179 #ifdef CONFIG_BLK_DEV_INITRD
180 initrd_start = (unsigned long)&__initramfs_start;
181 initrd_end = (unsigned long)&__initramfs_end;
184 pages = memsize() >> PAGE_SHIFT;
185 add_memory_region(ARCH_PFN_OFFSET << PAGE_SHIFT, pages <<
186 PAGE_SHIFT, BOOT_MEM_RAM);
188 #ifdef CONFIG_NEED_MULTIPLE_NODES
189 kernel_start = PFN_DOWN(CPHYSADDR((unsigned long)&_text));
190 kernel_end = PFN_UP(CPHYSADDR((unsigned long)&_end));
191 min_low_pfn = ARCH_PFN_OFFSET;
192 max_low_pfn = ARCH_PFN_OFFSET + pages;
193 max_mapnr = max_low_pfn;
194 free_pages = pages - (kernel_end - min_low_pfn);
195 bootmap_size = init_bootmem_node(NODE_DATA(0), kernel_end,
196 ARCH_PFN_OFFSET, max_low_pfn);
198 free_bootmem(PFN_PHYS(kernel_end), free_pages << PAGE_SHIFT);
199 memory_present(0, min_low_pfn, max_low_pfn);
200 reserve_bootmem(PFN_PHYS(kernel_end), bootmap_size);
201 mem_map = NODE_DATA(0)->node_mem_map;
205 unsigned long __init prom_free_prom_memory(void)