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

📄 init.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/arch/arm/mm/init.c * *  Copyright (C) 1995-2005 Russell King * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */#include <linux/config.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/ptrace.h>#include <linux/swap.h>#include <linux/init.h>#include <linux/bootmem.h>#include <linux/mman.h>#include <linux/nodemask.h>#include <linux/initrd.h>#include <asm/mach-types.h>#include <asm/hardware.h>#include <asm/setup.h>#include <asm/tlb.h>#include <asm/mach/arch.h>#include <asm/mach/map.h>#define TABLE_SIZE	(2 * PTRS_PER_PTE * sizeof(pte_t))DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);extern pgd_t swapper_pg_dir[PTRS_PER_PGD];extern void _stext, _text, _etext, __data_start, _end, __init_begin, __init_end;extern unsigned long phys_initrd_start;extern unsigned long phys_initrd_size;/* * The sole use of this is to pass memory configuration * data from paging_init to mem_init. */static struct meminfo meminfo __initdata = { 0, };/* * empty_zero_page is a special page that is used for * zero-initialized data and COW. */struct page *empty_zero_page;void show_mem(void){	int free = 0, total = 0, reserved = 0;	int shared = 0, cached = 0, slab = 0, node;	printk("Mem-info:\n");	show_free_areas();	printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));	for_each_online_node(node) {		struct page *page, *end;		page = NODE_MEM_MAP(node);		end  = page + NODE_DATA(node)->node_spanned_pages;		do {			total++;			if (PageReserved(page))				reserved++;			else if (PageSwapCache(page))				cached++;			else if (PageSlab(page))				slab++;			else if (!page_count(page))				free++;			else				shared += page_count(page) - 1;			page++;		} while (page < end);	}	printk("%d pages of RAM\n", total);	printk("%d free pages\n", free);	printk("%d reserved pages\n", reserved);	printk("%d slab pages\n", slab);	printk("%d pages shared\n", shared);	printk("%d pages swap cached\n", cached);}static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt){	return pmd_offset(pgd, virt);}static inline pmd_t *pmd_off_k(unsigned long virt){	return pmd_off(pgd_offset_k(virt), virt);}#define for_each_nodebank(iter,mi,no)			\	for (iter = 0; iter < mi->nr_banks; iter++)	\		if (mi->bank[iter].node == no)/* * FIXME: We really want to avoid allocating the bootmap bitmap * over the top of the initrd.  Hopefully, this is located towards * the start of a bank, so if we allocate the bootmap bitmap at * the end, we won't clash. */static unsigned int __initfind_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages){	unsigned int start_pfn, bank, bootmap_pfn;	start_pfn   = PAGE_ALIGN(__pa(&_end)) >> PAGE_SHIFT;	bootmap_pfn = 0;	for_each_nodebank(bank, mi, node) {		unsigned int start, end;		start = mi->bank[bank].start >> PAGE_SHIFT;		end   = (mi->bank[bank].size +			 mi->bank[bank].start) >> PAGE_SHIFT;		if (end < start_pfn)			continue;		if (start < start_pfn)			start = start_pfn;		if (end <= start)			continue;		if (end - start >= bootmap_pages) {			bootmap_pfn = start;			break;		}	}	if (bootmap_pfn == 0)		BUG();	return bootmap_pfn;}static int __init check_initrd(struct meminfo *mi){	int initrd_node = -2;#ifdef CONFIG_BLK_DEV_INITRD	unsigned long end = phys_initrd_start + phys_initrd_size;	/*	 * Make sure that the initrd is within a valid area of	 * memory.	 */	if (phys_initrd_size) {		unsigned int i;		initrd_node = -1;		for (i = 0; i < mi->nr_banks; i++) {			unsigned long bank_end;			bank_end = mi->bank[i].start + mi->bank[i].size;			if (mi->bank[i].start <= phys_initrd_start &&			    end <= bank_end)				initrd_node = mi->bank[i].node;		}	}	if (initrd_node == -1) {		printk(KERN_ERR "initrd (0x%08lx - 0x%08lx) extends beyond "		       "physical memory - disabling initrd\n",		       phys_initrd_start, end);		phys_initrd_start = phys_initrd_size = 0;	}#endif	return initrd_node;}/* * Reserve the various regions of node 0 */static __init void reserve_node_zero(pg_data_t *pgdat){	unsigned long res_size = 0;	/*	 * Register the kernel text and data with bootmem.	 * Note that this can only be in node 0.	 */#ifdef CONFIG_XIP_KERNEL	reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start);#else	reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext);#endif	/*	 * Reserve the page tables.  These are already in use,	 * and can only be in node 0.	 */	reserve_bootmem_node(pgdat, __pa(swapper_pg_dir),			     PTRS_PER_PGD * sizeof(pgd_t));	/*	 * Hmm... This should go elsewhere, but we really really need to	 * stop things allocating the low memory; ideally we need a better	 * implementation of GFP_DMA which does not assume that DMA-able	 * memory starts at zero.	 */	if (machine_is_integrator() || machine_is_cintegrator())		res_size = __pa(swapper_pg_dir) - PHYS_OFFSET;	/*	 * These should likewise go elsewhere.  They pre-reserve the	 * screen memory region at the start of main system memory.	 */	if (machine_is_edb7211())		res_size = 0x00020000;	if (machine_is_p720t())		res_size = 0x00014000;#ifdef CONFIG_SA1111	/*	 * Because of the SA1111 DMA bug, we want to preserve our	 * precious DMA-able memory...	 */	res_size = __pa(swapper_pg_dir) - PHYS_OFFSET;#endif	if (res_size)		reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size);}void __init build_mem_type_table(void);void __init create_mapping(struct map_desc *md);static unsigned long __initbootmem_init_node(int node, int initrd_node, struct meminfo *mi){	unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];	unsigned long start_pfn, end_pfn, boot_pfn;	unsigned int boot_pages;	pg_data_t *pgdat;	int i;	start_pfn = -1UL;	end_pfn = 0;	/*	 * Calculate the pfn range, and map the memory banks for this node.	 */	for_each_nodebank(i, mi, node) {		unsigned long start, end;		struct map_desc map;		start = mi->bank[i].start >> PAGE_SHIFT;		end = (mi->bank[i].start + mi->bank[i].size) >> PAGE_SHIFT;		if (start_pfn > start)			start_pfn = start;		if (end_pfn < end)			end_pfn = end;		map.pfn = __phys_to_pfn(mi->bank[i].start);		map.virtual = __phys_to_virt(mi->bank[i].start);		map.length = mi->bank[i].size;		map.type = MT_MEMORY;		create_mapping(&map);	}	/*	 * If there is no memory in this node, ignore it.	 */	if (end_pfn == 0)		return end_pfn;	/*	 * Allocate the bootmem bitmap page.	 */	boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);	boot_pfn = find_bootmap_pfn(node, mi, boot_pages);	/*	 * Initialise the bootmem allocator for this node, handing the	 * memory banks over to bootmem.	 */	node_set_online(node);	pgdat = NODE_DATA(node);	init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);	for_each_nodebank(i, mi, node)		free_bootmem_node(pgdat, mi->bank[i].start, mi->bank[i].size);	/*	 * Reserve the bootmem bitmap for this node.	 */	reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,			     boot_pages << PAGE_SHIFT);#ifdef CONFIG_BLK_DEV_INITRD	/*	 * If the initrd is in this node, reserve its memory.	 */	if (node == initrd_node) {		reserve_bootmem_node(pgdat, phys_initrd_start,				     phys_initrd_size);		initrd_start = __phys_to_virt(phys_initrd_start);		initrd_end = initrd_start + phys_initrd_size;	}#endif	/*	 * Finally, reserve any node zero regions.	 */	if (node == 0)		reserve_node_zero(pgdat);	/*	 * initialise the zones within this node.	 */	memset(zone_size, 0, sizeof(zone_size));	memset(zhole_size, 0, sizeof(zhole_size));	/*	 * The size of this node has already been determined.  If we need	 * to do anything fancy with the allocation of this memory to the	 * zones, now is the time to do it.	 */	zone_size[0] = end_pfn - start_pfn;	/*	 * For each bank in this node, calculate the size of the holes.	 *  holes = node_size - sum(bank_sizes_in_node)	 */	zhole_size[0] = zone_size[0];	for_each_nodebank(i, mi, node)		zhole_size[0] -= mi->bank[i].size >> PAGE_SHIFT;	/*	 * Adjust the sizes according to any special requirements for	 * this machine type.	 */	arch_adjust_zones(node, zone_size, zhole_size);

⌨️ 快捷键说明

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