BACKPORT: FROMLIST: KVM: arm64: smmu-v3: Reset the device

Now that all structures are initialized, send global invalidations and
reset the SMMUv3 device.

Link: https://lore.kernel.org/all/20241212180423.1578358-31-smostafa@google.com/

Bug: 357781595
Bug: 384432312

Change-Id: Ifa9925d5cc1a75b2cf5599128c9e490cc5a7d219
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Mostafa Saleh <smostafa@google.com>
This commit is contained in:
Jean-Philippe Brucker
2024-12-12 18:03:54 +00:00
committed by Mostafa Saleh
parent 4b3a037eea
commit a979ffaf14
@@ -446,6 +446,40 @@ static int smmu_init_strtab(struct hyp_arm_smmu_v3_device *smmu)
return 0;
}
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 ret;
@@ -477,6 +511,10 @@ static int smmu_init_device(struct hyp_arm_smmu_v3_device *smmu)
if (ret)
return ret;
ret = smmu_reset_device(smmu);
if (ret)
return ret;
return kvm_iommu_init_device(&smmu->iommu);
}