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>
29 #include <linux/module.h>
30 #include <linux/pfn.h>
31 #include <linux/proc_fs.h>
32 #include <linux/string.h>
33 #include <linux/swap.h>
35 #include <asm/bootinfo.h>
37 #include <asm/sections.h>
39 #include <asm/mips-boards/prom.h>
41 static int __init
memsize(void)
43 u32 size
= (64 << 20);
44 volatile u32
*addr
= (u32
*)KSEG1ADDR(0x14000000 + size
- 4);
45 u32
*kernel_end
= (u32
*)KSEG1ADDR(CPHYSADDR((u32
)&_end
));
47 while (addr
> kernel_end
) {
55 if (*addr
!= (u32
)addr
)
58 } while (size
< (64 << 20));
63 #ifdef CONFIG_NEED_MULTIPLE_NODES
64 static bootmem_data_t node_bootmem_data
;
65 pg_data_t __node_data
[1] = {
67 .bdata
= &node_bootmem_data
70 EXPORT_SYMBOL(__node_data
);
72 unsigned long max_mapnr
;
74 EXPORT_SYMBOL(max_mapnr
);
75 EXPORT_SYMBOL(mem_map
);
77 static unsigned long setup_zero_pages(void)
79 unsigned int order
= 3;
83 empty_zero_page
= __get_free_pages(GFP_KERNEL
| __GFP_ZERO
, order
);
85 panic("Oh boy, that early out of memory?");
87 page
= virt_to_page(empty_zero_page
);
88 split_page(page
, order
);
89 while (page
< virt_to_page(empty_zero_page
+ (PAGE_SIZE
<< order
))) {
90 SetPageReserved(page
);
94 size
= PAGE_SIZE
<< order
;
95 zero_page_mask
= (size
- 1) & PAGE_MASK
;
100 extern void pagetable_init(void);
102 void __init
paging_init(void)
104 unsigned long zones_size
[MAX_NR_ZONES
] = { 0, };
108 zones_size
[ZONE_DMA
] = max_low_pfn
- min_low_pfn
;
110 free_area_init_node(0, NODE_DATA(0), zones_size
, ARCH_PFN_OFFSET
, NULL
);
113 static struct kcore_list kcore_mem
, kcore_vmalloc
;
115 void __init
mem_init(void)
117 unsigned long codesize
, reservedpages
, datasize
, initsize
;
118 unsigned long tmp
, ram
;
119 unsigned long kernel_start
, kernel_end
;
121 kernel_start
= PFN_DOWN(CPHYSADDR((unsigned long)&_text
));
122 kernel_end
= PFN_UP(CPHYSADDR((unsigned long)&_end
));
123 for (tmp
= min_low_pfn
+ 1; tmp
< kernel_start
; tmp
++) {
124 ClearPageReserved(pfn_to_page(tmp
));
125 init_page_count(pfn_to_page(tmp
));
126 free_page((unsigned long)__va(tmp
<< PAGE_SHIFT
));
129 totalram_pages
+= free_all_bootmem();
130 totalram_pages
-= setup_zero_pages(); /* Setup zeroed pages. */
132 reservedpages
= ram
= 0;
133 for (tmp
= min_low_pfn
; tmp
<= max_low_pfn
; tmp
++) {
135 if (PageReserved(pfn_to_page(tmp
)))
136 if ((tmp
< kernel_start
) || (tmp
> kernel_end
))
141 codesize
= (unsigned long) &_etext
- (unsigned long) &_text
;
142 datasize
= (unsigned long) &_edata
- (unsigned long) &_etext
;
143 initsize
= (unsigned long) &__init_end
- (unsigned long) &__init_begin
;
145 kclist_add(&kcore_mem
, __va(min_low_pfn
),
146 (max_low_pfn
- min_low_pfn
) << PAGE_SHIFT
);
147 kclist_add(&kcore_vmalloc
, (void *)VMALLOC_START
,
148 VMALLOC_END
- VMALLOC_START
);
150 printk(KERN_INFO
"Memory: %luk/%luk available (%ldk kernel code, "
151 "%ldk reserved, %ldk data, %ldk init)\n",
152 (unsigned long) nr_free_pages() << (PAGE_SHIFT
-10),
153 ram
<< (PAGE_SHIFT
-10),
155 reservedpages
<< (PAGE_SHIFT
-10),
161 void __init
prom_meminit(void)
164 #ifdef CONFIG_NEED_MULTIPLE_NODES
165 unsigned long kernel_start
, kernel_end
;
166 unsigned long free_pages
;
167 unsigned long bootmap_size
;
170 pages
= memsize() >> PAGE_SHIFT
;
171 add_memory_region(ARCH_PFN_OFFSET
<< PAGE_SHIFT
, pages
<<
172 PAGE_SHIFT
, BOOT_MEM_RAM
);
174 #ifdef CONFIG_NEED_MULTIPLE_NODES
175 kernel_start
= PFN_DOWN(CPHYSADDR((unsigned long)&_text
));
176 kernel_end
= PFN_UP(CPHYSADDR((unsigned long)&_end
));
177 min_low_pfn
= ARCH_PFN_OFFSET
;
178 max_low_pfn
= ARCH_PFN_OFFSET
+ pages
;
179 max_mapnr
= max_low_pfn
;
180 free_pages
= pages
- (kernel_end
- min_low_pfn
);
181 bootmap_size
= init_bootmem_node(NODE_DATA(0), kernel_end
,
182 ARCH_PFN_OFFSET
, max_low_pfn
);
184 free_bootmem(PFN_PHYS(kernel_end
), free_pages
<< PAGE_SHIFT
);
185 memory_present(0, min_low_pfn
, max_low_pfn
);
186 reserve_bootmem(PFN_PHYS(kernel_end
), bootmap_size
);
187 mem_map
= NODE_DATA(0)->node_mem_map
;
191 void __init
prom_free_prom_memory(void)