Skip to contentSkip to conversation

efivars driver update and move

PATCH In review Matt Tolentino 3 participants 5 messages Apr 22, 2004 – Apr 26, 2004 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 efivars driver update and move

Andrew,

I broke up the efivars driver update patch I had sent out quite a while ago into several smaller patches. This includes several fixes and suggestions that were pointed out. The patches are broken down as follows:

1 - remove all traces of efivars from arch/ia64/ 2 - add new sysfs based efivars driver into
drivers/firmware with accompanying Kconfig/Makefile changes to make it fully functional for ia64 again.
3 - cleans up x86 references to the /proc version of
the efivars driver.

The patch is against 2.6.6-rc2 and has been tested on a Tiger4 system and an x86 system with EFI. The second and third patches will follow. Please apply.

thanks,
matt

arch/ia64/Kconfig +0 -10
diff -urN linux-2.6.6-rc2/arch/ia64/Kconfig linux-2.6.6-rc2-mod/arch/ia64/Kconfig
@@ -294,16 +294,6 @@
 	  To use this option, you have to ensure that the "/proc file system
 	  support" (CONFIG_PROC_FS) is enabled, too.
 
-config EFI_VARS
-	tristate "/proc/efi/vars support"
-	help
-	  If you say Y here, you are able to get EFI (Extensible Firmware
-	  Interface) variable information in /proc/efi/vars.  You may read,
-	  write, create, and destroy EFI variables through this interface.
-
-	  To use this option, you have to check that the "/proc file system
-	  support" (CONFIG_PROC_FS) is enabled, too.
-
 source "fs/Kconfig.binfmt"
 
 endmenu
arch/ia64/kernel/efi.c +0 -21
diff -urN linux-2.6.6-rc2/arch/ia64/kernel/efi.c linux-2.6.6-rc2-mod/arch/ia64/kernel/efi.c
@@ -24,7 +24,6 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/time.h>
-#include <linux/proc_fs.h>
 #include <linux/efi.h>
 
 #include <asm/io.h>
@@ -40,19 +39,6 @@
 struct efi efi;
 EXPORT_SYMBOL(efi);
 static efi_runtime_services_t *runtime;
-
-/*
- * efi_dir is allocated here, but the directory isn't created
- * here, as proc_mkdir() doesn't work this early in the bootup
- * process.  Therefore, each module, like efivars, must test for
- *    if (!efi_dir)  efi_dir = proc_mkdir("efi", NULL);
- * prior to creating their own entries under /proc/efi.
- */
-#ifdef CONFIG_PROC_FS
-struct proc_dir_entry *efi_dir;
-EXPORT_SYMBOL(efi_dir);
-#endif
-
 static unsigned long mem_limit = ~0UL;
 
 #define efi_call_virt(f, args...)	(*(f))(args)
@@ -747,10 +733,3 @@
 	return 0;
 }
 
-static void __exit
-efivars_exit (void)
-{
-#ifdef CONFIG_PROC_FS
- 	remove_proc_entry(efi_dir->name, NULL);
-#endif
-}
arch/ia64/kernel/efivars.c +0 -549

549 lines not on this page · raw message

arch/ia64/kernel/Makefile +0 -1
diff -urN linux-2.6.6-rc2/arch/ia64/kernel/Makefile linux-2.6.6-rc2-mod/arch/ia64/kernel/Makefile
@@ -8,7 +8,6 @@
 	 irq_lsapic.o ivt.o machvec.o pal.o patch.o process.o perfmon.o ptrace.o sal.o		\
 	 salinfo.o semaphore.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o unwind.o mca.o mca_asm.o
 
-obj-$(CONFIG_EFI_VARS)		+= efivars.o
 obj-$(CONFIG_IA64_BRL_EMU)	+= brl_emu.o
 obj-$(CONFIG_IA64_GENERIC)	+= acpi-ext.o
 obj-$(CONFIG_IA64_HP_ZX1)	+= acpi-ext.o
arch/ia64/mm/init.c +1 -0
diff -urN linux-2.6.6-rc2/arch/ia64/mm/init.c linux-2.6.6-rc2-mod/arch/ia64/mm/init.c
@@ -18,6 +18,7 @@
 #include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/swap.h>
+#include <linux/proc_fs.h>
 
 #include <asm/a.out.h>
 #include <asm/bitops.h>
#1 lore raw
Quoted 11 lines · Matt Tolentino

I broke up the efivars driver update patch I had sent out quite a while ago into several smaller patches. This includes several fixes and suggestions that were pointed out. The patches are broken down as follows:

1 - remove all traces of efivars from arch/ia64/ 2 - add new sysfs based efivars driver into
drivers/firmware with accompanying Kconfig/Makefile changes to make it fully functional for ia64 again.
3 - cleans up x86 references to the /proc version of
the efivars driver.

I like these changes.

I did notice that the new drivers/.../efivars.c is not identical to the old arch/ia64/kernel/efivars.c (the hints to emacs were removed). I like the emacs hint removal, but didn't review patch for any other differences.

Any plans to consolidate other bits from efi.c? There are a number of things there that look like they could be shared:

is_available_memory()
efi_init()
(mostly)
efi_initialize_iomem_resources()
(i386 only today, but I think we'd like it for ia64 also)
efi_mem_type()
efi_mem_attributes()
(the i386 versions look slightly buggy in that they assume a fixed descriptor size, so old kernels won't work with new firmware that adds stuff to the descriptor)

Bjorn

#2 lore raw
In reply to Matt Tolentino
Quoted 10 lines · Matt Tolentino

Andrew,

I broke up the efivars driver update patch I had sent out quite a while ago into several smaller patches. This includes several fixes and suggestions that were pointed out. The patches are broken down as follows:

2 - add new sysfs based efivars driver into
drivers/firmware with accompanying Kconfig/Makefile changes to make it fully functional for ia64 again.

Trying these against 2.6.5 + ia64 patch, with efibootmgr-0.5.2-test2.

Works: reading, deleting values.
Doesn't work: creating and editing values

I note that efibootmgr prints out a warning when it can't read nonexistant variables, like BootNext. I'll remove that warning.

It's likely a bug in efibootmgr, as this is the first time I've tried the sysfs side of things. If you're in a position to help debug, I'd appreciate it.

Thanks,
Matt

Signature · 4 lines
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com
#3 lore raw
Quoted 11 lines · Matt Domsch

Trying these against 2.6.5 + ia64 patch, with efibootmgr-0.5.2-test2.

Works: reading, deleting values.
Doesn't work: creating and editing values

I note that efibootmgr prints out a warning when it can't read nonexistant variables, like BootNext. I'll remove that warning.

It's likely a bug in efibootmgr, as this is the first time I've tried the sysfs side of things. If you're in a position to help debug, I'd appreciate it.

In fact, it *was* a bug in efibootmgr. Here's the patch to fix it...

There's also a bug in efivars.c:efivar_delete(), this one-liner should fix it.

drivers/firmware/efivars.c 2004-04-24 12:09:28.099545422 -0400 renamed from drivers/firmware/efivars.c 2004-04-24 06:58:08.000000000 -0400 +1 -1
@@ -532,7 +532,7 @@ efivar_delete(struct subsystem *sub, con
        efivar_unregister(search_efivar);
  
        /* It's dead Jim.... */
-       return status;
+       return size;
 }
 
 
Signature · 38 lines
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com

diff -urNp --exclude='*~' efibootmgr-0.5.0-test2.orig/src/lib/efi.c efibootmgr-0.5.0-test2/src/lib/efi.c
--- efibootmgr-0.5.0-test2.orig/src/lib/efi.c	2003-09-07 00:24:18.000000000 -0400
+++ efibootmgr-0.5.0-test2/src/lib/efi.c	2004-04-24 12:15:25.375908233 -0400
@@ -166,7 +166,7 @@ create_or_edit_variable(efi_variable_t *
 	memcpy(&testvar, var, sizeof(*var));
 	variable_to_name(var, name);
 
-	if (read_variable(name, &testvar))
+	if (read_variable(name, &testvar) == EFI_SUCCESS)
 		return edit_variable(var);
 	else
 		return create_variable(var);
diff -urNp --exclude='*~' efibootmgr-0.5.0-test2.orig/src/lib/efivars_sysfs.c efibootmgr-0.5.0-test2/src/lib/efivars_sysfs.c
--- efibootmgr-0.5.0-test2.orig/src/lib/efivars_sysfs.c	2003-09-07 00:21:37.000000000 -0400
+++ efibootmgr-0.5.0-test2/src/lib/efivars_sysfs.c	2004-04-24 12:35:38.207924626 -0400
@@ -49,8 +49,6 @@ sysfs_read_variable(const char *name, ef
 	snprintf(filename, PATH_MAX-1, "%s/%s/raw_var", SYSFS_DIR_EFI_VARS,name);
 	fd = open(filename, O_RDONLY);
 	if (fd == -1) {
-		sprintf(buffer, "sysfs_read_variable():open(%s)", filename);
-		perror(buffer);
 		return EFI_NOT_FOUND;
 	}
 	readsize = read(fd, var, sizeof(*var));
@@ -74,8 +72,6 @@ sysfs_write_variable(const char *filenam
 
 	fd = open(filename, O_WRONLY);
 	if (fd == -1) {
-		sprintf(buffer, "sysfs_write_variable():open(%s)", filename);
-		perror(buffer);
 		return EFI_INVALID_PARAMETER;
 	}
 	writesize = write(fd, var, sizeof(*var));
#4 lore raw

Patch below fixes three small bugs in efivars.c as posted by Matt Tolentino last week and included in the latest -mm. Aside from this small patch, I'm quite pleased with Matt T's work, thanks!

* dummy() used for reading write-only sysfs files should return -ENODEV to indicate failure, not 0.
* efivar_create() should return the number of bytes written on success, not zero.
* efivar_delete() should return the number of bytes written on success, not zero.

Compiled, tested with efibootmgr-0.5.0-test3. The anomolies I noted late Friday night are resolved by this kernel patch - efibootmgr was actually testing the values returned by writes.

Signature · 65 lines
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com

--- linux-2.6.5.orig/drivers/firmware/efivars.c	2004-04-24 06:58:08.000000000 -0400
+++ linux-2.6.5/drivers/firmware/efivars.c	2004-04-27 03:48:33.037318467 -0400
@@ -1,7 +1,7 @@
 /*
  * EFI Variables - efivars.c
  *
- * Copyright (C) 2001,2003 Dell <[email protected]>
+ * Copyright (C) 2001,2003,2004 Dell <[email protected]>
  * Copyright (C) 2004 Intel Corporation <[email protected]>
  *
  * This code takes all variables accessible from EFI runtime and
@@ -23,6 +23,9 @@
  *
  * Changelog:
  *
+ *  26 Apr 2004 - Matt Domsch <[email protected]>
+ *   minor bug fixes
+ *
  *  21 Apr 2004 - Matt Tolentino <[email protected])
  *   converted driver to export variable information via sysfs
  *   and moved to drivers/firmware directory
@@ -78,7 +81,7 @@ MODULE_AUTHOR("Matt Domsch <Matt_Domsch@
 MODULE_DESCRIPTION("sysfs interface to EFI Variables");
 MODULE_LICENSE("GPL");
 
-#define EFIVARS_VERSION "0.07 2003-Aug-29"
+#define EFIVARS_VERSION "0.07 2004-Apr-26"
 
 /*
  * efivars_lock protects two things:
@@ -408,7 +411,7 @@ static struct kobj_type ktype_efivar = {
 static ssize_t
 dummy(struct subsystem *sub, char *buf)
 {
-	return 0;
+	return -ENODEV;
 }
 
 static inline void
@@ -472,7 +475,10 @@ efivar_create(struct subsystem *sub, con
 	/* Create the entry in sysfs.  Locking is not required here */
 	status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName,
 			1024), new_var->VariableName, &new_var->VendorGuid);
-	return status;
+	if (status) {
+		printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n");
+	}
+	return count;
 }
 
 static ssize_t
@@ -532,7 +538,7 @@ efivar_delete(struct subsystem *sub, con
 	efivar_unregister(search_efivar);
 
 	/* It's dead Jim.... */
-	return status;
+	return count;
 }
 
 static VAR_SUBSYS_ATTR(new_var, 0200, dummy, efivar_create);