2 * IOMMU helper functions for the free area management
5 #include <linux/module.h>
6 #include <linux/bitops.h>
8 static unsigned long find_next_zero_area(unsigned long *map
,
12 unsigned long align_mask
)
14 unsigned long index
, end
, i
;
16 index
= find_next_zero_bit(map
, size
, start
);
18 /* Align allocation */
19 index
= (index
+ align_mask
) & ~align_mask
;
24 for (i
= index
; i
< end
; i
++) {
25 if (test_bit(i
, map
)) {
33 void iommu_area_reserve(unsigned long *map
, unsigned long i
, int len
)
35 unsigned long end
= i
+ len
;
42 int iommu_is_span_boundary(unsigned int index
, unsigned int nr
,
44 unsigned long boundary_size
)
46 BUG_ON(!is_power_of_2(boundary_size
));
48 shift
= (shift
+ index
) & (boundary_size
- 1);
49 return shift
+ nr
> boundary_size
;
52 unsigned long iommu_area_alloc(unsigned long *map
, unsigned long size
,
53 unsigned long start
, unsigned int nr
,
54 unsigned long shift
, unsigned long boundary_size
,
55 unsigned long align_mask
)
59 index
= find_next_zero_area(map
, size
, start
, nr
, align_mask
);
61 if (iommu_is_span_boundary(index
, nr
, shift
, boundary_size
)) {
62 /* we could do more effectively */
66 iommu_area_reserve(map
, index
, nr
);
70 EXPORT_SYMBOL(iommu_area_alloc
);
72 void iommu_area_free(unsigned long *map
, unsigned long start
, unsigned int nr
)
74 unsigned long end
= start
+ nr
;
77 __clear_bit(start
, map
);
81 EXPORT_SYMBOL(iommu_area_free
);