Merge master.kernel.org:/home/rmk/linux-2.6-arm
[powerpc.git] / arch / x86_64 / kernel / pci-gart.c
index c37fc77..a6c01e1 100644 (file)
@@ -65,9 +65,7 @@ static u32 gart_unmapped_entry;
 
 #define for_all_nb(dev) \
        dev = NULL;     \
-       while ((dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1103, dev))!=NULL)\
-            if (dev->bus->number == 0 &&                                    \
-                   (PCI_SLOT(dev->devfn) >= 24) && (PCI_SLOT(dev->devfn) <= 31))
+       while ((dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1103, dev))!=NULL)
 
 static struct pci_dev *northbridges[MAX_NB];
 static u32 northbridge_flush_word[MAX_NB];
@@ -148,9 +146,12 @@ static void flush_gart(struct device *dev)
                        if (!northbridges[i])
                                continue;
                        /* Make sure the hardware actually executed the flush. */
-                       do { 
+                       for (;;) { 
                                pci_read_config_dword(northbridges[i], 0x9c, &w);
-                       } while (w & 1);
+                               if (!(w & 1))
+                                       break;
+                               cpu_relax();
+                       }
                } 
                if (!flushed) 
                        printk("nothing to flush?\n");
@@ -228,11 +229,6 @@ static inline int need_iommu(struct device *dev, unsigned long addr, size_t size
        int mmu = high;
        if (force_iommu) 
                mmu = 1; 
-       if (no_iommu) { 
-               if (high) 
-                       panic("PCI-DMA: high address but no IOMMU.\n"); 
-               mmu = 0; 
-       }       
        return mmu; 
 }
 
@@ -241,11 +237,6 @@ static inline int nonforced_iommu(struct device *dev, unsigned long addr, size_t
        u64 mask = *dev->dma_mask;
        int high = addr + size >= mask;
        int mmu = high;
-       if (no_iommu) { 
-               if (high) 
-                       panic("PCI-DMA: high address but no IOMMU.\n"); 
-               mmu = 0; 
-       }       
        return mmu; 
 }
 
@@ -379,7 +370,7 @@ static int __dma_map_cont(struct scatterlist *sg, int start, int stopat,
                        SET_LEAK(iommu_page);
                        addr += PAGE_SIZE;
                        iommu_page++;
-       } 
+               }
        } 
        BUG_ON(iommu_page - iommu_start != pages);      
        return 0;
@@ -457,9 +448,12 @@ int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
 error:
        flush_gart(NULL);
        gart_unmap_sg(dev, sg, nents, dir);
-       /* When it was forced try again unforced */
-       if (force_iommu) 
-               return dma_map_sg_nonforce(dev, sg, nents, dir);
+       /* When it was forced or merged try again in a dumb way */
+       if (force_iommu || iommu_merge) {
+               out = dma_map_sg_nonforce(dev, sg, nents, dir);
+               if (out > 0)
+                       return out;
+       }
        if (panic_on_overflow)
                panic("dma_map_sg: overflow on %lu pages\n", pages);
        iommu_full(dev, pages << PAGE_SHIFT, dir);
@@ -631,20 +625,25 @@ static int __init pci_iommu_init(void)
                (agp_copy_info(agp_bridge, &info) < 0);
 #endif 
 
-       if (swiotlb) { 
-               no_iommu = 1;
+       if (swiotlb)
                return -1; 
-       } 
-       
+
        if (no_iommu ||
            (!force_iommu && end_pfn <= MAX_DMA32_PFN) ||
            !iommu_aperture ||
            (no_agp && init_k8_gatt(&info) < 0)) {
-               no_iommu = 1;
-               no_iommu_init();
+               printk(KERN_INFO "PCI-DMA: Disabling IOMMU.\n");
+               if (end_pfn > MAX_DMA32_PFN) {
+                       printk(KERN_ERR "WARNING more than 4GB of memory "
+                                       "but IOMMU not compiled in.\n"
+                              KERN_ERR "WARNING 32bit PCI may malfunction.\n"
+                              KERN_ERR "You might want to enable "
+                                       "CONFIG_GART_IOMMU\n");
+               }
                return -1;
        }
 
+       printk(KERN_INFO "PCI-DMA: using GART IOMMU.\n");
        aper_size = info.aper_size * 1024 * 1024;       
        iommu_size = check_iommu_size(info.aper_base, aper_size); 
        iommu_pages = iommu_size >> PAGE_SHIFT; 
@@ -718,7 +717,6 @@ static int __init pci_iommu_init(void)
                     
        flush_gart(NULL);
 
-       printk(KERN_INFO "PCI-DMA: using GART IOMMU.\n");
        dma_ops = &gart_dma_ops;
 
        return 0;