From patchwork Thu Feb 12 02:33:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 44578 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 17DEC21527 for ; Thu, 12 Feb 2015 02:33:57 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id r20sf523239wiv.3 for ; Wed, 11 Feb 2015 18:33:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:content-type :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=fuKo7DMmBfWXCAcTckmVP4IqppMSMSXgA25HILH8oK0=; b=gGChKLIwC2ok8Q+9ICNk0hnNlZrmxesam54I97Qu+QRdhC5JsMopvhHdcEpHyKcq+M lpqciqGjtAhrCXF9CwBhahtECgXf6sMXw/tBvLFHbOCzO33dXwvJR01QjaU1jkELNd6m /sFyu8bt/ohPfVnnxA8KIQSw5t17nXeZTJAFObp/3xzfjpPw1+IISmT/7ZejQfkFos0C QTconeLfDVNfZinQZk5+Z2nbrR5tauXRTrhZIYuEqOwFOq+CxL3nDLu6g4Oy47ENYO1C qX4nZNFVema1jGRjA7ToqRxidg/5Y8Vy1DVQcUJQRdhhEY2dTTCm1urEYO0wgBLtaZiT xTCQ== X-Gm-Message-State: ALoCoQnUnAKHaeuDCcWoLvuN/jE56+UHldfZxy2zHSD1qzC3iPpb/QATs5pCiIRIbK8UIMm3Oltp X-Received: by 10.112.130.70 with SMTP id oc6mr196642lbb.13.1423708436240; Wed, 11 Feb 2015 18:33:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.161.135 with SMTP id xs7ls145739lab.42.gmail; Wed, 11 Feb 2015 18:33:55 -0800 (PST) X-Received: by 10.112.140.74 with SMTP id re10mr1346018lbb.80.1423708435865; Wed, 11 Feb 2015 18:33:55 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id a8si1918923lbv.118.2015.02.11.18.33.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 18:33:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id z11so6973188lbi.5 for ; Wed, 11 Feb 2015 18:33:55 -0800 (PST) X-Received: by 10.152.28.227 with SMTP id e3mr1155727lah.117.1423708435449; Wed, 11 Feb 2015 18:33:55 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp167836lbj; Wed, 11 Feb 2015 18:33:54 -0800 (PST) X-Received: by 10.66.254.1 with SMTP id ae1mr2386595pad.107.1423708433123; Wed, 11 Feb 2015 18:33:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cy3si1840022pbb.224.2015.02.11.18.33.51; Wed, 11 Feb 2015 18:33:53 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754901AbbBLCdi (ORCPT + 28 others); Wed, 11 Feb 2015 21:33:38 -0500 Received: from mail-pd0-f176.google.com ([209.85.192.176]:32934 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754858AbbBLCdf (ORCPT ); Wed, 11 Feb 2015 21:33:35 -0500 Received: by pdjz10 with SMTP id z10so8653262pdj.0 for ; Wed, 11 Feb 2015 18:33:34 -0800 (PST) X-Received: by 10.68.224.201 with SMTP id re9mr2351093pbc.133.1423708414508; Wed, 11 Feb 2015 18:33:34 -0800 (PST) Received: from [192.168.34.143] ([210.177.145.249]) by mx.google.com with ESMTPSA id rx1sm2148460pbc.5.2015.02.11.18.33.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 18:33:33 -0800 (PST) Message-ID: <54DC10FC.6030008@linaro.org> Date: Thu, 12 Feb 2015 04:33:32 +0200 From: Ivan Khoronzhuk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Matt Fleming CC: Grant Likely , Ard Biesheuvel , "linux-kernel@vger.kernel.org" , linux-api@vger.kernel.org, linux-doc@vger.kernel.org, Leif Lindholm , Mark Salter Subject: Re: [Patch v4] firmware: dmi-sysfs: add SMBIOS entry point area attribute References: <1423069563-26467-1-git-send-email-ivan.khoronzhuk@linaro.org> <54D9D4B0.7020803@linaro.org> <20150211141703.GA4665@codeblueprint.co.uk> <20150211144321.GB4665@codeblueprint.co.uk> In-Reply-To: <20150211144321.GB4665@codeblueprint.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ivan.khoronzhuk@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 02/11/2015 04:43 PM, Matt Fleming wrote: > On Wed, 11 Feb, at 02:17:03PM, Matt Fleming wrote: >> On Tue, 10 Feb, at 11:51:44AM, Ivan Khoronzhuk wrote: >>> If you are Ok with this patch, could you please pickup it? >> Applied, thanks Ivan! > Btw this patch doesn't apply cleanly, the reject looks like this, > > --- drivers/firmware/dmi_scan.c > +++ drivers/firmware/dmi_scan.c > @@ -537,6 +543,8 @@ > dmi_ver &= 0xFFFFFF; The problem is in above string. I used linux next, but I had one patch before. Sorry... just forgot about it. I've attached the same patch but on top of linux_next, it can be applied cleanly. Sorry once again and thanks! > dmi_len = get_unaligned_le32(buf + 12); > dmi_base = get_unaligned_le64(buf + 16); > + smbios_header_size = buf[6]; > + memcpy(smbios_header, buf, smbios_header_size); > > /* > * The 64-bit SMBIOS 3.0 entry point no longer has a field > > What version of the kernel did you base this patch on? The conflict is > trivial to fixup and I've done so and pushed it out on the EFI 'next' > branch, but I wanted to call out this conflict explicitly. > >From b64185ddfb0b704f83324d8b0c6be7f7ee951581 Mon Sep 17 00:00:00 2001 From: Ivan Khoronzhuk Date: Tue, 30 Dec 2014 02:58:12 +0200 Subject: [PATCH] firmware: dmi-sysfs: add SMBIOS entry point area attribute Some utils, like dmidecode and smbios, needs to access SMBIOS entry table area in order to get information like SMBIOS version, size, etc. Currently it's done via /dev/mem. But for situation when /dev/mem usage is disabled, the utils have to use dmi sysfs instead, which doesn't represent SMBIOS entry. So this patch adds SMBIOS area to dmi-sysfs in order to allow utils in question to work correctly with dmi sysfs interface. Reviewed-by: Ard Biesheuvel Signed-off-by: Ivan Khoronzhuk --- Documentation/ABI/testing/sysfs-firmware-dmi | 10 +++++++ drivers/firmware/dmi-sysfs.c | 42 ++++++++++++++++++++++++++++ drivers/firmware/dmi_scan.c | 26 +++++++++++++++++ include/linux/dmi.h | 3 ++ 4 files changed, 81 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-firmware-dmi b/Documentation/ABI/testing/sysfs-firmware-dmi index c78f9ab..3a9ffe8 100644 --- a/Documentation/ABI/testing/sysfs-firmware-dmi +++ b/Documentation/ABI/testing/sysfs-firmware-dmi @@ -12,6 +12,16 @@ Description: cannot ensure that the data as exported to userland is without error either. + The firmware provides DMI structures as a packed list of + data referenced by a SMBIOS table entry point. The SMBIOS + entry point contains general information, like SMBIOS + version, DMI table size, etc. The structure, content and + size of SMBIOS entry point is dependent on SMBIOS version. + That's why SMBIOS entry point is represented in dmi sysfs + like a raw attribute and is accessible via + /sys/firmware/dmi/smbios_raw_header. The format of SMBIOS + entry point header can be read in SMBIOS specification. + 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 a firmware-provided diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c index e0f1cb3..9b396d7 100644 --- a/drivers/firmware/dmi-sysfs.c +++ b/drivers/firmware/dmi-sysfs.c @@ -29,6 +29,8 @@ #define MAX_ENTRY_TYPE 255 /* Most of these aren't used, but we consider the top entry type is only 8 bits */ +static const u8 *smbios_raw_header; + struct dmi_sysfs_entry { struct dmi_header dh; struct kobject kobj; @@ -646,9 +648,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; + + size = bin_attr->size; + + if (size > pos) + size -= pos; + else + return 0; + + if (count < size) + size = count; + + memcpy(buf, &smbios_raw_header[pos], size); + + return size; +} + +static struct bin_attribute smbios_raw_area_attr = { + .read = smbios_entry_area_raw_read, + .attr = {.name = "smbios_raw_header", .mode = 0400}, +}; + static int __init dmi_sysfs_init(void) { int error = -ENOMEM; + int size; int val; /* Set up our directory */ @@ -669,6 +699,18 @@ static int __init dmi_sysfs_init(void) goto err; } + smbios_raw_header = dmi_get_smbios_entry_area(&size); + if (!smbios_raw_header) { + pr_debug("dmi-sysfs: SMBIOS raw data is not available.\n"); + error = -EINVAL; + goto err; + } + + /* Create the raw binary file to access the entry area */ + smbios_raw_area_attr.size = size; + if (sysfs_create_bin_file(dmi_kobj, &smbios_raw_area_attr)) + goto err; + pr_debug("dmi-sysfs: loaded.\n"); return 0; diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index c5f7b4e..d55c712 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -113,6 +113,8 @@ static void dmi_table(u8 *buf, int len, int num, } } +static u8 smbios_header[32]; +static int smbios_header_size; static phys_addr_t dmi_base; static u16 dmi_len; static u16 dmi_num; @@ -474,6 +476,8 @@ static int __init dmi_present(const u8 *buf) if (memcmp(buf, "_SM_", 4) == 0 && buf[5] < 32 && dmi_checksum(buf, buf[5])) { smbios_ver = get_unaligned_be16(buf + 6); + smbios_header_size = buf[5]; + memcpy(smbios_header, buf, smbios_header_size); /* Some BIOS report weird SMBIOS version, fix that up */ switch (smbios_ver) { @@ -505,6 +509,8 @@ static int __init dmi_present(const u8 *buf) pr_info("SMBIOS %d.%d present.\n", dmi_ver >> 8, dmi_ver & 0xFF); } else { + smbios_header_size = 15; + memcpy(smbios_header, buf, smbios_header_size); dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F); pr_info("Legacy DMI %d.%d present.\n", @@ -530,6 +536,8 @@ static int __init dmi_smbios3_present(const u8 *buf) dmi_ver = get_unaligned_be16(buf + 7); dmi_len = get_unaligned_le32(buf + 12); dmi_base = get_unaligned_le64(buf + 16); + smbios_header_size = buf[6]; + memcpy(smbios_header, buf, smbios_header_size); /* * The 64-bit SMBIOS 3.0 entry point no longer has a field @@ -941,3 +949,21 @@ void dmi_memdev_name(u16 handle, const char **bank, const char **device) } } EXPORT_SYMBOL_GPL(dmi_memdev_name); + +/** + * dmi_get_smbios_entry_area - copy SMBIOS entry point area to array. + * @size - pointer to assign actual size of SMBIOS entry point area. + * + * returns NULL if table is not available, otherwise returns pointer on + * SMBIOS entry point area array. + */ +const u8 *dmi_get_smbios_entry_area(int *size) +{ + if (!smbios_header_size || !dmi_available) + return NULL; + + *size = smbios_header_size; + + return smbios_header; +} +EXPORT_SYMBOL_GPL(dmi_get_smbios_entry_area); diff --git a/include/linux/dmi.h b/include/linux/dmi.h index f820f0a..8e1a28d 100644 --- a/include/linux/dmi.h +++ b/include/linux/dmi.h @@ -109,6 +109,7 @@ extern int dmi_walk(void (*decode)(const struct dmi_header *, void *), void *private_data); extern bool dmi_match(enum dmi_field f, const char *str); extern void dmi_memdev_name(u16 handle, const char **bank, const char **device); +const u8 *dmi_get_smbios_entry_area(int *size); #else @@ -140,6 +141,8 @@ static inline void dmi_memdev_name(u16 handle, const char **bank, const char **device) { } static inline const struct dmi_system_id * dmi_first_match(const struct dmi_system_id *list) { return NULL; } +static inline const u8 *dmi_get_smbios_entry_area(int *size) + { return NULL; } #endif -- 1.9.1