Exporting DMI entries via sysfs
Subsystems (2)
v2 cover Exporting DMI entries via sysfs
This patchset applies to v2.6.38-rc6.
The following series exports information the DMI / SMBIOS tables via sysfs under the path /sys/firmware/dmi.
For our purposes, we actively use the System Event Log, as described by DMI entry Type 15. Currently, we have to grub around /dev/mem to find this thing, and potentially need to issue IOs directly from userland to get at the event log, which is suboptimal in terms of security and architecture.
This series implements the basics needed to iterate through the DMI entries safely from userland. Each entry has the handle, the formatted length and the raw bytes exposed in their own sub-directory under /sys/firmware/dmi/entries/<type>-<instance>.
As well, this series explodes type 15 as a proof-of-concept of how we can expose kernel interpretations of the entry data. For most entries, there isn't much sense in parsing the entry and exposing each field as a sysfs attribute as they can be interpreted from userland by accessing the raw entry itself. Type 15 however describes an indirection (pointing at the system event log), and it is generally useful to export this log in raw form to the user (which requires interpreting the DMI entry).
This driver relies solely on dmi_walk() for access to the dmi entries. They are not kept mapped in the "rest" state. The only bits memo-ized by the objects in sysfs are the dmi headers, which are used to the find
the entries via dmi_walk on read. Reading the raw bytes however is
'uncached' by this driver, so that any changes to the entries themselves are reflected properly by the user-exposed interface.
We intend to use this on our production servers, though it seems to also be sufficient in suiting Chrome OS's needs
(http://code.google.com/p/chromium-os/issues/detail?id=6795).
Thanks,
Mike Waychison
Related discussions
===================
- Andi Kleen suggesting that perhaps this data could be exported via sysfs:
http://kerneltrap.org/mailarchive/linux-kernel/2010/9/28/4625643/thread
- Tim Hockin suggesting a potential layout:
https://lkml.org/lkml/2011/2/10/550
Patchset summary
================
firmware: Add DMI entry types to the headers
firmware: Basic dmi-sysfs support
firmware: Break out system_event_log in dmi-sysfs
firmware: Expose DMI type 15 System Event Log
firmware: Add documentation for /sys/firmware/dmi
Diffstat
========
Documentation/ABI/testing/sysfs-firmware-dmi | 110 ++++ drivers/firmware/Kconfig | 11 drivers/firmware/Makefile | 1 drivers/firmware/dmi-sysfs.c | 698 +++++++++++++++++++++++++++ include/linux/dmi.h | 47 + 5 files changed, 867 insertions(+)
Changelog:
==========
- v2
- Added 'type', 'instance' and 'position' attributes to each DMI entry.
- Don't printk KERN_INFO on module load/unload.
- Default to 'n' for Kconfig.
- Grammar fixes.
- Fixed bug reading raw files when multiple instances of the same type exist.
- v1
- Initial public send-out.
PATCH v2 1/5 firmware: Add DMI entry types to the headers
In preparation for the upcoming commits, introduce the DMI entry types to the headers. These type names are based on those specified in the DMTF SMBIOS specification version 2.7.1.
--- include/linux/dmi.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-)
include/linux/dmi.h +47 -0
@@ -23,6 +23,53 @@ enum dmi_device_type { DMI_DEV_TYPE_DEV_ONBOARD = -3, }; +enum dmi_entry_type { +DMI_ENTRY_BIOS =0 , +DMI_ENTRY_SYSTEM , +DMI_ENTRY_BASEBOARD , +DMI_ENTRY_CHASSIS , +DMI_ENTRY_PROCESSOR , +DMI_ENTRY_MEM_CONTROLLER , +DMI_ENTRY_MEM_MODULE , +DMI_ENTRY_CACHE , +DMI_ENTRY_PORT_CONNECTOR , +DMI_ENTRY_SYSTEM_SLOT , +DMI_ENTRY_ONBOARD_DEVICE , +DMI_ENTRY_OEMSTRINGS , +DMI_ENTRY_SYSCONF , +DMI_ENTRY_BIOS_LANG , +DMI_ENTRY_GROUP_ASSOC , +DMI_ENTRY_SYSTEM_EVENT_LOG , +DMI_ENTRY_PHYS_MEM_ARRAY , +DMI_ENTRY_MEM_DEVICE , +DMI_ENTRY_32_MEM_ERROR , +DMI_ENTRY_MEM_ARRAY_MAPPED_ADDR , +DMI_ENTRY_MEM_DEV_MAPPED_ADDR , +DMI_ENTRY_BUILTIN_POINTING_DEV , +DMI_ENTRY_PORTABLE_BATTERY , +DMI_ENTRY_SYSTEM_RESET , +DMI_ENTRY_HW_SECURITY , +DMI_ENTRY_SYSTEM_POWER_CONTROLS , +DMI_ENTRY_VOLTAGE_PROBE , +DMI_ENTRY_COOLING_DEV , +DMI_ENTRY_TEMP_PROBE , +DMI_ENTRY_ELECTRICAL_CURRENT_PROBE , +DMI_ENTRY_OOB_REMOTE_ACCESS , +DMI_ENTRY_BIS_ENTRY , +DMI_ENTRY_SYSTEM_BOOT , +DMI_ENTRY_MGMT_DEV , +DMI_ENTRY_MGMT_DEV_COMPONENT , +DMI_ENTRY_MGMT_DEV_THRES , +DMI_ENTRY_MEM_CHANNEL , +DMI_ENTRY_IPMI_DEV , +DMI_ENTRY_SYS_POWER_SUPPLY , +DMI_ENTRY_ADDITIONAL , +DMI_ENTRY_ONBOARD_DEV_EXT , +DMI_ENTRY_MGMT_CONTROLLER_HOST , +DMI_ENTRY_INACTIVE =126 , +DMI_ENTRY_END_OF_TABLE =127 , +}; +struct dmi_header {u8 type;u8 length;
PATCH v2 2/5 firmware: Basic dmi-sysfs support
In reply to Mike WaychisonIntroduce a new module "dmi-sysfs" that exports the broken out entries of the DMI table through sysfs.
Entries are enumerated via dmi_walk() on module load, and are populated as kobjects rooted at /sys/firmware/dmi/entries.
Entries are named "<type>-<instance>", where:
<type> : is the type of the entry, and
<instance> : is the ordinal count within the DMI table of that
entry type. This instance is used in lieu the DMI entry's handle as no assurances are made by the kernel that handles are unique.
All entries export the following attributes:
length : The length of the formatted portion of the entry
handle : The handle given to this entry by the firmware
raw : The raw bytes of the entire entry, including the
formatted portion, the unformatted (strings) portion, and the two terminating nul characters.
type : The DMI entry type
instance : The ordinal instance of this entry given its type.
position : The position ordinal of the entry within the table in
its entirety.
Entries in dmi-sysfs are kobject backed members called "struct dmi_sysfs_entry" and belong to dmi_kset. They are threaded through entry_list (protected by entry_list_lock) so that we can find them at cleanup time.
---
Changelog:
- v2
- Added 'type', 'instance' and 'position' attributes to each DMI entry.
- Fixed module to default to 'n'.
- Fixed copyright year and module author.
- Replace module load/unload messages with pr_debug().
- Fixed a bug in handling multiple instance of the same type where reading the raw file for earlier instances would result in 0 bytes read due to the instance_count getting stuck at '0'.
--- drivers/firmware/Kconfig | 11 + drivers/firmware/Makefile | 1 drivers/firmware/dmi-sysfs.c | 396 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 408 insertions(+), 0 deletions(-) create mode 100644 drivers/firmware/dmi-sysfs.c
drivers/firmware/Kconfig +11 -0
@@ -113,6 +113,17 @@ config DMIID information from userspace through /sys/class/dmi/id/ or if you want DMI-based module auto-loading. +config DMI_SYSFS + tristate "DMI table support in sysfs" + depends on SYSFS && DMI + default n + help + Say Y or M here to enable the exporting of the raw DMI table + data via sysfs. This is useful for consuming the data without + requiring any access to /dev/mem at all. Tables are found + under /sys/firmware/dmi when this option is enabled and + loaded. + config ISCSI_IBFT_FIND bool "iSCSI Boot Firmware Table Attributes" depends on X86
drivers/firmware/Makefile +1 -0
@@ -2,6 +2,7 @@ # Makefile for the linux kernel. # obj-$(CONFIG_DMI) += dmi_scan.o +obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o obj-$(CONFIG_EDD) += edd.o obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_PCDP) += pcdp.o
drivers/firmware/dmi-sysfs.c new file +396 -0
396 lines not on this page · raw message
Re: [PATCH v2 2/5] firmware: Basic dmi-sysfs support
drivers/firmware/dmi-sysfs.c line 294
Quoted 3 lines · Mike Waychison
drivers/firmware/dmi-sysfs.c new file +3
-0+static void __init dmi_sysfs_register_handle (const struct dmi_header *dh, + void *_ret) +{
I'm seeing some unaligned references from this function on ia64. Code is loading a 2-byte value from an odd address. We are dereferencing "dh", so looking at the dmi_header definition, I'd have thought that we must be touching dh->handle:
struct dmi_header {
u8 type;
u8 length;
u16 handle;
};I don't see any code in this function that does this, so I assume there is some inlining or macro stuff happening.
-Tony
Re: [PATCH v2 2/5] firmware: Basic dmi-sysfs support
Quoted 17 lines · Tony Luck
drivers/firmware/dmi-sysfs.c line 294
Quoted 3 lines · Mike Waychison
drivers/firmware/dmi-sysfs.c new file +3
-0+static void __init dmi_sysfs_register_handle (const struct dmi_header *dh, + void *_ret) +{I'm seeing some unaligned references from this function on ia64. Code is loading a 2-byte value from an odd address. We are dereferencing "dh", so looking at the
dmi_headerdefinition, I'd have thought that we must be touchingdh->handle:struct
dmi_header{
u8 type;
u8 length;
u16 handle;
};
Quoted 3 lines
I don't see any code in this function that does this, so I assume there is some inlining or macro stuff happening.
Ya, I don't think there is anything that guarantees that dmi_header is
aligned. The access is probably the struct copy I did here:
/* Set the key */
entry->dh = *dh;What if we changed that guy to use memcpy? We'd probably need to memcpy the dmi_system_event_log as well. Patch attached (applies on top of the entire patchset).
Tony Luck
Tested-byRe: [PATCH v2 2/5] firmware: Basic dmi-sysfs support
Quoted 5 lines · Mike Waychison
Ya, I don't think there is anything that guarantees that
dmi_headeris aligned. The access is probably the struct copy I did here:/* Set the key */
entry->dh = *dh;
Yup - looking back at the assembly I see that one of the 2-byte accesses is offset 2
(picking up ->handle), but the second is offset 0 (picking up ->type and ->length). The
compiler assumed the structure was 2-byte aligned because of ->handle.
Quoted 3 lines
What if we changed that guy to use memcpy? We'd probably need to memcpy the
dmi_system_event_logas well. Patch attached (applies on top of the entire patchset).
With the patch, all the unaligned accesses go away.
-Tony
Re: [PATCH v2 2/5] firmware: Basic dmi-sysfs support
Quoted 13 lines · Tony Luck
Quoted 5 lines · Mike Waychison
Ya, I don't think there is anything that guarantees that
dmi_headeris aligned. The access is probably the struct copy I did here:/* Set the key */
entry->dh = *dh;Yup - looking back at the assembly I see that one of the 2-byte accesses is offset 2
(picking up ->handle), but the second is offset 0 (picking up ->type and ->length). The
compiler assumed the structure was 2-byte aligned because of ->handle.
Quoted 7 lines
Quoted 3 lines
What if we changed that guy to use memcpy? We'd probably need to memcpy the
dmi_system_event_logas well. Patch attached (applies on top of the entire patchset).With the patch, all the unaligned accesses go away.
Tested-by Tony Luck <[email protected]>
Great!
Mike, care to resend this last patch as a 6/5 patch with a proper subject, changelog comment, and signed-off-by: section so that I can queue it up?
thanks,
greg k-h
PATCH v2 3/5 firmware: Break out system_event_log in dmi-sysfs
In reply to Mike WaychisonThe optional type 15 entry of the DMI table describes a non-volatile storage-backed system event log.
In preparation for the next commit which exposes the raw bits of the event log to userland, create a new sub-directory within the dmi entry called "system_event_log" and expose attribute files that describe the event log itself.
Currently, only a single child object is permitted within a dmi_sysfs_entry. We simply point at this child from the dmi_sysfs_entry if it exists.
--- drivers/firmware/dmi-sysfs.c | 159 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 159 insertions(+), 0 deletions(-)
drivers/firmware/dmi-sysfs.c +159 -0
@@ -35,6 +35,7 @@ struct dmi_sysfs_entry {int instance;int position;struct list_head list; +struct kobject *child; };/*
@@ -77,6 +78,10 @@ struct dmi_sysfs_mapped_attribute dmi_sysfs_attr_##_entry##_##_name = { \/************************************************* * Generic DMI entry support. *************************************************/ +static void dmi_entry_free (struct kobject *kobj) +{ +kfree (kobj); +}static struct dmi_sysfs_entry *to_entry (struct kobject *kobj) {
@@ -186,6 +191,146 @@ static size_t dmi_entry_length(const struct dmi_header *dh) }/************************************************* +* Support bits for specialized DMI entry support +*************************************************/ +struct dmi_entry_attr_show_data { +struct attribute *attr; +char *buf; +}; + +static ssize_t dmi_entry_attr_show_helper (struct dmi_sysfs_entry *entry, +const struct dmi_header *dh, +void *_data) +{ +struct dmi_entry_attr_show_data *data = _data; +struct dmi_sysfs_mapped_attribute *attr; + + attr =container_of (data->attr, + struct dmi_sysfs_mapped_attribute, attr); +return attr->show (entry, dh, data->buf); +} + +static ssize_t dmi_entry_attr_show (struct kobject *kobj, +struct attribute *attr, +char *buf) +{ +struct dmi_entry_attr_show_data data = { + .attr = attr, + .buf = buf, + }; +/* Find the entry according to our parent and call the +* normalized show method hanging off of the attribute */ +return find_dmi_entry (to_entry (kobj->parent), + dmi_entry_attr_show_helper, &data); +} + +static const struct sysfs_ops dmi_sysfs_specialize_attr_ops = { + .show = dmi_entry_attr_show, +}; + +/************************************************* +* Specialized DMI entry support. +*************************************************/ + +/*** Type 15 - System Event Table ***/ + +#define DMI_SEL_ACCESS_METHOD_IO8 0x00 +#define DMI_SEL_ACCESS_METHOD_IO2x8 0x01 +#define DMI_SEL_ACCESS_METHOD_IO16 0x02 +#define DMI_SEL_ACCESS_METHOD_PHYS32 0x03 +#define DMI_SEL_ACCESS_METHOD_GPNV 0x04 + +struct dmi_system_event_log { +struct dmi_header header; +u16 area_length; +u16 header_start_offset; +u16 data_start_offset; +u8 access_method; +u8 status; +u32 change_token; +union { +struct { +u16 index_addr; +u16 data_addr; + } io; +u32 phys_addr32; +u16 gpnv_handle; +u32 access_method_address; + }; +u8 header_format; +u8 type_descriptors_supported_count; +u8 per_log_type_descriptor_length; +u8 supported_log_type_descriptos[0 ]; +} __packed; + +static const struct dmi_system_event_log *to_sel (const struct dmi_header *dh) +{ +return (const struct dmi_system_event_log *)dh; +} + +#define DMI_SYSFS_SEL_FIELD (_field) \ +static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \ + const struct dmi_header *dh, \ + char *buf) \ +{ \ + const struct dmi_system_event_log *sel = to_sel(dh); \ + if (sizeof(*sel) > dmi_entry_length(dh)) \ + return -EIO; \ + return sprintf(buf, "%u\n", sel->_field); \ +} \ +static DMI_SYSFS_MAPPED_ATTR(sel, _field) + +DMI_SYSFS_SEL_FIELD (area_length); +DMI_SYSFS_SEL_FIELD (header_start_offset); +DMI_SYSFS_SEL_FIELD (data_start_offset); +DMI_SYSFS_SEL_FIELD (access_method); +DMI_SYSFS_SEL_FIELD (status); +DMI_SYSFS_SEL_FIELD (change_token); +DMI_SYSFS_SEL_FIELD (access_method_address); +DMI_SYSFS_SEL_FIELD (header_format); +DMI_SYSFS_SEL_FIELD (type_descriptors_supported_count); +DMI_SYSFS_SEL_FIELD (per_log_type_descriptor_length); + +static struct attribute *dmi_sysfs_sel_attrs[] = { + &dmi_sysfs_attr_sel_area_length.attr, + &dmi_sysfs_attr_sel_header_start_offset.attr, + &dmi_sysfs_attr_sel_data_start_offset.attr, + &dmi_sysfs_attr_sel_access_method.attr, + &dmi_sysfs_attr_sel_status.attr, + &dmi_sysfs_attr_sel_change_token.attr, + &dmi_sysfs_attr_sel_access_method_address.attr, + &dmi_sysfs_attr_sel_header_format.attr, + &dmi_sysfs_attr_sel_type_descriptors_supported_count.attr, + &dmi_sysfs_attr_sel_per_log_type_descriptor_length.attr, +NULL , +}; + + +static struct kobj_type dmi_system_event_log_ktype = { + .release = dmi_entry_free, + .sysfs_ops = &dmi_sysfs_specialize_attr_ops, + .default_attrs = dmi_sysfs_sel_attrs, +}; + +static int dmi_system_event_log (struct dmi_sysfs_entry *entry) +{ +int ret; + + entry->child =kzalloc (sizeof (*entry->child),GFP_KERNEL ); +if (!entry->child) +return -ENOMEM ; + ret =kobject_init_and_add (entry->child, + &dmi_system_event_log_ktype, + &entry->kobj, +"system_event_log" ); +if (ret) + goto out_free; +out_free: +kfree (entry->child); +return ret; +} + +/************************************************* * Generic DMI entry support. *************************************************/
@@ -325,6 +470,18 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,list_add_tail (&entry->list, &entry_list);spin_unlock (&entry_list_lock); +/* Handle specializations by type */ +switch (dh->type) { +case DMI_ENTRY_SYSTEM_EVENT_LOG : + *ret =dmi_system_event_log (entry); +break ; +default : +/* No specialization */ +break ; + } +if (*ret) + goto out_err; +/* Create the raw binary file to access the entry */ *ret =sysfs_create_bin_file (&entry->kobj, &dmi_entry_raw_attr);if (*ret)
@@ -332,6 +489,7 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,return ; out_err: +kobject_put (entry->child);kobject_put (&entry->kobj);return ; }
@@ -342,6 +500,7 @@ static void cleanup_entry_list(void)/* No locks, we are on our way out */ list_for_each_entry_safe (entry, next, &entry_list, list) { +kobject_put (entry->child);kobject_put (&entry->kobj); } }
PATCH v2 4/5 firmware: Expose DMI type 15 System Event Log
In reply to Mike WaychisonThe System Event Log described by DMI entry type 15 may be backed by either memory or may be indirectly accessed via an IO index/data register pair.
In order to get read access to this log, expose it in the "system_event_log" sub-directory of type 15 DMI entries, ie:/sys/firmware/dmi/entries/15-0/system_event_log/raw_event_log.
This commit handles both IO accessed and memory access system event logs. OEM specific access and GPNV support is explicitly not handled and we error out in the logs when we do not recognize the access method.
--- drivers/firmware/dmi-sysfs.c | 143 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 143 insertions(+), 0 deletions(-)
drivers/firmware/dmi-sysfs.c +143 -0
@@ -312,6 +312,140 @@ static struct kobj_type dmi_system_event_log_ktype = { .default_attrs = dmi_sysfs_sel_attrs, }; +typedef u8 (*sel_io_reader )(const struct dmi_system_event_log *sel, +loff_t offset); + +static DEFINE_MUTEX (io_port_lock); + +static u8 read_sel_8bit_indexed_io (const struct dmi_system_event_log *sel, +loff_t offset) +{ +u8 ret; + +mutex_lock (&io_port_lock); +outb ((u8 )offset, sel->io.index_addr); + ret =inb (sel->io.data_addr); +mutex_unlock (&io_port_lock); +return ret; +} + +static u8 read_sel_2x8bit_indexed_io (const struct dmi_system_event_log *sel, +loff_t offset) +{ +u8 ret; + +mutex_lock (&io_port_lock); +outb ((u8 )offset, sel->io.index_addr); +outb ((u8)(offset >>8 ), sel->io.index_addr +1 ); + ret =inb (sel->io.data_addr); +mutex_unlock (&io_port_lock); +return ret; +} + +static u8 read_sel_16bit_indexed_io (const struct dmi_system_event_log *sel, +loff_t offset) +{ +u8 ret; + +mutex_lock (&io_port_lock); +outw ((u16 )offset, sel->io.index_addr); + ret =inb (sel->io.data_addr); +mutex_unlock (&io_port_lock); +return ret; +} + +static sel_io_reader sel_io_readers[] = { + [DMI_SEL_ACCESS_METHOD_IO8 ] = read_sel_8bit_indexed_io, + [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io, + [DMI_SEL_ACCESS_METHOD_IO16 ] = read_sel_16bit_indexed_io, +}; + +static ssize_t dmi_sel_raw_read_io (struct dmi_sysfs_entry *entry, +const struct dmi_system_event_log *sel, +char *buf,loff_t pos,size_t count) +{ +ssize_t wrote =0 ; + +sel_io_reader io_reader = sel_io_readers[sel->access_method]; + +while (count && pos < sel->area_length) { + count--; + *(buf++) =io_reader (sel, pos++); + wrote++; + } + +return wrote; +} + +static ssize_t dmi_sel_raw_read_phys32 (struct dmi_sysfs_entry *entry, +const struct dmi_system_event_log *sel, +char *buf,loff_t pos,size_t count) +{ +u8 __iomem *mapped; +ssize_t wrote =0 ; + + mapped =ioremap (sel->access_method_address, sel->area_length); +if (!mapped) +return -EIO ; + +while (count && pos < sel->area_length) { + count--; + *(buf++) =readb (mapped + pos++); + wrote++; + } + +iounmap (mapped); +return wrote; +} + +static ssize_t dmi_sel_raw_read_helper (struct dmi_sysfs_entry *entry, +const struct dmi_header *dh, +void *_state) +{ +struct dmi_read_state *state = _state; +const struct dmi_system_event_log *sel =to_sel (dh); + +if (sizeof (*sel) >dmi_entry_length (dh)) +return -EIO ; + +switch (sel->access_method) { +case DMI_SEL_ACCESS_METHOD_IO8 : +case DMI_SEL_ACCESS_METHOD_IO2x8: +case DMI_SEL_ACCESS_METHOD_IO16 : +return dmi_sel_raw_read_io (entry, sel, state->buf, + state->pos, state->count); +case DMI_SEL_ACCESS_METHOD_PHYS32 : +return dmi_sel_raw_read_phys32 (entry, sel, state->buf, + state->pos, state->count); +case DMI_SEL_ACCESS_METHOD_GPNV : +pr_info ("dmi-sysfs: GPNV support missing.\n" ); +return -EIO ; +default : +pr_info ("dmi-sysfs: Unknown access method %02x\n" , + sel->access_method); +return -EIO ; + } +} + +static ssize_t dmi_sel_raw_read (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr, +char *buf,loff_t pos,size_t count) +{ +struct dmi_sysfs_entry *entry =to_entry (kobj->parent); +struct dmi_read_state state = { + .buf = buf, + .pos = pos, + .count = count, + }; + +return find_dmi_entry (entry, dmi_sel_raw_read_helper, &state); +} + +static struct bin_attribute dmi_sel_raw_attr = { + .attr = {.name ="raw_event_log" , .mode =0400 }, + .read = dmi_sel_raw_read, +}; +static int dmi_system_event_log (struct dmi_sysfs_entry *entry) {int ret;
@@ -325,6 +459,15 @@ static int dmi_system_event_log(struct dmi_sysfs_entry *entry) "system_event_log");if (ret) goto out_free; + + ret =sysfs_create_bin_file (entry->child, &dmi_sel_raw_attr); +if (ret) + goto out_del; + +return 0 ; + +out_del: +kobject_del (entry->child); out_free:kfree (entry->child);return ret;
PATCH v2 5/5 firmware: Add documentation for /sys/firmware/dmi
In reply to Mike WaychisonDocument the new ABI added by the dmi-sysfs module.
---
Changelog:
- v2
- Added blurbs about 'type' and 'instance' attributes added in this version.
- Grammar fixes from Tim Hockin.
--- Documentation/ABI/testing/sysfs-firmware-dmi | 110 ++++++++++++++++++++++++++ 1 files changed, 110 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-dmi
Documentation/ABI/testing/sysfs-firmware-dmi new file +110 -0
@@ -0,0 +1,110 @@ +What: /sys/firmware/dmi/ +Date: February 2011 +Contact: Mike Waychison <[email protected]> +Description: + Many machines' firmware (x86 and ia64) export DMI / + SMBIOS tables to the operating system. Getting at this + information is often valuable to userland, especially in + cases where there are OEM extensions used. + + The kernel itself does not rely on the majority of the + information in these tables being correct. It equally + cannot ensure that the data as exported to userland is + without error either. + + DMI is structured as a large table of entries, where + each entry has a common header indicating the type and + length of the entry, as well as 'handle' that is + supposed to be unique amongst all entries. + + Some entries are required by the specification, but many + others are optional. In general though, users should + never expect to find a specific entry type on their + system unless they know for certain what their firmware + is doing. Machine to machine will vary. + + Multiple entries of the same type are allowed. In order + to handle these duplicate entry types, each entry is + assigned by the operating system an 'instance', which is + derived from an entry type's ordinal position. That is + to say, if there are 'N' multiple entries with the same type + 'T' in the DMI tables (adjacent or spread apart, it + doesn't matter), they will be represented in sysfs as + entries "T-0" through "T-(N-1)": + + Example entry directories: + + /sys/firmware/dmi/entries/17-0 + /sys/firmware/dmi/entries/17-1 + /sys/firmware/dmi/entries/17-2 + /sys/firmware/dmi/entries/17-3 + ... + + Instance numbers are used in lieu of the firmware + assigned entry handles as the kernel itself makes no + guarantees that handles as exported are unique, and + there are likely firmware images that get this wrong in + the wild. + + Each DMI entry in sysfs has the common header values + exported as attributes: + + handle : The 16bit 'handle' that is assigned to this + entry by the firmware. This handle may be + referred to by other entries. + length : The length of the entry, as presented in the + entry itself. Note that this is _not the + total count of bytes associated with the + entry_. This value represents the length of + the "formatted" portion of the entry. This + "formatted" region is sometimes followed by + the "unformatted" region composed of nul + terminated strings, with termination signalled + by a two nul characters in series. + raw : The raw bytes of the entry. This includes the + "formatted" portion of the entry, the + "unformatted" strings portion of the entry, + and the two terminating nul characters. + type : The type of the entry. This value is the same + as found in the directory name. It indicates + how the rest of the entry should be + interpreted. + instance: The instance ordinal of the entry for the + given type. This value is the same as found + in the parent directory name. + position: The position of the entry within the entirety + of the entirety. + + === Entry Specialization === + + Some entry types may have other information available in + sysfs. + + --- Type 15 - System Event Log --- + + This entry allows the firmware to export a log of + events the system has taken. This information is + typically backed by nvram, but the implementation + details are abstracted by this table. This entries data + is exported in the directory: + + /sys/firmware/dmi/entries/15-0/system_event_log + + and has the following attributes (documented in the + SMBIOS / DMI specification under "System Event Log (Type 15)": + + area_length + header_start_offset + data_start_offset + access_method + status + change_token + access_method_address + header_format + per_log_type_descriptor_length + type_descriptors_supported_count + + As well, the kernel exports the binary attribute: + + raw_event_log : The raw binary bits of the event log + as described by the DMI entry.
Quoted 4 lines · Mike Waychison
This patchset applies to v2.6.38-rc6.
The following series exports information the DMI / SMBIOS tables via sysfs under the path
/sys/firmware/dmi.
Looks good, all queued up now, thanks for following through with this.
greg k-h
[PATCH v2 6/5] Fix unaligned memory accesses in dmi-sysfs
In reply to Mike WaychisonDMI entries are arranged in memory back to back with no alignment guarantees. This means that the struct dmi_header passed to callbacks from dmi_walk() itself isn't byte aligned. This causes problems on architectures that expect aligned data, such as IA64.
The dmi-sysfs patchset introduced structure member accesses through this passed in dmi_header. Fix this by memcpy()ing the structures to temporary locations on stack when inspecting/copying them.
--- dmi-sysfs.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/firmware/dmi-sysfs.c +13 -15
@@ -263,20 +263,16 @@ struct dmi_system_event_log {u8 supported_log_type_descriptos[0 ]; } __packed; -static const struct dmi_system_event_log *to_sel (const struct dmi_header *dh) -{ -return (const struct dmi_system_event_log *)dh; -} -#define DMI_SYSFS_SEL_FIELD (_field) \ static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \ const struct dmi_header *dh, \ char *buf) \ { \ - const struct dmi_system_event_log *sel = to_sel(dh); \ - if (sizeof(*sel) > dmi_entry_length(dh)) \ + struct dmi_system_event_log sel; \ + if (sizeof(sel) > dmi_entry_length(dh)) \ return -EIO; \ - return sprintf(buf, "%u\n", sel->_field); \ + memcpy(&sel, dh, sizeof(sel)); \ + return sprintf(buf, "%u\n", sel._field); \ } \ static DMI_SYSFS_MAPPED_ATTR(sel, _field)
@@ -403,26 +399,28 @@ static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry, void *_state) {struct dmi_read_state *state = _state; -const struct dmi_system_event_log *sel =to_sel (dh); +struct dmi_system_event_log sel; -if (sizeof (*sel) >dmi_entry_length (dh)) +if (sizeof (sel) >dmi_entry_length (dh))return -EIO ; -switch (sel->access_method) { +memcpy (&sel, dh,sizeof (sel)); + +switch (sel.access_method) {case DMI_SEL_ACCESS_METHOD_IO8 :case DMI_SEL_ACCESS_METHOD_IO2x8:case DMI_SEL_ACCESS_METHOD_IO16 : -return dmi_sel_raw_read_io (entry, sel, state->buf, +return dmi_sel_raw_read_io (entry, &sel, state->buf, state->pos, state->count);case DMI_SEL_ACCESS_METHOD_PHYS32 : -return dmi_sel_raw_read_phys32 (entry, sel, state->buf, +return dmi_sel_raw_read_phys32 (entry, &sel, state->buf, state->pos, state->count);case DMI_SEL_ACCESS_METHOD_GPNV :pr_info ("dmi-sysfs: GPNV support missing.\n" );return -EIO ;default :pr_info ("dmi-sysfs: Unknown access method %02x\n" , - sel->access_method); + sel.access_method);return -EIO ; } }
@@ -595,7 +593,7 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh, }/* Set the key */ - entry->dh = *dh; +memcpy (&entry->dh, dh,sizeof (*dh)); entry->instance = instance_counts[dh->type]++; entry->position = position_count++;
Re: [PATCH v2 6/5] Fix unaligned memory accesses in dmi-sysfs
Quoted 20 lines · Mike Waychison
DMI entries are arranged in memory back to back with no alignment guarantees. This means that the struct
dmi_headerpassed to callbacks fromdmi_walk()itself isn't byte aligned. This causes problems on architectures that expect aligned data, such as IA64.The dmi-sysfs patchset introduced structure member accesses through this passed in
dmi_header. Fix this by memcpy()ing the structures to temporary locations on stack when inspecting/copying them.Signed-off-by Mike Waychison <[email protected]>Tested-by Tony Luck <[email protected]>--- dmi-sysfs.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)drivers/firmware/dmi-sysfs.c +0
-0
drivers/firmware/dmi-sysfs.c struct dmi_system_event_log { · line 266
Quoted 5 lines
drivers/firmware/dmi-sysfs.c +0
-1@@ -263,20 +263,16 @@ struct dmi_system_event_log {u8 supported_log_type_descriptos[0 ]; } __packed; -static const struct dmi_system_event_log *to_sel (const struct dmi_header *dh)
This patch is corrupted. I tried to edit it by hand, but git still didn't like it.
Please resend using whatever you did for your other patches, as this way was not correct :(
thanks,
greg k-h
[resend PATCH v2 6/5] Fix unaligned memory accesses in dmi-sysfs
In reply to Mike WaychisonDMI entries are arranged in memory back to back with no alignment guarantees. This means that the struct dmi_header passed to callbacks from dmi_walk() itself isn't byte aligned. This causes problems on architectures that expect aligned data, such as IA64.
The dmi-sysfs patchset introduced structure member accesses through this passed in dmi_header. Fix this by memcpy()ing the structures to temporary locations on stack when inspecting/copying them.
--- drivers/firmware/dmi-sysfs.c | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-)
drivers/firmware/dmi-sysfs.c +13 -15
@@ -263,20 +263,16 @@ struct dmi_system_event_log {u8 supported_log_type_descriptos[0 ]; } __packed; -static const struct dmi_system_event_log *to_sel (const struct dmi_header *dh) -{ -return (const struct dmi_system_event_log *)dh; -} -#define DMI_SYSFS_SEL_FIELD (_field) \ static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \ const struct dmi_header *dh, \ char *buf) \ { \ - const struct dmi_system_event_log *sel = to_sel(dh); \ - if (sizeof(*sel) > dmi_entry_length(dh)) \ + struct dmi_system_event_log sel; \ + if (sizeof(sel) > dmi_entry_length(dh)) \ return -EIO; \ - return sprintf(buf, "%u\n", sel->_field); \ + memcpy(&sel, dh, sizeof(sel)); \ + return sprintf(buf, "%u\n", sel._field); \ } \ static DMI_SYSFS_MAPPED_ATTR(sel, _field)
@@ -403,26 +399,28 @@ static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry, void *_state) {struct dmi_read_state *state = _state; -const struct dmi_system_event_log *sel =to_sel (dh); +struct dmi_system_event_log sel; -if (sizeof (*sel) >dmi_entry_length (dh)) +if (sizeof (sel) >dmi_entry_length (dh))return -EIO ; -switch (sel->access_method) { +memcpy (&sel, dh,sizeof (sel)); + +switch (sel.access_method) {case DMI_SEL_ACCESS_METHOD_IO8 :case DMI_SEL_ACCESS_METHOD_IO2x8:case DMI_SEL_ACCESS_METHOD_IO16 : -return dmi_sel_raw_read_io (entry, sel, state->buf, +return dmi_sel_raw_read_io (entry, &sel, state->buf, state->pos, state->count);case DMI_SEL_ACCESS_METHOD_PHYS32 : -return dmi_sel_raw_read_phys32 (entry, sel, state->buf, +return dmi_sel_raw_read_phys32 (entry, &sel, state->buf, state->pos, state->count);case DMI_SEL_ACCESS_METHOD_GPNV :pr_info ("dmi-sysfs: GPNV support missing.\n" );return -EIO ;default :pr_info ("dmi-sysfs: Unknown access method %02x\n" , - sel->access_method); + sel.access_method);return -EIO ; } }
@@ -595,7 +593,7 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh, }/* Set the key */ - entry->dh = *dh; +memcpy (&entry->dh, dh,sizeof (*dh)); entry->instance = instance_counts[dh->type]++; entry->position = position_count++;