Blame view

lib/iommu-helper.c 755 Bytes
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
2
3
4
  /*
   * IOMMU helper functions for the free area management
   */
a66022c45   Akinobu Mita   iommu-helper: use...
5
  #include <linux/bitmap.h>
79c1879ee   Christoph Hellwig   iommu-helper: mar...
6
  #include <linux/iommu-helper.h>
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
7
8
9
10
11
12
13
  
  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...
14
15
16
  
  	/* We don't want the last of the limit */
  	size -= 1;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
17
  again:
a66022c45   Akinobu Mita   iommu-helper: use...
18
19
  	index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
  	if (index < size) {
3715863aa   FUJITA Tomonori   iommu: export iom...
20
  		if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
f003a1f18   Sebastian Ott   lib/iommu-helper:...
21
  			start = ALIGN(shift + index, boundary_size) - shift;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
22
23
  			goto again;
  		}
a66022c45   Akinobu Mita   iommu-helper: use...
24
25
  		bitmap_set(map, index, nr);
  		return index;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
26
  	}
a66022c45   Akinobu Mita   iommu-helper: use...
27
  	return -1;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
28
  }