Blame view

lib/iommu-helper.c 1.04 KB
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
   */
8bc3bcc93   Paul Gortmaker   lib: reduce the u...
5
  #include <linux/export.h>
a66022c45   Akinobu Mita   iommu-helper: use...
6
  #include <linux/bitmap.h>
50af5ead3   Paul Gortmaker   bug.h: add includ...
7
  #include <linux/bug.h>
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
8

3715863aa   FUJITA Tomonori   iommu: export iom...
9
10
11
  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...
12
  {
3715863aa   FUJITA Tomonori   iommu: export iom...
13
  	BUG_ON(!is_power_of_2(boundary_size));
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
14
15
16
17
18
19
20
21
22
23
  	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...
24
25
26
  
  	/* We don't want the last of the limit */
  	size -= 1;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
27
  again:
a66022c45   Akinobu Mita   iommu-helper: use...
28
29
  	index = bitmap_find_next_zero_area(map, size, start, nr, align_mask);
  	if (index < size) {
3715863aa   FUJITA Tomonori   iommu: export iom...
30
  		if (iommu_is_span_boundary(index, nr, shift, boundary_size)) {
f003a1f18   Sebastian Ott   lib/iommu-helper:...
31
  			start = ALIGN(shift + index, boundary_size) - shift;
0291df8cc   FUJITA Tomonori   iommu sg: add IOM...
32
33
  			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);