From: Muli Ben-Yehuda swiotlb relies on the gart specific iommu_aperture variable to know if we discovered a hardware IOMMU before swiotlb initialization. Introduce iommu_detected to do the same thing, but in a HW IOMMU neutral manner, in preparation for adding the Calgary HW IOMMU. Signed-off-by: Muli Ben-Yehuda Signed-off-by: Jon Mason Cc: Andi Kleen Signed-off-by: Andrew Morton --- arch/x86_64/kernel/aperture.c | 1 + arch/x86_64/kernel/pci-dma.c | 3 +++ arch/x86_64/kernel/pci-gart.c | 4 ++++ arch/x86_64/kernel/pci-swiotlb.c | 2 +- include/asm-x86_64/dma-mapping.h | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86_64/kernel/aperture.c~x86-64-calgary-iommu-introduce-iommu_detected arch/x86_64/kernel/aperture.c --- devel/arch/x86_64/kernel/aperture.c~x86-64-calgary-iommu-introduce-iommu_detected 2006-03-25 22:40:03.000000000 -0800 +++ devel-akpm/arch/x86_64/kernel/aperture.c 2006-03-25 22:40:03.000000000 -0800 @@ -212,6 +212,7 @@ void __init iommu_hole_init(void) if (read_pci_config(0, num, 3, 0x00) != NB_ID_3) continue; + iommu_detected = 1; iommu_aperture = 1; aper_order = (read_pci_config(0, num, 3, 0x90) >> 1) & 7; diff -puN arch/x86_64/kernel/pci-dma.c~x86-64-calgary-iommu-introduce-iommu_detected arch/x86_64/kernel/pci-dma.c --- devel/arch/x86_64/kernel/pci-dma.c~x86-64-calgary-iommu-introduce-iommu_detected 2006-03-25 22:40:03.000000000 -0800 +++ devel-akpm/arch/x86_64/kernel/pci-dma.c 2006-03-25 22:40:03.000000000 -0800 @@ -33,6 +33,9 @@ int panic_on_overflow __read_mostly = 0; int force_iommu __read_mostly= 0; #endif +/* Set this to 1 if there is a HW IOMMU in the system */ +int iommu_detected __read_mostly = 0; + /* Dummy device used for NULL arguments (normally ISA). Better would be probably a smaller DMA mask, but this is bug-to-bug compatible to i386. */ diff -puN arch/x86_64/kernel/pci-gart.c~x86-64-calgary-iommu-introduce-iommu_detected arch/x86_64/kernel/pci-gart.c --- devel/arch/x86_64/kernel/pci-gart.c~x86-64-calgary-iommu-introduce-iommu_detected 2006-03-25 22:40:03.000000000 -0800 +++ devel-akpm/arch/x86_64/kernel/pci-gart.c 2006-03-25 22:40:03.000000000 -0800 @@ -628,6 +628,10 @@ static int __init pci_iommu_init(void) if (swiotlb) return -1; + /* Did we detect a different HW IOMMU? */ + if (iommu_detected && !iommu_aperture) + return -1; + if (no_iommu || (!force_iommu && end_pfn <= MAX_DMA32_PFN) || !iommu_aperture || diff -puN arch/x86_64/kernel/pci-swiotlb.c~x86-64-calgary-iommu-introduce-iommu_detected arch/x86_64/kernel/pci-swiotlb.c --- devel/arch/x86_64/kernel/pci-swiotlb.c~x86-64-calgary-iommu-introduce-iommu_detected 2006-03-25 22:40:03.000000000 -0800 +++ devel-akpm/arch/x86_64/kernel/pci-swiotlb.c 2006-03-25 22:40:03.000000000 -0800 @@ -31,7 +31,7 @@ struct dma_mapping_ops swiotlb_dma_ops = void pci_swiotlb_init(void) { /* don't initialize swiotlb if iommu=off (no_iommu=1) */ - if (!iommu_aperture && !no_iommu && + if (!iommu_detected && !no_iommu && (end_pfn > MAX_DMA32_PFN || force_iommu)) swiotlb = 1; if (swiotlb) { diff -puN include/asm-x86_64/dma-mapping.h~x86-64-calgary-iommu-introduce-iommu_detected include/asm-x86_64/dma-mapping.h --- devel/include/asm-x86_64/dma-mapping.h~x86-64-calgary-iommu-introduce-iommu_detected 2006-03-25 22:40:03.000000000 -0800 +++ devel-akpm/include/asm-x86_64/dma-mapping.h 2006-03-25 22:40:03.000000000 -0800 @@ -183,5 +183,6 @@ dma_cache_sync(void *vaddr, size_t size, extern struct device fallback_dev; extern int panic_on_overflow; +extern int iommu_detected; #endif /* _X8664_DMA_MAPPING_H */ _