From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B256DCD5BD1 for ; Mon, 1 Jun 2026 21:59:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UiMB5GJ3G5FDErhVSMyBY6oKC/dH+Rh8Dxtui0QM9OY=; b=YESV861bxps1WRCekpXErYPX8B aTsra92KM46UYGWjTxTlY6IDzBzbAFKqEGvIIDZV5ipqgpUcutU4ReLdYSCtTVKy77ZjgBWG1ynts ceAzY/PxT57jvB5jYG5ddtpe8iAsGUZbdoPx/GWCi23r4uFO0c4bIAXu4apa745LzI/bijwuyuUR1 G3KZQrEr71YfPW1iF37tvxTnDSvSXO+kl5r7fcpBOMRbWhQE3LWTjuLwvurbfIjnfpjeDRjnLXwxT RLwdWI34lDYP0aG7qlvrdprgU+M4ybskLZPGES2Wre62Cs9haeg6Oah1V0isza57SuAAbUAl/FBFt 5lyTACVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wUAfK-0000000BtGy-0HyA; Mon, 01 Jun 2026 21:59:22 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wUAfH-0000000BtFo-3pQF for linux-arm-kernel@lists.infradead.org; Mon, 01 Jun 2026 21:59:21 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-c857fa2706aso1442240a12.2 for ; Mon, 01 Jun 2026 14:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780351158; x=1780955958; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UiMB5GJ3G5FDErhVSMyBY6oKC/dH+Rh8Dxtui0QM9OY=; b=ZmZFQNsTr5bH4G9W1i0cA5yDG78lOXrFzGYD7e41+3IT/o6hIuLWHvdQ/LIjkCLMVP Y2yTgNNFJ6Wn8TpGGFYHStuGABhuDWSI6FvDcODcSHDfKwhhUDalj+bT+Q/9HUkXYQGB Pf6bSzLS6A8Mbr6PTWWrw5/ySBNKvDa62pMMzVwFdkrUynvQ/Mrr3MAuVxnnCsUXrf08 weL3dhy0V3bZF1YjJ07oOXcdONyWoapjJpo1aPTsrw/Nt2oRPRU/uPVTkEWccFFxN/v4 KEubU+NpjI3kTJY42wYybR92peC5ogHDm6VaLd707qcu+Y22BDjFT3GO3Sf0x6ADxKmf e09Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780351158; x=1780955958; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UiMB5GJ3G5FDErhVSMyBY6oKC/dH+Rh8Dxtui0QM9OY=; b=A8ZSmBKtuG+RXQ8EEnbQGj9E6LgiBHfWlnKysBjALLzOCanKpR+yFY7SnvwHABTU1r h4oItpoDABu0A2K2TNehtvXc7zCN235RNeTKQq5rWwdLyBm79HRr475k4B7qF33jDQaz TLPfqZcyOW+jFMMeq/gb5ydHNwyTGiCKRANdcx9eOrY+ra9JgprA0GCEPmkadsz6TbFK xLs0b16bFhnPsmgmtF2WND6sw6Ircn2mxgnyUaY8qFSzYR16XQd1BOfpQFgDm+TZ1w7C ubpmLZdIKurcOJz3yYSCX1w60dpLIkJefuVlIOk6D0wiw2pPJDAkD5fcuFJ6p4Obmhsj hS4Q== X-Forwarded-Encrypted: i=1; AFNElJ/Nj+4lwEIrlo8LF29Xcc/KTrbN16A68cTNIfwCslwKSXZxqTJnd8Tb283bKgGudQoX2XIIPh5lfBdS3Dv+fBbK@lists.infradead.org X-Gm-Message-State: AOJu0Yz8UNGy84MoznguZau+EMq3ko+Ylmx38jaNpNokg7dtJ1FS34CM jfuUtMric6QdyfXC17Zz1n5tae+jYyeFJXOGI2oM9/XIEyBmaulim9Tu1edzxKOXJqsS0kRDiLG icg== X-Received: from pgcl27.prod.google.com ([2002:a63:701b:0:b0:c85:104d:a751]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a96:b0:3b1:884a:c3d5 with SMTP id adf61e73a8af0-3b42823a975mr14463013637.24.1780351158251; Mon, 01 Jun 2026 14:59:18 -0700 (PDT) Date: Mon, 1 Jun 2026 21:59:00 +0000 In-Reply-To: <20260601215909.3958732-1-praan@google.com> Mime-Version: 1.0 References: <20260601215909.3958732-1-praan@google.com> X-Mailer: git-send-email 2.54.0.1013.g208068f2d8-goog Message-ID: <20260601215909.3958732-4-praan@google.com> Subject: [PATCH v8 03/12] iommu/tegra241-cmdqv: Add a helper to drain VCMDQs From: Pranjal Shrivastava To: iommu@lists.linux.dev Cc: Will Deacon , Joerg Roedel , Robin Murphy , Jason Gunthorpe , Mostafa Saleh , Nicolin Chen , Daniel Mentz , Ashish Mhetre , linux-arm-kernel@lists.infradead.org, Pranjal Shrivastava Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260601_145919_953965_A50BC9E8 X-CRM114-Status: GOOD ( 18.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The tegra241-cmdqv driver supports vCMDQs which need to be drained before suspending the SMMU. The current driver implementation only uses VINTF0 for vCMDQs owned by the kernel which need to be drained. Add a helper that drains all the enabled vCMDQs under VINTF0. Add another function ptr to arm_smmu_impl_ops to drain implementation specified queues and call it within `arm_smmu_drain_queues`. Reviewed-by: Nicolin Chen Signed-off-by: Pranjal Shrivastava --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 +++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+) 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 0e77ef1e4523..8682be5060ed 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -915,6 +915,13 @@ static int arm_smmu_drain_queues(struct arm_smmu_device *smmu) */ ret = arm_smmu_queue_poll_until_empty(smmu, &smmu->cmdq.q); + if (ret) + goto out; + + /* Drain all implementation-specific queues */ + if (smmu->impl_ops && smmu->impl_ops->drain_queues) + ret = smmu->impl_ops->drain_queues(smmu); +out: return ret; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index c855ab4962ed..24d5e28eea88 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -885,6 +885,7 @@ struct arm_smmu_impl_ops { size_t (*get_viommu_size)(enum iommu_viommu_type viommu_type); int (*vsmmu_init)(struct arm_vsmmu *vsmmu, const struct iommu_user_data *user_data); + int (*drain_queues)(struct arm_smmu_device *smmu); }; /* An SMMUv3 instance */ diff --git a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c index 67be62a6e764..cb1e75e4ee91 100644 --- a/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c +++ b/drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c @@ -414,6 +414,32 @@ tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu, return &vcmdq->cmdq; } +static int tegra241_cmdqv_drain_vintf0_lvcmdqs(struct arm_smmu_device *smmu) +{ + struct tegra241_cmdqv *cmdqv = + container_of(smmu, struct tegra241_cmdqv, smmu); + struct tegra241_vintf *vintf = cmdqv->vintfs[0]; + int ret = 0; + u16 lidx; + + /* Kernel only uses VINTF0. Return if it's disabled */ + if (!READ_ONCE(vintf->enabled)) + return 0; + + for (lidx = 0; lidx < cmdqv->num_lvcmdqs_per_vintf; lidx++) { + struct tegra241_vcmdq *vcmdq = vintf->lvcmdqs[lidx]; + + if (!vcmdq || !READ_ONCE(vcmdq->enabled)) + continue; + + ret = arm_smmu_queue_poll_until_empty(smmu, &vcmdq->cmdq.q); + if (ret) + break; + } + + return ret; +} + /* HW Reset Functions */ /* @@ -845,6 +871,7 @@ static struct arm_smmu_impl_ops tegra241_cmdqv_impl_ops = { .get_secondary_cmdq = tegra241_cmdqv_get_cmdq, .device_reset = tegra241_cmdqv_hw_reset, .device_remove = tegra241_cmdqv_remove, + .drain_queues = tegra241_cmdqv_drain_vintf0_lvcmdqs, /* For user-space use */ .hw_info = tegra241_cmdqv_hw_info, .get_viommu_size = tegra241_cmdqv_get_vintf_size, -- 2.54.0.1013.g208068f2d8-goog