Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 1 | #include <linux/gfp.h> |
Jaswinder Singh Rajput | 2c1b284 | 2009-04-11 00:03:10 +0530 | [diff] [blame] | 2 | #include <linux/initrd.h> |
Pekka Enberg | 540aca0 | 2009-03-04 11:46:40 +0200 | [diff] [blame] | 3 | #include <linux/ioport.h> |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 4 | #include <linux/swap.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 5 | #include <linux/memblock.h> |
Pekka Enberg | 540aca0 | 2009-03-04 11:46:40 +0200 | [diff] [blame] | 6 | |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 7 | #include <asm/cacheflush.h> |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 8 | #include <asm/e820.h> |
Pekka Enberg | 4fcb208 | 2009-03-05 14:55:08 +0200 | [diff] [blame] | 9 | #include <asm/init.h> |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 10 | #include <asm/page.h> |
Pekka Enberg | 540aca0 | 2009-03-04 11:46:40 +0200 | [diff] [blame] | 11 | #include <asm/page_types.h> |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 12 | #include <asm/sections.h> |
Jan Beulich | 4983439 | 2009-05-06 13:06:47 +0100 | [diff] [blame] | 13 | #include <asm/setup.h> |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 14 | #include <asm/system.h> |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 15 | #include <asm/tlbflush.h> |
Pekka Enberg | 9518e0e | 2009-04-28 16:00:50 +0300 | [diff] [blame] | 16 | #include <asm/tlb.h> |
Jaswinder Singh Rajput | 76c0692 | 2009-07-01 19:54:23 +0530 | [diff] [blame] | 17 | #include <asm/proto.h> |
Pekka Enberg | 9518e0e | 2009-04-28 16:00:50 +0300 | [diff] [blame] | 18 | |
| 19 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 20 | |
Pekka Enberg | 298af9d | 2009-03-05 14:55:06 +0200 | [diff] [blame] | 21 | unsigned long __initdata e820_table_start; |
| 22 | unsigned long __meminitdata e820_table_end; |
| 23 | unsigned long __meminitdata e820_table_top; |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 24 | |
| 25 | int after_bootmem; |
| 26 | |
| 27 | int direct_gbpages |
| 28 | #ifdef CONFIG_DIRECT_GBPAGES |
| 29 | = 1 |
| 30 | #endif |
| 31 | ; |
| 32 | |
| 33 | static void __init find_early_table_space(unsigned long end, int use_pse, |
| 34 | int use_gbpages) |
| 35 | { |
Yinghai Lu | 4b239f4 | 2010-12-17 16:58:28 -0800 | [diff] [blame] | 36 | unsigned long puds, pmds, ptes, tables, start = 0, good_end = end; |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 37 | phys_addr_t base; |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 38 | |
| 39 | puds = (end + PUD_SIZE - 1) >> PUD_SHIFT; |
| 40 | tables = roundup(puds * sizeof(pud_t), PAGE_SIZE); |
| 41 | |
| 42 | if (use_gbpages) { |
| 43 | unsigned long extra; |
| 44 | |
| 45 | extra = end - ((end>>PUD_SHIFT) << PUD_SHIFT); |
| 46 | pmds = (extra + PMD_SIZE - 1) >> PMD_SHIFT; |
| 47 | } else |
| 48 | pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT; |
| 49 | |
| 50 | tables += roundup(pmds * sizeof(pmd_t), PAGE_SIZE); |
| 51 | |
| 52 | if (use_pse) { |
| 53 | unsigned long extra; |
| 54 | |
| 55 | extra = end - ((end>>PMD_SHIFT) << PMD_SHIFT); |
| 56 | #ifdef CONFIG_X86_32 |
| 57 | extra += PMD_SIZE; |
| 58 | #endif |
| 59 | ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 60 | } else |
| 61 | ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 62 | |
| 63 | tables += roundup(ptes * sizeof(pte_t), PAGE_SIZE); |
| 64 | |
| 65 | #ifdef CONFIG_X86_32 |
| 66 | /* for fixmap */ |
| 67 | tables += roundup(__end_of_fixed_addresses * sizeof(pte_t), PAGE_SIZE); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 68 | |
Yinghai Lu | 4b239f4 | 2010-12-17 16:58:28 -0800 | [diff] [blame] | 69 | good_end = max_pfn_mapped << PAGE_SHIFT; |
Yinghai Lu | 80989ce | 2009-05-09 23:47:42 -0700 | [diff] [blame] | 70 | #endif |
Yinghai Lu | 1411e0e | 2010-12-27 16:48:17 -0800 | [diff] [blame^] | 71 | |
Yinghai Lu | 4b239f4 | 2010-12-17 16:58:28 -0800 | [diff] [blame] | 72 | base = memblock_find_in_range(start, good_end, tables, PAGE_SIZE); |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 73 | if (base == MEMBLOCK_ERROR) |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 74 | panic("Cannot find space for the kernel page tables"); |
| 75 | |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 76 | e820_table_start = base >> PAGE_SHIFT; |
Pekka Enberg | 298af9d | 2009-03-05 14:55:06 +0200 | [diff] [blame] | 77 | e820_table_end = e820_table_start; |
| 78 | e820_table_top = e820_table_start + (tables >> PAGE_SHIFT); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 79 | |
| 80 | printk(KERN_DEBUG "kernel direct mapping tables up to %lx @ %lx-%lx\n", |
Pekka Enberg | 298af9d | 2009-03-05 14:55:06 +0200 | [diff] [blame] | 81 | end, e820_table_start << PAGE_SHIFT, e820_table_top << PAGE_SHIFT); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | struct map_range { |
| 85 | unsigned long start; |
| 86 | unsigned long end; |
| 87 | unsigned page_size_mask; |
| 88 | }; |
| 89 | |
| 90 | #ifdef CONFIG_X86_32 |
| 91 | #define NR_RANGE_MR 3 |
| 92 | #else /* CONFIG_X86_64 */ |
| 93 | #define NR_RANGE_MR 5 |
| 94 | #endif |
| 95 | |
Jan Beulich | dc9dd5c | 2009-03-12 12:40:06 +0000 | [diff] [blame] | 96 | static int __meminit save_mr(struct map_range *mr, int nr_range, |
| 97 | unsigned long start_pfn, unsigned long end_pfn, |
| 98 | unsigned long page_size_mask) |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 99 | { |
| 100 | if (start_pfn < end_pfn) { |
| 101 | if (nr_range >= NR_RANGE_MR) |
| 102 | panic("run out of range for init_memory_mapping\n"); |
| 103 | mr[nr_range].start = start_pfn<<PAGE_SHIFT; |
| 104 | mr[nr_range].end = end_pfn<<PAGE_SHIFT; |
| 105 | mr[nr_range].page_size_mask = page_size_mask; |
| 106 | nr_range++; |
| 107 | } |
| 108 | |
| 109 | return nr_range; |
| 110 | } |
| 111 | |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 112 | /* |
| 113 | * Setup the direct mapping of the physical memory at PAGE_OFFSET. |
| 114 | * This runs before bootmem is initialized and gets pages directly from |
| 115 | * the physical memory. To access them they are temporarily mapped. |
| 116 | */ |
| 117 | unsigned long __init_refok init_memory_mapping(unsigned long start, |
| 118 | unsigned long end) |
| 119 | { |
| 120 | unsigned long page_size_mask = 0; |
| 121 | unsigned long start_pfn, end_pfn; |
Pekka Enberg | c77a3b5 | 2009-03-05 17:04:26 +0200 | [diff] [blame] | 122 | unsigned long ret = 0; |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 123 | unsigned long pos; |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 124 | |
| 125 | struct map_range mr[NR_RANGE_MR]; |
| 126 | int nr_range, i; |
| 127 | int use_pse, use_gbpages; |
| 128 | |
| 129 | printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end); |
| 130 | |
Vegard Nossum | f856129 | 2008-04-04 00:53:23 +0200 | [diff] [blame] | 131 | #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK) |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 132 | /* |
| 133 | * For CONFIG_DEBUG_PAGEALLOC, identity mapping will use small pages. |
| 134 | * This will simplify cpa(), which otherwise needs to support splitting |
| 135 | * large pages into small in interrupt context, etc. |
| 136 | */ |
| 137 | use_pse = use_gbpages = 0; |
| 138 | #else |
| 139 | use_pse = cpu_has_pse; |
| 140 | use_gbpages = direct_gbpages; |
| 141 | #endif |
| 142 | |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 143 | /* Enable PSE if available */ |
| 144 | if (cpu_has_pse) |
| 145 | set_in_cr4(X86_CR4_PSE); |
| 146 | |
| 147 | /* Enable PGE if available */ |
| 148 | if (cpu_has_pge) { |
| 149 | set_in_cr4(X86_CR4_PGE); |
| 150 | __supported_pte_mask |= _PAGE_GLOBAL; |
| 151 | } |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 152 | |
| 153 | if (use_gbpages) |
| 154 | page_size_mask |= 1 << PG_LEVEL_1G; |
| 155 | if (use_pse) |
| 156 | page_size_mask |= 1 << PG_LEVEL_2M; |
| 157 | |
| 158 | memset(mr, 0, sizeof(mr)); |
| 159 | nr_range = 0; |
| 160 | |
| 161 | /* head if not big page alignment ? */ |
| 162 | start_pfn = start >> PAGE_SHIFT; |
| 163 | pos = start_pfn << PAGE_SHIFT; |
| 164 | #ifdef CONFIG_X86_32 |
| 165 | /* |
| 166 | * Don't use a large page for the first 2/4MB of memory |
| 167 | * because there are often fixed size MTRRs in there |
| 168 | * and overlapping MTRRs into large pages can cause |
| 169 | * slowdowns. |
| 170 | */ |
| 171 | if (pos == 0) |
| 172 | end_pfn = 1<<(PMD_SHIFT - PAGE_SHIFT); |
| 173 | else |
| 174 | end_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT) |
| 175 | << (PMD_SHIFT - PAGE_SHIFT); |
| 176 | #else /* CONFIG_X86_64 */ |
| 177 | end_pfn = ((pos + (PMD_SIZE - 1)) >> PMD_SHIFT) |
| 178 | << (PMD_SHIFT - PAGE_SHIFT); |
| 179 | #endif |
| 180 | if (end_pfn > (end >> PAGE_SHIFT)) |
| 181 | end_pfn = end >> PAGE_SHIFT; |
| 182 | if (start_pfn < end_pfn) { |
| 183 | nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, 0); |
| 184 | pos = end_pfn << PAGE_SHIFT; |
| 185 | } |
| 186 | |
| 187 | /* big page (2M) range */ |
| 188 | start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT) |
| 189 | << (PMD_SHIFT - PAGE_SHIFT); |
| 190 | #ifdef CONFIG_X86_32 |
| 191 | end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT); |
| 192 | #else /* CONFIG_X86_64 */ |
| 193 | end_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT) |
| 194 | << (PUD_SHIFT - PAGE_SHIFT); |
| 195 | if (end_pfn > ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT))) |
| 196 | end_pfn = ((end>>PMD_SHIFT)<<(PMD_SHIFT - PAGE_SHIFT)); |
| 197 | #endif |
| 198 | |
| 199 | if (start_pfn < end_pfn) { |
| 200 | nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, |
| 201 | page_size_mask & (1<<PG_LEVEL_2M)); |
| 202 | pos = end_pfn << PAGE_SHIFT; |
| 203 | } |
| 204 | |
| 205 | #ifdef CONFIG_X86_64 |
| 206 | /* big page (1G) range */ |
| 207 | start_pfn = ((pos + (PUD_SIZE - 1))>>PUD_SHIFT) |
| 208 | << (PUD_SHIFT - PAGE_SHIFT); |
| 209 | end_pfn = (end >> PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT); |
| 210 | if (start_pfn < end_pfn) { |
| 211 | nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, |
| 212 | page_size_mask & |
| 213 | ((1<<PG_LEVEL_2M)|(1<<PG_LEVEL_1G))); |
| 214 | pos = end_pfn << PAGE_SHIFT; |
| 215 | } |
| 216 | |
| 217 | /* tail is not big page (1G) alignment */ |
| 218 | start_pfn = ((pos + (PMD_SIZE - 1))>>PMD_SHIFT) |
| 219 | << (PMD_SHIFT - PAGE_SHIFT); |
| 220 | end_pfn = (end >> PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT); |
| 221 | if (start_pfn < end_pfn) { |
| 222 | nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, |
| 223 | page_size_mask & (1<<PG_LEVEL_2M)); |
| 224 | pos = end_pfn << PAGE_SHIFT; |
| 225 | } |
| 226 | #endif |
| 227 | |
| 228 | /* tail is not big page (2M) alignment */ |
| 229 | start_pfn = pos>>PAGE_SHIFT; |
| 230 | end_pfn = end>>PAGE_SHIFT; |
| 231 | nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, 0); |
| 232 | |
| 233 | /* try to merge same page size and continuous */ |
| 234 | for (i = 0; nr_range > 1 && i < nr_range - 1; i++) { |
| 235 | unsigned long old_start; |
| 236 | if (mr[i].end != mr[i+1].start || |
| 237 | mr[i].page_size_mask != mr[i+1].page_size_mask) |
| 238 | continue; |
| 239 | /* move it */ |
| 240 | old_start = mr[i].start; |
| 241 | memmove(&mr[i], &mr[i+1], |
| 242 | (nr_range - 1 - i) * sizeof(struct map_range)); |
| 243 | mr[i--].start = old_start; |
| 244 | nr_range--; |
| 245 | } |
| 246 | |
| 247 | for (i = 0; i < nr_range; i++) |
| 248 | printk(KERN_DEBUG " %010lx - %010lx page %s\n", |
| 249 | mr[i].start, mr[i].end, |
| 250 | (mr[i].page_size_mask & (1<<PG_LEVEL_1G))?"1G":( |
| 251 | (mr[i].page_size_mask & (1<<PG_LEVEL_2M))?"2M":"4k")); |
| 252 | |
| 253 | /* |
| 254 | * Find space for the kernel direct mapping tables. |
| 255 | * |
| 256 | * Later we should allocate these tables in the local node of the |
| 257 | * memory mapped. Unfortunately this is done currently before the |
| 258 | * nodes are discovered. |
| 259 | */ |
| 260 | if (!after_bootmem) |
| 261 | find_early_table_space(end, use_pse, use_gbpages); |
| 262 | |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 263 | for (i = 0; i < nr_range; i++) |
| 264 | ret = kernel_physical_mapping_init(mr[i].start, mr[i].end, |
| 265 | mr[i].page_size_mask); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 266 | |
| 267 | #ifdef CONFIG_X86_32 |
| 268 | early_ioremap_page_table_range_init(); |
| 269 | |
| 270 | load_cr3(swapper_pg_dir); |
| 271 | #endif |
| 272 | |
| 273 | #ifdef CONFIG_X86_64 |
Jan Beulich | 4983439 | 2009-05-06 13:06:47 +0100 | [diff] [blame] | 274 | if (!after_bootmem && !start) { |
| 275 | pud_t *pud; |
| 276 | pmd_t *pmd; |
| 277 | |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 278 | mmu_cr4_features = read_cr4(); |
Jan Beulich | 4983439 | 2009-05-06 13:06:47 +0100 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * _brk_end cannot change anymore, but it and _end may be |
| 282 | * located on different 2M pages. cleanup_highmap(), however, |
| 283 | * can only consider _end when it runs, so destroy any |
| 284 | * mappings beyond _brk_end here. |
| 285 | */ |
| 286 | pud = pud_offset(pgd_offset_k(_brk_end), _brk_end); |
| 287 | pmd = pmd_offset(pud, _brk_end - 1); |
| 288 | while (++pmd <= pmd_offset(pud, (unsigned long)_end - 1)) |
| 289 | pmd_clear(pmd); |
| 290 | } |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 291 | #endif |
| 292 | __flush_tlb_all(); |
| 293 | |
Pekka Enberg | 298af9d | 2009-03-05 14:55:06 +0200 | [diff] [blame] | 294 | if (!after_bootmem && e820_table_end > e820_table_start) |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 295 | memblock_x86_reserve_range(e820_table_start << PAGE_SHIFT, |
Pekka Enberg | 298af9d | 2009-03-05 14:55:06 +0200 | [diff] [blame] | 296 | e820_table_end << PAGE_SHIFT, "PGTABLE"); |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 297 | |
| 298 | if (!after_bootmem) |
| 299 | early_memtest(start, end); |
| 300 | |
| 301 | return ret >> PAGE_SHIFT; |
| 302 | } |
| 303 | |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 304 | |
Pekka Enberg | 540aca0 | 2009-03-04 11:46:40 +0200 | [diff] [blame] | 305 | /* |
| 306 | * devmem_is_allowed() checks to see if /dev/mem access to a certain address |
| 307 | * is valid. The argument is a physical page number. |
| 308 | * |
| 309 | * |
| 310 | * On x86, access has to be given to the first megabyte of ram because that area |
| 311 | * contains bios code and data regions used by X and dosemu and similar apps. |
| 312 | * Access has to be given to non-kernel-ram areas as well, these contain the PCI |
| 313 | * mmio resources as well as potential bios/acpi data regions. |
| 314 | */ |
| 315 | int devmem_is_allowed(unsigned long pagenr) |
| 316 | { |
| 317 | if (pagenr <= 256) |
| 318 | return 1; |
| 319 | if (iomem_is_exclusive(pagenr << PAGE_SHIFT)) |
| 320 | return 0; |
| 321 | if (!page_is_ram(pagenr)) |
| 322 | return 1; |
| 323 | return 0; |
| 324 | } |
| 325 | |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 326 | void free_init_pages(char *what, unsigned long begin, unsigned long end) |
| 327 | { |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 328 | unsigned long addr; |
| 329 | unsigned long begin_aligned, end_aligned; |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 330 | |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 331 | /* Make sure boundaries are page aligned */ |
| 332 | begin_aligned = PAGE_ALIGN(begin); |
| 333 | end_aligned = end & PAGE_MASK; |
| 334 | |
| 335 | if (WARN_ON(begin_aligned != begin || end_aligned != end)) { |
| 336 | begin = begin_aligned; |
| 337 | end = end_aligned; |
| 338 | } |
| 339 | |
| 340 | if (begin >= end) |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 341 | return; |
| 342 | |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 343 | addr = begin; |
| 344 | |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 345 | /* |
| 346 | * If debugging page accesses then do not free this memory but |
| 347 | * mark them not present - any buggy init-section access will |
| 348 | * create a kernel page fault: |
| 349 | */ |
| 350 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 351 | printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n", |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 352 | begin, end); |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 353 | set_memory_np(begin, (end - begin) >> PAGE_SHIFT); |
| 354 | #else |
| 355 | /* |
| 356 | * We just marked the kernel text read only above, now that |
| 357 | * we are going to free part of that, we need to make that |
| 358 | * writeable first. |
| 359 | */ |
| 360 | set_memory_rw(begin, (end - begin) >> PAGE_SHIFT); |
| 361 | |
| 362 | printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); |
| 363 | |
| 364 | for (; addr < end; addr += PAGE_SIZE) { |
| 365 | ClearPageReserved(virt_to_page(addr)); |
| 366 | init_page_count(virt_to_page(addr)); |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 367 | memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE); |
Pekka Enberg | e5b2bb5 | 2009-03-03 13:15:06 +0200 | [diff] [blame] | 368 | free_page(addr); |
| 369 | totalram_pages++; |
| 370 | } |
| 371 | #endif |
| 372 | } |
| 373 | |
| 374 | void free_initmem(void) |
| 375 | { |
| 376 | free_init_pages("unused kernel memory", |
| 377 | (unsigned long)(&__init_begin), |
| 378 | (unsigned long)(&__init_end)); |
| 379 | } |
Pekka Enberg | 731ddea | 2009-03-04 11:13:40 +0200 | [diff] [blame] | 380 | |
| 381 | #ifdef CONFIG_BLK_DEV_INITRD |
| 382 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 383 | { |
Yinghai Lu | c967da6 | 2010-03-28 19:42:55 -0700 | [diff] [blame] | 384 | /* |
| 385 | * end could be not aligned, and We can not align that, |
| 386 | * decompresser could be confused by aligned initrd_end |
| 387 | * We already reserve the end partial page before in |
| 388 | * - i386_start_kernel() |
| 389 | * - x86_64_start_kernel() |
| 390 | * - relocate_initrd() |
| 391 | * So here We can do PAGE_ALIGN() safely to get partial page to be freed |
| 392 | */ |
| 393 | free_init_pages("initrd memory", start, PAGE_ALIGN(end)); |
Pekka Enberg | 731ddea | 2009-03-04 11:13:40 +0200 | [diff] [blame] | 394 | } |
| 395 | #endif |