From patchwork Tue Jul 21 13:31:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Graeme Gregory X-Patchwork-Id: 51310 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by patches.linaro.org (Postfix) with ESMTPS id CA1C420323 for ; Tue, 21 Jul 2015 13:31:36 +0000 (UTC) Received: by wgal16 with SMTP id l16sf20878240wga.2 for ; Tue, 21 Jul 2015 06:31:36 -0700 (PDT) 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=APJIciB13zu4G4q2WnxFpGgpLkNoyXjEYBtOOk0gooU=; b=Phq7w1Goj+vnVgVi3IQhEdvW82ihii8ItdTgN947RvB4jSP0AJXz9gBMPGovkhGkE0 AlhGqpyh6e9jAthH+SJL+8rK22pGI/0lAUkSbvLuIcJGHxgVgO4S0BL11Ul8LcEkk6Dz QI3/6j0K99APU8XxCXF8/sznMKWfqV9BOtz2Gn2AcXbImniOQOZxj7Qy3J5XRX1OgE/E 7UBT3XJYq/sGdcxmw10yTjafBBh82D0ttMSLw2+Ex6Fjf1sAlv9dNO7EqrkumkDH5r2o rJIK+Josvco4rC/Tn9jL9SDc4twcISMFJzL4Ki5JRck8mH3VjtlNayuQwnzPEEbSQ/0v Rk6w== X-Gm-Message-State: ALoCoQk594lfJWb+2qbZhroj9rvIpx2d0HblpYf12hFUT8l63uT/UwEgvaBq+1cNAn4b3FWdfa8i X-Received: by 10.152.27.130 with SMTP id t2mr17695732lag.2.1437485496072; Tue, 21 Jul 2015 06:31:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.103 with SMTP id kx7ls919290lac.62.gmail; Tue, 21 Jul 2015 06:31:35 -0700 (PDT) X-Received: by 10.152.121.42 with SMTP id lh10mr33703420lab.0.1437485495823; Tue, 21 Jul 2015 06:31:35 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id l6si20810185lbm.27.2015.07.21.06.31.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lahe2 with SMTP id e2so55359813lah.1 for ; Tue, 21 Jul 2015 06:31:35 -0700 (PDT) X-Received: by 10.152.5.228 with SMTP id v4mr32951950lav.36.1437485495582; Tue, 21 Jul 2015 06:31:35 -0700 (PDT) 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.7.198 with SMTP id l6csp1452615lba; Tue, 21 Jul 2015 06:31:34 -0700 (PDT) X-Received: by 10.70.8.33 with SMTP id o1mr36193389pda.88.1437485493738; Tue, 21 Jul 2015 06:31:33 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ng15si43590552pdb.208.2015.07.21.06.31.32; Tue, 21 Jul 2015 06:31:33 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932148AbbGUNbY (ORCPT + 28 others); Tue, 21 Jul 2015 09:31:24 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:34795 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754858AbbGUNbU (ORCPT ); Tue, 21 Jul 2015 09:31:20 -0400 Received: by wibud3 with SMTP id ud3so114361830wib.1 for ; Tue, 21 Jul 2015 06:31:19 -0700 (PDT) X-Received: by 10.194.238.193 with SMTP id vm1mr65727885wjc.57.1437485479420; Tue, 21 Jul 2015 06:31:19 -0700 (PDT) Received: from xora-haswell.xora.org.uk (host-92-22-78-162.as13285.net. [92.22.78.162]) by smtp.gmail.com with ESMTPSA id h9sm37096219wjx.20.2015.07.21.06.31.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jul 2015 06:31:18 -0700 (PDT) From: Graeme Gregory To: rjw@rjwysocki.net, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Graeme Gregory Subject: [RFC PATCH] ACPI: sysfs expose root tables RSDP/RSDT/XSDT Date: Tue, 21 Jul 2015 14:31:08 +0100 Message-Id: <1437485468-17107-2-git-send-email-graeme.gregory@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437485468-17107-1-git-send-email-graeme.gregory@linaro.org> References: <1437485468-17107-1-git-send-email-graeme.gregory@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: graeme.gregory@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.42 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 some architectures /dev/mem is being removed. For debug/analysis tools like FWTS/acpidump we therefore need to expose the ACPI root tables in sysfs like the other tables. Signed-off-by: Graeme Gregory --- drivers/acpi/sysfs.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c index 0876d77b..c998ea1 100644 --- a/drivers/acpi/sysfs.c +++ b/drivers/acpi/sysfs.c @@ -348,6 +348,127 @@ acpi_sysfs_table_handler(u32 event, void *table, void *context) return AE_OK; } +/* + * On some architectures /dev/mem interface is not available so for debug + * tools like FWTS, acpidump etc we will also need to export the three + * root tables RSDP, RSDT, XSDT where they exist. + */ + +struct acpi_root_table_attr { + struct bin_attribute attr; + acpi_physical_address table_addr; +}; + +static ssize_t acpi_table_show_root(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t offset, size_t count) +{ + struct acpi_root_table_attr *table_attr = + container_of(bin_attr, + struct acpi_root_table_attr, attr); + void *table; + int ret; + + table = acpi_os_map_memory(table_attr->table_addr, bin_attr->size); + + if (!table) + return -EIO; + + ret = memory_read_from_buffer(buf, count, &offset, table, + bin_attr->size); + acpi_os_unmap_memory(table, bin_attr->size); + + return ret; +} + +static int acpi_root_tables_sysfs_init(struct kobject *tables_kobj) +{ + struct acpi_root_table_attr *root_tables_attr; + struct acpi_table_rsdp *rsdp; + struct acpi_table_header *table_header = NULL; + acpi_physical_address rsdp_ptr, rsdt_ptr, xsdt_ptr; + int ret; + + rsdp_ptr = acpi_os_get_root_pointer(); + + if (!rsdp_ptr) + return -EIO; + + rsdp = acpi_os_map_memory(rsdp_ptr, sizeof(*rsdp)); + if (!rsdp) { + ret = -EIO; + goto err; + } + + root_tables_attr = kzalloc(sizeof(*root_tables_attr) * 3, GFP_KERNEL); + if (!root_tables_attr) { + ret = -ENOMEM; + goto err; + } + + root_tables_attr[0].table_addr = rsdp_ptr; + root_tables_attr[0].attr.size = sizeof(*rsdp); + root_tables_attr[0].attr.read = acpi_table_show_root; + root_tables_attr[0].attr.attr.name = "RSDP"; + root_tables_attr[0].attr.attr.mode = 0400; + + ret = sysfs_create_bin_file(tables_kobj, &root_tables_attr[0].attr); + if (ret) + goto err; + + rsdt_ptr = rsdp->rsdt_physical_address; + if (rsdt_ptr) { + table_header = acpi_os_map_memory(rsdt_ptr, + sizeof(*table_header)); + if (!table_header) { + ret = -EIO; + goto err; + } + + root_tables_attr[1].table_addr = rsdt_ptr; + root_tables_attr[1].attr.size = table_header->length; + root_tables_attr[1].attr.read = acpi_table_show_root; + root_tables_attr[1].attr.attr.name = "RSDT"; + root_tables_attr[1].attr.attr.mode = 0400; + + ret = sysfs_create_bin_file(tables_kobj, + &root_tables_attr[1].attr); + if (ret) + goto err; + acpi_os_unmap_memory(table_header, sizeof(*table_header)); + } + + xsdt_ptr = rsdp->xsdt_physical_address; + if (xsdt_ptr) { + table_header = acpi_os_map_memory(xsdt_ptr, + sizeof(*table_header)); + if (!table_header) { + ret = -EIO; + goto err; + } + + root_tables_attr[2].table_addr = xsdt_ptr; + root_tables_attr[2].attr.size = table_header->length; + root_tables_attr[2].attr.read = acpi_table_show_root; + root_tables_attr[2].attr.attr.name = "XSDT"; + root_tables_attr[2].attr.attr.mode = 0400; + + ret = sysfs_create_bin_file(tables_kobj, + &root_tables_attr[2].attr); + if (ret) + goto err; + acpi_os_unmap_memory(table_header, sizeof(*table_header)); + } + return ret; + +err: + if (rsdp) + acpi_os_map_memory(rsdp_ptr, sizeof(*rsdp)); + if (table_header) + acpi_os_unmap_memory(table_header, sizeof(*table_header)); + return ret; +} + static int acpi_tables_sysfs_init(void) { struct acpi_table_attr *table_attr; @@ -387,6 +508,8 @@ static int acpi_tables_sysfs_init(void) list_add_tail(&table_attr->node, &acpi_table_attr_list); } + acpi_root_tables_sysfs_init(tables_kobj); + kobject_uevent(tables_kobj, KOBJ_ADD); kobject_uevent(dynamic_tables_kobj, KOBJ_ADD); status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);