From patchwork Fri Mar 10 21:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 661929 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 B74CAC74A4B for ; Fri, 10 Mar 2023 21:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231469AbjCJVWg (ORCPT ); Fri, 10 Mar 2023 16:22:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbjCJVWe (ORCPT ); Fri, 10 Mar 2023 16:22:34 -0500 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2052.outbound.protection.outlook.com [40.107.102.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC6A212B7DA; Fri, 10 Mar 2023 13:22:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=by/igJ5XMCXz8aQ5i7qejWGCEYR/vzA7vta1HkhuHSHy4OMpQvQnrZ1J81QrWYypkdxybRdBRUZUiw6B1BYdVwrqltdP7EtqZtELpno2v3FlmbE/9XCw1osDL7TubyYU2cLW3lL2zC3GetVhDaewOckYgLuCp4LYidZEojBRm2T8bbQhwwykHUv58hLXByGbumhdOJJe8zljkYeqKUmqcI72IWWblsszj3ozuMFVL6MWKA5h6PKZWbK2lGxL8HMyUZY9gJaMJB6egJjdQYoJe6V8KH/uGFbpzTfzy7lYuwhDjaupWOegr8QhU9wuGCAFuG5ZjOKDWaEpyf0puzjJXA== 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=nuFABClax6BVJFKjxf0andJaMVVcPdFZx4+m4olz05g=; b=PALYE61ZvNRS5WjNTJdB2tKqh18VYAuKuzxX6JrFwVbt4/2TweOjnEDH+aAKVKoopc4F58Kt5E38qC248yC550gJ5DS2LFjaR/nzX17mokAXrueVIgJZ2U4ouEDVgtC0f5emiVwjzUfmf3iOq5An9p7rQw1oc07EHre2/BQNY3iaZ5YjoIw7weFW8LHmlm5hB4xx6MNHhg5Jo6E93ukk4gdU9iBiGJjNAAD8PM1lz+hwsIh04zRnpejNg51JFWEnuEY+uHOywPL5OyJtSskI1UzRfLgOjOs8KIoinO3pXbXbEnfR7Q0wiDty44tWJXrdgQG18ne6wKY5m9BdVF8CpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=semihalf.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=nuFABClax6BVJFKjxf0andJaMVVcPdFZx4+m4olz05g=; b=gHPRCVTD/ooroqEcJb8afFe1uufC4TMGlkgasW5H+GVXbb/YBLVQEbPy9u+H69QDvGX1KMgdHM6+Sim9C9ZVYlSuzlRJALgtuGBjDFXsCLq+Bqzyk8htM11zpkeopKNTd8DHEUoDGUmtitg5b7mkow0ImavobHn1XMBB04LBqWg= Received: from DS7PR05CA0027.namprd05.prod.outlook.com (2603:10b6:5:3b9::32) by LV2PR12MB5944.namprd12.prod.outlook.com (2603:10b6:408:14f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19; Fri, 10 Mar 2023 21:22:26 +0000 Received: from DM6NAM11FT075.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b9:cafe::b7) by DS7PR05CA0027.outlook.office365.com (2603:10b6:5:3b9::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19 via Frontend Transport; Fri, 10 Mar 2023 21:22:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT075.mail.protection.outlook.com (10.13.173.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:26 +0000 Received: from AUS-LX-MLIMONCI.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.2375.34; Fri, 10 Mar 2023 15:22:24 -0600 From: Mario Limonciello To: =?utf-8?b?SmFuIETEhWJyb8Wb?= , Grzegorz Bernacki , , , , Sean Christopherson , "Paolo Bonzini" , Brijesh Singh , "Tom Lendacky" , John Allen , "Jarkko Nikula" , Andy Shevchenko , Mika Westerberg CC: , Mario Limonciello , "Sumit Garg" , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , "David S. Miller" , Jens Wiklander , , , , , Subject: [PATCH v4 2/8] crypto: ccp: Add a header for multiple drivers to use `__psp_pa` Date: Fri, 10 Mar 2023 15:19:45 -0600 Message-ID: <20230310211954.2490-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230310211954.2490-1-mario.limonciello@amd.com> References: <20230310211954.2490-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT075:EE_|LV2PR12MB5944:EE_ X-MS-Office365-Filtering-Correlation-Id: 5db611bd-8975-4bab-ae3e-08db21ad8bc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eBNEFJ+QyQefx9AbDbTUifCFyQlm0ARnqK9CxDH/pnz6CGXMVFu1Ek0mPa1AXAJXa8a0RQiGI0QJwvdyqQNi/8WYOj8DVtF9OFXHX59jdUGiT/6CRnYdT7CQnO0WHrArGBkE7q6AZMLBtXV0P4Um4o78gBXH4/UQzYPM/dzI89+SNJSXvypWixbHxaWrtxZdTjmQrUENWVfOYUyortj54OOF3NBUjKSsRjUvsGeCz7dpSzOWLL1s/Lu+W53zjX7D0ZF9zZzeJ6xeAdLnda4tBe1XspQttMYkWeXFQGpACHAXbq8tK+RFCuVbxEmYDMY0rN1z8YpzlmYjMHV9ROYZwlY42ewSrN1P03gK0J+oL8ikQlmfkkMXrnzRXFcU0snqOIIFn1RWT8PLGGBIyzMFmGD8bvuGMQQCwRRxn5IviYhKZdV4N7S3if4BYr7/intbLWKSd4qcHB1LhAr7yMYLU841oj8FOqs86BasvrrwuwE0B92JvAn5e0RYnQz6nD4t9rrAWTQccL3G6s1hvShgvCrgjuudFvVD9qa7y+k5Vj0J9YZj5k60+Y/3dw+pPw0EOMwzjGNNZo25aGGKWd0YzSnh59JqcrBNkCpq8rU/wfBDK3W7oB4+Zq24WhXlu7Sfq0UZ53w5zgCDA1zy9er2HoxMNcsilhaEUwWvdJI0nP30ImUea1W5pb4n7IUuY0mGyiZnRxcLJeibhqM5i3b4A4J7M4aZMz2loH2oePlq0kcmAtSaM4GZRrMe7SSRS4h+X8uKTbv3NqKbtFuuMrhZgQ== 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:(13230025)(4636009)(376002)(346002)(136003)(39860400002)(396003)(451199018)(46966006)(40470700004)(36840700001)(82310400005)(1076003)(82740400003)(36860700001)(83380400001)(47076005)(426003)(36756003)(40480700001)(110136005)(54906003)(478600001)(921005)(316002)(356005)(41300700001)(7696005)(2616005)(81166007)(6666004)(186003)(26005)(16526019)(7416002)(70206006)(44832011)(40460700003)(336012)(5660300002)(8936002)(70586007)(4326008)(2906002)(86362001)(8676002)(81973001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 21:22:26.0257 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5db611bd-8975-4bab-ae3e-08db21ad8bc4 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: DM6NAM11FT075.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5944 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The TEE subdriver for CCP, the amdtee driver and the i2c-designware-amdpsp drivers all include `psp-sev.h` even though they don't use SEV functionality. Move the definition of `__psp_pa` into a common header to be included by all of these drivers. Reviewed-by: Jan Dabros Acked-by: Jarkko Nikula # For the drivers/i2c/busses/i2c-designware-amdpsp.c Acked-by: Sumit Garg # For TEE subsystem bits Acked-by: Tom Lendacky Acked-by: Sean Christopherson # KVM Signed-off-by: Mario Limonciello --- v3->v4: * Pick up tags v1->v2: * Add tags --- arch/x86/kvm/svm/sev.c | 1 + drivers/crypto/ccp/sev-dev.c | 1 + drivers/crypto/ccp/tee-dev.c | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 2 +- drivers/tee/amdtee/call.c | 2 +- drivers/tee/amdtee/shm_pool.c | 2 +- include/linux/psp-sev.h | 8 -------- include/linux/psp.h | 14 ++++++++++++++ 8 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 include/linux/psp.h diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c25aeb550cd9..ec18a756b7c9 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index e2f25926eb51..28945ca7c856 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index 5c9d47f3be37..f24fc953718a 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include "psp-dev.h" diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 8f36167bce62..80f28a1bbbef 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/tee/amdtee/call.c b/drivers/tee/amdtee/call.c index cec6e70f0ac9..e8cd9aaa3467 100644 --- a/drivers/tee/amdtee/call.c +++ b/drivers/tee/amdtee/call.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "amdtee_if.h" #include "amdtee_private.h" diff --git a/drivers/tee/amdtee/shm_pool.c b/drivers/tee/amdtee/shm_pool.c index f87f96a291c9..f0303126f199 100644 --- a/drivers/tee/amdtee/shm_pool.c +++ b/drivers/tee/amdtee/shm_pool.c @@ -5,7 +5,7 @@ #include #include -#include +#include #include "amdtee_private.h" static int pool_op_alloc(struct tee_shm_pool *pool, struct tee_shm *shm, diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 1595088c428b..7fd17e82bab4 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -14,14 +14,6 @@ #include -#ifdef CONFIG_X86 -#include - -#define __psp_pa(x) __sme_pa(x) -#else -#define __psp_pa(x) __pa(x) -#endif - #define SEV_FW_BLOB_MAX_SIZE 0x4000 /* 16KB */ /** diff --git a/include/linux/psp.h b/include/linux/psp.h new file mode 100644 index 000000000000..202162487ec3 --- /dev/null +++ b/include/linux/psp.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __PSP_H +#define __PSP_H + +#ifdef CONFIG_X86 +#include + +#define __psp_pa(x) __sme_pa(x) +#else +#define __psp_pa(x) __pa(x) +#endif + +#endif /* __PSP_H */ From patchwork Fri Mar 10 21:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 662285 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 848EAC6FD1E for ; Fri, 10 Mar 2023 21:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbjCJVWf (ORCPT ); Fri, 10 Mar 2023 16:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbjCJVWd (ORCPT ); Fri, 10 Mar 2023 16:22:33 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2085.outbound.protection.outlook.com [40.107.93.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9ED612B678; Fri, 10 Mar 2023 13:22:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GA1IvTIs/VqASsfvvlHhSGqzv3niNa+dmuyP/iUqx58nrXBLXM/fZ9aE6I7Sl8PAHW0J/XLcTfrDnIVWbGc69vH2fwWuKIjXqdmJO92SIOB4VUxdZo6Mw5pstn+E++rr7vdQFAjS/yaduH65jgqq1EfR38duUm8ySEfuM0pASv7+RqS3NG8wkvUV9ei+JPrdmMMOq186o9WRoCPDm3KA19EmCiMo6qgQ1a7v70hehekOkv04pOdVIwe+HcpElzGLxDXtDHvZhALbtR9/9RKuMGfUd7vd+6Q4s25bPQs0fK4dlLs6hXGhXqjuRxmWGodIFt2JPJ+T8+wd8DdBDYs4Dg== 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=6q7FD/5mu+whLXnEGkQAs5KJT9bvxS5gDy2C5Zt4ToU=; b=JZDBd+viJg5fsmjLlPVfASMJXAs4e6VphCTnS96ZdORcpEvXAx9fcJcD2wmihTrNkVkv+pxK9kSsZJmd7Ud0DFoaaMrnP59dOLg34SHQGtXEyR9C5cJfzXfewUd17y3YloP9U55v0B9SqX7BqtnFKi00ArMHcoSYsaZqMWz2ohiHpR710LnCWzmkS4JxEyBnFXKeNMG/Jhp1CiXmfJYdtFcmffSSKU3rKIKI4MUuTV7gECaujtWMguTZ39WGoaA+xrBEjzuG2ysW+HAjVnbOizzUsLoZdyEl3aNSRIpwc0cJIXRqMjKojdCeTvmlXXnTIvZdmL2CdvcMX2eIvAqE8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=semihalf.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=6q7FD/5mu+whLXnEGkQAs5KJT9bvxS5gDy2C5Zt4ToU=; b=DXmaUCB7hQAKExo8ioPNIMMjNccUM1ozY51SunQlN01OExYY3BvkjEHQvERhecW8U5uz5a/YulLVNyNgKGVMCEF32aeexKDcMU5v7d5eIkjUkojZVKj3B5rMsdxXfKP1POE2J4cBUtk7rIylyt9a6dWQ4lmDLqCdesZpCAOrXRM= Received: from DM6PR12CA0030.namprd12.prod.outlook.com (2603:10b6:5:1c0::43) by CY5PR12MB6405.namprd12.prod.outlook.com (2603:10b6:930:3e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17; Fri, 10 Mar 2023 21:22:28 +0000 Received: from DM6NAM11FT070.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::d9) by DM6PR12CA0030.outlook.office365.com (2603:10b6:5:1c0::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:28 +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 DM6NAM11FT070.mail.protection.outlook.com (10.13.173.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:27 +0000 Received: from AUS-LX-MLIMONCI.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.2375.34; Fri, 10 Mar 2023 15:22:26 -0600 From: Mario Limonciello To: =?utf-8?b?SmFuIETEhWJyb8Wb?= , Grzegorz Bernacki , , , , Tom Lendacky , "John Allen" , Brijesh Singh , "Jarkko Nikula" , Andy Shevchenko , Mika Westerberg CC: , Mario Limonciello , "David S. Miller" , , , Subject: [PATCH v4 3/8] crypto: ccp: Move some PSP mailbox bit definitions into common header Date: Fri, 10 Mar 2023 15:19:46 -0600 Message-ID: <20230310211954.2490-4-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230310211954.2490-1-mario.limonciello@amd.com> References: <20230310211954.2490-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT070:EE_|CY5PR12MB6405:EE_ X-MS-Office365-Filtering-Correlation-Id: f051f798-07b5-4462-f918-08db21ad8cde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gGC5oBDTwa9HK8SjJjrk2zTom9j12Eki4vC5UYziFBpSZAioIh/mU4HM7btARAJyEfxBWzsgbN3gsJRpbFoLP5wn+BJGn48+Mu/DOcDqjkkaG27rXbhsVFYpCwStcZsM8ebXsrCIDw/ul1L3yMkhtUn0Q6lwXxDkmmphvrzKfE/42PGS4GDJq2DmNzdh4QNRLFFM3tVrT65cAFpNku69pNczVoPNl2CFklkCh+qhcHmb4Ig+to2kT29TESE8e7aKLpt2KgC/1TS5v7mqyjiut8lE8oqN/vPQZBEIpdV5AKTup+/o1lnRBEy1ha0+wBP2weS14hPeb2U1KCmOtVHOG2RZ8kGb1WL3Ecj9g0uNOkKkgSRW6mR7WQdTt7ly3Vo5q9upPYhAzbF4FZzvpDy/3PkZRKAXONABmhMTRLE9Hda7njDl7r/xOImTMgdFNqhjT8Qe+YA/Z3FCYymBazcH2QQQixCqVvX81ti/P62Jm9vWVvs33kG02CcazibIsczahmwVlNxwDvuej8+eCcoV1R94cFs7zvy5/rAF8TefMGJNrDqAbjbcrraF31RvusBaE199tbHzStGcqY340zsvljtMQX2RNkcbvTHChgcE4a36C9q7MieA5yX9qhWZRO2QdbqnM8LQ4aSkrJ7k4njh2z7iM/jS3NYTV/0WgDF8CtRMRNpc4AQX5obqbx65UIzt/skoDoVuOmtViodWDnUetg55mActzYPCXJVxWn2/RjcXOAZ2waT0cf8BAOMsVD8h 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:(13230025)(4636009)(39860400002)(346002)(376002)(396003)(136003)(451199018)(36840700001)(40470700004)(46966006)(478600001)(82310400005)(44832011)(186003)(7416002)(16526019)(5660300002)(83380400001)(26005)(1076003)(40480700001)(2616005)(336012)(47076005)(426003)(86362001)(36860700001)(6666004)(36756003)(15650500001)(40460700003)(356005)(2906002)(70206006)(316002)(8676002)(41300700001)(81166007)(4326008)(70586007)(82740400003)(7696005)(921005)(54906003)(8936002)(110136005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 21:22:27.8757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f051f798-07b5-4462-f918-08db21ad8cde 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: DM6NAM11FT070.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6405 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Some of the bits and fields used for mailboxes communicating with the PSP are common across all mailbox implementations (SEV, TEE, etc). Move these bits into the common `linux/psp.h` so they don't need to be re-defined for each implementation. Acked-by: Rijo Thomas Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello Acked-by: Jarkko Nikula --- v3->v4: * Pick up tags v2->v3: * Pick up tags v1->v2: * Update comment to indicate it's PSP response not PSP ready --- drivers/crypto/ccp/psp-dev.h | 3 --- drivers/crypto/ccp/sev-dev.c | 15 +++++++-------- drivers/crypto/ccp/sev-dev.h | 2 +- drivers/crypto/ccp/tee-dev.c | 15 ++++++++------- drivers/i2c/busses/i2c-designware-amdpsp.c | 16 +++++----------- include/linux/psp.h | 12 ++++++++++++ 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h index 06e1f317216d..55f54bb2b3fb 100644 --- a/drivers/crypto/ccp/psp-dev.h +++ b/drivers/crypto/ccp/psp-dev.h @@ -17,9 +17,6 @@ #include "sp-dev.h" -#define PSP_CMDRESP_RESP BIT(31) -#define PSP_CMDRESP_ERR_MASK 0xffff - #define MAX_PSP_NAME_LEN 16 extern struct psp_device *psp_master; diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 28945ca7c856..6440d35dfa4e 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -7,6 +7,7 @@ * Author: Brijesh Singh */ +#include #include #include #include @@ -103,7 +104,7 @@ static void sev_irq_handler(int irq, void *data, unsigned int status) /* Check if it is SEV command completion: */ reg = ioread32(sev->io_regs + sev->vdata->cmdresp_reg); - if (reg & PSP_CMDRESP_RESP) { + if (FIELD_GET(PSP_CMDRESP_RESP, reg)) { sev->int_rcvd = 1; wake_up(&sev->int_queue); } @@ -347,9 +348,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) sev->int_rcvd = 0; - reg = cmd; - reg <<= SEV_CMDRESP_CMD_SHIFT; - reg |= SEV_CMDRESP_IOC; + reg = FIELD_PREP(SEV_CMDRESP_CMD, cmd) | SEV_CMDRESP_IOC; iowrite32(reg, sev->io_regs + sev->vdata->cmdresp_reg); /* wait for command completion */ @@ -367,11 +366,11 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) psp_timeout = psp_cmd_timeout; if (psp_ret) - *psp_ret = reg & PSP_CMDRESP_ERR_MASK; + *psp_ret = FIELD_GET(PSP_CMDRESP_STS, reg); - if (reg & PSP_CMDRESP_ERR_MASK) { - dev_dbg(sev->dev, "sev command %#x failed (%#010x)\n", - cmd, reg & PSP_CMDRESP_ERR_MASK); + if (FIELD_GET(PSP_CMDRESP_STS, reg)) { + dev_dbg(sev->dev, "sev command %#x failed (%#010lx)\n", + cmd, FIELD_GET(PSP_CMDRESP_STS, reg)); ret = -EIO; } else { ret = sev_write_init_ex_file_if_required(cmd); diff --git a/drivers/crypto/ccp/sev-dev.h b/drivers/crypto/ccp/sev-dev.h index 666c21eb81ab..778c95155e74 100644 --- a/drivers/crypto/ccp/sev-dev.h +++ b/drivers/crypto/ccp/sev-dev.h @@ -25,8 +25,8 @@ #include #include +#define SEV_CMDRESP_CMD GENMASK(26, 16) #define SEV_CMD_COMPLETE BIT(1) -#define SEV_CMDRESP_CMD_SHIFT 16 #define SEV_CMDRESP_IOC BIT(0) struct sev_misc_dev { diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c index f24fc953718a..5560bf8329a1 100644 --- a/drivers/crypto/ccp/tee-dev.c +++ b/drivers/crypto/ccp/tee-dev.c @@ -8,6 +8,7 @@ * Copyright (C) 2019,2021 Advanced Micro Devices, Inc. */ +#include #include #include #include @@ -69,7 +70,7 @@ static int tee_wait_cmd_poll(struct psp_tee_device *tee, unsigned int timeout, while (--nloop) { *reg = ioread32(tee->io_regs + tee->vdata->cmdresp_reg); - if (*reg & PSP_CMDRESP_RESP) + if (FIELD_GET(PSP_CMDRESP_RESP, *reg)) return 0; usleep_range(10000, 10100); @@ -149,9 +150,9 @@ static int tee_init_ring(struct psp_tee_device *tee) goto free_buf; } - if (reg & PSP_CMDRESP_ERR_MASK) { - dev_err(tee->dev, "tee: ring init command failed (%#010x)\n", - reg & PSP_CMDRESP_ERR_MASK); + if (FIELD_GET(PSP_CMDRESP_STS, reg)) { + dev_err(tee->dev, "tee: ring init command failed (%#010lx)\n", + FIELD_GET(PSP_CMDRESP_STS, reg)); tee_free_ring(tee); ret = -EIO; } @@ -179,9 +180,9 @@ static void tee_destroy_ring(struct psp_tee_device *tee) ret = tee_wait_cmd_poll(tee, TEE_DEFAULT_TIMEOUT, ®); if (ret) { dev_err(tee->dev, "tee: ring destroy command timed out\n"); - } else if (reg & PSP_CMDRESP_ERR_MASK) { - dev_err(tee->dev, "tee: ring destroy command failed (%#010x)\n", - reg & PSP_CMDRESP_ERR_MASK); + } else if (FIELD_GET(PSP_CMDRESP_STS, reg)) { + dev_err(tee->dev, "tee: ring destroy command failed (%#010lx)\n", + FIELD_GET(PSP_CMDRESP_STS, reg)); } free_ring: diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 80f28a1bbbef..652e6b64bd5f 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -25,12 +25,6 @@ #define PSP_I2C_REQ_STS_BUS_BUSY 0x1 #define PSP_I2C_REQ_STS_INV_PARAM 0x3 -#define PSP_MBOX_FIELDS_STS GENMASK(15, 0) -#define PSP_MBOX_FIELDS_CMD GENMASK(23, 16) -#define PSP_MBOX_FIELDS_RESERVED GENMASK(29, 24) -#define PSP_MBOX_FIELDS_RECOVERY BIT(30) -#define PSP_MBOX_FIELDS_READY BIT(31) - struct psp_req_buffer_hdr { u32 total_size; u32 status; @@ -99,15 +93,15 @@ static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) tmp = readl(&mbox->cmd_fields); - return FIELD_GET(PSP_MBOX_FIELDS_RECOVERY, tmp); + return FIELD_GET(PSP_CMDRESP_RECOVERY, tmp); } static int psp_wait_cmd(struct psp_mbox __iomem *mbox) { u32 tmp, expected; - /* Expect mbox_cmd to be cleared and ready bit to be set by PSP */ - expected = FIELD_PREP(PSP_MBOX_FIELDS_READY, 1); + /* Expect mbox_cmd to be cleared and the response bit to be set by PSP */ + expected = FIELD_PREP(PSP_CMDRESP_RESP, 1); /* * Check for readiness of PSP mailbox in a tight loop in order to @@ -124,7 +118,7 @@ static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) cmd_reg = readl(&mbox->cmd_fields); - return FIELD_GET(PSP_MBOX_FIELDS_STS, cmd_reg); + return FIELD_GET(PSP_CMDRESP_STS, cmd_reg); } static int psp_send_cmd(struct psp_i2c_req *req) @@ -148,7 +142,7 @@ static int psp_send_cmd(struct psp_i2c_req *req) writeq(req_addr, &mbox->i2c_req_addr); /* Write command register to trigger processing */ - cmd_reg = FIELD_PREP(PSP_MBOX_FIELDS_CMD, PSP_I2C_REQ_BUS_CMD); + cmd_reg = FIELD_PREP(PSP_CMDRESP_CMD, PSP_I2C_REQ_BUS_CMD); writel(cmd_reg, &mbox->cmd_fields); if (psp_wait_cmd(mbox)) diff --git a/include/linux/psp.h b/include/linux/psp.h index 202162487ec3..d3424790a70e 100644 --- a/include/linux/psp.h +++ b/include/linux/psp.h @@ -11,4 +11,16 @@ #define __psp_pa(x) __pa(x) #endif +/* + * Fields and bits used by most PSP mailboxes + * + * Note: Some mailboxes (such as SEV) have extra bits or different meanings + * and should include an appropriate local definition in their source file. + */ +#define PSP_CMDRESP_STS GENMASK(15, 0) +#define PSP_CMDRESP_CMD GENMASK(23, 16) +#define PSP_CMDRESP_RESERVED GENMASK(29, 24) +#define PSP_CMDRESP_RECOVERY BIT(30) +#define PSP_CMDRESP_RESP BIT(31) + #endif /* __PSP_H */ From patchwork Fri Mar 10 21:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 662284 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 A5F32C6FD1E for ; Fri, 10 Mar 2023 21:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjCJVWj (ORCPT ); Fri, 10 Mar 2023 16:22:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbjCJVWh (ORCPT ); Fri, 10 Mar 2023 16:22:37 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2073.outbound.protection.outlook.com [40.107.220.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BE4212B3F0; Fri, 10 Mar 2023 13:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UStir/59o3b8SfBANCkrZDpk4voxqc7gPW2U5+mv0cNB/A8i0XmLI1xeKAXBgaD31uqnH7o7aEBNoIZVAG1OlxeTF297Z2feJ9FjknbV1vxIdgQyQACsEozIf3hvF7LQiS3NtmzF4RJvmzgeY8QZUjIFRPHvxuvMHsizNwwpvPhP0CEOgfK0JTCifz+jYMhA9kojTs/SpIH9qGpE5yiau2RdOcZLxQZUNN0N4xI2dBUfHQjcDh0xWTGJG+iPefaKRNCTIIi0QvbY5s7e27gmgb5Q3hqXl9s9iGIZN1iXlZIT/RrSJvzLNkHK5tmbLLNAmYBDRzZEQ2pmNP4EHFtifQ== 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=mdS6w+aukh3VCSO/pzBCBON98EhgpUf7eO4q4hmDRTw=; b=H6jfJ3zjP/+TRgNgKvUexFnqZv1Mf+Wmz1izB7SWyHqirX7NlZGlUF36RzLVdFbveZT9D2jpPxZCTqT0I7Nv8hsL5H08gEVCmeJV1wepopsn+Nuwy4NkYV1Z0tTf90g2KqWd0HrB0kBoKkGuoAm8ltt2OSB84dZTj4ax9OQ0S/AMwxRr6qPDpH3OXFnGTQ67+7RsvX2DCRzWgzEIF1rJKFHDM7IcQXqbMdp9lubmFlW6GIqFOoE9ofUfCTqpW34VGAbTJ6mIDfEqidsOZQJoaqnXRHV1n9bSnT/fMd/57ITGoErXkGZohRqEpvp9cbA+mCO8rJiDLNlaL5s5qR78sQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=semihalf.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=mdS6w+aukh3VCSO/pzBCBON98EhgpUf7eO4q4hmDRTw=; b=ohVQHuliSkfdTVKZo0R/1kuiznr3lMXQC/GPNhrBuzb9LCe9a5IC3HNvVs+f2www1TfOHqfDl8NcLJxuQQAgMGO7nIgM9Ag+ee9EyMhw1nN7D1NxeePloXpyR8WtjYFwwTjYnxDfcBEvharVybdK9Q68SQj/EizKh9qNS0H7VpU= Received: from DM6PR12CA0030.namprd12.prod.outlook.com (2603:10b6:5:1c0::43) by IA1PR12MB8359.namprd12.prod.outlook.com (2603:10b6:208:3fc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.20; Fri, 10 Mar 2023 21:22:32 +0000 Received: from DM6NAM11FT070.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::d9) by DM6PR12CA0030.outlook.office365.com (2603:10b6:5:1c0::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:32 +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 DM6NAM11FT070.mail.protection.outlook.com (10.13.173.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:32 +0000 Received: from AUS-LX-MLIMONCI.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.2375.34; Fri, 10 Mar 2023 15:22:31 -0600 From: Mario Limonciello To: =?utf-8?b?SmFuIETEhWJyb8Wb?= , Grzegorz Bernacki , , , , Jarkko Nikula , Andy Shevchenko , Mika Westerberg CC: , Mario Limonciello , "Tom Lendacky" , , Subject: [PATCH v4 6/8] i2c: designware: Use PCI PSP driver for communication Date: Fri, 10 Mar 2023 15:19:49 -0600 Message-ID: <20230310211954.2490-7-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230310211954.2490-1-mario.limonciello@amd.com> References: <20230310211954.2490-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT070:EE_|IA1PR12MB8359:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bd8f7c2-2074-439e-b79b-08db21ad8fb3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OtjDEb5ROKcwo1A7Z4mdbfuxri3kkt+lwaRysCUwXjs5zmu/MinjNa5CIwbvPqhksiuqcLI6Lupwnj8zklr9A78jb1SwAKuP+355y9BVjAnCKqdlUZOUTJD5cgiOcopAsPJmscTX2gtG2vCEPhvDYWmY12SAGoRVS3gbOu3lcIXYPVLNYvqsNhx3ctIRaQfEnrHuwWfqNaltHSzL0xxF7Rv6YrAbhkFO5xLbHmmxDggAO61+7B7rb/Tl/na/I+Hj7w4vy1/NxxvW8VgDKAa7e8Lbtp/8KNyL6aIKbMiislioJlXoxWadV5gLQIrEDDr33spXtLvxS//j6XFjLR9gd71WHTKAUJDkDgtjAs5D6InrJ9F6rCMV2wHPQrygphnmaiLrA/SNegnvZEvzjDKX7auUdzKXasCaQUf1A+RFF/ltCPfLcZPKB4ehe5IN5lCYERWc/MdLqeT8e/Vd9VJ/8tmJ//MWrqfOaEOqKafcChXuy2ePlatGMBCU0o/UzLeqz7obA/LAzJx35wIrBxjMhHhdG4Y9UfCugrjzffPxGktTRNhNt1OOMpZX5ygNepKqnXmlEhyRKR2B9TW3owKA8sXbCOFK62SYxg9LuAQpjMizPJ1bxcjKQZdyia6gHAWZSKAbhB1/vfm5SHYOv+6N1Xv8bo7L3w29uHgvEFVLJ6yD1aRsK0IGyXjAwC4WeHlnpoZMlQRwT0HAralQuMfsCvsLqCuiak9h3SJtFcTlkEo= 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:(13230025)(4636009)(39860400002)(376002)(136003)(396003)(346002)(451199018)(36840700001)(46966006)(40470700004)(82310400005)(82740400003)(36860700001)(6666004)(83380400001)(47076005)(426003)(36756003)(478600001)(110136005)(54906003)(81166007)(356005)(316002)(40460700003)(336012)(186003)(2616005)(26005)(40480700001)(1076003)(16526019)(7696005)(5660300002)(2906002)(44832011)(70206006)(41300700001)(8676002)(70586007)(8936002)(86362001)(4326008)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 21:22:32.6254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd8f7c2-2074-439e-b79b-08db21ad8fb3 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: DM6NAM11FT070.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8359 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently the PSP semaphore communication base address is discovered by using an MSR that is not architecturally guaranteed for future platforms. Also the mailbox that is utilized for communication with the PSP may have other consumers in the kernel, so it's better to make all communication go through a single driver. Acked-by: Tom Lendacky Signed-off-by: Mario Limonciello Acked-by: Jarkko Nikula --- v3->v4: * Pick up tags v1->v2: * Fix Kconfig to use imply * Use IS_REACHABLE --- drivers/i2c/busses/Kconfig | 2 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 142 ++------------------ drivers/i2c/busses/i2c-designware-core.h | 1 - drivers/i2c/busses/i2c-designware-platdrv.c | 1 - include/linux/psp-platform-access.h | 1 + 5 files changed, 11 insertions(+), 136 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 25eb4e8fd22f..d53bf716f97d 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -566,9 +566,9 @@ config I2C_DESIGNWARE_PLATFORM config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" - depends on X86_MSR depends on ACPI depends on I2C_DESIGNWARE_PLATFORM + imply CRYPTO_DEV_SP_PSP help This driver enables managed host access to the selected I2C bus shared between AMD CPU and AMD PSP. diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 652e6b64bd5f..105584abcf8f 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -1,11 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include #include -#include +#include #include -#include #include #include @@ -13,23 +10,15 @@ #include "i2c-designware-core.h" #define MSR_AMD_PSP_ADDR 0xc00110a2 -#define PSP_MBOX_OFFSET 0x10570 -#define PSP_CMD_TIMEOUT_US (500 * USEC_PER_MSEC) #define PSP_I2C_RESERVATION_TIME_MS 100 -#define PSP_I2C_REQ_BUS_CMD 0x64 #define PSP_I2C_REQ_RETRY_CNT 400 #define PSP_I2C_REQ_RETRY_DELAY_US (25 * USEC_PER_MSEC) #define PSP_I2C_REQ_STS_OK 0x0 #define PSP_I2C_REQ_STS_BUS_BUSY 0x1 #define PSP_I2C_REQ_STS_INV_PARAM 0x3 -struct psp_req_buffer_hdr { - u32 total_size; - u32 status; -}; - enum psp_i2c_req_type { PSP_I2C_REQ_ACQUIRE, PSP_I2C_REQ_RELEASE, @@ -41,119 +30,12 @@ struct psp_i2c_req { enum psp_i2c_req_type type; }; -struct psp_mbox { - u32 cmd_fields; - u64 i2c_req_addr; -} __packed; - static DEFINE_MUTEX(psp_i2c_access_mutex); static unsigned long psp_i2c_sem_acquired; -static void __iomem *mbox_iomem; static u32 psp_i2c_access_count; static bool psp_i2c_mbox_fail; static struct device *psp_i2c_dev; -/* - * Implementation of PSP-x86 i2c-arbitration mailbox introduced for AMD Cezanne - * family of SoCs. - */ - -static int psp_get_mbox_addr(unsigned long *mbox_addr) -{ - unsigned long long psp_mmio; - - if (rdmsrl_safe(MSR_AMD_PSP_ADDR, &psp_mmio)) - return -EIO; - - *mbox_addr = (unsigned long)(psp_mmio + PSP_MBOX_OFFSET); - - return 0; -} - -static int psp_mbox_probe(void) -{ - unsigned long mbox_addr; - int ret; - - ret = psp_get_mbox_addr(&mbox_addr); - if (ret) - return ret; - - mbox_iomem = ioremap(mbox_addr, sizeof(struct psp_mbox)); - if (!mbox_iomem) - return -ENOMEM; - - return 0; -} - -/* Recovery field should be equal 0 to start sending commands */ -static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) -{ - u32 tmp; - - tmp = readl(&mbox->cmd_fields); - - return FIELD_GET(PSP_CMDRESP_RECOVERY, tmp); -} - -static int psp_wait_cmd(struct psp_mbox __iomem *mbox) -{ - u32 tmp, expected; - - /* Expect mbox_cmd to be cleared and the response bit to be set by PSP */ - expected = FIELD_PREP(PSP_CMDRESP_RESP, 1); - - /* - * Check for readiness of PSP mailbox in a tight loop in order to - * process further as soon as command was consumed. - */ - return readl_poll_timeout(&mbox->cmd_fields, tmp, (tmp == expected), - 0, PSP_CMD_TIMEOUT_US); -} - -/* Status equal to 0 means that PSP succeed processing command */ -static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) -{ - u32 cmd_reg; - - cmd_reg = readl(&mbox->cmd_fields); - - return FIELD_GET(PSP_CMDRESP_STS, cmd_reg); -} - -static int psp_send_cmd(struct psp_i2c_req *req) -{ - struct psp_mbox __iomem *mbox = mbox_iomem; - phys_addr_t req_addr; - u32 cmd_reg; - - if (psp_check_mbox_recovery(mbox)) - return -EIO; - - if (psp_wait_cmd(mbox)) - return -EBUSY; - - /* - * Fill mailbox with address of command-response buffer, which will be - * used for sending i2c requests as well as reading status returned by - * PSP. Use physical address of buffer, since PSP will map this region. - */ - req_addr = __psp_pa((void *)req); - writeq(req_addr, &mbox->i2c_req_addr); - - /* Write command register to trigger processing */ - cmd_reg = FIELD_PREP(PSP_CMDRESP_CMD, PSP_I2C_REQ_BUS_CMD); - writel(cmd_reg, &mbox->cmd_fields); - - if (psp_wait_cmd(mbox)) - return -ETIMEDOUT; - - if (psp_check_mbox_sts(mbox)) - return -EIO; - - return 0; -} - /* Helper to verify status returned by PSP */ static int check_i2c_req_sts(struct psp_i2c_req *req) { @@ -182,10 +64,10 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req) * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too * long. * In order to distinguish between these two in error handling code, all - * errors on the first level (returned by psp_send_cmd) are shadowed by + * errors on the first level (returned by psp_send_platform_access_msg) are shadowed by * -EIO. */ - if (psp_send_cmd(req)) + if (psp_send_platform_access_msg(PSP_I2C_REQ_BUS_CMD, (struct psp_request *)req)) return -EIO; return check_i2c_req_sts(req); @@ -202,7 +84,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) if (!req) return -ENOMEM; - req->hdr.total_size = sizeof(*req); + req->hdr.payload_size = sizeof(*req); req->type = i2c_req_type; start = jiffies; @@ -381,7 +263,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = { int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) { - int ret; + if (!IS_REACHABLE(CRYPTO_DEV_CCP_DD)) + return -ENODEV; if (!dev) return -ENODEV; @@ -393,11 +276,10 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) if (psp_i2c_dev) return -EEXIST; - psp_i2c_dev = dev->dev; + if (psp_check_platform_access_status()) + return -EPROBE_DEFER; - ret = psp_mbox_probe(); - if (ret) - return ret; + psp_i2c_dev = dev->dev; dev_info(psp_i2c_dev, "I2C bus managed by AMD PSP\n"); @@ -411,9 +293,3 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) return 0; } - -/* Unmap area used as a mailbox with PSP */ -void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev) -{ - iounmap(mbox_iomem); -} diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 050d8c63ad3c..c5d87aae39c6 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -383,7 +383,6 @@ int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev); #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_AMDPSP) int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev); -void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev); #endif int i2c_dw_validate_speed(struct dw_i2c_dev *dev); diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 74182db03a88..89ad88c54754 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -214,7 +214,6 @@ static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = { #ifdef CONFIG_I2C_DESIGNWARE_AMDPSP { .probe = i2c_dw_amdpsp_probe_lock_support, - .remove = i2c_dw_amdpsp_remove_lock_support, }, #endif {} diff --git a/include/linux/psp-platform-access.h b/include/linux/psp-platform-access.h index 977df5cfd494..f5a03cd11f10 100644 --- a/include/linux/psp-platform-access.h +++ b/include/linux/psp-platform-access.h @@ -7,6 +7,7 @@ enum psp_platform_access_msg { PSP_CMD_NONE = 0x0, + PSP_I2C_REQ_BUS_CMD = 0x64, }; struct psp_req_buffer_hdr { From patchwork Fri Mar 10 21:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 661928 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 C5A83C6FD19 for ; Fri, 10 Mar 2023 21:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231668AbjCJVWy (ORCPT ); Fri, 10 Mar 2023 16:22:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbjCJVWi (ORCPT ); Fri, 10 Mar 2023 16:22:38 -0500 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 83A8B12B659; Fri, 10 Mar 2023 13:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YA3jt0tgYJRXznJNZiZdgkbjCKiQ2GctyPXT20Hij/RDOzinpcjyED7VPoh+QJZVDH9VHB47b9eGabVbGaIf/rlmuKIeFpjLkylxmmutLynx8mRMQyfknPoD07lxT6/VR6GR+0bNG+FnHdVT+Eu4f2J5kUyJ5BjlT3JFfMz/FQCznzdxwQvjI2Gq5LNZUg9FaTnI91kATSGu9eT+t9dr1ZGWBbvGTu7HplEpc/yShadQVsi4BJ1i7YMghkYGO99RdA++5Dt+Autn5sBVAwXvli9ks0kh3CVDLbjCvz0ubI0xytKbJC9IAVIbCWCsRs5YVcvXzotAhDCfuhuJlWgj2Q== 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=Rxd6+gD0xK2CiphjJTVAFLuQItATGt9DyC/cZjwngzE=; b=b9mfBqO5WlSvTl9ErrP/7A5f296jzgOr9mgMGgn8lfe8EmWjcqaKZe7IRj4DxzNx4GFjRj8iT+rz0iknlj/5CSa9/S9+RQYGeODh9/H3pjm4Ft8KGhkVTrKNlzvTl9IJT5C70T3cr2WgsuK4fFeRiUFuerzj/eqhQoiqWQgw7VsFEwTMJFogeXDNvBr2Wfeh6R6fnib6zAPFtAHcuUdcQKlpkAoFMLLK9hHhrKWDudGMDUi2KiIBeBvN7qXfhky/vmLY/1Ksoh3rDtGUvC8TntOd1D2CkIZ9v7aJdRYdcI9K+yjR7qZd05z2JfBkDEj+NWdpE9dVgtYJOUYO12F2YQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=semihalf.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=Rxd6+gD0xK2CiphjJTVAFLuQItATGt9DyC/cZjwngzE=; b=cGzn5UfOekXgPJYYd9eWBb7EvHy05GM1dHeAfhFwyX+NA2BiZXqN0oAJcx6tW9ZSFxdA5nK07MUjcYxw8XvGbfEutld7eM8WWaXXMByBW1OYfCNYnokwhsUgWi9uHh5kl07suak0UYZ9JC1lg30JCUnmOjyMBsUNZ9JcTLrkJIQ= Received: from DM6PR05CA0041.namprd05.prod.outlook.com (2603:10b6:5:335::10) by SA1PR12MB6824.namprd12.prod.outlook.com (2603:10b6:806:25f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19; Fri, 10 Mar 2023 21:22:35 +0000 Received: from DM6NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:5:335:cafe::f) by DM6PR05CA0041.outlook.office365.com (2603:10b6:5:335::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT062.mail.protection.outlook.com (10.13.173.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.20 via Frontend Transport; Fri, 10 Mar 2023 21:22:35 +0000 Received: from AUS-LX-MLIMONCI.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.2375.34; Fri, 10 Mar 2023 15:22:34 -0600 From: Mario Limonciello To: =?utf-8?b?SmFuIETEhWJyb8Wb?= , Grzegorz Bernacki , , , , Jarkko Nikula , Andy Shevchenko , Mika Westerberg CC: , Mario Limonciello , , Subject: [PATCH v4 8/8] i2c: designware: Add doorbell support for Skyrim Date: Fri, 10 Mar 2023 15:19:51 -0600 Message-ID: <20230310211954.2490-9-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230310211954.2490-1-mario.limonciello@amd.com> References: <20230310211954.2490-1-mario.limonciello@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT062:EE_|SA1PR12MB6824:EE_ X-MS-Office365-Filtering-Correlation-Id: 0156f178-771d-4904-9fe3-08db21ad9148 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hc645T04SX01ZYmWPMCE0VK6rBdjyLPoBbCstP5NzghMqpmDYF6ffKYUlJBV2ltZazvp2kthtHA9058TpNiZj27GVTrkiQ1jOJ5S5U1UhSAvE4YCnBCh/4Uv1pw6Nb+hIGyzGf5TXhg4JaCvSKijOl0930gmVTdd24T98GzLYTc/bfwBwiRXEOYwwPD5eFl0OFkDNyYWDmHY2LnZA4nOxfADr7YRCDVQYplY8Tm4IB0h/+iQtGdInNf3EWZTZrKxIKILCDahLPi+oRoaKkPcylDS0s7hRgzTx1KcyH4Uhsv02EeyMRYlnHGn2xw8gzFw2X4OuTEeLhBgSxj53G0sivpohE2CvJEm2+2fKSZw6pIkAyN4+hOp/68uSnnRC59l50tL7gENJ69TASpwbaHYaAN9eBorAt8JovWaKyZErQhVXZtOPuwPS4j8I8qmXPdvM4ErU4hkB6Y/suhJYQD1Dyej3D6Z0BHdAw0y3E9J6HnLg31nBGwmaQSvuqYtLvhHnYodFkdPbkb3ag784Jg9WDzubQDw09WH+gPEfeQtDhDkGuWmbVOxZTjrNXrxCms/ukDAl67Hjw26vIQ3KgqZkS6axTEMm6F9X1iyPZvEIyT7XsJGNTVsuBfrLlASecYoreFwSwMnR39yuw8IL+5Y6PTDi90Mzc9C/AkRJPyZ+IgdmMvz6T1j4URDjXOENPLS4NqhuJCZ++PksPjR9raa/YqOze4SMlx3ZaLnodfbIVQ= 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:(13230025)(4636009)(376002)(136003)(346002)(39860400002)(396003)(451199018)(40470700004)(36840700001)(46966006)(336012)(47076005)(426003)(54906003)(110136005)(36756003)(40460700003)(356005)(86362001)(40480700001)(82740400003)(81166007)(1076003)(26005)(82310400005)(83380400001)(6666004)(186003)(16526019)(2616005)(36860700001)(316002)(7696005)(5660300002)(478600001)(966005)(41300700001)(8936002)(2906002)(70206006)(44832011)(4326008)(70586007)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 21:22:35.2790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0156f178-771d-4904-9fe3-08db21ad9148 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: DM6NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6824 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Skyrim and later platform don't use the platform feature mailbox for communication for I2C arbitration, they rely upon ringing a doorbell. Detect the platform by the device ID of the root port and choose the appropriate method. Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/ Signed-off-by: Mario Limonciello --- v3->v4: * Adjust to use PCI device ID and function pointers instead v2->v3: * Use CPU ID rather than ACPI ID, this will be pushed to a later patch v1->v2: * New patch --- drivers/i2c/busses/i2c-designware-amdpsp.c | 40 ++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 105584abcf8f..e5614d69c743 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -36,6 +37,8 @@ static u32 psp_i2c_access_count; static bool psp_i2c_mbox_fail; static struct device *psp_i2c_dev; +static int (*_psp_send_i2c_req)(enum psp_i2c_req_type); + /* Helper to verify status returned by PSP */ static int check_i2c_req_sts(struct psp_i2c_req *req) { @@ -73,34 +76,43 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req) return check_i2c_req_sts(req); } -static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) +static int psp_send_i2c_req_cezanne(enum psp_i2c_req_type i2c_req_type) { struct psp_i2c_req *req; - unsigned long start; int status, ret; /* Allocate command-response buffer */ req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) return -ENOMEM; - req->hdr.payload_size = sizeof(*req); req->type = i2c_req_type; - - start = jiffies; ret = read_poll_timeout(psp_send_check_i2c_req, status, (status != -EBUSY), PSP_I2C_REQ_RETRY_DELAY_US, PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, 0, req); - if (ret) { + kfree(req); + + if (ret) dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n", (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ? "release" : "acquire"); - goto cleanup; - } - ret = status; + return ret ? ret : status; +} + +static int psp_send_i2c_req_skyrim(enum psp_i2c_req_type i2c_req_type) +{ + return psp_ring_platform_doorbell(i2c_req_type); +} + +static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) +{ + unsigned long start = jiffies; + int ret; + + ret = _psp_send_i2c_req(i2c_req_type); if (ret) { dev_err(psp_i2c_dev, "PSP communication error\n"); goto cleanup; @@ -115,7 +127,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) psp_i2c_mbox_fail = true; } - kfree(req); return ret; } @@ -263,6 +274,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = { int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) { + struct pci_dev *rdev; + if (!IS_REACHABLE(CRYPTO_DEV_CCP_DD)) return -ENODEV; @@ -276,6 +289,13 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) if (psp_i2c_dev) return -EEXIST; + /* Cezanne uses platform mailbox, Skyrim and later use doorbell */ + rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); + if (rdev->device == 0x1630) + _psp_send_i2c_req = psp_send_i2c_req_cezanne; + else + _psp_send_i2c_req = psp_send_i2c_req_skyrim; + if (psp_check_platform_access_status()) return -EPROBE_DEFER;