Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * IOMMU helper functions for the free area management
0004  */
0005 
0006 #include <linux/bitmap.h>
0007 #include <linux/iommu-helper.h>
0008 
0009 unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
0010                    unsigned long start, unsigned int nr,
0011                    unsigned long shift, unsigned long boundary_size,
0012                    unsigned long align_mask)
0013 {
0014     unsigned long index;
0015 
0016     /* We don't want the last of the limit */
0017     size -= 1;
0018 again:
0019     index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
0020     if (index < size) {
0021         if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
0022             start = ALIGN(shift + index, boundary_size) - shift;
0023             goto again;
0024         }
0025         bitmap_set(map, index, nr);
0026         return index;
0027     }
0028     return -1;
0029 }