Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6748148ybc; Thu, 28 Nov 2019 04:53:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwGg1XoCO4lFghEej2Jrxw1f3NeS+VzagFTwGKZ77xHX4wzim/gnGNRn4aSVyQcdBaO6+l/ X-Received: by 2002:aa7:c384:: with SMTP id k4mr8538343edq.10.1574945633926; Thu, 28 Nov 2019 04:53:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574945633; cv=none; d=google.com; s=arc-20160816; b=T7KF14fFiGI+3acize5UHlr8ZUWWKGb21hb80nPtnmA5WjSCI+UtwOcWLwA4OA5hX7 HuQBWewkzsIfM3hMZjhehRJHwoO31we+3Um+WmPHJhyUvWfoop+Q0lPp9pKSoAu3CLZ5 72um+CPZJm3oGYf9n1bL0YeTbrJUO362Hjd03UqyJcUtB3yuVfqC1po8iS8pQgLDW4aG Ov7oVnG+2uaG5WDLI9eU+j7Qwi3i/DI7KX2qsDQHrbaBLMn+aEdcpVGAGBBLkz1ZIVQP zPtdl9tQdwhdMmHu0XIWTIzMbT/ponezfgsIQqkjgx5UTsvbG37P5bOkc9YE3XFw7f38 y8Iw== 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=r/Qtb3ZERKyiKM574EOCUn87VIOAQ2MiAJTI9WZq8LQ=; b=c8KRfYsvDNUVA183sBVnYh+1V+SHgHWfBsSFbnx+yFHhl8p9jOpb9MprK0AqPbtSuW K3lkEOSl66PyfaIDKSBwTyFlya60Jeb95nqASeHjexXpYzDhGsFQcNHPf4Sa8ZvagJlb Vw4cYUBoHVGZhnLhvWa8XPYtqFTAwRDkvaFZdVYZa1OYeEsh68P66ob4p9L6/MU9Y8uP oRmnIXcN7P4Bv5Y5pI3/X8E5qRPXOr/rcBFqYcfN6WfR0lTeZF2Jaar6jqDT6T43GbNr gNWqbIJFyrHOo1c+CPEhcZ1VYf4NKrx+WDhPmJGXD5n/ypekDZuqMrBEVP/O98HWDYen q6EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=Q97BIevk; 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 g8si6116535eds.278.2019.11.28.04.53.29; Thu, 28 Nov 2019 04:53:53 -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=Q97BIevk; 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 S1726699AbfK1Mv5 (ORCPT + 99 others); Thu, 28 Nov 2019 07:51:57 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42591 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbfK1Mv5 (ORCPT ); Thu, 28 Nov 2019 07:51:57 -0500 Received: by mail-wr1-f65.google.com with SMTP id a15so30967657wrf.9 for ; Thu, 28 Nov 2019 04:51:53 -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=r/Qtb3ZERKyiKM574EOCUn87VIOAQ2MiAJTI9WZq8LQ=; b=Q97BIevkGIp1y4UcUa6BeYIKIcwlLB7yRoPh4CA3a6dJNZYsUbyRQJpN3RV9EVmsDp mUiCVdEOOWVF+vwKGrsGIFW3lg2DCGAOFpd/Bp76xb90UVJSiJwZG/DjopYLetkhRBNk jy2lA1bE48RdwFzu2gM/uRfh8Pk2vR98Q1+nMMwFZlPGFPx8m8Glnc9g0wDmRgN3kG8N 1JB/6JmmAEtZ/pEWb9pMbWPL0jj7NqYLMpcsLXl+mt+miXwvqFCnEi404OcWGZZRHTz7 9hY5jzkCTvLeoBQ7NMHeoASYZ4cwpVQOX1yx7sud8k3g8t3jn47YS6Ii/qtcNajp2Wmq QLMw== 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=r/Qtb3ZERKyiKM574EOCUn87VIOAQ2MiAJTI9WZq8LQ=; b=mCehRRhsyn9ZPFu4QJNkPQvd39ZwI63iOcgrOZhFjpkeuzTaMi/7xSCDXRYBggdKK0 kp/N9nVpiHTBhNaIMrZKX5V16HgjuJUcY1PeiYnx4N8zFbSPGTgACStBnuFskGWel1wz AgiRerUWBjwPz0VTsg/IVMTk09OgMk8QU6UZmvudwhicLXlggax1U5QtgqZX/pWovyt9 kqYh7pvU0Na9E5xwb921eIMNoJjuGQ7jGEzIqowP4sWZo/rntNT3xQPRrbz3fZ0PRwMR Bmg+YLJ42gfCMoBXyNNdW4AQSMSkpyd60xaKulrVWQqXB+3nTlbddx0GiwDDS6hLa/Id gOaQ== X-Gm-Message-State: APjAAAVWitVprxVvJMfQVXsl3LA8ovzymrziRlM9yAaE1X9EL36gu8wQ FiND8miXgFbdh5RwldQiK7lLs1jymZ1NmOev X-Received: by 2002:adf:e5ce:: with SMTP id a14mr26520284wrn.214.1574945512016; Thu, 28 Nov 2019 04:51:52 -0800 (PST) Received: from rudolphp.sr1.9esec.dev (b2b-78-94-0-50.unitymedia.biz. [78.94.0.50]) by smtp.gmail.com with ESMTPSA id j11sm22959607wrq.26.2019.11.28.04.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 04:51:51 -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 , Julius Werner , Stephen Boyd , Samuel Holland Subject: [PATCH v3 2/2] firmware: google: Expose coreboot tables over sysfs Date: Thu, 28 Nov 2019 13:50:51 +0100 Message-Id: <20191128125100.14291-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191128125100.14291-1-patrick.rudolph@9elements.com> References: <20191128125100.14291-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 -v3: - Use BIN_ATTR_RO --- Documentation/ABI/stable/sysfs-bus-coreboot | 30 +++++++++++ drivers/firmware/google/coreboot_table.c | 57 +++++++++++++++++++++ 2 files changed, 87 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..1f7329d72f54 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,60 @@ 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 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 BIN_ATTR_RO(data, 0); + +static struct bin_attribute *cb_dev_bin_attrs[] = { + &bin_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 +159,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