blob: 34df4d9d03a6afb6f7a65627bb86d3da56c05cba [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>
18
19#include <asm/mach-types.h>
Russell King37efe642008-12-01 11:53:07 +000020#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/setup.h>
Russell King74d02fb2006-04-04 21:47:43 +010022#include <asm/sizes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/tlb.h>
24
25#include <asm/mach/arch.h>
26#include <asm/mach/map.h>
27
Russell King1b2e2b72006-08-21 17:06:38 +010028#include "mm.h"
29
Russell King012d1f42008-09-06 10:57:03 +010030static unsigned long phys_initrd_start __initdata = 0;
31static unsigned long phys_initrd_size __initdata = 0;
32
33static void __init early_initrd(char **p)
34{
35 unsigned long start, size;
36
37 start = memparse(*p, p);
38 if (**p == ',') {
39 size = memparse((*p) + 1, p);
40
41 phys_initrd_start = start;
42 phys_initrd_size = size;
43 }
44}
45__early_param("initrd=", early_initrd);
46
47static int __init parse_tag_initrd(const struct tag *tag)
48{
49 printk(KERN_WARNING "ATAG_INITRD is deprecated; "
50 "please update your bootloader.\n");
51 phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
52 phys_initrd_size = tag->u.initrd.size;
53 return 0;
54}
55
56__tagtable(ATAG_INITRD, parse_tag_initrd);
57
58static int __init parse_tag_initrd2(const struct tag *tag)
59{
60 phys_initrd_start = tag->u.initrd.start;
61 phys_initrd_size = tag->u.initrd.size;
62 return 0;
63}
64
65__tagtable(ATAG_INITRD2, parse_tag_initrd2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/*
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040068 * This keeps memory configuration data used by a couple memory
69 * initialization functions, as well as show_mem() for the skipping
70 * of holes in the memory map. It is populated by arm_add_memory().
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040072struct meminfo meminfo;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074void show_mem(void)
75{
76 int free = 0, total = 0, reserved = 0;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010077 int shared = 0, cached = 0, slab = 0, node, i;
78 struct meminfo * mi = &meminfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 printk("Mem-info:\n");
81 show_free_areas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 for_each_online_node(node) {
Russell King204ecae2007-01-16 14:01:47 +000083 pg_data_t *n = NODE_DATA(node);
Russell Kingb7a69ac2008-10-01 16:58:32 +010084 struct page *map = pgdat_page_nr(n, 0) - n->node_start_pfn;
Russell King204ecae2007-01-16 14:01:47 +000085
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010086 for_each_nodebank (i,mi,node) {
Russell Kingd2a38ef2008-10-01 16:56:15 +010087 struct membank *bank = &mi->bank[i];
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010088 unsigned int pfn1, pfn2;
89 struct page *page, *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Russell Kingd2a38ef2008-10-01 16:56:15 +010091 pfn1 = bank_pfn_start(bank);
92 pfn2 = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Russell King204ecae2007-01-16 14:01:47 +000094 page = map + pfn1;
95 end = map + pfn2;
Ray Lehtiniemi5e709822006-11-07 03:19:15 +010096
97 do {
98 total++;
99 if (PageReserved(page))
100 reserved++;
101 else if (PageSwapCache(page))
102 cached++;
103 else if (PageSlab(page))
104 slab++;
105 else if (!page_count(page))
106 free++;
107 else
108 shared += page_count(page) - 1;
109 page++;
110 } while (page < end);
111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
114 printk("%d pages of RAM\n", total);
115 printk("%d free pages\n", free);
116 printk("%d reserved pages\n", reserved);
117 printk("%d slab pages\n", slab);
118 printk("%d pages shared\n", shared);
119 printk("%d pages swap cached\n", cached);
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*
123 * FIXME: We really want to avoid allocating the bootmap bitmap
124 * over the top of the initrd. Hopefully, this is located towards
125 * the start of a bank, so if we allocate the bootmap bitmap at
126 * the end, we won't clash.
127 */
128static unsigned int __init
129find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
130{
Russell Kingd2a38ef2008-10-01 16:56:15 +0100131 unsigned int start_pfn, i, bootmap_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Russell King37efe642008-12-01 11:53:07 +0000133 start_pfn = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 bootmap_pfn = 0;
135
Russell Kingd2a38ef2008-10-01 16:56:15 +0100136 for_each_nodebank(i, mi, node) {
137 struct membank *bank = &mi->bank[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 unsigned int start, end;
139
Russell Kingd2a38ef2008-10-01 16:56:15 +0100140 start = bank_pfn_start(bank);
141 end = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 if (end < start_pfn)
144 continue;
145
146 if (start < start_pfn)
147 start = start_pfn;
148
149 if (end <= start)
150 continue;
151
152 if (end - start >= bootmap_pages) {
153 bootmap_pfn = start;
154 break;
155 }
156 }
157
158 if (bootmap_pfn == 0)
159 BUG();
160
161 return bootmap_pfn;
162}
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static int __init check_initrd(struct meminfo *mi)
165{
166 int initrd_node = -2;
167#ifdef CONFIG_BLK_DEV_INITRD
168 unsigned long end = phys_initrd_start + phys_initrd_size;
169
170 /*
171 * Make sure that the initrd is within a valid area of
172 * memory.
173 */
174 if (phys_initrd_size) {
175 unsigned int i;
176
177 initrd_node = -1;
178
179 for (i = 0; i < mi->nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100180 struct membank *bank = &mi->bank[i];
181 if (bank_phys_start(bank) <= phys_initrd_start &&
182 end <= bank_phys_end(bank))
183 initrd_node = bank->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
185 }
186
187 if (initrd_node == -1) {
Russell Kingb962a282008-07-30 21:24:56 +0100188 printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 "physical memory - disabling initrd\n",
Russell Kingb962a282008-07-30 21:24:56 +0100190 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 phys_initrd_start = phys_initrd_size = 0;
192 }
193#endif
194
195 return initrd_node;
196}
197
Russell King456335e2006-09-27 10:00:54 +0100198static inline void map_memory_bank(struct membank *bank)
199{
Russell Kingd111e8f2006-09-27 15:27:33 +0100200#ifdef CONFIG_MMU
Russell King456335e2006-09-27 10:00:54 +0100201 struct map_desc map;
202
Russell Kingd2a38ef2008-10-01 16:56:15 +0100203 map.pfn = bank_pfn_start(bank);
204 map.virtual = __phys_to_virt(bank_phys_start(bank));
205 map.length = bank_phys_size(bank);
Russell King456335e2006-09-27 10:00:54 +0100206 map.type = MT_MEMORY;
207
208 create_mapping(&map);
Russell Kingd111e8f2006-09-27 15:27:33 +0100209#endif
Russell King456335e2006-09-27 10:00:54 +0100210}
211
Russell Kingb7a69ac2008-10-01 16:58:32 +0100212static unsigned long __init bootmem_init_node(int node, struct meminfo *mi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Russell King90072052005-10-28 14:48:37 +0100214 unsigned long start_pfn, end_pfn, boot_pfn;
215 unsigned int boot_pages;
216 pg_data_t *pgdat;
217 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Russell King90072052005-10-28 14:48:37 +0100219 start_pfn = -1UL;
220 end_pfn = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /*
Russell King90072052005-10-28 14:48:37 +0100223 * Calculate the pfn range, and map the memory banks for this node.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 */
Russell King90072052005-10-28 14:48:37 +0100225 for_each_nodebank(i, mi, node) {
Russell King456335e2006-09-27 10:00:54 +0100226 struct membank *bank = &mi->bank[i];
Russell King90072052005-10-28 14:48:37 +0100227 unsigned long start, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Russell Kingd2a38ef2008-10-01 16:56:15 +0100229 start = bank_pfn_start(bank);
230 end = bank_pfn_end(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Russell King90072052005-10-28 14:48:37 +0100232 if (start_pfn > start)
233 start_pfn = start;
234 if (end_pfn < end)
235 end_pfn = end;
236
Russell King456335e2006-09-27 10:00:54 +0100237 map_memory_bank(bank);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
239
Russell King90072052005-10-28 14:48:37 +0100240 /*
241 * If there is no memory in this node, ignore it.
242 */
243 if (end_pfn == 0)
244 return end_pfn;
245
246 /*
247 * Allocate the bootmem bitmap page.
248 */
249 boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
250 boot_pfn = find_bootmap_pfn(node, mi, boot_pages);
251
252 /*
253 * Initialise the bootmem allocator for this node, handing the
254 * memory banks over to bootmem.
255 */
256 node_set_online(node);
257 pgdat = NODE_DATA(node);
258 init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);
259
Russell Kingd2a38ef2008-10-01 16:56:15 +0100260 for_each_nodebank(i, mi, node) {
261 struct membank *bank = &mi->bank[i];
262 free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank));
Russell Kingb7a69ac2008-10-01 16:58:32 +0100263 memory_present(node, bank_pfn_start(bank), bank_pfn_end(bank));
Russell Kingd2a38ef2008-10-01 16:56:15 +0100264 }
Russell King90072052005-10-28 14:48:37 +0100265
266 /*
267 * Reserve the bootmem bitmap for this node.
268 */
269 reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800270 boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Russell Kingb7a69ac2008-10-01 16:58:32 +0100272 return end_pfn;
273}
Russell Kingb962a282008-07-30 21:24:56 +0100274
Russell Kingb7a69ac2008-10-01 16:58:32 +0100275static void __init bootmem_reserve_initrd(int node)
276{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingb7a69ac2008-10-01 16:58:32 +0100278 pg_data_t *pgdat = NODE_DATA(node);
279 int res;
Russell Kingb962a282008-07-30 21:24:56 +0100280
Russell Kingb7a69ac2008-10-01 16:58:32 +0100281 res = reserve_bootmem_node(pgdat, phys_initrd_start,
282 phys_initrd_size, BOOTMEM_EXCLUSIVE);
283
284 if (res == 0) {
285 initrd_start = __phys_to_virt(phys_initrd_start);
286 initrd_end = initrd_start + phys_initrd_size;
287 } else {
288 printk(KERN_ERR
289 "INITRD: 0x%08lx+0x%08lx overlaps in-use "
290 "memory region - disabling initrd\n",
291 phys_initrd_start, phys_initrd_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293#endif
Russell Kingb7a69ac2008-10-01 16:58:32 +0100294}
295
296static void __init bootmem_free_node(int node, struct meminfo *mi)
297{
298 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
299 unsigned long start_pfn, end_pfn;
300 pg_data_t *pgdat = NODE_DATA(node);
301 int i;
302
303 start_pfn = pgdat->bdata->node_min_pfn;
304 end_pfn = pgdat->bdata->node_low_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Russell King90072052005-10-28 14:48:37 +0100306 /*
Russell King90072052005-10-28 14:48:37 +0100307 * initialise the zones within this node.
308 */
309 memset(zone_size, 0, sizeof(zone_size));
310 memset(zhole_size, 0, sizeof(zhole_size));
311
312 /*
313 * The size of this node has already been determined. If we need
314 * to do anything fancy with the allocation of this memory to the
315 * zones, now is the time to do it.
316 */
317 zone_size[0] = end_pfn - start_pfn;
318
319 /*
320 * For each bank in this node, calculate the size of the holes.
321 * holes = node_size - sum(bank_sizes_in_node)
322 */
323 zhole_size[0] = zone_size[0];
324 for_each_nodebank(i, mi, node)
Russell Kingd2a38ef2008-10-01 16:56:15 +0100325 zhole_size[0] -= bank_pfn_size(&mi->bank[i]);
Russell King90072052005-10-28 14:48:37 +0100326
327 /*
328 * Adjust the sizes according to any special requirements for
329 * this machine type.
330 */
331 arch_adjust_zones(node, zone_size, zhole_size);
332
Johannes Weiner9109fb72008-07-23 21:27:20 -0700333 free_area_init_node(node, zone_size, start_pfn, zhole_size);
Russell King90072052005-10-28 14:48:37 +0100334}
335
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400336void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100337{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400338 struct meminfo *mi = &meminfo;
Russell King456335e2006-09-27 10:00:54 +0100339 unsigned long memend_pfn = 0;
Russell Kingeca73212008-09-30 19:29:25 +0100340 int node, initrd_node;
Russell King90072052005-10-28 14:48:37 +0100341
Russell King90072052005-10-28 14:48:37 +0100342 /*
343 * Locate which node contains the ramdisk image, if any.
344 */
345 initrd_node = check_initrd(mi);
346
347 /*
348 * Run through each node initialising the bootmem allocator.
349 */
350 for_each_node(node) {
Russell Kingb7a69ac2008-10-01 16:58:32 +0100351 unsigned long end_pfn = bootmem_init_node(node, mi);
Russell King90072052005-10-28 14:48:37 +0100352
Russell Kingb7a69ac2008-10-01 16:58:32 +0100353 /*
354 * Reserve any special node zero regions.
355 */
356 if (node == 0)
357 reserve_node_zero(NODE_DATA(node));
358
359 /*
360 * If the initrd is in this node, reserve its memory.
361 */
362 if (node == initrd_node)
363 bootmem_reserve_initrd(node);
Russell King90072052005-10-28 14:48:37 +0100364
365 /*
366 * Remember the highest memory PFN.
367 */
368 if (end_pfn > memend_pfn)
369 memend_pfn = end_pfn;
370 }
371
Russell Kingb7a69ac2008-10-01 16:58:32 +0100372 /*
373 * sparse_init() needs the bootmem allocator up and running.
374 */
375 sparse_init();
376
377 /*
378 * Now free memory in each node - free_area_init_node needs
379 * the sparse mem_map arrays initialized by sparse_init()
380 * for memmap_init_zone(), otherwise all PFNs are invalid.
381 */
382 for_each_node(node)
383 bootmem_free_node(node, mi);
384
Russell King90072052005-10-28 14:48:37 +0100385 high_memory = __va(memend_pfn << PAGE_SHIFT);
386
387 /*
388 * This doesn't seem to be used by the Linux memory manager any
389 * more, but is used by ll_rw_block. If we can get rid of it, we
390 * also get rid of some of the stuff above as well.
391 *
392 * Note: max_low_pfn and max_pfn reflect the number of _pages_ in
393 * the system, not the maximum PFN.
394 */
395 max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET;
396}
397
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400398static inline int free_area(unsigned long pfn, unsigned long end, char *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400400 unsigned int pages = 0, size = (end - pfn) << (PAGE_SHIFT - 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400402 for (; pfn < end; pfn++) {
403 struct page *page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800405 init_page_count(page);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400406 __free_page(page);
407 pages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409
410 if (size && s)
411 printk(KERN_INFO "Freeing %s memory: %dK\n", s, size);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400412
413 return pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Russell Kinga0130532005-06-27 14:16:47 +0100416static inline void
417free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
418{
419 struct page *start_pg, *end_pg;
420 unsigned long pg, pgend;
421
422 /*
423 * Convert start_pfn/end_pfn to a struct page pointer.
424 */
425 start_pg = pfn_to_page(start_pfn);
426 end_pg = pfn_to_page(end_pfn);
427
428 /*
429 * Convert to physical addresses, and
430 * round start upwards and end downwards.
431 */
432 pg = PAGE_ALIGN(__pa(start_pg));
433 pgend = __pa(end_pg) & PAGE_MASK;
434
435 /*
436 * If there are free pages between these,
437 * free the section of the memmap array.
438 */
439 if (pg < pgend)
440 free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
441}
442
443/*
444 * The mem_map array can get very big. Free the unused area of the memory map.
445 */
446static void __init free_unused_memmap_node(int node, struct meminfo *mi)
447{
448 unsigned long bank_start, prev_bank_end = 0;
449 unsigned int i;
450
451 /*
452 * [FIXME] This relies on each bank being in address order. This
453 * may not be the case, especially if the user has provided the
454 * information on the command line.
455 */
Russell King90072052005-10-28 14:48:37 +0100456 for_each_nodebank(i, mi, node) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100457 struct membank *bank = &mi->bank[i];
458
459 bank_start = bank_pfn_start(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100460 if (bank_start < prev_bank_end) {
461 printk(KERN_ERR "MEM: unordered memory banks. "
462 "Not freeing memmap.\n");
463 break;
464 }
465
466 /*
467 * If we had a previous bank, and there is a space
468 * between the current bank and the previous, free it.
469 */
470 if (prev_bank_end && prev_bank_end != bank_start)
471 free_memmap(node, prev_bank_end, bank_start);
472
Russell Kingd2a38ef2008-10-01 16:56:15 +0100473 prev_bank_end = bank_pfn_end(bank);
Russell Kinga0130532005-06-27 14:16:47 +0100474 }
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/*
478 * mem_init() marks the free areas in the mem_map and tells us how much
479 * memory is free. This is done after various parts of the system have
480 * claimed their memory after the kernel image.
481 */
482void __init mem_init(void)
483{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400484 unsigned int codesize, datasize, initsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 int i, node;
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#ifndef CONFIG_DISCONTIGMEM
488 max_mapnr = virt_to_page(high_memory) - mem_map;
489#endif
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /* this will put all unused low memory onto the freelists */
492 for_each_online_node(node) {
493 pg_data_t *pgdat = NODE_DATA(node);
494
Russell Kinga0130532005-06-27 14:16:47 +0100495 free_unused_memmap_node(node, &meminfo);
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (pgdat->node_spanned_pages != 0)
498 totalram_pages += free_all_bootmem_node(pgdat);
499 }
500
501#ifdef CONFIG_SA1111
502 /* now that our DMA memory is actually so designated, we can free it */
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400503 totalram_pages += free_area(PHYS_PFN_OFFSET,
504 __phys_to_pfn(__pa(swapper_pg_dir)), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#endif
506
507 /*
508 * Since our memory may not be contiguous, calculate the
509 * real number of pages we have in this system
510 */
511 printk(KERN_INFO "Memory:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 num_physpages = 0;
513 for (i = 0; i < meminfo.nr_banks; i++) {
Russell Kingd2a38ef2008-10-01 16:56:15 +0100514 num_physpages += bank_pfn_size(&meminfo.bank[i]);
515 printk(" %ldMB", bank_phys_size(&meminfo.bank[i]) >> 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 printk(" = %luMB total\n", num_physpages >> (20 - PAGE_SHIFT));
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400518
Russell King37efe642008-12-01 11:53:07 +0000519 codesize = _etext - _text;
520 datasize = _end - _data;
521 initsize = __init_end - __init_begin;
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 printk(KERN_NOTICE "Memory: %luKB available (%dK code, "
524 "%dK data, %dK init)\n",
525 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400526 codesize >> 10, datasize >> 10, initsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 if (PAGE_SIZE >= 16384 && num_physpages <= 128) {
529 extern int sysctl_overcommit_memory;
530 /*
531 * On a machine this small we won't get
532 * anywhere without overcommit, so turn
533 * it on by default.
534 */
535 sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
536 }
537}
538
539void free_initmem(void)
540{
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400541 if (!machine_is_integrator() && !machine_is_cintegrator())
Russell King37efe642008-12-01 11:53:07 +0000542 totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)),
543 __phys_to_pfn(__pa(__init_end)),
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400544 "init");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545}
546
547#ifdef CONFIG_BLK_DEV_INITRD
548
549static int keep_initrd;
550
551void free_initrd_mem(unsigned long start, unsigned long end)
552{
553 if (!keep_initrd)
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400554 totalram_pages += free_area(__phys_to_pfn(__pa(start)),
555 __phys_to_pfn(__pa(end)),
556 "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559static int __init keepinitrd_setup(char *__unused)
560{
561 keep_initrd = 1;
562 return 1;
563}
564
565__setup("keepinitrd", keepinitrd_setup);
566#endif