@@ -411,33 +411,26 @@ static void iommu_set_device_table(struct amd_iommu *iommu)
411
411
& entry , sizeof (entry ));
412
412
}
413
413
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 )
416
415
{
417
416
u64 ctrl ;
418
417
419
418
ctrl = readq (iommu -> mmio_base + MMIO_CONTROL_OFFSET );
420
- ctrl |= (1ULL << bit );
419
+ mask <<= shift ;
420
+ ctrl &= ~mask ;
421
+ ctrl |= (val << shift ) & mask ;
421
422
writeq (ctrl , iommu -> mmio_base + MMIO_CONTROL_OFFSET );
422
423
}
423
424
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 )
425
427
{
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 );
431
429
}
432
430
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 )
434
432
{
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 );
441
434
}
442
435
443
436
/* Function to enable the hardware */
@@ -2651,7 +2644,7 @@ static void iommu_init_flags(struct amd_iommu *iommu)
2651
2644
iommu_feature_enable (iommu , CONTROL_COHERENT_EN );
2652
2645
2653
2646
/* 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 );
2655
2648
2656
2649
/* Enable Enhanced Peripheral Page Request Handling */
2657
2650
if (check_feature (FEATURE_EPHSUP ))
0 commit comments