There are situations when code needs to access SMBIOS entry table area, but cannot use /dev/mem for this. As the table format is consistent only for a version, and can be changed, use binary attribute to give access to raw SMBIOS entry table area.
Signed-off-by: Ivan Khoronzhuk ivan.khoronzhuk@linaro.org --- drivers/firmware/dmi-sysfs.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c index e0f1cb3..c308b8b 100644 --- a/drivers/firmware/dmi-sysfs.c +++ b/drivers/firmware/dmi-sysfs.c @@ -646,6 +646,37 @@ static void cleanup_entry_list(void) } }
+static ssize_t smbios_entry_area_raw_read(struct file *filp, + struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +{ + ssize_t size; + unsigned char area[32]; + + size = dmi_get_smbios_entry_area(area); + if (size == -ENODATA) + return size; + + if (size > pos) + size -= pos; + else + return 0; + + if (count < size) + size = count; + + memcpy(buf, &area[pos], size); + + return size; +} + +static const struct bin_attribute smbios_entry_area_raw_attr = { + .size = 32, + .read = smbios_entry_area_raw_read, + .attr = {.name = "smbios_raw", .mode = 0400}, +}; + static int __init dmi_sysfs_init(void) { int error = -ENOMEM; @@ -656,6 +687,10 @@ static int __init dmi_sysfs_init(void) if (!dmi_kobj) goto err;
+ /* Create the raw binary file to access the entry area */ + if (sysfs_create_bin_file(dmi_kobj, &smbios_entry_area_raw_attr)) + goto err; + dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj); if (!dmi_kset) goto err;