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

📄 e820_64.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * Handle the memory map. * The functions here do the job until bootmem takes over. * *  Getting sanitize_e820_map() in sync with i386 version by applying change: *  -  Provisions for empty E820 memory regions (reported by certain BIOSes). *     Alex Achenbach <xela@slit.de>, December 2002. *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> * */#include <linux/kernel.h>#include <linux/types.h>#include <linux/init.h>#include <linux/bootmem.h>#include <linux/ioport.h>#include <linux/string.h>#include <linux/kexec.h>#include <linux/module.h>#include <linux/mm.h>#include <linux/suspend.h>#include <linux/pfn.h>#include <asm/pgtable.h>#include <asm/page.h>#include <asm/e820.h>#include <asm/proto.h>#include <asm/setup.h>#include <asm/sections.h>struct e820map e820;/*  * PFN of last memory page. */unsigned long end_pfn; EXPORT_SYMBOL(end_pfn);/*  * end_pfn only includes RAM, while end_pfn_map includes all e820 entries. * The direct mapping extends to end_pfn_map, so that we can directly access * apertures, ACPI and other tables without having to play with fixmaps. */ unsigned long end_pfn_map; /*  * Last pfn which the user wants to use. */static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;extern struct resource code_resource, data_resource, bss_resource;/* Check for some hardcoded bad areas that early boot is not allowed to touch */ static inline int bad_addr(unsigned long *addrp, unsigned long size){ 	unsigned long addr = *addrp, last = addr + size; 	/* various gunk below that needed for SMP startup */	if (addr < 0x8000) { 		*addrp = PAGE_ALIGN(0x8000);		return 1; 	}	/* direct mapping tables of the kernel */	if (last >= table_start<<PAGE_SHIFT && addr < table_end<<PAGE_SHIFT) { 		*addrp = PAGE_ALIGN(table_end << PAGE_SHIFT);		return 1;	} 	/* initrd */ #ifdef CONFIG_BLK_DEV_INITRD	if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;		unsigned long ramdisk_end   = ramdisk_image+ramdisk_size;		if (last >= ramdisk_image && addr < ramdisk_end) {			*addrp = PAGE_ALIGN(ramdisk_end);			return 1;		}	} #endif	/* kernel code */	if (last >= __pa_symbol(&_text) && addr < __pa_symbol(&_end)) {		*addrp = PAGE_ALIGN(__pa_symbol(&_end));		return 1;	}	if (last >= ebda_addr && addr < ebda_addr + ebda_size) {		*addrp = PAGE_ALIGN(ebda_addr + ebda_size);		return 1;	}#ifdef CONFIG_NUMA	/* NUMA memory to node map */	if (last >= nodemap_addr && addr < nodemap_addr + nodemap_size) {		*addrp = nodemap_addr + nodemap_size;		return 1;	}#endif	/* XXX ramdisk image here? */ 	return 0;} /* * This function checks if any part of the range <start,end> is mapped * with type. */inte820_any_mapped(unsigned long start, unsigned long end, unsigned type){ 	int i;	for (i = 0; i < e820.nr_map; i++) { 		struct e820entry *ei = &e820.map[i]; 		if (type && ei->type != type) 			continue;		if (ei->addr >= end || ei->addr + ei->size <= start)			continue; 		return 1; 	} 	return 0;}EXPORT_SYMBOL_GPL(e820_any_mapped);/* * This function checks if the entire range <start,end> is mapped with type. * * Note: this function only works correct if the e820 table is sorted and * not-overlapping, which is the case */int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type){	int i;	for (i = 0; i < e820.nr_map; i++) {		struct e820entry *ei = &e820.map[i];		if (type && ei->type != type)			continue;		/* is the region (part) in overlap with the current region ?*/		if (ei->addr >= end || ei->addr + ei->size <= start)			continue;		/* if the region is at the beginning of <start,end> we move		 * start to the end of the region since it's ok until there		 */		if (ei->addr <= start)			start = ei->addr + ei->size;		/* if start is now at or beyond end, we're done, full coverage */		if (start >= end)			return 1; /* we're done */	}	return 0;}/*  * Find a free area in a specific range.  */ unsigned long __init find_e820_area(unsigned long start, unsigned long end, unsigned size) { 	int i; 	for (i = 0; i < e820.nr_map; i++) { 		struct e820entry *ei = &e820.map[i]; 		unsigned long addr = ei->addr, last; 		if (ei->type != E820_RAM) 			continue; 		if (addr < start) 			addr = start;		if (addr > ei->addr + ei->size) 			continue; 		while (bad_addr(&addr, size) && addr+size <= ei->addr+ei->size)			;		last = PAGE_ALIGN(addr) + size;		if (last > ei->addr + ei->size)			continue;		if (last > end) 			continue;		return addr; 	} 	return -1UL;		} /* * Find the highest page frame number we have available */unsigned long __init e820_end_of_ram(void){	unsigned long end_pfn = 0;	end_pfn = find_max_pfn_with_active_regions();		if (end_pfn > end_pfn_map) 		end_pfn_map = end_pfn;	if (end_pfn_map > MAXMEM>>PAGE_SHIFT)		end_pfn_map = MAXMEM>>PAGE_SHIFT;	if (end_pfn > end_user_pfn)		end_pfn = end_user_pfn;	if (end_pfn > end_pfn_map) 		end_pfn = end_pfn_map; 	printk("end_pfn_map = %lu\n", end_pfn_map);	return end_pfn;	}/* * Mark e820 reserved areas as busy for the resource manager. */void __init e820_reserve_resources(void){	int i;	for (i = 0; i < e820.nr_map; i++) {		struct resource *res;		res = alloc_bootmem_low(sizeof(struct resource));		switch (e820.map[i].type) {		case E820_RAM:	res->name = "System RAM"; break;		case E820_ACPI:	res->name = "ACPI Tables"; break;		case E820_NVS:	res->name = "ACPI Non-volatile Storage"; break;		default:	res->name = "reserved";		}		res->start = e820.map[i].addr;		res->end = res->start + e820.map[i].size - 1;		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;		request_resource(&iomem_resource, res);		if (e820.map[i].type == E820_RAM) {			/*			 *  We don't know which RAM region contains kernel data,			 *  so we try it repeatedly and let the resource manager			 *  test it.			 */			request_resource(res, &code_resource);			request_resource(res, &data_resource);			request_resource(res, &bss_resource);#ifdef CONFIG_KEXEC			if (crashk_res.start != crashk_res.end)				request_resource(res, &crashk_res);#endif		}	}}/* * Find the ranges of physical addresses that do not correspond to * e820 RAM areas and mark the corresponding pages as nosave for software * suspend and suspend to RAM. * * This function requires the e820 map to be sorted and without any * overlapping entries and assumes the first e820 area to be RAM. */void __init e820_mark_nosave_regions(void){	int i;	unsigned long paddr;	paddr = round_down(e820.map[0].addr + e820.map[0].size, PAGE_SIZE);	for (i = 1; i < e820.nr_map; i++) {		struct e820entry *ei = &e820.map[i];		if (paddr < ei->addr)			register_nosave_region(PFN_DOWN(paddr),						PFN_UP(ei->addr));		paddr = round_down(ei->addr + ei->size, PAGE_SIZE);		if (ei->type != E820_RAM)			register_nosave_region(PFN_UP(ei->addr),						PFN_DOWN(paddr));		if (paddr >= (end_pfn << PAGE_SHIFT))			break;	}}/* * Finds an active region in the address range from start_pfn to end_pfn and * returns its range in ei_startpfn and ei_endpfn for the e820 entry. */static int __init e820_find_active_region(const struct e820entry *ei,					  unsigned long start_pfn,					  unsigned long end_pfn,					  unsigned long *ei_startpfn,					  unsigned long *ei_endpfn){	*ei_startpfn = round_up(ei->addr, PAGE_SIZE) >> PAGE_SHIFT;	*ei_endpfn = round_down(ei->addr + ei->size, PAGE_SIZE) >> PAGE_SHIFT;	/* Skip map entries smaller than a page */	if (*ei_startpfn >= *ei_endpfn)		return 0;	/* Check if end_pfn_map should be updated */	if (ei->type != E820_RAM && *ei_endpfn > end_pfn_map)		end_pfn_map = *ei_endpfn;	/* Skip if map is outside the node */	if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||				    *ei_startpfn >= end_pfn)		return 0;	/* Check for overlaps */	if (*ei_startpfn < start_pfn)		*ei_startpfn = start_pfn;	if (*ei_endpfn > end_pfn)		*ei_endpfn = end_pfn;	/* Obey end_user_pfn to save on memmap */	if (*ei_startpfn >= end_user_pfn)		return 0;	if (*ei_endpfn > end_user_pfn)		*ei_endpfn = end_user_pfn;	return 1;}/* Walk the e820 map and register active regions within a node */void __inite820_register_active_regions(int nid, unsigned long start_pfn,							unsigned long end_pfn){	unsigned long ei_startpfn;	unsigned long ei_endpfn;	int i;	for (i = 0; i < e820.nr_map; i++)		if (e820_find_active_region(&e820.map[i],					    start_pfn, end_pfn,					    &ei_startpfn, &ei_endpfn))			add_active_range(nid, ei_startpfn, ei_endpfn);}/*  * Add a memory region to the kernel e820 map. */ void __init add_memory_region(unsigned long start, unsigned long size, int type){	int x = e820.nr_map;	if (x == E820MAX) {		printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");		return;	}	e820.map[x].addr = start;	e820.map[x].size = size;	e820.map[x].type = type;	e820.nr_map++;}/* * Find the hole size (in bytes) in the memory range. * @start: starting address of the memory range to scan * @end: ending address of the memory range to scan */unsigned long __init e820_hole_size(unsigned long start, unsigned long end){	unsigned long start_pfn = start >> PAGE_SHIFT;	unsigned long end_pfn = end >> PAGE_SHIFT;	unsigned long ei_startpfn;	unsigned long ei_endpfn;	unsigned long ram = 0;	int i;	for (i = 0; i < e820.nr_map; i++) {		if (e820_find_active_region(&e820.map[i],					    start_pfn, end_pfn,					    &ei_startpfn, &ei_endpfn))			ram += ei_endpfn - ei_startpfn;	}	return end - start - (ram << PAGE_SHIFT);}void __init e820_print_map(char *who){	int i;	for (i = 0; i < e820.nr_map; i++) {		printk(KERN_INFO " %s: %016Lx - %016Lx ", who,			(unsigned long long) e820.map[i].addr,			(unsigned long long) (e820.map[i].addr + e820.map[i].size));		switch (e820.map[i].type) {		case E820_RAM:	printk("(usable)\n");				break;

⌨️ 快捷键说明

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