1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/errno.h>
27#include <linux/bootmem.h>
28#include <linux/kernel.h>
29#include <linux/gfp.h>
30#include <linux/init.h>
31#include <linux/mm.h>
32#include <linux/mman.h>
33#include <linux/pagemap.h>
34#include <linux/proc_fs.h>
35#include <linux/sched.h>
36#include <linux/initrd.h>
37
38#include <asm/sections.h>
39#include <asm/tlb.h>
40
41unsigned long empty_zero_page;
42EXPORT_SYMBOL_GPL(empty_zero_page);
43
44static struct kcore_list kcore_mem, kcore_vmalloc;
45
46static unsigned long setup_zero_page(void)
47{
48 struct page *page;
49
50 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0);
51 if (!empty_zero_page)
52 panic("Oh boy, that early out of memory?");
53
54 page = virt_to_page((void *) empty_zero_page);
55 SetPageReserved(page);
56
57 return 1UL;
58}
59
60#ifndef CONFIG_NEED_MULTIPLE_NODES
61int page_is_ram(unsigned long pagenr)
62{
63 if (pagenr >= min_low_pfn && pagenr < max_low_pfn)
64 return 1;
65 else
66 return 0;
67}
68
69void __init paging_init(void)
70{
71 unsigned long max_zone_pfns[MAX_NR_ZONES];
72 unsigned long lastpfn;
73
74 pagetable_init();
75 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
76 lastpfn = max_low_pfn;
77 free_area_init_nodes(max_zone_pfns);
78}
79
80void __init mem_init(void)
81{
82 unsigned long codesize, reservedpages, datasize, initsize;
83 unsigned long tmp, ram = 0;
84
85 high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
86 totalram_pages += free_all_bootmem();
87 totalram_pages -= setup_zero_page();
88 reservedpages = 0;
89
90 for (tmp = 0; tmp < max_low_pfn; tmp++)
91 if (page_is_ram(tmp)) {
92 ram++;
93 if (PageReserved(pfn_to_page(tmp)))
94 reservedpages++;
95 }
96
97 num_physpages = ram;
98 codesize = (unsigned long) &_etext - (unsigned long) &_text;
99 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
100 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
101
102 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
103 "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
104 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
105 ram << (PAGE_SHIFT-10), codesize >> 10,
106 reservedpages << (PAGE_SHIFT-10), datasize >> 10,
107 initsize >> 10,
108 totalhigh_pages << (PAGE_SHIFT-10));
109}
110#endif
111
112static void free_init_pages(const char *what, unsigned long begin, unsigned long end)
113{
114 unsigned long pfn;
115
116 for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) {
117 struct page *page = pfn_to_page(pfn);
118 void *addr = phys_to_virt(PFN_PHYS(pfn));
119
120 ClearPageReserved(page);
121 init_page_count(page);
122 memset(addr, POISON_FREE_INITMEM, PAGE_SIZE);
123 __free_page(page);
124 totalram_pages++;
125 }
126 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
127}
128
129#ifdef CONFIG_BLK_DEV_INITRD
130void free_initrd_mem(unsigned long start, unsigned long end)
131{
132 free_init_pages("initrd memory",
133 virt_to_phys((void *) start),
134 virt_to_phys((void *) end));
135}
136#endif
137
138void __init_refok free_initmem(void)
139{
140 free_init_pages("unused kernel memory",
141 __pa(&__init_begin),
142 __pa(&__init_end));
143}
144
145unsigned long pgd_current;
146
147#define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order)))
148
149
150
151
152
153
154pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER);
155pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);
156