Back to home page

LXR

 
 

    


0001 /*
0002  * IOMMU helper functions for the free area management
0003  */
0004 
0005 #include <linux/export.h>
0006 #include <linux/bitmap.h>
0007 #include <linux/bug.h>
0008 
0009 int iommu_is_span_boundary(unsigned int index, unsigned int nr,
0010                unsigned long shift,
0011                unsigned long boundary_size)
0012 {
0013     BUG_ON(!is_power_of_2(boundary_size));
0014 
0015     shift = (shift + index) & (boundary_size - 1);
0016     return shift + nr > boundary_size;
0017 }
0018 
0019 unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
0020                    unsigned long start, unsigned int nr,
0021                    unsigned long shift, unsigned long boundary_size,
0022                    unsigned long align_mask)
0023 {
0024     unsigned long index;
0025 
0026     /* We don't want the last of the limit */
0027     size -= 1;
0028 again:
0029     index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
0030     if (index < size) {
0031         if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
0032             start = ALIGN(shift + index, boundary_size) - shift;
0033             goto again;
0034         }
0035         bitmap_set(map, index, nr);
0036         return index;
0037     }
0038     return -1;
0039 }
0040 EXPORT_SYMBOL(iommu_area_alloc);