From patchwork Fri Sep 22 17:50:42 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: 13396214 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 9631FCD484D for ; Fri, 22 Sep 2023 17:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233499AbjIVRxW (ORCPT ); Fri, 22 Sep 2023 13:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233748AbjIVRw5 (ORCPT ); Fri, 22 Sep 2023 13:52:57 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2064.outbound.protection.outlook.com [40.107.101.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD55E1FF6; Fri, 22 Sep 2023 10:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aX3qKuIw2ppwANjrReY9DVAv1fbegUU6L71b3gl3WipFxFhL4Gw7FSzqgwl9HEdc9C+aTk04NeWnz2pb6X5vvgosdo705EfUJsc5qePh91wS3xasAFHtz2TUgUz8P0a9KjLvAJkzmjpJC3Fon8HZa0vS/ex3i2Cs6f0nHpR8+0kpCELEL14vrDE9tBmTcuy/VnptAGDK/gPkfUIWWab7aRqWDakKHfWEGOwcVH+c/RbPBP0/UG3eZoybtDg5FAqkMdDadSOBwd8F0islVGog6suTw1nD4kpysgyR/HQysoNGg8rVLKwKSNAKfuXVwDkDYrgR+NRJwoysGe4M7KeGqA== 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=8yga+7UQFKQtP/QYey0SK+wG6MEm3AkmEtCzUGXdYDI=; b=llsrMMWAhhVjHpuZOXZUZivlJl7OEg6Lfs1DmPMDTQrT/WvR/TmfGJVuH2VHdpcMf4zlg12xNf4aQUQPPAvGB77HUe1Zhm08ftNWYO63YhtQ6XDaChtoBSwkjHzZBYpDX2TLjDft5W1pJ/UTarbHMEA2cJYBcojt8teLR3OXvTuI+KcRw5tdcXOVED6tzC9+U1LCQzYRbRhFrdAL+/WOL2Ui5akIz31JjyUzLFj8IXHXlDjKJqx3AXuF9qbv3rlIUbvdz1hwiBsg0r8zmLa8booMm1kvp8yxnmP42ddCIrOfaYjFVsciYb+DpHy8kpRwL3hLnNnb3xgiqBKfQNgrQw== 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=8yga+7UQFKQtP/QYey0SK+wG6MEm3AkmEtCzUGXdYDI=; b=Eu3WPpwr0QgdWcKFINLR7xiKBpHWEnuo+hyl3aGAjtYN7GugDAyEtqrDKncoG8O0+QSJFjLuZnxluoGrQrsfiabIlSeojrI+G0J5hgYoq+6N4kYLW/72FRQyj76dwiQzTTa+WwLjGvxRm6Si5XVFX3kEJKKxK2qYKIzsXNGduM8= Received: from SA1P222CA0172.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::28) by IA1PR12MB6284.namprd12.prod.outlook.com (2603:10b6:208:3e4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Fri, 22 Sep 2023 17:51:53 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:806:3c3:cafe::45) by SA1P222CA0172.outlook.office365.com (2603:10b6:806:3c3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:51:53 +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 SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:51:52 +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; Fri, 22 Sep 2023 12:51:43 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 01/15] platform/x86/amd/pmf: Add PMF TEE interface Date: Fri, 22 Sep 2023 23:20:42 +0530 Message-ID: <20230922175056.244940-2-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: SA2PEPF000015CA:EE_|IA1PR12MB6284:EE_ X-MS-Office365-Filtering-Correlation-Id: ab059b00-99e1-4b21-cc33-08dbbb949a63 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: coWJCqFT6rF+o+FED2nuic4rINzmsggzQGkzV8zbOEBNsTTK4zNzL9JuWze/J5anAo3WtUw5B695ZfZFWsRNw5SsHFp53LAzW87KxXaAzPppb5Cbd5tTbd3VwshEq806zFET+hPqMiBVw8MyGd+q1EXxjYK5s0N2P7U0CkQ2A5MOuwdA2JlTssudBBMQYEfd4ZozCTkOxibg02K8T0KtCsQVblHYfb2Mbacsw3aj6LapQbEc1TwZQ5JnPR7sbIGt4z/WPbygeWF725Z481cSsIv5dXRmTHyEoU0dJWVV51nSufu6oajIScUfa0xgILhYzjbY5geFc4ra5n1MFm9ylcjgJthZMSaByU1uhysZAITsbGoH9U1VOVieAttJAKTZKWDYghR9Tt0sR8LAOdnQ39aqdFFo7NjB4lf9KizNpKkeG1lakz63QVV4gtjG7Or6VbHuvqA4LBDiT5QbaRD+UsJSONzC9O3GDHQmu/pJrh3t5NLn2YrMnMdofPR0A/oXKGF+g4w+1uuDP3pKFxnz+VSuvE93kxMsN88xt1hjdjssNw9NPNTIrDEz+mKsZgvkkFOkpl4LtBEA7wKbarSzWshoEzQMMomr2YihIvcLFC/YUyd17Y8YPf8soy96ymK/mfKfCR5Z7ouFnjbfQ4ZJmgj6p8jWBVJZrziOhx+OAK4FpJM1iLdraQRJvPP2RuWe/pw6vwTlwWwdSplSlzs5PkAcXTgkF94957HSyiCeIr01OrRn6inxuXdpxAWDDaE0fOzXxhRALMAYbG1cw5dsoZ30WdqZngB5nk4db9qZfuu1uRrbVhLx6V2R5YDdQYDmdKTIuIQqqM/6XQePhJ8n9Q== 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)(186009)(230921699003)(451199024)(1800799009)(82310400011)(36840700001)(46966006)(40470700004)(41300700001)(478600001)(110136005)(70586007)(70206006)(54906003)(83380400001)(316002)(47076005)(86362001)(4326008)(5660300002)(8676002)(8936002)(1076003)(16526019)(2616005)(36756003)(7416002)(26005)(7696005)(2906002)(36860700001)(82740400003)(356005)(40480700001)(921005)(336012)(81166007)(40460700003)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:51:52.2217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab059b00-99e1-4b21-cc33-08dbbb949a63 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6284 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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/Makefile | 3 +- drivers/platform/x86/amd/pmf/core.c | 11 ++- drivers/platform/x86/amd/pmf/pmf.h | 16 ++++ drivers/platform/x86/amd/pmf/tee-if.c | 106 ++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 drivers/platform/x86/amd/pmf/tee-if.c 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..68f1389dda3e 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -309,8 +309,11 @@ 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)) { + /* Enable Smart PC Solution builder */ + dev_dbg(dev->dev, "Smart PC Solution Enabled\n"); + } else if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) { + /* Enable 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) || @@ -330,7 +333,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..02460c2a31ea 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..b48340edbf44 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -0,0 +1,106 @@ +// 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("%s: tee_client_open_session failed err:%#x, ret:%#x\n", + __func__, sess_arg.ret, rc); + rc = -EINVAL; + } else { + *id = sess_arg.session; + } + + return rc; +} + +static int amd_pmf_tee_init(struct amd_pmf_dev *dev) +{ + int ret; + u32 size; + + /* Open context with TEE driver */ + 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, "%s: tee_client_open_context failed\n", __func__); + return PTR_ERR(dev->tee_ctx); + } + + /* Open session with PMF Trusted App */ + ret = amd_pmf_ta_open_session(dev->tee_ctx, &dev->session_id); + if (ret) { + dev_err(dev->dev, "%s: amd_pmf_ta_open_session failed(%d)\n", __func__, 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, "%s: tee_shm_alloc_kernel_buf failed\n", __func__); + ret = PTR_ERR(dev->fw_shm_pool); + goto out_sess; + } + + dev->shbuf = tee_shm_get_va(dev->fw_shm_pool, 0); + dev_dbg(dev->dev, "TEE init done\n"); + + return 0; + +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) +{ + /* Free the shared memory pool */ + tee_shm_free(dev->fw_shm_pool); + + /* close the existing session with PMF TA*/ + tee_client_close_session(dev->tee_ctx, dev->session_id); + + /* close the context with TEE driver */ + 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 Fri Sep 22 17:50:43 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: 13396216 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 27A1FCD484B for ; Fri, 22 Sep 2023 17:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233646AbjIVRxd (ORCPT ); Fri, 22 Sep 2023 13:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbjIVRxI (ORCPT ); Fri, 22 Sep 2023 13:53:08 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2054.outbound.protection.outlook.com [40.107.244.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 161041711; Fri, 22 Sep 2023 10:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hKs9jB74pdl7zfGDgpV1I8aedEISi5Xj0zlHqPFl/y+Q55O9+nuvXpbe4/CGmh3WeNBuD3ozj7nim4QN0rVm2vs+oiXEVm+4X3BY0/KE+ryt1XA0b7qYoLgyy55zBWM29rMjhFp0pBg9XcbXCYbI32TIg21xW0mhL4iaEQGhS1ziCQBPgxzi9UtqHKTfZ2JKkc7hFr07e4rbURGHKK4oInCzdgiPGW78UY7ljnWXB4vDxVb8Oj4iNunX4WDlEupYwdUzXvVnZtOVQObttPYnigWL+Us5GXGAc4lP/v3OILkHDO/BVTCIb0icGq4J0vdzqqQixw2B7IYXsj5IQ/Yhew== 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=4rGiesDEPc/x/okJXb/tTvuoPo44x9iNOUkjocF5IeU=; b=JSfv2TVVUYRuO3Vciq/s6CVODIJ88F5oX0NYIhDUFdHv+HAoEpJgPvflwzdxWL3/SRyZFjpW/PHRy+T8kain8eSyB2s1J2bM/dqESkDO7YkJ1KOkqWj39TQ+ROFKYAQpt02HW2pm8PWWzmFPwlmFruVPBcrecypUd2emgAjBJTfEwkDhwudIBiP4nvFOougYlrZRJiGYfXfTTGQgvfM+MW+ftEv1WIDK3khtb/WukeU3HRl9DgO00TXBMp0DnJ4YOyLfI4D+gS5arIWXqCXGprspheOg5quVR/3dupiwd6CWpQqohS8eYV9JooX+8S3U01VXq5O/9v8Xzm65meN2vA== 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=4rGiesDEPc/x/okJXb/tTvuoPo44x9iNOUkjocF5IeU=; b=r4VIZMuQ0BBJ9Yx7TeX/85mYqrwxCEXuttMa+9LGD4/6z08XGsC7sQQqtpbV1oiUyDw8u5VIq64p2VdhZZjZTA6+cuqTvmAAmNc0pu8EuxWvAHCsCNEKbGJyNNYzE/c9rwxlwrSLw2GUIVCVHhBUpixRrPVe5r5duLVN2XM8Ht8= Received: from SA1P222CA0172.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::28) by PH8PR12MB7350.namprd12.prod.outlook.com (2603:10b6:510:216::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Fri, 22 Sep 2023 17:51:54 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:806:3c3:cafe::29) by SA1P222CA0172.outlook.office365.com (2603:10b6:806:3c3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:51:53 +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 SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:51:53 +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; Fri, 22 Sep 2023 12:51:48 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 02/15] platform/x86/amd/pmf: Add support PMF-TA interaction Date: Fri, 22 Sep 2023 23:20:43 +0530 Message-ID: <20230922175056.244940-3-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: SA2PEPF000015CA:EE_|PH8PR12MB7350:EE_ X-MS-Office365-Filtering-Correlation-Id: e20a8ed7-572f-4021-ad07-08dbbb949b67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1bXoLgt+2RS6gv5cgpd1jNEILMH1tnDlgrlB63Itw6vQjnQ5IdrVXr4ZG32hMQLGVdoJkMfCFXjzlq3FZKD04SGyt4S04cP2UDr09622dy6jXFNEei+6hsBLTxR+sU2EZNcuahTBG1SzvXGz2KBJMO8eSVScUYjshWKt2a+Q0BjEDal1D34vPXg2UEvhddshbjzNF/4FUL2Hh9qX+nIRtLG1smrwCR+Wj+sFeVMQXFds042SSndSR3aWa9WrPEmX61eiFfbQr/aHmTseCLmDyawaA3Ht8ZyssPWaM0Xw0F85JihJpXTqiaVwlVoCfPUfp8ow5p12W0ID3V7SDaxZd56acrYqBQIIcHjSKORMDZrrPdov+50lNedHORsWbB6baCeocAWIe1dKYvy51a87lWv3s/f8uD7dhALG55nlcS1R+xqt+Kv4z/ICeWW2v9IUn7eEMbSWtZ9Q/9YwoTQW7aoQUEMKdaQ1qePBvEQ6sC4CYMbDK62qHvCnKFTVggNcGhDXylS/qe4YNP+7Tyw2PdT1VHqKH/xoQS/HfC1iG6xRYRsgdjUWWZ04a6rDmP0qFBtymh440zjW0u4JOQWzlhpt6cK1/Jo+07Ulo1vJWHrV7BpMleUbkRQX+aVhPEF+7eWaw8KuB0CRk0hY9mPsbZEUjqPJ2s13p9PRo58la/WY0wlrktX1a0MBzWJtLIQqLY5oh30wnDz0I2kuLGlJ1Sef2PPAS75WttQdkD0h8eSTMXTRH7IbxBzkK4n3tYUcv91dDVpfkq5uGM8rZZbGI3B4xqm3lxB4N45C7kJYriAGTNI0cW3yB2/tmDqjacFE81hpr5UySB9dmO0KuVjyFQ== 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)(451199024)(230921699003)(82310400011)(186009)(1800799009)(40470700004)(46966006)(36840700001)(478600001)(7696005)(40480700001)(5660300002)(86362001)(316002)(41300700001)(54906003)(110136005)(70206006)(70586007)(6666004)(2616005)(8936002)(921005)(356005)(81166007)(82740400003)(16526019)(26005)(47076005)(36860700001)(336012)(36756003)(426003)(4326008)(1076003)(8676002)(40460700003)(83380400001)(7416002)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:51:53.9249 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e20a8ed7-572f-4021-ad07-08dbbb949b67 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7350 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 02460c2a31ea..a9333ff6c0a7 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; +/* cmd 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 b48340edbf44..1fce04beacb3 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 = 1000; +#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 = (struct ta_pmf_shared_memory *)dev->shbuf; + memset(ta_sm, 0, sizeof(struct ta_pmf_shared_memory)); + 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, "%s failed TEE err: %x, ret:%x\n", __func__, arg.ret, ret); + return -EINVAL; + } + + 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, "%s tee_ctx no context\n", __func__); + return -ENODEV; + } + + ta_sm = (struct ta_pmf_shared_memory *)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, "%s failed TEE err: %x, ret:%x\n", __func__, arg.ret, ret); + return -EINVAL; + } + + 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; @@ -97,10 +184,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 Fri Sep 22 17:50:44 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: 13396215 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 C740ECD4850 for ; Fri, 22 Sep 2023 17:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233647AbjIVRxf (ORCPT ); Fri, 22 Sep 2023 13:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233568AbjIVRxJ (ORCPT ); Fri, 22 Sep 2023 13:53:09 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2041.outbound.protection.outlook.com [40.107.92.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BC282101; Fri, 22 Sep 2023 10:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QAmxYIIP7I9kSj6MiOvU61T9dqQmn+SRXa0oYVipEKiiZJEyzvjd+VKq61V7eHGePNZCNh17/HskD7DmhLwExnrBfoBfi0zUmoW33q36QBa4hu7twvV/6GmSAoymlCkxGDDcFealKLw8VBKydKMBmjyggsEAfACYILBJmzub1hVXnqWgrA6eBQFe6iaDWa/kors0UlRL0r2mE4eQkshYmkthtlxadDYRJ93ddc2VFqk4RSJiwiDFM/hlW7sWb5tJ7ME629lE+zn3yjGOjLt96vAGD870D3nqMsf3p6o7jx60hpL+7mPlk+2PasZmegcPVCpF/UmO8eYO+QaIjyuLWg== 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=aL//3y7UzczxCd1EtG0BGZayUc/qVAf2wxPRQTYYYRg=; b=FRFGKBX5vq9H1GOKfyazU8tAyu6Z7o+lJL6BQwbZF0/vryqj4p1Tzlc0r68/nTM3l6dlg6Y89QvO7Ih3de1CUQzNg5AGvnvO5OrcVosQ2vss11vOHbF1WSEmXaEhf7UY05LP7biVan5ioMpuFm9iN5oE+6MPn/v9ciCHjtwlLSGsUi5clf/5X6ZReJZgH+sw3BbLPCUzTFj1SFofETeLUtwccDCLrOlA7BAnnwa7GMHvMo3rdL8BkhHnxE2zGaFw6EEqRREKyrxnO3iGYyjKOs1Bofe60q/F4cg0b7ji74LPjSdgP8Gc+LgdDcQ+niqpwhxnmSrQe/S9oosDdlnwbA== 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=aL//3y7UzczxCd1EtG0BGZayUc/qVAf2wxPRQTYYYRg=; b=b5fOItkxGkp28OYI2kmuEEJhGeNIMAoh4kTSglTS2lXWbHEe7mOUpyoWQh7TiNAtGTjAJIIEmZMgwBnEK1IlZeGvfCZjqDYkBVWbfW3oufgk/QPLldFIHln9ASCGlJq52YMTkha9lkC6zt+4CSMBpvwvOYQUAHVktRkAOzTrhaQ= Received: from MN2PR11CA0027.namprd11.prod.outlook.com (2603:10b6:208:23b::32) by MN0PR12MB6223.namprd12.prod.outlook.com (2603:10b6:208:3c1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Fri, 22 Sep 2023 17:51:58 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::df) by MN2PR11CA0027.outlook.office365.com (2603:10b6:208:23b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.32 via Frontend Transport; Fri, 22 Sep 2023 17:51:58 +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 BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:51:58 +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; Fri, 22 Sep 2023 12:51:53 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 03/15] platform/x86/amd/pmf: Change signature of amd_pmf_set_dram_addr Date: Fri, 22 Sep 2023 23:20:44 +0530 Message-ID: <20230922175056.244940-4-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A102:EE_|MN0PR12MB6223:EE_ X-MS-Office365-Filtering-Correlation-Id: bcf655cf-f061-4d6f-e817-08dbbb949e07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w3J15fObfSHKHI/k98DGH+LAQviLrawaXSB54LL4C+p0kHbV+KQDu/SplRtpAJ+L/TwRteaAy3MIU+gQuRURxxmP9yx5lFofaxtjhvdwHMbcf2k+EyWvobV63Lt8NBGy2yDPafJ5fcTucjit/xUczWkp/IDzf2Dds62rdfRtu+DBJoGC0cG6LCqyaIMm8YO04cLtuXjDn2tmtgCJtjuQeNhzzMAag79Qz5YHjuiMvGNzCrth5iROxerp05wpRhCDiBwC8FDBEXM+WP26kZmPFNC9esg6Yqk/bG8v3SGrn8ekiveJ49+IfvaEa7psN5hUae+cjGeWac5kAGkmQTKjsXw9ZU6s6WwitbpnKeHXgE2VE6F8DMUYhn7dwVvZpQ0g2zRCl5Ke0eDNL9Av9taI0cZVNt2ck7lOUq6GUCPQR0gqYKLeH4KYAt/0+Fy1vdWhzzFPoAjqncnuBMEVq9osWsBkFTPo3ifo8jtH33GNbqjYPtAeqkGmhMTC/1jzgayf7B6aK5HxO6NEx4pFlJzf5Js2DiZ0uiwg652EtgFAdGoS98Q7e0Jb618IuH5O3KOvjkvYhkK7c5eA3pGyhMV6GDtokRVJlIh6CsnmU/Brt7eG8yxcaYYR1uaLAbsrw0X4fIWCMbkRVavVcdSG3pDEvA1+HuELy9hDtv3OLuXG7yBDzHA8j+/XaBIPJarCtyaCuLVcAiHRV09hlKFkoNg+FF2Xd9S05P7eoto7QZFsszYnvilLlxfDTfa2q1FKmDaoY4aym/QDu7WalBqJ4yN02qtyqD3Y5DjU3I1ADQuJxO2NlsD+QsZHMeehmVfMfjYvUQ6Osni67WfB4ZPpiMeXKA== 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)(1800799009)(230921699003)(186009)(82310400011)(451199024)(36840700001)(46966006)(40470700004)(8936002)(40460700003)(5660300002)(336012)(83380400001)(16526019)(1076003)(2616005)(26005)(36860700001)(47076005)(70206006)(54906003)(478600001)(110136005)(70586007)(316002)(41300700001)(7416002)(8676002)(7696005)(6666004)(82740400003)(921005)(426003)(4326008)(356005)(2906002)(81166007)(86362001)(36756003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:51:58.3460 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bcf655cf-f061-4d6f-e817-08dbbb949e07 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6223 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Make amd_pmf_set_dram_addr() as non-static so that same function can be used across files. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/core.c | 14 ++++++++------ drivers/platform/x86/amd/pmf/pmf.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 68f1389dda3e..5fb03ed614ff 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -251,26 +251,28 @@ 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; - INIT_DELAYED_WORK(&dev->work_buffer, amd_pmf_get_metrics); amd_pmf_set_dram_addr(dev); diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index a9333ff6c0a7..ea15ce547d24 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 Fri Sep 22 17:50:45 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: 13396219 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 1B8CFCD484B for ; Fri, 22 Sep 2023 17:53:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233479AbjIVRxv (ORCPT ); Fri, 22 Sep 2023 13:53:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbjIVRxd (ORCPT ); Fri, 22 Sep 2023 13:53:33 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2076.outbound.protection.outlook.com [40.107.223.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6E0211B; Fri, 22 Sep 2023 10:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UjTp6O+uupYOLO5o4GEcTCp2X3U4Nhb/d4yPj1ZL5BnZp5dc6aQDptZhaySGFraa/BYNKMQ/vr5P3ynMTFIUJddfPw6mu0raWaFJoKtONhkW2D4JKLmuoNxzxjbFYJw+QoY/u37+UeURC0rgqGlv6/xjUfqudDfB7KyX1myFbjWdi+KdJZdh0nkEOgZ1w2xiS2U6vx7dCpODk/NwVJEASIEWXuwA/3d6HAM4RT9/Oyio+jKrSGIbU6cCff9Qw6D2Tqr/uLP15k4hnCP3gMbm+DMwvRAcdLHkNyWYVl+lPjrVUWFWd/ZktFpg9uJKY7cD63pcdbjsj7zmGAXAtudG0g== 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=wOB/Yz1unjXC+CgO6f8ds5iS9Qn2nRLYTvd5+SZlSow=; b=jypxrruNuRlbkddtiApdjNJwAxtgdT5aJaNqn6zuT2GIjNxeIfiZ8PTjQAM8NVZOyWiDLkI7tnVZ7DFoUL+4x/+RWvwWPt832LNwB/myQpDIkFCUKu/H5s7uuSjzo5Nc20b9O2vPZCHDxep1oFTuG1gUlX6/xMURJLmLucb/qw2pwCq7xKs2LqzhCP9Oj0s6c1pQeljd1rVDxlY5AzL3pwhVbNqwbUl8sGfSvJ7QOaZfCjAXJak+7NnSmRIK8qhYKWA05Qjf8sfvyinUwUi68iUWanUvhN8nzfMA/zCPJeTmjqjve5PLTpGZLvwGsssIWjAg7Es5eff7EdVXNRDiFQ== 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=wOB/Yz1unjXC+CgO6f8ds5iS9Qn2nRLYTvd5+SZlSow=; b=fjHG8d4aHirPhDyVsdDiT6bIPO3EQL7WAG4IJzV0oXqC5Zup/Q4B2IPt/f05u2jr31YygynlF5oi7PwbgqeF8lbd0L9adNUJVTgks5btPXlym0IMr94j9D1lyMkyuO7XCutfBvsw32L4hIC3zI2Da1W1oB8eHYBb6AkJVhOwpJk= Received: from BL0PR1501CA0015.namprd15.prod.outlook.com (2603:10b6:207:17::28) by BN9PR12MB5384.namprd12.prod.outlook.com (2603:10b6:408:105::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Fri, 22 Sep 2023 17:52:03 +0000 Received: from BL02EPF0001A104.namprd05.prod.outlook.com (2603:10b6:207:17:cafe::94) by BL0PR1501CA0015.outlook.office365.com (2603:10b6:207:17::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.32 via Frontend Transport; Fri, 22 Sep 2023 17:52:03 +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 BL02EPF0001A104.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:52:03 +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; Fri, 22 Sep 2023 12:51:58 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 04/15] platform/x86/amd/pmf: Add support for PMF Policy Binary Date: Fri, 22 Sep 2023 23:20:45 +0530 Message-ID: <20230922175056.244940-5-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A104:EE_|BN9PR12MB5384:EE_ X-MS-Office365-Filtering-Correlation-Id: cae69927-62c0-40f6-ba5b-08dbbb94a0de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GVMOF4aI//u0w8W3NoAwTyuCsQ4uKfgeOtyle9DEhfGhl4tP+9F+LtXmCS/H8FclnLATgY5V6xxbLnaWXAH2swUs3IYpTYaae6q0xwt/WE76ehL4SBwJYvZR7xYT7m0wIP47X61WmGyDbdjPJlg+rFTPOF4L9+fcDC+JnH1K77xNDy1xTiS5gFM/1Ju/urxZCl3/ghwQZ3PtuQS6JlpjQ0rm3rU5t8l4r8pwnvwnW2Kb9Bk8gidSy47n87kYshyQguEu33xU54g0Q7BbpdOZ+vMbuwmeq4UJapDHaMUdptZ6Y68fSbK6yc+EXFtadefwP391r758hS0l26My6vrZDL8d/S/9d7pvP37fGSEomLaWu/KObV/8elUlDTwxlqpcegl0m3dfOpUyf8SP46LAwAdbhAPyvbrpwCnnaMFwIzhxDYRhDmxsep3WJUiupkctvFvAdgWQ13VZo/FkW8cUPmlErnw+fMMiVkPsos7mHta4bqAIa02bT3W0HEIP4gDbwZfEw0uwH5kSyHENuIiQoTCKZTv5Yr4vdCKOEc10SaKDkVAr7gLRmFGn1OV46kkzoJ9OrMIAaHvYlw+Pp3WeKlJU/V5nngOEH9FwkdRyo2LposTbwp3vGzxwiLarzxSbGy58UHuUz2XEfoITe9gbTYUTIkVyA8RUX67rgzf1GzVjSCKOG1jqwf+wv1qdeKRUMtheFv/OH+BFUJRLWiJ7EwLsX7sZbMofsjANntQi5KJ6Q3P9v0Toiq0Zj1TX4RrGtHdGCAM5Voz/6oU7MIgPw1N6iTCERv5EAYcwirRoL5K3JHbaohOczhRtG2mzis0LQNV+ZMZRvicNgENukXHtJA== 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)(39860400002)(396003)(376002)(346002)(230921699003)(82310400011)(451199024)(1800799009)(186009)(36840700001)(40470700004)(46966006)(2906002)(30864003)(7416002)(1076003)(40460700003)(6666004)(83380400001)(356005)(921005)(5660300002)(54906003)(316002)(41300700001)(40480700001)(8676002)(4326008)(36756003)(8936002)(70206006)(70586007)(86362001)(2616005)(7696005)(16526019)(82740400003)(26005)(426003)(336012)(81166007)(110136005)(47076005)(478600001)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:03.1093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cae69927-62c0-40f6-ba5b-08dbbb94a0de 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: BL02EPF0001A104.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5384 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 "request_module" has been added to address this. Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/acpi.c | 37 +++++++ drivers/platform/x86/amd/pmf/core.c | 12 +++ drivers/platform/x86/amd/pmf/pmf.h | 132 ++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 141 +++++++++++++++++++++++++- 5 files changed, 321 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 3064bc8ea167..437b78c6d1c5 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 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..d0512af2cd42 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\n"); + return status; + } + + 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 5fb03ed614ff..6f36c43e081e 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -376,6 +376,18 @@ static int amd_pmf_probe(struct platform_device *pdev) return -ENOMEM; dev->dev = &pdev->dev; + err = apmf_check_smart_pc(dev); + if (!err) { + /* in order for Smart PC solution to work it has a hard dependency + * on the amdtee driver to be loaded first even before the PMF driver + * loads. PMF ASL has a _CRS method that advertises the existence + * of Smart PC bit. If this information is present, use this to + * explicitly probe the amdtee driver, so that "tee" plumbing is done + * before the PMF Smart PC init happens. + */ + if (request_module("amdtee")) + pr_err("Failed to load amdtee. PMF Smart PC not enabled!\n"); + } rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); if (!rdev || !pci_match_id(pmf_pci_ids, rdev)) { diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index ea15ce547d24..81acf2a37366 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -13,6 +13,8 @@ #include #include +#define POLICY_BUF_MAX_SZ 0x4b000 +#define POLICY_SIGN_COOKIE 0x31535024 /* APMF Functions */ #define APMF_FUNC_VERIFY_INTERFACE 0 @@ -59,8 +61,20 @@ #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 MAX_OPERATION_PARAMS 4 /* AMD PMF BIOS interfaces */ struct apmf_verify_interface { @@ -183,11 +197,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 +418,129 @@ struct apmf_dyn_slider_output { struct apmf_cnqf_power_set ps[APMF_CNQF_MAX]; } __packed; +/* Smart PC - TA internals */ +enum ta_slider { + TA_BEST_BATTERY, /* Best Battery */ + TA_BETTER_BATTERY, /* Better Battery */ + TA_BETTER_PERFORMANCE, /* Better Performance */ + TA_BEST_PERFORMANCE, /* Best Performance */ + TA_MAX, +}; + /* cmd 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 { + unsigned long spl; /* in mW */ + unsigned long sppt; /* in mW */ + unsigned long sppt_apuonly; /* in mW */ + unsigned long fppt; /* in mW */ + unsigned long stt_minlimit; /* in mW */ + unsigned long stt_skintemp_apu; /* in C */ + unsigned long 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[906]; +}; + 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 +591,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 1fce04beacb3..a8b05e746efd 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 : %d\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 : %d\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 : %d\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 : %d\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 : %d\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 : %d\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 : %d\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 = (struct ta_pmf_shared_memory *)dev->shbuf; + out = &ta_sm->pmf_output.policy_apply_table; + memset(ta_sm, 0, sizeof(struct ta_pmf_shared_memory)); 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 -EINVAL; } + if (ta_sm->pmf_result == TA_PMF_TYPE__SUCCESS && out->actions_count) { + dev_dbg(dev->dev, "action count:%d 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,20 @@ static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) return -ENODEV; } + dev_dbg(dev->dev, "Policy Binary size: %d bytes\n", dev->policy_sz); + memset(dev->shbuf, 0, dev->policy_sz); ta_sm = (struct ta_pmf_shared_memory *)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 +191,47 @@ 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 + 0x10); + length = readl(dev->policy_buf + 0x14); + + 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 = 1; + schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms * 3)); + } else { + dev_err(dev->dev, "%s ta invoke_cmd_init failed err: %x\n", __func__, res); + 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 = ioremap(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; @@ -149,7 +278,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, "%s: tee_shm_alloc_kernel_buf failed\n", __func__); @@ -191,11 +320,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 Fri Sep 22 17:50:46 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: 13396217 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 3C07CCD484C for ; Fri, 22 Sep 2023 17:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233435AbjIVRxk (ORCPT ); Fri, 22 Sep 2023 13:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233650AbjIVRxU (ORCPT ); Fri, 22 Sep 2023 13:53:20 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2051.outbound.protection.outlook.com [40.107.102.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2AB8E7D; Fri, 22 Sep 2023 10:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QUNjpljpI8W6KupdZHePKxeSJ9iMYWwEqieWaI+oDsXDV6U9D6mcPPqtYBbfZYYzzM8fpBraB82fvsLKsXxaDEdsvHNJUUnKAJDYTAIkAQTpFb037PP4KY4AVh/Y10lbH7hkgJPx0bOfjere4QtBOo0PSD3SXhZSgIrQQ7CMGSq4DmKo7zx1w1F6+X+LvRBa1R9czb20gVjyJnywRcPyu7GVUbCVJ2IzrSSX6H5z86uaiTZnYIZTXQpXnLyzEnocgeHaOm6fADf16m9UC4SrEhhvGpFAKgFiQIY6msLkxcujVxBk/ocKOrerqShxU5Pv1v5n51WG03KdvTUFg0QAlQ== 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=eRqX3Qp/XNorhFJElDFWl8CCho1EgTmSZc20lhsFdUE=; b=Ujj6T4lv8Z63ZbBBgmdpgGD6P4+prVr9EqSxWROYHTvR9EOiNpG/JzhWGds7VsVXF8ACT+K1eXk/sCdyv9oBDlArOsZBSWyLxm35sJlRjXG6c59HmdmXU8bOzPVuoZTL8XL/9CK3ZaWKRHgDO1yINfA7J+6lQt1TVCYNzRvREslnx9F97IvswfhAofo6MoXMtQC7x4Imcr12GWCre1BQgaTt1IhA6xbP5JEo3jV1TBRtAjFdM++sMKylMCK5ThOybMoz752/9Y+uo1tv8RAtkRiC1ARyPz2S1L/q5wbj7SwqoLjT+n8++6N80lhi1DAPhlrQuouY8WGRa3Qp38amSQ== 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=eRqX3Qp/XNorhFJElDFWl8CCho1EgTmSZc20lhsFdUE=; b=e8u3WR7r6tEwHHGBaxgCzACFgirJ9QoZNqQIcsuPaiTyhO20FM6lRiYcwJnkby5+5q9eLBP5/JuE1hCvuD26AAeBEra3ui0qKaqsfn2NjXnGFJBMAYpBQ4V0xNe+3MR7PhCrLQrD4qMiSgWh7u2Klu179hcKniXCNXI3sknaM6A= Received: from MN2PR17CA0024.namprd17.prod.outlook.com (2603:10b6:208:15e::37) by BY5PR12MB4083.namprd12.prod.outlook.com (2603:10b6:a03:20d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Fri, 22 Sep 2023 17:52:08 +0000 Received: from BL02EPF0001A103.namprd05.prod.outlook.com (2603:10b6:208:15e:cafe::3a) by MN2PR17CA0024.outlook.office365.com (2603:10b6:208:15e::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:52: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 BL02EPF0001A103.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:52: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; Fri, 22 Sep 2023 12:52:03 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 05/15] platform/x86/amd/pmf: change debugfs init sequence Date: Fri, 22 Sep 2023 23:20:46 +0530 Message-ID: <20230922175056.244940-6-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A103:EE_|BY5PR12MB4083:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b208ac5-5326-4148-6d39-08dbbb94a39a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BXPD++gghd6cL2DZVdkNHV+WzMGHnf3XVMnouxmckhlYyldiySAxMwW3f2/f62M+UwvN+cP3qJNC/aSZfkVor+NL1D+4MN0zoc7fF8MUohFkefSoVXhYhN0C9KKfDW3XWt2OJ/dLMkCgh670aD4aTaYvIIv1WdiHY7T2O98m8Yg2QY83jxWluEHHmHzo36hILUmqBdK8uQOx/BSL62sS56yEEBLEOFVyWq4Sccaycra++aYZJq6YWwmHhQ7qYDWkkuoxjFfHlORpItK93k//w5pIMSk2wl09ARaibnX5LfpVTU8Xio7o15TGbfxqEJAEJLfsRDPvHOLm+I8t+cUdH7/kqSEZAFXaGWPXpAdIm9zIhec0VjkoIQi2u9FzpZt8TrO2s2o2fIJDFKM3sf7+cjOLfl5jxcuzDLI4cIXK0MOMzHgO2aWfw5Bjgpy/RWGXmgIbPs2jBv2oeiUdHkWBgG+HBKkdLCrVachKUt/LAJes983YWY/5/JakqOe7pn/a8yugiBLEW1nwQ7x7bxuTgcJMLFmM93VFAe2XSuhVVPl4/X6rzaxdz7S11ooReb6Dn1j86C4WdTxqU+eGpEBobHJLxnnhFnaED54k7X6HZzIlRQ0NrAZuHV++EL1c3hYf95lB2IgPNeTXb0xKl6G/LrRXPC0Y7JYFhBu7F0YKaBwirQasEsloOPEOU2nyM4thXIWyLU+9zTBiPYbHtKzc95o9U7x0Xc3T2rlZcALcoaCo+CIxt7a06RskGLEWmQzB7L9DjjXgYnEK0ftfaBHCCr7TWsjF5hFoeodsZxX2Ji4oMJBjaQQvhi8j/33+pMwJv7wbC/rMCFaWurWnG73/CQ== 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)(396003)(376002)(39860400002)(346002)(82310400011)(1800799009)(451199024)(230921699003)(186009)(46966006)(36840700001)(40470700004)(426003)(1076003)(8936002)(26005)(41300700001)(5660300002)(8676002)(4326008)(921005)(356005)(83380400001)(336012)(36860700001)(2616005)(16526019)(47076005)(7696005)(82740400003)(478600001)(81166007)(316002)(40480700001)(70586007)(110136005)(70206006)(54906003)(86362001)(36756003)(6666004)(4744005)(40460700003)(2906002)(7416002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:07.7105 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b208ac5-5326-4148-6d39-08dbbb94a39a 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: BL02EPF0001A103.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4083 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org amd_pmf_dbgfs_register() needs to be called before amd_pmf_init_features(). Hence change the sequence. 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 6f36c43e081e..dbfe7c1d6fc4 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -427,9 +427,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 Fri Sep 22 17:50:47 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: 13396218 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 0B7BBCD484E for ; Fri, 22 Sep 2023 17:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233570AbjIVRxw (ORCPT ); Fri, 22 Sep 2023 13:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233608AbjIVRxd (ORCPT ); Fri, 22 Sep 2023 13:53:33 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2088.outbound.protection.outlook.com [40.107.243.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 568EF212B; Fri, 22 Sep 2023 10:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PNiBZz5sb091nb68ZC3uXNo1ViUCMqrXPJ80R6e3V7yS8dRqKUsmhvtabwgrYjbHB2ruSezw0G+z6d+CVJ4zPzJkBWKX/Cd69Fi3HpC1J7f3p0WlQB2/6xdrecelUAP/XSoyQ66sm44I7YThYH2ZBSox6EiOGKOX6jNoyn8aw6whHDnviLVeY7+Vf46WCNK3RsLaCuA4S0B+Go2zoCcPJP+gTSh9rbDu0m1vNAapTfbnoY70jQiBw5a42g2iQzYfYA2vcqH6HUZGrxo6o6BU//ALoFEOrwYDA3soxdHAwOUjucbL1mWoV6t7KMzN8jVL5ruG4QMC3HHqM6KAHYU0bA== 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=T2fqI3CvjA9IVDknvfrPEaq4mUF7ZlAt4ZyHB15/Muc=; b=HnjB78y0Vr2v3WwzJK4bO0J8pIrUXi3Y8N/6KaVOvkMKrwfoI8KXNw+bdbYDJJpEevufgXLKr5riFKPIKiDdY7r8VUI9cjhbneSAQd2KYukkE9dCVZ+YJtPy/1LMYn9d72GqLHMVNzktpLhxz1lDoY2nf6/h19HbgAPd0YMJFUM5YftLRwIFZdPHRM9TVbAMQUb3jjsyXNgKbQTgJOiGZWihe6A7Nr4+oQhmuZmKHdBnJtnRO7DM6Y6AGZ1ESKiSxjYUxtY4bWsbKt0X1h8fH57PQnqR2tbu3lvbl8F5dg0Xvk73gmkkWBApsz53Pi46PeaHmF1qBKvArwyp1KkonA== 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=T2fqI3CvjA9IVDknvfrPEaq4mUF7ZlAt4ZyHB15/Muc=; b=V6Rz81OHch1xb7bnyr4yzyYZeCx+gut02rwyMv+3Q+qZVj0DrARrotRcIWHWYLsgMdiAOGyjUFauqpjG7RatOkX8hKyZSgvjIW6scgU9EkQNPkv1EgiZKf7ua7gsLFYS+YP0x3gXUX44D8er25Kuq5hHvmf5aLZyp2nl4c1lZus= Received: from MN2PR17CA0012.namprd17.prod.outlook.com (2603:10b6:208:15e::25) by IA1PR12MB7544.namprd12.prod.outlook.com (2603:10b6:208:42c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Fri, 22 Sep 2023 17:52:12 +0000 Received: from BL02EPF0001A103.namprd05.prod.outlook.com (2603:10b6:208:15e:cafe::48) by MN2PR17CA0012.outlook.office365.com (2603:10b6:208:15e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.31 via Frontend Transport; Fri, 22 Sep 2023 17:52:12 +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 BL02EPF0001A103.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:52:12 +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; Fri, 22 Sep 2023 12:52:07 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 06/15] platform/x86/amd/pmf: Add support to get inputs from other subsystems Date: Fri, 22 Sep 2023 23:20:47 +0530 Message-ID: <20230922175056.244940-7-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A103:EE_|IA1PR12MB7544:EE_ X-MS-Office365-Filtering-Correlation-Id: 122db49b-6c24-4223-c11b-08dbbb94a678 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nxwfkxzmc0Il6DjsBDt+2DKIrs8EoayukoQDBuqmu7h9jPA5TMjskArfENx3HZOWoakrwtyH/LLSOz7HQYZvDVHAu191MOtplI+whWQbD5xaPX2daRsuYQdre6H/m3KUcqqEzVq+M13nEHCTKHJC/jLXuNJkYEoBqrGY8+OmOLA2pwKDrGr5jGDtz81kgMFyIZk4RVASikFCAvsCgroiz8y9V8mIUePW9zNzIUH9NDDd9bD+MVILwyPKvca6aEETU/bkgF228mIrO15E6qCcu/Fj0tLkD06NgxMWAR/9Q8fwQ5QUalNQ+GrDaqC211C+0VFiCyU5ADclxfx2fdWcoUS/n7w82lblgElsevaP6K9SUW6+l1f3RaUvlI1Cs/38rT0/mzJi2rqYvp+VbG6ZysgBpiUxo1rMsw4bgj2YsJWT5rS2Jj5YWkT3PwezM0p+3d8suhvRCOHfoVx8mJ1VFggf+qSeOM49e95WdqiFrH0P/ydziD+l11OdGhCAg4tAt4NWlTdzgI0ACsnkB9CbNouvea/AT0AN5t4NBo6XcQwaT/ReWA5wYgGiPGsdNJVJbmJtldTgDYn5yVZ6LujroJmlBhcnOjMS68/K3oO5asI3MdU0/wUWWMK4ZuPNT7/9z0PEbGCPXHKFmN5kPfDL4CBYLFrsGoh5EExS0tOEM38XTeNsIJT49M6jMp52IeA+3wJM1jpRAap+TxP6t957K9QqLgXt69GHIxmANNwZGjjLfwrfDbjmNX1ecqYRgAJJlkVMu9cMItnzvbExRW3wZimFkJe3ATCrEcScHJFamRoD3CUp2YFpqAV2ktKaDnGMEKIx0BQeWDepc8LTEKUQDQ== 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)(396003)(39860400002)(346002)(376002)(1800799009)(186009)(451199024)(82310400011)(230921699003)(46966006)(36840700001)(40470700004)(36860700001)(47076005)(426003)(16526019)(36756003)(26005)(336012)(2616005)(7696005)(81166007)(82740400003)(6666004)(921005)(356005)(83380400001)(478600001)(70586007)(316002)(54906003)(110136005)(41300700001)(8676002)(70206006)(4326008)(8936002)(5660300002)(7416002)(40460700003)(1076003)(86362001)(2906002)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:12.4917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 122db49b-6c24-4223-c11b-08dbbb94a678 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: BL02EPF0001A103.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7544 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 | 118 ++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 3 + 4 files changed, 140 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 81acf2a37366..e64b4d285624 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -146,6 +146,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 { @@ -592,4 +607,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..08159cd5f853 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -0,0 +1,118 @@ +// 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 "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 C0 residency of all the cores */ + for (i = 0; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++) + avg += dev->m_table.avg_core_c0residency[i]; + + /* get the max C0 residency of all the cores */ + max = dev->m_table.avg_core_c0residency[0]; + for (i = 1; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++) { + if (dev->m_table.avg_core_c0residency[i] > max) + max = dev->m_table.avg_core_c0residency[i]; + } + + in->ev_info.avg_c0residency = avg / ARRAY_SIZE(dev->m_table.avg_core_c0residency); + 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 get_battery_prop(enum power_supply_property prop) +{ + union power_supply_propval value; + struct power_supply *psy; + int i, ret = -EINVAL; + + 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 = get_battery_prop(POWER_SUPPLY_PROP_PRESENT); + if (val != 1) + return -EINVAL; + + in->ev_info.bat_percentage = get_battery_prop(POWER_SUPPLY_PROP_CAPACITY); + /* all values in mWh metrics */ + in->ev_info.bat_design = get_battery_prop(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN) / 1000; + in->ev_info.full_charge_capacity = get_battery_prop(POWER_SUPPLY_PROP_ENERGY_FULL) / 1000; + in->ev_info.drain_rate = get_battery_prop(POWER_SUPPLY_PROP_POWER_NOW) / 1000; + + 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 a8b05e746efd..eb25d5ce3a9a 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 = (struct ta_pmf_shared_memory *)dev->shbuf; out = &ta_sm->pmf_output.policy_apply_table; + in = &ta_sm->pmf_input.enact_table; memset(ta_sm, 0, sizeof(struct ta_pmf_shared_memory)); 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 Fri Sep 22 17:50:48 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: 13396221 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 1AAD8CD4847 for ; Fri, 22 Sep 2023 17:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbjIVRyG (ORCPT ); Fri, 22 Sep 2023 13:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233781AbjIVRxi (ORCPT ); Fri, 22 Sep 2023 13:53:38 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2081.outbound.protection.outlook.com [40.107.94.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B5A4E7A; Fri, 22 Sep 2023 10:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ebx0AKk8MgsXQnc0F3A/7vNVKXWhFvQVLbym/4AFKRH7NLlo3oIuEVm7o9YzTRA8aZnQyULk3IyI6BtK6Q+tjLewCY+3eFAJaHkugu0himZzQbHxAMhDh+mig/aDzHe3/ARuHMlWRLzwyFN2e4zSCSiaSTU6wG7e/AGxX2Op5S/g3in43vBQTAiSIlMEX8i8tzg8l+L+7pPEeFpiJx83RkagPfW51K/+OHTPHLJMfvu5h/ZWDh/b62knD/zE04ELvf8wnHAWMmGVV15ZU0CNq1M0rM3hJhLCcBlkGYmuga3rY+4WwCkN9f2L+s1xG1VnIqMWVzM0eutguAf0PWGxCg== 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=0k2MpGBmfTzY01G99nNKlUwwK+Tm3MjEykFfBDj+NVk=; b=dnTB0gAFDxeK0ERcUdt4nb9q5p6p3gwcBzVc1tEmtQG55/Uu4CsnVBjb8x7CT/LMyAS1cj2CEKRojCmMcmZ9WoWRh9NN6E8GgfZ9TqKgETNIM+fhe9QU+GxrV0gCgpZ+WurruIr0GbSGOIIEbRqzlCVvTl/mtc78CKKcT9DEfpOE+7Cy6eclXpePRGFpBxCGIrftviAxqrW/XYsLLnJXdPMX8OVJqagcqoSSOQsscbMNN6Xd0eQAy5o+g4vWnDGDS5QcjSf4rH1wr9J/hdbyDi8kw1opY07wtkoz9bgMllCyB6Zs+gdsH/LRQkIyNy6BmBGQUm5rlU7Plsq8vblKLw== 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=0k2MpGBmfTzY01G99nNKlUwwK+Tm3MjEykFfBDj+NVk=; b=aKcy/maJRoJgzrglH6AuJe3PxMw2za7yGdvyvLEoMu8hcXb7Endn3KUoaqsGmFRTAjwyF/tKdfb9TwJlUNAzyKDIK73YBPDiQ13zI3YOnMWZOx+69Yfw+ZSrsIuKD7jrtp6NTulhRP/Ph8bGNuxSuFOW4f75s2Hu5uc/u4Td60c= Received: from MN2PR17CA0032.namprd17.prod.outlook.com (2603:10b6:208:15e::45) by CY8PR12MB7537.namprd12.prod.outlook.com (2603:10b6:930:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Fri, 22 Sep 2023 17:52:17 +0000 Received: from BL02EPF0001A103.namprd05.prod.outlook.com (2603:10b6:208:15e:cafe::60) by MN2PR17CA0032.outlook.office365.com (2603:10b6:208:15e::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.32 via Frontend Transport; Fri, 22 Sep 2023 17:52:17 +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 BL02EPF0001A103.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:52:17 +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; Fri, 22 Sep 2023 12:52:12 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 07/15] platform/x86/amd/pmf: Add support update p3t limit Date: Fri, 22 Sep 2023 23:20:48 +0530 Message-ID: <20230922175056.244940-8-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A103:EE_|CY8PR12MB7537:EE_ X-MS-Office365-Filtering-Correlation-Id: 92a3523d-149e-49a2-0263-08dbbb94a944 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8K+zskcFcmp3ThbeEThCF0WpMR0tZHUEuGUY2WhqAn6HYYUp4k2xpcx71OE1rHj87uBX3/Kzes71vAwIRL2YVyWiZgZ/pbUqov1c0mtjIoZcY0As8Dk7evz+32e6hF0ha2KIus5RL4PUOHKN+m2JBC7/1oyUH5ZtpRTZ4DgUNVFfmv9CNTWejAXFUg+thz+T49nziS1PHMpPSkNF/75mdqUCrAanlBw4xCRVn22Sk8d+mEJSaafsW46Oo7lKVmxFHrhzG2SOL1wFPyFejPvHTLC2dBgkuNOOhTD0xj9kg/lA+Muf6qrlBcNgBY+/VJtgkoRKeRepkUtE/mQeqEPQckS152sRyqmn2miekXwoB95l1ppFIJJ5TcnPvNgomkHIgvWpDeyieNerwTmIm7Gz/17KwEEW3TjIdGaZ7Zc9gp1W+q6GG7QdEW07w67FELuEIh6xY0p165MZHujjYOvrnB9Pc6LbHUKHcbz24JpIxfpCHEQqepwLdIzKKveAHKsRD8BP2L8/g5i44D3AnjDq3XIG499BZGveiRiJu/GinPNbdwtS856fHrrCyrpOfzez6J70fVOsRcw5NpDBO8KMJYfyeEiKgycn6WNI/N25zpDIKUwKLAhjT5P+WBZYb8yPo4Ay2cBVJCmWn81m3C4DUOw0ySKKOJKj9brGCgzdZiTFp6uDIX7nMhLbWLn8TpCPjnQEka7aZAW3CsK5SS8wNeJ8tX2SakOGodEhP7Kh7+fA7ShtEPpo6F/1DzJvXMEdIv1zBkX3QAn0emwIO47opXFh1KtKeC2y+dcRGiON0q6/8lhj1Ph++SMlb9mjrNOl4/7sL+BUkVxamUNSxFaxZbexgKgd179ZquFEoByHe68= 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)(396003)(39860400002)(136003)(186009)(82310400011)(1800799009)(451199024)(230921699003)(36840700001)(40470700004)(46966006)(36756003)(40460700003)(40480700001)(82740400003)(7696005)(2616005)(6666004)(921005)(356005)(336012)(426003)(26005)(1076003)(16526019)(41300700001)(70206006)(110136005)(54906003)(70586007)(478600001)(47076005)(316002)(81166007)(36860700001)(83380400001)(7416002)(15650500001)(2906002)(5660300002)(8676002)(86362001)(8936002)(4326008)(42413004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:17.2105 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92a3523d-149e-49a2-0263-08dbbb94a944 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: BL02EPF0001A103.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7537 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 e64b4d285624..897f61b75e2f 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -46,6 +46,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 @@ -69,6 +70,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 @@ -472,6 +474,7 @@ struct pmf_action_table { unsigned long stt_minlimit; /* in mW */ unsigned long stt_skintemp_apu; /* in C */ unsigned long stt_skintemp_hs2; /* in C */ + unsigned long 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 eb25d5ce3a9a..883dd143375a 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 : %d\n", val); + dev->prev_data->p3t_limit = val; + } + break; } } } From patchwork Fri Sep 22 17:50:49 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: 13396222 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 C11D3CD484A for ; Fri, 22 Sep 2023 17:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233622AbjIVRyJ (ORCPT ); Fri, 22 Sep 2023 13:54:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjIVRxk (ORCPT ); Fri, 22 Sep 2023 13:53:40 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 320A319C; Fri, 22 Sep 2023 10:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h3n8Z0KywdDi+OW6lW/y3tfVRf1jiaNWGGAZvskt8WSDdxRngyOvUwqjwod0wlCFrHpn7jUEj6Tr37VLCEKq2RTqyA6PvAWwi3be/tnxzqOtWxAf3Lxg94bF1IrAePiUDKlJE9SAlvRBVwqe+pfF8q3cvbsWzmfHviCwmJ2/gaxw7EZTlmHZNDtLXz1ZDSoDptKsQ/MnOyE586WUfLL4aQ1+MV3tMHZZNggFTjfT6E+drG0xJ/TafC6/YdwbpXgcNHvhAXvKLhcrI2epdy0fszN3MTM2cSZjR2fgicTWBUojEO1ua33jWNVo2q/d9Gc/Z+co5XGwqXN3AQDLCyDHpA== 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=yVzCcDukQBAZIUv9/0ZmHEAnTKpwYhoFBQoviqaAF00=; b=NPJGpp7mEI9AXsruR3jE316N+ozhItRca0F3I4X71Gdd8khQlRg/cVAjK/8CnGzxFNA36KTCkELsoHGVEsp74biCYtyWvcVWDHovTYmIZuDZsUQErTokVSgS4R4Hzrrc1ChfSqI/WUsCf4IPZikDqkvmOILqDgNKoh28lj31D5PzVZ/uiwBZtRvXkz7lXv3JutNHAjKio92HEGKve8pBXVhjDU0/dfQml+gQnBYGsvIDjPhGpf5HfKFyZthERuceA5MfYUDl/sJyWJtA0+nZIyrbpczRhuvr0ZS6cyQuAnpEKb4XchXCf49EoYJnyIMX7nZNmP69S3IiIfErskQkbg== 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=yVzCcDukQBAZIUv9/0ZmHEAnTKpwYhoFBQoviqaAF00=; b=4pHGh7N3hdbc5F3oLLxSP47F2V/n1oXiwocDFBzgboKeXc1orTH+xHHZfbSf27Qy646UEYMN1e0Gxc5gc8yQbUFjps7KlG2X/t0vj/MScrehzqEXeFokUP6xjpOqKJrkrijajSmTRTHaoqxvl/csfSVIZhlHTukAEOcW/URx/Pk= Received: from BL1PR13CA0191.namprd13.prod.outlook.com (2603:10b6:208:2be::16) by MN2PR12MB4080.namprd12.prod.outlook.com (2603:10b6:208:1d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Fri, 22 Sep 2023 17:52:22 +0000 Received: from BL02EPF0001A108.namprd05.prod.outlook.com (2603:10b6:208:2be:cafe::6c) by BL1PR13CA0191.outlook.office365.com (2603:10b6:208:2be::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.12 via Frontend Transport; Fri, 22 Sep 2023 17:52:21 +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 BL02EPF0001A108.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:52:21 +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; Fri, 22 Sep 2023 12:52:17 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 08/15] platform/x86/amd/pmf: Add support to update system state Date: Fri, 22 Sep 2023 23:20:49 +0530 Message-ID: <20230922175056.244940-9-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A108:EE_|MN2PR12MB4080:EE_ X-MS-Office365-Filtering-Correlation-Id: 36898169-fb95-4a5b-3acd-08dbbb94ac07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: raUPHbLlkVQEL/Zk8cxcO1kJUaPfMYRDJFU+HhIuEHbfqlxe5QHDC67kaNIv+LE1tKoU2WciVTqQARpFqf43YZ+hRfrZMCmve7hNTBIbVQ9vLUb7GsquzNkdeA2hyB4OOCbE/ZyjJ3Me/0ogaLnLBM++QBnYeYaHcQHjb1b6ScSu0os8bgig8VgY0unQcI3BA4PafJCZOQeyi3r/SsLOY42Jx6b3PcJAzcP4w5hQ5REB+zB6T2xv2ZMo9/tW3/VQrrl+hyIiB1Hc+0ITkKQ8gGWn9ARuHv4abRx27wgDTQEcHRMGAFdJU+I0rtrL/5tacPE0JZRblOUNRr+zU3/V5mT93qak8CxIoXD5a+dJHx4zhtuGHvxZF0avCHTouZhKVBi5h4ov6XSlsT6HfbJBmjWeHvtUzmJplSwVnR9mkToMUgnUTWmwrJ0y+aIy5+xMviwFX56JEjFtb+HrTViiNzo7aJmXRWDNHE5UpBUoijVF7wqPfV21m6d6WusUWpnfjeFI5qOtWuKhe+uT+mmr+U1KCNtMFYY1j6MhlLsS3Vjyko3W77hopMYASdSYo0102u7B2yXuShWA0ITinQF7kkp0UAwMqdrk9h1fFurrdkU7KLIq6cZf10K093q+OHZH6gvslC+lC2D0pSO2RRyPEvXRSeNUYql6KfUgrpy72RU+Ca3iDvtHFrvoXunBPaphEnixFNbH35/JYFg9lRw6svBMQELuE1bRVED6d+0V8uWYeTh+SkFZRtd1nn30lTIRnmgYX5wxWbMP0iGlCCw1LJ9MplKD9YkTEWkl2a9a3X+qm90qez8Z2gavim1aqZQyfnhWDzYlXXcRkpzaozS6uQ== 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)(39860400002)(346002)(136003)(396003)(82310400011)(186009)(1800799009)(230921699003)(451199024)(36840700001)(40470700004)(46966006)(7696005)(47076005)(2616005)(6666004)(478600001)(8936002)(16526019)(26005)(7416002)(1076003)(5660300002)(426003)(336012)(2906002)(15650500001)(70206006)(70586007)(316002)(54906003)(41300700001)(4326008)(8676002)(110136005)(40460700003)(36756003)(36860700001)(86362001)(81166007)(921005)(82740400003)(40480700001)(356005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:21.8297 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 36898169-fb95-4a5b-3acd-08dbbb94ac07 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: BL02EPF0001A108.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4080 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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. Signed-off-by: Shyam Sundar S K --- Documentation/admin-guide/pmf.rst | 24 ++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 9 ++++++ drivers/platform/x86/amd/pmf/tee-if.c | 40 ++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/pmf.rst diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst new file mode 100644 index 000000000000..b60f381410c3 --- /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}=="1", RUN+="/usr/bin/systemctl suspend" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/usr/bin/systemctl hibernate" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="3", RUN+="/bin/loginctl lock-sessions" + +EVENT_ID values: +1= Put the system to S0i3/S2Idle +2= Put the system to hibernate +3= Lock the screen + diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 897f61b75e2f..c5334f1177a4 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -70,6 +70,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 */ @@ -436,6 +437,13 @@ struct apmf_dyn_slider_output { } __packed; /* Smart PC - TA internals */ +enum system_state { + SYSTEM_STATE__S0i3 = 1, + SYSTEM_STATE__S4, + SYSTEM_STATE__SCREEN_LOCK, + SYSTEM_STATE__MAX +}; + enum ta_slider { TA_BEST_BATTERY, /* Best Battery */ TA_BETTER_BATTERY, /* Better Battery */ @@ -467,6 +475,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + enum system_state system_state; unsigned long spl; /* in mW */ unsigned long sppt; /* in mW */ unsigned long 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 883dd143375a..1629856c20b4 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,9 +56,23 @@ 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; + u32 val, event = 0; int idx; for (idx = 0; idx < out->actions_count; idx++) { @@ -113,6 +141,16 @@ 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: + event = val + 1; + if (dev->prev_data->system_state != event) { + amd_pmf_update_uevents(dev, event); + dev_dbg(dev->dev, "update SYSTEM_STATE : %s\n", + amd_pmf_uevent_as_str(event)); + dev->prev_data->system_state = 0; + } + break; } } } From patchwork Fri Sep 22 17:50:50 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: 13396223 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 20C97CD484A for ; Fri, 22 Sep 2023 17:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbjIVRyZ (ORCPT ); Fri, 22 Sep 2023 13:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233408AbjIVRxv (ORCPT ); Fri, 22 Sep 2023 13:53:51 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2064.outbound.protection.outlook.com [40.107.101.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B99D10E0; Fri, 22 Sep 2023 10:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fCuN48GV80aC5RDa3+CJJ4lbrwXo5xjN4YGkS+YY5iuBDDBXCj5CIfoOvLawNQO/9LVwkKFpE7szDGnFBMWchjVTGdPxNRtvZcO76BrOQJEtaM1zi6nYGxkLPuNrQJb5821Fz2TMrTSmknrsSSzM1VWnHkAoKtx3VcQXtf0fFqUsygQF9sMMan9VKgnMhHJE/cklm9Sd2pnIXzhEQEAYgwMINwcUHckgiOTXk/q6wzPLrktfLwCy4Rug+qp91kVxMLXEwUrbp8Q5BIaBxc/U2hi/78b31Cu9okORvB/hyb9CRQuzpdgDbML5uZeR3Vxi3DFhuTMK2riqCxXEpU5VIw== 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=gFRMKDsCi0+gO8oX5eF9s6N3hhDHuRhCTx9gMYHVFmY=; b=SNVxcgtN5m/moQFBYqfVu2HRh2FN0NsP1FxtTfTyHA9DDFBLviWhfRWNFXRHsyvUySdaahK5zFnJuz044l+w5emTu0GbkGUJtUiAniGf/cw2OXWl7TEK0BoPP3umxZARAc4I7jDA+DThw3294O0oGmLEkXWhGP5Cx2wWCM10D5pwJoxR+oSPGu56J2LS6xrUbRCTJXufME1AssNclTNDUyx8FWSvmY+QISvV8fJbd7YE9MANgOutThQ4+m+KdELiZQnIWS3GOUs1Hm5yGCSmbNBHq8nfP7KSujsTgQOR5JupAtLek6uIYijOaDMT6uneitWAEPn5QvCjguCHsRUp5w== 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=gFRMKDsCi0+gO8oX5eF9s6N3hhDHuRhCTx9gMYHVFmY=; b=UrMvIRK8oBrG/UB65J7aVROl6qsaLAMJQRHYmbkCRb2t+k+4YDEKuKBkSmoi+1KXVPqsDYFZkFdWJwZOLZOlvYsjmM3KdtkjuIDmuh4NyEcs+KFj3+HRqjZ0HbzL5ccatUmljEN99XJailmRZ069KH6x7RVf094QZQxShCdClDY= Received: from BL1PR13CA0183.namprd13.prod.outlook.com (2603:10b6:208:2be::8) by MN2PR12MB4424.namprd12.prod.outlook.com (2603:10b6:208:26a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Fri, 22 Sep 2023 17:52:26 +0000 Received: from BL02EPF0001A108.namprd05.prod.outlook.com (2603:10b6:208:2be:cafe::ce) by BL1PR13CA0183.outlook.office365.com (2603:10b6:208:2be::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.12 via Frontend Transport; Fri, 22 Sep 2023 17:52: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 BL02EPF0001A108.mail.protection.outlook.com (10.167.241.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:52: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; Fri, 22 Sep 2023 12:52:21 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 09/15] platform/x86/amd/pmf: Add facility to dump TA inputs Date: Fri, 22 Sep 2023 23:20:50 +0530 Message-ID: <20230922175056.244940-10-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A108:EE_|MN2PR12MB4424:EE_ X-MS-Office365-Filtering-Correlation-Id: 89166e51-c5df-4be9-f378-08dbbb94aee7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hfna38sXuxzlEW8QXr41rfzCwpyo0fWhhkw3/jE00uiamp7LiZFHcJT45AecdfXj2Ennsiv/+6jeHoRIg7Lgk6a+5zVeJEw58bnB9aPqbW4gIcmQa3s+F2GRqH18pY07Swr/rbFg3XBgTyFgonkhvAa7WrIwKctMUd/t3JLXqwIKNL6Q5VO7lQg5xvjPzbDlxWIih0TtiRrbLjB6Anr5qanGOXhKHrOTglUi7xN5NhZa6dId0//4bnbktuaNDzlOYh91QSFwaxcV52VHU5WZjKlMKZMIzqPLnJRXbkfUmzeXlZgBLJv9KPQ5HUbaWzxIVndodlHzVlAGsEFfP5FlJDaVVC2P40JGdwHM2J+jocamBzbEIM7ndkAk5sj1E/F0ey3bJsw4OfubyCSRlrc1j73J4sQSsehYt7U9m7erHuGJu3SmQJA3cn0XGoTF4PgQ9EAXzss7/ZePlkp8yTRlrzCEWTHz7oM+ch7Sqbi1e/sSHT9mOf6xj+EuIBRAsz+Nw1TXWpfs+d7ZqhBoxn8RPesPK282NK0WUlSsbStBGEYZe4L8AWYAMidj2kHBtuQQBFjoKrW7vupPW5toUejSIGGWPAYvVVQ9IOLdl1mW4WGiZk8YjS+RhvzuNEVAo4hkG7B6s9CwYtvhOlM7K4iSiXYdq/dxbotIeVlp9Ad4f3BZdbkMGoEvfRhOG+Cog2JS/t2ewsLGRjhwbKyXPthdEA0MONMZ44KoQGamOoJg5vo51xma77hOx1kbcq+uEpqeOfdxjBJIGeNEwrIuLVALscuQfsw24S2atgB6KATRtm/TTPZgm3+rWctYQwF6X6LczFcW4zHA7Yr2rdpzJt1exw== 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)(346002)(376002)(396003)(136003)(451199024)(186009)(1800799009)(230921699003)(82310400011)(46966006)(40470700004)(36840700001)(83380400001)(6666004)(7696005)(478600001)(36756003)(921005)(40460700003)(86362001)(81166007)(40480700001)(356005)(82740400003)(47076005)(36860700001)(426003)(336012)(2906002)(7416002)(1076003)(2616005)(26005)(41300700001)(4326008)(8676002)(5660300002)(110136005)(316002)(54906003)(70206006)(70586007)(16526019)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:26.5172 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89166e51-c5df-4be9-f378-08dbbb94aee7 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: BL02EPF0001A108.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4424 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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. 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/sps.c | 2 +- drivers/platform/x86/amd/pmf/tee-if.c | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index c5334f1177a4..61a0f3225b62 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -592,6 +592,7 @@ int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev, bool is_pprof_balanced(struct amd_pmf_dev *pmf); int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev); +const char *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); @@ -622,4 +623,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 08159cd5f853..5c6745f56ed1 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -13,6 +13,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", source_as_str(in->ev_info.power_source)); + dev_dbg(dev->dev, "Battery Percentage : %d\n", in->ev_info.bat_percentage); + dev_dbg(dev->dev, "Designed Battery Capacity : %d\n", in->ev_info.bat_design); + dev_dbg(dev->dev, "Fully Charged Capacity : %d\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 : %d\n", in->ev_info.socket_power); + dev_dbg(dev->dev, "Skin Temperature : %d\n", in->ev_info.skin_temperature); + dev_dbg(dev->dev, "Avg C0 Residency : %d\n", in->ev_info.avg_c0residency); + dev_dbg(dev->dev, "Max C0 Residency : %d\n", in->ev_info.max_c0residency); + dev_dbg(dev->dev, "GFX Busy : %d\n", in->ev_info.gfx_busy); + dev_dbg(dev->dev, "Connected Display Count : %d\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/sps.c b/drivers/platform/x86/amd/pmf/sps.c index a70e67749be3..13e36b52dfe8 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 *source_as_str(unsigned int state) { switch (state) { case POWER_SOURCE_AC: diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 1629856c20b4..4844782d93c7 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -186,6 +186,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:%d result:%x\n", out->actions_count, ta_sm->pmf_result); amd_pmf_apply_policies(dev, out); From patchwork Fri Sep 22 17:50:51 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: 13396224 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 CE895CD484C for ; Fri, 22 Sep 2023 17:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232924AbjIVRy2 (ORCPT ); Fri, 22 Sep 2023 13:54:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbjIVRyC (ORCPT ); Fri, 22 Sep 2023 13:54:02 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2085.outbound.protection.outlook.com [40.107.243.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE44A10E9; Fri, 22 Sep 2023 10:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DG37GrYZK0U18zigtfB4cwjBNPKVFhADKSw1QnN0wdvZFD2r8gNSA2G+8mgl0ShZrK14mWlZ5PFZKoC/aUnw3MA9qV7VmT1CYEudathLJjMEtZb2KhKmibrHH/ULcWn4EvVFYzAf3xCOoLsnzDMafoH27AJOMNMhEawP9tPg/FE4+oHZVuIAEDJdVhPpgop8zIowbQ9R9DyQzXyyF4+5Rt3foF1ykPaFIodFRyU1GXQ/U+mkHiiExlcIyH9bHbHPCL5VTB2ajikccvEVqIjNocUaRUPSbwKRv0rEhhdDR3NS+V0NX/XPCUT75Cd9M4c1FDDanl+RekzBw59EhfCgZA== 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=MWMU1BMJvqDyeO5obDmNUMw7Jb9+R5M/XfXzTvQ/pGM=; b=jXQdhvUVe5Oz3lE1OCS+01k1n1Y6Ec8stpdzt98ZEeysu2dsVgq/zZ73tH4QytlF26HrmtoyjmtCKwCh2Lvt8JAXQQ2wjX/RBfS9/qoFL0P3Ytl1IdF9MZTjt7OYZTM+GdWI8ujD6duozsaJwx1/qH8p+CSzOVhpJyoSwt3HzpJqO1QHiCnExkOEtIrlqEQp6vDL+gT6cLBWwFLo6JFTAsxBsYO854+FJx9FNWZSwSXCfcGD7v8sIstZib+XL8nX5yiAN34WNYzf/3dM6H19ZLjk0edfroL4Pii6fx7lLKdZH52HCNyXQ77h2YrkaasVlmGoMjRP/ZRGfyc2XHbiaA== 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=MWMU1BMJvqDyeO5obDmNUMw7Jb9+R5M/XfXzTvQ/pGM=; b=URvAZBRs7Qqz37Q3M23KKsHvNwY7XYb40mV36sd4bKf3Skwq6k08Jh1IwBJwqJAldDcznu/BoDHm4bHcxQl5HYtOMULwglcHmduygy2rpzkRMqh59b4WCYAVefdzYZwguvublaXM6DVeM8OYgJ/mXPwHUS3cGk6mvxacl0SL9lI= Received: from MN2PR11CA0030.namprd11.prod.outlook.com (2603:10b6:208:23b::35) by MN2PR12MB4254.namprd12.prod.outlook.com (2603:10b6:208:1d0::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.21; Fri, 22 Sep 2023 17:52:31 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:23b:cafe::9a) by MN2PR11CA0030.outlook.office365.com (2603:10b6:208:23b::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.32 via Frontend Transport; Fri, 22 Sep 2023 17:52: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 BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:52: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; Fri, 22 Sep 2023 12:52:26 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 10/15] platform/x86/amd/pmf: Add capability to sideload of policy binary Date: Fri, 22 Sep 2023 23:20:51 +0530 Message-ID: <20230922175056.244940-11-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A102:EE_|MN2PR12MB4254:EE_ X-MS-Office365-Filtering-Correlation-Id: cf184bc4-4176-4a1b-df9a-08dbbb94b1c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hukeWvQAUFJjQ1AM2lRC93qgkp8Jhocir4m92NS9Ia1w5fhlb7rFoAZ4e8DOvIT1RMalWFTt56/u6y1XLr2xg0+dQNoOf6Af8dzFftrqOO5HChHrrclqTzCiiSxRPsToomnVzHNE7TOziyemgddoxNTV2SkEc4ULfR9Nwrp1WIIuurPGQ1LvO4aZbQtr2EVBXEZsdKxMK++G0usuR+va+/jCPPxMKN+xzCHVkHdOguF2IFuEUD5fK8oI1WsDE5qU3i/Ki5KnAQugx2CsU/IAjTq/97fsjIa5gQafsEWNLrJ1v1ESl1s2dytilwZLemIINBP7urRgjKhcceywqMaLjGh7xsw1GDat4GdlQypBvuB145iZj76vSOJVKgdKswCyXqle4haPnSWZi19WnS9+IiIl795ND4z5GpFnij0knfkPyxO4MOuIEJR2IXEUD4VUMZdjtkQE9yYJVgNmNAjiiL46Bv73kHSQURnOEmJg/IX6BjJbCB534rvq1FHNQsEbj4WDy3EPxGhZX52qjoW2o3NnW2iz51hPdgG9+IfkjsWNfcvmzJ5ceg5DT35il0Au0prfEUSan7fuCiPAf0sEeo5E8BagvP00/bbBBt7iwfcVqcQPNEg5rt/B+hJy/8NVZSlpSg1PqhK1Blgq1LzCUzbL7RCpOqc9mgt9sbrZPMTb50zYHupII42o95Zu1HueFR96VNz8gH1HAxxJkHZm3S2NcdQlqopVNfHxqb30XE0K9p9PjOfis5q3vpakD0O9EFtI/nnFSUrLToJ59wmXuzAGHZX48nUplrWyCLsu8EjdsWgLIeZ9TSeweS/Ehkr3cMY2klsXlNMSmFLXJN7nLQ== 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)(451199024)(82310400011)(1800799009)(230921699003)(186009)(46966006)(36840700001)(40470700004)(7696005)(40460700003)(83380400001)(6666004)(356005)(921005)(82740400003)(81166007)(86362001)(2616005)(47076005)(36756003)(1076003)(426003)(336012)(36860700001)(7416002)(16526019)(40480700001)(26005)(41300700001)(70586007)(316002)(70206006)(54906003)(5660300002)(110136005)(2906002)(4326008)(8676002)(8936002)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:31.4717 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf184bc4-4176-4a1b-df9a-08dbbb94b1c8 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4254 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 | 60 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 61a0f3225b62..780c442239e3 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -215,6 +215,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 4844782d93c7..fa37cfab2dc7 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" @@ -21,6 +22,13 @@ module_param(pb_actions_ms, int, 0644); MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (default = 1000ms)"); #endif +#ifdef CONFIG_AMD_PMF_DEBUG +/* Sideload policy binaries to debug policy failures */ +static bool pb_side_load; +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, 0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43); @@ -267,6 +275,49 @@ 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, +}; + +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; +} +#endif + static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) { dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); @@ -279,6 +330,11 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); +#ifdef CONFIG_AMD_PMF_DEBUG + if (pb_side_load) + amd_pmf_open_pb(dev, dev->dbgfs_dir); +#endif + return amd_pmf_start_policy_engine(dev); } @@ -381,6 +437,10 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) { +#ifdef CONFIG_AMD_PMF_DEBUG + if (pb_side_load) + debugfs_remove_recursive(dev->esbin); +#endif kfree(dev->prev_data); kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); From patchwork Fri Sep 22 17:50:52 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: 13396225 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 17784CD484A for ; Fri, 22 Sep 2023 17:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233983AbjIVRyo (ORCPT ); Fri, 22 Sep 2023 13:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbjIVRyH (ORCPT ); Fri, 22 Sep 2023 13:54:07 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2048.outbound.protection.outlook.com [40.107.94.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91F91990; Fri, 22 Sep 2023 10:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mW+rW/rhFMshlN01+rfFzD1DfjB3BjmZ7w61090PTBzBrNaEHTNMdbtX8vd2yb8ZboVXF2AJv2iOLC9tNsVy4G7tlaTPc9Ff59W9A4kOQODAbajLGOAd0vGmfxesXEjReyiA/A53oejSs7V1xuk/DfdiVMxBN0aWFgrzledo0Efv1BtJVGoteFKzWxy1bJjk4CahwB9oEiJxYYZaGfxLwrtcR0hyFHbVMt04NYziYBY02a+Ujdn7ctAQ0tbx4n0WmPXb4970fwtnh9OvTPMg+wF/WGhzgl+ybRGsDiU3FyRqcpS1RQ313EwwjkIEblwfCTOjOCFWwf//suBOoJ9t5Q== 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=xS+5BixkfOE5EX9QuYophZBVswH4pHkTzPOe4TlftCQ=; b=h4gg+n7aQ/oQ2tPoeS2GK8y2UVgnmngKeNMSl8GafaMElQn7YVJd646h9QEkb4yEXdf8BKmcd2YRyj1nUJhPXTyl9wxnvX8xAv8+QdYksPwiKkBuVucZSfJWl+PIXfbWvZP89IdQjkdr4teSDfWEK8wEim3TOXPA8aJZn/PW4dtqqCODD+cXHRErPlQv3/Q9l7zcOdVBXJIoSIOXPQfMk27rWX8DiOKVo6A+7j71Z8VdZd4mC65FU0w3p6jF0JLtKPN+b+dGfoP5JBouXHatjB3oE3CZ67kB3TZ9wTWXjXvhyWJaqKKdQBF+GUWTM/sSco2znF1SN2zzec2Lon5pvQ== 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=xS+5BixkfOE5EX9QuYophZBVswH4pHkTzPOe4TlftCQ=; b=d9OONSly1PAtfJ2Kizj+jW8S3qcIW70IAE4RkD42EVDh7WhMGfIAt8TLd+ZFcfXT9EjrBFdGvtxCgWcAnybh7Ep+FHYWdqrkhIfmrPQAdwLBmlcNi69NYsXWZqhrtJIqxp01N/GYXHAmfnQ8UBtZzqYKWHQH5NPQ0wLtnWTs5Lc= Received: from BLAPR03CA0011.namprd03.prod.outlook.com (2603:10b6:208:32b::16) by IA0PR12MB8983.namprd12.prod.outlook.com (2603:10b6:208:490::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Fri, 22 Sep 2023 17:52:36 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:32b:cafe::e1) by BLAPR03CA0011.outlook.office365.com (2603:10b6:208:32b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:52:35 +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 BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:52:35 +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; Fri, 22 Sep 2023 12:52:31 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 11/15] platform/x86/amd/pmf: dump policy binary data Date: Fri, 22 Sep 2023 23:20:52 +0530 Message-ID: <20230922175056.244940-12-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A101:EE_|IA0PR12MB8983:EE_ X-MS-Office365-Filtering-Correlation-Id: a925dada-4853-4ccc-6751-08dbbb94b45a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OFNr/msp7JYNAzNFIYM352unPpdB8xM/0+qNDMYsMt4g8b01BO1FDt0eDLZ2p1tXlCRMTz6Tpxls+edaG4BJQN+OPNLBnd6cmt35EzlORNueoz5PWXfJ+7PNFsqCOxWEcZFZCeCeNBLdJtpxFI2IfFnTeKa36W0eOLhdEjWMZuml821y9+W3dyX8LCNIcu/4v4jg/rSW3Lzq4yh6FMRIMFGE6q3uoJX/D2+TykwvmIhjWNUBZNMnGvxFw2GVlyimK07cdhyzWtb2wSvg868BsexQ3R3igSBMQ1yBCaqO89CN3ESnxlG7PsteQQebCuRgUuG7/sKTugiiFXzveG2N5AAbziDurnBYGOQH0UNdOAYdmTFqQ3TR7ChpvnRw5slszswjt/XoyjwOBmCcvESvgWWxuM/s95QGcMvkbYVjyz2m6aA7Esqr1B8VNkk2rXj0VKlrA5CVmEkRTcXe89mdO6VxN+26P4DR38ty0MYvfLndT5wQ4GaTq+yGtIVgwxPiD+lRJSBIJq9Iv0iFhqgMbKjwi8kw3IPGs2/ami4CdkOS+xiUWY4Kb9pZ9+WQe6Pd8vNJv3KMJEQmvqzyqwMCmeUJxIsvus+X/fxJC8AhXHpyLL0aTxhJWYyh46rXytCX18ekEPE9IWhp0me92duD2SbEgqUr2O9IwR0XyAH3Bodaqo9WO6wiH2mkxn2WppFHDHA2Z6EvY0nJEOwng/vDqO6/MrvWzfuRISv/O+9XG2iwMQIqi45kHe3x8QJYpya4gsA3gX8+LQmPeAyJnreqvoHYPTAkrcgsalfOy8kbF2Vl1i0cupC9Y1fShc7hHjVAc7aB2YbImDZmnzDeiccCLg== 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)(376002)(39860400002)(396003)(346002)(186009)(1800799009)(82310400011)(230921699003)(451199024)(36840700001)(46966006)(40470700004)(6666004)(7696005)(478600001)(110136005)(2616005)(426003)(16526019)(1076003)(316002)(2906002)(336012)(70586007)(26005)(7416002)(54906003)(41300700001)(5660300002)(70206006)(8676002)(40460700003)(8936002)(36756003)(82740400003)(86362001)(47076005)(4326008)(36860700001)(356005)(921005)(81166007)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:35.7965 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a925dada-4853-4ccc-6751-08dbbb94b45a 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8983 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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. Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/tee-if.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index fa37cfab2dc7..3daa122f35d5 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -290,6 +290,9 @@ 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; + print_hex_dump_debug("(pb): ", DUMP_PREFIX_OFFSET, 16, 1, dev->policy_buf, + dev->policy_sz, false); + ret = amd_pmf_start_policy_engine(dev); if (ret) return -EINVAL; @@ -329,6 +332,10 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) return -ENOMEM; memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); +#ifdef CONFIG_AMD_PMF_DEBUG + print_hex_dump_debug("(pb): ", DUMP_PREFIX_OFFSET, 16, 1, dev->policy_buf, + dev->policy_sz, false); +#endif #ifdef CONFIG_AMD_PMF_DEBUG if (pb_side_load) From patchwork Fri Sep 22 17:50:53 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: 13396314 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 1A265CD484A for ; Fri, 22 Sep 2023 17:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233922AbjIVRzU (ORCPT ); Fri, 22 Sep 2023 13:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233555AbjIVRyr (ORCPT ); Fri, 22 Sep 2023 13:54:47 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2072.outbound.protection.outlook.com [40.107.223.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B69B19AF; Fri, 22 Sep 2023 10:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oLcG8vb/GRXriSThl3YmwnhJ1DOELkgNkFBiO490Y64U2+/Y7THpiOfnegGpLIZQ7oQKF6WSsDA06tqYTNeLXqDHcqRI8EKQRgvON+zZ00dnbRKqoIJOKQNSIbxoCb+olBfW7pQE4b2AkIUsoNNSjEc97yx45yXLcIwp4vANm21l0FnLaZfPFbHho71l+tynSnDygZqUNiWyLagbzWwJwVdWMdYf4BHqKtNNaab2vQ2iTI48wtfNqg0Wl4bLhwmceJi1NxgEYRN7tX2iVYX3JAzktO1Kfsd15+1ux9BODFr7xuqt0zhRR4Il/7GcEM4/JyyGkeeq7Wu5yY/OfXFzRQ== 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=0IpmrxrdMe/kHmzLijfRFeLkjrJTX2EbVrBzeS86ejs=; b=bdns5JMPc43gnFjzUlTFpUZLMroCyMxt+4pd6FxmMOccr8apVrGxwnnAca7EeiSL0UNNt0FsVidZglxT05inUhKUxs4JxGqo+LCtNVvUGS0fcscxmG9C3rqhas3aqbEPTV/dNvQxXgM2cZnKFhx12vPkQPc2IVpNxyyclvP25wMS6CWmIrstq7nWg5cnT8v28bD05iMwEMtKfHYBhgJnGl1CB7XTewPjb5eG/tWQzNxwXh83TPW1/TycLlHvHWTb/Pb4ONDJPnQqgkc/t9MQOCjPAxnq2LhgD50xmNlSVuVy2+VbuDcv/wFur5T90eiDR9BspWzq+kS3gaZTG5Ecfw== 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=0IpmrxrdMe/kHmzLijfRFeLkjrJTX2EbVrBzeS86ejs=; b=QUmtN6Q0yVpoFK5WF/ysvrWX3nZxchhAu5f37qc272lYvm5vT5NfOXKHKA6TvTZX5dOhzK9Wupd/xJlw3IXLZ4FVKBgIfdKrjJW1kyRbjiPK8oOxyDy5q3TvCXpdnAve4+XlfjS17HcLWcHYVczOY4jEJPYZQCECOpoWR2i+y8A= Received: from MN2PR18CA0027.namprd18.prod.outlook.com (2603:10b6:208:23c::32) by MN0PR12MB6366.namprd12.prod.outlook.com (2603:10b6:208:3c1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Fri, 22 Sep 2023 17:52:59 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:23c:cafe::38) by MN2PR18CA0027.outlook.office365.com (2603:10b6:208:23c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:52:59 +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 BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:52:59 +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; Fri, 22 Sep 2023 12:52:35 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 12/15] platform/x86/amd/pmf: Add PMF-AMDGPU get interface Date: Fri, 22 Sep 2023 23:20:53 +0530 Message-ID: <20230922175056.244940-13-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A101:EE_|MN0PR12MB6366:EE_ X-MS-Office365-Filtering-Correlation-Id: 520f9621-f353-43b4-e5cf-08dbbb94c259 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wW5DeTy0AHprgHYwkq0VKx3gCAcSa+h8JmhnqZmgZls98/l/2D3lBZTEt6QZdeK7A7KwGuaq/DzD1vGlgzuEtC90VCWcXLXiue7E2cqUSsracunEZ6aYJPaBnEcXbCPajCbyT070lZj6LawgMIVT4/aPFW7aMMqmt3gbuNU5kWEzd+qhIUDVF8pc6SmqKHyCTt9c+LHGvJBHSi2l7Y9v4IgC87JXLbk2zFZWc/mmXdvMRUUmDAzJ3AWcCo9L81NLWXvC9AUnJFalHeFkEV/zTE2Fcio6OtkdZXPOEFrbn9ayEACoG0bgAJOE/RrH/w1SOdfm2WFvjbZ7c3CmFEP/GkM+HwepjdE9X3BwDKCD0UuHEhKrb/NOvw0hAfIZ4VHFpmcdv4AUfXv0AQne6sEccjgD0bQ/MLZ4nzWs6UT87ZHNq5mP34De0C+1A79vQTreteRn78sb+wP4ySLjmvbve0yJh1AXStMr2L1+xwxIPHFkGS0R7lGMfZF95GeUJW8ST9X/qKwCH2E12pJBBbvqmk4U+z94Xo8kU4+szvXo+oP6zxmHkSleK4ESQs6Ajox8rILHPa12S9C7VFyyBQp9bDTi7rjqDOza9s5K/++eueuMRORYDqNjJuCUi+zvjVOMFW4VDEIwluuVSNb3+Z4w/PfTVX53t4Uor6fSvcveTE382V5AIxaoVJ/KTJhOum2WiMDsZd8gO+bURJM+o6UeWdLI4BlWqFK1UR+LBb6ogggaV6Z2aPVtqefBL7LoQ6toehH3Eyknjl7/7ux/sVOTnkb6vLqkRgAV4YX09qHFLT0UGtwo6NLRgVqDjNQOvc+JE+V7d2JA0Io5aaJgm3AxgQ== 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)(376002)(396003)(230921699003)(451199024)(1800799009)(186009)(82310400011)(46966006)(40470700004)(36840700001)(4326008)(8676002)(41300700001)(70206006)(70586007)(8936002)(478600001)(40480700001)(54906003)(316002)(110136005)(5660300002)(40460700003)(2906002)(30864003)(7416002)(81166007)(47076005)(921005)(356005)(82740400003)(83380400001)(16526019)(26005)(426003)(336012)(1076003)(2616005)(66899024)(86362001)(36860700001)(6666004)(7696005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:52:59.2813 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 520f9621-f353-43b4-e5cf-08dbbb94c259 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6366 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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 | 70 +++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/core.c | 1 + drivers/platform/x86/amd/pmf/pmf.h | 4 ++ drivers/platform/x86/amd/pmf/spc.c | 13 +++++ drivers/platform/x86/amd/pmf/tee-if.c | 22 ++++++++ include/linux/amd-pmf-io.h | 28 ++++++++++ 9 files changed, 142 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 dc2d53081e80..475f3e248f35 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..232d11833ddc --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -0,0 +1,70 @@ +/* + * 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; + struct backlight_device *bd; + 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; + } + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + pmf->brightness = backlight_get_brightness(bd); + + mutex_lock(&mode_config->mutex); + drm_connector_list_iter_begin(drm_dev, &iter); + + drm_for_each_connector_iter(connector, &iter) { + if (i > MAX_SUPPORTED) + break; + + if (connector->status == connector_status_connected) { + pmf->con_status[i] = connector->status; + pmf->connector_type[i] = connector->connector_type; + pmf->display_count++; + } + i++; + } + drm_connector_list_iter_end(&iter); + mutex_unlock(&mode_config->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 437b78c6d1c5..0cd08f9ab51b 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 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 dbfe7c1d6fc4..c468d208b1dc 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -396,6 +396,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 780c442239e3..9032df4ba48a 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -13,6 +13,8 @@ #include #include +#include + #define POLICY_BUF_MAX_SZ 0x4b000 #define POLICY_SIGN_COOKIE 0x31535024 @@ -224,9 +226,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 5c6745f56ed1..5f3ab1ce09d2 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -43,6 +43,10 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "Max C0 Residency : %d\n", in->ev_info.max_c0residency); dev_dbg(dev->dev, "GFX Busy : %d\n", in->ev_info.gfx_busy); dev_dbg(dev->dev, "Connected Display Count : %d\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"); } @@ -144,6 +148,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 */ @@ -152,4 +164,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 3daa122f35d5..1608996654e8 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" @@ -345,6 +346,20 @@ 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) { + dev->gfx_data.gpu_dev = pci_get_device(pdev->vendor, pdev->device, NULL); + if (dev->gfx_data.gpu_dev) { + pci_dev_put(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; @@ -435,6 +450,12 @@ 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"); + dev->prev_data = kzalloc(sizeof(*dev->prev_data), GFP_KERNEL); if (!dev->prev_data) return -ENOMEM; @@ -451,5 +472,6 @@ 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); + 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..a2d4af231362 --- /dev/null +++ b/include/linux/amd-pmf-io.h @@ -0,0 +1,28 @@ +/* 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 + +#define MAX_SUPPORTED 4 + +/* amdgpu */ +struct amd_gpu_pmf_data { + struct pci_dev *gpu_dev; + enum drm_connector_status con_status[MAX_SUPPORTED]; + int display_count; + int connector_type[MAX_SUPPORTED]; + int brightness; +}; + +int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); +#endif From patchwork Fri Sep 22 17:50:54 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: 13396329 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 3ABDFCD4847 for ; Fri, 22 Sep 2023 18:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233868AbjIVSFq (ORCPT ); Fri, 22 Sep 2023 14:05:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjIVSFa (ORCPT ); Fri, 22 Sep 2023 14:05:30 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2089.outbound.protection.outlook.com [40.107.94.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEFE11F1B; Fri, 22 Sep 2023 10:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=llr9pIBpWj5mMoayltF6z0STF/bVF5m3SBbkzLAfj5yEbJou78/U3eI2+JuF8xUAMqgRrsjU1MY9L5Ak4ZJgS5cho9m3mn1nIDJGHIAwG2eSRd0BlE5OmWwuvt+Xa5DJtNQPUFXLrx85xOT5GeCHTTghZinelgkkCjMYqVsnNU1TnpxCTn2xl8ea1Li350Wo+7mQ62PNEoLxpZfW9kaSmkP0IcS1FPEoDPjaYR9MyiKNasEowG6qgQiKLcmvdXdm4HAcor8hpW22PqPzYlcWjt1+O3xlcBtULG5tdqcsKacpkogIU00VbN7tsYQvEd5bWoxMdLPB6s03G9DLlE+Cjg== 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=OXkbVhQ7IKBoM4wQ6XXY6ozTN/ug3ZSnz4TrGE1a/0E=; b=bFEJ4swtxUY9aU4fE/Kbq/jk7+dP6BhhTFa38OH8AZqghCZEt0AWNlCMMka0P7psZCchIauLy+oJGrr0p93UbfQJZpKe07LfZoqiinIAxFCCt/34g+bFmi00aaj69N7Kqj7SOK+HV2/kdD2k55trgPGkqsfCwTFDvYvo7s+4o8tisLXz3X51CiVZDubDDREXtm11tewr1Bi0gGGivcM2rNqvP7rA44LdGbHQlTRa/8YQwmtCgfP1Am7j4NWD6zwMIAjAZWPAZsxL50cnww+cq3NIZBQzbvZz4MDHQbN+M4EhcIMIGmsS95bGIBqyAMWdoCJ6oS0Xg4O1/9Eteh1y3Q== 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=OXkbVhQ7IKBoM4wQ6XXY6ozTN/ug3ZSnz4TrGE1a/0E=; b=rf4xfh7Z/KgNlqesUqD4/jNzmAF1Gb9X604kGf/dvGo4e4xhfFBEsTtB3R9fCDLOTL2uUDni1tMbcPhXssxiGRpS2koH3igVKDs+zv6RWV00vuSCf0vmuwPTAVKE6X0SVwIt7eFiXMiiL1x78Ii1cQZDFMhYNlKG0+aFsOzU85E= Received: from BY3PR04CA0025.namprd04.prod.outlook.com (2603:10b6:a03:217::30) by CH2PR12MB4860.namprd12.prod.outlook.com (2603:10b6:610:6c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Fri, 22 Sep 2023 17:53:05 +0000 Received: from MWH0EPF000971E4.namprd02.prod.outlook.com (2603:10b6:a03:217:cafe::8d) by BY3PR04CA0025.outlook.office365.com (2603:10b6:a03:217::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.31 via Frontend Transport; Fri, 22 Sep 2023 17:53:04 +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 MWH0EPF000971E4.mail.protection.outlook.com (10.167.243.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:53:03 +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; Fri, 22 Sep 2023 12:52:57 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH 13/15] platform/x86/amd/pmf: Add PMF-AMDGPU set interface Date: Fri, 22 Sep 2023 23:20:54 +0530 Message-ID: <20230922175056.244940-14-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: MWH0EPF000971E4:EE_|CH2PR12MB4860:EE_ X-MS-Office365-Filtering-Correlation-Id: 83b0c5f3-fde7-4aa1-3dec-08dbbb94c53d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rWoou7nIAzBwJ0IcSahTzFgrC+/AWpfg9tUzXP43Mv9oDMQbsbhFhcYOJ9skCjCVomSFb0P3v2N/sUc2GXQcYJ/kHYWXX6jDSP8o2A2EXwgmqHeP45H45bzUtQOsdP13fg3i6trc+MaPzdJ5hQRionLFwmXXlcNqamWEHuTzCp9pI/5EY+4tGoDMBLp4YsFDO08WgqzEGoEOH3Y2eiDrmMirvccuooJvPcDU9fgiv2VI0mNBUfXnQ9SDNB2T+PF7xiybKbAcHzxk/XrnGmPT/5u5LIyDsfV1W3UwyghkAmsijKX012HcpvrbWmw06xVJiAeHBiKIeklIyB+JvP8hEEEzaCrx7DCQJQOVt1QvCAxbTppv+TCGGJNIaQ830nDCXOIeWQ7qmaUfVcNQ4aHsEO/OcNw5D4isB84UeG34KnMr9b1lfB9m9/Uzak76Sa5N40TX2uvHN3+KZq9bkh07SRIKyjYTeiyOPwdeQma83AtTDejB+gkroYZEntwkdQxr4Xi90/lngHRlcgcJuG+kAPvJaJOsRz91VsPcEG6J5qDsRTpkyWQaWNVgViieDyLbltNvr530Df+EaMh4DBD/vQIBoJJQXgxk4I5QrX6OyL7XhEZeYgZF/zQr/uw9octQug4YoaTbgjeGitBdJ6zXPsoF9sWGG6ls4OwO9QZ3RMJ+f5tGXWCdTOzC3PzGOpBqsaAeep4vkq7ttaCZUPV2sCc5EVPIGCY0YTkBciNjf4mKFfxgLLXv8vsMOc8ZqzeuSY2CfLlNDFxVsKIw6ZfjSHgSkK96mp2gYIwLuf7PA77DAD5DoPb2875Uz2D9cfG2pr1rtlEjMCGU4Om13oKdOA== 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)(346002)(39860400002)(376002)(136003)(186009)(230921699003)(1800799009)(451199024)(82310400011)(40470700004)(36840700001)(46966006)(8676002)(8936002)(4326008)(110136005)(5660300002)(7416002)(40460700003)(83380400001)(36860700001)(316002)(16526019)(26005)(7696005)(40480700001)(70206006)(54906003)(70586007)(82740400003)(921005)(356005)(81166007)(6666004)(41300700001)(336012)(86362001)(2616005)(47076005)(426003)(1076003)(478600001)(36756003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:53:03.3923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83b0c5f3-fde7-4aa1-3dec-08dbbb94c53d 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: MWH0EPF000971E4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4860 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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. 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 | 21 +++++++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 2 ++ drivers/platform/x86/amd/pmf/tee-if.c | 19 +++++++++++++++++-- include/linux/amd-pmf-io.h | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c index 232d11833ddc..5c567bff0548 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -68,3 +68,24 @@ int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf) return 0; } EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); + +int amd_pmf_set_gfx_data(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); + struct backlight_device *bd; + + if (!(adev->flags & AMD_IS_APU)) { + DRM_ERROR("PMF-AMDGPU interface not supported\n"); + return -ENODEV; + } + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + backlight_device_set_brightness(bd, pmf->brightness); + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_set_gfx_data); diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 9032df4ba48a..ce89cc0daa5a 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_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 */ @@ -480,6 +481,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + unsigned long display_brightness; enum system_state system_state; unsigned long spl; /* in mW */ unsigned long sppt; /* in mW */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 1608996654e8..eefffff83a4c 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -79,10 +79,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) { u32 val, event = 0; - int idx; + int idx, ret; for (idx = 0; idx < out->actions_count; idx++) { val = out->actions_list[idx].value; @@ -160,8 +160,23 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_ dev->prev_data->system_state = 0; } break; + + case PMF_POLICY_DISPLAY_BRIGHTNESS: + ret = amd_pmf_get_gfx_data(&dev->gfx_data); + if (ret) + return ret; + + dev->prev_data->display_brightness = dev->gfx_data.brightness; + if (dev->prev_data->display_brightness != val) { + dev->gfx_data.brightness = val; + amd_pmf_set_gfx_data(&dev->gfx_data); + dev_dbg(dev->dev, "update DISPLAY_BRIGHTNESS : %d\n", val); + } + break; } } + + return 0; } static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index a2d4af231362..ecae387ddaa6 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -25,4 +25,5 @@ struct amd_gpu_pmf_data { }; int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); +int amd_pmf_set_gfx_data(struct amd_gpu_pmf_data *pmf); #endif From patchwork Fri Sep 22 17:50:55 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: 13396315 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 71C49CD484B for ; Fri, 22 Sep 2023 17:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbjIVRzd (ORCPT ); Fri, 22 Sep 2023 13:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233158AbjIVRy5 (ORCPT ); Fri, 22 Sep 2023 13:54:57 -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 8E9D31FCA; Fri, 22 Sep 2023 10:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kaDHyqEV20DprEr8lgePLr7vFybaGYl7a29PoayJG8HjgDjrprG/Gb8b3Z7qGgeFOEe/R8xAgDOUxpLQrpjWDknptCTkKLAkrE99FCvkEI1eYuHnNfEvPS71/UIc92NfMOgX1R0lJ1sTcQBLapp7oIPjZ3Zj1dmWgBkKerK/vSeUkmAdpTaR/aOCQi/+utINz6gRfxbd5X0uhxbKaeAes5tEJdrWoz15Ma87yTla6I0rBJnPfdUpJ2tEcj9S+xd2RbMDP2babKmNWOQlChO/NQRaFDqaO6z95gLJtCUy7rYWNuXxULHEdl43nPqUQMTzWSYeTWMEG7qMyOvQoKvCag== 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=rIeZlv50GF+A0GlcUULwxGe4T92+O4Eo3KJvtr+bF08=; b=Ij487NBY0cylA3Yh96IrLdvCXoMQtziorFk9mXdmrHiXUiAPC4+FIrP1rL9xIx4+gLVWFwnz/8gZC33rIuzcyVaj+t19/+Ss9RlB6ZYrI0YHrNbQOe66XUavzt7KIN5xpkoP5rHRT6zfvFzB+4p19rDO9TPJMRaquO25r2ut5AN/GjUehaWUP6Y7aMCv5a8wcFV8kk5wqhzikhKDhl/UAms1COkNsG0kFJxfKB6JQeitN/2rzv1JgVfge7xrbi3Tfi03TtbVia8J1CiELxa05TOnIEm+7BRvRUUBNbeFcr43NSivCfKeL4HY7/iSdKRxnL4RXmQ5sGM/uWU+t+iHvw== 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=rIeZlv50GF+A0GlcUULwxGe4T92+O4Eo3KJvtr+bF08=; b=SCsyhuESq2Y1XfQ2dSJ3YdVQ2K4pW9/dZ7C1MFiaNgOHm6ozQi5xxcqUU5ihKVlnbisHhvJsyptm6chLfjTUikaE9kUEnGblsB2tD7SYqL38nYjZVlepxtY1oBks5HGKw7VwSbjG00jHOSjzrpX6JEvrQItc9x5rHFRss7iijhI= Received: from MN2PR18CA0013.namprd18.prod.outlook.com (2603:10b6:208:23c::18) by CY5PR12MB9055.namprd12.prod.outlook.com (2603:10b6:930:35::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Fri, 22 Sep 2023 17:53:07 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:208:23c:cafe::d2) by MN2PR18CA0013.outlook.office365.com (2603:10b6:208:23c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.34 via Frontend Transport; Fri, 22 Sep 2023 17:53: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 BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:53: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; Fri, 22 Sep 2023 12:53:02 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH 14/15] platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD Date: Fri, 22 Sep 2023 23:20:55 +0530 Message-ID: <20230922175056.244940-15-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: BL02EPF0001A101:EE_|CY5PR12MB9055:EE_ X-MS-Office365-Filtering-Correlation-Id: e5c775c9-6b33-4ff9-4e93-08dbbb94c74e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JYTVMfHELFUJXEXSDmmCPETVYdKgDJrHo+r+8e1I4Pk3ieHRmL2zz5U5qo4XthC65jF6sbBRlB86feiFDRePjP4IBwGOcCTldjI9040Sb+fVzd7B1La6yyCcCIkGgNvgaiDrV/6qCGYUTHTW/41TFXabHmk4dyehUxcPFvMHB2FoEUVnMsUks0S6mqbv7VYMZl862qbIMIlNserDcvpFjK62RP1tOIg2QiHEeg+gA53U1dLKnHcpkAncHv5xVo+fmfU2KIqqPGlX4md6h4QbhzMtndl/lofqhQJrDq0M4sf2BJTUuRi+DcV8/27fuca++0SEaowGy3M9cToLwKDe8mkdOXM0t1OFC6+geivWVBEhSow4+Yc8xek7/nd4q6zLYCR/x7zk1rbE7mztl8JGwt4/IfyUBIsYaNsZMY3aAPTmJF8pSIQ2nnybYiXs0529tty7QJsniDVyXE9i2XN659bvUQYP6USsqRo+0K64uAUs+jMDMGrq1AWLY0+AJScA/wLTWCjQhbgDUsygp1Ra+GXj+LpTv+gZQwKfIZ9bp2dGSof5ylEb9DvE29+wWvqAsxD6Vg+0wd7J+bjro681VFzrQp+wBFKg7k6xSxhnqDkqr1UJANKbFNY3IWsSa9xg2EOU7rWKRXWhqIHklnO4o34SJIcg2qnAez9O8kIkdO4UvFX9gePuTa3BX0ziGCctogFb8sPh9tRU+5XdudVJOFXIvV8rkKY5Eizj0I0omUXDQhKc/T8AdKASxMj0rQ1cR0O/OgYXa4sQNHyYQ8F7gZ+Xxnd+PHWB9qUih3QvnyT0HPH1G42uptaekl4BoGR9BD0xL8DPflH3Utd5F0YJsA== 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)(136003)(39860400002)(396003)(451199024)(186009)(230921699003)(82310400011)(1800799009)(36840700001)(46966006)(40470700004)(86362001)(2906002)(5660300002)(40480700001)(26005)(70586007)(1076003)(16526019)(41300700001)(70206006)(316002)(110136005)(7416002)(54906003)(336012)(8936002)(8676002)(426003)(4326008)(478600001)(6666004)(7696005)(40460700003)(36860700001)(47076005)(36756003)(2616005)(81166007)(921005)(83380400001)(356005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:53:07.5940 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5c775c9-6b33-4ff9-4e93-08dbbb94c74e 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9055 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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_desc.c | 2 +- drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 11 ++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 28 +++++++++++++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h | 1 + drivers/platform/x86/amd/pmf/spc.c | 21 ++++++++++++++ include/linux/amd-pmf-io.h | 22 ++++++++++++++- 7 files changed, 88 insertions(+), 2 deletions(-) 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_desc.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c index 06bdcf072d10..d7467c41ad3b 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 float_to_int(u32 flt32_val) { int fraction, shift, mantissa, sign, exp, zeropre; 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..9c623456ee12 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..63a5bbca5a09 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 -1; } +EXPORT_SYMBOL_GPL(amd_get_sfh_info); 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..8a36386e6bce 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 @@ -149,6 +149,7 @@ struct hpd_status { }; }; +int float_to_int(u32 flt32_val); void sfh_interface_init(struct amd_mp2_dev *mp2); void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops); #endif diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 5f3ab1ce09d2..97293ae25cf5 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -48,6 +48,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 @@ -156,6 +157,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 */ @@ -165,4 +185,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 ecae387ddaa6..4f82973f6ad2 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 @@ -26,4 +27,23 @@ struct amd_gpu_pmf_data { int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); int amd_pmf_set_gfx_data(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; + /* add future caps below */ +}; + +int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op); + #endif From patchwork Fri Sep 22 17:50:56 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: 13396316 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 D6739CD484A for ; Fri, 22 Sep 2023 17:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233816AbjIVRzh (ORCPT ); Fri, 22 Sep 2023 13:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233835AbjIVRzN (ORCPT ); Fri, 22 Sep 2023 13:55:13 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2089.outbound.protection.outlook.com [40.107.243.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6621F3E; Fri, 22 Sep 2023 10:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bnEUX9cYUkZtNAcm2qyJ9AySB8LYlTEy1GH5GyJq6CAKls7VOL00/3FAW8RsJJZDZ6Ss/K3acSf+8j0jZuQr0klGHNQwDkuI8xGe+8zkgPPVmYpP7uxBi+Nuw2KzNAQCVfjQtkQG9ZO+Y+qRFUeXWgx9J532KuLaVx4dSgjmRIJM+lXEaPQH0nFrASg7TQrrTsUUat7BOgY411cMns2ncq1rkY5ku5n5TwRGHxeOY9JRfa7e7CybgyUtF7/FHkqrXtUB1uUJaHVveL/3yZDaHJGHBlKLBQMPHXy48wyxJZ86IdOYlPGoDasK5P4ldFq9MSREJ5xRlXrIXeqVSgkMAw== 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=GbQuQvkZfDZ13Sj4SXzVEcaw91G+GkWRwS7S4VyP9ZY=; b=ZNkfB7tixK8Uz//vz+IYPw2+tLa2Z6uiSzST6V0LRxKgXsAwu0Tiu8mAdVRbTtGthXmW8xzzYI9Nrc8S8Zh3hWZIMxe0+xnNDMt53ex5YkKjOPdu2IQ075whVggxbyAjEjLYe4SSpJtnahrAew1VKSaRfxKM+Yib0paHE9Ngqr/3tUihoP+KJoMczxUVAucYmJefIiifSF66/71hx+TE67aCQVBFV86IY0zN/GTuQjPHJYO73h3FU3w1RqTHuDgo1dpouPlmY/9v/JG6x2WHx48LVxopsh9VSAXWxoHvF2Y9bqfk6g1hJi0MrmU7+mgRlWNs3P5F2JC+STJ/4nwmqQ== 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=GbQuQvkZfDZ13Sj4SXzVEcaw91G+GkWRwS7S4VyP9ZY=; b=H0DCXoEcloqSPS/31ws0IiWEGnQXAcMe06zbvfS70Wp99z1EV98uBfh2CEgYYZcNXEHtDMoGAWICr5INCYQ4QHpOZ7tH5+Wx/U6/D/9aZTeDPHDDU1AVpRc6JEALGzkraumlNcxwC/+7B6BNmEaMRuwTogm5F4oMWMmCAcbl42M= Received: from BYAPR05CA0073.namprd05.prod.outlook.com (2603:10b6:a03:e0::14) by SJ0PR12MB5675.namprd12.prod.outlook.com (2603:10b6:a03:42d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Fri, 22 Sep 2023 17:53:15 +0000 Received: from MWH0EPF000971E6.namprd02.prod.outlook.com (2603:10b6:a03:e0:cafe::2) by BYAPR05CA0073.outlook.office365.com (2603:10b6:a03:e0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.14 via Frontend Transport; Fri, 22 Sep 2023 17:53:15 +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 MWH0EPF000971E6.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 22 Sep 2023 17:53:15 +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; Fri, 22 Sep 2023 12:53:07 -0500 From: Shyam Sundar S K To: , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH 15/15] platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS Date: Fri, 22 Sep 2023 23:20:56 +0530 Message-ID: <20230922175056.244940-16-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> References: <20230922175056.244940-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: MWH0EPF000971E6:EE_|SJ0PR12MB5675:EE_ X-MS-Office365-Filtering-Correlation-Id: a020a714-63fb-42a0-3ee1-08dbbb94cbfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ig62JesUl7hpBtwm0vMnbgkvtsjKHj43GCbO+t9prcHGiUohKQkS8fDEi2ohA/9kb4etj2I6lD1+nnvFGKVKrEHsmvKi3gzWxfKU4acf5Vqbqj24vI3Q6A9u+KaxYQGg4mT6v6ZQcIwVoN8E7jXnFPm/+CXYfUqeVem8arrYkpSvIzrC9FE6p5W4+zzAG7PwehNqgcKyfP/Nvr6FJcsX9JjtdiLfs+hd5rrQtdph74YVXe+c3PKJwDZWf5TfswUcYPElKFBTitEXtMDHhI+fN3kHoCpjhM4ieO0sFqyshe+oh880RnPPVvIOH13JhsCul3LYd5NE2Gup4BNGNElsfp3uM6CUBSLWdSs8Q5f/nLGiFssCeNHogoAkvdKxvbo7sRqr73wWHVZimWHqwZKWOcX9AeqXhThyfBFBDko1Ns0RIfA0iH2Km0j89gUB2vfTYOFZsRqzIUzDgJhfow1OFXfMQFmBKJ+6UQ0fvnHl4Y93TMv0dmklz+Q5I6Qr5nwrL0ww9b8hpt6bdHoXMmBIDrvGCpXMZwJ7YWCiRWOFufOeTvuwkDtSBBnzF4uX7gKg1QRaMdUwlNu0vH2410CSbtUvh4i08XFpHHpvdMfWeOZ77qUcmFe+4GXjO6j1+tYUpAifbdn/flY7J8OrlC0+2a0bfJAl4ZI9+BmJC8k02cp7Jb/0EK2snPUy7Xo7uiI1goXu0nkxkpfm62K6ZExHMKzZggtGUdwCJ0q0RXlZcdXdGCvji+y+rWWQk/pR3YauXs27HujPlBlLTEepl3iwcwL00A3P/6ye56sEWSaGTmtQvYkIPLZfcp3Z4KebeA9oO9jyK7D81wgS/q3N+lemiA== 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)(346002)(396003)(39860400002)(186009)(1800799009)(230921699003)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(6666004)(478600001)(7696005)(47076005)(86362001)(921005)(36756003)(81166007)(8936002)(356005)(36860700001)(82740400003)(336012)(426003)(40460700003)(2616005)(16526019)(1076003)(83380400001)(2906002)(7416002)(40480700001)(8676002)(26005)(54906003)(4326008)(5660300002)(110136005)(41300700001)(70586007)(316002)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2023 17:53:15.3067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a020a714-63fb-42a0-3ee1-08dbbb94cbfa 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: MWH0EPF000971E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5675 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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. 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 | 5 +++++ include/linux/amd-pmf-io.h | 2 ++ 5 files changed, 34 insertions(+) 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 9c623456ee12..d8dad39d68b5 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 63a5bbca5a09..2f8200fc3062 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 = 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 -1; diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 97293ae25cf5..8e19b351e76f 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 * "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 @@ -161,6 +162,10 @@ static void amd_pmf_get_sensor_info(struct amd_pmf_dev *dev, struct ta_pmf_enact { struct amd_sfh_info sfh_info; + /* get ALS data */ + amd_get_sfh_info(&sfh_info, MT_ALS); + 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) { diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index 4f82973f6ad2..dac0af573a16 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -31,6 +31,7 @@ int amd_pmf_set_gfx_data(struct amd_gpu_pmf_data *pmf); /* amd-sfh */ enum sfh_message_type { MT_HPD, + MT_ALS, }; enum hpd_info { @@ -40,6 +41,7 @@ enum hpd_info { }; struct amd_sfh_info { + u32 ambient_light; u8 user_present; /* add future caps below */ };