aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/intel-iommu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/intel-iommu.c')
-rw-r--r--drivers/pci/intel-iommu.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index b8802ae4bcdb..8d6159426311 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -2767,7 +2767,15 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
2767 2767
2768 size = PAGE_ALIGN(size); 2768 size = PAGE_ALIGN(size);
2769 order = get_order(size); 2769 order = get_order(size);
2770 flags &= ~(GFP_DMA | GFP_DMA32); 2770
2771 if (!iommu_no_mapping(hwdev))
2772 flags &= ~(GFP_DMA | GFP_DMA32);
2773 else if (hwdev->coherent_dma_mask < dma_get_required_mask(hwdev)) {
2774 if (hwdev->coherent_dma_mask < DMA_BIT_MASK(32))
2775 flags |= GFP_DMA;
2776 else
2777 flags |= GFP_DMA32;
2778 }
2771 2779
2772 vaddr = (void *)__get_free_pages(flags, order); 2780 vaddr = (void *)__get_free_pages(flags, order);
2773 if (!vaddr) 2781 if (!vaddr)
@@ -3207,6 +3215,33 @@ static int __init init_iommu_sysfs(void)
3207} 3215}
3208#endif /* CONFIG_PM */ 3216#endif /* CONFIG_PM */
3209 3217
3218/*
3219 * Here we only respond to action of unbound device from driver.
3220 *
3221 * Added device is not attached to its DMAR domain here yet. That will happen
3222 * when mapping the device to iova.
3223 */
3224static int device_notifier(struct notifier_block *nb,
3225 unsigned long action, void *data)
3226{
3227 struct device *dev = data;
3228 struct pci_dev *pdev = to_pci_dev(dev);
3229 struct dmar_domain *domain;
3230
3231 domain = find_domain(pdev);
3232 if (!domain)
3233 return 0;
3234
3235 if (action == BUS_NOTIFY_UNBOUND_DRIVER && !iommu_pass_through)
3236 domain_remove_one_dev_info(domain, pdev);
3237
3238 return 0;
3239}
3240
3241static struct notifier_block device_nb = {
3242 .notifier_call = device_notifier,
3243};
3244
3210int __init intel_iommu_init(void) 3245int __init intel_iommu_init(void)
3211{ 3246{
3212 int ret = 0; 3247 int ret = 0;
@@ -3231,7 +3266,7 @@ int __init intel_iommu_init(void)
3231 * Check the need for DMA-remapping initialization now. 3266 * Check the need for DMA-remapping initialization now.
3232 * Above initialization will also be used by Interrupt-remapping. 3267 * Above initialization will also be used by Interrupt-remapping.
3233 */ 3268 */
3234 if (no_iommu || swiotlb || dmar_disabled) 3269 if (no_iommu || dmar_disabled)
3235 return -ENODEV; 3270 return -ENODEV;
3236 3271
3237 iommu_init_mempool(); 3272 iommu_init_mempool();
@@ -3252,13 +3287,17 @@ int __init intel_iommu_init(void)
3252 "PCI-DMA: Intel(R) Virtualization Technology for Directed I/O\n"); 3287 "PCI-DMA: Intel(R) Virtualization Technology for Directed I/O\n");
3253 3288
3254 init_timer(&unmap_timer); 3289 init_timer(&unmap_timer);
3255 force_iommu = 1; 3290#ifdef CONFIG_SWIOTLB
3291 swiotlb = 0;
3292#endif
3256 dma_ops = &intel_dma_ops; 3293 dma_ops = &intel_dma_ops;
3257 3294
3258 init_iommu_sysfs(); 3295 init_iommu_sysfs();
3259 3296
3260 register_iommu(&intel_iommu_ops); 3297 register_iommu(&intel_iommu_ops);
3261 3298
3299 bus_register_notifier(&pci_bus_type, &device_nb);
3300
3262 return 0; 3301 return 0;
3263} 3302}
3264 3303