Commit 3bdb2591 authored by David Woodhouse's avatar David Woodhouse

iommu/vt-d: Make iommu_should_identity_map() take struct device

Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 0b9d9753
...@@ -2518,9 +2518,12 @@ static bool device_has_rmrr(struct device *dev) ...@@ -2518,9 +2518,12 @@ static bool device_has_rmrr(struct device *dev)
return false; return false;
} }
static int iommu_should_identity_map(struct pci_dev *pdev, int startup) static int iommu_should_identity_map(struct device *dev, int startup)
{ {
if (dev_is_pci(dev)) {
struct pci_dev *pdev = to_pci_dev(dev);
/* /*
* We want to prevent any device associated with an RMRR from * We want to prevent any device associated with an RMRR from
* getting placed into the SI Domain. This is done because * getting placed into the SI Domain. This is done because
...@@ -2529,7 +2532,7 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup) ...@@ -2529,7 +2532,7 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup)
* from this process due to their usage of RMRRs that are known * from this process due to their usage of RMRRs that are known
* to not be needed after BIOS hand-off to OS. * to not be needed after BIOS hand-off to OS.
*/ */
if (device_has_rmrr(&pdev->dev) && if (device_has_rmrr(dev) &&
(pdev->class >> 8) != PCI_CLASS_SERIAL_USB) (pdev->class >> 8) != PCI_CLASS_SERIAL_USB)
return 0; return 0;
...@@ -2566,10 +2569,14 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup) ...@@ -2566,10 +2569,14 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup)
return 0; return 0;
} 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 0;
} else {
if (device_has_rmrr(dev))
return 0;
}
/* /*
* At boot time, we don't yet know if devices will be 64-bit capable. * At boot time, we don't yet know if devices will be 64-bit capable.
* Assume that they will -- if they turn out not to be, then we can * Assume that they will — if they turn out not to be, then we can
* take them out of the 1:1 domain later. * take them out of the 1:1 domain later.
*/ */
if (!startup) { if (!startup) {
...@@ -2577,13 +2584,13 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup) ...@@ -2577,13 +2584,13 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup)
* If the device's dma_mask is less than the system's memory * If the device's dma_mask is less than the system's memory
* size then this is not a candidate for identity mapping. * size then this is not a candidate for identity mapping.
*/ */
u64 dma_mask = pdev->dma_mask; u64 dma_mask = *dev->dma_mask;
if (pdev->dev.coherent_dma_mask && if (dev->coherent_dma_mask &&
pdev->dev.coherent_dma_mask < dma_mask) dev->coherent_dma_mask < dma_mask)
dma_mask = pdev->dev.coherent_dma_mask; dma_mask = dev->coherent_dma_mask;
return dma_mask >= dma_get_required_mask(&pdev->dev); return dma_mask >= dma_get_required_mask(dev);
} }
return 1; return 1;
...@@ -2599,7 +2606,7 @@ static int __init iommu_prepare_static_identity_mapping(int hw) ...@@ -2599,7 +2606,7 @@ static int __init iommu_prepare_static_identity_mapping(int hw)
return -EFAULT; return -EFAULT;
for_each_pci_dev(pdev) { for_each_pci_dev(pdev) {
if (iommu_should_identity_map(pdev, 1)) { if (iommu_should_identity_map(&pdev->dev, 1)) {
ret = domain_add_dev_info(si_domain, pdev, ret = domain_add_dev_info(si_domain, pdev,
hw ? CONTEXT_TT_PASS_THROUGH : hw ? CONTEXT_TT_PASS_THROUGH :
CONTEXT_TT_MULTI_LEVEL); CONTEXT_TT_MULTI_LEVEL);
...@@ -2917,7 +2924,7 @@ static int iommu_no_mapping(struct device *dev) ...@@ -2917,7 +2924,7 @@ static int iommu_no_mapping(struct device *dev)
pdev = to_pci_dev(dev); pdev = to_pci_dev(dev);
found = identity_mapping(dev); found = identity_mapping(dev);
if (found) { if (found) {
if (iommu_should_identity_map(pdev, 0)) if (iommu_should_identity_map(&pdev->dev, 0))
return 1; return 1;
else { else {
/* /*
...@@ -2934,7 +2941,7 @@ static int iommu_no_mapping(struct device *dev) ...@@ -2934,7 +2941,7 @@ static int iommu_no_mapping(struct device *dev)
* In case of a detached 64 bit DMA device from vm, the device * In case of a detached 64 bit DMA device from vm, the device
* is put into si_domain for identity mapping. * is put into si_domain for identity mapping.
*/ */
if (iommu_should_identity_map(pdev, 0)) { if (iommu_should_identity_map(&pdev->dev, 0)) {
int ret; int ret;
ret = domain_add_dev_info(si_domain, pdev, ret = domain_add_dev_info(si_domain, pdev,
hw_pass_through ? hw_pass_through ?
......
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