add SMBIOS tables to sysfs
PATCH 1/1 add SMBIOS tables to sysfs
Andrew,
Below is a short patch to add SMBIOS data to sysfs. It it against latest
bitkeeper 2.6.6-rc (specifically, it applies after the efivars patch that recently went in) but should apply to any recent kernel with only minor reject on drivers/firmware/Makefile. A version for 2.4 (using /proc) will follow tomorrow.
--Rationale-- In the past, systems management applications that wanted to parse the
SMBIOS tables used the /dev/mem interface to directly read the table header + data from physical memory. The spec says that the table header (sometimes referred to as the table entry point) should be somewhere in memory between 0xF0000 and 0xFFFFF. The table header contains a 32-bit pointer to the table proper. Up until this point, most BIOS implementations put the actual table in F-block as well.
This is changing. Many systems want to do dynamic SMBIOS tables, and some
systems are running out of memory in F-block to store the table. On these systems, the actual SMBIOS table is typically in high memory somewhere in an E820 reserved section. The normal /dev/mem driver will not allow access to these regions.
Next, in Red Hat 2.6 kernels, the /dev/mem interface has been restricted
so that it will only allow access to the first 1MB of RAM for security purposes.
And last, access to /dev/mem is allowed only to users with CAP_SYS_RAWIO.
So, to get around these restrictions here is a small SMBIOS driver that
presents existing SMBIOS information as files in sysfs. It creates /sys/firmware/smbios/smbios/table_entry_point, and /sys/firmware/smbios/smbios/table. These files are binary-mode files that contain the raw contents of the table entry point and table, respectively. These files can easily be parsed by userspace apps.
--
Michael Brown
# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/04/27 20:27:21-05:00 [email protected]
# Add sysfs driver to present SMBIOS data
#
# drivers/firmware/smbios.h # 2004/04/27 20:25:16-05:00 [email protected] +53 -0 # # drivers/firmware/smbios.h # 2004/04/27 20:25:16-05:00 [email protected] +0 -0 # BitKeeper file /home/michael_e_brown/kernel/bk/subtrees/smbios-driver-work2/drivers/firmware/smbios.h # # drivers/firmware/smbios.c # 2004/04/27 20:25:15-05:00 [email protected] +266 -0 # # drivers/firmware/smbios.c # 2004/04/27 20:25:15-05:00 [email protected] +0 -0 # BitKeeper file /home/michael_e_brown/kernel/bk/subtrees/smbios-driver-work2/drivers/firmware/smbios.c # # drivers/firmware/Makefile # 2004/04/27 20:25:15-05:00 [email protected] +1 -0 # add SMBIOS to build system # # drivers/firmware/Kconfig # 2004/04/27 20:25:15-05:00 [email protected] +8 -0 # Add SMBIOS sysfs config option # diff -Nru a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig --- a/drivers/firmware/Kconfig Tue Apr 27 20:28:39 2004 +++ b/drivers/firmware/Kconfig Tue Apr 27 20:28:39 2004 @@ -34,4 +34,12 @@ Subsequent efibootmgr releases may be found at: http://linux.dell.com/efibootmgr
+config SMBIOS
+ tristate "BIOS SMBIOS table access driver."
+ help
+ Say Y or M here if you want to enable access to the SMBIOS table + via driverfs. It exposes /sys/firmware/smbios/ subdirectory tree + containing a binary dump of the SMBIOS table header as well as the SMBIOS + table.
+
endmenu
drivers/firmware/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o +obj-$(CONFIG_SMBIOS) += smbios.o
drivers/firmware/smbios.c new file +266 -0
266 lines not on this page · raw message
drivers/firmware/smbios.h new file +53 -0
53 lines not on this page · raw message
Quoted 6 lines · Michael Brown
Andrew,
Below is a short patch to add SMBIOS data to sysfs. It it against latest
bitkeeper 2.6.6-rc (specifically, it applies after the efivars patch that recently went in) but should apply to any recent kernel with only minor reject ondrivers/firmware/Makefile. A version for 2.4 (using /proc) will follow tomorrow.
Nice idea and patch. A few minor comments:
Quoted 2 lines
/sys/firmware/smbios/smbios/table_entry_point/sys/firmware/smbios/smbios/table
Why repeat the "smbios" directory? Is this a limitation in the sysfs interface right now? Or are you going to put more files in the main smbios directory some day?
drivers/firmware/smbios.c line 223
Quoted 1 line
drivers/firmware/smbios.c new file +1
-0+snprintf (sdev->kobj.name,7 ,"smbios" );
Try using kobject_set_name() instead, it will do the proper thing if the string is bigger than the base kobj.name field.
thanks,
greg k-h
Quoted 1 line · Greg KH
Nice idea and patch. A few minor comments:
Thank you.
Quoted 9 lines
Quoted 3 lines
/sys/firmware/smbios/smbios/table_entry_point/sys/firmware/smbios/smbios/tableWhy repeat the "smbios" directory? Is this a limitation in the sysfs interface right now? Or are you going to put more files in the main smbios directory some day?
From what I could tell (please correct me if I am wrong), you can add
only subsystems to the firmware directory. The first "smbios" is for the subsystem. Then, you can only add devices to the subsystem. The second "smbios" is for the device.
I really would like to get rid of one myself, but it was not obvious to me how to do this. No, I do not plan on adding new objects in there.
Quoted 5 lines
drivers/firmware/smbios.c line 223
Quoted 2 lines
drivers/firmware/smbios.c new file +1
-0+snprintf (sdev->kobj.name,7 ,"smbios" );Try using
kobject_set_name()instead, it will do the proper thing if the string is bigger than the base kobj.name field.
Ok, thanks.
Thanks,
Michael
Quoted 9 lines · Michael Brown
Quoted 7 lines · Greg KH
Quoted 3 lines
/sys/firmware/smbios/smbios/table_entry_point/sys/firmware/smbios/smbios/tableWhy repeat the "smbios" directory? Is this a limitation in the sysfs interface right now? Or are you going to put more files in the main smbios directory some day?
Quoted 7 lines
Quoted 1 line
From what I could tell (please correct me if I am wrong), you can add
only subsystems to the firmware directory. The first "smbios" is for the subsystem. Then, you can only add devices to the subsystem. The second "smbios" is for the device.
I really would like to get rid of one myself, but it was not obvious to me how to do this. No, I do not plan on adding new objects in there.
Ok, here are 2 patches. The first small one is on top of your latest version. It gets rid of the extra subdirectory, and removes the unneeded kobject from your static structure (NEVER USE A KOBJECT IN A STATIC STRUCTURE!!!!)
The secone one is against a clean 2.6.6-rc3 kernel that has your latest version + my changes.
If you approve of my changes, I'd be glad to add the driver to my bk trees to have it show up in the next -mm release, and I will push it off to Linus after 2.6.6 is out. Sound ok?
thanks,
greg k-h
----------------------------------
# My cleanups to the smbios driver.
drivers/firmware/smbios.c +13 -31
@@ -10,9 +10,9 @@* * This code takes information provided by SMBIOS tables * and presents it in sysfs as: -* /sys/firmware/smbios/smbios -* |--> /table_entry_point -* |--> /table +* /sys/firmware/smbios +* |--> /table_entry_point +* |--> /table * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License v2.0 as published by
@@ -42,7 +42,6 @@struct smbios_device {struct smbios_table_entry_point table_eps;unsigned int smbios_table_real_length; -struct kobject kobj; };/* there shall be only one */
@@ -143,7 +142,7 @@ smbios_read_table_entry_point(struct kobject *kobj, char *buffer, loff_t pos, size_t size) { - struct smbios_device *sdev = to_smbios_device(kobj); + struct smbios_device *sdev = &the_smbios_device;const char *p = (const char *)&(sdev->table_eps);unsigned int count = size > sizeof(sdev->table_eps) ?
@@ -156,7 +155,7 @@ smbios_read_table(struct kobject *kobj, char *buffer, loff_t pos, size_t size) { - struct smbios_device *sdev = to_smbios_device(kobj); + struct smbios_device *sdev = &the_smbios_device;u8 *buf;unsigned int count = sdev->smbios_table_real_length - pos;int i =0 ;
@@ -204,30 +203,16 @@ static decl_subsys(smbios,&ktype_smbios,NULL); -static inline void -smbios_device_unregister (struct smbios_device *sdev) +static void smbios_device_unregister (void ) { -sysfs_remove_bin_file (&sdev->kobj, &tep_attr ); -sysfs_remove_bin_file (&sdev->kobj, &table_attr ); -kobject_unregister (&sdev->kobj); +sysfs_remove_bin_file (&smbios_subsys.kset.kobj, &tep_attr ); +sysfs_remove_bin_file (&smbios_subsys.kset.kobj, &table_attr ); } -static int -smbios_device_register (struct smbios_device *sdev) +static void __init smbios_device_register (void ) { -int error; - -if (!sdev) -return 1 ; - -kobject_set_name (&sdev->kobj,"smbios" ); -kobj_set_kset_s (sdev,smbios_subsys); - error =kobject_register (&sdev->kobj); -if (!error){ -sysfs_create_bin_file (&sdev->kobj, &tep_attr ); -sysfs_create_bin_file (&sdev->kobj, &table_attr ); - } -return error; +sysfs_create_bin_file (&smbios_subsys.kset.kobj, &tep_attr ); +sysfs_create_bin_file (&smbios_subsys.kset.kobj, &table_attr ); } static int __init
@@ -247,10 +232,7 @@if (rc)return rc; - rc =smbios_device_register (&the_smbios_device); - -if (rc) -firmware_unregister (&smbios_subsys); +smbios_device_register ();return rc; }
@@ -258,7 +240,7 @@ static void __exitsmbios_exit (void ) { -smbios_device_unregister (&the_smbios_device); +smbios_device_unregister ();firmware_unregister (&smbios_subsys); }
----------------------------------
# Whole smbios driver with my cleanup in it.
drivers/firmware/Kconfig +8 -0
@@ -34,4 +34,12 @@ Subsequent efibootmgr releases may be found at: http://linux.dell.com/efibootmgr +config SMBIOS + tristate "BIOS SMBIOS table access driver." + help + Say Y or M here if you want to enable access to the SMBIOS table + via driverfs. It exposes /sys/firmware/smbios/ subdirectory tree + containing a binary dump of the SMBIOS table header as well as the SMBIOS + table. + endmenu
drivers/firmware/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o +obj-$(CONFIG_SMBIOS) += smbios.o
drivers/firmware/smbios.c new file +248 -0
248 lines not on this page · raw message
drivers/firmware/smbios.h new file +53 -0
53 lines not on this page · raw message
Quoted 4 lines · Greg KH
drivers/firmware/smbios.c line 223
Quoted 1 line
drivers/firmware/smbios.c new file +1
-0+snprintf (sdev->kobj.name,7 ,"smbios" );Try using
kobject_set_name()instead, it will do the proper thing if the string is bigger than the base kobj.name field.
Looks like this API was added in Aug03. A quick grep through the tree shows only <10 users. Are there patches pending to convert others, or are you just having new stuff do this? I know of at least one sysfs driver (edd) that uses snprintf() that could be converted. I'll send an updated patch shortly for smbios.c, just curious.
--
Michael
Quoted 9 lines · Michael Brown
Quoted 4 lines · Greg KH
drivers/firmware/smbios.c line 223
Quoted 1 line
drivers/firmware/smbios.c new file +1
-0+snprintf (sdev->kobj.name,7 ,"smbios" );Try using
kobject_set_name()instead, it will do the proper thing if the string is bigger than the base kobj.name field.Looks like this API was added in Aug03. A quick grep through the tree shows only <10 users. Are there patches pending to convert others, or are you just having new stuff do this?
New stuff should use it, and if you want to convert any current code to also use it, please feel free to, I'll gladly take those patches.
thanks,
greg k-h
Re: [BK PATCH] add SMBIOS tables to sysfs -- UPDATED
In reply to Greg KHQuoted 4 lines · Greg KH
Review
Quoted 1 line
(quoted diff) +1
-0+ snprintf(sdev->kobj.name, 7, "smbios" );Try using
kobject_set_name()instead, it will do the proper thing if the string is bigger than the base kobj.name field.
Updated per Greg's comments. One other change, I fixed up a cut and paste error in the copyright line, no code affected.
built and run tested ok.
--
Michael
# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/04/27 23:29:00-05:00 [email protected]
# Add driver to present SMBIOS data in sysfs.
#
# drivers/firmware/smbios.h # 2004/04/27 23:26:57-05:00 [email protected] +53 -0 # # drivers/firmware/smbios.h # 2004/04/27 23:26:57-05:00 [email protected] +0 -0 # BitKeeper file /home/michael_e_brown/kernel/bk/subtrees/smbios-driver-work-fb/drivers/firmware/smbios.h # # drivers/firmware/smbios.c # 2004/04/27 23:26:56-05:00 [email protected] +266 -0 # # drivers/firmware/smbios.c # 2004/04/27 23:26:56-05:00 [email protected] +0 -0 # BitKeeper file /home/michael_e_brown/kernel/bk/subtrees/smbios-driver-work-fb/drivers/firmware/smbios.c # # drivers/firmware/Makefile # 2004/04/27 23:26:56-05:00 [email protected] +1 -0 # add SMBIOS sysfs driver to build system # # drivers/firmware/Kconfig # 2004/04/27 23:26:56-05:00 [email protected] +8 -0 # Add SMBIOS sysfs config option # diff -Nru a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig --- a/drivers/firmware/Kconfig Tue Apr 27 23:30:02 2004 +++ b/drivers/firmware/Kconfig Tue Apr 27 23:30:02 2004 @@ -34,4 +34,12 @@ Subsequent efibootmgr releases may be found at: http://linux.dell.com/efibootmgr
+config SMBIOS
+ tristate "BIOS SMBIOS table access driver."
+ help
+ Say Y or M here if you want to enable access to the SMBIOS table + via driverfs. It exposes /sys/firmware/smbios/ subdirectory tree + containing a binary dump of the SMBIOS table header as well as the SMBIOS + table.
+
endmenu
drivers/firmware/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o +obj-$(CONFIG_SMBIOS) += smbios.o
drivers/firmware/smbios.c new file +266 -0
266 lines not on this page · raw message
drivers/firmware/smbios.h new file +53 -0
53 lines not on this page · raw message