⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 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);DEFINE_PER_CPU(unsigned long *, __pgtable_quicklist);DEFINE_PER_CPU(long, __pgtable_quicklist_size);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);#endifstruct page *zero_page_memmap_ptr;	/* map entry for zero page */EXPORT_SYMBOL(zero_page_memmap_ptr);#define MIN_PGT_PAGES			25UL#define MAX_PGT_FREES_PER_PASS		16L#define PGT_FRACTION_OF_NODE_MEM	16static inline longmax_pgt_pages(void){	u64 node_free_pages, max_pgt_pages;#ifndef	CONFIG_NUMA	node_free_pages = nr_free_pages();#else	node_free_pages = nr_free_pages_pgdat(NODE_DATA(numa_node_id()));#endif	max_pgt_pages = node_free_pages / PGT_FRACTION_OF_NODE_MEM;	max_pgt_pages = max(max_pgt_pages, MIN_PGT_PAGES);	return max_pgt_pages;}static inline longmin_pages_to_free(void){	long pages_to_free;	pages_to_free = pgtable_quicklist_size - max_pgt_pages();	pages_to_free = min(pages_to_free, MAX_PGT_FREES_PER_PASS);	return pages_to_free;}voidcheck_pgt_cache(void){	long pages_to_free;	if (unlikely(pgtable_quicklist_size <= MIN_PGT_PAGES))		return;	preempt_disable();	while (unlikely((pages_to_free = min_pages_to_free()) > 0)) {		while (pages_to_free--) {			free_page((unsigned long)pgtable_quicklist_alloc());		}		preempt_enable();		preempt_disable();	}	preempt_enable();}voidlazy_mmu_prot_update (pte_t pte){	unsigned long addr;	struct page *page;	if (!pte_exec(pte))		return;				/* not an executable page... */	page = pte_page(pte);	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|VM_ACCOUNT;		down_write(&current->mm->mmap_sem);		if (insert_vm_struct(current->mm, vma)) {			up_write(&current->mm->mmap_sem);			kmem_cache_free(vm_area_cachep, vma);			return;		}		up_write(&current->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(&current->mm->mmap_sem);			if (insert_vm_struct(current->mm, vma)) {				up_write(&current->mm->mmap_sem);				kmem_cache_free(vm_area_cachep, vma);				return;			}			up_write(&current->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()! */	{		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_kernel(pmd, address);		if (!pte)			goto out;		if (!pte_none(*pte))			goto out;		set_pte(pte, mk_pte(page, pgprot));	}  out:	/* 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);	/* Fill in the holes (if any) with read-only zero pages: */	{		unsigned long addr;		for (addr = GATE_ADDR + PAGE_SIZE;		     addr < GATE_ADDR + PERCPU_PAGE_SIZE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -