aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2014-03-09 19:03:08 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2014-03-24 10:07:55 -0400
commit3bdb259116059a6b805cfe9be66f4054f92598a3 (patch)
tree847d1c8e1ddae08e81daaac8e75cecb2730d2b82 /drivers/iommu
parent0b9d9753155b9ed72e864592f9bf482a688c3c11 (diff)
iommu/vt-d: Make iommu_should_identity_map() take struct device
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/intel-iommu.c107
1 files changed, 57 insertions, 50 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 7b2b9f321c74..ccfce8832954 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2518,58 +2518,65 @@ static bool device_has_rmrr(struct device *dev)
2518 return false; 2518 return false;
2519} 2519}
2520 2520
2521static int iommu_should_identity_map(struct pci_dev *pdev, int startup) 2521static int iommu_should_identity_map(struct device *dev, int startup)
2522{ 2522{
2523 2523
2524 /* 2524 if (dev_is_pci(dev)) {
2525 * We want to prevent any device associated with an RMRR from 2525 struct pci_dev *pdev = to_pci_dev(dev);
2526 * getting placed into the SI Domain. This is done because
2527 * problems exist when devices are moved in and out of domains
2528 * and their respective RMRR info is lost. We exempt USB devices
2529 * from this process due to their usage of RMRRs that are known
2530 * to not be needed after BIOS hand-off to OS.
2531 */
2532 if (device_has_rmrr(&pdev->dev) &&
2533 (pdev->class >> 8) != PCI_CLASS_SERIAL_USB)
2534 return 0;
2535 2526
2536 if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev)) 2527 /*
2537 return 1; 2528 * We want to prevent any device associated with an RMRR from
2529 * getting placed into the SI Domain. This is done because
2530 * problems exist when devices are moved in and out of domains
2531 * and their respective RMRR info is lost. We exempt USB devices
2532 * from this process due to their usage of RMRRs that are known
2533 * to not be needed after BIOS hand-off to OS.
2534 */
2535 if (device_has_rmrr(dev) &&
2536 (pdev->class >> 8) != PCI_CLASS_SERIAL_USB)
2537 return 0;
2538 2538
2539 if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev)) 2539 if ((iommu_identity_mapping & IDENTMAP_AZALIA) && IS_AZALIA(pdev))
2540 return 1; 2540 return 1;
2541 2541
2542 if (!(iommu_identity_mapping & IDENTMAP_ALL)) 2542 if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
2543 return 0; 2543 return 1;
2544 2544
2545 /* 2545 if (!(iommu_identity_mapping & IDENTMAP_ALL))
2546 * We want to start off with all devices in the 1:1 domain, and
2547 * take them out later if we find they can't access all of memory.
2548 *
2549 * However, we can't do this for PCI devices behind bridges,
2550 * because all PCI devices behind the same bridge will end up
2551 * with the same source-id on their transactions.
2552 *
2553 * Practically speaking, we can't change things around for these
2554 * devices at run-time, because we can't be sure there'll be no
2555 * DMA transactions in flight for any of their siblings.
2556 *
2557 * So PCI devices (unless they're on the root bus) as well as
2558 * their parent PCI-PCI or PCIe-PCI bridges must be left _out_ of
2559 * the 1:1 domain, just in _case_ one of their siblings turns out
2560 * not to be able to map all of memory.
2561 */
2562 if (!pci_is_pcie(pdev)) {
2563 if (!pci_is_root_bus(pdev->bus))
2564 return 0; 2546 return 0;
2565 if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI) 2547
2548 /*
2549 * We want to start off with all devices in the 1:1 domain, and
2550 * take them out later if we find they can't access all of memory.
2551 *
2552 * However, we can't do this for PCI devices behind bridges,
2553 * because all PCI devices behind the same bridge will end up
2554 * with the same source-id on their transactions.
2555 *
2556 * Practically speaking, we can't change things around for these
2557 * devices at run-time, because we can't be sure there'll be no
2558 * DMA transactions in flight for any of their siblings.
2559 *
2560 * So PCI devices (unless they're on the root bus) as well as
2561 * their parent PCI-PCI or PCIe-PCI bridges must be left _out_ of
2562 * the 1:1 domain, just in _case_ one of their siblings turns out
2563 * not to be able to map all of memory.
2564 */
2565 if (!pci_is_pcie(pdev)) {
2566 if (!pci_is_root_bus(pdev->bus))
2567 return 0;
2568 if (pdev->class >> 8 == PCI_CLASS_BRIDGE_PCI)
2569 return 0;
2570 } else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE)
2566 return 0; 2571 return 0;
2567 } else if (pci_pcie_type(pdev) == PCI_EXP_TYPE_PCI_BRIDGE) 2572 } else {
2568 return 0; 2573 if (device_has_rmrr(dev))
2574 return 0;
2575 }
2569 2576
2570 /* 2577 /*
2571 * At boot time, we don't yet know if devices will be 64-bit capable. 2578 * At boot time, we don't yet know if devices will be 64-bit capable.
2572 * Assume that they will -- if they turn out not to be, then we can 2579 * Assume that they will if they turn out not to be, then we can
2573 * take them out of the 1:1 domain later. 2580 * take them out of the 1:1 domain later.
2574 */ 2581 */
2575 if (!startup) { 2582 if (!startup) {
@@ -2577,13 +2584,13 @@ static int iommu_should_identity_map(struct pci_dev *pdev, int startup)
2577 * If the device's dma_mask is less than the system's memory 2584 * If the device's dma_mask is less than the system's memory
2578 * size then this is not a candidate for identity mapping. 2585 * size then this is not a candidate for identity mapping.
2579 */ 2586 */
2580 u64 dma_mask = pdev->dma_mask; 2587 u64 dma_mask = *dev->dma_mask;
2581 2588
2582 if (pdev->dev.coherent_dma_mask && 2589 if (dev->coherent_dma_mask &&
2583 pdev->dev.coherent_dma_mask < dma_mask) 2590 dev->coherent_dma_mask < dma_mask)
2584 dma_mask = pdev->dev.coherent_dma_mask; 2591 dma_mask = dev->coherent_dma_mask;
2585 2592
2586 return dma_mask >= dma_get_required_mask(&pdev->dev); 2593 return dma_mask >= dma_get_required_mask(dev);
2587 } 2594 }
2588 2595
2589 return 1; 2596 return 1;
@@ -2599,7 +2606,7 @@ static int __init iommu_prepare_static_identity_mapping(int hw)
2599 return -EFAULT; 2606 return -EFAULT;
2600 2607
2601 for_each_pci_dev(pdev) { 2608 for_each_pci_dev(pdev) {
2602 if (iommu_should_identity_map(pdev, 1)) { 2609 if (iommu_should_identity_map(&pdev->dev, 1)) {
2603 ret = domain_add_dev_info(si_domain, pdev, 2610 ret = domain_add_dev_info(si_domain, pdev,
2604 hw ? CONTEXT_TT_PASS_THROUGH : 2611 hw ? CONTEXT_TT_PASS_THROUGH :
2605 CONTEXT_TT_MULTI_LEVEL); 2612 CONTEXT_TT_MULTI_LEVEL);
@@ -2917,7 +2924,7 @@ static int iommu_no_mapping(struct device *dev)
2917 pdev = to_pci_dev(dev); 2924 pdev = to_pci_dev(dev);
2918 found = identity_mapping(dev); 2925 found = identity_mapping(dev);
2919 if (found) { 2926 if (found) {
2920 if (iommu_should_identity_map(pdev, 0)) 2927 if (iommu_should_identity_map(&pdev->dev, 0))
2921 return 1; 2928 return 1;
2922 else { 2929 else {
2923 /* 2930 /*
@@ -2934,7 +2941,7 @@ static int iommu_no_mapping(struct device *dev)
2934 * In case of a detached 64 bit DMA device from vm, the device 2941 * In case of a detached 64 bit DMA device from vm, the device
2935 * is put into si_domain for identity mapping. 2942 * is put into si_domain for identity mapping.
2936 */ 2943 */
2937 if (iommu_should_identity_map(pdev, 0)) { 2944 if (iommu_should_identity_map(&pdev->dev, 0)) {
2938 int ret; 2945 int ret;
2939 ret = domain_add_dev_info(si_domain, pdev, 2946 ret = domain_add_dev_info(si_domain, pdev,
2940 hw_pass_through ? 2947 hw_pass_through ?