From: Olof Johansson <olof@lixom.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Jean Delvare <khali@linux-fr.org>,
Tejun Heo <tj@kernel.org>
Subject: [PATCH] dmi: export dmi data through debugfs
Date: Tue, 28 Sep 2010 16:12:46 -0500 [thread overview]
Message-ID: <20100928211246.GA20941@lixom.net> (raw)
I've found this quite useful since it allows dmidecode to run without
root privileges using --from-dump to read this file instead (note:
dmidecode needs a change to fall back from mmap to regular reads, since
debugfs exports can't be mmapped()).
It also changes the calling convention of dmi_present somewhat, since the
16-byte EPS header is needed in the exported file.
Signed-off-by: Olof Johansson <olof@lixom.net>
---
drivers/firmware/dmi_scan.c | 94 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 83 insertions(+), 11 deletions(-)
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index d464672..26141e1 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -5,6 +5,7 @@
#include <linux/dmi.h>
#include <linux/efi.h>
#include <linux/bootmem.h>
+#include <linux/debugfs.h>
#include <asm/dmi.h>
/*
@@ -99,6 +100,73 @@ static u32 dmi_base;
static u16 dmi_len;
static u16 dmi_num;
+#ifdef CONFIG_DEBUG_FS
+static struct debugfs_blob_wrapper dmi_blob;
+
+/* Export a copy of the DMI blob through debugfs. Just concatenate the
+ * header with the main blob, and make the pointer the file offset of the
+ * main blob (i.e. 32 bytes).
+ */
+static int __init dmi_debug_setup(const char __iomem *p)
+{
+ u8 *blob, *buf, tmp;
+ int i;
+
+ blob = dmi_alloc(dmi_len + 32);
+ if (!blob)
+ return -ENOMEM;
+
+ memcpy_fromio(blob, p, 32);
+
+ buf = dmi_ioremap(dmi_base, dmi_len);
+ memcpy_fromio(blob + 32, buf, dmi_len);
+ dmi_iounmap(buf, dmi_len);
+
+ /* 32 is the offset into the file */
+ blob[24] = 32;
+ blob[25] = 0;
+ blob[26] = 0;
+ blob[27] = 0;
+
+ /* First checksum the IEPS */
+ blob[21] = 0;
+ tmp = 0;
+ for (i = 0x10; i < 0x1f; i++)
+ tmp += blob[i];
+ blob[21] = -tmp;
+
+ /* Then the EPS */
+ blob[4] = 0;
+ tmp = 0;
+ for (i = 0; i < blob[5]; i++)
+ tmp += blob[i];
+ blob[4] = -tmp;
+
+ dmi_blob.data = blob;
+ dmi_blob.size = dmi_len + 32;
+
+ return 0;
+}
+
+static int __init dmi_debugfs_create(void)
+{
+ void *ret = ERR_PTR(-ENODEV);
+
+ if (dmi_blob.data)
+ ret = debugfs_create_blob("dmidump", 0444, NULL, &dmi_blob);
+
+ return PTR_ERR(ret);
+}
+late_initcall(dmi_debugfs_create);
+
+#else
+
+static int __init dmi_debug_setup(const char __iomem *p)
+{
+ return 0;
+}
+#endif /* CONFIG_DEBUGFS */
+
static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
void *))
{
@@ -338,26 +406,30 @@ static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
static int __init dmi_present(const char __iomem *p)
{
- u8 buf[15];
+ u8 buf[31];
- memcpy_fromio(buf, p, 15);
- if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
- dmi_num = (buf[13] << 8) | buf[12];
- dmi_len = (buf[7] << 8) | buf[6];
- dmi_base = (buf[11] << 24) | (buf[10] << 16) |
- (buf[9] << 8) | buf[8];
+ memcpy_fromio(buf, p, 31);
+ /* _DMI_ string starts 16 bytes in. */
+ if ((memcmp(buf+16, "_DMI_", 5) == 0) && dmi_checksum(buf+16)) {
+ dmi_num = (buf[29] << 8) | buf[28];
+ dmi_len = (buf[23] << 8) | buf[22];
+ dmi_base = (buf[27] << 24) | (buf[26] << 16) |
+ (buf[25] << 8) | buf[24];
/*
* DMI version 0.0 means that the real version is taken from
* the SMBIOS version, which we don't know at this point.
*/
- if (buf[14] != 0)
+ if (buf[30] != 0)
printk(KERN_INFO "DMI %d.%d present.\n",
- buf[14] >> 4, buf[14] & 0xF);
+ buf[30] >> 4, buf[30] & 0xf);
else
printk(KERN_INFO "DMI present.\n");
- if (dmi_walk_early(dmi_decode) == 0)
+ if (dmi_walk_early(dmi_decode) == 0) {
+ dmi_debug_setup(p);
+
return 0;
+ }
}
return 1;
}
@@ -379,7 +451,7 @@ void __init dmi_scan_machine(void)
if (p == NULL)
goto error;
- rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
+ rc = dmi_present(p);
dmi_iounmap(p, 32);
if (!rc) {
dmi_available = 1;
--
1.7.0.4
next reply other threads:[~2010-09-28 21:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-28 21:12 Olof Johansson [this message]
2010-09-29 7:34 ` [PATCH] dmi: export dmi data through debugfs Jean Delvare
2010-09-29 14:53 ` Olof Johansson
2010-09-29 15:11 ` Jean Delvare
2010-09-29 21:28 ` Alan Cox
2010-09-30 6:36 ` Jean Delvare
2010-09-30 14:31 ` Olof Johansson
2010-09-30 17:34 ` Andi Kleen
2010-09-30 17:59 ` Jean Delvare
2010-09-30 15:32 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100928211246.GA20941@lixom.net \
--to=olof@lixom.net \
--cc=akpm@linux-foundation.org \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox