📄 init.c
字号:
/* * Initialize MMU support. * * Copyright (C) 1998-2003 Hewlett-Packard Co * David Mosberger-Tang <davidm@hpl.hp.com> */#include <linux/config.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/bootmem.h>#include <linux/efi.h>#include <linux/elf.h>#include <linux/mm.h>#include <linux/mmzone.h>#include <linux/module.h>#include <linux/personality.h>#include <linux/reboot.h>#include <linux/slab.h>#include <linux/swap.h>#include <linux/proc_fs.h>#include <linux/bitops.h>#include <asm/a.out.h>#include <asm/dma.h>#include <asm/ia32.h>#include <asm/io.h>#include <asm/machvec.h>#include <asm/numa.h>#include <asm/patch.h>#include <asm/pgalloc.h>#include <asm/sal.h>#include <asm/sections.h>#include <asm/system.h>#include <asm/tlb.h>#include <asm/uaccess.h>#include <asm/unistd.h>#include <asm/mca.h>DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);extern void ia64_tlb_init (void);unsigned long MAX_DMA_ADDRESS = PAGE_OFFSET + 0x100000000UL;#ifdef CONFIG_VIRTUAL_MEM_MAPunsigned long vmalloc_end = VMALLOC_END_INIT;EXPORT_SYMBOL(vmalloc_end);struct page *vmem_map;EXPORT_SYMBOL(vmem_map);#endifstatic int pgt_cache_water[2] = { 25, 50 };struct page *zero_page_memmap_ptr; /* map entry for zero page */EXPORT_SYMBOL(zero_page_memmap_ptr);voidcheck_pgt_cache (void){ int low, high; low = pgt_cache_water[0]; high = pgt_cache_water[1]; preempt_disable(); if (pgtable_cache_size > (u64) high) { do { if (pgd_quicklist) free_page((unsigned long)pgd_alloc_one_fast(NULL)); if (pmd_quicklist) free_page((unsigned long)pmd_alloc_one_fast(NULL, 0)); } while (pgtable_cache_size > (u64) low); } preempt_enable();}voidupdate_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte){ unsigned long addr; struct page *page; if (!pte_exec(pte)) return; /* not an executable page... */ page = pte_page(pte); /* don't use VADDR: it may not be mapped on this CPU (or may have just been flushed): */ addr = (unsigned long) page_address(page); if (test_bit(PG_arch_1, &page->flags)) return; /* i-cache is already coherent with d-cache */ flush_icache_range(addr, addr + PAGE_SIZE); set_bit(PG_arch_1, &page->flags); /* mark page as clean */}inline voidia64_set_rbs_bot (void){ unsigned long stack_size = current->signal->rlim[RLIMIT_STACK].rlim_max & -16; if (stack_size > MAX_USER_STACK_SIZE) stack_size = MAX_USER_STACK_SIZE; current->thread.rbs_bot = STACK_TOP - stack_size;}/* * This performs some platform-dependent address space initialization. * On IA-64, we want to setup the VM area for the register backing * store (which grows upwards) and install the gateway page which is * used for signal trampolines, etc. */voidia64_init_addr_space (void){ struct vm_area_struct *vma; ia64_set_rbs_bot(); /* * If we're out of memory and kmem_cache_alloc() returns NULL, we simply ignore * the problem. When the process attempts to write to the register backing store * for the first time, it will get a SEGFAULT in this case. */ vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); if (vma) { memset(vma, 0, sizeof(*vma)); vma->vm_mm = current->mm; vma->vm_start = current->thread.rbs_bot & PAGE_MASK; vma->vm_end = vma->vm_start + PAGE_SIZE; vma->vm_page_prot = protection_map[VM_DATA_DEFAULT_FLAGS & 0x7]; vma->vm_flags = VM_DATA_DEFAULT_FLAGS | VM_GROWSUP; down_write(¤t->mm->mmap_sem); if (insert_vm_struct(current->mm, vma)) { up_write(¤t->mm->mmap_sem); kmem_cache_free(vm_area_cachep, vma); return; } up_write(¤t->mm->mmap_sem); } /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */ if (!(current->personality & MMAP_PAGE_ZERO)) { vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); if (vma) { memset(vma, 0, sizeof(*vma)); vma->vm_mm = current->mm; vma->vm_end = PAGE_SIZE; vma->vm_page_prot = __pgprot(pgprot_val(PAGE_READONLY) | _PAGE_MA_NAT); vma->vm_flags = VM_READ | VM_MAYREAD | VM_IO | VM_RESERVED; down_write(¤t->mm->mmap_sem); if (insert_vm_struct(current->mm, vma)) { up_write(¤t->mm->mmap_sem); kmem_cache_free(vm_area_cachep, vma); return; } up_write(¤t->mm->mmap_sem); } }}voidfree_initmem (void){ unsigned long addr, eaddr; addr = (unsigned long) ia64_imva(__init_begin); eaddr = (unsigned long) ia64_imva(__init_end); while (addr < eaddr) { ClearPageReserved(virt_to_page(addr)); set_page_count(virt_to_page(addr), 1); free_page(addr); ++totalram_pages; addr += PAGE_SIZE; } printk(KERN_INFO "Freeing unused kernel memory: %ldkB freed\n", (__init_end - __init_begin) >> 10);}voidfree_initrd_mem (unsigned long start, unsigned long end){ struct page *page; /* * EFI uses 4KB pages while the kernel can use 4KB or bigger. * Thus EFI and the kernel may have different page sizes. It is * therefore possible to have the initrd share the same page as * the end of the kernel (given current setup). * * To avoid freeing/using the wrong page (kernel sized) we: * - align up the beginning of initrd * - align down the end of initrd * * | | * |=============| a000 * | | * | | * | | 9000 * |/////////////| * |/////////////| * |=============| 8000 * |///INITRD////| * |/////////////| * |/////////////| 7000 * | | * |KKKKKKKKKKKKK| * |=============| 6000 * |KKKKKKKKKKKKK| * |KKKKKKKKKKKKK| * K=kernel using 8KB pages * * In this example, we must free page 8000 ONLY. So we must align up * initrd_start and keep initrd_end as is. */ start = PAGE_ALIGN(start); end = end & PAGE_MASK; if (start < end) printk(KERN_INFO "Freeing initrd memory: %ldkB freed\n", (end - start) >> 10); for (; start < end; start += PAGE_SIZE) { if (!virt_addr_valid(start)) continue; page = virt_to_page(start); ClearPageReserved(page); set_page_count(page, 1); free_page(start); ++totalram_pages; }}/* * This installs a clean page in the kernel's page table. */struct page *put_kernel_page (struct page *page, unsigned long address, pgprot_t pgprot){ pgd_t *pgd; pud_t *pud; pmd_t *pmd; pte_t *pte; if (!PageReserved(page)) printk(KERN_ERR "put_kernel_page: page at 0x%p not in reserved memory\n", page_address(page)); pgd = pgd_offset_k(address); /* note: this is NOT pgd_offset()! */ spin_lock(&init_mm.page_table_lock); { pud = pud_alloc(&init_mm, pgd, address); if (!pud) goto out; pmd = pmd_alloc(&init_mm, pud, address); if (!pmd) goto out; pte = pte_alloc_map(&init_mm, pmd, address); if (!pte) goto out; if (!pte_none(*pte)) { pte_unmap(pte); goto out; } set_pte(pte, mk_pte(page, pgprot)); pte_unmap(pte); } out: spin_unlock(&init_mm.page_table_lock); /* no need for flush_tlb */ return page;}static voidsetup_gate (void){ struct page *page; /* * Map the gate page twice: once read-only to export the ELF headers etc. and once * execute-only page to enable privilege-promotion via "epc": */ page = virt_to_page(ia64_imva(__start_gate_section)); put_kernel_page(page, GATE_ADDR, PAGE_READONLY);#ifdef HAVE_BUGGY_SEGREL page = virt_to_page(ia64_imva(__start_gate_section + PAGE_SIZE)); put_kernel_page(page, GATE_ADDR + PAGE_SIZE, PAGE_GATE);#else put_kernel_page(page, GATE_ADDR + PERCPU_PAGE_SIZE, PAGE_GATE);#endif ia64_patch_gate();}void __devinitia64_mmu_init (void *my_cpu_data){ unsigned long psr, pta, impl_va_bits; extern void __devinit tlb_init (void);#ifdef CONFIG_DISABLE_VHPT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -