Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2166901rdb; Mon, 20 Nov 2023 04:09:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLZ/0WY0ewCUFAHSGkPZjTmh9jWf/WD8Nr9frXuNQZi+gj58xB9pkHKv8TIC4D4jCXKo+x X-Received: by 2002:a9d:6757:0:b0:6d6:4fed:a21a with SMTP id w23-20020a9d6757000000b006d64feda21amr7237312otm.6.1700482197670; Mon, 20 Nov 2023 04:09:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700482197; cv=none; d=google.com; s=arc-20160816; b=odAWwIelOkpDEbbDqDH6j8+nFjRjJ8NmwFdXJb0zl7cOeMEMgkbjQRp9wg8YrbDdJ6 UDU6jZWS0cuXXN2ZU0cSoF4g2W3DggxK903b1I2/TFMgmbRM53Pi2Ng/QfsySGVHmW7o XyJvDuTmVo0dr8HpGpYOFxCW/8fkFOq7AGT8XHbWpsmCp5jzFMjA8seJlvI98uDrVko+ dK46UNSVbhou2M+U/9WIUa+skTaIfFRTRVAujvnw4XxWUNzSxD8ef6eMT4oD062yplHI C4R5CLf/61LQgodtMZ9tPujqn6CBF/f1VDrfPyCmHKGqcZaQim9e1+bZr5sdTzl6yGCn 5bRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=NGGINrOnXHiAyQbwcJPDkwHzuVc+37O0od/BUqv0EJI=; fh=LrjGCQr9k+7CYyd6XEdJgJkCFIUW/cPwqK3zW8PbdHI=; b=HnnuDFv87VTOLrphAd32L9x6JdjymCylAsoL3y7Pj7hVBD7GbQNSIwTzCD9ILL0Saw +Qas5h8/U8rmBPBoTeNRGZLXEPs2q2INJ9cW98JulVSh9HbsngUtKq+G28/CKEZCtCvp peHrkWUoxHYbPzwVhmOh5HKe5H0FYfn89BZo5Rq5lGekEOuig8PyNITDpye9WskeKaTY FjPfLfPmyHYz+teTb9xR5+fYVGRHbKlHOliseUOA0fW3KHtwDRxzEf8B8uGHRZwJu/xr qi99XObPBFoKiDOMpGHji/mRwEAIwMJt9aYL/oXHgTFW7DgSE45LK1gWum92x8/AYDDj Jarw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kf2UoTg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id r74-20020a632b4d000000b0056433b221b9si8314920pgr.477.2023.11.20.04.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 04:09:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kf2UoTg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 95D4480423B4; Mon, 20 Nov 2023 04:09:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233444AbjKTMJL (ORCPT + 99 others); Mon, 20 Nov 2023 07:09:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233431AbjKTMJJ (ORCPT ); Mon, 20 Nov 2023 07:09:09 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48290AA; Mon, 20 Nov 2023 04:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700482145; x=1732018145; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=gvs+oGGs0WvlVsw/cdAYmZ/ijzQlY+bl7G7dinrml1Q=; b=kf2UoTg+NnH1CovoKECCnJtedN2L4PnpZNmuP2LsmjUD/0xaUkJBDQmc FTe29pKpTNrQXblJIen7+d7LyH+HzYHixSKc6xFENMu0xIJUAH91VtZph 5lsqjfz4uU3bPZFexgzMZNoI+WO1AeqXS9p7rtYdaTnsGBpnrI2ErJqjx XIGPXz9Y7Kt03f8lpVbWLBGTAx42bgJ+Tb52tjObICDwvuJIEbLEMrqi/ PZnvo9Ob2MIRQ/YYChaAmRjnXNVAx0SkVTatV+pzHr+ijnrFev3PxK+kM ORPkvRbC9Hd8GMHBYaaSBNHSSRaLM6wc4wNk0dvLJAGIn/bv6bAhM6hC5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="394455694" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="394455694" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 04:09:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="769878605" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="769878605" Received: from inlubt0316.iind.intel.com ([10.191.20.213]) by fmsmga007.fm.intel.com with ESMTP; 20 Nov 2023 04:08:55 -0800 From: Raag Jadav To: mika.westerberg@linux.intel.com, andriy.shevchenko@linux.intel.com, rafael@kernel.org, lenb@kernel.org, robert.moore@intel.com, ardb@kernel.org, will@kernel.org, mark.rutland@arm.com Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linuxfoundation.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mallikarjunappa.sangannavar@intel.com, bala.senthil@intel.com, Raag Jadav Subject: [PATCH v1 2/6] ACPI: bus: update acpi_dev_uid_match() to support multiple types Date: Mon, 20 Nov 2023 17:38:33 +0530 Message-Id: <20231120120837.3002-3-raag.jadav@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231120120837.3002-1-raag.jadav@intel.com> References: <20231120120837.3002-1-raag.jadav@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 04:09:54 -0800 (PST) According to ACPI specification, a _UID object can evaluate to either a numeric value or a string. Update acpi_dev_uid_match() helper to support _UID matching for both integer and string types. Suggested-by: Andy Shevchenko Suggested-by: Mika Westerberg Suggested-by: Rafael J. Wysocki Signed-off-by: Raag Jadav --- drivers/acpi/utils.c | 19 ------------------- include/acpi/acpi_bus.h | 35 ++++++++++++++++++++++++++++++++++- include/linux/acpi.h | 8 +++----- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 28c75242fca9..fe7e850c6479 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -824,25 +824,6 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs) } EXPORT_SYMBOL(acpi_check_dsm); -/** - * acpi_dev_uid_match - Match device by supplied UID - * @adev: ACPI device to match. - * @uid2: Unique ID of the device. - * - * Matches UID in @adev with given @uid2. - * - * Returns: - * - %true if matches. - * - %false otherwise. - */ -bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2) -{ - const char *uid1 = acpi_device_uid(adev); - - return uid1 && uid2 && !strcmp(uid1, uid2); -} -EXPORT_SYMBOL_GPL(acpi_dev_uid_match); - /** * acpi_dev_hid_uid_match - Match device by supplied HID and UID * @adev: ACPI device to match. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 989ea623b1c2..25b9fabf350f 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -9,6 +9,7 @@ #ifndef __ACPI_BUS_H__ #define __ACPI_BUS_H__ +#include #include #include @@ -856,10 +857,42 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set); } -bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2); bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer); +static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2) +{ + const char *uid1 = acpi_device_uid(adev); + + return uid1 && uid2 && !strcmp(uid1, uid2); +} + +static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2) +{ + u64 uid1; + + return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2; +} + +/** + * acpi_dev_uid_match - Match device by supplied UID + * @adev: ACPI device to match. + * @uid2: Unique ID of the device. + * + * Matches UID in @adev with given @uid2. + * + * Returns: %true if matches, %false otherwise. + */ + +/* Treat uid as a string for pointer and array types, treat as an integer otherwise */ +#define get_uid_type(x) \ + (__builtin_choose_expr(is_array_or_pointer_type(x), (const char *)0, (u64)0)) + +#define acpi_dev_uid_match(adev, uid2) \ + _Generic(get_uid_type(uid2), \ + const char *: acpi_str_uid_match, \ + u64: acpi_int_uid_match)(adev, uid2) + void acpi_dev_clear_dependencies(struct acpi_device *supplier); bool acpi_dev_ready_for_enumeration(const struct acpi_device *device); struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 54189e0e5f41..3d7ee8c0b86a 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -756,6 +756,9 @@ const char *acpi_get_subsystem_id(acpi_handle handle); #define ACPI_HANDLE(dev) (NULL) #define ACPI_HANDLE_FWNODE(fwnode) (NULL) +/* Get rid of the -Wunused-variable for adev */ +#define acpi_dev_uid_match(adev, uid2) (adev && false) + #include struct fwnode_handle; @@ -772,11 +775,6 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) struct acpi_device; -static inline bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2) -{ - return false; -} - static inline bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2) { -- 2.17.1