Skip to content

Commit e339b51

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Modify logic for checking GT and PPR features
In order to support v2 page table, IOMMU driver need to check if the hardware can support Guest Translation (GT) and Peripheral Page Request (PPR) features. Currently, IOMMU driver uses global (amd_iommu_v2_present) and per-iommu (struct amd_iommu.is_iommu_v2) variables to track the features. There variables area redundant since we could simply just check the global EFR mask. Therefore, replace it with a helper function with appropriate name. Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Co-developed-by: Vasant Hegde <vasant.hegde@amd.com> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Link: https://lore.kernel.org/r/20230921092147.5930-10-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 7b7563a commit e339b51

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ static inline int check_feature_gpt_level(void)
102102
return ((amd_iommu_efr >> FEATURE_GATS_SHIFT) & FEATURE_GATS_MASK);
103103
}
104104

105+
static inline bool amd_iommu_gt_ppr_supported(void)
106+
{
107+
return (check_feature(FEATURE_GT) &&
108+
check_feature(FEATURE_PPR));
109+
}
110+
105111
static inline u64 iommu_virt_to_phys(void *vaddr)
106112
{
107113
return (u64)__sme_set(virt_to_phys(vaddr));

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,6 @@ struct amd_iommu {
679679
/* Extended features 2 */
680680
u64 features2;
681681

682-
/* IOMMUv2 */
683-
bool is_iommu_v2;
684-
685682
/* PCI device id of the IOMMU device */
686683
u16 devid;
687684

@@ -890,8 +887,6 @@ extern unsigned long *amd_iommu_pd_alloc_bitmap;
890887
/* Smallest max PASID supported by any IOMMU in the system */
891888
extern u32 amd_iommu_max_pasid;
892889

893-
extern bool amd_iommu_v2_present;
894-
895890
extern bool amd_iommu_force_isolation;
896891

897892
/* Max levels of glxval supported */

drivers/iommu/amd/init.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ bool amd_iommu_iotlb_sup __read_mostly = true;
187187

188188
u32 amd_iommu_max_pasid __read_mostly = ~0;
189189

190-
bool amd_iommu_v2_present __read_mostly;
191190
static bool amd_iommu_pc_present __read_mostly;
192191
bool amdr_ivrs_remap_support __read_mostly;
193192

@@ -2101,12 +2100,6 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
21012100
amd_iommu_max_glx_val = min(amd_iommu_max_glx_val, glxval);
21022101
}
21032102

2104-
if (check_feature(FEATURE_GT) &&
2105-
check_feature(FEATURE_PPR)) {
2106-
iommu->is_iommu_v2 = true;
2107-
amd_iommu_v2_present = true;
2108-
}
2109-
21102103
if (check_feature(FEATURE_PPR) && alloc_ppr_log(iommu))
21112104
return -ENOMEM;
21122105

@@ -3676,7 +3669,7 @@ bool amd_iommu_v2_supported(void)
36763669
* (i.e. EFR[SNPSup]=1), IOMMUv2 page table cannot be used without
36773670
* setting up IOMMUv1 page table.
36783671
*/
3679-
return amd_iommu_v2_present && !amd_iommu_snp_en;
3672+
return amd_iommu_gt_ppr_supported() && !amd_iommu_snp_en;
36803673
}
36813674
EXPORT_SYMBOL(amd_iommu_v2_supported);
36823675

drivers/iommu/amd/iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static int iommu_init_device(struct amd_iommu *iommu, struct device *dev)
397397
*/
398398
if ((iommu_default_passthrough() || !amd_iommu_force_isolation) &&
399399
dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) {
400-
dev_data->iommu_v2 = iommu->is_iommu_v2;
400+
dev_data->iommu_v2 = amd_iommu_gt_ppr_supported();
401401
}
402402

403403
dev_iommu_priv_set(dev, dev_data);

0 commit comments

Comments
 (0)