Blame view

lib/iommu-helper.c 1006 Bytes
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
1
2
3
4
5
  /*
   * IOMMU helper functions for the free area management
   */
  
  #include <linux/module.h>
a66022c45   Akinobu Mita   iommu-helper: use...
6
  #include <linux/bitmap.h>
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
7

3715863aa   FUJITA Tomonori   iommu: export iom...
8
9
10
  int iommu_is_span_boundary(unsigned int index, unsigned int nr,
  			   unsigned long shift,
  			   unsigned long boundary_size)
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
11
  {
3715863aa   FUJITA Tomonori   iommu: export iom...
12
  	BUG_ON(!is_power_of_2(boundary_size));
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
13
14
15
16
17
18
19
20
21
22
  	shift = (shift + index) & (boundary_size - 1);
  	return shift + nr > boundary_size;
  }
  
  unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
  			       unsigned long start, unsigned int nr,
  			       unsigned long shift, unsigned long boundary_size,
  			       unsigned long align_mask)
  {
  	unsigned long index;
a66022c45   Akinobu Mita   iommu-helper: use...
23
24
25
  
  	/* We don't want the last of the limit */
  	size -= 1;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
26
  again:
a66022c45   Akinobu Mita   iommu-helper: use...
27
28
  	index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
  	if (index < size) {
3715863aa   FUJITA Tomonori   iommu: export iom...
29
  		if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
30
31
32
33
  			/* we could do more effectively */
  			start = index + 1;
  			goto again;
  		}
a66022c45   Akinobu Mita   iommu-helper: use...
34
35
  		bitmap_set(map, index, nr);
  		return index;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
36
  	}
a66022c45   Akinobu Mita   iommu-helper: use...
37
  	return -1;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
38
39
  }
  EXPORT_SYMBOL(iommu_area_alloc);