From patchwork Mon Jul 11 11:25:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589855 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 2C33DC433EF for ; Mon, 11 Jul 2022 11:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbiGKLg4 (ORCPT ); Mon, 11 Jul 2022 07:36:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231496AbiGKLgi (ORCPT ); Mon, 11 Jul 2022 07:36:38 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EAFF8AB13 for ; Mon, 11 Jul 2022 04:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538644; x=1689074644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WvVYEfjiHVi/nihMsg112ut3JOPPn8HoWlDQ3tjdcDY=; b=YrBDjllr4WjP/HpZrt3ZwFJ4Ccfo2ui/bQ+fntdkJ4k9CNf5nlPWhm5k 3L3ncz0IIj0rdCr2ZUGujsQr7mtU7zAfvGkVY4MOYE40kiaYeup8ZUxfQ 2s8jLDyWhOYMZ9wqEqgsLZZnbFzWWWdKV4iyd7HmeoxFxWMlBWUePvwqL rhHoRQXmHJNk9rZEt4rZiQBEg1CByzQI2OwM9QNX+PPpTZXmV9c80bNK1 xbab70hNRwKAHi3elmUUIXDfj+QkAeGrQsajT/v7rdXJJwIpbNLcO6SEU 7fmXAeBRCg2/pUFnwGOQ564u36p/KBgcy0vUH+eeH/DH0tejrVpqsiFhE Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="282186964" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="282186964" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="840973460" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:00 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id D98892073E; Mon, 11 Jul 2022 14:23:57 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYR-8Y; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 1/8] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Date: Mon, 11 Jul 2022 14:25:59 +0300 Message-Id: <20220711112606.3050368-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 Reviewed-by: Andy Shevchenko --- 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 e764f9ac9cf8f..6d698f3f83a0a 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 Mon Jul 11 11:26:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589853 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 B4088C43334 for ; Mon, 11 Jul 2022 11:37:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbiGKLhR (ORCPT ); Mon, 11 Jul 2022 07:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231492AbiGKLgy (ORCPT ); Mon, 11 Jul 2022 07:36:54 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469418CC88 for ; Mon, 11 Jul 2022 04:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538654; x=1689074654; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dgHYjxjaZ22vidNEa9JBIfWnldQrAuv7O6HrKbbOWWs=; b=UDWc8U6pJ7JaqKLj0Wy7Qa6lVvpboeYkqtpNbAhVRBs0owr5z4py8CzZ CA63jwEafDILQh5SI2cZ/gw0bbRn9GXyktwC4aGqIm4LRgT43bbpcSyRm RhxrUWNOzrzDiuEFME+pw4aMH/WB5VbzP6hEL++bhRXRngH9QXvK9/B0F j4ZgMKr+MpXNenDiXfjpyEsNcQk4uBTGcd92z0yMuWUf+0ax6PZWelqez c9TA7kku2pYVWH71UcoY1Suz3K+W5HXeviDS0+dn4iRgOLYYRCgO+mxW+ szCgS/921Ubhw+k+bJVOeodJw5djJFF5z+dbVZpBLhODxYexEjGcpY0XB Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="310239433" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="310239433" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="592221522" 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; 11 Jul 2022 04:23:59 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id E445E20861; Mon, 11 Jul 2022 14:23:57 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYU-9z; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 2/8] ACPI: property: Tie data nodes to acpi handles Date: Mon, 11 Jul 2022 14:26:00 +0300 Message-Id: <20220711112606.3050368-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 6d698f3f83a0a..08b5292d2f89b 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 bool 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; + bool 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 false; + } + + ret = acpi_tie_nondev_subnodes(&dn->data); + if (!ret) + return ret; + } + + return true; +} + 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)) { + 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 Mon Jul 11 11:26:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589406 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 A70ABC43334 for ; Mon, 11 Jul 2022 11:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbiGKLgz (ORCPT ); Mon, 11 Jul 2022 07:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiGKLgi (ORCPT ); Mon, 11 Jul 2022 07:36:38 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A1C28AB07 for ; Mon, 11 Jul 2022 04:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538644; x=1689074644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RuUud+uK31dex1m6iS8IIrvWzluL4paahSNSvfsne1o=; b=QaTksEVyGjgzgHl4rVF99Gcw9PaAcoN9NPK+gsTiE31RziL0I0FAHXVX quY+Bq1xdqeFCI3sgEqpVqOq8dJgTedLGsTx2LHjpAaO/2xi3FkJXLbU4 cIEhp5is7RLek14N2s73iiRMMO5YvyO6Ev/zWqRMxO9wNyQnH3o9MiGDr b6S0vJJAxOin4bPa9BiezN+DVVZug5EfsrToac3ok+NFbe6OGdiNG9dxl aZWWDhUEaEqCymadkhY2PjXiIBJlT1p9RWXJAAN9og0dDqvyXB3lgmFeO QmhlYPPqpglGyNdv8iBbr8oUndvk8kYlp2ML/2xHKjUqrbZG8C9YuORnb w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="282186965" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="282186965" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="840973462" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:00 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id EEF0C21AA1; Mon, 11 Jul 2022 14:23:57 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYX-BW; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 3/8] ACPI: property: Use acpi_object_type consistently in property ref parsing Date: Mon, 11 Jul 2022 14:26:01 +0300 Message-Id: <20220711112606.3050368-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 Reviewed-by: Andy Shevchenko --- 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 08b5292d2f89b..8d757ca2a58f3 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 Mon Jul 11 11:26:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589403 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 12F48C433EF for ; Mon, 11 Jul 2022 11:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231553AbiGKLhS (ORCPT ); Mon, 11 Jul 2022 07:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbiGKLgy (ORCPT ); Mon, 11 Jul 2022 07:36:54 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0E248CC83 for ; Mon, 11 Jul 2022 04:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538653; x=1689074653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QpHao9gHcDm8aajq6jUIYt3R7xeDPpVj8JfzaffUFnw=; b=Ik+czpxrKSXGGOmQRMtRhNScEAfP2BYZcK+UPuvrEdON0YOUX2kMFnFi xIdVk2pP+RTWVR1cSfP7PYWOlPYxlMWyDpVrT0qDmdR7nO/+Xeo0hML12 1QXuUX7TKTyQPP6zFwRago5pDxIWy9qQr3tiJdvxz12N8pJuzD0QJwaog Z3pow72bnBvehWznI9AvxbEdJ+MAr8A+rffqZO/6p/KAXlB6Ozn9oqMqe ZHQ8oMT+aSAFsBrc48q4sVW0baBgyuNt2f+81VnToGIEqoM6+ltpK1lBD j1HYqSl/Ez7pwRpj0wXMYRF0Wp7Iw+s3wkDaG55mRczr5siKIpkB5VlAE A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="310239430" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="310239430" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="684350396" 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; 11 Jul 2022 04:24:00 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 0871F21AFD; Mon, 11 Jul 2022 14:23:58 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYa-D1; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 4/8] ACPI: property: Move property ref argument parsing into a new function Date: Mon, 11 Jul 2022 14:26:02 +0300 Message-Id: <20220711112606.3050368-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 | 103 ++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 8d757ca2a58f3..a2733f8981c7f 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -673,6 +673,58 @@ 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 +813,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 Mon Jul 11 11:26:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589402 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 18B07C433EF for ; Mon, 11 Jul 2022 11:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbiGKLh1 (ORCPT ); Mon, 11 Jul 2022 07:37:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiGKLg7 (ORCPT ); Mon, 11 Jul 2022 07:36:59 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92246371B3 for ; Mon, 11 Jul 2022 04:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538674; x=1689074674; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X9HWFNT0qCPQRY1yL4Km4YWL+W1aFZnA3HRIUBMwNZU=; b=M45U9XiCEpl0612LMWB/iSURV/JLdMZpcHtJPRis69AgXhUlMlSmCt2W NK6eKLbdMmfjNIx0NpOX5pg4I5Yt934E1Gsf8apkCjHUl2Q6puM7Su7IF 5+yTI3VR0YsuMSmsshE+vHAeiyjnkcjAgFkHPIBk0xaSW+kN5IyVr/PTP HcWwn6CcP8GEo6SDIY6wtD7SzySwQOR90X44R6UsaeiSdpJmPbaaifxYW zaBTurCNHXmisOOp7N46OWqxPrKd0RgPlYfed+j/V1g0Y5pVqOhFzxrVH KGY+ZR/xvemGoX77hoL5K21qh+5S0JSxH6tY/TIBQooOL1NaJdSY4UME2 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="310239562" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="310239562" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:34 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="737059034" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:33 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 1360821D4A; Mon, 11 Jul 2022 14:23:58 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYd-Ep; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 5/8] ACPI: property: Switch node property referencing from ifs to a switch Date: Mon, 11 Jul 2022 14:26:03 +0300 Message-Id: <20220711112606.3050368-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 Reviewed-by: Andy Shevchenko --- 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 a2733f8981c7f..3411cd0433b88 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -778,11 +778,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; @@ -793,19 +791,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; @@ -813,7 +813,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; @@ -829,11 +830,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 Mon Jul 11 11:26:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589852 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 97818CCA47B for ; Mon, 11 Jul 2022 11:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbiGKLhS (ORCPT ); Mon, 11 Jul 2022 07:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbiGKLgz (ORCPT ); Mon, 11 Jul 2022 07:36:55 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4659C8CC8B for ; Mon, 11 Jul 2022 04:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538656; x=1689074656; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hqFCK5307o7mcbNOsL35AaW+Rib09PnmYoL/+sZ3aQ0=; b=Ugm4deItUtIjeJ86PgBSk3d2L9suf3HrOgeF/aVTir2auGjYGOEnJEDS JLq41pwmizel8Hrt0f035A89n0nn6pehwxB0bJa7HNHkg2hvZY3hugG+m BgJOTVRx1Zlx6noAnqptPjM+eEJ89mhS0Fw4FM2VCbarlEYBRLlE9aPsI EvxhPIwqIlygqBzFwysSD/7rPbWEvYbc+v7MxieNuhiC6SFTyIPtTuR81 mCmXPOwkG0agDpCsZwuOd/oRSwCCykEauVgeAix0mx4xiXqxcSymGYDRD C457lSWxjuzfsy6HeqM040u1kGzsYDb/nZ36Jg5VwKlb5spgvWMjy9unP A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="310239442" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="310239442" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:03 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="684350410" 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; 11 Jul 2022 04:24:02 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 1F1D521FE5; Mon, 11 Jul 2022 14:23:58 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYg-GS; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 6/8] ACPI: property: Unify integer value reading functions Date: Mon, 11 Jul 2022 14:26:04 +0300 Message-Id: <20220711112606.3050368-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 using C99 _Generic(). Also use size_t for the counter instead of int. Signed-off-by: Sakari Ailus --- drivers/acpi/property.c | 96 +++++++++++++---------------------------- 1 file changed, 31 insertions(+), 65 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 3411cd0433b88..236a847f1bfbd 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -908,67 +908,33 @@ 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; - } - 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; -} +#define acpi_copy_property_array_uint(items, val, nval) \ + ({ \ + typeof(items) __items = items; \ + typeof(val) __val = val; \ + typeof(nval) __nval = nval; \ + size_t i; \ + int ret = 0; \ + \ + for (i = 0; i < __nval; i++) { \ + if (__items[i].type != ACPI_TYPE_INTEGER) { \ + ret = -EPROTO; \ + break; \ + } \ + if (__items[i].integer.value > _Generic(__val, \ + u8: U8_MAX, \ + u16: U16_MAX, \ + u32: U32_MAX, \ + u64: U64_MAX, \ + default: 0U)) { \ + ret = -EOVERFLOW; \ + break; \ + } \ + \ + __val[i] = __items[i].integer.value; \ + } \ + ret; \ + }) static int acpi_copy_property_array_string(const union acpi_object *items, char **val, size_t nval) @@ -1025,16 +991,16 @@ static int acpi_data_prop_read(const struct acpi_device_data *data, switch (proptype) { case DEV_PROP_U8: - ret = acpi_copy_property_array_u8(items, (u8 *)val, nval); + ret = acpi_copy_property_array_uint(items, (u8 *)val, nval); break; case DEV_PROP_U16: - ret = acpi_copy_property_array_u16(items, (u16 *)val, nval); + ret = acpi_copy_property_array_uint(items, (u16 *)val, nval); break; case DEV_PROP_U32: - ret = acpi_copy_property_array_u32(items, (u32 *)val, nval); + ret = acpi_copy_property_array_uint(items, (u32 *)val, nval); break; case DEV_PROP_U64: - ret = acpi_copy_property_array_u64(items, (u64 *)val, nval); + ret = acpi_copy_property_array_uint(items, (u64 *)val, nval); break; case DEV_PROP_STRING: ret = acpi_copy_property_array_string( From patchwork Mon Jul 11 11:26:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589404 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 A5E3BC433EF for ; Mon, 11 Jul 2022 11:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbiGKLhJ (ORCPT ); Mon, 11 Jul 2022 07:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbiGKLgw (ORCPT ); Mon, 11 Jul 2022 07:36:52 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE348BA86 for ; Mon, 11 Jul 2022 04:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538647; x=1689074647; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Up/emJxCa0W79mpVZm/FCUSFb5FZXF2iTT9CDDKqchQ=; b=k6U0oG1C0rgCwglNOYSZ/iIFRZgfqjzu6YFlD3lDsABIa6WxYG1M6Vx+ 7UEvNSawqjX+PqhephBcuL4WYHIu5rqSALMzjm65zjDtLIqQKpg4+uyPr ON2geTWqD2FAUes7i5kLrqeg/EayUHvqpRdRpe/9tnW3SwlSra4OHc84g 3S8I+t7LdnhuXb9FmMf74ahMZtbPmGbD++G44grc0RfkfvX1YHQIIbQBR C5L9+RHR36+QUpX7Ywl3egO4CoAkxvg8Hh49DlFOJC1xfL8Xg93Ma2hxS 5JOpzFO4hyeLpLE28dF9S5gcfKEyuHnQ9h4bBBXOp0DkfEU+yGNl3cUuI A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="282186973" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="282186973" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:04 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="544975519" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:03 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 2AD0222018; Mon, 11 Jul 2022 14:23:58 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYk-Hw; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 7/8] ACPI: property: Add support for parsing buffer property UUID Date: Mon, 11 Jul 2022 14:26:05 +0300 Message-Id: <20220711112606.3050368-8-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 | 142 ++++++++++++++++++++++++++++++++++++---- include/acpi/acpi_bus.h | 3 +- include/linux/acpi.h | 2 +- 3 files changed, 132 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 236a847f1bfbd..7621f684212ff 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,104 @@ static bool acpi_tie_nondev_subnodes(struct acpi_device_data *data) return true; } -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 \"%*pE\" as buffer\n", + obj->string.length, + 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 +490,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 +505,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 +557,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 +587,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 54c5566df9fe1..88a17fce49fd0 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 4f82a5bc6d987..93a695cab9d8a 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1243,7 +1243,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 Mon Jul 11 11:26:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 589405 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 23432C433EF for ; Mon, 11 Jul 2022 11:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbiGKLhD (ORCPT ); Mon, 11 Jul 2022 07:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiGKLgn (ORCPT ); Mon, 11 Jul 2022 07:36:43 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 137398AB31 for ; Mon, 11 Jul 2022 04:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657538646; x=1689074646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=psNICnFTPbDrrn1NO0zWmVYMlWvqb2EQZh+2TVt76zo=; b=HWjQTy/VRw6iVKVgT6ZLCXaCoeaWnUcSaqxjzrzocHHgrk7RITrzmk8F UoRdZrLOP6bkORnbywujwd0KFxVWpwYLkH1CpGv0eziLCCtHOPnQOsRkU WyQeXN5CkSZ+mFQQ9BP7hHciNbDYx4DVKCv/KIh99puc2z3kJaGjxlNJc BJsTH9uRQrIgRc8y5eMQJ/wQHF1wHtEUHi1hD/sjdnL67WzgzWdVBLeb+ ASnWEkf+LP4OCSnyJHubgJ91PdMWszUaCgyEJF62cFroq/L473Nzc2CyM 0tryzpzJEf4s1iAgjtY/E0sx+xQpnvRc8hrpH21uYmjjJ+J1aH+ZOb4qT Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="282186971" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="282186971" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:03 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="840973475" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 04:24:02 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 349D2220AA; Mon, 11 Jul 2022 14:23:58 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1oArYE-00CnYo-Jb; Mon, 11 Jul 2022 14:26:06 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH v4 8/8] ACPI: property: Read buffer properties as integers Date: Mon, 11 Jul 2022 14:26:06 +0300 Message-Id: <20220711112606.3050368-9-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220711112606.3050368-1-sakari.ailus@linux.intel.com> References: <20220711112606.3050368-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 | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 7621f684212ff..9711482014a60 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, int ret = 0; \ \ 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) { \ ret = -EPROTO; \ break; \ @@ -1092,18 +1096,41 @@ 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) + return -EOVERFLOW; + break; + } + fallthrough; + default: + if (nval > obj->package.count) + return -EOVERFLOW; + break; + } 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: