From patchwork Fri Apr 14 14:40:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 83461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp439080vqo; Fri, 14 Apr 2023 07:50:45 -0700 (PDT) X-Google-Smtp-Source: AKy350bHA7NYdyVW6G4j0u5w+z4Bq0aueyJGpSuLz+dVciAbKdZCHSrG42uxKdM6XDjeJuYYS/+B X-Received: by 2002:a05:6a00:c91:b0:634:b9ac:f6e1 with SMTP id a17-20020a056a000c9100b00634b9acf6e1mr9380025pfv.20.1681483844689; Fri, 14 Apr 2023 07:50:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681483844; cv=pass; d=google.com; s=arc-20160816; b=lD2z7TpFPvDFCOSIUCzfDziZ994GuJPlC+FtHZS6VhNsdm5za5jl9ttOofDeOLrB9F laG8KIcDfcUSqbbX2MdnLxtXBV4XH/SCsCKI/Qm9YuKwQtpF0u98cIYcbOhuf5qyCm4Q tWchMcPb+dVpoWgK5/55jF+gmPIcqFLuFaGvJWUTcE9+N4l/qlG85ceuI23IqkNBAQNi twBPKSv5tAXAfG6rvbGA2whZgIvMTK6EZcDTiopmLrPU6swfdr0EEZn9HWvwi0HOvMxn dsUzx6KqNc2V8nMuIOGwNkp2LFCuxUgrLKLrPMtWcSFwFI+h8KrRrFDeX+wqsHldXJwd HfYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k3FWRAqMxtM4W/7JpChjLbSpdI87l/eBCn1Fzov6vco=; b=wiiRriUni6uLl0QDfdsvML4W58aQFfknIEq+8ORjgkgTAfVn9ohizrxGwrm/l8x9uF INBYbP37XTOwgZspI8qmIyb8DCDw7BEVki6E2Ey9wCZsuHrMlkpTHnxxZ7V0Ar0SIZiu P+KzRioksByFw6CZJDWj93nrGq7ZY1VoA8iLG8TiwTVA9bCF9FEvT+BosUdYyrgr+S4J Af60WHgRPTS+v/6darhCsaapPrB77rRxjie0kN++JTV3ZoJBGiA53+vrnQs4hCjmjX7y 8+i6CYWoRxlQjY7x9ZO+ESvbRTpvCzuowBbbYz9JpRA94zqfuGn8OGCD1dNpvjESwT0D MgJw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LmTjlFas; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z13-20020aa79f8d000000b0063b61a7ab70si2606214pfr.205.2023.04.14.07.50.31; Fri, 14 Apr 2023 07:50:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LmTjlFas; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230403AbjDNOkr (ORCPT + 99 others); Fri, 14 Apr 2023 10:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjDNOkf (ORCPT ); Fri, 14 Apr 2023 10:40:35 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A68C16A; Fri, 14 Apr 2023 07:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G01Uhl4Dj4mPSQ7ZfkPts5FsLKLOQfdEpZohOyXXNubz9HQ7n4P+NVoByXA4DFb6MyPPRiJHsBCtkc+uJmH1ZwTdZwiAbStJde7zxGWyVdBlug/DhCPhWxpYkKrEiqe2Tg103XtLXwAZNrlT/dMlbHMxuvP+iDmq3z+mJdGLe3R/hvcmvbyEX9hGZA9HGFoE9hJbD/Rxl1IrzRZYYHEyWdemflELMKQVtYyxiYF9KJuZGqhqfC8ux6fZevTyA1kuXW1XXQl88lG0LI06XefgIxV9Raa5TmcpGfhAaNnW/kiFTB4I7ebovmY5jbREVWuLHiZMw4LCoydJv19x9oIgQQ== 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=k3FWRAqMxtM4W/7JpChjLbSpdI87l/eBCn1Fzov6vco=; b=TzUmzXk6XvvQWfFiIYbqY1E16kqsA3ZVqrsnr+aaNmXmaTY3QUJxMYyIYqYP+Vola+AH3RGHGsUexY0uTLziJGuCMCQ4+oC6J/ks86b1YBSucMBCFbzdqBmKsWBXQJAXbZJDDAlXVUpo7MsZbofMVllE+jQsiiE9sxGit4eNe8wPPgB7RdzuGfFpToOe2BGkQ33L5JGnkFAZhwT5OttPNEK8ua/KfATUGbewKm/itnbQ0htcqEjkCpJbHiG8H2ay5f3n10lu3CDQsIopocENpj1s7bU3vByVu2M09MEtBNLOYL6yEmv0aQuaV9VQY+PHOKHVt913VWImXrhRDEkSrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au 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=k3FWRAqMxtM4W/7JpChjLbSpdI87l/eBCn1Fzov6vco=; b=LmTjlFasI0toUZZImDymOptC6dOrnSC4S+WlIodesiB9U07cnacryGLIeyIL/KzpDE+c8u6VqDw46/vJgeMnYWTgaVYZLQLYdXDeI3NfY2WekadkMUDpoBfXpN2ddPtWWN7f13j+t2ztrsbdRQkGyRFPraZPxHB8U2uRucJ7iow= Received: from BN9PR03CA0118.namprd03.prod.outlook.com (2603:10b6:408:fd::33) by BN9PR12MB5116.namprd12.prod.outlook.com (2603:10b6:408:119::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Fri, 14 Apr 2023 14:40:26 +0000 Received: from BN8NAM11FT090.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fd:cafe::cd) by BN9PR03CA0118.outlook.office365.com (2603:10b6:408:fd::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.36 via Frontend Transport; Fri, 14 Apr 2023 14:40: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 BN8NAM11FT090.mail.protection.outlook.com (10.13.177.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.33 via Frontend Transport; Fri, 14 Apr 2023 14:40: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, 14 Apr 2023 09:40:24 -0500 From: Mario Limonciello To: Herbert Xu , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jan Dabros CC: , Mario Limonciello , Mark Hasemeyer , "Wolfram Sang" , , Subject: [PATCH v9 1/2] i2c: designware: Use PCI PSP driver for communication Date: Fri, 14 Apr 2023 09:40:07 -0500 Message-ID: <20230414144008.836-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414144008.836-1-mario.limonciello@amd.com> References: <20230414144008.836-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: BN8NAM11FT090:EE_|BN9PR12MB5116:EE_ X-MS-Office365-Filtering-Correlation-Id: df750195-fa20-4c1a-a3e6-08db3cf62fa6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s/IQD8mrtmn8e3qOMsBdMIt+bmajLxop6Pi3TDmjhlcFq5/Mm+qepjZDw1NKJataFNcigGP+G9ofHKcFyEJttEeO6gXbRxuUIQuit7dk1QAgnghq4cpzz7/RCqLZL6jH3bVI8zDFwhwlDo963PlmgtK5BpiViLxWZyGTF+4bsJLkK1lfM1XyTaoLuE6GszSCa8XHhW7hzyXWKPhEOrHZJqcc9PQACVL8KhfsPIxsZmOH2EWGAQ0hzgGv5uSDTwGZaE/aJJWzXnFM3xy83ut4xCRL77iBwtvELtyPoQjVW2aDpeSrb7hx9uHPkS0Qj6NyDsL5RGFzddfhGgkLtNDEGwclDplET3oEl1LY03LU8XAKFBbvvIIU+X2j+JdkiCqc6oYhmYXJRs4MnOFp8jP81MK6kFrtyIYB7AXeBxxkJoOtXIJl9gOnp6Sn3iOrEValr1qCpdxQcItqtjFt0ELEdoaXrieLtXdqNFzykj6u2t4XqFuf7qJgmfO8yqBYKh+Vjm4TrQa0OshYhnFaCtOhZnZXKYdEtA6l/VJeZoqdnhHB7D2j8i8qZ2wAQbM1ig2JklEyndACJs1tyKWY2OXxMcVw0UVQdkAI8SLZPZcjzYzAJkPTgnoVo8TAp0ZAa+vYkoaVRGUTaFhnZznc524g+suCxcAVDq9jf4aquRy1ndGhad5iEdmUVXLto8CKSDGLv0UoZ0Gz5XoawAQWiDeKJQgCiTbw0h50/qA+s96ugqk= 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:(13230028)(4636009)(346002)(396003)(136003)(376002)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(82310400005)(83380400001)(82740400003)(16526019)(356005)(81166007)(40460700003)(186003)(316002)(6666004)(7696005)(110136005)(54906003)(478600001)(4326008)(86362001)(36756003)(70206006)(41300700001)(70586007)(26005)(36860700001)(336012)(8676002)(1076003)(47076005)(426003)(40480700001)(8936002)(7416002)(5660300002)(2616005)(44832011)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2023 14:40:26.1503 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df750195-fa20-4c1a-a3e6-08db3cf62fa6 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: BN8NAM11FT090.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5116 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763163604193985714?= X-GMAIL-MSGID: =?utf-8?q?1763163604193985714?= 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. Signed-off-by: Mario Limonciello Reviewed-by: Mark Hasemeyer Acked-by: Jarkko Nikula Tested-by: Mark Hasemeyer Acked-by: Wolfram Sang --- v8->v9 * Add tag v7->v8: * Drop hunk changing error message * Stop using imply. As shown by failed configs for kernel robot we need stronger dependencies. Model them off of I2C_DESIGNWARE_BAYTRAIL which has a similar relationship --- drivers/i2c/busses/Kconfig | 4 +- drivers/i2c/busses/i2c-designware-amdpsp.c | 175 +++----------------- 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, 29 insertions(+), 153 deletions(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 25eb4e8fd22f..89f8b75043d0 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -566,9 +566,11 @@ config I2C_DESIGNWARE_PLATFORM config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" - depends on X86_MSR depends on ACPI + depends on CRYPTO_DEV_SP_PSP depends on I2C_DESIGNWARE_PLATFORM + depends on (I2C_DESIGNWARE_PLATFORM=y && CRYPTO_DEV_CCP_DD=y) || \ + (I2C_DESIGNWARE_PLATFORM=m && CRYPTO_DEV_CCP_DD) 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..12870dc44bdb 100644 --- a/drivers/i2c/busses/i2c-designware-amdpsp.c +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c @@ -1,35 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include #include -#include +#include #include -#include #include -#include - #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 +26,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) { @@ -173,22 +51,25 @@ static int check_i2c_req_sts(struct psp_i2c_req *req) } } -static int psp_send_check_i2c_req(struct psp_i2c_req *req) +/* + * Errors in x86-PSP i2c-arbitration protocol may occur at two levels: + * 1. mailbox communication - PSP is not operational or some IO errors with + * basic communication had happened. + * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too long. + * + * In order to distinguish between these in error handling code all mailbox + * communication errors on the first level (from CCP symbols) will be passed + * up and if -EIO is returned the second level will be checked. + */ +static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req) { - /* - * Errors in x86-PSP i2c-arbitration protocol may occur at two levels: - * 1. mailbox communication - PSP is not operational or some IO errors - * with basic communication had happened; - * 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 - * -EIO. - */ - if (psp_send_cmd(req)) - return -EIO; + int ret; - return check_i2c_req_sts(req); + ret = psp_send_platform_access_msg(PSP_I2C_REQ_BUS_CMD, (struct psp_request *)req); + if (ret == -EIO) + return check_i2c_req_sts(req); + + return ret; } static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) @@ -202,11 +83,11 @@ 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; - ret = read_poll_timeout(psp_send_check_i2c_req, status, + ret = read_poll_timeout(psp_send_i2c_req_cezanne, status, (status != -EBUSY), PSP_I2C_REQ_RETRY_DELAY_US, PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, @@ -381,7 +262,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(CONFIG_CRYPTO_DEV_CCP_DD)) + return -ENODEV; if (!dev) return -ENODEV; @@ -393,11 +275,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 +292,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 1b661341d8f3..75da8f5f7ad8 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 Apr 14 14:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 83460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp438004vqo; Fri, 14 Apr 2023 07:49:02 -0700 (PDT) X-Google-Smtp-Source: AKy350ao91KcNY2M3SS192R3YA6RMvYahzsLSVO39UfIstGACAnLSBGvse0csrAioZp+8yTF/UQq X-Received: by 2002:a05:6a20:4c96:b0:eb:765d:e0cd with SMTP id fq22-20020a056a204c9600b000eb765de0cdmr4546233pzb.48.1681483741873; Fri, 14 Apr 2023 07:49:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681483741; cv=pass; d=google.com; s=arc-20160816; b=kh9fvNHboq+0M1+QO/yj38JEktZ5+6/hQ5V/6p1wjNkvvlgR4MOdctayMkqKLuuztg wx/02nHaB92CM/KhsBq+RZ8oqX67cv2nUhQyNWMOERv9Fl6KlnQA9w9o6lE08XLFPj04 LEP2HlvA9bXmsDKK/7G0ydd4MqHMobECm+MyfbmAFPXxxqh79dPgV3oca6EibpDFzRFF Css3oSxEw6L3wl8NthiBcYEjSRtMCmtBllgtAdq6vZ8qVXCQC0T5Cwdxxd5DhB7YuoBJ MUPjbsxYK+com8uKHaoseD8ppopTJ/mXBkvHaGqMB4pZaNeMjvlLV5dSJoNOYOskYu6Y CEmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B3D7jx9wsbXrF7ajqwptdEzUSmNmvay40HB00Ok1hKQ=; b=ulfTcM+AVE/Y0Ry32ZgWQ10f6N8+nygtGPJt7aZNaHluYhHc+L3Sofsbi4yJG6aR71 zmZSApTJDF/OZ4QBmTogXLWV27LRSp7xvsRBEnEZeS7jHCXTjnKdrkKEPVgNFr1WpfBu wlsSOjpTzr1d4I62Llh5L3gENTqrjtQCrbAl6wpheNxnrm93lj2Q4DuZ7HCWgJr8sT4c 3OTQvU7tFFdCWsURUaPaa1A5Y9iW33zYh1dUEWeJDuJ4cvL73o0t4wZvaROThrfLLio7 LN47v1hAi/dlBwbTBhApaVvRverHXOfh5C+3YfDaxbd8+zcjgxb+Zq/VbfnqTvkpUYma 7PfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v6F5OLqR; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t184-20020a6381c1000000b005030006a2desi4873795pgd.182.2023.04.14.07.48.49; Fri, 14 Apr 2023 07:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v6F5OLqR; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbjDNOkg (ORCPT + 99 others); Fri, 14 Apr 2023 10:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjDNOkd (ORCPT ); Fri, 14 Apr 2023 10:40:33 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2089.outbound.protection.outlook.com [40.107.223.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A78B9BBB3; Fri, 14 Apr 2023 07:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RdQZXJoXqzCnSelTQIAjolCQLYDxu2/m3tMJHvSO0PmyzBZlfO9pyJ6Iz10i2KtN87hdKEwNTLhBoCL+bw7dO58zIUSgFaGEvnEdPHNV6u/tgQwNDMjAxXkUQI4/aCuvGVB7oSZbSHWwQ8R8RM1sfoHCnpnCz3zY1I81Pukeplqsh1zPyQf5x+199fAa/MW9kMZbL+6d+7IiRR//bNRH3CO129x3ekT/vu5OWPyaUi+1jPK0NLvPjJj1DPYMfbGj5NSu9dAqXsc1y/enW2jo6cNE9IHc56E4pg7cFEDHfOYwfol5AYsPXGlct5pUy2Qc817yqoNQO01rcTLGC3xvfw== 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=B3D7jx9wsbXrF7ajqwptdEzUSmNmvay40HB00Ok1hKQ=; b=UbYMuE6EBFF29yLkQ/CWWiG5Exlvq7wr31J47xBtsmVeiPn6gSWqdhVmgiH4lgWojYgpzY4SKz2FnZ/qb5Exu2UymwHTAbetkTaGoXQ/5vbflQQ7Z+OcU1I72r1RleZwl1rcKn9rboLsZrNxjSDlfVTo3qi+s+kz0WPcF1mXamcJsOwKcsBSBsxJTEQceoWOTh3O3xNYv1YBkWoDp+OKB1QudQXjIeRIApHVcYOllYesZTlzUhCWKkENf0cMkaXYNMkQNh4Wet74WJa+oE5mYgZY5Cu5bt+UI82m16pbod1Er6NBNR5RT/fR+UTSB//0zozU0lsnunxT4vcERWrMrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gondor.apana.org.au 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=B3D7jx9wsbXrF7ajqwptdEzUSmNmvay40HB00Ok1hKQ=; b=v6F5OLqR5I9ao2SeY9CvI3zhkSlwMtbhxYnklRtgPNL+HwQDWa/5Qs8onILWAAx1T7XMbXoA1xoZTQU1d65K1OPfIuU+arsiePg2Kv6kb6M71784+VfHRf6jAUqs4pU5Z1GFTn0fsq6ZayMZKUahR/s81beMYILyIx5mivHhDug= Received: from BN0PR04CA0206.namprd04.prod.outlook.com (2603:10b6:408:e9::31) by IA0PR12MB8207.namprd12.prod.outlook.com (2603:10b6:208:401::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Fri, 14 Apr 2023 14:40:29 +0000 Received: from BN8NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::fc) by BN0PR04CA0206.outlook.office365.com (2603:10b6:408:e9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.36 via Frontend Transport; Fri, 14 Apr 2023 14:40: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 BN8NAM11FT017.mail.protection.outlook.com (10.13.177.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.37 via Frontend Transport; Fri, 14 Apr 2023 14:40:28 +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, 14 Apr 2023 09:40:26 -0500 From: Mario Limonciello To: Herbert Xu , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jan Dabros CC: , Mario Limonciello , Mark Hasemeyer , "Wolfram Sang" , , Subject: [PATCH v9 2/2] i2c: designware: Add doorbell support for Mendocino Date: Fri, 14 Apr 2023 09:40:08 -0500 Message-ID: <20230414144008.836-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414144008.836-1-mario.limonciello@amd.com> References: <20230414144008.836-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: BN8NAM11FT017:EE_|IA0PR12MB8207:EE_ X-MS-Office365-Filtering-Correlation-Id: 00cbae68-dc5e-4e74-1ad8-08db3cf630c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LuDgX6ZSghPM6bsaeKbEMNNoKBgGiQyyjMmTB1IVrZW4+IcyPnjiwbLUD++jC2D+WskV+vs+14eIYno2sd64rmuVhyW82s59ZGZDVY2iMWHSv3JUvprLeYFH2pnFNdUjRMIF1SGfx17ys0SdrUBEzKQIWmLoqCVkpu4ScJNMHMfi+Rs9D0T8+Vg6pKKH3AJiTl5MqUx28+vb5hJXCFedqBV/VxhjG+ajwPK1BcdEJCAcy95tS/Vc9lcjIbuUtQN29lOsgvnRQAEh4qXhcQ5JOgW4V9kYTnYgT9ZFvwheKVmkiixvyBET10OL4OAhG+uMtclS7jZ6hSt7Jh5q06u0H2pB13Rdajg+dG5/LZLTdOd/1nWFIVFkwqncw67AZeavVRia99QQipnR0CXFQ+/VjFcj9Oq6TiiH/mJDF+/qAJpvUdmfxljNLZsZRsL5Onc6p9ktp1bk9+DM0Kkb6RsNRJS8oGWmjkrv5ZWwZodLCaKz1y5mY6/7GDKk3E1fKSVMgnjSujUWbUdOQg2oxH99gU7fiEaxc5lPCuwJqvuASxy/nyVdr9EdIGD4ILNVAq/xOIw5o/XIfJAf0xNU2hQOinRqcFGZc0EQgJmAN9KCjT0DFklmFDmjuIi4tCB7kpDFfNyjfbpU4tPGIyXf39148dLHbYKqFAfP6M0rhlY19tTSRzNFBPN+LamGbl+TFm9U+FIuZwkOr6c70lC/0zirGg63LKFf4rMjRBOmb7Y1AEo= 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:(13230028)(4636009)(346002)(396003)(376002)(136003)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(26005)(36860700001)(5660300002)(36756003)(7416002)(44832011)(2906002)(316002)(40480700001)(8936002)(86362001)(4326008)(8676002)(81166007)(40460700003)(41300700001)(82310400005)(82740400003)(356005)(966005)(426003)(1076003)(70206006)(336012)(47076005)(70586007)(83380400001)(2616005)(54906003)(110136005)(186003)(7696005)(478600001)(16526019)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2023 14:40:28.0564 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00cbae68-dc5e-4e74-1ad8-08db3cf630c7 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: BN8NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8207 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763163496162435669?= X-GMAIL-MSGID: =?utf-8?q?1763163496162435669?= Mendocino 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 Acked-by: Jarkko Nikula Reviewed-by: Mark Hasemeyer Tested-by: Mark Hasemeyer Acked-by: Wolfram Sang --- v8->v9: * Add tag drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-designware-amdpsp.c | 26 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 89f8b75043d0..4b4323bbf268 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -568,6 +568,7 @@ config I2C_DESIGNWARE_AMDPSP bool "AMD PSP I2C semaphore support" depends on ACPI depends on CRYPTO_DEV_SP_PSP + depends on PCI depends on I2C_DESIGNWARE_PLATFORM depends on (I2C_DESIGNWARE_PLATFORM=y && CRYPTO_DEV_CCP_DD=y) || \ (I2C_DESIGNWARE_PLATFORM=m && CRYPTO_DEV_CCP_DD) diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c index 12870dc44bdb..63454b06e5da 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 @@ -32,6 +33,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)(struct psp_i2c_req *req); + /* Helper to verify status returned by PSP */ static int check_i2c_req_sts(struct psp_i2c_req *req) { @@ -72,6 +75,17 @@ static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req) return ret; } +static int psp_send_i2c_req_doorbell(struct psp_i2c_req *req) +{ + int ret; + + ret = psp_ring_platform_doorbell(req->type, &req->hdr.status); + if (ret == -EIO) + return check_i2c_req_sts(req); + + return ret; +} + static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) { struct psp_i2c_req *req; @@ -87,7 +101,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) req->type = i2c_req_type; start = jiffies; - ret = read_poll_timeout(psp_send_i2c_req_cezanne, status, + ret = read_poll_timeout(_psp_send_i2c_req, status, (status != -EBUSY), PSP_I2C_REQ_RETRY_DELAY_US, PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, @@ -262,6 +276,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(CONFIG_CRYPTO_DEV_CCP_DD)) return -ENODEV; @@ -275,6 +291,14 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) if (psp_i2c_dev) return -EEXIST; + /* Cezanne uses platform mailbox, Mendocino 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_doorbell; + pci_dev_put(rdev); + if (psp_check_platform_access_status()) return -EPROBE_DEFER;