Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3853131imw; Thu, 7 Jul 2022 08:33:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1twk+ESOitB+CCNcegbl7Jph44lb6X70pOjj8Hd8tsaV2FMyDjgXLJJYUIQy7VCt4eUkK8P X-Received: by 2002:a17:907:1c11:b0:726:851e:179e with SMTP id nc17-20020a1709071c1100b00726851e179emr45802356ejc.39.1657208024583; Thu, 07 Jul 2022 08:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657208024; cv=none; d=google.com; s=arc-20160816; b=cWgtVybAGd/GPq7+JWwFDAPEyF8MnKDwZ743Se8JK38mVIfVcwLbsbKdH9aVOeay0u j7CabTYQ9PdiKaqN79LS0VCxXrNIJo7Nh5tth4WpXG7ckO84ar43cKtn7gp2oM1WhdrT mNk09oYMhSYCggQPos9XC5Aqn65xyU9qgY2SHtb9KtArzzUboqF1pzlIyBFj8b4RV9Wj x7l2/a4diR1chy+oUOgsssjMJ7vkZANVEefIbavmFcM5NpCBVknzzFRb8A0pM5K1jYcF VIoEL8E0q28wj91A5l5Qb0rt2XamigkOZesMZT/Ue/ZIAUazE/Wfe6rc6cqPdztbREZl 4fLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eI3etg7tS+4dRtyIr56IkjyI/lNnf1+cKi1Idvp6WZ4=; b=0N861Mn6HvpDRL1rKp7C+YLi9nBtLBNwn2xuF9NyF/8WrkAzHPZ8ak5qJeoU1juQ02 pDBPjNBB4jRBOTsIvGvFyh4I5z/s3dLiTFJcWH2oUilkb9nck2yf0Ni6CbU/oV7XGvAF mk1TWuH1wr0n2rpIQrIhfQJnWArW49xoyxmKafNPeGYLCey/tGuuaKTthcnaMWH4oJEm x/R6gmTTDQQWKWi7dL8TAhnL50fR1ufK9J3IvaH+J0bB1DY9Nj2M3Rgt2h5/PZrrxrTv ig3g3eOdMrOw2lG6D42MwMRya0Ic11kHmpLRs5wKjjsikO5wpdaz8oQg4arQPn7T6UpM 5TBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=EM4+LfwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a170906795600b0072b1da65a1esi337089ejo.284.2022.07.07.08.33.15; Thu, 07 Jul 2022 08:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=EM4+LfwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236136AbiGGPLP (ORCPT + 99 others); Thu, 7 Jul 2022 11:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235985AbiGGPLE (ORCPT ); Thu, 7 Jul 2022 11:11:04 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 039CE26AFC; Thu, 7 Jul 2022 08:11:04 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 267BU6Ji020187; Thu, 7 Jul 2022 10:10:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=eI3etg7tS+4dRtyIr56IkjyI/lNnf1+cKi1Idvp6WZ4=; b=EM4+LfwLChmNPZqRm9P/dN3McEwRhzyTIcFsUPyeaHPtz7tG7ra5hhgHjXaSKdykhNWl jP5doNJbi7XsDnveFSd79Lji/sHT1LrVJxE4v8oR4kXSWOjj1eKwYVhLpVwmDFwulk/R WHkI+OOKkMZwyV2qq9YSjURQ+PVTZ6TRsxm17H1xYb7ivCQfIYVLzQF3U4OAqOBkCijB XSlLqbx1D8JMjuHSexc8r/Ez57Gx84g17ZSpvIx2i3clKPJ47soxjo5EBtMFRq39KbtO ydJGYd/2riMV0+WO4kygzMuH3PR5RUVTZbx8WalNaIlmBbC96y8LGxshUhRmAIcfD0pF 2g== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3h4ucmjr6f-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 07 Jul 2022 10:10:47 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 7 Jul 2022 16:10:44 +0100 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1118.9; Thu, 7 Jul 2022 10:10:44 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Thu, 7 Jul 2022 16:10:44 +0100 Received: from sbinding-cirrus-dsktp.ad.cirrus.com (NEWBNB750653-PC.ad.cirrus.com [198.90.238.195]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id EB38446A; Thu, 7 Jul 2022 15:10:43 +0000 (UTC) From: Stefan Binding To: "Rafael J . Wysocki" , Len Brown , Mark Brown , Liam Girdwood CC: , , , , "Stefan Binding" Subject: [PATCH v6 1/2] ACPI: utils: Add api to read _SUB from ACPI Date: Thu, 7 Jul 2022 16:10:36 +0100 Message-ID: <20220707151037.3901050-2-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707151037.3901050-1-sbinding@opensource.cirrus.com> References: <20220707151037.3901050-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: nXzdEGsX5TRFa1bZ1Bt_e7IGnOHN5v0e X-Proofpoint-ORIG-GUID: nXzdEGsX5TRFa1bZ1Bt_e7IGnOHN5v0e X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a wrapper function to read the _SUB string from ACPI. Signed-off-by: Stefan Binding --- drivers/acpi/utils.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 3a9773a09e19..5a7b8065e77f 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -291,6 +291,44 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) } EXPORT_SYMBOL(acpi_get_local_address); +#define ACPI_MAX_SUB_BUF_SIZE 9 + +const char *acpi_get_subsystem_id(acpi_handle handle) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + acpi_status status; + const char *sub; + size_t len; + + status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status); + return ERR_PTR(-ENODATA); + } + + obj = buffer.pointer; + if (obj->type == ACPI_TYPE_STRING) { + len = strlen(obj->string.pointer); + if (len < ACPI_MAX_SUB_BUF_SIZE && len > 0) { + sub = kstrdup(obj->string.pointer, GFP_KERNEL); + if (!sub) + sub = ERR_PTR(-ENOMEM); + } else { + acpi_handle_err(handle, "ACPI _SUB Length %zu is Invalid\n", len); + sub = ERR_PTR(-ENODATA); + } + } else { + acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n"); + sub = ERR_PTR(-ENODATA); + } + + acpi_os_free(buffer.pointer); + + return sub; +} +EXPORT_SYMBOL_GPL(acpi_get_subsystem_id); + acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 2a0e95336094..447898685e09 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -762,6 +762,7 @@ static inline u64 acpi_arch_get_root_pointer(void) #endif int acpi_get_local_address(acpi_handle handle, u32 *addr); +const char *acpi_get_subsystem_id(acpi_handle handle); #else /* !CONFIG_ACPI */ @@ -1023,6 +1024,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) return -ENODEV; } +static inline const char *acpi_get_subsystem_id(acpi_handle handle) +{ + return ERR_PTR(-ENODEV); +} + static inline int acpi_register_wakeup_handler(int wake_irq, bool (*wakeup)(void *context), void *context) { -- 2.25.1