aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSowmini Varadhan <sowmini.varadhan@oracle.com>2015-03-12 20:02:36 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-16 15:44:56 -0400
commitf1600e549b948a32ad7672e069b2915314637ae3 (patch)
tree1386e80c8654c0a88b80c56f605a2705e0f4a115
parent10b88a4b17d31a7409494b179dcb76e7ab2fcaea (diff)
sparc: Make sparc64 use scalable lib/iommu-common.c functions
In iperf experiments running linux as the Tx side (TCP client) with 10 threads results in a severe performance drop when TSO is disabled, indicating a weakness in the software that can be avoided by using the scalable IOMMU arena DMA allocation. Baseline numbers before this patch: with default settings (TSO enabled) : 9-9.5 Gbps Disable TSO using ethtool- drops badly: 2-3 Gbps. After this patch, iperf client with 10 threads, can give a throughput of at least 8.5 Gbps, even when TSO is disabled. Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/sparc/include/asm/iommu_64.h7
-rw-r--r--arch/sparc/kernel/iommu.c188
-rw-r--r--arch/sparc/kernel/iommu_common.h8
-rw-r--r--arch/sparc/kernel/pci_sun4v.c193
4 files changed, 160 insertions, 236 deletions
diff --git a/arch/sparc/include/asm/iommu_64.h b/arch/sparc/include/asm/iommu_64.h
index 2b9321ab064d..e3cd4493d81d 100644
--- a/arch/sparc/include/asm/iommu_64.h
+++ b/arch/sparc/include/asm/iommu_64.h
@@ -16,6 +16,7 @@
16#define IOPTE_WRITE 0x0000000000000002UL 16#define IOPTE_WRITE 0x0000000000000002UL
17 17
18#define IOMMU_NUM_CTXS 4096 18#define IOMMU_NUM_CTXS 4096
19#include <linux/iommu-common.h>
19 20
20struct iommu_arena { 21struct iommu_arena {
21 unsigned long *map; 22 unsigned long *map;
@@ -24,11 +25,10 @@ struct iommu_arena {
24}; 25};
25 26
26struct iommu { 27struct iommu {
28 struct iommu_table tbl;
27 spinlock_t lock; 29 spinlock_t lock;
28 struct iommu_arena arena; 30 u32 dma_addr_mask;
29 void (*flush_all)(struct iommu *);
30 iopte_t *page_table; 31 iopte_t *page_table;
31 u32 page_table_map_base;
32 unsigned long iommu_control; 32 unsigned long iommu_control;
33 unsigned long iommu_tsbbase; 33 unsigned long iommu_tsbbase;
34 unsigned long iommu_flush; 34 unsigned long iommu_flush;
@@ -40,7 +40,6 @@ struct iommu {
40 unsigned long dummy_page_pa; 40 unsigned long dummy_page_pa;
41 unsigned long ctx_lowest_free; 41 unsigned long ctx_lowest_free;
42 DECLARE_BITMAP(ctx_bitmap, IOMMU_NUM_CTXS); 42 DECLARE_BITMAP(ctx_bitmap, IOMMU_NUM_CTXS);
43 u32 dma_addr_mask;
44}; 43};
45 44
46struct strbuf { 45struct strbuf {
diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
index bfa4d0c2df42..9b16b341b6ae 100644
--- a/arch/sparc/kernel/iommu.c
+++ b/arch/sparc/kernel/iommu.c
@@ -13,11 +13,15 @@
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/iommu-helper.h> 14#include <linux/iommu-helper.h>
15#include <linux/bitmap.h> 15#include <linux/bitmap.h>
16#include <linux/hash.h>
17#include <linux/iommu-common.h>
16 18
17#ifdef CONFIG_PCI 19#ifdef CONFIG_PCI
18#include <linux/pci.h> 20#include <linux/pci.h>
19#endif 21#endif
20 22
23static DEFINE_PER_CPU(unsigned int, iommu_pool_hash);
24
21#include <asm/iommu.h> 25#include <asm/iommu.h>
22 26
23#include "iommu_common.h" 27#include "iommu_common.h"
@@ -45,8 +49,9 @@
45 "i" (ASI_PHYS_BYPASS_EC_E)) 49 "i" (ASI_PHYS_BYPASS_EC_E))
46 50
47/* Must be invoked under the IOMMU lock. */ 51/* Must be invoked under the IOMMU lock. */
48static void iommu_flushall(struct iommu *iommu) 52static void iommu_flushall(struct iommu_table *iommu_table)
49{ 53{
54 struct iommu *iommu = container_of(iommu_table, struct iommu, tbl);
50 if (iommu->iommu_flushinv) { 55 if (iommu->iommu_flushinv) {
51 iommu_write(iommu->iommu_flushinv, ~(u64)0); 56 iommu_write(iommu->iommu_flushinv, ~(u64)0);
52 } else { 57 } else {
@@ -87,94 +92,23 @@ static inline void iopte_make_dummy(struct iommu *iommu, iopte_t *iopte)
87 iopte_val(*iopte) = val; 92 iopte_val(*iopte) = val;
88} 93}
89 94
90/* Based almost entirely upon the ppc64 iommu allocator. If you use the 'handle' 95static struct iommu_tbl_ops iommu_sparc_ops = {
91 * facility it must all be done in one pass while under the iommu lock. 96 .reset = iommu_flushall
92 * 97};
93 * On sun4u platforms, we only flush the IOMMU once every time we've passed
94 * over the entire page table doing allocations. Therefore we only ever advance
95 * the hint and cannot backtrack it.
96 */
97unsigned long iommu_range_alloc(struct device *dev,
98 struct iommu *iommu,
99 unsigned long npages,
100 unsigned long *handle)
101{
102 unsigned long n, end, start, limit, boundary_size;
103 struct iommu_arena *arena = &iommu->arena;
104 int pass = 0;
105
106 /* This allocator was derived from x86_64's bit string search */
107
108 /* Sanity check */
109 if (unlikely(npages == 0)) {
110 if (printk_ratelimit())
111 WARN_ON(1);
112 return DMA_ERROR_CODE;
113 }
114
115 if (handle && *handle)
116 start = *handle;
117 else
118 start = arena->hint;
119
120 limit = arena->limit;
121
122 /* The case below can happen if we have a small segment appended
123 * to a large, or when the previous alloc was at the very end of
124 * the available space. If so, go back to the beginning and flush.
125 */
126 if (start >= limit) {
127 start = 0;
128 if (iommu->flush_all)
129 iommu->flush_all(iommu);
130 }
131
132 again:
133
134 if (dev)
135 boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
136 1 << IO_PAGE_SHIFT);
137 else
138 boundary_size = ALIGN(1UL << 32, 1 << IO_PAGE_SHIFT);
139
140 n = iommu_area_alloc(arena->map, limit, start, npages,
141 iommu->page_table_map_base >> IO_PAGE_SHIFT,
142 boundary_size >> IO_PAGE_SHIFT, 0);
143 if (n == -1) {
144 if (likely(pass < 1)) {
145 /* First failure, rescan from the beginning. */
146 start = 0;
147 if (iommu->flush_all)
148 iommu->flush_all(iommu);
149 pass++;
150 goto again;
151 } else {
152 /* Second failure, give up */
153 return DMA_ERROR_CODE;
154 }
155 }
156
157 end = n + npages;
158
159 arena->hint = end;
160
161 /* Update handle for SG allocations */
162 if (handle)
163 *handle = end;
164
165 return n;
166}
167 98
168void iommu_range_free(struct iommu *iommu, dma_addr_t dma_addr, unsigned long npages) 99static void setup_iommu_pool_hash(void)
169{ 100{
170 struct iommu_arena *arena = &iommu->arena; 101 unsigned int i;
171 unsigned long entry; 102 static bool do_once;
172
173 entry = (dma_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT;
174 103
175 bitmap_clear(arena->map, entry, npages); 104 if (do_once)
105 return;
106 do_once = true;
107 for_each_possible_cpu(i)
108 per_cpu(iommu_pool_hash, i) = hash_32(i, IOMMU_POOL_HASHBITS);
176} 109}
177 110
111
178int iommu_table_init(struct iommu *iommu, int tsbsize, 112int iommu_table_init(struct iommu *iommu, int tsbsize,
179 u32 dma_offset, u32 dma_addr_mask, 113 u32 dma_offset, u32 dma_addr_mask,
180 int numa_node) 114 int numa_node)
@@ -187,22 +121,22 @@ int iommu_table_init(struct iommu *iommu, int tsbsize,
187 /* Setup initial software IOMMU state. */ 121 /* Setup initial software IOMMU state. */
188 spin_lock_init(&iommu->lock); 122 spin_lock_init(&iommu->lock);
189 iommu->ctx_lowest_free = 1; 123 iommu->ctx_lowest_free = 1;
190 iommu->page_table_map_base = dma_offset; 124 iommu->tbl.page_table_map_base = dma_offset;
191 iommu->dma_addr_mask = dma_addr_mask; 125 iommu->dma_addr_mask = dma_addr_mask;
192 126
193 /* Allocate and initialize the free area map. */ 127 /* Allocate and initialize the free area map. */
194 sz = num_tsb_entries / 8; 128 sz = num_tsb_entries / 8;
195 sz = (sz + 7UL) & ~7UL; 129 sz = (sz + 7UL) & ~7UL;
196 iommu->arena.map = kmalloc_node(sz, GFP_KERNEL, numa_node); 130 iommu->tbl.map = kmalloc_node(sz, GFP_KERNEL, numa_node);
197 if (!iommu->arena.map) { 131 if (!iommu->tbl.map)
198 printk(KERN_ERR "IOMMU: Error, kmalloc(arena.map) failed.\n");
199 return -ENOMEM; 132 return -ENOMEM;
200 } 133 memset(iommu->tbl.map, 0, sz);
201 memset(iommu->arena.map, 0, sz);
202 iommu->arena.limit = num_tsb_entries;
203
204 if (tlb_type != hypervisor) 134 if (tlb_type != hypervisor)
205 iommu->flush_all = iommu_flushall; 135 iommu_sparc_ops.reset = NULL; /* not needed on on sun4v */
136
137 setup_iommu_pool_hash();
138 iommu_tbl_pool_init(&iommu->tbl, num_tsb_entries, IO_PAGE_SHIFT,
139 &iommu_sparc_ops, false, 1);
206 140
207 /* Allocate and initialize the dummy page which we 141 /* Allocate and initialize the dummy page which we
208 * set inactive IO PTEs to point to. 142 * set inactive IO PTEs to point to.
@@ -235,18 +169,20 @@ out_free_dummy_page:
235 iommu->dummy_page = 0UL; 169 iommu->dummy_page = 0UL;
236 170
237out_free_map: 171out_free_map:
238 kfree(iommu->arena.map); 172 kfree(iommu->tbl.map);
239 iommu->arena.map = NULL; 173 iommu->tbl.map = NULL;
240 174
241 return -ENOMEM; 175 return -ENOMEM;
242} 176}
243 177
244static inline iopte_t *alloc_npages(struct device *dev, struct iommu *iommu, 178static inline iopte_t *alloc_npages(struct device *dev,
179 struct iommu *iommu,
245 unsigned long npages) 180 unsigned long npages)
246{ 181{
247 unsigned long entry; 182 unsigned long entry;
248 183
249 entry = iommu_range_alloc(dev, iommu, npages, NULL); 184 entry = iommu_tbl_range_alloc(dev, &iommu->tbl, npages, NULL,
185 __this_cpu_read(iommu_pool_hash));
250 if (unlikely(entry == DMA_ERROR_CODE)) 186 if (unlikely(entry == DMA_ERROR_CODE))
251 return NULL; 187 return NULL;
252 188
@@ -284,7 +220,7 @@ static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
284 dma_addr_t *dma_addrp, gfp_t gfp, 220 dma_addr_t *dma_addrp, gfp_t gfp,
285 struct dma_attrs *attrs) 221 struct dma_attrs *attrs)
286{ 222{
287 unsigned long flags, order, first_page; 223 unsigned long order, first_page;
288 struct iommu *iommu; 224 struct iommu *iommu;
289 struct page *page; 225 struct page *page;
290 int npages, nid; 226 int npages, nid;
@@ -306,16 +242,14 @@ static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
306 242
307 iommu = dev->archdata.iommu; 243 iommu = dev->archdata.iommu;
308 244
309 spin_lock_irqsave(&iommu->lock, flags);
310 iopte = alloc_npages(dev, iommu, size >> IO_PAGE_SHIFT); 245 iopte = alloc_npages(dev, iommu, size >> IO_PAGE_SHIFT);
311 spin_unlock_irqrestore(&iommu->lock, flags);
312 246
313 if (unlikely(iopte == NULL)) { 247 if (unlikely(iopte == NULL)) {
314 free_pages(first_page, order); 248 free_pages(first_page, order);
315 return NULL; 249 return NULL;
316 } 250 }
317 251
318 *dma_addrp = (iommu->page_table_map_base + 252 *dma_addrp = (iommu->tbl.page_table_map_base +
319 ((iopte - iommu->page_table) << IO_PAGE_SHIFT)); 253 ((iopte - iommu->page_table) << IO_PAGE_SHIFT));
320 ret = (void *) first_page; 254 ret = (void *) first_page;
321 npages = size >> IO_PAGE_SHIFT; 255 npages = size >> IO_PAGE_SHIFT;
@@ -336,16 +270,12 @@ static void dma_4u_free_coherent(struct device *dev, size_t size,
336 struct dma_attrs *attrs) 270 struct dma_attrs *attrs)
337{ 271{
338 struct iommu *iommu; 272 struct iommu *iommu;
339 unsigned long flags, order, npages; 273 unsigned long order, npages;
340 274
341 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT; 275 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
342 iommu = dev->archdata.iommu; 276 iommu = dev->archdata.iommu;
343 277
344 spin_lock_irqsave(&iommu->lock, flags); 278 iommu_tbl_range_free(&iommu->tbl, dvma, npages, false, NULL);
345
346 iommu_range_free(iommu, dvma, npages);
347
348 spin_unlock_irqrestore(&iommu->lock, flags);
349 279
350 order = get_order(size); 280 order = get_order(size);
351 if (order < 10) 281 if (order < 10)
@@ -375,8 +305,8 @@ static dma_addr_t dma_4u_map_page(struct device *dev, struct page *page,
375 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK); 305 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
376 npages >>= IO_PAGE_SHIFT; 306 npages >>= IO_PAGE_SHIFT;
377 307
378 spin_lock_irqsave(&iommu->lock, flags);
379 base = alloc_npages(dev, iommu, npages); 308 base = alloc_npages(dev, iommu, npages);
309 spin_lock_irqsave(&iommu->lock, flags);
380 ctx = 0; 310 ctx = 0;
381 if (iommu->iommu_ctxflush) 311 if (iommu->iommu_ctxflush)
382 ctx = iommu_alloc_ctx(iommu); 312 ctx = iommu_alloc_ctx(iommu);
@@ -385,7 +315,7 @@ static dma_addr_t dma_4u_map_page(struct device *dev, struct page *page,
385 if (unlikely(!base)) 315 if (unlikely(!base))
386 goto bad; 316 goto bad;
387 317
388 bus_addr = (iommu->page_table_map_base + 318 bus_addr = (iommu->tbl.page_table_map_base +
389 ((base - iommu->page_table) << IO_PAGE_SHIFT)); 319 ((base - iommu->page_table) << IO_PAGE_SHIFT));
390 ret = bus_addr | (oaddr & ~IO_PAGE_MASK); 320 ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
391 base_paddr = __pa(oaddr & IO_PAGE_MASK); 321 base_paddr = __pa(oaddr & IO_PAGE_MASK);
@@ -496,7 +426,7 @@ static void dma_4u_unmap_page(struct device *dev, dma_addr_t bus_addr,
496 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK); 426 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
497 npages >>= IO_PAGE_SHIFT; 427 npages >>= IO_PAGE_SHIFT;
498 base = iommu->page_table + 428 base = iommu->page_table +
499 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 429 ((bus_addr - iommu->tbl.page_table_map_base) >> IO_PAGE_SHIFT);
500 bus_addr &= IO_PAGE_MASK; 430 bus_addr &= IO_PAGE_MASK;
501 431
502 spin_lock_irqsave(&iommu->lock, flags); 432 spin_lock_irqsave(&iommu->lock, flags);
@@ -515,11 +445,11 @@ static void dma_4u_unmap_page(struct device *dev, dma_addr_t bus_addr,
515 for (i = 0; i < npages; i++) 445 for (i = 0; i < npages; i++)
516 iopte_make_dummy(iommu, base + i); 446 iopte_make_dummy(iommu, base + i);
517 447
518 iommu_range_free(iommu, bus_addr, npages);
519
520 iommu_free_ctx(iommu, ctx); 448 iommu_free_ctx(iommu, ctx);
521
522 spin_unlock_irqrestore(&iommu->lock, flags); 449 spin_unlock_irqrestore(&iommu->lock, flags);
450
451 iommu_tbl_range_free(&iommu->tbl, bus_addr, npages,
452 false, NULL);
523} 453}
524 454
525static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist, 455static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
@@ -567,7 +497,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
567 max_seg_size = dma_get_max_seg_size(dev); 497 max_seg_size = dma_get_max_seg_size(dev);
568 seg_boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1, 498 seg_boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
569 IO_PAGE_SIZE) >> IO_PAGE_SHIFT; 499 IO_PAGE_SIZE) >> IO_PAGE_SHIFT;
570 base_shift = iommu->page_table_map_base >> IO_PAGE_SHIFT; 500 base_shift = iommu->tbl.page_table_map_base >> IO_PAGE_SHIFT;
571 for_each_sg(sglist, s, nelems, i) { 501 for_each_sg(sglist, s, nelems, i) {
572 unsigned long paddr, npages, entry, out_entry = 0, slen; 502 unsigned long paddr, npages, entry, out_entry = 0, slen;
573 iopte_t *base; 503 iopte_t *base;
@@ -581,7 +511,8 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
581 /* Allocate iommu entries for that segment */ 511 /* Allocate iommu entries for that segment */
582 paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s); 512 paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
583 npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE); 513 npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE);
584 entry = iommu_range_alloc(dev, iommu, npages, &handle); 514 entry = iommu_tbl_range_alloc(dev, &iommu->tbl, npages, &handle,
515 __this_cpu_read(iommu_pool_hash));
585 516
586 /* Handle failure */ 517 /* Handle failure */
587 if (unlikely(entry == DMA_ERROR_CODE)) { 518 if (unlikely(entry == DMA_ERROR_CODE)) {
@@ -594,7 +525,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
594 base = iommu->page_table + entry; 525 base = iommu->page_table + entry;
595 526
596 /* Convert entry to a dma_addr_t */ 527 /* Convert entry to a dma_addr_t */
597 dma_addr = iommu->page_table_map_base + 528 dma_addr = iommu->tbl.page_table_map_base +
598 (entry << IO_PAGE_SHIFT); 529 (entry << IO_PAGE_SHIFT);
599 dma_addr |= (s->offset & ~IO_PAGE_MASK); 530 dma_addr |= (s->offset & ~IO_PAGE_MASK);
600 531
@@ -654,15 +585,17 @@ iommu_map_failed:
654 vaddr = s->dma_address & IO_PAGE_MASK; 585 vaddr = s->dma_address & IO_PAGE_MASK;
655 npages = iommu_num_pages(s->dma_address, s->dma_length, 586 npages = iommu_num_pages(s->dma_address, s->dma_length,
656 IO_PAGE_SIZE); 587 IO_PAGE_SIZE);
657 iommu_range_free(iommu, vaddr, npages);
658 588
659 entry = (vaddr - iommu->page_table_map_base) 589 entry = (vaddr - iommu->tbl.page_table_map_base)
660 >> IO_PAGE_SHIFT; 590 >> IO_PAGE_SHIFT;
661 base = iommu->page_table + entry; 591 base = iommu->page_table + entry;
662 592
663 for (j = 0; j < npages; j++) 593 for (j = 0; j < npages; j++)
664 iopte_make_dummy(iommu, base + j); 594 iopte_make_dummy(iommu, base + j);
665 595
596 iommu_tbl_range_free(&iommu->tbl, vaddr, npages,
597 false, NULL);
598
666 s->dma_address = DMA_ERROR_CODE; 599 s->dma_address = DMA_ERROR_CODE;
667 s->dma_length = 0; 600 s->dma_length = 0;
668 } 601 }
@@ -677,17 +610,19 @@ iommu_map_failed:
677/* If contexts are being used, they are the same in all of the mappings 610/* If contexts are being used, they are the same in all of the mappings
678 * we make for a particular SG. 611 * we make for a particular SG.
679 */ 612 */
680static unsigned long fetch_sg_ctx(struct iommu *iommu, struct scatterlist *sg) 613static unsigned long fetch_sg_ctx(struct iommu *iommu,
614 struct scatterlist *sg)
681{ 615{
682 unsigned long ctx = 0; 616 unsigned long ctx = 0;
683 617
684 if (iommu->iommu_ctxflush) { 618 if (iommu->iommu_ctxflush) {
685 iopte_t *base; 619 iopte_t *base;
686 u32 bus_addr; 620 u32 bus_addr;
621 struct iommu_table *tbl = &iommu->tbl;
687 622
688 bus_addr = sg->dma_address & IO_PAGE_MASK; 623 bus_addr = sg->dma_address & IO_PAGE_MASK;
689 base = iommu->page_table + 624 base = iommu->page_table +
690 ((bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 625 ((bus_addr - tbl->page_table_map_base) >> IO_PAGE_SHIFT);
691 626
692 ctx = (iopte_val(*base) & IOPTE_CONTEXT) >> 47UL; 627 ctx = (iopte_val(*base) & IOPTE_CONTEXT) >> 47UL;
693 } 628 }
@@ -723,9 +658,8 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
723 if (!len) 658 if (!len)
724 break; 659 break;
725 npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE); 660 npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE);
726 iommu_range_free(iommu, dma_handle, npages);
727 661
728 entry = ((dma_handle - iommu->page_table_map_base) 662 entry = ((dma_handle - iommu->tbl.page_table_map_base)
729 >> IO_PAGE_SHIFT); 663 >> IO_PAGE_SHIFT);
730 base = iommu->page_table + entry; 664 base = iommu->page_table + entry;
731 665
@@ -737,6 +671,8 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
737 for (i = 0; i < npages; i++) 671 for (i = 0; i < npages; i++)
738 iopte_make_dummy(iommu, base + i); 672 iopte_make_dummy(iommu, base + i);
739 673
674 iommu_tbl_range_free(&iommu->tbl, dma_handle, npages, false,
675 NULL);
740 sg = sg_next(sg); 676 sg = sg_next(sg);
741 } 677 }
742 678
@@ -770,9 +706,10 @@ static void dma_4u_sync_single_for_cpu(struct device *dev,
770 if (iommu->iommu_ctxflush && 706 if (iommu->iommu_ctxflush &&
771 strbuf->strbuf_ctxflush) { 707 strbuf->strbuf_ctxflush) {
772 iopte_t *iopte; 708 iopte_t *iopte;
709 struct iommu_table *tbl = &iommu->tbl;
773 710
774 iopte = iommu->page_table + 711 iopte = iommu->page_table +
775 ((bus_addr - iommu->page_table_map_base)>>IO_PAGE_SHIFT); 712 ((bus_addr - tbl->page_table_map_base)>>IO_PAGE_SHIFT);
776 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL; 713 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
777 } 714 }
778 715
@@ -805,9 +742,10 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
805 if (iommu->iommu_ctxflush && 742 if (iommu->iommu_ctxflush &&
806 strbuf->strbuf_ctxflush) { 743 strbuf->strbuf_ctxflush) {
807 iopte_t *iopte; 744 iopte_t *iopte;
745 struct iommu_table *tbl = &iommu->tbl;
808 746
809 iopte = iommu->page_table + 747 iopte = iommu->page_table + ((sglist[0].dma_address -
810 ((sglist[0].dma_address - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 748 tbl->page_table_map_base) >> IO_PAGE_SHIFT);
811 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL; 749 ctx = (iopte_val(*iopte) & IOPTE_CONTEXT) >> 47UL;
812 } 750 }
813 751
diff --git a/arch/sparc/kernel/iommu_common.h b/arch/sparc/kernel/iommu_common.h
index 1ec0de4156e7..f4be0d724fc6 100644
--- a/arch/sparc/kernel/iommu_common.h
+++ b/arch/sparc/kernel/iommu_common.h
@@ -48,12 +48,4 @@ static inline int is_span_boundary(unsigned long entry,
48 return iommu_is_span_boundary(entry, nr, shift, boundary_size); 48 return iommu_is_span_boundary(entry, nr, shift, boundary_size);
49} 49}
50 50
51unsigned long iommu_range_alloc(struct device *dev,
52 struct iommu *iommu,
53 unsigned long npages,
54 unsigned long *handle);
55void iommu_range_free(struct iommu *iommu,
56 dma_addr_t dma_addr,
57 unsigned long npages);
58
59#endif /* _IOMMU_COMMON_H */ 51#endif /* _IOMMU_COMMON_H */
diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
index 47ddbd496a1e..9b76b9d639e1 100644
--- a/arch/sparc/kernel/pci_sun4v.c
+++ b/arch/sparc/kernel/pci_sun4v.c
@@ -15,6 +15,8 @@
15#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/log2.h> 16#include <linux/log2.h>
17#include <linux/of_device.h> 17#include <linux/of_device.h>
18#include <linux/hash.h>
19#include <linux/iommu-common.h>
18 20
19#include <asm/iommu.h> 21#include <asm/iommu.h>
20#include <asm/irq.h> 22#include <asm/irq.h>
@@ -28,6 +30,7 @@
28 30
29#define DRIVER_NAME "pci_sun4v" 31#define DRIVER_NAME "pci_sun4v"
30#define PFX DRIVER_NAME ": " 32#define PFX DRIVER_NAME ": "
33static DEFINE_PER_CPU(unsigned int, iommu_pool_hash);
31 34
32static unsigned long vpci_major = 1; 35static unsigned long vpci_major = 1;
33static unsigned long vpci_minor = 1; 36static unsigned long vpci_minor = 1;
@@ -155,14 +158,13 @@ static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
155 158
156 iommu = dev->archdata.iommu; 159 iommu = dev->archdata.iommu;
157 160
158 spin_lock_irqsave(&iommu->lock, flags); 161 entry = iommu_tbl_range_alloc(dev, &iommu->tbl, npages, NULL,
159 entry = iommu_range_alloc(dev, iommu, npages, NULL); 162 __this_cpu_read(iommu_pool_hash));
160 spin_unlock_irqrestore(&iommu->lock, flags);
161 163
162 if (unlikely(entry == DMA_ERROR_CODE)) 164 if (unlikely(entry == DMA_ERROR_CODE))
163 goto range_alloc_fail; 165 goto range_alloc_fail;
164 166
165 *dma_addrp = (iommu->page_table_map_base + 167 *dma_addrp = (iommu->tbl.page_table_map_base +
166 (entry << IO_PAGE_SHIFT)); 168 (entry << IO_PAGE_SHIFT));
167 ret = (void *) first_page; 169 ret = (void *) first_page;
168 first_page = __pa(first_page); 170 first_page = __pa(first_page);
@@ -188,45 +190,46 @@ static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
188 return ret; 190 return ret;
189 191
190iommu_map_fail: 192iommu_map_fail:
191 /* Interrupts are disabled. */ 193 iommu_tbl_range_free(&iommu->tbl, *dma_addrp, npages, false, NULL);
192 spin_lock(&iommu->lock);
193 iommu_range_free(iommu, *dma_addrp, npages);
194 spin_unlock_irqrestore(&iommu->lock, flags);
195 194
196range_alloc_fail: 195range_alloc_fail:
197 free_pages(first_page, order); 196 free_pages(first_page, order);
198 return NULL; 197 return NULL;
199} 198}
200 199
200static void dma_4v_iommu_demap(void *demap_arg, unsigned long entry,
201 unsigned long npages)
202{
203 u32 devhandle = *(u32 *)demap_arg;
204 unsigned long num, flags;
205
206 local_irq_save(flags);
207 do {
208 num = pci_sun4v_iommu_demap(devhandle,
209 HV_PCI_TSBID(0, entry),
210 npages);
211
212 entry += num;
213 npages -= num;
214 } while (npages != 0);
215 local_irq_restore(flags);
216}
217
201static void dma_4v_free_coherent(struct device *dev, size_t size, void *cpu, 218static void dma_4v_free_coherent(struct device *dev, size_t size, void *cpu,
202 dma_addr_t dvma, struct dma_attrs *attrs) 219 dma_addr_t dvma, struct dma_attrs *attrs)
203{ 220{
204 struct pci_pbm_info *pbm; 221 struct pci_pbm_info *pbm;
205 struct iommu *iommu; 222 struct iommu *iommu;
206 unsigned long flags, order, npages, entry; 223 unsigned long order, npages, entry;
207 u32 devhandle; 224 u32 devhandle;
208 225
209 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT; 226 npages = IO_PAGE_ALIGN(size) >> IO_PAGE_SHIFT;
210 iommu = dev->archdata.iommu; 227 iommu = dev->archdata.iommu;
211 pbm = dev->archdata.host_controller; 228 pbm = dev->archdata.host_controller;
212 devhandle = pbm->devhandle; 229 devhandle = pbm->devhandle;
213 entry = ((dvma - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 230 entry = ((dvma - iommu->tbl.page_table_map_base) >> IO_PAGE_SHIFT);
214 231 dma_4v_iommu_demap(&devhandle, entry, npages);
215 spin_lock_irqsave(&iommu->lock, flags); 232 iommu_tbl_range_free(&iommu->tbl, dvma, npages, false, NULL);
216
217 iommu_range_free(iommu, dvma, npages);
218
219 do {
220 unsigned long num;
221
222 num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry),
223 npages);
224 entry += num;
225 npages -= num;
226 } while (npages != 0);
227
228 spin_unlock_irqrestore(&iommu->lock, flags);
229
230 order = get_order(size); 233 order = get_order(size);
231 if (order < 10) 234 if (order < 10)
232 free_pages((unsigned long)cpu, order); 235 free_pages((unsigned long)cpu, order);
@@ -253,14 +256,13 @@ static dma_addr_t dma_4v_map_page(struct device *dev, struct page *page,
253 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK); 256 npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
254 npages >>= IO_PAGE_SHIFT; 257 npages >>= IO_PAGE_SHIFT;
255 258
256 spin_lock_irqsave(&iommu->lock, flags); 259 entry = iommu_tbl_range_alloc(dev, &iommu->tbl, npages, NULL,
257 entry = iommu_range_alloc(dev, iommu, npages, NULL); 260 __this_cpu_read(iommu_pool_hash));
258 spin_unlock_irqrestore(&iommu->lock, flags);
259 261
260 if (unlikely(entry == DMA_ERROR_CODE)) 262 if (unlikely(entry == DMA_ERROR_CODE))
261 goto bad; 263 goto bad;
262 264
263 bus_addr = (iommu->page_table_map_base + 265 bus_addr = (iommu->tbl.page_table_map_base +
264 (entry << IO_PAGE_SHIFT)); 266 (entry << IO_PAGE_SHIFT));
265 ret = bus_addr | (oaddr & ~IO_PAGE_MASK); 267 ret = bus_addr | (oaddr & ~IO_PAGE_MASK);
266 base_paddr = __pa(oaddr & IO_PAGE_MASK); 268 base_paddr = __pa(oaddr & IO_PAGE_MASK);
@@ -290,11 +292,7 @@ bad:
290 return DMA_ERROR_CODE; 292 return DMA_ERROR_CODE;
291 293
292iommu_map_fail: 294iommu_map_fail:
293 /* Interrupts are disabled. */ 295 iommu_tbl_range_free(&iommu->tbl, bus_addr, npages, false, NULL);
294 spin_lock(&iommu->lock);
295 iommu_range_free(iommu, bus_addr, npages);
296 spin_unlock_irqrestore(&iommu->lock, flags);
297
298 return DMA_ERROR_CODE; 296 return DMA_ERROR_CODE;
299} 297}
300 298
@@ -304,7 +302,7 @@ static void dma_4v_unmap_page(struct device *dev, dma_addr_t bus_addr,
304{ 302{
305 struct pci_pbm_info *pbm; 303 struct pci_pbm_info *pbm;
306 struct iommu *iommu; 304 struct iommu *iommu;
307 unsigned long flags, npages; 305 unsigned long npages;
308 long entry; 306 long entry;
309 u32 devhandle; 307 u32 devhandle;
310 308
@@ -321,22 +319,9 @@ static void dma_4v_unmap_page(struct device *dev, dma_addr_t bus_addr,
321 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK); 319 npages = IO_PAGE_ALIGN(bus_addr + sz) - (bus_addr & IO_PAGE_MASK);
322 npages >>= IO_PAGE_SHIFT; 320 npages >>= IO_PAGE_SHIFT;
323 bus_addr &= IO_PAGE_MASK; 321 bus_addr &= IO_PAGE_MASK;
324 322 entry = (bus_addr - iommu->tbl.page_table_map_base) >> IO_PAGE_SHIFT;
325 spin_lock_irqsave(&iommu->lock, flags); 323 dma_4v_iommu_demap(&devhandle, entry, npages);
326 324 iommu_tbl_range_free(&iommu->tbl, bus_addr, npages, false, NULL);
327 iommu_range_free(iommu, bus_addr, npages);
328
329 entry = (bus_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT;
330 do {
331 unsigned long num;
332
333 num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry),
334 npages);
335 entry += num;
336 npages -= num;
337 } while (npages != 0);
338
339 spin_unlock_irqrestore(&iommu->lock, flags);
340} 325}
341 326
342static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist, 327static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
@@ -371,14 +356,14 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
371 /* Init first segment length for backout at failure */ 356 /* Init first segment length for backout at failure */
372 outs->dma_length = 0; 357 outs->dma_length = 0;
373 358
374 spin_lock_irqsave(&iommu->lock, flags); 359 local_irq_save(flags);
375 360
376 iommu_batch_start(dev, prot, ~0UL); 361 iommu_batch_start(dev, prot, ~0UL);
377 362
378 max_seg_size = dma_get_max_seg_size(dev); 363 max_seg_size = dma_get_max_seg_size(dev);
379 seg_boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1, 364 seg_boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
380 IO_PAGE_SIZE) >> IO_PAGE_SHIFT; 365 IO_PAGE_SIZE) >> IO_PAGE_SHIFT;
381 base_shift = iommu->page_table_map_base >> IO_PAGE_SHIFT; 366 base_shift = iommu->tbl.page_table_map_base >> IO_PAGE_SHIFT;
382 for_each_sg(sglist, s, nelems, i) { 367 for_each_sg(sglist, s, nelems, i) {
383 unsigned long paddr, npages, entry, out_entry = 0, slen; 368 unsigned long paddr, npages, entry, out_entry = 0, slen;
384 369
@@ -391,7 +376,8 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
391 /* Allocate iommu entries for that segment */ 376 /* Allocate iommu entries for that segment */
392 paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s); 377 paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
393 npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE); 378 npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE);
394 entry = iommu_range_alloc(dev, iommu, npages, &handle); 379 entry = iommu_tbl_range_alloc(dev, &iommu->tbl, npages, &handle,
380 __this_cpu_read(iommu_pool_hash));
395 381
396 /* Handle failure */ 382 /* Handle failure */
397 if (unlikely(entry == DMA_ERROR_CODE)) { 383 if (unlikely(entry == DMA_ERROR_CODE)) {
@@ -404,7 +390,7 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
404 iommu_batch_new_entry(entry); 390 iommu_batch_new_entry(entry);
405 391
406 /* Convert entry to a dma_addr_t */ 392 /* Convert entry to a dma_addr_t */
407 dma_addr = iommu->page_table_map_base + 393 dma_addr = iommu->tbl.page_table_map_base +
408 (entry << IO_PAGE_SHIFT); 394 (entry << IO_PAGE_SHIFT);
409 dma_addr |= (s->offset & ~IO_PAGE_MASK); 395 dma_addr |= (s->offset & ~IO_PAGE_MASK);
410 396
@@ -451,7 +437,7 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
451 if (unlikely(err < 0L)) 437 if (unlikely(err < 0L))
452 goto iommu_map_failed; 438 goto iommu_map_failed;
453 439
454 spin_unlock_irqrestore(&iommu->lock, flags); 440 local_irq_restore(flags);
455 441
456 if (outcount < incount) { 442 if (outcount < incount) {
457 outs = sg_next(outs); 443 outs = sg_next(outs);
@@ -469,7 +455,8 @@ iommu_map_failed:
469 vaddr = s->dma_address & IO_PAGE_MASK; 455 vaddr = s->dma_address & IO_PAGE_MASK;
470 npages = iommu_num_pages(s->dma_address, s->dma_length, 456 npages = iommu_num_pages(s->dma_address, s->dma_length,
471 IO_PAGE_SIZE); 457 IO_PAGE_SIZE);
472 iommu_range_free(iommu, vaddr, npages); 458 iommu_tbl_range_free(&iommu->tbl, vaddr, npages,
459 false, NULL);
473 /* XXX demap? XXX */ 460 /* XXX demap? XXX */
474 s->dma_address = DMA_ERROR_CODE; 461 s->dma_address = DMA_ERROR_CODE;
475 s->dma_length = 0; 462 s->dma_length = 0;
@@ -477,7 +464,7 @@ iommu_map_failed:
477 if (s == outs) 464 if (s == outs)
478 break; 465 break;
479 } 466 }
480 spin_unlock_irqrestore(&iommu->lock, flags); 467 local_irq_restore(flags);
481 468
482 return 0; 469 return 0;
483} 470}
@@ -489,7 +476,7 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
489 struct pci_pbm_info *pbm; 476 struct pci_pbm_info *pbm;
490 struct scatterlist *sg; 477 struct scatterlist *sg;
491 struct iommu *iommu; 478 struct iommu *iommu;
492 unsigned long flags; 479 unsigned long flags, entry;
493 u32 devhandle; 480 u32 devhandle;
494 481
495 BUG_ON(direction == DMA_NONE); 482 BUG_ON(direction == DMA_NONE);
@@ -498,33 +485,27 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
498 pbm = dev->archdata.host_controller; 485 pbm = dev->archdata.host_controller;
499 devhandle = pbm->devhandle; 486 devhandle = pbm->devhandle;
500 487
501 spin_lock_irqsave(&iommu->lock, flags); 488 local_irq_save(flags);
502 489
503 sg = sglist; 490 sg = sglist;
504 while (nelems--) { 491 while (nelems--) {
505 dma_addr_t dma_handle = sg->dma_address; 492 dma_addr_t dma_handle = sg->dma_address;
506 unsigned int len = sg->dma_length; 493 unsigned int len = sg->dma_length;
507 unsigned long npages, entry; 494 unsigned long npages;
495 struct iommu_table *tbl = &iommu->tbl;
496 unsigned long shift = IO_PAGE_SHIFT;
508 497
509 if (!len) 498 if (!len)
510 break; 499 break;
511 npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE); 500 npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE);
512 iommu_range_free(iommu, dma_handle, npages); 501 entry = ((dma_handle - tbl->page_table_map_base) >> shift);
513 502 dma_4v_iommu_demap(&devhandle, entry, npages);
514 entry = ((dma_handle - iommu->page_table_map_base) >> IO_PAGE_SHIFT); 503 iommu_tbl_range_free(&iommu->tbl, dma_handle, npages,
515 while (npages) { 504 false, NULL);
516 unsigned long num;
517
518 num = pci_sun4v_iommu_demap(devhandle, HV_PCI_TSBID(0, entry),
519 npages);
520 entry += num;
521 npages -= num;
522 }
523
524 sg = sg_next(sg); 505 sg = sg_next(sg);
525 } 506 }
526 507
527 spin_unlock_irqrestore(&iommu->lock, flags); 508 local_irq_restore(flags);
528} 509}
529 510
530static struct dma_map_ops sun4v_dma_ops = { 511static struct dma_map_ops sun4v_dma_ops = {
@@ -536,6 +517,8 @@ static struct dma_map_ops sun4v_dma_ops = {
536 .unmap_sg = dma_4v_unmap_sg, 517 .unmap_sg = dma_4v_unmap_sg,
537}; 518};
538 519
520static struct iommu_tbl_ops dma_4v_iommu_ops;
521
539static void pci_sun4v_scan_bus(struct pci_pbm_info *pbm, struct device *parent) 522static void pci_sun4v_scan_bus(struct pci_pbm_info *pbm, struct device *parent)
540{ 523{
541 struct property *prop; 524 struct property *prop;
@@ -550,30 +533,33 @@ static void pci_sun4v_scan_bus(struct pci_pbm_info *pbm, struct device *parent)
550} 533}
551 534
552static unsigned long probe_existing_entries(struct pci_pbm_info *pbm, 535static unsigned long probe_existing_entries(struct pci_pbm_info *pbm,
553 struct iommu *iommu) 536 struct iommu_table *iommu)
554{ 537{
555 struct iommu_arena *arena = &iommu->arena; 538 struct iommu_pool *pool;
556 unsigned long i, cnt = 0; 539 unsigned long i, pool_nr, cnt = 0;
557 u32 devhandle; 540 u32 devhandle;
558 541
559 devhandle = pbm->devhandle; 542 devhandle = pbm->devhandle;
560 for (i = 0; i < arena->limit; i++) { 543 for (pool_nr = 0; pool_nr < iommu->nr_pools; pool_nr++) {
561 unsigned long ret, io_attrs, ra; 544 pool = &(iommu->arena_pool[pool_nr]);
562 545 for (i = pool->start; i <= pool->end; i++) {
563 ret = pci_sun4v_iommu_getmap(devhandle, 546 unsigned long ret, io_attrs, ra;
564 HV_PCI_TSBID(0, i), 547
565 &io_attrs, &ra); 548 ret = pci_sun4v_iommu_getmap(devhandle,
566 if (ret == HV_EOK) { 549 HV_PCI_TSBID(0, i),
567 if (page_in_phys_avail(ra)) { 550 &io_attrs, &ra);
568 pci_sun4v_iommu_demap(devhandle, 551 if (ret == HV_EOK) {
569 HV_PCI_TSBID(0, i), 1); 552 if (page_in_phys_avail(ra)) {
570 } else { 553 pci_sun4v_iommu_demap(devhandle,
571 cnt++; 554 HV_PCI_TSBID(0,
572 __set_bit(i, arena->map); 555 i), 1);
556 } else {
557 cnt++;
558 __set_bit(i, iommu->map);
559 }
573 } 560 }
574 } 561 }
575 } 562 }
576
577 return cnt; 563 return cnt;
578} 564}
579 565
@@ -601,22 +587,22 @@ static int pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
601 dma_offset = vdma[0]; 587 dma_offset = vdma[0];
602 588
603 /* Setup initial software IOMMU state. */ 589 /* Setup initial software IOMMU state. */
604 spin_lock_init(&iommu->lock);
605 iommu->ctx_lowest_free = 1; 590 iommu->ctx_lowest_free = 1;
606 iommu->page_table_map_base = dma_offset; 591 iommu->tbl.page_table_map_base = dma_offset;
607 iommu->dma_addr_mask = dma_mask; 592 iommu->dma_addr_mask = dma_mask;
608 593
609 /* Allocate and initialize the free area map. */ 594 /* Allocate and initialize the free area map. */
610 sz = (num_tsb_entries + 7) / 8; 595 sz = (num_tsb_entries + 7) / 8;
611 sz = (sz + 7UL) & ~7UL; 596 sz = (sz + 7UL) & ~7UL;
612 iommu->arena.map = kzalloc(sz, GFP_KERNEL); 597 iommu->tbl.map = kzalloc(sz, GFP_KERNEL);
613 if (!iommu->arena.map) { 598 if (!iommu->tbl.map) {
614 printk(KERN_ERR PFX "Error, kmalloc(arena.map) failed.\n"); 599 printk(KERN_ERR PFX "Error, kmalloc(arena.map) failed.\n");
615 return -ENOMEM; 600 return -ENOMEM;
616 } 601 }
617 iommu->arena.limit = num_tsb_entries; 602 iommu_tbl_pool_init(&iommu->tbl, num_tsb_entries, IO_PAGE_SHIFT,
618 603 &dma_4v_iommu_ops, false /* no large_pool */,
619 sz = probe_existing_entries(pbm, iommu); 604 0 /* default npools */);
605 sz = probe_existing_entries(pbm, &iommu->tbl);
620 if (sz) 606 if (sz)
621 printk("%s: Imported %lu TSB entries from OBP\n", 607 printk("%s: Imported %lu TSB entries from OBP\n",
622 pbm->name, sz); 608 pbm->name, sz);
@@ -1015,8 +1001,17 @@ static struct platform_driver pci_sun4v_driver = {
1015 .probe = pci_sun4v_probe, 1001 .probe = pci_sun4v_probe,
1016}; 1002};
1017 1003
1004static void setup_iommu_pool_hash(void)
1005{
1006 unsigned int i;
1007
1008 for_each_possible_cpu(i)
1009 per_cpu(iommu_pool_hash, i) = hash_32(i, IOMMU_POOL_HASHBITS);
1010}
1011
1018static int __init pci_sun4v_init(void) 1012static int __init pci_sun4v_init(void)
1019{ 1013{
1014 setup_iommu_pool_hash();
1020 return platform_driver_register(&pci_sun4v_driver); 1015 return platform_driver_register(&pci_sun4v_driver);
1021} 1016}
1022 1017