-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 83019 b: refs/heads/master c: 0291df8 h: refs/heads/master i: 83017: 7f482aa 83015: 28f6b51 v: v3
- Loading branch information
FUJITA Tomonori
authored and
Linus Torvalds
committed
Feb 5, 2008
1 parent
cc0a08c
commit ea8a218
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 0c95fdc59640824d7e0b017be295fb912ceef4ab | ||
refs/heads/master: 0291df8cc9dac09c303d21d5bcd2ad73762c836a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extern 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); | ||
extern void iommu_area_free(unsigned long *map, unsigned long start, | ||
unsigned int nr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* IOMMU helper functions for the free area management | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/bitops.h> | ||
|
||
static unsigned long find_next_zero_area(unsigned long *map, | ||
unsigned long size, | ||
unsigned long start, | ||
unsigned int nr, | ||
unsigned long align_mask) | ||
{ | ||
unsigned long index, end, i; | ||
again: | ||
index = find_next_zero_bit(map, size, start); | ||
|
||
/* Align allocation */ | ||
index = (index + align_mask) & ~align_mask; | ||
|
||
end = index + nr; | ||
if (end >= size) | ||
return -1; | ||
for (i = index; i < end; i++) { | ||
if (test_bit(i, map)) { | ||
start = i+1; | ||
goto again; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
static inline void set_bit_area(unsigned long *map, unsigned long i, | ||
int len) | ||
{ | ||
unsigned long end = i + len; | ||
while (i < end) { | ||
__set_bit(i, map); | ||
i++; | ||
} | ||
} | ||
|
||
static inline int is_span_boundary(unsigned int index, unsigned int nr, | ||
unsigned long shift, | ||
unsigned long boundary_size) | ||
{ | ||
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; | ||
again: | ||
index = find_next_zero_area(map, size, start, nr, align_mask); | ||
if (index != -1) { | ||
if (is_span_boundary(index, nr, shift, boundary_size)) { | ||
/* we could do more effectively */ | ||
start = index + 1; | ||
goto again; | ||
} | ||
set_bit_area(map, index, nr); | ||
} | ||
return index; | ||
} | ||
EXPORT_SYMBOL(iommu_area_alloc); | ||
|
||
void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) | ||
{ | ||
unsigned long end = start + nr; | ||
|
||
while (start < end) { | ||
__clear_bit(start, map); | ||
start++; | ||
} | ||
} | ||
EXPORT_SYMBOL(iommu_area_free); |