]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* init.c: memory initialisation for FRV |
2 | * | |
3 | * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * Derived from: | |
12 | * - linux/arch/m68knommu/mm/init.c | |
13 | * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, Kenneth Albanowski <kjahds@kjahds.com>, | |
14 | * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com) | |
15 | * - linux/arch/m68k/mm/init.c | |
16 | * - Copyright (C) 1995 Hamish Macdonald | |
17 | */ | |
18 | ||
1da177e4 LT |
19 | #include <linux/signal.h> |
20 | #include <linux/sched.h> | |
21 | #include <linux/pagemap.h> | |
5a0e3ad6 | 22 | #include <linux/gfp.h> |
1da177e4 LT |
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> | |
fb56f0f9 | 30 | #include <linux/module.h> |
1da177e4 LT |
31 | |
32 | #include <asm/setup.h> | |
33 | #include <asm/segment.h> | |
34 | #include <asm/page.h> | |
35 | #include <asm/pgtable.h> | |
36 | #include <asm/system.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 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | |
45 | ||
46 | /* | |
47 | * BAD_PAGE is the page that is used for page faults when linux | |
48 | * is out-of-memory. Older versions of linux just did a | |
49 | * do_exit(), but using this instead means there is less risk | |
50 | * for a process dying in kernel mode, possibly leaving a inode | |
51 | * unused etc.. | |
52 | * | |
53 | * BAD_PAGETABLE is the accompanying page-table: it is initialized | |
54 | * to point to BAD_PAGE entries. | |
55 | * | |
56 | * ZERO_PAGE is a special page that is used for zero-initialized | |
57 | * data and COW. | |
58 | */ | |
59 | static unsigned long empty_bad_page_table; | |
60 | static unsigned long empty_bad_page; | |
fb56f0f9 | 61 | |
1da177e4 | 62 | unsigned long empty_zero_page; |
fb56f0f9 | 63 | EXPORT_SYMBOL(empty_zero_page); |
1da177e4 LT |
64 | |
65 | /*****************************************************************************/ | |
1da177e4 LT |
66 | /* |
67 | * paging_init() continues the virtual memory environment setup which | |
68 | * was begun by the code in arch/head.S. | |
69 | * The parameters are pointers to where to stick the starting and ending | |
70 | * addresses of available kernel virtual memory. | |
71 | */ | |
72 | void __init paging_init(void) | |
73 | { | |
f06a9684 | 74 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
1da177e4 LT |
75 | |
76 | /* allocate some pages for kernel housekeeping tasks */ | |
77 | empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); | |
78 | empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); | |
79 | empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); | |
80 | ||
81 | memset((void *) empty_zero_page, 0, PAGE_SIZE); | |
82 | ||
8080f231 | 83 | #ifdef CONFIG_HIGHMEM |
1da177e4 LT |
84 | if (num_physpages - num_mappedpages) { |
85 | pgd_t *pge; | |
86 | pud_t *pue; | |
87 | pmd_t *pme; | |
88 | ||
89 | pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE); | |
90 | ||
1da177e4 LT |
91 | pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE); |
92 | pue = pud_offset(pge, PKMAP_BASE); | |
93 | pme = pmd_offset(pue, PKMAP_BASE); | |
94 | __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE); | |
95 | } | |
96 | #endif | |
97 | ||
98 | /* distribute the allocatable pages across the various zones and pass them to the allocator | |
99 | */ | |
fa642754 | 100 | zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn; |
1da177e4 LT |
101 | #ifdef CONFIG_HIGHMEM |
102 | zones_size[ZONE_HIGHMEM] = num_physpages - num_mappedpages; | |
103 | #endif | |
104 | ||
105 | free_area_init(zones_size); | |
106 | ||
107 | #ifdef CONFIG_MMU | |
108 | /* initialise init's MMU context */ | |
109 | init_new_context(&init_task, &init_mm); | |
110 | #endif | |
111 | ||
112 | } /* end paging_init() */ | |
113 | ||
114 | /*****************************************************************************/ | |
115 | /* | |
116 | * | |
117 | */ | |
118 | void __init mem_init(void) | |
119 | { | |
120 | unsigned long npages = (memory_end - memory_start) >> PAGE_SHIFT; | |
121 | unsigned long tmp; | |
122 | #ifdef CONFIG_MMU | |
123 | unsigned long loop, pfn; | |
124 | int datapages = 0; | |
125 | #endif | |
126 | int codek = 0, datak = 0; | |
127 | ||
128 | /* this will put all memory onto the freelists */ | |
129 | totalram_pages = free_all_bootmem(); | |
130 | ||
131 | #ifdef CONFIG_MMU | |
132 | for (loop = 0 ; loop < npages ; loop++) | |
133 | if (PageReserved(&mem_map[loop])) | |
134 | datapages++; | |
135 | ||
136 | #ifdef CONFIG_HIGHMEM | |
137 | for (pfn = num_physpages - 1; pfn >= num_mappedpages; pfn--) { | |
138 | struct page *page = &mem_map[pfn]; | |
139 | ||
140 | ClearPageReserved(page); | |
7835e98b | 141 | init_page_count(page); |
1da177e4 LT |
142 | __free_page(page); |
143 | totalram_pages++; | |
144 | } | |
145 | #endif | |
146 | ||
147 | codek = ((unsigned long) &_etext - (unsigned long) &_stext) >> 10; | |
148 | datak = datapages << (PAGE_SHIFT - 10); | |
149 | ||
150 | #else | |
151 | codek = (_etext - _stext) >> 10; | |
152 | datak = 0; //(_ebss - _sdata) >> 10; | |
153 | #endif | |
154 | ||
155 | tmp = nr_free_pages() << PAGE_SHIFT; | |
156 | printk("Memory available: %luKiB/%luKiB RAM, %luKiB/%luKiB ROM (%dKiB kernel code, %dKiB data)\n", | |
157 | tmp >> 10, | |
158 | npages << (PAGE_SHIFT - 10), | |
159 | (rom_length > 0) ? ((rom_length >> 10) - codek) : 0, | |
160 | rom_length >> 10, | |
161 | codek, | |
162 | datak | |
163 | ); | |
164 | ||
165 | } /* end mem_init() */ | |
166 | ||
167 | /*****************************************************************************/ | |
168 | /* | |
169 | * free the memory that was only required for initialisation | |
170 | */ | |
e4fc5a1a | 171 | void free_initmem(void) |
1da177e4 LT |
172 | { |
173 | #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL) | |
174 | unsigned long start, end, addr; | |
175 | ||
176 | start = PAGE_ALIGN((unsigned long) &__init_begin); /* round up */ | |
177 | end = ((unsigned long) &__init_end) & PAGE_MASK; /* round down */ | |
178 | ||
179 | /* next to check that the page we free is not a partial page */ | |
180 | for (addr = start; addr < end; addr += PAGE_SIZE) { | |
181 | ClearPageReserved(virt_to_page(addr)); | |
7835e98b | 182 | init_page_count(virt_to_page(addr)); |
1da177e4 LT |
183 | free_page(addr); |
184 | totalram_pages++; | |
185 | } | |
186 | ||
187 | printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n", | |
188 | (end - start) >> 10, start, end); | |
189 | #endif | |
190 | } /* end free_initmem() */ | |
191 | ||
192 | /*****************************************************************************/ | |
193 | /* | |
194 | * free the initial ramdisk memory | |
195 | */ | |
196 | #ifdef CONFIG_BLK_DEV_INITRD | |
197 | void __init free_initrd_mem(unsigned long start, unsigned long end) | |
198 | { | |
199 | int pages = 0; | |
200 | for (; start < end; start += PAGE_SIZE) { | |
201 | ClearPageReserved(virt_to_page(start)); | |
7835e98b | 202 | init_page_count(virt_to_page(start)); |
1da177e4 LT |
203 | free_page(start); |
204 | totalram_pages++; | |
205 | pages++; | |
206 | } | |
207 | printk("Freeing initrd memory: %dKiB freed\n", (pages * PAGE_SIZE) >> 10); | |
208 | } /* end free_initrd_mem() */ | |
209 | #endif |