From patchwork Fri Nov 19 07:19:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12693106 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C1F2C433F5 for ; Fri, 19 Nov 2021 07:29:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1C7C460F4F for ; Fri, 19 Nov 2021 07:29:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C7C460F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CWBHB9XTCfzd9PPchqW+lex0mzjUwpwCpBDFpdtqjD4=; b=Zvk+2nTUeZxsDU R7dI8K9d68MXZVurSHKC7k+oA+iFzkwd0wktOr7sgK36u0c1eQzi1XMZezX6vG5/SkiygfkJgHKNg 8sqwe8vfwgi/KAwu+dUrGWFotrJjtVCkLaoILAkgIkJul2U/M7HCAGjKJufjC/ih6+mAn+MHUcK87 QKRLGyR0tf3dP1hFoMjHQGntaiPSC8jZ54S2/mOCW5WI49JcH0tXNYOz7hJwn4YIg6uvQSpGJYE6x dBy7lKNwz+K8XKHd7Fy2LzP/RPwWp3hxoL3d8F9lgFhmNiX+6hL0wyLrcqNEhanzxjiAgzj1NGCQi 5V0jdwTl895dQ7eQeMoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJR-009aeH-TX; Fri, 19 Nov 2021 07:27:58 +0000 Received: from mail-dm6nam11on2067.outbound.protection.outlook.com ([40.107.223.67] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJB-009aWc-D8 for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 07:27:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K1Drrr/r9QwuLizYUsAa7BgOQygkJcvjHDo2Dy5uzOu9HTs8lKe1fedVNFlJRaH/6hsfypipVD2Qfzjh3KJqBv+C30yiDh+44wKQqiQX94JVva7ObScpM/lEqIHGJtcyfyAxBGE5qeVzLZH0K3Uqh8Su0GHQoBwMdnp8E+M5cpOpvO+DE8XmziRi6v7WEk+lD4bZmHpqglg+NcioJuNr6tkli9JFeOh4+EJ54X9lCD7jq+PM5ZqLlEvWxtYJEebyfzK3mbNw1XohPSXUafUveXZljFRzrU6/Z3VBwhf9uArf/hIvLb8OeEIxV9EwQm6kdHvV2lb84nzXGTUjPut4Zw== 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=GkagOCbFUsmRyTNFeaYX6wFbNPq2tFycC7QRLHnpPfU=; b=l2Kv/D0GGzLDIt/Q6PDds4m4laCo8kjiOqTAEaqBMw5wK3JVXqb31EKY+JOC1GYv2ULoPSnkzJBVUxOgjJ32PlYXTcgaO+fmr/MKdeH5AO5zsNsxnpJLqFI143MuMFaY3LTeQbrlSflt0Iu8D3Wo7nmolCZEnVSt3dgm+YdsVmSw/ixgDcf9/f5LxFZ9mcpsPEiXXPg28QCyxgEPaB+HAxIX8x2qqKyyex7njEtKSiR6WwuN3txGrLrw1kro1Esa7Phhza5NySL6sSf+yAigM6NBH0wZ3RHcZUTx1XPfhr57lg/Sjny7J+qSruPEI7pQ/DcM/N7qkfXmjPgNjJguzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=GkagOCbFUsmRyTNFeaYX6wFbNPq2tFycC7QRLHnpPfU=; b=VwCqdfP4iHx7z4NgOuYe+ZxWBhoM00LKaPXYgc1SgYWClW+smzq0oG9NT2yqOi6eT4YIMkecoQkud6aonqUz0FLusF0gWtAtEC+HVFyaLgTVfrohW+i7V4Q4Df/R7lS+jAEogb8PFEtYH36paOtYG3nD1KOLgy2VG7EOWwWLSQF4K9OMI0RdgX0hJS82nBYxhrbHOeKNnwOU683P7oiBjfacwjq6JMEMy2kdJQ9DJwv+DrbBbwviPpTt/WW6+RyrKU43KGUlNpGqJpN5tsFKL4PTIe2IuuqAiD7qmgZaE7RBEMKiMAOmGWBqGz+RYhVNpP2iP//LK5nGIQWopXY0jA== Received: from DM6PR08CA0051.namprd08.prod.outlook.com (2603:10b6:5:1e0::25) by BL0PR12MB2450.namprd12.prod.outlook.com (2603:10b6:207:4d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 07:27:37 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::5d) by DM6PR08CA0051.outlook.office365.com (2603:10b6:5:1e0::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 07:27:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 19 Nov 2021 07:27:36 +0000 Received: from Asurada-Nvidia.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 From: Nicolin Chen To: , , Subject: [PATCH v3 1/5] iommu/arm-smmu-v3: Add CS_NONE quirk Date: Thu, 18 Nov 2021 23:19:55 -0800 Message-ID: <20211119071959.16706-2-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119071959.16706-1-nicolinc@nvidia.com> References: <20211119071959.16706-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc09f842-8823-4e78-ac62-08d9ab2e0fb4 X-MS-TrafficTypeDiagnostic: BL0PR12MB2450: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MaY2CJG+mef8qOHNSig8NQs+ssfbhTdlbyeCrYFAp/b1U91T4PssDRtvbT+9AzZaaXnjwWoG8R6ci9JlNqQ1kdJ8t0yNS5rLskAyf+FOcm6AvmgSxJpVelH7/3JwfUScXNx0Sh1LLDSQRbHFU0KajCX0I2mm5CLGRlKdiFrm1va/51qLU/6SSTkHwvEcwfheyuXfO1NcDUbp8OlUzAt+gFE1Cr/7UpM6okZvJHMKJe9idsf+aJiHlazbokeJeZQSnWMBwp5y/5WQ1ieMKJnbLFSOn3xCZy0l/MJBsyKWIyNaGp4yX4KnC1J6Ib/Tf0CJxeemxfSTC0D1WISapjoOuYRc+dAW8iyIbz6nJEtPmekWWeZG11glnnrW60uu0CMvuCFGH4jjsk2/JoRWZt707dIuBCoCd+JlFwkOO7TG1GgIpy7y1KdmShx/kgfWzJ4O5Fk3osx1P9S3vMUAD2Vp3Zt/xUBaBi23+sT46oYkiDbGjkKrkJUXeeaXAp0IMchlOhBx9zEEipv8PfhyvGISJbGZLqR70r3hxIz1/HD42kW60GpNTWn1cEofxoc+G21naUg7TA+kPwXseGsWMfS8/iBilj4QGrnE7J8w4C43Vns5gp23FscUICO6LYqGxiyoUni7YpuuZDrBQnEc29avsGVvrsLAN+VWk0x++M1LeKUJQMMCSS2AM5xF0xEhb8NNrnqQlIFczc1cWac+r1m3pA== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(36860700001)(26005)(47076005)(4326008)(508600001)(6666004)(356005)(5660300002)(7636003)(82310400003)(426003)(7416002)(70206006)(1076003)(70586007)(8936002)(2906002)(2616005)(336012)(186003)(110136005)(54906003)(36756003)(36906005)(8676002)(7696005)(107886003)(83380400001)(86362001)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 07:27:36.8400 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc09f842-8823-4e78-ac62-08d9ab2e0fb4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2450 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_232741_578014_77AB26D0 X-CRM114-Status: GOOD ( 13.74 ) 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: , Cc: jean-philippe@linaro.org, nwatterson@nvidia.com, chenxiang66@hisilicon.com, Jonathan.Cameron@huawei.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, nicoleotsuka@gmail.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jgg@nvidia.com, thunder.leizhen@huawei.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The CMDQV extension in NVIDIA Grace SoC only supports CS_NONE in the CS field of CMD_SYNC. So this patch adds a quirk flag to accommodate that. 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 | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 f5848b351b19..e6fee69dd79c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -319,7 +319,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 { @@ -356,6 +358,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); } 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 4cb136f07914..7a6a6045700d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -499,6 +499,7 @@ struct arm_smmu_cmdq_ent { #define CMDQ_OP_CMD_SYNC 0x46 struct { u64 msiaddr; + bool cs_none; } sync; }; }; @@ -531,6 +532,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 Nov 19 07:19:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12693105 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2688EC433EF for ; Fri, 19 Nov 2021 07:29:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E1B0661AFB for ; Fri, 19 Nov 2021 07:29:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E1B0661AFB Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a428jZEuIgkM+CzSy+3MnODH7cvVVRPb4djZEcIOmAM=; b=LC7CszKb+zBXzJ A+vawXN7X/JZE2n3zVtQ4fPoFCOKvJ/4H+IwOgdDcbgbqZTcy5WZ+W99UvOpJiY8hooGXGuuMZkGv /f55cTzdJcn6I2itb1y3qWNPU31LJ/Bfrp4POmck74PJHbkAJxlS4EXn8Xs5UzTRk+672UlWzR+4l SMfJW33UKFKKNsu2rsPNwKfYtPkC91MezfesY+7+u1BZQ3b81BXHbwoF6mTJgeInvFKflKRi531Le vr1qpnoFO2Dmh7o6JJmbbn1NnZkZxCSLh+MWjkuNRenuLKXdm+w9lN0E227vE8pJ5LEgAzeg8+jd7 82djFnCrDJW3u2/8AZ2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJF-009aY9-79; Fri, 19 Nov 2021 07:27:45 +0000 Received: from mail-mw2nam10on2049.outbound.protection.outlook.com ([40.107.94.49] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJB-009aWd-Di for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 07:27:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yb7arpSxG08qvRlL6yZIkk587yu1ixW5qbeAwpPZG1hVnkqYQsdKWj6YbL6wd8dJqB4o2zz7rpULqfFVTW0g/HX4HQM7UxR8R2tmimjgs0BpNmwpdQESFYXtVnQKSNakSEcrcSpTuIbh5hDMi8LqbW4AjmX0yfeE4QRV4V5TU7DLZOF9ud9H/vc20fpwxQKORV9ZWENilpwLHlH//W1ouhruP/iTgZNDigN8f/BKlM7JB2L8IFFwoh4bH4YcDklNcbN27ESaSPt8xu+WQkNl0Xy4srbtigILiYX49Kceixcfrr6H7rueLORmcS4CNPf7DI8NoXWxDB10ygkseFsoNg== 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=FCQuTRlxOn6XcYrGbcqc9ZJWKlLkdN4TwjtWXL80snE=; b=deon+cU0RUMd/5/1Dg7iK8lA+4aNu66GlszY2t2vqCPkl9A2FoLOqDboqsIsA6+8ybtu3mFW/kaOcpkBRPn0aLeXxjA8t4pcvkYY/n5kqh6CNulDw+KO7tCtBVGoZgChAb79N3HfNfiksFgIJQFPcO2u3k1Hkz0A38FabQ6RlJFIlfnI/5USDPHFYtzCVClgwwIU7+/8VABaZP6o+uLppFYC2FqBxFWUPgkUvPHwmemaQZGjtAgMs5yT3gZOtO4Sd1kFJwDEltKlovHPXNtZLIYZkyEUR+1dHmF44b61QZ+B/QlEZIGf1LgHp26MXrVXK8/QHxtOcZ1dwTo/yQoH+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=FCQuTRlxOn6XcYrGbcqc9ZJWKlLkdN4TwjtWXL80snE=; b=UV6QM/EieYZUDr4eCmtg4YyVOuB/uRbtxc5h1D3eQXzyRinkRxN+qyPawejT/oZwN1L4xo+G4uJd252ijUBS/QZ4j3kMiVScXOSdvFuwrh41C1UEgDicrxoNM2YYVAJ5KeR47AVjvx4YPxo4B6VdN6Tk87hqVBCek/NfuqEhyx4SQLUotbzsIYEdsrFUTDEdD4+BBMoAN7nY1L/e+ClseCMbpAarrVCik0HPVAgb1OSqvNrgdy9qedD8afYUOWqpZIo3I4kWdOh7ZDMycom9dZ7NcFfvnGJv2k77WFxIXzpREpBHv1BwmclmdR9w8Cp1oukMaxF6gOdXnDkdj3xeVg== Received: from DM6PR08CA0044.namprd08.prod.outlook.com (2603:10b6:5:1e0::18) by MN2PR12MB4223.namprd12.prod.outlook.com (2603:10b6:208:1d3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 07:27:37 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::4) by DM6PR08CA0044.outlook.office365.com (2603:10b6:5:1e0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Fri, 19 Nov 2021 07:27:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Fri, 19 Nov 2021 07:27:37 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 19 Nov 2021 07:27:36 +0000 Received: from Asurada-Nvidia.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 From: Nicolin Chen To: , , Subject: [PATCH v3 2/5] iommu/arm-smmu-v3: Make arm_smmu_cmdq_init reusable Date: Thu, 18 Nov 2021 23:19:56 -0800 Message-ID: <20211119071959.16706-3-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119071959.16706-1-nicolinc@nvidia.com> References: <20211119071959.16706-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6bc2af9-d686-4246-4e11-08d9ab2e101b X-MS-TrafficTypeDiagnostic: MN2PR12MB4223: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PiepUiWlsgJFSHSgoVIzblT859f33ot+emXh/ax4Izxh14p/7gyPNI5H8XKUdql5Pi0BoYMrwgj0FZ3eumKDoY+0c72USfo/FDUoG21GO8qA2U25jFDxoTnqmEsQ/gFJ6FlXo7I5YWkhzX9a3p9uBenODlOZTEnZpS2ZCIDuO64l0nSfMLmyJemi2FamiflcBeEPRNjJzwBd8tpkEcM6N8QQ9UH9nMebTgd+FbfJwJmkAm+wul0A/6MS3+pdMzVmHaHEhfiFchCEPJPA+e2QXCOxmKdBxmTnZYCiPz4ngAOJ6O7cH0lY/o6uHofRjCTSlXPDX0bdNSjRJaLKWOiAWduT/l/wLDyXWtu/Hj/lux1o/gyCbSfpfn2ZO8RI9EIaN7BrQOVkaf/oeGija3drq5h5qzJZEM3SvKSoILNDeKtf62MJJ+Rxbl9+cBLeoSCvagLD2NbNnlwFj18/QxqaazUcQaPrpVddDH1UQEg7PvS4iMan9KV5v/LBJrnGrFd4qw3EtaDprVl5twd3IvsjymFInm/a6ECQeJi30diRpujhYtEAhZrKL7aEkdFEBWFX4wgIEnwLAX0f44T4dG+sjknRX3Z4nAWdsudfC2CYx5TiORZHG2VxMNjlv+I//lmQixFx836HWTtNXBMLGFtjLaavi3kB44CHr26d1hpRutqfT3Re/yG16rYC5ZMD1xk8KaDiurMN/uv8D7QzlISCaQ== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(26005)(86362001)(508600001)(107886003)(83380400001)(7416002)(36906005)(5660300002)(47076005)(336012)(6666004)(7696005)(2906002)(1076003)(4326008)(70586007)(110136005)(7636003)(36756003)(426003)(356005)(8676002)(82310400003)(2616005)(186003)(54906003)(8936002)(70206006)(36860700001)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 07:27:37.5146 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e6bc2af9-d686-4246-4e11-08d9ab2e101b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4223 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_232741_580059_7B67F2BC X-CRM114-Status: GOOD ( 12.94 ) 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: , Cc: jean-philippe@linaro.org, nwatterson@nvidia.com, chenxiang66@hisilicon.com, Jonathan.Cameron@huawei.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, nicoleotsuka@gmail.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jgg@nvidia.com, thunder.leizhen@huawei.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The CMDQV extension in NVIDIA Grace SoC resues the arm_smmu_cmdq structure while the queue location isn't same as smmu->cmdq. So, this patch adds 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 | 2 ++ 2 files changed, 5 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 e6fee69dd79c..6be20e926f63 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2922,10 +2922,10 @@ static void arm_smmu_cmdq_free_bitmap(void *data) bitmap_free(bitmap); } -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) { int ret = 0; - struct arm_smmu_cmdq *cmdq = &smmu->cmdq; unsigned int nents = 1 << cmdq->q.llq.max_n_shift; atomic_long_t *bitmap; @@ -2955,7 +2955,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 7a6a6045700d..475f004ccbe4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -751,6 +751,8 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, 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); From patchwork Fri Nov 19 07:19:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12693107 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C887C433F5 for ; Fri, 19 Nov 2021 07:29:56 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 64501610A0 for ; Fri, 19 Nov 2021 07:29:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 64501610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AdQuLhmz6X00hzeSXz4JQgEffOz73598jzM/0mbvuaM=; b=FchI3ahabNfaY/ pqiCLBbQop0rTgUVOqcEH0/Y+Qco5V6nXqtatfHKoUgPt+lg0I+e/aV7/JhaIB5KXs8nachYlYy0U TUUDgVfoS++I1OmbmkLA/hJtf54RTLOmKKETIBIKicAbZT+3xl0BLdQfCIzcLgQYgIOBC8P2KIxC/ bs1iaK5+DXJOxKOFKMNhp2O/QMBp00ifEtZrRNnUfnucsp/mGCacl4pstqymB3EkMGpmv7q1zojiD aIm+gXMNtD5ZC6Wmof/GUfghz+90ZxLm3KcUaj+f09wrCrOdmOc9NZVaSiJ/ck01FXPKNvLaRTK1g M+XRV/HT4rzdzYTQkz1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJe-009afT-MW; Fri, 19 Nov 2021 07:28:10 +0000 Received: from mail-bn8nam11on2045.outbound.protection.outlook.com ([40.107.236.45] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJB-009aWe-G3 for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 07:27:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hq3oUPvisnNfl7MRWzOHG7ym314y/z3HHvL/988Q9G//5rnyEBcfAXdr4CnkKVGKdbr10QyykbQu4LhU53s5772EA8NKJUlhYDpz5mDHKdZtLHwsECFJhKX2oUn9LvhWyWfHo/sab3RDXBoRkSICJamFTDNooiMz0x5DPDw4HzLf072f001mrzONb1urgohrEy7TWkhSkJvX5i0w72e5rNdDTlT+pBPeeWzuTCkcO4DzFUcpr0aktpFjk/0d0BPT4fMgnXe9B0nOI4QfiFPNJcJ9tm+G/SIjtx5PdBkdJJCcUokG1v43CnAyOFMlx5qrCO2xmG4cppSbZ2Kn3z77Rg== 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=zsRK1Q74hiK7MaCRZch1f4+qyyM7SfVCtHJX4+aYgS8=; b=D/8MkN0Z0ByM2dy3roEaMRXQKecNuPE5wu8W/Fi9FDXX/nDvSKa0rg6OFtr2T1pTIckbWzGxuR1YZN3QVXK29/v2RoiAdz98QcFG5qmuyA0At1ubOJ5nPvAZtpQN78FGZPP9SzQJ83rOgQzPFlNIdXNbMl2iepmLjG5Of674SJ14N2tJ66cZaZpmnpKUwPyQqCSN7plvQwwZ1rbjpltIFx+bzOtOCnDLNeKVjvCAA8ZGMYRGX03u7K8A8jFB+29bbOlacZpCdFdtznLQfu7f5cLQ0xDb5iF1IL1AlnAXM8bhslyjwZsyePdc2p6kEolwV77DxrtAz8omvFcQFmwerA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=zsRK1Q74hiK7MaCRZch1f4+qyyM7SfVCtHJX4+aYgS8=; b=oYeqCkCAoozFh+CjaEjq01hmLHQ8t6pH5GrdUpyMg9PWwGA/FVTP66RGCvoiPnwNhgR9CWRgY9RndBZopbGWO2wx53t6kBDaWsR+gm6i9uO3X7xmzx+rVSbr0+25/ScAvs4k3+9UCeNAAtqQRu+UCgRG02HKAT7ys8KduQ7+pEoLZkIdivxa/ncwmNtptagIFvsLQiV122iHB3i0iXH7RYnt/ZFLLfzpQAMUrOPkS8+F7m/vm9xYkGbzBB+0fQEs7YFM4TwgVP8HiV8xZ3oJ/+4CHiihhtbQ8f17jUZwPh64RScTSTcJNgON90SYZeLYBsdMAUHG88fF1u5IZ9Lg3g== Received: from MW4PR03CA0212.namprd03.prod.outlook.com (2603:10b6:303:b9::7) by BL0PR12MB4675.namprd12.prod.outlook.com (2603:10b6:207:35::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 07:27:38 +0000 Received: from CO1NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::b6) by MW4PR03CA0212.outlook.office365.com (2603:10b6:303:b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 07:27:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT045.mail.protection.outlook.com (10.13.175.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Fri, 19 Nov 2021 07:27:37 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 19 Nov 2021 07:27:36 +0000 Received: from Asurada-Nvidia.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 From: Nicolin Chen To: , , Subject: [PATCH v3 3/5] iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist() Date: Thu, 18 Nov 2021 23:19:57 -0800 Message-ID: <20211119071959.16706-4-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119071959.16706-1-nicolinc@nvidia.com> References: <20211119071959.16706-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5de930be-b995-436c-5edc-08d9ab2e0fcc X-MS-TrafficTypeDiagnostic: BL0PR12MB4675: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QfP51KMxUm23Yz7qg4t8XDnDaWkwTSFm1vY7JQu3Nq4IcB7P3+mLuCGvM4/q+zNm5Ess3sWes+aPw2ctv5QoK1ProX6PZAa4N4LkrifgWYq3oj/xhUlHmuwHqrAeOrrAYhZ5md5X1IHOTX6CIFD4nynYtu338Lcj+mEwPZOKO44XbysLk/+ZUGfpnme1AtPP6ShcYU0O2EeIpoKBmUe14+8rXjRix/GRG4WDIxSRv+8A0/HYfiX6AWE/gW084Wt7jXhwkOmVP+UPmoUUC6XBAfi5v+wjthZDJs9GUqVwFCkJrgMWbZZqi7zbSobf3+ZPlbk7iotjicElkwrOoL83OFU6cXVMV7v/HScTb/o9e/pJULEL351sO3WBCJwKsPER2r7pPHgA1Yd1L8dqdbe0BhZPmzlqH6NQ75X4XmOwBS+6BY7jMeN61MhN6butpjIqyCIAcJ++coAPQApbnc4IbGKDZ/c3demZGIltLHrNvYpRMRiwmUGAM+dDACoIR+PmtGENp6oj4zon5A3derjiDsFZOmgmmEi44fS1qIyp2k9UM3uUlV/1SToF7oU83tKF+epb8EvaAkiFT/Nwekw5jUUb6sZE/cJrz18k6HSCX8ukIWuKyjYiAsdkoLZZtjif033CvEazF9hWdEoLntON3yzyc9rSjUwoikp0/oFI4gvpLJz4393ScdRO9P+HJmuJB7pNs1sC8e3MRolqrVPpuw== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(6666004)(54906003)(7636003)(7416002)(4326008)(8936002)(36906005)(70586007)(26005)(5660300002)(508600001)(316002)(356005)(82310400003)(8676002)(110136005)(70206006)(7696005)(426003)(2906002)(83380400001)(107886003)(36860700001)(1076003)(336012)(47076005)(86362001)(36756003)(2616005)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 07:27:37.0503 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5de930be-b995-436c-5edc-08d9ab2e0fcc X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4675 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_232741_586195_0B33E359 X-CRM114-Status: GOOD ( 13.42 ) 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: , Cc: jean-philippe@linaro.org, nwatterson@nvidia.com, chenxiang66@hisilicon.com, Jonathan.Cameron@huawei.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, nicoleotsuka@gmail.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jgg@nvidia.com, thunder.leizhen@huawei.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org 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 internally in different places, though they are all actually called from the same source -- arm_smmu_cmdq_issue_cmdlist() function. This patch changes this to pass the cmdq pointer to these functions instead of calling arm_smmu_get_cmdq() every time. This also helps CMDQV extension in NVIDIA Grace SoC, whose driver'd maintain its own cmdq pointers and needs to redirect arm_smmu->cmdq to that upon seeing a supported command by checking its opcode. 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 6be20e926f63..188865ec9a33 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -586,11 +586,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; /* @@ -621,11 +621,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); @@ -645,10 +645,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; @@ -695,12 +695,13 @@ 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) - 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, @@ -757,7 +758,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); } @@ -833,7 +834,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 Nov 19 07:19:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12693108 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DFE0C433EF for ; Fri, 19 Nov 2021 07:30:15 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AEB23610A0 for ; Fri, 19 Nov 2021 07:30:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AEB23610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4XmrbPHWycR6oC2lRBjRAzxt3J2TbDzVpiPGy2oxTg0=; b=tlz1kEwtn9gvPr /S6atDvv4zqhvOa6RyPZwGpsZ+vXLxAkXUIGnNx5KqGWAVPQN93QeGDETV7LCukZD4QUDnGz182Ag T875YNbukctFC5Fhdmx8jOOwxIyX3qgjYGk0pR+6L7pfQ4MCVSGWf+TrANaqj0zAH0qcX9pgmCBcN YAlNlFABT32RX1bIAyfWLyp0U18jHjjjZSnbej1OOjQP9bRri93OcWw0GDG5Q0D24boHMNn9R0Sb/ LeZsmdI9SWFdeF5v83Z5XDoT5o4idsYO7Asj2DLsTDU5/dapuoVJJCPRE/k6/3UzDoKY6CBWNJRcn lmBodm0Bd25OjqqSenHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJq-009ahl-60; Fri, 19 Nov 2021 07:28:22 +0000 Received: from mail-mw2nam12on2062.outbound.protection.outlook.com ([40.107.244.62] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJB-009aWh-Sq for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 07:27:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bmUhppMY/Vre4LWbhXft0ZHYT+Hp9F9sx4XuSf/Lyjk1aO+/AAQM4l7AFA16ZeoP6s6OKo2B8XvlgO7x5LcBY4QxR42KOD1b7D9OcZTFq9XybnIeZVyGcJapAS1d6P4uZl5VgMFZn2USBd4m4MqoprEO4j/9ubvf4EVRJ6/6fswLyVI4vlCtMIwFiSxmVFHrEnkDIYS2ERC+jcOXSNg1mLKj4GJfYVCW0SBuOFZfMzu/egVttPqI34mwr6zn36o2hpD4RQGTH0gVRdzQl6aBAaNA7r2jta7QiowPMYfOlOtPcwWsT92JHoAKmHOLkz+7i6Hi/3vh6s8KpDanAVKtWA== 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=iWxjoXw0evaRr6lqTRZyGZVAYAp4Wey+Heeu1jQzDA0=; b=WF5rRul8ztR/j05fabAy3gFtbEb2566bBNpsRCTEFTKkdsfVqfhnjL+52btQ5zfMksKT2PEVTlPMhuJnk5YU+2sw1TrmnH4yhEJzjVGnREptj94rpFAf0dVtia51qOYn4FWDBzWlNsw2Z/JwPFwHH1Vvc2W9qiapkyiHFi8ai2WKeKSTG8SwBNA0bclqAS+r9tTxMJn7aWcdlahIZPaCYTBkqtBe7TPssP41AjAGCDrdEsph7nxRILC7OPJlCQlMfo2SaEGre8hqzEkPNUppbEBfBdk3wnCxaOQxeryRtwPTaF5+oWEasV4v1jIUKM3OnqjiZysq+4YPoL9b5E45Fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=iWxjoXw0evaRr6lqTRZyGZVAYAp4Wey+Heeu1jQzDA0=; b=me3bC2FbhJoqJBRhI8rFI11k4z+ZILPg0OwkaFGNswemGykQFyhSlS9CE3mAPRcGCi5869259CwcLb3BoI/+UMIsIwfIa+V6PitbFBdTZdad9RD/Wtb7zaNtzQBNBr8995Ac33xRcG4MBuh1i3BRcRzrWxfwy5IYiTlCTEqqCutJPOhp9O+DtCXFnHf4X/XA/NAfIJMRVbloweVzz8O5S9BOvlq7Azjakgt3BzXPmAf0bOZB8HioP5IzHjTLNgEYqnTrE/O0sHaK9F9zspbY3ivfQbXcmMPSU9ZtIsXv2TbfbtvDLdLN8zH+k53crCagkcPEY6uBgVoXbFS0pjpkFQ== Received: from DM6PR08CA0062.namprd08.prod.outlook.com (2603:10b6:5:1e0::36) by DM6PR12MB4879.namprd12.prod.outlook.com (2603:10b6:5:1b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 07:27:38 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::26) by DM6PR08CA0062.outlook.office365.com (2603:10b6:5:1e0::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 07:27:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Fri, 19 Nov 2021 07:27:38 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 19 Nov 2021 07:27:36 +0000 Received: from Asurada-Nvidia.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 From: Nicolin Chen To: , , Subject: [PATCH v3 4/5] iommu/arm-smmu-v3: Add host support for NVIDIA Grace CMDQ-V Date: Thu, 18 Nov 2021 23:19:58 -0800 Message-ID: <20211119071959.16706-5-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119071959.16706-1-nicolinc@nvidia.com> References: <20211119071959.16706-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 185b7249-ccc7-4f90-481f-08d9ab2e106c X-MS-TrafficTypeDiagnostic: DM6PR12MB4879: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hCm+fgFtu38T3JZWNRf+u/F0iuc3wgSLnDfKbd0f7QHqR9iTpKGkkQLrzymNr94zF+gpjiOnEPL5NOVEXibQDxrAR1etqihaOumMr5flu7ZS4JDy4yIHogOYTjA1N6DJAc/xg/iZqR6HhhkiOxTxjJVDPx/cGQ6AehzsV+8couYwrgHdUCDfPqWtCGMfNYUVAS0dAJsBTcr92FOquBphiM99STvnzGJF4nXOcrqnWByaUChMQGEIHgBg3R6Kgmz7sVDKYgbBPbFx8YZ4C2NNnftOnVzwMse5Dk4jHhFNsGYyfHF20sGx+AOr9koix6RE9pWzl71NMuVgO5cfJD1r36gZr0PcsJoxBr5o+FYOpeQyr4yQec5gWqC/GCxt0E17+nfx7wjF1ykoK3J78RL7vpog3gKN04M2OfPBzPG75hdUO54Y5W9i8izQ+NdVD/NUUjPOfSvMoiUaLZmqWY66y1Ivv6j+2sLtNj+YjNODoKJVegfk3o2f2hlrLTxZ8Z/JbylKGUquo5wSsg1gFCjhVScQyJI+cJWXAJG/s9ugVRSXCVpjO6FYtbqa0cHCwALRZS+WRGvWnqVutZrz2F1h4lAOa64C08LFXV2AFBqtDjNGwfyr6vdDleOaiW0fjQ+fU9tdlE+dzG25klXqnI6kTcQJfCtofO/IIW1KQW6nOsX/Rv6k0xxMptTamPdS1RlIVnij34byIp7NfHj9U/F6ew== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(110136005)(2906002)(82310400003)(86362001)(7696005)(356005)(54906003)(107886003)(6666004)(83380400001)(4326008)(26005)(316002)(30864003)(7416002)(186003)(70586007)(336012)(70206006)(36906005)(426003)(2616005)(7636003)(5660300002)(508600001)(36756003)(8676002)(47076005)(1076003)(36860700001)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 07:27:38.0443 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 185b7249-ccc7-4f90-481f-08d9ab2e106c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4879 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_232742_017417_4905CBEE X-CRM114-Status: GOOD ( 27.74 ) 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: , Cc: jean-philippe@linaro.org, nwatterson@nvidia.com, chenxiang66@hisilicon.com, Jonathan.Cameron@huawei.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, nicoleotsuka@gmail.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jgg@nvidia.com, thunder.leizhen@huawei.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nate Watterson NVIDIA's Grace Soc has a CMDQ-Virtualization (CMDQV) hardware, which extends the standard ARM SMMU v3 IP to support multiple VCMDQs with virtualization capabilities. In-kernel of host OS, they're used to reduce contention on a single queue. In terms of command queue, they are very like the standard CMDQ/ECMDQs, but only support CS_NONE in the CS field of CMD_SYNC command. This patch adds a new nvidia-grace-cmdqv file and inserts its structure pointer into the existing arm_smmu_device, and then adds related function calls in the arm-smmu-v3 driver. In the CMDQV driver itself, this patch only adds minimal part for host kernel support. Upon probe(), VINTF0 is reserved for in-kernel use. And some of the VCMDQs are assigned to VINTF0. Then the driver will select one of VCMDQs in the VINTF0 based on the CPU currently executing, to issue commands. Note that for the current plan the CMDQV driver only supports ACPI configuration. Signed-off-by: Nate Watterson Signed-off-by: Nicolin Chen --- Changelog: v2->v3: * Replaced impl design with simpler "nvidia_grace_cmdqv" pointer * Aligned all the namings to "nvidia_grace_cmdqv" or "cmdqv" * Changed VINTF_ENABLED check in get_cmdq() to VINTF_STATUS * Dropped overrides at smmu->features and smmu->options * Inlined hw_probe() to acpi_probe() for simplification * Added a new CMDQV CONFIG depending on CONFIG_ACPI * Removed additional platform_device involvement * Switched krealloc to kzalloc for cmdqv Pointer * Moved devm_request_irq() out of device_reset() * Dropped IRQF_SHARED flag at devm_request_irq() * Reused acpi_iort_node pointer from SMMU driver * Reused existing smmu functions to init vcmdqs * Changed writel_relaxed to writel to be safe * Removed pointless comments and prints * Updated Copyright lines MAINTAINERS | 1 + drivers/iommu/Kconfig | 12 + drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 21 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 41 ++ .../arm/arm-smmu-v3/nvidia-grace-cmdqv.c | 418 ++++++++++++++++++ 6 files changed, 488 insertions(+), 6 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c diff --git a/MAINTAINERS b/MAINTAINERS index f32c7d733255..0314ee1edf62 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18726,6 +18726,7 @@ M: Thierry Reding R: Krishna Reddy L: linux-tegra@vger.kernel.org S: Supported +F: drivers/iommu/arm/arm-smmu-v3/nvidia-grace-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 3eb68fa1b8cc..290af9c7b2a5 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -388,6 +388,18 @@ config ARM_SMMU_V3_SVA Say Y here if your system supports SVA extensions such as PCIe PASID and PRI. +config NVIDIA_GRACE_CMDQV + bool "NVIDIA Grace CMDQ-V extension support for ARM SMMUv3" + depends on ARM_SMMU_V3 + depends on ACPI + help + Support for NVIDIA Grace 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 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..a083019de68a 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_NVIDIA_GRACE_CMDQV) += nvidia-grace-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 188865ec9a33..b1182dd825fd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -339,6 +339,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->nvidia_grace_cmdqv) + return nvidia_grace_cmdqv_get_cmdq(smmu); + return &smmu->cmdq; } @@ -2874,12 +2877,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; @@ -3438,6 +3439,12 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) return ret; } + if (smmu->nvidia_grace_cmdqv) { + ret = nvidia_grace_cmdqv_device_reset(smmu); + if (ret) + return ret; + } + return 0; } @@ -3686,6 +3693,8 @@ 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->nvidia_grace_cmdqv = nvidia_grace_cmdqv_acpi_probe(smmu, node); + 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 475f004ccbe4..24f93444aeeb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -619,6 +619,8 @@ struct arm_smmu_strtab_cfg { u32 strtab_base_cfg; }; +struct nvidia_grace_cmdqv; + /* An SMMUv3 instance */ struct arm_smmu_device { struct device *dev; @@ -679,6 +681,12 @@ struct arm_smmu_device { struct rb_root streams; struct mutex streams_mutex; + + /* + * Pointer to NVIDIA Grace CMDQ-Virtualization Extension support, + * similar to v3.3 ECMDQ except with virtualization capabilities. + */ + struct nvidia_grace_cmdqv *nvidia_grace_cmdqv; }; struct arm_smmu_stream { @@ -753,6 +761,10 @@ 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); +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); @@ -812,4 +824,33 @@ static inline u32 arm_smmu_sva_get_pasid(struct iommu_sva *handle) static inline void arm_smmu_sva_notifier_synchronize(void) {} #endif /* CONFIG_ARM_SMMU_V3_SVA */ + +struct acpi_iort_node; + +#ifdef CONFIG_NVIDIA_GRACE_CMDQV +struct nvidia_grace_cmdqv * +nvidia_grace_cmdqv_acpi_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node); +int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu); +struct arm_smmu_cmdq *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu); +#else /* CONFIG_NVIDIA_GRACE_CMDQV */ +static inline struct nvidia_grace_cmdqv * +nvidia_grace_cmdqv_acpi_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + return NULL; +} + +static inline int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu) +{ + return -ENODEV; +} + +static inline struct arm_smmu_cmdq * +nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +{ + return NULL; +} +#endif /* CONFIG_NVIDIA_GRACE_CMDQV */ + #endif /* _ARM_SMMU_V3_H */ diff --git a/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c new file mode 100644 index 000000000000..c0d7351f13e2 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c @@ -0,0 +1,418 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2021 NVIDIA CORPORATION & AFFILIATES */ + +#define dev_fmt(fmt) "nvidia_grace_cmdqv: " fmt + +#include +#include +#include +#include +#include + +#include + +#include "arm-smmu-v3.h" + +#define NVIDIA_CMDQV_HID "NVDA0600" + +/* CMDQV register page base and size defines */ +#define NVIDIA_CMDQV_CONFIG_BASE (0) +#define NVIDIA_CMDQV_CONFIG_SIZE (SZ_64K) +#define NVIDIA_VCMDQ_BASE (0 + SZ_64K) +#define NVIDIA_VCMDQ_SIZE (SZ_64K * 2) /* PAGE0 and PAGE1 */ + +/* CMDQV global config regs */ +#define NVIDIA_CMDQV_CONFIG 0x0000 +#define CMDQV_EN BIT(0) + +#define NVIDIA_CMDQV_PARAM 0x0004 +#define CMDQV_NUM_VINTF_LOG2 GENMASK(11, 8) +#define CMDQV_NUM_VCMDQ_LOG2 GENMASK(7, 4) + +#define NVIDIA_CMDQV_STATUS 0x0008 +#define CMDQV_STATUS GENMASK(2, 1) +#define CMDQV_ENABLED BIT(0) + +#define NVIDIA_CMDQV_VINTF_ERR_MAP 0x000C +#define NVIDIA_CMDQV_VINTF_INT_MASK 0x0014 +#define NVIDIA_CMDQV_VCMDQ_ERR_MAP 0x001C + +#define NVIDIA_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 NVIDIA_CMDQV_VINTF(v) (0x1000 + 0x100*(v)) + +#define NVIDIA_VINTF_CONFIG 0x0000 +#define VINTF_HYP_OWN BIT(17) +#define VINTF_VMID GENMASK(16, 1) +#define VINTF_EN BIT(0) + +#define NVIDIA_VINTF_STATUS 0x0004 +#define VINTF_STATUS GENMASK(3, 1) +#define VINTF_ENABLED BIT(0) + +/* VCMDQ config regs */ +/* -- PAGE0 -- */ +#define NVIDIA_CMDQV_VCMDQ(q) (NVIDIA_VCMDQ_BASE + 0x80*(q)) + +#define NVIDIA_VCMDQ_CONS 0x00000 +#define VCMDQ_CONS_ERR GENMASK(30, 24) + +#define NVIDIA_VCMDQ_PROD 0x00004 + +#define NVIDIA_VCMDQ_CONFIG 0x00008 +#define VCMDQ_EN BIT(0) + +#define NVIDIA_VCMDQ_STATUS 0x0000C +#define VCMDQ_ENABLED BIT(0) + +#define NVIDIA_VCMDQ_GERROR 0x00010 +#define NVIDIA_VCMDQ_GERRORN 0x00014 + +/* -- PAGE1 -- */ +#define NVIDIA_VCMDQ_BASE_L(q) (NVIDIA_CMDQV_VCMDQ(q) + SZ_64K) +#define VCMDQ_ADDR GENMASK(47, 5) +#define VCMDQ_LOG2SIZE GENMASK(4, 0) + +struct nvidia_grace_cmdqv_vintf { + u16 idx; + u32 cfg; + u32 status; + + void __iomem *base; + struct arm_smmu_cmdq *vcmdqs; +}; + +struct nvidia_grace_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; + + /* CMDQV_VINTF(0) reserved for host kernel use */ + struct nvidia_grace_cmdqv_vintf vintf0; +}; + +static irqreturn_t nvidia_grace_cmdqv_isr(int irq, void *devid) +{ + struct nvidia_grace_cmdqv *cmdqv = (struct nvidia_grace_cmdqv *)devid; + struct nvidia_grace_cmdqv_vintf *vintf0 = &cmdqv->vintf0; + u32 vintf_err_map[2]; + u32 vcmdq_err_map[4]; + + vintf_err_map[0] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VINTF_ERR_MAP); + vintf_err_map[1] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VINTF_ERR_MAP + 0x4); + + vcmdq_err_map[0] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VCMDQ_ERR_MAP); + vcmdq_err_map[1] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0x4); + vcmdq_err_map[2] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0x8); + vcmdq_err_map[3] = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_VCMDQ_ERR_MAP + 0xC); + + dev_warn(cmdqv->dev, + "unexpected cmdqv error reported: vintf_map %08X %08X, vcmdq_map %08X %08X %08X %08X\n", + vintf_err_map[0], vintf_err_map[1], vcmdq_err_map[0], vcmdq_err_map[1], + vcmdq_err_map[2], vcmdq_err_map[3]); + + /* If the error was reported by vintf0, avoid using any of its VCMDQs */ + if (vintf_err_map[vintf0->idx / 32] & (1 << (vintf0->idx % 32))) { + vintf0->status = readl_relaxed(vintf0->base + NVIDIA_VINTF_STATUS); + + dev_warn(cmdqv->dev, "error (0x%lX) reported by host vintf0 - disabling its vcmdqs\n", + FIELD_GET(VINTF_STATUS, vintf0->status)); + } else if (vintf_err_map[0] || vintf_err_map[1]) { + dev_err(cmdqv->dev, "cmdqv error interrupt triggered by unassigned vintf!\n"); + } + + return IRQ_HANDLED; +} + +/* Adapt struct arm_smmu_cmdq init sequences from arm-smmu-v3.c for VCMDQs */ +static int nvidia_grace_cmdqv_init_one_vcmdq(struct nvidia_grace_cmdqv *cmdqv, + struct arm_smmu_cmdq *cmdq, + void __iomem *vcmdq_base, u16 qidx) +{ + struct arm_smmu_queue *q = &cmdq->q; + char name[16]; + int ret; + + sprintf(name, "vcmdq%u", qidx); + + 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_base, + NVIDIA_VCMDQ_PROD, NVIDIA_VCMDQ_CONS, + CMDQ_ENT_DWORDS, name); + if (ret) + return ret; + + /* ...override q_base for VCMDQ_BASE_L/H 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 *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +{ + struct nvidia_grace_cmdqv *cmdqv = smmu->nvidia_grace_cmdqv; + struct nvidia_grace_cmdqv_vintf *vintf0 = &cmdqv->vintf0; + u16 qidx; + + /* Check error status of vintf0 */ + if (!FIELD_GET(VINTF_STATUS, vintf0->status)) + 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 &vintf0->vcmdqs[qidx]; +} + +int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu) +{ + struct nvidia_grace_cmdqv *cmdqv = smmu->nvidia_grace_cmdqv; + struct nvidia_grace_cmdqv_vintf *vintf0 = &cmdqv->vintf0; + u32 regval; + u16 qidx; + int ret; + + /* Setup vintf0 for host kernel */ + vintf0->idx = 0; + vintf0->base = cmdqv->base + NVIDIA_CMDQV_VINTF(0); + + regval = FIELD_PREP(VINTF_HYP_OWN, 1); + writel(regval, vintf0->base + NVIDIA_VINTF_CONFIG); + + regval |= FIELD_PREP(VINTF_EN, 1); + writel(regval, vintf0->base + NVIDIA_VINTF_CONFIG); + + vintf0->cfg = regval; + + ret = readl_relaxed_poll_timeout(vintf0->base + NVIDIA_VINTF_STATUS, + regval, regval == VINTF_ENABLED, + 1, ARM_SMMU_POLL_TIMEOUT_US); + vintf0->status = regval; + if (ret) { + dev_err(cmdqv->dev, "failed to enable VINTF%u: STATUS = 0x%08X\n", + vintf0->idx, regval); + return ret; + } + + /* Allocate vcmdqs to vintf0 */ + for (qidx = 0; qidx < cmdqv->num_vcmdqs_per_vintf; qidx++) { + regval = FIELD_PREP(CMDQV_CMDQ_ALLOC_VINTF, vintf0->idx); + regval |= FIELD_PREP(CMDQV_CMDQ_ALLOC_LVCMDQ, qidx); + regval |= CMDQV_CMDQ_ALLOCATED; + writel_relaxed(regval, cmdqv->base + NVIDIA_CMDQV_CMDQ_ALLOC(qidx)); + } + + /* Build an arm_smmu_cmdq for each vcmdq allocated to vintf0 */ + vintf0->vcmdqs = devm_kcalloc(cmdqv->dev, cmdqv->num_vcmdqs_per_vintf, + sizeof(*vintf0->vcmdqs), GFP_KERNEL); + if (!vintf0->vcmdqs) + return -ENOMEM; + + for (qidx = 0; qidx < cmdqv->num_vcmdqs_per_vintf; qidx++) { + void __iomem *vcmdq_base = cmdqv->base + NVIDIA_CMDQV_VCMDQ(qidx); + struct arm_smmu_cmdq *cmdq = &vintf0->vcmdqs[qidx]; + + /* Setup struct arm_smmu_cmdq data members */ + nvidia_grace_cmdqv_init_one_vcmdq(cmdqv, cmdq, vcmdq_base, qidx); + + /* Configure and enable the vcmdq */ + writel_relaxed(0, vcmdq_base + NVIDIA_VCMDQ_PROD); + writel_relaxed(0, vcmdq_base + NVIDIA_VCMDQ_CONS); + + writeq_relaxed(cmdq->q.q_base, cmdqv->base + NVIDIA_VCMDQ_BASE_L(qidx)); + + writel(VCMDQ_EN, vcmdq_base + NVIDIA_VCMDQ_CONFIG); + ret = readl_poll_timeout(vcmdq_base + NVIDIA_VCMDQ_STATUS, + regval, regval == VCMDQ_ENABLED, + 1, ARM_SMMU_POLL_TIMEOUT_US); + if (ret) { + u32 gerror = readl_relaxed(vcmdq_base + NVIDIA_VCMDQ_GERROR); + u32 gerrorn = readl_relaxed(vcmdq_base + NVIDIA_VCMDQ_GERRORN); + u32 cons = readl_relaxed(vcmdq_base + NVIDIA_VCMDQ_CONS); + + dev_err(cmdqv->dev, + "failed to enable VCMDQ%u: GERROR=0x%X, GERRORN=0x%X, CONS=0x%X\n", + qidx, gerror, gerrorn, cons); + return ret; + } + + dev_info(cmdqv->dev, "VCMDQ%u allocated to VINTF%u as logical-VCMDQ%u\n", + qidx, vintf0->idx, qidx); + } + + return 0; +} + +static int nvidia_grace_cmdqv_acpi_is_memory(struct acpi_resource *res, void *data) +{ + struct resource r; + + return !acpi_dev_resource_memory(res, &r); +} + +static int nvidia_grace_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 */ +} + +/* + * Function taking care of all ACPI resource probings and according allocations + * + * Note that it uses devm_* functions for resource allocations here so that smmu + * driver can roll back cmdqv resources automatically without additional cleanup + * routine, if any further error happens there. Yet this means all error unwinds + * here will have to go with devm_* too. + */ +static struct nvidia_grace_cmdqv * +nvidia_grace_cmdqv_find_resource(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + struct nvidia_grace_cmdqv *cmdqv = NULL; + 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's iort_node identifier */ + match_uid = kasprintf(GFP_KERNEL, "%u", node->identifier); + adev = acpi_dev_get_first_match_dev(NVIDIA_CMDQV_HID, match_uid, -1); + kfree(match_uid); + + if (!adev) + return NULL; + + dev_info(smmu->dev, "found companion CMDQV device, %s\n", dev_name(&adev->dev)); + + INIT_LIST_HEAD(&resource_list); + ret = acpi_dev_get_resources(adev, &resource_list, + nvidia_grace_cmdqv_acpi_is_memory, NULL); + if (ret < 0) { + dev_err(smmu->dev, "failed to get memory resource: %d\n", ret); + goto put_dev; + } + + cmdqv = devm_kzalloc(smmu->dev, sizeof(*cmdqv), GFP_KERNEL); + if (!cmdqv) + goto free_list; + + rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node); + if (!rentry) { + dev_err(smmu->dev, "failed to get memory resource entry\n"); + goto free_cmdqv; + } + + cmdqv->smmu = smmu; + cmdqv->dev = smmu->dev; + cmdqv->res = rentry->res; + + cmdqv->base = devm_ioremap_resource(smmu->dev, rentry->res); + if (IS_ERR(cmdqv->base)) { + dev_err(smmu->dev, "failed to ioremap: %ld\n", PTR_ERR(cmdqv->base)); + goto free_cmdqv; + } + + ret = acpi_dev_get_resources(adev, &resource_list, + nvidia_grace_cmdqv_acpi_get_irqs, &cmdqv->irq); + if (ret < 0) { + dev_warn(smmu->dev, "no cmdqv interrupt - errors will not be reported\n"); + cmdqv->irq = 0; + } else { + ret = devm_request_irq(smmu->dev, cmdqv->irq, nvidia_grace_cmdqv_isr, + 0, "nvidia-grace-cmdqv", cmdqv); + if (ret) { + dev_err(smmu->dev, "failed to request irq (%d): %d\n", + cmdqv->irq, ret); + goto iounmap; + } + } + + goto free_list; + +iounmap: + devm_iounmap(smmu->dev, cmdqv->base); + devm_release_mem_region(smmu->dev, cmdqv->res->start, + resource_size(cmdqv->res)); +free_cmdqv: + devm_kfree(smmu->dev, cmdqv); + cmdqv = NULL; +free_list: + acpi_dev_free_resource_list(&resource_list); +put_dev: + put_device(&adev->dev); + + return cmdqv; +} + +struct nvidia_grace_cmdqv * +nvidia_grace_cmdqv_acpi_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + struct nvidia_grace_cmdqv *cmdqv; + u32 regval; + + cmdqv = nvidia_grace_cmdqv_find_resource(smmu, node); + if (!cmdqv) + return NULL; + + regval = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_CONFIG); + if (!FIELD_GET(CMDQV_EN, regval)) { + dev_err(cmdqv->dev, "CMDQV h/w is disabled: CMDQV_CONFIG=0x%08X\n", regval); + goto free_res; + } + + regval = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_STATUS); + if (!FIELD_GET(CMDQV_ENABLED, regval) || FIELD_GET(CMDQV_STATUS, regval)) { + dev_err(cmdqv->dev, "CMDQV h/w not ready: CMDQV_STATUS=0x%08X\n", regval); + goto free_res; + } + + regval = readl_relaxed(cmdqv->base + NVIDIA_CMDQV_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; + + return cmdqv; + +free_res: + if (cmdqv->irq) + devm_free_irq(smmu->dev, cmdqv->irq, cmdqv); + devm_iounmap(smmu->dev, cmdqv->base); + devm_release_mem_region(smmu->dev, cmdqv->res->start, + resource_size(cmdqv->res)); + devm_kfree(smmu->dev, cmdqv); + + return NULL; +} From patchwork Fri Nov 19 07:19:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 12693110 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FCC4C433EF for ; Fri, 19 Nov 2021 07:30:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 27E25610A0 for ; Fri, 19 Nov 2021 07:30:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 27E25610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9AJdUBAIUOy6I1nOqnXTX75ELHc//LGg4BqCNnZoYaQ=; b=EZKvWUFeshSXIV unUBiNAviMbLd/qgyZOOrz/q6UYgt5VwUZOp0xDkjjNTKOjd+ePlIFC8m+mOvz18IJAg+GC+6W5rI su5S4FC/RnkkE8VQdbVnmJC6KUaxwo9rs2Q9QrO0FqCmYx0yD727wPAgL0XnFv8rgd3VB5B9O13BA yWnV9f6REWre0QtXjSjtL6Ct+g7lIJyywR/7a4b8pcS1IyoH3EcCsSMxqoacaJxUd1XHbQVF31pjl q8zwXgaJ7Q7O1Eq4gLHJtHqBldnKaMxZ5J0+Ydt/iTOTHVrLUWqH39VBHY5m5ooTx+osxSSRM8Sad hhUNB29auIq0mv4lcG8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyKM-009arK-AY; Fri, 19 Nov 2021 07:28:55 +0000 Received: from mail-co1nam11on2066.outbound.protection.outlook.com ([40.107.220.66] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyJK-009aaM-1h for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 07:27:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BnzLdI+gdjRA1AMmAUbOCL1APraF6QkvuHPJG3x/JvD0/yIu6Uqu2EaNM9ENxE7PVCkgD9t6ZmlQU1SAy9ikr4iR3KEqxQwUqyzx3MsZA1K+8Ngnl3mhVjYZgXe0K96sC6XoACk+szpAdJMjxT5g1frkYgfPFRCm3U7M2RX6WVx+p5UWAzzn5OazwIYSxMbKyWgJt83+/XbnW/6/i3+QaJ9MitlSdSPpb6Jd75Fcr0jM6D1bdSWdsZGu2CIasjbKHG01v4D+IeFmTlEwLVxbo1Eg9CfxluXMCVroQsTnRntRw4Zct4isdyNrCUiJ+ZuvoAZ9ja8hivqFl92fPd/aDQ== 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=KqVazHekPsNWX39MMNHQ2+i+FphwKMZ2tdNIoHcP+iM=; b=RMn0nfoTUdPIUnPPCQxT+zEJSdsFNhEMEvGtdp3KdbjVU7OB5mju2xDOBXS2MY849ho2dM2J47WvsX3zVmGY+t8F8eKetWsRICfQawP04t0FW8xPQj1sLdht1n5gN+N6E2zwxyLf6H5QzSqqJvRRNuI6OS8kTdnL0BhnWoNd7605qdeOnENox4zKtwASu+qvX7XXK4tTP3JjwynzbcQnvx65O6vPrrfZu4XQLtSzdHegoWmi3EfSHmJEXRyywyzS557rhHuF1JaTMuWGZyuxN0GUn7zKNGXXmUeHP2WBsQfPobfRq4Qw+V+634Iyp3A0+kp2rgFi4E7SrHibW3gldA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none 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=KqVazHekPsNWX39MMNHQ2+i+FphwKMZ2tdNIoHcP+iM=; b=h9oiv6b1HqKD4ynvtJgT24PX/Dhqsz7u2LRv9YI2JVLVGsH//y/mw0dqL6pH0wJfIoxKsnbWXg/E3SeyIh8GAbWCe+hQnVtEMJu4446ExFVKQ7yelM6FV/xCn/YlqmYP+oreK3nUeQRc3Bl6t2Da4+7WiFuGgccPLhiIt13w59HWnggxwmdJv0DxYXaCdhqDEdoc9Bidt+q3RaW2DeiwhOt8hwJcw77ci9Om/r3CDu3iXavFM1YbIDBNW2NhcPaW9FZJ2Dv7KTQ6OtIDiOQLmT0WIIvghk3ev+Wg0OAqgbcz515GaCIGiLe+jxGo1bqAntE3sFKPJMb0mxufs7rZRA== Received: from DM6PR08CA0051.namprd08.prod.outlook.com (2603:10b6:5:1e0::25) by MWHPR12MB1230.namprd12.prod.outlook.com (2603:10b6:300:f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Fri, 19 Nov 2021 07:27:38 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::5d) by DM6PR08CA0051.outlook.office365.com (2603:10b6:5:1e0::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 07:27:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) 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.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Fri, 19 Nov 2021 07:27:38 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 19 Nov 2021 07:27:37 +0000 Received: from Asurada-Nvidia.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 19 Nov 2021 07:27:36 +0000 From: Nicolin Chen To: , , Subject: [PATCH v3 5/5] iommu/nvidia-grace-cmdqv: Limit CMDs for guest owned VINTF Date: Thu, 18 Nov 2021 23:19:59 -0800 Message-ID: <20211119071959.16706-6-nicolinc@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211119071959.16706-1-nicolinc@nvidia.com> References: <20211119071959.16706-1-nicolinc@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 974e3c5a-ffdb-463c-f895-08d9ab2e10ba X-MS-TrafficTypeDiagnostic: MWHPR12MB1230: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1850; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9Y/URpi5lr6qdUQp52/7sFoRMNrVrxsxfPs8VhbI6Z9VfnMjmwVgPDTV06oaCqEUu6A49/zeD5S4UCD3cuANb3dloPDYDCS59iVNFaTg4U1j1oluWjcImHBAd9ml+3VB6My55NPrN1MuekCL6UhBJNXoTGyH+mP8Hh3UyR2NMJ+EC8pWVG//Vumbe6o240RKaPuxHvSz36Bu/CrgeNEr1P57nPy2TEU8JhJCLWjQm3InUgA1TvRXDRXec6uMSmHbakB0nNXIrWDU1IrKV5M3X1JD3gxrI1Y4UzsarEaNOIPtr6koZP+/8wBIN/ZvUUD8HBuf4/IND+LOJodCHmkXVO/07Y3DzV/MRTVTLUSWxv4RXUzsp9U7aop36DZOcu4vlTxapsMIpJJLMxZ0iliRRFUxovIG0dXip1Q3M9BK+2IEHWOLcVaUM7/VYJEM5WSFn0T93QNHxh+Da7QvVRz6eINkPnRa4cdwwxpU6yEtVpuoMw4R5dsPMpcF2z94QoYJcRzEkNO1Vh4aVQcU3X4FdE0wnArtOYDnwSiULcThGxrCDWUc0TCa+aq/jGigyAIhBKUD8NFg9+FWboY8Ep9dpS2KKEM7DJePxy7k7UzEP/V7RqsrzlEId4UnQ3jSK/Ybaa9KxU+7O3t14eUZCKnNqrX7I2OGYl+p5N7GpEC2FTVz9SPG0dIwwWrbS1EnMqOxxru1Rzkhr6cNiQ2Oz076Rw== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(86362001)(110136005)(54906003)(7636003)(316002)(1076003)(356005)(70586007)(70206006)(2906002)(36906005)(36860700001)(36756003)(4326008)(5660300002)(186003)(26005)(7696005)(2616005)(107886003)(336012)(6666004)(47076005)(8936002)(426003)(8676002)(508600001)(7416002)(83380400001)(82310400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 07:27:38.4651 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 974e3c5a-ffdb-463c-f895-08d9ab2e10ba X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1230 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_232750_128524_33D21703 X-CRM114-Status: GOOD ( 20.19 ) 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: , Cc: jean-philippe@linaro.org, nwatterson@nvidia.com, chenxiang66@hisilicon.com, Jonathan.Cameron@huawei.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, nicoleotsuka@gmail.com, linux-tegra@vger.kernel.org, thierry.reding@gmail.com, jgg@nvidia.com, thunder.leizhen@huawei.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org 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 that is owned by a guest, not hypervisor (HYP_OWN bit is unset), only TLB invalidation commands are supported. This requires get_cmd() function to scan the input cmd before selecting cmdq between smmu->cmdq and vintf->vcmdq, so unsupported commands can still go through emulated smmu->cmdq. Also the guest shouldn't have HYP_OWN bit being set regardless of guest kernel driver writing it or not, i.e. the user space driver 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. So instead of using the existing regval, this patch reads out the register value explicitly to cache in vintf->cfg. 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 | 5 +-- .../arm/arm-smmu-v3/nvidia-grace-cmdqv.c | 32 +++++++++++++++++-- 3 files changed, 36 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 b1182dd825fd..73941ccc1a3e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -337,10 +337,10 @@ 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->nvidia_grace_cmdqv) - return nvidia_grace_cmdqv_get_cmdq(smmu); + return nvidia_grace_cmdqv_get_cmdq(smmu, cmds, n); return &smmu->cmdq; } @@ -747,7 +747,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 24f93444aeeb..085c775c2eea 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -832,7 +832,8 @@ struct nvidia_grace_cmdqv * nvidia_grace_cmdqv_acpi_probe(struct arm_smmu_device *smmu, struct acpi_iort_node *node); int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu); -struct arm_smmu_cmdq *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu); +struct arm_smmu_cmdq *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu, + u64 *cmds, int n); #else /* CONFIG_NVIDIA_GRACE_CMDQV */ static inline struct nvidia_grace_cmdqv * nvidia_grace_cmdqv_acpi_probe(struct arm_smmu_device *smmu, @@ -847,7 +848,7 @@ static inline int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu) } static inline struct arm_smmu_cmdq * -nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu, u64 *cmds, int n) { return NULL; } diff --git a/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c index c0d7351f13e2..71f6bc684e64 100644 --- a/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c +++ b/drivers/iommu/arm/arm-smmu-v3/nvidia-grace-cmdqv.c @@ -166,7 +166,8 @@ static int nvidia_grace_cmdqv_init_one_vcmdq(struct nvidia_grace_cmdqv *cmdqv, return arm_smmu_cmdq_init(cmdqv->smmu, cmdq); } -struct arm_smmu_cmdq *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +struct arm_smmu_cmdq * +nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu, u64 *cmds, int n) { struct nvidia_grace_cmdqv *cmdqv = smmu->nvidia_grace_cmdqv; struct nvidia_grace_cmdqv_vintf *vintf0 = &cmdqv->vintf0; @@ -176,6 +177,24 @@ struct arm_smmu_cmdq *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) if (!FIELD_GET(VINTF_STATUS, vintf0->status)) return &smmu->cmdq; + /* Check for supported CMDs if VINTF is owned by guest (not hypervisor) */ + if (!FIELD_GET(VINTF_HYP_OWN, vintf0->cfg)) { + u64 opcode = (n) ? FIELD_GET(CMDQ_0_OP, cmds[0]) : CMDQ_OP_CMD_SYNC; + + /* List all supported CMDs for vintf->cmdq pathway */ + switch (opcode) { + case CMDQ_OP_TLBI_NH_ASID: + case CMDQ_OP_TLBI_NH_VA: + case CMDQ_OP_TLBI_S12_VMALL: + case CMDQ_OP_TLBI_S2_IPA: + case CMDQ_OP_ATC_INV: + break; + default: + /* Unsupported CMDs go for smmu->cmdq pathway */ + 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 @@ -199,13 +218,22 @@ int nvidia_grace_cmdqv_device_reset(struct arm_smmu_device *smmu) vintf0->idx = 0; vintf0->base = cmdqv->base + NVIDIA_CMDQV_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); writel(regval, vintf0->base + NVIDIA_VINTF_CONFIG); regval |= FIELD_PREP(VINTF_EN, 1); writel(regval, vintf0->base + NVIDIA_VINTF_CONFIG); - vintf0->cfg = regval; + /* + * As being mentioned above, HYP_OWN bit is wired to zero for a guest + * kernel, so read back regval from HW to ensure that reflects in cfg + */ + vintf0->cfg = readl(vintf0->base + NVIDIA_VINTF_CONFIG); ret = readl_relaxed_poll_timeout(vintf0->base + NVIDIA_VINTF_STATUS, regval, regval == VINTF_ENABLED,