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: 725466 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 80141CD484C for ; Fri, 22 Sep 2023 17:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233711AbjIVRxV (ORCPT ); Fri, 22 Sep 2023 13:53:21 -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: linux-input@vger.kernel.org AMD PMF driver loads the PMF TA (Trusted Application) into the AMD ASP's (AMD Security Processor) TEE (Trusted Execution Environment). PMF Trusted Application is a secured firmware placed under /lib/firmware/amdtee gets loaded only when the TEE environment is initialized. Add the initial code path to build these pipes. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/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); +}