AMD/IOMMU: add helper to check whether ATS is to be used for a device

The same set of conditions is used in three places, requiring to be kept
in sync. Introduce a helper to centralize these checks.

To allow all parameters of the new helper be pointer-to-const,
iommu_has_cap() also needs its 1st parameter to be constified. Beyond
that further "modernize" that function.

Requested-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
This commit is contained in:
Jan Beulich committed 2024-05-06 14:52:48 +02:00
1 parent b5996ab284
commit d7032b4ca2
2 files changed
+15 -11

No files matched your search

+2 -2
View File
@@ -341,9 +341,9 @@ static inline void __free_amd_iommu_tables(void *table, unsigned int order)
free_xenheap_pages(table, order);
}
static inline int iommu_has_cap(struct amd_iommu *iommu, uint32_t bit)
static inline bool iommu_has_cap(const struct amd_iommu *iommu, unsigned int bit)
{
return !!(iommu->cap.header & (1u << bit));
return iommu->cap.header & (1u << bit);
}
/* access device id field from iommu cmd */
+13 -9
View File
@@ -114,6 +114,16 @@ static bool any_pdev_behind_iommu(const struct domain *d,
return false;
}
static bool use_ats(
const struct pci_dev *pdev,
const struct amd_iommu *iommu,
const struct ivrs_mappings *ivrs_dev)
{
return !ivrs_dev->block_ats &&
iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) &&
pci_ats_device(iommu->seg, pdev->bus, pdev->devfn);
}
static int __must_check amd_iommu_setup_domain_device(
struct domain *domain, struct amd_iommu *iommu,
uint8_t devfn, struct pci_dev *pdev)
@@ -185,9 +195,7 @@ static int __must_check amd_iommu_setup_domain_device(
dte->ex = ivrs_dev->dte_allow_exclusion;
dte->sys_mgt = MASK_EXTR(ivrs_dev->device_flags, ACPI_IVHD_SYSTEM_MGMT);
if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&
!ivrs_dev->block_ats &&
iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) )
if ( use_ats(pdev, iommu, ivrs_dev) )
dte->i = ats_enabled;
spin_unlock_irqrestore(&iommu->lock, flags);
@@ -248,9 +256,7 @@ static int __must_check amd_iommu_setup_domain_device(
ASSERT(dte->sys_mgt == MASK_EXTR(ivrs_dev->device_flags,
ACPI_IVHD_SYSTEM_MGMT));
if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&
!ivrs_dev->block_ats &&
iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) )
if ( use_ats(pdev, iommu, ivrs_dev) )
ASSERT(dte->i == ats_enabled);
spin_unlock_irqrestore(&iommu->lock, flags);
@@ -268,9 +274,7 @@ static int __must_check amd_iommu_setup_domain_device(
ASSERT(pcidevs_locked());
if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&
!ivrs_dev->block_ats &&
iommu_has_cap(iommu, PCI_CAP_IOTLB_SHIFT) &&
if ( use_ats(pdev, iommu, ivrs_dev) &&
!pci_ats_enabled(iommu->seg, bus, pdev->devfn) )
{
if ( devfn == pdev->devfn )
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.