@@ -2930,29 +2930,37 @@ static bool device_is_rmrr_locked(struct device *dev)
2930
2930
return true;
2931
2931
}
2932
2932
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 )
2934
2945
{
2935
2946
if (dev_is_pci (dev )) {
2936
2947
struct pci_dev * pdev = to_pci_dev (dev );
2937
2948
2938
2949
if (device_is_rmrr_locked (dev ))
2939
- return 0 ;
2950
+ return IOMMU_DOMAIN_DMA ;
2940
2951
2941
2952
/*
2942
2953
* Prevent any device marked as untrusted from getting
2943
2954
* placed into the statically identity mapping domain.
2944
2955
*/
2945
2956
if (pdev -> untrusted )
2946
- return 0 ;
2957
+ return IOMMU_DOMAIN_DMA ;
2947
2958
2948
2959
if ((iommu_identity_mapping & IDENTMAP_AZALIA ) && IS_AZALIA (pdev ))
2949
- return 1 ;
2960
+ return IOMMU_DOMAIN_IDENTITY ;
2950
2961
2951
2962
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 ;
2956
2964
2957
2965
/*
2958
2966
* 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)
2973
2981
*/
2974
2982
if (!pci_is_pcie (pdev )) {
2975
2983
if (!pci_is_root_bus (pdev -> bus ))
2976
- return 0 ;
2984
+ return IOMMU_DOMAIN_DMA ;
2977
2985
if (pdev -> class >> 8 == PCI_CLASS_BRIDGE_PCI )
2978
- return 0 ;
2986
+ return IOMMU_DOMAIN_DMA ;
2979
2987
} else if (pci_pcie_type (pdev ) == PCI_EXP_TYPE_PCI_BRIDGE )
2980
- return 0 ;
2988
+ return IOMMU_DOMAIN_DMA ;
2981
2989
} else {
2982
2990
if (device_has_rmrr (dev ))
2983
- return 0 ;
2991
+ return IOMMU_DOMAIN_DMA ;
2984
2992
}
2985
2993
2986
2994
/*
@@ -3002,7 +3010,13 @@ static int iommu_should_identity_map(struct device *dev, int startup)
3002
3010
return dma_mask >= dma_get_required_mask (dev );
3003
3011
}
3004
3012
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 ;
3006
3020
}
3007
3021
3008
3022
static int __init dev_prepare_static_identity_mapping (struct device * dev , int hw )
0 commit comments