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

📄 efi.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
	memset(&efi, 0, sizeof(efi) );	memset(&efi_phys, 0, sizeof(efi_phys));	efi_phys.systab = EFI_SYSTAB;	memmap.phys_map = EFI_MEMMAP;	memmap.nr_map = EFI_MEMMAP_SIZE/EFI_MEMDESC_SIZE;	memmap.desc_version = EFI_MEMDESC_VERSION;	memmap.desc_size = EFI_MEMDESC_SIZE;	efi.systab = (efi_system_table_t *)		boot_ioremap((unsigned long) efi_phys.systab,			sizeof(efi_system_table_t));	/*	 * Verify the EFI Table	 */	if (efi.systab == NULL)		printk(KERN_ERR PFX "Woah! Couldn't map the EFI system table.\n");	if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)		printk(KERN_ERR PFX "Woah! EFI system table signature incorrect\n");	if ((efi.systab->hdr.revision ^ EFI_SYSTEM_TABLE_REVISION) >> 16 != 0)		printk(KERN_ERR PFX		       "Warning: EFI system table major version mismatch: "		       "got %d.%02d, expected %d.%02d\n",		       efi.systab->hdr.revision >> 16,		       efi.systab->hdr.revision & 0xffff,		       EFI_SYSTEM_TABLE_REVISION >> 16,		       EFI_SYSTEM_TABLE_REVISION & 0xffff);	/*	 * Grab some details from the system table	 */	num_config_tables = efi.systab->nr_tables;	config_tables = (efi_config_table_t *)efi.systab->tables;	runtime = efi.systab->runtime;	/*	 * Show what we know for posterity	 */	c16 = (efi_char16_t *) boot_ioremap(efi.systab->fw_vendor, 2);	if (c16) {		for (i = 0; i < sizeof(vendor) && *c16; ++i)			vendor[i] = *c16++;		vendor[i] = '\0';	} else		printk(KERN_ERR PFX "Could not map the firmware vendor!\n");	printk(KERN_INFO PFX "EFI v%u.%.02u by %s \n",	       efi.systab->hdr.revision >> 16,	       efi.systab->hdr.revision & 0xffff, vendor);	/*	 * Let's see what config tables the firmware passed to us.	 */	config_tables = (efi_config_table_t *)				boot_ioremap((unsigned long) config_tables,			        num_config_tables * sizeof(efi_config_table_t));	if (config_tables == NULL)		printk(KERN_ERR PFX "Could not map EFI Configuration Table!\n");	for (i = 0; i < num_config_tables; i++) {		if (efi_guidcmp(config_tables[i].guid, MPS_TABLE_GUID) == 0) {			efi.mps = (void *)config_tables[i].table;			printk(KERN_INFO " MPS=0x%lx ", config_tables[i].table);		} else		    if (efi_guidcmp(config_tables[i].guid, ACPI_20_TABLE_GUID) == 0) {			efi.acpi20 = __va(config_tables[i].table);			printk(KERN_INFO " ACPI 2.0=0x%lx ", config_tables[i].table);		} else		    if (efi_guidcmp(config_tables[i].guid, ACPI_TABLE_GUID) == 0) {			efi.acpi = __va(config_tables[i].table);			printk(KERN_INFO " ACPI=0x%lx ", config_tables[i].table);		} else		    if (efi_guidcmp(config_tables[i].guid, SMBIOS_TABLE_GUID) == 0) {			efi.smbios = (void *) config_tables[i].table;			printk(KERN_INFO " SMBIOS=0x%lx ", config_tables[i].table);		} else		    if (efi_guidcmp(config_tables[i].guid, HCDP_TABLE_GUID) == 0) {			efi.hcdp = (void *)config_tables[i].table;			printk(KERN_INFO " HCDP=0x%lx ", config_tables[i].table);		} else		    if (efi_guidcmp(config_tables[i].guid, UGA_IO_PROTOCOL_GUID) == 0) {			efi.uga = (void *)config_tables[i].table;			printk(KERN_INFO " UGA=0x%lx ", config_tables[i].table);		}	}	printk("\n");	/*	 * Check out the runtime services table. We need to map	 * the runtime services table so that we can grab the physical	 * address of several of the EFI runtime functions, needed to	 * set the firmware into virtual mode.	 */	runtime = (efi_runtime_services_t *) boot_ioremap((unsigned long)						runtime,				      		sizeof(efi_runtime_services_t));	if (runtime != NULL) {		/*	 	 * We will only need *early* access to the following		 * two EFI runtime services before set_virtual_address_map		 * is invoked. 	 	 */		efi_phys.get_time = (efi_get_time_t *) runtime->get_time;		efi_phys.set_virtual_address_map =			(efi_set_virtual_address_map_t *)				runtime->set_virtual_address_map;	} else		printk(KERN_ERR PFX "Could not map the runtime service table!\n");	/* Map the EFI memory map for use until paging_init() */	memmap.map = boot_ioremap((unsigned long) EFI_MEMMAP, EFI_MEMMAP_SIZE);	if (memmap.map == NULL)		printk(KERN_ERR PFX "Could not map the EFI memory map!\n");	memmap.map_end = memmap.map + (memmap.nr_map * memmap.desc_size);#if EFI_DEBUG	print_efi_memmap();#endif}static inline void __init check_range_for_systab(efi_memory_desc_t *md){	if (((unsigned long)md->phys_addr <= (unsigned long)efi_phys.systab) &&		((unsigned long)efi_phys.systab < md->phys_addr +		((unsigned long)md->num_pages << EFI_PAGE_SHIFT))) {		unsigned long addr;		addr = md->virt_addr - md->phys_addr +			(unsigned long)efi_phys.systab;		efi.systab = (efi_system_table_t *)addr;	}}/* * This function will switch the EFI runtime services to virtual mode. * Essentially, look through the EFI memmap and map every region that * has the runtime attribute bit set in its memory descriptor and update * that memory descriptor with the virtual address obtained from ioremap(). * This enables the runtime services to be called without having to * thunk back into physical mode for every invocation. */void __init efi_enter_virtual_mode(void){	efi_memory_desc_t *md;	efi_status_t status;	void *p;	efi.systab = NULL;	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {		md = p;		if (!(md->attribute & EFI_MEMORY_RUNTIME))			continue;		md->virt_addr = (unsigned long)ioremap(md->phys_addr,			md->num_pages << EFI_PAGE_SHIFT);		if (!(unsigned long)md->virt_addr) {			printk(KERN_ERR PFX "ioremap of 0x%lX failed\n",				(unsigned long)md->phys_addr);		}		/* update the virtual address of the EFI system table */		check_range_for_systab(md);	}	if (!efi.systab)		BUG();	status = phys_efi_set_virtual_address_map(			memmap.desc_size * memmap.nr_map,			memmap.desc_size,			memmap.desc_version,		       	memmap.phys_map);	if (status != EFI_SUCCESS) {		printk (KERN_ALERT "You are screwed! "			"Unable to switch EFI into virtual mode "			"(status=%lx)\n", status);		panic("EFI call to SetVirtualAddressMap() failed!");	}	/*	 * Now that EFI is in virtual mode, update the function	 * pointers in the runtime service table to the new virtual addresses.	 */	efi.get_time = (efi_get_time_t *) efi.systab->runtime->get_time;	efi.set_time = (efi_set_time_t *) efi.systab->runtime->set_time;	efi.get_wakeup_time = (efi_get_wakeup_time_t *)					efi.systab->runtime->get_wakeup_time;	efi.set_wakeup_time = (efi_set_wakeup_time_t *)					efi.systab->runtime->set_wakeup_time;	efi.get_variable = (efi_get_variable_t *)					efi.systab->runtime->get_variable;	efi.get_next_variable = (efi_get_next_variable_t *)					efi.systab->runtime->get_next_variable;	efi.set_variable = (efi_set_variable_t *)					efi.systab->runtime->set_variable;	efi.get_next_high_mono_count = (efi_get_next_high_mono_count_t *)					efi.systab->runtime->get_next_high_mono_count;	efi.reset_system = (efi_reset_system_t *)					efi.systab->runtime->reset_system;}void __initefi_initialize_iomem_resources(struct resource *code_resource,			       struct resource *data_resource){	struct resource *res;	efi_memory_desc_t *md;	void *p;	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {		md = p;		if ((md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) >		    0x100000000ULL)			continue;		res = alloc_bootmem_low(sizeof(struct resource));		switch (md->type) {		case EFI_RESERVED_TYPE:			res->name = "Reserved Memory";			break;		case EFI_LOADER_CODE:			res->name = "Loader Code";			break;		case EFI_LOADER_DATA:			res->name = "Loader Data";			break;		case EFI_BOOT_SERVICES_DATA:			res->name = "BootServices Data";			break;		case EFI_BOOT_SERVICES_CODE:			res->name = "BootServices Code";			break;		case EFI_RUNTIME_SERVICES_CODE:			res->name = "Runtime Service Code";			break;		case EFI_RUNTIME_SERVICES_DATA:			res->name = "Runtime Service Data";			break;		case EFI_CONVENTIONAL_MEMORY:			res->name = "Conventional Memory";			break;		case EFI_UNUSABLE_MEMORY:			res->name = "Unusable Memory";			break;		case EFI_ACPI_RECLAIM_MEMORY:			res->name = "ACPI Reclaim";			break;		case EFI_ACPI_MEMORY_NVS:			res->name = "ACPI NVS";			break;		case EFI_MEMORY_MAPPED_IO:			res->name = "Memory Mapped IO";			break;		case EFI_MEMORY_MAPPED_IO_PORT_SPACE:			res->name = "Memory Mapped IO Port Space";			break;		default:			res->name = "Reserved";			break;		}		res->start = md->phys_addr;		res->end = res->start + ((md->num_pages << EFI_PAGE_SHIFT) - 1);		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;		if (request_resource(&iomem_resource, res) < 0)			printk(KERN_ERR PFX "Failed to allocate res %s : 0x%lx-0x%lx\n",				res->name, res->start, res->end);		/*		 * We don't know which region contains kernel data so we try		 * it repeatedly and let the resource manager test it.		 */		if (md->type == EFI_CONVENTIONAL_MEMORY) {			request_resource(res, code_resource);			request_resource(res, data_resource);#ifdef CONFIG_KEXEC			request_resource(res, &crashk_res);#endif		}	}}/* * Convenience functions to obtain memory types and attributes */u32 efi_mem_type(unsigned long phys_addr){	efi_memory_desc_t *md;	void *p;	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {		md = p;		if ((md->phys_addr <= phys_addr) && (phys_addr <			(md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))			return md->type;	}	return 0;}u64 efi_mem_attributes(unsigned long phys_addr){	efi_memory_desc_t *md;	void *p;	for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {		md = p;		if ((md->phys_addr <= phys_addr) && (phys_addr <			(md->phys_addr + (md-> num_pages << EFI_PAGE_SHIFT)) ))			return md->attribute;	}	return 0;}

⌨️ 快捷键说明

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