Merge ../linux-2.6-watchdog-mm
[linux-drm-fsl-dcu.git] / arch / powerpc / sysdev / dart_iommu.c
index 6232091cc72bcd87b8e6f69c9242257b770926e1..572b7846cc77226870784995534d98ea794bd979 100644 (file)
@@ -27,7 +27,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -101,8 +100,8 @@ retry:
        if (l == (1L << limit)) {
                if (limit < 4) {
                        limit++;
-                       reg = DART_IN(DART_CNTL);
-                       reg &= ~inv_bit;
+                       reg = DART_IN(DART_CNTL);
+                       reg &= ~inv_bit;
                        DART_OUT(DART_CNTL, reg);
                        goto retry;
                } else
@@ -111,11 +110,40 @@ retry:
        }
 }
 
+static inline void dart_tlb_invalidate_one(unsigned long bus_rpn)
+{
+       unsigned int reg;
+       unsigned int l, limit;
+
+       reg = DART_CNTL_U4_ENABLE | DART_CNTL_U4_IONE |
+               (bus_rpn & DART_CNTL_U4_IONE_MASK);
+       DART_OUT(DART_CNTL, reg);
+
+       limit = 0;
+wait_more:
+       l = 0;
+       while ((DART_IN(DART_CNTL) & DART_CNTL_U4_IONE) && l < (1L << limit)) {
+               rmb();
+               l++;
+       }
+
+       if (l == (1L << limit)) {
+               if (limit < 4) {
+                       limit++;
+                       goto wait_more;
+               } else
+                       panic("DART: TLB did not flush after waiting a long "
+                             "time. Buggy U4 ?");
+       }
+}
+
 static void dart_flush(struct iommu_table *tbl)
 {
-       if (dart_dirty)
+       mb();
+       if (dart_dirty) {
                dart_tlb_invalidate_all();
-       dart_dirty = 0;
+               dart_dirty = 0;
+       }
 }
 
 static void dart_build(struct iommu_table *tbl, long index,
@@ -124,18 +152,17 @@ static void dart_build(struct iommu_table *tbl, long index,
 {
        unsigned int *dp;
        unsigned int rpn;
+       long l;
 
        DBG("dart: build at: %lx, %lx, addr: %x\n", index, npages, uaddr);
 
-       index <<= DART_PAGE_FACTOR;
-       npages <<= DART_PAGE_FACTOR;
-
        dp = ((unsigned int*)tbl->it_base) + index;
 
        /* On U3, all memory is contigous, so we can move this
         * out of the loop.
         */
-       while (npages--) {
+       l = npages;
+       while (l--) {
                rpn = virt_to_abs(uaddr) >> DART_PAGE_SHIFT;
 
                *(dp++) = DARTMAP_VALID | (rpn & DARTMAP_RPNMASK);
@@ -143,7 +170,18 @@ static void dart_build(struct iommu_table *tbl, long index,
                uaddr += DART_PAGE_SIZE;
        }
 
-       dart_dirty = 1;
+       /* make sure all updates have reached memory */
+       mb();
+       in_be32((unsigned __iomem *)dp);
+       mb();
+
+       if (dart_is_u4) {
+               rpn = index;
+               while (npages--)
+                       dart_tlb_invalidate_one(rpn++);
+       } else {
+               dart_dirty = 1;
+       }
 }
 
 
@@ -158,9 +196,6 @@ static void dart_free(struct iommu_table *tbl, long index, long npages)
 
        DBG("dart: free at: %lx, %lx\n", index, npages);
 
-       index <<= DART_PAGE_FACTOR;
-       npages <<= DART_PAGE_FACTOR;
-
        dp  = ((unsigned int *)tbl->it_base) + index;
 
        while (npages--)
@@ -240,7 +275,7 @@ static void iommu_table_dart_setup(void)
        iommu_table_dart.it_busno = 0;
        iommu_table_dart.it_offset = 0;
        /* it_size is in number of entries */
-       iommu_table_dart.it_size = (dart_tablesize / sizeof(u32)) >> DART_PAGE_FACTOR;
+       iommu_table_dart.it_size = dart_tablesize / sizeof(u32);
 
        /* Initialize the common IOMMU code */
        iommu_table_dart.it_base = (unsigned long)dart_vbase;