blob: d72ab58fd83e743cdeba8cac08e02634cc8f552b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/cris/mm/init.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 * Copyright (C) 2000,2001 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (bjornw@axis.com)
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/bootmem.h>
14#include <asm/tlb.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016unsigned long empty_zero_page;
17
18extern char _stext, _edata, _etext; /* From linkerscript */
19extern char __init_begin, __init_end;
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021void __init
22mem_init(void)
23{
24 int codesize, reservedpages, datasize, initsize;
25 unsigned long tmp;
26
Stoyan Gaydarov59b97762009-03-10 06:10:40 +010027 BUG_ON(!mem_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 /* max/min_low_pfn was set by setup.c
30 * now we just copy it to some other necessary places...
31 *
32 * high_memory was also set in setup.c
33 */
34
35 max_mapnr = num_physpages = max_low_pfn - min_low_pfn;
36
37 /* this will put all memory onto the freelists */
38 totalram_pages = free_all_bootmem();
39
40 reservedpages = 0;
41 for (tmp = 0; tmp < max_mapnr; tmp++) {
42 /*
43 * Only count reserved RAM pages
44 */
45 if (PageReserved(mem_map + tmp))
46 reservedpages++;
47 }
48
49 codesize = (unsigned long) &_etext - (unsigned long) &_stext;
50 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
51 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
52
53 printk(KERN_INFO
54 "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, "
55 "%dk init)\n" ,
Geert Uytterhoevencc013a82009-09-21 17:02:36 -070056 nr_free_pages() << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 max_mapnr << (PAGE_SHIFT-10),
58 codesize >> 10,
59 reservedpages << (PAGE_SHIFT-10),
60 datasize >> 10,
61 initsize >> 10
62 );
63}
64
65/* free the pages occupied by initialization code */
66
67void
68free_initmem(void)
69{
70 unsigned long addr;
71
72 addr = (unsigned long)(&__init_begin);
73 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
74 ClearPageReserved(virt_to_page(addr));
Nick Piggin7835e982006-03-22 00:08:40 -080075 init_page_count(virt_to_page(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 free_page(addr);
77 totalram_pages++;
78 }
79 printk (KERN_INFO "Freeing unused kernel memory: %luk freed\n",
80 (unsigned long)((&__init_end - &__init_begin) >> 10));
81}