From patchwork Tue Sep 13 16:31:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 606813 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 5ADC2C6FA82 for ; Tue, 13 Sep 2022 17:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbiIMRkL (ORCPT ); Tue, 13 Sep 2022 13:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233183AbiIMRjk (ORCPT ); Tue, 13 Sep 2022 13:39:40 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2A77C33D; Tue, 13 Sep 2022 09:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663086737; x=1694622737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V80BdvPU7ap78HoolUzQor9A2iHpp5rs73DM1e1058s=; b=mAN8O/k6YeDL8bgLwp2R/fvGTLGSpUzDm/x+AujOnf3KmLID04sEXZY/ b+YIXqWxyGIaGq2WIE/Etft6XJxiRFIhNH1ix3J+TQsRZztA9W3YB1b+o 8RHn8pN9UdEX+nePIqfB4Goe7exCt16pQhMkY2oDaX7EhNeA8CixPXdgJ iAaEra4x278jRHROjEjQ15OLmfd9d+is74PRGXLb9/WFJx8iha6Dv3njz RaeGz8XX9rjZS2aEtOY1bk8fHqumg9kDf2JMEdJpg6Q0LVYOVqJrImka8 4o5YuQtGYv4/0noxjJXWgfnVWmHgEyBMtZ6xO0U1Ri7vM7erpbAIena7Q g==; X-IronPort-AV: E=McAfee;i="6500,9779,10469"; a="362135438" X-IronPort-AV: E=Sophos;i="5.93,313,1654585200"; d="scan'208";a="362135438" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2022 09:31:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,313,1654585200"; d="scan'208";a="594008224" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 13 Sep 2022 09:31:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3935B235; Tue, 13 Sep 2022 19:31:49 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Andy Shevchenko , Hans de Goede , Ard Biesheuvel , Wolfram Sang , Mark Brown , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, devel@acpica.org Cc: "Rafael J. Wysocki" , Len Brown , Elie Morisse , Nehal Shah , Shyam Sundar S K , Khalil Blaiech , Andy Gross , Bjorn Andersson , Konrad Dybcio , Will Deacon , Mark Rutland , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Robert Moore Subject: [PATCH v3 1/8] ACPI: utils: Add acpi_dev_uid_to_integer() helper to get _UID as integer Date: Tue, 13 Sep 2022 19:31:40 +0300 Message-Id: <20220913163147.24258-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220913163147.24258-1-andriy.shevchenko@linux.intel.com> References: <20220913163147.24258-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Some users interpret _UID only as integer and for them it's easier to have an integer representation of _UID. Add respective helper for that. Signed-off-by: Andy Shevchenko Reviewed-by: Hans de Goede --- drivers/acpi/utils.c | 24 ++++++++++++++++++++++++ include/acpi/acpi_bus.h | 1 + include/linux/acpi.h | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 4acd6f7d1395..2ea14648a661 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -793,6 +793,30 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev, } EXPORT_SYMBOL(acpi_dev_hid_uid_match); +/** + * acpi_dev_uid_to_integer - treat ACPI device _UID as integer + * @adev: ACPI device to get _UID from + * @integer: output buffer for integer + * + * Considers _UID as integer and converts it to @integer. + * + * Returns 0 on success, or negative error code otherwise. + */ +int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer) +{ + const char *uid; + + if (!adev) + return -ENODEV; + + uid = acpi_device_uid(adev); + if (!uid) + return -ENODATA; + + return kstrtou64(uid, 0, integer); +} +EXPORT_SYMBOL(acpi_dev_uid_to_integer); + /** * acpi_dev_found - Detect presence of a given ACPI device in the namespace. * @hid: Hardware ID of the device. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 42f76f2c2d49..1804d7a70918 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -739,6 +739,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) } 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); void acpi_dev_clear_dependencies(struct acpi_device *supplier); bool acpi_dev_ready_for_enumeration(const struct acpi_device *device); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ed4aa395cc49..619b2b1e4fb4 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -799,6 +799,11 @@ acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *u return false; } +static inline int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer) +{ + return -ENODEV; +} + static inline struct acpi_device * acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) {