Skip to contentSkip to conversation

for efi support in ia32 kernels

PATCH RESEND New Matt Tolentino 1 participant 1 message Oct 3, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 for efi support in ia32 kernels

Well, looks like the first mail got munged. Here's the original mail with the patch inline.... Sorry for the trash.

matt

Attached is another patch that enables EFI boot-up support in ia32 = kernels. This one has numerous changes based on the various comments = and suggestions made on the last one several weeks ago. The patch is = against 2.6.0-test6-mm2. =20

This patch departs from the last in that I am no longer adding separate = boot parameters at the end of the the empty_zero_page; rather, based on = Eric's suggestion, I've added EFI parameters via offset grouped with the = rest of the existing boot parameters. This allows the reuse of several = parameters which were redundant (command-line, initrd, etc.). This also = simplifies some of the code in setup_arch(). =20

In order to continue to determine whether the kernel should initialize = using EFI tables, I've temporarily added a check on the LOADER_TYPE boot = parameter. Although I haven't requested that elilo be assigned an id = for this yet, I've used this to determine whether the kernel should use = the EFI initialization path as well as a check to see if the EFI_SYSTAB = boot parameter contains anything. If someone has a better suggestion = for determining this, I'm open...

This patch also uses the existing ioremapping functions to map the efi = tables into kernel virtual address space. I've added an option such = that I could use Dave Hansen's boot_ioremap() before paging_init(). = After paging_init, I then remap the efi memmap using bt_ioremap for use = later. This has eliminated the need for several functions...thanks for = the suggestions and thanks for your help Dave. Still this could use a = look-see. =20

Something else that I'd like to solicit suggestions on is how to deal = with CONFIG_ACPI_EFI. One of the goals of this patch is to enable the = kernel to "just know" at boot time when to use EFI information to = initialize. That way, the same kernel image would theoretically still = boot on existing systems with a different BIOS. I think this patch = accomplishes that goal to some degree, but how best to deal with = when/when not to look at the EFI config table for the RSDP is still = dealt with at compile time. I'd like to dynamically determine this as = well, but am not sure of the best way...suggestions? Len? Andrew?

Note, I'm still working on verifying this works properly on a system = with >4GB system memory, as well as with the 4G/4G split (hence the = reason this is against the -mm kernel)...hopefully, I'll be able to = steal some time on one of those monsters next week.

Comments and suggestions are welcome...

thanks,
matt

arch/i386/Kconfig +3 -2
diff -urN linux-2.6.0-test6-mm2/arch/i386/Kconfig linux-2.6.0-test6-mm2-efi/arch/i386/Kconfig
@@ -840,8 +840,9 @@
 # turning this on wastes a bunch of space.
 # Summit needs it only when NUMA is on
 config BOOT_IOREMAP
-	bool
-	depends on ((X86_SUMMIT || X86_GENERICARCH) && NUMA)
+	bool 
+	depends on X86_PC
+# depends on (((X86_SUMMIT || X86_GENERICARCH) && NUMA)) || X86_GENERICARCH
 	default y
 
 endmenu
arch/i386/kernel/acpi/boot.c +6 -1
diff -urN linux-2.6.0-test6-mm2/arch/i386/kernel/acpi/boot.c linux-2.6.0-test6-mm2-efi/arch/i386/kernel/acpi/boot.c
@@ -26,6 +26,7 @@
 #include <linux/init.h>
 #include <linux/config.h>
 #include <linux/acpi.h>
+#include <linux/efi.h>
 #include <asm/pgalloc.h>
 #include <asm/io_apic.h>
 #include <asm/apic.h>
@@ -295,7 +296,11 @@
 acpi_find_rsdp (void)
 {
 	unsigned long		rsdp_phys = 0;
-
+	
+	if (efi.acpi20)
+		return __pa(efi.acpi20);
+	else if (efi.acpi)
+		return __pa(efi.acpi);
 	/*
 	 * Scan memory looking for the RSDP signature. First search EBDA (low
 	 * memory) paragraphs and then search upper memory (E0000-FFFFF).
arch/i386/kernel/efi.c +606 -0

606 lines not on this page · raw message

arch/i386/kernel/efi_stub.S +125 -0

125 lines not on this page · raw message

arch/i386/kernel/Makefile +1 -1
diff -urN linux-2.6.0-test6-mm2/arch/i386/kernel/Makefile linux-2.6.0-test6-mm2-efi/arch/i386/kernel/Makefile
@@ -7,7 +7,7 @@
 obj-y	:= process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \
 		ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o \
 		pci-dma.o i386_ksyms.o i387.o dmi_scan.o bootflag.o \
-		doublefault.o entry_trampoline.o
+		doublefault.o efi.o efi_stub.o entry_trampoline.o
 
 obj-y				+= cpu/
 obj-y				+= timers/
arch/i386/kernel/reboot.c +11 -1
diff -urN linux-2.6.0-test6-mm2/arch/i386/kernel/reboot.c linux-2.6.0-test6-mm2-efi/arch/i386/kernel/reboot.c
@@ -7,6 +7,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/mc146818rtc.h>
+#include <linux/efi.h>
 #include <asm/uaccess.h>
 #include <asm/apic.h>
 #include "mach_reboot.h"
@@ -261,7 +262,12 @@
 	disable_IO_APIC();
 #endif
 
-	if(!reboot_thru_bios) {
+	if (!reboot_thru_bios) {
+		if (efi_enabled) {
+			efi.reset_system(EFI_RESET_COLD, EFI_SUCCESS, 0, 0);
+			__asm__ __volatile__("lidt %0": :"m" (no_idt));
+			__asm__ __volatile__("int3");
+		}
 		/* rebooting needs to touch the page at absolute addr 0 */
 		*((unsigned short *)__va(0x472)) = reboot_mode;
 		for (;;) {
@@ -271,6 +277,8 @@
 			__asm__ __volatile__("int3");
 		}
 	}
+	if (efi_enabled)
+		efi.reset_system(EFI_RESET_WARM, EFI_SUCCESS, 0, 0);
 
 	machine_real_restart(jump_to_bios, sizeof(jump_to_bios));
 }
@@ -281,6 +289,8 @@
 
 void machine_power_off(void)
 {
+	if (efi_enabled)
+		efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, 0);
 	if (pm_power_off)
 		pm_power_off();
 }
arch/i386/kernel/setup.c +118 -17

238 lines not on this page · raw message

arch/i386/kernel/time.c +62 -4

102 lines not on this page · raw message

arch/i386/mm/init.c +20 -1
diff -urN linux-2.6.0-test6-mm2/arch/i386/mm/init.c linux-2.6.0-test6-mm2-efi/arch/i386/mm/init.c
@@ -25,6 +25,7 @@
 #include <linux/bootmem.h>
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
+#include <linux/efi.h>
 
 #include <asm/processor.h>
 #include <asm/system.h>
@@ -52,12 +53,30 @@
 	return 0;
 }
 
+extern int is_available_memory(efi_memory_desc_t *);
+
 static inline int page_is_ram(unsigned long pagenr)
 {
 	int i;
+	unsigned long addr, end;
+
+	if (efi_enabled) {
+		efi_memory_desc_t *md;
+		
+		for (i = 0; i < memmap.nr_map; i++) {
+			md = &memmap.map[i];
+			if (!is_available_memory(md))
+				continue;
+			addr = (md->phys_addr+PAGE_SIZE-1) >> PAGE_SHIFT;
+			end = (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT)) >> PAGE_SHIFT;
+
+			if ((pagenr >= addr) && (pagenr < end))
+				return 1;
+		}
+		return 0;
+	}
 
 	for (i = 0; i < e820.nr_map; i++) {
-		unsigned long addr, end;
 
 		if (e820.map[i].type != E820_RAM)	/* not usable memory */
 			continue;
drivers/acpi/Kconfig +9 -3
diff -urN linux-2.6.0-test6-mm2/drivers/acpi/Kconfig linux-2.6.0-test6-mm2-efi/drivers/acpi/Kconfig
@@ -252,10 +252,16 @@
 	  dump your ACPI DSDT table using /proc/acpi/dsdt.
 
 config ACPI_EFI
-	bool
+ 	bool "Obtain RSDP from EFI Configuration Table" 
 	depends on ACPI_INTERPRETER
-	depends on IA64
-	default y
+	depends on IA64 || X86
+  	default y
+ 	help
+ 	   On EFI Systems the RSDP pointer is passed to the kernel via
+ 	   the EFI Configuration Table.  On Itanium systems this is 
+ 	   standard and required.  For IA-32, systems that have
+ 	   EFI firmware should leave this enabled.  Platforms with 
+ 	   traditional legacy BIOS should disable this option.
 
 config ACPI_RELAXED_AML
 	bool "Relaxed AML"
drivers/acpi/osl.c +0 -1
diff -urN linux-2.6.0-test6-mm2/drivers/acpi/osl.c linux-2.6.0-test6-mm2-efi/drivers/acpi/osl.c
@@ -43,7 +43,6 @@
 
 #ifdef CONFIG_ACPI_EFI
 #include <linux/efi.h>
-u64 efi_mem_attributes (u64 phys_addr);
 #endif
 
 
include/asm-i386/setup.h +5 -0
diff -urN linux-2.6.0-test6-mm2/include/asm-i386/setup.h linux-2.6.0-test6-mm2-efi/include/asm-i386/setup.h
@@ -29,6 +29,11 @@
 #define IST_INFO   (*(struct ist_info *) (PARAM+0x60))
 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 #define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
+#define EFI_SYSTAB ((efi_system_table_t *) *((unsigned long *)(PARAM+0x1c4)))
+#define EFI_MEMDESC_SIZE (*((unsigned long *) (PARAM+0x1c8)))
+#define EFI_MEMDESC_VERSION (*((unsigned long *) (PARAM+0x1cc)))
+#define EFI_MEMMAP ((efi_memory_desc_t *) *((unsigned long *)(PARAM+0x1d0)))
+#define EFI_MEMMAP_SIZE (*((unsigned long *) (PARAM+0x1d4)))
 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
 #define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8))
 #define VIDEO_MODE (*(unsigned short *) (PARAM+0x1FA))
include/linux/efi.h +33 -0
diff -urN linux-2.6.0-test6-mm2/include/linux/efi.h linux-2.6.0-test6-mm2-efi/include/linux/efi.h
@@ -16,6 +16,8 @@
 #include <linux/time.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
+#include <linux/rtc.h>
+#include <linux/ioport.h>
 
 #include <asm/page.h>
 #include <asm/system.h>
@@ -89,6 +91,11 @@
 
 #define EFI_PAGE_SHIFT		12
 
+/* 
+ * For current x86 implementations of EFI, there is 
+ * additional padding in the mem descriptors.  This is not
+ * the case in ia64.  Need to have this fixed in the f/w.
+ */
 typedef struct {
 	u32 type;
 	u32 pad;
@@ -96,6 +103,9 @@
 	u64 virt_addr;
 	u64 num_pages;
 	u64 attribute;
+#if defined (__i386__)
+	u64 pad1;
+#endif
 } efi_memory_desc_t;
 
 typedef int efi_freemem_callback_t (unsigned long start, unsigned long end, void *arg);
@@ -132,6 +142,7 @@
  */
 #define EFI_RESET_COLD 0
 #define EFI_RESET_WARM 1
+#define EFI_RESET_SHUTDOWN 2
 
 /*
  * EFI Runtime Services table
@@ -169,6 +180,10 @@
 typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
 typedef void efi_reset_system_t (int reset_type, efi_status_t status,
 				 unsigned long data_size, efi_char16_t *data);
+typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
+						unsigned long descriptor_size,
+						u32 descriptor_version,
+						efi_memory_desc_t *virtual_map);
 
 /*
  *  EFI Configuration Table and GUID definitions
@@ -194,6 +209,9 @@
 #define HCDP_TABLE_GUID	\
     EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 )
 
+#define UGA_IO_PROTOCOL_GUID \
+    EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 )
+
 typedef struct {
 	efi_guid_t guid;
 	unsigned long table;
@@ -218,6 +236,13 @@
 	unsigned long tables;
 } efi_system_table_t;
 
+struct efi_memory_map {
+	efi_memory_desc_t *phys_map;
+	efi_memory_desc_t *map;
+	int nr_map;
+	unsigned long desc_version;
+};
+
 /*
  * All runtime access to EFI goes through this structure:
  */
@@ -230,6 +255,7 @@
 	void *sal_systab;		/* SAL system table */
 	void *boot_info;		/* boot info table */
 	void *hcdp;			/* HCDP table */
+	void *uga;			/* UGA table */
 	efi_get_time_t *get_time;
 	efi_set_time_t *set_time;
 	efi_get_wakeup_time_t *get_wakeup_time;
@@ -239,6 +265,7 @@
 	efi_set_variable_t *set_variable;
 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
 	efi_reset_system_t *reset_system;
+	efi_set_virtual_address_map_t *set_virtual_address_map;
 } efi;
 
 static inline int
@@ -260,12 +287,18 @@
 
 extern void efi_init (void);
 extern void efi_map_pal_code (void);
+extern void efi_map_memmap(void);
 extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
 extern void efi_gettimeofday (struct timespec *ts);
 extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
 extern u64 efi_get_iobase (void);
 extern u32 efi_mem_type (unsigned long phys_addr);
 extern u64 efi_mem_attributes (unsigned long phys_addr);
+extern void efi_initialize_iomem_resources(struct resource *code_resource,
+					struct resource *data_resource);
+extern efi_status_t phys_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc);
+extern struct efi_memory_map memmap;
+extern int efi_enabled;
 
 /*
  * Variable Attributes
init/main.c +3 -0
diff -urN linux-2.6.0-test6-mm2/init/main.c linux-2.6.0-test6-mm2-efi/init/main.c
@@ -37,6 +37,7 @@
 #include <linux/moduleparam.h>
 #include <linux/writeback.h>
 #include <linux/cpu.h>
+#include <linux/efi.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -436,6 +437,8 @@
 	pidmap_init();
 	pgtable_cache_init();
 	pte_chain_init();
+	if (efi_enabled)
+		efi_enter_virtual_mode();
 	fork_init(num_physpages);
 	proc_caches_init();
 	buffer_init();