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

📄 efi.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Extensible Firmware Interface * * Based on Extensible Firmware Interface Specification version 1.0 * * Copyright (C) 1999 VA Linux Systems * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> * Copyright (C) 1999-2002 Hewlett-Packard Co. *	David Mosberger-Tang <davidm@hpl.hp.com> *	Stephane Eranian <eranian@hpl.hp.com> * * All EFI Runtime Services are not implemented yet as EFI only * supports physical mode addressing on SoftSDV. This is to be fixed * in a future version.  --drummond 1999-07-20 * * Implemented EFI runtime services and virtual mode calls.  --davidm * * Goutham Rao: <goutham.rao@intel.com> *	Skip non-WB memory and ignore empty memory ranges. */#include <linux/config.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/mm.h>#include <linux/types.h>#include <linux/time.h>#include <linux/spinlock.h>#include <linux/bootmem.h>#include <linux/ioport.h>#include <linux/module.h>#include <linux/efi.h>#include <linux/kexec.h>#include <asm/setup.h>#include <asm/io.h>#include <asm/page.h>#include <asm/pgtable.h>#include <asm/processor.h>#include <asm/desc.h>#include <asm/tlbflush.h>#define EFI_DEBUG	0#define PFX 		"EFI: "extern efi_status_t asmlinkage efi_call_phys(void *, ...);struct efi efi;EXPORT_SYMBOL(efi);static struct efi efi_phys;struct efi_memory_map memmap;/* * We require an early boot_ioremap mapping mechanism initially */extern void * boot_ioremap(unsigned long, unsigned long);/* * To make EFI call EFI runtime service in physical addressing mode we need * prelog/epilog before/after the invocation to disable interrupt, to * claim EFI runtime service handler exclusively and to duplicate a memory in * low memory space say 0 - 3G. */static unsigned long efi_rt_eflags;static DEFINE_SPINLOCK(efi_rt_lock);static pgd_t efi_bak_pg_dir_pointer[2];static void efi_call_phys_prelog(void){	unsigned long cr4;	unsigned long temp;	spin_lock(&efi_rt_lock);	local_irq_save(efi_rt_eflags);	/*	 * If I don't have PSE, I should just duplicate two entries in page	 * directory. If I have PSE, I just need to duplicate one entry in	 * page directory.	 */	cr4 = read_cr4();	if (cr4 & X86_CR4_PSE) {		efi_bak_pg_dir_pointer[0].pgd =		    swapper_pg_dir[pgd_index(0)].pgd;		swapper_pg_dir[0].pgd =		    swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;	} else {		efi_bak_pg_dir_pointer[0].pgd =		    swapper_pg_dir[pgd_index(0)].pgd;		efi_bak_pg_dir_pointer[1].pgd =		    swapper_pg_dir[pgd_index(0x400000)].pgd;		swapper_pg_dir[pgd_index(0)].pgd =		    swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;		temp = PAGE_OFFSET + 0x400000;		swapper_pg_dir[pgd_index(0x400000)].pgd =		    swapper_pg_dir[pgd_index(temp)].pgd;	}	/*	 * After the lock is released, the original page table is restored.	 */	local_flush_tlb();	cpu_gdt_descr[0].address = __pa(cpu_gdt_descr[0].address);	load_gdt((struct Xgt_desc_struct *) __pa(&cpu_gdt_descr[0]));}static void efi_call_phys_epilog(void){	unsigned long cr4;	cpu_gdt_descr[0].address =		(unsigned long) __va(cpu_gdt_descr[0].address);	load_gdt(&cpu_gdt_descr[0]);	cr4 = read_cr4();	if (cr4 & X86_CR4_PSE) {		swapper_pg_dir[pgd_index(0)].pgd =		    efi_bak_pg_dir_pointer[0].pgd;	} else {		swapper_pg_dir[pgd_index(0)].pgd =		    efi_bak_pg_dir_pointer[0].pgd;		swapper_pg_dir[pgd_index(0x400000)].pgd =		    efi_bak_pg_dir_pointer[1].pgd;	}	/*	 * After the lock is released, the original page table is restored.	 */	local_flush_tlb();	local_irq_restore(efi_rt_eflags);	spin_unlock(&efi_rt_lock);}static efi_status_tphys_efi_set_virtual_address_map(unsigned long memory_map_size,				 unsigned long descriptor_size,				 u32 descriptor_version,				 efi_memory_desc_t *virtual_map){	efi_status_t status;	efi_call_phys_prelog();	status = efi_call_phys(efi_phys.set_virtual_address_map,				     memory_map_size, descriptor_size,				     descriptor_version, virtual_map);	efi_call_phys_epilog();	return status;}static efi_status_tphys_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc){	efi_status_t status;	efi_call_phys_prelog();	status = efi_call_phys(efi_phys.get_time, tm, tc);	efi_call_phys_epilog();	return status;}inline int efi_set_rtc_mmss(unsigned long nowtime){	int real_seconds, real_minutes;	efi_status_t 	status;	efi_time_t 	eft;	efi_time_cap_t 	cap;	spin_lock(&efi_rt_lock);	status = efi.get_time(&eft, &cap);	spin_unlock(&efi_rt_lock);	if (status != EFI_SUCCESS)		panic("Ooops, efitime: can't read time!\n");	real_seconds = nowtime % 60;	real_minutes = nowtime / 60;	if (((abs(real_minutes - eft.minute) + 15)/30) & 1)		real_minutes += 30;	real_minutes %= 60;	eft.minute = real_minutes;	eft.second = real_seconds;	if (status != EFI_SUCCESS) {		printk("Ooops: efitime: can't read time!\n");		return -1;	}	return 0;}/* * This should only be used during kernel init and before runtime * services have been remapped, therefore, we'll need to call in physical * mode.  Note, this call isn't used later, so mark it __init. */inline unsigned long __init efi_get_time(void){	efi_status_t status;	efi_time_t eft;	efi_time_cap_t cap;	status = phys_efi_get_time(&eft, &cap);	if (status != EFI_SUCCESS)		printk("Oops: efitime: can't read time status: 0x%lx\n",status);	return mktime(eft.year, eft.month, eft.day, eft.hour,			eft.minute, eft.second);}int is_available_memory(efi_memory_desc_t * md){	if (!(md->attribute & EFI_MEMORY_WB))		return 0;	switch (md->type) {		case EFI_LOADER_CODE:		case EFI_LOADER_DATA:		case EFI_BOOT_SERVICES_CODE:		case EFI_BOOT_SERVICES_DATA:		case EFI_CONVENTIONAL_MEMORY:			return 1;	}	return 0;}/* * We need to map the EFI memory map again after paging_init(). */void __init efi_map_memmap(void){	memmap.map = NULL;	memmap.map = bt_ioremap((unsigned long) memmap.phys_map,			(memmap.nr_map * memmap.desc_size));	if (memmap.map == NULL)		printk(KERN_ERR PFX "Could not remap the EFI memmap!\n");	memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);}#if EFI_DEBUGstatic void __init print_efi_memmap(void){	efi_memory_desc_t *md;	void *p;	int i;	for (p = memmap.map, i = 0; p < memmap.map_end; p += memmap.desc_size, i++) {		md = p;		printk(KERN_INFO "mem%02u: type=%u, attr=0x%llx, "			"range=[0x%016llx-0x%016llx) (%lluMB)\n",			i, md->type, md->attribute, md->phys_addr,			md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),			(md->num_pages >> (20 - EFI_PAGE_SHIFT)));	}}#endif  /*  EFI_DEBUG  *//* * Walks the EFI memory map and calls CALLBACK once for each EFI * memory descriptor that has memory that is available for kernel use. */void efi_memmap_walk(efi_freemem_callback_t callback, void *arg){	int prev_valid = 0;	struct range {		unsigned long start;		unsigned long end;	} prev, curr;	efi_memory_desc_t *md;	unsigned long start, end;	void *p;	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {		md = p;		if ((md->num_pages == 0) || (!is_available_memory(md)))			continue;		curr.start = md->phys_addr;		curr.end = curr.start + (md->num_pages << EFI_PAGE_SHIFT);		if (!prev_valid) {			prev = curr;			prev_valid = 1;		} else {			if (curr.start < prev.start)				printk(KERN_INFO PFX "Unordered memory map\n");			if (prev.end == curr.start)				prev.end = curr.end;			else {				start =				    (unsigned long) (PAGE_ALIGN(prev.start));				end = (unsigned long) (prev.end & PAGE_MASK);				if ((end > start)				    && (*callback) (start, end, arg) < 0)					return;				prev = curr;			}		}	}	if (prev_valid) {		start = (unsigned long) PAGE_ALIGN(prev.start);		end = (unsigned long) (prev.end & PAGE_MASK);		if (end > start)			(*callback) (start, end, arg);	}}void __init efi_init(void){	efi_config_table_t *config_tables;	efi_runtime_services_t *runtime;	efi_char16_t *c16;	char vendor[100] = "unknown";	unsigned long num_config_tables;	int i = 0;

⌨️ 快捷键说明

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