From patchwork Mon Jan 26 13:28:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 43757 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1311E20D5D for ; Mon, 26 Jan 2015 13:29:14 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf4263081lab.3 for ; Mon, 26 Jan 2015 05:29:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=LcjP7OYOIUj4peFG16YfYwHzVqY4/KGQPJ6LDaUv32Y=; b=lPy5F510EJ4UD51prTxdq7JoKI0RfrYQsThVf8WpCCgqifYIOAethPLd5CTEL88l/z jb8QvxUpaKkQJiZUl//LP3TR2DiJE1Siwo3rb+zcX/U1mshj5s4AxXayCAeZaKYABtyx cs49xoiHjXgXg1GIqHgu6z+Lqoc9e98RafUPYZWQbixMeiyY55HDAXlSmGkdmxqFsHVi f/OgHbDCenq17XZTFygw4JHHFHMJqlMWm4btIYh9Eeh9ZwieidkkrNXMC+RMFAfCd1AD 4VtugVSZQogJ9BbXglNJNgMxiw9Dh6alsJuwuvkb5DoJGZDDHld/gtJitocdOBLEQphx jUOg== X-Gm-Message-State: ALoCoQntQQaASWqSJSKVX55z4JwGWVlB2hwD56LB7clceJ/crf2+FPe/rufnEPKKnUPz25l89Slp X-Received: by 10.180.212.76 with SMTP id ni12mr1836866wic.0.1422278952962; Mon, 26 Jan 2015 05:29:12 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.38 with SMTP id ld6ls520971lac.50.gmail; Mon, 26 Jan 2015 05:29:12 -0800 (PST) X-Received: by 10.112.130.65 with SMTP id oc1mr21232832lbb.7.1422278952679; Mon, 26 Jan 2015 05:29:12 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id yd10si8970956lbb.131.2015.01.26.05.29.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 05:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id pv20so7552383lab.7 for ; Mon, 26 Jan 2015 05:29:12 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr21287113laa.80.1422278952576; Mon, 26 Jan 2015 05:29:12 -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 h5csp780231lbj; Mon, 26 Jan 2015 05:29:11 -0800 (PST) X-Received: by 10.69.19.171 with SMTP id gv11mr35134557pbd.16.1422278950721; Mon, 26 Jan 2015 05:29:10 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qb7si12112344pbb.216.2015.01.26.05.29.09; Mon, 26 Jan 2015 05:29:10 -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 S1754865AbbAZN3E (ORCPT + 28 others); Mon, 26 Jan 2015 08:29:04 -0500 Received: from mail-we0-f173.google.com ([74.125.82.173]:42043 "EHLO mail-we0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751885AbbAZN25 (ORCPT ); Mon, 26 Jan 2015 08:28:57 -0500 Received: by mail-we0-f173.google.com with SMTP id w62so9046678wes.4 for ; Mon, 26 Jan 2015 05:28:55 -0800 (PST) X-Received: by 10.194.110.69 with SMTP id hy5mr44911857wjb.121.1422278935746; Mon, 26 Jan 2015 05:28:55 -0800 (PST) Received: from khorivan.itg.ti.com ([195.238.92.128]) by mx.google.com with ESMTPSA id tc2sm13921553wic.21.2015.01.26.05.28.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Jan 2015 05:28:54 -0800 (PST) From: Ivan Khoronzhuk To: linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org Cc: dmidecode-devel@nongnu.org, grant.likely@linaro.org, leif.lindholm@linaro.org, matt.fleming@intel.com, Ivan Khoronzhuk Subject: [Patch v2 2/2] firmware: dmi-sysfs: add SMBIOS entry point area attribute Date: Mon, 26 Jan 2015 15:28:38 +0200 Message-Id: <1422278918-31477-3-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422278918-31477-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1422278918-31477-1-git-send-email-ivan.khoronzhuk@linaro.org> 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.215.48 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: , 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 Reviewed-by: Ard Biesheuvel --- drivers/firmware/dmi-sysfs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c index e0f1cb3..61b6a38 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 = -ENODATA; + 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;