google firmware support
v2 cover google firmware support
This patchset applies to v2.6.38-rc8.
The following series implements some support for interfaces exposed by google's servers' firmware. Unlike the previous send-out, it only includes two of the three drivers as I'm not yet finished fixing the "bootlog" driver from the last send-out (and I've discovered more "undocumented" firmware functionality that I'd rather unravel before sending out again).
In order to address various concerns had with the previous patchset, I've changed the user ABI significantly:
Instead of messing with the dmesg log_buf ring-buffer, we now expose firmware logs via /sys/firmware/log.
As well, instead of using a ioctl interface the gsmi driver, I've changed it completely to use sysfs instead (rooted at /sys/firmware/gsmi). gsmi provides access to EFI variables through a means other than through the EFI runtime services page, so I've reused the bulk of the code exposed by the efivars driver. To make this work, I had to refactor a bit of the efivars driver. The only user-visible change here is that the module will successfully load now even if you aren't on an EFI system (which is much more consistent with other drivers anyway).
I'd like to have these small drivers included as they are required for proper use of the kernel in our infrastructure. They may not seem like much, but a lot of our health automation as well as our human debugging efforts are dependent on the functionality herein. Getting these in the public Linux tree would bring us closer to being able to easily test kernels as they are released.
Thanks,
Patchset summary
================
Patches [1 through 6] refactor the 'efivars' module to let the "gsmi" driver in patch [11] re-use the variable functionality.
Patch [7] documents existing 'efivars' functionality that has been present in the tree since 2004.
Patches [8] and [9] add sanity checking for accessing the EBDA.
Patch [10] introduces CONFIG_GOOGLE_FIRMWARE that is disabled by default and which gates Google-specific drivers.
Patch [11] adds the "gsmi" driver that we use to make calls into our firmware.
Patch [12] adds the "memconsole" driver that finds the firmware's logs and exposes them on /sys/firmware/log.
Diffstat
========
Documentation/ABI/stable/sysfs-firmware-efi-vars | 75 + Documentation/ABI/testing/sysfs-firmware-gsmi | 58 + Documentation/ABI/testing/sysfs-firmware-log | 7 arch/x86/include/asm/bios_ebda.h | 28 drivers/firmware/Kconfig | 2 drivers/firmware/Makefile | 2 drivers/firmware/efivars.c | 343 +++++--- drivers/firmware/google/Kconfig | 33 drivers/firmware/google/Makefile | 3 drivers/firmware/google/gsmi.c | 927 +++++++++++++++++++++++ drivers/firmware/google/memconsole.c | 151 +++ include/linux/efi.h | 37 12 files changed, 1526 insertions(+), 140 deletions(-)
ChangeLog:
==========
- v2
- Efivars can now be used by other drivers.
- Documentation added for /sys/firmware/efi/vars
- Memory console no longer touches log_buf ring buffer.
- The firmware log is exported to userland as /sys/firmware/log
- Ioctls for accessing nvram variables in gsmi driver replaced with efivars at /sys/firmware/gsmi/vars.
- die_notifier is used instead of adding new notifer_lists.
- EBDA scrubbing for memconsole now checks that we aren't walking
into 0xA0000.
- Documentation added for /sys/firmware/log
- Documentation added for /sys/firmware/gsmi
- Use kernel fixed width types instead of C99 types.
- v1
- Initial public send-out.
PATCH v2 1/12 efivars: move efivars globals into struct efivars
In preparation for abstracting out efivars to be usable by other similar variable services, move the global lock, list and kset into a structure. Later patches will change the scope of 'efivars' and have it be passed by function argument.
--- drivers/firmware/efivars.c | 86 ++++++++++++++++++++++++-------------------- 1 files changed, 46 insertions(+), 40 deletions(-)
drivers/firmware/efivars.c +46 -40
@@ -89,16 +89,21 @@ MODULE_DESCRIPTION("sysfs interface to EFI Variables");MODULE_LICENSE ("GPL" );MODULE_VERSION (EFIVARS_VERSION ); -/* -* efivars_lock protects two things: -* 1) efivar_list - adds, removals, reads, writes -* 2) efi.[gs]et_variable() calls. -* It must not be held when creating sysfs entries or calling kmalloc. -* efi.get_next_variable() is only called from efivars_init(), -* which is protected by the BKL, so that path is safe. -*/ -static DEFINE_SPINLOCK (efivars_lock); -static LIST_HEAD (efivar_list); +struct efivars { +/* +* ->lock protects two things: +* 1) ->list - adds, removals, reads, writes +* 2) efi.[gs]et_variable() calls. +* It must not be held when creating sysfs entries or calling kmalloc. +* efi.get_next_variable() is only called from efivars_init(), +* which is protected by the BKL, so that path is safe. +*/ +spinlock_t lock; +struct list_head list; +struct kset *kset; +}; +static struct efivars __efivars; +static struct efivars *efivars = &__efivars;/* * The maximum size of VariableName + Data = 1024
@@ -174,14 +179,14 @@ get_var_data(struct efi_variable *var) {efi_status_t status; -spin_lock (&efivars_lock); +spin_lock (&efivars->lock); var->DataSize =1024 ; status = efi.get_variable (var->VariableName, &var->VendorGuid, &var->Attributes, &var->DataSize, var->Data); -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);if (status !=EFI_SUCCESS ) {printk (KERN_WARNING "efivars: get_variable() failed 0x%lx!\n" , status);
@@ -291,14 +296,14 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)return -EINVAL ; } -spin_lock (&efivars_lock); +spin_lock (&efivars->lock); status = efi.set_variable (new_var->VariableName, &new_var->VendorGuid, new_var->Attributes, new_var->DataSize, new_var->Data); -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);if (status !=EFI_SUCCESS ) { printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
@@ -415,12 +420,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -spin_lock (&efivars_lock); +spin_lock (&efivars->lock);/* * Does this variable already exist? */ -list_for_each_entry_safe (search_efivar, n, &efivar_list, list) { +list_for_each_entry_safe (search_efivar, n, &efivars->list, list) { strsize1 =utf8_strsize (search_efivar->var.VariableName,1024 ); strsize2 =utf8_strsize (new_var->VariableName,1024 ); if (strsize1 == strsize2 &&
@@ -433,7 +438,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, } }if (found) { -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);return -EINVAL ; }
@@ -447,10 +452,10 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,if (status !=EFI_SUCCESS ) {printk (KERN_WARNING "efivars: set_variable() failed: status=%lx\n" , status); -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);return -EIO ; } -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);/* Create the entry in sysfs. Locking is not required here */ status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName,
@@ -474,12 +479,12 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,if (!capable (CAP_SYS_ADMIN ))return -EACCES ; -spin_lock (&efivars_lock); +spin_lock (&efivars->lock);/* * Does this variable already exist? */ -list_for_each_entry_safe (search_efivar, n, &efivar_list, list) { +list_for_each_entry_safe (search_efivar, n, &efivars->list, list) { strsize1 =utf8_strsize (search_efivar->var.VariableName,1024 ); strsize2 =utf8_strsize (del_var->VariableName,1024 ); if (strsize1 == strsize2 &&
@@ -492,7 +497,7 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, } }if (!found) { -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);return -EINVAL ; }/* force the Attributes/DataSize to 0 to ensure deletion */
@@ -508,12 +513,12 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,if (status !=EFI_SUCCESS ) {printk (KERN_WARNING "efivars: set_variable() failed: status=%lx\n" , status); -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);return -EIO ; }list_del (&search_efivar->list);/* We need to release this lock before unregistering. */ -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);efivar_unregister (search_efivar);/* It's dead Jim.... */
@@ -572,8 +577,6 @@ static struct attribute_group efi_subsys_attr_group = { .attrs = efi_subsys_attrs, }; - -static struct kset *vars_kset;static struct kobject *efi_kobj;/*
@@ -582,7 +585,7 @@ static struct kobject *efi_kobj;* variable_name_size = number of bytes required to hold * variable_name (not counting the NULL * character at the end. -* efivars_lock is not held on entry or exit. +* efivars->lock is not held on entry or exit. * Returns 1 on failure, 0 on success */ static int
@@ -618,7 +621,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, *(short_name +strlen (short_name)) ='-' ;efi_guid_unparse (vendor_guid, short_name +strlen (short_name)); - new_efivar->kobj.kset = vars_kset; + new_efivar->kobj.kset = efivars->kset; i =kobject_init_and_add (&new_efivar->kobj, &efivar_ktype,NULL ,"%s" , short_name);if (i) {
@@ -631,9 +634,9 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,kfree (short_name); short_name =NULL ; -spin_lock (&efivars_lock); -list_add (&new_efivar->list, &efivar_list); -spin_unlock (&efivars_lock); +spin_lock (&efivars->lock); +list_add (&new_efivar->list, &efivars->list); +spin_unlock (&efivars->lock);return 0 ; }
@@ -674,8 +677,11 @@ efivars_init(void) goto out_free; } - vars_kset =kset_create_and_add ("vars" ,NULL , efi_kobj); -if (!vars_kset) { +spin_lock_init (&efivars->lock); +INIT_LIST_HEAD (&efivars->list); + + efivars->kset =kset_create_and_add ("vars" ,NULL , efi_kobj); +if (!efivars->kset) {printk (KERN_ERR "efivars: Subsystem registration failed.\n" ); error = -ENOMEM ; goto out_firmware_unregister;
@@ -712,12 +718,12 @@ efivars_init(void)* Now add attributes to allow creation of new vars * and deletion of existing ones... */ - error =sysfs_create_bin_file (&vars_kset->kobj, + error =sysfs_create_bin_file (&efivars->kset->kobj, &var_subsys_attr_new_var);if (error)printk (KERN_ERR "efivars: unable to create new_var sysfs file" " due to error %d\n" , error); - error =sysfs_create_bin_file (&vars_kset->kobj, + error =sysfs_create_bin_file (&efivars->kset->kobj, &var_subsys_attr_del_var);if (error) printk(KERN_ERR "efivars: unable to create del_var sysfs file"
@@ -730,7 +736,7 @@ efivars_init(void)else goto out_free; -kset_unregister (vars_kset); +kset_unregister (efivars->kset); out_firmware_unregister:kobject_put (efi_kobj);
@@ -746,14 +752,14 @@ efivars_exit(void) {struct efivar_entry *entry, *n; -list_for_each_entry_safe (entry, n, &efivar_list, list) { -spin_lock (&efivars_lock); +list_for_each_entry_safe (entry, n, &efivars->list, list) { +spin_lock (&efivars->lock);list_del (&entry->list); -spin_unlock (&efivars_lock); +spin_unlock (&efivars->lock);efivar_unregister (entry); } -kset_unregister (vars_kset); +kset_unregister (efivars->kset);kobject_put (efi_kobj); }
PATCH v2 2/12 efivars: Make efivars bin_attributes dynamic
In reply to Mike WaychisonIn preparation for encapsulating efivars, we need to have the bin_attributes be dynamically allocated so that we can use their ->private fields to get back to the struct efivars structure.
--- drivers/firmware/efivars.c | 93 ++++++++++++++++++++++++++++++++------------ 1 files changed, 68 insertions(+), 25 deletions(-)
drivers/firmware/efivars.c +68 -25
@@ -101,6 +101,7 @@ struct efivars {spinlock_t lock;struct list_head list;struct kset *kset; +struct bin_attribute *new_var, *del_var; };static struct efivars __efivars;static struct efivars *efivars = &__efivars;
@@ -525,16 +526,6 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,return count; } -static struct bin_attribute var_subsys_attr_new_var = { - .attr = {.name ="new_var" , .mode =0200 }, - .write = efivar_create, -}; - -static struct bin_attribute var_subsys_attr_del_var = { - .attr = {.name ="del_var" , .mode =0200 }, - .write = efivar_delete, -}; -/* * Let's not leave out systab information that snuck into * the efivars driver
@@ -640,6 +631,66 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,return 0 ; } + +static int +create_efivars_bin_attributes (struct efivars *efivars) +{ +struct bin_attribute *attr; +int error; + +/* new_var */ + attr =kzalloc (sizeof (*attr),GFP_KERNEL ); +if (!attr) +return -ENOMEM ; + + attr->attr.name ="new_var" ; + attr->attr.mode =0200 ; + attr->write = efivar_create; + attr->private = efivars; + efivars->new_var = attr; + +/* del_var */ + attr =kzalloc (sizeof (*attr),GFP_KERNEL ); +if (!attr) { + error = -ENOMEM ; + goto out_free; + } + attr->attr.name ="del_var" ; + attr->attr.mode =0200 ; + attr->write = efivar_delete; + attr->private = efivars; + efivars->del_var = attr; + +sysfs_bin_attr_init (efivars->new_var); +sysfs_bin_attr_init (efivars->del_var); + +/* Register */ + error =sysfs_create_bin_file (&efivars->kset->kobj, + efivars->new_var); +if (error) { +printk (KERN_ERR "efivars: unable to create new_var sysfs file" +" due to error %d\n" , error); + goto out_free; + } + error =sysfs_create_bin_file (&efivars->kset->kobj, + efivars->del_var); +if (error) { +printk (KERN_ERR "efivars: unable to create del_var sysfs file" +" due to error %d\n" , error); +sysfs_remove_bin_file (&efivars->kset->kobj, + efivars->new_var); + goto out_free; + } + +return 0 ; +out_free: +kfree (efivars->new_var); + efivars->new_var =NULL ; +kfree (efivars->new_var); + efivars->new_var =NULL ; +return error; +} +/* * For now we register the efi subsystem with the firmware subsystem * and the vars subsystem with the efi subsystem. In the future, it
@@ -714,20 +765,7 @@ efivars_init(void) } }while (status !=EFI_NOT_FOUND ); -/* -* Now add attributes to allow creation of new vars -* and deletion of existing ones... -*/ - error =sysfs_create_bin_file (&efivars->kset->kobj, - &var_subsys_attr_new_var); -if (error) -printk (KERN_ERR "efivars: unable to create new_var sysfs file" -" due to error %d\n" , error); - error =sysfs_create_bin_file (&efivars->kset->kobj, - &var_subsys_attr_del_var); -if (error) -printk (KERN_ERR "efivars: unable to create del_var sysfs file" -" due to error %d\n" , error); + error =create_efivars_bin_attributes (efivars);/* Don't forget the systab entry */ error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group);
@@ -758,7 +796,12 @@ efivars_exit(void)spin_unlock (&efivars->lock);efivar_unregister (entry); } - +if (efivars->new_var) +sysfs_remove_bin_file (&efivars->kset->kobj, efivars->new_var); +if (efivars->del_var) +sysfs_remove_bin_file (&efivars->kset->kobj, efivars->del_var); +kfree (efivars->new_var); +kfree (efivars->del_var);kset_unregister (efivars->kset);kobject_put (efi_kobj); }
PATCH v2 3/12 efivars: parameterize efivars
In reply to Mike WaychisonNow that we all global variable state is encapsulated by struct efivars, parameterize all functions to the efivars local to the control flow rather than at file scope. We do this by removing the variable "efivars" at file scope and move its storage down to the end of the file.
Variables get at efivars by storing the efivars pointer within each efivar_entry. The "new_var" and "del_var" binary attribute files get at the efivars through the private pointer.
--- drivers/firmware/efivars.c | 49 ++++++++++++++++++++++++++++---------------- 1 files changed, 31 insertions(+), 18 deletions(-)
drivers/firmware/efivars.c +31 -18
@@ -103,8 +103,6 @@ struct efivars {struct kset *kset;struct bin_attribute *new_var, *del_var; }; -static struct efivars __efivars; -static struct efivars *efivars = &__efivars;/* * The maximum size of VariableName + Data = 1024
@@ -124,6 +122,7 @@ struct efi_variable {struct efivar_entry { +struct efivars *efivars;struct efi_variable var;struct list_head list;struct kobject kobj;
@@ -150,9 +149,10 @@ struct efivar_attribute efivar_attr_##_name = { \* Prototype for sysfs creation function */ static int -efivar_create_sysfs_entry (unsigned long variable_name_size, -efi_char16_t *variable_name, -efi_guid_t *vendor_guid); +efivar_create_sysfs_entry (struct efivars *efivars, +unsigned long variable_name_size, +efi_char16_t *variable_name, +efi_guid_t *vendor_guid);/* Return the number of unicode characters in data */ static unsigned long
@@ -176,7 +176,7 @@ utf8_strsize(efi_char16_t *data, unsigned long maxlength) }static efi_status_t -get_var_data (struct efi_variable *var) +get_var_data (struct efivars *efivars,struct efi_variable *var) {efi_status_t status;
@@ -221,7 +221,7 @@ efivar_attr_read(struct efivar_entry *entry, char *buf)if (!entry || !buf)return -EINVAL ; - status =get_var_data (var); + status =get_var_data (entry->efivars, var);if (status !=EFI_SUCCESS )return -EIO ;
@@ -244,7 +244,7 @@ efivar_size_read(struct efivar_entry *entry, char *buf)if (!entry || !buf)return -EINVAL ; - status =get_var_data (var); + status =get_var_data (entry->efivars, var);if (status !=EFI_SUCCESS )return -EIO ;
@@ -261,7 +261,7 @@ efivar_data_read(struct efivar_entry *entry, char *buf)if (!entry || !buf)return -EINVAL ; - status =get_var_data (var); + status =get_var_data (entry->efivars, var);if (status !=EFI_SUCCESS )return -EIO ;
@@ -276,6 +276,7 @@ static ssize_t efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) { struct efi_variable *new_var, *var = &entry->var; +struct efivars *efivars = entry->efivars;efi_status_t status =EFI_NOT_FOUND ;if (count !=sizeof (struct efi_variable ))
@@ -325,7 +326,7 @@ efivar_show_raw(struct efivar_entry *entry, char *buf)if (!entry || !buf)return 0 ; - status =get_var_data (var); + status =get_var_data (entry->efivars, var);if (status !=EFI_SUCCESS )return -EIO ;
@@ -413,6 +414,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, char *buf, loff_t pos, size_t count) {struct efi_variable *new_var = (struct efi_variable *)buf; +struct efivars *efivars = bin_attr->private;struct efivar_entry *search_efivar, *n;unsigned long strsize1, strsize2;efi_status_t status =EFI_NOT_FOUND ;
@@ -459,8 +461,11 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,spin_unlock (&efivars->lock);/* 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); + status =efivar_create_sysfs_entry (efivars, +utf8_strsize (new_var->VariableName, +1024 ), + new_var->VariableName, + &new_var->VendorGuid);if (status) {printk (KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n" ); }
@@ -472,6 +477,7 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, char *buf, loff_t pos, size_t count) {struct efi_variable *del_var = (struct efi_variable *)buf; +struct efivars *efivars = bin_attr->private;struct efivar_entry *search_efivar, *n;unsigned long strsize1, strsize2;efi_status_t status =EFI_NOT_FOUND ;
@@ -580,9 +586,10 @@ static struct kobject *efi_kobj;* Returns 1 on failure, 0 on success */ static int -efivar_create_sysfs_entry (unsigned long variable_name_size, -efi_char16_t *variable_name, -efi_guid_t *vendor_guid) +efivar_create_sysfs_entry (struct efivars *efivars, +unsigned long variable_name_size, +efi_char16_t *variable_name, +efi_guid_t *vendor_guid) {int i, short_name_size = variable_name_size /sizeof (efi_char16_t) +38 ;char *short_name;
@@ -597,6 +604,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,return 1 ; } + new_efivar->efivars = efivars;memcpy (new_efivar->var.VariableName, variable_name, variable_name_size);memcpy (&(new_efivar->var.VendorGuid), vendor_guid,sizeof (efi_guid_t));
@@ -691,6 +699,8 @@ out_free:return error; } +static struct efivars __efivars; +/* * For now we register the efi subsystem with the firmware subsystem * and the vars subsystem with the efi subsystem. In the future, it
@@ -706,6 +716,7 @@ efivars_init(void)efi_guid_t vendor_guid;efi_char16_t *variable_name;unsigned long variable_name_size =1024 ; +struct efivars *efivars = &__efivars;int error =0 ;if (!efi_enabled)
@@ -751,9 +762,10 @@ efivars_init(void) &vendor_guid);switch (status) {case EFI_SUCCESS : -efivar_create_sysfs_entry (variable_name_size, - variable_name, - &vendor_guid); +efivar_create_sysfs_entry (efivars, + variable_name_size, + variable_name, + &vendor_guid);break ;case EFI_NOT_FOUND :break ;
@@ -788,6 +800,7 @@ out_free: static void __exitefivars_exit (void ) { +struct efivars *efivars = &__efivars;struct efivar_entry *entry, *n;list_for_each_entry_safe (entry, n, &efivars->list, list) {
PATCH v2 4/12 efivars: Split out variable registration
In reply to Mike WaychisonIn anticipation of re-using the variable facilities in efivars from elsewhere, split out the registration and unregistration of struct efivars from the rest of the EFI specific sysfs code.
--- drivers/firmware/efivars.c | 122 ++++++++++++++++++++++++-------------------- 1 files changed, 67 insertions(+), 55 deletions(-)
drivers/firmware/efivars.c +67 -55
@@ -95,7 +95,7 @@ struct efivars {* 1) ->list - adds, removals, reads, writes * 2) efi.[gs]et_variable() calls. * It must not be held when creating sysfs entries or calling kmalloc. -* efi.get_next_variable() is only called from efivars_init(), +* efi.get_next_variable() is only called from register_efivars(), * which is protected by the BKL, so that path is safe. */ spinlock_t lock;
@@ -699,54 +699,48 @@ out_free:return error; } -static struct efivars __efivars; +static void unregister_efivars (struct efivars *efivars) +{ +struct efivar_entry *entry, *n; -/* -* For now we register the efi subsystem with the firmware subsystem -* and the vars subsystem with the efi subsystem. In the future, it -* might make sense to split off the efi subsystem into its own -* driver, but for now only efivars will register with it, so just -* include it here. -*/ +list_for_each_entry_safe (entry, n, &efivars->list, list) { +spin_lock (&efivars->lock); +list_del (&entry->list); +spin_unlock (&efivars->lock); +efivar_unregister (entry); + } +if (efivars->new_var) +sysfs_remove_bin_file (&efivars->kset->kobj, efivars->new_var); +if (efivars->del_var) +sysfs_remove_bin_file (&efivars->kset->kobj, efivars->del_var); +kfree (efivars->new_var); +kfree (efivars->del_var); +kset_unregister (efivars->kset); +} -static int __init -efivars_init (void ) +static int register_efivars (struct efivars *efivars, +struct kobject *parent_kobj) {efi_status_t status =EFI_NOT_FOUND ;efi_guid_t vendor_guid;efi_char16_t *variable_name;unsigned long variable_name_size =1024 ; -struct efivars *efivars = &__efivars;int error =0 ; -if (!efi_enabled) -return -ENODEV ; - variable_name =kzalloc (variable_name_size,GFP_KERNEL );if (!variable_name) {printk (KERN_ERR "efivars: Memory allocation failed.\n" );return -ENOMEM ; } -printk (KERN_INFO "EFI Variables Facility v%s %s\n" ,EFIVARS_VERSION , -EFIVARS_DATE ); - -/* For now we'll register the efi directory at /sys/firmware/efi */ - efi_kobj =kobject_create_and_add ("efi" , firmware_kobj); -if (!efi_kobj) { -printk (KERN_ERR "efivars: Firmware registration failed.\n" ); - error = -ENOMEM ; - goto out_free; - } -spin_lock_init (&efivars->lock);INIT_LIST_HEAD (&efivars->list); - efivars->kset =kset_create_and_add ("vars" ,NULL , efi_kobj); + efivars->kset =kset_create_and_add ("vars" ,NULL , parent_kobj);if (!efivars->kset) {printk (KERN_ERR "efivars: Subsystem registration failed.\n" ); error = -ENOMEM ; - goto out_firmware_unregister; + goto out; }/*
@@ -778,21 +772,54 @@ efivars_init(void) }while (status !=EFI_NOT_FOUND ); error =create_efivars_bin_attributes (efivars); - -/* Don't forget the systab entry */ - error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group);if (error) -printk (KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n" , error); -else - goto out_free; +unregister_efivars (efivars); -kset_unregister (efivars->kset); +out: +kfree (variable_name); -out_firmware_unregister: -kobject_put (efi_kobj); +return error; +} -out_free: -kfree (variable_name); +static struct efivars __efivars; + +/* +* For now we register the efi subsystem with the firmware subsystem +* and the vars subsystem with the efi subsystem. In the future, it +* might make sense to split off the efi subsystem into its own +* driver, but for now only efivars will register with it, so just +* include it here. +*/ + +static int __init +efivars_init (void ) +{ +int error =0 ; + +printk (KERN_INFO "EFI Variables Facility v%s %s\n" ,EFIVARS_VERSION , +EFIVARS_DATE ); + +if (!efi_enabled) +return -ENODEV ; + +/* For now we'll register the efi directory at /sys/firmware/efi */ + efi_kobj =kobject_create_and_add ("efi" , firmware_kobj); +if (!efi_kobj) { +printk (KERN_ERR "efivars: Firmware registration failed.\n" ); +return -ENOMEM ; + } + + error =register_efivars (&__efivars, efi_kobj); + +/* Don't forget the systab entry */ + error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group); +if (error) { +printk (KERN_ERR +"efivars: Sysfs attribute export failed with error %d.\n" , + error); +unregister_efivars (&__efivars); +kobject_put (efi_kobj); + }return error; }
@@ -800,22 +827,7 @@ out_free: static void __exitefivars_exit (void ) { -struct efivars *efivars = &__efivars; -struct efivar_entry *entry, *n; - -list_for_each_entry_safe (entry, n, &efivars->list, list) { -spin_lock (&efivars->lock); -list_del (&entry->list); -spin_unlock (&efivars->lock); -efivar_unregister (entry); - } -if (efivars->new_var) -sysfs_remove_bin_file (&efivars->kset->kobj, efivars->new_var); -if (efivars->del_var) -sysfs_remove_bin_file (&efivars->kset->kobj, efivars->del_var); -kfree (efivars->new_var); -kfree (efivars->del_var); -kset_unregister (efivars->kset); +unregister_efivars (&__efivars);kobject_put (efi_kobj); }
PATCH v2 5/12 efivars: Parameterize operations.
In reply to Mike WaychisonInstead of letting efivars access struct efi directly when dealing with variables, use an operations structure. This allows a later change to reuse the efivars logic without having to pretend to support everything in struct efi.
--- drivers/firmware/efivars.c | 61 +++++++++++++++++++++++++++----------------- 1 files changed, 37 insertions(+), 24 deletions(-)
drivers/firmware/efivars.c +37 -24
@@ -89,19 +89,26 @@ MODULE_DESCRIPTION("sysfs interface to EFI Variables");MODULE_LICENSE ("GPL" );MODULE_VERSION (EFIVARS_VERSION ); +struct efivar_operations { +efi_get_variable_t *get_variable; +efi_get_next_variable_t *get_next_variable; +efi_set_variable_t *set_variable; +}; +struct efivars {/* * ->lock protects two things: * 1) ->list - adds, removals, reads, writes -* 2) efi.[gs]et_variable() calls. +* 2) ops.[gs]et_variable() calls. * It must not be held when creating sysfs entries or calling kmalloc. -* efi.get_next_variable() is only called from register_efivars(), +* ops.get_next_variable() is only called from register_efivars(), * which is protected by the BKL, so that path is safe. */ spinlock_t lock;struct list_head list;struct kset *kset;struct bin_attribute *new_var, *del_var; +const struct efivar_operations *ops; };/*
@@ -182,11 +189,11 @@ get_var_data(struct efivars *efivars, struct efi_variable *var)spin_lock (&efivars->lock); var->DataSize =1024 ; - status = efi.get_variable (var->VariableName, - &var->VendorGuid, - &var->Attributes, - &var->DataSize, - var->Data); + status = efivars->ops->get_variable (var->VariableName, + &var->VendorGuid, + &var->Attributes, + &var->DataSize, + var->Data);spin_unlock (&efivars->lock);if (status !=EFI_SUCCESS ) { printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n",
@@ -299,11 +306,11 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) }spin_lock (&efivars->lock); - status = efi.set_variable (new_var->VariableName, - &new_var->VendorGuid, - new_var->Attributes, - new_var->DataSize, - new_var->Data); + status = efivars->ops->set_variable (new_var->VariableName, + &new_var->VendorGuid, + new_var->Attributes, + new_var->DataSize, + new_var->Data);spin_unlock (&efivars->lock);
@@ -446,11 +453,11 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, }/* now *really* create the variable via EFI */ - status = efi.set_variable (new_var->VariableName, - &new_var->VendorGuid, - new_var->Attributes, - new_var->DataSize, - new_var->Data); + status = efivars->ops->set_variable (new_var->VariableName, + &new_var->VendorGuid, + new_var->Attributes, + new_var->DataSize, + new_var->Data);if (status !=EFI_SUCCESS ) { printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
@@ -511,11 +518,11 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, del_var->Attributes =0 ; del_var->DataSize =0 ; - status = efi.set_variable (del_var->VariableName, - &del_var->VendorGuid, - del_var->Attributes, - del_var->DataSize, - del_var->Data); + status = efivars->ops->set_variable (del_var->VariableName, + &del_var->VendorGuid, + del_var->Attributes, + del_var->DataSize, + del_var->Data);if (status !=EFI_SUCCESS ) { printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
@@ -719,6 +726,7 @@ static void unregister_efivars(struct efivars *efivars) }static int register_efivars (struct efivars *efivars, +const struct efivar_operations *ops,struct kobject *parent_kobj) {efi_status_t status =EFI_NOT_FOUND ;
@@ -735,6 +743,7 @@ static int register_efivars(struct efivars *efivars,spin_lock_init (&efivars->lock);INIT_LIST_HEAD (&efivars->list); + efivars->ops = ops; efivars->kset =kset_create_and_add ("vars" ,NULL , parent_kobj);if (!efivars->kset) {
@@ -751,7 +760,7 @@ static int register_efivars(struct efivars *efivars, do { variable_name_size = 1024; - status = efi.get_next_variable(&variable_name_size, + status = ops->get_next_variable(&variable_name_size, variable_name, &vendor_guid); switch (status) {
@@ -782,6 +791,7 @@ out: }static struct efivars __efivars; +static struct efivar_operations ops;/* * For now we register the efi subsystem with the firmware subsystem
@@ -809,7 +819,10 @@ efivars_init(void)return -ENOMEM ; } - error =register_efivars (&__efivars, efi_kobj); + ops.get_variable = efi.get_variable; + ops.set_variable = efi.set_variable; + ops.get_next_variable = efi.get_next_variable; + error =register_efivars (&__efivars, &ops, efi_kobj);/* Don't forget the systab entry */ error =sysfs_create_group (efi_kobj, &efi_subsys_attr_group);
PATCH v2 6/12 efivars: Expose efivars functionality to external drivers.
In reply to Mike Waychison--- drivers/firmware/efivars.c | 34 +++++++--------------------------- include/linux/efi.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 27 deletions(-)
drivers/firmware/efivars.c +7 -27
@@ -89,28 +89,6 @@ MODULE_DESCRIPTION("sysfs interface to EFI Variables");MODULE_LICENSE ("GPL" );MODULE_VERSION (EFIVARS_VERSION ); -struct efivar_operations { -efi_get_variable_t *get_variable; -efi_get_next_variable_t *get_next_variable; -efi_set_variable_t *set_variable; -}; - -struct efivars { -/* -* ->lock protects two things: -* 1) ->list - adds, removals, reads, writes -* 2) ops.[gs]et_variable() calls. -* It must not be held when creating sysfs entries or calling kmalloc. -* ops.get_next_variable() is only called from register_efivars(), -* which is protected by the BKL, so that path is safe. -*/ -spinlock_t lock; -struct list_head list; -struct kset *kset; -struct bin_attribute *new_var, *del_var; -const struct efivar_operations *ops; -}; -/* * The maximum size of VariableName + Data = 1024 * Therefore, it's reasonable to save that much
@@ -706,7 +684,7 @@ out_free:return error; } -static void unregister_efivars (struct efivars *efivars) +void unregister_efivars (struct efivars *efivars) {struct efivar_entry *entry, *n;
@@ -724,10 +702,11 @@ static void unregister_efivars(struct efivars *efivars)kfree (efivars->del_var);kset_unregister (efivars->kset); } +EXPORT_SYMBOL_GPL (unregister_efivars); -static int register_efivars (struct efivars *efivars, -const struct efivar_operations *ops, -struct kobject *parent_kobj) +int register_efivars (struct efivars *efivars, +const struct efivar_operations *ops, +struct kobject *parent_kobj) {efi_status_t status =EFI_NOT_FOUND ;efi_guid_t vendor_guid;
@@ -789,6 +768,7 @@ out:return error; } +EXPORT_SYMBOL_GPL (register_efivars);static struct efivars __efivars;static struct efivar_operations ops;
@@ -810,7 +790,7 @@ efivars_init(void) EFIVARS_DATE);if (!efi_enabled) -return -ENODEV ; +return 0 ;/* For now we'll register the efi directory at /sys/firmware/efi */ efi_kobj =kobject_create_and_add ("efi" , firmware_kobj);
include/linux/efi.h +37 -0
@@ -397,4 +397,41 @@ static inline void memrange_efi_to_native(u64 *addr, u64 *npages) *addr &= PAGE_MASK; } +#if defined(CONFIG_EFI_VARS ) || defined(CONFIG_EFI_VARS_MODULE ) +/* +* EFI Variable support. +* +* Different firmware drivers can expose their EFI-like variables using +* the following. +*/ + +struct efivar_operations { +efi_get_variable_t *get_variable; +efi_get_next_variable_t *get_next_variable; +efi_set_variable_t *set_variable; +}; + +struct efivars { +/* +* ->lock protects two things: +* 1) ->list - adds, removals, reads, writes +* 2) ops.[gs]et_variable() calls. +* It must not be held when creating sysfs entries or calling kmalloc. +* ops.get_next_variable() is only called from register_efivars(), +* which is protected by the BKL, so that path is safe. +*/ +spinlock_t lock; +struct list_head list; +struct kset *kset; +struct bin_attribute *new_var, *del_var; +const struct efivar_operations *ops; +}; + +int register_efivars (struct efivars *efivars, +const struct efivar_operations *ops, +struct kobject *parent_kobj); +void unregister_efivars (struct efivars *efivars); + +#endif /* CONFIG_EFI_VARS */ +#endif /* _LINUX_EFI_H */
PATCH v2 7/12 efivars: Add Documentation
In reply to Mike WaychisonThis patch documents the interface exposed by the 'efivars' module.
--- Documentation/ABI/stable/sysfs-firmware-efi-vars | 75 ++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/stable/sysfs-firmware-efi-vars
Documentation/ABI/stable/sysfs-firmware-efi-vars new file +75 -0
@@ -0,0 +1,75 @@ +What: /sys/firmware/efi/vars +Date: April 2004 +Contact: Matt Domsch <[email protected]> +Description: + This directory exposes interfaces for interactive with + EFI variables. For more information on EFI variables, + see 'Variable Services' in the UEFI specification + (section 7.2 in specification version 2.3 Errata D). + + In summary, EFI variables are named, and are classified + into separate namespaces through the use of a vendor + GUID. They also have an arbitrary binary value + associated with them. + + The efivars module enumerates these variables and + creates a separate directory for each one found. Each + directory has a name of the form "<key>-<vendor guid>" + and contains the following files: + + attributes: A read-only text file enumerating the + EFI variable flags. Potential values + include: + + EFI_VARIABLE_NON_VOLATILE + EFI_VARIABLE_BOOTSERVICE_ACCESS + EFI_VARIABLE_RUNTIME_ACCESS + EFI_VARIABLE_HARDWARE_ERROR_RECORD + EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS + + See the EFI documentation for an + explanation of each of these variables. + + data: A read-only binary file that can be read + to attain the value of the EFI variable + + guid: The vendor GUID of the variable. This + should always match the GUID in the + variable's name. + + raw_var: A binary file that can be read to obtain + a structure that contains everything + there is to know about the variable. + For structure definition see "struct + efi_variable" in the kernel sources. + + This file can also be written to in + order to update the value of a variable. + For this to work however, all fields of + the "struct efi_variable" passed must + match byte for byte with the structure + read out of the file, save for the value + portion. + + **Note** the efi_variable structure + read/written with this file contains a + 'long' type that may change widths + depending on your underlying + architecture. + + size: As ASCII representation of the size of + the variable's value. + + + In addition, two other magic binary files are provided + in the top-level directory and are used for adding and + removing variables: + + new_var: Takes a "struct efi_variable" and + instructs the EFI firmware to create a + new variable. + + del_var: Takes a "struct efi_variable" and + instructs the EFI firmware to remove any + variable that has a matching vendor GUID + and variable key name.
PATCH v2 8/12 x86: get_bios_ebda_length()
In reply to Mike WaychisonAdd a wrapper routine that tells us the length of the EBDA if it is present. This guy also ensures that the returned length doesn't let the EBDA run past the 640KiB mark.
--- arch/x86/include/asm/bios_ebda.h | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
arch/x86/include/asm/bios_ebda.h +21 -0
@@ -14,6 +14,27 @@ static inline unsigned int get_bios_ebda(void)return address;/* 0 means none */ } +/* +* Return the sanitized length of the EBDA in bytes, if it exists. +*/ +static inline unsigned int get_bios_ebda_length (void ) +{ +unsigned int address; +unsigned int length; + + address =get_bios_ebda (); +if (!address) +return 0 ; + +/* EBDA length is byte 0 of the EBDA (stored in KiB) */ + length = *(unsigned char *)phys_to_virt (address); + length <<=10 ; + +/* Trim the length if it extends beyond 640KiB */ + length = min_t(unsigned int, (640 * 1024) - address, length); +return length; +} +void reserve_ebda_region (void );#ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
Re: [PATCH v2 08/12] x86: get_bios_ebda_length()
Quoted 8 lines · Mike Waychison
Add a wrapper routine that tells us the length of the EBDA if it is present. This guy also ensures that the returned length doesn't let the EBDA run past the 640KiB mark.
Signed-off-by Mike Waychison <[email protected]>--- arch/x86/include/asm/bios_ebda.h | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
Any objections from the x86 developers about me including this with the other efi patches in my driver-core-next tree?
thanks,
greg k-h
PATCH v2 9/12 x86: Better comments for get_bios_ebda()
In reply to Mike WaychisonMake the comments a bit clearer for get_bios_ebda so that it actually tells us what it is returning.
--- arch/x86/include/asm/bios_ebda.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/bios_ebda.h +5 -2
@@ -4,11 +4,14 @@#include <asm/io.h> /* -* there is a real-mode segmented pointer pointing to the -* 4K EBDA area at 0x40E. +* Returns physical address of EBDA. Returns 0 if there is no EBDA. */ static inline unsigned int get_bios_ebda (void ) { +/* +* There is a real-mode segmented pointer pointing to the +* 4K EBDA area at 0x40E. +*/ unsigned int address = *(unsigned short *)phys_to_virt (0x40E ); address <<=4 ;return address;/* 0 means none */
Re: [PATCH v2 09/12] x86: Better comments for get_bios_ebda()
Quoted 7 lines · Mike Waychison
Make the comments a bit clearer for
get_bios_ebdaso that it actually tells us what it is returning.Signed-off-by Mike Waychison <[email protected]>--- arch/x86/include/asm/bios_ebda.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
Any objection/acks from the x86 maintainers about me including this in the driver-core-next tree along with the other efi patches?
thanks,
greg k-h
PATCH v2 10/12 Introduce CONFIG_GOOGLE_FIRMWARE
In reply to Mike WaychisonIn order to keep Google's firmware drivers organized amongst themselves, create a new directory for them to live in. As well, all Google firmware drivers are gated on CONFIG_GOOGLE_FIRMWARE=y, which defaults to 'n' in the kernel build.
--- drivers/firmware/Kconfig | 2 ++ drivers/firmware/Makefile | 2 ++ drivers/firmware/google/Kconfig | 14 ++++++++++++++ drivers/firmware/google/Makefile | 1 + 4 files changed, 19 insertions(+), 0 deletions(-) create mode 100644 drivers/firmware/google/Kconfig create mode 100644 drivers/firmware/google/Makefile
drivers/firmware/Kconfig +2 -0
@@ -134,4 +134,6 @@ config ISCSI_IBFT detect iSCSI boot parameters dynamically during system boot, say Y. Otherwise, say N. +source "drivers/firmware/google/Kconfig" + endmenu
drivers/firmware/Makefile +2 -0
@@ -11,3 +11,5 @@ obj-$(CONFIG_DMIID) += dmi-id.o obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o + +obj-$(CONFIG_GOOGLE_FIRMWARE) += google/
drivers/firmware/google/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config GOOGLE_FIRMWARE + bool "Google Firmware Drivers" + depends on X86 + default n + help + These firmware drivers are used by Google's servers. They are + only useful if you are working directly on one of their + proprietary servers or implementing similar firmware + interfaces. If in doubt, say "N". + +menu "Google Firmware Drivers" + depends on GOOGLE_FIRMWARE + +endmenu
drivers/firmware/google/Makefile new file +1 -0
@@ -0,0 +1 @@ +
Re: [PATCH v2 10/12] Introduce CONFIG_GOOGLE_FIRMWARE
Quoted 4 lines · Mike Waychison
In order to keep Google's firmware drivers organized amongst themselves, create a new directory for them to live in. As well, all Google firmware drivers are gated on
CONFIG_GOOGLE_FIRMWARE=y, which defaults to 'n' in the kernel build.
Everything defaults to 'n' in the kernel build system, so this really isn't a big deal :)
Quoted 38 lines
Signed-off-by Mike Waychison <[email protected]>--- drivers/firmware/Kconfig | 2 ++ drivers/firmware/Makefile | 2 ++ drivers/firmware/google/Kconfig | 14 ++++++++++++++ drivers/firmware/google/Makefile | 1 + 4 files changed, 19 insertions(+), 0 deletions(-) create mode 100644 drivers/firmware/google/Kconfig create mode 100644 drivers/firmware/google/Makefiledrivers/firmware/Kconfig +2
-0@@ -134,4 +134,6 @@ config ISCSI_IBFT detect iSCSI boot parameters dynamically during system boot, say Y. Otherwise, say N. +source "drivers/firmware/google/Kconfig" + endmenudrivers/firmware/Makefile +2
-0@@ -11,3 +11,5 @@ obj-$(CONFIG_DMIID) += dmi-id.o obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o + +obj-$(CONFIG_GOOGLE_FIRMWARE) += google/drivers/firmware/google/Kconfig new file +0
-0
drivers/firmware/google/Kconfig line 9
Quoted 9 lines
drivers/firmware/google/Kconfig new file +9
-0@@ -0,0 +1,14 @@ +config GOOGLE_FIRMWARE + bool "Google Firmware Drivers" + depends on X86 + default n + help + These firmware drivers are used by Google's servers. They are + only useful if you are working directly on one of their + proprietary servers or implementing similar firmware + interfaces. If in doubt, say "N".
How about dropping the "or implementing..." part of this sentance, as that leaves a lot open for some people to justify enabling this option for their machines, when it really isn't true at all at this point in time.
thanks,
greg k-h
Re: [PATCH v2 10/12] Introduce CONFIG_GOOGLE_FIRMWARE
Quoted 8 lines · Greg KH
Quoted 4 lines · Mike Waychison
In order to keep Google's firmware drivers organized amongst themselves, create a new directory for them to live in. As well, all Google firmware drivers are gated on
CONFIG_GOOGLE_FIRMWARE=y, which defaults to 'n' in the kernel build.Everything defaults to 'n' in the kernel build system, so this really isn't a big deal :)
Well, I was hoping that we could have options gating on CONFIG_GOOGLE_FIRMWARE, but default to 'y'. This makes our lives a bit easier as it means we have a single switch we need to enable on our side and all the options we care about (presumably all google-specific drivers) get enabled.
If you have strong objections to this, I can flip the default values of the specific config options to 'n' as well though...
Quoted 45 lines
Quoted 45 lines
Signed-off-by Mike Waychison <[email protected]>---
drivers/firmware/Kconfig | 2 ++drivers/firmware/Makefile| 2 ++drivers/firmware/google/Kconfig| 14 ++++++++++++++drivers/firmware/google/Makefile| 1 +4 files changed, 19 insertions(+), 0 deletions(-)create mode 100644
drivers/firmware/google/Kconfigcreate mode 100644drivers/firmware/google/Makefiledrivers/firmware/Kconfig +0
-0@@ -134,4 +134,6 @@ config ISCSI_IBFTdetect iSCSI boot parameters dynamically during system boot, say Y. Otherwise, say N.
drivers/firmware/Kconfig +2
-0+source "drivers/firmware/google/Kconfig" +endmenu
drivers/firmware/Makefile +0
-0@@ -11,3 +11,5 @@ obj-$(CONFIG_DMIID) += dmi-id.oobj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o
drivers/firmware/Makefile +2
-0+ +obj-$(CONFIG_GOOGLE_FIRMWARE) += google/drivers/firmware/google/Kconfig new file +6
-0@@ -0,0 +1,14 @@ +config GOOGLE_FIRMWARE + bool "Google Firmware Drivers" + depends on X86 + default n + help + These firmware drivers are used by Google's servers. They are
Quoted 9 lines
drivers/firmware/google/Kconfig line 9
Quoted 3 lines
drivers/firmware/google/Kconfig new file +3
-0+ only useful if you are working directly on one of their + proprietary servers or implementing similar firmware + interfaces. If in doubt, say "N".How about dropping the "or implementing..." part of this sentance, as that leaves a lot open for some people to justify enabling this option for their machines, when it really isn't true at all at this point in time.
OK.
Re: [PATCH v2 10/12] Introduce CONFIG_GOOGLE_FIRMWARE
Quoted 10 lines · Mike Waychison
Quoted 8 lines · Greg KH
Quoted 4 lines · Mike Waychison
In order to keep Google's firmware drivers organized amongst themselves, create a new directory for them to live in. As well, all Google firmware drivers are gated on
CONFIG_GOOGLE_FIRMWARE=y, which defaults to 'n' in the kernel build.Everything defaults to 'n' in the kernel build system, so this really isn't a big deal :)
Quoted 8 lines
Well, I was hoping that we could have options gating on
CONFIG_GOOGLE_FIRMWARE, but default to 'y'. This makes our lives a bit easier as it means we have a single switch we need to enable on our side and all the options we care about (presumably all google-specific drivers) get enabled.If you have strong objections to this, I can flip the default values of the specific config options to 'n' as well though...
As decreed by Linus and others, all new config options should default to 'n', unless your box is going to blow up into tiny pieces if you don't select it.
thanks,
greg k-h
Re: [PATCH v2 10/12] Introduce CONFIG_GOOGLE_FIRMWARE
Quoted 17 lines · Greg KH
Quoted 16 lines · Mike Waychison
Quoted 8 lines · Greg KH
Quoted 4 lines · Mike Waychison
In order to keep Google's firmware drivers organized amongst themselves, create a new directory for them to live in. As well, all Google firmware drivers are gated on
CONFIG_GOOGLE_FIRMWARE=y, which defaults to 'n' in the kernel build.Everything defaults to 'n' in the kernel build system, so this really isn't a big deal :)
Well, I was hoping that we could have options gating on
CONFIG_GOOGLE_FIRMWARE, but default to 'y'. This makes our lives a bit easier as it means we have a single switch we need to enable on our side and all the options we care about (presumably all google-specific drivers) get enabled.
Quoted 6 lines
Quoted 2 lines
If you have strong objections to this, I can flip the default values of the specific config options to 'n' as well though...
As decreed by Linus and others, all new config options should default to 'n', unless your box is going to blow up into tiny pieces if you don't select it.
Fair enough.
Quoted 5 lines
thanks,
greg k-h
PATCH v2 11/12 driver: Google EFI SMI
In reply to Mike WaychisonThe "gsmi" driver bridges userland with firmware specific routines for accessing hardware.
Currently, this driver only supports NVRAM and eventlog information. Deprecated functions have been removed from the driver, though their op-codes are left in place so that they are not re-used.
This driver works by trampolining into the firmware via the smi_command outlined in the FADT table. Three protocols are used due to various limitations over time, but all are included herein.
---
Changelog:
v2:
- Use ARRAY_SIZE() rather than open coded construct.
- Fix off-by-one in array lookup.
- Removed superfluous memset.
- Removed superfluous variable clear.
- switch from posix integer types to linux kernel integer types.
- Replaced use of dropped oops_notifier_list with die_notifier_list.
- Added dependency on CONFIG_DMI.
- Fixed a bug which crashed the kernel if no DMI tables were found.
- Replace nvram ioctls with efivars interface at /sys/firmware/gsmi/vars.
- Removed NOOP command that is unused.
- Change gsmi_dev to not be statically allocated.
- Removed ioctl interface
- Removed chardev interface
- Removed header as user ABI is all done via sysfs.
- Fix output clobber for firmware call so that we don't clobber the compiler-cached value for 'cmd'.
- Added docs to Documentation/ABI for exposed system call interface.
--- Documentation/ABI/testing/sysfs-firmware-gsmi | 58 ++ drivers/firmware/google/Kconfig | 11 drivers/firmware/google/Makefile | 1 drivers/firmware/google/gsmi.c | 927 +++++++++++++++++++++++++ 4 files changed, 997 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-gsmi create mode 100644 drivers/firmware/google/gsmi.c
Documentation/ABI/testing/sysfs-firmware-gsmi new file +58 -0
@@ -0,0 +1,58 @@ +What: /sys/firmware/gsmi +Date: March 2011 +Contact: Mike Waychison <[email protected]> +Description: + Some servers used internally at Google have firmware + that provides callback functionality via explicit SMI + triggers. Some of the callbacks are similar to those + provided by the EFI runtime services page, but due to + historical reasons this different entry-point has been + used. + + The gsmi driver implements the kernel's abstraction for + these firmware callbacks. Currently, this functionality + is limited to handling the system event log and getting + access to EFI-style variables stored in nvram. + + Layout: + + /sys/firmware/gsmi/vars: + + This directory has the same layout (and + underlying implementation as /sys/firmware/efi/vars. + See Documentation/ABI/*/sysfs-firmware-efi-vars + for more information on how to interact with + this structure. + + /sys/firmware/gsmi/append_to_eventlog - write-only: + + This file takes a binary blob and passes it onto + the firmware to be timestamped and appended to + the system eventlog. The binary format is + interpreted by the firmware and may change from + platform to platform. The only kernel-enforced + requirement is that the blob be prefixed with a + 32bit host-endian type used as part of the + firmware call. + + /sys/firmware/gsmi/clear_config - write-only: + + Writing any value to this file will cause the + entire firmware configuration to be reset to + "factory defaults". Callers should assume that + a reboot is required for the configuration to be + cleared. + + /sys/firmware/gsmi/clear_eventlog - write-only: + + This file is used to clear out a portion/the + whole of the system event log. Values written + should be values between 1 and 100 inclusive (in + ASCII) representing the fraction of the log to + clear. Not all platforms support fractional + clearing though, and this writes to this file + will error out if the firmware doesn't like your + submitted fraction. + + Callers should assume that a reboot is needed + for this operation to complete.
drivers/firmware/google/Kconfig +11 -0
@@ -11,4 +11,15 @@ config GOOGLE_FIRMWARE menu "Google Firmware Drivers" depends on GOOGLE_FIRMWARE +config GOOGLE_SMI + bool "SMI interface for Google platforms" + depends on ACPI && DMI + select EFI_VARS + default y + help + Say Y here if you want to enable SMI callbacks for Google + platforms. This provides an interface for writing to and + clearing the EFI event log and reading and writing NVRAM + variables. + endmenu
drivers/firmware/google/Makefile +1 -0
@@ -1 +1,2 @@ +obj-$(CONFIG_GOOGLE_SMI) += gsmi.o
drivers/firmware/google/gsmi.c new file +927 -0
927 lines not on this page · raw message
Re: [PATCH v2 11/12] driver: Google EFI SMI
Quoted 2 lines · Mike Waychison
The "gsmi" driver bridges userland with firmware specific routines for accessing hardware.
As with the other driver in this series, what keeps this driver from being loaded on hardware that does not support this functionality? If it is loaded, will it cause bad things to happen?
Also, what causes it to be loaded on hardware that needs it? There should be some MODULE_DEVICE_TABLE somewhere in this thing to cause it to be autoloaded?
thanks,
greg k-h
Re: [PATCH v2 11/12] driver: Google EFI SMI
Quoted 7 lines · Greg KH
Quoted 2 lines · Mike Waychison
The "gsmi" driver bridges userland with firmware specific routines for accessing hardware.
As with the other driver in this series, what keeps this driver from being loaded on hardware that does not support this functionality? If it is loaded, will it cause bad things to happen?
gsmi itself is better guarded than the memconsole driver that the x86 maintainers objected to.
It relies on keying off of a couple different strings, looking for "GOOGLE" as either the OEM ID in the FADT table, or "Google, Inc." as the board vendor. We further discriminate whether the driver should load (it doesn't apply to all of our boards) with a couple other checks. See gsmi_system_valid(). I've added a comment to the patch description indicating this for the upcoming v3 send-out.
Quoted 4 lines
Also, what causes it to be loaded on hardware that needs it? There should be some
MODULE_DEVICE_TABLEsomewhere in this thing to cause it to be autoloaded?
I don't know if there is a good way to have this guy autoloaded, but that's probably fine. We will likely compile it in as a built-in or adjust our userland to have the module loaded. We use it on all machines we've been building for the last 4-5 years, and a table of device IDs would just contain a list of a bunch of parts that aren't really google-specific.
Re: [PATCH v2 11/12] driver: Google EFI SMI
Quoted 12 lines · Mike Waychison
Quoted 7 lines · Greg KH
Quoted 2 lines · Mike Waychison
The "gsmi" driver bridges userland with firmware specific routines for accessing hardware.
As with the other driver in this series, what keeps this driver from being loaded on hardware that does not support this functionality? If it is loaded, will it cause bad things to happen?
gsmi itself is better guarded than the memconsole driver that the x86 maintainers objected to.
Quoted 6 lines
It relies on keying off of a couple different strings, looking for "GOOGLE" as either the OEM ID in the FADT table, or "Google, Inc." as the board vendor. We further discriminate whether the driver should load (it doesn't apply to all of our boards) with a couple other checks. See
gsmi_system_valid(). I've added a comment to the patch description indicating this for the upcoming v3 send-out.
Ok, fair enough. I'm guessing that you have tried testing the module by loading it in a machine where this doesn't work?
Quoted 10 lines
Quoted 3 lines
Also, what causes it to be loaded on hardware that needs it? There should be some
MODULE_DEVICE_TABLEsomewhere in this thing to cause it to be autoloaded?I don't know if there is a good way to have this guy autoloaded, but that's probably fine. We will likely compile it in as a built-in or adjust our userland to have the module loaded. We use it on all machines we've been building for the last 4-5 years, and a table of device IDs would just contain a list of a bunch of parts that aren't really google-specific.
What's wrong with using DMI strings? Are there going to be that many different ones of them here?
thanks,
greg k-h
Re: [PATCH v2 11/12] driver: Google EFI SMI
Quoted 34 lines · Greg KH
Quoted 12 lines · Mike Waychison
Quoted 7 lines · Greg KH
Quoted 2 lines · Mike Waychison
The "gsmi" driver bridges userland with firmware specific routines for accessing hardware.
As with the other driver in this series, what keeps this driver from being loaded on hardware that does not support this functionality? If it is loaded, will it cause bad things to happen?
gsmi itself is better guarded than the memconsole driver that the x86 maintainers objected to.
Quoted 6 lines
It relies on keying off of a couple different strings, looking for "GOOGLE" as either the OEM ID in the FADT table, or "Google, Inc." as the board vendor. We further discriminate whether the driver should load (it doesn't apply to all of our boards) with a couple other checks. See
gsmi_system_valid(). I've added a comment to the patch description indicating this for the upcoming v3 send-out.Ok, fair enough. I'm guessing that you have tried testing the module by loading it in a machine where this doesn't work?
Quoted 10 lines
Quoted 3 lines
Also, what causes it to be loaded on hardware that needs it? There should be some
MODULE_DEVICE_TABLEsomewhere in this thing to cause it to be autoloaded?I don't know if there is a good way to have this guy autoloaded, but that's probably fine. We will likely compile it in as a built-in or adjust our userland to have the module loaded. We use it on all machines we've been building for the last 4-5 years, and a table of device IDs would just contain a list of a bunch of parts that aren't really google-specific.
Quoted 2 lines
What's wrong with using DMI strings? Are there going to be that many different ones of them here?
DMI strings would probably work. I totally missed the fact that I could use them for MODULE_DEVICE_TABLE. Let me re-work patch 11 and 12 to use this matching stuff.
Re: [PATCH v2 11/12] driver: Google EFI SMI
In reply to Greg KHQuoted 10 lines
Quoted 7 lines
I don't know if there is a good way to have this guy autoloaded, but that's probably fine. We will likely compile it in as a built-in or adjust our userland to have the module loaded. We use it on all machines we've been building for the last 4-5 years, and a table of device IDs would just contain a list of a bunch of parts that aren't really google-specific.
What's wrong with using DMI strings? Are there going to be that many different ones of them here?
If you've got them in the ACPI tables that's as good as DMI if not better IMHO
PATCH v2 12/12 driver: Google Memory Console
In reply to Mike WaychisonThis patch introduces the 'memconsole' driver.
Our firmware gives us access to an in-memory log of the firmware's
output. This gives us visibility in a data-center of headless machines
as to what the firmware is doing.
The memory console is found by the driver by finding a header block in the EBDA. The buffer is then copied out, and is exported to userland in the file /sys/firmware/log.
---
Changelog:
v2:
- Removed bits that had this driver muck with the kernel's ring dmesg buffer (log_buf).
- Introduced the log as /sys/firmware/log, a binary file that isn't interpreted by the kernel.
- Don't use C99 fixed width types; use kernel fixed width types.
- Added file to Documentation/ABI for /sys/firmware/log
--- Documentation/ABI/testing/sysfs-firmware-log | 7 + drivers/firmware/google/Kconfig | 8 + drivers/firmware/google/Makefile | 1 drivers/firmware/google/memconsole.c | 151 ++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-log create mode 100644 drivers/firmware/google/memconsole.c
Documentation/ABI/testing/sysfs-firmware-log new file +7 -0
@@ -0,0 +1,7 @@ +What: /sys/firmware/log +Date: February 2011 +Contact: Mike Waychison <[email protected]> +Description: + The /sys/firmware/log is a binary file that represents a + read-only copy of the firmware's log if one is + available.
drivers/firmware/google/Kconfig +8 -0
@@ -22,4 +22,12 @@ config GOOGLE_SMI clearing the EFI event log and reading and writing NVRAM variables. +config GOOGLE_MEMCONSOLE + tristate "Firmware Memory Console" + default y + help + This option enables the kernel to search for a firmware log in + the EBDA. If found, this log is prepended to the kernel's + dmesg logs so they are visible to the user. + endmenu
drivers/firmware/google/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_GOOGLE_SMI) += gsmi.o +obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o
drivers/firmware/google/memconsole.c new file +151 -0
151 lines not on this page · raw message
Re: [PATCH v2 12/12] driver: Google Memory Console
Quoted 10 lines · Mike Waychison
This patch introduces the 'memconsole' driver.
Our firmware gives us access to an in-memory log of the firmware's
output. This gives us visibility in a data-center of headless machines
as to what the firmware is doing.The memory console is found by the driver by finding a header block in the EBDA. The buffer is then copied out, and is exported to userland in the file
/sys/firmware/log.
OK, I really don't like this.
All it has is a 32-bit nonrandom signature, no DMI keying or anything else to protect it. This really isn't sufficient.
-hpa
Re: [PATCH v2 12/12] driver: Google Memory Console
"Sufficient" or not, that's how the BIOSes we've got work. We can't retrofit that.
Quoted 19 lines · H. Peter Anvin
Quoted 10 lines · Mike Waychison
This patch introduces the 'memconsole' driver.
Our firmware gives us access to an in-memory log of the firmware's output. This gives us visibility in a data-center of headless machines as to what the firmware is doing.
The memory console is found by the driver by finding a header block in the EBDA. The buffer is then copied out, and is exported to userland in the file
/sys/firmware/log.OK, I really don't like this.
All it has is a 32-bit nonrandom signature, no DMI keying or anything else to protect it. This really isn't sufficient.
-hpa
Re: [PATCH v2 12/12] driver: Google Memory Console
Quoted 2 lines · Tim Hockin
"Sufficient" or not, that's how the BIOSes we've got work. We can't retrofit that.
Uhm... what about, say, a DMI signature?
-hpa
Re: [PATCH v2 12/12] driver: Google Memory Console
Quoted 5 lines · H. Peter Anvin
Quoted 2 lines · Tim Hockin
"Sufficient" or not, that's how the BIOSes we've got work. We can't retrofit that.
Uhm... what about, say, a DMI signature?
Yes - how does the dmidecode output look like on such a box?
Thanks,
Ingo
Re: [PATCH v2 12/12] driver: Google Memory Console
This same BIOS logic is used across a number of Platforms. We could use something like the vendor strings to trigger this code off, I suppose, but ick. It's already in a google/ subdir and wrapped with CONFIG_GOOGLE_MEMCONSOLE.
Quoted 15 lines · Ingo Molnar
Quoted 5 lines · H. Peter Anvin
Quoted 2 lines · Tim Hockin
"Sufficient" or not, that's how the BIOSes we've got work. We can't retrofit that.
Uhm... what about, say, a DMI signature?
Yes - how does the dmidecode output look like on such a box?
Thanks,
Ingo
Re: [PATCH v2 12/12] driver: Google Memory Console
Quoted 2 lines · Tim Hockin
This same BIOS logic is used across a number of Platforms. We could use something like the vendor strings to trigger this code off, [...]
Correct.
Quoted 2 lines
[...] I suppose, but ick. It's already in a google/ subdir and wrapped with
CONFIG_GOOGLE_MEMCONSOLE.
That's not the point though - in this day and age we simply do not add non-generic hacks like that - we've come a long way since the ISA days. The point is to make it safe enough to limit its effects not just to CONFIG_GOOGLE_MEMCONSOLE but also to affected hardware only.
Thanks,
Ingo
Re: [PATCH v2 12/12] driver: Google Memory Console
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Tim Hockin
This same BIOS logic is used across a number of Platforms. We could use something like the vendor strings to trigger this code off, [...]
Correct.
Quoted 7 lines
Quoted 2 lines
[...] I suppose, but ick. It's already in a google/ subdir and wrapped with
CONFIG_GOOGLE_MEMCONSOLE.That's not the point though - in this day and age we simply do not add non-generic hacks like that - we've come a long way since the ISA days. The point is to make it safe enough to limit its effects not just to
CONFIG_GOOGLE_MEMCONSOLEbut also to affected hardware only.
I strongly agree, we can't take this as-is without this type of code added to the driver, sorry.
Thanks,
greg k-h
Re: [PATCH v2 12/12] driver: Google Memory Console
In reply to H. Peter AnvinQuoted 12 lines · H. Peter Anvin
Quoted 10 lines · Mike Waychison
This patch introduces the 'memconsole' driver.
Our firmware gives us access to an in-memory log of the firmware's output. This gives us visibility in a data-center of headless machines as to what the firmware is doing.
The memory console is found by the driver by finding a header block in the EBDA. The buffer is then copied out, and is exported to userland in the file
/sys/firmware/log.
Quoted 4 lines
OK, I really don't like this.
All it has is a 32-bit nonrandom signature, no DMI keying or anything else to protect it. This really isn't sufficient.
Good point. I'll add some DMI strings checks. It *should* be sufficient to just ensure that "Google, Inc." is the board vendor string (though I'll need to run some tests to verify that this covers the boards we care about).
H. Peter Anvin
reviewerRe: [PATCH v2 12/12] driver: Google Memory Console
Quoted 15 lines · Mike Waychison
Quoted 14 lines · H. Peter Anvin
Quoted 10 lines · Mike Waychison
This patch introduces the 'memconsole' driver.
Our firmware gives us access to an in-memory log of the firmware's
output. This gives us visibility in a data-center of headless machines
as to what the firmware is doing.The memory console is found by the driver by finding a header block in the EBDA. The buffer is then copied out, and is exported to userland in the file
/sys/firmware/log.OK, I really don't like this.
Quoted 8 lines
Quoted 2 lines
All it has is a 32-bit nonrandom signature, no DMI keying or anything else to protect it. This really isn't sufficient.
Good point. I'll add some DMI strings checks. It *should* be sufficient to just ensure that "Google, Inc." is the board vendor string (though I'll need to run some tests to verify that this covers the boards we care about).
Sounds good.
-hpa
Quoted 8 lines · Mike Waychison
Patchset summary
================Patches [1 through 6] refactor the 'efivars' module to let the "gsmi" driver in patch [11] re-use the variable functionality.
Patch [7] documents existing 'efivars' functionality that has been present in the tree since 2004.
Very nice work Mike. I can't test the efivars changes for another week or more, but reading it all, looks like a nice cleanup while allowing you to reuse the underlying code.
Thanks,
Matt
Signature · 3 lines
Matt Domsch Technology Strategist Dell | Office of the CTO
Quoted 7 lines · Matt Domsch
Quoted 6 lines · Mike Waychison
Patchset summary
================Patches [1 through 6] refactor the 'efivars' module to let the "gsmi" driver in patch [11] re-use the variable functionality.
Quoted 6 lines
Quoted 2 lines
Patch [7] documents existing 'efivars' functionality that has been present in the tree since 2004.
Very nice work Mike. I can't test the efivars changes for another week or more, but reading it all, looks like a nice cleanup while allowing you to reuse the underlying code.
I agree, I've applied these 7 patches to my tree for merging with Linus in .39.
I'll wait on the other 5 as I need acks from others to apply them.
thanks,
greg k-h