inflate_fast: sout is already a short so ptr arith was off by one.
[safe/jmp/linux-2.6] / lib / iommu-helper.c
index a3b8d4c..c0251f4 100644 (file)
@@ -3,42 +3,7 @@
  */
 
 #include <linux/module.h>
-#include <linux/bitops.h>
-
-static unsigned long find_next_zero_area(unsigned long *map,
-                                        unsigned long size,
-                                        unsigned long start,
-                                        unsigned int nr,
-                                        unsigned long align_mask)
-{
-       unsigned long index, end, i;
-again:
-       index = find_next_zero_bit(map, size, start);
-
-       /* Align allocation */
-       index = (index + align_mask) & ~align_mask;
-
-       end = index + nr;
-       if (end >= size)
-               return -1;
-       for (i = index; i < end; i++) {
-               if (test_bit(i, map)) {
-                       start = i+1;
-                       goto again;
-               }
-       }
-       return index;
-}
-
-static inline void set_bit_area(unsigned long *map, unsigned long i,
-                               int len)
-{
-       unsigned long end = i + len;
-       while (i < end) {
-               __set_bit(i, map);
-               i++;
-       }
-}
+#include <linux/bitmap.h>
 
 int iommu_is_span_boundary(unsigned int index, unsigned int nr,
                           unsigned long shift,
@@ -56,27 +21,29 @@ unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
                               unsigned long align_mask)
 {
        unsigned long index;
+
+       /* We don't want the last of the limit */
+       size -= 1;
 again:
-       index = find_next_zero_area(map, size, start, nr, align_mask);
-       if (index != -1) {
+       index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
+       if (index < 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);
+               bitmap_set(map, index, nr);
+               return index;
        }
-       return index;
+       return -1;
 }
 EXPORT_SYMBOL(iommu_area_alloc);
 
-void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len,
+                             unsigned long io_page_size)
 {
-       unsigned long end = start + nr;
+       unsigned long size = (addr & (io_page_size - 1)) + len;
 
-       while (start < end) {
-               __clear_bit(start, map);
-               start++;
-       }
+       return DIV_ROUND_UP(size, io_page_size);
 }
-EXPORT_SYMBOL(iommu_area_free);
+EXPORT_SYMBOL(iommu_num_pages);