Skip to content

Commit 2c78e74

Browse files
nicolincjgunthorpe
authored andcommitted
iommu/arm-smmu-v3: Replace vsmmu_size/type with get_viommu_size
It's more flexible to have a get_viommu_size op. Replace static vsmmu_size and vsmmu_type with that. Link: https://patch.msgid.link/r/[email protected] Suggested-by: Will Deacon <[email protected]> Acked-by: Will Deacon <[email protected]> Reviewed-by: Pranjal Shrivastava <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 5a1c759 commit 2c78e74

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,9 @@ size_t arm_smmu_get_viommu_size(struct device *dev,
423423
if (viommu_type == IOMMU_VIOMMU_TYPE_ARM_SMMUV3)
424424
return VIOMMU_STRUCT_SIZE(struct arm_vsmmu, core);
425425

426-
if (!smmu->impl_ops || !smmu->impl_ops->vsmmu_size ||
427-
viommu_type != smmu->impl_ops->vsmmu_type)
426+
if (!smmu->impl_ops || !smmu->impl_ops->get_viommu_size)
428427
return 0;
429-
return smmu->impl_ops->vsmmu_size;
428+
return smmu->impl_ops->get_viommu_size(viommu_type);
430429
}
431430

432431
int arm_vsmmu_init(struct iommufd_viommu *viommu,
@@ -451,12 +450,6 @@ int arm_vsmmu_init(struct iommufd_viommu *viommu,
451450
return 0;
452451
}
453452

454-
/*
455-
* Unsupported type should be rejected by arm_smmu_get_viommu_size.
456-
* Seeing one here indicates a kernel bug or some data corruption.
457-
*/
458-
if (WARN_ON(viommu->type != smmu->impl_ops->vsmmu_type))
459-
return -EOPNOTSUPP;
460453
return smmu->impl_ops->vsmmu_init(vsmmu, user_data);
461454
}
462455

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4716,8 +4716,8 @@ static struct arm_smmu_device *arm_smmu_impl_probe(struct arm_smmu_device *smmu)
47164716

47174717
ops = new_smmu->impl_ops;
47184718
if (ops) {
4719-
/* vsmmu_size and vsmmu_init ops must be paired */
4720-
if (WARN_ON(!ops->vsmmu_size != !ops->vsmmu_init)) {
4719+
/* get_viommu_size and vsmmu_init ops must be paired */
4720+
if (WARN_ON(!ops->get_viommu_size != !ops->vsmmu_init)) {
47214721
ret = -EINVAL;
47224722
goto err_remove;
47234723
}

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,7 @@ struct arm_smmu_impl_ops {
728728
*/
729729
void *(*hw_info)(struct arm_smmu_device *smmu, u32 *length,
730730
enum iommu_hw_info_type *type);
731-
const size_t vsmmu_size;
732-
const enum iommu_viommu_type vsmmu_type;
731+
size_t (*get_viommu_size)(enum iommu_viommu_type viommu_type);
733732
int (*vsmmu_init)(struct arm_vsmmu *vsmmu,
734733
const struct iommu_user_data *user_data);
735734
};

drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,15 +832,21 @@ static void *tegra241_cmdqv_hw_info(struct arm_smmu_device *smmu, u32 *length,
832832
return info;
833833
}
834834

835+
static size_t tegra241_cmdqv_get_vintf_size(enum iommu_viommu_type viommu_type)
836+
{
837+
if (viommu_type != IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV)
838+
return 0;
839+
return VIOMMU_STRUCT_SIZE(struct tegra241_vintf, vsmmu.core);
840+
}
841+
835842
static struct arm_smmu_impl_ops tegra241_cmdqv_impl_ops = {
836843
/* For in-kernel use */
837844
.get_secondary_cmdq = tegra241_cmdqv_get_cmdq,
838845
.device_reset = tegra241_cmdqv_hw_reset,
839846
.device_remove = tegra241_cmdqv_remove,
840847
/* For user-space use */
841848
.hw_info = tegra241_cmdqv_hw_info,
842-
.vsmmu_size = VIOMMU_STRUCT_SIZE(struct tegra241_vintf, vsmmu.core),
843-
.vsmmu_type = IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV,
849+
.get_viommu_size = tegra241_cmdqv_get_vintf_size,
844850
.vsmmu_init = tegra241_cmdqv_init_vintf_user,
845851
};
846852

@@ -1273,6 +1279,13 @@ tegra241_cmdqv_init_vintf_user(struct arm_vsmmu *vsmmu,
12731279
phys_addr_t page0_base;
12741280
int ret;
12751281

1282+
/*
1283+
* Unsupported type should be rejected by tegra241_cmdqv_get_vintf_size.
1284+
* Seeing one here indicates a kernel bug or some data corruption.
1285+
*/
1286+
if (WARN_ON(vsmmu->core.type != IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV))
1287+
return -EOPNOTSUPP;
1288+
12761289
if (!user_data)
12771290
return -EINVAL;
12781291

0 commit comments

Comments
 (0)