Commit f273a453 authored by Lu Baolu's avatar Lu Baolu Committed by Joerg Roedel

iommu/vt-d: Add device_def_domain_type() helper

This helper returns the default domain type that the device
requires.
Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent d8190dc6
...@@ -2930,29 +2930,37 @@ static bool device_is_rmrr_locked(struct device *dev) ...@@ -2930,29 +2930,37 @@ static bool device_is_rmrr_locked(struct device *dev)
return true; return true;
} }
static int iommu_should_identity_map(struct device *dev, int startup) /*
* Return the required default domain type for a specific device.
*
* @dev: the device in query
* @startup: true if this is during early boot
*
* Returns:
* - IOMMU_DOMAIN_DMA: device requires a dynamic mapping domain
* - IOMMU_DOMAIN_IDENTITY: device requires an identical mapping domain
* - 0: both identity and dynamic domains work for this device
*/
static int device_def_domain_type(struct device *dev, int startup)
{ {
if (dev_is_pci(dev)) { if (dev_is_pci(dev)) {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
if (device_is_rmrr_locked(dev)) if (device_is_rmrr_locked(dev))
return 0; return IOMMU_DOMAIN_DMA;
/* /*
* Prevent any device marked as untrusted from getting * Prevent any device marked as untrusted from getting
* placed into the statically identity mapping domain. * placed into the statically identity mapping domain.
*/ */
if (pdev->untrusted) if (pdev->untrusted)
return 0; return IOMMU_DOMAIN_DMA;
if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev)) if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev))
return 1; return IOMMU_DOMAIN_IDENTITY;
if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev)) if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
return 1; return IOMMU_DOMAIN_IDENTITY;
if (!(iommu_identity_mapping & IDENTMAP_ALL))
return 0;
/* /*
* We want to start off with all devices in the 1:1 domain, and * 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,14 +2981,14 @@ static int iommu_should_identity_map(struct device *dev, int startup)
*/ */
if (!pci_is_pcie(pdev)) { if (!pci_is_pcie(pdev)) {
if (!pci_is_root_bus(pdev->bus)) if (!pci_is_root_bus(pdev->bus))
return 0; return IOMMU_DOMAIN_DMA;
if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI) if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI)
return 0; return IOMMU_DOMAIN_DMA;
} else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE) } else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE)
return 0; return IOMMU_DOMAIN_DMA;
} else { } else {
if (device_has_rmrr(dev)) if (device_has_rmrr(dev))
return 0; return IOMMU_DOMAIN_DMA;
} }
/* /*
...@@ -3002,7 +3010,13 @@ static int iommu_should_identity_map(struct device *dev, int startup) ...@@ -3002,7 +3010,13 @@ static int iommu_should_identity_map(struct device *dev, int startup)
return dma_mask >= dma_get_required_mask(dev); return dma_mask >= dma_get_required_mask(dev);
} }
return 1; return (iommu_identity_mapping & IDENTMAP_ALL) ?
IOMMU_DOMAIN_IDENTITY : 0;
}
static inline int iommu_should_identity_map(struct device *dev, int startup)
{
return device_def_domain_type(dev, startup) == IOMMU_DOMAIN_IDENTITY;
} }
static int __init dev_prepare_static_identity_mapping(struct device *dev, int hw) static int __init dev_prepare_static_identity_mapping(struct device *dev, int hw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment