ia64/xen-unstable

view linux-2.6-xen-sparse/arch/xen/i386/mm/init.c @ 6316:f7dfaa2af90c

merge?
author cl349@firebug.cl.cam.ac.uk
date Sun Aug 21 11:02:00 2005 +0000 (2005-08-21)
parents 1872e09bfba3
children 6721abf6b16d
line source
1 /*
2 * linux/arch/i386/mm/init.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 *
6 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
7 */
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/string.h>
16 #include <linux/types.h>
17 #include <linux/ptrace.h>
18 #include <linux/mman.h>
19 #include <linux/mm.h>
20 #include <linux/hugetlb.h>
21 #include <linux/swap.h>
22 #include <linux/smp.h>
23 #include <linux/init.h>
24 #include <linux/highmem.h>
25 #include <linux/pagemap.h>
26 #include <linux/bootmem.h>
27 #include <linux/slab.h>
28 #include <linux/proc_fs.h>
29 #include <linux/efi.h>
31 #include <asm/processor.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/dma.h>
36 #include <asm/fixmap.h>
37 #include <asm/e820.h>
38 #include <asm/apic.h>
39 #include <asm/tlb.h>
40 #include <asm/tlbflush.h>
41 #include <asm/sections.h>
42 #include <asm-xen/hypervisor.h>
44 extern unsigned long *contiguous_bitmap;
46 #if defined(CONFIG_SWIOTLB)
47 extern void swiotlb_init(void);
48 int swiotlb;
49 EXPORT_SYMBOL(swiotlb);
50 #endif
52 unsigned int __VMALLOC_RESERVE = 128 << 20;
54 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
55 unsigned long highstart_pfn, highend_pfn;
57 static int noinline do_test_wp_bit(void);
59 /*
60 * Creates a middle page table and puts a pointer to it in the
61 * given global directory entry. This only returns the gd entry
62 * in non-PAE compilation mode, since the middle layer is folded.
63 */
64 static pmd_t * __init one_md_table_init(pgd_t *pgd)
65 {
66 pud_t *pud;
67 pmd_t *pmd_table;
69 #ifdef CONFIG_X86_PAE
70 pmd_table = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE);
71 make_page_readonly(pmd_table);
72 set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
73 pud = pud_offset(pgd, 0);
74 if (pmd_table != pmd_offset(pud, 0))
75 BUG();
76 #else
77 pud = pud_offset(pgd, 0);
78 pmd_table = pmd_offset(pud, 0);
79 #endif
81 return pmd_table;
82 }
84 /*
85 * Create a page table and place a pointer to it in a middle page
86 * directory entry.
87 */
88 static pte_t * __init one_page_table_init(pmd_t *pmd)
89 {
90 if (pmd_none(*pmd)) {
91 pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
92 make_page_readonly(page_table);
93 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
94 if (page_table != pte_offset_kernel(pmd, 0))
95 BUG();
97 return page_table;
98 }
100 return pte_offset_kernel(pmd, 0);
101 }
103 /*
104 * This function initializes a certain range of kernel virtual memory
105 * with new bootmem page tables, everywhere page tables are missing in
106 * the given range.
107 */
109 /*
110 * NOTE: The pagetables are allocated contiguous on the physical space
111 * so we can cache the place of the first one and move around without
112 * checking the pgd every time.
113 */
114 static void __init page_table_range_init (unsigned long start, unsigned long end, pgd_t *pgd_base)
115 {
116 pgd_t *pgd;
117 pud_t *pud;
118 pmd_t *pmd;
119 int pgd_idx, pmd_idx;
120 unsigned long vaddr;
122 vaddr = start;
123 pgd_idx = pgd_index(vaddr);
124 pmd_idx = pmd_index(vaddr);
125 pgd = pgd_base + pgd_idx;
127 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
128 if (pgd_none(*pgd))
129 one_md_table_init(pgd);
130 pud = pud_offset(pgd, vaddr);
131 pmd = pmd_offset(pud, vaddr);
132 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end); pmd++, pmd_idx++) {
133 if (vaddr < HYPERVISOR_VIRT_START && pmd_none(*pmd))
134 one_page_table_init(pmd);
136 vaddr += PMD_SIZE;
137 }
138 pmd_idx = 0;
139 }
140 }
142 static inline int is_kernel_text(unsigned long addr)
143 {
144 if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
145 return 1;
146 return 0;
147 }
149 /*
150 * This maps the physical memory to kernel virtual address space, a total
151 * of max_low_pfn pages, by creating page tables starting from address
152 * PAGE_OFFSET.
153 */
154 static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
155 {
156 unsigned long pfn;
157 pgd_t *pgd;
158 pmd_t *pmd;
159 pte_t *pte;
160 int pgd_idx, pmd_idx, pte_ofs;
162 unsigned long max_ram_pfn = xen_start_info.nr_pages;
163 if (max_ram_pfn > max_low_pfn)
164 max_ram_pfn = max_low_pfn;
166 pgd_idx = pgd_index(PAGE_OFFSET);
167 pgd = pgd_base + pgd_idx;
168 pfn = 0;
169 pmd_idx = pmd_index(PAGE_OFFSET);
170 pte_ofs = pte_index(PAGE_OFFSET);
172 for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
173 #ifdef CONFIG_XEN
174 /*
175 * Native linux hasn't PAE-paging enabled yet at this
176 * point. When running as xen domain we are in PAE
177 * mode already, thus we can't simply hook a empty
178 * pmd. That would kill the mappings we are currently
179 * using ...
180 */
181 pmd = pmd_offset(pud_offset(pgd, PAGE_OFFSET), PAGE_OFFSET);
182 #else
183 pmd = one_md_table_init(pgd);
184 #endif
185 if (pfn >= max_low_pfn)
186 continue;
187 pmd += pmd_idx;
188 for (; pmd_idx < PTRS_PER_PMD && pfn < max_low_pfn; pmd++, pmd_idx++) {
189 unsigned int address = pfn * PAGE_SIZE + PAGE_OFFSET;
190 if (address >= HYPERVISOR_VIRT_START)
191 continue;
193 /* Map with big pages if possible, otherwise create normal page tables. */
194 if (cpu_has_pse) {
195 unsigned int address2 = (pfn + PTRS_PER_PTE - 1) * PAGE_SIZE + PAGE_OFFSET + PAGE_SIZE-1;
197 if (is_kernel_text(address) || is_kernel_text(address2))
198 set_pmd(pmd, pfn_pmd(pfn, PAGE_KERNEL_LARGE_EXEC));
199 else
200 set_pmd(pmd, pfn_pmd(pfn, PAGE_KERNEL_LARGE));
201 pfn += PTRS_PER_PTE;
202 } else {
203 pte = one_page_table_init(pmd);
205 pte += pte_ofs;
206 for (; pte_ofs < PTRS_PER_PTE && pfn < max_low_pfn; pte++, pfn++, pte_ofs++) {
207 /* XEN: Only map initial RAM allocation. */
208 if ((pfn >= max_ram_pfn) || pte_present(*pte))
209 continue;
210 if (is_kernel_text(address))
211 set_pte(pte, pfn_pte(pfn, PAGE_KERNEL_EXEC));
212 else
213 set_pte(pte, pfn_pte(pfn, PAGE_KERNEL));
214 }
215 pte_ofs = 0;
216 }
217 }
218 pmd_idx = 0;
219 }
220 }
222 static inline int page_kills_ppro(unsigned long pagenr)
223 {
224 if (pagenr >= 0x70000 && pagenr <= 0x7003F)
225 return 1;
226 return 0;
227 }
229 extern int is_available_memory(efi_memory_desc_t *);
231 static inline int page_is_ram(unsigned long pagenr)
232 {
233 int i;
234 unsigned long addr, end;
236 if (efi_enabled) {
237 efi_memory_desc_t *md;
239 for (i = 0; i < memmap.nr_map; i++) {
240 md = &memmap.map[i];
241 if (!is_available_memory(md))
242 continue;
243 addr = (md->phys_addr+PAGE_SIZE-1) >> PAGE_SHIFT;
244 end = (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) >> PAGE_SHIFT;
246 if ((pagenr >= addr) && (pagenr < end))
247 return 1;
248 }
249 return 0;
250 }
252 for (i = 0; i < e820.nr_map; i++) {
254 if (e820.map[i].type != E820_RAM) /* not usable memory */
255 continue;
256 /*
257 * !!!FIXME!!! Some BIOSen report areas as RAM that
258 * are not. Notably the 640->1Mb area. We need a sanity
259 * check here.
260 */
261 addr = (e820.map[i].addr+PAGE_SIZE-1) >> PAGE_SHIFT;
262 end = (e820.map[i].addr+e820.map[i].size) >> PAGE_SHIFT;
263 if ((pagenr >= addr) && (pagenr < end))
264 return 1;
265 }
266 return 0;
267 }
269 #ifdef CONFIG_HIGHMEM
270 pte_t *kmap_pte;
271 pgprot_t kmap_prot;
273 #define kmap_get_fixmap_pte(vaddr) \
274 pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), vaddr), (vaddr)), (vaddr))
276 static void __init kmap_init(void)
277 {
278 unsigned long kmap_vstart;
280 /* cache the first kmap pte */
281 kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
282 kmap_pte = kmap_get_fixmap_pte(kmap_vstart);
284 kmap_prot = PAGE_KERNEL;
285 }
287 static void __init permanent_kmaps_init(pgd_t *pgd_base)
288 {
289 pgd_t *pgd;
290 pud_t *pud;
291 pmd_t *pmd;
292 pte_t *pte;
293 unsigned long vaddr;
295 vaddr = PKMAP_BASE;
296 page_table_range_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base);
298 pgd = swapper_pg_dir + pgd_index(vaddr);
299 pud = pud_offset(pgd, vaddr);
300 pmd = pmd_offset(pud, vaddr);
301 pte = pte_offset_kernel(pmd, vaddr);
302 pkmap_page_table = pte;
303 }
305 void __init one_highpage_init(struct page *page, int pfn, int bad_ppro)
306 {
307 if (page_is_ram(pfn) && !(bad_ppro && page_kills_ppro(pfn))) {
308 ClearPageReserved(page);
309 set_bit(PG_highmem, &page->flags);
310 set_page_count(page, 1);
311 if (pfn < xen_start_info.nr_pages)
312 __free_page(page);
313 totalhigh_pages++;
314 } else
315 SetPageReserved(page);
316 }
318 #ifndef CONFIG_DISCONTIGMEM
319 static void __init set_highmem_pages_init(int bad_ppro)
320 {
321 int pfn;
322 for (pfn = highstart_pfn; pfn < highend_pfn; pfn++)
323 one_highpage_init(pfn_to_page(pfn), pfn, bad_ppro);
324 totalram_pages += totalhigh_pages;
325 }
326 #else
327 extern void set_highmem_pages_init(int);
328 #endif /* !CONFIG_DISCONTIGMEM */
330 #else
331 #define kmap_init() do { } while (0)
332 #define permanent_kmaps_init(pgd_base) do { } while (0)
333 #define set_highmem_pages_init(bad_ppro) do { } while (0)
334 #endif /* CONFIG_HIGHMEM */
336 unsigned long long __PAGE_KERNEL = _PAGE_KERNEL;
337 unsigned long long __PAGE_KERNEL_EXEC = _PAGE_KERNEL_EXEC;
339 #ifndef CONFIG_DISCONTIGMEM
340 #define remap_numa_kva() do {} while (0)
341 #else
342 extern void __init remap_numa_kva(void);
343 #endif
345 pgd_t *swapper_pg_dir;
347 static void __init pagetable_init (void)
348 {
349 unsigned long vaddr;
350 pgd_t *pgd_base = (pgd_t *)xen_start_info.pt_base;
352 swapper_pg_dir = pgd_base;
353 init_mm.pgd = pgd_base;
355 #ifdef CONFIG_X86_PAE
356 int i;
357 /* Init entries of the first-level page table to the zero page */
358 for (i = 0; i < PTRS_PER_PGD; i++)
359 set_pgd(pgd_base + i, __pgd(__pa(empty_zero_page) | _PAGE_PRESENT));
360 #endif
362 /* Enable PSE if available */
363 if (cpu_has_pse) {
364 set_in_cr4(X86_CR4_PSE);
365 }
367 /* Enable PGE if available */
368 if (cpu_has_pge) {
369 set_in_cr4(X86_CR4_PGE);
370 __PAGE_KERNEL |= _PAGE_GLOBAL;
371 __PAGE_KERNEL_EXEC |= _PAGE_GLOBAL;
372 }
374 init_mm.context.pinned = 1;
375 kernel_physical_mapping_init(pgd_base);
376 remap_numa_kva();
378 /*
379 * Fixed mappings, only the page table structure has to be
380 * created - mappings will be set by set_fixmap():
381 */
382 vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK;
383 page_table_range_init(vaddr, 0, pgd_base);
385 permanent_kmaps_init(pgd_base);
387 #if 0 /* def CONFIG_X86_PAE */
388 /*
389 * Add low memory identity-mappings - SMP needs it when
390 * starting up on an AP from real-mode. In the non-PAE
391 * case we already have these mappings through head.S.
392 * All user-space mappings are explicitly cleared after
393 * SMP startup.
394 */
395 set_pgd(&pgd_base[0], pgd_base[USER_PTRS_PER_PGD]);
396 #endif
397 }
399 #if defined(CONFIG_PM_DISK) || defined(CONFIG_SOFTWARE_SUSPEND)
400 /*
401 * Swap suspend & friends need this for resume because things like the intel-agp
402 * driver might have split up a kernel 4MB mapping.
403 */
404 char __nosavedata swsusp_pg_dir[PAGE_SIZE]
405 __attribute__ ((aligned (PAGE_SIZE)));
407 static inline void save_pg_dir(void)
408 {
409 memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
410 }
411 #else
412 static inline void save_pg_dir(void)
413 {
414 }
415 #endif
417 void zap_low_mappings (void)
418 {
419 int i;
421 save_pg_dir();
423 /*
424 * Zap initial low-memory mappings.
425 *
426 * Note that "pgd_clear()" doesn't do it for
427 * us, because pgd_clear() is a no-op on i386.
428 */
429 for (i = 0; i < USER_PTRS_PER_PGD; i++)
430 #if defined(CONFIG_X86_PAE) && !defined(CONFIG_XEN)
431 set_pgd(swapper_pg_dir+i, __pgd(1 + __pa(empty_zero_page)));
432 #else
433 set_pgd(swapper_pg_dir+i, __pgd(0));
434 #endif
435 flush_tlb_all();
436 }
438 static int disable_nx __initdata = 0;
439 u64 __supported_pte_mask = ~_PAGE_NX;
441 /*
442 * noexec = on|off
443 *
444 * Control non executable mappings.
445 *
446 * on Enable
447 * off Disable
448 */
449 void __init noexec_setup(const char *str)
450 {
451 if (!strncmp(str, "on",2) && cpu_has_nx) {
452 __supported_pte_mask |= _PAGE_NX;
453 disable_nx = 0;
454 } else if (!strncmp(str,"off",3)) {
455 disable_nx = 1;
456 __supported_pte_mask &= ~_PAGE_NX;
457 }
458 }
460 int nx_enabled = 0;
461 #ifdef CONFIG_X86_PAE
463 static void __init set_nx(void)
464 {
465 unsigned int v[4], l, h;
467 if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
468 cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
469 if ((v[3] & (1 << 20)) && !disable_nx) {
470 rdmsr(MSR_EFER, l, h);
471 l |= EFER_NX;
472 wrmsr(MSR_EFER, l, h);
473 nx_enabled = 1;
474 __supported_pte_mask |= _PAGE_NX;
475 }
476 }
477 }
479 /*
480 * Enables/disables executability of a given kernel page and
481 * returns the previous setting.
482 */
483 int __init set_kernel_exec(unsigned long vaddr, int enable)
484 {
485 pte_t *pte;
486 int ret = 1;
488 if (!nx_enabled)
489 goto out;
491 pte = lookup_address(vaddr);
492 BUG_ON(!pte);
494 if (!pte_exec_kernel(*pte))
495 ret = 0;
497 if (enable)
498 pte->pte_high &= ~(1 << (_PAGE_BIT_NX - 32));
499 else
500 pte->pte_high |= 1 << (_PAGE_BIT_NX - 32);
501 __flush_tlb_all();
502 out:
503 return ret;
504 }
506 #endif
508 /*
509 * paging_init() sets up the page tables - note that the first 8MB are
510 * already mapped by head.S.
511 *
512 * This routines also unmaps the page at virtual kernel address 0, so
513 * that we can trap those pesky NULL-reference errors in the kernel.
514 */
515 void __init paging_init(void)
516 {
517 #ifdef CONFIG_XEN_PHYSDEV_ACCESS
518 int i;
519 #endif
521 #ifdef CONFIG_X86_PAE
522 set_nx();
523 if (nx_enabled)
524 printk("NX (Execute Disable) protection: active\n");
525 #endif
527 pagetable_init();
529 #if defined(CONFIG_X86_PAE) && !defined(CONFIG_XEN)
530 /*
531 * We will bail out later - printk doesn't work right now so
532 * the user would just see a hanging kernel.
533 * when running as xen domain we are already in PAE mode at
534 * this point.
535 */
536 if (cpu_has_pae)
537 set_in_cr4(X86_CR4_PAE);
538 #endif
539 __flush_tlb_all();
541 kmap_init();
543 /* Switch to the real shared_info page, and clear the dummy page. */
544 set_fixmap(FIX_SHARED_INFO, xen_start_info.shared_info);
545 HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
546 memset(empty_zero_page, 0, sizeof(empty_zero_page));
548 #ifdef CONFIG_XEN_PHYSDEV_ACCESS
549 /* Setup mapping of lower 1st MB */
550 for (i = 0; i < NR_FIX_ISAMAPS; i++)
551 if (xen_start_info.flags & SIF_PRIVILEGED)
552 set_fixmap(FIX_ISAMAP_BEGIN - i, i * PAGE_SIZE);
553 else
554 __set_fixmap(FIX_ISAMAP_BEGIN - i,
555 virt_to_machine(empty_zero_page),
556 PAGE_KERNEL_RO);
557 #endif
558 }
560 /*
561 * Test if the WP bit works in supervisor mode. It isn't supported on 386's
562 * and also on some strange 486's (NexGen etc.). All 586+'s are OK. This
563 * used to involve black magic jumps to work around some nasty CPU bugs,
564 * but fortunately the switch to using exceptions got rid of all that.
565 */
567 static void __init test_wp_bit(void)
568 {
569 printk("Checking if this processor honours the WP bit even in supervisor mode... ");
571 /* Any page-aligned address will do, the test is non-destructive */
572 __set_fixmap(FIX_WP_TEST, __pa(&swapper_pg_dir), PAGE_READONLY);
573 boot_cpu_data.wp_works_ok = do_test_wp_bit();
574 clear_fixmap(FIX_WP_TEST);
576 if (!boot_cpu_data.wp_works_ok) {
577 printk("No.\n");
578 #ifdef CONFIG_X86_WP_WORKS_OK
579 panic("This kernel doesn't support CPU's with broken WP. Recompile it for a 386!");
580 #endif
581 } else {
582 printk("Ok.\n");
583 }
584 }
586 static void __init set_max_mapnr_init(void)
587 {
588 #ifdef CONFIG_HIGHMEM
589 num_physpages = highend_pfn;
590 #else
591 num_physpages = max_low_pfn;
592 #endif
593 #ifndef CONFIG_DISCONTIGMEM
594 max_mapnr = num_physpages;
595 #endif
596 }
598 static struct kcore_list kcore_mem, kcore_vmalloc;
600 void __init mem_init(void)
601 {
602 extern int ppro_with_ram_bug(void);
603 int codesize, reservedpages, datasize, initsize;
604 int tmp;
605 int bad_ppro;
606 unsigned long pfn;
608 contiguous_bitmap = alloc_bootmem_low_pages(
609 (max_low_pfn + 2*BITS_PER_LONG) >> 3);
610 BUG_ON(!contiguous_bitmap);
611 memset(contiguous_bitmap, 0, (max_low_pfn + 2*BITS_PER_LONG) >> 3);
613 #if defined(CONFIG_SWIOTLB)
614 swiotlb_init();
615 #endif
617 #ifndef CONFIG_DISCONTIGMEM
618 if (!mem_map)
619 BUG();
620 #endif
622 bad_ppro = ppro_with_ram_bug();
624 #ifdef CONFIG_HIGHMEM
625 /* check that fixmap and pkmap do not overlap */
626 if (PKMAP_BASE+LAST_PKMAP*PAGE_SIZE >= FIXADDR_START) {
627 printk(KERN_ERR "fixmap and kmap areas overlap - this will crash\n");
628 printk(KERN_ERR "pkstart: %lxh pkend: %lxh fixstart %lxh\n",
629 PKMAP_BASE, PKMAP_BASE+LAST_PKMAP*PAGE_SIZE, FIXADDR_START);
630 BUG();
631 }
632 #endif
634 set_max_mapnr_init();
636 #ifdef CONFIG_HIGHMEM
637 high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
638 #else
639 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
640 #endif
641 printk("vmalloc area: %lx-%lx, maxmem %lx\n",
642 VMALLOC_START,VMALLOC_END,MAXMEM);
643 BUG_ON(VMALLOC_START > VMALLOC_END);
645 /* this will put all low memory onto the freelists */
646 totalram_pages += free_all_bootmem();
647 /* XEN: init and count low-mem pages outside initial allocation. */
648 for (pfn = xen_start_info.nr_pages; pfn < max_low_pfn; pfn++) {
649 ClearPageReserved(&mem_map[pfn]);
650 set_page_count(&mem_map[pfn], 1);
651 totalram_pages++;
652 }
654 reservedpages = 0;
655 for (tmp = 0; tmp < max_low_pfn; tmp++)
656 /*
657 * Only count reserved RAM pages
658 */
659 if (page_is_ram(tmp) && PageReserved(pfn_to_page(tmp)))
660 reservedpages++;
662 set_highmem_pages_init(bad_ppro);
664 codesize = (unsigned long) &_etext - (unsigned long) &_text;
665 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
666 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
668 kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
669 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
670 VMALLOC_END-VMALLOC_START);
672 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init, %ldk highmem)\n",
673 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
674 num_physpages << (PAGE_SHIFT-10),
675 codesize >> 10,
676 reservedpages << (PAGE_SHIFT-10),
677 datasize >> 10,
678 initsize >> 10,
679 (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10))
680 );
682 #ifdef CONFIG_X86_PAE
683 if (!cpu_has_pae)
684 panic("cannot execute a PAE-enabled kernel on a PAE-less CPU!");
685 #endif
686 if (boot_cpu_data.wp_works_ok < 0)
687 test_wp_bit();
689 /*
690 * Subtle. SMP is doing it's boot stuff late (because it has to
691 * fork idle threads) - but it also needs low mappings for the
692 * protected-mode entry to work. We zap these entries only after
693 * the WP-bit has been tested.
694 */
695 #ifndef CONFIG_SMP
696 zap_low_mappings();
697 #endif
698 }
700 kmem_cache_t *pgd_cache;
701 kmem_cache_t *pmd_cache;
703 void __init pgtable_cache_init(void)
704 {
705 if (PTRS_PER_PMD > 1) {
706 pmd_cache = kmem_cache_create("pmd",
707 PTRS_PER_PMD*sizeof(pmd_t),
708 PTRS_PER_PMD*sizeof(pmd_t),
709 0,
710 pmd_ctor,
711 NULL);
712 if (!pmd_cache)
713 panic("pgtable_cache_init(): cannot create pmd cache");
714 }
715 pgd_cache = kmem_cache_create("pgd",
716 #if 0 /* How the heck _this_ works in native linux ??? */
717 PTRS_PER_PGD*sizeof(pgd_t),
718 PTRS_PER_PGD*sizeof(pgd_t),
719 #else
720 PAGE_SIZE,
721 PAGE_SIZE,
722 #endif
723 0,
724 pgd_ctor,
725 pgd_dtor);
726 if (!pgd_cache)
727 panic("pgtable_cache_init(): Cannot create pgd cache");
728 }
730 /*
731 * This function cannot be __init, since exceptions don't work in that
732 * section. Put this after the callers, so that it cannot be inlined.
733 */
734 static int noinline do_test_wp_bit(void)
735 {
736 char tmp_reg;
737 int flag;
739 __asm__ __volatile__(
740 " movb %0,%1 \n"
741 "1: movb %1,%0 \n"
742 " xorl %2,%2 \n"
743 "2: \n"
744 ".section __ex_table,\"a\"\n"
745 " .align 4 \n"
746 " .long 1b,2b \n"
747 ".previous \n"
748 :"=m" (*(char *)fix_to_virt(FIX_WP_TEST)),
749 "=q" (tmp_reg),
750 "=r" (flag)
751 :"2" (1)
752 :"memory");
754 return flag;
755 }
757 void free_initmem(void)
758 {
759 unsigned long addr;
761 addr = (unsigned long)(&__init_begin);
762 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
763 ClearPageReserved(virt_to_page(addr));
764 set_page_count(virt_to_page(addr), 1);
765 memset((void *)addr, 0xcc, PAGE_SIZE);
766 free_page(addr);
767 totalram_pages++;
768 }
769 printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", (__init_end - __init_begin) >> 10);
770 }
772 #ifdef CONFIG_BLK_DEV_INITRD
773 void free_initrd_mem(unsigned long start, unsigned long end)
774 {
775 if (start < end)
776 printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
777 for (; start < end; start += PAGE_SIZE) {
778 ClearPageReserved(virt_to_page(start));
779 set_page_count(virt_to_page(start), 1);
780 free_page(start);
781 totalram_pages++;
782 }
783 }
784 #endif