[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250728175316.3706196-23-smostafa@google.com>
Date: Mon, 28 Jul 2025 17:53:09 +0000
From: Mostafa Saleh <smostafa@...gle.com>
To: linux-kernel@...r.kernel.org, kvmarm@...ts.linux.dev,
linux-arm-kernel@...ts.infradead.org, iommu@...ts.linux.dev
Cc: maz@...nel.org, oliver.upton@...ux.dev, joey.gouly@....com,
suzuki.poulose@....com, yuzenghui@...wei.com, catalin.marinas@....com,
will@...nel.org, robin.murphy@....com, jean-philippe@...aro.org,
qperret@...gle.com, tabba@...gle.com, jgg@...pe.ca, mark.rutland@....com,
praan@...gle.com, Mostafa Saleh <smostafa@...gle.com>
Subject: [PATCH v3 22/29] iommu/arm-smmu-v3-kvm: Reset the device
From: Jean-Philippe Brucker <jean-philippe@...aro.org>
Now that all structures are initialized, send global invalidations and
reset the SMMUv3 device.
Signed-off-by: Jean-Philippe Brucker <jean-philippe@...aro.org>
Signed-off-by: Mostafa Saleh <smostafa@...gle.com>
---
.../iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c
index 74e6dfb53528..5e988ffede92 100644
--- a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c
@@ -301,6 +301,40 @@ static int smmu_init_strtab(struct hyp_arm_smmu_v3_device *smmu)
strtab_size >> PAGE_SHIFT, prot);
}
+static int smmu_reset_device(struct hyp_arm_smmu_v3_device *smmu)
+{
+ int ret;
+ struct arm_smmu_cmdq_ent cfgi_cmd = {
+ .opcode = CMDQ_OP_CFGI_ALL,
+ };
+ struct arm_smmu_cmdq_ent tlbi_cmd = {
+ .opcode = CMDQ_OP_TLBI_NSNH_ALL,
+ };
+
+ /* Invalidate all cached configs and TLBs */
+ ret = smmu_write_cr0(smmu, CR0_CMDQEN);
+ if (ret)
+ return ret;
+
+ ret = smmu_add_cmd(smmu, &cfgi_cmd);
+ if (ret)
+ goto err_disable_cmdq;
+
+ ret = smmu_add_cmd(smmu, &tlbi_cmd);
+ if (ret)
+ goto err_disable_cmdq;
+
+ ret = smmu_sync_cmd(smmu);
+ if (ret)
+ goto err_disable_cmdq;
+
+ /* Enable translation */
+ return smmu_write_cr0(smmu, CR0_SMMUEN | CR0_CMDQEN | CR0_ATSCHK);
+
+err_disable_cmdq:
+ return smmu_write_cr0(smmu, 0);
+}
+
static int smmu_init_device(struct hyp_arm_smmu_v3_device *smmu)
{
int i;
@@ -333,6 +367,9 @@ static int smmu_init_device(struct hyp_arm_smmu_v3_device *smmu)
if (ret)
goto out_err;
+ ret = smmu_reset_device(smmu);
+ if (ret)
+ goto out_err;
return ret;
out_err:
--
2.50.1.552.g942d659e1b-goog
Powered by blists - more mailing lists