From patchwork Fri Mar 29 06:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610179 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2F67C6FD1F for ; Fri, 29 Mar 2024 06:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=u9qIL2g6iphX5TQW/T9rbyMVo8HxuzhLYpG1+TdnvKk=; b=MITX56AGLn8nl4 31sVYlFSRKjq7Nfxi7knlQFN5D31DbU8651CdMKhJI/YEpBVGOitNG0utzNcy5GjQulh20yVwY8cp e9OhsJGQ7uNfD+igS3gyFZm296S5IdB4iheJJE1WcwdLscsOJtlyIVCTim08qzjHdEiYRRxnzyDgv gSEJZLSt9JIXOxg6ubr1ZA4jV716UlInYDMeVXJhI0G/iXWjCXOFlXmD/akn2edLCMK5jfZmOY7OK 5AqXL/IM8l/6+tRD5OyOgpu5aso2oeK4GODxVjyqo13v4snLAyUprcKHej6i+GAxRMftRZlDN+QNV 0XqhRgzc+5KXsE9vC54Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Ws-0000000H03r-2ILr; Fri, 29 Mar 2024 06:15:54 +0000 Received: from mail-bn8nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2418::600] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wc-0000000GztL-0bxK for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qi96cVR2DRsaYA6hQCj+m4VgZTK20OGyeuW4DTjlPgF1d6EVtAX8h5Mc05PD7rJcJ40IriyZieM2FQxSzTDohJM64wKGxKRMsqY/5nxVKP49m5BzRvNM+E4SRj2UXAfoN7dX1CEDd8uiPkTcos/d44MDnd8qDdo9bgnQ9zn0HIVgxoFwHOrXEiIlPUxhUwTvnp0AdHwdWVTIsQVTDpEMf9Wi8iZ7QdmJ5YoNxkK42BrhPuHj35FHMLi4SFY4AOAIKCDSaKuYTLZp8baOUjb4xHhzxzmR9LiY0SohsfI9q3ZelICK/zf7tYMtcGqYg4K80MdN4hlt8D+L45owUPnV1Q== 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=YuuLxMzEvDctqxAwqaLasOXBtsTJWU9VsIqTNzStANY=; b=BcBWYXmYbbG/JtVlypvm/RlLYluvC81ng1VeCPSNId9Ch4YdULbdTcQyv/j430NmQyoeij7H5o09AbZyfK8bhQQy1kxzPPJ8X+ppyJ4bJcHYBOx7C2HGmpV70c1zUAnJ7R3xA1suT5e7fiRUQ5RhpVBJYYBl8Ag8UzQ5VnU9c1BBDqH9s/KiUN/9s2pI1JGV7xzCx6uTcTvL58kre9rnQqiqPIbmLNzyAzHD/EQ8TGjdG76QICI9ltY88KVdbP+JWzbjnRXez0UfevZIm28ehN0oRuFfY2Cp1WjjJwbog5efuLo1c7B1PEGvnH5sNB/pqOQww3898ECgwJ90y7yWHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YuuLxMzEvDctqxAwqaLasOXBtsTJWU9VsIqTNzStANY=; b=amisSJm3svD8JDBzkHINDP+Q5JdL/UQo9ptPKHAGPVYrseCnfLZrxjMqdU4G81XsjhlQke0D8Lf9v8tnGiPIapViwhmSZJpAPfqvvPs5YkLOnQtlH/pasS12Dciel/lPpOgQ1wiAPhy3j3EJia1MgTBxQRZfkHCvAs+KzQlJZwoWMOY0zfcdve5prW9vbEzFQCmTxR7uuhID5dQ0Ii9aN8JZLxZqyBSoUKPBxyvfaR/LMXBpxBh6crxATS1FktiookBll3EIt1IAsSsD0cc55B9FnthimsrmS6yP0M6R736zXwuZYQnestDC2mb3SmnywuqOEgeU9+IctpoNgcxyAQ== Received: from PH7P220CA0091.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32d::10) by MN2PR12MB4343.namprd12.prod.outlook.com (2603:10b6:208:26f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.38; Fri, 29 Mar 2024 06:15:25 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:510:32d:cafe::38) by PH7P220CA0091.outlook.office365.com (2603:10b6:510:32d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.41 via Frontend Transport; Fri, 29 Mar 2024 06:15:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:25 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:14 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:14 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:13 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 1/6] iommu/arm-smmu-v3: Add CS_NONE quirk Date: Thu, 28 Mar 2024 23:14:05 -0700 Message-ID: <6e1704f99d8f31b7abe653fe95f459377857937b.1711690673.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4F:EE_|MN2PR12MB4343:EE_ X-MS-Office365-Filtering-Correlation-Id: caefcdb2-6aa3-43a4-d929-08dc4fb79f80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AUkP+oRyt0zynWwQ6GRHj+Q6/y0cV+qT0I0RnaJKu+hiPl9TDeTdmi20FpUb/hU/u+Szb+nREKZ1xco7NA0QlUKK8O6HoN7xTX6778o+ViecUPAfD6akxugGk85+XAJEjtPneJEbjuCnbyDPSnoFwvWUP/qfEXeyV25suyEH8kL+2muNjrqenpFHYoNq3olLIVqfHrMlxX0tCDnmH61v610er253pW7rbFHy+ABvsU5069qW9NbtV7gEVy9b8EE3lIqLLQPlhuOZYL/Gbpf9ySHIPC7OMPYkIMRA1CuIgKMs08lndvTQ+idn25MOZA1mvez3nBaJ7krN5IiMaMoous/HpUqEOwHMdAxHn7JVFz2rOV1ISXmSKbn7lw0In+M7Y9SkOdLvquW8/edfZKUxUn1RizqY0OC/if/YOMzluRxJmYap3G/EAgCEpRWqzO2kTajA15EOhfQBHQowPeHxPXKiCMZ9dZXKJif4pDsnrxhQnUFOdH+YKlrHptUekQd4fHajXvAsHJ0E1AsVYj0oNTrAxjXqqJpeZkV/gSmwEsIxVGI0Z/wC58+sV/bxHzSIGpnxjMFAiGRTJoRzLQY+QPlOWdunBOynFw4tRHPpuNqd4nMFy7ajjRCyp2uMx4pkXYBVOpaLrXZQI/6sofhgYhzmoZXcJpXKobUuHbwaBJ4qegf6UQvu1gi3+2GsnahvTatWCWqtMmyTUHc9HdcanHok/YiOumC6e2L8lhcjvFddPgAi8w3qjdFuN4zQJ0m8 X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:25.2148 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: caefcdb2-6aa3-43a4-d929-08dc4fb79f80 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4343 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231538_385338_18A4647C X-CRM114-Status: GOOD ( 14.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The CMDQV extension in NVIDIA Tegra241 SoC only supports CS_NONE in the CS field of CMD_SYNC. Add a quirk flag to accommodate that. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 ++++++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 5ed036225e69..da3957ad95be 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -334,7 +334,9 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) cmd[1] |= FIELD_PREP(CMDQ_RESUME_1_STAG, ent->resume.stag); break; case CMDQ_OP_CMD_SYNC: - if (ent->sync.msiaddr) { + if (ent->sync.cs_none) { + cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_NONE); + } else if (ent->sync.msiaddr) { cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_IRQ); cmd[1] |= ent->sync.msiaddr & CMDQ_SYNC_1_MSIADDR_MASK; } else { @@ -371,6 +373,9 @@ static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, q->ent_dwords * 8; } + if (q->quirks & CMDQ_QUIRK_SYNC_CS_NONE_ONLY) + ent.sync.cs_none = true; + arm_smmu_cmdq_build_cmd(cmd, &ent); } @@ -707,7 +712,8 @@ static int __arm_smmu_cmdq_poll_until_consumed(struct arm_smmu_device *smmu, static int arm_smmu_cmdq_poll_until_sync(struct arm_smmu_device *smmu, struct arm_smmu_ll_queue *llq) { - if (smmu->options & ARM_SMMU_OPT_MSIPOLL) + if (smmu->options & ARM_SMMU_OPT_MSIPOLL && + !(cmdq->q.quirks & CMDQ_QUIRK_SYNC_CS_NONE_ONLY)) return __arm_smmu_cmdq_poll_until_msi(smmu, llq); return __arm_smmu_cmdq_poll_until_consumed(smmu, llq); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 23baf117e7e4..b95d9a9ae0a8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -509,6 +509,7 @@ struct arm_smmu_cmdq_ent { #define CMDQ_OP_CMD_SYNC 0x46 struct { u64 msiaddr; + bool cs_none; } sync; }; }; @@ -541,6 +542,9 @@ struct arm_smmu_queue { u32 __iomem *prod_reg; u32 __iomem *cons_reg; + +#define CMDQ_QUIRK_SYNC_CS_NONE_ONLY BIT(0) /* CMD_SYNC CS field supports CS_NONE only */ + u32 quirks; }; struct arm_smmu_queue_poll { From patchwork Fri Mar 29 06:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610175 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A627C6FD1F for ; Fri, 29 Mar 2024 06:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JvlhgAhrq3/IpQYkxu1uwTlBff0TH4FDjp7MKHXOYMs=; b=yklHC378ld2aGC WcgsX9DWtJwnVkZ7Gf/8MTQq7N0oWffa8rMySOecS0ocwdbs3O4q016Qe6mYAPhqrtnMnWgSBhmSc ZelRI3MMTd5TqkwTMa/8BCPT7UJ1H6MmbotU/N3jJFKmwE8k0nEuNXxvgIuPVuh8QRyuwWGao5JPz NMW5r9hDxtgBecnVaAmeGpMr3efob0JGzT0yeolSRRQEJtq0sM3NRAi+8HUOAPewFmb97lxi1jwiz 1cxgOTxmit/GR9AeMVBqn6vfC22km8BR/KuTAG1MILDVdcXL9gQmS+4wtW9owUs+IN1of/ynYnkOB Px/ZtQ8B7arCYX/0AU+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wn-0000000H00S-1fwW; Fri, 29 Mar 2024 06:15:49 +0000 Received: from mail-mw2nam10on20600.outbound.protection.outlook.com ([2a01:111:f403:2412::600] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5WY-0000000GztC-0Bx3 for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eD0u1x5u8DoarqzZiMtP1qE1RSlbZaLQQMZcYdSbkO2ac80VlKpvULnhu2QXmn2nFN34VcXcnb2hVsezHyuXgwOTw6D9fWxZf/TH8chASQokQLRKoBsnkU+UpANuwjo6Wa+yHCFyZJhJZ57OucC8Hp0RoQBcdWXpkyKpiXHQrzi24akoBJDWbh4Wk0+h4vQ7sopM55m9MWNyES3+8Z089K+rv/XJ1x9BAOnkLqfEjUMpdvr8mAgL50OaB1u210OuhK7u1oqm22Q4p5xs8CEs3kNdsYhzeLUl3bq6N0fZWKwqXAuiFYdKCrZRhov2dpEslD1AlYS7MADcDMZf5iYINg== 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=aNdl1o6namIad3uQYT5rONipX5GXGrLZZUwZ9BvNdbk=; b=Pa1IAgleg8BZBljeapG9fGpHdjVKtAy46PIwImq4QLfG8NOaNr/9f0flMvMlADnzA1X5MPWY43ehr2WTeUKNWHu1qGkShuiHNIWKcQT+rsNVjcRO2T/tfxni024inKxCK1c22Q2tNG3C3w+80rBFZjIUFMG2qLMXJ9Pki+7yB155LBO+5QBfoqKR2ImzUOkZoYALVYcVDy9PszuKhQH+ZTPPoYN7mN++MHXMkeUpZfT7x1bqKo5jrz9LfgXDAPatgycu7gfPHC4TrbUzQK40zHE3lAzFh5mFjUTfztrUjxkF2ZoiLgsfmos0oJjvOOXx/CH75OjrqceZFE2pAYo15w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aNdl1o6namIad3uQYT5rONipX5GXGrLZZUwZ9BvNdbk=; b=Y3MHW9qLgYLiqfipIt8zNjOyO4nEHl8OhbOBda5olHk6650SRN1voxBGWrsUy1ftXSGEsrFo1e8shCXOfVGKEctDH/1Hamp7JNl/9CLG0MacXPtJUlVsi1qiV1YaZOVU9vOzBEyhzi6rmBCW+PQb56wqEUBAjhUt4qpddjYOIUVWe14k5dZThQLMJAtbBcddyZdztyYShCjez1qV7tepOqOUJKyirV7K80ZM3JEvjZqN21vPsWYuzgO7v72fIbFU8M8mv5C8iCoGLzHurmy0z2XOsWFlxfKJzPLrHU9lSKuaX+31BkxKwGGX6pxJurnPNYhjNTGikasj8nB+aksNJw== Received: from BN1PR13CA0013.namprd13.prod.outlook.com (2603:10b6:408:e2::18) by IA0PR12MB8839.namprd12.prod.outlook.com (2603:10b6:208:493::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Fri, 29 Mar 2024 06:15:27 +0000 Received: from BN2PEPF000044A2.namprd02.prod.outlook.com (2603:10b6:408:e2:cafe::b8) by BN1PR13CA0013.outlook.office365.com (2603:10b6:408:e2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Fri, 29 Mar 2024 06:15:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN2PEPF000044A2.mail.protection.outlook.com (10.167.243.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:27 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:15 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:15 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:14 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 2/6] iommu/arm-smmu-v3: Make arm_smmu_cmdq_init reusable Date: Thu, 28 Mar 2024 23:14:06 -0700 Message-ID: <78032b4ba243d778b1fdc24ea46019da6626a760.1711690673.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A2:EE_|IA0PR12MB8839:EE_ X-MS-Office365-Filtering-Correlation-Id: 7778ef85-e802-456d-e401-08dc4fb7a0bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2oK+n6MNDLAHZ0BHbX0U7Xm4I4wryyY31ezrOd27saZEhdcq3A6/dO5XS6dpxXSuH2BnEHezNDNhng84F7HJG6uBjU1o8YV9QZnnAx6xA4VWS77ow8syIknTpsssli521TDd+indAUzjjvP8ArkLgtdxTj4eyPQBE+QpLGMgcR+56kuZAOIXNr+HLUXZ6/KtfmcjplJguflUf4A8EPvD2uGZ//M7dmf+niKGRqkD5DVO08s84wQO9N2Ag8MU8eKzFyENz20pfuEGpUGIxhYq3PFKvWm6bCbuAe63Ef8JftIohNOL9KMW6gCsix3l6hDlUSJj/chN8H6v6SYFGanod9vX9MSlnhyjVJBr4ZVX28skZ5dKVuVxwbhq+8TerTzgDnL2NgiaFhLmENUbys86aFcYUdlU6gliaf0eEr/yFcmgMtdSpZQWdrYCxSSHvJrx0d8yIpAlnxI5ChJ5m8Y26pqN5xbuKPcD8LUvK+g7pfVg1VPutONDDukPMdlU5/EKSvH0n1mQB9zDX1n2qemwebBLBqa64YW+NVAtelHbz3eRExx4Qxa4YjPFu3AgToQ5VvYHMCRl3MdPsCtTtEr9dl9nFpc+RjghIafepoLSX8vCIlgigIhP8lu6LZGBKvlGLcNc+zPKj+UZQH1MaY5WF6f9zyydmlhXKYy/ukq958YR77l2XVvJmUKP/x/87fV5f9aIAcKNF/JUvzjidhLjAOgSkYO6Ube1Nmm6KWWuEVMOygC9JGgCs+vUsHKCJSLJ X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(36860700004)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:27.2145 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7778ef85-e802-456d-e401-08dc4fb7a0bd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A2.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231534_133324_917167AC X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The CMDQV extension in NVIDIA Tegra241 SoC resues the arm_smmu_cmdq structure while the queue location isn't same as smmu->cmdq. Add a cmdq argument to arm_smmu_cmdq_init() function and shares its define in the header for CMDQV driver to use. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 +++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index da3957ad95be..44fcc0c0a149 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3135,9 +3135,9 @@ static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, return 0; } -static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu) +int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq) { - struct arm_smmu_cmdq *cmdq = &smmu->cmdq; unsigned int nents = 1 << cmdq->q.llq.max_n_shift; atomic_set(&cmdq->owner_prod, 0); @@ -3162,7 +3162,7 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) if (ret) return ret; - ret = arm_smmu_cmdq_init(smmu); + ret = arm_smmu_cmdq_init(smmu, &smmu->cmdq); if (ret) return ret; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index b95d9a9ae0a8..4af0976a2338 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -758,6 +758,9 @@ bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, unsigned long iova, size_t size); +int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq); + #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); bool arm_smmu_master_sva_supported(struct arm_smmu_master *master); From patchwork Fri Mar 29 06:14:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610176 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CBC4C6FD1F for ; Fri, 29 Mar 2024 06:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6wiRFpJoinjsspnztAA0qKW7+j9bO9mULjkM3tRqKUY=; b=JzrarcJBdD9QvK QNBbXLciyqNzDQthyQ8HZnwmSOxiNJj2Q5GjuRGLqz/2Cr06PQjUdaIFlCUqFucUT5sBurSU4T3Eo 78n7gm5v3Tp/zYIGmfzDCLQ+qzExlf3RRV5eXGHck31MZtV5yaT9nJKUehr9WUfUO1rcdBEI6NhBA a2Ly05UQ0Wv/Nw6VYC5BoynHG8GFXSEhX4XKYUXwA2U2QoODclkcCXqELKkV9evZFJMDArkrEjBao KGBZX4XwztHm0Nds3u42qBDxSUwfBz2SD+zykrJOO99WIVQpKNzHNYSOkk+BnUiZBTh7LMZVd4l7r bxsxiA/sOKBddt8DxHyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wo-0000000H01A-14ks; Fri, 29 Mar 2024 06:15:50 +0000 Received: from mail-dm6nam10on20621.outbound.protection.outlook.com ([2a01:111:f400:7e88::621] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wa-0000000GztM-0HE7 for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5XGpUu4Y9gPOVzuHPoixS4863LuWBIlv176pu4lUxFV7h5fXGmbmyH9WxTo4jUnrV5oIKrjUqxr1FMB8nhvO+3/lW9Yu1IpFNjD5bW3K3MPWORU8OJujAG8g8RODa1STN2iFh3SFCKyxaoA8f2yf/dy6CzdkfBe56ZKZzbE+geJRyF0GIGYX8Uz9Yt5BxIUU2cj0hwVSaz8TozXJZig/o7H0U57YWSlyEns6v3vckZJMJjsLM5oFgTErcgJ8NqoXtuWiCi2x1jCZN+Vi60qtrM62n5qI3Xhr9/n1tlwhGpUF8K3L4OdMtHAQXW98ZkCwNZeQpGglQ4aGJ8MHJ/9LA== 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=XzeJgMasrBKZweYz/iNOmJOpwf+fNatuH2gYLFkexFU=; b=RrjNShnfj9XsUdiEppZIFGTHFtNn25z0BlOmYvHgJZqum1zrLJp3sX4Gvlr85wkGtsb2lymOHH+Up4vVYRio3FxtU5ttw1/ACWPBSoQCPMV+0AZjFe6mCm+x97FzAW6tVFzcjymjKZxq60GYKzoGfWNmqOqPY8Opln3TvP43oF8kcyRhyvuvDEW9z4y+cWagPg/6oNErpGG5kt4a3RsLGhqSlgZkm4rWdOpUrKR6axuxzVLKNP3kOAYgYZVtvku7Vlc6NKvA1jzbVmke2FpYADfEb4MA0V21uqZK9BrI5FyVp3vgBK2T9oOqNLRiR8lEjSYaOIQvP4NKvhU+RVgn0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XzeJgMasrBKZweYz/iNOmJOpwf+fNatuH2gYLFkexFU=; b=Xxm8WOx7NarVcWYZ76KpxiI3PSTppWo3KA0JB/hBJ1QA4qOrQmIgg43op9KfILHcrzfKdaksUKsMJDzEt+7tESH6NT04Gg7aYzbW8f+yBm7N/Z0B7OOyroyX8qWL5dckrZEVbZ7z30N5V0x/Nh+Tg74dPvd8nGww7vNhEKPNet3kVciZUuU1YrJs2tCyZAzt1j2gj8MGrQQ68tmbbP8wBvW6Ui/A/bXmBtO/WXWeY4FGuykVuLv2g75V/wPDxEamPlsXrzxoRSxKPvEyoayqpbu4ObItCQmiQEorV3HNQr6gHof/puYnDe9paS3b9eMXI1c9S+2Kca1Xy0OVUOoc6g== Received: from BN9PR03CA0534.namprd03.prod.outlook.com (2603:10b6:408:131::29) by IA1PR12MB6092.namprd12.prod.outlook.com (2603:10b6:208:3ec::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Fri, 29 Mar 2024 06:15:29 +0000 Received: from BN2PEPF0000449E.namprd02.prod.outlook.com (2603:10b6:408:131:cafe::cd) by BN9PR03CA0534.outlook.office365.com (2603:10b6:408:131::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Fri, 29 Mar 2024 06:15:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN2PEPF0000449E.mail.protection.outlook.com (10.167.243.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:28 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:16 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:15 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 3/6] iommu/arm-smmu-v3: Make __arm_smmu_cmdq_skip_err reusable Date: Thu, 28 Mar 2024 23:14:07 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449E:EE_|IA1PR12MB6092:EE_ X-MS-Office365-Filtering-Correlation-Id: 70dc324b-dbe7-4e88-60d9-08dc4fb7a1b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7MF2ou5YM9FgbRGYjKg2kvI3gOHUDmb+YStlSLZ2SwbxuMGJ9UeoCdlStNXsk5CxlA0AEeXAo5Ne01EOpdPHaSMD0vN542lJOOW7EYaHnLE2vvj70bUE5Acnp1iHSpzv9oBrr/sjKTGdwfRRRB6BwRoYDCUKk3/G72gRnho7eqbDqBYudRdksNe0kWqcPvxDIR/VAjRSQ7i02lY/IOPCq6/59uf49D/yQJyCQcKgSKtKYhfbBT3p1De3NZT6h/Lw0MSs8Dan+s3Nfzht/W25eQsDvamd2tn87VDvkFHe3LMXQNtQWIBm3Ir8ueBZFq9bBaqQSzK7r28yC3TqM5BYr998sVi9KikB1XCKmzyCw5xLwhlSk4be9EI6BU28jD/oZ4rHLOWVigTHHzGbseY3aSYdDsAysehsEBgScMmKKjSgBHsVSga+M9o5OZzmfxzLHhfwEia8WdaSOyQBn7OzGX7Auc6+5TLcJR6l3flM05dQwQ11t2OkFaPx/5xLJVcihDoeAwnXRMKjo3pWSRJ0TsJURKZ988RbSAA6y2NWukUfIKxGw9xx7wv4+5O6E4XnctX32zT1tQzjvwekVLRVKVayEDvZlgrS1LMqWVBxLHdKEEkg04Mj8JnJ1NDqcmtyxrHjjHqFwOBb311SPcxwYn5nz6XBTFyeJwUbnqvV19ZoXqrGG3KsE2aTrBPaHubJZytTX2gjG5ZWrw6IVk1MVqXUItjb8B+1XM0PNNJM8aDnC5nKqWcE/6DeIiq0Tnzv X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:28.8455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70dc324b-dbe7-4e88-60d9-08dc4fb7a1b4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6092 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231536_354562_16CA5FE6 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allow __arm_smmu_cmdq_skip_err function to be reused by NVIDIA Tegra241 CMDQV unit since it will use the same data structure for q. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 +++++++++------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 44fcc0c0a149..6cb20bff5a8a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -379,8 +379,7 @@ static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, arm_smmu_cmdq_build_cmd(cmd, &ent); } -static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, - struct arm_smmu_queue *q) +void __arm_smmu_cmdq_skip_err(struct device *dev, struct arm_smmu_queue *q) { static const char * const cerror_str[] = { [CMDQ_ERR_CERROR_NONE_IDX] = "No error", @@ -397,12 +396,12 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, .opcode = CMDQ_OP_CMD_SYNC, }; - dev_err(smmu->dev, "CMDQ error (cons 0x%08x): %s\n", cons, + dev_err(dev, "CMDQ error (cons 0x%08x): %s\n", cons, idx < ARRAY_SIZE(cerror_str) ? cerror_str[idx] : "Unknown"); switch (idx) { case CMDQ_ERR_CERROR_ABT_IDX: - dev_err(smmu->dev, "retrying command fetch\n"); + dev_err(dev, "retrying command fetch\n"); return; case CMDQ_ERR_CERROR_NONE_IDX: return; @@ -424,9 +423,12 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, * not to touch any of the shadow cmdq state. */ queue_read(cmd, Q_ENT(q, cons), q->ent_dwords); - dev_err(smmu->dev, "skipping command in error state:\n"); + dev_err(dev, "skipping command in error state:\n"); for (i = 0; i < ARRAY_SIZE(cmd); ++i) - dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); + dev_err(dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); + + if (q->quirks & CMDQ_QUIRK_SYNC_CS_NONE_ONLY) + cmd_sync.sync.cs_none = true; /* Convert the erroneous command into a CMD_SYNC */ arm_smmu_cmdq_build_cmd(cmd, &cmd_sync); @@ -436,7 +438,7 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, static void arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu) { - __arm_smmu_cmdq_skip_err(smmu, &smmu->cmdq.q); + __arm_smmu_cmdq_skip_err(smmu->dev, &smmu->cmdq.q); } /* diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 4af0976a2338..3046c1028e66 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -760,6 +760,7 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq); +void __arm_smmu_cmdq_skip_err(struct device *dev, struct arm_smmu_queue *q); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); From patchwork Fri Mar 29 06:14:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610177 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB264CD1288 for ; Fri, 29 Mar 2024 06:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kKkrTHh/CBZ0s0qw3WhP086tqiRIyBBVxcyVM55ifyQ=; b=Tw3Pq2ktcr/JVb go0Xdd7Ubt2OuiRVoqrWhToskhr+8NwLjH4VVnmlRiLmZXPyqqAVfOdBygR84Q2BrZvkdvqcbMRKL jcO/6dzyKNVHW3gSHrXb89v1KlCsXqDlGfYI2ZtyQcuKGMi95XG34G8rcmHN0Jsye69BXEoUYKvJV ysjmXk46X8nNiOLS3O4gquIU27A8bmtthKqsA0kKiRf+iEesmHsQylkVEiH8ieCSGICKjK5Jp0bK9 5FMFMaDG7dVY7jbQI+SlRkUyyhUVtf1hPwOoEaafV1ps0bP/xpZZhkGq8Z/geJwlUIJsLzYp3HX7k 6hVjNJAieVGYi1kvkySQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wq-0000000H02J-3Mth; Fri, 29 Mar 2024 06:15:52 +0000 Received: from mail-mw2nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:200a::600] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wa-0000000Gztm-19ol for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EP8ebBUwOJtevfhMYjsgjn52pkLeB/g1+jA30wqdUB1/1vdvNXsQGWmdUzYFxLsZLeQOlEehThmet9y26XQkrfT0kt0UMr8q3TRsFugVEhjk5fFxkOVrrXRNgBf5vLMQu9lw2mkdfXswR4F8xO0u3uMkYKNioY3TNvSDbbwx9unYjBw2iKgeWk73v+EOMzFvx16/V4GnnlK7pY4pz3F4xMxdaEBATgRkf59Y60WMzm/i7bcQYzOmp0vyXVDHSBckbO3f1QwiSDs1F1HTNDMB2yhKmyWcmSniuOCuTHiNqAd1PIpPUsXeHhRz9dGyYSWt6g0VAtPvpOT7El0RyguIvg== 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=PcurntWljFabsf9xTfcX1B5g9bJ+JITr1GT/HWbNbmk=; b=KbeKNW4fOsaktCz3iHl3r42U3+pDn0LaWUw3L+cc6GE1pTxICYjva7UIdGJ+KzmI5c/pgLQ9ayf1yQyN6DwSElwmXmV6/KapiCWUJTrnxZh39nLQThl4UTjuCgpEf7JpvsGJ7DyfvzrLTsGVbWE9s4G4yEYX5Q1TCMoQCx4ZDffYDyvmtS8RlkziyS/M/9LtNQVX1tD7T6YQJuWanCfScS3uPS7gfBTgxfhXxxIlHeikWHHz1Bbd/yqvYsLJXuyKjQJP2GINutNrehbcTww7jiel12pxqyxxMpPJR9ScAJxLY0NO3IbgSZtDX8lARgJThfYDp6cpkAbyDCywItNtmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PcurntWljFabsf9xTfcX1B5g9bJ+JITr1GT/HWbNbmk=; b=MfA6GcC4QyUkOxkf4UI0O8Xg46a4GhJwNgKfeu7Vppl5+XYQe8PgySSZgCVHny5sjl17Za5ILb/MFTbAzaFEYu1ISSF3nceNB+a3FBhJiGy8okJCGuxxN6+P3Kvk8bsGh4YVMAbIz2FdTaUS3Kkn3OIEkUo2cYHynj5fdyM0dkY18NBKDJZKw+W3rLzB31vvc8ufg1wQ97fFce1BV28IcOKTDF4F0juSEnobCQHDAtKPkTVMYMeqbGCv2dUR3STA9eRmUsJKI6UtLPoqgTUirzTI3bLRnlM32SvFhwGI0gZKvKrigPDdtnMebrvCgF2lsQHako8yxmLZIX4taOLmKw== Received: from BN9PR03CA0859.namprd03.prod.outlook.com (2603:10b6:408:13d::24) by BL1PR12MB5945.namprd12.prod.outlook.com (2603:10b6:208:398::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.38; Fri, 29 Mar 2024 06:15:30 +0000 Received: from BN2PEPF000044A4.namprd02.prod.outlook.com (2603:10b6:408:13d:cafe::fb) by BN9PR03CA0859.outlook.office365.com (2603:10b6:408:13d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Fri, 29 Mar 2024 06:15:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN2PEPF000044A4.mail.protection.outlook.com (10.167.243.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:30 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:17 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:17 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:16 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 4/6] iommu/arm-smmu-v3: Pass in cmdq pointer to arm_smmu_cmdq_issue_cmdlist() Date: Thu, 28 Mar 2024 23:14:08 -0700 Message-ID: <5f1283471b5e0fe415afc7af3b6db7d06f21ff53.1711690673.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A4:EE_|BL1PR12MB5945:EE_ X-MS-Office365-Filtering-Correlation-Id: 620fdab4-09e7-47bf-2bc7-08dc4fb7a2ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aJIQQY59UzjpSt2z3+GRQqc1qgnt9a/hMUOc0WzRWp69MPiruTF/6tP3qT39DMPLKWoOaPMFQ5zYjUHXA/5qA83wqEaVIOAp4+7EN3i53VOsms5fbpOtsyU39ONsXRF7F5SREcyuOz0LJQ5Rf067MWpKAzLBB6j88rnofBRcZpgQuNBbx3bDNClTn9TtYritjjrgoNmoB3ijVP5DPs40TPhID8EFHLxs17ebozzQbMvRw/5qXouw1pvZZLXDan6pAnV6iWRe43rr1z98fs+UGL8755nEGyakDV/+xXSTr6wK7M90YYwtE5nh2kFAKkHj1XDOHGnWME3sTwlAtzTW+oADczD6w0XSn8Ure+icShupBysqw/1qpA8wmA55mD8wjvK2n3VedDVHybMt9q2m+BAKLGA76oLd0tR7G/emPTkuvrNByeQ2/92rgxHV7/0VNBvy6uewfMw6yt48YQaSu0AaSWRdVDmKtb0ZkqyqLzYT3PqxKhOZ1KSf+lca/Mm3fH2YfOnulgr2FR35Kr8yBP4YOLIEhiu6zE1k7YDQhJcPFz/C2yBlNG41Wqlu8zL9th5b2tjTwnZIaJQIv+as64LUxMX6T1X7M/X4IvCMYHh5Cu6AnZT8SbGNbd0SZVWPPMg6s0sNJPZjdx7Abd1hgLFB7JMXFkhsiLEbhGmbOQVzP8BktWvJ6G2XLmwkdfNyXS6b8NaK1i4TY3fqeUsFxbfIBo4slnPqEhexJyzJ/qgj0Hg/Ql/rg3hGH/BHD6Wa X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:30.5455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 620fdab4-09e7-47bf-2bc7-08dc4fb7a2ba X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5945 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231536_758756_4D16AF1D X-CRM114-Status: GOOD ( 12.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver currently calls arm_smmu_get_cmdq() helper in different places, although they are all called from the arm_smmu_cmdq_issue_cmdlist(). Allow to pass in the cmdq pointer, instead of calling arm_smmu_get_cmdq() every time. This will also help CMDQV extension in NVIDIA Tegra241 SoC, as its driver will maintain its own cmdq pointers, then need to redirect arm_smmu->cmdq to one of its vcmdqs upon seeing a supported command. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6cb20bff5a8a..7630c1dd5235 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -603,11 +603,11 @@ static void arm_smmu_cmdq_poll_valid_map(struct arm_smmu_cmdq *cmdq, /* Wait for the command queue to become non-full */ static int arm_smmu_cmdq_poll_until_not_full(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq, struct arm_smmu_ll_queue *llq) { unsigned long flags; struct arm_smmu_queue_poll qp; - struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu); int ret = 0; /* @@ -638,11 +638,11 @@ static int arm_smmu_cmdq_poll_until_not_full(struct arm_smmu_device *smmu, * Must be called with the cmdq lock held in some capacity. */ static int __arm_smmu_cmdq_poll_until_msi(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq, struct arm_smmu_ll_queue *llq) { int ret = 0; struct arm_smmu_queue_poll qp; - struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu); u32 *cmd = (u32 *)(Q_ENT(&cmdq->q, llq->prod)); queue_poll_init(smmu, &qp); @@ -662,10 +662,10 @@ static int __arm_smmu_cmdq_poll_until_msi(struct arm_smmu_device *smmu, * Must be called with the cmdq lock held in some capacity. */ static int __arm_smmu_cmdq_poll_until_consumed(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq, struct arm_smmu_ll_queue *llq) { struct arm_smmu_queue_poll qp; - struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu); u32 prod = llq->prod; int ret = 0; @@ -712,13 +712,14 @@ static int __arm_smmu_cmdq_poll_until_consumed(struct arm_smmu_device *smmu, } static int arm_smmu_cmdq_poll_until_sync(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq, struct arm_smmu_ll_queue *llq) { if (smmu->options & ARM_SMMU_OPT_MSIPOLL && !(cmdq->q.quirks & CMDQ_QUIRK_SYNC_CS_NONE_ONLY)) - return __arm_smmu_cmdq_poll_until_msi(smmu, llq); + return __arm_smmu_cmdq_poll_until_msi(smmu, cmdq, llq); - return __arm_smmu_cmdq_poll_until_consumed(smmu, llq); + return __arm_smmu_cmdq_poll_until_consumed(smmu, cmdq, llq); } static void arm_smmu_cmdq_write_entries(struct arm_smmu_cmdq *cmdq, u64 *cmds, @@ -775,7 +776,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, while (!queue_has_space(&llq, n + sync)) { local_irq_restore(flags); - if (arm_smmu_cmdq_poll_until_not_full(smmu, &llq)) + if (arm_smmu_cmdq_poll_until_not_full(smmu, cmdq, &llq)) dev_err_ratelimited(smmu->dev, "CMDQ timeout\n"); local_irq_save(flags); } @@ -851,7 +852,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, /* 5. If we are inserting a CMD_SYNC, we must wait for it to complete */ if (sync) { llq.prod = queue_inc_prod_n(&llq, n); - ret = arm_smmu_cmdq_poll_until_sync(smmu, &llq); + ret = arm_smmu_cmdq_poll_until_sync(smmu, cmdq, &llq); if (ret) { dev_err_ratelimited(smmu->dev, "CMD_SYNC timeout at 0x%08x [hwprod 0x%08x, hwcons 0x%08x]\n", From patchwork Fri Mar 29 06:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610180 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4FB2CD1283 for ; Fri, 29 Mar 2024 06:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v6JzGlFuvmvmuIfRI06/4ypqYcNrX+BCYf2gvXUbfGI=; b=1zmeqk1RB12Rki G9o71s4uU90iq30ti0RL2rx7PiHp8jbLm9uDl1UZ7tuA2O7Z8fmMPwhX87Yya/nJEB+SdbpVTDn6P gSpNbHaS12SxwNZ7bAX2T4rgOb/oL4hfC2E7loPm269OwRYS6+WYSmxjjRBcP0Ep+NsXig1Xidxme L/Ixtn6p8vwV1Qd1IZ8YJdNdawg0ZQm7JO51zYvzQCoBzoxzGDKqJhF7hBL3RTtKx3gr6V4hs1hVK t06nHAdyOEzf+wqsH9RYvQU8LDyM8bdGlSacJXOl5w/LFMiocELbMF8u1lPix9Hg67vT5mJ/85Zp1 4uLirzmnZUlv7+HWPOFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Ww-0000000H06S-0gYQ; Fri, 29 Mar 2024 06:15:58 +0000 Received: from mail-bn8nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2414::600] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wf-0000000Gzwl-2HcU for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KoiZCyKiYTIYPk+bnEdda50kD3gqn0IKrE9BFsl7XI/RrSiaQcYKV+1AELr8bbDjzxk+VE4boE3hSScFybSX68ptRIta/v/zv/lS9+4rJoCu5Rbj8hWf+v/qfOrdSM5RWtEtLDXL/7Png0Xko+7Vi3NEFIANSend81LfX+8pvDbCnK5DMzzrDBMZX2Y/5f5dsW0wsnUk7LfcaX4+2CCkobKDTgvRR0g9pIn6jj34L1qOouel3tk9T7aAd1g1Lh559WrAXfD47gEIsD4hnfWKfFkOVLoQblLwjXX8lUqodqoUaBj0VJnkofEtL28lWPskCn+PXdDQxx7Bt7oiHAD+cg== 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=X5b5S57VndnN5sTUmYsqvhl46CqKwFsi7IdwZGkYII0=; b=K6647ZKWDiveuQrsUYVwpL6QPmAi8e7XAMy3MSXjeiwJIkuC/nYwTVUZnC970eUP7xUyRhYXuWQVC+1+axkWOg4lbN8JZSdk9K1eqxeqdKU6a/00o6AFuw1DVZHLkCoDRmpvZk2NWdNgofIaHSb3/0UtILCIpQjpmKRfoji+pLLf5XBU9Ofm1CXo7CE7cZh4xJu1GCSaofNoyw9f9m1UuQvjg9d93vZK+KfqbfsMr1a/VOYDfT5SHXyD16Me4/o3pwjrJsmrj/kNtiNjbod62nuMp83wW2lNm6qodzQT1a1Xx41bfKTfUFitYs4aydLkwhNfX8uZdQ++53yLnaSdmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X5b5S57VndnN5sTUmYsqvhl46CqKwFsi7IdwZGkYII0=; b=jDNFQfyiiq/XxH32QINq+CBAf7FQsNWLZFsS0ukirKuE3BzG8y6S5v1dmzCneZLRa1BiVF5BQcMb5cT4ahysvt5ee4JE9Meu20Y8s25KoQjVBxElWimApYo/W+F3wuORTaXrLpm7exS5B9TFX3kW67OF1TgdyYwAuDypUr7WDTI7H5w1NtNQDqHjIS+Gl+8qZuFldxLRw5Lm8W0C5Y7Cnib246rwVGPWYCWT4UgXEml88yy5yutKkuZmmd45uRSX4EoB8iiYC0sr/xxAq2LFteDDYkVlTDWixsuIMJrRCJCVh5Rx6j+7N56gm6UNcgkUNZBMnEmXLbowKNY1kmEbsg== Received: from BN1PR12CA0028.namprd12.prod.outlook.com (2603:10b6:408:e1::33) by MN2PR12MB4080.namprd12.prod.outlook.com (2603:10b6:208:1d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Fri, 29 Mar 2024 06:15:33 +0000 Received: from BN2PEPF0000449D.namprd02.prod.outlook.com (2603:10b6:408:e1:cafe::e7) by BN1PR12CA0028.outlook.office365.com (2603:10b6:408:e1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Fri, 29 Mar 2024 06:15:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN2PEPF0000449D.mail.protection.outlook.com (10.167.243.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:32 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:18 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:17 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:17 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 5/6] iommu/arm-smmu-v3: Add in-kernel support for NVIDIA Tegra241 (Grace) CMDQV Date: Thu, 28 Mar 2024 23:14:09 -0700 Message-ID: <98e72b164485b530991d434554d1fa5dc0eb4027.1711690673.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449D:EE_|MN2PR12MB4080:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d19947b-db76-4907-5817-08dc4fb7a409 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dvyFPN8YnhF4wNtu2IWyxLrWGfYvg2G61bBZxrjyDpSzLmQO7DY8Pzcdyl3uMPnU0wzPG6qE4p93Pl/nme7GWOEXyOH9oTpE9KYmZK4NVnlQQj72c14ESxoYOvCMUPoQE+9ZvuS5KSdCT2dyImgdZ9jttt6bq9EijlAo/TLk9XdAIGX8E58n8wi0oC0Ir0o7MLz6odAOKSV/PtvkxpuXrbfdjgrS5iAHLgzwtX9+Dr3PemVI6fBZiuS3Pi3uje07UijVKNMNBxymxpvvWq7b/6SbLNVl00uSWAjVa6zos0fdyJFFFGVAK4HWA33SJhxIw25wGCKWfs4FtpgWnvuPeqMf+iy2eThlTCcaYs5fwQid4QLax+vMpk7BkWxaoKLTV3Nwsrzqb3GF4SIr4edWR+Ux6nH7UT3Q+c43rIozPesJEz8HicMwSzgMGbg/pCDNEwXZ+BCClVPAeBr/+KpRUvjbSU8XFRKzajBfuCohMBTjXJsoQWKESLObsWpWGFL6aJo0NfP8+ojtFPaQQqD1+LK4kcZ/MAq9i3SmKz95LdzuLv/Ibe3LzvQSRggmHBnwXCYGOZlxr7yRC4FMuvXIOLC75yHs9gKzUo4icH96wmTaHwE/upUpgDA7aKSqJ8VxFByRaFUTeYwGuuVIhHCU8JuqQd7KOTO3ygWFHed1m1crl2BJ9XHdkKZmeKFhtfyOg1xvyGrH8jMEU1hNJgAVc/ZjkF5DrwOVqGhFkJgRp9kznw+L+WgVf7sN6dwrPBZ2 X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:32.7578 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d19947b-db76-4907-5817-08dc4fb7a409 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4080 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231542_173453_E3DB416F X-CRM114-Status: GOOD ( 30.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nate Watterson NVIDIA's Tegra241 Soc has a CMDQ-Virtualization (CMDQV) hardware, extending the standard ARM SMMU v3 IP to support multiple VCMDQs with virtualization capabilities. In terms of command queue, they are very like a standard SMMU CMDQ (or ECMDQs), but only support CS_NONE in the CS field of CMD_SYNC. Add a new tegra241-cmdqv driver, and insert its structure pointer into the existing arm_smmu_device, and then add related function calls in the SMMUv3 driver to interact with the CMDQV driver. In the CMDQV driver, add a minimal part for the in-kernel support: reserve VINTF0 for in-kernel use, and assign some of the VCMDQs to the VINTF0, and select one VCMDQ based on the current CPU ID to execute supported commands. This multi-queue design for in-kernel use gives some limited improvements: up to 20% reduction of invalidation time was measured by a multi-threaded DMA unmap benchmark, compared to a single queue. The other part of the CMDQV driver will be user-space support that gives a hypervisor running on the host OS to talk to the driver for virtualization use cases, allowing VMs to use VCMDQs without trappings, i.e. no VM Exits. This is currently WIP based on IOMMUFD, and will be sent for review after SMMU nesting patches are getting merged. This part will provide a guest OS a bigger improvement: 70% to 90% reductions of TLB invalidation time were measured by DMA unmap tests running in a guest OS, compared to nested SMMU CMDQ (with trappings). However, it is very important for this in-kernel support to get merged and installed to VMs running on Grace-powered servers as soon as possible. So, later those servers would only need to upgrade their host kernels for the user-space support. As the initial version, the CMDQV driver only supports ACPI configurations. Signed-off-by: Nate Watterson Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen --- MAINTAINERS | 1 + drivers/iommu/Kconfig | 12 + drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 37 ++ .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 623 ++++++++++++++++++ 6 files changed, 690 insertions(+), 6 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c diff --git a/MAINTAINERS b/MAINTAINERS index aa3b947fb080..ebe8f720fffc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21719,6 +21719,7 @@ M: Thierry Reding R: Krishna Reddy L: linux-tegra@vger.kernel.org S: Supported +F: drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c F: drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c F: drivers/iommu/tegra* diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 0af39bbbe3a3..82e557de31e3 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -410,6 +410,18 @@ config ARM_SMMU_V3_SVA Say Y here if your system supports SVA extensions such as PCIe PASID and PRI. +config TEGRA241_CMDQV + bool "NVIDIA Tegra241 CMDQ-V extension support for ARM SMMUv3" + depends on ARM_SMMU_V3 + depends on ACPI + help + Support for NVIDIA CMDQ-Virtualization extension for ARM SMMUv3. The + CMDQ-V extension is similar to v3.3 ECMDQ for multi command queues + support, except with virtualization capabilities. + + Say Y here if your system is NVIDIA Tegra241 (Grace) or it has the same + CMDQ-V extension. + config S390_IOMMU def_bool y if S390 && PCI depends on S390 && PCI diff --git a/drivers/iommu/arm/arm-smmu-v3/Makefile b/drivers/iommu/arm/arm-smmu-v3/Makefile index 54feb1ecccad..8dff2bc4c7f3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/Makefile +++ b/drivers/iommu/arm/arm-smmu-v3/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o arm_smmu_v3-objs-y += arm-smmu-v3.o arm_smmu_v3-objs-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o +arm_smmu_v3-objs-$(CONFIG_TEGRA241_CMDQV) += tegra241-cmdqv.o arm_smmu_v3-objs := $(arm_smmu_v3-objs-y) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 7630c1dd5235..d12e048ddd93 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -354,6 +354,9 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu) { + if (smmu->tegra241_cmdqv) + return tegra241_cmdqv_get_cmdq(smmu); + return &smmu->cmdq; } @@ -3095,12 +3098,10 @@ static struct iommu_ops arm_smmu_ops = { }; /* Probing and initialisation functions */ -static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, - struct arm_smmu_queue *q, - void __iomem *page, - unsigned long prod_off, - unsigned long cons_off, - size_t dwords, const char *name) +int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, + struct arm_smmu_queue *q, void __iomem *page, + unsigned long prod_off, unsigned long cons_off, + size_t dwords, const char *name) { size_t qsz; @@ -3635,6 +3636,12 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) return ret; } + if (smmu->tegra241_cmdqv) { + ret = tegra241_cmdqv_device_reset(smmu); + if (ret) + return ret; + } + return 0; } @@ -3928,6 +3935,9 @@ static int arm_smmu_device_acpi_probe(struct platform_device *pdev, if (iort_smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE) smmu->features |= ARM_SMMU_FEAT_COHERENCY; + smmu->tegra241_cmdqv = + tegra241_cmdqv_acpi_probe(smmu, node->identifier); + return 0; } #else diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 3046c1028e66..22270de3aed7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -625,6 +625,8 @@ struct arm_smmu_strtab_cfg { u32 strtab_base_cfg; }; +struct tegra241_cmdqv; + /* An SMMUv3 instance */ struct arm_smmu_device { struct device *dev; @@ -687,6 +689,12 @@ struct arm_smmu_device { struct rb_root streams; struct mutex streams_mutex; + + /* + * Pointer to NVIDIA Tegra241 CMDQ-Virtualization Extension support, + * similar to v3.3 ECMDQ except with virtualization capabilities. + */ + struct tegra241_cmdqv *tegra241_cmdqv; }; struct arm_smmu_stream { @@ -761,6 +769,10 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq); void __arm_smmu_cmdq_skip_err(struct device *dev, struct arm_smmu_queue *q); +int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, + struct arm_smmu_queue *q, void __iomem *page, + unsigned long prod_off, unsigned long cons_off, + size_t dwords, const char *name); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); @@ -817,4 +829,29 @@ static inline void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, { } #endif /* CONFIG_ARM_SMMU_V3_SVA */ + +#ifdef CONFIG_TEGRA241_CMDQV +struct tegra241_cmdqv * +tegra241_cmdqv_acpi_probe(struct arm_smmu_device *smmu, int id); +int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu); +struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu); +#else /* CONFIG_TEGRA241_CMDQV */ +static inline struct tegra241_cmdqv * +tegra241_cmdqv_acpi_probe(struct arm_smmu_device *smmu, int id) +{ + return NULL; +} + +static inline int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu) +{ + return -ENODEV; +} + +static inline struct arm_smmu_cmdq * +tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +{ + return NULL; +} +#endif /* CONFIG_TEGRA241_CMDQV */ + #endif /* _ARM_SMMU_V3_H */ diff --git a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c new file mode 100644 index 000000000000..4bfddeb658e2 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c @@ -0,0 +1,623 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2021-2024 NVIDIA CORPORATION & AFFILIATES. */ + +#define dev_fmt(fmt) "tegra241_cmdqv: " fmt + +#include +#include +#include +#include +#include + +#include + +#include "arm-smmu-v3.h" + +#define TEGRA241_CMDQV_HID "NVDA200C" + +/* CMDQV register page base and size defines */ +#define TEGRA241_CMDQV_CONFIG_BASE (0) +#define TEGRA241_CMDQV_CONFIG_SIZE (SZ_64K) +#define TEGRA241_VCMDQ_PAGE0_BASE (TEGRA241_CMDQV_CONFIG_BASE + SZ_64K) +#define TEGRA241_VCMDQ_PAGE1_BASE (TEGRA241_VCMDQ_PAGE0_BASE + SZ_64K) +#define TEGRA241_VINTF_VCMDQ_BASE (TEGRA241_VCMDQ_PAGE1_BASE + SZ_64K) + +/* CMDQV global config regs */ +#define TEGRA241_CMDQV_CONFIG 0x0000 +#define CMDQV_EN BIT(0) + +#define TEGRA241_CMDQV_PARAM 0x0004 +#define CMDQV_NUM_VINTF_LOG2 GENMASK(11, 8) +#define CMDQV_NUM_VCMDQ_LOG2 GENMASK(7, 4) + +#define TEGRA241_CMDQV_STATUS 0x0008 +#define CMDQV_STATUS GENMASK(2, 1) +#define CMDQV_ENABLED BIT(0) + +#define TEGRA241_CMDQV_VINTF_ERR_MAP 0x0014 +#define TEGRA241_CMDQV_VINTF_INT_MASK 0x001C +#define TEGRA241_CMDQV_VCMDQ_ERR_MAP0 0x0024 +#define TEGRA241_CMDQV_VCMDQ_ERR_MAP(i) (0x0024 + 0x4*(i)) + +#define TEGRA241_CMDQV_CMDQ_ALLOC(q) (0x0200 + 0x4*(q)) +#define CMDQV_CMDQ_ALLOC_VINTF GENMASK(20, 15) +#define CMDQV_CMDQ_ALLOC_LVCMDQ GENMASK(7, 1) +#define CMDQV_CMDQ_ALLOCATED BIT(0) + +/* VINTF config regs */ +#define TEGRA241_VINTF(v) (0x1000 + 0x100*(v)) + +#define TEGRA241_VINTF_CONFIG 0x0000 +#define VINTF_HYP_OWN BIT(17) +#define VINTF_VMID GENMASK(16, 1) +#define VINTF_EN BIT(0) + +#define TEGRA241_VINTF_STATUS 0x0004 +#define VINTF_STATUS GENMASK(3, 1) +#define VINTF_ENABLED BIT(0) + +#define TEGRA241_VINTF_CMDQ_ERR_MAP(m) (0x00C0 + 0x4*(m)) + +/* VCMDQ config regs */ +/* -- PAGE0 -- */ +#define TEGRA241_VCMDQ_PAGE0(q) (TEGRA241_VCMDQ_PAGE0_BASE + 0x80*(q)) + +#define TEGRA241_VCMDQ_CONS 0x00000 +#define VCMDQ_CONS_ERR GENMASK(30, 24) + +#define TEGRA241_VCMDQ_PROD 0x00004 + +#define TEGRA241_VCMDQ_CONFIG 0x00008 +#define VCMDQ_EN BIT(0) + +#define TEGRA241_VCMDQ_STATUS 0x0000C +#define VCMDQ_ENABLED BIT(0) + +#define TEGRA241_VCMDQ_GERROR 0x00010 +#define TEGRA241_VCMDQ_GERRORN 0x00014 + +/* -- PAGE1 -- */ +#define TEGRA241_VCMDQ_PAGE1(q) (TEGRA241_VCMDQ_PAGE1_BASE + 0x80*(q)) +#define VCMDQ_ADDR GENMASK(47, 5) +#define VCMDQ_LOG2SIZE GENMASK(4, 0) + +#define TEGRA241_VCMDQ_BASE 0x00000 +#define TEGRA241_VCMDQ_CONS_INDX_BASE 0x00008 + +/* VINTF logical-VCMDQ pages */ +#define TEGRA241_VINTFi_PAGE0(i) (TEGRA241_VINTF_VCMDQ_BASE + SZ_128K*(i)) +#define TEGRA241_VINTFi_PAGE1(i) (TEGRA241_VINTFi_PAGE0(i) + SZ_64K) +#define TEGRA241_VINTFi_VCMDQ_PAGE0(i, q) \ + (TEGRA241_VINTFi_PAGE0(i) + 0x80*(q)) +#define TEGRA241_VINTFi_VCMDQ_PAGE1(i, q) \ + (TEGRA241_VINTFi_PAGE1(i) + 0x80*(q)) + +/* MMIO helpers */ +#define cmdqv_readl(reg) \ + readl(cmdqv->base + TEGRA241_CMDQV_##reg) +#define cmdqv_readl_relaxed(reg) \ + readl_relaxed(cmdqv->base + TEGRA241_CMDQV_##reg) +#define cmdqv_write(val, reg) \ + writel((val), cmdqv->base + TEGRA241_CMDQV_##reg) +#define cmdqv_writel_relaxed(val, reg) \ + writel_relaxed((val), cmdqv->base + TEGRA241_CMDQV_##reg) + +#define vintf_readl(reg) \ + readl(vintf->base + TEGRA241_VINTF_##reg) +#define vintf_readl_relaxed(reg) \ + readl_relaxed(vintf->base + TEGRA241_VINTF_##reg) +#define vintf_writel(val, reg) \ + writel((val), vintf->base + TEGRA241_VINTF_##reg) +#define vintf_writel_relaxed(val, reg) \ + writel_relaxed((val), vintf->base + TEGRA241_VINTF_##reg) + +#define vcmdq_page0_readl(reg) \ + readl(vcmdq->page0 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page0_readl_relaxed(reg) \ + readl_relaxed(vcmdq->page0 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page0_writel(val, reg) \ + writel((val), vcmdq->page0 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page0_writel_relaxed(val, reg) \ + writel_relaxed((val), vcmdq->page0 + TEGRA241_VCMDQ_##reg) + +#define vcmdq_page1_readl(reg) \ + readl(vcmdq->page1 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page1_readl_relaxed(reg) \ + readl_relaxed(vcmdq->page1 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page1_writel(val, reg) \ + writel((val), vcmdq->page1 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page1_writel_relaxed(val, reg) \ + writel_relaxed((val), vcmdq->page1 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page1_writeq(val, reg) \ + writeq((val), vcmdq->page1 + TEGRA241_VCMDQ_##reg) +#define vcmdq_page1_writeq_relaxed(val, reg) \ + writeq_relaxed((val), vcmdq->page1 + TEGRA241_VCMDQ_##reg) + +/* Logging helpers */ +#define cmdqv_warn(fmt, ...) \ + dev_warn(cmdqv->dev, fmt, ##__VA_ARGS__) +#define cmdqv_err(fmt, ...) \ + dev_err(cmdqv->dev, fmt, ##__VA_ARGS__) +#define cmdqv_info(fmt, ...) \ + dev_info(cmdqv->dev, fmt, ##__VA_ARGS__) +#define cmdqv_dbg(fmt, ...) \ + dev_dbg(cmdqv->dev, fmt, ##__VA_ARGS__) + +#define vintf_warn(fmt, ...) \ + dev_warn(cmdqv->dev, "VINTF%u: " fmt, vintf->idx, ##__VA_ARGS__) +#define vintf_err(fmt, ...) \ + dev_err(cmdqv->dev, "VINTF%u: " fmt, vintf->idx, ##__VA_ARGS__) +#define vintf_info(fmt, ...) \ + dev_info(cmdqv->dev, "VINTF%u: " fmt, vintf->idx, ##__VA_ARGS__) +#define vintf_dbg(fmt, ...) \ + dev_dbg(cmdqv->dev, "VINTF%u: " fmt, vintf->idx, ##__VA_ARGS__) + +#define vcmdq_warn(fmt, ...) \ + do { \ + if (vcmdq->vintf) \ + vintf_warn("VCMDQ%u/LVCMDQ%u: " fmt, \ + vcmdq->idx, vcmdq->logical_idx, \ + ##__VA_ARGS__); \ + else \ + dev_warn(cmdqv->dev, "VCMDQ%u: " fmt, \ + vcmdq->idx, ##__VA_ARGS__); \ + } while (0) +#define vcmdq_err(fmt, ...) \ + do { \ + if (vcmdq->vintf) \ + vintf_err("VCMDQ%u/LVCMDQ%u: " fmt, \ + vcmdq->idx, vcmdq->logical_idx, \ + ##__VA_ARGS__); \ + else \ + dev_err(cmdqv->dev, "VCMDQ%u: " fmt, \ + vcmdq->idx, ##__VA_ARGS__); \ + } while (0) +#define vcmdq_info(fmt, ...) \ + do { \ + if (vcmdq->vintf) \ + vintf_info("VCMDQ%u/LVCMDQ%u: " fmt, \ + vcmdq->idx, vcmdq->logical_idx, \ + ##__VA_ARGS__); \ + else \ + dev_info(cmdqv->dev, "VCMDQ%u: " fmt, \ + vcmdq->idx, ##__VA_ARGS__); \ + } while (0) +#define vcmdq_dbg(fmt, ...) \ + do { \ + if (vcmdq->vintf) \ + vintf_dbg("VCMDQ%u/LVCMDQ%u: " fmt, \ + vcmdq->idx, vcmdq->logical_idx, \ + ##__VA_ARGS__); \ + else \ + dev_dbg(cmdqv->dev, "VCMDQ%u: " fmt, \ + vcmdq->idx, ##__VA_ARGS__); \ + } while (0) + +static bool disable_cmdqv; +module_param(disable_cmdqv, bool, 0444); +MODULE_PARM_DESC(disable_cmdqv, + "This allows to disable CMDQV and use default SMMU internal CMDQ."); + +struct tegra241_vcmdq { + u16 idx; + u16 logical_idx; + + struct arm_smmu_cmdq cmdq; + struct tegra241_vintf *vintf; + + void __iomem *page0; + void __iomem *page1; +}; + +struct tegra241_vintf { + u16 idx; + + bool enabled; + atomic_t error; + + struct tegra241_cmdqv *cmdqv; + struct tegra241_vcmdq **vcmdqs; + + void __iomem *base; +}; + +struct tegra241_cmdqv { + struct arm_smmu_device *smmu; + + struct device *dev; + struct resource res; + void __iomem *base; + int irq; + + /* CMDQV Hardware Params */ + u16 num_total_vintfs; + u16 num_total_vcmdqs; + u16 num_vcmdqs_per_vintf; + + struct xarray vcmdqs; + struct xarray vintfs; + + struct tegra241_vintf **vintf; +}; + +static void tegra241_cmdqv_handle_vintf0_error(struct tegra241_cmdqv *cmdqv) +{ + struct tegra241_vintf *vintf = cmdqv->vintf[0]; + bool error; + int i; + + /* Cache error status to bypass VCMDQs until error is recovered */ + error = !!FIELD_GET(VINTF_STATUS, vintf_readl_relaxed(STATUS)); + atomic_set(&vintf->error, error); + + for (i = 0; i < 4; i++) { + u32 lvcmdq_err_map = vintf_readl_relaxed(CMDQ_ERR_MAP(i)); + + while (lvcmdq_err_map) { + int qidx = ffs(lvcmdq_err_map) - 1; + struct tegra241_vcmdq *vcmdq = vintf->vcmdqs[qidx]; + u32 gerrorn, gerror; + + lvcmdq_err_map &= ~BIT(qidx); + + __arm_smmu_cmdq_skip_err(cmdqv->dev, &vcmdq->cmdq.q); + + gerrorn = vcmdq_page0_readl_relaxed(GERRORN); + gerror = vcmdq_page0_readl_relaxed(GERROR); + + vcmdq_page0_writel(gerror, GERRORN); + } + } + + /* Now error status should be clean, cache it again */ + error = !!FIELD_GET(VINTF_STATUS, vintf_readl_relaxed(STATUS)); + atomic_set(&vintf->error, error); +} + +static irqreturn_t tegra241_cmdqv_isr(int irq, void *devid) +{ + struct tegra241_cmdqv *cmdqv = (struct tegra241_cmdqv *)devid; + u32 vintf_errs[2]; + u32 vcmdq_errs[4]; + + vintf_errs[0] = cmdqv_readl_relaxed(VINTF_ERR_MAP); + vintf_errs[1] = cmdqv_readl_relaxed(VINTF_ERR_MAP + 0x4); + + vcmdq_errs[0] = cmdqv_readl_relaxed(VCMDQ_ERR_MAP(0)); + vcmdq_errs[1] = cmdqv_readl_relaxed(VCMDQ_ERR_MAP(1)); + vcmdq_errs[2] = cmdqv_readl_relaxed(VCMDQ_ERR_MAP(2)); + vcmdq_errs[3] = cmdqv_readl_relaxed(VCMDQ_ERR_MAP(3)); + + cmdqv_warn("unexpected cmdqv error reported\n"); + cmdqv_warn(" vintf_map: 0x%08X%08X\n", vintf_errs[1], vintf_errs[0]); + cmdqv_warn(" vcmdq_map: 0x%08X%08X%08X%08X\n", + vcmdq_errs[3], vcmdq_errs[2], vcmdq_errs[1], vcmdq_errs[0]); + + /* Handle VINTF0 and its VCMDQs */ + if (vintf_errs[0] & 0x1) + tegra241_cmdqv_handle_vintf0_error(cmdqv); + + return IRQ_HANDLED; +} + +/* Adapt struct arm_smmu_cmdq init sequences from arm-smmu-v3.c for VCMDQs */ +static int tegra241_cmdqv_init_one_vcmdq(struct tegra241_vcmdq *vcmdq) +{ + struct tegra241_cmdqv *cmdqv = vcmdq->vintf->cmdqv; + struct arm_smmu_cmdq *cmdq = &vcmdq->cmdq; + struct arm_smmu_queue *q = &cmdq->q; + char name[16]; + int ret; + + sprintf(name, "vcmdq%u", vcmdq->idx); + + q->llq.max_n_shift = ilog2(SZ_64K >> CMDQ_ENT_SZ_SHIFT); + + /* Use the common helper to init the VCMDQ, and then... */ + ret = arm_smmu_init_one_queue(cmdqv->smmu, q, vcmdq->page0, + TEGRA241_VCMDQ_PROD, TEGRA241_VCMDQ_CONS, + CMDQ_ENT_DWORDS, name); + if (ret) + return ret; + + /* ...override q_base to write VCMDQ_BASE registers */ + q->q_base = q->base_dma & VCMDQ_ADDR; + q->q_base |= FIELD_PREP(VCMDQ_LOG2SIZE, q->llq.max_n_shift); + + /* All VCMDQs support CS_NONE only for CMD_SYNC */ + q->quirks = CMDQ_QUIRK_SYNC_CS_NONE_ONLY; + + return arm_smmu_cmdq_init(cmdqv->smmu, cmdq); +} + +struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = smmu->tegra241_cmdqv; + struct tegra241_vintf *vintf = cmdqv->vintf[0]; + u16 qidx; + + /* Use SMMU CMDQ if vintf[0] is uninitialized */ + if (!vintf->enabled) + return &smmu->cmdq; + + /* Use SMMU CMDQ if vintf[0] has error status */ + if (atomic_read(&vintf->error)) + return &smmu->cmdq; + + /* + * Select a vcmdq to use. Here we use a temporal solution to + * balance out traffic on cmdq issuing: each cmdq has its own + * lock, if all cpus issue cmdlist using the same cmdq, only + * one CPU at a time can enter the process, while the others + * will be spinning at the same lock. + */ + qidx = smp_processor_id() % cmdqv->num_vcmdqs_per_vintf; + return &vintf->vcmdqs[qidx]->cmdq; +} + +static int tegra241_vintf0_init_vcmdq(struct tegra241_vcmdq *vcmdq) +{ + struct tegra241_vintf *vintf = vcmdq->vintf; + struct tegra241_cmdqv *cmdqv = vintf->cmdqv; + u32 regval; + int ret; + + /* Setup struct arm_smmu_cmdq data members */ + tegra241_cmdqv_init_one_vcmdq(vcmdq); + + /* Configure and enable the vcmdq */ + vcmdq_page0_writel_relaxed(0, PROD); + vcmdq_page0_writel_relaxed(0, CONS); + + vcmdq_page1_writeq_relaxed(vcmdq->cmdq.q.q_base, BASE); + vcmdq_page0_writel_relaxed(VCMDQ_EN, CONFIG); + + ret = readl_poll_timeout(vcmdq->page0 + TEGRA241_VCMDQ_STATUS, + regval, regval == VCMDQ_ENABLED, + 1, ARM_SMMU_POLL_TIMEOUT_US); + if (ret) { + u32 gerror = vcmdq_page0_readl_relaxed(GERROR); + u32 gerrorn = vcmdq_page0_readl_relaxed(GERRORN); + u32 cons = vcmdq_page0_readl_relaxed(CONS); + + vcmdq_err("failed to enable\n"); + vcmdq_err(" GERROR=0x%X\n", gerror); + vcmdq_err(" GERRORN=0x%X\n", gerrorn); + vcmdq_err(" CONS=0x%X\n", cons); + return ret; + } + + vcmdq_info("inited\n"); + return 0; +} + +int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = smmu->tegra241_cmdqv; + struct tegra241_vintf *vintf = cmdqv->vintf[0]; + u32 regval; + u16 qidx; + int ret; + + /* Setup vintf[0] for host kernel */ + vintf->idx = 0; + vintf->cmdqv = cmdqv; + atomic_set(&vintf->error, 0); + vintf->base = cmdqv->base + TEGRA241_VINTF(0); + + regval = FIELD_PREP(VINTF_HYP_OWN, 1); + vintf_writel(regval, CONFIG); + + regval |= FIELD_PREP(VINTF_EN, 1); + vintf_writel(regval, CONFIG); + + ret = readl_relaxed_poll_timeout(vintf->base + TEGRA241_VINTF_STATUS, + regval, regval & VINTF_ENABLED, + 1, ARM_SMMU_POLL_TIMEOUT_US); + if (ret) { + vintf_err("failed to enable: STATUS = 0x%08X\n", regval); + return ret; + } + + vintf->enabled = true; + + /* Allocate vcmdqs to vintf */ + for (qidx = 0; qidx < cmdqv->num_vcmdqs_per_vintf; qidx++) { + regval = FIELD_PREP(CMDQV_CMDQ_ALLOC_VINTF, vintf->idx); + regval |= FIELD_PREP(CMDQV_CMDQ_ALLOC_LVCMDQ, qidx); + regval |= CMDQV_CMDQ_ALLOCATED; + cmdqv_writel_relaxed(regval, CMDQ_ALLOC(qidx)); + } + + /* Build an arm_smmu_cmdq for each vcmdq allocated to vintf */ + vintf->vcmdqs = devm_kcalloc(cmdqv->dev, cmdqv->num_vcmdqs_per_vintf, + sizeof(*vintf->vcmdqs), GFP_KERNEL); + if (!vintf->vcmdqs) + return -ENOMEM; + + for (qidx = 0; qidx < cmdqv->num_vcmdqs_per_vintf; qidx++) { + struct tegra241_vcmdq *vcmdq; + + vcmdq = devm_kzalloc(cmdqv->dev, sizeof(*vcmdq), GFP_KERNEL); + if (!vcmdq) + return -ENOMEM; + vcmdq->vintf = vintf; + vcmdq->idx = vcmdq->logical_idx = qidx; + vcmdq->page0 = cmdqv->base + TEGRA241_VCMDQ_PAGE0(qidx); + vcmdq->page1 = cmdqv->base + TEGRA241_VCMDQ_PAGE1(qidx); + ret = tegra241_vintf0_init_vcmdq(vcmdq); + if (ret) + return ret; + vintf->vcmdqs[qidx] = vcmdq; + } + + /* Reserve vintf[0] for kernel and hypervisor use */ + xa_init_flags(&cmdqv->vintfs, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT); + xa_init_flags(&cmdqv->vcmdqs, XA_FLAGS_ALLOC | XA_FLAGS_ACCOUNT); + + if (cmdqv->vintf && cmdqv->vintf[0]) + cmdqv->vintf[0] = vintf; + + return 0; +} + +static int tegra241_cmdqv_acpi_is_memory(struct acpi_resource *res, void *data) +{ + struct resource_win win; + + return !acpi_dev_resource_address_space(res, &win); +} + +static int tegra241_cmdqv_acpi_get_irqs(struct acpi_resource *ares, void *data) +{ + struct resource r; + int *irq = data; + + if (*irq <= 0 && acpi_dev_resource_interrupt(ares, 0, &r)) + *irq = r.start; + return 1; /* No need to add resource to the list */ +} + +static struct tegra241_cmdqv * +tegra241_cmdqv_find_resource(struct arm_smmu_device *smmu, int id) +{ + struct tegra241_cmdqv *cmdqv = NULL; + struct device *dev = smmu->dev; + struct list_head resource_list; + struct resource_entry *rentry; + struct acpi_device *adev; + const char *match_uid; + int ret; + + if (acpi_disabled) + return NULL; + + /* Look for a device in the DSDT whose _UID matches the SMMU node ID */ + match_uid = kasprintf(GFP_KERNEL, "%u", id); + adev = acpi_dev_get_first_match_dev(TEGRA241_CMDQV_HID, match_uid, -1); + kfree(match_uid); + + if (!adev) + return NULL; + + dev_info(dev, "found companion CMDQV device, %s\n", + dev_name(&adev->dev)); + + INIT_LIST_HEAD(&resource_list); + ret = acpi_dev_get_resources(adev, &resource_list, + tegra241_cmdqv_acpi_is_memory, NULL); + if (ret < 0) { + dev_err(dev, "failed to get memory resource: %d\n", ret); + goto put_dev; + } + + cmdqv = devm_kzalloc(dev, sizeof(*cmdqv), GFP_KERNEL); + if (!cmdqv) + goto free_list; + + cmdqv->dev = dev; + cmdqv->smmu = smmu; + + rentry = list_first_entry_or_null(&resource_list, + struct resource_entry, node); + if (!rentry) { + cmdqv_err("failed to get memory resource entry\n"); + goto free_cmdqv; + } + + cmdqv->res = *(rentry->res); + + cmdqv->base = devm_ioremap_resource(smmu->dev, rentry->res); + if (IS_ERR(cmdqv->base)) { + cmdqv_err("failed to ioremap: %ld\n", PTR_ERR(cmdqv->base)); + goto free_cmdqv; + } + + acpi_dev_free_resource_list(&resource_list); + + INIT_LIST_HEAD(&resource_list); + + ret = acpi_dev_get_resources(adev, &resource_list, + tegra241_cmdqv_acpi_get_irqs, &cmdqv->irq); + if (ret < 0 || cmdqv->irq <= 0) { + cmdqv_warn("no cmdqv interrupt. errors will not be reported\n"); + } else { + ret = devm_request_irq(smmu->dev, cmdqv->irq, + tegra241_cmdqv_isr, 0, + "tegra241-cmdqv", cmdqv); + if (ret) { + cmdqv_err("failed to request irq (%d): %d\n", + cmdqv->irq, ret); + goto iounmap; + } + } + + goto free_list; + +iounmap: + devm_iounmap(cmdqv->dev, cmdqv->base); +free_cmdqv: + devm_kfree(cmdqv->dev, cmdqv); + cmdqv = NULL; +free_list: + acpi_dev_free_resource_list(&resource_list); +put_dev: + put_device(&adev->dev); + + return cmdqv; +} + +struct tegra241_cmdqv * +tegra241_cmdqv_acpi_probe(struct arm_smmu_device *smmu, int id) +{ + struct tegra241_cmdqv *cmdqv; + u32 regval; + + cmdqv = tegra241_cmdqv_find_resource(smmu, id); + if (!cmdqv) + return NULL; + + regval = cmdqv_readl_relaxed(CONFIG); + if (disable_cmdqv) { + cmdqv_info("disable_cmdqv=true. Falling back to SMMU CMDQ\n"); + cmdqv_writel_relaxed(regval & ~CMDQV_EN, CONFIG); + goto free_res; + } + + cmdqv_writel_relaxed(regval | CMDQV_EN, CONFIG); + + regval = cmdqv_readl_relaxed(STATUS); + if (!FIELD_GET(CMDQV_ENABLED, regval) || + FIELD_GET(CMDQV_STATUS, regval)) { + cmdqv_err("CMDQV h/w not ready: CMDQV_STATUS=0x%08X\n", regval); + goto free_res; + } + + regval = cmdqv_readl_relaxed(PARAM); + cmdqv->num_total_vintfs = 1 << FIELD_GET(CMDQV_NUM_VINTF_LOG2, regval); + cmdqv->num_total_vcmdqs = 1 << FIELD_GET(CMDQV_NUM_VCMDQ_LOG2, regval); + cmdqv->num_vcmdqs_per_vintf = + cmdqv->num_total_vcmdqs / cmdqv->num_total_vintfs; + + cmdqv->vintf = devm_kcalloc(cmdqv->dev, cmdqv->num_total_vintfs, + sizeof(*cmdqv->vintf), GFP_KERNEL); + if (!cmdqv->vintf) + goto free_res; + + cmdqv->vintf[0] = devm_kzalloc(cmdqv->dev, sizeof(*(cmdqv->vintf[0])), + GFP_KERNEL); + if (!cmdqv->vintf[0]) + goto free_vintf; + + return cmdqv; + +free_vintf: + devm_kfree(cmdqv->dev, cmdqv->vintf); +free_res: + if (cmdqv->irq > 0) + devm_free_irq(smmu->dev, cmdqv->irq, cmdqv); + devm_iounmap(smmu->dev, cmdqv->base); + devm_kfree(smmu->dev, cmdqv); + + return NULL; +} From patchwork Fri Mar 29 06:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13610178 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 745FBCD1283 for ; Fri, 29 Mar 2024 06:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=no8pq2oAUatsStYo+ardBc2ZmGDreA5rJNyTi+PxuFs=; b=VtzMrUJiN/S4tq UJZppO1srkewxzH3s8Fcqt98zd8wtvD+dR0nMhwIlKpwcTo47xWaEcjo2F0Zv8+06TOdu0NqgCsMl 8wtQG3x+MJSOVMOicDzSI0ndB7qZYNe0G266FqWRx0B+HNPhEVdp4rNvnlJkp0dUt3THP3MjCBSBs 4ATXUeuvK+XJpBHd4/iF8oBAGniumkaGbespE04wMMOBoO7X74SPbxutlzhVJI7OuG1sLCrvZJzQF 11cRwJ5xphbB7IuIcD2bSzu3YECljw1n2YDzlfHy3wcW/OTgFOSLno17ata59klkCWk0WkAF8WHP9 nDNDy6Zb70IBca95VEOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wu-0000000H05Y-39gz; Fri, 29 Mar 2024 06:15:56 +0000 Received: from mail-co1nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2416::600] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rq5Wg-0000000GzxI-1cYa for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2024 06:15:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5nSW3yfUJtrfLJ866zHryt6oIH+9f+dEHD1LQSt4YMUS0AOmV2/p2kMLBJTViqk8yoBXgG7Wz4ZH7QfJXV8ES4v9+C2jyP2fgiJ/jr37vNaIh371/Pz81eXn8AQOPrDe3GAU2WmeCoZoLSYKIzzeZ1XvJk5ls6vNc2PepHTzivBlHhTay/SPpZYjhS9J4RJ4CjYwNGfSDoB4c9uUphP9s1P4O7XNnuYv0q4WKS68JJL8bv8vy1iITmzxLmNFptfBxohwkP30upUEAky2KjGIZbGQvUIFHaLDe13oUcFYR56XTBPY+BJe09pY7OG6hxGqyB4IewsMQyl366B6F7P8Q== 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=vbtlNqhfEjwLm10D5TifXP4/kRQtBuXCBRVV7ZftVrM=; b=TFUQ0EM91ybfGyyJjs0BEHAxPsCypuFpjytp6yDTBY+ZKHnlG6m12pB3eCjFBRZFfTP6IiaJS9hM7JRcRhkybLt/akT7pm4gY9RBpcnHzi82Z3+3gAil3vB3CQ+Pf/wv7hD3RcRcXlfJ2qNuqm5AohHC+NiIscZfT3FyTDfwzOI1f0IqxzcAObSHGv/4r5c2azf0Is7bPfMnGicb4R2X84ArUP8gIP5tQ3v60QriHaN5lva8UT4jaI7oNQ/tl1wbKMhxHTSqWW3zuOb/4kf0wvxR/S4+0ZWFmr800UiZTaMpcVOUM4hfa9h/BmlwaYgF+o0Fi2M/5bWDV/sr3i7ziA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vbtlNqhfEjwLm10D5TifXP4/kRQtBuXCBRVV7ZftVrM=; b=lKOx/EQdvPiSZliW7OqJGz2UtR3K7/95KWJKmgh7s8QPXiwSDI+kBR/NdBJHwL1cEeiMbgsvt2zUtWZiFhw837/SGsL0ZLDKbPlUkygvEdIHXPnA87QgKoRg0K79uZpTX40wmO1LDwzAo5ghDmrwnHQtoGZxUaiS7j9D+LeSkAXinIoyPpmnJuZKN+Ksq3f+vTWaVnvu6B9g83B/fp+rpGVm2vRxbJepPefISWDyYEqqZVjcASUP+/oNmLe4v6gmCOmeR2bD1OfefRTH7nbd4OWaW6LjJmfd3Zzfp/C3L8I08GnSbWtK2O8qelZwNX0Tx3XsWeVkVXbNW0zHquvECA== Received: from BN9PR03CA0855.namprd03.prod.outlook.com (2603:10b6:408:13d::20) by IA1PR12MB8310.namprd12.prod.outlook.com (2603:10b6:208:3ff::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Fri, 29 Mar 2024 06:15:35 +0000 Received: from BN2PEPF000044A4.namprd02.prod.outlook.com (2603:10b6:408:13d:cafe::35) by BN9PR03CA0855.outlook.office365.com (2603:10b6:408:13d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Fri, 29 Mar 2024 06:15:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN2PEPF000044A4.mail.protection.outlook.com (10.167.243.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 06:15:34 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 28 Mar 2024 23:15:19 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 28 Mar 2024 23:15:18 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Thu, 28 Mar 2024 23:15:18 -0700 From: Nicolin Chen To: , CC: , , , , , , , , Subject: [PATCH v4 6/6] iommu/tegra241-cmdqv: Limit CMDs for guest owned VINTF Date: Thu, 28 Mar 2024 23:14:10 -0700 Message-ID: <473c173f8b5ab2878f2948c68d9c9846d664f771.1711690673.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A4:EE_|IA1PR12MB8310:EE_ X-MS-Office365-Filtering-Correlation-Id: 47c22c8b-ebb6-4765-c04d-08dc4fb7a536 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 07O7WT6bb9//9m/0oOUasyvljaOu2cIAp4nXJFYs8Oa1um+8CQfj7sRhi/62JWM9LQhr6boUQ64GRJ54NxsTJyXPiyPJr2br6kp4At/o5bPaueEwWhShQ2GQK/52xlGRCMclBWCVh234Z6gHbwb9UoByYDgg12CH9IpN7IQgifu4Q30THdqrdglhyNTqVaWCz4FV+qB6NmDPFJbmBsuPwTH9rZQG4hoWQV32uJF738AV4zpYfs4RxgyGU++ixR2gdbQJm7lekHGhpiTwoPu8OVKG4FXKCRen0LDbHBHl6sJbW+sD3VTmvEalm/XvyLNCBWja7Dr7o0UrO3AucgoINT0WdhBy1J64K69+fsxSa9xnWV2C3qP+dKzr+VBY40SnZJQMrKm4plgcvGmUsbAefwr5KBefMOd/m4FdgRw4W4beL254n/jEqYRAG5jp9/iUzHkUtP2IC4fIAbi2zfxQ+HM8z/vCver/gd6Hya85Jrro+osh2g9AjdbeQuOhVGqo90XESc47zMqlgZZ7ng3nfSBPjOqlybpSGv4UFfBsQZEtHi3hnbb8JSkkYcrcN0HlozQpZT5wsxJaAKK1e+PkRP7GWLKZHtybxQ9aGfjZ5JLN+MK1gxC5ihVlOjbMsMA31xFr/EIWoF/dSq9cuPZXP0VmhsI2YUxHVGPO7OaTAduPb7MfZml0fcgDU9S2iOlv1HipNIV0bYz+4pFMJEAwpLpVk/175QSHsHgUcivHXq41jWfOi93fVva78UCzO+Vl X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(36860700004)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 06:15:34.7331 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47c22c8b-ebb6-4765-c04d-08dc4fb7a536 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000044A4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8310 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240328_231542_711826_26F0C145 X-CRM114-Status: GOOD ( 20.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When VCMDQs are assigned to a VINTF owned by a guest (HYP_OWN bit unset), only TLB and ATC invalidation commands are supported by the VCMDQ HW. So, add a new helper to scan the input cmds to make sure every single command is supported when selecting a queue. Note that the guest VM shouldn't have HYP_OWN bit being set regardless of guest kernel driver writing it or not, i.e. the hypervisor running in the host OS should wire this bit to zero when trapping a write access to this VINTF_CONFIG register from a guest kernel. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 5 ++- .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 44 ++++++++++++++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index d12e048ddd93..5cc31cdf1ab7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -352,10 +352,11 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) return 0; } -static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu) +static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu, + u64 *cmds, int n) { if (smmu->tegra241_cmdqv) - return tegra241_cmdqv_get_cmdq(smmu); + return tegra241_cmdqv_get_cmdq(smmu, cmds, n); return &smmu->cmdq; } @@ -765,7 +766,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, u32 prod; unsigned long flags; bool owner; - struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu); + struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu, cmds, n); struct arm_smmu_ll_queue llq, head; int ret = 0; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 22270de3aed7..495c80579c8e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -834,7 +834,8 @@ static inline void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct tegra241_cmdqv * tegra241_cmdqv_acpi_probe(struct arm_smmu_device *smmu, int id); int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu); -struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu); +struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu, + u64 *cmds, int n); #else /* CONFIG_TEGRA241_CMDQV */ static inline struct tegra241_cmdqv * tegra241_cmdqv_acpi_probe(struct arm_smmu_device *smmu, int id) @@ -848,7 +849,7 @@ static inline int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu) } static inline struct arm_smmu_cmdq * -tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu, u64 *cmds, int n) { return NULL; } diff --git a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c index 4bfddeb658e2..7816ec8e6075 100644 --- a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c +++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c @@ -213,6 +213,7 @@ struct tegra241_vintf { u16 idx; bool enabled; + bool hyp_own; atomic_t error; struct tegra241_cmdqv *cmdqv; @@ -330,7 +331,33 @@ static int tegra241_cmdqv_init_one_vcmdq(struct tegra241_vcmdq *vcmdq) return arm_smmu_cmdq_init(cmdqv->smmu, cmdq); } -struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +static bool tegra241_vintf_support_cmds(struct tegra241_vintf *vintf, + u64 *cmds, int n) +{ + int i; + + /* VINTF owned by hypervisor can execute any command */ + if (vintf->hyp_own) + return true; + + /* Guest-owned VINTF must Check against the list of supported CMDs */ + for (i = 0; i < n; i++) { + switch (FIELD_GET(CMDQ_0_OP, cmds[i * CMDQ_ENT_DWORDS])) { + case CMDQ_OP_TLBI_NH_ASID: + case CMDQ_OP_TLBI_NH_VA: + case CMDQ_OP_ATC_INV: + continue; + default: + return false; + } + } + + return true; +} + +struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu, + u64 *cmds, int n) + { struct tegra241_cmdqv *cmdqv = smmu->tegra241_cmdqv; struct tegra241_vintf *vintf = cmdqv->vintf[0]; @@ -344,6 +371,10 @@ struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) if (atomic_read(&vintf->error)) return &smmu->cmdq; + /* Unsupported CMDs go for smmu->cmdq pathway */ + if (!tegra241_vintf_support_cmds(vintf, cmds, n)) + return &smmu->cmdq; + /* * Select a vcmdq to use. Here we use a temporal solution to * balance out traffic on cmdq issuing: each cmdq has its own @@ -405,12 +436,23 @@ int tegra241_cmdqv_device_reset(struct arm_smmu_device *smmu) atomic_set(&vintf->error, 0); vintf->base = cmdqv->base + TEGRA241_VINTF(0); + /* + * Note that HYP_OWN bit is wired to zero when running in guest kernel + * regardless of enabling it here, as !HYP_OWN cmdqs have a restricted + * set of supported commands, by following the HW design. + */ regval = FIELD_PREP(VINTF_HYP_OWN, 1); vintf_writel(regval, CONFIG); regval |= FIELD_PREP(VINTF_EN, 1); vintf_writel(regval, CONFIG); + /* + * As being mentioned above, HYP_OWN bit is wired to zero for a guest + * kernel, so read it back from HW to ensure that reflects in hyp_own + */ + vintf->hyp_own = !!FIELD_GET(VINTF_HYP_OWN, vintf_readl(CONFIG)); + ret = readl_relaxed_poll_timeout(vintf->base + TEGRA241_VINTF_STATUS, regval, regval & VINTF_ENABLED, 1, ARM_SMMU_POLL_TIMEOUT_US);