1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/signal.h>
20#include <linux/sched.h>
21#include <linux/pagemap.h>
22#include <linux/gfp.h>
23#include <linux/swap.h>
24#include <linux/mm.h>
25#include <linux/kernel.h>
26#include <linux/string.h>
27#include <linux/types.h>
28#include <linux/bootmem.h>
29#include <linux/highmem.h>
30#include <linux/module.h>
31
32#include <asm/setup.h>
33#include <asm/segment.h>
34#include <asm/page.h>
35#include <asm/pgtable.h>
36#include <asm/mmu_context.h>
37#include <asm/virtconvert.h>
38#include <asm/sections.h>
39#include <asm/tlb.h>
40
41#undef DEBUG
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56static unsigned long empty_bad_page_table;
57static unsigned long empty_bad_page;
58
59unsigned long empty_zero_page;
60EXPORT_SYMBOL(empty_zero_page);
61
62
63
64
65
66
67
68
69void __init paging_init(void)
70{
71 unsigned long zones_size[MAX_NR_ZONES] = {0, };
72
73
74 empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
75 empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
76 empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
77
78 memset((void *) empty_zero_page, 0, PAGE_SIZE);
79
80#ifdef CONFIG_HIGHMEM
81 if (get_num_physpages() - num_mappedpages) {
82 pgd_t *pge;
83 pud_t *pue;
84 pmd_t *pme;
85
86 pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
87
88 pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
89 pue = pud_offset(pge, PKMAP_BASE);
90 pme = pmd_offset(pue, PKMAP_BASE);
91 __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
92 }
93#endif
94
95
96
97 zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
98#ifdef CONFIG_HIGHMEM
99 zones_size[ZONE_HIGHMEM] = get_num_physpages() - num_mappedpages;
100#endif
101
102 free_area_init(zones_size);
103
104#ifdef CONFIG_MMU
105
106 init_new_context(&init_task, &init_mm);
107#endif
108
109}
110
111
112
113
114
115void __init mem_init(void)
116{
117 unsigned long code_size = _etext - _stext;
118
119
120 free_all_bootmem();
121#if defined(CONFIG_MMU) && defined(CONFIG_HIGHMEM)
122 {
123 unsigned long pfn;
124
125 for (pfn = get_num_physpages() - 1;
126 pfn >= num_mappedpages; pfn--)
127 free_highmem_page(&mem_map[pfn]);
128 }
129#endif
130
131 mem_init_print_info(NULL);
132 if (rom_length > 0 && rom_length >= code_size)
133 printk("Memory available: %luKiB/%luKiB ROM\n",
134 (rom_length - code_size) >> 10, rom_length >> 10);
135}
136
137
138
139
140
141void free_initmem(void)
142{
143#if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
144 free_initmem_default(-1);
145#endif
146}
147
148
149
150
151
152#ifdef CONFIG_BLK_DEV_INITRD
153void __init free_initrd_mem(unsigned long start, unsigned long end)
154{
155 free_reserved_area((void *)start, (void *)end, -1, "initrd");
156}
157#endif
158