From patchwork Fri May 6 13:00:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570717 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 C6B40C433EF for ; Fri, 6 May 2022 12:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356050AbiEFNC5 (ORCPT ); Fri, 6 May 2022 09:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392221AbiEFNCs (ORCPT ); Fri, 6 May 2022 09:02:48 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF8C68F94 for ; Fri, 6 May 2022 05:59: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=1651841941; x=1683377941; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S5b95Kaj7dMb6Y2XDMJXvWieDst0bDySoTHaHwIApcQ=; b=gWOGNWBVdMdVkzvzZW8JNyRmzcHxL1pvn574t3duKe5zVFj6mlWxLQZx 7bnRqdVYQyY2Z3SiE3T06BeQb9lMTfQ/Xm9EyAIOrkGwDjAURFBhpBuZ4 y7dmJ7s2S+yihxIiIBGMwNRi/7zIFtb1/TCmRno1XY1wQ7EIWaazV2x32 o3nw51Fd3KCmKMX+yNNKSaCDTx6p3ZENPGVV9FDR7HGzlzq+8bJDtHCh3 4m1PQB6S/D/PcHCoUAPJeyGN6thLzNB30yRmn4UR6yvdEosgKh8ykT6+S CwPZD9dWl9ZfysF8K40wRPak7PIb7jvapxGvZpNg9+q0zqZvpGlYCJsuT w==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="248365012" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="248365012" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:59:01 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="654692333" 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; 06 May 2022 05:59:00 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 9989E20621; Fri, 6 May 2022 15:58:28 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480O-7H; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 01/11] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Date: Fri, 6 May 2022 16:00:15 +0300 Message-Id: <20220506130025.984026-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 6 13:00:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570721 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 17625C433EF for ; Fri, 6 May 2022 12:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392141AbiEFNCR (ORCPT ); Fri, 6 May 2022 09:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356442AbiEFNCP (ORCPT ); Fri, 6 May 2022 09:02:15 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 876CF6338E for ; Fri, 6 May 2022 05:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651841912; x=1683377912; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1+u3D5272MmR3cXbcceeLW6iNFLPmVc+zRjoajCHDgI=; b=mivn6oJZ7ZEWDybbi3e1gTqVruUW/mkaRpzYkyXwdAHeMVNDVdfctGl7 vNomLQ19r1g3WnuqNwn5ieJ079khyV6+bK5Gegm6fh35VcfwepTJe83n0 H14YOH6ON8aPW9rf9E0iPYnr6sXOF3X8+ct1JLy+VcJ7U/99O1MA9i1ze o4tRI9dM+anls4Og0EAOaxOfjWlmlDCTfyVTWI92EQGnkqqIEliQeq3L8 dSG7KrqrPFwDP4xtonkFtlqKs1V9PQL+Awh+0HlM/tcOI5uHIJ4ku3Bur 8zZnMSW90JRnIkGn1DvEL9m8qp13hxS1nGFNi1lfUQ4Kg0lQTBh1QJfh0 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="266051605" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="266051605" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:32 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="695169231" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:30 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id B008020BC8; Fri, 6 May 2022 15:58:28 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480U-AE; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 03/11] ACPI: property: Tie data nodes to acpi handles Date: Fri, 6 May 2022 16:00:17 +0300 Message-Id: <20220506130025.984026-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 6 13:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570722 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 4F476C433FE for ; Fri, 6 May 2022 12:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233344AbiEFNCQ (ORCPT ); Fri, 6 May 2022 09:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346526AbiEFNCP (ORCPT ); Fri, 6 May 2022 09:02:15 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A57263383 for ; Fri, 6 May 2022 05:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651841912; x=1683377912; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YoOjvt6ZWy+Epk5pxRi/nkuhj8uwUo7L7f23DdSGlTE=; b=bryyFBZ5Kgh6p/HnyHS2KgP9NWmiS88/wBaNSb4o7+ppWjjBgviyJGHJ QgrKMvwTxn8+DH5QoIlbQIynDV88Rxa8aany38coqrnLWaQHf9bFbzVLa eNGzo4RaPcesQX/LNKmrSrTNB7q8OxhLZFjsXZn7gdRcbsy+b7vImi2VM jM9eymIY8m7YOEoHFTnplxlPBHyIx7a+pXRiwSP2aABcEf8I+Zf0DQk0m g++nlxOFvNBN7LHeKSGiJ8qt7m0Q+he+EaQX9muhWUH8NiP467U80EGbC YbszlRv502mEbl0ttuZgfjAbWG08lhz6DnsVWHY5XaL1WOYwjnggdyi3o w==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="329004152" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="329004152" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:31 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="709452094" 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; 06 May 2022 05:58:30 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id BABF320D40; Fri, 6 May 2022 15:58:28 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480X-Bn; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 04/11] ACPI: property: Use acpi_object_type consistently in property ref parsing Date: Fri, 6 May 2022 16:00:18 +0300 Message-Id: <20220506130025.984026-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 6 13:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570719 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 64020C433EF for ; Fri, 6 May 2022 12:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392205AbiEFNCY (ORCPT ); Fri, 6 May 2022 09:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343907AbiEFNCV (ORCPT ); Fri, 6 May 2022 09:02:21 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67BAD63383 for ; Fri, 6 May 2022 05:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651841915; x=1683377915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DxZC8syyR9C+xK5/dPtjALY1tEDptkd13YlvwScvvMM=; b=JEx6NPE2vHi7B9R2gMU3IfpcXCIupmjnqTPJyrctRgUYPaUQn0S+3diD KQ3N+AuXbOJt7miO8vs8AEWQEKQ7G59619cUOUQPci6GwqQAQwSCIwaon tx7uRItCaMoUBUWQPIrEoav9NoiCt7nH9UFuqBN4sCW0TRWPYKoFbdIPE +3DPpT/+Vk6PI4Cpo+Q8Sg8b5niUB0OadSftM8y9Q2eHdXf/5OhLpARpk AgFUOc0sd224j2pzsVYA42wQxUODtC+5ttkMM0FmQMygm6dF9tuUL77nc 1NJ6x4w/zxRA3cdhdVKutka+r9vQ3JM+HhFJI2xFxtfJt2nnqUdjmJxkM g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="331447752" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="331447752" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:35 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="665467965" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:33 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id D43CD20DD5; Fri, 6 May 2022 15:58:28 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480d-Ez; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 06/11] ACPI: property: Switch node property referencing from ifs to a switch Date: Fri, 6 May 2022 16:00:20 +0300 Message-Id: <20220506130025.984026-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 6 13:00:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570718 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 45D72C43217 for ; Fri, 6 May 2022 12:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392220AbiEFNCZ (ORCPT ); Fri, 6 May 2022 09:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392209AbiEFNCW (ORCPT ); Fri, 6 May 2022 09:02:22 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6AF06338E for ; Fri, 6 May 2022 05:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651841915; x=1683377915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AWXX9RIJyfn+TklamiDPXtkmP70XK6wxbDByAy02EMA=; b=QTzrj5CvTGk2CvOAK+itSIAmulNCO875cxPVRMbe0h6zyYMaWP3OR7Av wkLK9rW4wks1bV9/R1pGiNbMsaPajDa8Lz9MmYUbffbBUdEvHCScE1SU6 0KmuGmCVf+tQiHCjHSACFAR2bT20S5NoQfhl1ghvwvgS6R059owKg2QMU ML7+9/8RFq2OLYZjrp2UTzhFwGrWMjz2ZzwjsAGCOnkOHRhyYIyPnttcM 0qG9pxV0Px7QDymmG+hiN36OvCZMDWz+7cqlgoYIAGd5084JQMpZXnRB4 2rWq+FIXSIoC6JdDRxpP9M6z74cEl+4oaS2y7vY0/dbadrUEA/FjSJgZr A==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="266051622" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="266051622" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:35 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="695169289" Received: from punajuuri.fi.intel.com (HELO paasikivi.fi.intel.com) ([10.237.72.43]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:34 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id EAA3E20EAC; Fri, 6 May 2022 15:58:28 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480p-IU; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 09/11] ACPI: property: Unify integer value reading functions Date: Fri, 6 May 2022 16:00:23 +0300 Message-Id: <20220506130025.984026-10-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 9325a9b2c0543..2205612fd6e98 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -985,67 +985,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 6 13:00:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 570720 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 3C360C433F5 for ; Fri, 6 May 2022 12:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392211AbiEFNCW (ORCPT ); Fri, 6 May 2022 09:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392208AbiEFNCW (ORCPT ); Fri, 6 May 2022 09:02:22 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E989363516 for ; Fri, 6 May 2022 05:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651841915; x=1683377915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BRsEBnKg3OuAt/OYFEsvgzGX9Vw6DHxSrTbSVZJyRF0=; b=jXNn4y9K3s8LqjQihPRemTNkz0V4+Kj6Rx3Kc7NokdklJ1mM5mcuFfGb 2/1yDFnPLFYfSeQMxEDN+N0eStk6KULBvm5aRMvycEZGSaFa1aRtEWMnA HQMdc2j3Hp20Lx0+bVavWaCiTtuL9SQlODSj6T8nGk7b6g0HR9GnTnbcf RNF7Ih5n+kssq8GY/Hekk1O253fjCjNqFkWZxuEnDqwQ8AflkSJUm5QEy 5vFwYZ/3oATSZxCxCkA3iJRr81qFKXkFI/AjJo6eromms9oO49giqgpNi mXXnFcO5v6dX41DL+QZ6MA0riTgrfUGCVy+5wZJPoMPFodQDdmy+BRGw/ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="268064810" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="268064810" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 05:58:35 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="621813783" 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; 06 May 2022 05:58:34 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 0058120F73; Fri, 6 May 2022 15:58:29 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.94.2) (envelope-from ) id 1nmxZJ-00480s-JY; Fri, 06 May 2022 16:00:25 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@intel.com Subject: [PATCH 10/11] ACPI: property: Add support for parsing buffer property UUID Date: Fri, 6 May 2022 16:00:24 +0300 Message-Id: <20220506130025.984026-11-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com> References: <20220506130025.984026-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 2205612fd6e98..d3f6d95e0fb19 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 b44aaffedb914..8df984013ee71 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 d7136d13aa442..a411bae44b7e2 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1204,7 +1204,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);