]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - lib/iommu-helper.c
Merge branch 'v28-range-hrtimers-for-linus-v2' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-omap-h63xx.git] / lib / iommu-helper.c
index 495575a59ca643f752a2314b44e5e0e77a2963f5..75dbda03f4fb99a92ef8cc3ead817afefd707702 100644 (file)
@@ -30,8 +30,7 @@ again:
        return index;
 }
 
-static inline void set_bit_area(unsigned long *map, unsigned long i,
-                               int len)
+void iommu_area_reserve(unsigned long *map, unsigned long i, int len)
 {
        unsigned long end = i + len;
        while (i < end) {
@@ -40,10 +39,12 @@ static inline void set_bit_area(unsigned long *map, unsigned long i,
        }
 }
 
-static inline int is_span_boundary(unsigned int index, unsigned int nr,
-                                  unsigned long shift,
-                                  unsigned long boundary_size)
+int iommu_is_span_boundary(unsigned int index, unsigned int nr,
+                          unsigned long shift,
+                          unsigned long boundary_size)
 {
+       BUG_ON(!is_power_of_2(boundary_size));
+
        shift = (shift + index) & (boundary_size - 1);
        return shift + nr > boundary_size;
 }
@@ -57,12 +58,12 @@ unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 again:
        index = find_next_zero_area(map, size, start, nr, align_mask);
        if (index != -1) {
-               if (is_span_boundary(index, nr, shift, boundary_size)) {
+               if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
                        /* we could do more effectively */
                        start = index + 1;
                        goto again;
                }
-               set_bit_area(map, index, nr);
+               iommu_area_reserve(map, index, nr);
        }
        return index;
 }
@@ -78,3 +79,12 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
        }
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len,
+                             unsigned long io_page_size)
+{
+       unsigned long size = (addr & (io_page_size - 1)) + len;
+
+       return DIV_ROUND_UP(size, io_page_size);
+}
+EXPORT_SYMBOL(iommu_num_pages);