Commit a66022c457755b5eef61e30866114679c95e1f54
Committed by
Linus Torvalds
1 parent
c1a2a962a2
Exists in
master
and in
20 other branches
iommu-helper: use bitmap library
Use bitmap library and kill some unused iommu helper functions. 1. s/iommu_area_free/bitmap_clear/ 2. s/iommu_area_reserve/bitmap_set/ 3. Use bitmap_find_next_zero_area instead of find_next_zero_area This cannot be simple substitution because find_next_zero_area doesn't check the last bit of the limit in bitmap 4. Remove iommu_area_free, iommu_area_reserve, and find_next_zero_area Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 7 changed files with 21 additions and 64 deletions Side-by-side Diff
arch/powerpc/kernel/iommu.c
... | ... | @@ -30,7 +30,7 @@ |
30 | 30 | #include <linux/spinlock.h> |
31 | 31 | #include <linux/string.h> |
32 | 32 | #include <linux/dma-mapping.h> |
33 | -#include <linux/bitops.h> | |
33 | +#include <linux/bitmap.h> | |
34 | 34 | #include <linux/iommu-helper.h> |
35 | 35 | #include <linux/crash_dump.h> |
36 | 36 | #include <asm/io.h> |
... | ... | @@ -251,7 +251,7 @@ |
251 | 251 | } |
252 | 252 | |
253 | 253 | ppc_md.tce_free(tbl, entry, npages); |
254 | - iommu_area_free(tbl->it_map, free_entry, npages); | |
254 | + bitmap_clear(tbl->it_map, free_entry, npages); | |
255 | 255 | } |
256 | 256 | |
257 | 257 | static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr, |
arch/sparc/kernel/iommu.c
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | #include <linux/dma-mapping.h> |
12 | 12 | #include <linux/errno.h> |
13 | 13 | #include <linux/iommu-helper.h> |
14 | +#include <linux/bitmap.h> | |
14 | 15 | |
15 | 16 | #ifdef CONFIG_PCI |
16 | 17 | #include <linux/pci.h> |
... | ... | @@ -169,7 +170,7 @@ |
169 | 170 | |
170 | 171 | entry = (dma_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT; |
171 | 172 | |
172 | - iommu_area_free(arena->map, entry, npages); | |
173 | + bitmap_clear(arena->map, entry, npages); | |
173 | 174 | } |
174 | 175 | |
175 | 176 | int iommu_table_init(struct iommu *iommu, int tsbsize, |
arch/x86/kernel/amd_iommu.c
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | |
20 | 20 | #include <linux/pci.h> |
21 | 21 | #include <linux/gfp.h> |
22 | -#include <linux/bitops.h> | |
22 | +#include <linux/bitmap.h> | |
23 | 23 | #include <linux/debugfs.h> |
24 | 24 | #include <linux/scatterlist.h> |
25 | 25 | #include <linux/dma-mapping.h> |
... | ... | @@ -1162,7 +1162,7 @@ |
1162 | 1162 | |
1163 | 1163 | address = (address % APERTURE_RANGE_SIZE) >> PAGE_SHIFT; |
1164 | 1164 | |
1165 | - iommu_area_free(range->bitmap, address, pages); | |
1165 | + bitmap_clear(range->bitmap, address, pages); | |
1166 | 1166 | |
1167 | 1167 | } |
1168 | 1168 |
arch/x86/kernel/pci-calgary_64.c
... | ... | @@ -31,7 +31,7 @@ |
31 | 31 | #include <linux/string.h> |
32 | 32 | #include <linux/crash_dump.h> |
33 | 33 | #include <linux/dma-mapping.h> |
34 | -#include <linux/bitops.h> | |
34 | +#include <linux/bitmap.h> | |
35 | 35 | #include <linux/pci_ids.h> |
36 | 36 | #include <linux/pci.h> |
37 | 37 | #include <linux/delay.h> |
... | ... | @@ -212,7 +212,7 @@ |
212 | 212 | |
213 | 213 | spin_lock_irqsave(&tbl->it_lock, flags); |
214 | 214 | |
215 | - iommu_area_reserve(tbl->it_map, index, npages); | |
215 | + bitmap_set(tbl->it_map, index, npages); | |
216 | 216 | |
217 | 217 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
218 | 218 | } |
... | ... | @@ -303,7 +303,7 @@ |
303 | 303 | |
304 | 304 | spin_lock_irqsave(&tbl->it_lock, flags); |
305 | 305 | |
306 | - iommu_area_free(tbl->it_map, entry, npages); | |
306 | + bitmap_clear(tbl->it_map, entry, npages); | |
307 | 307 | |
308 | 308 | spin_unlock_irqrestore(&tbl->it_lock, flags); |
309 | 309 | } |
arch/x86/kernel/pci-gart_64.c
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | #include <linux/module.h> |
24 | 24 | #include <linux/topology.h> |
25 | 25 | #include <linux/interrupt.h> |
26 | -#include <linux/bitops.h> | |
26 | +#include <linux/bitmap.h> | |
27 | 27 | #include <linux/kdebug.h> |
28 | 28 | #include <linux/scatterlist.h> |
29 | 29 | #include <linux/iommu-helper.h> |
... | ... | @@ -126,7 +126,7 @@ |
126 | 126 | unsigned long flags; |
127 | 127 | |
128 | 128 | spin_lock_irqsave(&iommu_bitmap_lock, flags); |
129 | - iommu_area_free(iommu_gart_bitmap, offset, size); | |
129 | + bitmap_clear(iommu_gart_bitmap, offset, size); | |
130 | 130 | if (offset >= next_bit) |
131 | 131 | next_bit = offset + size; |
132 | 132 | spin_unlock_irqrestore(&iommu_bitmap_lock, flags); |
... | ... | @@ -792,7 +792,7 @@ |
792 | 792 | * Out of IOMMU space handling. |
793 | 793 | * Reserve some invalid pages at the beginning of the GART. |
794 | 794 | */ |
795 | - iommu_area_reserve(iommu_gart_bitmap, 0, EMERGENCY_PAGES); | |
795 | + bitmap_set(iommu_gart_bitmap, 0, EMERGENCY_PAGES); | |
796 | 796 | |
797 | 797 | pr_info("PCI-DMA: Reserving %luMB of IOMMU area in the AGP aperture\n", |
798 | 798 | iommu_size >> 20); |
include/linux/iommu-helper.h
... | ... | @@ -14,14 +14,11 @@ |
14 | 14 | extern int iommu_is_span_boundary(unsigned int index, unsigned int nr, |
15 | 15 | unsigned long shift, |
16 | 16 | unsigned long boundary_size); |
17 | -extern void iommu_area_reserve(unsigned long *map, unsigned long i, int len); | |
18 | 17 | extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size, |
19 | 18 | unsigned long start, unsigned int nr, |
20 | 19 | unsigned long shift, |
21 | 20 | unsigned long boundary_size, |
22 | 21 | unsigned long align_mask); |
23 | -extern void iommu_area_free(unsigned long *map, unsigned long start, | |
24 | - unsigned int nr); | |
25 | 22 | |
26 | 23 | extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len, |
27 | 24 | unsigned long io_page_size); |
lib/iommu-helper.c
... | ... | @@ -3,42 +3,8 @@ |
3 | 3 | */ |
4 | 4 | |
5 | 5 | #include <linux/module.h> |
6 | -#include <linux/bitops.h> | |
6 | +#include <linux/bitmap.h> | |
7 | 7 | |
8 | -static unsigned long find_next_zero_area(unsigned long *map, | |
9 | - unsigned long size, | |
10 | - unsigned long start, | |
11 | - unsigned int nr, | |
12 | - unsigned long align_mask) | |
13 | -{ | |
14 | - unsigned long index, end, i; | |
15 | -again: | |
16 | - index = find_next_zero_bit(map, size, start); | |
17 | - | |
18 | - /* Align allocation */ | |
19 | - index = (index + align_mask) & ~align_mask; | |
20 | - | |
21 | - end = index + nr; | |
22 | - if (end >= size) | |
23 | - return -1; | |
24 | - for (i = index; i < end; i++) { | |
25 | - if (test_bit(i, map)) { | |
26 | - start = i+1; | |
27 | - goto again; | |
28 | - } | |
29 | - } | |
30 | - return index; | |
31 | -} | |
32 | - | |
33 | -void iommu_area_reserve(unsigned long *map, unsigned long i, int len) | |
34 | -{ | |
35 | - unsigned long end = i + len; | |
36 | - while (i < end) { | |
37 | - __set_bit(i, map); | |
38 | - i++; | |
39 | - } | |
40 | -} | |
41 | - | |
42 | 8 | int iommu_is_span_boundary(unsigned int index, unsigned int nr, |
43 | 9 | unsigned long shift, |
44 | 10 | unsigned long boundary_size) |
45 | 11 | |
46 | 12 | |
47 | 13 | |
48 | 14 | |
... | ... | @@ -55,30 +21,23 @@ |
55 | 21 | unsigned long align_mask) |
56 | 22 | { |
57 | 23 | unsigned long index; |
24 | + | |
25 | + /* We don't want the last of the limit */ | |
26 | + size -= 1; | |
58 | 27 | again: |
59 | - index = find_next_zero_area(map, size, start, nr, align_mask); | |
60 | - if (index != -1) { | |
28 | + index = bitmap_find_next_zero_area(map, size, start, nr, align_mask); | |
29 | + if (index < size) { | |
61 | 30 | if (iommu_is_span_boundary(index, nr, shift, boundary_size)) { |
62 | 31 | /* we could do more effectively */ |
63 | 32 | start = index + 1; |
64 | 33 | goto again; |
65 | 34 | } |
66 | - iommu_area_reserve(map, index, nr); | |
35 | + bitmap_set(map, index, nr); | |
36 | + return index; | |
67 | 37 | } |
68 | - return index; | |
38 | + return -1; | |
69 | 39 | } |
70 | 40 | EXPORT_SYMBOL(iommu_area_alloc); |
71 | - | |
72 | -void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) | |
73 | -{ | |
74 | - unsigned long end = start + nr; | |
75 | - | |
76 | - while (start < end) { | |
77 | - __clear_bit(start, map); | |
78 | - start++; | |
79 | - } | |
80 | -} | |
81 | -EXPORT_SYMBOL(iommu_area_free); | |
82 | 41 | |
83 | 42 | unsigned long iommu_num_pages(unsigned long addr, unsigned long len, |
84 | 43 | unsigned long io_page_size) |