From patchwork Tue Apr 19 22:39:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Octavian Purdila X-Patchwork-Id: 8883691 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 13B46BF29F for ; Tue, 19 Apr 2016 22:40:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2A710202D1 for ; Tue, 19 Apr 2016 22:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39E6020260 for ; Tue, 19 Apr 2016 22:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932329AbcDSWkh (ORCPT ); Tue, 19 Apr 2016 18:40:37 -0400 Received: from mga04.intel.com ([192.55.52.120]:61700 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932516AbcDSWkJ (ORCPT ); Tue, 19 Apr 2016 18:40:09 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 19 Apr 2016 15:40:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,507,1455004800"; d="scan'208";a="88266686" Received: from mbenvenu-mobl.ger.corp.intel.com (HELO opurdila-mobl.ger.corp.intel.com) ([10.252.34.94]) by fmsmga004.fm.intel.com with ESMTP; 19 Apr 2016 15:40:05 -0700 From: Octavian Purdila To: "Rafael J. Wysocki" , Len Brown , Matt Fleming , Mark Brown , Wolfram Sang Cc: Joel Becker , linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, irina.tirdea@intel.com, Octavian Purdila Subject: [RFC PATCH v2 10/10] HACK: acpi: configfs: add unload_hanlde_path attribute for tables Date: Wed, 20 Apr 2016 01:39:08 +0300 Message-Id: <1461105548-20618-11-git-send-email-octavian.purdila@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461105548-20618-1-git-send-email-octavian.purdila@intel.com> References: <1461105548-20618-1-git-send-email-octavian.purdila@intel.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because there is no way to get a references to a table that we can use to unload a table this patch adds an attribute allows the user to attach a path to an ACPI handle to be used when unloading the table. The ACPI handle must have been loaded with the table to which attribute is part of, otherwise the unload operation will not be correct. This patch should only be used to test table unloading and removal of associated ACPI devices and should not be merged. Once the new table loading/unloading APIs make it in ACPICA we can implement table unloading properly. Signed-off-by: Octavian Purdila --- drivers/acpi/configfs.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/acpi/configfs.c b/drivers/acpi/configfs.c index 5efa8ca..7bcdfbb 100644 --- a/drivers/acpi/configfs.c +++ b/drivers/acpi/configfs.c @@ -18,6 +18,7 @@ static struct config_group *acpi_table_group; struct acpi_user_table { struct config_item cfg; struct acpi_table_header *table; + acpi_handle handle; }; static ssize_t acpi_table_data_write(struct config_item *cfg, @@ -65,14 +66,59 @@ static ssize_t acpi_table_data_write(struct config_item *cfg, CONFIGFS_BIN_ATTR_WO(acpi_table_, data, NULL, MAX_ACPI_TABLE_SIZE); +ssize_t acpi_table_unload_handle_path_show(struct config_item *item, char *page) +{ + struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL}; + struct acpi_user_table *table; + int ret; + + table = container_of(item, struct acpi_user_table, cfg); + + ret = acpi_get_name(table->handle, ACPI_FULL_PATHNAME, &path); + if (ret) + return ret; + + ret = sprintf(page, "%s\n", (char *)path.pointer); + kfree(path.pointer); + + return ret; +} + +ssize_t acpi_table_unload_handle_path_store(struct config_item *item, + const char *page, size_t count) +{ + struct acpi_user_table *table; + char *str; + + table = container_of(item, struct acpi_user_table, cfg); + + str = kmalloc(count + 1, GFP_KERNEL); + memcpy(str, page, count); + str[count] = 0; + + acpi_get_handle(NULL, strim(str), &table->handle); + + kfree(str); + + return count; +} + +CONFIGFS_ATTR(acpi_table_, unload_handle_path); + struct configfs_bin_attribute *acpi_table_bin_attrs[] = { &acpi_table_attr_data, NULL, }; +struct configfs_attribute *acpi_table_attrs[] = { + &acpi_table_attr_unload_handle_path, + NULL, +}; + static struct config_item_type acpi_table_type = { .ct_owner = THIS_MODULE, .ct_bin_attrs = acpi_table_bin_attrs, + .ct_attrs = acpi_table_attrs, }; static struct config_item *acpi_table_make_item(struct config_group *group, @@ -88,8 +134,20 @@ static struct config_item *acpi_table_make_item(struct config_group *group, return &table->cfg; } +static void acpi_table_drop_item(struct config_group *group, + struct config_item *item) +{ + struct acpi_user_table *table; + + table = container_of(item, struct acpi_user_table, cfg); + + if (table->handle) + acpi_unload_parent_table(table->handle); +} + struct configfs_group_operations acpi_table_group_ops = { .make_item = acpi_table_make_item, + .drop_item = acpi_table_drop_item, }; static struct config_item_type acpi_tables_type = {