Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1891087ybc; Wed, 20 Nov 2019 05:49:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwY9K4zz9vSLc6uIrP5w6VjSSzD6BYYFGHTvx7vqi/jRWxcWGBi6TfdXwwq0avw01KECeKc X-Received: by 2002:a17:906:3606:: with SMTP id q6mr5400327ejb.307.1574257762740; Wed, 20 Nov 2019 05:49:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574257762; cv=none; d=google.com; s=arc-20160816; b=0/ht53B2TMTChNDG/7ZM31iuz2xcOvl0cD0TXhxECsBzZRABJCUnVGZQWqZJCq25lL UNcbidOGorCohkN5RIRaMSaej0xScmXs3pJzrOaZ+Ow/Be1iWxd6FgUy25Ivuq4WzSsn OkJS81hBNSplNl81+bwKQr54AuoIvqV09k/UEuD/k8e1TBTgV8hn9eJCCmEBdEsCgYpO PNI+UpcfgYA47sUW6lnslAwg58G7cG7k5VOSSXKorqGcbvNCLC0vKt4EiSkaZD+Fh1Yn sPRE/+eg6tx+oUOTbzs7XFYf4E29x5CIZQ4/clUamjHdIpiDBotZLEvcblyoAfXz9/Cj tI3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DHnopwWvkmmTnJVl2X6mKxjcUforEZXEgcJgrEmjAB0=; b=Bicu2AVrff8WtxZyj+tWwftXYSU2ffuTPfU6oVVNiVQoMwOOadlfrY92Kw9ayeBVDU AZIBoHHS4KY8OpwkbMekGQXbMFhWP+1viPuwt7gj/iDu+Uj1X33vMhghKwsYRUbB722r F+AxV3pymEEuJOwT0QGSh9/83Kcupw72/q5syI8YdcNhiVN8At5u0/iD+kY+xUgzX/s4 Q+Zh0+35+DZgPz1FWHT/ClELdW5WDwI/SZPCwxrK1tlGt5JCI+JptoBOINJxcYR9gbf/ or5LpLE8Oymi08NArC3vyLKIFPkn00g2xj6vrqORFkWLEKZ0GKq+tDQ9Zds1tHGSjgLv XeGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=f7xLTrPB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bo10si14231533edb.424.2019.11.20.05.48.58; Wed, 20 Nov 2019 05:49:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=f7xLTrPB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731224AbfKTNkq (ORCPT + 99 others); Wed, 20 Nov 2019 08:40:46 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44028 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbfKTNkp (ORCPT ); Wed, 20 Nov 2019 08:40:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id n1so28167410wra.10 for ; Wed, 20 Nov 2019 05:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DHnopwWvkmmTnJVl2X6mKxjcUforEZXEgcJgrEmjAB0=; b=f7xLTrPBQvQxEF9vkj2upkWeReLoDBCeQFkkhGeuGdXmxpYd2OtAzoXGDBuEx/8C/k m5bxP2LjKSSkyW6ge8Op8AF7EowaRz+PqyzmjsLdNYj72LGIkn5sQY61kjUC9SODE4Zs es0tYHkUSMdKQY1qviz2GHB3e8BGVqGfBe2fcywh43arhWUlnSohr1Wgc/pwN4Hpw+Sf cV0yTfiQa3TaL6fMJ2NRPUNvtA6pJf7LKFlsxNQQX3xKxpoR2E8oOLTCeZT6T6LefMGH TOrpYycWxDbn9WJuw+SuNsRIDR9y0fhx7hr7vtIDGX2VztQtcz3Dja317H903tX9AvKi TLqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DHnopwWvkmmTnJVl2X6mKxjcUforEZXEgcJgrEmjAB0=; b=YSSgA2ZGFQZEGzWMTTLVzUjN0UezgrGPKHMlNaNhDWOkdm6t7xRwAjcJ0EiAXCoABR x6aJyVIb8Vfae4MEmvR6lNgQeCrScsxiex7wmpgEim1hqcheXAt7sr4HeJ/jfHe5pqh6 uPRK4hqWRfnaqWJwHR2R4xjWQNuwvbxXL9J6KI/1StJuk97PWD6GuSXPFeUrY9AZJqQl b0HiiL4BzscaAEPur00nC7yNvKIDAPcgz/c/3yH4tg2/k8+cD86f+0JSDG8LPkVzTIMg 7yvxRPZGMxVYPy843JG0IBHRhjcz35DASSm5pIr/DheuzC/18oPKgHA1UnCcHmRyyAZE KgoA== X-Gm-Message-State: APjAAAW8dnKKnG1ifUz1Qc8QCFnpB8frmeNi9B+H31J8zA60zNVRWfez 2F02+G15e/SyJLt7A6SPho8M3JC7AoJCdPXl X-Received: by 2002:adf:fa4a:: with SMTP id y10mr3506109wrr.177.1574257242554; Wed, 20 Nov 2019 05:40:42 -0800 (PST) Received: from rudolphp.9e.network (b2b-78-94-0-50.unitymedia.biz. [78.94.0.50]) by smtp.gmail.com with ESMTPSA id t14sm30473434wrw.87.2019.11.20.05.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2019 05:40:42 -0800 (PST) From: patrick.rudolph@9elements.com To: linux-kernel@vger.kernel.org Cc: Patrick Rudolph , Thomas Gleixner , Greg Kroah-Hartman , Alexios Zavras , Allison Randal , Stephen Boyd , Samuel Holland , Julius Werner Subject: [PATCH 2/2] firmware: google: Expose coreboot tables over sysfs Date: Wed, 20 Nov 2019 14:39:47 +0100 Message-Id: <20191120133958.13160-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191120133958.13160-1-patrick.rudolph@9elements.com> References: <20191120133958.13160-1-patrick.rudolph@9elements.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Patrick Rudolph Make all coreboot table entries available to userland. This is useful for tools that are currently using /dev/mem. Besides the tag and size also expose the raw table data itself. Update the ABI documentation to explain the new sysfs interface. Tools can easily scan for the right coreboot table by reading /sys/bus/coreboot/devices/coreboot*/attributes/id The binary table data can then be read from /sys/bus/coreboot/devices/coreboot*/attributes/data Signed-off-by: Patrick Rudolph --- -v2: - Add ABI documentation - Add 0x prefix on hex values - Remove wrong ioremap hint as found by CI --- Documentation/ABI/stable/sysfs-bus-coreboot | 30 +++++++++++ drivers/firmware/google/coreboot_table.c | 60 +++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-bus-coreboot b/Documentation/ABI/stable/sysfs-bus-coreboot index 1b04b8abc858..0f28601229f3 100644 --- a/Documentation/ABI/stable/sysfs-bus-coreboot +++ b/Documentation/ABI/stable/sysfs-bus-coreboot @@ -41,3 +41,33 @@ Description: buffer. The file holds a read-only binary representation of the CBMEM buffer. + +What: /sys/bus/coreboot/devices/.../attributes/id +Date: Nov 2019 +KernelVersion: 5.5 +Contact: Patrick Rudolph +Description: + coreboot device directory can contain a file named attributes/id. + The file holds an ASCII representation of the coreboot table ID + in hex (e.g. 0x000000ef). On coreboot enabled platforms the ID is + usually called TAG. + +What: /sys/bus/coreboot/devices/.../attributes/size +Date: Nov 2019 +KernelVersion: 5.5 +Contact: Patrick Rudolph +Description: + coreboot device directory can contain a file named + attributes/size. + The file holds an ASCII representation as decimal number of the + coreboot table size (e.g. 64). + +What: /sys/bus/coreboot/devices/.../attributes/data +Date: Nov 2019 +KernelVersion: 5.5 +Contact: Patrick Rudolph +Description: + coreboot device directory can contain a file named + attributes/data. + The file holds a read-only binary representation of the coreboot + table. diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c index 8d132e4f008a..d3a6379fb2a6 100644 --- a/drivers/firmware/google/coreboot_table.c +++ b/drivers/firmware/google/coreboot_table.c @@ -6,6 +6,7 @@ * * Copyright 2017 Google Inc. * Copyright 2017 Samuel Holland + * Copyright 2019 9elements Agency GmbH */ #include @@ -84,6 +85,63 @@ void coreboot_driver_unregister(struct coreboot_driver *driver) } EXPORT_SYMBOL(coreboot_driver_unregister); +static ssize_t id_show(struct device *dev, + struct device_attribute *attr, char *buffer) +{ + struct coreboot_device *device = CB_DEV(dev); + + return sprintf(buffer, "0x%08x\n", device->entry.tag); +} + +static ssize_t size_show(struct device *dev, + struct device_attribute *attr, char *buffer) +{ + struct coreboot_device *device = CB_DEV(dev); + + return sprintf(buffer, "%u\n", device->entry.size); +} + +static DEVICE_ATTR_RO(id); +static DEVICE_ATTR_RO(size); + +static struct attribute *cb_dev_attrs[] = { + &dev_attr_id.attr, + &dev_attr_size.attr, + NULL +}; + +static ssize_t table_data_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buffer, loff_t offset, size_t count) +{ + struct device *dev = kobj_to_dev(kobj); + struct coreboot_device *device = CB_DEV(dev); + + return memory_read_from_buffer(buffer, count, &offset, + &device->entry, device->entry.size); +} + +static struct bin_attribute coreboot_attr_data = { + .attr = { .name = "data", .mode = 0444 }, + .read = table_data_read, +}; + +static struct bin_attribute *cb_dev_bin_attrs[] = { + &coreboot_attr_data, + NULL +}; + +static const struct attribute_group cb_dev_attr_group = { + .name = "attributes", + .attrs = cb_dev_attrs, + .bin_attrs = cb_dev_bin_attrs, +}; + +static const struct attribute_group *cb_dev_attr_groups[] = { + &cb_dev_attr_group, + NULL +}; + static int coreboot_table_populate(struct device *dev, void *ptr) { int i, ret; @@ -104,6 +162,8 @@ static int coreboot_table_populate(struct device *dev, void *ptr) device->dev.parent = dev; device->dev.bus = &coreboot_bus_type; device->dev.release = coreboot_device_release; + device->dev.groups = cb_dev_attr_groups; + memcpy(&device->entry, ptr_entry, entry->size); ret = device_register(&device->dev); -- 2.21.0