Skip to content

Commit 014e756

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Update PASID, GATS, GLX, SNPAVICSUP feature related macros
Clean up and reorder them according to the bit index. There is no functional change. Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Suravee Suthikulpanit <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent e5e5cc8 commit 014e756

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ static inline bool check_feature2(u64 mask)
121121
return (amd_iommu_efr2 & mask);
122122
}
123123

124-
static inline int check_feature_gpt_level(void)
125-
{
126-
return ((amd_iommu_efr >> FEATURE_GATS_SHIFT) & FEATURE_GATS_MASK);
127-
}
128-
129124
static inline bool amd_iommu_gt_ppr_supported(void)
130125
{
131126
return (check_feature(FEATURE_GT) &&

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef _ASM_X86_AMD_IOMMU_TYPES_H
99
#define _ASM_X86_AMD_IOMMU_TYPES_H
1010

11+
#include <linux/bitfield.h>
1112
#include <linux/iommu.h>
1213
#include <linux/types.h>
1314
#include <linux/mmu_notifier.h>
@@ -95,26 +96,21 @@
9596
#define FEATURE_GA BIT_ULL(7)
9697
#define FEATURE_HE BIT_ULL(8)
9798
#define FEATURE_PC BIT_ULL(9)
98-
#define FEATURE_GATS_SHIFT (12)
99-
#define FEATURE_GATS_MASK (3ULL)
99+
#define FEATURE_GATS GENMASK_ULL(13, 12)
100+
#define FEATURE_GLX GENMASK_ULL(15, 14)
100101
#define FEATURE_GAM_VAPIC BIT_ULL(21)
102+
#define FEATURE_PASMAX GENMASK_ULL(36, 32)
101103
#define FEATURE_GIOSUP BIT_ULL(48)
102104
#define FEATURE_HASUP BIT_ULL(49)
103105
#define FEATURE_EPHSUP BIT_ULL(50)
104106
#define FEATURE_HDSUP BIT_ULL(52)
105107
#define FEATURE_SNP BIT_ULL(63)
106108

107-
#define FEATURE_PASID_SHIFT 32
108-
#define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT)
109-
110-
#define FEATURE_GLXVAL_SHIFT 14
111-
#define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT)
112109

113110
/* Extended Feature 2 Bits */
114-
#define FEATURE_SNPAVICSUP_SHIFT 5
115-
#define FEATURE_SNPAVICSUP_MASK (0x07ULL << FEATURE_SNPAVICSUP_SHIFT)
111+
#define FEATURE_SNPAVICSUP GENMASK_ULL(7, 5)
116112
#define FEATURE_SNPAVICSUP_GAM(x) \
117-
((x & FEATURE_SNPAVICSUP_MASK) >> FEATURE_SNPAVICSUP_SHIFT == 0x1)
113+
(FIELD_GET(FEATURE_SNPAVICSUP, x) == 0x1)
118114

119115
/* Note:
120116
* The current driver only support 16-bit PASID.

drivers/iommu/amd/init.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,14 +2042,12 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
20422042
int glxval;
20432043
u64 pasmax;
20442044

2045-
pasmax = amd_iommu_efr & FEATURE_PASID_MASK;
2046-
pasmax >>= FEATURE_PASID_SHIFT;
2045+
pasmax = FIELD_GET(FEATURE_PASMAX, amd_iommu_efr);
20472046
iommu->iommu.max_pasids = (1 << (pasmax + 1)) - 1;
20482047

20492048
BUG_ON(iommu->iommu.max_pasids & ~PASID_MASK);
20502049

2051-
glxval = amd_iommu_efr & FEATURE_GLXVAL_MASK;
2052-
glxval >>= FEATURE_GLXVAL_SHIFT;
2050+
glxval = FIELD_GET(FEATURE_GLX, amd_iommu_efr);
20532051

20542052
if (amd_iommu_max_glx_val == -1)
20552053
amd_iommu_max_glx_val = glxval;
@@ -3088,7 +3086,7 @@ static int __init early_amd_iommu_init(void)
30883086

30893087
/* 5 level guest page table */
30903088
if (cpu_feature_enabled(X86_FEATURE_LA57) &&
3091-
check_feature_gpt_level() == GUEST_PGTABLE_5_LEVEL)
3089+
FIELD_GET(FEATURE_GATS, amd_iommu_efr) == GUEST_PGTABLE_5_LEVEL)
30923090
amd_iommu_gpt_level = PAGE_MODE_5_LEVEL;
30933091

30943092
/* Disable any previously enabled IOMMUs */

0 commit comments

Comments
 (0)