Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4674897ybc; Fri, 15 Nov 2019 08:18:58 -0800 (PST) X-Google-Smtp-Source: APXvYqz9boEefcg24pX48wQssFzfElegwvRVXdjk7Lz4ARW640djWRXDxKz7UOjtgBYZ0+UWKhpI X-Received: by 2002:a17:906:7750:: with SMTP id o16mr2003351ejn.224.1573834737899; Fri, 15 Nov 2019 08:18:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573834737; cv=none; d=google.com; s=arc-20160816; b=DJkJesoscd24KTcc9GTg2P0pjObBnrfdpQ5nBsdDXMsYuLbz9vqXir9GHAAv8+O7xY YV+9patDhAINgRG3x5DdVgu/b1N82r7b+WXY6hvPq8C8zOOSW2t6dT6lLmv8Aslzh9BH vwt+ltmjlxMQPs1ylMudon8YqeMPi3Zod0w91gYeDnH2zxQEkt1zxkRgVdScDwikOfiL SoWCsnbHXjLwNB31pjkbUAlS0SDgajqUTuNW+FPIZgAEdoMh92r/k110EtACn1EmVbva B6J+5KPK3cb5Z3pbRaDIfsnXwr7JqjL8Ai295N4oAJ9NtV3V5nChIDSknOMkFCbrIKHk 0yDg== 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=MVxHSx/minQx5d0tJI7s0eZgBU80i8rjqDZ6K3QTLuc=; b=ywF9Xe5gJpcievqVKwoy9pzHQxb/Tu5+J5JzLpiKwnGHzf/gPdZj8XyPFc/ZPkn0UB dg7U+aNJJ/TaTepIyk6BaJoiNai1VzvizI8PXe49Rlwc3c4XScWTbR4tLqiL91rU8Lsn gtL0evWRTS0r39RwA2naBcusHPSVdpE47QDLo4rjO1RlFAk2EdJ5XucPBlJmvz8L0oVp Z7+s10wB6akugbB2IgvaLmMOEP8tE0stocIxjrz0yF3slUw/6DLnHxiW+WreXf9QPsiC MBQfRGGiG2tjIyzsrtbAIKGRNmUURbUB0lI0k7uxxqj0ahxlD+uTZyLU8yOmICf5z6kE HTJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=PmFLvl34; 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 ca22si5868399ejb.22.2019.11.15.08.18.32; Fri, 15 Nov 2019 08:18:57 -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=PmFLvl34; 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 S1727654AbfKOQQZ (ORCPT + 99 others); Fri, 15 Nov 2019 11:16:25 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50507 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727423AbfKOQQZ (ORCPT ); Fri, 15 Nov 2019 11:16:25 -0500 Received: by mail-wm1-f68.google.com with SMTP id l17so10203776wmh.0 for ; Fri, 15 Nov 2019 08:16:23 -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=MVxHSx/minQx5d0tJI7s0eZgBU80i8rjqDZ6K3QTLuc=; b=PmFLvl34Ywer4Wi+BfDYl4JasRk9hvc+CVeCSzTbzSUY8ons28GoXPXrCaQ5fkiCo1 jcx9b+Flgnv1ERWX9hMnls1XE4KhqCoZTeuFtMlM1VVP6uIef5yX4g03j6jUBhB+LSOg 8tHjIiItg312SB8bZ7lTk2vJQAgIuFr1W4AAHP1+pR52GMXM57x8LiXVTuW/nyPytOKO gV7kZfj5gSrf8gqlcYCzA5jLbPYYX8HrzvRJIUmEzzNk0RhOqC+8RqcsDUzAKpObxxSo vXGmUx3qIazJp6jvkRPsq8A0keQ0r7zX/5243sZ+xBOQDC/5HJl2e7dnONWr26Kwc1Jm ZrKQ== 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=MVxHSx/minQx5d0tJI7s0eZgBU80i8rjqDZ6K3QTLuc=; b=IsJhNT1RPKCORpJYJiYKBdeyk389ROKqFZtQfTxNBuwzsUnM75dYBVORop6rVJ0HUF aOVyFPK4eEtxcYpZgZKSv7zRO0RVhWleV2t2QMCeZnR9CFJrMIvzig7yE63ae81ICRjB xg5B6Tbu4qs9Si89cZk4Egng7be3ZjCknWz/MdxWAgY/DiM1K0RQ9AQSs9VaTUdrerKh CejlQ6eOOCWrtb/V9ANZlrhURa/lFLrdyPc94OBfV6fIrkmy7V3bf0IB/Puo6+9BjS+E HzC99Ou2/blb3p+kzWpl/2ax4zn+KO1by+TNk9HxHlcdLdV062aVo9ToK2GR5hXtxCO4 S9qg== X-Gm-Message-State: APjAAAXxAyiUUkiq4Fm5n5UCIVLZo4GlUKKy7EVJ8p+5XyisOd4nIbEa f1OSswbvGVc4lNmAKRK6gz0Pn9Fm8H7eQ8Eg X-Received: by 2002:a1c:6405:: with SMTP id y5mr16534329wmb.175.1573834582334; Fri, 15 Nov 2019 08:16:22 -0800 (PST) Received: from rudolphp.sr1.9esec.dev (ip-94-114-101-228.unity-media.net. [94.114.101.228]) by smtp.gmail.com with ESMTPSA id o5sm11637467wrx.15.2019.11.15.08.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 08:16:21 -0800 (PST) From: patrick.rudolph@9elements.com To: linux-kernel@vger.kernel.org Cc: coreboot@coreboot.org, Patrick Rudolph , Greg Kroah-Hartman , Thomas Gleixner , Alexios Zavras , Allison Randal , Samuel Holland , Julius Werner , Stephen Boyd Subject: [PATCH 2/2] firmware: google: Expose coreboot tables over sysfs Date: Fri, 15 Nov 2019 17:15:16 +0100 Message-Id: <20191115161524.23738-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191115161524.23738-1-patrick.rudolph@9elements.com> References: <20191115161524.23738-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. 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 --- drivers/firmware/google/coreboot_table.c | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c index 8d132e4f008a..baddf28a2103 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, "%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