From patchwork Wed Oct 18 07:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426512 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 96E58C41513 for ; Wed, 18 Oct 2023 07:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235118AbjJRHEn (ORCPT ); Wed, 18 Oct 2023 03:04:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235145AbjJRHEb (ORCPT ); Wed, 18 Oct 2023 03:04:31 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEA391A6; Wed, 18 Oct 2023 00:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nkO6xAUiRUEfF0zXqIn+43gOph2y/oquxDxxRfm1RqGBpmOEtYL/dPgwq7lkY6tp1rhGdLyY/IotjxZDwzm1WsTeWtT8wmjxTCRb4obAm0+wc7VC62I9rcnwRPgoCI0+z+dNmmJYn+JERSDE/sCBmsnA4fzij8CswcsIOJJKI4F/pGxqIMA8Hn+etzxnlAqF31wlh8gs5vB/FVga3FAzaQelIVYc2XuWf0cYBfjdhKGXEzlQZtXenFA/YdGLDuCdvnnrFNOFHMwzP83aozIk4UmpN9NqGPR76qq/RdCTVNgdi1+62B9w6Eux8SktePllrjfs6EwWvPFRKOu/TwLshg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=94c9Q5V+XUdv8Ka4fJVccg+grc4RvDx4r/hek9LK+R8=; b=gYyaXm/sYwVcJWdk20Jxiy4GXt+xAs0exRguvF5eAKZfxBRJFQ8opuVByX2Pdl3TKTjSLNfA7M0fQsVwkHdOB/dtMeC+2IKHcnD7W3y3vmHoPxh7f0KlNCKJ9BmpSkLk6vY4j8lzYwOaJx7U4dRBcDzbE+bD6XCFvljcRBm9uPzIWttGhR0LOZQNL4aD/JTvebr5PGA98UWV/aChFHJMiW/MTE4AJsBs8IZNbXPKegNWmryrNIh2T1WMqgzZLactv7CD2DJXrK3DMd1rEQUG8bxRBphJ3nfaM9xhgqSTtOb7CMRTfaqSBwNF9Hx6c9ke2wiAjV+H13HcjshFQ/8mkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=94c9Q5V+XUdv8Ka4fJVccg+grc4RvDx4r/hek9LK+R8=; b=LXrJ8ssu+gfFzM5Zup9br/4h4rDofFctgbm1HqTCffBuvAOAv5XCv4/fzJVV7BSq6xxmxV4TRhlqxntSIPUl5lw2wvUVlRSws+oSAPaLBmbhl57nPevLKOIhbx+ene89/V8gxSU2b8MUtgWUaaJPtZ2OqniyAvkUg2/StY3iS20= Received: from DS7PR03CA0294.namprd03.prod.outlook.com (2603:10b6:5:3ad::29) by IA1PR12MB8287.namprd12.prod.outlook.com (2603:10b6:208:3f5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 07:04:08 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::f) by DS7PR03CA0294.outlook.office365.com (2603:10b6:5:3ad::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:04:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:07 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:03:48 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 01/17] platform/x86/amd/pmf: Add PMF TEE interface Date: Wed, 18 Oct 2023 12:32:25 +0530 Message-ID: <20231018070241.2041529-2-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D4:EE_|IA1PR12MB8287:EE_ X-MS-Office365-Filtering-Correlation-Id: 2783aa66-98b5-456b-5524-08dbcfa86c05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iztRMHzA8TTb60NstFkZVMTG+osea2pYqAfWihIIMorcd81oFzqCVcw3fC9WenFPFmEXNWPMxIwneOusbT7tp+PC6wjPthJnUC5klkcniHsnxkX3gtV6TxoPFOXgHn5fqMFHmu8/RnC102KsECmraK1fs8bME2mO+3B8/n/O6ZgUaY75avTaWYD40EGhjltmC4b5VgH9aN76ymPAEHCr2ua3g8jkFjR0GjDwjhAJMYfGWmq94oDWbGdcVHOUgo8KSceT/oy+HH6Jb9P1n0A+GGxGG40tWdo0J+pXnF66XNcnxDnj7YpmDHyYdbeYL4kRH/hYWdMWmkRJM2iOaQttZOb2ZDKR3h1htIYexDPMsVCECq7QWZCxRhe7OqfCXTMZO/XhSzNKIouQRAHrPChANisywn+FY7dMbrfDlMCm1ukJdJ1z3tgY0g9uZrysAktsfjVXJChqAoJ1P4kKUFZBFB0sBKLuSDX0wq8WR394J/n/NQ/QXyj9gxEQ21+0Bd6d9T6fJg11e9Al0FfjpcFqQ2VmudFGQmXr7M8FNuUDzCnCg3im7MxqBYXOmrcjn59TAjUjDvjBBprTKS1E2Smov2fOMZXSuDAggnjUZTFqVy63UYeJATxDtz9DxIjCA1vb8t8DhrxT3/F6vzLJwQfnvxpRyQNlj82mcglXqkj2p6ZwuECyInuWz2zZHYH2R8QvKJOihaiXQjGqY4iEwb2ABXVhDPQL4DHU9Sqth2MNQ77m0csKYA4/KjDo6xc/0NV+1SphswXwA/uCb5RSSVVgUMW1BXsJARezXTkK6dzXwLE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(376002)(346002)(136003)(230922051799003)(82310400011)(186009)(64100799003)(1800799009)(451199024)(36840700001)(40470700004)(46966006)(36756003)(40480700001)(40460700003)(26005)(70586007)(54906003)(70206006)(86362001)(110136005)(356005)(921005)(81166007)(36860700001)(336012)(83380400001)(6666004)(1076003)(2616005)(16526019)(7696005)(426003)(8936002)(316002)(2906002)(82740400003)(478600001)(5660300002)(47076005)(8676002)(7416002)(4326008)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:07.6020 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2783aa66-98b5-456b-5524-08dbcfa86c05 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8287 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org AMD PMF driver loads the PMF TA (Trusted Application) into the AMD ASP's (AMD Security Processor) TEE (Trusted Execution Environment). PMF Trusted Application is a secured firmware placed under /lib/firmware/amdtee gets loaded only when the TEE environment is initialized. Add the initial code path to build these pipes. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/Makefile | 3 +- drivers/platform/x86/amd/pmf/core.c | 10 ++- drivers/platform/x86/amd/pmf/pmf.h | 16 ++++ drivers/platform/x86/amd/pmf/tee-if.c | 105 ++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 drivers/platform/x86/amd/pmf/tee-if.c diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 3064bc8ea167..32a029e8db80 100644 --- a/drivers/platform/x86/amd/pmf/Kconfig +++ b/drivers/platform/x86/amd/pmf/Kconfig @@ -9,6 +9,7 @@ config AMD_PMF depends on POWER_SUPPLY depends on AMD_NB select ACPI_PLATFORM_PROFILE + depends on TEE help This driver provides support for the AMD Platform Management Framework. The goal is to enhance end user experience by making AMD PCs smarter, diff --git a/drivers/platform/x86/amd/pmf/Makefile b/drivers/platform/x86/amd/pmf/Makefile index fdededf54392..d2746ee7369f 100644 --- a/drivers/platform/x86/amd/pmf/Makefile +++ b/drivers/platform/x86/amd/pmf/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_AMD_PMF) += amd-pmf.o amd-pmf-objs := core.o acpi.o sps.o \ - auto-mode.o cnqf.o + auto-mode.o cnqf.o \ + tee-if.o diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 78ed3ee22555..ec92d1cc0dac 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -309,13 +309,13 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev) dev_dbg(dev->dev, "SPS enabled and Platform Profiles registered\n"); } - /* Enable Auto Mode */ - if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) { + if (!amd_pmf_init_smart_pc(dev)) { + dev_dbg(dev->dev, "Smart PC Solution Enabled\n"); + } else if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) { amd_pmf_init_auto_mode(dev); dev_dbg(dev->dev, "Auto Mode Init done\n"); } else if (is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_AC) || is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_DC)) { - /* Enable Cool n Quiet Framework (CnQF) */ ret = amd_pmf_init_cnqf(dev); if (ret) dev_warn(dev->dev, "CnQF Init failed\n"); @@ -330,7 +330,9 @@ static void amd_pmf_deinit_features(struct amd_pmf_dev *dev) amd_pmf_deinit_sps(dev); } - if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) { + if (!dev->smart_pc_enabled) { + amd_pmf_deinit_smart_pc(dev); + } else if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) { amd_pmf_deinit_auto_mode(dev); } else if (is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_AC) || is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_DC)) { diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index deba88e6e4c8..bd40458937ba 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -179,6 +179,12 @@ struct amd_pmf_dev { bool cnqf_enabled; bool cnqf_supported; struct notifier_block pwr_src_notifier; + /* Smart PC solution builder */ + struct tee_context *tee_ctx; + struct tee_shm *fw_shm_pool; + u32 session_id; + void *shbuf; + bool smart_pc_enabled; }; struct apmf_sps_prop_granular { @@ -389,6 +395,13 @@ struct apmf_dyn_slider_output { struct apmf_cnqf_power_set ps[APMF_CNQF_MAX]; } __packed; +struct ta_pmf_shared_memory { + int command_id; + int resp_id; + u32 pmf_result; + u32 if_version; +}; + /* Core Layer */ int apmf_acpi_init(struct amd_pmf_dev *pmf_dev); void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev); @@ -433,4 +446,7 @@ void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev); int amd_pmf_trans_cnqf(struct amd_pmf_dev *dev, int socket_power, ktime_t time_lapsed_ms); extern const struct attribute_group cnqf_feature_attribute_group; +/* Smart PC builder Layer */ +int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev); +void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev); #endif /* PMF_H */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c new file mode 100644 index 000000000000..6ec8c3726624 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD Platform Management Framework Driver - TEE Interface + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Author: Shyam Sundar S K + */ + +#include +#include +#include "pmf.h" + +#define MAX_TEE_PARAM 4 +static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, + 0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43); + +static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) +{ + return ver->impl_id == TEE_IMPL_ID_AMDTEE; +} + +static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id) +{ + struct tee_ioctl_open_session_arg sess_arg = {}; + int rc; + + export_uuid(sess_arg.uuid, &amd_pmf_ta_uuid); + sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC; + sess_arg.num_params = 0; + + rc = tee_client_open_session(ctx, &sess_arg, NULL); + if (rc < 0 || sess_arg.ret != 0) { + pr_err("Failed to open TEE session err:%#x, rc:%d\n", sess_arg.ret, rc); + return rc; + } + + *id = sess_arg.session; + + return rc; +} + +static int amd_pmf_tee_init(struct amd_pmf_dev *dev) +{ + u32 size; + int ret; + + dev->tee_ctx = tee_client_open_context(NULL, amd_pmf_amdtee_ta_match, NULL, NULL); + if (IS_ERR(dev->tee_ctx)) { + dev_err(dev->dev, "Failed to open TEE context\n"); + return PTR_ERR(dev->tee_ctx); + } + + ret = amd_pmf_ta_open_session(dev->tee_ctx, &dev->session_id); + if (ret) { + dev_err(dev->dev, "Failed to open TA session (%d)\n", ret); + ret = -EINVAL; + goto out_ctx; + } + + size = sizeof(struct ta_pmf_shared_memory); + dev->fw_shm_pool = tee_shm_alloc_kernel_buf(dev->tee_ctx, size); + if (IS_ERR(dev->fw_shm_pool)) { + dev_err(dev->dev, "Failed to alloc TEE shared memory\n"); + ret = PTR_ERR(dev->fw_shm_pool); + goto out_sess; + } + + dev->shbuf = tee_shm_get_va(dev->fw_shm_pool, 0); + if (IS_ERR(dev->shbuf)) { + dev_err(dev->dev, "Failed to get TEE virtual address\n"); + ret = PTR_ERR(dev->shbuf); + goto out_shm; + } + dev_dbg(dev->dev, "TEE init done\n"); + + return 0; + +out_shm: + tee_shm_free(dev->fw_shm_pool); +out_sess: + tee_client_close_session(dev->tee_ctx, dev->session_id); +out_ctx: + tee_client_close_context(dev->tee_ctx); + + return ret; +} + +static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev) +{ + tee_shm_free(dev->fw_shm_pool); + tee_client_close_session(dev->tee_ctx, dev->session_id); + tee_client_close_context(dev->tee_ctx); +} + +int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) +{ + return amd_pmf_tee_init(dev); +} + +void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) +{ + amd_pmf_tee_deinit(dev); +} From patchwork Wed Oct 18 07:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426513 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 5E9CBC41513 for ; Wed, 18 Oct 2023 07:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344533AbjJRHEv (ORCPT ); Wed, 18 Oct 2023 03:04:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344601AbjJRHEk (ORCPT ); Wed, 18 Oct 2023 03:04:40 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79D0A1BC; Wed, 18 Oct 2023 00:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gqIOkii6ThmHy/yb/gyV0ZPzoKMu0Rbku22UKh27Vbh58EnvMMsffzBp18M7hdegW+cwzCnKFHaNsZ+V+Q4gXGzm3ydpC3GExpA0KsqPkvimwsFReTD9W+0Ell54twDdQi20FUFmOJx0VJE64F8C2B00Ns5c/j/Osd13k5xiFWhtpzQZsed22LqYhC+EOFCxRucZalkJxz43trgWTxJBJR1UltugrzLFpPE2VbikJBS/BW4R6XbFnWBcjw6SvyBCYCPZO3HO7qnyyZtGleWjw8QaYye/HY+AVshBDL/2qppafDkfkyFB0Jcos9o55hiSEULSYegh/9Kju1M7MY/yRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XmU7y06Itd7QfranZqr9or5/oCfwvJzwuG0mWOSWRpI=; b=HxjGQSncJ1+rh1qYil9CRsrtVeaJZrOuJK3qK5rwPVP4aTkH3isv8XJde/ZwDMm++yXKBVCxD9Vc+VyM2o0BLzONqEzHIy5tb4Dbetv5THSr88mbPazCrf97wqR+VeNgz9AwLAgnIfNQGcaX2Btq3RWr7Cyh6xsyw/rX3yRLFj+0YfR26IecuxDTO03zqsnhtWnEpJEQaoYiI3SP17Wk96h8KNgl4r4aFQnq1Dne8ZegIUtiqGPEzHvuE1HaySlbFJScGNgSrPXApirTdwYGqsL0apolxNckDlVluIB9Cj7Z/Jlnm5TSIDKYs4/iAK70P94+oxSG4WdUTlHz0uDS6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XmU7y06Itd7QfranZqr9or5/oCfwvJzwuG0mWOSWRpI=; b=hVkMxC3DSxPhv9fIrphO4vQdxlx2nP3gctuUOpSqd7PIFgE2152jOFg6XyyMhlvHSYGT6CXesouKjGeuQORv4dwx7plQHzJuW4p97f7sRSbXbY81aq6MNKnN3LqyyTR+EwZvQVrh63cqWQkvYNTGyhBW7ophukbOGNbYFUSOWxo= Received: from DS7P222CA0012.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::15) by DS7PR12MB8324.namprd12.prod.outlook.com (2603:10b6:8:ec::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Wed, 18 Oct 2023 07:04:23 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:8:2e:cafe::54) by DS7P222CA0012.outlook.office365.com (2603:10b6:8:2e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:04:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:22 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:03 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 02/17] platform/x86/amd/pmf: Add support for PMF-TA interaction Date: Wed, 18 Oct 2023 12:32:26 +0530 Message-ID: <20231018070241.2041529-3-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D7:EE_|DS7PR12MB8324:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e469839-a4c0-463c-7b58-08dbcfa874b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vznu+e+9aoVj3D3AeJ7bqSjgH6LS74AbgxWGIscOcMFc7vrjAuzNYaieq+dBL/TzLLhjn/ywCGcgetZwwyh64EHdCVxJXOUU8FOTtDByLtVgT4KXQgQvA7mOf/aGch4K5MXWoHwKji5DAnkXHr9lrlA9HX8J7qQBUZzA6INmjBGV1SwgCWb8obDKiJ2DDzYv7rOHjJqWh9OSH5sC+P2HMrF1yzyV1SCM7bz8U09mu4tT4H4OefP1bB/Bj3NLD/Z62hZBo6EHroYGWSIZewIglHvl8lvEmf2ddelncuslcv2eBjbQTqV/On0rI21Rd8fOxYmpGHFnDVWL0sdmr08hq8j6glGXtXIkBjS8QRoHxegAVP3cpGBQU/21asKYgDuwLsgtoaUwe/E3cyBseqlMngP/Eq8QFM4WlufhGBt9NpUrkpVlStZ8tnplko0GNfICPuilcBFv1T4CMEk+bthsfLaJqDOM+0LiDgH2tbKXlrziwQD02D8mWZWY3QMPPw7UPjulGz6csi7dZCUjZgwWvtuRzAcHZTN7xQLEx6zWuSnvlqFlTwXtvz8C09lRaRJfZpdFuU6XSOHWdTlnSJvbJ8UtN4jgPU3uRwjLN5bWys++V8IN9/J9ebPDhi+SVR1Cioi3OBm0oGvbRVZXPflTXYyeWL9LCu+2P8CovjMRtYT9Mk+ssbxTAQaHxrltVu/KVMF4XNEUQEEl1UobWU3mNY/mYSqb5ZvYTaPEP/M8qMpov7RzntRT89rmY6qyVzPttlktut7vLqPQISl+oXUvoXNqNQ6TF1d1+MNswF9MltQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(346002)(376002)(396003)(39860400002)(230922051799003)(1800799009)(82310400011)(451199024)(186009)(64100799003)(36840700001)(46966006)(40470700004)(110136005)(7416002)(356005)(921005)(40480700001)(81166007)(86362001)(41300700001)(478600001)(2906002)(36756003)(54906003)(70586007)(70206006)(36860700001)(6666004)(7696005)(316002)(8936002)(8676002)(40460700003)(16526019)(426003)(82740400003)(336012)(1076003)(26005)(2616005)(83380400001)(4326008)(47076005)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:22.1741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e469839-a4c0-463c-7b58-08dbcfa874b2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8324 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org PMF TA (Trusted Application) loads via the TEE environment into the AMD ASP. PMF-TA supports two commands: 1) Init: Initialize the TA with the PMF Smart PC policy binary and start the policy engine. A policy is a combination of inputs and outputs, where; - the inputs are the changing dynamics of the system like the user behaviour, system heuristics etc. - the outputs, which are the actions to be set on the system which lead to better power management and enhanced user experience. PMF driver acts as a central manager in this case to supply the inputs required to the TA (either by getting the information from the other kernel subsystems or from userland) 2) Enact: Enact the output actions from the TA. The action could be applying a new thermal limit to boost/throttle the power limits or change system behavior. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 10 +++ drivers/platform/x86/amd/pmf/tee-if.c | 97 ++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index bd40458937ba..a24e34e42032 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -59,6 +59,9 @@ #define ARG_NONE 0 #define AVG_SAMPLE_SIZE 3 +/* TA macros */ +#define PMF_TA_IF_VERSION_MAJOR 1 + /* AMD PMF BIOS interfaces */ struct apmf_verify_interface { u16 size; @@ -184,6 +187,7 @@ struct amd_pmf_dev { struct tee_shm *fw_shm_pool; u32 session_id; void *shbuf; + struct delayed_work pb_work; bool smart_pc_enabled; }; @@ -395,6 +399,12 @@ struct apmf_dyn_slider_output { struct apmf_cnqf_power_set ps[APMF_CNQF_MAX]; } __packed; +/* Command ids for TA communication */ +enum ta_pmf_command { + TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, + TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, +}; + struct ta_pmf_shared_memory { int command_id; int resp_id; diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 6ec8c3726624..4036f435f1e2 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -13,9 +13,96 @@ #include "pmf.h" #define MAX_TEE_PARAM 4 + +/* Policy binary actions sampling frequency (in ms) */ +static int pb_actions_ms = MSEC_PER_SEC; +#ifdef CONFIG_AMD_PMF_DEBUG +module_param(pb_actions_ms, int, 0644); +MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (default = 1000ms)"); +#endif + static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, 0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43); +static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd, + struct tee_ioctl_invoke_arg *arg, + struct tee_param *param) +{ + memset(arg, 0, sizeof(*arg)); + memset(param, 0, MAX_TEE_PARAM * sizeof(*param)); + + arg->func = cmd; + arg->session = dev->session_id; + arg->num_params = MAX_TEE_PARAM; + + /* Fill invoke cmd params */ + param[0].u.memref.size = sizeof(struct ta_pmf_shared_memory); + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT; + param[0].u.memref.shm = dev->fw_shm_pool; + param[0].u.memref.shm_offs = 0; +} + +static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) +{ + struct ta_pmf_shared_memory *ta_sm = NULL; + struct tee_param param[MAX_TEE_PARAM]; + struct tee_ioctl_invoke_arg arg; + int ret = 0; + + if (!dev->tee_ctx) + return -ENODEV; + + ta_sm = dev->shbuf; + memset(ta_sm, 0, sizeof(*ta_sm)); + ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES; + ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR; + + amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, &arg, param); + + ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(dev->dev, "TEE enact cmd failed. err: %x, ret:%d\n", arg.ret, ret); + return ret; + } + + return 0; +} + +static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) +{ + struct ta_pmf_shared_memory *ta_sm = NULL; + struct tee_param param[MAX_TEE_PARAM]; + struct tee_ioctl_invoke_arg arg; + int ret = 0; + + if (!dev->tee_ctx) { + dev_err(dev->dev, "Failed to get TEE context\n"); + return -ENODEV; + } + + ta_sm = dev->shbuf; + ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE; + ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR; + + amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, &arg, param); + + ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); + if (ret < 0 || arg.ret != 0) { + dev_err(dev->dev, "Failed to invoke TEE init cmd. err: %x, ret:%d\n", arg.ret, ret); + return ret; + } + + return ta_sm->pmf_result; +} + +static void amd_pmf_invoke_cmd(struct work_struct *work) +{ + struct amd_pmf_dev *dev = container_of(work, struct amd_pmf_dev, pb_work.work); + + amd_pmf_invoke_cmd_enact(dev); + schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms)); +} + static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) { return ver->impl_id == TEE_IMPL_ID_AMDTEE; @@ -96,10 +183,18 @@ static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev) int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) { - return amd_pmf_tee_init(dev); + int ret; + + ret = amd_pmf_tee_init(dev); + if (ret) + return ret; + + INIT_DELAYED_WORK(&dev->pb_work, amd_pmf_invoke_cmd); + return 0; } void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) { + cancel_delayed_work_sync(&dev->pb_work); amd_pmf_tee_deinit(dev); } From patchwork Wed Oct 18 07:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426514 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 1A0CECDB47E for ; Wed, 18 Oct 2023 07:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbjJRHEw (ORCPT ); Wed, 18 Oct 2023 03:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344621AbjJRHEl (ORCPT ); Wed, 18 Oct 2023 03:04:41 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2042.outbound.protection.outlook.com [40.107.94.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB351D48; Wed, 18 Oct 2023 00:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WflORXmpQHo8/H19VBynJgvxZVdFy06U5JFiAVAmbRT6idN1jWEzAsVKkU7toTfnw64wKJn4wo07gL7O6Ygw67+2uZW2jpSwzhmsz/K9p7aDepVFUR/7/tWiA28qd0vfCryxxvweJOqKC1PqYwl+t0KPfCnLj1gf/M5InPax7uUJUWTM/6BX94aQDUUdD53HkxXA//94npI/VXH72TTe/tYQWmyPaMwTsPAT+6A43k8pR8yLA1opQaehOO06SyPRIky3Dh0uch64ty9OXQ/bIRNmReDHDFBHuALGkQnU1dIxphVq0BjAy4LnInDTnjGNzVtWO0a+1FajXkLWOCGAJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=luMp8R58CCOqHa+5av0BV3DYV9/iHbJDmL3D8gL+//w=; b=mWoFwMxo5C3XDxdXJA1Zohkh/AufwDwWuwMhzxNPBz/AU2TdoY5T/Ocid//XgmLFnsbgl5dLge1P7HSeVtpTy8WYqEv1ZmbsTPeeVqtHNsTGcoZPAIMx8SKhw8l8HuGaiAG/pmVHNfDOyAcj7D5GxhkLxElouMgQ4PLOEYGHOosfdNIaUQe4NbsUsXEahyUlikmjYJKHR+ls9tNmKt53Gp81skP+R4dc+nUVxbSEmMF4kBaTymsn3dRQAOZzwpFujLfjKag/TxEV8yN21VE9PEXTraGH251GffB6VbqSJwibXPMQZiwn5YGcLr/T6D79cgTeWTZm7w/Gywzegcfqkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=luMp8R58CCOqHa+5av0BV3DYV9/iHbJDmL3D8gL+//w=; b=XfuVj3oBAOiEkw5zoEKrFstA6XpH39RE1t2BcuCOPHUok9hwe1yPRtTQP5GFn6a1FVggXXs29TJo3/kpJLLuPogTdHty3L676yy1R6fEWKeLx6dEVTpyc4Yhjh63tLbEuNjQ8YcIAlBOrhJAHTUieasKpT3ZGjJXl1wU+kRmg0s= Received: from CH0PR04CA0053.namprd04.prod.outlook.com (2603:10b6:610:77::28) by SA3PR12MB7832.namprd12.prod.outlook.com (2603:10b6:806:31f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Wed, 18 Oct 2023 07:04:26 +0000 Received: from DS3PEPF000099D3.namprd04.prod.outlook.com (2603:10b6:610:77:cafe::ef) by CH0PR04CA0053.outlook.office365.com (2603:10b6:610:77::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:04:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D3.mail.protection.outlook.com (10.167.17.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:25 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:08 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 03/17] platform/x86/amd/pmf: Change return type of amd_pmf_set_dram_addr() Date: Wed, 18 Oct 2023 12:32:27 +0530 Message-ID: <20231018070241.2041529-4-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D3:EE_|SA3PR12MB7832:EE_ X-MS-Office365-Filtering-Correlation-Id: 855ebba5-7bbb-4133-c558-08dbcfa876ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IDZsiCrdJSeaUHSFbXWP+x9X20HiWaEuiztOY83L9l1KbR1XiBUBVhi0EHldWSS76kxKHZSahJJZes8rWo5xpxpGp8EqEcwgcEx8RxKRtA8soh3NvwVFKOLs0k9hLg27haUzSnUY1kWjwEz1DaHMLe+w5BIZb6wuMtBs0fiatne/7ddIde20Y9v+lU/xDju3b1S3/N5DK5JV8N1aubmf+xfXpwgsvjWJGL0q5mBfxoO2w/kzlmMdl73fanGDjtk2CkzAgIzVwNPJ9dfhCKPAnRWUMVYK9JvOkfaF41tilXtCH+E9ES2i65/sjCiPSq9ggBKGUcAx4Tz/up9lz+gdAZxkWTlRLDhd3+cQGbgB75Ug46eo4DCZAlLs82YDAklXF3VCZ4bQ9w/qW7qh0IkJGkz28JC11YO0yeZ6AZnxKBh3bPrHROaefipYr/qH6i67kCQ6aWm/ZPk0K16aVlT92J1RodyOS00XLTrbJWOn6NxAiL/y6NU9QXs0lDxmpQBPUL0KrdTRl62CcUrAdGdKpA5v2VDSbkjpoIKNxLTmWQMditx4InspC4mgqejzDRxr0uQlIZUEW/xTPRFUnwPJ85Mw4r2XNgzXSVsfjM73sCVvy3xNY+ykLg4E+l4X6TpuCpAbwvqSVGjMduBuj+DWtayPYIAnoKq7IulWnUtZpYqEelnZ8TpD/JKyuiLpBzqhuL4u4t76NDdZJtuNoga2Shr8N7rYNbz4+2CD4vGQ/xaMB/GA+9c/4VrjjRwjy5P5c2d8IeAfLwJyr0InyFs3S/BU5pjNcPnsQ+cP6ZJdYl4= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(346002)(39860400002)(136003)(230922051799003)(1800799009)(186009)(82310400011)(451199024)(64100799003)(36840700001)(40470700004)(46966006)(7416002)(7696005)(2906002)(5660300002)(4326008)(8936002)(8676002)(41300700001)(70206006)(70586007)(54906003)(110136005)(40460700003)(316002)(478600001)(6666004)(336012)(1076003)(2616005)(26005)(16526019)(40480700001)(83380400001)(426003)(81166007)(36860700001)(47076005)(36756003)(921005)(356005)(82740400003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:25.4740 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 855ebba5-7bbb-4133-c558-08dbcfa876ae X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7832 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org In the current code, the metrics table information was required only for auto-mode or CnQF at a given time. Hence keeping the return type of amd_pmf_set_dram_addr() as static made sense. But with the addition of Smart PC builder feature, the metrics table information has to be shared by the Smart PC also and this feature resides outside of core.c. To make amd_pmf_set_dram_addr() visible outside of core.c make it as a non-static function and move the allocation of memory for metrics table from amd_pmf_init_metrics_table() to amd_pmf_set_dram_addr() as amd_pmf_set_dram_addr() is the common function to set the DRAM address. Add a suspend handler that can free up the allocated memory for getting the metrics table information. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/core.c | 42 ++++++++++++++++++++++------- drivers/platform/x86/amd/pmf/pmf.h | 1 + 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index ec92d1cc0dac..f50b7ec9a625 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -251,29 +251,35 @@ static const struct pci_device_id pmf_pci_ids[] = { { } }; -static void amd_pmf_set_dram_addr(struct amd_pmf_dev *dev) +int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev) { u64 phys_addr; u32 hi, low; + /* Get Metrics Table Address */ + dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL); + if (!dev->buf) + return -ENOMEM; + phys_addr = virt_to_phys(dev->buf); hi = phys_addr >> 32; low = phys_addr & GENMASK(31, 0); amd_pmf_send_cmd(dev, SET_DRAM_ADDR_HIGH, 0, hi, NULL); amd_pmf_send_cmd(dev, SET_DRAM_ADDR_LOW, 0, low, NULL); + + return 0; } int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev) { - /* Get Metrics Table Address */ - dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL); - if (!dev->buf) - return -ENOMEM; + int ret; INIT_DELAYED_WORK(&dev->work_buffer, amd_pmf_get_metrics); - amd_pmf_set_dram_addr(dev); + ret = amd_pmf_set_dram_addr(dev); + if (ret) + return ret; /* * Start collecting the metrics data after a small delay @@ -284,17 +290,35 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev) return 0; } +static int amd_pmf_suspend_handler(struct device *dev) +{ + struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + + /* + * Free the buffer allocated for storing the metrics table + * information, as will have to allocate it freshly after + * resume. + */ + kfree(pdev->buf); + + return 0; +} + static int amd_pmf_resume_handler(struct device *dev) { struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + int ret; - if (pdev->buf) - amd_pmf_set_dram_addr(pdev); + if (pdev->buf) { + ret = amd_pmf_set_dram_addr(pdev); + if (ret) + return ret; + } return 0; } -static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, NULL, amd_pmf_resume_handler); +static DEFINE_SIMPLE_DEV_PM_OPS(amd_pmf_pm, amd_pmf_suspend_handler, amd_pmf_resume_handler); static void amd_pmf_init_features(struct amd_pmf_dev *dev) { diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index a24e34e42032..6a0e4c446dd3 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -421,6 +421,7 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev); int amd_pmf_get_power_source(void); int apmf_install_handler(struct amd_pmf_dev *pmf_dev); int apmf_os_power_slider_update(struct amd_pmf_dev *dev, u8 flag); +int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev); /* SPS Layer */ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf); From patchwork Wed Oct 18 07:02:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426515 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 8E517C41513 for ; Wed, 18 Oct 2023 07:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344556AbjJRHE4 (ORCPT ); Wed, 18 Oct 2023 03:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235142AbjJRHEo (ORCPT ); Wed, 18 Oct 2023 03:04:44 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94C1E13E; Wed, 18 Oct 2023 00:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jR5NBlUXA4UisCJ8vqDfbpvB3iPUQHhbvxbN34dfg8hvOzm3NTlhOt0i+y3Y49EV+o3r/3yYzIx3vS3KqmBMBQXDInm3B/Y2GLNJW2epyo4EC37SuqvSuBGJxvd3lPoh+9kBGiqef5+s+JLL6krkE9uBiP6CzEMs5Qg7k0sSgxd2BV9y8yDtPD6u5MvrYvgwpbUk9tqIoM1QZwmqBVjKjqT3mCoX6m+WSJ8+qTm4bbfbhuTpdN8n/DE5j9qu3TjlPHeJCdZ5VUsuqyGrZhSRw9aKIXe77YcGfWM5IeJHMeUarS8JoijtauuPuTvuzwBgZXsB5SPeP99XJe+bIKWtgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PfNzWGMBt3NjQtqiw4vJxhbgq53E4qzSTZcgu5oyky0=; b=KAgjlxlc9LFnoK+Uk3b9np10bWuW1ruwcotd5iCD+0OTAvQ1ZvpfhDDhJhHfttGUGXTMPMLSWMP5VWRc1KM6K96AV/OVFR4n5x5ECcv85RZkkPN08dtW3Rgc/rfKUow4S+Gxy4JAKc0qJ3+r2XuLttOdzlD1RG12GO8sJBHFSat4jnbG/pWfCFwsE+jeEvCXTEJS7vlywAqZOe95YhATkMukqvn4JFXnevTQ+0jUEKjPCbiRqQgzP80wmSdAw+5d7Drk9VPXhSFwu1TkFzJrYDozohqmNfGvY2nS7POGyJwIaTLTqT4aGI4uFk1U2k9aGJPwUxuKFHvUxPJuWZD6Kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PfNzWGMBt3NjQtqiw4vJxhbgq53E4qzSTZcgu5oyky0=; b=nbkRAWs9Cmx5WDiyZRgqP3mPI5MzStKrjxIEhP5PC4gxcF7G2S9jh2W3fUfXoALBCCXG00NJYhzGT9MR4nQbpoGoYtPN12y9vx5bF00hGek6ydZpKkBnfT7xWXPXtG8tZZgRq0Qb0Jm7aMSeKfq4vSfjhJmbDpCHnwsV0PRYekQ= Received: from CH0PR04CA0043.namprd04.prod.outlook.com (2603:10b6:610:77::18) by SA1PR12MB6702.namprd12.prod.outlook.com (2603:10b6:806:252::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 07:04:35 +0000 Received: from DS3PEPF000099D3.namprd04.prod.outlook.com (2603:10b6:610:77:cafe::17) by CH0PR04CA0043.outlook.office365.com (2603:10b6:610:77::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:04:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D3.mail.protection.outlook.com (10.167.17.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:34 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:25 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 04/17] platform/x86/amd/pmf: Add support for PMF Policy Binary Date: Wed, 18 Oct 2023 12:32:28 +0530 Message-ID: <20231018070241.2041529-5-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D3:EE_|SA1PR12MB6702:EE_ X-MS-Office365-Filtering-Correlation-Id: 8aa143da-ea74-4450-e1a9-08dbcfa87c23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EsGkySMgMEK4tOUIFB6zi35GYLfnbJBJNhHj91DWjvc0Q22S9EzxUG+NPW6zIuoKLijsSj4hjQJn6F7hM2QkvF31gFnm8KQkvIhd2HQqbg1fmCudq3Q40ltpTy2qPiRROcS6YrVTBmbeB/O7iL0wX6jF/I5ppqZElRzH5mZSTkY5Ukp3Ezvtbby/eTAhE0/XYvCBCS9JwHOfaFOGR/rqDHOcG+KZCbUVbIv4Yqhw20hiSyxuNwlQKx+99jNXJJlP26OK6W+uMgDlvI0EgzrbKGCtWOdimOGvi2/2Vcw3IzLa966JaZizzPrV3IT9VDdFtrSYl/dZEp69sgLhDayYtaHxYcBKD8QoQE6pcVip+fa7HkRK5qCtUEuh2wo9y9xonkgG2yCBgPHJg8Vvq7y70OdOaL4nY2cW2pZdblxhtdjHiLaQXt/1DQPpmUdSOfHjnU3ZznNyN4BwP0Cge3qD5aUBOBz6FjeyNVdMImHSQC8is3oTbl7vYd7275viayh+UA9iTIWfr3q1ThZSt+phXIA7e7TGOfKjjG0WxkJIUmFB0dtebOJaOQZ2EDWRxU+c9Rc3ZOtxsrG/WjSGSYvoEmanKgseWJafarJdNS3PubDFVBzZITzlSGDGiFWZOcFcl1v/0ZR7p9c8+CqcwcGdWsozltHvLwbrTxN3Egw3e3YtTP+WaxGY1DmyG7B+1YREsnAG4L4bh6D/NxLBry21zKF8kikmACLsCNiLoxhUcNy8YRfU0VVecupPEVzzaHazjdGHqhk7fRIM10qsE8YBMgKxAUuBLRfVraqQJZqfpbg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(396003)(346002)(230922051799003)(1800799009)(82310400011)(451199024)(64100799003)(186009)(36840700001)(46966006)(40470700004)(356005)(7416002)(82740400003)(81166007)(921005)(4326008)(8936002)(8676002)(30864003)(40460700003)(41300700001)(5660300002)(86362001)(2906002)(40480700001)(7696005)(47076005)(478600001)(426003)(16526019)(336012)(36756003)(26005)(1076003)(83380400001)(2616005)(54906003)(110136005)(70586007)(70206006)(36860700001)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:34.6457 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8aa143da-ea74-4450-e1a9-08dbcfa87c23 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6702 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org PMF Policy binary is a encrypted and signed binary that will be part of the BIOS. PMF driver via the ACPI interface checks the existence of Smart PC bit. If the advertised bit is found, PMF driver walks the acpi namespace to find out the policy binary size and the address which has to be passed to the TA during the TA init sequence. The policy binary is comprised of inputs (or the events) and outputs (or the actions). With the PMF ecosystem, OEMs generate the policy binary (or could be multiple binaries) that contains a supported set of inputs and outputs which could be specifically carved out for each usage segment (or for each user also) that could influence the system behavior either by enriching the user experience or/and boost/throttle power limits. Once the TA init command succeeds, the PMF driver sends the changing events in the current environment to the TA for a constant sampling frequency time (the event here could be a lid close or open) and if the policy binary has corresponding action built within it, the TA sends the action for it in the subsequent enact command. If the inputs sent to the TA has no output defined in the policy binary generated by OEMs, there will be no action to be performed by the PMF driver. Example policies: 1) if slider is performance ; set the SPL to 40W Here PMF driver registers with the platform profile interface and when the slider position is changed, PMF driver lets the TA know about this. TA sends back an action to update the Sustained Power Limit (SPL). PMF driver updates this limit via the PMFW mailbox. 2) if user_away ; then lock the system Here PMF driver hooks to the AMD SFH driver to know the user presence and send the inputs to TA and if the condition is met, the TA sends the action of locking the system. PMF driver generates a uevent and based on the udev rule in the userland the system gets locked with systemctl. The intent here is to provide the OEM's to make a policy to lock the system when the user is away ; but the userland can make a choice to ignore it. and so on. The OEMs will have an utility to create numerous such policies and the policies shall be reviewed by AMD before signing and encrypting them. Policies are shared between operating systems to have seemless user experience. Since all this action has to happen via the "amdtee" driver, currently there is no caller for it in the kernel which can load the amdtee driver. Without amdtee driver loading onto the system the "tee" calls shall fail from the PMF driver. Hence an explicit MODULE_SOFTDEP has been added to address this. Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/Kconfig | 2 +- drivers/platform/x86/amd/pmf/acpi.c | 37 +++++++ drivers/platform/x86/amd/pmf/core.c | 9 ++ drivers/platform/x86/amd/pmf/pmf.h | 141 ++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 147 +++++++++++++++++++++++++- 5 files changed, 333 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 32a029e8db80..f246252bddd8 100644 --- a/drivers/platform/x86/amd/pmf/Kconfig +++ b/drivers/platform/x86/amd/pmf/Kconfig @@ -9,7 +9,7 @@ config AMD_PMF depends on POWER_SUPPLY depends on AMD_NB select ACPI_PLATFORM_PROFILE - depends on TEE + depends on TEE && AMDTEE help This driver provides support for the AMD Platform Management Framework. The goal is to enhance end user experience by making AMD PCs smarter, diff --git a/drivers/platform/x86/amd/pmf/acpi.c b/drivers/platform/x86/amd/pmf/acpi.c index 3fc5e4547d9f..4ec7957eb707 100644 --- a/drivers/platform/x86/amd/pmf/acpi.c +++ b/drivers/platform/x86/amd/pmf/acpi.c @@ -286,6 +286,43 @@ int apmf_install_handler(struct amd_pmf_dev *pmf_dev) return 0; } +static acpi_status apmf_walk_resources(struct acpi_resource *res, void *data) +{ + struct amd_pmf_dev *dev = data; + + switch (res->type) { + case ACPI_RESOURCE_TYPE_ADDRESS64: + dev->policy_addr = res->data.address64.address.minimum; + dev->policy_sz = res->data.address64.address.address_length; + break; + case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: + dev->policy_addr = res->data.fixed_memory32.address; + dev->policy_sz = res->data.fixed_memory32.address_length; + break; + } + + if (!dev->policy_addr || dev->policy_sz > POLICY_BUF_MAX_SZ || dev->policy_sz == 0) { + pr_err("Incorrect Policy params, possibly a SBIOS bug\n"); + return AE_ERROR; + } + + return AE_OK; +} + +int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev) +{ + acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev); + acpi_status status; + + status = acpi_walk_resources(ahandle, METHOD_NAME__CRS, apmf_walk_resources, pmf_dev); + if (ACPI_FAILURE(status)) { + dev_err(pmf_dev->dev, "acpi_walk_resources failed :%d\n", status); + return -EINVAL; + } + + return 0; +} + void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev) { acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev); diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index f50b7ec9a625..c8f6ec4c2e2c 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -395,6 +395,14 @@ static int amd_pmf_probe(struct platform_device *pdev) return -ENOMEM; dev->dev = &pdev->dev; + err = apmf_check_smart_pc(dev); + if (err) + /* + * Lets not return from here if Smart PC bit is not advertised in + * the BIOS. This way, there will be some amount of power savings + * to the user with static slider (if enabled). + */ + pr_err("PMF Smart PC not advertised in BIOS!:%d\n", err); rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); if (!rdev || !pci_match_id(pmf_pci_ids, rdev)) { @@ -474,3 +482,4 @@ module_platform_driver(amd_pmf_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("AMD Platform Management Framework Driver"); +MODULE_SOFTDEP("pre: amdtee"); diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 6a0e4c446dd3..092be501d4d3 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -14,6 +14,11 @@ #include #include +#define POLICY_BUF_MAX_SZ 0x4b000 +#define POLICY_SIGN_COOKIE 0x31535024 +#define POLICY_COOKIE_OFFSET 0x10 +#define POLICY_COOKIE_LEN 0x14 + /* APMF Functions */ #define APMF_FUNC_VERIFY_INTERFACE 0 #define APMF_FUNC_GET_SYS_PARAMS 1 @@ -59,8 +64,21 @@ #define ARG_NONE 0 #define AVG_SAMPLE_SIZE 3 +/* Policy Actions */ +#define PMF_POLICY_SPL 2 +#define PMF_POLICY_SPPT 3 +#define PMF_POLICY_FPPT 4 +#define PMF_POLICY_SPPT_APU_ONLY 5 +#define PMF_POLICY_STT_MIN 6 +#define PMF_POLICY_STT_SKINTEMP_APU 7 +#define PMF_POLICY_STT_SKINTEMP_HS2 8 + /* TA macros */ #define PMF_TA_IF_VERSION_MAJOR 1 +#define TA_PMF_ACTION_MAX 32 +#define TA_PMF_UNDO_MAX 8 +#define TA_OUTPUT_RESERVED_MEM 906 +#define MAX_OPERATION_PARAMS 4 /* AMD PMF BIOS interfaces */ struct apmf_verify_interface { @@ -183,11 +201,16 @@ struct amd_pmf_dev { bool cnqf_supported; struct notifier_block pwr_src_notifier; /* Smart PC solution builder */ + unsigned char *policy_buf; + u32 policy_sz; struct tee_context *tee_ctx; struct tee_shm *fw_shm_pool; u32 session_id; void *shbuf; struct delayed_work pb_work; + struct pmf_action_table *prev_data; + u64 policy_addr; + void *policy_base; bool smart_pc_enabled; }; @@ -399,17 +422,134 @@ struct apmf_dyn_slider_output { struct apmf_cnqf_power_set ps[APMF_CNQF_MAX]; } __packed; +enum smart_pc_status { + PMF_SMART_PC_ENABLED, + PMF_SMART_PC_DISABLED, +}; + +/* Smart PC - TA internals */ +enum ta_slider { + TA_BEST_BATTERY, + TA_BETTER_BATTERY, + TA_BETTER_PERFORMANCE, + TA_BEST_PERFORMANCE, + TA_MAX, +}; + /* Command ids for TA communication */ enum ta_pmf_command { TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, }; +enum ta_pmf_error_type { + TA_PMF_TYPE_SUCCESS, + TA_PMF_ERROR_TYPE_GENERIC, + TA_PMF_ERROR_TYPE_CRYPTO, + TA_PMF_ERROR_TYPE_CRYPTO_VALIDATE, + TA_PMF_ERROR_TYPE_CRYPTO_VERIFY_OEM, + TA_PMF_ERROR_TYPE_POLICY_BUILDER, + TA_PMF_ERROR_TYPE_PB_CONVERT, + TA_PMF_ERROR_TYPE_PB_SETUP, + TA_PMF_ERROR_TYPE_PB_ENACT, + TA_PMF_ERROR_TYPE_ASD_GET_DEVICE_INFO, + TA_PMF_ERROR_TYPE_ASD_GET_DEVICE_PCIE_INFO, + TA_PMF_ERROR_TYPE_SYS_DRV_FW_VALIDATION, + TA_PMF_ERROR_TYPE_MAX, +}; + +struct pmf_action_table { + u32 spl; /* in mW */ + u32 sppt; /* in mW */ + u32 sppt_apuonly; /* in mW */ + u32 fppt; /* in mW */ + u32 stt_minlimit; /* in mW */ + u32 stt_skintemp_apu; /* in C */ + u32 stt_skintemp_hs2; /* in C */ +}; + +/* Input conditions */ +struct ta_pmf_condition_info { + u32 power_source; + u32 bat_percentage; + u32 power_slider; + u32 lid_state; + bool user_present; + u32 rsvd1[2]; + u32 monitor_count; + u32 rsvd2[2]; + u32 bat_design; + u32 full_charge_capacity; + int drain_rate; + bool user_engaged; + u32 device_state; + u32 socket_power; + u32 skin_temperature; + u32 rsvd3[5]; + u32 ambient_light; + u32 length; + u32 avg_c0residency; + u32 max_c0residency; + u32 s0i3_entry; + u32 gfx_busy; + u32 rsvd4[7]; + bool camera_state; + u32 workload_type; + u32 display_type; + u32 display_state; + u32 rsvd5[150]; +}; + +struct ta_pmf_load_policy_table { + u32 table_size; + u8 table[POLICY_BUF_MAX_SZ]; +}; + +/* TA initialization params */ +struct ta_pmf_init_table { + u32 frequency; /* SMU sampling frequency */ + bool validate; + bool sku_check; + bool metadata_macrocheck; + struct ta_pmf_load_policy_table policies_table; +}; + +/* Everything the TA needs to Enact Policies */ +struct ta_pmf_enact_table { + struct ta_pmf_condition_info ev_info; + u32 name; +}; + +struct ta_pmf_action { + u32 action_index; + u32 value; +}; + +/* Output actions from TA */ +struct ta_pmf_enact_result { + u32 actions_count; + struct ta_pmf_action actions_list[TA_PMF_ACTION_MAX]; + u32 undo_count; + struct ta_pmf_action undo_list[TA_PMF_UNDO_MAX]; +}; + +union ta_pmf_input { + struct ta_pmf_enact_table enact_table; + struct ta_pmf_init_table init_table; +}; + +union ta_pmf_output { + struct ta_pmf_enact_result policy_apply_table; + u32 rsvd[TA_OUTPUT_RESERVED_MEM]; +}; + struct ta_pmf_shared_memory { int command_id; int resp_id; u32 pmf_result; u32 if_version; + union ta_pmf_output pmf_output; + union ta_pmf_input pmf_input; }; /* Core Layer */ @@ -460,4 +600,5 @@ extern const struct attribute_group cnqf_feature_attribute_group; /* Smart PC builder Layer */ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev); void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev); +int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev); #endif /* PMF_H */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 4036f435f1e2..92290d51a4af 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -42,9 +42,77 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd, param[0].u.memref.shm_offs = 0; } +static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) +{ + u32 val; + int idx; + + for (idx = 0; idx < out->actions_count; idx++) { + val = out->actions_list[idx].value; + switch (out->actions_list[idx].action_index) { + case PMF_POLICY_SPL: + if (dev->prev_data->spl != val) { + amd_pmf_send_cmd(dev, SET_SPL, false, val, NULL); + dev_dbg(dev->dev, "update SPL : %u\n", val); + dev->prev_data->spl = val; + } + break; + + case PMF_POLICY_SPPT: + if (dev->prev_data->sppt != val) { + amd_pmf_send_cmd(dev, SET_SPPT, false, val, NULL); + dev_dbg(dev->dev, "update SPPT : %u\n", val); + dev->prev_data->sppt = val; + } + break; + + case PMF_POLICY_FPPT: + if (dev->prev_data->fppt != val) { + amd_pmf_send_cmd(dev, SET_FPPT, false, val, NULL); + dev_dbg(dev->dev, "update FPPT : %u\n", val); + dev->prev_data->fppt = val; + } + break; + + case PMF_POLICY_SPPT_APU_ONLY: + if (dev->prev_data->sppt_apuonly != val) { + amd_pmf_send_cmd(dev, SET_SPPT_APU_ONLY, false, val, NULL); + dev_dbg(dev->dev, "update SPPT_APU_ONLY : %u\n", val); + dev->prev_data->sppt_apuonly = val; + } + break; + + case PMF_POLICY_STT_MIN: + if (dev->prev_data->stt_minlimit != val) { + amd_pmf_send_cmd(dev, SET_STT_MIN_LIMIT, false, val, NULL); + dev_dbg(dev->dev, "update STT_MIN : %u\n", val); + dev->prev_data->stt_minlimit = val; + } + break; + + case PMF_POLICY_STT_SKINTEMP_APU: + if (dev->prev_data->stt_skintemp_apu != val) { + amd_pmf_send_cmd(dev, SET_STT_LIMIT_APU, false, val, NULL); + dev_dbg(dev->dev, "update STT_SKINTEMP_APU : %u\n", val); + dev->prev_data->stt_skintemp_apu = val; + } + break; + + case PMF_POLICY_STT_SKINTEMP_HS2: + if (dev->prev_data->stt_skintemp_hs2 != val) { + amd_pmf_send_cmd(dev, SET_STT_LIMIT_HS2, false, val, NULL); + dev_dbg(dev->dev, "update STT_SKINTEMP_HS2 : %u\n", val); + dev->prev_data->stt_skintemp_hs2 = val; + } + break; + } + } +} + static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) { struct ta_pmf_shared_memory *ta_sm = NULL; + struct ta_pmf_enact_result *out = NULL; struct tee_param param[MAX_TEE_PARAM]; struct tee_ioctl_invoke_arg arg; int ret = 0; @@ -52,7 +120,10 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) if (!dev->tee_ctx) return -ENODEV; + memset(dev->shbuf, 0, dev->policy_sz); ta_sm = dev->shbuf; + out = &ta_sm->pmf_output.policy_apply_table; + memset(ta_sm, 0, sizeof(*ta_sm)); ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES; ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR; @@ -65,6 +136,12 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) return ret; } + if (ta_sm->pmf_result == TA_PMF_TYPE_SUCCESS && out->actions_count) { + dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, + ta_sm->pmf_result); + amd_pmf_apply_policies(dev, out); + } + return 0; } @@ -72,6 +149,7 @@ static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) { struct ta_pmf_shared_memory *ta_sm = NULL; struct tee_param param[MAX_TEE_PARAM]; + struct ta_pmf_init_table *in = NULL; struct tee_ioctl_invoke_arg arg; int ret = 0; @@ -80,10 +158,21 @@ static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) return -ENODEV; } + dev_dbg(dev->dev, "Policy Binary size: %u bytes\n", dev->policy_sz); + memset(dev->shbuf, 0, dev->policy_sz); ta_sm = dev->shbuf; + in = &ta_sm->pmf_input.init_table; + ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE; ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR; + in->metadata_macrocheck = false; + in->sku_check = false; + in->validate = true; + in->frequency = pb_actions_ms; + in->policies_table.table_size = dev->policy_sz; + + memcpy(in->policies_table.table, dev->policy_buf, dev->policy_sz); amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, &arg, param); ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); @@ -103,6 +192,52 @@ static void amd_pmf_invoke_cmd(struct work_struct *work) schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms)); } +static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) +{ + u32 cookie, length; + int res; + + cookie = readl(dev->policy_buf + POLICY_COOKIE_OFFSET); + length = readl(dev->policy_buf + POLICY_COOKIE_LEN); + + if (cookie != POLICY_SIGN_COOKIE || !length) + return -EINVAL; + + /* Update the actual length */ + dev->policy_sz = length + 512; + res = amd_pmf_invoke_cmd_init(dev); + if (res == TA_PMF_TYPE_SUCCESS) { + /* Now its safe to announce that smart pc is enabled */ + dev->smart_pc_enabled = PMF_SMART_PC_ENABLED; + /* + * Start collecting the data from TA FW after a small delay + * or else, we might end up getting stale values. + */ + schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms * 3)); + } else { + dev_err(dev->dev, "ta invoke cmd init failed err: %x\n", res); + dev->smart_pc_enabled = PMF_SMART_PC_DISABLED; + return res; + } + + return 0; +} + +static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) +{ + dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); + if (!dev->policy_buf) + return -ENOMEM; + + dev->policy_base = devm_ioremap(dev->dev, dev->policy_addr, dev->policy_sz); + if (!dev->policy_base) + return -ENOMEM; + + memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); + + return amd_pmf_start_policy_engine(dev); +} + static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) { return ver->impl_id == TEE_IMPL_ID_AMDTEE; @@ -146,7 +281,7 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev) goto out_ctx; } - size = sizeof(struct ta_pmf_shared_memory); + size = sizeof(struct ta_pmf_shared_memory) + dev->policy_sz; dev->fw_shm_pool = tee_shm_alloc_kernel_buf(dev->tee_ctx, size); if (IS_ERR(dev->fw_shm_pool)) { dev_err(dev->dev, "Failed to alloc TEE shared memory\n"); @@ -190,11 +325,19 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) return ret; INIT_DELAYED_WORK(&dev->pb_work, amd_pmf_invoke_cmd); - return 0; + amd_pmf_set_dram_addr(dev); + amd_pmf_get_bios_buffer(dev); + dev->prev_data = kzalloc(sizeof(*dev->prev_data), GFP_KERNEL); + if (!dev->prev_data) + return -ENOMEM; + + return dev->smart_pc_enabled; } void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) { + kfree(dev->prev_data); + kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); amd_pmf_tee_deinit(dev); } From patchwork Wed Oct 18 07:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426516 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 10E44CDB484 for ; Wed, 18 Oct 2023 07:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbjJRHE5 (ORCPT ); Wed, 18 Oct 2023 03:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235141AbjJRHEo (ORCPT ); Wed, 18 Oct 2023 03:04:44 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DDA8187; Wed, 18 Oct 2023 00:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQQj0p4LV4QpA69+ywFA+voVlTI4WPQj+tEXnVK7gIsLN+RiN7ep3UyqJnQypQgHqjCS/Z654hGkBmRgl/ReLGgvVuMf4XRvIpx3sbXg5VReBasjUOlmMC5nnq7/DwNj4wp+lYVikcKiI3gpLjxyjg1wKFkecIPQsbYPnQe/CHA6PwEnvfnUFskvTNWLDWnJfyJRdC5Jc/gntF8c+ffQC2hVFkdPal3r8eGkRoZSeWFjFwu4Ps++l4fkFcxY7jkVfR3YLEQIueDMtPFQ1lRsCd/bS6KUdKzmkEuo6s4x/ZTc0L47+eHgyXObMV/pYxYGAZkJdAsbvZgz4m+xYotKJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=c/YbupjGoS/lgXiknOa+geJjoTcviN3AVo7Z56beCcE=; b=OQazrWA44XrccgeL8kv0GOX36EGdnHKeDREENmFsCNIDGj6b4BsCxTWEdZDtIpyqK1SlANAaNAsnFUTl+eBPxsX9NC3mUW5eebuTZuVb3/zNvKePuoVIhhUXK7IkVxvrToEw1knJqR2omhwLO5IL6tHGaxrPLMMGU8yeinlVEhl47mnGeAbBpANdXiCos+j/QiXD99I7kuj+GGh1IYmMVYAqDmd7lsipOigfrGB+7kZcgoRr+6gkuPSppSVVsmyL2koNDV2G+euVi8wg0pL8a/LIv3g0Kl7bZhpYeym4rT1TxCKJGY8mFyE1KoqSX27ZWLlOjQPZJTJbLJqeqoKUVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c/YbupjGoS/lgXiknOa+geJjoTcviN3AVo7Z56beCcE=; b=nah/M899YXbtfJByiLd+sluvBXiGEGMaDKnhvT0WUv/lTE2exhkex6yJO7Kdd3tWulix4aeBixYy5fb5uWUQvUQXS+QXsXv/STUF1EvtsY+Cw/01MDo6/E8+G6c4KV1l1BNFE9AmpY9avCcxxhWizQx5ft39rA/EJG7qNJ9vGDU= Received: from CH2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:610:5a::35) by MN0PR12MB6175.namprd12.prod.outlook.com (2603:10b6:208:3c4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 07:04:36 +0000 Received: from DS3PEPF000099D9.namprd04.prod.outlook.com (2603:10b6:610:5a:cafe::6f) by CH2PR08CA0025.outlook.office365.com (2603:10b6:610:5a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:04:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D9.mail.protection.outlook.com (10.167.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:36 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:30 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 05/17] platform/x86/amd/pmf: change amd_pmf_init_features() call sequence Date: Wed, 18 Oct 2023 12:32:29 +0530 Message-ID: <20231018070241.2041529-6-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D9:EE_|MN0PR12MB6175:EE_ X-MS-Office365-Filtering-Correlation-Id: ea69804e-12b8-4422-d694-08dbcfa87d01 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JBNyQdYaYakuF0XqqCdY58mGryOhTQ24S384xe3PeLCy10BRHmULdn+JC/2ZooYm7UY5l+cF+9R7NtMWrT5Wh0a0e82XUt0YN2fWdsOsrmpwTQdjUfHNGGBTaVZ9Id/CHfbhtSP0sI4BmJvwSjXvxYJuj3zA3OgjlRFuIgG4jgNPH42fJRIbRUJ+QqydEso+LbqQpU4Pciv9EgTvgNbP7o0/ZCGTVIpF+Y2XyWwwekffuwFmgaHQfFtpOEJ289xHM+KVStHo5wYJOE1FJDcuk4r5ivNU1Ta7Ht9UjoJJFeBPodw5tY4wQnG2zEKuipRtI3gueZsV5eB5HpVT8LsrLGLEysCiufEbjJRrIn56RnEa1KdyA27Od2eiYdUXCVwZuGxQO+LCSzbe96Q9t6VIBRlhti9NRoqG7QhUV6qJoH7lhYk1FgZ7+KxQ2qLSlRcjd05R3z1UM7me68uuejbGAysVd1zvlP8V1gmq0IWWsDTi4CqcPPBewtvLMXPB6a6cxqXRNpQOJ02U3nM6mzBEmyiWDBf1onZstotCFsHmROsd5kaosVrII21WYk7Lgtj82oif8edeE9O8petgBbE1qo22d8GPgqJ9ECQuHZqpxBrZOCyf41lBKLsBK8MD93/thwNg3BkLqYjGBCbftcML0+po6W+M+6/sLoIFs7bzAiMQfTAjMpOpZou/BeTgHwH+TfFDF0/xEASNS/I8TSR/ZMf3Efe01emJ3/uJaQdRW2+cR854zt77GhAm4A8gUa7fKtQIPAZ0qGOq7vCxCRLNXb4e2cIvV0Yz5IRcewQB5T8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(39860400002)(396003)(136003)(230922051799003)(451199024)(64100799003)(82310400011)(186009)(1800799009)(46966006)(36840700001)(40470700004)(40460700003)(2616005)(1076003)(26005)(7696005)(16526019)(8936002)(426003)(336012)(83380400001)(41300700001)(7416002)(5660300002)(4326008)(8676002)(47076005)(2906002)(36860700001)(70206006)(70586007)(478600001)(316002)(54906003)(110136005)(81166007)(82740400003)(356005)(921005)(86362001)(36756003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:36.0847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea69804e-12b8-4422-d694-08dbcfa87d01 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D9.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6175 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org To sideload pmf policy binaries, the Smart PC Solution Builder provides a debugfs file called "update_policy"; that gets created under a new debugfs directory called "pb" and this new directory has to be associated with existing parent directory for PMF driver called "amd_pmf". In the current code structure, amd_pmf_dbgfs_register() is called after amd_pmf_init_features(). This will not help when the Smart PC builder feature has to be assoicated to the parent directory. Hence change the order of amd_pmf_dbgfs_register() and call it before amd_pmf_init_features() so that when the Smart PC init happens, it has the parent debugfs directory to get itself hooked. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index c8f6ec4c2e2c..4b8156033fa6 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -442,9 +442,9 @@ static int amd_pmf_probe(struct platform_device *pdev) apmf_acpi_init(dev); platform_set_drvdata(pdev, dev); + amd_pmf_dbgfs_register(dev); amd_pmf_init_features(dev); apmf_install_handler(dev); - amd_pmf_dbgfs_register(dev); dev_info(dev->dev, "registered PMF device successfully\n"); From patchwork Wed Oct 18 07:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426517 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 A5550C46CA1 for ; Wed, 18 Oct 2023 07:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344562AbjJRHE6 (ORCPT ); Wed, 18 Oct 2023 03:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbjJRHEr (ORCPT ); Wed, 18 Oct 2023 03:04:47 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2058.outbound.protection.outlook.com [40.107.220.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7356F9; Wed, 18 Oct 2023 00:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lAJoaIos2MkNSfoeU85PfWdt4cHE+TCCqOhQ60HWHdq3tZzIjyMTiJvTm+bXsXzXepsMnVYNYczYaf/0qJRe/zlTA0cGDev7uj9nN5EnQTGYiPi7EXRShm+s1lfE8Azlk3wxn2Cf8uAowoNofqv9o9dmCpDtSklIOZREqTiXmj4ZADnj/dyEPFmMEd6kGZxNDniGHMncVMQrBoXdNtjIekjDSeazSW0+EOgCeDeNb/WAcnM43Gc8Wu2VOSEUeg7MvT3Z6gsm7QAxnEwNvte+FtgdOq/tXtKYgvEeSuDp/LGVA94oGnQrudUwvw8jTeHSA4Jy3GCwOPg9Vwqtfskusw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EgzemWbGIIUfQbJlSwHL9FkZDTDt9S5i/epSx9F8Hng=; b=e/r1HCeMMk1QJddpttEyNI/v4OOfZlqHAhnarYqU5BVcSRGVW9iYwxeSZDRhoxKvf7feZnPBcUzq2kKqdBXV7SyBSCFOaLszJdHRoxHD/PQBEQ5UBikXUijy7z23SDLpHDZIvanV4m61Ii/Gn4/XtO00dPS9E8CfdRh6Hm4I1Tt2GdsQIgOPFSz+Abqs5DfBjXG9A8NJapLbDGui2JvT56+sUw5Jdq1019RRS55fpjonbcakhAkgXfXui/BoVwvqbKoTXn4OVmpP6DqEw8C/E28GSwf+wlzrZRlIYxG0aDsLZR56trsEHQ1h9rQkcLynRI4rAC20J/j2u2FhfFXC+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EgzemWbGIIUfQbJlSwHL9FkZDTDt9S5i/epSx9F8Hng=; b=c/GeKrpKmj4jtuU+MozOnl3gTPEBha1nRam5MhX+KEuoDaAPcEpCf7EqpE6KvKL0N7LnLvPfb+z1rztgbEF52qY2eOMeHP4JDPTLl+sU4qVSI3CLIR1GZ/lQ2p2umxq9p3CKjihMux4xSiZK/WE0Lc6hYdE5fSVhSBzJ2XNN9Nw= Received: from DS7P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::18) by PH7PR12MB9075.namprd12.prod.outlook.com (2603:10b6:510:2f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.47; Wed, 18 Oct 2023 07:04:41 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:8:2e:cafe::fe) by DS7P222CA0011.outlook.office365.com (2603:10b6:8:2e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.23 via Frontend Transport; Wed, 18 Oct 2023 07:04:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:41 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:36 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 06/17] platform/x86/amd/pmf: Add support to get inputs from other subsystems Date: Wed, 18 Oct 2023 12:32:30 +0530 Message-ID: <20231018070241.2041529-7-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D7:EE_|PH7PR12MB9075:EE_ X-MS-Office365-Filtering-Correlation-Id: 3af0ebc1-d2eb-4f32-d16e-08dbcfa8802b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 80AdMR1iWLH1ftn2T6DykvkFCMiUsWsSfYds2DFO8bWMkpaeS65LT9cQCdeI7n2wZT5MKXu3CxuKy+FijLBp/ozusqy4LTr8d88sHethPSa9GDRa0rRXUbedDMPsmH22thMuCzN3ur+kQfYSEgg+dQCiES29ZNL+28Vn702OOb7FFS4GE2Ge6sB2VhcPJn+RNRG94QklG4VcIwuk7JEyqI/R9pTfH0u/tGLKzTGGasNjVOudyrv6ld2QGHKdXFhKBe78pN+Yj/yRJKBPOy9qOQqTpCZd80CuBT88gFfY3yrYFRhQbe4E7aZBAkkyiA/WfZkSiVyWA3S0ItZew2BcZfh0HI7HzCbtbcuJkiomv8QWAGt2RVf5XiuDQ2VKdKOFWuR4tFTum73rmgUMSTVM2IyfL3rQ0vuCDwZvSPH7KVQPoUqcnwp4lwIdf6wt5NjDTAEAPO8ome/emURldg+I7d39epGZWHHd2l6i3qWW6zUTqgBCyXRzu6cB6DldfIJS2aSu+yva+PvMoqx+lo+5Uoe3CWmWvwBBf24ys/aZQchYEjqB/4Po1LXttUWMadg5sz8JNmZ8QKUHJMV6N2lxZm3mOVI8+Dnzg8fXc7TjUrzB21tHBuO4C4ivhs1GGfODD2ufR3TD+pVGlrpofj97TkD6NRqUzpLFutgPAaXp7Jt3jWXbFdC2/WtlALV7871b0iKDY6pFDAIYQOzojcT9CJQdYelLeUSjGPmGMzM6H/icTx+zcWvU4CJ9vuYwBg7jbJEhTgqbYTsI9soi7UW8BSsrCh9dgDNgpvwy3B2DMgw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(376002)(136003)(39860400002)(396003)(230922051799003)(1800799009)(186009)(82310400011)(451199024)(64100799003)(46966006)(40470700004)(36840700001)(86362001)(40480700001)(36756003)(40460700003)(2616005)(54906003)(1076003)(82740400003)(110136005)(81166007)(70586007)(356005)(921005)(36860700001)(8936002)(47076005)(5660300002)(6666004)(316002)(426003)(7696005)(336012)(83380400001)(478600001)(7416002)(16526019)(8676002)(4326008)(70206006)(41300700001)(2906002)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:41.4086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3af0ebc1-d2eb-4f32-d16e-08dbcfa8802b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9075 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org PMF driver sends changing inputs from each subystem to TA for evaluating the conditions in the policy binary. Add initial support of plumbing in the PMF driver for Smart PC to get information from other subsystems in the kernel. Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/Makefile | 2 +- drivers/platform/x86/amd/pmf/pmf.h | 18 ++++ drivers/platform/x86/amd/pmf/spc.c | 120 ++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 3 + 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/x86/amd/pmf/spc.c diff --git a/drivers/platform/x86/amd/pmf/Makefile b/drivers/platform/x86/amd/pmf/Makefile index d2746ee7369f..6b26e48ce8ad 100644 --- a/drivers/platform/x86/amd/pmf/Makefile +++ b/drivers/platform/x86/amd/pmf/Makefile @@ -7,4 +7,4 @@ obj-$(CONFIG_AMD_PMF) += amd-pmf.o amd-pmf-objs := core.o acpi.o sps.o \ auto-mode.o cnqf.o \ - tee-if.o + tee-if.o spc.o diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 092be501d4d3..a4a73b845c09 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -150,6 +150,21 @@ struct smu_pmf_metrics { u16 infra_gfx_maxfreq; /* in MHz */ u16 skin_temp; /* in centi-Celsius */ u16 device_state; + u16 curtemp; /* in centi-Celsius */ + u16 filter_alpha_value; + u16 avg_gfx_clkfrequency; + u16 avg_fclk_frequency; + u16 avg_gfx_activity; + u16 avg_socclk_frequency; + u16 avg_vclk_frequency; + u16 avg_vcn_activity; + u16 avg_dram_reads; + u16 avg_dram_writes; + u16 avg_socket_power; + u16 avg_core_power[2]; + u16 avg_core_c0residency[16]; + u16 spare1; + u32 metrics_counter; } __packed; enum amd_stt_skin_temp { @@ -601,4 +616,7 @@ extern const struct attribute_group cnqf_feature_attribute_group; int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev); void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev); int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev); + +/* Smart PC - TA interfaces */ +void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in); #endif /* PMF_H */ diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c new file mode 100644 index 000000000000..bd5061fdfdbe --- /dev/null +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD Platform Management Framework Driver - Smart PC Capabilities + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Authors: Shyam Sundar S K + * Patil Rajesh Reddy + */ + +#include +#include +#include +#include "pmf.h" + +static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + u16 max, avg = 0; + int i; + + memset(dev->buf, 0, sizeof(dev->m_table)); + amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, 0, 7, NULL); + memcpy(&dev->m_table, dev->buf, sizeof(dev->m_table)); + + in->ev_info.socket_power = dev->m_table.apu_power + dev->m_table.dgpu_power; + in->ev_info.skin_temperature = dev->m_table.skin_temp; + + /* Get the avg and max C0 residency of all the cores */ + max = dev->m_table.avg_core_c0residency[0]; + for (i = 0; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++) { + avg += dev->m_table.avg_core_c0residency[i]; + if (dev->m_table.avg_core_c0residency[i] > max) + max = dev->m_table.avg_core_c0residency[i]; + } + + avg = DIV_ROUND_CLOSEST(avg, ARRAY_SIZE(dev->m_table.avg_core_c0residency)); + in->ev_info.avg_c0residency = avg; + in->ev_info.max_c0residency = max; + in->ev_info.gfx_busy = dev->m_table.avg_gfx_activity; +} + +static const char * const pmf_battery_supply_name[] = { + "BATT", + "BAT0", +}; + +static int amd_pmf_get_battery_prop(enum power_supply_property prop) +{ + union power_supply_propval value; + struct power_supply *psy; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(pmf_battery_supply_name); i++) { + psy = power_supply_get_by_name(pmf_battery_supply_name[i]); + if (!psy) + continue; + + ret = power_supply_get_property(psy, prop, &value); + if (ret) { + power_supply_put(psy); + return ret; + } + } + + return value.intval; +} + +static int amd_pmf_get_battery_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + int val; + + val = amd_pmf_get_battery_prop(POWER_SUPPLY_PROP_PRESENT); + if (val >= 0 && val != 1) + return -ENODEV; + + in->ev_info.bat_percentage = amd_pmf_get_battery_prop(POWER_SUPPLY_PROP_CAPACITY); + /* all values in mWh metrics */ + in->ev_info.bat_design = amd_pmf_get_battery_prop(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN) / + MILLIWATT_PER_WATT; + in->ev_info.full_charge_capacity = amd_pmf_get_battery_prop(POWER_SUPPLY_PROP_ENERGY_FULL) / + MILLIWATT_PER_WATT; + in->ev_info.drain_rate = amd_pmf_get_battery_prop(POWER_SUPPLY_PROP_POWER_NOW) / + MILLIWATT_PER_WATT; + + return 0; +} + +static int amd_pmf_get_slider_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + int val; + + switch (dev->current_profile) { + case PLATFORM_PROFILE_PERFORMANCE: + val = TA_BEST_PERFORMANCE; + break; + case PLATFORM_PROFILE_BALANCED: + val = TA_BETTER_PERFORMANCE; + break; + case PLATFORM_PROFILE_LOW_POWER: + val = TA_BEST_BATTERY; + break; + default: + dev_err(dev->dev, "Unknown Platform Profile.\n"); + return -EOPNOTSUPP; + } + in->ev_info.power_slider = val; + + return 0; +} + +void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + /* TA side lid open is 1 and close is 0, hence the ! here */ + in->ev_info.lid_state = !acpi_lid_open(); + in->ev_info.power_source = amd_pmf_get_power_source(); + amd_pmf_get_smu_info(dev, in); + amd_pmf_get_battery_info(dev, in); + amd_pmf_get_slider_info(dev, in); +} diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 92290d51a4af..da6520f202e7 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -113,6 +113,7 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) { struct ta_pmf_shared_memory *ta_sm = NULL; struct ta_pmf_enact_result *out = NULL; + struct ta_pmf_enact_table *in = NULL; struct tee_param param[MAX_TEE_PARAM]; struct tee_ioctl_invoke_arg arg; int ret = 0; @@ -123,11 +124,13 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) memset(dev->shbuf, 0, dev->policy_sz); ta_sm = dev->shbuf; out = &ta_sm->pmf_output.policy_apply_table; + in = &ta_sm->pmf_input.enact_table; memset(ta_sm, 0, sizeof(*ta_sm)); ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES; ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR; + amd_pmf_populate_ta_inputs(dev, in); amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, &arg, param); ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); From patchwork Wed Oct 18 07:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426518 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 C790ACDB486 for ; Wed, 18 Oct 2023 07:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344577AbjJRHFA (ORCPT ); Wed, 18 Oct 2023 03:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344544AbjJRHE7 (ORCPT ); Wed, 18 Oct 2023 03:04:59 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2065.outbound.protection.outlook.com [40.107.92.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50FDEB0; Wed, 18 Oct 2023 00:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zd2nVx8B5YPruwRiNHCft5Z/ChaRz8n8xepajYEa5+f+pICfV4Oh4LXL4+6ZImAPOABfamV1INn38KFwMPKsc/IguIHn0C3hwNdCacnNqyjPj8Jc/Ozn0Xn89tOHI7taW5fFGLV2QMVBsjQSnoQm0VFhTpQy668NjNyTpU3J3mEbgkkUjSJZwp1XLWj+kdZVFnEXp5g//a1RFAoi1rTk3570sOuSI49VnHOUhA2LBy+7CqNpm8RIQJcWKvWAu2hWhsjGFHRF+eohDRCUuAmTVuKL4442jDw7IVDCj/UjCVGriWGAQ7aB3/yYaj6rYa0JMd4od4XVtlK45oKlphzr3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lRnV8D3E0uYtd/DpXul8m5iYsefn/BT3C3rU9K0Un+c=; b=b2u/u/UEf0wPIpa9vk8QR6UwmLbJPeiXd1vksl3QzV9BJA95S5g1c7LeEYLm5VLCOvOnXtjrL29cm8w87Jf2Ka/UfwPaPvXsNq1/HqnYKb6PnSseoQL51tkcYJZVYSOKuOi7ICg8uQviXYeQFUne8WvjQsm21p1jArpUrL1P9zGGT4ZFA1tFYGSD/WQ8Y8OuoQ2t49B2PTDa74FckUjprIJ+o14pyJBP/Yqg4DzYRwt+Nb6nlAuTx1mXpVzAUhJNEF+7/oU1m4kiNPHMoObKiTwqugn+e3+xXSCh8o0BN+yZ7hU+D8Wvm0NsoazXh5/Of5bmXaAU99Z39N53MiFLpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lRnV8D3E0uYtd/DpXul8m5iYsefn/BT3C3rU9K0Un+c=; b=3ID96Kf2DqLNyvAo8GyRWDx3sYq9DxpyJMy6J4JJ/H7hjhxFzVZGKV9EvvFmtYe3401RFha/J1TgWCAq9DPGcQsLk4iyk3AH0UuadUG6cEBJBCPVS8f05QEr+h/Eatmu+A3vpcvQCE8JWlJgd/wcbxa+NAnnjurYIxrYqmodt5I= Received: from DS7P222CA0016.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::8) by DM6PR12MB4156.namprd12.prod.outlook.com (2603:10b6:5:218::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Wed, 18 Oct 2023 07:04:55 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:8:2e:cafe::36) by DS7P222CA0016.outlook.office365.com (2603:10b6:8:2e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.23 via Frontend Transport; Wed, 18 Oct 2023 07:04:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:04:55 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:41 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 07/17] platform/x86/amd/pmf: Add support update p3t limit Date: Wed, 18 Oct 2023 12:32:31 +0530 Message-ID: <20231018070241.2041529-8-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D7:EE_|DM6PR12MB4156:EE_ X-MS-Office365-Filtering-Correlation-Id: fbf0bc29-e305-4c3e-1312-08dbcfa88846 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L0wWyKz+xBJa4TnniBNPMec7Oji+5277F7OayjQA4GKrp63/Vjhyy3zT6QlROlA/u8hpsljhld248fCff3Ewafzh1bVuHvjcdgulW2TqVecaz5p7N/0LZ0pv6Wuj7usIWDrLW7rsi356z3c+1wV98c/NT6G7VKO9YO/bCuE8boNjkRx77NjPKAfXoIKKBfoR6Ylfj0EPllKKHCZhErK7nx1HqWNhSwSA3skUJCw3pGrPsG6KdCq0Ck3sMi1QPlLziib7Q4ROspLIChvpQn4acwmzZsl9cDKYJhFt4Uoyy78RYOj/28a6EMvobsw+C5OpRpBaLWM0ghd6VHKk8wr4U3mkHxIgs1ur+8ArZbLNzDOV1hSo5BrXdA0Vd3Z3METN2DXzA9OFNauLM2okELexXo7A1Rmws02d4X7njCpgJbH4T0WVNtIRrwmIGcESzIHGKWPumznOzzQTwYW7xyqGWrtmXWuWr4RlfIXdmnwes6F4h4sYpOD14tkeHXDghNZ1xcWZY3LOxrm18usvlD8pl7K/pO/wuXggi8+jTp2AhtWnZ2MJFRjdQ+hCzALZV9o4J1uoR2zsHDRS8bXlNaxQOe9mkpz4hJ39lsXeHTmpUdUeUup1sHrSKI3agxNlPaO4BZ4BCmDYXXuTMZAIrziX3V4cGTLSonmnhsM13MTOxBz2VJ6P6JEsBHhdYa/D6Pz18W54Tg/Q0QeNrOLHNs+kHSPwa944z+1ynS/xtbawpsS+UZczgpYZDDjVv+1/KgVWGz/YyY9jYOzatd/dGQpmob0B7CzJTbgFkctjdAoG0ocYMJxErWWzQgQSrpzPzUcY X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(346002)(136003)(39860400002)(230922051799003)(451199024)(64100799003)(1800799009)(82310400011)(186009)(36840700001)(40470700004)(46966006)(26005)(36756003)(86362001)(921005)(356005)(81166007)(336012)(40480700001)(82740400003)(5660300002)(41300700001)(15650500001)(478600001)(2906002)(8936002)(7696005)(8676002)(2616005)(83380400001)(4326008)(1076003)(40460700003)(6666004)(110136005)(426003)(70206006)(316002)(54906003)(7416002)(47076005)(16526019)(36860700001)(70586007)(42413004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:04:55.0025 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fbf0bc29-e305-4c3e-1312-08dbcfa88846 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4156 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org P3T (Peak Package Power Limit) is a metric within the SMU controller that can influence the power limits. Add support from the driver to update P3T limits accordingly. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 3 +++ drivers/platform/x86/amd/pmf/tee-if.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index a4a73b845c09..781989c7dddd 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -49,6 +49,7 @@ #define GET_STT_MIN_LIMIT 0x1F #define GET_STT_LIMIT_APU 0x20 #define GET_STT_LIMIT_HS2 0x21 +#define SET_P3T 0x23 /* P3T: Peak Package Power Limit */ /* OS slider update notification */ #define DC_BEST_PERF 0 @@ -72,6 +73,7 @@ #define PMF_POLICY_STT_MIN 6 #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 +#define PMF_POLICY_P3T 38 /* TA macros */ #define PMF_TA_IF_VERSION_MAJOR 1 @@ -481,6 +483,7 @@ struct pmf_action_table { u32 stt_minlimit; /* in mW */ u32 stt_skintemp_apu; /* in C */ u32 stt_skintemp_hs2; /* in C */ + u32 p3t_limit; /* in mW */ }; /* Input conditions */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index da6520f202e7..6f4a59950b27 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -105,6 +105,14 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_ dev->prev_data->stt_skintemp_hs2 = val; } break; + + case PMF_POLICY_P3T: + if (dev->prev_data->p3t_limit != val) { + amd_pmf_send_cmd(dev, SET_P3T, false, val, NULL); + dev_dbg(dev->dev, "update P3T : %u\n", val); + dev->prev_data->p3t_limit = val; + } + break; } } } From patchwork Wed Oct 18 07:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426519 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 6669ACDB484 for ; Wed, 18 Oct 2023 07:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344595AbjJRHFP (ORCPT ); Wed, 18 Oct 2023 03:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344581AbjJRHFO (ORCPT ); Wed, 18 Oct 2023 03:05:14 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2046.outbound.protection.outlook.com [40.107.93.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE17BF9; Wed, 18 Oct 2023 00:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PAUAIaXiIT0IZZhnWYCHtiUh8JF1EfMKUfQVql1b+cb0FabD0J70rPPb1HciaKRMsYDoctQM6IEJX8+fly10NSCR6SJq0RQ7GLzZdSXaz3kKP5pYqGQl/AbiH4UceGGCVCXxJlq9FEqX/mrQmcOhZgMj5A5FauWYRDNTGHZ+aMtD9L7zZoIm5jCdStvauA/ZUaLgzNI5CHBc07t4veyhtAAyw39ERjuCnrcuwFi9NOaBQORLlmb8nlLhxI9Ys1cAweTQiFCtwkdOEsxUCsyDuvyCJT8W0H/uVcAQ6FSeUew8zq/RvRHZrz4g7Ooh0fzCp36yNvh4cPc3veptZxkZGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hYA5KfGG/0L/i7CPFFShfUwwWmK/hp6SSBbzVgnEYqo=; b=botN3DkQ8Q+3PbPRqdikW+dWo9Ryye4iAm4oyq42lBu1V8U42fNa0YfNsuus//v85ra0PqB85aTL+rQhFD813EuAAFX93RoZ7gy56zr/GdDl9urhlHwU1oLGm0bbqgnLYsZ0dXavkmiS3AdpR/YLCebEtDRLby2Ck9hqPNBZrpwSsR/hYnbgvcignmJ0kFJRcjkU4hiSov6ymoVT5W5uGhU23a0cV2g0F0L01wMO/ajyqT5jg9AtLxDQ/6OAmN8bof5or/Myt8GcFvOV42OzzeFniUH9Vlly3Cd6qw1o2A2YBICJ1ioru+b6qTz4+DOd5WaQAaK0GrWKtSXh0Nt35g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hYA5KfGG/0L/i7CPFFShfUwwWmK/hp6SSBbzVgnEYqo=; b=OmdnDHEwOycSJq+o2An26EAOBeFa+bc24KEXiGh9dcPSB7LlhnZVnni1vw6pdtZcY8hElGzNMVMSr5OCITDfjvJVh0SOr7HDc2LTRERzXilAhIt7YsZtTe+koEZXw55DELhNm+sD8CfEh/PVtmUqIYcRz7B/sG/H7wqciAa1FdU= Received: from BYAPR05CA0063.namprd05.prod.outlook.com (2603:10b6:a03:74::40) by LV8PR12MB9156.namprd12.prod.outlook.com (2603:10b6:408:181::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Wed, 18 Oct 2023 07:05:10 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:a03:74:cafe::18) by BYAPR05CA0063.outlook.office365.com (2603:10b6:a03:74::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.18 via Frontend Transport; Wed, 18 Oct 2023 07:05:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:09 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:04:54 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 08/17] platform/x86/amd/pmf: Add support to update system state Date: Wed, 18 Oct 2023 12:32:32 +0530 Message-ID: <20231018070241.2041529-9-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D5:EE_|LV8PR12MB9156:EE_ X-MS-Office365-Filtering-Correlation-Id: 3acee6cc-5ca6-40d3-6637-08dbcfa890d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hpDPma5l+gn5TsdlWu/0wpLBIm/MJVHOpMQlQ6y+uKM+qaiFf36Zp3FQU357aPpzP9bF8KLlspZXPBMHr2pdjV52IKWMe4gT0jr6Q2kQ+6Wo/b2WTtSEvUr7UV8TB82QxMmZd/lZW3qGJHQoIXnvN6jcDiJN4DUs6RgeafPvDhzlZQ9RB4HPf7htcAvyFWKBCVF5NLS8WAopLkABuh+ISRNSKFIsUykhncytRNGUgvK5O8WE9fL5XvO7KH+MPlSC/rf45utTDePEYn100Om8RjD/VNr8a34pV0eG0PRBVh4fjtfpv4dHjBJSe99VVTuhbACAZtYY55zjH0zBUszYiZsggBrg+YUVngwDTuNqiD2j7XXbxDx6Sf3N3aJfVAx06hEo2Ls5WaySHulP8Ja8FQc+MPm2rFb/QVGqT3CrIfntcytr/HqOs3yuJEIyrrB25lUODt9KY9twRC5IGfeRj1HZpciFgqtYgM4/gtMF7CW6ZWpiB0QTmQoF7JIC+n/KTe7r4KECcYMEQeOv9nJCVqZe50YVzPHtnPONWhtVbm5YHOrMA2HxD4+FkLs5Fhu3UEmgPgrjcO5ZBxfeOehjVVAE7/7+YDv3MZnHjycHXCwW4PG3Uk9df9BjphIh2C5LGvIqr7aCcC6O40jlmcrm1kZz/Qgs5rQHoC+b428hzEscyxmRXpBiqmZj0Z3EyFb0v1Bf8ba17U7S7Z6Fz82N8moQMgxhwGHV7e5FxpoNTJhAUed60Ca4Vn6uNcDkc/iN3mcI875Svt0X2CUZnk7wGWWtonT/7jrTa01JQINXXC8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(376002)(39860400002)(346002)(230922051799003)(82310400011)(186009)(451199024)(64100799003)(1800799009)(46966006)(36840700001)(40470700004)(8936002)(26005)(1076003)(54906003)(16526019)(7696005)(2616005)(110136005)(70206006)(316002)(70586007)(5660300002)(83380400001)(426003)(41300700001)(8676002)(4326008)(336012)(478600001)(6666004)(40460700003)(7416002)(47076005)(2906002)(15650500001)(40480700001)(82740400003)(81166007)(921005)(356005)(36860700001)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:09.2970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3acee6cc-5ca6-40d3-6637-08dbcfa890d2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9156 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org PMF driver based on the output actions from the TA can request to update the system states like entering s0i3, lock screen etc. by generating an uevent. Based on the udev rules set in the userspace the event id matching the uevent shall get updated accordingly using the systemctl. Sample udev rules under Documentation/admin-guide/pmf.rst. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/pmf.rst | 24 +++++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 9 +++++++ drivers/platform/x86/amd/pmf/tee-if.c | 34 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 Documentation/admin-guide/pmf.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guide/index.rst index 43ea35613dfc..fb40a1f6f79e 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -119,6 +119,7 @@ configure specific aspects of kernel behavior to your liking. parport perf-security pm/index + pmf pnp rapidio ras diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst new file mode 100644 index 000000000000..9ee729ffc19b --- /dev/null +++ b/Documentation/admin-guide/pmf.rst @@ -0,0 +1,24 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Set udev rules for PMF Smart PC Builder +--------------------------------------- + +AMD PMF(Platform Management Framework) Smart PC Solution builder has to set the system states +like S0i3, Screen lock, hibernate etc, based on the output actions provided by the PMF +TA (Trusted Application). + +In order for this to work the PMF driver generates a uevent for userspace to react to. Below are +sample udev rules that can facilitate this experience when a machine has PMF Smart PC solution builder +enabled. + +Please add the following line(s) to +``/etc/udev/rules.d/99-local.rules``:: + + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="0", RUN+="/usr/bin/systemctl suspend" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="1", RUN+="/usr/bin/systemctl hibernate" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/bin/loginctl lock-sessions" + +EVENT_ID values: +0= Put the system to S0i3/S2Idle +1= Put the system to hibernate +2= Lock the screen diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 781989c7dddd..fb9ce2593236 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -73,6 +73,7 @@ #define PMF_POLICY_STT_MIN 6 #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 +#define PMF_POLICY_SYSTEM_STATE 9 #define PMF_POLICY_P3T 38 /* TA macros */ @@ -445,6 +446,13 @@ enum smart_pc_status { }; /* Smart PC - TA internals */ +enum system_state { + SYSTEM_STATE_S0i3, + SYSTEM_STATE_S4, + SYSTEM_STATE_SCREEN_LOCK, + SYSTEM_STATE_MAX, +}; + enum ta_slider { TA_BEST_BATTERY, TA_BETTER_BATTERY, @@ -476,6 +484,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + enum system_state system_state; u32 spl; /* in mW */ u32 sppt; /* in mW */ u32 sppt_apuonly; /* in mW */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 6f4a59950b27..d48f980fb1db 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -24,6 +24,20 @@ MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (defau static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, 0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43); +static const char *amd_pmf_uevent_as_str(unsigned int state) +{ + switch (state) { + case SYSTEM_STATE_S0i3: + return "S0i3"; + case SYSTEM_STATE_S4: + return "S4"; + case SYSTEM_STATE_SCREEN_LOCK: + return "SCREEN_LOCK"; + default: + return "Unknown Smart PC event"; + } +} + static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd, struct tee_ioctl_invoke_arg *arg, struct tee_param *param) @@ -42,6 +56,20 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd, param[0].u.memref.shm_offs = 0; } +static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event) +{ + char *envp[2] = {}; + + envp[0] = kasprintf(GFP_KERNEL, "EVENT_ID=%d", event); + if (!envp[0]) + return -EINVAL; + + kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, envp); + + kfree(envp[0]); + return 0; +} + static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) { u32 val; @@ -113,6 +141,12 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_ dev->prev_data->p3t_limit = val; } break; + + case PMF_POLICY_SYSTEM_STATE: + amd_pmf_update_uevents(dev, val); + dev_dbg(dev->dev, "update SYSTEM_STATE : %s\n", + amd_pmf_uevent_as_str(val)); + break; } } } From patchwork Wed Oct 18 07:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426520 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 E5D67CDB483 for ; Wed, 18 Oct 2023 07:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344581AbjJRHFS (ORCPT ); Wed, 18 Oct 2023 03:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344601AbjJRHFR (ORCPT ); Wed, 18 Oct 2023 03:05:17 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2087.outbound.protection.outlook.com [40.107.100.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5FEEF9; Wed, 18 Oct 2023 00:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TjVQdFpWeapuslQvSvlrlVRY63QKotTttPjwnQwOzREYJstcnqgoYnJEcA/GaqJ+M9BLqc4LeV4uVbPckJ+4GOz/6VjJP8SqYrSjMnRyYd0J8iPgOKWOHv/B/o0YjcBdbJirsKjPYMZLwMFEQz2c8/nNhp1qUHvgx9Hh2JuA4B8JfY/RSed0rvXtwaPgr/CGHy4+/Io/MKb1QgEEkthhLfPW5HR8xnL8uB5tSl30yBxxUNpHC8bA2NfRuwd2VJiF8j+cjhrjWQpcIGYYmEZFjbGArAlxJg0oJ6FzyWtKuRpNXijsSeBX3EJpfrS6spU+akvoV65hGXFgJC1BoU0v9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H4ThUBmT2J1YBqouHs0nneydTTV69xNOBh60SWe/WSY=; b=iu6OEGS92r75iVG6TK1fu4Yobv/fPNyMjLxhcKcLu0pbcc/4v3KokBxShSc8Fkn4Z/L/4i1aOxmmae04K+TWj/6AVM9qlQJQvuOBKx1+bFPNE7d+g90oFRmGqkaNttIjfGY7cu+3YMfM7Gr5yHulib/Y8wqGuGfRf8noY5HXuYGm5hdA44n3NOMnJ/nNHLuUW9PEjIVQDwoXbJG7FdjruRV6GEdsdhuxc487Pgv1i2Pwry3su24EG9OwcATDJ5ChekFdejmOvfYhIBo5RwkzQS3LXwipRWXf1NTeswfSQ6UNc9RnG/duo1nT9Gx38iqA9XBKQQkyUr6VGPjrr5u7jg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H4ThUBmT2J1YBqouHs0nneydTTV69xNOBh60SWe/WSY=; b=IngRZRBo9zcTNusyWBCXeyYkC49dULujz8ZGMohK7I5lmkXYYarlYyHXFfridonlTNe/LeQZRNG0F3ibl0KVh28pC2zj35CfkUfxSURhjlEWX5Vrxx5QXUS3vlZ//8y/1dHm8rvnNnKy8QOJFiONLBpoDhrQb5Ii7kWM81loeMI= Received: from DS7P222CA0024.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::13) by DM8PR12MB5494.namprd12.prod.outlook.com (2603:10b6:8:24::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Wed, 18 Oct 2023 07:05:13 +0000 Received: from DS3PEPF000099D7.namprd04.prod.outlook.com (2603:10b6:8:2e:cafe::10) by DS7P222CA0024.outlook.office365.com (2603:10b6:8:2e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.23 via Frontend Transport; Wed, 18 Oct 2023 07:05:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D7.mail.protection.outlook.com (10.167.17.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:13 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:08 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 09/17] platform/x86/amd/pmf: Make source_as_str() as non-static Date: Wed, 18 Oct 2023 12:32:33 +0530 Message-ID: <20231018070241.2041529-10-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D7:EE_|DM8PR12MB5494:EE_ X-MS-Office365-Filtering-Correlation-Id: b656d6aa-f260-464d-81b8-08dbcfa89356 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HTVaVM7R3YN0MdgZofPICQkT1EgEkzz6dg2PoVh0yl3MptGvyaJpWCAxZtwvd94U5vfddzkfc94BX9acQd4hfGEYEmHiaOk4+6z3h2IuD3hDT4hzENoZO2NtEPxMljYhVFEJAh0/09J6tRsVaA6iL9L9JXhrf+oCML3CfzYbF84q5ZYgfUyAX7TeNe8Uu2eidAmIRnmNzEa2zK8tvmn50/DqtTtr5+1yJfqn8d1QRfC6U+5+MHMQg6H5Lq6a6McU8VJBu7Ncbbs0xzWSXz32vzGrKWJS7dC/s4FoPqENM6m/F7Z7H8reELrNKXjTeX9caziIQmCok+HRT38v4WUyciNIDULcFpdKeBEvH9zKbTPV7xvKrYTHn+h25cFcbSLVtVr/RT/0wB9AY2+oO5gaLFd+mr5hETK8WE3Mau8RaZilMTxbQq8uIIPi9SKsu6l/V4EzJflQ0vnO09PSk/2Dfo3hNm8UZ9jiJ1V56q4Y5FFcgINYMsxYIFVap3ELFWlTx67mpCZ16NZ37f+bu/BcEO1DkzMZf25sm7+xcFy1BnT3zfJ1u/DHkL51/FxL68w2nBBanxPLdL/CmxKNIEVq8ucJ1PjIjEBpoLiFy+ETfAYYjeKOhiNFMGfjSjBBz1pCmwhbnjuREbvkx1nGG6/YR6U12/WHMSXRV5ziDloXAkF6sMtE+/ERcEdWpUKmrCgL1QPhQdLDTEtvKat2pckkq7WUXJBKwAI2A5WQLcRPLHPqZLZ/uGlU2cvrEc27/xtbEglCHOQXKUD8aNXHdyFVFuJdKlhZ122NWB9GPsVm8Tk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(396003)(39860400002)(346002)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(82310400011)(40470700004)(46966006)(36840700001)(83380400001)(41300700001)(40460700003)(40480700001)(36756003)(2616005)(81166007)(2906002)(1076003)(86362001)(110136005)(54906003)(70206006)(5660300002)(7416002)(4326008)(8676002)(8936002)(70586007)(478600001)(316002)(6666004)(7696005)(426003)(336012)(921005)(356005)(26005)(16526019)(82740400003)(36860700001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:13.5651 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b656d6aa-f260-464d-81b8-08dbcfa89356 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D7.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5494 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add amd_pmf prefix to source_as_str() function, so that the function name does not look generic. As this is a helper function make it as non-static so that it can be reused across multiple PMF features. Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 1 + drivers/platform/x86/amd/pmf/sps.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index fb9ce2593236..216a9f795436 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -600,6 +600,7 @@ int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev, struct apmf_static_slider_granular_output *output); bool is_pprof_balanced(struct amd_pmf_dev *pmf); int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev); +const char *amd_pmf_source_as_str(unsigned int state); int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx); diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/pmf/sps.c index a70e67749be3..33e23e25c8b1 100644 --- a/drivers/platform/x86/amd/pmf/sps.c +++ b/drivers/platform/x86/amd/pmf/sps.c @@ -27,7 +27,7 @@ static const char *slider_as_str(unsigned int state) } } -static const char *source_as_str(unsigned int state) +const char *amd_pmf_source_as_str(unsigned int state) { switch (state) { case POWER_SOURCE_AC: @@ -47,7 +47,8 @@ static void amd_pmf_dump_sps_defaults(struct amd_pmf_static_slider_granular *dat for (i = 0; i < POWER_SOURCE_MAX; i++) { for (j = 0; j < POWER_MODE_MAX; j++) { - pr_debug("--- Source:%s Mode:%s ---\n", source_as_str(i), slider_as_str(j)); + pr_debug("--- Source:%s Mode:%s ---\n", amd_pmf_source_as_str(i), + slider_as_str(j)); pr_debug("SPL: %u mW\n", data->prop[i][j].spl); pr_debug("SPPT: %u mW\n", data->prop[i][j].sppt); pr_debug("SPPT_ApuOnly: %u mW\n", data->prop[i][j].sppt_apu_only); From patchwork Wed Oct 18 07:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426521 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 C2CA9CDB483 for ; Wed, 18 Oct 2023 07:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344646AbjJRHF1 (ORCPT ); Wed, 18 Oct 2023 03:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344605AbjJRHFY (ORCPT ); Wed, 18 Oct 2023 03:05:24 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2050.outbound.protection.outlook.com [40.107.244.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C69106; Wed, 18 Oct 2023 00:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gjaqjldn9/uSOgs538U0hdnLk5mmN4Os3eCBal8iBfj4LbKPhUTzu8RmSAazzERJHPkaMhjIL/ozj58Cc6m9DJWVK+cLjZiLKI7sQGPctOPIP4L5U/bGpias7ZS4Oqr5aR16zY45UiMMrHhh5cmHhpoPrQE2sMT6uaJMGzdD5yLpSSQXo7rnHZqUD1m+YLx3bpzRQ6dmbFrqxnmMROyezXc+rJdUBVkSjSTnAkNEgpq3acSAgL1ppWA9g57nyNoOz6bqSfqGZ7hQaWQ1y71aeK214Ut/YpH5NKZwimUuShTLYO2tZO7qbe+MHrf0D1+NtJXccj0wu7xnl8+3zhBN+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rBjDfLPTF3L4Dn4BsPvY1/IBlCDqHdYjqYkYqwm+TLY=; b=UYbi80V4dtIkl9PhgOSHLBn3kaeWLmyYoxOUH+5JxiI7jgabY6O6YUk+8ggk1E7QJDH9Jl0HaSitcFwv176bjycTbQAwactZnOPh7OkldeZxI02eDddUH6FQo8HjMk34PxQGZeX8eybScqaO3veb774s0fbe3oVXLV4UHMPNzN+v8aKe2T5/osVG3XkCDnxI1byOS7FUCE9xnmI+dAIOd7R1AP60FbQhCDGGekYJSw9PJNNqQw1f8NUS5Xlc/OMHvAXort9OCI/cMGwdMd7HD3iPQNjf4LC478YvT9oK/TJJosaVwWMX1Kbmyi9z6VlTngIhFt/ANHtciqE6onoYqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rBjDfLPTF3L4Dn4BsPvY1/IBlCDqHdYjqYkYqwm+TLY=; b=G/wzIbbnOis9BAg2u9s7MNPGh6rZSdxWUuvaBsIGh5yE0SbrQ10Y2QfLwTVHhLm9TEz/3G9f53ZLf7KUkAH9c1Dp/NW0/zqFmREi5scQslOzIto4DZDLPbtS/bwOiIjaW4JDbYDaFQATOiXbGl6Jc6NQi46J3nEnCazef3pejiE= Received: from DS7PR03CA0279.namprd03.prod.outlook.com (2603:10b6:5:3ad::14) by PH7PR12MB9067.namprd12.prod.outlook.com (2603:10b6:510:1f5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Wed, 18 Oct 2023 07:05:19 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::8a) by DS7PR03CA0279.outlook.office365.com (2603:10b6:5:3ad::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:05:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:18 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:13 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 10/17] platform/x86/amd/pmf: Add facility to dump TA inputs Date: Wed, 18 Oct 2023 12:32:34 +0530 Message-ID: <20231018070241.2041529-11-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D4:EE_|PH7PR12MB9067:EE_ X-MS-Office365-Filtering-Correlation-Id: da849d8e-ebab-44a8-b721-08dbcfa89699 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xsmZGsHI5M5NJeDW69HhQDGBDemtjuOJlbemDosKJGLguO3G9ojgkSxFt1BGiK0OLHEs1SGKSiKkXULoZn4N0SyAWO8ECn22Ttkba8xNQoEbHSJ2/RbKOyVpUBHyPcXDi54VzhjUi20u9ZSZI03a/+2Tf6LyGuQoJeQugBqWl2sBLipcN0H7RypvSTjZQTCwgm9Ii5c60Rg1wz4uq59ACum4+yuCpK8ds5yL97GtyopFgTdSitqC54LpyJ9AxU9tIDhnDsbfrC+opYv5KyO16ecamvo9lzAeLAfTrbD98MwDwQDIqANukBn8M2/2Jl5JiQlDRiLr0GICqP49krcJh3OLbgKxrF4C7IuDGFX5TBv+8GJBrESQQHBHEcRMsOYhr+EaXVV6V42fuj8tIgU1NYcbxpWXPwsJ4aa2JOnwMxlT3WiO4YOd1dG6hUsMtUj6X7yIzFRBHY8pcZmQPPxg/c8nK9n48/vR+GvE0Ke2ac7px5M+9Y5GosUk3jyQRfgRg2y3pBoTP+Y0+3zF4rwnmdUBJHxqN1SkJGbt8c3ft/GSp09ob86vDe4h98eoa58dhy2CJJAT5ybTMMQTq3FRTpeIi0BSPwNrpCtLBL0fSS7317WzntRHQ0uUY57mlqnfbnV0xCan1h7DOHberfCQU8TT9Ppanaq0iyQfGEU1YTsbhPgNqey5x6ZluD9EAMvGMYEcX2g3xitDB0rvE2vyPTB1YufMe3JBqDRWgTjMCHWbe7xObZuhIxodDxJJyiftxNcWkmtHoG+Yh7uwDDQB+0jK27NvmjrBAv4E3LZotQg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(396003)(39860400002)(136003)(230922051799003)(82310400011)(1800799009)(186009)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(40480700001)(36756003)(86362001)(40460700003)(26005)(110136005)(316002)(70206006)(70586007)(36860700001)(356005)(81166007)(921005)(82740400003)(54906003)(47076005)(336012)(83380400001)(7696005)(6666004)(1076003)(16526019)(2616005)(426003)(8936002)(478600001)(41300700001)(5660300002)(4326008)(8676002)(2906002)(7416002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:18.8981 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da849d8e-ebab-44a8-b721-08dbcfa89699 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9067 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org PMF driver sends constant inputs to TA which its gets via the other subsystems in the kernel. To debug certain TA issues knowing what inputs being sent to TA becomes critical. Add debug facility to the driver which can isolate Smart PC and TA related issues. Also, make source_as_str() as non-static function as this helper is required outside of sps.c file. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 3 +++ drivers/platform/x86/amd/pmf/spc.c | 37 +++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 1 + 3 files changed, 41 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 216a9f795436..593930519039 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -602,6 +602,7 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf); int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev); const char *amd_pmf_source_as_str(unsigned int state); +const char *amd_pmf_source_as_str(unsigned int state); int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx); int amd_pmf_set_sps_power_limits(struct amd_pmf_dev *pmf); @@ -632,4 +633,6 @@ int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev); /* Smart PC - TA interfaces */ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in); +void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in); + #endif /* PMF_H */ diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index bd5061fdfdbe..512e0c66efdc 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -14,6 +14,43 @@ #include #include "pmf.h" +#ifdef CONFIG_AMD_PMF_DEBUG +static const char *ta_slider_as_str(unsigned int state) +{ + switch (state) { + case TA_BEST_PERFORMANCE: + return "PERFORMANCE"; + case TA_BETTER_PERFORMANCE: + return "BALANCED"; + case TA_BEST_BATTERY: + return "POWER_SAVER"; + default: + return "Unknown TA Slider State"; + } +} + +void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + dev_dbg(dev->dev, "==== TA inputs START ====\n"); + dev_dbg(dev->dev, "Slider State : %s\n", ta_slider_as_str(in->ev_info.power_slider)); + dev_dbg(dev->dev, "Power Source : %s\n", amd_pmf_source_as_str(in->ev_info.power_source)); + dev_dbg(dev->dev, "Battery Percentage : %u\n", in->ev_info.bat_percentage); + dev_dbg(dev->dev, "Designed Battery Capacity : %u\n", in->ev_info.bat_design); + dev_dbg(dev->dev, "Fully Charged Capacity : %u\n", in->ev_info.full_charge_capacity); + dev_dbg(dev->dev, "Drain Rate : %d\n", in->ev_info.drain_rate); + dev_dbg(dev->dev, "Socket Power : %u\n", in->ev_info.socket_power); + dev_dbg(dev->dev, "Skin Temperature : %u\n", in->ev_info.skin_temperature); + dev_dbg(dev->dev, "Avg C0 Residency : %u\n", in->ev_info.avg_c0residency); + dev_dbg(dev->dev, "Max C0 Residency : %u\n", in->ev_info.max_c0residency); + dev_dbg(dev->dev, "GFX Busy : %u\n", in->ev_info.gfx_busy); + dev_dbg(dev->dev, "Connected Display Count : %u\n", in->ev_info.monitor_count); + dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); + dev_dbg(dev->dev, "==== TA inputs END ====\n"); +} +#else +void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) {} +#endif + static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { u16 max, avg = 0; diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index d48f980fb1db..0eba258f4040 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -182,6 +182,7 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) } if (ta_sm->pmf_result == TA_PMF_TYPE_SUCCESS && out->actions_count) { + amd_pmf_dump_ta_inputs(dev, in); dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, ta_sm->pmf_result); amd_pmf_apply_policies(dev, out); From patchwork Wed Oct 18 07:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426522 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 25C58CDB47E for ; Wed, 18 Oct 2023 07:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344601AbjJRHFk (ORCPT ); Wed, 18 Oct 2023 03:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344636AbjJRHFi (ORCPT ); Wed, 18 Oct 2023 03:05:38 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD810FA; Wed, 18 Oct 2023 00:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=loOOipVPsaP6LgBcQKNMcZFb3DTalmFjk8iYwSt6jKjCAvcKTslsKidCsCFJzEiuiS4j+wNLSQCKbpVWyxhMQfQMNIKnjjGF3+rV9avjtDHH7KE2d+DEM8/Cpku07hE8MLtbCWhEUIQwttEbMNwQgo5BpbaWQzU8Z2XGZhpIEJr7DdUkTONSS0ESRRVrMWC0IKS835aY12SP2I8JOxYiFAbz8k/mHvtx76Z22ceuAHXSTQRQqCXIKJVePFwBms6k8fyROhEVWagncrFJDkCcysTe5y9s4K8Y/rbM4ZKQ4mPfNaAimc0j80ZbAJ5189VOu1495Nd6J20AYw9CCdXhYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jleF8nXN/hSBwVBoyUl3lll/FoVl4X+JIAuvh/Peo0c=; b=IJkpi5mITP7Cl2VUA9c32K4wy9M9owtnR51FAA0zN33U2XghgCB0g6C+XCXh5xLzZtos1MaleHVVFB1xEfWihNrrwvfoZAfDanXKdmpYkOKYAB4egoBQx4Spv8S+rXX1rBNie9NYLmUH+Llfan1N+syBA9DzEcTsH1/EEEdNOcPCaWs4UrqzegWd8zt99vx3tmXSIPZMzMX+xulnkaOhIqyHIS7z6K3Ritrq40poqExguyS3qLTGBYj7XvPReEGiQ3RLkXxP7oNfX/AR6mOTSBtGhQoagJ+Dy+R6eAvylB0Z7ekcvITL3evADsvnKtYqQzkZbN7Y8o3nrVODeuB+uQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jleF8nXN/hSBwVBoyUl3lll/FoVl4X+JIAuvh/Peo0c=; b=Vx4rdsWMMAaFO1RH8P6ylRGh3rQd+fymXvqYj5LGdnOaAoaXo1bXR9KE110RHfNh017uORUcpaFoMTBdUCVdWMwmq2y7wloIc7PAYRc+vOaGN82MMYrS+0ag8EBpsjqaRTlk0LM+H8yUO0tzAHmTZ/rLPMiyr1z2U/MjDtO9uaY= Received: from DS7PR03CA0285.namprd03.prod.outlook.com (2603:10b6:5:3ad::20) by SJ0PR12MB5488.namprd12.prod.outlook.com (2603:10b6:a03:3ad::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.46; Wed, 18 Oct 2023 07:05:24 +0000 Received: from DS3PEPF000099D4.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::62) by DS7PR03CA0285.outlook.office365.com (2603:10b6:5:3ad::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:05:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D4.mail.protection.outlook.com (10.167.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:24 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:18 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 11/17] platform/x86/amd/pmf: Add capability to sideload of policy binary Date: Wed, 18 Oct 2023 12:32:35 +0530 Message-ID: <20231018070241.2041529-12-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D4:EE_|SJ0PR12MB5488:EE_ X-MS-Office365-Filtering-Correlation-Id: ba069f74-2885-4fc5-9134-08dbcfa899a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0BJMaUvPGkLhFezmwGaY/apCBi2iaOMHWEYMGstvmxjTRu9J2EwyooZbCIXxORFVEP8rk2GhgJwxBbVbsCSklzbYJ1eIWViU+mm/d4Xiyc7sZG6I9z/4Lj5Qd7n1o4XhKAj6Xw7kULrFTekRbiD1a/FG1xJDUSuTeAdjjeXzWdYBhYFWT0ufPvWjOWMlX1phcfT+LsrV0Rd/QQjC6GpzSlrrstdLvwZzMekhON71uPJrcmBRyMxVp+kfa+clGM0N0gupXcZUyfBIalM7RgKB9xee260eQU+41if41P4JotvPE+oTXFza69SS/6ib7LpfawJjVdrk7tFrPujcVXo4dYNT/YFxWiX4xLZ9fqw/RCI0PWkrt+AVGfPvSzUt85S+uM/zt8dqQLiXMelWs42u8WupQic+CfN/PztugVvQ9m0eXWFmB8C20nVPdI1jk2Gc7Z+K+73lP0qW+20TtC+LLdlsSjODu75H3iZyaPhy4PfGRTGP3FHu4ksG9T/95IOxGm7HQj1OtmV/BKZ6TmA1qqdqFRlZ0CRx7Qa+qxVEk2Scyj7JjwqKlAkkPTPmsXJhhD1mCSVFmu6umOChAIpnbZ5r7OThv7TgdLp1T+BfgYK3SlG6t452FrJHprqlw+aujA3U2+c5JkZ/49pnj+z6aPatC39eonA1faMf8xStr20UVocfUn+CA9iNw+2eXodQMKY8Qr5eXjFt2QWN1UPei0oNz+ycbdQ19j5INjsqP4lglRG9dlBOZ3xb4tcr1cjVXxanbbI2YnE4WyyJZP0z9GnIwYuiDOHxx+Yy0kRNfAo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(82310400011)(36840700001)(46966006)(40470700004)(6666004)(336012)(426003)(40480700001)(1076003)(40460700003)(478600001)(36860700001)(81166007)(36756003)(47076005)(921005)(83380400001)(16526019)(82740400003)(2906002)(70586007)(54906003)(41300700001)(2616005)(70206006)(316002)(356005)(110136005)(8936002)(86362001)(7696005)(7416002)(4326008)(5660300002)(8676002)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:24.1012 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba069f74-2885-4fc5-9134-08dbcfa899a0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5488 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org A policy binary is OS agnostic, and the same policies are expected to work across the OSes. At times it becomes difficult to debug when the policies inside the policy binaries starts to misbehave. Add a way to sideload such policies independently to debug them via a debugfs entry. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 1 + drivers/platform/x86/amd/pmf/tee-if.c | 67 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 593930519039..8712299ad52b 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -219,6 +219,7 @@ struct amd_pmf_dev { bool cnqf_supported; struct notifier_block pwr_src_notifier; /* Smart PC solution builder */ + struct dentry *esbin; unsigned char *policy_buf; u32 policy_sz; struct tee_context *tee_ctx; diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 0eba258f4040..6c4ce22ba518 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -8,6 +8,7 @@ * Author: Shyam Sundar S K */ +#include #include #include #include "pmf.h" @@ -16,9 +17,14 @@ /* Policy binary actions sampling frequency (in ms) */ static int pb_actions_ms = MSEC_PER_SEC; +/* Sideload policy binaries to debug policy failures */ +static bool pb_side_load; + #ifdef CONFIG_AMD_PMF_DEBUG module_param(pb_actions_ms, int, 0644); MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (default = 1000ms)"); +module_param(pb_side_load, bool, 0444); +MODULE_PARM_DESC(pb_side_load, "Sideload policy binaries debug policy failures"); #endif static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, @@ -269,6 +275,61 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) return 0; } +#ifdef CONFIG_AMD_PMF_DEBUG +static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, + size_t length, loff_t *pos) +{ + struct amd_pmf_dev *dev = filp->private_data; + int ret; + + /* Policy binary size cannot exceed POLICY_BUF_MAX_SZ */ + if (length > POLICY_BUF_MAX_SZ || length == 0) + return -EINVAL; + + dev->policy_sz = length; + if (copy_from_user(dev->policy_buf, buf, dev->policy_sz)) + return -EFAULT; + + ret = amd_pmf_start_policy_engine(dev); + if (ret) + return -EINVAL; + + return length; +} + +static const struct file_operations pb_fops = { + .write = amd_pmf_get_pb_data, + .open = simple_open, +}; + +static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) +{ + struct dentry *file = NULL; + + dev->esbin = debugfs_create_dir("pb", debugfs_root); + if (IS_ERR(dev->esbin)) + return -EINVAL; + + file = debugfs_create_file("update_policy", 0644, dev->esbin, dev, &pb_fops); + if (!file) + return -EINVAL; + + return 0; +} + +static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) +{ + debugfs_remove_recursive(dev->esbin); +} +#else +static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) +{ + return 0; +} + +static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {} +#endif + static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) { dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); @@ -281,6 +342,9 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); + if (pb_side_load) + amd_pmf_open_pb(dev, dev->dbgfs_dir); + return amd_pmf_start_policy_engine(dev); } @@ -382,6 +446,9 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) { + if (pb_side_load) + amd_pmf_remove_pb(dev); + kfree(dev->prev_data); kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); From patchwork Wed Oct 18 07:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426523 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 93D40CDB482 for ; Wed, 18 Oct 2023 07:05:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344631AbjJRHFr (ORCPT ); Wed, 18 Oct 2023 03:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344626AbjJRHFq (ORCPT ); Wed, 18 Oct 2023 03:05:46 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2072.outbound.protection.outlook.com [40.107.94.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96440111; Wed, 18 Oct 2023 00:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k3/liThR46bp1tsAS0ro+GLK/3AjPI5h/WHMqtbiYJLrxaqbRB95eLDkgY6KKvw8JpA3/TGI4d3DuJXA1X1DOIG7aKcB1GD8zCA7hNMJyqWH7PmkpHZuXIlM4kmzqOdU6OWrdzB56/SqAN4pjYJoZ6pakzd5td9OTnN5f0UGrYogOHMLXKengST/kg1LVKRoSvIQXusWW/baXXH/eSZbiEbdQXB1yO1JGFyxl1505fm2tNuw03ZJA/Ou+2PITD3qJTV1p6ZTlu0wp9L+eFa5D/kZgJnA7xcT8kyD1gHjQAqE3gS+O955TV5EDusd/+IO/s/7Z51apGfsvO+CmNi1/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GHp3TdCunsFu2okfyF3kzl9IEonGNelw3Q8a/BT3lsY=; b=gNr6LMgGNtMzuu3ge72hCy4UbIlSJM1Le5jJUStpFWCGKJg7un5gz1xnbQpIc3PcGRlE5/hiEBQ231AOCbuNP36MA7m/WOCAYlOSVg8WVKUV3Ysfnvs/GQaLDjd8LxBScOpKz32hZdjBqgUqfccFWGThRsaqbsoc7ZYr6eofbQiTDguMP9QvoRtZdOgPJMDVhNdE0YbgslcrogySGG4K0+06dsNm+B04QyOY/gSjWaCiJJSlQhAWulIUPU2m1R+pBH7fREWlfl8iq+qOEcrPCch2TgfRekBEZ4h5i9aOdgIiSXHTK6Iefb131c43vrhyK5eG2Zd0Pg68AKVVGA61kQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GHp3TdCunsFu2okfyF3kzl9IEonGNelw3Q8a/BT3lsY=; b=qifyOq68T902N+uDuoWI554Ebp6WDi9n3HIrk4tT3uJVqyI62wjTfv+sAeryck+PE3O9fERc8n442L/+otKTHuQuE91vbWDSTbtEHm6v5tCByxIrP0muxO/N245T2iRZZWdZ8vgN8dn90eIH2BXr52tJT1ZP05nvIjlzKqNlqnA= Received: from SA1P222CA0113.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c5::27) by IA1PR12MB6554.namprd12.prod.outlook.com (2603:10b6:208:3a2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 07:05:40 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:806:3c5:cafe::39) by SA1P222CA0113.outlook.office365.com (2603:10b6:806:3c5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:05:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:39 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:24 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 12/17] platform/x86/amd/pmf: dump policy binary data Date: Wed, 18 Oct 2023 12:32:36 +0530 Message-ID: <20231018070241.2041529-13-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4F:EE_|IA1PR12MB6554:EE_ X-MS-Office365-Filtering-Correlation-Id: a062e01f-42b4-4ea1-71c1-08dbcfa8a2f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h/E+raNnjGMwy0RRgZ/Wb7sxZp9mwQc7I7e0mRigaXlNCYSqIUZSTZhpO4T5luFpZF6MykiSfGTX3bXOHWVhwgvX0el59Kr1PxbBL48F09OJwaRS0J8AzBZcn9MZ2GmhJbXNdcmSar+DEehXpTIu9YTXW9xYVgijeive+SiyV5UE4gztOiWibgz9t7gIXfgG4kVp7LVcM9mnsVZ8OOHckqojvc+fqXFr42+ycOuKNSYTCyhXcixGdggxTJgRtmkkdWTzkI/WOk85M8BvXxwcPl9qrP/uaBimdIfUiC7ZVCPkPkTkBo4izsBI83OwYIBTbHxzZhgfqQT/HfvcLBVcfGlwezYhyVul/g5PlaLEh7/VGosKj6K/ah8aInv93jict8GAr3zKaXbegfU/NEwHmWgAS6BMHMUL72k+arIxLoFbU1gpcNtrEWQkbM8vjcxH8aAJo7RNG3Ujw3qjVrayHKPeNu72EdUftShJTDkGA4e0TShb4h7nUPRvrZR27eJo4do0ZPrU1vMyQFJkb9J1ZrEDQUAISJ8Mlu35Id3RNbttTL371QNz2VK1e6By0XrcFn0mGSJrU/6M2QQDrGK2nFSG/+VFdF97gNAecyjHuMykqdkByUlvxTS9ZfeI6zS5n/rJwllzAwFAr0CDZnlBsfYrccl7tpGqsrzcZhBp9xs575eAeI17FAp7rAw/ABITDbD3IQNBz6Spa5YydVfirdSf4EqDA4B2mBtQNiCS9njF1fHiIeGR9hVbxQTnHq7hYsrXMnnfjyAR0//2bkmjR7w8hVcCGZcXrF+I5c27W+s= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(136003)(346002)(376002)(230922051799003)(1800799009)(451199024)(186009)(82310400011)(64100799003)(36840700001)(40470700004)(46966006)(7416002)(6666004)(2906002)(7696005)(5660300002)(8936002)(4326008)(8676002)(41300700001)(70206006)(70586007)(54906003)(110136005)(40460700003)(316002)(478600001)(336012)(26005)(1076003)(2616005)(47076005)(40480700001)(16526019)(82740400003)(426003)(36756003)(36860700001)(921005)(81166007)(356005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:39.7972 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a062e01f-42b4-4ea1-71c1-08dbcfa8a2f4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6554 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Sometimes policy binary retrieved from the BIOS maybe incorrect that can end up in failing to enable the Smart PC solution feature. Use print_hex_dump_debug() to dump the policy binary in hex, so that we debug the issues related to the binary even before sending that to TA. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K Reviewed-by: Ilpo Järvinen --- drivers/platform/x86/amd/pmf/tee-if.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 6c4ce22ba518..2f5fb8623c20 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -276,6 +276,12 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) } #ifdef CONFIG_AMD_PMF_DEBUG +static void amd_pmf_hex_dump_pb(struct amd_pmf_dev *dev) +{ + print_hex_dump_debug("(pb): ", DUMP_PREFIX_OFFSET, 16, 1, dev->policy_buf, + dev->policy_sz, false); +} + static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, size_t length, loff_t *pos) { @@ -290,6 +296,7 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, if (copy_from_user(dev->policy_buf, buf, dev->policy_sz)) return -EFAULT; + amd_pmf_hex_dump_pb(dev); ret = amd_pmf_start_policy_engine(dev); if (ret) return -EINVAL; @@ -328,6 +335,7 @@ static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) } static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {} +static void amd_pmf_hex_dump_pb(struct amd_pmf_dev *dev) {} #endif static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) @@ -342,6 +350,7 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); + amd_pmf_hex_dump_pb(dev); if (pb_side_load) amd_pmf_open_pb(dev, dev->dbgfs_dir); From patchwork Wed Oct 18 07:02:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426524 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 461ECCDB484 for ; Wed, 18 Oct 2023 07:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344607AbjJRHFz (ORCPT ); Wed, 18 Oct 2023 03:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344647AbjJRHFx (ORCPT ); Wed, 18 Oct 2023 03:05:53 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2046.outbound.protection.outlook.com [40.107.212.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE1FE10C; Wed, 18 Oct 2023 00:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MdUVtnz/XNbD3aWxohct1XlVVE8qOw41PijLLiXCqOEvhdHabDOWy2rSFsMNN6ZiQEzyZdmiGvngxDrKwfTdx0uVR2mb0bkVekSupVELXeomI9r3DlizSmX1FpxFtJkf/zrN4ufElLnYCuw7OUCrZzvrCyFOrmyNzoUSpxJh2q57UXCUiSuTcN/S9sKLocf9xkdgy0zC4d+SdteWje2uA5RTKGjDjDjy1JWq5PZ3vYGHdn06JqDG1zeG82tD06oc5ETY0ZAg5OxSydxnIDb6D18IY+L40cRZ+WnEYnMcbodxxv+Je2FfGnc2R/PiVuV4L1LN4fy4FTMmVHkymt1xHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qfTTjC4lyHQdyOu8d/064peSpCtRg11dgK5kLZri7/0=; b=fQPj8lh9OceX6e7gUIt77Qk3WHhOGZfxb+oVRngyhkaVNzCSouamu2LUKGG9f6X//58eJkWipy8ljj4GUtSr6h2p8bsYjiTrWWlHSrvy/KeaN5Wd3mmKMxdJ6tdhzd9kti5kAgva/b6goK6+5x6ur2VcmkFKXHUQh5+fBGtHU/JZutv5A1V8iYv5Z4TGq3jmIDhn3IogkVg7PanTYUnQITLYLcFgsZj9+iOafphNaZhkc4hUaCx6CTyqPIwIwOWvZOIeoLe8M9oegGbJPdfpTzxr+KE1miX8e2LMdYXf0WMIHw4De0Rkm1Ec3aPkH9FT7ywmn9GRRqKKNO2FS00eNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qfTTjC4lyHQdyOu8d/064peSpCtRg11dgK5kLZri7/0=; b=HcfGCUbPxgNgHovdWoMUrVe7/MGj20ODHxbAuCUJBJ2JHTJ4MnCmAUARrQNM5lLwYZJLHxt0rVTiZzk7JxtZk8AkbCRK2iKHrYYoM9KT+d1f+5Anp33wf1OmqJkfDviTOtv8H1uHD6FkV63GD6hD3MDq2qpctY410oatDaSWr9U= Received: from SN7P222CA0026.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::24) by SJ0PR12MB6989.namprd12.prod.outlook.com (2603:10b6:a03:448::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Wed, 18 Oct 2023 07:05:45 +0000 Received: from SN1PEPF0002BA4D.namprd03.prod.outlook.com (2603:10b6:806:124:cafe::aa) by SN7P222CA0026.outlook.office365.com (2603:10b6:806:124::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:05:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4D.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:45 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:39 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 13/17] platform/x86/amd/pmf: Add PMF-AMDGPU get interface Date: Wed, 18 Oct 2023 12:32:37 +0530 Message-ID: <20231018070241.2041529-14-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4D:EE_|SJ0PR12MB6989:EE_ X-MS-Office365-Filtering-Correlation-Id: 047a6e42-1e64-46ed-c1bd-08dbcfa8a631 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kWTDNxsSAgtMtX6JYyxtrLGaxnbOANViQ9GasdB7Uk+Yz4hPr1L2AAUfzhEzZxUkgUTjdg7ohcwOdNyaDI5C3wpX6WJPfyhJrZLl8Fl2Ei+LxDtIhq5vmggaKG+BDvCoEgK9Oc3deOonVbN2S8LQsDPRytxhgftKOmR7uR/gktln3VzVWxVb/CPEWq8xx+EvuCPkKEOib6jlIuEZbGnNba2H20SK2yxjYRhYK0CpeB4HzNT1m/GnZgJ5R+jbISqe2R4lfSjmx/M0/6rpnA98qRs62l7alDYZ143bGpu2pbdfyh5uCFPDiOHK9PG71RnqHIfyyT4PF7ihFV8xz1thRHGoW9drLaSZjl7iOCuZksv6UgjZePtbJ6rj3IqO2WlQPsWtMzZlmqEikxIpqBH6un7lNeefZta++zJD6cpowWwOKb3jfGGw4WJXlV+DB+xGsECmbBmnLDmN5avQVldiyFN08JCey+QPkDMx30xQtVT7zzMpvFBoVoL1yCcuIlQ1Nk7NNmhCLko+aWw0rtwowMcpZSxDLRPQZCUdpwCkVmqNbU/BbpYaCiiwGWole2PBAivsYfWHoXscUP6miYaek5Mbe3dQP269dyPbZrD5L+YKxIIw29SXxUEc7U9fqKmS+sAp0QxklCkJ5jYC3oHjQAcS2sWd0M93pF9E6sPinUHsHj6Q7BroFO/iybdbjEoj9N14WfROft1sIUfLwCrxG8a8Uy+wPQ5KROWJtx5UdZ2eNQVATf16byogN2/xeOo4jgzp47A4z8a3mrAyfX4EN76eQpOAq7xbcqLBpottmMk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(39860400002)(346002)(396003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(82310400011)(40470700004)(36840700001)(46966006)(66899024)(40460700003)(40480700001)(70586007)(110136005)(478600001)(70206006)(41300700001)(54906003)(921005)(83380400001)(36860700001)(47076005)(86362001)(356005)(82740400003)(2616005)(316002)(336012)(7696005)(426003)(16526019)(26005)(1076003)(30864003)(81166007)(4326008)(7416002)(8676002)(36756003)(2906002)(8936002)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:45.2322 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 047a6e42-1e64-46ed-c1bd-08dbcfa8a631 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6989 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org In order to provide GPU inputs to TA for the Smart PC solution to work, we need to have interface between the PMF driver and the AMDGPU driver. Add the initial code path for get interface from AMDGPU. Co-developed-by: Mario Limonciello Signed-off-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/gpu/drm/amd/amdgpu/Makefile | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c | 138 ++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/core.c | 1 + drivers/platform/x86/amd/pmf/pmf.h | 3 + drivers/platform/x86/amd/pmf/spc.c | 13 +++ drivers/platform/x86/amd/pmf/tee-if.c | 26 +++++ include/linux/amd-pmf-io.h | 35 ++++++ 9 files changed, 220 insertions(+) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c create mode 100644 include/linux/amd-pmf-io.h diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile index 384b798a9bad..7fafccefbd7a 100644 --- a/drivers/gpu/drm/amd/amdgpu/Makefile +++ b/drivers/gpu/drm/amd/amdgpu/Makefile @@ -86,6 +86,8 @@ amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o +amdgpu-$(CONFIG_AMD_PMF) += amdgpu_pmf.o + # add asic specific block amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o \ dce_v8_0.o gfx_v7_0.o cik_sdma.o uvd_v4_2.o vce_v2_0.o diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index a79d53bdbe13..26ffa1b4fe57 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -50,6 +50,7 @@ #include #include #include +#include #include #include diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c new file mode 100644 index 000000000000..ac981848df50 --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -0,0 +1,138 @@ +/* + * Copyright 2023 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Author: Shyam Sundar S K + * + */ + +#include +#include "amdgpu.h" + +int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf) +{ + struct drm_device *drm_dev = pci_get_drvdata(pmf->gpu_dev); + struct drm_mode_config *mode_config = &drm_dev->mode_config; + struct amdgpu_device *adev = drm_to_adev(drm_dev); + struct drm_connector_list_iter iter; + struct drm_connector *connector; + int i = 0; + + /* Reset the count to zero */ + pmf->display_count = 0; + if (!(adev->flags & AMD_IS_APU)) { + DRM_ERROR("PMF-AMDGPU interface not supported\n"); + return -ENODEV; + } + + mutex_lock(&mode_config->mutex); + drm_connector_list_iter_begin(drm_dev, &iter); + drm_for_each_connector_iter(connector, &iter) { + if (connector->status == connector_status_connected) + pmf->display_count++; + if (connector->status != pmf->con_status[i]) + pmf->con_status[i] = connector->status; + if (connector->connector_type != pmf->connector_type[i]) + pmf->connector_type[i] = connector->connector_type; + + i++; + if (i >= MAX_SUPPORTED) + break; + } + drm_connector_list_iter_end(&iter); + mutex_unlock(&mode_config->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); + +static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device *cooling_dev, + unsigned long *state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + *state = backlight_get_brightness(bd); + + return 0; +} + +static int amd_pmf_gpu_get_max_state(struct thermal_cooling_device *cooling_dev, + unsigned long *state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + if (backlight_is_blank(bd)) + *state = 0; + else + *state = bd->props.max_brightness; + + return 0; +} + +static const struct thermal_cooling_device_ops bd_cooling_ops = { + .get_max_state = amd_pmf_gpu_get_max_state, + .get_cur_state = amd_pmf_gpu_get_cur_state, +}; + +int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf) +{ + struct drm_device *drm_dev = pci_get_drvdata(pmf->gpu_dev); + struct amdgpu_device *adev = drm_to_adev(drm_dev); + + if (!(adev->flags & AMD_IS_APU)) { + DRM_ERROR("PMF-AMDGPU interface not supported\n"); + return -ENODEV; + } + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + pmf->raw_bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!pmf->raw_bd) + return -ENODEV; + + pmf->cooling_dev = thermal_cooling_device_register("pmf_gpu_bd", + pmf, &bd_cooling_ops); + if (IS_ERR(pmf->cooling_dev)) + return -ENODEV; + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_gpu_init); + +void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf) +{ + thermal_cooling_device_unregister(pmf->cooling_dev); +} +EXPORT_SYMBOL_GPL(amd_pmf_gpu_deinit); diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index f246252bddd8..7f430de7af44 100644 --- a/drivers/platform/x86/amd/pmf/Kconfig +++ b/drivers/platform/x86/amd/pmf/Kconfig @@ -10,6 +10,7 @@ config AMD_PMF depends on AMD_NB select ACPI_PLATFORM_PROFILE depends on TEE && AMDTEE + depends on DRM_AMDGPU help This driver provides support for the AMD Platform Management Framework. The goal is to enhance end user experience by making AMD PCs smarter, diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 4b8156033fa6..c59ba527ff49 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -411,6 +411,7 @@ static int amd_pmf_probe(struct platform_device *pdev) } dev->cpu_id = rdev->device; + dev->root = rdev; err = amd_smn_read(0, AMD_PMF_BASE_ADDR_LO, &val); if (err) { diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 8712299ad52b..615cd3a31986 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -13,6 +13,7 @@ #include #include +#include #define POLICY_BUF_MAX_SZ 0x4b000 #define POLICY_SIGN_COOKIE 0x31535024 @@ -228,9 +229,11 @@ struct amd_pmf_dev { void *shbuf; struct delayed_work pb_work; struct pmf_action_table *prev_data; + struct amd_gpu_pmf_data gfx_data; u64 policy_addr; void *policy_base; bool smart_pc_enabled; + struct pci_dev *root; }; struct apmf_sps_prop_granular { diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 512e0c66efdc..cf4962ef97c2 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -44,6 +44,10 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "Max C0 Residency : %u\n", in->ev_info.max_c0residency); dev_dbg(dev->dev, "GFX Busy : %u\n", in->ev_info.gfx_busy); dev_dbg(dev->dev, "Connected Display Count : %u\n", in->ev_info.monitor_count); + dev_dbg(dev->dev, "Primary Display Type : %s\n", + drm_get_connector_type_name(in->ev_info.display_type)); + dev_dbg(dev->dev, "Primary Display State : %s\n", in->ev_info.display_state ? + "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } @@ -146,6 +150,14 @@ static int amd_pmf_get_slider_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_ return 0; } +static void amd_pmf_get_gpu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + amd_pmf_get_gfx_data(&dev->gfx_data); + in->ev_info.monitor_count = dev->gfx_data.display_count; + in->ev_info.display_type = dev->gfx_data.connector_type[0]; + in->ev_info.display_state = dev->gfx_data.con_status[0]; +} + void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { /* TA side lid open is 1 and close is 0, hence the ! here */ @@ -154,4 +166,5 @@ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_tab amd_pmf_get_smu_info(dev, in); amd_pmf_get_battery_info(dev, in); amd_pmf_get_slider_info(dev, in); + amd_pmf_get_gpu_info(dev, in); } diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 2f5fb8623c20..956e66b78605 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include "pmf.h" @@ -357,6 +358,19 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) return amd_pmf_start_policy_engine(dev); } +static int amd_pmf_get_gpu_handle(struct pci_dev *pdev, void *data) +{ + struct amd_pmf_dev *dev = data; + + if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->devfn == 0) { + /* Found the amdgpu handle from the pci root after walking through the pci bus */ + dev->gfx_data.gpu_dev = pdev; + return 1; /* Stop walking */ + } + + return 0; /* Continue walking */ +} + static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) { return ver->impl_id == TEE_IMPL_ID_AMDTEE; @@ -446,6 +460,15 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) INIT_DELAYED_WORK(&dev->pb_work, amd_pmf_invoke_cmd); amd_pmf_set_dram_addr(dev); amd_pmf_get_bios_buffer(dev); + + /* Get amdgpu handle */ + pci_walk_bus(dev->root->bus, amd_pmf_get_gpu_handle, dev); + if (!dev->gfx_data.gpu_dev) + dev_err(dev->dev, "GPU handle not found!\n"); + + if (!amd_pmf_gpu_init(&dev->gfx_data)) + dev->gfx_data.gpu_dev_en = true; + dev->prev_data = kzalloc(sizeof(*dev->prev_data), GFP_KERNEL); if (!dev->prev_data) return -ENOMEM; @@ -461,5 +484,8 @@ void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) kfree(dev->prev_data); kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); + if (dev->gfx_data.gpu_dev_en) + amd_pmf_gpu_deinit(&dev->gfx_data); + pci_dev_put(dev->gfx_data.gpu_dev); amd_pmf_tee_deinit(dev); } diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h new file mode 100644 index 000000000000..5f79e66a41b3 --- /dev/null +++ b/include/linux/amd-pmf-io.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * AMD Platform Management Framework Interface + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Author: Shyam Sundar S K + */ + +#ifndef AMD_PMF_IO_H +#define AMD_PMF_IO_H + +#include +#include +#include +#include + +#define MAX_SUPPORTED 4 + +/* amdgpu */ +struct amd_gpu_pmf_data { + struct pci_dev *gpu_dev; + struct backlight_device *raw_bd; + struct thermal_cooling_device *cooling_dev; + enum drm_connector_status con_status[MAX_SUPPORTED]; + int display_count; + int connector_type[MAX_SUPPORTED]; + bool gpu_dev_en; +}; + +int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); +int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf); +void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); +#endif From patchwork Wed Oct 18 07:02:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426525 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 033EDCDB47E for ; Wed, 18 Oct 2023 07:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344633AbjJRHF6 (ORCPT ); Wed, 18 Oct 2023 03:05:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344635AbjJRHF4 (ORCPT ); Wed, 18 Oct 2023 03:05:56 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC0C0B6; Wed, 18 Oct 2023 00:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hWzu3sIBQ5pgvfGKeURUftuiU1RSlzNISuCojYe+sK2QiYVq0hbGGfQu+KJ0sWmSCKCjWMUKJh8NfA0Hg07F34BgwsTpuF5R3uv4bpfvLSElJXNy7z3KEvn8pNs6+d8kIyHgxBDOuXy2GNFwNSlMnUAPfwtZBDBK76DtH/ShYjzWeH50RlyVdVt6/rBcIq8DjD5RoUkVSEDze16DrNPlysPylpgW8BI+uParTdtF/X/0xgqdgiRNvrsO0jtf71FgraGpQqsrxQwlT3Vfxsvh6tkKPkSsu8lG6LEHSeqJFxC5daTvSOsGriL2R7bXYQxnxT2iHlk/voK2Hc6r8KmYQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ovycl2j8PmF13Yq6U5nRt9Sf3Tz/3ozmIpNbPmiOBDA=; b=PcCgzMk0GoaoLWuQo0tq2YZ+w9NRE1mBRh0froCDNdCDfcCQK6H0E7MrwM0O/WLBF/oZjTiWN4y2cLHthYZTsWQ3HlziujkVei5Dy6h+zbs2xQHAXDg5vpGpR41mXjrLwuQzu7iZR1uyoL18unGdJfFLv40/EIkpQqy57+Z0l1cKEkN7kUg5+GVvk4Z2dBcqqccd1btac8MehvoSMJzEsouchDO9QxB3BRsKPKJ4vhvj+jL93vx+YMiQ6ewvzzkmpImDoeOlylsqJaNfycZGi50VxW9ajGTV5e/LFrvVTOcXlirCTZUxTpPdVHL7DXWOhUQNHzQw3fjsmTqdnBMXXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ovycl2j8PmF13Yq6U5nRt9Sf3Tz/3ozmIpNbPmiOBDA=; b=FdZHASeWUmsg6H/ZEjL1DtXkHL658OrSnFT5ov6X76cLMcvpaDWe5MC7bcudxGAE2mpxzhXuE723ASL2qXyC/YuX6u/N2GR3L5DcIeXEvDfKVIFLxzSlAnOObA00c8+iG4grBlT7o2g9wFgF08a06dhy6h4F6gl7OuWPHalqmBk= Received: from SN7P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::18) by CY8PR12MB8266.namprd12.prod.outlook.com (2603:10b6:930:79::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 07:05:50 +0000 Received: from SN1PEPF0002BA4D.namprd03.prod.outlook.com (2603:10b6:806:124:cafe::d8) by SN7P222CA0004.outlook.office365.com (2603:10b6:806:124::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:05:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4D.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:05:50 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:45 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v4 14/17] platform/x86/amd/pmf: Add PMF-AMDGPU set interface Date: Wed, 18 Oct 2023 12:32:38 +0530 Message-ID: <20231018070241.2041529-15-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4D:EE_|CY8PR12MB8266:EE_ X-MS-Office365-Filtering-Correlation-Id: 55a01764-1fb2-47e1-757a-08dbcfa8a950 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cWFxZoIPIEiPvurqdE0cziTJg9QMOkjj0F88PTLUPpXlChYChLS18sr1ww+KieWfsIC/BpZKCqrg5prDiKQG9n0j7/kJDD/fAHWkXOxOCU/hFn5I9LmQIryKjEa5j6XAlAmyoEQ2B8TrICaEMqEwhqwl90HTYhUcT3LRyclCcYaOaIduMjPTZhVwMy6NK0oqCn1aEuoMRibOXRZw2pIxYT481OC0pdY+VEzVnxW5Xd6+yFN9emT4k4EUzCSbrH6AfX4ZNdt2LCVrUdiM0Gb6P6JejvPW2T5G9z3v5nIY+spkpYQXPBNoZj+3UX3BPOUWmShgMh7p4y7lkMC4+piUSkCpIGLG3rSTyWr2JvFGke/BmMG4ArhbB18UQnL4eTk5Xd5SgzfOxxUbgwpNkgf77tX3HPMtvOtiToqLdicQf3ozPpWTUOoyLdPp2Z2wKkwQhMilqSIxnNvp83Z6dtKVWX6C7xS02ac7IUvLkA/Z+Yh30X4RVyGOkO82/NDREwwUryr8XqinK1bZKjN4Bw1nvfqQF3m06bv0sRfP9tjbRtkFYzjs2c8C9quRlS1qtSI02mr6m58/y9n3+qBQwBkALy9NFy/G0qeNpdfDCMhQWX3YoLwrL9PAz17ZKoJQ6uKl5KXrBZqBdo1BccCBJPAI+5AMqXWQUE30ajAXFTMda2UNSSROArGyqfnH1NX5ByYcgW7L6kDqdj+gp39OiXgcxBkla6r7YCjHTtDk2AgHSpxm1OnCKHurOt7CTzafPO6QDT9upuYHMeN+q++o9J1a9Rz9VyGDiZWTc6ULtASNzJA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(136003)(346002)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799009)(82310400011)(36840700001)(40470700004)(46966006)(16526019)(336012)(426003)(36756003)(7696005)(47076005)(6666004)(478600001)(36860700001)(110136005)(70206006)(70586007)(316002)(2616005)(83380400001)(1076003)(54906003)(26005)(41300700001)(5660300002)(921005)(7416002)(82740400003)(356005)(81166007)(4326008)(8936002)(8676002)(40460700003)(2906002)(40480700001)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:05:50.4197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55a01764-1fb2-47e1-757a-08dbcfa8a950 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8266 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org For the Smart PC Solution to fully work, it has to enact to the actions coming from TA. Add the initial code path for set interface to AMDGPU. Change amd_pmf_apply_policies() return type, so that it can return errors when the call to retrieve information from amdgpu fails. Co-developed-by: Mario Limonciello Signed-off-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c | 18 ++++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 2 ++ drivers/platform/x86/amd/pmf/tee-if.c | 21 +++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c index ac981848df50..57acfc32219a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -63,6 +63,23 @@ int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf) } EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); +static int amd_pmf_gpu_set_cur_state(struct thermal_cooling_device *cooling_dev, + unsigned long state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + backlight_device_set_brightness(bd, state); + + return 0; +} + static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long *state) { @@ -103,6 +120,7 @@ static int amd_pmf_gpu_get_max_state(struct thermal_cooling_device *cooling_dev, static const struct thermal_cooling_device_ops bd_cooling_ops = { .get_max_state = amd_pmf_gpu_get_max_state, .get_cur_state = amd_pmf_gpu_get_cur_state, + .set_cur_state = amd_pmf_gpu_set_cur_state, }; int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 615cd3a31986..641af94ba378 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -75,6 +75,7 @@ #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 #define PMF_POLICY_SYSTEM_STATE 9 +#define PMF_POLICY_DISPLAY_BRIGHTNESS 12 #define PMF_POLICY_P3T 38 /* TA macros */ @@ -488,6 +489,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + unsigned long display_brightness; enum system_state system_state; u32 spl; /* in mW */ u32 sppt; /* in mW */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 956e66b78605..b39f30a4f92d 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -77,8 +77,10 @@ static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event) return 0; } -static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) +static int amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) { + struct thermal_cooling_device *cdev = dev->gfx_data.cooling_dev; + unsigned long state; u32 val; int idx; @@ -154,8 +156,21 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_ dev_dbg(dev->dev, "update SYSTEM_STATE : %s\n", amd_pmf_uevent_as_str(val)); break; + + case PMF_POLICY_DISPLAY_BRIGHTNESS: + if (!dev->gfx_data.gpu_dev_en) + return -ENODEV; + + cdev->ops->get_cur_state(cdev, &state); + if (state != val) { + cdev->ops->set_cur_state(cdev, val); + dev_dbg(dev->dev, "update DISPLAY_BRIGHTNESS : %u\n", val); + } + break; } } + + return 0; } static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) @@ -192,7 +207,9 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) amd_pmf_dump_ta_inputs(dev, in); dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, ta_sm->pmf_result); - amd_pmf_apply_policies(dev, out); + ret = amd_pmf_apply_policies(dev, out); + if (ret) + return ret; } return 0; From patchwork Wed Oct 18 07:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426526 X-Patchwork-Delegate: jikos@jikos.cz 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 CCBAACDB482 for ; Wed, 18 Oct 2023 07:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjJRHGf (ORCPT ); Wed, 18 Oct 2023 03:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjJRHGe (ORCPT ); Wed, 18 Oct 2023 03:06:34 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2087.outbound.protection.outlook.com [40.107.243.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 258ABB6; Wed, 18 Oct 2023 00:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TMx3UUV9+IIC1sf1Bb8D4BBDOx3Ky255+awhBN1Ijv8Y3EXHmMobBa/+GleDaq7NiBEBi+ZF6BHM+29Jx1/1E4Kxf9SrYcjHYyRtpsJm5QCPewhS2oy7EQG0Sda31aQrAE6ZliQcEQlSfi5PCwDcT4JnPCuLfqWjO4bJlHSpyI530bl6szGNwR/eTu3TEtvH8Y+ounH7ieJ2c8HTMUOYuV0G0JYpjXHRzsQNekVvDbRGl3r924QgjeW/UxsPiiHZGFLHjv2Bbf3paTrcMMPuPl6As93gHI8LViTMd+gE5jE0xdHPDlFZr6J+IiK4N2JNQ2fHQTP787s7xP+DQlm5gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OuNFyqlpTn2w3FbqRjeEvX91fcvnPhkhZplxElTPv70=; b=JhMaU6yECpbZsWtEG7B4qP/PaCQx5hNw+v+jOqGHMuTRx4XkhRFNAs0DNZ8Zgpo2pckVqehZyX0K10FTGah+E56vNAHUgZCnEFKbrsoOIENo291s3Yu4iTov/q7ynHJrLSWtXAnBbuv5NwOhCYe/rssOmISlsffK91ZD8HhTPmk9uPqwVcSknbnhg5DralhQwr9jnWrpbUqsj4zz1oZd6qfxjnZofibRMFrEc2xWxEj/3M8fn6dWaWnngvFs6UqbNDL34yeIwdG8mEIoTFH0AkZ+qgDlN9u9ez2gQdCpli9uyp3e1mmg4sagSHLm92/+n3NvIZngXIPt0RY4QAm6XQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OuNFyqlpTn2w3FbqRjeEvX91fcvnPhkhZplxElTPv70=; b=mtgokX+IXXEFMsQozJjKVY1JIB99iGfcfSjmRUcx9wXuQahUTCyY52i5ENqoJWrKSSArk+3rvCZ9CUV/xhzsJKLFObfdIhj7ldCodXHt50Yr90TirXBTsSApxAa+sadpp6A9Zq0S5mgTyYfcUlCFbw6M/wvAaJhvUcu00ebuBOM= Received: from PR0P264CA0218.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1e::14) by SJ0PR12MB5612.namprd12.prod.outlook.com (2603:10b6:a03:427::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Wed, 18 Oct 2023 07:06:27 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10a6:100:1e:cafe::be) by PR0P264CA0218.outlook.office365.com (2603:10a6:100:1e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21 via Frontend Transport; Wed, 18 Oct 2023 07:06:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:06:26 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:05:50 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v4 15/17] HID: amd_sfh: rename float_to_int() to amd_sfh_float_to_int() Date: Wed, 18 Oct 2023 12:32:39 +0530 Message-ID: <20231018070241.2041529-16-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|SJ0PR12MB5612:EE_ X-MS-Office365-Filtering-Correlation-Id: dd3f4867-7784-4043-b40f-08dbcfa8bed6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qAPPFQHFy/3GOW2ufrdtheRuy7LSupWTTziCG88zkc/bp9liaNuoL6csv+XFhR70s0pomd1pxn3lsyrVnEqq5WafWSKjocHtcZwaC/40eKyuvkLlsyU5uZRDr84mPf90WYR5icZnvM9bWEe8mvLIOaqWIEHi3ne+HzRg5Y0qVCTzp16xqM9j+AKj8f+VzYAKLfj7fjaGRCgyRdBeAEf3HKK29NTUzpQgjHGmJrg+xCh8Jj3Mk5t0pZWFtceAocnvUQiSAtRbuohvYNEfHThMtzhn89NA2wRCys4LdEeocpyHcBvSKaN+LaDrpy1FFkXMjsAzjFnQHO9CF53fG0oxCTqY9WThXjvkbS95WRmMwirFZay9X1ExsNePpivv4E+v2P4WQBQx980Alh4JUoEoDotyZwITA188Dogn+friYxXgrmBOBJALGrgdynKkHcB4AawJGVLJeMvElW4cZhjGoX3WNbZSx327b6V2tkhrPGk1pC+9WSAQyKW/uxtVRaOUyDBAU93lYF89FkCekoh1V1jK6rJp16Ki6WZHB2+VtUxKNNrsOHuPcYd0qTrg+V+U9R0H7cH6JyO8oaxozOSxXBHuwAosc9r0YR/YjSLRWUjV3z/kh2M0eJH+KLgkJV+FY3zS+o2hz7sTHfHYJOO8k3KQ+YJ04xhv+VBFmBNqze9Slh+iN76N/IMgcAW4FZJPjJgnMdTSPIq4GUM3Af38YgEBtIz0Xxb+PIluNyW5+p/XJlPBSY0XzBy3GFS6bcp0cR9CEYEzJklx0mfdSarTbFI/hn5sInWLbiBJ8qdqMYE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(346002)(396003)(376002)(230922051799003)(186009)(1800799009)(82310400011)(64100799003)(451199024)(40470700004)(36840700001)(46966006)(54906003)(110136005)(70586007)(478600001)(70206006)(6666004)(2616005)(16526019)(26005)(86362001)(5660300002)(1076003)(426003)(316002)(7416002)(4326008)(8676002)(336012)(81166007)(2906002)(8936002)(41300700001)(36756003)(356005)(47076005)(921005)(36860700001)(7696005)(83380400001)(82740400003)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:06:26.5629 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd3f4867-7784-4043-b40f-08dbcfa8bed6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5612 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Basavaraj Natikar Current amd_sfh driver has float_to_int() to convert units from float to int. This is fine until this function gets called outside of the current scope of file. Add a prefix "amd_sfh" to float_to_int() so that function represents the driver name. This function will be called by multiple callers in the next patch. Co-developed-by: Shyam Sundar S K Signed-off-by: Shyam Sundar S K Signed-off-by: Basavaraj Natikar Reviewed-by: Ilpo Järvinen --- drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c | 22 +++++++++---------- .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c index 06bdcf072d10..dbc8c6943ca1 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c @@ -132,7 +132,7 @@ static void get_common_inputs(struct common_input_property *common, int report_i common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; } -static int float_to_int(u32 flt32_val) +int amd_sfh_float_to_int(u32 flt32_val) { int fraction, shift, mantissa, sign, exp, zeropre; @@ -200,9 +200,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&accel_data, sensoraddr, sizeof(struct sfh_accel_data)); get_common_inputs(&acc_input.common_property, report_id); - acc_input.in_accel_x_value = float_to_int(accel_data.acceldata.x) / 100; - acc_input.in_accel_y_value = float_to_int(accel_data.acceldata.y) / 100; - acc_input.in_accel_z_value = float_to_int(accel_data.acceldata.z) / 100; + acc_input.in_accel_x_value = amd_sfh_float_to_int(accel_data.acceldata.x) / 100; + acc_input.in_accel_y_value = amd_sfh_float_to_int(accel_data.acceldata.y) / 100; + acc_input.in_accel_z_value = amd_sfh_float_to_int(accel_data.acceldata.z) / 100; memcpy(input_report, &acc_input, sizeof(acc_input)); report_size = sizeof(acc_input); break; @@ -211,9 +211,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&gyro_data, sensoraddr, sizeof(struct sfh_gyro_data)); get_common_inputs(&gyro_input.common_property, report_id); - gyro_input.in_angel_x_value = float_to_int(gyro_data.gyrodata.x) / 1000; - gyro_input.in_angel_y_value = float_to_int(gyro_data.gyrodata.y) / 1000; - gyro_input.in_angel_z_value = float_to_int(gyro_data.gyrodata.z) / 1000; + gyro_input.in_angel_x_value = amd_sfh_float_to_int(gyro_data.gyrodata.x) / 1000; + gyro_input.in_angel_y_value = amd_sfh_float_to_int(gyro_data.gyrodata.y) / 1000; + gyro_input.in_angel_z_value = amd_sfh_float_to_int(gyro_data.gyrodata.z) / 1000; memcpy(input_report, &gyro_input, sizeof(gyro_input)); report_size = sizeof(gyro_input); break; @@ -222,9 +222,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&mag_data, sensoraddr, sizeof(struct sfh_mag_data)); get_common_inputs(&magno_input.common_property, report_id); - magno_input.in_magno_x = float_to_int(mag_data.magdata.x) / 100; - magno_input.in_magno_y = float_to_int(mag_data.magdata.y) / 100; - magno_input.in_magno_z = float_to_int(mag_data.magdata.z) / 100; + magno_input.in_magno_x = amd_sfh_float_to_int(mag_data.magdata.x) / 100; + magno_input.in_magno_y = amd_sfh_float_to_int(mag_data.magdata.y) / 100; + magno_input.in_magno_z = amd_sfh_float_to_int(mag_data.magdata.z) / 100; magno_input.in_magno_accuracy = mag_data.accuracy / 100; memcpy(input_report, &magno_input, sizeof(magno_input)); report_size = sizeof(magno_input); @@ -234,7 +234,7 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data)); get_common_inputs(&als_input.common_property, report_id); - als_input.illuminance_value = float_to_int(als_data.lux); + als_input.illuminance_value = amd_sfh_float_to_int(als_data.lux); report_size = sizeof(als_input); memcpy(input_report, &als_input, sizeof(als_input)); break; diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h index 9d31d5b510eb..78e22850417a 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h @@ -151,4 +151,5 @@ struct hpd_status { void sfh_interface_init(struct amd_mp2_dev *mp2); void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops); +int amd_sfh_float_to_int(u32 flt32_val); #endif From patchwork Wed Oct 18 07:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426527 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 1BBBECDB485 for ; Wed, 18 Oct 2023 07:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbjJRHGh (ORCPT ); Wed, 18 Oct 2023 03:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjJRHGg (ORCPT ); Wed, 18 Oct 2023 03:06:36 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2084.outbound.protection.outlook.com [40.107.101.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C0A9B6; Wed, 18 Oct 2023 00:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KFIZpDLUOaRq6aa7Rfy3SJfN/jXlLR6XOWai3/Vh4JkkiJlbPdNFPWwLYsQwy0EjfVaEnVHF4wyUI21ZaZJ1e3AW2rhrikcsRhmDV2SWbyNzfPjn4pX5rGSVS33/TD6fHY6ICzdtQHDfRhegsia4Nrv6uWpfWP7MeW9hXDXE3PWms77F96f9gd5SlqmWi94J0v8ntp56nrFyONQeEr8Gt/1bA0nhgz09oJe/CQOA6kJF0F/CjunisGrn4ElEjkq6LXRQCNBok6PeG13UgngsWc0cMT25mOvZm5iRh4AkA/NWtE/hxg9qoLBLdbi2Zn5h4spYXuuzRKZhA4aHr/mGqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=d6Rhl3f/cKcNKhHxVbmjiU4JIMtv5GNvT4blo37ris4=; b=MTrNSvhowCdM/LsS0jA1hQN3pXBLUIKxGqBhcVbp6oWc3ER8jRpvQD+YAidSTRmjels+1aQStj6jx/6iF6imSW34T8yNyGldfAqhwId0fT+GS+ebRWqSjec/QLjrTSsj880IYjxWcNBgTjxLQ0wCFlLeVdg2tI8D25MOZF/0V8nr0idfhSWGxUO1aE4I2EKMcTynqUEDpiEa33eyMmOirmeLoBJW66/iwIALKEWaJhV2FcXucm5z21EkV3ZwZrCUNCP4kJnLkithN9rOt/f9lWU9YfhiLIoEddbgmpiMK3nqxVyt8V+UBa5Yyi4ZhNDZ7oaMQNErv3Q43SYeyP1n7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d6Rhl3f/cKcNKhHxVbmjiU4JIMtv5GNvT4blo37ris4=; b=FzKklcaMKQh4zJdgWVfYHpjndle1WTkvYHTXaIfiR9M8TePIN24uBJ6NaZENotdQq1F24C2sew64GGMIByuAieMKnQH+WZlmXR6+Ww8v9fZ75zy5TTbTOPWbn/ILSzAVYy38HT10IwVrEqp1yThcaPo9QrmcEYXE5Mb3fZFwhzY= Received: from SN7PR04CA0221.namprd04.prod.outlook.com (2603:10b6:806:127::16) by SN7PR12MB6886.namprd12.prod.outlook.com (2603:10b6:806:262::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Wed, 18 Oct 2023 07:06:31 +0000 Received: from SN1PEPF0002BA51.namprd03.prod.outlook.com (2603:10b6:806:127:cafe::c) by SN7PR04CA0221.outlook.office365.com (2603:10b6:806:127::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:06:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA51.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:06:31 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:06:25 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v4 16/17] platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD Date: Wed, 18 Oct 2023 12:32:40 +0530 Message-ID: <20231018070241.2041529-17-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA51:EE_|SN7PR12MB6886:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f10b4a6-4066-414a-e7fa-08dbcfa8c195 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k49s6oOJ9LHBUIYHLiqyQ3c3TV7swt9wZzmahEZAkDH/srb8zDf4yxMkllENbbv/g7sPrejxaccmxKTftApc0G6RFYR8F/R6JxV3cStDH7R4uiN3HpOdwFjIDMhvhAbkEmzKm0BZGT00AbKXoC3NsSTDP+hfvCHXdnwWvPlOMAjvD1UgnwGXXggyemoB59A501qV7FvOgIIe+IOBtsI6OkPf2tlO14plhtgEqoIWyqv5Rbz4cMy2Gjazr3ZWXaVCi80BP93gW3Gqw91lkz+CS4LC46Ivzq7ONeOovVPf+HQX80Tjcff3jOXG4KET8PNMkv7XMGaSuUFr0/uqPfMRv6CF2mqWzCb3/J++0sgaigqHXobqHCJbDQQmU6WayOFBpn9Q52/dcOBxu8mzzgc70clr7S8932TFdeKe2kLQhELyWzLhF03rd0wYiK3eljg3fhTacNr2reIlYehF2H3axD6f2a63tgXqMunF3M2yPk7/J9SJBi8MshDbD4l+GlH0IDlYfwpnkIXO4N3y3By4f+PAlZA7OFKzmKU4+mfLsBOGCZzUd9div93NtSgZZXdaGALlhI26sU0J8F3v7YD52X9dahqTeCcIl8iu5d66qIJhE8wGtpF9QIWUPccgNTyZyNEpUsiM/fsGeoK548BNq3951QupWP7vT48eUQQjGZ2yxE8mN/rfEwpdiNK9O+6PrwCt0acmCGGux38UFES9P3Lpk+h2Xpzj0+k72QG+oiyyVJ0NjNHCXMhHBxOkRKe86ZsSgsguZijNIC0AO7GOSHEd9IODrMjzJx+et/O3ktw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(136003)(346002)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799009)(82310400011)(46966006)(36840700001)(40470700004)(1076003)(478600001)(316002)(110136005)(70586007)(41300700001)(7416002)(8676002)(4326008)(8936002)(54906003)(70206006)(5660300002)(7696005)(40480700001)(47076005)(356005)(86362001)(921005)(81166007)(82740400003)(36860700001)(16526019)(36756003)(336012)(83380400001)(26005)(6666004)(2906002)(40460700003)(426003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:06:31.1714 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f10b4a6-4066-414a-e7fa-08dbcfa8c195 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA51.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6886 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Basavaraj Natikar AMDSFH has information about the User presence information via the Human Presence Detection (HPD) sensor which is part of the AMD sensor fusion hub. Add PMF and AMDSFH interface to get this information. Co-developed-by: Shyam Sundar S K Signed-off-by: Shyam Sundar S K Signed-off-by: Basavaraj Natikar --- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 5 ++++ drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 11 ++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 28 +++++++++++++++++++ drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/spc.c | 21 ++++++++++++++ include/linux/amd-pmf-io.h | 20 ++++++++++++- 6 files changed, 85 insertions(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index 2643bb14fee2..cd57037bf217 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -37,6 +37,10 @@ struct amd_mp2_sensor_info { dma_addr_t dma_address; }; +struct sfh_dev_status { + bool is_hpd_present; +}; + struct amd_mp2_dev { struct pci_dev *pdev; struct amdtp_cl_data *cl_data; @@ -47,6 +51,7 @@ struct amd_mp2_dev { struct amd_input_data in_data; /* mp2 active control status */ u32 mp2_acs; + struct sfh_dev_status dev_en; }; struct amd_mp2_ops { diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c index e9c6413af24a..3dc652d41d7d 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c @@ -73,6 +73,12 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) int i, status; for (i = 0; i < cl_data->num_hid_devices; i++) { + switch (cl_data->sensor_idx[i]) { + case HPD_IDX: + privdata->dev_en.is_hpd_present = false; + break; + } + if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]); status = amd_sfh_wait_for_response @@ -178,6 +184,11 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) rc = amdtp_hid_probe(i, cl_data); if (rc) goto cleanup; + switch (cl_data->sensor_idx[i]) { + case HPD_IDX: + privdata->dev_en.is_hpd_present = true; + break; + } } dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c index 4f81ef2d4f56..7637da0dec6f 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c @@ -7,11 +7,14 @@ * * Author: Basavaraj Natikar */ +#include #include #include #include "amd_sfh_interface.h" +static struct amd_mp2_dev *emp2; + static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id) { struct sfh_cmd_response cmd_resp; @@ -76,4 +79,29 @@ static struct amd_mp2_ops amd_sfh_ops = { void sfh_interface_init(struct amd_mp2_dev *mp2) { mp2->mp2_ops = &amd_sfh_ops; + emp2 = mp2; +} + +static int amd_sfh_hpd_info(u8 *user_present) +{ + if (emp2 && emp2->dev_en.is_hpd_present) { + struct hpd_status hpdstatus; + + hpdstatus.val = readl(emp2->mmio + AMD_C2P_MSG(4)); + *user_present = hpdstatus.shpd.presence; + return 0; + } + return -ENODEV; +} + +int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op) +{ + if (sfh_info) { + switch (op) { + case MT_HPD: + return amd_sfh_hpd_info(&sfh_info->user_present); + } + } + return -EINVAL; } +EXPORT_SYMBOL_GPL(amd_get_sfh_info); diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 7f430de7af44..d368d35a49ac 100644 --- a/drivers/platform/x86/amd/pmf/Kconfig +++ b/drivers/platform/x86/amd/pmf/Kconfig @@ -11,6 +11,7 @@ config AMD_PMF select ACPI_PLATFORM_PROFILE depends on TEE && AMDTEE depends on DRM_AMDGPU + depends on AMD_SFH_HID help This driver provides support for the AMD Platform Management Framework. The goal is to enhance end user experience by making AMD PCs smarter, diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index cf4962ef97c2..8bdfb395f316 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -49,6 +49,7 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "Primary Display State : %s\n", in->ev_info.display_state ? "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); + dev_dbg(dev->dev, "User Presence : %s\n", in->ev_info.user_present ? "Present" : "Away"); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } #else @@ -158,6 +159,25 @@ static void amd_pmf_get_gpu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_ta in->ev_info.display_state = dev->gfx_data.con_status[0]; } +static void amd_pmf_get_sensor_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + struct amd_sfh_info sfh_info; + + /* get HPD data */ + amd_get_sfh_info(&sfh_info, MT_HPD); + switch (sfh_info.user_present) { + case SFH_NOT_DETECTED: + in->ev_info.user_present = 0xff; /* assume no sensors connected */ + break; + case SFH_USER_PRESENT: + in->ev_info.user_present = 1; + break; + case SFH_USER_AWAY: + in->ev_info.user_present = 0; + break; + } +} + void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { /* TA side lid open is 1 and close is 0, hence the ! here */ @@ -167,4 +187,5 @@ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_tab amd_pmf_get_battery_info(dev, in); amd_pmf_get_slider_info(dev, in); amd_pmf_get_gpu_info(dev, in); + amd_pmf_get_sensor_info(dev, in); } diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index 5f79e66a41b3..76e42552b62c 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -5,7 +5,8 @@ * Copyright (c) 2023, Advanced Micro Devices, Inc. * All Rights Reserved. * - * Author: Shyam Sundar S K + * Authors: Shyam Sundar S K + * Basavaraj Natikar */ #ifndef AMD_PMF_IO_H @@ -32,4 +33,21 @@ struct amd_gpu_pmf_data { int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf); void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); + +/* amd-sfh */ +enum sfh_message_type { + MT_HPD, +}; + +enum hpd_info { + SFH_NOT_DETECTED, + SFH_USER_PRESENT, + SFH_USER_AWAY, +}; + +struct amd_sfh_info { + u8 user_present; +}; + +int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op); #endif From patchwork Wed Oct 18 07:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Sundar S K X-Patchwork-Id: 13426528 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 12027C41513 for ; Wed, 18 Oct 2023 07:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344544AbjJRHGo (ORCPT ); Wed, 18 Oct 2023 03:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjJRHGn (ORCPT ); Wed, 18 Oct 2023 03:06:43 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2070.outbound.protection.outlook.com [40.107.220.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB19B6; Wed, 18 Oct 2023 00:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yb98mSS7L8NpXUDIqmJIGyfKJNV6TXpijjtN3Vyg8HGVd/mz7EMFrfclwpiQk0SX93Dzdz50cHQZ3gAUDWr0XmG6kVYw7AIdBDu8XPYTXN8tFebmtR4HL8gXYHBeA5dBFeQgXziuuElDVvO+QK0wn+vSB6IuSsQAovlWbkyDV6OIXKlla1L832fBf1Mx4Kokc5/WYc6QFYlNfggQfWAluKm/6iLLbdFWlA+HjjvUVVg3j5Ex52mI7i7yHrCIgWxmhV3VxT914FcQBpaIaaWtIhW0hT6ZN/IG6dbOIg2dqCU6lybbcRqZ+/f/D9+dzjW1AfXbitWrGwlYbWMFZ0rnsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wlLRLMyJ+Pqa2BgRo0txSc5xyb6Vj+O2+4CjXyORf2M=; b=htWDtrQ+kNebZvtM76m9p/KYXuGJJH4HuwfMjZEJ1Elu/7kZjeWoqGIRz12PLS3OlJpH8TXF8fohHsPVw4agGTV8pkLx22HanxJZlWEYrZHq158gv5SZymSXXvyGchGhaKopFILvXH4K0krImL/D9ghjPrhdQBARTGPNeF0bOWXZPypILd9PhW3T2Lr2/VRrxc2yuonDzQAKWc8OncDYTdtNo1DanqRNb7rOEW5R1pFDKulpolbQC3HQ3R9GPTOAesV4W5hL5NXybE0kSarDSV+F0i6XpR9aHLxcTOXesC7S6t2MvqdXn1zS0EKLiXIMlxDC7SflIZxeEUkveqkFuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wlLRLMyJ+Pqa2BgRo0txSc5xyb6Vj+O2+4CjXyORf2M=; b=SmIXbqhkJaF/USATv8YFUQSBQoCv628eD4K+9RwhwMsr8fRy96d6ZvVP0uz6SjGW7en7TjO66ha6j9ewj9SoTJuRxmjFdFjQKgJeVUIMZmbNCGgbGLiyREvS1f82Vw0RKqaj7FmEuYvkAj98n5faFAPP4XRll2Lw1w+wXJmq11M= Received: from PR0P264CA0238.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1e::34) by SJ2PR12MB8112.namprd12.prod.outlook.com (2603:10b6:a03:4f8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Wed, 18 Oct 2023 07:06:38 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10a6:100:1e:cafe::e4) by PR0P264CA0238.outlook.office365.com (2603:10a6:100:1e::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Wed, 18 Oct 2023 07:06:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Wed, 18 Oct 2023 07:06:36 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 18 Oct 2023 02:06:30 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v4 17/17] platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS Date: Wed, 18 Oct 2023 12:32:41 +0530 Message-ID: <20231018070241.2041529-18-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> References: <20231018070241.2041529-1-Shyam-sundar.S-k@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|SJ2PR12MB8112:EE_ X-MS-Office365-Filtering-Correlation-Id: 8aa24938-0691-4c41-be42-08dbcfa8c4f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q8PLaCaXIeLIG/i+E120aEUFR7i6+thN+m4jJd+QbB/DZsEoMikJ2YtjGmXA+4RdC3hN/DD41UNp8q5FIi5FZxWz8BI4KMloveCNGax+I6Yxw1qFy8ZzVC2e+DsGM/PlnPvoqzbi3c02Is2ypQFpW21MPjdPHIQdJEg03CVgTTYOYYPNGi5HrigpfXcqUcYr6rV0FYIfC7nta3TRVpZ7ObXv8QuvLhRZwGb5ZJNdJYCq7lx2jI5ioRBotGEQywddQyLN2+vPdaNZcrUB/FsZqO31AHkpzSxgm7aVuG/iV8lYgW6RempGSNj9zDln1P71c3Z3RjegRzOhyEhDvQo1vaKRKT3nl5n84je0/IzKssMnVRbcGIuO10ILRkhhrITrBVjbWOngd/CmFMlPFem4fMyN0m50mWBRX/6u5UBi1CfweqWRFMtLBEo9DTt0Ey+Ymi5q9CPIXYVxJyattUxOeHxqVvGzbLbBwByV1nATgXqHjmBFfOmiWLth0VL5QnCZ0o9Z6BdH78e1BlExD4icODVflefBeISBTm4EHRMAd556UESVP2ZNA4eY7AUK39vLDAa9tFcu7FKYR0Rqec3XVtve1a99ESemm20Rz4gatoPs0X18Xvjub9p7v5QRbdaJiDwuxidkv0Ud1UMcttA1qI8gWjMsSN/SZDh30sEXDKTHda7hLXIBSGAOgxzfY0acLcmWdEYTUIYwryZYxOBGM5AS+qxWU2vEaGMoN/EBOldqYkC3bGEulLcYy7+H3AHUbvDGJ3JeOl7r8hhpoMc64Bw7Q6hjPDZ7rnSTJnpvjCI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(376002)(136003)(230922051799003)(451199024)(82310400011)(186009)(64100799003)(1800799009)(40470700004)(46966006)(36840700001)(336012)(40480700001)(40460700003)(36756003)(921005)(82740400003)(47076005)(81166007)(356005)(1076003)(6666004)(36860700001)(83380400001)(7696005)(2906002)(54906003)(16526019)(478600001)(426003)(70586007)(70206006)(316002)(2616005)(110136005)(7416002)(26005)(8936002)(86362001)(41300700001)(5660300002)(4326008)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 07:06:36.8130 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8aa24938-0691-4c41-be42-08dbcfa8c4f2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8112 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Basavaraj Natikar AMDSFH has information about the Ambient light via the Ambient Light Sensor (ALS) which is part of the AMD sensor fusion hub. Add PMF and AMDSFH interface to get this information. Reviewed-by: Mario Limonciello Co-developed-by: Shyam Sundar S K Signed-off-by: Shyam Sundar S K Signed-off-by: Basavaraj Natikar --- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 1 + drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 6 ++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 20 +++++++++++++++++++ drivers/platform/x86/amd/pmf/spc.c | 9 ++++++++- include/linux/amd-pmf-io.h | 2 ++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index cd57037bf217..a1950bc6e6ce 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -39,6 +39,7 @@ struct amd_mp2_sensor_info { struct sfh_dev_status { bool is_hpd_present; + bool is_als_present; }; struct amd_mp2_dev { diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c index 3dc652d41d7d..f2890d329459 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c @@ -77,6 +77,9 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) case HPD_IDX: privdata->dev_en.is_hpd_present = false; break; + case ALS_IDX: + privdata->dev_en.is_als_present = false; + break; } if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { @@ -188,6 +191,9 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) case HPD_IDX: privdata->dev_en.is_hpd_present = true; break; + case ALS_IDX: + privdata->dev_en.is_als_present = true; + break; } } dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c index 7637da0dec6f..48a7a450e029 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c @@ -94,12 +94,32 @@ static int amd_sfh_hpd_info(u8 *user_present) return -ENODEV; } +static int amd_sfh_als_info(u32 *ambient_light) +{ + if (emp2 && emp2->dev_en.is_als_present) { + struct sfh_als_data als_data; + void __iomem *sensoraddr; + + sensoraddr = emp2->vsbase + + (ALS_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) + + OFFSET_SENSOR_DATA_DEFAULT; + memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data)); + *ambient_light = amd_sfh_float_to_int(als_data.lux); + + return 0; + } + + return -ENODEV; +} + int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op) { if (sfh_info) { switch (op) { case MT_HPD: return amd_sfh_hpd_info(&sfh_info->user_present); + case MT_ALS: + return amd_sfh_als_info(&sfh_info->ambient_light); } } return -EINVAL; diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 8bdfb395f316..934afe346f7e 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -50,6 +50,7 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); dev_dbg(dev->dev, "User Presence : %s\n", in->ev_info.user_present ? "Present" : "Away"); + dev_dbg(dev->dev, "Ambient Light : %d\n", in->ev_info.ambient_light); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } #else @@ -162,8 +163,14 @@ static void amd_pmf_get_gpu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_ta static void amd_pmf_get_sensor_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { struct amd_sfh_info sfh_info; + int ret; - /* get HPD data */ + /* Get ALS data */ + ret = amd_get_sfh_info(&sfh_info, MT_ALS); + if (!ret) + in->ev_info.ambient_light = sfh_info.ambient_light; + + /* Get HPD data */ amd_get_sfh_info(&sfh_info, MT_HPD); switch (sfh_info.user_present) { case SFH_NOT_DETECTED: diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index 76e42552b62c..912d341d5fbe 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -37,6 +37,7 @@ void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); /* amd-sfh */ enum sfh_message_type { MT_HPD, + MT_ALS, }; enum hpd_info { @@ -46,6 +47,7 @@ enum hpd_info { }; struct amd_sfh_info { + u32 ambient_light; u8 user_present; };