blob: 3a7279c1ce5e7eb5ed857f6d7bf442920c12860c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/init.c
3 *
Russell King90072052005-10-28 14:48:37 +01004 * Copyright (C) 1995-2005 Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/swap.h>
13#include <linux/init.h>
14#include <linux/bootmem.h>
15#include <linux/mman.h>
16#include <linux/nodemask.h>
17#include <linux/initrd.h>
Nicolas Pitre3835f6c2008-09-17 15:21:55 -040018#include <linux/highmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/mach-types.h>
Russell King37efe642008-12-01 11:53:07 +000021#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/setup.h>
Russell King74d02fb2006-04-04 21:47:43 +010023#include <asm/sizes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/tlb.h>
25
26#include <asm/mach/arch.h>
27#include <asm/mach/map.h>
28
Russell King1b2e2b72006-08-21 17:06:38 +010029#include "mm.h"
30
Russell King012d1f42008-09-06 10:57:03 +010031static unsigned long phys_initrd_start __initdata = 0;
32static unsigned long phys_initrd_size __initdata = 0;
33
34static void __init early_initrd(char **p)
35{
36 unsigned long start, size;
37
38 start = memparse(*p, p);
39 if (**p == ',') {
40 size = memparse((*p) + 1, p);
41
42 phys_initrd_start = start;
43 phys_initrd_size = size;
44 }
45}
46__early_param("initrd=", early_initrd);
47
48static int __init parse_tag_initrd(const struct tag *tag)
49{
50 printk(KERN_WARNING "ATAG_INITRD is deprecated; "
51 "please update your bootloader.\n");
52 phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
53 phys_initrd_size = tag->u.initrd.size;
54 return 0;
55}
56
57__tagtable(ATAG_INITRD, parse_tag_initrd);
58
59static int __init parse_tag_initrd2(const struct tag *tag)
60{
61 phys_initrd_start = tag->u.initrd.start;
62 phys_initrd_size = tag->u.initrd.size;
63 return 0;
64}
65
66__tagtable(ATAG_INITRD2, parse_tag_initrd2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040069 * This keeps memory configuration data used by a couple memory
70 * initialization functions, as well as show_mem() for the skipping
71 * of holes in the memory map. It is populated by arm_add_memory().
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040073struct meminfo meminfo;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075void show_mem(void)
76{
77 int free = 0, total = 0, reserved = 0;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010078 int shared = 0, cached = 0, slab = 0, node, i;
79 struct meminfo * mi = &meminfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 printk("Mem-info:\n");
82 show_free_areas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 for_each_online_node(node) {
Russell King204ecae2007-01-16 14:01:47 +000084 pg_data_t *n = NODE_DATA(node);
Russell Kingb7a69ac2008-10-01 16:58:32 +010085 struct page *map = pgdat_page_nr(n, 0) - n->node_start_pfn;
Russell King204ecae2007-01-16 14:01:47 +000086
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010087 for_each_nodebank (i,mi,node) {
Russell Kingd2a38ef2008-10-01 16:56:15 +010088 struct membank *bank = &mi->bank[i];
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010089 unsigned int pfn1, pfn2;
90 struct page *page, *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Russell Kingd2a38ef2008-10-01 16:56:15 +010092 pfn1 = bank_pfn_start(bank);
93 pfn2 = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Russell King204ecae2007-01-16 14:01:47 +000095 page = map + pfn1;
96 end = map + pfn2;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010097
98 do {
99 total++;
100 if (PageReserved(page))
101 reserved++;
102 else if (PageSwapCache(page))
103 cached++;
104 else if (PageSlab(page))
105 slab++;
106 else if (!page_count(page))
107 free++;
108 else
109 shared += page_count(page) - 1;
110 page++;
111 } while (page < end);
112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114
115 printk("%d pages of RAM\n", total);
116 printk("%d free pages\n", free);
117 printk("%d reserved pages\n", reserved);
118 printk("%d slab pages\n", slab);
119 printk("%d pages shared\n", shared);
120 printk("%d pages swap cached\n", cached);
121}
122
Russell Kingdde58282009-08-15 12:36:00 +0100123static void __init find_node_limits(int node, struct meminfo *mi,
124 unsigned long *min, unsigned long *max_low, unsigned long *max_high)
125{
126 int i;
127
128 *min = -1UL;
129 *max_low = *max_high = 0;
130
131 for_each_nodebank(i, mi, node) {
132 struct membank *bank = &mi->bank[i];
133 unsigned long start, end;
134
135 start = bank_pfn_start(bank);
136 end = bank_pfn_end(bank);
137
138 if (*min > start)
139 *min = start;
140 if (*max_high < end)
141 *max_high = end;
142 if (bank->highmem)
143 continue;
144 if (*max_low < end)
145 *max_low = end;
146 }
147}
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/*
150 * FIXME: We really want to avoid allocating the bootmap bitmap
151 * over the top of the initrd. Hopefully, this is located towards
152 * the start of a bank, so if we allocate the bootmap bitmap at
153 * the end, we won't clash.
154 */
155static unsigned int __init
156find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
157{
Russell Kingd2a38ef2008-10-01 16:56:15 +0100158 unsigned int start_pfn, i, bootmap_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Russell King37efe642008-12-01 11:53:07 +0000160 start_pfn = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 bootmap_pfn = 0;
162
Russell Kingd2a38ef2008-10-01 16:56:15 +0100163 for_each_nodebank(i, mi, node) {
164 struct membank *bank = &mi->bank[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 unsigned int start, end;
166
Russell Kingd2a38ef2008-10-01 16:56:15 +0100167 start = bank_pfn_start(bank);
168 end = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 if (end < start_pfn)
171 continue;
172
173 if (start < start_pfn)
174 start = start_pfn;
175
176 if (end <= start)
177 continue;
178
179 if (end - start >= bootmap_pages) {
180 bootmap_pfn = start;
181 break;
182 }
183 }
184
185 if (bootmap_pfn == 0)
186 BUG();
187
188 return bootmap_pfn;
189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static int __init check_initrd(struct meminfo *mi)
192{
193 int initrd_node = -2;
194#ifdef CONFIG_BLK_DEV_INITRD
195 unsigned long end = phys_initrd_start + phys_initrd_size;
196
197 /*
198 * Make sure that the initrd is within a valid area of
199 * memory.
200 */
201 if (phys_initrd_size) {
202 unsigned int i;
203
204 initrd_node = -1;
205
206 for (i = 0; i < mi->nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100207 struct membank *bank = &mi->bank[i];
208 if (bank_phys_start(bank) <= phys_initrd_start &&
209 end <= bank_phys_end(bank))
210 initrd_node = bank->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212 }
213
214 if (initrd_node == -1) {
Russell Kingb962a282008-07-30 21:24:56 +0100215 printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 "physical memory - disabling initrd\n",
Russell Kingb962a282008-07-30 21:24:56 +0100217 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 phys_initrd_start = phys_initrd_size = 0;
219 }
220#endif
221
222 return initrd_node;
223}
224
Russell King456335e2006-09-27 10:00:54 +0100225static inline void map_memory_bank(struct membank *bank)
226{
Russell Kingd111e8f2006-09-27 15:27:33 +0100227#ifdef CONFIG_MMU
Russell King456335e2006-09-27 10:00:54 +0100228 struct map_desc map;
229
Russell Kingd2a38ef2008-10-01 16:56:15 +0100230 map.pfn = bank_pfn_start(bank);
231 map.virtual = __phys_to_virt(bank_phys_start(bank));
232 map.length = bank_phys_size(bank);
Russell King456335e2006-09-27 10:00:54 +0100233 map.type = MT_MEMORY;
234
235 create_mapping(&map);
Russell Kingd111e8f2006-09-27 15:27:33 +0100236#endif
Russell King456335e2006-09-27 10:00:54 +0100237}
238
Russell Kingdde58282009-08-15 12:36:00 +0100239static void __init bootmem_init_node(int node, struct meminfo *mi,
240 unsigned long start_pfn, unsigned long end_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Russell Kingdde58282009-08-15 12:36:00 +0100242 unsigned long boot_pfn;
Russell King90072052005-10-28 14:48:37 +0100243 unsigned int boot_pages;
244 pg_data_t *pgdat;
245 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 /*
Russell Kingdde58282009-08-15 12:36:00 +0100248 * Map the memory banks for this node.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 */
Russell King90072052005-10-28 14:48:37 +0100250 for_each_nodebank(i, mi, node) {
Russell King456335e2006-09-27 10:00:54 +0100251 struct membank *bank = &mi->bank[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Russell Kingdde58282009-08-15 12:36:00 +0100253 if (!bank->highmem)
254 map_memory_bank(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 }
256
Russell King90072052005-10-28 14:48:37 +0100257 /*
Russell King90072052005-10-28 14:48:37 +0100258 * Allocate the bootmem bitmap page.
259 */
260 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
261 boot_pfn = find_bootmap_pfn(node, mi, boot_pages);
262
263 /*
264 * Initialise the bootmem allocator for this node, handing the
265 * memory banks over to bootmem.
266 */
267 node_set_online(node);
268 pgdat = NODE_DATA(node);
269 init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);
270
Russell Kingd2a38ef2008-10-01 16:56:15 +0100271 for_each_nodebank(i, mi, node) {
272 struct membank *bank = &mi->bank[i];
Russell Kingdde58282009-08-15 12:36:00 +0100273 if (!bank->highmem)
274 free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank));
Russell Kingb7a69ac2008-10-01 16:58:32 +0100275 memory_present(node, bank_pfn_start(bank), bank_pfn_end(bank));
Russell Kingd2a38ef2008-10-01 16:56:15 +0100276 }
Russell King90072052005-10-28 14:48:37 +0100277
278 /*
279 * Reserve the bootmem bitmap for this node.
280 */
281 reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800282 boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
Russell Kingb7a69ac2008-10-01 16:58:32 +0100283}
Russell Kingb962a282008-07-30 21:24:56 +0100284
Russell Kingb7a69ac2008-10-01 16:58:32 +0100285static void __init bootmem_reserve_initrd(int node)
286{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingb7a69ac2008-10-01 16:58:32 +0100288 pg_data_t *pgdat = NODE_DATA(node);
289 int res;
Russell Kingb962a282008-07-30 21:24:56 +0100290
Russell Kingb7a69ac2008-10-01 16:58:32 +0100291 res = reserve_bootmem_node(pgdat, phys_initrd_start,
292 phys_initrd_size, BOOTMEM_EXCLUSIVE);
293
294 if (res == 0) {
295 initrd_start = __phys_to_virt(phys_initrd_start);
296 initrd_end = initrd_start + phys_initrd_size;
297 } else {
298 printk(KERN_ERR
299 "INITRD: 0x%08lx+0x%08lx overlaps in-use "
300 "memory region - disabling initrd\n",
301 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303#endif
Russell Kingb7a69ac2008-10-01 16:58:32 +0100304}
305
306static void __init bootmem_free_node(int node, struct meminfo *mi)
307{
308 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
Russell Kingdde58282009-08-15 12:36:00 +0100309 unsigned long min, max_low, max_high;
Russell Kingb7a69ac2008-10-01 16:58:32 +0100310 int i;
311
Russell Kingdde58282009-08-15 12:36:00 +0100312 find_node_limits(node, mi, &min, &max_low, &max_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Russell King90072052005-10-28 14:48:37 +0100314 /*
Russell King90072052005-10-28 14:48:37 +0100315 * initialise the zones within this node.
316 */
317 memset(zone_size, 0, sizeof(zone_size));
Russell King90072052005-10-28 14:48:37 +0100318
319 /*
320 * The size of this node has already been determined. If we need
321 * to do anything fancy with the allocation of this memory to the
322 * zones, now is the time to do it.
323 */
Russell Kingdde58282009-08-15 12:36:00 +0100324 zone_size[0] = max_low - min;
325#ifdef CONFIG_HIGHMEM
326 zone_size[ZONE_HIGHMEM] = max_high - max_low;
327#endif
Russell King90072052005-10-28 14:48:37 +0100328
329 /*
330 * For each bank in this node, calculate the size of the holes.
331 * holes = node_size - sum(bank_sizes_in_node)
332 */
Russell Kingdde58282009-08-15 12:36:00 +0100333 memcpy(zhole_size, zone_size, sizeof(zhole_size));
334 for_each_nodebank(i, mi, node) {
335 int idx = 0;
336#ifdef CONFIG_HIGHMEM
337 if (mi->bank[i].highmem)
338 idx = ZONE_HIGHMEM;
339#endif
340 zhole_size[idx] -= bank_pfn_size(&mi->bank[i]);
341 }
Russell King90072052005-10-28 14:48:37 +0100342
343 /*
344 * Adjust the sizes according to any special requirements for
345 * this machine type.
346 */
347 arch_adjust_zones(node, zone_size, zhole_size);
348
Russell Kingdde58282009-08-15 12:36:00 +0100349 free_area_init_node(node, zone_size, min, zhole_size);
Russell King90072052005-10-28 14:48:37 +0100350}
351
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400352void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100353{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400354 struct meminfo *mi = &meminfo;
Russell Kingdde58282009-08-15 12:36:00 +0100355 unsigned long min, max_low, max_high;
Russell Kingeca73212008-09-30 19:29:25 +0100356 int node, initrd_node;
Russell King90072052005-10-28 14:48:37 +0100357
Russell King90072052005-10-28 14:48:37 +0100358 /*
359 * Locate which node contains the ramdisk image, if any.
360 */
361 initrd_node = check_initrd(mi);
362
Russell Kingdde58282009-08-15 12:36:00 +0100363 max_low = max_high = 0;
364
Russell King90072052005-10-28 14:48:37 +0100365 /*
366 * Run through each node initialising the bootmem allocator.
367 */
368 for_each_node(node) {
Russell Kingdde58282009-08-15 12:36:00 +0100369 unsigned long node_low, node_high;
370
371 find_node_limits(node, mi, &min, &node_low, &node_high);
372
373 if (node_low > max_low)
374 max_low = node_low;
375 if (node_high > max_high)
376 max_high = node_high;
377
378 /*
379 * If there is no memory in this node, ignore it.
380 * (We can't have nodes which have no lowmem)
381 */
382 if (node_low == 0)
383 continue;
384
385 bootmem_init_node(node, mi, min, node_low);
Russell King90072052005-10-28 14:48:37 +0100386
Russell Kingb7a69ac2008-10-01 16:58:32 +0100387 /*
388 * Reserve any special node zero regions.
389 */
390 if (node == 0)
391 reserve_node_zero(NODE_DATA(node));
392
393 /*
394 * If the initrd is in this node, reserve its memory.
395 */
396 if (node == initrd_node)
397 bootmem_reserve_initrd(node);
Russell King90072052005-10-28 14:48:37 +0100398 }
399
Russell Kingb7a69ac2008-10-01 16:58:32 +0100400 /*
401 * sparse_init() needs the bootmem allocator up and running.
402 */
403 sparse_init();
404
405 /*
406 * Now free memory in each node - free_area_init_node needs
407 * the sparse mem_map arrays initialized by sparse_init()
408 * for memmap_init_zone(), otherwise all PFNs are invalid.
409 */
410 for_each_node(node)
411 bootmem_free_node(node, mi);
412
Russell Kingdde58282009-08-15 12:36:00 +0100413 high_memory = __va((max_low << PAGE_SHIFT) - 1) + 1;
Russell King90072052005-10-28 14:48:37 +0100414
415 /*
416 * This doesn't seem to be used by the Linux memory manager any
417 * more, but is used by ll_rw_block. If we can get rid of it, we
418 * also get rid of some of the stuff above as well.
419 *
420 * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
421 * the system, not the maximum PFN.
422 */
Russell Kingdde58282009-08-15 12:36:00 +0100423 max_low_pfn = max_low - PHYS_PFN_OFFSET;
424 max_pfn = max_high - PHYS_PFN_OFFSET;
Russell King90072052005-10-28 14:48:37 +0100425}
426
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400427static inline int free_area(unsigned long pfn, unsigned long end, char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400429 unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400431 for (; pfn < end; pfn++) {
432 struct page *page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800434 init_page_count(page);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400435 __free_page(page);
436 pages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
439 if (size && s)
440 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400441
442 return pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
Russell Kinga0130532005-06-27 14:16:47 +0100445static inline void
446free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
447{
448 struct page *start_pg, *end_pg;
449 unsigned long pg, pgend;
450
451 /*
452 * Convert start_pfn/end_pfn to a struct page pointer.
453 */
454 start_pg = pfn_to_page(start_pfn);
455 end_pg = pfn_to_page(end_pfn);
456
457 /*
458 * Convert to physical addresses, and
459 * round start upwards and end downwards.
460 */
461 pg = PAGE_ALIGN(__pa(start_pg));
462 pgend = __pa(end_pg) & PAGE_MASK;
463
464 /*
465 * If there are free pages between these,
466 * free the section of the memmap array.
467 */
468 if (pg < pgend)
469 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
470}
471
472/*
473 * The mem_map array can get very big. Free the unused area of the memory map.
474 */
475static void __init free_unused_memmap_node(int node, struct meminfo *mi)
476{
477 unsigned long bank_start, prev_bank_end = 0;
478 unsigned int i;
479
480 /*
481 * [FIXME] This relies on each bank being in address order. This
482 * may not be the case, especially if the user has provided the
483 * information on the command line.
484 */
Russell King90072052005-10-28 14:48:37 +0100485 for_each_nodebank(i, mi, node) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100486 struct membank *bank = &mi->bank[i];
487
488 bank_start = bank_pfn_start(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100489 if (bank_start < prev_bank_end) {
490 printk(KERN_ERR "MEM: unordered memory banks. "
491 "Not freeing memmap.\n");
492 break;
493 }
494
495 /*
496 * If we had a previous bank, and there is a space
497 * between the current bank and the previous, free it.
498 */
499 if (prev_bank_end && prev_bank_end != bank_start)
500 free_memmap(node, prev_bank_end, bank_start);
501
Russell Kingd2a38ef2008-10-01 16:56:15 +0100502 prev_bank_end = bank_pfn_end(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100503 }
504}
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506/*
507 * mem_init() marks the free areas in the mem_map and tells us how much
508 * memory is free. This is done after various parts of the system have
509 * claimed their memory after the kernel image.
510 */
511void __init mem_init(void)
512{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400513 unsigned int codesize, datasize, initsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 int i, node;
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#ifndef CONFIG_DISCONTIGMEM
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400517 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#endif
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* this will put all unused low memory onto the freelists */
521 for_each_online_node(node) {
522 pg_data_t *pgdat = NODE_DATA(node);
523
Russell Kinga0130532005-06-27 14:16:47 +0100524 free_unused_memmap_node(node, &meminfo);
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (pgdat->node_spanned_pages != 0)
527 totalram_pages += free_all_bootmem_node(pgdat);
528 }
529
530#ifdef CONFIG_SA1111
531 /* now that our DMA memory is actually so designated, we can free it */
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400532 totalram_pages += free_area(PHYS_PFN_OFFSET,
533 __phys_to_pfn(__pa(swapper_pg_dir)), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#endif
535
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400536#ifdef CONFIG_HIGHMEM
537 /* set highmem page free */
538 for_each_online_node(node) {
539 for_each_nodebank (i, &meminfo, node) {
540 unsigned long start = bank_pfn_start(&meminfo.bank[i]);
541 unsigned long end = bank_pfn_end(&meminfo.bank[i]);
542 if (start >= max_low_pfn + PHYS_PFN_OFFSET)
543 totalhigh_pages += free_area(start, end, NULL);
544 }
545 }
546 totalram_pages += totalhigh_pages;
547#endif
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /*
550 * Since our memory may not be contiguous, calculate the
551 * real number of pages we have in this system
552 */
553 printk(KERN_INFO "Memory:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 num_physpages = 0;
555 for (i = 0; i < meminfo.nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100556 num_physpages += bank_pfn_size(&meminfo.bank[i]);
557 printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400560
Russell King37efe642008-12-01 11:53:07 +0000561 codesize = _etext - _text;
562 datasize = _end - _data;
563 initsize = __init_end - __init_begin;
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 printk(KERN_NOTICE "Memory: %luKB available (%dK code, "
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400566 "%dK data, %dK init, %luK highmem)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400568 codesize >> 10, datasize >> 10, initsize >> 10,
569 (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
572 extern int sysctl_overcommit_memory;
573 /*
574 * On a machine this small we won't get
575 * anywhere without overcommit, so turn
576 * it on by default.
577 */
578 sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
579 }
580}
581
582void free_initmem(void)
583{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400584 if (!machine_is_integrator() && !machine_is_cintegrator())
Russell King37efe642008-12-01 11:53:07 +0000585 totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)),
586 __phys_to_pfn(__pa(__init_end)),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400587 "init");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
590#ifdef CONFIG_BLK_DEV_INITRD
591
592static int keep_initrd;
593
594void free_initrd_mem(unsigned long start, unsigned long end)
595{
596 if (!keep_initrd)
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400597 totalram_pages += free_area(__phys_to_pfn(__pa(start)),
598 __phys_to_pfn(__pa(end)),
599 "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
602static int __init keepinitrd_setup(char *__unused)
603{
604 keep_initrd = 1;
605 return 1;
606}
607
608__setup("keepinitrd", keepinitrd_setup);
609#endif