Skip to content

Commit f273a45

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Add device_def_domain_type() helper
This helper returns the default domain type that the device requires. Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent d8190dc commit f273a45

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,29 +2930,37 @@ static bool device_is_rmrr_locked(struct device *dev)
29302930
return true;
29312931
}
29322932

2933-
static int iommu_should_identity_map(struct device *dev, int startup)
2933+
/*
2934+
* Return the required default domain type for a specific device.
2935+
*
2936+
* @dev: the device in query
2937+
* @startup: true if this is during early boot
2938+
*
2939+
* Returns:
2940+
* - IOMMU_DOMAIN_DMA: device requires a dynamic mapping domain
2941+
* - IOMMU_DOMAIN_IDENTITY: device requires an identical mapping domain
2942+
* - 0: both identity and dynamic domains work for this device
2943+
*/
2944+
static int device_def_domain_type(struct device *dev, int startup)
29342945
{
29352946
if (dev_is_pci(dev)) {
29362947
struct pci_dev *pdev = to_pci_dev(dev);
29372948

29382949
if (device_is_rmrr_locked(dev))
2939-
return 0;
2950+
return IOMMU_DOMAIN_DMA;
29402951

29412952
/*
29422953
* Prevent any device marked as untrusted from getting
29432954
* placed into the statically identity mapping domain.
29442955
*/
29452956
if (pdev->untrusted)
2946-
return 0;
2957+
return IOMMU_DOMAIN_DMA;
29472958

29482959
if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev))
2949-
return 1;
2960+
return IOMMU_DOMAIN_IDENTITY;
29502961

29512962
if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
2952-
return 1;
2953-
2954-
if (!(iommu_identity_mapping & IDENTMAP_ALL))
2955-
return 0;
2963+
return IOMMU_DOMAIN_IDENTITY;
29562964

29572965
/*
29582966
* We want to start off with all devices in the 1:1 domain, and
@@ -2973,14 +2981,14 @@ static int iommu_should_identity_map(struct device *dev, int startup)
29732981
*/
29742982
if (!pci_is_pcie(pdev)) {
29752983
if (!pci_is_root_bus(pdev->bus))
2976-
return 0;
2984+
return IOMMU_DOMAIN_DMA;
29772985
if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI)
2978-
return 0;
2986+
return IOMMU_DOMAIN_DMA;
29792987
} else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE)
2980-
return 0;
2988+
return IOMMU_DOMAIN_DMA;
29812989
} else {
29822990
if (device_has_rmrr(dev))
2983-
return 0;
2991+
return IOMMU_DOMAIN_DMA;
29842992
}
29852993

29862994
/*
@@ -3002,7 +3010,13 @@ static int iommu_should_identity_map(struct device *dev, int startup)
30023010
return dma_mask >= dma_get_required_mask(dev);
30033011
}
30043012

3005-
return 1;
3013+
return (iommu_identity_mapping & IDENTMAP_ALL) ?
3014+
IOMMU_DOMAIN_IDENTITY : 0;
3015+
}
3016+
3017+
static inline int iommu_should_identity_map(struct device *dev, int startup)
3018+
{
3019+
return device_def_domain_type(dev, startup) == IOMMU_DOMAIN_IDENTITY;
30063020
}
30073021

30083022
static int __init dev_prepare_static_identity_mapping(struct device *dev, int hw)

0 commit comments

Comments
 (0)