Skip to contentSkip to conversation

x86_64 EFI runtime service support: EFI basic runtime service support

PATCH In review Huang, Ying 1 participant 1 message Aug 13, 2007 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 x86_64 EFI runtime service support: EFI basic runtime service support

Changelog between v3 of EFI x86_64 support patch and this version:

1. Remove E820_RUNTIME_CODE, the EFI memory map is used to deal with EFI runtime code area.
2. The method used to make EFI runtime code area executable is change:
a. Before page allocation is usable, the PMD of direct mapping is
changed temporarily before and after each EFI call.
b. After page allocation is usable, change_page_attr_addr is used
to change corresponding page attribute.
3. Use fixmap to map EFI memory mapped IO memory area to make kexec workable.
4. Add a kernel command line option "noefi" to make it possible to turn off EFI runtime services support.

Changelog between v2 and v3:

1. The EFI callwrapper is re-implemented in assembler.

---

This patch adds basic runtime services support for EFI x86_64 system. The main file of the patch is the addition of efi.c for x86_64. This file is modeled after the EFI IA32 avatar. EFI runtime services initialization are implemented in efi.c. Some x86_64 specifics are worth noting here. On x86_64, parameters passed to UEFI firmware services need to follow the UEFI calling convention. For this purpose, a set of functions named lin2win<x> (<x> is the number of parameters) are implemented. EFI function calls are wrapped before calling the firmware service.

---

 arch/x86_64/Kconfig               |   13 
 arch/x86_64/kernel/Makefile       |    1 
 arch/x86_64/kernel/efi.c          |  581 ++++++++++++++++++++++++++++++++++++++
 arch/x86_64/kernel/efi_callwrap.S |   69 ++++
 arch/x86_64/kernel/setup.c        |   15 
 include/asm-x86_64/bootsetup.h    |    6 
 include/asm-x86_64/eficallwrap.h  |   33 ++
 include/asm-x86_64/efidef.h       |    6 
 include/asm-x86_64/fixmap.h       |    3 
 9 files changed, 726 insertions(+), 1 deletion(-)
include/asm-x86_64/eficallwrap.h new file +33 -0
Index: linux-2.6.23-rc2/include/asm-x86_64/eficallwrap.h
===================================================================
@@ -0,0 +1,33 @@
+/*
+ *  Copyright (C) 2007 Intel Corp
+ *	Bibo Mao <[email protected]>
+ *	Huang Ying <[email protected]>
+ *
+ *  Function calling ABI conversion from SYSV to Windows for x86_64
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ */
+
+#ifndef __ASM_X86_64_EFICALLWRAP_H
+#define __ASM_X86_64_EFICALLWRAP_H
+
+extern efi_status_t lin2win0(void *fp);
+extern efi_status_t lin2win1(void *fp, u64 arg1);
+extern efi_status_t lin2win2(void *fp, u64 arg1, u64 arg2);
+extern efi_status_t lin2win3(void *fp, u64 arg1, u64 arg2, u64 arg3);
+extern efi_status_t lin2win4(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4);
+extern efi_status_t lin2win5(void *fp, u64 arg1, u64 arg2, u64 arg3,
+			     u64 arg4, u64 arg5);
+extern efi_status_t lin2win6(void *fp, u64 arg1, u64 arg2, u64 arg3,
+			     u64 arg4, u64 arg5, u64 arg6);
+
+#endif
arch/x86_64/kernel/efi.c new file +581 -0

581 lines not on this page · raw message

arch/x86_64/kernel/efi_callwrap.S new file +69 -0

69 lines not on this page · raw message

include/asm-x86_64/bootsetup.h +6 -0
Index: linux-2.6.23-rc2/include/asm-x86_64/bootsetup.h
===================================================================
@@ -17,6 +17,12 @@
 #define APM_BIOS_INFO (*(struct apm_bios_info *) (PARAM+0x40))
 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 #define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
+#define EFI_LOADER_SIG ((unsigned char *)(PARAM+0x1c0))
+#define EFI_MEMDESC_SIZE (*((unsigned int *) (PARAM+0x1c4)))
+#define EFI_MEMDESC_VERSION (*((unsigned int *) (PARAM+0x1c8)))
+#define EFI_MEMMAP_SIZE (*((unsigned int *) (PARAM+0x1cc)))
+#define EFI_MEMMAP (*((unsigned long *)(PARAM+0x1d0)))
+#define EFI_SYSTAB (*((unsigned long *)(PARAM+0x1d8)))
 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
 #define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8))
 #define SAVED_VIDEO_MODE (*(unsigned short *) (PARAM+0x1FA))
arch/x86_64/kernel/setup.c +14 -1
Index: linux-2.6.23-rc2/arch/x86_64/kernel/setup.c
===================================================================
@@ -44,6 +44,7 @@
 #include <linux/dmi.h>
 #include <linux/dma-mapping.h>
 #include <linux/ctype.h>
+#include <linux/efi.h>
 
 #include <asm/mtrr.h>
 #include <asm/uaccess.h>
@@ -236,6 +237,10 @@
 	rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
 	rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
 #endif
+#ifdef CONFIG_EFI
+	if (!strncmp(EFI_LOADER_SIG, "EFIL", 4))
+		efi_enabled = 1;
+#endif
 	setup_memory_region();
 	copy_edd();
 
@@ -273,6 +278,8 @@
 	discover_ebda();
 
 	init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
+	if (efi_enabled)
+		efi_init();
 
 	dmi_scan_machine();
 
@@ -339,6 +346,11 @@
         */
        acpi_reserve_bootmem();
 #endif
+
+	/* Reserve efi memory map */
+	if (efi_enabled)
+		reserve_bootmem_generic(EFI_MEMMAP, EFI_MEMMAP_SIZE);
+
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
@@ -411,7 +423,8 @@
 
 #ifdef CONFIG_VT
 #if defined(CONFIG_VGA_CONSOLE)
-	conswitchp = &vga_con;
+	if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
+		conswitchp = &vga_con;
 #elif defined(CONFIG_DUMMY_CONSOLE)
 	conswitchp = &dummy_con;
 #endif
include/asm-x86_64/fixmap.h +3 -0
Index: linux-2.6.23-rc2/include/asm-x86_64/fixmap.h
===================================================================
@@ -15,6 +15,7 @@
 #include <asm/apicdef.h>
 #include <asm/page.h>
 #include <asm/vsyscall.h>
+#include <asm/efidef.h>
 
 /*
  * Here we define all the compile-time 'special' virtual
@@ -41,6 +42,8 @@
 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
 	FIX_IO_APIC_BASE_0,
 	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
+	FIX_EFI_IO_MAP_LAST_PAGE,
+	FIX_EFI_IO_MAP_FIRST_PAGE = FIX_EFI_IO_MAP_LAST_PAGE+MAX_EFI_IO_PAGES-1,
 	__end_of_fixed_addresses
 };
 
include/asm-x86_64/efidef.h new file +6 -0
Index: linux-2.6.23-rc2/include/asm-x86_64/efidef.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef __ASM_X86_64_EFIDEF_H
+#define __ASM_X86_64_EFIDEF_H
+
+#define MAX_EFI_IO_PAGES	100
+
+#endif
arch/x86_64/Kconfig +13 -0
Index: linux-2.6.23-rc2/arch/x86_64/Kconfig
===================================================================
@@ -266,6 +266,19 @@
 	depends on SMP && !MK8
 	default y
 
+config EFI
+	bool "Boot from EFI support (EXPERIMENTAL)"
+	---help---
+	  This enables the the kernel to boot on EFI platforms using
+	  system configuration information passed to it from the firmware.
+	  This also enables the kernel to use any EFI runtime services that are
+	  available (such as the EFI variable services).
+	  This option is only useful on systems that have EFI firmware
+	  and will result in a kernel image that is ~8k larger. However,
+	  even with this option, the resultant kernel should continue to
+	  boot on existing non-EFI platforms. For more information on
+	  how to set up [U]EFI64 system, see Documentation/x86_64/uefi.txt.
+
 config MATH_EMULATION
 	bool
 
arch/x86_64/kernel/Makefile +1 -0
Index: linux-2.6.23-rc2/arch/x86_64/kernel/Makefile
===================================================================
@@ -37,6 +37,7 @@
 obj-$(CONFIG_X86_VSMP)		+= vsmp.o
 obj-$(CONFIG_K8_NB)		+= k8.o
 obj-$(CONFIG_AUDIT)		+= audit.o
+obj-$(CONFIG_EFI)		+= efi.o efi_callwrap.o
 
 obj-$(CONFIG_MODULES)		+= module.o
 obj-$(CONFIG_PCI)		+= early-quirks.o