From patchwork Fri May 20 06:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ECB7C433F5 for ; Fri, 20 May 2022 06:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241384AbiETGLl (ORCPT ); Fri, 20 May 2022 02:11:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244942AbiETGLj (ORCPT ); Fri, 20 May 2022 02:11:39 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A70C27A812 for ; Thu, 19 May 2022 23:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027098; x=1684563098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S5b95Kaj7dMb6Y2XDMJXvWieDst0bDySoTHaHwIApcQ=; b=PYIA4gHkKfBg7ZR2mLAuSI5v+apes2WGx+hAxNQUiiGwPyiVWoGl+9a2 ZNdUqCNHXZ/bHhEquYoBcWFZsg3sLTi1fKYnI8R4Fn+NTFzY42KRPZIvW Bu7O3YmXn7UvtcYm2CyU+AgP4jHzWVtJxlRmUbR2KIuM+fj4Abi6D7N3n 6NSkD+ZMc8NLbSIwy8oWWkUV2jDtzsBjFg1r1WU0LbppNm7Zk97DzZwKt ycQItdtBLPzHoYMhunwhajmg9xwetSTh/BtQ982HkmVPX2kdJuFbuDQA9 sOY6endZd9sbYMUlBtjWq9tNzveiqNMWHkjDvbDh5q7AKPCtBGiz8NF+A A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="297813972" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="297813972" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="743339746" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:37 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id E9FE020656; Fri, 20 May 2022 09:11:34 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005ZZ-3p; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 1/8] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Date: Fri, 20 May 2022 09:11:41 +0300 Message-Id: <20220520061148.21366-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The value acpi_add_nondev_subnodes() returns is bool so change the return type of the function to match that. Fixes: 445b0eb058f5 ("ACPI / property: Add support for data-only subnodes") Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index d3173811614ec..bc9a645f8bb77 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -155,10 +155,10 @@ static bool acpi_nondev_subnode_ok(acpi_handle scope, return acpi_nondev_subnode_data_ok(handle, link, list, parent); } -static int acpi_add_nondev_subnodes(acpi_handle scope, - const union acpi_object *links, - struct list_head *list, - struct fwnode_handle *parent) +static bool acpi_add_nondev_subnodes(acpi_handle scope, + const union acpi_object *links, + struct list_head *list, + struct fwnode_handle *parent) { bool ret = false; int i; From patchwork Fri May 20 06:11:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574964 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5697BC433EF for ; Fri, 20 May 2022 06:11:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242531AbiETGLl (ORCPT ); Fri, 20 May 2022 02:11:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241384AbiETGLj (ORCPT ); Fri, 20 May 2022 02:11:39 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1A5B7E1FE for ; Thu, 19 May 2022 23:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027098; x=1684563098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1+u3D5272MmR3cXbcceeLW6iNFLPmVc+zRjoajCHDgI=; b=ixlXTEXMw6/7tBQtjfIR5GPrlThhjGnd4PT1w/g6gdwFv3ur2Cu0HL0s CKffgdSpLpw2gcT0nKMdAY1TiLO7OUuR2vdJ6F56pHKVvryA0N9VmWtUF IN2S8hHAiEL6MA6daPK+j1j4UGtW8t92byp+qS82cududDABHeYLVVcaE IBI6I6slDzqq8d9xWYbYvZj7Gf3KWq2saGUHzynLsXTkta3qHp21arWo0 GkGIuwOWbHWXsqpNQlFu5/MEbjOhnEXX6jj86Kluu2urg8yisx/R1t+4m If0e6DGSebnzUIAWYsROpY5qsgIfry7iqXQ0k4XmjLK37Kb9nvB+tE6f2 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="253020031" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="253020031" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="557306528" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:37 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 0194E20680; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zc-5H; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 2/8] ACPI: property: Tie data nodes to acpi handles Date: Fri, 20 May 2022 09:11:42 +0300 Message-Id: <20220520061148.21366-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org ACPICA allows associating additional information (i.e. pointers with specific tag) to acpi_handles. The acpi_device's are associated to acpi_handle's in acpi_tie_acpi_dev() in scan.c, do the same here for the _DSD data nodes. This allows direct data node references in properties, implemented later on in the series. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 42 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index bc9a645f8bb77..f8c83ee6c8d59 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -340,6 +340,43 @@ acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid, return props; } +static void acpi_nondev_subnode_tag(acpi_handle handle, void *context) +{ +} + +static void acpi_untie_nondev_subnodes(struct acpi_device_data *data) +{ + struct acpi_data_node *dn; + + list_for_each_entry(dn, &data->subnodes, sibling) { + acpi_detach_data(dn->handle, acpi_nondev_subnode_tag); + + acpi_untie_nondev_subnodes(&dn->data); + } +} + +static int acpi_tie_nondev_subnodes(struct acpi_device_data *data) +{ + struct acpi_data_node *dn; + + list_for_each_entry(dn, &data->subnodes, sibling) { + acpi_status status; + int ret; + + status = acpi_attach_data(dn->handle, acpi_nondev_subnode_tag, dn); + if (ACPI_FAILURE(status)) { + acpi_handle_err(dn->handle, "Can't tag data node\n"); + return 0; + } + + ret = acpi_tie_nondev_subnodes(&dn->data); + if (ret) + return ret; + } + + return 0; +} + static bool acpi_extract_properties(const union acpi_object *desc, struct acpi_device_data *data) { @@ -419,7 +456,9 @@ void acpi_init_properties(struct acpi_device *adev) &adev->data, acpi_fwnode_handle(adev))) adev->data.pointer = buf.pointer; - if (!adev->data.pointer) { + if (!adev->data.pointer || + acpi_tie_nondev_subnodes(&adev->data) < 0) { + acpi_untie_nondev_subnodes(&adev->data); acpi_handle_debug(adev->handle, "Invalid _DSD data, skipping\n"); ACPI_FREE(buf.pointer); } @@ -462,6 +501,7 @@ static void acpi_destroy_nondev_subnodes(struct list_head *list) void acpi_free_properties(struct acpi_device *adev) { + acpi_untie_nondev_subnodes(&adev->data); acpi_destroy_nondev_subnodes(&adev->data.subnodes); ACPI_FREE((void *)adev->data.pointer); adev->data.of_compatible = NULL; From patchwork Fri May 20 06:11:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 664A1C4332F for ; Fri, 20 May 2022 06:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244942AbiETGLm (ORCPT ); Fri, 20 May 2022 02:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236617AbiETGLj (ORCPT ); Fri, 20 May 2022 02:11:39 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75EDE75218 for ; Thu, 19 May 2022 23:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027098; x=1684563098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YoOjvt6ZWy+Epk5pxRi/nkuhj8uwUo7L7f23DdSGlTE=; b=dUGr1SF1hS2h+hkRSwXLh6uPPWSAvKFDtmape7OcGWINe5A0KLSgnYC4 l19qrhRLKchgRO9bwMdoEAguJjk18eppCqAbtJygirOQ1eBmobAtyZf1+ 96q7RD5iy4C6cNe16zB7vycyUHTaA8tQki+mKNVV0I9TLwy61iocyHZr8 slqWBxObVV8ccNbSHm/YxWi9UhesjhaofbbVxpQDEfJBmBB0Js5w6hgcF SkI2KfVQ7hVAoqYW2aUIQudt+8g42PI4Zh4SJXt5Z7sUFS+ugcPbM3kjt 1t5qeAnVXj30Zf9dNoPYLy+QvuAbXRxoQVrd1xqEhkNb1gPk+gmNl2kn4 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="260084995" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="260084995" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="606876155" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:37 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 0C3C220BAD; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zf-6q; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 3/8] ACPI: property: Use acpi_object_type consistently in property ref parsing Date: Fri, 20 May 2022 09:11:43 +0300 Message-Id: <20220520061148.21366-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The type of union acpi_object field type is acpi_object_type. Use that instead of int. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index f8c83ee6c8d59..b36cb7e36e420 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -793,7 +793,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, * nor integer, return an error, we can't parse it. */ for (i = 0; element + i < end && i < num_args; i++) { - int type = element[i].type; + acpi_object_type type = element[i].type; if (type == ACPI_TYPE_LOCAL_REFERENCE) break; From patchwork Fri May 20 06:11:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E15B0C433EF for ; Fri, 20 May 2022 06:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236617AbiETGLo (ORCPT ); Fri, 20 May 2022 02:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244128AbiETGLj (ORCPT ); Fri, 20 May 2022 02:11:39 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD9BC7CB19 for ; Thu, 19 May 2022 23:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027098; x=1684563098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zi5cjQFC1838grmpR4io2PGlZVTBTN4P4rakv1O9iwM=; b=LNpFUnv7GgMEZ2DZ0h1UCttT5K157OUm4PUccrB2N3fRs9HJ5JxVF85w UsQ+c65LSQSZ3fCMoHwm30+xdUnBfj02dWdSQzzrrrtBq4H844JyEzb7o 8UuWXtOXKog9puLBTb8+82FXi54YlF3GzbPzvI8bKR7E+02oq6L4z7dN7 0GMFfpK1b9EdrRd/E8vflJEgi0u1YZIm5yXWnWj1BbtC1Lo0/r7WGZHsK 6DgTwvSBnunFIuuzs4UqnBaeCBAY1PDYAGvtqObPO6s3pbLGOsWpU/FC6 jjq+igI4C3IP5cpmH0zHeb2RN/28fINksUaBVTqmsT5NR2zibZMiTULeE g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333128675" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333128675" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="640173112" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:37 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 17F9B20C9E; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zi-8B; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 4/8] ACPI: property: Move property ref argument parsing into a new function Date: Fri, 20 May 2022 09:11:44 +0300 Message-Id: <20220520061148.21366-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Split out property reference argument parsing out of the __acpi_node_get_property_reference() function into a new one, acpi_get_ref_args(). The new function will be needed also for parsing string references soon. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 105 +++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index b36cb7e36e420..dd6cce955ee28 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -673,6 +673,60 @@ acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, return NULL; } +static int +acpi_get_ref_args(struct fwnode_reference_args *args, + struct fwnode_handle *ref_fwnode, + const union acpi_object **element, + const union acpi_object *end, size_t num_args) +{ + u32 nargs = 0, i; + + /* + * Find the referred data extension node under the + * referred device node. + */ + for (; *element < end && (*element)->type == ACPI_TYPE_STRING; + (*element)++) { + const char *child_name = (*element)->string.pointer; + + ref_fwnode = acpi_fwnode_get_named_child_node(ref_fwnode, + child_name); + if (!ref_fwnode) + return -EINVAL; + } + + /* + * Assume the following integer elements are all args. Stop counting on + * the first reference or end of the package arguments. In case of + * neither reference, nor integer, return an error, we can't parse it. + */ + for (i = 0; (*element) + i < end && i < num_args; i++) { + acpi_object_type type = (*element)[i].type; + + if (type == ACPI_TYPE_LOCAL_REFERENCE) + break; + + if (type == ACPI_TYPE_INTEGER) + nargs++; + else + return -EINVAL; + } + + if (nargs > NR_FWNODE_REFERENCE_ARGS) + return -EINVAL; + + if (args) { + args->fwnode = ref_fwnode; + args->nargs = nargs; + for (i = 0; i < nargs; i++) + args->args[i] = (*element)[i].integer.value; + } + + (*element) += nargs; + + return 0; +} + /** * __acpi_node_get_property_reference - returns handle to the referenced object * @fwnode: Firmware node to get the property from @@ -761,61 +815,22 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, end = element + obj->package.count; while (element < end) { - u32 nargs, i; - if (element->type == ACPI_TYPE_LOCAL_REFERENCE) { - struct fwnode_handle *ref_fwnode; - device = acpi_fetch_acpi_dev(element->reference.handle); if (!device) return -EINVAL; - nargs = 0; element++; - /* - * Find the referred data extension node under the - * referred device node. - */ - for (ref_fwnode = acpi_fwnode_handle(device); - element < end && element->type == ACPI_TYPE_STRING; - element++) { - ref_fwnode = acpi_fwnode_get_named_child_node( - ref_fwnode, element->string.pointer); - if (!ref_fwnode) - return -EINVAL; - } - - /* - * Assume the following integer elements are all args. - * Stop counting on the first reference or end of the - * package arguments. In case of neither reference, - * nor integer, return an error, we can't parse it. - */ - for (i = 0; element + i < end && i < num_args; i++) { - acpi_object_type type = element[i].type; - - if (type == ACPI_TYPE_LOCAL_REFERENCE) - break; - if (type == ACPI_TYPE_INTEGER) - nargs++; - else - return -EINVAL; - } - - if (nargs > NR_FWNODE_REFERENCE_ARGS) - return -EINVAL; - - if (idx == index) { - args->fwnode = ref_fwnode; - args->nargs = nargs; - for (i = 0; i < nargs; i++) - args->args[i] = element[i].integer.value; + ret = acpi_get_ref_args(idx == index ? args : NULL, + acpi_fwnode_handle(device), + &element, end, num_args); + if (ret < 0) + return ret; + if (idx == index) return 0; - } - element += nargs; } else if (element->type == ACPI_TYPE_INTEGER) { if (idx == index) return -ENOENT; From patchwork Fri May 20 06:11:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C35FAC433EF for ; Fri, 20 May 2022 06:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345730AbiETGLs (ORCPT ); Fri, 20 May 2022 02:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345747AbiETGLm (ORCPT ); Fri, 20 May 2022 02:11:42 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7770199680 for ; Thu, 19 May 2022 23:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027101; x=1684563101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DxZC8syyR9C+xK5/dPtjALY1tEDptkd13YlvwScvvMM=; b=ZNjsn+qz9SG07Bhz3+Vr2GDl1KKEZqxzU1Tr4roryYBU/+jRPKm3Zilh ZYM6DKSceTGEGYXf3aoiL+MCJS+saP0mhOf0kLe9xy67wlGuOB5OYf/Y3 J6nWKH2PuJSMomFTP5l0EV58cAenlX2EJsvXoW4Hf8AknIr2XU5178yIS GpQkeyIbukvF9fWG1NXYgtq/ER0SBiVzUOKCnDUnQGThrSMoznFkZINi+ pb/dwVLjLi9skK8KRHQWDdOzD2AG7EAMJ8YTG+qfPqrSi0gDItpdFFiAp cKGRZn//BhGUxS9hgP1UjqbWpC8viCFFLOnF+GM0iZ0HIK+zjmdxNm+0X Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="333128686" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="333128686" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:41 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570642281" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 24BC220E17; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zl-9s; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 5/8] ACPI: property: Switch node property referencing from ifs to a switch Date: Fri, 20 May 2022 09:11:45 +0300 Message-Id: <20220520061148.21366-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org __acpi_node_get_property_reference() uses a series of if () statements for testing the same variable. There's soon going to be one more value to be tested. Switch to use switch() instead. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index dd6cce955ee28..a8e8a214a524f 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -780,11 +780,9 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, if (ret) return ret == -EINVAL ? -ENOENT : -EINVAL; - /* - * The simplest case is when the value is a single reference. Just - * return that reference then. - */ - if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) { + switch (obj->type) { + case ACPI_TYPE_LOCAL_REFERENCE: + /* Plain single reference without arguments. */ if (index) return -ENOENT; @@ -795,19 +793,21 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, args->fwnode = acpi_fwnode_handle(device); args->nargs = 0; return 0; + case ACPI_TYPE_PACKAGE: + /* + * If it is not a single reference, then it is a package of + * references followed by number of ints as follows: + * + * Package () { REF, INT, REF, INT, INT } + * + * The index argument is then used to determine which reference + * the caller wants (along with the arguments). + */ + break; + default: + return -EINVAL; } - /* - * If it is not a single reference, then it is a package of - * references followed by number of ints as follows: - * - * Package () { REF, INT, REF, INT, INT } - * - * The index argument is then used to determine which reference - * the caller wants (along with the arguments). - */ - if (obj->type != ACPI_TYPE_PACKAGE) - return -EINVAL; if (index >= obj->package.count) return -ENOENT; @@ -815,7 +815,8 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, end = element + obj->package.count; while (element < end) { - if (element->type == ACPI_TYPE_LOCAL_REFERENCE) { + switch (element->type) { + case ACPI_TYPE_LOCAL_REFERENCE: device = acpi_fetch_acpi_dev(element->reference.handle); if (!device) return -EINVAL; @@ -831,11 +832,13 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, if (idx == index) return 0; - } else if (element->type == ACPI_TYPE_INTEGER) { + break; + case ACPI_TYPE_INTEGER: if (idx == index) return -ENOENT; element++; - } else { + break; + default: return -EINVAL; } From patchwork Fri May 20 06:11:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D438C433EF for ; Fri, 20 May 2022 06:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345762AbiETGLu (ORCPT ); Fri, 20 May 2022 02:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345749AbiETGLn (ORCPT ); Fri, 20 May 2022 02:11:43 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 566CE9968E for ; Thu, 19 May 2022 23:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027102; x=1684563102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3P0dUciLnGB0TF3Km1s18i8l/6YKxsugCmYC0o7NSlY=; b=PaNXLzunW3YV8QoMrUqMzwcMJgnhIaZwXGVJ+5ov/xlZlxxpsL2DD6IS l/qTVCYuknf3UM9J13DuRVq/XEE1kurSKZ6AwDkxmYAyX5Q0mXtpnKwnr +SGu4tj2+pHNe4w0zRdKm35Cj15IBL7yfHslz5JNMWzrwi5iVgL2LUEGK ESai4dLsvjlAX/QY5iloTCuGkl5ZB3W5UnAq7RZ7DxI9N+BShb7nZ4pzC r4OvMl0/JtFIFrWVQoYGE21dL+Kkhx0OQsu9wywkOIfqRFlS55nNR13mD u6iDv18VtzrFEJsC2I/mH9+rpCuLKzvhlWe/46VDsbHl4fj44mbSHZG1f w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="252390965" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="252390965" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:41 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="546518553" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 2E8CA20F37; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zo-BU; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 6/8] ACPI: property: Unify integer value reading functions Date: Fri, 20 May 2022 09:11:46 +0300 Message-Id: <20220520061148.21366-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Unify functions reading ACPI property integer values into a single macro, and call that macro to generate the functions for each bit depth. Also use size_t for the counter instead of int. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 79 +++++++++++------------------------------ 1 file changed, 20 insertions(+), 59 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index a8e8a214a524f..8449479e18442 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -910,67 +910,28 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data, return ret; } -static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val, - size_t nval) -{ - int i; - - for (i = 0; i < nval; i++) { - if (items[i].type != ACPI_TYPE_INTEGER) - return -EPROTO; - if (items[i].integer.value > U8_MAX) - return -EOVERFLOW; - - val[i] = items[i].integer.value; - } - return 0; -} - -static int acpi_copy_property_array_u16(const union acpi_object *items, - u16 *val, size_t nval) -{ - int i; - - for (i = 0; i < nval; i++) { - if (items[i].type != ACPI_TYPE_INTEGER) - return -EPROTO; - if (items[i].integer.value > U16_MAX) - return -EOVERFLOW; - - val[i] = items[i].integer.value; - } - return 0; -} - -static int acpi_copy_property_array_u32(const union acpi_object *items, - u32 *val, size_t nval) -{ - int i; - - for (i = 0; i < nval; i++) { - if (items[i].type != ACPI_TYPE_INTEGER) - return -EPROTO; - if (items[i].integer.value > U32_MAX) - return -EOVERFLOW; - - val[i] = items[i].integer.value; +#define DECLARE_ACPI_PROPERTY_COPY(bits) \ + static int \ + acpi_copy_property_array_u##bits(const union acpi_object *items, \ + u##bits *val, size_t nval) \ + { \ + size_t i; \ + \ + for (i = 0; i < nval; i++) { \ + if (items[i].type != ACPI_TYPE_INTEGER) \ + return -EPROTO; \ + if (items[i].integer.value > U##bits##_MAX) \ + return -EOVERFLOW; \ + \ + val[i] = items[i].integer.value; \ + } \ + return 0; \ } - return 0; -} -static int acpi_copy_property_array_u64(const union acpi_object *items, - u64 *val, size_t nval) -{ - int i; - - for (i = 0; i < nval; i++) { - if (items[i].type != ACPI_TYPE_INTEGER) - return -EPROTO; - - val[i] = items[i].integer.value; - } - return 0; -} +DECLARE_ACPI_PROPERTY_COPY(8) +DECLARE_ACPI_PROPERTY_COPY(16) +DECLARE_ACPI_PROPERTY_COPY(32) +DECLARE_ACPI_PROPERTY_COPY(64) static int acpi_copy_property_array_string(const union acpi_object *items, char **val, size_t nval) From patchwork Fri May 20 06:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23111C433F5 for ; Fri, 20 May 2022 06:11:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345747AbiETGLt (ORCPT ); Fri, 20 May 2022 02:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345738AbiETGLm (ORCPT ); Fri, 20 May 2022 02:11:42 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635B5994FC for ; Thu, 19 May 2022 23:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027101; x=1684563101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pDR7CZmGTQW30+xrsUCUoG+ozXrT8dpbp96ohMiKRjY=; b=FqXWFA6HNZWd2+dMKxqTjiJ8nAyJhPs0PBr6ivWrd7wsUsr+NLLK3aIj p6w7mFvBh43iT8SBa/QDCza5mUTYug0pSXAD6lv6hTv0AOqfkxnTrRqfu 3p09zVWHG4drHV7zbxx+dxBpD+w0Y7MLjoJf+pRUozPNZKyI2716Dazqn +ynxNpVCW3rk//giPCARxsfWK5ZX1A/H3tAzbgU0aVk8ySU3dMRUqgM8J 1sxEzcVyxGxG+n/nBEdiqOloxn2x4LdDBL+krCbPPG/nG6VX4Pu1BxTjr uuHg0qtxSMgCYCy2/RpYjs6QrFHhnM3D6QLjkZWmPiNPbI4XRtTZhbcN4 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="260085002" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="260085002" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:41 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="662108587" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:39 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 3C2A820F4E; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zs-D7; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 7/8] ACPI: property: Add support for parsing buffer property UUID Date: Fri, 20 May 2022 09:11:47 +0300 Message-Id: <20220520061148.21366-8-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add support for newly added buffer property UUID, as defined in the DSD guide. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 141 ++++++++++++++++++++++++++++++++++++---- include/acpi/acpi_bus.h | 3 +- include/linux/acpi.h | 2 +- 3 files changed, 131 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 8449479e18442..93157af151c9b 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -55,14 +55,19 @@ static const guid_t ads_guid = GUID_INIT(0xdbb8e3e6, 0x5886, 0x4ba6, 0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b); +static const guid_t buffer_prop_guid = + GUID_INIT(0xedb12dd0, 0x363d, 0x4085, + 0xa3, 0xd2, 0x49, 0x52, 0x2c, 0xa1, 0x60, 0xc4); + static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, - const union acpi_object *desc, + union acpi_object *desc, struct acpi_device_data *data, struct fwnode_handle *parent); -static bool acpi_extract_properties(const union acpi_object *desc, +static bool acpi_extract_properties(acpi_handle handle, + union acpi_object *desc, struct acpi_device_data *data); -static bool acpi_nondev_subnode_extract(const union acpi_object *desc, +static bool acpi_nondev_subnode_extract(union acpi_object *desc, acpi_handle handle, const union acpi_object *link, struct list_head *list, @@ -81,7 +86,7 @@ static bool acpi_nondev_subnode_extract(const union acpi_object *desc, INIT_LIST_HEAD(&dn->data.properties); INIT_LIST_HEAD(&dn->data.subnodes); - result = acpi_extract_properties(desc, &dn->data); + result = acpi_extract_properties(handle, desc, &dn->data); if (handle) { acpi_handle scope; @@ -156,7 +161,7 @@ static bool acpi_nondev_subnode_ok(acpi_handle scope, } static bool acpi_add_nondev_subnodes(acpi_handle scope, - const union acpi_object *links, + union acpi_object *links, struct list_head *list, struct fwnode_handle *parent) { @@ -164,7 +169,7 @@ static bool acpi_add_nondev_subnodes(acpi_handle scope, int i; for (i = 0; i < links->package.count; i++) { - const union acpi_object *link, *desc; + union acpi_object *link, *desc; acpi_handle handle; bool result; @@ -204,7 +209,7 @@ static bool acpi_add_nondev_subnodes(acpi_handle scope, } static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, - const union acpi_object *desc, + union acpi_object *desc, struct acpi_device_data *data, struct fwnode_handle *parent) { @@ -212,7 +217,8 @@ static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, /* Look for the ACPI data subnodes GUID. */ for (i = 0; i < desc->package.count; i += 2) { - const union acpi_object *guid, *links; + const union acpi_object *guid; + union acpi_object *links; guid = &desc->package.elements[i]; links = &desc->package.elements[i + 1]; @@ -325,7 +331,7 @@ static bool acpi_is_property_guid(const guid_t *guid) struct acpi_device_properties * acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid, - const union acpi_object *properties) + union acpi_object *properties) { struct acpi_device_properties *props; @@ -377,7 +383,103 @@ static int acpi_tie_nondev_subnodes(struct acpi_device_data *data) return 0; } -static bool acpi_extract_properties(const union acpi_object *desc, +static void acpi_data_add_buffer_props(acpi_handle handle, + struct acpi_device_data *data, + union acpi_object *properties) +{ + struct acpi_device_properties *props; + union acpi_object *package; + size_t alloc_size; + unsigned int i; + u32 *count; + + if (check_mul_overflow((size_t)properties->package.count, + sizeof(*package) + sizeof(void *), + &alloc_size) || + check_add_overflow(sizeof(*props) + sizeof(*package), alloc_size, + &alloc_size)) { + acpi_handle_warn(handle, + "can't allocate memory for %u buffer props", + properties->package.count); + return; + } + + props = kvzalloc(alloc_size, GFP_KERNEL); + if (!props) + return; + + props->guid = &buffer_prop_guid; + props->bufs = (void *)(props + 1); + props->properties = (void *)(props->bufs + properties->package.count); + + /* Outer package */ + package = props->properties; + package->type = ACPI_TYPE_PACKAGE; + package->package.elements = package + 1; + count = &package->package.count; + *count = 0; + + /* Inner packages */ + package++; + + for (i = 0; i < properties->package.count; i++) { + struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER }; + union acpi_object *property = &properties->package.elements[i]; + union acpi_object *prop, *obj, *buf_obj; + acpi_status status; + + if (property->type != ACPI_TYPE_PACKAGE || + property->package.count != 2) { + acpi_handle_warn(handle, + "buffer property %u has %u entries\n", + i, property->package.count); + continue; + } + + prop = &property->package.elements[0]; + obj = &property->package.elements[1]; + + if (prop->type != ACPI_TYPE_STRING || + obj->type != ACPI_TYPE_STRING) { + acpi_handle_warn(handle, + "wrong object types %u and %u\n", + prop->type, obj->type); + continue; + } + + status = acpi_evaluate_object_typed(handle, obj->string.pointer, + NULL, &buf, + ACPI_TYPE_BUFFER); + if (ACPI_FAILURE(status)) { + acpi_handle_warn(handle, + "can't evaluate \"%s\" as buffer\n", + obj->string.pointer); + continue; + } + + package->type = ACPI_TYPE_PACKAGE; + package->package.elements = prop; + package->package.count = 2; + + buf_obj = buf.pointer; + + /* Replace the string object with a buffer object */ + obj->type = ACPI_TYPE_BUFFER; + obj->buffer.length = buf_obj->buffer.length; + obj->buffer.pointer = buf_obj->buffer.pointer; + + props->bufs[i] = buf.pointer; + package++; + (*count)++; + } + + if (*count) + list_add(&props->list, &data->properties); + else + kvfree(props); +} + +static bool acpi_extract_properties(acpi_handle scope, union acpi_object *desc, struct acpi_device_data *data) { int i; @@ -387,7 +489,8 @@ static bool acpi_extract_properties(const union acpi_object *desc, /* Look for the device properties GUID. */ for (i = 0; i < desc->package.count; i += 2) { - const union acpi_object *guid, *properties; + const union acpi_object *guid; + union acpi_object *properties; guid = &desc->package.elements[i]; properties = &desc->package.elements[i + 1]; @@ -401,6 +504,12 @@ static bool acpi_extract_properties(const union acpi_object *desc, properties->type != ACPI_TYPE_PACKAGE) break; + if (guid_equal((guid_t *)guid->buffer.pointer, + &buffer_prop_guid)) { + acpi_data_add_buffer_props(scope, data, properties); + continue; + } + if (!acpi_is_property_guid((guid_t *)guid->buffer.pointer)) continue; @@ -447,7 +556,7 @@ void acpi_init_properties(struct acpi_device *adev) if (ACPI_FAILURE(status)) goto out; - if (acpi_extract_properties(buf.pointer, &adev->data)) { + if (acpi_extract_properties(adev->handle, buf.pointer, &adev->data)) { adev->data.pointer = buf.pointer; if (acpi_of) acpi_init_of_compatible(adev); @@ -477,8 +586,14 @@ static void acpi_free_device_properties(struct list_head *list) struct acpi_device_properties *props, *tmp; list_for_each_entry_safe(props, tmp, list, list) { + u32 i; + list_del(&props->list); - kfree(props); + /* Buffer data properties were separately allocated */ + if (props->bufs) + for (i = 0; i < props->properties->package.count; i++) + ACPI_FREE(props->bufs[i]); + kvfree(props); } } diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 772590e2eddb8..d5c60537982d8 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -344,8 +344,9 @@ struct acpi_device_physical_node { struct acpi_device_properties { const guid_t *guid; - const union acpi_object *properties; + union acpi_object *properties; struct list_head list; + void **bufs; }; /* ACPI Device Specific Data (_DSD) */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index fadda404bcc9b..2213a8f046571 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1201,7 +1201,7 @@ static inline bool acpi_dev_has_props(const struct acpi_device *adev) struct acpi_device_properties * acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid, - const union acpi_object *properties); + union acpi_object *properties); int acpi_node_prop_get(const struct fwnode_handle *fwnode, const char *propname, void **valptr); From patchwork Fri May 20 06:11:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 574564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B803DC433F5 for ; Fri, 20 May 2022 06:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345613AbiETGLp (ORCPT ); Fri, 20 May 2022 02:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345730AbiETGLm (ORCPT ); Fri, 20 May 2022 02:11:42 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A466980AB for ; Thu, 19 May 2022 23:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653027101; x=1684563101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bPXXKavxL+d6+YbI5ot0vxwKxtnOjhjq2wIhHY2Abec=; b=NLJNP6UND89JGaVEs4A5HKJ5MQV0yN9+mnOqt5sDuJo/b0woTmMlSkIy UXh+XboRoZf7r9YL2i2T9H8UgNJS65hpEDSyNR9bolkyL0WCFpegXNsUV CmFugBPJgptHPvTxEBK3pBUgnODI5kPAa8KrxIU8mXiQFgA4x2qCTK4zA gJilHapAleSsX+HeKHGUlYf5WdM2nNOKaNCawSvLzcJk9TrdTB1PQSz4F dHWK+34UamAjb9Qgp/zC2A5kbHVVw1HKRMy8oi9fy78hDJi0rihpsSNp9 sf/4a+sgiTsiTvnt2VJ5ynDQLm1Piaiz9BAS0Ewb072MUqlahNB7/zcE5 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="253020036" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="253020036" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:41 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="627996999" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 23:11:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 46F4120FA1; Fri, 20 May 2022 09:11:35 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nrvrZ-0005Zw-Ef; Fri, 20 May 2022 09:11:49 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v2 8/8] ACPI: property: Read buffer properties as integers Date: Fri, 20 May 2022 09:11:48 +0300 Message-Id: <20220520061148.21366-9-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520061148.21366-1-sakari.ailus@linux.intel.com> References: <20220520061148.21366-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Instead of adding a new property type, read buffer properties as integers. Even though the internal representation in ACPI is different, the data type is the same (byte) than on 8-bit integers. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 93157af151c9b..e94dc4dbbf627 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1033,6 +1033,10 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data, size_t i; \ \ for (i = 0; i < nval; i++) { \ + if (items->type == ACPI_TYPE_BUFFER) { \ + val[i] = items->buffer.pointer[i]; \ + continue; \ + } \ if (items[i].type != ACPI_TYPE_INTEGER) \ return -EPROTO; \ if (items[i].integer.value > U##bits##_MAX) \ @@ -1088,18 +1092,40 @@ static int acpi_data_prop_read(const struct acpi_device_data *data, } ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj); + if (ret && proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) + ret = acpi_data_get_property(data, propname, ACPI_TYPE_BUFFER, + &obj); if (ret) return ret; - if (!val) + if (!val) { + if (obj->type == ACPI_TYPE_BUFFER) + return obj->buffer.length; + return obj->package.count; + } - if (proptype != DEV_PROP_STRING && nval > obj->package.count) - return -EOVERFLOW; + switch (proptype) { + case DEV_PROP_STRING: + break; + case DEV_PROP_U8 ... DEV_PROP_U64: + if (obj->type == ACPI_TYPE_BUFFER) { + if (nval <= obj->buffer.length) + break; + return -EOVERFLOW; + } + fallthrough; + default: + if (nval > obj->package.count) + return -EOVERFLOW; + } if (nval == 0) return -EINVAL; - items = obj->package.elements; + if (obj->type != ACPI_TYPE_BUFFER) + items = obj->package.elements; + else + items = obj; switch (proptype) { case DEV_PROP_U8: