From patchwork Sun Jul 28 22:44:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=bF37lCbG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3108-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGls3kcSz1ybY for ; Mon, 29 Jul 2024 08:45:13 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 815421C20C05 for ; Sun, 28 Jul 2024 22:45:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFD507C6DF; Sun, 28 Jul 2024 22:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bF37lCbG" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 733CF7B3FE; Sun, 28 Jul 2024 22:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206710; cv=fail; b=Luc0kL+5ITCdx9G9NUIxh1W2wN9IyU0KG1H3p2NP+VyWORgAP9Z7AYCRgvdNhxpfM1tPadT3ST4Qc4gUq8Y4xaiSzaYb4Zn53B6VGm26ZanBI8QZmkPVcp3/AmlDKImdVQ72XiomIOL051wR0Rbmrh6knexUgwqDnsBCOP1dEJk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206710; c=relaxed/simple; bh=6IHx3tvJEQWkDsVcgGvHuGuW6HP05TvkHD7iGHqRXzo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t4HKGddh6eqvwoYB3SyJsqhXWsEpgWfDyVAG24FSgB/Ex5Kf443pWDezTZlekoLUkeRJSjW5+WPZDdSMASZ7t6aTS+JDyCpt5FjVapTKSMruwn/8BJIW/fI9mYazr6b7xxwhgnOrFsBKs5l800knadaSSIERHyWpHITNP03Zb2Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=bF37lCbG; arc=fail smtp.client-ip=40.107.223.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FFJehGSGdt3t52EVRx01phhtd6s+2eCovJqzSa2VWsjoWcaLtdVIJTdc9WtI3hBaiTfwyFO6extt8A3+O77squA8wgBwJoFiLwQH96zlSlzdRXlMdmHrtVXN4oz7sasDLQq600LwKPc71jM+2BgeL12tFpbrKTeT2plyJId+vy4TDVceXt2+bCQPX/jFBg69q0sTEdLoJURZmN3jkIxBMlL9bvVAhKymnFaYagELq10sRTJtSFu2iW1vuWEoNen6KgBGHL0xGmlik2ICmCW+GmP5TPrxnaqEoddeZ9Hvhv1wId4O4fEUeO1sHQT4Sc6GlDS48fY6vBGATy+2dmDhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Szvf8FNNaJdmb3wTPkXL69Q1ICFOtriSCanDluqqtW8=; b=YtPDo36C4fuAJpXCHOr/rQ/fsQGsSDBOR5kZK8J22gZ5TJpXzU9qWoETh7i8P37YiyfrJZMek0II7LVJMhI8TxwCmTzy/ec4KNqAbE98I9Tn72SGKnQetP6UwdAdf4e407LqUXidEeQKI5OONtM75s+TYnzCSBifU5VP2vwLEkja20T6EBa81Jtn2EJQkcIr7NGFRYbJLzHEN8kV+bxJ3lx9JgeZSJ3GrvETzktebM/jyuhXGRDexiKRrouoLSM+S1l8jpMCdBSekVQxD5Svq8ZATXYu+tn1UqVUOcI764mgwutABD026WJ9xf4s2wlsK2/3x+fk8Jo03FnmcjxG2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=Szvf8FNNaJdmb3wTPkXL69Q1ICFOtriSCanDluqqtW8=; b=bF37lCbGRKsi4ieE46QXbgqvvkx159rDlGGcol3pUUsh9JzW+03Uvry/bvzNzZXq5vp5xgXfwWztw9pb+e2uiK66HdRwFSEicCQjruz2RpfcWOnmj/nq83IOp13ShcY1UVIvI2OiO5y0jwZZ3/sTRWOv8jBEAtdSP1k1/q7QLu/JN3hguuSrnhkNOKeM9ipP5a76EiBOnJdRGrx+nRKXvDp1kDDFdHbG0B94E46FDVpHrtuSexRriiEpbqW4Gizc/eHJxzaHKb9X3lRvMsabqUioorvFk9bCr4f1zkWcZyZJkulJkYz9ESdfpXojj/iCVNWa/2mZuBo37ep+xecuMA== Received: from PH7P221CA0064.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:328::18) by CY8PR12MB7489.namprd12.prod.outlook.com (2603:10b6:930:90::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.26; Sun, 28 Jul 2024 22:45:04 +0000 Received: from MWH0EPF000A672F.namprd04.prod.outlook.com (2603:10b6:510:328:cafe::72) by PH7P221CA0064.outlook.office365.com (2603:10b6:510:328::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A672F.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:04 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:01 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:01 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:00 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 1/9] iommu/arm-smmu-v3: Issue a batch of commands to the same cmdq Date: Sun, 28 Jul 2024 15:44:46 -0700 Message-ID: <573c571ab9162d5fc13200f21bfcb9dc7b54e0b6.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672F:EE_|CY8PR12MB7489:EE_ X-MS-Office365-Filtering-Correlation-Id: b6aa034d-ba75-42e8-22a5-08dcaf56ebfd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: PbTsBcaZzXy6EHtmuVl8T0b1Vgv2uQFkHntzENmWHakFuKVR/IrETHF3X+uGp3ZmiEnrE8SjsILEsiQ5vNgvpLbW0tdDTUBp2jBCXmuwuQsDkNady3TuSFeUKfRBsUzXTHjog/IDNzPr56fu54jc7DC4ZoiDTsHTjoQbeh3Tu4mlLoOXOKWLA8kH8ONDMqlYsJjInEONeR0voFB7/VaYv3VxINPvZ8+e7jJlagWY9DaLuipk8PjX82G0rFaf79igKoOsXy/gcqiH1I72iSxB3X+Q4tktc4k0ifN0hvNANqE6tz8NrDng/f7YSa645p+nFPHtlHCZEQLgizLJn7D1ftTi/z4aXJSxPD2fOPFQL+pJa6+uSPnQoill562zv7NDU5bWZrhDPRSAxcB0Z9fk/WH0OPUqu454ARcuWvu5ChFbBE0hp88ltFG2PO81eGN+slR10oYfJ47c0SRnzWIAZZ63OuJh4p6Ah+vDejUreEFWD0VO/QQg9Moa+bcITcJNSvreTRko4+IhjvFJh/QBHLKcSJCGgb9XKMLIBndDQoi1Jjh5zCYagNMjVlFImDxNxqSL1PQPZyT16Uqd1cIc1ouOkmf44K/YJP9x91KJnRHDP/Q6Pf6Rsg3nshPbnBSfTex/lwcejQH5U/VBjox3kb/DPLOP1YDRRrYljR3WKcEZLF853fUIvHGm/YTU4XO4mzNPgJFVGPPXPBJo44AdR4GktKRVvsmZ57zj3Km+epi4M9WkBS5W9+mY6o01Vv5iHtld1W1VnoKI7fB69z0+iD/3sUY1VJjIxTMxtb46oIkgN6EoLqyfr9K9EE79mz2lGLqev2WeR7xUvcAlvKnY0kipwwBNQDxlgngGCMwDXsKqOXSgD7mjl7dK253VwQzRpTN5TYF6A43NCEgYxsn4SnuEXSMrwjTUJzXV6mL7LHKPFdK8RAKGTqYQOoUiGkapHy7pxEQFVO1YV9na20IsXfhrEKxLuGcV+EZlQXhEqVmId6a19aHgr/oJxz8UHvg8e8JLZy3F4SWxZPhlCgm7WrGwyPpH8H1f61w07oj8ioTU/17rovYhmVR6XWC71bpXP2jW9nfJ6X/Yg1/DPWWwCofF7ts3pHdz1fa2MR1nscmDLRPRkxROi3YrdrVl1g5IhQwlqHY5Nj0aF61ly+6YYg5OAr8SbA3eVQBCZDDnasFvSeQfD6WZtgGtkgiK6xZBwp1N04yFlwSH9Bbh+J2Gg1ESDxcIxVTKXa6IKqyoGqInnptKDlnpvBN0jy9n86pjBLmu276wPz62zVj9506tIfp+YRzVvOkD2rgtJlnXsgewaARZi6Sbh8x4JIJGG6xWoj7bbubwXep23ywL+VHkkUeRjOL+r6IIEw7LbzfaUuoe8A+tUihbRsCWGqbNfxamsqgs6VCDd2EoMVgGxe7ezgmLGotDidVgoptYH2mhszlRS44bVkEP/pWKIpUtQcDH X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:04.0270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6aa034d-ba75-42e8-22a5-08dcaf56ebfd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A672F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7489 The driver calls in different places the arm_smmu_get_cmdq() helper, and it's fine to do so since the helper always returns the single SMMU CMDQ. However, with NVIDIA CMDQV extension or SMMU ECMDQ, there can be multiple cmdqs in the system to select one from. And either case requires a batch of commands to be issued to the same cmdq. Thus, a cmdq has to be decided in the higher-level callers. Add a cmdq pointer in arm_smmu_cmdq_batch structure, and decide the cmdq when initializing the batch. Pass its pointer down to the bottom function. Update __arm_smmu_cmdq_issue_cmd() accordingly for single command issuers. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 44 +++++++++++++-------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 29 insertions(+), 16 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 a31460f9f3d42..f409ead589ffc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -592,11 +592,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; /* @@ -627,11 +627,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); @@ -651,10 +651,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; @@ -701,12 +701,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, @@ -743,13 +744,13 @@ static void arm_smmu_cmdq_write_entries(struct arm_smmu_cmdq *cmdq, u64 *cmds, * CPU will appear before any of the commands from the other CPU. */ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq, u64 *cmds, int n, bool sync) { u64 cmd_sync[CMDQ_ENT_DWORDS]; u32 prod; unsigned long flags; bool owner; - struct arm_smmu_cmdq *cmdq = arm_smmu_get_cmdq(smmu); struct arm_smmu_ll_queue llq, head; int ret = 0; @@ -763,7 +764,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); } @@ -839,7 +840,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", @@ -874,7 +875,8 @@ static int __arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, return -EINVAL; } - return arm_smmu_cmdq_issue_cmdlist(smmu, cmd, 1, sync); + return arm_smmu_cmdq_issue_cmdlist( + smmu, arm_smmu_get_cmdq(smmu), cmd, 1, sync); } static int arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, @@ -889,6 +891,13 @@ static int arm_smmu_cmdq_issue_cmd_with_sync(struct arm_smmu_device *smmu, return __arm_smmu_cmdq_issue_cmd(smmu, ent, true); } +static void arm_smmu_cmdq_batch_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds) +{ + cmds->num = 0; + cmds->cmdq = arm_smmu_get_cmdq(smmu); +} + static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, struct arm_smmu_cmdq_batch *cmds, struct arm_smmu_cmdq_ent *cmd) @@ -897,12 +906,14 @@ static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, if (cmds->num == CMDQ_BATCH_ENTRIES - 1 && (smmu->options & ARM_SMMU_OPT_CMDQ_FORCE_SYNC)) { - arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, true); + arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmdq, cmds->cmds, + cmds->num, true); cmds->num = 0; } if (cmds->num == CMDQ_BATCH_ENTRIES) { - arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false); + arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmdq, cmds->cmds, + cmds->num, false); cmds->num = 0; } @@ -919,7 +930,8 @@ static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, static int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu, struct arm_smmu_cmdq_batch *cmds) { - return arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, true); + return arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmdq, cmds->cmds, + cmds->num, true); } static void arm_smmu_page_response(struct device *dev, struct iopf_fault *unused, @@ -1170,7 +1182,7 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, }, }; - cmds.num = 0; + arm_smmu_cmdq_batch_init(smmu, &cmds); for (i = 0; i < master->num_streams; i++) { cmd.cfgi.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); @@ -2021,7 +2033,7 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); - cmds.num = 0; + arm_smmu_cmdq_batch_init(master->smmu, &cmds); for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(master->smmu, &cmds, &cmd); @@ -2059,7 +2071,7 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!atomic_read(&smmu_domain->nr_ats_masters)) return 0; - cmds.num = 0; + arm_smmu_cmdq_batch_init(smmu_domain->smmu, &cmds); spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_for_each_entry(master_domain, &smmu_domain->devices, @@ -2141,7 +2153,7 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, num_pages++; } - cmds.num = 0; + arm_smmu_cmdq_batch_init(smmu, &cmds); while (iova < end) { if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { 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 14bca41a981b4..c1454e9758c48 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -570,6 +570,7 @@ struct arm_smmu_cmdq { struct arm_smmu_cmdq_batch { u64 cmds[CMDQ_BATCH_ENTRIES * CMDQ_ENT_DWORDS]; + struct arm_smmu_cmdq *cmdq; int num; }; From patchwork Sun Jul 28 22:44:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=rwDTo2SZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3109-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm01Pnzz1ybY for ; Mon, 29 Jul 2024 08:45:20 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8F2021F2129F for ; Sun, 28 Jul 2024 22:45:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C0A22AD29; Sun, 28 Jul 2024 22:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="rwDTo2SZ" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2049.outbound.protection.outlook.com [40.107.220.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E587278C99; Sun, 28 Jul 2024 22:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206715; cv=fail; b=YDbPYYZfu5leTAqc3OI5W41vvPHRJdTPPp6K/9frAEHMSrk0gF5nXiL42mabHa5ajjyF4MvY6VaiktUhF0oEQPhW20b+DGa8hyFb0qh0NSpNS1NKsmb9+6t6gij3X6pYLIxtzf4JD0K/IR+JPQXVx0PTf54SB38a+ldwBDB60K0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206715; c=relaxed/simple; bh=qwaapivLAl6n71A5v+bwVuc4o0W0t7DrMzkVZju4Wzc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RfAJQqg+8hi1yl8UdnoSj3xhauD4U6AB7qCUUvPhOXY4NDPsBY1nWUkdr4pPxh3jj9ItNykIPR50OF9/Bw0THdlvTjcMK8MDUtewB5yG6qdIxsRho/TyQvVKd9UxZ4FjouR6uaV6dbE0X9seSfT/Q8JrsKtFGbDFz4EwmapzP0k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=rwDTo2SZ; arc=fail smtp.client-ip=40.107.220.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IIf+hzBGrdPwQADjjtZy8N3X++1lo1pdUILNRiZClws/8S2GYJmOHHPz7uwuSdxIQWrinHG/M3cG4+fLZcEs7lcZ3VhI8o/lGHlSB9r7IHZtBEEXbbzVb0+wQR0HP4M5EBIKvV6O3ge4cBbefGOns1Inr8d/9yCGruqSPMcGBER35bZ+2bZiY02jid0G7XP3ylgxZ69GJdtgMZEOJ9nhI5QxaofdEfxakON7JX4uzvmGDbGUK1ashKBVoE5BsCRjB05YqKoq2QV5xUy2CzB3tJ3AZ35pt3aSBSBIDo/jpsngtzEp18FYjGVO2GlCF5zGu5h9+9IF/oTLqTBHFuCGGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=M+CorPqZ5Rgj/E7HLb5fue3wNMi97HXrFIPFf3cWV0A=; b=aIcTuJ5Kw5caqrj56ERCAcRuEh36QRg+SsFbrgqKFvkP+nUyMeoYxL1/xJXNXSiFoZ7aseIyc5uOY5q3uFWt47UXkoepsTXm6gYH2S1FGJzn+3jwuv6RdJ3NTEVWp1hUuNggT0wlBRG2MP0pBlRFcDIt6jFAfOZDIqrH+HXKV4tIWUhq7Lbch810u2Frleu/old5S1cSQVlK6bdgtHcg9457pS/loRnN6sKCOfhfAy4I/H7wczufGLud0q9uwYvIyoFjapae+lueUF5VdB1iCnsMyUNDEnI5Et3SzbI+TRXesqWOn4cpVNR1DWtC+z2mviWSW30EQlGEpwxLgKG0yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=M+CorPqZ5Rgj/E7HLb5fue3wNMi97HXrFIPFf3cWV0A=; b=rwDTo2SZLWeHg8HnAEJRmzjvhOKleTkFDgGHuDX59OJJZ9qGz958PITykX9s+9wTXHpxSbh76MjPv7EPvd+JGUUP1r+mhTmyOThh8aoy1xtBB5YCGTwOmnQsCx/jLX+h9k56OLNX1kXzl6NFRyR56uolpPpxrNh4UfXXEyepiS2pNYmExrRmx5PELzURZ8Q3GCwt1BFul4+4OKK7PRTvJJk4MXIDssfAqm3EqAmTmZJGhHyEMajx15gS0KuTCl0O6RhAwKDZrCGAK9c2k8theC9rlvwMbFmCGvXg9cPrtAeNRrclt3Gknv75B2Up9Rzn/FufvKL4zqg9oRGUxIG+kA== Received: from PH7P221CA0064.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:328::18) by IA0PR12MB8349.namprd12.prod.outlook.com (2603:10b6:208:407::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.29; Sun, 28 Jul 2024 22:45:09 +0000 Received: from MWH0EPF000A672F.namprd04.prod.outlook.com (2603:10b6:510:328:cafe::72) by PH7P221CA0064.outlook.office365.com (2603:10b6:510:328::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A672F.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:03 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:02 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:01 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 2/9] iommu/arm-smmu-v3: Enforce arm_smmu_cmdq_build_sync_cmd Date: Sun, 28 Jul 2024 15:44:47 -0700 Message-ID: <176261860828f690958d93edf53569ca2505680c.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672F:EE_|IA0PR12MB8349:EE_ X-MS-Office365-Filtering-Correlation-Id: 836de568-628c-49fa-6583-08dcaf56eee7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: iEP1nUw6G8yXzQMT0pdPbuojGIMPmhZVs5K48QNxPr6iXNrjONLMReeRUnrEXXlO7MrFZvSMb3LA/ve/kc/QLHX+jVKOe2A4xDHxDJQodNnLyB6RvaxPXJHtEul1Aj20X30CgdthG0kXyHaOW9gFr4Dnep6OtjPJDO14idwrUlPDlEL0GnqPXPNIA26Pdg/T33xKaSsRgeQ3WYNnxPTejq5QVMwByIxFUSkGFAf3aNHr3FPScebuLk5s9LDlUC+CkQtYMA2gc4Csv9VBzul2rwND6tvnPGOWgdnlaO3d7ZzbzfG6YkdDf16h+6404aLuOMZLNWWAzSSClobjF3JGd+f9w/iNbAHEFMYre3oouoT9i0N3mIx2H2zWTI66R5pwQDLqBVth4xV2D4ABKh+4QJzgG44AK6H2s1/8DajzjU9Dli9QoGFLnltyH0HErkPDNXFT8DIOP3/QcsFtXzu3HCzPVZnKVE5WOgdV8RP2fNXKt2p6PEFJxAvRkjLrg0hs33SpiVfFEJnjw9YuQdGthitxp9oMu85gaLF7ALN8tAK8Z7PV2u4ZB6KlK3lSYgKHfc7mBLmkzQ6GsvkKofK3LYqdSl+DOqt/ZsmW81RJBEKBDDzyDcc1myogrtdanbhegZc59DlyFMjuyjSgD7E3Vsq66vRFpCe541HOATIb770QJR63HOe7l2kkrerr+3Uv5fLGdMszJOOtPNCVm3HE1naBeQDB8LkXyaVFE6IseAWOHkzDJbhgSYEj37IoB1kktCxJWO7FEIUWJFCX/b3k7uIB+GBYy7rBa2OhrID4zO6eYHjQFrW1ujTeyXMWOroOTgu+RFMm76S9XKbNjlx8eteaV6hg8yzKQHnT991Q+bSr1NPyEEVwJlP9oM9E3uw3WxReS+DMHCyF4n0Xo/IeR+RZzgpRohJPW/RHCKOgOlpL7MCj27aMvLEN+4l3M9ryrtJzCey/jgsGO0IV0m4YLJ1eaBcZ7B+MfMdRU4CbtOFqTpCkqsJCj9nN7HOblZPAq/q2zIit+zfmWV1O7RVm5MiccU5hSn+DNGlNx6Xw44rFc8OP3z6pclH9kk2yC13qY0dQxQqayrJ1gK39Gck+gyadZPEDAsS/G3fcpY22RKNFAu3fFrJjwqURKSju2fpN2UR2K+r+EZQr9IqOjIxT02RpiW8b1A9gkixNmH6PqWDbx6xKYVojMrnbs16FhuVy55jKO9d+5p4/RYKaGgqZpMnfzU2EG2B22qNxRAt9p0wWOYHBdGM6jqSM/QoyyS/auI5w405TLAlZRtSBw9gLwDWan0qmGe0+4bc2xuUoLqLH8Z29A6bJm3SDibXg97wT5BshxOAhsmcVmwCh/8DIxo7hzpbZkU0kbZz94msJ+4FfQWMy4uAWNJc35Nv4TAd5bWDbHwVJPPszDFYpjRYEv87akYu1Id+x3g85a0WyLcdLvjKiv/IcpfmK0cHggwYP X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:08.9176 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 836de568-628c-49fa-6583-08dcaf56eee7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A672F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8349 There is an existing arm_smmu_cmdq_build_sync_cmd() so the driver should call it at all places other than going through arm_smmu_cmdq_build_cmd() separately. This helps the following patch that adds a CS_NONE option. Note that this changes the type of CMD_SYNC in __arm_smmu_cmdq_skip_err, in ARM_SMMU_OPT_MSIPOLL=true case, from previously a non-MSI one to now an MSI one that is proven to still work using a hacking test: nvme: Adding to iommu group 10 nvme: --------hacking----------- arm-smmu-v3: unexpected global error reported (0x00000001), this could be serious arm-smmu-v3: CMDQ error (cons 0x01000022): Illegal command arm-smmu-v3: skipping command in error state: arm-smmu-v3: 0x0000000000000000 arm-smmu-v3: 0x0000000000000000 nvme: -------recovered---------- nvme nvme0: 72/0/0 default/read/poll queues nvme0n1: p1 p2 Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 36 ++++++++------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 -- 2 files changed, 13 insertions(+), 26 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 f409ead589ffc..f481d7be3d4ec 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -329,16 +329,6 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) cmd[0] |= FIELD_PREP(CMDQ_RESUME_0_RESP, ent->resume.resp); cmd[1] |= FIELD_PREP(CMDQ_RESUME_1_STAG, ent->resume.stag); break; - case CMDQ_OP_CMD_SYNC: - 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 { - cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_SEV); - } - cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSH, ARM_SMMU_SH_ISH); - cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSIATTR, ARM_SMMU_MEMATTR_OIWB); - break; default: return -ENOENT; } @@ -354,20 +344,23 @@ static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu) static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, struct arm_smmu_queue *q, u32 prod) { - struct arm_smmu_cmdq_ent ent = { - .opcode = CMDQ_OP_CMD_SYNC, - }; + cmd[1] = 0; + cmd[0] = FIELD_PREP(CMDQ_0_OP, CMDQ_OP_CMD_SYNC) | + FIELD_PREP(CMDQ_SYNC_0_MSH, ARM_SMMU_SH_ISH) | + FIELD_PREP(CMDQ_SYNC_0_MSIATTR, ARM_SMMU_MEMATTR_OIWB); + + if (!(smmu->options & ARM_SMMU_OPT_MSIPOLL)) { + cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_SEV); + return; + } /* * Beware that Hi16xx adds an extra 32 bits of goodness to its MSI * payload, so the write will zero the entire command on that platform. */ - if (smmu->options & ARM_SMMU_OPT_MSIPOLL) { - ent.sync.msiaddr = q->base_dma + Q_IDX(&q->llq, prod) * - q->ent_dwords * 8; - } - - arm_smmu_cmdq_build_cmd(cmd, &ent); + cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_IRQ); + cmd[1] |= (q->base_dma + Q_IDX(&q->llq, prod) * q->ent_dwords * 8) & + CMDQ_SYNC_1_MSIADDR_MASK; } static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, @@ -384,9 +377,6 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, u64 cmd[CMDQ_ENT_DWORDS]; u32 cons = readl_relaxed(q->cons_reg); u32 idx = FIELD_GET(CMDQ_CONS_ERR, cons); - struct arm_smmu_cmdq_ent cmd_sync = { - .opcode = CMDQ_OP_CMD_SYNC, - }; dev_err(smmu->dev, "CMDQ error (cons 0x%08x): %s\n", cons, idx < ARRAY_SIZE(cerror_str) ? cerror_str[idx] : "Unknown"); @@ -420,7 +410,7 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); /* Convert the erroneous command into a CMD_SYNC */ - arm_smmu_cmdq_build_cmd(cmd, &cmd_sync); + arm_smmu_cmdq_build_sync_cmd(cmd, smmu, q, cons); queue_write(Q_ENT(q, cons), cmd, q->ent_dwords); } 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 c1454e9758c48..6c5739f6b90f5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -518,9 +518,6 @@ struct arm_smmu_cmdq_ent { } resume; #define CMDQ_OP_CMD_SYNC 0x46 - struct { - u64 msiaddr; - } sync; }; }; From patchwork Sun Jul 28 22:44:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=qaN1Jd8B; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3110-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm23Y9Sz1ybY for ; Mon, 29 Jul 2024 08:45:22 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5E1691F21A45 for ; Sun, 28 Jul 2024 22:45:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF97D7E583; Sun, 28 Jul 2024 22:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="qaN1Jd8B" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2051.outbound.protection.outlook.com [40.107.95.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22F277D3FB; Sun, 28 Jul 2024 22:45:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206717; cv=fail; b=KGmY7oBAvLZfePTFZFwTNI6Uoga0kUk8iIpK6485FghayaC2PxX9ZqzKZ2DvvLHFn1GlJJteXmlkT2PYqfaQBAyWJvRDR3/ndLB56g7vb7D9JPAxw+ny6g1WsmbdQ9wP2KzKwM59uB9imkiNv5dZPPbRJ3ROaFU/c+0M8DUJcWY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206717; c=relaxed/simple; bh=1x7gkIHK3LnJuU2JwM5AT/xILlkni2pSP4aWlCRgfU8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SJsrTC34KsgyTG96wZ44ikfe0QE6U1zvxRZe4HYLB46zwIB4kHjq3rohpk1C4k6r6ZNfXNlByEGOo1Ki/2JK+s6bL1yFIfGA+rF37CYLO1664TM0sOi081lV0TOjrbkui1UAPII7ps55Ek6HypvlBODEEjLjb1sgHkkZaFmewdM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=qaN1Jd8B; arc=fail smtp.client-ip=40.107.95.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Oai3bUupdAQ0DS1NLDOiRv4JPKc8SpF2KUK8Ouk464+H09u2vbjIfoxhEF2ZRSnVzEBUbES8h1r4ecBKD2SlJPotKBmTvTFV3zoMQGsyyV8LG5X1QpT/JxwyD5NKlvxTj/+FRuHGScOflgD+iKVYc3L9+H6MAaJFB7gzinegKAoyDj65ezRjbKDlZFTFOYcIlIHQkWAH9noua8GQxkD3lbGGkdTEqGeGirZj45vh/6ogXPONtOqJiU+/3B7gPu4x1HV+Yo6beHcXjF68jGqxEIUkIQCWAojQsIBEP1J7BnjVByx7m+u8xLaiQjzJMUGdWRetXIY5aOlo7CzPLqH7ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=pb0uMIkIpQ+ja0981Lebu6N2+gBun1AKMN4dGSg67hU=; b=VQXZUiZRyjbYwkSB5lfCXVv9td82EPG9o5F6Q5LKHgLswaPTsw0DZawOIsdzCPtP631Kx8YCR4zo28FluGtSDodrhDX2OYR82P2ftEJWkNAPiKhT0SKTd2KZpHcL2F+KmkNfx5Jchvl+wyAvsmhw1vB0VoaYoJ3CAyaSljbq7ijNjirLyfNlfVYdaSKAM4oviAoZtP2Px9k82S86U6uOHhUGc6sIjbT9H7OZpqQsewng/mdt6Rzllty1qb/X2cc/0n5eyt/Cqt6yuKrLeoUlrp8eT2h2lXW6JZzbHEtoXaJg13ppMaubXklXgnRq+sZU18IES4NcH1DqrRyyzwjXPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=pb0uMIkIpQ+ja0981Lebu6N2+gBun1AKMN4dGSg67hU=; b=qaN1Jd8BIY1jJ0qHgUhnm6k4IPgIy47Dw1SQAxnrbqSDbgXakuL10+G8bQ2tksJzmKZi5LFJNg1dJIC+p0sUk/y+lrF6ZsVm0+k962DA/rCOzfNtvXaDjjKJuQujIfLM/VEFXHkovj/28Qz8DD6HVqpaD0rNDz/T5lLP63nVCMcEm7lDVm28GWnx9zGOCeKjifxsdVixIIrTZZ6jRUGpLGoBXOLFljiWIxZ8nEssKoK8SumnwFEMGx29Da6XN64rK1vv3C7ugugUIAj2vrp6BGZqemZ1BU4VqEchaxi+d/oiJiNjWz0+6Mz4W3dxbZ5N1LyLebm7NEa+3eRoyFlBiA== Received: from MW4PR03CA0095.namprd03.prod.outlook.com (2603:10b6:303:b7::10) by DS0PR12MB7510.namprd12.prod.outlook.com (2603:10b6:8:132::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Sun, 28 Jul 2024 22:45:13 +0000 Received: from MWH0EPF000A6731.namprd04.prod.outlook.com (2603:10b6:303:b7:cafe::a2) by MW4PR03CA0095.outlook.office365.com (2603:10b6:303:b7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A6731.mail.protection.outlook.com (10.167.249.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:13 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:04 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:04 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:03 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 3/9] iommu/arm-smmu-v3: Pass in cmdq pointer to arm_smmu_cmdq_build_sync_cmd Date: Sun, 28 Jul 2024 15:44:48 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A6731:EE_|DS0PR12MB7510:EE_ X-MS-Office365-Filtering-Correlation-Id: 2304aece-2ab9-4861-c1e4-08dcaf56f16d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: fdJpCxYZYJsbM9pSjsLPoiPnHdudgJBitZRibOYd4z/Dm0oMn7cB5AV5Szh0y92S34k9QwZwrXk1H8CqeFCo4CphGGj3agM7heUnerd53lFURLMIUyb3t2DWod63nEElpriOevfiOZdQgoQ3h5S1m4ifgQ09I6f2GRqnfSMBcLmp3QoNiKxKZf02BwJDI1oD37zE25H29w5kSYUJEjlJMP2GyXWsNG7zd3eUOIp49tZ83orF2YpbzPJOj8hgh7ucJD9MdMYuqHOXWnZupsRfAGwM/+a2yYqsNhtmE3OwkWspXGjKi3byYNntjXBjCSYRF4Fxf6+epQxgSJVsB0KG6GbjNIa1LoPPdB6xt2rOlCL8eLLqqPky7Uc9Zr0w+dnwOIMoBiJlw9Q7YCdD7oZtXT55NvFiVK1winLK6FmnVY42pVctY0APu0wLlRJBmOSdw9DPwufW69hQyDSX6Vz6kssN+KbhtWlVBw7MWNtnhl5KFJtiM0lIOonyocd2b1yhgG2oeLWSqx9uak1dUAVdVSdtmU/8+V1oUoefGlFzQJhZkgCQ1YP2bGx6owlQLvZGJ0P0cwzHJI+ypWH/Z8KzKM4qt4zJC7h98ssvCYYioFNyoqJBjEEDg+tg3Jv2AXxyp5hnp99KK3P11NYTN/QkTffP5olLYD6Wy14ttOcF6DiZHXSK6CCwqrnhQBHIC4D2df1dVa4fp8Q/ukJvvhELKatC1BOEJmfdFOIm1CRM2SBhhKAVJ4eNp2oXZkVcCyNcyhNfHCAlY4c/6VdTFH0jC3EZS18qdnyxCk8iQ/xpmIEHvq2HVacHSh/YGFiOAqU5ih57dfALIcXnB+aYZ2mOM3J0DVhD+pI02lfUk8Qh50W3MxvCE2FHPoE4LxFQMrBxtRQlaqml4veIZx8LvP2Nf9w4hBc+JdM50bdqgjJgqgWwbFgLGLxTmVjtW0I9w79TWH6uc/pVsvWR4asQedeyiISqPmwFtTcVnFQkiaNhZcO8s4MG72IrIV2N/zL8Zxmid9t8AmZjXKZ0rcQPCrHC8xeBSDu/IBwoInJ0W9ZJ4EQvURyHafQzQXusHxGvwPbxNe3IOMvTbDNOFKCF1KOyezAvYmbTQccD3LAYeXHPuQFz1AQXylzqVgCbzYavZuE5oe1Aearui3YcpSoTSDjR7x3oAjjmgRDfGGiFXUztMUGR8SwHYG08UDl1n8ypeMg4fxM+f0dXdBGczkgG9AoRDIvBEOyW1XpQ9HIUi/kOKT+6jGCkpTKo04ExwuAz/tTID3B90Kzg8eBNNshj4O7il1luUpLyWMq/B5O5iISwcXSwbQjKFDUUvEO7minn2ZtpEdHkIp4KO0Ae3kUwYrHjThkP0PI6p5tCEgZ7u+W5A/0dOXN+XCQldMODEMM6Irznfcv8hkAqiue9LxYc9aCYNuLfRoexFn0Q3nWitw3VOZ9dlgixo2YBBPB49iTJ48nh X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:13.1380 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2304aece-2ab9-4861-c1e4-08dcaf56f16d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A6731.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7510 The CMDQV extension on NVIDIA Tegra241 SoC only supports CS_NONE in the CS field of CMD_SYNC, v.s. standard SMMU CMDQ. Pass in the cmdq pointer directly, so the function can identify a different cmdq implementation. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 f481d7be3d4ec..d11362e9fc8a0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -342,8 +342,10 @@ static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu) } static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, - struct arm_smmu_queue *q, u32 prod) + struct arm_smmu_cmdq *cmdq, u32 prod) { + struct arm_smmu_queue *q = &cmdq->q; + cmd[1] = 0; cmd[0] = FIELD_PREP(CMDQ_0_OP, CMDQ_OP_CMD_SYNC) | FIELD_PREP(CMDQ_SYNC_0_MSH, ARM_SMMU_SH_ISH) | @@ -364,7 +366,7 @@ static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, } static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, - struct arm_smmu_queue *q) + struct arm_smmu_cmdq *cmdq) { static const char * const cerror_str[] = { [CMDQ_ERR_CERROR_NONE_IDX] = "No error", @@ -372,6 +374,7 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, [CMDQ_ERR_CERROR_ABT_IDX] = "Abort on command fetch", [CMDQ_ERR_CERROR_ATC_INV_IDX] = "ATC invalidate timeout", }; + struct arm_smmu_queue *q = &cmdq->q; int i; u64 cmd[CMDQ_ENT_DWORDS]; @@ -410,14 +413,14 @@ static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); /* Convert the erroneous command into a CMD_SYNC */ - arm_smmu_cmdq_build_sync_cmd(cmd, smmu, q, cons); + arm_smmu_cmdq_build_sync_cmd(cmd, smmu, cmdq, cons); queue_write(Q_ENT(q, cons), cmd, q->ent_dwords); } 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, &smmu->cmdq); } /* @@ -780,7 +783,7 @@ static int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, arm_smmu_cmdq_write_entries(cmdq, cmds, llq.prod, n); if (sync) { prod = queue_inc_prod_n(&llq, n); - arm_smmu_cmdq_build_sync_cmd(cmd_sync, smmu, &cmdq->q, prod); + arm_smmu_cmdq_build_sync_cmd(cmd_sync, smmu, cmdq, prod); queue_write(Q_ENT(&cmdq->q, prod), cmd_sync, CMDQ_ENT_DWORDS); /* From patchwork Sun Jul 28 22:44:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=qf5Z3pI4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3112-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm35TxKz1ybY for ; Mon, 29 Jul 2024 08:45:23 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CCA291C210ED for ; Sun, 28 Jul 2024 22:45:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AB6480617; Sun, 28 Jul 2024 22:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="qf5Z3pI4" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2087.outbound.protection.outlook.com [40.107.220.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D30A7E0F0; Sun, 28 Jul 2024 22:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206721; cv=fail; b=UZLlafnzqN9ALkS/40dXdUMkb1eZk9ZhYvtRCUZFPlkN4Ks3UEnnEcgYw3JEunF/BR2MlHtzrQCNEyABuCBb6boLz6kPUOxjZn3BrZdgDpDkHUu/pWxxHYTJi0G1VBIjjCmUbXHGVnrU7KhG++pHPjuY8d84O1XWJpAarHZk538= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206721; c=relaxed/simple; bh=avvyZA8d9DZfXEroETBuInY9Zi88oDGG0ufA94gzFQQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wkoj8grRvULn/PazgDd/qTk+XoNhRranX2/Y8v0o90b5ixypxRa0xTfagWVyZPc3pKC0x83mbSjPKG7ug2rtt2aO8HVdcACzQRVplgRPYWYi2nQqHJhs/0b+weh1GkkLXWqfhXX+aqQjA9XOd3TI8ff13UKWZ+wEDoGyL1gbP3Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=qf5Z3pI4; arc=fail smtp.client-ip=40.107.220.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eLUvrfGYQw5isPijJqw2IpiLfXCmvajJgCNDf45eGtnvD7RhYoPuBH8iKgAngWBilYNHL4g8SXT3in02gdXRtDL9hDSf9Vne8rF1kfTSSZxj39f6Jigxavuacg/kCL2SMpZsk/tpQt5R5w2C/3WSCdVxvdT/ocA8av+WjYFyi+UkruSEWzliD7RvXXVt+HIVlrLg+2lTxtPwmRhnbnFArGs8uImqOve7kBGe3dSrWT/+wW7KPl5eLdYmup32LwpuF6ERnK9jH2e09vqEwxfZwsGkXB1Qr7RMKUyrD2igh2cmuReXhM9yQ+LcaaWoC22Poz6a22x4b7BlVbVPPbuzWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=cI/OiTdXtgsi6NNmf2ubMy0NEsjWKNJmXMhqXXxmHfo=; b=go8Lhe5KYViU1IF1EhjyxtZ/IgTeHvXD7iDXGrJ9f+VYxmbn7M2KYHw+xbZDe96taBMRxL8lPpVSwLPghYSMa0KXr191o4hs/BX2G6NSCRCGnTAvV8u8tvTOcJPPl6cnf8DBqPo1GT6GlaDzmPwKMdxyTDm55Yq+J9UNDAShLotnzPHLaKm+M+FwuAQHuL8WndoMQazfCPAbTVYwzCppCFEGhy7SI8GeAmYYbzPD+JF6kCJ/YQSRnNRhKhnVmP9Drhf0kCFqqdodBm+WtmAr5rYOOMv2Qw3R+WbgOfHT8Xs1R2VZWJ6L1NmsbyVw/vUww7SOY/FRXu6eC7TV+XGXVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=cI/OiTdXtgsi6NNmf2ubMy0NEsjWKNJmXMhqXXxmHfo=; b=qf5Z3pI4RxrBOKWQ4IIbRitPexIZOR+7gU0bywV2aB2C8U4Uyq81W+DpMfqdK4q5oegbQaczAdA9ZYRbodNCoLriE6XtdcxrqWHXumvi4qLdG0YX/+cZGhiqKUO3kXWWsH619qp5CK/2r5L5HXYB+yqr7B3eJUVMvqff+6rGRChiP4UzNbop7WzoyIDHDgm44cAXHphiwS2udpP6G6XoGH94awpLAUfTYjW4le6crQ1BwePh49mNhMo7MdLyT65YyRbFxarPfjEbtGZ2KpJnInQMx4D9jz2izuPdthCwYU3AC5DecU47K75mdecJ+vm6/i3WOLX72syR4M4s9iPdPA== Received: from MW4PR03CA0127.namprd03.prod.outlook.com (2603:10b6:303:8c::12) by MN2PR12MB4319.namprd12.prod.outlook.com (2603:10b6:208:1dc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Sun, 28 Jul 2024 22:45:16 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:303:8c:cafe::73) by MW4PR03CA0127.outlook.office365.com (2603:10b6:303:8c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:15 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:05 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:05 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:04 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 4/9] iommu/arm-smmu-v3: Pass in cmdq pointer to arm_smmu_cmdq_init Date: Sun, 28 Jul 2024 15:44:49 -0700 Message-ID: <01498fee0d3c3ffba7a53e46463671584fa3193e.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672E:EE_|MN2PR12MB4319:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f859b3b-027e-41b0-e159-08dcaf56f301 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: qzelv20fQskrkNFG5O7QWUMc12JNHwOVVP1ly1gwG2nOQA8F5i8FRTtzQanM/7terYoQgyd8Duu+EryoA9yGVUdGTbpqr7CqzDdWJGHraPSwX8f/ls2CL4buef0rQPvbIhwdfiPPm+k5PUoM3bEM/ifIiZFmRjvbX22fCBwBP00+tZxovDP+5X6cfYcbGALbE67hCYVN03DpDf8eBsqRly+4lYvINQIR+iFWWe7BRmykLvldeOn6J8LxoRxqgVwjZwHDeuJwjoYZG1D8D4L8G5jVy3pFSJVa9j7vE4DqOSayvRy98PM20DWW8kjWs6rlJOzkV9sUOZr/AZIuGhcpQ/AoviuqMJyxnpO9VfAYnq59k+CCgvNb4jxYPShujeU+647aks1jxq0Yw89o4OR631JsIXp88Mf3IKzTsh71MNYTTgm6kKSgrU3a8AvgBdOoqeUF1kRoshki/anhFN7O/Fmcq45o4JPe+w1brpP0va9OM8/dUaUSVktgXV/KAgFvy1cvjDWJoc0d60aq0AprZ/AQ7X9FbmQFz6O33xoX/6p5o5B9ACcQzRPWscK4oIIIr62htT9UzOiUOG0S0ACspxBA8vQZuGF02q8TVyoTzdDDQNHCaI/ZHi9+V6Pvh0dU+UDOKPgBXzHNnBAhdEF1dqzwdhVFUeBHL9ztrWEe72IdP990lU1s5pR8Lj5+2BOVobybnO7k6a19MQIWvLOFsgQh7uureuLTKoLk3j0FseF3R7Rq5cre75D5CY/pqK3ArfJyg27KMPJgDVi6KE3DiAQIGwKjAfPZF3ckxho/Uyz6PIQe5Lya/Gft/3Vsrv04aBUv1Hqak3tuxGSratd/Af5weyOs1/xjVyEWFXkwSbekEXh0FmMp0KBAcmf2F5EUWtf0fAs98NBFjxf2f35jYj7lBeoQxsN/38Ai72N2ta+T9qEFxvulJQYPpdHPZjUIPRI+d/usbzRHoy5rUvbB/SELOenmcgkeJBzKQb/mRMqNIU+XhFJFP8B2Znec7RbbMhe7kl6Z+lp3lvYpwSVok0vqg4SCu6ZzAUnsuxP1NmnC0j280onKeYN7bewfsmiMhIKDCrwFrx6kL3PM3F/2ZyNOi4GXARypLZV5BGAx8xI+XfHVr1gGKENsHYhBXryBNvY8c7b3rLwYcDvrNbniLfQI71/mp/wI5YHvWU2i/+GkUsOtUqKLYwHwJm1kH0zgtGW/nU8wxCjwFHiD8c+Qzp1xdNAcy5LND9tUrvQG4tNj9zV7AUVQzFqvG1vVwuQNmudOcGgfmzGblh6zrJnMURW3FGBo+qKU7eJaqqb7D2MlYxu1C5lyQoUoVePJXq7GbbG6Bb+QkVOmdtT2/g3TPse5Y+M5gTjJhMUxBaEIq6TrSy1+xECZ6H2JdA3wGaXPy7ekjP3KR7vbuGpHM3eCPlK18GFuWUWwJyzNMtL6lTcFEgy6tsGhJ/EELz+cANci X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:15.7865 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f859b3b-027e-41b0-e159-08dcaf56f301 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4319 So that this function can be used by other cmdqs than &smmu->cmdq only. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 +++--- 1 file changed, 3 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 d11362e9fc8a0..e664c40b14aee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3555,9 +3555,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) +static 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); @@ -3582,7 +3582,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; From patchwork Sun Jul 28 22:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=OQl1fZ9p; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3111-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm30wNzz1yf4 for ; Mon, 29 Jul 2024 08:45:23 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C6CD01C21201 for ; Sun, 28 Jul 2024 22:45:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B2A67FBAC; Sun, 28 Jul 2024 22:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="OQl1fZ9p" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2069.outbound.protection.outlook.com [40.107.93.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 462B27E575; Sun, 28 Jul 2024 22:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206719; cv=fail; b=YVVv5gZFY9SOTYCIJrenLYWyYtivzxrJtOHwqSohS+foJ6iMkfMGFCDbKbMolfvLhjahm11N7ualv9kitp++UkVbPB9+D4m/325TOuCoGgLAX1PZIv+k5dHOhxtJUI3arjNhNOp+v+b6nSx/dMKliRjD/W9uoBQaW81seFGmWTk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206719; c=relaxed/simple; bh=dsAHJUbsGTPuiKCW7n7YR4iCllYos119LtCwFV/7rTQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bE/DW7YbvLUL1K5GV5MFc3Bw0rCF2H4Iq84tGGbcng4P8rfhtTl7Dcn0dvS69PUB6cexgHEPcsKPCpTH+jQ5W+BgA+AaTtnUNMh8gug9UPsbMMUQ8Js9DGQhzSpu+BIhINILuoYZ9U8dW0wisdmAIP1A9fLL1qKDXiLuqjHI55I= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=OQl1fZ9p; arc=fail smtp.client-ip=40.107.93.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BQyxpGivdkkff0JFkjV/dm8cu/m9UmbEhp3qiVoti3e0Jr5MYx8LG3/S0J/OlnWaPq9f9uIxeI8Pnh298E1+3ymJYbTYkPbycpMoPzK1sUlGMl9XHHYD9vJc8qK/w0L3IsQSkqON4WpO1O32Gei6pEitKiP7MjpEF+hTKzlWS0F7CUjnb21pjinOuNcTkSs1Nm5dbO2hmF/eNwuBsGl0nwbFA1UGw5wCohAW3EgX6u3Allam3z4HBoFHwiUQTBKOXXnbek8isRfJIqO+hyF3Y1mvJxBzDSS8ZgZbi8+xdt/EUdj9BaMjnqGB/alXwHCxSYLjpr4eRYmVPLU0bFSF5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=41SMbmXA1PL2XA4MRC3xrC1ZAH6GVqfqgvwuMEyz9rQ=; b=dD5tfNszxLV3fSRTtEAZtS9484jagSBL3l3TbRbP28Ljz0qP7hqesSMYs/9aJnRKi9wjfUiTfnDYKE3TleDzr2y4NP8E1gVVaUbxf6se2ReFQqNYck5u7NNQgZ7ShrYc+rZHjqsdDvZqlM+bh9TVKzo06pE9RGy0w9qL6l/dfPLtYB4XNSux0CEILfO9mTvMA41jYKxNbX7CPzp/WJ0XZbVxuDfrRaYf9uCaej+kP3HDlKO0i3nCfsg0MjWu8EC8pHnTc+r7fFCklHRhxnwlMacw/fs1XqPa4Jdpxqhir795cV1WSh0BHtRUtoehK0e/3v4XW/lZ3W3yBe9aSfkYGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=41SMbmXA1PL2XA4MRC3xrC1ZAH6GVqfqgvwuMEyz9rQ=; b=OQl1fZ9pNTRhU/mvTJQAQw30csmZTd1Tx0C9OllOMbUEvnP9zrKMZQoBvuFBVmy5oNbHPdVTVTzrsbNNArvjWWSjXaptX6GXoQtyi9QHptbbRsgcShVjopIKWMpGIsu/0aqu6DHi0edpG1eVMbcCJTMKmi74xYyUAInf6csl4AZ2sfKazNdyCMWgy6/IfUIJ50VUlVyzRQjo7GOx+kyB6B54r8Itjv++LR7087Mtz1v9gdgugN/IegGxmePzIvPZlD4rlUB5yMgAps3+tfFO5cbteXXdB1rjfgj5ghXroQyUbBKy0t/VdG2QUabk2xqEbee7s+T0jdI+5JtAYWAr5Q== Received: from BL1PR13CA0189.namprd13.prod.outlook.com (2603:10b6:208:2be::14) by SA1PR12MB8162.namprd12.prod.outlook.com (2603:10b6:806:33a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.26; Sun, 28 Jul 2024 22:45:14 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:208:2be:cafe::26) by BL1PR13CA0189.outlook.office365.com (2603:10b6:208:2be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.14 via Frontend Transport; Sun, 28 Jul 2024 22:45:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:13 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:07 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:06 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:05 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 5/9] iommu/arm-smmu-v3: Make symbols public for CONFIG_TEGRA241_CMDQV Date: Sun, 28 Jul 2024 15:44:50 -0700 Message-ID: <294090fe478aa8beac1f3de741d828c8e63e0522.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B372:EE_|SA1PR12MB8162:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f05b073-d8d5-48a6-c83a-08dcaf56f1c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: hHvk4VtN04tCsxdq9WpY7x26qchYOVg6ritaUwqYVIKoRW9Hk1XR2wCsBidl3hLP9j6Uqa5g6sahkshQKbAOTEAz2LDb/PRRBOaox8zNHKked92/ILUsHVV7qj4zzfzK5tRAQDP3lFagAhATH1AUhwtNOqAqy7Eh1joBmPfr0VXnI5wzOnl69fq9cK23717jawfS8RUseF9hPrG3u0db8/OadBKmG++HJ0Jux7TStLWIbp/mn69j8NtiiQCwBYzNpvKez+BwripmefDd+QAjEpL5+4HT3knpMV7cuLlCa6UdNFfdFF/DrfLr+o/JQ/7ZWSkMlY9foUT1EhvdXxXQLGZidA0GflBoYkn2sQQXwzwdklvjXfPPT8SiH9USj1pExefszBW0SSfZH1yVjxBQTRI3k+YHMvoFdr0aDvFWbW+ljJSADRMDDBZGlmlWV+do0euAmaJauMOUZEkZN2LfwX4uO/rAPFTQsHU8HDYncuuMd4dDAJos2tJrn5SZPo/ekW77pLUsUf6bfFz7HjFtkWOLEaemmyB5jn5q1Z5x54Q1NtJdimwUcrARU57SrsNayhUB1xj7xpntydoCbUXM+omKPqFFX+YJgWykmq+KYsqGFQImXkL6Jn7rq3WIZSPHtEa++Y7LBDvIxhrgUI9vL4Gub5PNP9wfNlBwtWg0Zks/JSvJCFLd/R97sGh81gu9zvxmks4JmOaL6mZXpFOBAOSSnnoJYgc7xFGEyP5Av/ykImABOoWC+D0Bq8OusbfEPKE7QxFTQz1Jxi7NkF6pwtWq+G437jg1c1wJwm7uqAcsYJg9iAolzHBIuBC0ElAHEbH6doE3+cOqkwtcJzpI0ntWok2bHikvYzAGEvH1sKoKpMCwWQojY2cfr+f+mqIdUVnWZCOamLtlABKrz1Tv6yFWTgwB6PBwYkKp4egevSSnUu8YnhYzIOFM6Dk9VT10ktIBv2SwQalv+TWrX/DKIuDNyxiy3aDSrP8ZKdYoXYT5nc9ufPeyPIOLCki70QWdUS55h/nf14NsRUncN/PsN0R1lKQaBlwVP/nVd/gdvYSC0C1lmMbiRJ3PJQfSgjeIU6nYQPi04bJh1agFEv/iaAWiec594Rrj7wf5DotftrByx3u9lURuIh1TSF8jlrqFSFv8269lEV1Infx0n3xUAiW8i2cbKyMXUkg+JaCpF59P76F/Fbe1Ts9Qo7kMgEY6CzGemBLjsGpxiUVMwbNHRu6SqMvbu/R2yWPiZIPcMOG4+EU6FN8m/D0MSI8e+q1oMpBcjUzn576E5LA7e70N7XGmqYHAqwLoMIQmExxGYeT8F1s197FOVOhdF/p6XO7hYhAGFk0APsNCosUcaardzXbAG7Mpvoo+Hqn1sX8ssK9OSDAO/8op+OZ/nUwzmB0yjqO8gWNduytz2rkCz3knyA== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:13.6252 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f05b073-d8d5-48a6-c83a-08dcaf56f1c8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8162 The symbols __arm_smmu_cmdq_skip_err(), arm_smmu_init_one_queue(), and arm_smmu_cmdq_init() need to be used by the tegra241-cmdqv compilation unit in a following patch. Remove the static and put prototypes in the header. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 18 ++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 +++++++++ 2 files changed, 17 insertions(+), 10 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 e664c40b14aee..df11490958606 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -365,8 +365,8 @@ static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, CMDQ_SYNC_1_MSIADDR_MASK; } -static void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq *cmdq) +void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq) { static const char * const cerror_str[] = { [CMDQ_ERR_CERROR_NONE_IDX] = "No error", @@ -3512,12 +3512,10 @@ static struct iommu_dirty_ops arm_smmu_dirty_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; @@ -3555,8 +3553,8 @@ 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, - struct arm_smmu_cmdq *cmdq) +int arm_smmu_cmdq_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq) { unsigned int nents = 1 << cmdq->q.llq.max_n_shift; 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 6c5739f6b90f5..6c5dc2f10a330 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -813,6 +813,15 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, unsigned long iova, size_t size); +void __arm_smmu_cmdq_skip_err(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); +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 Sun Jul 28 22:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=HnZ2MfL2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3113-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm729mMz1ybY for ; Mon, 29 Jul 2024 08:45:27 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 808AF1C212BE for ; Sun, 28 Jul 2024 22:45:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCAA976056; Sun, 28 Jul 2024 22:45:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="HnZ2MfL2" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2059.outbound.protection.outlook.com [40.107.95.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE31E7B3F3; Sun, 28 Jul 2024 22:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206724; cv=fail; b=SrndpKxc/KPVdWpIgX8YCOAuVHi8t35xmEcbsY6e4QBuD3MFkBd2sUQnpE4bIXM2iQYOssTZqs+J41vzWpzO8NW0VhW1+s6ynGRerLc2Oke31DaLTlcVipVpV4sbToW/Bi/KhNE+45fGIzdDx0BbqkjvM3/G2EL0zz7Z6iSd0t8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206724; c=relaxed/simple; bh=hiAI0WgtgYqigGFXj8P6PtDw3hUYC7coDdrHRKzo+mM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a4weiCXBjoFZFGhupPxnTHVvzgpmHyX3oD1A4kFgF9s/qQ387xQiTDjJ0ve/2EMEtWybuA+Asrq18PpSOmHAyNvJXm+pFrL2gEnYKUvQAEYX2AErX3NbJJ2jssK+41cJI27ZzUJTPRAndgQOCoVfoDOd0JoGgmRyN8sRYMQRM6w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=HnZ2MfL2; arc=fail smtp.client-ip=40.107.95.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w6O0tFAMKqbZoaK7UStVy1fi81x8zqU9uWqm3V/Uvn1o+E4f/atu/IIvIvaJMa1djeU30AuK0OgktvLHREXha6NYtlLl6PAWabpfuJO9cWs2em5g1ok4eaf9DBGEa9aolDP/JRdhl9SLm73uuQZoGwTiSy7YATJci+c1/sWUJ93d7bzHLH0jw13bTQ3BSffh+Id00m/FBS1pBi3mSzvop/UhvKMmTa2lWdNH2TfbyfstmXAbre3z0posvS9cE+7otxRMGjMNruT+iUB+rfIPpMl9cvYwDJXRsRWd2C//Ra+ttxnfmIRbONO7eR2cVJ207pkaWrXt3sa77aVN3Ox0tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=0lX330gpONN9VLSnuGmr1Xpjw47SVCwsTiFk7BWjFqk=; b=d26O9u0DVW+WDElBRrMw/NjD0x5Yl5qWB/7Lxkrjen5NLxAdXA1YjZIv2D9BktVlB1nQ080uBHAtSQB757YHgDl1niukHjzW0hFtGIpqTcC/jeOntXgbiY1aICDvm7BfCWNougg9wDAJYAN8oxogUJy4Ebu0ct8/T+xtv+Ac36/e0JCmztiQP6nyyUnqhwE0j2oZHdgB9koGc647PE51qyxQbWeS7m5ib11z18eufuHeTDEE+23pOJvwUHGqPmAY/v/IekO2qlT8JxEgX/zH2eppzNlOXZzAhNBN6a8Z8+ukR4VEbUm2sGQNsZRghercMl5jDv/28SI5cJHHZ0ElDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=0lX330gpONN9VLSnuGmr1Xpjw47SVCwsTiFk7BWjFqk=; b=HnZ2MfL2Qrts5+t99O0H8rGkCyWgq05iUMyFGxzDCEHEfJcE/au4Q+6qbsoaeqq1LU1nsm67FHLS5c2mcgoEk1f5EkFtqWIsrzGSgeYw3+LU2aYeHl2xvX9uUWs8mfg0Q6kgmZ/Ptmp6IOjbcCoZLt/wRPYgFuEKL0dgSN9/HMrQTfK81EhQK78ro+w4+NbI8wIUsmJ+TOk4uw5MleqCnD+W72inox+76SHPIAH7sKiHNRkjlsC+kYbMFW8NwzPQxtE2GHb3rWWT/zzGRDYezKHTu+s5XmtPHpI+Jc5iOwRycwa/xD3ScPVAMa8hAFVpn+oU/ogy1mEjAAhpBM4v7Q== Received: from MW4PR03CA0126.namprd03.prod.outlook.com (2603:10b6:303:8c::11) by MW4PR12MB6874.namprd12.prod.outlook.com (2603:10b6:303:20b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.26; Sun, 28 Jul 2024 22:45:20 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:303:8c:cafe::2d) by MW4PR03CA0126.outlook.office365.com (2603:10b6:303:8c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:19 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:08 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:07 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:07 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 6/9] iommu/arm-smmu-v3: Add ARM_SMMU_OPT_SECONDARY_CMDQ_CS_NONE_ONLY Date: Sun, 28 Jul 2024 15:44:51 -0700 Message-ID: <433068cfde6748f3e51aaddfa0ced9be97b0a5c5.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672E:EE_|MW4PR12MB6874:EE_ X-MS-Office365-Filtering-Correlation-Id: b6a5712c-7ff9-431a-ecba-08dcaf56f574 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: aJa0wDd25pGgxyx+FCWUCm7hAgFSjmJhPLKLdG7jpvP4oZ1UN2UbkO3dmybXeZhPc4jaMQM4acys2mLw06eqIb76fXtX6jhqbz38wtSZWtJBALXU+8yECUePY8/Z7vhtlrDetaU42S0shlnqyDasg5IUe4h9M8rylfxO9rBurMpyMRke3zbW32zcE5G24OCn9PBDpAoDtTsKWQAZKchMGdyI9pgYyrqgqZAvzXDuHPSp2t8dy+ILKzLwU6jUtg6qqoDxeEq66sPb0Ku2Yf9MztLQlw9DulMTzSa4tDoRCKBgsQoBhIC0FBEeBcGqdTcD7aLeRxI5DqbXkEcDkTscwYyBWxSI1P0kZf+g8607A97cOBVHTs7tZF5ZYpdGoqcEXQOUKzwYvgBAhkVLLkB2tGPEEnAGFHc4M+YqqxU+gj/x3Q8pghCTLe8nAnLp20jcDowlwKukRjULhjoEG62xs+OUB0E/PPGxgeEPPcHvPbqIindmg952itID91rugMxiXzVYenrrpQZ3nyIijOQ1cZPZEySpcPsQDdoyqgn+NHzJN4uvNUljOIowbZY8kSHBI7Uj6LAZfUBdsPdvN8FgWJM/CQWx/q7YJcVZZt6EnStfEmb+rKeo+7X226bdlO91OMPOHRljF3qP+or6ZUz4N3wEPb68squ2s1qu7sOXkGXFK6FQpzYsgOyy6vLsJmErtaKRktqh/nw/w2xW6LaV13MP4jJ6BlkZaH3QkxjVSN4jEx/z361Ht9hK5n2tZfykk4/DojgjuwVd8obAAKIG+ZrCQs0d0vKzg7HCkaeI4JGsun8Vi96HcCR+/qhuv0fuuBkUsqNgCOThFXr/hzoNBg9DM2KSu9IVLauK4j/WlM6jMBKmHDYtTkEisJBxafIiwjb384WevFTjcZRQBFlQulnQwtVL5+kb2kgLxXhs2/tjmVPZ6lp8k2K4U+Hby8syOfDgt+j3ZmktrCpj6reXRw1q3wcT99h4QqAlOtw/ZYf7csmNY/Q+1oPTLoJiVl5Je8RidSUAROyBbdwYHuIMWGQTcT7BD+jsPdljSYHLB3gljPI4jf9mtaVK4b0/NQibvn0BlNP0X86i/mBCW+gS89U3bpd1/5zpSfM20phbuCCvKPCheqnrIIah9LTYfdnjZcabMWejS2QmeYwDOiOfQ6F7j6GT3V1PSQiMEm9q2nO6wdo21LOGYlOXZz7m5vZcmbgg0yO8vPKzgfiLIxil+3M3Sp9jNihcrImAzElsAdHB4RomFYQFDS4pUUguA+yujMuBYBxpCvBoSNDCEBqKticwz5vbZJuUqFunfQyKEH34Pglf/x1EACBPziYHrBrqOhMIEGsfX41DgGaIm9n9PI4ez/F3CvasLLPxt//ACgfzpPdSLVWZVdlhL0UnjLaYdJHFAGVqfXoxzTeNOHaCFHnI9Ai8Z2Pyp1ahrLR24ZeMRtbjiXsR3H9U51JXyvrc X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:19.9115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6a5712c-7ff9-431a-ecba-08dcaf56f574 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6874 The CMDQV extension in NVIDIA Tegra241 SoC only supports CS_NONE in the CS field of CMD_SYNC. Add a new SMMU option to accommodate that. Suggested-by: Will Deacon Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 17 ++++++++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 +++++---- 2 files changed, 21 insertions(+), 5 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 df11490958606..e764236a92166 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -341,6 +341,15 @@ static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu) return &smmu->cmdq; } +static bool arm_smmu_cmdq_needs_busy_polling(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq *cmdq) +{ + if (cmdq == &smmu->cmdq) + return false; + + return smmu->options & ARM_SMMU_OPT_SECONDARY_CMDQ_CS_NONE_ONLY; +} + static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq, u32 prod) { @@ -351,6 +360,11 @@ static void arm_smmu_cmdq_build_sync_cmd(u64 *cmd, struct arm_smmu_device *smmu, FIELD_PREP(CMDQ_SYNC_0_MSH, ARM_SMMU_SH_ISH) | FIELD_PREP(CMDQ_SYNC_0_MSIATTR, ARM_SMMU_MEMATTR_OIWB); + if (arm_smmu_cmdq_needs_busy_polling(smmu, cmdq)) { + cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_NONE); + return; + } + if (!(smmu->options & ARM_SMMU_OPT_MSIPOLL)) { cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_SEV); return; @@ -697,7 +711,8 @@ 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) + if (smmu->options & ARM_SMMU_OPT_MSIPOLL && + !arm_smmu_cmdq_needs_busy_polling(smmu, cmdq)) return __arm_smmu_cmdq_poll_until_msi(smmu, cmdq, llq); return __arm_smmu_cmdq_poll_until_consumed(smmu, cmdq, 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 6c5dc2f10a330..71818f5860364 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -658,10 +658,11 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_HD (1 << 22) u32 features; -#define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) -#define ARM_SMMU_OPT_PAGE0_REGS_ONLY (1 << 1) -#define ARM_SMMU_OPT_MSIPOLL (1 << 2) -#define ARM_SMMU_OPT_CMDQ_FORCE_SYNC (1 << 3) +#define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) +#define ARM_SMMU_OPT_PAGE0_REGS_ONLY (1 << 1) +#define ARM_SMMU_OPT_MSIPOLL (1 << 2) +#define ARM_SMMU_OPT_CMDQ_FORCE_SYNC (1 << 3) +#define ARM_SMMU_OPT_SECONDARY_CMDQ_CS_NONE_ONLY (1 << 4) u32 options; struct arm_smmu_cmdq cmdq; From patchwork Sun Jul 28 22:44:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=KhcRnIe/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3115-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGmB3zCWz1ybY for ; Mon, 29 Jul 2024 08:45:30 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 77672B20F93 for ; Sun, 28 Jul 2024 22:45:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D43DE79B96; Sun, 28 Jul 2024 22:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="KhcRnIe/" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24D0781AB6; Sun, 28 Jul 2024 22:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206727; cv=fail; b=eUWpMijDM9W79Epop4UV72BY9dl/3ldu1GzgJqlaSGigy7ziOjXMUpEV5ylHcCP73JgvpftmNJIP2yV9D71n5IdI5q27L2n3greQNSr1w5gOB9Co3sHRd96P7DCaNen++amg+tS0VJx4vxH6GEHbl33NOic2YjSe0oTmdn4JB8I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206727; c=relaxed/simple; bh=En3a8Osk8GgAJ3Mr6l/DVLt4N7ToChSxlINtSb4iqpc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sHvm6hbLJ52454cNzFLIt6RAg1ylf3mYHqDVN1haagZudutPJEItONB1HgKvGCmpqTyy3Lq5IWSQJW2W/v43Ru6w/aNh/YF9KMGbBXG3dhqwn3vJ1YCdW2AaqkBkZOnbRAwnXnqQupIiG/qfzhWOi8sldYhraMBKPtm7zHmP9GQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=KhcRnIe/; arc=fail smtp.client-ip=40.107.237.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=el9M2s1qPS2MJJqX0ceKCRLji0UIM9d5flCIq+8005pMFKIGXCUOmY5Misek/UDxEbFReSsFkV9/uI0wmpNqKIqcckGaPdSJPR/JgSQ4e7Oo9QkUWx0DS6LhzBuO++KPjsM9OrsXnXSsd8E8yvbYRXQZ76x43N9ogAD2PRSmz8RQ90oB5TxbyjTgJl+ox3RUdKF74t6ug1aYCJ+ux7yzFdItRetS77jKEKvCU3fNSAemEO1QftUS0s5JL964yoq18GBvZH/3FTbdVhKxt2AFlesVtcOVAj8jiUh2BzSBVYrZS7caS94/DC+UklmWagl2FhnXKNCl6jfUhi7Hhi24+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=+1DysAuwBylhHD4G5WD3grReAAbyn9//uozGOk5p3sA=; b=oVJNvyUhx4BMdYMB1AxQq0gPGVXTYHzn5lFF3BtP1Q07wMdMv8qkJsym0DQQT1FhZzsQ/0P/477X+RoaSLcqb+79uAD9+k/NgFF8x0jRou3Vrqqqh6DMJ294AHW7Dk9syA9UGHnYOF2B5m9HbBq3HW3JMVo1RqOXw9lptkqqKI3Qa0NC2v5RkqKrE25RJzqKpvrt7zXMBrasmQOgdBGsD0piwHkedRqdyJIdRO+vEzx2Vci61ErNhxF8bS1YVaECb+TPD9f5yaN0KhtJVwfsKYaDtuqtnzT6gTU228uR4pDFwu8EVBkL2PKXEB5gKC4kj57XXx88GTjPhjFi1YrqJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=+1DysAuwBylhHD4G5WD3grReAAbyn9//uozGOk5p3sA=; b=KhcRnIe/vV/rmlX6KsZpvmNulipqornQHLhNVjrwQlcZk2d0GpJ6ELzfAvfrtKa9Ucre5b/lB5khqBL4FQAxS7PA3+Ew6UMPqMMTyiPN0Mrfpbr6PYzoyf/uyp52BF43QezJadlsxlT5gkQdWv/Kds+KZ/tmD5gmQ4EZYr0+V6bRWhWdugR5I3tVJNf6qbnpoQN3WhsUexUptYxbsQl/QAtT/txG93fvHADVn7rVesM3l3vu2euXwd+bgwkDSlvicpAIvAOutXKCD66ULY1Rz0t80gkJEXbwivrB8la1msWahL9l3EhlBB/sI78WtWc4SSgpkC0UvOQv2D99+OzCRg== Received: from MW4PR03CA0121.namprd03.prod.outlook.com (2603:10b6:303:8c::6) by MN2PR12MB4357.namprd12.prod.outlook.com (2603:10b6:208:262::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Sun, 28 Jul 2024 22:45:20 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:303:8c:cafe::62) by MW4PR03CA0121.outlook.office365.com (2603:10b6:303:8c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:20 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:09 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:09 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:08 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 7/9] iommu/arm-smmu-v3: Add struct arm_smmu_impl Date: Sun, 28 Jul 2024 15:44:52 -0700 Message-ID: <173976eb174eef0a36d5280abe175f6ca0cdcc90.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A672E:EE_|MN2PR12MB4357:EE_ X-MS-Office365-Filtering-Correlation-Id: 6eed9f48-d428-4f94-87a3-08dcaf56f5b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: T/mZJ4o6vi3SZqsEaLrZhXCZkCdAscAFv3DPxagrwIAN//DaD8TV9ipdn5xbzcmpolZ19Z1/Ncf2RZDpVKLWf0uxe2i98zcEsubDaL4TNW/DpUqXJl9nxtAFzlWW1oG7SpI+9owYuxwYdsS/KJLnWcaAGm4IVhaD14s55dP6G7iqvLwkLhTYAX023800lna4yd+0KoFg+vp/QTs5AYwm+RIVztwOfjmq1YenSD1cX7KlfuedS2yNIkrk5UWLQ5uSJSlNk6q3/rluxrxO4TQ8Xvn/YmFbwrvfXpS+5iT6X0SEY3A+eN+5MNj+91Dlrvg/n6jeS5cPGFNIbfAI8aCLFLC/tlHk49URoJpI3nBwUE/QzmkJv659eYP6pMqDZgX8tUzZPDD2xsJydCfRVq7oO1wKqSun6l8XukdzGBsgMv6E8bKeeQR5jrnVNK2NY5impUkQd1b/0bx7OFTg2/aafXhAh7JRpiaRba1hOVYkXhqhtKep7cijA1UZwgejgR8967dJXF14aLTHEObKf4weyUbqFz0UWIBViY7CxFLgm7XJcqzKHcpnCUDAd6uVVbRej1YY3KJZoJ0qDPcdhlVypr/x8777I/lgiLW681qx7bWafmGUBpJBJKqsiJSem8eOP/Vo0cXR/Vz0CU8QVmH1EonMLgRk7VGgILrH73QrQDKA08/U7Eyh0Snx3hOGb1GYx4N6C77SJoMoZTOhrTGPD5FE4pMtQPaaZc4aQIkynxyDmZ4YAfy1sdSM/Jk8esnynnCPlmA/+RMxzcY5lstJCkFLoIcd8riyebqZ5oNuUxakPHG5AFWCC9InphZ7bTswybZurP8NcBOGsJJw22uQbbqh/RndmKy5pG0ruWTBUDgSELwNtM9I4WNUrKSGCCUAskKIthum2GqH+/Xrr8WFdxY0BHeHD4v95WDY1UB4pi5MGgKEniescx3u394RoghhCartwfVv+YKqsjC/21CgHjm9U99u/h40cFenwu92K7mAYXxRoBM/BlkTwt/v9x5nV48/dOV4g2NSvVBuyIDI6eoNKNaQseK6gVsqL+qeJdTseu8MC5AzWxpc1DwQcxAsnfGmsZtnrjRFiMC6pqM4v9G4fuKLWoHhQWZppxljnoVeY0ZyqqCAn8yWRpiyETXJGtiRaGIaLNp9GBdVHfKZZfyM5RVUWJfySeZwz9SO6931a0TxAMIlqtkastnHPTE74UkrcjQdTnR1tgIxObFY06er+8rnJv/sA3pQ6y+kQ+dHnCwp+3URmJAre83k9g4fuWwDzhtY1wfaZCUL0WnEFKAmmKze4z5s5QnGUw3ph+/C4r1j3nOpV4aJmQGpoyWrpsIaiDMW5uEgmFHaii9rfpBvb4ZOlM2k2Zn4ErPThVTO+o1WfB3ArNHwL4C7DvoljoLY54fn3P+op1x0RhGMxu2WJoHUSpIM2M5S4lbnB7T/G9reHspBhNm8lsHd7o1x X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:20.3021 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6eed9f48-d428-4f94-87a3-08dcaf56f5b0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4357 NVIDIA Tegra241 implemented SMMU in a slightly different way that supports a CMDQV extension feature as a secondary CMDQ for virtualization cases. Mimicing the arm-smmu (v2) driver, introduce a new struct arm_smmu_impl to accommodate impl routines. Suggested-by: Will Deacon Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 67 +++++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 19 ++++++ 2 files changed, 74 insertions(+), 12 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 e764236a92166..18d940c65e2ca 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -338,7 +338,12 @@ 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) { - return &smmu->cmdq; + struct arm_smmu_cmdq *cmdq = NULL; + + if (smmu->impl && smmu->impl->get_secondary_cmdq) + cmdq = smmu->impl->get_secondary_cmdq(smmu); + + return cmdq ?: &smmu->cmdq; } static bool arm_smmu_cmdq_needs_busy_polling(struct arm_smmu_device *smmu, @@ -4044,6 +4049,14 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu) return ret; } + if (smmu->impl && smmu->impl->device_reset) { + ret = smmu->impl->device_reset(smmu); + if (ret) { + dev_err(smmu->dev, "failed to reset impl\n"); + return ret; + } + } + return 0; } @@ -4347,8 +4360,23 @@ static void acpi_smmu_get_options(u32 model, struct arm_smmu_device *smmu) dev_notice(smmu->dev, "option mask 0x%x\n", smmu->options); } -static int arm_smmu_device_acpi_probe(struct platform_device *pdev, - struct arm_smmu_device *smmu) +static struct arm_smmu_device * +arm_smmu_impl_acpi_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + /* + * DSDT might hold some SMMU extension, so we have no option but to go + * through the ACPI tables unconditionally. On success, this returns a + * copy of smmu struct holding an impl pointer. Otherwise, an impl may + * choose to return an ERR_PTR as an error out, or to return the pass- + * in smmu pointer as a fallback to the standard SMMU. + */ + return arm_smmu_impl_acpi_dsdt_probe(smmu, node); +} + +static struct arm_smmu_device * +arm_smmu_device_acpi_probe(struct platform_device *pdev, + struct arm_smmu_device *smmu) { struct acpi_iort_smmu_v3 *iort_smmu; struct device *dev = smmu->dev; @@ -4372,18 +4400,20 @@ static int arm_smmu_device_acpi_probe(struct platform_device *pdev, smmu->features |= ARM_SMMU_FEAT_HA; } - return 0; + return arm_smmu_impl_acpi_probe(smmu, node); } #else -static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev, - struct arm_smmu_device *smmu) +static struct arm_smmu_device * +arm_smmu_device_acpi_probe(struct platform_device *pdev, + struct arm_smmu_device *smmu) { - return -ENODEV; + return ERR_PTR(-ENODEV); } #endif -static int arm_smmu_device_dt_probe(struct platform_device *pdev, - struct arm_smmu_device *smmu) +static struct arm_smmu_device * +arm_smmu_device_dt_probe(struct platform_device *pdev, + struct arm_smmu_device *smmu) { struct device *dev = &pdev->dev; u32 cells; @@ -4401,7 +4431,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev, if (of_dma_is_coherent(dev->of_node)) smmu->features |= ARM_SMMU_FEAT_COHERENCY; - return ret; + return ret ? ERR_PTR(ret) : smmu; } static unsigned long arm_smmu_resource_size(struct arm_smmu_device *smmu) @@ -4453,6 +4483,14 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) iort_put_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); } +static void arm_smmu_impl_remove(void *data) +{ + struct arm_smmu_device *smmu = data; + + if (smmu->impl && smmu->impl->device_remove) + smmu->impl->device_remove(smmu); +} + static int arm_smmu_device_probe(struct platform_device *pdev) { int irq, ret; @@ -4467,10 +4505,14 @@ static int arm_smmu_device_probe(struct platform_device *pdev) smmu->dev = dev; if (dev->of_node) { - ret = arm_smmu_device_dt_probe(pdev, smmu); + smmu = arm_smmu_device_dt_probe(pdev, smmu); } else { - ret = arm_smmu_device_acpi_probe(pdev, smmu); + smmu = arm_smmu_device_acpi_probe(pdev, smmu); } + if (IS_ERR(smmu)) + return PTR_ERR(smmu); + + ret = devm_add_action_or_reset(dev, arm_smmu_impl_remove, smmu); if (ret) return ret; @@ -4560,6 +4602,7 @@ static void arm_smmu_device_remove(struct platform_device *pdev) { struct arm_smmu_device *smmu = platform_get_drvdata(pdev); + arm_smmu_impl_remove(smmu); iommu_device_unregister(&smmu->iommu); iommu_device_sysfs_remove(&smmu->iommu); arm_smmu_device_disable(smmu); 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 71818f5860364..38d4a84e2c821 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -14,6 +14,9 @@ #include #include +struct arm_smmu_device; +struct acpi_iort_node; + /* MMIO registers */ #define ARM_SMMU_IDR0 0x0 #define IDR0_ST_LVL GENMASK(28, 27) @@ -627,9 +630,25 @@ struct arm_smmu_strtab_cfg { u32 strtab_base_cfg; }; +struct arm_smmu_impl { + int (*device_reset)(struct arm_smmu_device *smmu); + void (*device_remove)(struct arm_smmu_device *smmu); + struct arm_smmu_cmdq *(*get_secondary_cmdq)(struct arm_smmu_device *smmu); +}; + +static inline struct arm_smmu_device * +arm_smmu_impl_acpi_dsdt_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + return smmu; +} + /* An SMMUv3 instance */ struct arm_smmu_device { struct device *dev; + /* An SMMUv3 implementation */ + const struct arm_smmu_impl *impl; + void __iomem *base; void __iomem *page1; From patchwork Sun Jul 28 22:44:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=k7biE0wo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3114-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGm81vKSz1yf4 for ; Mon, 29 Jul 2024 08:45:28 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5C4E71C21128 for ; Sun, 28 Jul 2024 22:45:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD3A882495; Sun, 28 Jul 2024 22:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="k7biE0wo" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2042.outbound.protection.outlook.com [40.107.223.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C91648121F; Sun, 28 Jul 2024 22:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206725; cv=fail; b=UNAN4B2wpjg6HLcKX20v4hQM6qwnArWc2SMwzVkUdkYyJsIf/gBuF5y1nvKnHTxCK2z0PgnT3mnlejZ1TZLiayv4mOSAyUYpevqfcvxxVv9snjvzuuB5yEdy2mWe97Q7SQfQcdVmnB7nhUNaMbbl1LrBOzLBO/6qKNAY7u77hPI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206725; c=relaxed/simple; bh=g09KH9o4s5iyhOh4QLBfOcqYtKT1yeb3guDPJ4YPr7U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aQ/62NSNAF6P7n2p4TRyJMSu+ZunhghiH+PfXuRk51EBJVEyii1qrbr3UEc2yf5/gIuT54UZH8RI4R6lPE89/tFthdqIdAYfM5ZVRITN4bJrCwwEc4ULxGu1j0td1k5kWZsOH/490f75OV83hTuSTSV159Dp+qHWUH89KodlWeE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=k7biE0wo; arc=fail smtp.client-ip=40.107.223.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kuv/iPZkqQ5/z1zHxJaggRv65oIVSDCcU+7Kt6OEoJBy/zZ92R3ONKdh9XWHqANx8OqM9nQ4ZlsdFdfHBr6/QwqfQApJpqDjPsBgJffcSkHstr3ntuXDnqZqC1axBch3iZRbt7ea1CSEKG+HVmKYONFJD2mnhRnaEhaMmfpq/C3DCusuP1VGAWj1NqVsmnEOyWtKlCRlmCAm2iPXFpc5R8aoeJWvF7VMlXR3qUmVmo5gnfbT08iBHOwr35mCIO15EoJtqstpMlaY5eeMWG8nPj/3el6wy+pJV8a5N1KjAHHwdgqAVAzCdP6SphuBmRwgwydbPf+ynn8GAUX6rRvBRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=AyL3Nse6z8g9La9ZVxEO+YR4IeK8w2bdvmcOev48FqA=; b=nmZjN47rU+QIpkA+8+NI33xe3OEmIvD13XtOrNChTwqsnRXPFw5CIswadhek2U/hK0TyNTNT7vs5spn+DpF0Y40NNYjbTz8QeiQmrQZoCspA3M3cM5nuaRQ/rBhkr41hMbp15DCeALUF/z+NDFUFd9PgIgfqIVFAVwAyv8TbPHeKT96GvZAirpxL7fXtB99uU0B0SR8YkAhaFgakXNFW25bQZW+soNbl0TYCXcYQNB4DF0ArKWDzilhvoAfaCnrHp04CFkWY3P5cQ8TqjQ9jxbQSFOUix6yw5Ght7lBKdlmRy45uuXLYsRU9n+HLwh3PEpDLil+wIrOuxSe4IhAIvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=AyL3Nse6z8g9La9ZVxEO+YR4IeK8w2bdvmcOev48FqA=; b=k7biE0wooYnH1uatGSuLzZPsxC6ZKVT4cZfpphzvYxWzuxen2Ru0h1Af7Lf3Qgi6qNy9SWHiHysOaQd0hLckedgqO5dq+T/oLu/JBq7C844pu0foC7lDris8gSUJd4lYub60krUX7wVbLEd43Ud8y8cBvArE2WIfhBAxVx6BByh3E0ITOnNd/VWWTNc6ciprz0h4QZ+V0eRqT27H/x1KlxHCnrSWppTmqjIiV1XThiQy1AG1BY1VsEwMJ1v1My58vCtjHtMqcBHQNshFGMs/k6XEE+7rJ4Xg0x2JJB4jprFqxnGX2uBC6GM3ZWxRMdxNHY51LXmB25h6vozXrf4w0Q== Received: from BN0PR04CA0037.namprd04.prod.outlook.com (2603:10b6:408:e8::12) by LV3PR12MB9401.namprd12.prod.outlook.com (2603:10b6:408:21c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.26; Sun, 28 Jul 2024 22:45:18 +0000 Received: from BL6PEPF00020E60.namprd04.prod.outlook.com (2603:10b6:408:e8:cafe::34) by BN0PR04CA0037.outlook.office365.com (2603:10b6:408:e8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.34 via Frontend Transport; Sun, 28 Jul 2024 22:45:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL6PEPF00020E60.mail.protection.outlook.com (10.167.249.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:18 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:10 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:10 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:09 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 8/9] iommu/arm-smmu-v3: Add in-kernel support for NVIDIA Tegra241 (Grace) CMDQV Date: Sun, 28 Jul 2024 15:44:53 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E60:EE_|LV3PR12MB9401:EE_ X-MS-Office365-Filtering-Correlation-Id: 5457764c-a826-42e6-bd49-08dcaf56f4ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: yeWlSv9V4uFoE652nCW3KxPPHKy9W16VB2LJyDMQSxyBG/slNmLfo8hlgbXR3vboG/zZNUUKIdNYKZbV+lEWPJrkLsJRj0P5WaFz7ZCh/pml7OciBhvA7+6430dTd842e0QB1AQYIn4zBiIZByK2sOm3QcLvfxXS23pT4Oubfo8Ev38PlX1I4aj7K8ycTtzk+RxHGT1ROsVEyVHSJ+zqD7apXAI3k3d68kNwLm9/rKz11/2rSInT6KKTK3OSEjPVWiB63BKYSz5v9ip7FohisKQc25plQaf1Yw3qUqw2kZJBUV/u1O74l0aGOvv7bH107aWehjUIL4nNvFK5jYnjStNYaVeL5adfwyRyquuxehwNd7ktFBzg4lbtsTIX+tg/loTSw3IoM2nyMBPgYNbD8up2tnFfA0NxW2voI8TzOEo4jUAeAQ4epNS9fxmgRYeFIM1qe3PSHuFLyb/lRxRUtfd4X9hrBKVLrz3jx2lcRECmKsBqU5xwKEYMUGRMLHP3jYkB2SwHnxipdwX+DefZHv3GAUasb0UvH0++zXd52asoquaMk01/24e/H4eMsSyZfkTDRnTj+aYq9ArYnfAEFbMmKBSNKbBAouHsmSJ98aL8nVldH0xWiH1TFq1e8QfZLNQ/AYjSWSomri865+yldvLzKNhbEFtA8XRWKm3uymgLFlrS4XUDg7U6RWnz04VjgUTWVR3yQPhUbM2hE0n6UWYWWN/CPCdBZ20k0qkVxLzuxBW5SfpAknYJ/KHPT400cSWjrWn4oPlr+LDsnn220P5i9XSsMXUFvexbuQmphPPkyOAdIvWp69rQngoCb3tJBAjf5HifMyiPobWmJEcgy+QeXDEEricJAg5fTO621t4RSouZNQh2G6tShlSsZ+WMj2gUoZJElaMUdvFs2eQ//uSEFon1tzo+lJS7+WlcB1y8Gd4PS0G/k6VB1avKrSJcNGP6+FcQ4sw49WMW2mFIvXB0sKX29nQq0CSgg7neN4P9Zc3hbr4KI17PotKk1ctNyRyWMhnYA9U/yiHSREtNyNN0sF0mfgiQNCajB1vqnMz9AWJlvmtCQoTDZZ7WedUh3Wridp4Bcy9/3YYx3xx8eEeGL1X5KxVQMHBglXzPSWbRC7KZeK+cfiRmxA/qOsAoMMb67MNWqu0AlTHhV+8T8b5yiMAYQRgtJgNurMM5CXQ+9jlWz/97Djy/O7Eok1tBqsosFXVnnqHLIv8/zmX34AOG4P2J3vtq+4tBeyXDpKcS1lwiPCY/PTRJilnV0tBmiMbx+HxDCxyk2tUi0qq7jopayhd5TuDl4PBhRPidtlSaTbmcQFP9Qqv7ZSgH129O2ITysaDMMe4phmKrJK9oJLXkwq4lx41BT+DoBfSm9vusBA540731XFhxv+pQb9omoFYZJ3f9Tbwhg1fVk8ACnWWXspiv/2M06LDiqTBnNvSM2UWQx/38Tq1O1Cvg88TX X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:18.6868 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5457764c-a826-42e6-bd49-08dcaf56f4ca X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E60.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9401 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 designed based on IOMMUFD, and its RFC series is also under review. It 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, compared to nested SMMU CMDQ (with trappings). As the initial version, the CMDQV driver only supports ACPI configurations. Signed-off-by: Nate Watterson Reviewed-by: Jason Gunthorpe Co-developed-by: Nicolin Chen Signed-off-by: Nicolin Chen --- MAINTAINERS | 1 + drivers/iommu/Kconfig | 11 + drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 + .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 867 ++++++++++++++++++ 5 files changed, 889 insertions(+) create mode 100644 drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c diff --git a/MAINTAINERS b/MAINTAINERS index 42decde383206..fb9ab8909618b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22471,6 +22471,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 a82f10054aec8..22addaedf64df 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -424,6 +424,17 @@ config ARM_SMMU_V3_KUNIT_TEST Enable this option to unit-test arm-smmu-v3 driver functions. If unsure, say N. + +config TEGRA241_CMDQV + bool "NVIDIA Tegra241 CMDQ-V extension support for ARM SMMUv3" + 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. endif config S390_IOMMU diff --git a/drivers/iommu/arm/arm-smmu-v3/Makefile b/drivers/iommu/arm/arm-smmu-v3/Makefile index 355173d1441d2..dc98c88b48c82 100644 --- a/drivers/iommu/arm/arm-smmu-v3/Makefile +++ b/drivers/iommu/arm/arm-smmu-v3/Makefile @@ -2,5 +2,6 @@ obj-$(CONFIG_ARM_SMMU_V3) += arm_smmu_v3.o arm_smmu_v3-y := arm-smmu-v3.o arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o +arm_smmu_v3-$(CONFIG_TEGRA241_CMDQV) += tegra241-cmdqv.o obj-$(CONFIG_ARM_SMMU_V3_KUNIT_TEST) += arm-smmu-v3-test.o 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 38d4a84e2c821..367f5e160af4e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -636,10 +636,19 @@ struct arm_smmu_impl { struct arm_smmu_cmdq *(*get_secondary_cmdq)(struct arm_smmu_device *smmu); }; +#ifdef CONFIG_TEGRA241_CMDQV +struct arm_smmu_device * +tegra241_cmdqv_acpi_dsdt_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node); +#endif + static inline struct arm_smmu_device * arm_smmu_impl_acpi_dsdt_probe(struct arm_smmu_device *smmu, struct acpi_iort_node *node) { +#ifdef CONFIG_TEGRA241_CMDQV + smmu = tegra241_cmdqv_acpi_dsdt_probe(smmu, node); +#endif return smmu; } 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 0000000000000..891302fb20901 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c @@ -0,0 +1,867 @@ +// 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 + +#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_PAGE_BASE (TEGRA241_VCMDQ_PAGE1_BASE + SZ_64K) + +/* CMDQV global base 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_ENABLED BIT(0) + +#define TEGRA241_CMDQV_VINTF_ERR_MAP 0x0014 +#define TEGRA241_CMDQV_VINTF_INT_MASK 0x001C +#define TEGRA241_CMDQV_CMDQ_ERR_MAP(m) (0x0024 + 0x4*(m)) + +#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 base 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_LVCMDQ_ERR_MAP_64(m) \ + (0x00C0 + 0x8*(m)) +#define LVCMDQ_ERR_MAP_NUM_64 2 + +/* VCMDQ base 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_PAGE_BASE + SZ_128K*(i)) +#define TEGRA241_VINTFi_PAGE1(i) (TEGRA241_VINTFi_PAGE0(i) + SZ_64K) +#define TEGRA241_VINTFi_LVCMDQ_PAGE0(i, q) \ + (TEGRA241_VINTFi_PAGE0(i) + 0x80*(q)) +#define TEGRA241_VINTFi_LVCMDQ_PAGE1(i, q) \ + (TEGRA241_VINTFi_PAGE1(i) + 0x80*(q)) + +/* MMIO helpers */ +#define REG_CMDQV(_cmdqv, _regname) \ + ((_cmdqv)->base + TEGRA241_CMDQV_##_regname) +#define REG_VINTF(_vintf, _regname) \ + ((_vintf)->base + TEGRA241_VINTF_##_regname) +#define REG_VCMDQ_PAGE0(_vcmdq, _regname) \ + ((_vcmdq)->page0 + TEGRA241_VCMDQ_##_regname) +#define REG_VCMDQ_PAGE1(_vcmdq, _regname) \ + ((_vcmdq)->page1 + TEGRA241_VCMDQ_##_regname) + + +static bool disable_cmdqv; +module_param(disable_cmdqv, bool, 0444); +MODULE_PARM_DESC(disable_cmdqv, + "This allows to disable CMDQV HW and use default SMMU internal CMDQ."); + +static bool bypass_vcmdq; +module_param(bypass_vcmdq, bool, 0444); +MODULE_PARM_DESC(bypass_vcmdq, + "This allows to bypass VCMDQ for debugging use or perf comparison."); + +/** + * struct tegra241_vcmdq - Virtual Command Queue + * @idx: Global index in the CMDQV + * @lidx: Local index in the VINTF + * @enabled: Enable status + * @cmdqv: Parent CMDQV pointer + * @vintf: Parent VINTF pointer + * @cmdq: Command Queue struct + * @page0: MMIO Page0 base address + * @page1: MMIO Page1 base address + */ +struct tegra241_vcmdq { + u16 idx; + u16 lidx; + + bool enabled; + + struct tegra241_cmdqv *cmdqv; + struct tegra241_vintf *vintf; + struct arm_smmu_cmdq cmdq; + + void __iomem *page0; + void __iomem *page1; +}; + +/** + * struct tegra241_vintf - Virtual Interface + * @idx: Global index in the CMDQV + * @enabled: Enable status + * @cmdqv: Parent CMDQV pointer + * @lvcmdqs: List of logical VCMDQ pointers + * @base: MMIO base address + */ +struct tegra241_vintf { + u16 idx; + + bool enabled; + + struct tegra241_cmdqv *cmdqv; + struct tegra241_vcmdq **lvcmdqs; + + void __iomem *base; +}; + +/** + * struct tegra241_cmdqv - CMDQ-V for SMMUv3 + * @smmu: SMMUv3 device + * @base: MMIO base address + * @irq: IRQ number + * @num_vintfs: Total number of VINTFs + * @num_vcmdqs: Total number of VCMDQs + * @num_lvcmdqs_per_vintf: Number of logical VCMDQs per VINTF + * @vintf_ids: VINTF id allocator + * @vtinfs: List of VINTFs + */ +struct tegra241_cmdqv { + struct arm_smmu_device smmu; + + void __iomem *base; + int irq; + + /* CMDQV Hardware Params */ + u16 num_vintfs; + u16 num_vcmdqs; + u16 num_lvcmdqs_per_vintf; + + struct ida vintf_ids; + + struct tegra241_vintf **vintfs; +}; + +/* Config and Polling Helpers */ + +static inline int tegra241_cmdqv_write_config(struct tegra241_cmdqv *cmdqv, + void __iomem *addr_config, + void __iomem *addr_status, + u32 regval, const char *header, + bool *out_enabled) +{ + bool en = regval & BIT(0); + int ret; + + writel(regval, addr_config); + ret = readl_poll_timeout(addr_status, regval, + en ? regval & BIT(0) : !(regval & BIT(0)), + 1, ARM_SMMU_POLL_TIMEOUT_US); + if (ret) + dev_err(cmdqv->smmu.dev, "%sfailed to %sable, STATUS=0x%08X\n", + header, en ? "en" : "dis", regval); + if (out_enabled) + WRITE_ONCE(*out_enabled, regval & BIT(0)); + return ret; +} + +static inline int cmdqv_write_config(struct tegra241_cmdqv *cmdqv, u32 regval) +{ + return tegra241_cmdqv_write_config(cmdqv, + REG_CMDQV(cmdqv, CONFIG), + REG_CMDQV(cmdqv, STATUS), + regval, "CMDQV: ", NULL); +} + +static inline int vintf_write_config(struct tegra241_vintf *vintf, u32 regval) +{ + char header[16]; + + snprintf(header, 16, "VINTF%u: ", vintf->idx); + return tegra241_cmdqv_write_config(vintf->cmdqv, + REG_VINTF(vintf, CONFIG), + REG_VINTF(vintf, STATUS), + regval, header, &vintf->enabled); +} + +static inline char *lvcmdq_error_header(struct tegra241_vcmdq *vcmdq, + char *header, int hlen) +{ + WARN_ON(hlen < 32); + if (WARN_ON(!vcmdq->vintf)) + return ""; + snprintf(header, hlen, "VINTF%u: VCMDQ%u/LVCMDQ%u: ", + vcmdq->vintf->idx, vcmdq->idx, vcmdq->lidx); + return header; +} + +static inline int vcmdq_write_config(struct tegra241_vcmdq *vcmdq, u32 regval) +{ + char header[32], *h = lvcmdq_error_header(vcmdq, header, 32); + + return tegra241_cmdqv_write_config(vcmdq->cmdqv, + REG_VCMDQ_PAGE0(vcmdq, CONFIG), + REG_VCMDQ_PAGE0(vcmdq, STATUS), + regval, h, &vcmdq->enabled); +} + +/* ISR Functions */ + +static void tegra241_vintf0_handle_error(struct tegra241_vintf *vintf) +{ + int i; + + for (i = 0; i < LVCMDQ_ERR_MAP_NUM_64; i++) { + u64 map = readq_relaxed(REG_VINTF(vintf, LVCMDQ_ERR_MAP_64(i))); + + while (map) { + unsigned long lidx = __ffs64(map) - 1; + struct tegra241_vcmdq *vcmdq = vintf->lvcmdqs[lidx]; + u32 gerror = readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERROR)); + + __arm_smmu_cmdq_skip_err(&vintf->cmdqv->smmu, &vcmdq->cmdq); + writel(gerror, REG_VCMDQ_PAGE0(vcmdq, GERRORN)); + map &= ~BIT_ULL(lidx); + } + } +} + +static irqreturn_t tegra241_cmdqv_isr(int irq, void *devid) +{ + struct tegra241_cmdqv *cmdqv = (struct tegra241_cmdqv *)devid; + void __iomem *reg_vintf_map = REG_CMDQV(cmdqv, VINTF_ERR_MAP); + char err_str[256]; + u64 vintf_map; + + /* Use readl_relaxed() as register addresses are not 64-bit aligned */ + vintf_map = (u64)readl_relaxed(reg_vintf_map + 0x4) << 32 | + (u64)readl_relaxed(reg_vintf_map); + + snprintf(err_str, sizeof(err_str), + "vintf_map: %016llx, vcmdq_map %08x:%08x:%08x:%08x", vintf_map, + readl_relaxed(REG_CMDQV(cmdqv, CMDQ_ERR_MAP(3))), + readl_relaxed(REG_CMDQV(cmdqv, CMDQ_ERR_MAP(2))), + readl_relaxed(REG_CMDQV(cmdqv, CMDQ_ERR_MAP(1))), + readl_relaxed(REG_CMDQV(cmdqv, CMDQ_ERR_MAP(0)))); + + dev_warn(cmdqv->smmu.dev, "unexpected error reported. %s\n", err_str); + + /* Handle VINTF0 and its LVCMDQs */ + if (vintf_map & BIT_ULL(0)) { + tegra241_vintf0_handle_error(cmdqv->vintfs[0]); + vintf_map &= ~BIT_ULL(0); + } + + return IRQ_HANDLED; +} + +/* Command Queue Function */ + +static struct arm_smmu_cmdq * +tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = + container_of(smmu, struct tegra241_cmdqv, smmu); + struct tegra241_vintf *vintf = cmdqv->vintfs[0]; + struct tegra241_vcmdq *vcmdq; + u16 lidx; + + if (READ_ONCE(bypass_vcmdq)) + return NULL; + + /* Use SMMU CMDQ if VINTF0 is uninitialized */ + if (!READ_ONCE(vintf->enabled)) + return NULL; + + /* + * Select a LVCMDQ 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. + */ + lidx = smp_processor_id() % cmdqv->num_lvcmdqs_per_vintf; + vcmdq = vintf->lvcmdqs[lidx]; + if (!vcmdq || !READ_ONCE(vcmdq->enabled)) + return NULL; + return &vcmdq->cmdq; +} + +/* HW Reset Functions */ + +static void tegra241_vcmdq_hw_deinit(struct tegra241_vcmdq *vcmdq) +{ + char header[32], *h = lvcmdq_error_header(vcmdq, header, 32); + u32 gerrorn, gerror; + + if (vcmdq_write_config(vcmdq, 0)) { + dev_err(vcmdq->cmdqv->smmu.dev, + "%sGERRORN=0x%X, GERROR=0x%X, CONS=0x%X\n", h, + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERRORN)), + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERROR)), + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, CONS))); + } + writel_relaxed(0, REG_VCMDQ_PAGE0(vcmdq, PROD)); + writel_relaxed(0, REG_VCMDQ_PAGE0(vcmdq, CONS)); + writeq_relaxed(0, REG_VCMDQ_PAGE1(vcmdq, BASE)); + writeq_relaxed(0, REG_VCMDQ_PAGE1(vcmdq, CONS_INDX_BASE)); + + gerrorn = readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERRORN)); + gerror = readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERROR)); + if (gerror != gerrorn) { + dev_warn(vcmdq->cmdqv->smmu.dev, + "%suncleared error detected, resetting\n", h); + writel(gerror, REG_VCMDQ_PAGE0(vcmdq, GERRORN)); + } + + dev_dbg(vcmdq->cmdqv->smmu.dev, "%sdeinited\n", h); +} + +static int tegra241_vcmdq_hw_init(struct tegra241_vcmdq *vcmdq) +{ + char header[32], *h = lvcmdq_error_header(vcmdq, header, 32); + int ret; + + /* Reset VCMDQ */ + tegra241_vcmdq_hw_deinit(vcmdq); + + /* Configure and enable VCMDQ */ + writeq_relaxed(vcmdq->cmdq.q.q_base, REG_VCMDQ_PAGE1(vcmdq, BASE)); + + ret = vcmdq_write_config(vcmdq, VCMDQ_EN); + if (ret) { + dev_err(vcmdq->cmdqv->smmu.dev, + "%sGERRORN=0x%X, GERROR=0x%X, CONS=0x%X\n", h, + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERRORN)), + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, GERROR)), + readl_relaxed(REG_VCMDQ_PAGE0(vcmdq, CONS))); + return ret; + } + + dev_dbg(vcmdq->cmdqv->smmu.dev, "%sinited\n", h); + return 0; +} + +static void tegra241_vintf_hw_deinit(struct tegra241_vintf *vintf) +{ + u16 lidx; + + for (lidx = 0; lidx < vintf->cmdqv->num_lvcmdqs_per_vintf; lidx++) + if (vintf->lvcmdqs && vintf->lvcmdqs[lidx]) + tegra241_vcmdq_hw_deinit(vintf->lvcmdqs[lidx]); + vintf_write_config(vintf, 0); +} + +static int tegra241_vintf_hw_init(struct tegra241_vintf *vintf, bool hyp_own) +{ + u32 regval; + u16 lidx; + int ret; + + /* Reset VINTF */ + tegra241_vintf_hw_deinit(vintf); + + /* Configure and enable VINTF */ + regval = FIELD_PREP(VINTF_HYP_OWN, hyp_own); + writel(regval, REG_VINTF(vintf, CONFIG)); + + ret = vintf_write_config(vintf, regval | VINTF_EN); + if (ret) + return ret; + + for (lidx = 0; lidx < vintf->cmdqv->num_lvcmdqs_per_vintf; lidx++) { + if (vintf->lvcmdqs && vintf->lvcmdqs[lidx]) { + ret = tegra241_vcmdq_hw_init(vintf->lvcmdqs[lidx]); + if (ret) { + tegra241_vintf_hw_deinit(vintf); + return ret; + } + } + } + + return 0; +} + +static int tegra241_cmdqv_hw_reset(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = + container_of(smmu, struct tegra241_cmdqv, smmu); + u16 qidx, lidx, idx; + u32 regval; + int ret; + + /* Reset CMDQV */ + regval = readl_relaxed(REG_CMDQV(cmdqv, CONFIG)); + ret = cmdqv_write_config(cmdqv, regval & ~CMDQV_EN); + if (ret) + return ret; + ret = cmdqv_write_config(cmdqv, regval | CMDQV_EN); + if (ret) + return ret; + + /* Assign preallocated global VCMDQs to each VINTF as LVCMDQs */ + for (idx = 0, qidx = 0; idx < cmdqv->num_vintfs; idx++) { + for (lidx = 0; lidx < cmdqv->num_lvcmdqs_per_vintf; lidx++) { + regval = FIELD_PREP(CMDQV_CMDQ_ALLOC_VINTF, idx); + regval |= FIELD_PREP(CMDQV_CMDQ_ALLOC_LVCMDQ, lidx); + regval |= CMDQV_CMDQ_ALLOCATED; + writel_relaxed(regval, + REG_CMDQV(cmdqv, CMDQ_ALLOC(qidx++))); + } + } + + return tegra241_vintf_hw_init(cmdqv->vintfs[0], true); +} + +/* VCMDQ Resource Helpers */ + +static void tegra241_vcmdq_free_smmu_cmdq(struct tegra241_vcmdq *vcmdq) +{ + struct arm_smmu_queue *q = &vcmdq->cmdq.q; + size_t nents = 1 << q->llq.max_n_shift; + size_t qsz = nents << CMDQ_ENT_SZ_SHIFT; + + if (!q->base) + return; + dmam_free_coherent(vcmdq->cmdqv->smmu.dev, qsz, q->base, q->base_dma); +} + +static int tegra241_vcmdq_alloc_smmu_cmdq(struct tegra241_vcmdq *vcmdq) +{ + struct arm_smmu_device *smmu = &vcmdq->cmdqv->smmu; + struct arm_smmu_cmdq *cmdq = &vcmdq->cmdq; + struct arm_smmu_queue *q = &cmdq->q; + char name[16]; + int ret; + + snprintf(name, 16, "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(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); + + return arm_smmu_cmdq_init(smmu, cmdq); +} + +/* VINTF Logical VCMDQ Resource Helpers */ + +static void tegra241_vintf_deinit_lvcmdq(struct tegra241_vintf *vintf, u16 lidx) +{ + vintf->lvcmdqs[lidx] = NULL; +} + +static int tegra241_vintf_init_lvcmdq(struct tegra241_vintf *vintf, u16 lidx, + struct tegra241_vcmdq *vcmdq) +{ + struct tegra241_cmdqv *cmdqv = vintf->cmdqv; + u16 idx = vintf->idx; + + vcmdq->idx = idx * cmdqv->num_lvcmdqs_per_vintf + lidx; + vcmdq->lidx = lidx; + vcmdq->cmdqv = cmdqv; + vcmdq->vintf = vintf; + vcmdq->page0 = cmdqv->base + TEGRA241_VINTFi_LVCMDQ_PAGE0(idx, lidx); + vcmdq->page1 = cmdqv->base + TEGRA241_VINTFi_LVCMDQ_PAGE1(idx, lidx); + + vintf->lvcmdqs[lidx] = vcmdq; + return 0; +} + +static void tegra241_vintf_free_lvcmdq(struct tegra241_vintf *vintf, u16 lidx) +{ + struct tegra241_vcmdq *vcmdq = vintf->lvcmdqs[lidx]; + char header[32]; + + tegra241_vcmdq_free_smmu_cmdq(vcmdq); + tegra241_vintf_deinit_lvcmdq(vintf, lidx); + + dev_dbg(vintf->cmdqv->smmu.dev, + "%sdeallocated\n", lvcmdq_error_header(vcmdq, header, 32)); + kfree(vcmdq); +} + +static struct tegra241_vcmdq * +tegra241_vintf_alloc_lvcmdq(struct tegra241_vintf *vintf, u16 lidx) +{ + struct tegra241_cmdqv *cmdqv = vintf->cmdqv; + struct tegra241_vcmdq *vcmdq; + char header[32]; + int ret; + + vcmdq = kzalloc(sizeof(*vcmdq), GFP_KERNEL); + if (!vcmdq) + return ERR_PTR(-ENOMEM); + + ret = tegra241_vintf_init_lvcmdq(vintf, lidx, vcmdq); + if (ret) + goto free_vcmdq; + + /* Build an arm_smmu_cmdq for each LVCMDQ */ + ret = tegra241_vcmdq_alloc_smmu_cmdq(vcmdq); + if (ret) + goto deinit_lvcmdq; + + dev_dbg(cmdqv->smmu.dev, + "%sallocated\n", lvcmdq_error_header(vcmdq, header, 32)); + return vcmdq; + +deinit_lvcmdq: + tegra241_vintf_deinit_lvcmdq(vintf, lidx); +free_vcmdq: + kfree(vcmdq); + return ERR_PTR(ret); +} + +/* VINTF Resource Helpers */ + +static void tegra241_cmdqv_deinit_vintf(struct tegra241_cmdqv *cmdqv, u16 idx) +{ + kfree(cmdqv->vintfs[idx]->lvcmdqs); + ida_free(&cmdqv->vintf_ids, idx); + cmdqv->vintfs[idx] = NULL; +} + +static int tegra241_cmdqv_init_vintf(struct tegra241_cmdqv *cmdqv, u16 max_idx, + struct tegra241_vintf *vintf) +{ + + u16 idx; + int ret; + + ret = ida_alloc_max(&cmdqv->vintf_ids, max_idx, GFP_KERNEL); + if (ret < 0) + return ret; + idx = ret; + + vintf->idx = idx; + vintf->cmdqv = cmdqv; + vintf->base = cmdqv->base + TEGRA241_VINTF(idx); + + vintf->lvcmdqs = kcalloc(cmdqv->num_lvcmdqs_per_vintf, + sizeof(*vintf->lvcmdqs), GFP_KERNEL); + if (!vintf->lvcmdqs) { + ida_free(&cmdqv->vintf_ids, idx); + return -ENOMEM; + } + + cmdqv->vintfs[idx] = vintf; + return ret; +} + +/* Remove Helpers */ + +static void tegra241_vintf_remove_lvcmdq(struct tegra241_vintf *vintf, u16 lidx) +{ + tegra241_vcmdq_hw_deinit(vintf->lvcmdqs[lidx]); + tegra241_vintf_free_lvcmdq(vintf, lidx); +} + +static void tegra241_cmdqv_remove_vintf(struct tegra241_cmdqv *cmdqv, u16 idx) +{ + struct tegra241_vintf *vintf = cmdqv->vintfs[idx]; + u16 lidx; + + /* Remove LVCMDQ resources */ + for (lidx = 0; lidx < vintf->cmdqv->num_lvcmdqs_per_vintf; lidx++) + if (vintf->lvcmdqs[lidx]) + tegra241_vintf_remove_lvcmdq(vintf, lidx); + + /* Remove VINTF resources */ + tegra241_vintf_hw_deinit(vintf); + + dev_dbg(cmdqv->smmu.dev, "VINTF%u: deallocated\n", vintf->idx); + tegra241_cmdqv_deinit_vintf(cmdqv, idx); + kfree(vintf); +} + +static void tegra241_cmdqv_remove(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = + container_of(smmu, struct tegra241_cmdqv, smmu); + u16 idx; + + /* Remove VINTF resources */ + for (idx = 0; idx < cmdqv->num_vintfs; idx++) { + if (cmdqv->vintfs[idx]) { + /* Only vintf0 should remain at this stage */ + WARN_ON(idx > 0); + tegra241_cmdqv_remove_vintf(cmdqv, idx); + } + } + + /* Remove cmdqv resources */ + ida_destroy(&cmdqv->vintf_ids); + + if (cmdqv->irq > 0) + free_irq(cmdqv->irq, cmdqv); + iounmap(cmdqv->base); + kfree(cmdqv->vintfs); +} + +static struct arm_smmu_impl tegra241_cmdqv_impl = { + .get_secondary_cmdq = tegra241_cmdqv_get_cmdq, + .device_reset = tegra241_cmdqv_hw_reset, + .device_remove = tegra241_cmdqv_remove, +}; + +/* Probe Functions */ + +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 resource * +tegra241_cmdqv_find_acpi_resource(struct arm_smmu_device *smmu, + struct acpi_iort_node *node, int *irq) +{ + struct device *dev = smmu->dev; + struct list_head resource_list; + struct resource_entry *rentry; + struct resource *res = NULL; + 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", node->identifier); + 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; + } + + rentry = list_first_entry_or_null(&resource_list, + struct resource_entry, node); + if (!rentry) { + dev_err(dev, "failed to get memory resource entry\n"); + goto free_list; + } + + /* Caller must free the res */ + res = kzalloc(sizeof(*res), GFP_KERNEL); + if (!res) + goto free_list; + + *res = *rentry->res; + + acpi_dev_free_resource_list(&resource_list); + + INIT_LIST_HEAD(&resource_list); + + if (irq) + ret = acpi_dev_get_resources(adev, &resource_list, + tegra241_cmdqv_acpi_get_irqs, irq); + if (ret < 0 || !irq || *irq <= 0) + dev_warn(dev, "no interrupt. errors will not be reported\n"); + +free_list: + acpi_dev_free_resource_list(&resource_list); +put_dev: + put_device(&adev->dev); + + return res; +} + +struct dentry *cmdqv_debugfs_dir; + +static struct arm_smmu_device * +tegra241_cmdqv_probe(struct arm_smmu_device *smmu, + struct resource *res, int irq) +{ + struct tegra241_cmdqv *cmdqv = NULL; + struct tegra241_vintf *vintf; + void __iomem *base; + u32 regval; + int lidx; + int ret; + + base = ioremap(res->start, resource_size(res)); + if (IS_ERR(base)) { + dev_err(smmu->dev, "failed to ioremap: %ld\n", PTR_ERR(base)); + goto iounmap; + } + + regval = readl(base + TEGRA241_CMDQV_CONFIG); + if (disable_cmdqv) { + dev_info(smmu->dev, "Detected disable_cmdqv=true\n"); + writel(regval & ~CMDQV_EN, base + TEGRA241_CMDQV_CONFIG); + goto iounmap; + } + + cmdqv = devm_krealloc(smmu->dev, smmu, sizeof(*cmdqv), GFP_KERNEL); + if (!cmdqv) + goto iounmap; + smmu = &cmdqv->smmu; + + cmdqv->irq = irq; + cmdqv->base = base; + + if (cmdqv->irq > 0) { + ret = request_irq(irq, tegra241_cmdqv_isr, 0, + "tegra241-cmdqv", cmdqv); + if (ret) { + dev_err(smmu->dev, "failed to request irq (%d): %d\n", + cmdqv->irq, ret); + goto iounmap; + } + } + + regval = readl_relaxed(REG_CMDQV(cmdqv, PARAM)); + cmdqv->num_vintfs = 1 << FIELD_GET(CMDQV_NUM_VINTF_LOG2, regval); + cmdqv->num_vcmdqs = 1 << FIELD_GET(CMDQV_NUM_VCMDQ_LOG2, regval); + cmdqv->num_lvcmdqs_per_vintf = cmdqv->num_vcmdqs / cmdqv->num_vintfs; + + cmdqv->vintfs = kcalloc(cmdqv->num_vintfs, + sizeof(*cmdqv->vintfs), GFP_KERNEL); + if (!cmdqv->vintfs) + goto free_irq; + + ida_init(&cmdqv->vintf_ids); + + vintf = kzalloc(sizeof(*vintf), GFP_KERNEL); + if (!vintf) + goto destroy_ids; + + /* Init VINTF0 for in-kernel use */ + ret = tegra241_cmdqv_init_vintf(cmdqv, 0, vintf); + if (ret) { + dev_err(smmu->dev, "failed to init vintf0: %d\n", ret); + goto free_vintf; + } + + /* Preallocate logical VCMDQs to VINTF0 */ + for (lidx = 0; lidx < cmdqv->num_lvcmdqs_per_vintf; lidx++) { + struct tegra241_vcmdq *vcmdq; + + vcmdq = tegra241_vintf_alloc_lvcmdq(vintf, lidx); + if (IS_ERR(vcmdq)) + goto free_lvcmdq; + } + +#ifdef CONFIG_IOMMU_DEBUGFS + if (!cmdqv_debugfs_dir) { + cmdqv_debugfs_dir = + debugfs_create_dir("tegra241_cmdqv", iommu_debugfs_dir); + debugfs_create_bool("bypass_vcmdq", 0644, + cmdqv_debugfs_dir, &bypass_vcmdq); + } +#endif + + cmdqv->smmu.impl = &tegra241_cmdqv_impl; + cmdqv->smmu.options |= ARM_SMMU_OPT_SECONDARY_CMDQ_CS_NONE_ONLY; + + return &cmdqv->smmu; + +free_lvcmdq: + for (lidx--; lidx >= 0; lidx--) + tegra241_vintf_free_lvcmdq(vintf, lidx); + tegra241_cmdqv_deinit_vintf(cmdqv, vintf->idx); +free_vintf: + kfree(vintf); +destroy_ids: + ida_destroy(&cmdqv->vintf_ids); + kfree(cmdqv->vintfs); +free_irq: + if (cmdqv->irq > 0) + free_irq(cmdqv->irq, cmdqv); +iounmap: + iounmap(base); + dev_info(smmu->dev, "Falling back to standard SMMU CMDQ\n"); + return smmu; +} + +struct arm_smmu_device * +tegra241_cmdqv_acpi_dsdt_probe(struct arm_smmu_device *smmu, + struct acpi_iort_node *node) +{ + struct resource *res; + int irq; + + /* Keep the pointer smmu intact if !res */ + res = tegra241_cmdqv_find_acpi_resource(smmu, node, &irq); + if (!res) + return smmu; + + smmu = tegra241_cmdqv_probe(smmu, res, irq); + kfree(res); + return smmu; +} From patchwork Sun Jul 28 22:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 1965767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=jG5eTec7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-tegra+bounces-3116-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXGmG3LkHz1ybY for ; Mon, 29 Jul 2024 08:45:34 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9F4351F21A0C for ; Sun, 28 Jul 2024 22:45:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 259C8839F7; Sun, 28 Jul 2024 22:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="jG5eTec7" X-Original-To: linux-tegra@vger.kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2084.outbound.protection.outlook.com [40.107.93.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CDE980BF2; Sun, 28 Jul 2024 22:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206729; cv=fail; b=BVWQbKYIjLT+ysECxyRUeLrc5SCvCoETsrvWY83X0cN83O+KTrNYCOpJGTURFUfoRKBvAWnzVf944kYNaJq24G0TFGQvi1BJc8XM5vNHKF//679pez/0cFirpcno56JB7fbtM8Y8VZU1tpX9UwKtY7ZMA8j6uAYItR/a2e5ztRk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722206729; c=relaxed/simple; bh=Gfiuhf1x10vOfLqQFYGDJDpyMwXhX8B1cl0yt6Di5JM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N9PEdsGr0EbtFIhYackjbvHzlr5BX29ahLfArG4EGrOWnwLlOXbrX7YaS/Gs4bCnm2KNsc20bePqsmXohqSQKjPGDUGwTUZXwThnAFP00ZiDc/2rPWl8QfbaXoP6EyP0dH8x6d8u4+nALcaSUbHzjojA3ZnuSC7q8j3HpCOLQYM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=jG5eTec7; arc=fail smtp.client-ip=40.107.93.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PVCtArZ+4ogPJSx6EcmjmFagevdZWoihZFedPMkQspGILol+za7xoE5m/3rjBOvhwwq1DAfTBIGPW84sPL8b0IXc27qIXWJck8+FanJTTlbmuvu3g1CN43LXVnCgoYIpiHk8KuBrvhCEborIclugA8RnMyNkN86/Vv03Q0i4LC6LhvUfoKIxA8n2nzy8ClIuGDPNNQ1CSe372ble5xShf6O3cftsN98f5xmOiHSkB14N5Nwuyihrmp4yRA3HAE4hQuMRpbcvdjEOojkBy3HmdETeh38GpMmROXiqgQ9OIxZmluiN2dKv2ywMu+zwOh47JwcmohaGqU13FEAkTdiAsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=BNhySSY7sJdkTbpwdHnepRwQDVNL5WJN/z17jFv9MUw=; b=QvxhknOcJB1+xIyfwdOrIFzVKTvLNUKkIglO6fRWmn6uIoipF/RwY3Tpxg7S+XU01wGAml4jGSj5vVnwmmtB+E91Tpo8q4hL5m+bz4s+4qzMNDxJ4vkhzFAkStyvzC8+8LVQLbE3nERqp3CvUAKHcZKqrr8SjSLjluLYaNdd819pVG7q9COrqPmFLzHLRhv5n43yKd+IcdtlROQa22ca4mBD1D4AfxP5ZN5mkeqVJK9d7dvB2c/s+eHgKh1ArPJ+hTjAtk6irzkSgC6/10WEalgOYedNkZmc1y70o8w+2kIZf9kkQVOJKqQ4IEhxxSR5H8wPuhsDy9cJiwPLu4MzXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=BNhySSY7sJdkTbpwdHnepRwQDVNL5WJN/z17jFv9MUw=; b=jG5eTec7NaUPf9r/G4ZnxAiaoTUmE+zsavMW1Q5yWWic715H6CE3Skv1WfHJzsLkbCcO712BY1hl6FjOV4c9Hd56WAE7na0I3xKD1tJigjq525md66bS6789tpThIDz5lKI/1Mf9i8Y5NVs/EBVJi59JBPZKiP4kC5eS/kCf7iK6fI/p5A53b4KN7Jh2fL+YoxpUtaNaMRt/FZkkg4lUXuJxSbPURRFu4+ObBN0ao7OGoHeQ0GsKKrvoA875pmsxxoaEUqBhssY66KVybvkRTVxR1JZ/3CXFDI355vTwFZvntZy7mRC0Zx8Y0X3kdRvjyJ8iqFWsjGs9R2Gg7DbJyw== Received: from BL1PR13CA0100.namprd13.prod.outlook.com (2603:10b6:208:2b9::15) by SJ1PR12MB6028.namprd12.prod.outlook.com (2603:10b6:a03:489::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Sun, 28 Jul 2024 22:45:21 +0000 Received: from BL6PEPF00020E62.namprd04.prod.outlook.com (2603:10b6:208:2b9:cafe::19) by BL1PR13CA0100.outlook.office365.com (2603:10b6:208:2b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.28 via Frontend Transport; Sun, 28 Jul 2024 22:45:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL6PEPF00020E62.mail.protection.outlook.com (10.167.249.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.11 via Frontend Transport; Sun, 28 Jul 2024 22:45:20 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:12 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 28 Jul 2024 15:45:11 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Sun, 28 Jul 2024 15:45:10 -0700 From: Nicolin Chen To: CC: , , , , , , , , , Subject: [PATCH v10 9/9] iommu/tegra241-cmdqv: Limit CMDs for guest owned VINTF Date: Sun, 28 Jul 2024 15:44:54 -0700 Message-ID: <36795f48022361769fc22f15309299f92a415c54.1722206275.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-tegra@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E62:EE_|SJ1PR12MB6028:EE_ X-MS-Office365-Filtering-Correlation-Id: 796aa0ce-6b70-4cdc-b00d-08dcaf56f5a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: xpNgy9O1Tb/uyCq1rhABmlBuCon1NhRXwGbLEyNLw3nJi5gYPwUXkB0RLSb2YYqkMQo87vQ7JoW6JY2IQnvmBponC/4HRUNjASsnCbvXa0j3U5k2xJ/tpQTJpezg140WwCBjPLFF+TSQ6SUJhZb+U1kbxMDfnah07Xk2mA0LxwmjOZ4HaXjhEiCN3ggDz0JFFHduJfW/Ce8dyiEjwqXShF5O+cPapi8Re61p5Jv+iH1aj3YNoZxns86oYbk6MFWchEfMC89y31LepYg1FnsjpGaPchbFkWMjZM1uBIoHEo6I7gFIjbjogCQA9XhfjOZK61ONzFQ09EzhRImF/20naWLmzwfqiwPWz8rSyV1wbwfYMm4/YowgHunKuP30mo1KiG4UL6dwnTyMYHbO2Cblow+R/nPrMyzKf7O1x006oBIgMEpEhQdtNOkLcjYFx1MLAJ1GiFS1AmR+Po7V/QyHppatTAq+52jOaj7yZgH+ir8X1Uj+NTudlRO9wEZDT4H9qoqwh6Lx7QUxTjfCwudGS9y828svxWe3mmIaYyT8Z0yup2I/WyQf9AU9+klVZVcevUkEg7WlRIXa2QMtFh3NY7CQZphWYel9F2lahCwA6VCR53IPg+U5rAWmQ9UisvZs+5E8zG05JkVJNTb0LAAF7CIG9Xsf4oTBcdPJm1tIhT/mM0XIeu+sXkCBh8ubpoKAFG3Jk2CspH9LBGhgZweXczFDsrMgmgZl7Jw6zBotkOL7FXIA6DYHwzhT4EZjKQA64ThwUJ2rBfAI302WtE1iEEFWhQ94A5Nf/oLk4vQoK1Ry0J34Dl9KeZs0vpBb/MjVcBUpuOV4YodTOkb2i2oWdAOa0szCnAykoORvMEiU8lPaa84a9iS5PqdN1asttEn2NaQ1pWx0eXFFiXclU9KaNyP0aOc7g2f/6Anjf5IbgcHTYDcbDjSfkzgOr+tK4qo7J8rm9ogWtoj+x0jPd07hG9wyOQVbzh9JurTFJz5d5pR+Cga8STjo4LOmyIIIQsPqK6R4HJk4+w7GhDro+nUTgdIaTF0Khok6wPYNp8mukpvRXh5vOWzqRj1H/2DcawUNNT1GDld1kzqppOwQoRWdJDhE9BT7ihKhoSC7fApIpORIK+VlaA5GJREIY4vKMX215KuHSeGeieVc4Qh7HUg1GOikJawlU0zhnWB5MfFBHVMSWnubRySJsV0c7G3aisO3C3cUTbXX0htZHbxB5zGkRmwtgLR8HhJMyYC7zbj5QXP/+Bpvd6z8+mXFuSOTcYg6VtBbDrq+Lw92E9GeR8uB2uLtfRkkSZ4jtayr8Xz5/V9wXAVGA67sAtBhTLz0HD3zlzae3qjtoL1AobiafG7cdn/D7OHCK6UrdKSbpitkF7ajVcLVaxjD+x8LQPsQ1+uVTrRNvzIsfV64HXDY3Au/t24XBdU330X/pBifkKdnl1XCKgP1li1xlYE8XnOeiodA X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2024 22:45:20.1620 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 796aa0ce-6b70-4cdc-b00d-08dcaf56f5a4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6028 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 cmd to make sure it is supported when selecting a queue, though this assumes that SMMUv3 driver will only add the same type of commands into an arm_smmu_cmdq_batch as it does today. 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. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +- .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 35 ++++++++++++++++++- 3 files changed, 49 insertions(+), 11 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 18d940c65e2ca..8ff8e264d5e7c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -336,12 +336,13 @@ 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, + u8 opcode) { struct arm_smmu_cmdq *cmdq = NULL; if (smmu->impl && smmu->impl->get_secondary_cmdq) - cmdq = smmu->impl->get_secondary_cmdq(smmu); + cmdq = smmu->impl->get_secondary_cmdq(smmu, opcode); return cmdq ?: &smmu->cmdq; } @@ -889,7 +890,7 @@ static int __arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, } return arm_smmu_cmdq_issue_cmdlist( - smmu, arm_smmu_get_cmdq(smmu), cmd, 1, sync); + smmu, arm_smmu_get_cmdq(smmu, ent->opcode), cmd, 1, sync); } static int arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, @@ -905,10 +906,13 @@ static int arm_smmu_cmdq_issue_cmd_with_sync(struct arm_smmu_device *smmu, } static void arm_smmu_cmdq_batch_init(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq_batch *cmds) + struct arm_smmu_cmdq_batch *cmds, + u8 opcode) { + WARN_ON_ONCE(!opcode); + cmds->num = 0; - cmds->cmdq = arm_smmu_get_cmdq(smmu); + cmds->cmdq = arm_smmu_get_cmdq(smmu, opcode); } static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, @@ -1195,7 +1199,7 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, }, }; - arm_smmu_cmdq_batch_init(smmu, &cmds); + arm_smmu_cmdq_batch_init(smmu, &cmds, CMDQ_OP_CFGI_CD); for (i = 0; i < master->num_streams; i++) { cmd.cfgi.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); @@ -2046,7 +2050,7 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); - arm_smmu_cmdq_batch_init(master->smmu, &cmds); + arm_smmu_cmdq_batch_init(master->smmu, &cmds, CMDQ_OP_ATC_INV); for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; arm_smmu_cmdq_batch_add(master->smmu, &cmds, &cmd); @@ -2084,7 +2088,7 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!atomic_read(&smmu_domain->nr_ats_masters)) return 0; - arm_smmu_cmdq_batch_init(smmu_domain->smmu, &cmds); + arm_smmu_cmdq_batch_init(smmu_domain->smmu, &cmds, CMDQ_OP_ATC_INV); spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_for_each_entry(master_domain, &smmu_domain->devices, @@ -2166,7 +2170,7 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, num_pages++; } - arm_smmu_cmdq_batch_init(smmu, &cmds); + arm_smmu_cmdq_batch_init(smmu, &cmds, cmd->opcode); while (iova < end) { if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { 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 367f5e160af4e..c7f34a5c31f3f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -633,7 +633,8 @@ struct arm_smmu_strtab_cfg { struct arm_smmu_impl { int (*device_reset)(struct arm_smmu_device *smmu); void (*device_remove)(struct arm_smmu_device *smmu); - struct arm_smmu_cmdq *(*get_secondary_cmdq)(struct arm_smmu_device *smmu); + struct arm_smmu_cmdq *(*get_secondary_cmdq)(struct arm_smmu_device *smmu, + u8 opcode); }; #ifdef CONFIG_TEGRA241_CMDQV diff --git a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c index 891302fb20901..13c57a5fb758c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c +++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c @@ -143,6 +143,7 @@ struct tegra241_vcmdq { * struct tegra241_vintf - Virtual Interface * @idx: Global index in the CMDQV * @enabled: Enable status + * @hyp_own: Owned by hypervisor (in-kernel) * @cmdqv: Parent CMDQV pointer * @lvcmdqs: List of logical VCMDQ pointers * @base: MMIO base address @@ -151,6 +152,7 @@ struct tegra241_vintf { u16 idx; bool enabled; + bool hyp_own; struct tegra241_cmdqv *cmdqv; struct tegra241_vcmdq **lvcmdqs; @@ -300,8 +302,25 @@ static irqreturn_t tegra241_cmdqv_isr(int irq, void *devid) /* Command Queue Function */ +static bool tegra241_vintf_support_cmd(struct tegra241_vintf *vintf, u8 opcode) +{ + /* Hypervisor-owned VINTF can execute any command in its VCMDQs */ + if (READ_ONCE(vintf->hyp_own)) + return true; + + /* Guest-owned VINTF must check against the list of supported CMDs */ + switch (opcode) { + case CMDQ_OP_TLBI_NH_ASID: + case CMDQ_OP_TLBI_NH_VA: + case CMDQ_OP_ATC_INV: + return true; + default: + return false; + } +} + static struct arm_smmu_cmdq * -tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) +tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu, u8 opcode) { struct tegra241_cmdqv *cmdqv = container_of(smmu, struct tegra241_cmdqv, smmu); @@ -316,6 +335,10 @@ tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu) if (!READ_ONCE(vintf->enabled)) return NULL; + /* Unsupported CMD go for smmu->cmdq pathway */ + if (!tegra241_vintf_support_cmd(vintf, opcode)) + return NULL; + /* * Select a LVCMDQ to use. Here we use a temporal solution to * balance out traffic on cmdq issuing: each cmdq has its own @@ -405,12 +428,22 @@ static int tegra241_vintf_hw_init(struct tegra241_vintf *vintf, bool hyp_own) tegra241_vintf_hw_deinit(vintf); /* Configure and enable VINTF */ + /* + * Note that HYP_OWN bit is wired to zero when running in guest kernel, + * whether enabling it here or not, as !HYP_OWN cmdq HWs only support a + * restricted set of supported commands. + */ regval = FIELD_PREP(VINTF_HYP_OWN, hyp_own); writel(regval, REG_VINTF(vintf, CONFIG)); ret = vintf_write_config(vintf, regval | VINTF_EN); if (ret) return ret; + /* + * 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 = !!(VINTF_HYP_OWN & readl(REG_VINTF(vintf, CONFIG))); for (lidx = 0; lidx < vintf->cmdqv->num_lvcmdqs_per_vintf; lidx++) { if (vintf->lvcmdqs && vintf->lvcmdqs[lidx]) {