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