From patchwork Sat Sep 30 08:37:00 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: 13405050 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 44F13E77365 for ; Sat, 30 Sep 2023 08:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234084AbjI3Ii2 (ORCPT ); Sat, 30 Sep 2023 04:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3Ii1 (ORCPT ); Sat, 30 Sep 2023 04:38:27 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2053.outbound.protection.outlook.com [40.107.92.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63F7A195; Sat, 30 Sep 2023 01:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jk6tti3ko9qqL866GnImR78+nmc7rUrRyIcVQyHHVVyU8ltcy5HugTL4swJSSlPub2qVTETeFUAPbx9VHCbPynitrYO7NaYDECYkdDlTEyfZJPMcu11P0KxrPkazr2LI/C1O9CfaLM7OeMUuHk1IvK3G+Pu/gbGKHTZH4CtLRP47NwjxHq/seIyuFsgaJFwI+2Uk7P5dw6Jodhutk5w+7QBVy50Uw7LMNET/Dpqrz+P5y2+9ZgviP7MB6rhMzebfgpMIQ0SGf2JnEO1t98vDXeb6hM6aPLXu2SyOb+q4S0AJ83O3l6arlc9N2lVgWkkBgcR0gHm+Qva8bnSN5h17xg== 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=sAeLJc5nN4mbmiBHkfsm9EP+38vQ6v1sonp/qDaQT8w=; b=hkN0gSGSiv0QeEPalpsgfSoT4w5qXTW9tqgMvOnxFmpMfByVIIcREGzJvsefMaYBKTO8WLGYQRTpX8sdV+B63oPD56zruHeZ6Ny9HXN7ZJD7xBwPq40RAPThWjpNOt8+RI61Tl0DLTzO0+IiNLM4AgJQJ4llYulj7KEyVougtLXidGrp3VyL962txH/M9nnfrl8sSfny226RjoLGNbuaU68FLZC35UYYI4OpkVLdQ8QmmIeUZaMjQNc1s1BhN5qLjcAfE9XQEnOoebAEQUAXEGPRPOnBI+uOmHISVUlLnr0a9XcXRrete9DCxb67jGyuD5BVMPBQlK/dLJ9gd7fJ4A== 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=sAeLJc5nN4mbmiBHkfsm9EP+38vQ6v1sonp/qDaQT8w=; b=uId3Fgjwh1rOQXoUw0P70xhs6JZi1xzumgFj65qT6jAQaYqagRrkx5hTuL1i5WxO+cqD5qHSy5+wbCq2EOFk9dzMOoI6C6SOxKZQBhlnECo0Bbn822DR+58mE19nTw+6Ur7xkLc+beES7G7Ke78hfgM4IlCNxJp6AdX1myOtcns= Received: from MN2PR04CA0022.namprd04.prod.outlook.com (2603:10b6:208:d4::35) by IA0PR12MB7529.namprd12.prod.outlook.com (2603:10b6:208:441::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.27; Sat, 30 Sep 2023 08:38:19 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::39) by MN2PR04CA0022.outlook.office365.com (2603:10b6:208:d4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25 via Frontend Transport; Sat, 30 Sep 2023 08:38:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:19 +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; Sat, 30 Sep 2023 03:38:14 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 01/16] platform/x86/amd/pmf: Add PMF TEE interface Date: Sat, 30 Sep 2023 14:07:00 +0530 Message-ID: <20230930083715.2050863-2-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB74:EE_|IA0PR12MB7529:EE_ X-MS-Office365-Filtering-Correlation-Id: c8f8ea00-66dd-4734-2a6e-08dbc1909943 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GfzmgEs+1/iPtUwyIuKj/VaZPtOvCoUr+AQghbceAdUxau9HoVQgpeqPAesCWcuBgCoMQu+sChiwaHVMkZuv+aNbU/bL4YLKRgnKqA7h9qBJuSC85qXh8e2Kms2WfE3uCzoISNuAVCwNRgcGKD0a+CVgeRuSK7UlrY77LeIlMMI7YL0trdp2Y/Gyqz1Il7Diy6Sw4U/SAIboT6VAzN+sS5M+K4+P8LTH7JrlIwBzXR7f0l/PhXBiv88xBmQqngyHyKoIO2iDnUX/jwBIyGF/ccyEoN0faUEE/qR9cP2Mfk4OX1MkyJxK7a/gK8M5zmYOBcioSIDBUmazYJjN8dVGLbFrx7Ih1zsSiQwQoFxCYqnFZLYxCStbaD4YITV4R98+aAJNMPsFR7tGTzaGL9mmbbgDJqnlvo/FIvKtYEt34QFMhcIUxCqF90CINp3jf9gXrpbm/v3Afh/jW4mYfmtNFFNcIC1Em0/3TmVHhPRKgr/g4ejxHTkXAstZuTH4gZ4abgOytL1KWK5zIXAYH+u6OFuCx6bEVY3Ny4cmLps6W7c4/elKAnQgYmRLNaxKnlNXa8s0NEz+RE2Saj/Tfa+1boYtclYWh27Dh6+Y8VE0wxD3LSor5AxF6GXLm34sC7siCBGwuChhRILOAFX+C+6sOtkgoI71S5JFfU/aTn4nt4HRZWNC7kTEOO700FLxI6nPFpbu+31durFnCNcoYa4XCPsVke1drMHu4K/8gBnFDP3W2XotH8Os+9igqIEkV1P09pgkSnA9p/EIXhKtMzrI499dCTUyo137Tjbz0nS0fZ0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(346002)(396003)(376002)(39860400002)(230922051799003)(82310400011)(1800799009)(186009)(451199024)(64100799003)(40470700004)(36840700001)(46966006)(41300700001)(40480700001)(40460700003)(316002)(54906003)(110136005)(336012)(70586007)(70206006)(426003)(36756003)(7416002)(83380400001)(26005)(16526019)(81166007)(921005)(82740400003)(356005)(47076005)(2906002)(86362001)(5660300002)(1076003)(36860700001)(4326008)(8676002)(8936002)(6666004)(2616005)(478600001)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:19.3511 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8f8ea00-66dd-4734-2a6e-08dbc1909943 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7529 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 | 112 ++++++++++++++++++++++++++ 4 files changed, 138 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..4db80ca59a11 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD Platform Management Framework Driver - TEE Interface + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Author: Shyam Sundar S K + */ + +#include +#include +#include "pmf.h" + +#define MAX_TEE_PARAM 4 +static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, + 0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43); + +static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) +{ + return ver->impl_id == TEE_IMPL_ID_AMDTEE; +} + +static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id) +{ + struct tee_ioctl_open_session_arg sess_arg = {}; + int rc; + + export_uuid(sess_arg.uuid, &amd_pmf_ta_uuid); + sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC; + sess_arg.num_params = 0; + + rc = tee_client_open_session(ctx, &sess_arg, NULL); + if (rc < 0 || sess_arg.ret != 0) { + pr_err("Failed to open TEE session err:%#x, ret:%#x\n", 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, "Failed to open TEE context\n"); + 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, "Failed to open TA session (%d)\n", ret); + ret = -EINVAL; + goto out_ctx; + } + + size = sizeof(struct ta_pmf_shared_memory); + dev->fw_shm_pool = tee_shm_alloc_kernel_buf(dev->tee_ctx, size); + if (IS_ERR(dev->fw_shm_pool)) { + dev_err(dev->dev, "Failed to alloc TEE shared memory\n"); + ret = PTR_ERR(dev->fw_shm_pool); + goto out_sess; + } + + dev->shbuf = tee_shm_get_va(dev->fw_shm_pool, 0); + if (IS_ERR(dev->shbuf)) { + dev_err(dev->dev, "Failed to get TEE virtual address\n"); + ret = PTR_ERR(dev->shbuf); + goto out_shm; + } + dev_dbg(dev->dev, "TEE init done\n"); + + return 0; + +out_shm: + tee_shm_free(dev->fw_shm_pool); +out_sess: + tee_client_close_session(dev->tee_ctx, dev->session_id); +out_ctx: + tee_client_close_context(dev->tee_ctx); + + return ret; +} + +static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev) +{ + /* 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 Sat Sep 30 08:37:01 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: 13405051 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 1C6BDE77362 for ; Sat, 30 Sep 2023 08:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234161AbjI3Iia (ORCPT ); Sat, 30 Sep 2023 04:38:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3Ii3 (ORCPT ); Sat, 30 Sep 2023 04:38:29 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE9D195; Sat, 30 Sep 2023 01:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LC0IQF45kD2+8gSUvXpx9WSr8J0j8wO9UYEi/vCObsQvKurL+n3XjjCcfjMn56qCoad/w5u2cYLYFn2HJEomB1dyoprrQk4S5brxjfL9KctYhiuEmP+qqE8tQiHDwSR3kcNeHoiyN/MgLg0hpmcYqwSqx5hVUmcwQg+N8jWx0wlbth4C9MYLRKldqhNYYhFIOYxq+Mkhs9LLykCo2cHKFc2W/FBratJZe++8kL517UK2Dks58GDr0O2XVf1N5RqQR81DSTvfDZu8gx+/925Dv4HudOGdbrkNnb4cN0rc+dd9LVJfSwtr2r+L7gFhecWrk8LS1WKKY1vCez3R4ztfqw== 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=OXZ9nu8zgiI8fl1PVckWCMbLtSVwz8sApT+QImD2RRw=; b=kTiyt7IfEYgilqdtXkzooJB60JjBrGG6I7jPBptapo0SpQISqyzmwcTCm700YOVQ68cZnfNJstS41hW3swSrTGs4QisGWBU7xG2FUM2K1Lo/ds+sAo4XPm62fAK0QWSqaUzhHJod3deUm/asg0/WSvfNS6B6ZBZdnx0E9RxzJyKrWvMi7iUayDZJ/tWM7bTNKcWClJvoJNQ96UtigTX2Cc0Bc45QcKP0MraN96hw1k/RmTso5bnudHRLW4ZgzUJKX34GoTZAW8JBcL5DNtwDRkzRJvKdaokhIEp7ClKHlRV0gZxd1SuZcsotTCZnkDJegVFfX3kXC2pBper3om5Nuw== 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=OXZ9nu8zgiI8fl1PVckWCMbLtSVwz8sApT+QImD2RRw=; b=RHt6F8H9t9yBsntip9OssB3NTHYBK4bl87N3SjJ9Jfw0VbQCobL59FTeYb65Hc2wJQ5lmGtO4bpDpik070uWaptlROhSfZgiiJgUdYGl5QDlwjC2pJt2j9fvtWRZ8/cuiMUVtN7MEU5vwHcPFmW8XdQchWtQ+t/YiXRJuZhr5CE= Received: from MN2PR14CA0010.namprd14.prod.outlook.com (2603:10b6:208:23e::15) by CY5PR12MB6058.namprd12.prod.outlook.com (2603:10b6:930:2d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Sat, 30 Sep 2023 08:38:24 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:23e:cafe::4) by MN2PR14CA0010.outlook.office365.com (2603:10b6:208:23e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28 via Frontend Transport; Sat, 30 Sep 2023 08:38:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:24 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:38:19 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 02/16] platform/x86/amd/pmf: Add support PMF-TA interaction Date: Sat, 30 Sep 2023 14:07:01 +0530 Message-ID: <20230930083715.2050863-3-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB72:EE_|CY5PR12MB6058:EE_ X-MS-Office365-Filtering-Correlation-Id: eb861e27-769a-4e69-b218-08dbc1909c16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C125aaqOmUBFhBqcUF8MLCPiE9Lqe2PvVbc0WUwR9/ZsTDQBI3DEl0yZmUnRLeCppwesl8WpVkAFmyh5xDrIugr7RiNNU2IAzAM1E1ebqLbdXbocSe+j5fB+jDQjVybiZoWRV6kdwR/JPlaAFBKvLrPEbBMPHVUFJ/4N7pNoyD61f6d8tE8h1W4SLeKQuK618M89fKnVMQf50PEo57/An4B/lJj61EAT4yJLrjkfhUMJEzVgkUKksWO6IHzmgrcm5uArdXDYkVEvcMuy94MZtn5hmSAJcGU6bvE1T8J79GSwq5JLorgBhTHEilnOvPt/Yhf+UnNzvahVDBDZMq79di66hd9VaxtWozj3ldAze9o+NDbnJWUq5+G4jW5Kwj8U37X6kvetHIqJUA4MCq7kfg1LbZh0eHDkSVilUqIBEzsNZidWvveUO/j+tG6wnomuL3kXni0oEWnc3q2Hgcsk2KSwiUwN5h9WtY73/DV9Mopzd0Ox9Et61ro6q7Xofsi+kRRyigp2w7XJ+yKzfP/ZDo8TqGzNP1yOxvj7GHXsNigZMzfAkXzAQM0hcFzXTtZQeR0Tqa0+7MQ/t/8z2CG1VDaek6ZJyrQdqIdHwVOCtYp4qJi6bsDPCaCsJcHZSZ9uVbAiyDj1ykks1PBgCmwAFO15FjDdL1YEmciuRmW95RUD/znSTCtNE0A713awkIOgoLYS8SpRTraZEixqCnvpaxlH1fEIyr9kIfQSD7Alod5PIgQK2KECVLn787wYYMx6QCutd89AJOa7e/pYW0znj+heETcrqxbjhIYpequDI40= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(186009)(82310400011)(64100799003)(451199024)(1800799009)(36840700001)(46966006)(40470700004)(81166007)(86362001)(82740400003)(921005)(356005)(40460700003)(40480700001)(36756003)(478600001)(70206006)(54906003)(2616005)(7696005)(6666004)(7416002)(70586007)(8936002)(5660300002)(316002)(8676002)(4326008)(83380400001)(2906002)(41300700001)(47076005)(110136005)(16526019)(36860700001)(26005)(1076003)(336012)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:24.0772 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb861e27-769a-4e69-b218-08dbc1909c16 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: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6058 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..e0837799f521 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 4db80ca59a11..1b3985cd7c08 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, "TEE enact cmd failed. err: %x, ret:%x\n", 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, "Failed to get TEE context\n"); + 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, "Failed to invoke TEE init cmd. err: %x, ret:%x\n", 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; @@ -103,10 +190,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 Sat Sep 30 08:37:02 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: 13405052 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 7EDFDE77364 for ; Sat, 30 Sep 2023 08:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234115AbjI3Iis (ORCPT ); Sat, 30 Sep 2023 04:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3Iis (ORCPT ); Sat, 30 Sep 2023 04:38:48 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12041A7; Sat, 30 Sep 2023 01:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kkYuGxU2iO/vstOvW6/B34lptZ3K0AiPPomLZlAsPhivpnDUNCOM7TqpBunR98SfDFj64IPVX6AhNp43LZqOe/AfAyF9VHRb0K7vQdLA8/Oys0HBKpO585H3WsNDxQW3LXqZb3OHoemedo55kY3/VP/BwQwmbtWXxAfEgoSbx9/DVS3icc+LCUtqRUylmD5w+Lc9bqoFMcmpi8AAaoX/xWQMJGy1zr2wmmokOLMRa4DvCESqfica6z3PDGKZ/u48uT2DhBfJlGPIx7vdWHjkmN2kfPeCgGhU9/EwzTwK8Lh6RqmeNw6vJnIScuNYQuuMXSTYeHzVXX2Bq80OSxit/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BvhjcAd2wSHKmqwA7A5y4WG7DJ3FKJLdP71xUzcOvjs=; b=ch957cGblvvQJFn0zH5ZKBTF5mevtiQlG6fKnofzH2ZLqQP71pbwzvnhk0qPz6POhvSJRtpkiyjk2NsUs+/yqVyr4ilb11fCjm8dVgLfclJRx2KtlZscEa+6mtp5U7hvH59l2OYUxAJ7OGABwHXx3t0QMFBCnLq2bOK6rmacmD4ANKbSwOcqBI2gwvjUBU8Mfyt2Ree63EPfS/H2X7StjOYSZF8wm72/2cxqrcrDP3M1uSE+NgNYuEZ2nHUFeb7qegyVbahXtedv3j0DjwH4egBFCZUbcT6qL4LPykgMuoobzmzbzpwsN+XuFNJV86BcIJRrgbIDIOVL0s9yDKpOwA== 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=BvhjcAd2wSHKmqwA7A5y4WG7DJ3FKJLdP71xUzcOvjs=; b=HvYE+dnJjo+UHmqvd7kh5MHsHEkyavpoLm50jlsBDQjFaet4lXNOdLui9QSY8Fq29pn29m0ypciqIqiS4B0hvSrfCpjz/6iabYLCrGnEcgbtxufg5WI+cmBmhyJuPY8YcoU4hlw5yKJn51bR27JqIm3MmlBy2aA/gGGg3oVI78c= Received: from MN2PR14CA0006.namprd14.prod.outlook.com (2603:10b6:208:23e::11) by LV2PR12MB5845.namprd12.prod.outlook.com (2603:10b6:408:176::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Sat, 30 Sep 2023 08:38:40 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:23e:cafe::18) by MN2PR14CA0006.outlook.office365.com (2603:10b6:208:23e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.27 via Frontend Transport; Sat, 30 Sep 2023 08:38:40 +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 BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:40 +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; Sat, 30 Sep 2023 03:38:24 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 03/16] platform/x86/amd/pmf: Change return type of amd_pmf_set_dram_addr() Date: Sat, 30 Sep 2023 14:07:02 +0530 Message-ID: <20230930083715.2050863-4-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB72:EE_|LV2PR12MB5845:EE_ X-MS-Office365-Filtering-Correlation-Id: 00ec4784-4c28-449d-98f9-08dbc190a5e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r2ljVX/qlx/ojhvolFqpz7xB2OgMYNwEeUKoCUfp6qxZ+4+In6J4CWrk+FtUBGDW6Lz6XdIhgorcIwaMcM3x22/Flav03AS0SQNy39Vf6qQxt7VeledLGq/MWhdK5vJXwHhP1/ASIALzMSzArJJE5H4i9NlSaTaanGR8nvTE0xiOQ/RIj290xiR8B+4IrKDngOHTbpKFipNk11Gxoh1zksQ7CwmHz2J8GAbteW3r6zyvrwoUG8hR2//h/0Hp/jHaqxXoFOFBYpM6xXVyUPNUQby7n5ZetgMwyZcfFe/oNbLjeNokthWSgGLK9PbRBnjMI+9Mr7SUecPjre9XMNghNaA3naZ3tZ7iIQqqHMQYr1JrD1rLJLJ39OXxh7FJA221PqOP/9eDTnqY48cGBgweG3wrMVqD3hiIs54eF7tPOe6ZVxC1JA577QvflBGMa0Di65E/D8WI/MpseAcfrGaxV/c1EX87MieNbFKI6vHgSDWua0CfzDOJhLjdelrapYO9Wxm7Nt28gkFEvdgRaOnYLshyG7ESICuWrKjiXwn/icPbSxX4vgJDu8nWogWrFmrpewwBmm4s+04ho7ulgXA3WlH+XDwMgP0jZb6mSI96okgsiNd9r6rnZw9gLEwwsz0C+t9FBy3IFnYx2RgsaPwx3HuQav/wBsIgux1nl0QHeRrFEtkIvgCAcn2qhy/yvEFLGV8wlPRZpds2aaXdfB5AZBlfqY12tBrunxiCXjX7M5pITJbesVcLhVy7dr1L16o3pOOIIyzQ31ghOWLvfXJo+7zuBGIkf9Nq4tR92Seg5oA= 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)(136003)(396003)(346002)(230922051799003)(186009)(1800799009)(82310400011)(64100799003)(451199024)(46966006)(36840700001)(40470700004)(40460700003)(40480700001)(47076005)(7416002)(26005)(2616005)(110136005)(36756003)(2906002)(86362001)(8676002)(1076003)(336012)(4326008)(81166007)(41300700001)(8936002)(316002)(478600001)(5660300002)(70586007)(70206006)(426003)(16526019)(54906003)(36860700001)(356005)(921005)(6666004)(7696005)(82740400003)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:40.5458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00ec4784-4c28-449d-98f9-08dbc190a5e7 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: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5845 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org In the current code, the metrics table information was required only for auto-mode or CnQF at a given time. Hence keeping the return type of amd_pmf_set_dram_addr() as static made sense. But with the addition of Smart PC builder feature, the metrics table information has to be shared by the Smart PC also and this feature resides outside of core.c. To make amd_pmf_set_dram_addr() visible outside of core.c make it as a non-static function and move the allocation of memory for metrics table from amd_pmf_init_metrics_table() to amd_pmf_set_dram_addr() as amd_pmf_set_dram_addr() is the common function to set the DRAM address. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/core.c | 26 ++++++++++++++++++-------- drivers/platform/x86/amd/pmf/pmf.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 68f1389dda3e..678dce4fea08 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -251,29 +251,35 @@ static const struct pci_device_id pmf_pci_ids[] = { { } }; -static void amd_pmf_set_dram_addr(struct amd_pmf_dev *dev) +int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev) { u64 phys_addr; u32 hi, low; + /* Get Metrics Table Address */ + dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL); + if (!dev->buf) + return -ENOMEM; + phys_addr = virt_to_phys(dev->buf); hi = phys_addr >> 32; low = phys_addr & GENMASK(31, 0); amd_pmf_send_cmd(dev, SET_DRAM_ADDR_HIGH, 0, hi, NULL); amd_pmf_send_cmd(dev, SET_DRAM_ADDR_LOW, 0, low, NULL); + + return 0; } int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev) { - /* Get Metrics Table Address */ - dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL); - if (!dev->buf) - return -ENOMEM; + int ret; INIT_DELAYED_WORK(&dev->work_buffer, amd_pmf_get_metrics); - amd_pmf_set_dram_addr(dev); + ret = amd_pmf_set_dram_addr(dev); + if (ret) + return ret; /* * Start collecting the metrics data after a small delay @@ -287,9 +293,13 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev) static int amd_pmf_resume_handler(struct device *dev) { struct amd_pmf_dev *pdev = dev_get_drvdata(dev); + int ret; - if (pdev->buf) - amd_pmf_set_dram_addr(pdev); + if (pdev->buf) { + ret = amd_pmf_set_dram_addr(pdev); + if (ret) + return ret; + } return 0; } diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index e0837799f521..3930b8ed8333 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 Sat Sep 30 08:37:03 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: 13405053 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 5C1E2E77362 for ; Sat, 30 Sep 2023 08:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232620AbjI3Iix (ORCPT ); Sat, 30 Sep 2023 04:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3Iix (ORCPT ); Sat, 30 Sep 2023 04:38:53 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2050.outbound.protection.outlook.com [40.107.96.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865C61A4; Sat, 30 Sep 2023 01:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9MUZWk4d+KFSxrVJv+XiQu/gbCISU0W5+CgGgGwjgKeb+waGuhlXLx9T25LbdbE9+Md+WZ9fJBMFkaT2X8cexe5fU/tDXGjPtzCgQthQ2RQumoGkCamB3/02Z897Dgi8i0F7T/YGxlLt1TjJoxKTjFy9Anj70dtYPP+taQO299jCyox1KB/m2oKX+1+F+XrQNXtZsTzBYcOC1KK7xK0ekrW8Gx9H2kuHNkmhmLCDAwwWEdQKJ1245xpkc4oVSDFDZN4AebufdxTvgNKDWPpeTBk6e74gEw1TJdpYCluRJGyPA/tTx/EBAt+qabRLDpEdaMlpbYoEhdHyIrvpVgLSg== 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=9Z6RatZiakEQom+JeqPcbTDXRmBQFd1wd5wdoqofpvs=; b=XeohVsFtWnJj3JqjTm7stHiGbu45u9vgPUfMp2wSt0PS3sDHc/tasf2lh/uzLVopDz5dbyBn9porPUTop8N1tPkhH/jp8vPQRPGOogjwO1NSPyq9fLbYAATHfqK91Cdyqg8QrCBfS54AHzyLSm5XwxyElbzlKSetMSWdVho25ilrmdV6nvOMd1+Mu8kZp2/nbPQISUTf4mPVh6UrPTEBS8WcS6+mJt1qi7l1Hb/wUT6As2K9dZqKhg650V1w1U3vHedv79v7KUFKRlcXZZHCuxVCkNzMNyKN7xv46rV1nrcOrR/5N9Ag2f2acuz8M6IkoLsbm+oMktTGBGBViBjaPg== 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=9Z6RatZiakEQom+JeqPcbTDXRmBQFd1wd5wdoqofpvs=; b=HnYtzkRF8sT5lORx9wF8gLdMfijs9h5E1j92UBK7PnHf0DgIJfU8H8S1/ocFtlgcaA4TlATwFUB1SjtbICPUQ/akROWaC+fQyi3IqGqQy6nRPdTVqGMCQx8W7MdBc9pHUeBedETMKYfepNjXacRWitEy4BDemVMqClAkpM/7cqg= Received: from MN2PR14CA0005.namprd14.prod.outlook.com (2603:10b6:208:23e::10) by PH7PR12MB5903.namprd12.prod.outlook.com (2603:10b6:510:1d7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26; Sat, 30 Sep 2023 08:38:45 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:23e:cafe::53) by MN2PR14CA0005.outlook.office365.com (2603:10b6:208:23e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28 via Frontend Transport; Sat, 30 Sep 2023 08:38:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:45 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:38:40 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 04/16] platform/x86/amd/pmf: Add support for PMF Policy Binary Date: Sat, 30 Sep 2023 14:07:03 +0530 Message-ID: <20230930083715.2050863-5-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB72:EE_|PH7PR12MB5903:EE_ X-MS-Office365-Filtering-Correlation-Id: 5681f9d4-2e59-4866-c40b-08dbc190a8be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m0yTfoA/Mpyvwam6W/OjFjS9NQ4s7h6eahB4ibvvm6itvXP4WH+lv89U8FHS3MXKFYmFIriQ9/Q2Oo8eBBZlopXIeVgl5Y0eX68g8IuPuQgawLwcMJtMxWwLWB2968zx+ykWweFhhRo/OQQ0Vpc97EgqDUhkdhAK7MwpNJrNLFA7yDKlQbIvg9sPSVqMLas1ZIFXy7dUoy9VfplNSJSCnq8GpnTy8YNL3RuLLHt7q3KgS5u7wZHpE0LrKndzPcF6TitmddPIL0F1oX1ePCVS4jXB+hsEF1O3IWcIybyd5QWJj5dSaOeK0xDNDWo2Xh5Ajbva11qs7y9U6adM8oT7e6+7hQ8+7EInPqoowIdbyhL87u/MtOYP+QuP7Zpe/Wa1/2aSx9DSOwLa65rWSkzS9JvimkxTQOihMJ02bOnE/FG9oiV0uXe0zjmGgkSrBT0+ZQhM/70ZmWOfTcTZ9VmJiJgoEO3D2XwT20Jf0q1TQz/ponTIaWn8gLGhZBttAaqrzbRlZI3hBe95lvh7blSqyhLjGhy0ziDvEyPu2Mb25j772WfAQDGFueHgSReuo+b7ZPD/bDkPTrvUc9w6Ew0KrHbqhvnfKFcXUh58r7FVb+HgLKXkTN+xUBmCyhAeOSZ31IbAFTvQYo21tDotu349BNpHLff1dBVzThGLqFYhu3nrQp7d+na6NQGw5Tfl4i2oU2FvkOM35vjdgli9VR9uu3z+6w6GVQ1CWuLELSfH4Vrp2InEjonpPKz1rMIGy5czGHGS9A6xNjWy7eTUwDrM9fW60p/CC+5HKABTr3VHu28= 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)(136003)(39860400002)(376002)(396003)(230922051799003)(82310400011)(64100799003)(186009)(1800799009)(451199024)(46966006)(40470700004)(36840700001)(2616005)(7696005)(6666004)(478600001)(54906003)(47076005)(83380400001)(30864003)(2906002)(7416002)(316002)(70206006)(5660300002)(70586007)(426003)(41300700001)(8936002)(336012)(110136005)(8676002)(26005)(4326008)(40460700003)(1076003)(36756003)(16526019)(36860700001)(356005)(86362001)(921005)(40480700001)(82740400003)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:45.3114 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5681f9d4-2e59-4866-c40b-08dbc190a8be 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: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5903 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 | 135 ++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 141 +++++++++++++++++++++++++- 5 files changed, 324 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 678dce4fea08..787f25511191 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -384,6 +384,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 3930b8ed8333..6f4b6f4ecee4 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -14,6 +14,11 @@ #include #include +#define POLICY_BUF_MAX_SZ 0x4b000 +#define POLICY_SIGN_COOKIE 0x31535024 +#define POLICY_COOKIE_OFFSET 0x10 +#define POLICY_COOKIE_LEN 0x14 + /* APMF Functions */ #define APMF_FUNC_VERIFY_INTERFACE 0 #define APMF_FUNC_GET_SYS_PARAMS 1 @@ -59,8 +64,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 +200,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 +421,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 +594,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 1b3985cd7c08..15aa6e6e1050 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) +{ + unsigned long 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 : %lu\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 : %lu\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 : %lu\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 : %lu\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 : %lu\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 : %lu\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 : %lu\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:%u result:%x\n", out->actions_count, + ta_sm->pmf_result); + amd_pmf_apply_policies(dev, out); + } + return 0; } @@ -72,6 +149,7 @@ static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) { struct ta_pmf_shared_memory *ta_sm = NULL; struct tee_param param[MAX_TEE_PARAM]; + struct ta_pmf_init_table *in = NULL; struct tee_ioctl_invoke_arg arg; int ret = 0; @@ -80,10 +158,20 @@ static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) return -ENODEV; } + dev_dbg(dev->dev, "Policy Binary size: %u bytes\n", dev->policy_sz); + memset(dev->shbuf, 0, dev->policy_sz); ta_sm = (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 + POLICY_COOKIE_OFFSET); + length = readl(dev->policy_buf + POLICY_COOKIE_LEN); + + if (cookie != POLICY_SIGN_COOKIE || !length) + return -EINVAL; + + /* update the actual length */ + dev->policy_sz = length + 512; + res = amd_pmf_invoke_cmd_init(dev); + if (res == TA_PMF_TYPE_SUCCESS) { + /* now its safe to announce that smart pc is enabled */ + dev->smart_pc_enabled = 1; + schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms * 3)); + } else { + dev_err(dev->dev, "ta invoke cmd init failed err: %x\n", res); + return res; + } + + return 0; +} + +static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) +{ + dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); + if (!dev->policy_buf) + return -ENOMEM; + + dev->policy_base = devm_ioremap(dev->dev, dev->policy_addr, dev->policy_sz); + if (!dev->policy_base) + return -ENOMEM; + + memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); + + return amd_pmf_start_policy_engine(dev); +} + static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const void *data) { return ver->impl_id == TEE_IMPL_ID_AMDTEE; @@ -148,7 +277,7 @@ static int amd_pmf_tee_init(struct amd_pmf_dev *dev) goto out_ctx; } - size = sizeof(struct ta_pmf_shared_memory); + size = sizeof(struct ta_pmf_shared_memory) + dev->policy_sz; dev->fw_shm_pool = tee_shm_alloc_kernel_buf(dev->tee_ctx, size); if (IS_ERR(dev->fw_shm_pool)) { dev_err(dev->dev, "Failed to alloc TEE shared memory\n"); @@ -197,11 +326,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 Sat Sep 30 08:37:04 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: 13405054 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 31415E77362 for ; Sat, 30 Sep 2023 08:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234167AbjI3Ii6 (ORCPT ); Sat, 30 Sep 2023 04:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3Ii5 (ORCPT ); Sat, 30 Sep 2023 04:38:57 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2064.outbound.protection.outlook.com [40.107.223.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF731A5; Sat, 30 Sep 2023 01:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCczof1kQ4EJz0chhKt8FZJ3mqt4Tztffi7WsJ1yELhTjdzJpohfqej17SO4rHAZeMaRhtjelM6eC2i8K3uLUD9JPiFh/LmWWSAz/2pvasndEjoG3dLxa7V1qLRtar1GR5zsWHpzfWmW5x1I2epOSBUUNJfbmAeE2BuGRKC3zIB14nxE5x5yBW10Z9afpB4gFhyTaK4fwrH+IACDEgijXN+q2PgzLhWAtQVVSFAYTpbmiRYDMaAmGc7lS19R+nz1Y0R/KlunBBBWXY57OpnF9KpEn/Kgxvi4CknApih+erkJZ9tNJ622UYpQMUQmdCSQnZemLOS8MualGsDWtlA6HQ== 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=3qZsydZKHbXMZHeYccoWih7jFXNn3p6Li7qH7v1jYHs=; b=hoK79b6OBUvtfL/RVJ7KD0IpgqJvs/O0CYzr50kiNFAZnjBi3PZX/VZDC8JS9Pho7ZHvWqErZehKHD0Sp8nzr8FySoEz2UUtkioxQi2iNMh0PET+cVFdP8RVhycGeo81xf6OVJmHUkGZeZg3FEJlahCBaI1YAhwjHoQBMY2JXgrlw/HEoHoMvohp3kkUryeXp9lyhdmjdbQ7sFUr7Dcz4ZhrIRnOnnS7E85WmFxxVzlGV8e46qv016BToJS6K11+sGF3ltGmi/qb1FEDeLqr43L0GHmKbkJgoVocvU9BHWORPmH23jgfEMZjbQIOCeVfMtRi7EBEStdMHuL3b1Cf9A== 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=3qZsydZKHbXMZHeYccoWih7jFXNn3p6Li7qH7v1jYHs=; b=CKH6FTt44TzfnMW7QCq2n9pDM9hWUg7OnFByflCIQ9o+CpPTXTrE9w4lxvkI/Q9O7DLyUYt0Ym7GPz+rAVaJSd1Dh953aGs+v8UrwcCPKlJqOqh82UTsiodvgUFUDJAXUkG4fZBdiPxRviHfCB+th1E2DIIPQJ3L55IUOCcXK18= Received: from MN2PR07CA0009.namprd07.prod.outlook.com (2603:10b6:208:1a0::19) by DS0PR12MB8218.namprd12.prod.outlook.com (2603:10b6:8:f2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26; Sat, 30 Sep 2023 08:38:50 +0000 Received: from BL6PEPF0001AB71.namprd02.prod.outlook.com (2603:10b6:208:1a0:cafe::71) by MN2PR07CA0009.outlook.office365.com (2603:10b6:208:1a0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.29 via Frontend Transport; Sat, 30 Sep 2023 08:38:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB71.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:50 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:38:45 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 05/16] platform/x86/amd/pmf: change amd_pmf_init_features() call sequence Date: Sat, 30 Sep 2023 14:07:04 +0530 Message-ID: <20230930083715.2050863-6-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB71:EE_|DS0PR12MB8218:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a409e8a-bd2b-464a-9c22-08dbc190ab9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0fleaQFW0oGjaipTYjqFaoLcRXR2+Xs7SYSGaHmeN/cVm/EdKMtFP1L7ZC0zQ5dWdPjr1W1INk+6bylThC/IAKcm10fiPa3Zeb8aE8VlllXO3Gkizb4WZJZkEEeX0Hn04Fg3jH27+4JTbKT4Cy9UB+Xdwe+XOftvLiGwTNM5qbKQmDj2Gw4VukKhpDcQONvR/rxYp578fIGTeUgfzcS13Pgj3exSeB1a6/rpNe2/UdHWGxTGo/APh+kK3CgeK1wEtdTpxmE0iFpfTIs3Z0msKZ0xkc7MoOl3FHXNagSsbl4cYcC4396C9Pn2LSeruCIQi6n3oqxeG3sM3rFqWsTSoS7NZGecmmoMqsZCMwT2lifzcAPCukfk21VEZS6uQwIvKeFJ2xUOsvMWGAu+mLyWZMo2uWEKrRAi2ZFBi4HRUGgRtWni/vTaJn9itGSQOzligEAlpNz5ziQ9nO+7Q6podhBCN8AoerH3Tw98iWWxrEzkbFrdG2Ald8X/IIOhWyH8YYb5FCIfZIs+SJJExuxMVykUrDm5BgfduVt0LFlpVZ1HrPkG2zIuRRPKVZRE/CHC3LzAxH9UEM/SoejNT7uSIS/CzlWCJGyD3edqqS0lw1rRakyXALrQNaRVRcufAtB3cigB8hc3rBnj1IqbT4a+/L1X/+fYMp4uMpC6SPiSa1QikGCJS5crfNfx4/8VsCgYYsbGmqB4BUErdr13pdTHeWfyYeO3ahZehzAwaMK+RCS2YweSnkY2qau2sc2omQzS5kYbhdgeo2DdHXkAuwTd5mzJS+xgAQmwf2ggqEzAR68= 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)(396003)(39860400002)(376002)(136003)(230922051799003)(186009)(1800799009)(82310400011)(451199024)(64100799003)(46966006)(36840700001)(40470700004)(40480700001)(40460700003)(8936002)(82740400003)(36756003)(6666004)(2616005)(921005)(26005)(356005)(81166007)(1076003)(41300700001)(70206006)(86362001)(316002)(70586007)(54906003)(110136005)(2906002)(5660300002)(336012)(426003)(47076005)(83380400001)(16526019)(7416002)(4326008)(8676002)(36860700001)(7696005)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:50.1298 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a409e8a-bd2b-464a-9c22-08dbc190ab9b 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: BL6PEPF0001AB71.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8218 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org To sideload pmf policy binaries, the Smart PC Solution Builder provides a debugfs file called "update_policy"; that gets created under a new debugfs directory called "pb" and this new directory has to be associated with existing parent directory for PMF driver called "amd_pmf". In the current code structure, amd_pmf_dbgfs_register() is called after amd_pmf_init_features(). This will not help when the Smart PC builder feature has to be assoicated to the parent directory. Hence change the order of amd_pmf_dbgfs_register() and call it before amd_pmf_init_features() so that when the Smart PC init happens, it has the parent debugfs directory to get itself hooked. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c index 787f25511191..39671d245e96 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -435,9 +435,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 Sat Sep 30 08:37:05 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: 13405055 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 3A295E77364 for ; Sat, 30 Sep 2023 08:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234173AbjI3IjD (ORCPT ); Sat, 30 Sep 2023 04:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3IjC (ORCPT ); Sat, 30 Sep 2023 04:39:02 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2059.outbound.protection.outlook.com [40.107.220.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F731A4; Sat, 30 Sep 2023 01:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EXvcJ64eq631GDcl1Q4Xo37c1P3uG20+50ivJi7wjD+kUCXG+kA7sDnVcwGUoWo5JBMtFwVo8AtIBBvsgw+pZ6ZxG1JEJk9oi9/A2vbTksg4cLkAfyODBHde25D2pWIuPJ+BCyNJDpcsQ/6eK3Y7EZZfDG8X4Ae7O5vFnedoC17Oh+FxZ2fpiMC0blusOPuXTJcDaUsi5F2ohzHoyC+hGHuguvWi4JHsX18cNIsInCdZxzEvMgVSclQHmishG5tpN6jJ/t6eORdGjXUN6P4qP7P3m11HCWg7u89JUxhtUxztS0RxAweifHx9McduYqIUMTfUU5iNxOb9z7FFUb49hA== 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=xLMuNx6brx9mbSEehP0Y+y1Oj2nURm3RJRcrXHPERUc=; b=ZLoeVqN+dB+81SvgoxR7fXGgz9GEWgB1JKNpOjF5bx5XIVnqdVRMnNDWLO3m1JOI60eEj0VScQjjWvISNLKcCo0zuQSagwlM08gitCuLt6FPiCxDCGYFiLzsb4fJfCX2Nkh/pRXMCauIkNpr+mgiJYMMZuhDwYnKQKJ+kTAQacKuBmVQ7qxaK4fb/XhZplp3p5Ud3FzrKxKCkPo1TTlBGyHwZ5dYG86MKHsOoeRIs6NBgo/KsmHmejpY8sSOdrESBmKN6IFAiYI0AnnqSLZg2aVMwNuZf+YkAnhCeCD2W0EF7urOYY3xmlpZO0LyigO2JD5Sg4btpAZeLanRO6nnJA== 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=xLMuNx6brx9mbSEehP0Y+y1Oj2nURm3RJRcrXHPERUc=; b=1QKilUA/Z8WG34jk+4EQWYVv5VcyNe9HdGV/nM7p5d9Wx5YjXA3AucWHMiXd4a6KFTKN4lRUWTt2mlUWYfb4CMAq4XycCfXnfMDRWyfCHu7OWLshnhEYWLWSEtnRWlcm9XO0mE448vxrKc9duuQ2B1iqDoujLt9G/dLsREoLWOk= Received: from MN2PR14CA0011.namprd14.prod.outlook.com (2603:10b6:208:23e::16) by DM4PR12MB5343.namprd12.prod.outlook.com (2603:10b6:5:389::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26; Sat, 30 Sep 2023 08:38:55 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:23e:cafe::99) by MN2PR14CA0011.outlook.office365.com (2603:10b6:208:23e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28 via Frontend Transport; Sat, 30 Sep 2023 08:38:54 +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 BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:38:54 +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; Sat, 30 Sep 2023 03:38:50 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 06/16] platform/x86/amd/pmf: Add support to get inputs from other subsystems Date: Sat, 30 Sep 2023 14:07:05 +0530 Message-ID: <20230930083715.2050863-7-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB72:EE_|DM4PR12MB5343:EE_ X-MS-Office365-Filtering-Correlation-Id: 146e361b-c726-4aa2-05ff-08dbc190ae79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5AJ4uZBXV3RTJSNFF3l+bDxi4t7iZzvgjYxpLc++3xHgTyby+ZcSGBbtSU47wBs+WlF3xmgKbgP+vXxrtgVvDv067vvBWvtvx2Bq7A8zYhbhFZt8RPfgbX3s/iASRcgbqjMcMYaFqncKGAnpAHh4KheYIIUOhhJx6h//ogU1voy57sY4zWr2JBN/NYCjOB0vaw72PXW6L24Q5BEejcLyugyWSaRC6+8Lttebn+ypLrWuduGnmsMQ4WhCFInzsgPmk5YEgao3zOZ+Ng1td88aNzFD5HafKAadOsnUUEqkM2uspOZ3Nn1eLFUUcr/6pzUO0mKaRJN14L5zEKNF4PhxcRlxJGfIZTt0ank26fmkSIiBX0/hYIPvff3jVhgQsGmo6EMd8VK5+wMI4TgEEo7roafF9zsu8VTwlsWlQYU+nmugFskUoKW7amEsna51kp8Uku9nr0m2rx+lrJotHoHI4VeXoZuUIPUWRZoZtO2OEQor0/0YrBleTu5192E0pA2yXNRbvRUol8fgNUB3RW9SDEa6s0O8SMNG2v7EvetSM8iulhXXo4pdfw8mMY65x+g6CiO/2lKw40SAENyiCbQPupxLSKHsbIlD0gwhZR0MnaQItnOMNC8klVeH8JO3R2cl65EOcQanq88zANDTLCsMqYWQWCowB5528V7z/nvQn6SUYaJVWTv7uJTXAuGVcyokQgVv1bG0Xje+yQjATMQjaoLvGcfFNG2geZSbxGhKc+2qKgdEo5FWmgQdgUAszNYRUuOWTJzKPM8RwE7Y20262rTPrCQAnEUMu0pvEggfZ08= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(39860400002)(346002)(136003)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(7696005)(2616005)(40460700003)(86362001)(36756003)(921005)(356005)(81166007)(82740400003)(40480700001)(36860700001)(1076003)(336012)(426003)(2906002)(478600001)(47076005)(6666004)(83380400001)(7416002)(8936002)(4326008)(26005)(8676002)(16526019)(41300700001)(316002)(70586007)(5660300002)(110136005)(70206006)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:38:54.8269 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 146e361b-c726-4aa2-05ff-08dbc190ae79 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: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5343 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 | 119 ++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/tee-if.c | 3 + 4 files changed, 141 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 6f4b6f4ecee4..60b11455dadf 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -149,6 +149,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 { @@ -595,4 +610,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..3113bde051d9 --- /dev/null +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD Platform Management Framework Driver - Smart PC Capabilities + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Authors: Shyam Sundar S K + * Patil Rajesh Reddy + */ + +#include +#include +#include +#include "pmf.h" + +static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + u16 max, avg = 0; + int i; + + memset(dev->buf, 0, sizeof(dev->m_table)); + amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, 0, 7, NULL); + memcpy(&dev->m_table, dev->buf, sizeof(dev->m_table)); + + in->ev_info.socket_power = dev->m_table.apu_power + dev->m_table.dgpu_power; + in->ev_info.skin_temperature = dev->m_table.skin_temp; + + /* get the avg 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) / MILLI; + in->ev_info.full_charge_capacity = get_battery_prop(POWER_SUPPLY_PROP_ENERGY_FULL) / MILLI; + in->ev_info.drain_rate = get_battery_prop(POWER_SUPPLY_PROP_POWER_NOW) / MILLI; + + 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 15aa6e6e1050..1fc3b57f8d78 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 Sat Sep 30 08:37:06 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: 13405056 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 E5BC9E77362 for ; Sat, 30 Sep 2023 08:39:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234176AbjI3IjH (ORCPT ); Sat, 30 Sep 2023 04:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3IjG (ORCPT ); Sat, 30 Sep 2023 04:39:06 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2052.outbound.protection.outlook.com [40.107.220.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D7571A5; Sat, 30 Sep 2023 01:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E9/W6sw81qYa3117UdvuGsNPusXqVT/EAxhiUdPy+B8lH+yX3MspeLb7NpZ4Iqq5oYcFWuu8yRjXyzQLjLSyoDF9iygsEeJFdBPCWNgyx0DxjiEn9qw6n1HaHzLm1v88aldtXj27/vGqe+Q64KJdt9ysRma1bJgJ+S68SL51x7rJtBr7RIKcsnVROR3wKWLGj+9/x2ZzKj1iiK2k6NYXDJZkzQrZ1m5vIfNElRa9YMaIboo7SpLvFsIj0oilWYhndThPhkRRXj5JaYUFMvNNQBPLbbo1yZ588b6nzju5cntbpvbSb/1KInlkJ1vKvVPKgD4BDxnBhFq5pIJHqB16ug== 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=wHleaaHMIsPOooV+w8qEmjplzoizISPCEQ3zTMDBSSg=; b=Dn77QWjf5qh3RBCaQ6stlTlL/ze4wkQMsRUKjQ+yzXTpxgapD4n+JYiixjloC0UNs2zj2a94CWTjixa0w/OxISM7XJltUPSn8nsREQ1WNVxuoFAJX2tgvpvukPXV2EdZE6fuUvFU8n24bllEf23tbiDIpLf15MP4yGy7TienmMg1i5fB7SE+9S1hcKLHJuQF/z5pA2Tqs9enWS6kMnNkUoLy/AyffoRIQ2o61K8ttVXfq8sXsTarUCW0c/Ox17uW/oSQDtziQ5qTERG9/gQgs8mYzc4ueHRYyIPBUcoOglQGojF8EsEaNGA03w75o6MyPihOmf+5dcbMDMhm2o6uXA== 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=wHleaaHMIsPOooV+w8qEmjplzoizISPCEQ3zTMDBSSg=; b=MtMYCFRcFn6l/B+kyFNvktStCoPqLTfBCLMR9Grp6tkCHgjBsU6obHtxHgIOnHHMVPaKDGxwrNEFUXIwolJg7UBx4N070rAi2HhfqHTZFZ4WnAmvlRGMOtW1oqK+blbm6nJYjIVXm1TR5YdJZlizZopAMNy1EkS7NVY3PJCD8GE= Received: from BL1PR13CA0136.namprd13.prod.outlook.com (2603:10b6:208:2bb::21) by PH7PR12MB8156.namprd12.prod.outlook.com (2603:10b6:510:2b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26; Sat, 30 Sep 2023 08:39:01 +0000 Received: from BL6PEPF0001AB77.namprd02.prod.outlook.com (2603:10b6:208:2bb:cafe::32) by BL1PR13CA0136.outlook.office365.com (2603:10b6:208:2bb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.17 via Frontend Transport; Sat, 30 Sep 2023 08:39:00 +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 BL6PEPF0001AB77.mail.protection.outlook.com (10.167.242.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:00 +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; Sat, 30 Sep 2023 03:38:54 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 07/16] platform/x86/amd/pmf: Add support update p3t limit Date: Sat, 30 Sep 2023 14:07:06 +0530 Message-ID: <20230930083715.2050863-8-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB77:EE_|PH7PR12MB8156:EE_ X-MS-Office365-Filtering-Correlation-Id: 200b3e93-6498-4c54-b52a-08dbc190b1d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sd9k0QqXRpZsR20NCFGXRj8ptcf/Vz9wKt7p/5V+g9RMJCwPyRav/RarhFgs8Jm7YYVcKJgLPAvWQgRoaewoDJwr2immhIM3dwBu2sCmMQiPIUaVwGdTyPDP011DEDK++Afv/5xgr00XnHlJ0e5dIhgNVjQ0RzyW+SwGlaQXf3FmYL/JgkttujmW7HH496qkSqazfkspH2adsiSEpyMyva1+rsNBVoVYOLsabMcdh3jzNRBWTaikI8kX7+vnJ/+43s44ONNiL0Az83YggTLsRVQNlgkFUGWJmlR7mMi/9NdayXn/KNgX+aRN160FjaUDBFvg7lB8OeYmJXyLyNSdPTcknVsugMkwuJl+6pSD3hbRMFK7SeO0diQ/9gB8LzSlzwC+oDzYuK4NIr3IZ1a3W7W+uLQx2So+xTku6RfzEsHDf+IyIjNadEsagKbl+Bqx5rRpY/yhNVZ/QVB+hyDAj7rOqk1C6WH6Zy3aRu+AVZUqyvmz765xN1VuXsr2nOcSV6qse5fQjYFXH2koTzLrDC1s0HPk3gWMf7bh2Nq0mKnY3dXm/ad6iw33ZcSRlIm4iUPQkrjhD6/rhFdF382jF1IqO81ot9pWHJ5SyfI4kIQUQ1jDf917/U27BWuhvCSClSNGrI+pviLMlHlLCC2SbfqMF8Jn+t5z+LBR5TghnmnvQG/dI3aQB2aWm1yrdl1wu+osprJWKZsluH2QnYr3YHH++bXLfX155OVeYYI+PfOQKEZZMIBLhemQe1geuga7GnbnM4Avi3JchClAKPLR68wSVrKaSQjKO+f6XJ4Xgx4O9iJTLylHzMuQTkLb0lY8 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)(396003)(346002)(376002)(230922051799003)(64100799003)(1800799009)(82310400011)(186009)(451199024)(40470700004)(46966006)(36840700001)(2906002)(40460700003)(6666004)(1076003)(2616005)(54906003)(110136005)(70586007)(70206006)(7696005)(86362001)(478600001)(83380400001)(47076005)(36860700001)(26005)(336012)(82740400003)(426003)(16526019)(356005)(921005)(81166007)(316002)(15650500001)(36756003)(40480700001)(5660300002)(7416002)(41300700001)(8936002)(8676002)(4326008)(42413004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:00.5481 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 200b3e93-6498-4c54-b52a-08dbc190b1d3 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: BL6PEPF0001AB77.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8156 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 60b11455dadf..d5e410c41e81 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -49,6 +49,7 @@ #define GET_STT_MIN_LIMIT 0x1F #define GET_STT_LIMIT_APU 0x20 #define GET_STT_LIMIT_HS2 0x21 +#define SET_P3T 0x23 /* P3T: Peak Package Power Limit */ /* OS slider update notification */ #define DC_BEST_PERF 0 @@ -72,6 +73,7 @@ #define PMF_POLICY_STT_MIN 6 #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 +#define PMF_POLICY_P3T 38 /* TA macros */ #define PMF_TA_IF_VERSION_MAJOR 1 @@ -475,6 +477,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 1fc3b57f8d78..315e3d2eacdf 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 : %lu\n", val); + dev->prev_data->p3t_limit = val; + } + break; } } } From patchwork Sat Sep 30 08:37:07 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: 13405057 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 F0FE3E77351 for ; Sat, 30 Sep 2023 08:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234178AbjI3IjS (ORCPT ); Sat, 30 Sep 2023 04:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjI3IjR (ORCPT ); Sat, 30 Sep 2023 04:39:17 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2084.outbound.protection.outlook.com [40.107.94.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AFE91AE; Sat, 30 Sep 2023 01:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nrbS0oYyA4KZr7gnmXKVyIKCK9x6TgMtywfiyogYc9ykQb+76F6zjj8pPvqi1rOgefp8NWHn5uPjrbOEiIAF30kEfamGi//jLPvMAZLwW9mTRDl8yRFDjr08L8QhwN39mBgMo1OgLx70Ng8i9xQXL/omZeQVqyW7yfThfcru2d9RszZyb0ROWlJ74WjICojMXSe04LwYL5MYsyFqrsja2L3/6HqV5kOkZxi5mW1NMHGZHxiotPxJzRWcOLL4Xr69c//1muANJhKw17WL7EG0dMcNcl+zHtrYnJUWhw6eNkJC5p/54wPvej5fO+wrgQX/VxQf6Krwykc6KOK6KznhBA== 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=tblJTI+tITqnfmJndsWv0Gsmx/80H7qotc/ZjwtLX1Q=; b=bVD4ubdwXJ68iKIP4D4/WT668hamMMqMUD/Enn45eF67lvpQ7/fzLblEBgO3wymUPCZzBkaDcZveDURf4tTmsax2GCQ/7Q7jNp1zyhmClxYcpxHYNtP8oYR0bIfy0TgXiZjWx0IZbig6xBB7w8P9wO/A1EYQu7kQQ1/oZZW+iTEHF2FCx4rPNGRQ6za6yl1qFiVOVbmSXBCOIW/+BAKwhgmRuz7j4Mk4B2zS/g0LZ7nhFwCuL0JJ0h8ZsY5RlXC8U2nsIZa38fZcUUulgTrPlT1Te9D9tJZS4VnxIuAvstQdjpxYsuQ88g1qrefGy9gyyB+biQEvCmUJuy4iHSOkHA== 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=tblJTI+tITqnfmJndsWv0Gsmx/80H7qotc/ZjwtLX1Q=; b=HLzW2z6s3LcgC/gokU685j3c2grL/QV0Qt03M+a3OsV/a5iqZ2CN8ov/MN6sz6cUlvvUc8iQAjAPtkoLtwWDndF5NNbrJ95SLEYuxNDY33wnqEXvfmScKIJXxdHnDWchCtzscMUdjsP+D4uilksU6kv1jToOL2yszmB+HU5wrKg= Received: from BL1PR13CA0122.namprd13.prod.outlook.com (2603:10b6:208:2bb::7) by SJ0PR12MB5609.namprd12.prod.outlook.com (2603:10b6:a03:42c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.35; Sat, 30 Sep 2023 08:39:05 +0000 Received: from BL6PEPF0001AB77.namprd02.prod.outlook.com (2603:10b6:208:2bb:cafe::ff) by BL1PR13CA0122.outlook.office365.com (2603:10b6:208:2bb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.17 via Frontend Transport; Sat, 30 Sep 2023 08:39: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 BL6PEPF0001AB77.mail.protection.outlook.com (10.167.242.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:04 +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; Sat, 30 Sep 2023 03:38:59 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" , kernel test robot Subject: [PATCH v2 08/16] platform/x86/amd/pmf: Add support to update system state Date: Sat, 30 Sep 2023 14:07:07 +0530 Message-ID: <20230930083715.2050863-9-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB77:EE_|SJ0PR12MB5609:EE_ X-MS-Office365-Filtering-Correlation-Id: c41c7766-a6e1-484a-ab2c-08dbc190b452 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nIO1/XtHx0nu9paDo77rRke2LfBhI5gvY7giGRUWk+VBXa2lJsSnx7fKIB/teMTxAp7tXoURCFgBwq7kYeHqybnGi4UcoC9qmWdKwsIrm7VTfhl2f+2mwhmME1F7bFvk9OF0gAcuu3A8L/vp5AfCJ/JUsdnBwPzAMlx1qpm6WyHnC5rCRxSzfxlrEEMihqK8rZG7xY7oGuQ6NcqSKcDrK++Yh1BwEoOIj3ZnaS6bZdWv9rUZbuVQ+iaRtFZUIMJe6eDr1bEGv5nx1kH/z01fNi9BCm3wHm9j6Js7WgzWErX5D+jdeWrQRV/pOLGYZfQ7d1yqer7CbTjxOCUPpMzNf5K/CU92D0dfMqtVw1NKO6bb06iagEKz9zarN6uyAnnVR8Z5dgCF2OA2Gcs8JrRz7bSgBECkTkV00N5MGMTrBlwipBN/dlAJvGGplFIS+5EQKTqEjImCiaekBxj+RDK1pIDwE0O/9Dz71zd+TByZhvnFy3sU0kQxC+G71PrGc+wVOX3dHjCSc8FAWe45B2PeAsrPnKqE+iioo2Bbl4vKOTXnUyPldGwQ+azR+HUXHT/BJXdIUVsV0X8AsUZQV1adu+moT3RscV8VdbWFUgke6JKRz/FbBOrpdqFbr1UAFjUQzEu3EJnKYPVzt2fGtLeJsI/5qPOJnm0iCb/nlkq4NJDcMxghbqjtkm81AMDa2gjiY3F7xSM3en9GmaCOVz5IegVQ0gXAGfW/ALYshK8kbHbqKOxE66kxJEOOUfMrWb2mWosiG6D0Bk5AVt7BO6T/XA== 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)(230922051799003)(1800799009)(451199024)(186009)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(2906002)(40480700001)(40460700003)(2616005)(966005)(6666004)(478600001)(110136005)(83380400001)(7416002)(47076005)(15650500001)(336012)(26005)(1076003)(16526019)(426003)(8936002)(70586007)(70206006)(54906003)(316002)(5660300002)(41300700001)(8676002)(4326008)(81166007)(356005)(36756003)(86362001)(921005)(82740400003)(36860700001)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:04.7512 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c41c7766-a6e1-484a-ab2c-08dbc190b452 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: BL6PEPF0001AB77.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5609 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. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202309260515.5XbR6N0g-lkp@intel.com/ Signed-off-by: Shyam Sundar S K --- Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/pmf.rst | 25 ++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 9 ++++++ drivers/platform/x86/amd/pmf/tee-if.c | 41 ++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/pmf.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guide/index.rst index 43ea35613dfc..fb40a1f6f79e 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -119,6 +119,7 @@ configure specific aspects of kernel behavior to your liking. parport perf-security pm/index + pmf pnp rapidio ras diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst new file mode 100644 index 000000000000..90072add511e --- /dev/null +++ b/Documentation/admin-guide/pmf.rst @@ -0,0 +1,25 @@ +.. 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 d5e410c41e81..34778192432e 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -73,6 +73,7 @@ #define PMF_POLICY_STT_MIN 6 #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 +#define PMF_POLICY_SYSTEM_STATE 9 #define PMF_POLICY_P3T 38 /* TA macros */ @@ -439,6 +440,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 */ @@ -470,6 +478,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 315e3d2eacdf..961011530c1b 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) { - unsigned long val; + unsigned long val, event = 0; int idx; for (idx = 0; idx < out->actions_count; idx++) { @@ -113,6 +141,17 @@ 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)); + /* reset the previous recorded state to zero */ + dev->prev_data->system_state = 0; + } + break; } } } From patchwork Sat Sep 30 08:37:08 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: 13405058 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 69664E77366 for ; Sat, 30 Sep 2023 08:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbjI3IjS (ORCPT ); Sat, 30 Sep 2023 04:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3IjR (ORCPT ); Sat, 30 Sep 2023 04:39:17 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B1091B1; Sat, 30 Sep 2023 01:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mVSid6SxFxThYn9CdorKMhVgyWHyMNAQdN92pInGxer38Kc2unJ/88KgXeehQg/d5rFxd04JC8X+dTRNo2rbqJ4n/BKlsQZ+uYO7YuitE6Jona62WP6alZbg3VzdM+Wi2HcM6Q+dVa6jR/krOCyu4h29GHkhWERCuuseVacjCbjNOkaxiPw88WCoxfYsMehdGz0rw3crAuKHQENSrhUqbwhe4aAWt9JJ7Dwa4Mdcy24lIzXSmoI8iX3RKezMKEwIEUzgcDGvHFcY0YQxa7FE/jNCGSwTHr0h24Gz+3X1NsZb4jKXn5NgaeDcIepzgueH2nlfrLqOAKL108GFzITa+g== 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=5Uta5TUsJdI6QyGMlOLV58HXi0zHWzSpkx2drtgPLRY=; b=fdWhFrVRqmjZJi3guY16mghxF7bKgRilu5rLNioVyPounreFE2PvoJP/cEI/Ig9xnZscFhzSEATyAMj6w+m0uJjfoCNB6RqHq+a/IYFFfzPd71iby4/PIi05u7HlB6geWbVkwsxGx+Ro+0m2WHai/P09s7IHyDBd+B7ueJN3x16j7TC+LIcktjmlXa/V7vxCBi/O5g3i2DOsJ77KwRk6pDbv+Xjy9FYlFZyRMz3w07i8rFxM+VK/rY//LqsGH9IUDaXk9yX92+cHwrxQynPY7d+Yksc89ugroK8+vuuQPbhMQvTCgmHuZ4Of6rfKY1+nzt3wRdC7up1j7DPQupGr5w== 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=5Uta5TUsJdI6QyGMlOLV58HXi0zHWzSpkx2drtgPLRY=; b=bp3pQVdIaZxVLFtUT6WgEu0EXc7R4/1rZFYFeMZ22KA1ns/8Azf2D13/vpw1kP0Wydip0eg6gIcD/cjFJwEiYauf7kcuTzzFKBDZYKIB9bABhdHGbr8oygWhJsmuUE16XQLTRL5f9ivJzyEJPNkOBinTo8pDJg/nFbb/s/BppZI= Received: from MN2PR04CA0005.namprd04.prod.outlook.com (2603:10b6:208:d4::18) by MW3PR12MB4507.namprd12.prod.outlook.com (2603:10b6:303:2c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28; Sat, 30 Sep 2023 08:39:11 +0000 Received: from BL6PEPF0001AB75.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::55) by MN2PR04CA0005.outlook.office365.com (2603:10b6:208:d4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28 via Frontend Transport; Sat, 30 Sep 2023 08:39:10 +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 BL6PEPF0001AB75.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:10 +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; Sat, 30 Sep 2023 03:39:04 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 09/16] platform/x86/amd/pmf: Add facility to dump TA inputs Date: Sat, 30 Sep 2023 14:07:08 +0530 Message-ID: <20230930083715.2050863-10-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB75:EE_|MW3PR12MB4507:EE_ X-MS-Office365-Filtering-Correlation-Id: ded81c90-dc3d-4eae-2b73-08dbc190b7c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2SAzQ238q7ymVOeS8vvlL0ghuIJyRa5A3Es4MKFu3rvo4JJoi+BkC3z5BOdNaGm/SPC0I695mYH1wMgXwBHYv30WmTa6iYkZLqtnJhjbkiFnJ1G6rM95e6BPE6Cvq1VZJTDAZsvkaX5rBfQLPDELXLy1arWRBNnE3loMv1itvIDFOhahwlSZt08NzjbRiozBk4C/IbdABrOPmVpWwhnLK3sEFHkh7W7JaHOqjb/WhHF4NNbIlSFTW8JeJVOgbrrNsmHNtWuzl6crgZO6jUAC7FOHGuUnX5rDNx9OddHhT85Qssbp6bcx07arMIWwvpV0D2JUYorhSEnvcfvxgRh4U0ivBqTgR6/8HuXcLm2wXp08zPm9PFGv4AbuDcnK6GSt9Oy0UpOJ7pVJVNWV+u/ko9btn56JicnKx2HzbgfNB/atepbqZctXzER0talNbpuDh5k2kVotMa9zH8edsbBZVhzGTX/8kmQWXkB/XzchU+Qt2VroRZUB98yC1i5GWF7zYyRJAZCicV1kxQS6aSh7LMoXkfN6Ql6W8hPZ7IVZKXhWY9lkfKO0isThct9I2xtIWaRa9gdohtfYvjViaJVxAVA09FdaZO+XYuNpaWF7khukbf4u3VamnSrLboMK+DbkNCz4hJbBKRTv+GwJ4qxqNGRHTNF71Qc0Q0eRMk06OQgbh5f9oNe+dJRSSfkJKxpobP6BKqXHSTqFg0ErkDm/Zbc7acuKT2EGw721lEU5BuThs9w/k11HMDfP7BzQBpBhZVhkhV+mOmIWBEcM5J+Q76wqjlrgy6ye6UJDKTuA+Ow= 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)(396003)(376002)(346002)(230922051799003)(82310400011)(1800799009)(186009)(64100799003)(451199024)(36840700001)(40470700004)(46966006)(40460700003)(7696005)(83380400001)(82740400003)(81166007)(921005)(356005)(86362001)(36860700001)(47076005)(36756003)(1076003)(26005)(2616005)(40480700001)(16526019)(426003)(336012)(316002)(54906003)(41300700001)(7416002)(110136005)(70206006)(70586007)(2906002)(5660300002)(8676002)(8936002)(4326008)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:10.4929 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ded81c90-dc3d-4eae-2b73-08dbc190b7c1 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: BL6PEPF0001AB75.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4507 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. Also, make source_as_str() as non-static function as this helper is required outside of sps.c file. Reviewed-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/pmf.h | 3 +++ drivers/platform/x86/amd/pmf/spc.c | 37 +++++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/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 34778192432e..2ad5ece47601 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -595,6 +595,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); @@ -625,4 +626,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 3113bde051d9..3aee78629cce 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -14,6 +14,43 @@ #include #include "pmf.h" +#ifdef CONFIG_AMD_PMF_DEBUG +static const char *ta_slider_as_str(unsigned int state) +{ + switch (state) { + case TA_BEST_PERFORMANCE: + return "PERFORMANCE"; + case TA_BETTER_PERFORMANCE: + return "BALANCED"; + case TA_BEST_BATTERY: + return "POWER_SAVER"; + default: + return "Unknown TA Slider State"; + } +} + +void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) +{ + dev_dbg(dev->dev, "==== TA inputs START ====\n"); + dev_dbg(dev->dev, "Slider State : %s\n", ta_slider_as_str(in->ev_info.power_slider)); + dev_dbg(dev->dev, "Power Source : %s\n", source_as_str(in->ev_info.power_source)); + dev_dbg(dev->dev, "Battery Percentage : %u\n", in->ev_info.bat_percentage); + dev_dbg(dev->dev, "Designed Battery Capacity : %u\n", in->ev_info.bat_design); + dev_dbg(dev->dev, "Fully Charged Capacity : %u\n", in->ev_info.full_charge_capacity); + dev_dbg(dev->dev, "Drain Rate : %d\n", in->ev_info.drain_rate); + dev_dbg(dev->dev, "Socket Power : %u\n", in->ev_info.socket_power); + dev_dbg(dev->dev, "Skin Temperature : %u\n", in->ev_info.skin_temperature); + dev_dbg(dev->dev, "Avg C0 Residency : %u\n", in->ev_info.avg_c0residency); + dev_dbg(dev->dev, "Max C0 Residency : %u\n", in->ev_info.max_c0residency); + dev_dbg(dev->dev, "GFX Busy : %u\n", in->ev_info.gfx_busy); + dev_dbg(dev->dev, "Connected Display Count : %u\n", in->ev_info.monitor_count); + dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); + dev_dbg(dev->dev, "==== TA inputs END ====\n"); +} +#else +void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) {} +#endif + static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { u16 max, avg = 0; diff --git a/drivers/platform/x86/amd/pmf/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 961011530c1b..b0711b2f8c8f 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -187,6 +187,7 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) } if (ta_sm->pmf_result == TA_PMF_TYPE_SUCCESS && out->actions_count) { + amd_pmf_dump_ta_inputs(dev, in); dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, ta_sm->pmf_result); amd_pmf_apply_policies(dev, out); From patchwork Sat Sep 30 08:37:09 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: 13405059 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 42F4BE77362 for ; Sat, 30 Sep 2023 08:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234182AbjI3IjX (ORCPT ); Sat, 30 Sep 2023 04:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3IjX (ORCPT ); Sat, 30 Sep 2023 04:39:23 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2073.outbound.protection.outlook.com [40.107.223.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A59D1A5; Sat, 30 Sep 2023 01:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UBRUUhjcMDGCjMIpQnAo6wLEvwrG+El3vqUzq28Cbt/ocFcwuQ/18gorWV+wq4TQqgBszeJumsgrQ65uPzvazIqmTcv/KdNvla4Njg6R0uZQDBjcVssmJR1xUV4k4oFngvR1eRhTwPI3TnL/JSx7JXdsjJIy4lvBflWm/xQqzyVtFqKkXy/lV0XxuMthcox8/ZAFsvGsxSnJxSJzPs3JWE9LCKQd27JeT9LynrNR3lC04YXzfRcIwYEmWmug3jd7RqKCnDrjEN4nCMLxom3G7ieWFfZlyXeBNv/AnRg/E6pvXauPShYOtrp9ON3S+7FhVx3RC8bN3huYK4Kwfq+p8A== 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=N+1mYP+/igZfYYYmEUJOKYCosvS8yyrS33+ej8kqP84=; b=XWKUV1LeC+O3Bms3GKy9FGE4CFs7SYdEw1UO8S9m+BM3+w/a6/o/UXvy5tl2/NvNgaNvV5vyAkd0AOgDX2gUULLHsVwJbOZSoBmcTM45IRJXKc/eJWwOJ2t8303nQVuKt3Yippjt2iZqGo3gCORAiaJGoAi4EnlU0LgfZBqNEDTYkYO/XUJe/3yQgumL+vAkEFvgqw7KFSborEsbDaxC9wqiE6Pi6jZvMlYV+/ObVOxjyTvTdYtnB9jzOsJikYJe2v5nI7n3VmSrsVQ2h1c7ZNE4bbT4iYfaovCiu+/i90Jy7ovbzZZtWqopqscpVhwF6zG1EK+b3BrlydXZEprxQA== 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=N+1mYP+/igZfYYYmEUJOKYCosvS8yyrS33+ej8kqP84=; b=DiP72jxGEnzTVpGCFfzRP0nibTzF3PgINcp+4CLKvskhQEKt77plLvSvwBPuUs/cYxTL8KqAoeVKFw8Nv8FSmXb94D3uksXQICkPnkREtSf60Sm7/GzBdOn+o6nnefEEs5oKnftpTGSui1RKw+5vRiIloB1nwYFE3IsrJSv1CIE= Received: from MN2PR07CA0014.namprd07.prod.outlook.com (2603:10b6:208:1a0::24) by SA1PR12MB7037.namprd12.prod.outlook.com (2603:10b6:806:24c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Sat, 30 Sep 2023 08:39:17 +0000 Received: from BL6PEPF0001AB71.namprd02.prod.outlook.com (2603:10b6:208:1a0:cafe::74) by MN2PR07CA0014.outlook.office365.com (2603:10b6:208:1a0::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26 via Frontend Transport; Sat, 30 Sep 2023 08:39: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 BL6PEPF0001AB71.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39: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; Sat, 30 Sep 2023 03:39:09 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" , kernel test robot Subject: [PATCH v2 10/16] platform/x86/amd/pmf: Add capability to sideload of policy binary Date: Sat, 30 Sep 2023 14:07:09 +0530 Message-ID: <20230930083715.2050863-11-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB71:EE_|SA1PR12MB7037:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f793c31-2487-425b-b5d6-08dbc190bbec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2dUOPM4kAMfuRkyZEVG5xV7ghslDGPgNV+ts81hY9tgcKiuk3KMXKO0m4V9/+w54Pc5LCqc2Fi8saY/GvzwWRKMNIVzO42vyVIzJU8uBQvXCASqBwCTg2R0i9vsT+dvDTV9irpBLUDjjseVK3iuKhhKkFylhJ8KP5EE9a7yLXZRjuYU3oRfoV+O4j9YmiVviwBzfkKoop89jvTsE+PMaUGvkTu8Xb+NR+xkUAVl6VlYZS8H0K9y0L6L0f+8urroYjUD+hCsUlRZ6taSCSSXrCznQ2mOhq7EiOxWwcatSAM4X4Jlv4fqPHc2HP1QeCfoVl0csOXN8R6m92lAvFib8EbTIPDH1JgMm8S517vAWoDA/nx/uvcclcJBE0OAGseZFviUL9zy/TQnvwOmRNS4u1ik9+mdSrx8MbSKAJIgGQTR6pPfftB09aLm1Y1Qb9vvxCOZqMigvlz5wvqNlM7TNOcvK/rBXMWAnXo/ji+WVBZaPlewAOFrqpwXCpGGem2zO93NGI5OiK8yiTpN17Q8mMwGivveisvbdimVaPTCS1HuJQu33WSqE2BprON2L1IEce4NWe4lOVHMKy2+squAifHbjcJKp/ypUkoe4B3XLfThjfMt82O6W/EoV7Wif/qTAz2hp5fWXxnzTIWCYMpuZ2MPXVRDpXs/DTwQRyGy8SbLIYED3vXn+/l4+/XOSSeFECnNPWI4z0bglSBQa1XwWwl6C05CBD2bXIxA0+FkhUvqR2kNHcvcPywcKy5piltnjb33+wup9CM2a/Fd6Q3pTSg== 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)(136003)(376002)(396003)(230922051799003)(1800799009)(451199024)(82310400011)(186009)(64100799003)(40470700004)(36840700001)(46966006)(2616005)(47076005)(16526019)(426003)(336012)(83380400001)(26005)(1076003)(36860700001)(40460700003)(54906003)(36756003)(82740400003)(40480700001)(356005)(86362001)(921005)(70586007)(110136005)(70206006)(81166007)(316002)(8936002)(41300700001)(5660300002)(4326008)(8676002)(2906002)(7416002)(7696005)(966005)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:17.4892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6f793c31-2487-425b-b5d6-08dbc190bbec 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: BL6PEPF0001AB71.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7037 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. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202309251031.awDDkRgS-lkp@intel.com/ 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 | 68 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 2ad5ece47601..b862cd4f902e 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -218,6 +218,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 b0711b2f8c8f..01f974b55a6a 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -8,6 +8,7 @@ * Author: Shyam Sundar S K */ +#include #include #include #include "pmf.h" @@ -16,9 +17,15 @@ /* Policy binary actions sampling frequency (in ms) */ static int pb_actions_ms = 1000; +/* Sideload policy binaries to debug policy failures */ +static bool pb_side_load; + #ifdef CONFIG_AMD_PMF_DEBUG module_param(pb_actions_ms, int, 0644); MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (default = 1000ms)"); + +module_param(pb_side_load, bool, 0444); +MODULE_PARM_DESC(pb_side_load, "Sideload policy binaries debug policy failures"); #endif static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d, @@ -268,6 +275,61 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) return 0; } +#ifdef CONFIG_AMD_PMF_DEBUG +static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, + size_t length, loff_t *pos) +{ + struct amd_pmf_dev *dev = filp->private_data; + int ret; + + /* policy binary size cannot exceed POLICY_BUF_MAX_SZ */ + if (length > POLICY_BUF_MAX_SZ || length == 0) + return -EINVAL; + + dev->policy_sz = length; + if (copy_from_user(dev->policy_buf, buf, dev->policy_sz)) + return -EFAULT; + + ret = amd_pmf_start_policy_engine(dev); + if (ret) + return -EINVAL; + + return length; +} + +static const struct file_operations pb_fops = { + .write = amd_pmf_get_pb_data, + .open = simple_open, +}; + +static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) +{ + struct dentry *file = NULL; + + dev->esbin = debugfs_create_dir("pb", debugfs_root); + if (IS_ERR(dev->esbin)) + return -EINVAL; + + file = debugfs_create_file("update_policy", 0644, dev->esbin, dev, &pb_fops); + if (!file) + return -EINVAL; + + return 0; +} + +static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) +{ + debugfs_remove_recursive(dev->esbin); +} +#else +static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) +{ + return 0; +} + +static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {} +#endif + static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) { dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); @@ -280,6 +342,9 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev) memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz); + if (pb_side_load) + amd_pmf_open_pb(dev, dev->dbgfs_dir); + return amd_pmf_start_policy_engine(dev); } @@ -388,6 +453,9 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) { + if (pb_side_load) + amd_pmf_remove_pb(dev); + kfree(dev->prev_data); kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); From patchwork Sat Sep 30 08:37:10 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: 13405060 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 B55DBE77351 for ; Sat, 30 Sep 2023 08:39:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234183AbjI3Ij1 (ORCPT ); Sat, 30 Sep 2023 04:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3Ij1 (ORCPT ); Sat, 30 Sep 2023 04:39:27 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894DE1AE; Sat, 30 Sep 2023 01:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ds9l38xxC/PS7PcU4xAqbIB2QPaVWd1CYEwgRW4hjukliDo54JIsc9NRmqiWKQHyWs0233IzaWgK/B3PHvlO105oprDLWkW2q23xEh17Z8S1Lc2Bajjl3M52nbN3vehtVePvMFDoEhHpdKEV2Ngsr310UOB3qy1wL3EMmHIamS3SD/bSWFUAfajR+nppYw8yUnt0f+wEBgweX5bCwBTV2ofrl3fw8R/u37R6lrMtac7ALf6YozMxHR/MelNEBGJsd/KC68Dy1H4Gedy7Wv7UQjR780l4MVIdOx2teNNIHDE7GYUkWVk400xQTZce5GLio8bRHAkFbuPHpUvyjHW2qA== 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=iW8uPcfL5rjtduGeUbEp+Tm2YhE6J6dvo5DGpOaQlk0=; b=bzeguezKZzOjQOfQoaAdIBHtgVVvSIrfzYwdsIUV+K+PbfjJYtPq6z1VPXHTyJmOJACOcx42V6I2eHuwXyR70JOlF7UxutjBkNNEIQSyYYisvZmUFTb+MXm9P8Bo3L/CbFXEGQ9pKhRN6NdSKbZQ1yceGJm7kDtVc0iPvtImhSuT9HPoNx3Kd5zhHWdN3Xkgl8kqGe47dOzUiPq5pnTcmqS6yTmLn3/p6Top/quha0tygm2PDxPLl2+vcRDXj6SW6WMPimJK6ins6y/lkQbnf68UFdEtShcFD5PymcTGdLj87fJXh0/uxCwD8kRkkhgmsrAEJwh1/yR/O28Y72ZTZA== 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=iW8uPcfL5rjtduGeUbEp+Tm2YhE6J6dvo5DGpOaQlk0=; b=WZEungcmYRRljRrkjiFq6SXMMSq1vWnmG71SPeYi2HfHiPv8TlVA9VRDeQ+h4hxKLrSpKytsIpTvbSH7T5vpazohRbQahJaJD5/ZhuQ01iG5hqTSoozhB7whbh7jMF4ei4i8KRLdmKHPV+Du7EXe4yAyxoVQd/Hcv+3U92743wQ= Received: from MN2PR04CA0018.namprd04.prod.outlook.com (2603:10b6:208:d4::31) by PH7PR12MB7427.namprd12.prod.outlook.com (2603:10b6:510:202::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28; Sat, 30 Sep 2023 08:39:19 +0000 Received: from BL6PEPF0001AB75.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::86) by MN2PR04CA0018.outlook.office365.com (2603:10b6:208:d4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.26 via Frontend Transport; Sat, 30 Sep 2023 08:39:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB75.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:19 +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; Sat, 30 Sep 2023 03:39:14 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 11/16] platform/x86/amd/pmf: dump policy binary data Date: Sat, 30 Sep 2023 14:07:10 +0530 Message-ID: <20230930083715.2050863-12-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB75:EE_|PH7PR12MB7427:EE_ X-MS-Office365-Filtering-Correlation-Id: 7baa6db3-5b76-4e8a-af20-08dbc190bcfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UqFLrWfId2aqkoX4Eq+xxj8f7BDN2sLH6mWrBwTmY5DBa+m2dyFKMxr2kpkGCethu6K1ggINg9frgA2gygy24S41PyPXcMrRFjEia2KkuIhHYXs4ail/rnrQMEr0rgO+Z3/D7EyYNIRUIH+EvYuZTao80phqYwc9f+f07B+lnd+uveDu/X9hJxmvRDec8aYwNNYG6Z4rVNypUJCG/XFilDUlrjgSvLfuwsNK9KVzF0P9iZpKIoakoLdvH+/tUTyJvJlGzKpHOHlPB/gyFs6PdkUy58jbfJF3lWJzmgPlG/5Y6mu5cLLwq5ZNsHIi+pApPATbP48OyWVhfNP2Vo69zwdSU7cUGnkHhuPLxrk9lJPd7uUU+tkXS5IS+RPjzDM/BCfigmE9BGc8DJTRvYEpwQ2IZoiNS41oUeI367MLRNsOe0fQ8+0Fun+70kzPwWRSaxm6OcbvpUb2JAE9HsS/zNxo/ITzNbjM/4wPxATCLbHw+mWHyAGQUqzYx7s0PfxydR8Z40hPm0hfrv+pwq3/gx3jHgyc255SY/tSXFWnrulyRc2W2EyteVPH38QXl30fr5VtBq2K+AZycnaYnpRjqUAzgIfMCDRnGsZDqOkX5OcWRSz3Ibusp3GZPBUb1pqvlPggAB2qolJC9Vp/KU4pisThoLjFe7uye/RdD5tDppwXHD3TzSMF/q1dpEhTH5oZrMBJeJBCuc4VGn7UOG8qQ53SfM+8OwJukK4DjQV28ZFME3T1+8iFbAT0uw85TWJWn8QdjI2o055BNRkSus16p1XJB4SNS4MllBNFTj/WNE0= 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)(230922051799003)(82310400011)(186009)(1800799009)(64100799003)(451199024)(46966006)(36840700001)(40470700004)(40460700003)(8936002)(4326008)(2906002)(86362001)(26005)(1076003)(2616005)(16526019)(7696005)(7416002)(36756003)(6666004)(336012)(47076005)(36860700001)(81166007)(82740400003)(356005)(426003)(921005)(40480700001)(478600001)(8676002)(5660300002)(70586007)(70206006)(110136005)(54906003)(316002)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:19.2585 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7baa6db3-5b76-4e8a-af20-08dbc190bcfa 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: BL6PEPF0001AB75.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7427 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 01f974b55a6a..d16bdecfd43a 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; @@ -341,6 +344,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 if (pb_side_load) amd_pmf_open_pb(dev, dev->dbgfs_dir); From patchwork Sat Sep 30 08:37:11 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: 13405061 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 BABD4E77351 for ; Sat, 30 Sep 2023 08:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234187AbjI3Ijd (ORCPT ); Sat, 30 Sep 2023 04:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3Ijc (ORCPT ); Sat, 30 Sep 2023 04:39:32 -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 E56011A7; Sat, 30 Sep 2023 01:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l5ZGWYcz4HeajCRzVDH1ZFjdcvYPwJqk7DhkoQpvexdht4oTQhEtar9Wzp4zyzV+TOE9wLQjYWPYeZhMRfSc+uFHVzH+3RPMJvkxRGMV5qApMqN66/yYRRNIbBgt15W+v3XxQoTFqfie5jdRBaEEL1M6BRokYNos2cgR+GXgOPgiVhsJqHv1rqAR8lz1ZjObjxUq8h+BFhfG8m4Z7u0+PCz9cJZ3RKcNP8Cv6Zi7UkEYvRNycvUCVz8qHQw+/rF8i/r1Y0odoNJB3zxteV/Sr8QupMDR7mrs/QYpOxGTj83v7v3Lxjo5gnu55brEzwoa8LQaCOtUUvbbn8IbSjEYoQ== 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=6pBIxcT01BS8so/qGq+Ut6rZQE126lioQMs225ITGKo=; b=nyoGPA/qFajpMrIeBMTpF+RLb6vXbvfAmDUYIpxSeIuU0m8aA4UUoN780XVaqD4n/Vi8BOLbq/bB4J2anrhgG36cIjUNjZ0kk9MUaddJOR3BTgM3dW1kgYNw+S4wdOVhiWSMJWvRos9yF9zkD0lgxdwk02XJg3YVrJutkWJjjmKqxPexq8iDGuG43Vfns3ts031ns2ozknRVhQljT2GZm/LXJXPMaLdTpwdCyDn5zFtKYjKvTWhYtO6gPalc4o6okyOjSR+6tlJyxIqkbXdMGfJ58qMAnNvPNA/PA8LBLNGneQuaFJOLaTdm8NRoDw+nmvqiTHWvt/vUS48BBfXamA== 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=6pBIxcT01BS8so/qGq+Ut6rZQE126lioQMs225ITGKo=; b=ST4JxpkEoMypEnTHVH92/ptKp3ysnszuxJhlQ8B3WsZg9ZZ++754ObxkBEBQ10K7RZyETcFChSRy7KxZukdBLnqR5wdCmFDiHimh9ssfZorIXSV6Fc1SybbyGvAvSguEQpWsg+GekzGyl5/V86h4U1Gjkt7D6ODQchuFTqBpmOo= Received: from MN2PR04CA0022.namprd04.prod.outlook.com (2603:10b6:208:d4::35) by CH2PR12MB5516.namprd12.prod.outlook.com (2603:10b6:610:6b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28; Sat, 30 Sep 2023 08:39:24 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::fe) by MN2PR04CA0022.outlook.office365.com (2603:10b6:208:d4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25 via Frontend Transport; Sat, 30 Sep 2023 08:39:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:24 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:39:19 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 12/16] platform/x86/amd/pmf: Add PMF-AMDGPU get interface Date: Sat, 30 Sep 2023 14:07:11 +0530 Message-ID: <20230930083715.2050863-13-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB74:EE_|CH2PR12MB5516:EE_ X-MS-Office365-Filtering-Correlation-Id: c555830e-c0b5-43c9-5b02-08dbc190bfee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bKlNuvcLwov88830v33PsCCRJgipwsw5kSQX9+9o2Ul2M/8Ghmi93GyiYVRTYj1V2yKXARE8VrjKI36jZj4ocPUEGJrQ1CUa8ZXJD3dipnsP6oylUHoHBXyrBrpBOWyTa9lAgfSyrOCh4i7lQVg84rKksHMRAEeCOnU39YVDIANAA8sqyvz2PBMaj4y2Ds/6w1Gfn7rjz6Grt1ysK50osloX4hZqX/YHmdIPEMRxSrbWDyCb+Z7o+ZiPv5xc1wGZY3/w9v0BSMOqb6dHeVPNN5mHY4o88rIhWQmXPdQbysnwbzRC4oxvF+65VdZUpFaOPItVK4eBRDxU46llXO5rGFV3341buL7Nsi1HvWD9yRnifmNLy6FqStH7TwoUyv7s8bql0NfdM2FyztiuznxRMJJhShMcUqbBAdqq2u5/wZzM6INTddY0gfbwVyWv+6a/Yew/5Vw4BwsPIydlCIOC4cFtaJKr/bq43GtySykRazhpNvp9l2TLcPlfsz53Sgmpe3A1yADtZckn1kO52b4eoKfp7Qz25SQqKi1QqUZ7u29EKUiyZj6ni0BybSLXwr5up7CeJdxHjGGKJ1Aw6F7f/OTXDpQO75wPivvqD7P/KX/YAmxdCzYpNAz/nQ1IxtrZMgVL7ywj01iCnxnZyF9EWtsIZOjYURdT4ZiChuHWfNp3xbWJb+135rVEARxhWgVVrhJJxDF7yNXRjA0/atNeBa46SdoyeOl41qcSGAmUD94RSX4489UXsnwEJfh+S1qUaNDbO0bsFku6NVPh4tJC4XjBcMJrx/B+LJXKe7Z51Cc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(346002)(136003)(39860400002)(230922051799003)(64100799003)(451199024)(82310400011)(186009)(1800799009)(46966006)(40470700004)(36840700001)(36756003)(86362001)(40480700001)(7416002)(2616005)(5660300002)(30864003)(2906002)(54906003)(70206006)(478600001)(41300700001)(70586007)(316002)(110136005)(7696005)(6666004)(40460700003)(83380400001)(426003)(336012)(47076005)(66899024)(36860700001)(8676002)(8936002)(4326008)(26005)(1076003)(16526019)(82740400003)(356005)(921005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:24.2108 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c555830e-c0b5-43c9-5b02-08dbc190bfee 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5516 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 | 136 ++++++++++++++++++++++++ drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/core.c | 1 + drivers/platform/x86/amd/pmf/pmf.h | 3 + drivers/platform/x86/amd/pmf/spc.c | 13 +++ drivers/platform/x86/amd/pmf/tee-if.c | 28 +++++ include/linux/amd-pmf-io.h | 35 ++++++ 9 files changed, 220 insertions(+) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c create mode 100644 include/linux/amd-pmf-io.h diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile index 384b798a9bad..7fafccefbd7a 100644 --- a/drivers/gpu/drm/amd/amdgpu/Makefile +++ b/drivers/gpu/drm/amd/amdgpu/Makefile @@ -86,6 +86,8 @@ amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o +amdgpu-$(CONFIG_AMD_PMF) += amdgpu_pmf.o + # add asic specific block amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o \ dce_v8_0.o gfx_v7_0.o cik_sdma.o uvd_v4_2.o vce_v2_0.o diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 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..45a079c028d3 --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -0,0 +1,136 @@ +/* + * Copyright 2023 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + + * * Author: Shyam Sundar S K + */ + +#include +#include "amdgpu.h" + +int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf) +{ + struct drm_device *drm_dev = pci_get_drvdata(pmf->gpu_dev); + struct drm_mode_config *mode_config = &drm_dev->mode_config; + struct amdgpu_device *adev = drm_to_adev(drm_dev); + struct drm_connector_list_iter iter; + struct drm_connector *connector; + int i = 0; + + /* reset the count to zero */ + pmf->display_count = 0; + if (!(adev->flags & AMD_IS_APU)) { + DRM_ERROR("PMF-AMDGPU interface not supported\n"); + return -ENODEV; + } + + mutex_lock(&mode_config->mutex); + drm_connector_list_iter_begin(drm_dev, &iter); + drm_for_each_connector_iter(connector, &iter) { + if (connector->status == connector_status_connected) { + pmf->con_status[i] = connector->status; + pmf->connector_type[i] = connector->connector_type; + pmf->display_count++; + } + i++; + + if (i > MAX_SUPPORTED) + break; + } + drm_connector_list_iter_end(&iter); + mutex_unlock(&mode_config->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); + +static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device *cooling_dev, + unsigned long *state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + *state = backlight_get_brightness(bd); + + return 0; +} + +static int amd_pmf_gpu_get_max_state(struct thermal_cooling_device *cooling_dev, + unsigned long *state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + if (backlight_is_blank(bd)) + *state = 0; + else + *state = bd->props.max_brightness; + + return 0; +} + +static const struct thermal_cooling_device_ops bd_cooling_ops = { + .get_max_state = amd_pmf_gpu_get_max_state, + .get_cur_state = amd_pmf_gpu_get_cur_state, +}; + +int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf) +{ + struct drm_device *drm_dev = pci_get_drvdata(pmf->gpu_dev); + struct amdgpu_device *adev = drm_to_adev(drm_dev); + + if (!(adev->flags & AMD_IS_APU)) { + DRM_ERROR("PMF-AMDGPU interface not supported\n"); + return -ENODEV; + } + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + pmf->raw_bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!pmf->raw_bd) + return -ENODEV; + + pmf->cooling_dev = thermal_cooling_device_register("pmf_gpu_bd", + pmf, &bd_cooling_ops); + if (IS_ERR(pmf->cooling_dev)) + return -ENODEV; + + return 0; +} +EXPORT_SYMBOL_GPL(amd_pmf_gpu_init); + +void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf) +{ + thermal_cooling_device_unregister(pmf->cooling_dev); +} +EXPORT_SYMBOL_GPL(amd_pmf_gpu_deinit); diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 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 39671d245e96..78bf50ad7e12 100644 --- a/drivers/platform/x86/amd/pmf/core.c +++ b/drivers/platform/x86/amd/pmf/core.c @@ -404,6 +404,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 b862cd4f902e..97cadd080742 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -13,6 +13,7 @@ #include #include +#include #define POLICY_BUF_MAX_SZ 0x4b000 #define POLICY_SIGN_COOKIE 0x31535024 @@ -227,9 +228,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 3aee78629cce..40872afb99e5 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -44,6 +44,10 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "Max C0 Residency : %u\n", in->ev_info.max_c0residency); dev_dbg(dev->dev, "GFX Busy : %u\n", in->ev_info.gfx_busy); dev_dbg(dev->dev, "Connected Display Count : %u\n", in->ev_info.monitor_count); + dev_dbg(dev->dev, "Primary Display Type : %s\n", + drm_get_connector_type_name(in->ev_info.display_type)); + dev_dbg(dev->dev, "Primary Display State : %s\n", in->ev_info.display_state ? + "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } @@ -145,6 +149,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 */ @@ -153,4 +165,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 d16bdecfd43a..9216c2065fd3 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" @@ -355,6 +356,21 @@ 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) { + /* get the amdgpu handle from the pci root after walking through the pci bus */ + 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; @@ -451,6 +467,15 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) INIT_DELAYED_WORK(&dev->pb_work, amd_pmf_invoke_cmd); amd_pmf_set_dram_addr(dev); amd_pmf_get_bios_buffer(dev); + + /* get amdgpu handle */ + pci_walk_bus(dev->root->bus, amd_pmf_get_gpu_handle, dev); + if (!dev->gfx_data.gpu_dev) + dev_err(dev->dev, "GPU handle not found!\n"); + + if (!amd_pmf_gpu_init(&dev->gfx_data)) + dev->gfx_data.gpu_dev_en = true; + dev->prev_data = kzalloc(sizeof(*dev->prev_data), GFP_KERNEL); if (!dev->prev_data) return -ENOMEM; @@ -466,5 +491,8 @@ void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) kfree(dev->prev_data); kfree(dev->policy_buf); cancel_delayed_work_sync(&dev->pb_work); + if (dev->gfx_data.gpu_dev_en) + amd_pmf_gpu_deinit(&dev->gfx_data); + pci_dev_put(dev->gfx_data.gpu_dev); amd_pmf_tee_deinit(dev); } diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h new file mode 100644 index 000000000000..5f79e66a41b3 --- /dev/null +++ b/include/linux/amd-pmf-io.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * AMD Platform Management Framework Interface + * + * Copyright (c) 2023, Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Author: Shyam Sundar S K + */ + +#ifndef AMD_PMF_IO_H +#define AMD_PMF_IO_H + +#include +#include +#include +#include + +#define MAX_SUPPORTED 4 + +/* amdgpu */ +struct amd_gpu_pmf_data { + struct pci_dev *gpu_dev; + struct backlight_device *raw_bd; + struct thermal_cooling_device *cooling_dev; + enum drm_connector_status con_status[MAX_SUPPORTED]; + int display_count; + int connector_type[MAX_SUPPORTED]; + bool gpu_dev_en; +}; + +int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); +int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf); +void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); +#endif From patchwork Sat Sep 30 08:37:12 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: 13405062 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 21017E77365 for ; Sat, 30 Sep 2023 08:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234189AbjI3Ijg (ORCPT ); Sat, 30 Sep 2023 04:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3Ijf (ORCPT ); Sat, 30 Sep 2023 04:39:35 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061.outbound.protection.outlook.com [40.107.94.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A601A7; Sat, 30 Sep 2023 01:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SR7sRnOYZbJZ/+l9NndkUrYN4LrkBWEoJgMHjUKcAuxIIKnSqYzYGaYCS8XC6NBsczweaow31KniylSI5ur33vK5jz0pTCI7JXrYZjA9WDAzUa0/MP9/2M6gbqI28it5akw5V2uRZYWOprWKzT5HKRqWCf7g+YZx9vDjtq106J1mUP2WI6UV8oFX9Uh0BQkXa8n+JaEH31HZzidO801YncJI/CO6zHXrSMfIS0JYs1VC8/KaZh9s/M5Ya88eB2UWFCb2Rex1nExYHI9JM59EvaKb5X40Hd/RpjDaZXFgokugPKjt0x1U6+vo/OjAbHtoWP1HLyL2eGT43nLmM9WEKg== 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=IooPqTUNIYSRAMfK5KoaGKxDsRf6f54aVVwxJtYzgHQ=; b=LF49muYReZ31wuBD1KoC7PSOZIyb8sjNGTwkKQL3OAESKTbIswNjfocMH39zkPFDaOUEn+p5XYc8hpe1JyKnWX61DdGi2Y0TbwPiiJRFYttfua4F5Y2n4qjjWwW/bDQqaZLWFKtWflomeEEDVJpVXufewM6bBbkytJp0N6FDbFW3cdZtIC4O9pqKwmkHz3gTAcvAPi6K3emS0sCX5uBbXkL5+Qdj+v1J1NELZdfcBIUgDNMp/zjG5i4pVlLI98N40iP1aDpouk56Pdbdk28P38+laaCRTJiOv9TqABvIS4qo0rWgWC0/6oxMmS0+llccKFxnF/ZMP0ks564+BzemLQ== 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=IooPqTUNIYSRAMfK5KoaGKxDsRf6f54aVVwxJtYzgHQ=; b=kHHPWlKeUSgT7i/RSPS7je8KcVsVikQD2JKSxtkAHiFjQwwMHMS+lf0xYXM5HQZ3lvVyop5ZTUEnNp8hh9KLOs/KalIwgdJOkdCnrutoXsZz1xpgkZXJa+xZdTCWXEWQPHpyUtG64yconx4dzPjm3J9MavEArmii55LvGtlAuSU= Received: from BL1PR13CA0027.namprd13.prod.outlook.com (2603:10b6:208:256::32) by MW4PR12MB6999.namprd12.prod.outlook.com (2603:10b6:303:20a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.39; Sat, 30 Sep 2023 08:39:29 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:256:cafe::d2) by BL1PR13CA0027.outlook.office365.com (2603:10b6:208:256::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.17 via Frontend Transport; Sat, 30 Sep 2023 08:39:29 +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 BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:28 +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; Sat, 30 Sep 2023 03:39:24 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Shyam Sundar S K" Subject: [PATCH v2 13/16] platform/x86/amd/pmf: Add PMF-AMDGPU set interface Date: Sat, 30 Sep 2023 14:07:12 +0530 Message-ID: <20230930083715.2050863-14-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB78:EE_|MW4PR12MB6999:EE_ X-MS-Office365-Filtering-Correlation-Id: 9db22f12-19ef-47bb-54a4-08dbc190c2c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ol6WRkWpTZyIe984bcOvyzlmV7oeSX1AW4r7q0I6H2CXwtUmoXOJy0fMAj8Z8ndOmjNQF6Yfqp8uJOsJE4SiIKWrMX+3MPfN4cJIIJFpT/fIxevJtQ6kZzT5OrpY8HfGlSGB8cw1n7HKw+T2RoOxE6SSLJqHWODQkwnHa09w6EDeAkGXFHx2ComqL+xhF0WBA3MbDiBSgOByDRd/1Xtr6nJgZ0uI7EewFPComt6XCQtOE0NsW++tltKv9o39GKx3BJqTLcOzeX1D6eZjzh1tQGPcveTA5hJUE3aHhi5WKSvIwlWlIbFVzFqHfg7VqXXtPqLKOai12gTqz3zmA5jggwiPTbA6lRYba5pPxsw9LtpTfmFiYargpnQtRoT8OSZpm0+FoLwMTrqj6vjL1AP6hTfzveMiEx2IVRkiJ/i5BokKd5qYxQiISwgjdjeWUreHH1dsVoS5ik+iInBFanhrMkmfJkigZIGMBkvhk6t0oMTAL0c37vhDRyx+5k7pTS6XFVFmZwUqkEYmYd1sB2gBCv/ax9FixrtyAvYIJzcS4VaXZPQjm6YLg41g5E9WsVUiC1l+EzDUYAy8r+tWwhnzZgAtT1pnZizNvKljcnuso29D1SndgfFjgpKA2lQTubd/pfiBiAkX0H8VQaC91DOts/KYTN3AmXBr0GMpR8oVXNnjKH9rnxGC0ReD+75tKrVchdzAybbk0Wsz/yr1uCQ/+vT6WZO8YS+l1brsKnuOse0XNHsaV6u9AH3SpL2Qtx4PLuIndtd5FQ/BKge9oO17ZSmAKT9yRhEEoZJm0cHf1/I= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(376002)(396003)(136003)(230922051799003)(82310400011)(1800799009)(64100799003)(451199024)(186009)(36840700001)(40470700004)(46966006)(7696005)(2616005)(83380400001)(478600001)(6666004)(47076005)(8676002)(54906003)(426003)(7416002)(26005)(2906002)(8936002)(316002)(110136005)(5660300002)(70206006)(70586007)(41300700001)(4326008)(40460700003)(36756003)(1076003)(16526019)(336012)(921005)(86362001)(40480700001)(82740400003)(81166007)(36860700001)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:28.9424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9db22f12-19ef-47bb-54a4-08dbc190c2c0 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: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6999 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. Change amd_pmf_apply_policies() return type, so that it can return errors when the call to retrieve information from amdgpu fails. Co-developed-by: Mario Limonciello Signed-off-by: Mario Limonciello Signed-off-by: Shyam Sundar S K --- drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c | 18 ++++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 2 ++ drivers/platform/x86/amd/pmf/tee-if.c | 21 +++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c index 45a079c028d3..803e6bb66914 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c @@ -61,6 +61,23 @@ int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf) } EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data); +static int amd_pmf_gpu_set_cur_state(struct thermal_cooling_device *cooling_dev, + unsigned long state) +{ + struct backlight_device *bd; + + if (!acpi_video_backlight_use_native()) + return -ENODEV; + + bd = backlight_device_get_by_type(BACKLIGHT_RAW); + if (!bd) + return -ENODEV; + + backlight_device_set_brightness(bd, state); + + return 0; +} + static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long *state) { @@ -101,6 +118,7 @@ static int amd_pmf_gpu_get_max_state(struct thermal_cooling_device *cooling_dev, static const struct thermal_cooling_device_ops bd_cooling_ops = { .get_max_state = amd_pmf_gpu_get_max_state, .get_cur_state = amd_pmf_gpu_get_cur_state, + .set_cur_state = amd_pmf_gpu_set_cur_state, }; int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf) diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 97cadd080742..59329308ed8e 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -75,6 +75,7 @@ #define PMF_POLICY_STT_SKINTEMP_APU 7 #define PMF_POLICY_STT_SKINTEMP_HS2 8 #define PMF_POLICY_SYSTEM_STATE 9 +#define PMF_POLICY_DISPLAY_BRIGHTNESS 12 #define PMF_POLICY_P3T 38 /* TA macros */ @@ -482,6 +483,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 9216c2065fd3..d20821c914c7 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -78,9 +78,11 @@ static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event) return 0; } -static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) +static int amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) { + struct thermal_cooling_device *cdev = dev->gfx_data.cooling_dev; unsigned long val, event = 0; + unsigned long state; int idx; for (idx = 0; idx < out->actions_count; idx++) { @@ -160,8 +162,21 @@ 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: + if (!dev->gfx_data.gpu_dev_en) + return -ENODEV; + + cdev->ops->get_cur_state(cdev, &state); + if (state != val) { + cdev->ops->set_cur_state(cdev, val); + dev_dbg(dev->dev, "update DISPLAY_BRIGHTNESS : %lu\n", val); + } + break; } } + + return 0; } static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) @@ -198,7 +213,9 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) amd_pmf_dump_ta_inputs(dev, in); dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, ta_sm->pmf_result); - amd_pmf_apply_policies(dev, out); + ret = amd_pmf_apply_policies(dev, out); + if (ret) + return ret; } return 0; From patchwork Sat Sep 30 08:37:13 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: 13405079 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 6B10AE77364 for ; Sat, 30 Sep 2023 08:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234193AbjI3Ijp (ORCPT ); Sat, 30 Sep 2023 04:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjI3Ijo (ORCPT ); Sat, 30 Sep 2023 04:39:44 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2043.outbound.protection.outlook.com [40.107.92.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E901A7; Sat, 30 Sep 2023 01:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TsaLQPwKz+ZDQ0YEqQQgFKl78lDGWdaDvvZD5KZvov6Zt5bH1WzHz7JFVr5qd+r7J/4FUSd43hGVbE3ipcicaDmb6omteyD8QmRn2CVHfcCcTL2VJMwEt2dJ2iTsQIq5CmoWhvPzsBKHhaELIaiSBTzZWMjhMybHhIea/NHOUzqth5mrQm+G/iq7msnDbSuF5EKTlIAvBuh4GwJFrD13T2m73EnxGLzjfm4NYPIFW5pxvUW/WfowRc+FVKXI5q4TZGAaIx/lMSDMQx37fODNulSheJxsOnbZ+V+TM6oLwX00Lj5tx+Tx42G3F4YLN25oO3ves0bXjvE20R0ITUiwXQ== 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=X+jTmfNoVkIqiYQ+hCrelFeX2PgBxIli578HUrRTH+8=; b=SLBdkLeazAE2e/1glipB05fKpQZelSCHN8N5t127dkn4ZPqaRyFnnX0OdXKPqghMKBqdYqB31Co0AeeXvI+H13Yo7MLte4NW07kz9/GjBXG81yodPN+DA1ympzkF+2hJGKuHcafxwFkwiEta1qFPpYIsBnmew4ZJsZyvJPIFKsqzFUg/svhcwQyHithohXztWOFp9/01P5MgkU8STWuf0BMUbRin2JlZ189NlXNCdCgqcDK0coyKxm4LSrqaFWpoXAkA8C2OPSAww6HcKC+MK0wzUn9Yz15Ff77NEcYlLEFhXkZrhn8gY/3T3Cnys54BobiQvfbWz/iZnAV2BHJQxA== 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=X+jTmfNoVkIqiYQ+hCrelFeX2PgBxIli578HUrRTH+8=; b=bkbqEk1dWF5aPb6TJH/HAFuCsteVBj7w5xyEUWfnnQ5TNoPi+COUl1U/ACHPXgtfYa42hv+qaOi8kMUn9dPoczWx0v8K3cnEcCM8PFrPS1K4tT6Z85i4ft87x+nmoybNJvYSl+Uc7DguNme1VEWe5EwwFsK3kp8y1AJpyRO0Pk0= Received: from MN2PR14CA0002.namprd14.prod.outlook.com (2603:10b6:208:23e::7) by SJ1PR12MB6172.namprd12.prod.outlook.com (2603:10b6:a03:459::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28; Sat, 30 Sep 2023 08:39:35 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:23e:cafe::80) by MN2PR14CA0002.outlook.office365.com (2603:10b6:208:23e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.28 via Frontend Transport; Sat, 30 Sep 2023 08:39:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:34 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:39:28 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v2 14/16] HID: amd_sfh: rename float_to_int() to amd_sfh_float_to_int() Date: Sat, 30 Sep 2023 14:07:13 +0530 Message-ID: <20230930083715.2050863-15-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB72:EE_|SJ1PR12MB6172:EE_ X-MS-Office365-Filtering-Correlation-Id: bbfc5cf2-bccb-43df-dd78-08dbc190c614 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OGS7h8JuBVBTgC8JTNR24UQNYHL3YXwkppWnJFcHVpakSG+tjLMqXijUzTeyvXIx1+TVpwL/ZA9ng0xrQL0M0w6IQ+s2QFhCj3qoXRb7XhNMjc43nAe5eqXBj5WyWiXAo98NTJvaL8kcN44qA0xGvI44yZntoEvGa4MeMu4877gtAVneG0iEihYn9XemDxZ9G0u1m9WNxaCNOJR9PxM3A6q3YxAVzTAO/41CppZSruPAFS8+OgB6yidHT1zxnngfHIWui85ITe6hv6sLfBrVIHjljXFqpxG/VZl5oDptqf99ny9NkN0HIfYus35tKf5pxXMFrlcYDT3Jbf6QbtHGWr/NGo/7AXlrh2ixdUNxYozUzAaeJhoecKPJ1O5mxxMUoMZQRAjur5WFew1DSeDo1nPTrx7hxn8bN4+guzRS1DUs/k9unBk1Gexxu5AIwFDD1Q3T3XdrcsK3U+UO1iIbc/Ll6uihZv3xsNkVMAZCLFwYLoUhDILYAV2WEZkVOU559YTPMuHFgYNZbgcCtxbvNpEERR9bnfLLg+clohWBndYAWMbwVYoU2UlHzSBPAGA3iFlbXNt9pQNeXtgd/rE8cz998BsodLd5is5AaIuieLdQPLXMD11OU5+wuwd2w8UyntBdongKhD6/vx0nvjGS0hia+FsBMqjGFvv61INVtPWj3er2QNCx7hO7i4QDw+MVuUEdXltA/JG0xQVSU8WmfWIo9rHFN5zFFHlUM1DRf7Wet055YdqSssM78zApUMl8SIbWfq9AYMTKm92EeFtByv5pj8FreYoEpyISNj8xQxc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(346002)(136003)(396003)(230922051799003)(186009)(1800799009)(451199024)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(40480700001)(40460700003)(47076005)(83380400001)(336012)(426003)(1076003)(26005)(16526019)(82740400003)(356005)(921005)(81166007)(36860700001)(8936002)(8676002)(4326008)(478600001)(70206006)(54906003)(70586007)(110136005)(316002)(41300700001)(7416002)(2616005)(2906002)(5660300002)(7696005)(6666004)(36756003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:34.5295 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbfc5cf2-bccb-43df-dd78-08dbc190c614 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: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6172 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org From: Basavaraj Natikar Current amd_sfh driver has float_to_int() to convert units from float to int. This is fine until this function gets called outside of the current scope of file. Add a prefix "amd_sfh" to float_to_int() so that function represents the driver name. This function will be called by multiple callers in the next patch. Co-developed-by: Shyam Sundar S K Signed-off-by: Shyam Sundar S K Signed-off-by: Basavaraj Natikar --- drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c index 06bdcf072d10..47a87b28e00e 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) +static int amd_sfh_float_to_int(u32 flt32_val) { int fraction, shift, mantissa, sign, exp, zeropre; @@ -200,9 +200,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&accel_data, sensoraddr, sizeof(struct sfh_accel_data)); get_common_inputs(&acc_input.common_property, report_id); - acc_input.in_accel_x_value = float_to_int(accel_data.acceldata.x) / 100; - acc_input.in_accel_y_value = float_to_int(accel_data.acceldata.y) / 100; - acc_input.in_accel_z_value = float_to_int(accel_data.acceldata.z) / 100; + acc_input.in_accel_x_value = amd_sfh_float_to_int(accel_data.acceldata.x) / 100; + acc_input.in_accel_y_value = amd_sfh_float_to_int(accel_data.acceldata.y) / 100; + acc_input.in_accel_z_value = amd_sfh_float_to_int(accel_data.acceldata.z) / 100; memcpy(input_report, &acc_input, sizeof(acc_input)); report_size = sizeof(acc_input); break; @@ -211,9 +211,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&gyro_data, sensoraddr, sizeof(struct sfh_gyro_data)); get_common_inputs(&gyro_input.common_property, report_id); - gyro_input.in_angel_x_value = float_to_int(gyro_data.gyrodata.x) / 1000; - gyro_input.in_angel_y_value = float_to_int(gyro_data.gyrodata.y) / 1000; - gyro_input.in_angel_z_value = float_to_int(gyro_data.gyrodata.z) / 1000; + gyro_input.in_angel_x_value = amd_sfh_float_to_int(gyro_data.gyrodata.x) / 1000; + gyro_input.in_angel_y_value = amd_sfh_float_to_int(gyro_data.gyrodata.y) / 1000; + gyro_input.in_angel_z_value = amd_sfh_float_to_int(gyro_data.gyrodata.z) / 1000; memcpy(input_report, &gyro_input, sizeof(gyro_input)); report_size = sizeof(gyro_input); break; @@ -222,9 +222,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&mag_data, sensoraddr, sizeof(struct sfh_mag_data)); get_common_inputs(&magno_input.common_property, report_id); - magno_input.in_magno_x = float_to_int(mag_data.magdata.x) / 100; - magno_input.in_magno_y = float_to_int(mag_data.magdata.y) / 100; - magno_input.in_magno_z = float_to_int(mag_data.magdata.z) / 100; + magno_input.in_magno_x = amd_sfh_float_to_int(mag_data.magdata.x) / 100; + magno_input.in_magno_y = amd_sfh_float_to_int(mag_data.magdata.y) / 100; + magno_input.in_magno_z = amd_sfh_float_to_int(mag_data.magdata.z) / 100; magno_input.in_magno_accuracy = mag_data.accuracy / 100; memcpy(input_report, &magno_input, sizeof(magno_input)); report_size = sizeof(magno_input); @@ -234,7 +234,7 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, OFFSET_SENSOR_DATA_DEFAULT; memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data)); get_common_inputs(&als_input.common_property, report_id); - als_input.illuminance_value = float_to_int(als_data.lux); + als_input.illuminance_value = amd_sfh_float_to_int(als_data.lux); report_size = sizeof(als_input); memcpy(input_report, &als_input, sizeof(als_input)); break; From patchwork Sat Sep 30 08:37:14 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: 13405080 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 CADAFE77366 for ; Sat, 30 Sep 2023 08:39:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234196AbjI3Ijq (ORCPT ); Sat, 30 Sep 2023 04:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234190AbjI3Ijp (ORCPT ); Sat, 30 Sep 2023 04:39:45 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2081.outbound.protection.outlook.com [40.107.102.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 960261AE; Sat, 30 Sep 2023 01:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dVjP+lF3Fho0zD38FS6ALBSuIGvkOMdkuqRFKGGMLQrQSfXViAjdiGIw7RVv16hSX+rs07UtGbqZoRlzBcV8ZH2VYtf/74ktSPJYae1/87FIzBOmzeE1a2eJeEAep1G0CElYBtEsFln2rv6WjEjXwOcmY6uJpDLi7LUZEFTlwIvleXMePatk4s7KB5pRec7003Yx7KiYHi1SPNS3LQ2g2R5PspbzTJY9uEVaORYQ8+IxNW5ybW8DRJGAgt9KqW08IHjzQoaXsX7sjYJ5WMXSjb69VXmY2pG2xtxR1x/qa24eRxz/6gy9w3cO4Rz9BVOutZpklHHO96X74gSlpd1s/w== 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=fklZ3P9rNJ0Ckc9OJhriL1pL8CxdThHWD/2wbimzpJo=; b=YK1XPJmOa0DVI6UFDR4ifk3LblZiOBmjC/R7jqts7297DhOqzpv93NuyF3BsHjus3x21waOiR5HV4Qf8n1Tzzql3tUgQ/h+U4JPJzcB9nc58cxNA7Y8pViKeaVMnL6qGgV0iH5g/DdYiXDwwAlNQiJoDBHIRBR15cwseSZJHhM+EW9xy72gSyK5jv0o/RCENN2QQslesdEwfDt6yNrw7w6eHI1/Ya5JsLDHUr8HNwIn9CbBAg+3f934E0OGlyO3hG1NWy926obaBDOhLq8eyerZ+qHgojs58G8SyKd8G8P6a0aJTUeL/TS8wTUvyZf/Orw2ASvcCX6/tnNwxbqTSzQ== 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=fklZ3P9rNJ0Ckc9OJhriL1pL8CxdThHWD/2wbimzpJo=; b=xIE5d6J6mJnFZzUFcysLm7nuOmi4lXyfLD7Y1YGXfZDoqKEeGRIKzXMtHMSxdSYJogIcOOg7OlRlupGoR/FwSgDkemQZdz0/pv98cylwq10LkNfExsWvNnegJPazELYWntwvk2QviumUHPoVjd4B/+xy/IsZGZ0SAeLNpQ6WAWg= Received: from BL1PR13CA0076.namprd13.prod.outlook.com (2603:10b6:208:2b8::21) by SN7PR12MB8130.namprd12.prod.outlook.com (2603:10b6:806:32e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.27; Sat, 30 Sep 2023 08:39:39 +0000 Received: from BL6PEPF0001AB76.namprd02.prod.outlook.com (2603:10b6:208:2b8:cafe::41) by BL1PR13CA0076.outlook.office365.com (2603:10b6:208:2b8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.15 via Frontend Transport; Sat, 30 Sep 2023 08:39:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB76.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:39 +0000 Received: from jatayu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 30 Sep 2023 03:39:33 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v2 15/16] platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD Date: Sat, 30 Sep 2023 14:07:14 +0530 Message-ID: <20230930083715.2050863-16-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB76:EE_|SN7PR12MB8130:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e614363-5ada-4146-28f9-08dbc190c8d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AOu0IzQY0fNx/n36hetK9NUQDcRLCQshSQLIopq7T+bhshtfaL2B+I2J1lkf+ygRFEccC1puOsZKe8a8tuiw8XZbWk+i8v8nSkSaGUB4W63xjjNJ2MhSl03/Z+pkZC1Hfgm7GBQi5GSt39iyIIqV+vfG2lGDI5qcujM63Mo304VTRVwcMP8b5jNlbDtw1pR7V8y1ogbfJYJphZE7wvl+aXegHT2jCTUwvadMxIRfQAJLoFYGLd+uTF91ymgb0sfks5FPBGqVyrdwZUsr98jwvIW0y2RUxUFPmFb63t9Nbw1WUTk3NuMYOKi8ZMoaCJsD3V+7AvJct3W5C+DU0IxlRUWJoaDp1kt4caW5GqicoUInKes5tE62doOXkOn44V2DjPKE1BuondFDYHZQE05VRv4S/jxoG8D/pHfBN14B3SVKTr2EcL9hNyo/rlyFTfQ38fXIiiT0cZAPGf350nEr+MH6dGNRv2dxREJoi8ijfUPcWV40yYTrIhOmfZEMc8PdMGX2LjZ/8WBHhDLAlscrVPHFB6OqTeXlwTxQDjliN2ZSEsQpSJYhRIlfc9KrC9hcPSJCakDNkUF4J+IevmkfMJx+lhdced7CCAFXrezYipuXFWaY7O/mqBQFHwJVf9+JZnD9qjeH4EBC3dMkzRlW6Kz13DT08IwWVYY3VaIDnQ3BHYHaCQ0TaK0vCD8FRGApuhff9cvyj3L3ePv2p2yqy53go+17duGRyeuNRJNHjRkVGiJxelZ6xXKPLnqwjQBbEJKGgo5wBBvG2hiLLaE/HqeV+cBTTqxl4ZHAXnnuYsc= 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)(396003)(136003)(346002)(230922051799003)(1800799009)(64100799003)(186009)(82310400011)(451199024)(36840700001)(46966006)(40470700004)(54906003)(40460700003)(316002)(41300700001)(2616005)(1076003)(81166007)(16526019)(336012)(26005)(36756003)(426003)(86362001)(7696005)(6666004)(478600001)(82740400003)(921005)(356005)(47076005)(83380400001)(36860700001)(70206006)(70586007)(110136005)(40480700001)(7416002)(2906002)(8676002)(8936002)(4326008)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:39.1452 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e614363-5ada-4146-28f9-08dbc190c8d5 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: BL6PEPF0001AB76.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8130 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_init.c | 11 ++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 28 +++++++++++++++++++ drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/spc.c | 21 ++++++++++++++ include/linux/amd-pmf-io.h | 20 ++++++++++++- 6 files changed, 85 insertions(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index 2643bb14fee2..cd57037bf217 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -37,6 +37,10 @@ struct amd_mp2_sensor_info { dma_addr_t dma_address; }; +struct sfh_dev_status { + bool is_hpd_present; +}; + struct amd_mp2_dev { struct pci_dev *pdev; struct amdtp_cl_data *cl_data; @@ -47,6 +51,7 @@ struct amd_mp2_dev { struct amd_input_data in_data; /* mp2 active control status */ u32 mp2_acs; + struct sfh_dev_status dev_en; }; struct amd_mp2_ops { diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c index e9c6413af24a..3dc652d41d7d 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c @@ -73,6 +73,12 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) int i, status; for (i = 0; i < cl_data->num_hid_devices; i++) { + switch (cl_data->sensor_idx[i]) { + case HPD_IDX: + privdata->dev_en.is_hpd_present = false; + break; + } + if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]); status = amd_sfh_wait_for_response @@ -178,6 +184,11 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) rc = amdtp_hid_probe(i, cl_data); if (rc) goto cleanup; + switch (cl_data->sensor_idx[i]) { + case HPD_IDX: + privdata->dev_en.is_hpd_present = true; + break; + } } dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c index 4f81ef2d4f56..7637da0dec6f 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c @@ -7,11 +7,14 @@ * * Author: Basavaraj Natikar */ +#include #include #include #include "amd_sfh_interface.h" +static struct amd_mp2_dev *emp2; + static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id) { struct sfh_cmd_response cmd_resp; @@ -76,4 +79,29 @@ static struct amd_mp2_ops amd_sfh_ops = { void sfh_interface_init(struct amd_mp2_dev *mp2) { mp2->mp2_ops = &amd_sfh_ops; + emp2 = mp2; +} + +static int amd_sfh_hpd_info(u8 *user_present) +{ + if (emp2 && emp2->dev_en.is_hpd_present) { + struct hpd_status hpdstatus; + + hpdstatus.val = readl(emp2->mmio + AMD_C2P_MSG(4)); + *user_present = hpdstatus.shpd.presence; + return 0; + } + return -ENODEV; +} + +int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op) +{ + if (sfh_info) { + switch (op) { + case MT_HPD: + return amd_sfh_hpd_info(&sfh_info->user_present); + } + } + return -EINVAL; } +EXPORT_SYMBOL_GPL(amd_get_sfh_info); diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig index 0cd08f9ab51b..ca4f7d5a11b2 100644 --- a/drivers/platform/x86/amd/pmf/Kconfig +++ b/drivers/platform/x86/amd/pmf/Kconfig @@ -11,6 +11,7 @@ config AMD_PMF select ACPI_PLATFORM_PROFILE depends on AMDTEE depends on DRM_AMDGPU + depends on AMD_SFH_HID help This driver provides support for the AMD Platform Management Framework. The goal is to enhance end user experience by making AMD PCs smarter, diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c index 40872afb99e5..4fd1953167ed 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -49,6 +49,7 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * dev_dbg(dev->dev, "Primary Display State : %s\n", in->ev_info.display_state ? "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); + dev_dbg(dev->dev, "User Presence : %s\n", in->ev_info.user_present ? "Present" : "Away"); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } #else @@ -157,6 +158,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 */ @@ -166,4 +186,5 @@ void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_tab amd_pmf_get_battery_info(dev, in); amd_pmf_get_slider_info(dev, in); amd_pmf_get_gpu_info(dev, in); + amd_pmf_get_sensor_info(dev, in); } diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index 5f79e66a41b3..43e5a88d2cad 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -5,7 +5,8 @@ * Copyright (c) 2023, Advanced Micro Devices, Inc. * All Rights Reserved. * - * Author: Shyam Sundar S K + * Authors: Shyam Sundar S K + * Basavaraj Natikar */ #ifndef AMD_PMF_IO_H @@ -32,4 +33,21 @@ struct amd_gpu_pmf_data { int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf); int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf); void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); + +/* amd-sfh */ +enum sfh_message_type { + MT_HPD, +}; + +enum hpd_info { + SFH_NOT_DETECTED, + SFH_USER_PRESENT, + SFH_USER_AWAY +}; + +struct amd_sfh_info { + u8 user_present; +}; + +int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op); #endif From patchwork Sat Sep 30 08:37:15 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: 13405081 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 665B5E77351 for ; Sat, 30 Sep 2023 08:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234197AbjI3Ijv (ORCPT ); Sat, 30 Sep 2023 04:39:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234190AbjI3Ijv (ORCPT ); Sat, 30 Sep 2023 04:39:51 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2087.outbound.protection.outlook.com [40.107.94.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29AE91AE; Sat, 30 Sep 2023 01:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HFsrn/Dyj21E0Sxtbx3h2JURiYU+q2F8lAtXfRvGRJYJajdgbKOUOt1UgdwWOc27qngDwB8UsYhGDpQtbUWEzHHFqpLhf7+qhjnGIUaeGYnYkGzvl+fUhlFjq7uSTuUtWQuQIH336toiy5EZUyOQ4YI5SUGcbrqClPjJO6p1gGAlEwEQTDv1dlx+5iBU8BuZsv+iFxXeZHvNkhH64fgfYf+G72d2qslqyVj/NYeJzrqMOBwvphFyCFzDnbLPynz1wvqNiN4GyWzoFjZz6Sck5C7iUVTOxAiopV6G5EbuG3y8NDtb/LrGwaDOkTb0FIJLobc/xzgkCqckGDPe418yMg== 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=JNprEuylK+kJWqN3PvwrP8ULOynKqZnssj0Jaa2vYT8=; b=PC1v1aXyXJ+SndalrqCM6iSpnV5n50I2FZb1yhyNimx3fFmBRtk719MRfmvgA055kbjIv/HvkBWElxbj7LWZRmw/+5SGhaPIXropeV/y1yvNeD6Dt4rZWQbPGJc+IDMBFpS5A+/U3VEKewknX5cwtFiibygQEZ9Wtjrmc2isepxLm7rDSOYC6ir4mX4huI30fAL+mUmiLA3HQwKeMg482vE90JCTgJEwS7xuE7gKLdpdMLhl8WaeYhS75L6SGXJAeEotZbSZJE/VcihRs89VbFdtf+9Z3OGOhbkwSV3X3ana0LXa38gaJhIJHJiUtbhw9PP8+ulpVvYaxLUEN0Pbnw== 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=JNprEuylK+kJWqN3PvwrP8ULOynKqZnssj0Jaa2vYT8=; b=DBawKAFs9bpo+cjzbPXdtvV4Qjjsr0jqnF9ErhuzKUNGruxVW4mmF+gvWU2+pv5w/irBTK7WAeFfkO+Nsvfx2zCMy/tfLgpc3udyjiBOfLaZJi2PpnUSI9Nw6QaKi5SCBvWmnWKTe8NKhOx9IfVcpeik881SglYibUBAwg6IqM8= Received: from BL1PR13CA0076.namprd13.prod.outlook.com (2603:10b6:208:2b8::21) by CY8PR12MB8066.namprd12.prod.outlook.com (2603:10b6:930:70::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.21; Sat, 30 Sep 2023 08:39:44 +0000 Received: from BL6PEPF0001AB76.namprd02.prod.outlook.com (2603:10b6:208:2b8:cafe::14) by BL1PR13CA0076.outlook.office365.com (2603:10b6:208:2b8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.15 via Frontend Transport; Sat, 30 Sep 2023 08:39:44 +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 BL6PEPF0001AB76.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Sat, 30 Sep 2023 08:39:43 +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; Sat, 30 Sep 2023 03:39:38 -0500 From: Shyam Sundar S K To: , , , , , , , , , , CC: , , , , , , "Basavaraj Natikar" , Shyam Sundar S K Subject: [PATCH v2 16/16] platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS Date: Sat, 30 Sep 2023 14:07:15 +0530 Message-ID: <20230930083715.2050863-17-Shyam-sundar.S-k@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230930083715.2050863-1-Shyam-sundar.S-k@amd.com> References: <20230930083715.2050863-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: BL6PEPF0001AB76:EE_|CY8PR12MB8066:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ff1fae5-19e1-444d-dc99-08dbc190cbb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a/WzSxl1w1TVHv3zM8Y7m91Ec3+P/iCvhxoiBYJc3/ont4fbV+Z4idXKjZb8jTVewdg/Bv2itG7aX3h6IcVDNQbkIXlrMm7lZP6xWGqD/uE5NsAHQRzY/Ka5nr3M6hOD9T/W7sDo2fGhM06CRmIWV57hJegwz+R0x46HLaZW6OJzPLap9WlGVWBrDIbvzQLKndkvGlj5+DfVInX9YvZTHSedIxU2RJNuT7eyag2hLkRqUlk7h1TRCrYGp0IbDMGYfmHgaA4657z4c9clKv443sr1F8T0zC7tLpDeq8/Y+uziuRtrFRVoANIMCaCsbRuIWMsCkIAd5xEe2ezL23PgvAG8C9DEHxZn9MOJaqsXSWEEaZswkVtdLFDRIE4v1m5NtU2LPqDRjIg1fui+TKH7Xkf3ndwYnFycQDWfBnx1mqw2bjXpfqSkZUixHvskSvlrvnwqZKtck4rsf9Wt+2s7IiAGDtCMhMzLeSM20hXwiLjn4F5AJD0aV/TJUK22zMYG9BZOHsOJSBPZAz/D4XWN+jISh0joVnio1TSOpLozWDPFRvMwWJ1ASRHiPHx5kGnZBrpcOFrkLt4WMG2kXwgcOXDkVjo3QNT9xa3m+woxl4fXiDHPazruqbsCxFrxvDMms8KI1t1WEEE1nlaEpT6tBtNxKzcx4NnDlY4jH05Ka89CCu/4ZxkOzFURvOVEaMr0jMYX8LxPZdndRU6I4gfrB+cU30iw+ugGSoXNe6mwPX20vFXT4BpEuFsnHbZKcL3pCCdtkM1kPCyMPcjZa7enGd5pFE9bYTg/Zp1xwNubyHo= 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)(396003)(39860400002)(376002)(136003)(230922051799003)(186009)(1800799009)(64100799003)(451199024)(82310400011)(40470700004)(46966006)(36840700001)(47076005)(2906002)(40460700003)(7416002)(356005)(82740400003)(40480700001)(86362001)(81166007)(36756003)(5660300002)(921005)(4326008)(70206006)(36860700001)(83380400001)(426003)(316002)(26005)(41300700001)(1076003)(54906003)(8936002)(8676002)(2616005)(6666004)(7696005)(478600001)(70586007)(336012)(110136005)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2023 08:39:43.9733 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ff1fae5-19e1-444d-dc99-08dbc190cbb5 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: BL6PEPF0001AB76.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8066 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. make amd_sfh_float_to_int() as non-static function so that this can be called outside of the current file. 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_desc.c | 2 +- drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 6 ++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 20 +++++++++++++++++++ .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h | 1 + drivers/platform/x86/amd/pmf/spc.c | 7 +++++++ include/linux/amd-pmf-io.h | 2 ++ 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index cd57037bf217..a1950bc6e6ce 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -39,6 +39,7 @@ struct amd_mp2_sensor_info { struct sfh_dev_status { bool is_hpd_present; + bool is_als_present; }; struct amd_mp2_dev { diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c index 47a87b28e00e..dbc8c6943ca1 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c @@ -132,7 +132,7 @@ static void get_common_inputs(struct common_input_property *common, int report_i common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; } -static int amd_sfh_float_to_int(u32 flt32_val) +int amd_sfh_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 3dc652d41d7d..f2890d329459 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c @@ -77,6 +77,9 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) case HPD_IDX: privdata->dev_en.is_hpd_present = false; break; + case ALS_IDX: + privdata->dev_en.is_als_present = false; + break; } if (cl_data->sensor_sts[i] == SENSOR_ENABLED) { @@ -188,6 +191,9 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata) case HPD_IDX: privdata->dev_en.is_hpd_present = true; break; + case ALS_IDX: + privdata->dev_en.is_als_present = true; + break; } } dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c index 7637da0dec6f..48a7a450e029 100644 --- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c @@ -94,12 +94,32 @@ static int amd_sfh_hpd_info(u8 *user_present) return -ENODEV; } +static int amd_sfh_als_info(u32 *ambient_light) +{ + if (emp2 && emp2->dev_en.is_als_present) { + struct sfh_als_data als_data; + void __iomem *sensoraddr; + + sensoraddr = emp2->vsbase + + (ALS_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) + + OFFSET_SENSOR_DATA_DEFAULT; + memcpy_fromio(&als_data, sensoraddr, sizeof(struct sfh_als_data)); + *ambient_light = amd_sfh_float_to_int(als_data.lux); + + return 0; + } + + return -ENODEV; +} + int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op) { if (sfh_info) { switch (op) { case MT_HPD: return amd_sfh_hpd_info(&sfh_info->user_present); + case MT_ALS: + return amd_sfh_als_info(&sfh_info->ambient_light); } } return -EINVAL; diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h index 9d31d5b510eb..7ecddad430e4 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 amd_sfh_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 4fd1953167ed..10c35291e7ae 100644 --- a/drivers/platform/x86/amd/pmf/spc.c +++ b/drivers/platform/x86/amd/pmf/spc.c @@ -50,6 +50,7 @@ void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table * "Connected" : "disconnected/unknown"); dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : "Open"); dev_dbg(dev->dev, "User Presence : %s\n", in->ev_info.user_present ? "Present" : "Away"); + dev_dbg(dev->dev, "Ambient Light : %d\n", in->ev_info.ambient_light); dev_dbg(dev->dev, "==== TA inputs END ====\n"); } #else @@ -161,6 +162,12 @@ static void amd_pmf_get_gpu_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_ta static void amd_pmf_get_sensor_info(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in) { struct amd_sfh_info sfh_info; + int ret; + + /* get ALS data */ + ret = amd_get_sfh_info(&sfh_info, MT_ALS); + if (!ret) + in->ev_info.ambient_light = sfh_info.ambient_light; /* get HPD data */ amd_get_sfh_info(&sfh_info, MT_HPD); diff --git a/include/linux/amd-pmf-io.h b/include/linux/amd-pmf-io.h index 43e5a88d2cad..a2990c0d72f6 100644 --- a/include/linux/amd-pmf-io.h +++ b/include/linux/amd-pmf-io.h @@ -37,6 +37,7 @@ void amd_pmf_gpu_deinit(struct amd_gpu_pmf_data *pmf); /* amd-sfh */ enum sfh_message_type { MT_HPD, + MT_ALS, }; enum hpd_info { @@ -46,6 +47,7 @@ enum hpd_info { }; struct amd_sfh_info { + u32 ambient_light; u8 user_present; };