Skip to content

Commit 1c608b0

Browse files
sarunkodjoergroedel
authored andcommitted
iommu/amd: Introduce generic function to set multibit feature value
Define generic function `iommu_feature_set()` to set the values in the feature control register and replace `iommu_set_inv_tlb_timeout()` with it. Signed-off-by: Sairaj Kodilkar <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 6255868 commit 1c608b0

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
#define CONTROL_IRTCACHEDIS 59
182182
#define CONTROL_SNPAVIC_EN 61
183183

184-
#define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT)
184+
#define CTRL_INV_TO_MASK 7
185185
#define CTRL_INV_TO_NONE 0
186186
#define CTRL_INV_TO_1MS 1
187187
#define CTRL_INV_TO_10MS 2

drivers/iommu/amd/init.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -411,33 +411,26 @@ static void iommu_set_device_table(struct amd_iommu *iommu)
411411
&entry, sizeof(entry));
412412
}
413413

414-
/* Generic functions to enable/disable certain features of the IOMMU. */
415-
void iommu_feature_enable(struct amd_iommu *iommu, u8 bit)
414+
static void iommu_feature_set(struct amd_iommu *iommu, u64 val, u64 mask, u8 shift)
416415
{
417416
u64 ctrl;
418417

419418
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
420-
ctrl |= (1ULL << bit);
419+
mask <<= shift;
420+
ctrl &= ~mask;
421+
ctrl |= (val << shift) & mask;
421422
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
422423
}
423424

424-
static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit)
425+
/* Generic functions to enable/disable certain features of the IOMMU. */
426+
void iommu_feature_enable(struct amd_iommu *iommu, u8 bit)
425427
{
426-
u64 ctrl;
427-
428-
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
429-
ctrl &= ~(1ULL << bit);
430-
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
428+
iommu_feature_set(iommu, 1ULL, 1ULL, bit);
431429
}
432430

433-
static void iommu_set_inv_tlb_timeout(struct amd_iommu *iommu, int timeout)
431+
static void iommu_feature_disable(struct amd_iommu *iommu, u8 bit)
434432
{
435-
u64 ctrl;
436-
437-
ctrl = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
438-
ctrl &= ~CTRL_INV_TO_MASK;
439-
ctrl |= (timeout << CONTROL_INV_TIMEOUT) & CTRL_INV_TO_MASK;
440-
writeq(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
433+
iommu_feature_set(iommu, 0ULL, 1ULL, bit);
441434
}
442435

443436
/* Function to enable the hardware */
@@ -2651,7 +2644,7 @@ static void iommu_init_flags(struct amd_iommu *iommu)
26512644
iommu_feature_enable(iommu, CONTROL_COHERENT_EN);
26522645

26532646
/* Set IOTLB invalidation timeout to 1s */
2654-
iommu_set_inv_tlb_timeout(iommu, CTRL_INV_TO_1S);
2647+
iommu_feature_set(iommu, CTRL_INV_TO_1S, CTRL_INV_TO_MASK, CONTROL_INV_TIMEOUT);
26552648

26562649
/* Enable Enhanced Peripheral Page Request Handling */
26572650
if (check_feature(FEATURE_EPHSUP))

0 commit comments

Comments
 (0)