blob: 8277802ec85926abe0e3bd7ad6dd10fb83e987d4 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
124 * FIXME: We really want to avoid allocating the bootmap bitmap
125 * over the top of the initrd. Hopefully, this is located towards
126 * the start of a bank, so if we allocate the bootmap bitmap at
127 * the end, we won't clash.
128 */
129static unsigned int __init
130find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
131{
Russell Kingd2a38ef2008-10-01 16:56:15 +0100132 unsigned int start_pfn, i, bootmap_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Russell King37efe642008-12-01 11:53:07 +0000134 start_pfn = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 bootmap_pfn = 0;
136
Russell Kingd2a38ef2008-10-01 16:56:15 +0100137 for_each_nodebank(i, mi, node) {
138 struct membank *bank = &mi->bank[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 unsigned int start, end;
140
Russell Kingd2a38ef2008-10-01 16:56:15 +0100141 start = bank_pfn_start(bank);
142 end = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 if (end < start_pfn)
145 continue;
146
147 if (start < start_pfn)
148 start = start_pfn;
149
150 if (end <= start)
151 continue;
152
153 if (end - start >= bootmap_pages) {
154 bootmap_pfn = start;
155 break;
156 }
157 }
158
159 if (bootmap_pfn == 0)
160 BUG();
161
162 return bootmap_pfn;
163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static int __init check_initrd(struct meminfo *mi)
166{
167 int initrd_node = -2;
168#ifdef CONFIG_BLK_DEV_INITRD
169 unsigned long end = phys_initrd_start + phys_initrd_size;
170
171 /*
172 * Make sure that the initrd is within a valid area of
173 * memory.
174 */
175 if (phys_initrd_size) {
176 unsigned int i;
177
178 initrd_node = -1;
179
180 for (i = 0; i < mi->nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100181 struct membank *bank = &mi->bank[i];
182 if (bank_phys_start(bank) <= phys_initrd_start &&
183 end <= bank_phys_end(bank))
184 initrd_node = bank->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186 }
187
188 if (initrd_node == -1) {
Russell Kingb962a282008-07-30 21:24:56 +0100189 printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 "physical memory - disabling initrd\n",
Russell Kingb962a282008-07-30 21:24:56 +0100191 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 phys_initrd_start = phys_initrd_size = 0;
193 }
194#endif
195
196 return initrd_node;
197}
198
Russell King456335e2006-09-27 10:00:54 +0100199static inline void map_memory_bank(struct membank *bank)
200{
Russell Kingd111e8f2006-09-27 15:27:33 +0100201#ifdef CONFIG_MMU
Russell King456335e2006-09-27 10:00:54 +0100202 struct map_desc map;
203
Russell Kingd2a38ef2008-10-01 16:56:15 +0100204 map.pfn = bank_pfn_start(bank);
205 map.virtual = __phys_to_virt(bank_phys_start(bank));
206 map.length = bank_phys_size(bank);
Russell King456335e2006-09-27 10:00:54 +0100207 map.type = MT_MEMORY;
208
209 create_mapping(&map);
Russell Kingd111e8f2006-09-27 15:27:33 +0100210#endif
Russell King456335e2006-09-27 10:00:54 +0100211}
212
Russell Kingb7a69ac2008-10-01 16:58:32 +0100213static unsigned long __init bootmem_init_node(int node, struct meminfo *mi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Russell King90072052005-10-28 14:48:37 +0100215 unsigned long start_pfn, end_pfn, boot_pfn;
216 unsigned int boot_pages;
217 pg_data_t *pgdat;
218 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Russell King90072052005-10-28 14:48:37 +0100220 start_pfn = -1UL;
221 end_pfn = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /*
Russell King90072052005-10-28 14:48:37 +0100224 * Calculate the pfn range, and map the memory banks for this node.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 */
Russell King90072052005-10-28 14:48:37 +0100226 for_each_nodebank(i, mi, node) {
Russell King456335e2006-09-27 10:00:54 +0100227 struct membank *bank = &mi->bank[i];
Russell King90072052005-10-28 14:48:37 +0100228 unsigned long start, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Russell Kingd2a38ef2008-10-01 16:56:15 +0100230 start = bank_pfn_start(bank);
231 end = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Russell King90072052005-10-28 14:48:37 +0100233 if (start_pfn > start)
234 start_pfn = start;
235 if (end_pfn < end)
236 end_pfn = end;
237
Russell King456335e2006-09-27 10:00:54 +0100238 map_memory_bank(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
240
Russell King90072052005-10-28 14:48:37 +0100241 /*
242 * If there is no memory in this node, ignore it.
243 */
244 if (end_pfn == 0)
245 return end_pfn;
246
247 /*
248 * Allocate the bootmem bitmap page.
249 */
250 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
251 boot_pfn = find_bootmap_pfn(node, mi, boot_pages);
252
253 /*
254 * Initialise the bootmem allocator for this node, handing the
255 * memory banks over to bootmem.
256 */
257 node_set_online(node);
258 pgdat = NODE_DATA(node);
259 init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);
260
Russell Kingd2a38ef2008-10-01 16:56:15 +0100261 for_each_nodebank(i, mi, node) {
262 struct membank *bank = &mi->bank[i];
263 free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank));
Russell Kingb7a69ac2008-10-01 16:58:32 +0100264 memory_present(node, bank_pfn_start(bank), bank_pfn_end(bank));
Russell Kingd2a38ef2008-10-01 16:56:15 +0100265 }
Russell King90072052005-10-28 14:48:37 +0100266
267 /*
268 * Reserve the bootmem bitmap for this node.
269 */
270 reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800271 boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Russell Kingb7a69ac2008-10-01 16:58:32 +0100273 return end_pfn;
274}
Russell Kingb962a282008-07-30 21:24:56 +0100275
Russell Kingb7a69ac2008-10-01 16:58:32 +0100276static void __init bootmem_reserve_initrd(int node)
277{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingb7a69ac2008-10-01 16:58:32 +0100279 pg_data_t *pgdat = NODE_DATA(node);
280 int res;
Russell Kingb962a282008-07-30 21:24:56 +0100281
Russell Kingb7a69ac2008-10-01 16:58:32 +0100282 res = reserve_bootmem_node(pgdat, phys_initrd_start,
283 phys_initrd_size, BOOTMEM_EXCLUSIVE);
284
285 if (res == 0) {
286 initrd_start = __phys_to_virt(phys_initrd_start);
287 initrd_end = initrd_start + phys_initrd_size;
288 } else {
289 printk(KERN_ERR
290 "INITRD: 0x%08lx+0x%08lx overlaps in-use "
291 "memory region - disabling initrd\n",
292 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294#endif
Russell Kingb7a69ac2008-10-01 16:58:32 +0100295}
296
297static void __init bootmem_free_node(int node, struct meminfo *mi)
298{
299 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
300 unsigned long start_pfn, end_pfn;
301 pg_data_t *pgdat = NODE_DATA(node);
302 int i;
303
304 start_pfn = pgdat->bdata->node_min_pfn;
305 end_pfn = pgdat->bdata->node_low_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Russell King90072052005-10-28 14:48:37 +0100307 /*
Russell King90072052005-10-28 14:48:37 +0100308 * initialise the zones within this node.
309 */
310 memset(zone_size, 0, sizeof(zone_size));
311 memset(zhole_size, 0, sizeof(zhole_size));
312
313 /*
314 * The size of this node has already been determined. If we need
315 * to do anything fancy with the allocation of this memory to the
316 * zones, now is the time to do it.
317 */
318 zone_size[0] = end_pfn - start_pfn;
319
320 /*
321 * For each bank in this node, calculate the size of the holes.
322 * holes = node_size - sum(bank_sizes_in_node)
323 */
324 zhole_size[0] = zone_size[0];
325 for_each_nodebank(i, mi, node)
Russell Kingd2a38ef2008-10-01 16:56:15 +0100326 zhole_size[0] -= bank_pfn_size(&mi->bank[i]);
Russell King90072052005-10-28 14:48:37 +0100327
328 /*
329 * Adjust the sizes according to any special requirements for
330 * this machine type.
331 */
332 arch_adjust_zones(node, zone_size, zhole_size);
333
Johannes Weiner9109fb72008-07-23 21:27:20 -0700334 free_area_init_node(node, zone_size, start_pfn, zhole_size);
Russell King90072052005-10-28 14:48:37 +0100335}
336
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400337void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100338{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400339 struct meminfo *mi = &meminfo;
Russell King456335e2006-09-27 10:00:54 +0100340 unsigned long memend_pfn = 0;
Russell Kingeca73212008-09-30 19:29:25 +0100341 int node, initrd_node;
Russell King90072052005-10-28 14:48:37 +0100342
Russell King90072052005-10-28 14:48:37 +0100343 /*
344 * Locate which node contains the ramdisk image, if any.
345 */
346 initrd_node = check_initrd(mi);
347
348 /*
349 * Run through each node initialising the bootmem allocator.
350 */
351 for_each_node(node) {
Russell Kingb7a69ac2008-10-01 16:58:32 +0100352 unsigned long end_pfn = bootmem_init_node(node, mi);
Russell King90072052005-10-28 14:48:37 +0100353
Russell Kingb7a69ac2008-10-01 16:58:32 +0100354 /*
355 * Reserve any special node zero regions.
356 */
357 if (node == 0)
358 reserve_node_zero(NODE_DATA(node));
359
360 /*
361 * If the initrd is in this node, reserve its memory.
362 */
363 if (node == initrd_node)
364 bootmem_reserve_initrd(node);
Russell King90072052005-10-28 14:48:37 +0100365
366 /*
367 * Remember the highest memory PFN.
368 */
369 if (end_pfn > memend_pfn)
370 memend_pfn = end_pfn;
371 }
372
Russell Kingb7a69ac2008-10-01 16:58:32 +0100373 /*
374 * sparse_init() needs the bootmem allocator up and running.
375 */
376 sparse_init();
377
378 /*
379 * Now free memory in each node - free_area_init_node needs
380 * the sparse mem_map arrays initialized by sparse_init()
381 * for memmap_init_zone(), otherwise all PFNs are invalid.
382 */
383 for_each_node(node)
384 bootmem_free_node(node, mi);
385
Russell King1522ac32009-03-12 17:03:48 +0000386 high_memory = __va((memend_pfn << PAGE_SHIFT) - 1) + 1;
Russell King90072052005-10-28 14:48:37 +0100387
388 /*
389 * This doesn't seem to be used by the Linux memory manager any
390 * more, but is used by ll_rw_block. If we can get rid of it, we
391 * also get rid of some of the stuff above as well.
392 *
393 * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
394 * the system, not the maximum PFN.
395 */
396 max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET;
397}
398
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400399static inline int free_area(unsigned long pfn, unsigned long end, char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400401 unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400403 for (; pfn < end; pfn++) {
404 struct page *page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800406 init_page_count(page);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400407 __free_page(page);
408 pages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410
411 if (size && s)
412 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400413
414 return pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Russell Kinga0130532005-06-27 14:16:47 +0100417static inline void
418free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
419{
420 struct page *start_pg, *end_pg;
421 unsigned long pg, pgend;
422
423 /*
424 * Convert start_pfn/end_pfn to a struct page pointer.
425 */
426 start_pg = pfn_to_page(start_pfn);
427 end_pg = pfn_to_page(end_pfn);
428
429 /*
430 * Convert to physical addresses, and
431 * round start upwards and end downwards.
432 */
433 pg = PAGE_ALIGN(__pa(start_pg));
434 pgend = __pa(end_pg) & PAGE_MASK;
435
436 /*
437 * If there are free pages between these,
438 * free the section of the memmap array.
439 */
440 if (pg < pgend)
441 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
442}
443
444/*
445 * The mem_map array can get very big. Free the unused area of the memory map.
446 */
447static void __init free_unused_memmap_node(int node, struct meminfo *mi)
448{
449 unsigned long bank_start, prev_bank_end = 0;
450 unsigned int i;
451
452 /*
453 * [FIXME] This relies on each bank being in address order. This
454 * may not be the case, especially if the user has provided the
455 * information on the command line.
456 */
Russell King90072052005-10-28 14:48:37 +0100457 for_each_nodebank(i, mi, node) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100458 struct membank *bank = &mi->bank[i];
459
460 bank_start = bank_pfn_start(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100461 if (bank_start < prev_bank_end) {
462 printk(KERN_ERR "MEM: unordered memory banks. "
463 "Not freeing memmap.\n");
464 break;
465 }
466
467 /*
468 * If we had a previous bank, and there is a space
469 * between the current bank and the previous, free it.
470 */
471 if (prev_bank_end && prev_bank_end != bank_start)
472 free_memmap(node, prev_bank_end, bank_start);
473
Russell Kingd2a38ef2008-10-01 16:56:15 +0100474 prev_bank_end = bank_pfn_end(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100475 }
476}
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478/*
479 * mem_init() marks the free areas in the mem_map and tells us how much
480 * memory is free. This is done after various parts of the system have
481 * claimed their memory after the kernel image.
482 */
483void __init mem_init(void)
484{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400485 unsigned int codesize, datasize, initsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 int i, node;
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#ifndef CONFIG_DISCONTIGMEM
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400489 max_mapnr = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#endif
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* this will put all unused low memory onto the freelists */
493 for_each_online_node(node) {
494 pg_data_t *pgdat = NODE_DATA(node);
495
Russell Kinga0130532005-06-27 14:16:47 +0100496 free_unused_memmap_node(node, &meminfo);
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (pgdat->node_spanned_pages != 0)
499 totalram_pages += free_all_bootmem_node(pgdat);
500 }
501
502#ifdef CONFIG_SA1111
503 /* now that our DMA memory is actually so designated, we can free it */
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400504 totalram_pages += free_area(PHYS_PFN_OFFSET,
505 __phys_to_pfn(__pa(swapper_pg_dir)), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#endif
507
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400508#ifdef CONFIG_HIGHMEM
509 /* set highmem page free */
510 for_each_online_node(node) {
511 for_each_nodebank (i, &meminfo, node) {
512 unsigned long start = bank_pfn_start(&meminfo.bank[i]);
513 unsigned long end = bank_pfn_end(&meminfo.bank[i]);
514 if (start >= max_low_pfn + PHYS_PFN_OFFSET)
515 totalhigh_pages += free_area(start, end, NULL);
516 }
517 }
518 totalram_pages += totalhigh_pages;
519#endif
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 /*
522 * Since our memory may not be contiguous, calculate the
523 * real number of pages we have in this system
524 */
525 printk(KERN_INFO "Memory:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 num_physpages = 0;
527 for (i = 0; i < meminfo.nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100528 num_physpages += bank_pfn_size(&meminfo.bank[i]);
529 printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400532
Russell King37efe642008-12-01 11:53:07 +0000533 codesize = _etext - _text;
534 datasize = _end - _data;
535 initsize = __init_end - __init_begin;
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 printk(KERN_NOTICE "Memory: %luKB available (%dK code, "
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400538 "%dK data, %dK init, %luK highmem)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400540 codesize >> 10, datasize >> 10, initsize >> 10,
541 (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
544 extern int sysctl_overcommit_memory;
545 /*
546 * On a machine this small we won't get
547 * anywhere without overcommit, so turn
548 * it on by default.
549 */
550 sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
551 }
552}
553
554void free_initmem(void)
555{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400556 if (!machine_is_integrator() && !machine_is_cintegrator())
Russell King37efe642008-12-01 11:53:07 +0000557 totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)),
558 __phys_to_pfn(__pa(__init_end)),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400559 "init");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
562#ifdef CONFIG_BLK_DEV_INITRD
563
564static int keep_initrd;
565
566void free_initrd_mem(unsigned long start, unsigned long end)
567{
568 if (!keep_initrd)
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400569 totalram_pages += free_area(__phys_to_pfn(__pa(start)),
570 __phys_to_pfn(__pa(end)),
571 "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
574static int __init keepinitrd_setup(char *__unused)
575{
576 keep_initrd = 1;
577 return 1;
578}
579
580__setup("keepinitrd", keepinitrd_setup);
581#endif