aboutsummaryrefslogtreecommitdiffstats
path: root/lib/swiotlb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/swiotlb.c')
-rw-r--r--lib/swiotlb.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 34e3082632d8..99093b396145 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -60,7 +60,7 @@ int swiotlb_force;
60static char *io_tlb_start, *io_tlb_end; 60static char *io_tlb_start, *io_tlb_end;
61 61
62/* 62/*
63 * The number of IO TLB blocks (in groups of 64) betweeen io_tlb_start and 63 * The number of IO TLB blocks (in groups of 64) between io_tlb_start and
64 * io_tlb_end. This is command line adjustable via setup_io_tlb_npages. 64 * io_tlb_end. This is command line adjustable via setup_io_tlb_npages.
65 */ 65 */
66static unsigned long io_tlb_nslabs; 66static unsigned long io_tlb_nslabs;
@@ -70,7 +70,7 @@ static unsigned long io_tlb_nslabs;
70 */ 70 */
71static unsigned long io_tlb_overflow = 32*1024; 71static unsigned long io_tlb_overflow = 32*1024;
72 72
73void *io_tlb_overflow_buffer; 73static void *io_tlb_overflow_buffer;
74 74
75/* 75/*
76 * This is a free list describing the number of free entries available from 76 * This is a free list describing the number of free entries available from
@@ -110,6 +110,11 @@ setup_io_tlb_npages(char *str)
110__setup("swiotlb=", setup_io_tlb_npages); 110__setup("swiotlb=", setup_io_tlb_npages);
111/* make io_tlb_overflow tunable too? */ 111/* make io_tlb_overflow tunable too? */
112 112
113unsigned long swioltb_nr_tbl(void)
114{
115 return io_tlb_nslabs;
116}
117
113/* Note that this doesn't work with highmem page */ 118/* Note that this doesn't work with highmem page */
114static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev, 119static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
115 volatile void *address) 120 volatile void *address)
@@ -147,16 +152,16 @@ void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
147 * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE 152 * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
148 * between io_tlb_start and io_tlb_end. 153 * between io_tlb_start and io_tlb_end.
149 */ 154 */
150 io_tlb_list = alloc_bootmem(io_tlb_nslabs * sizeof(int)); 155 io_tlb_list = alloc_bootmem_pages(PAGE_ALIGN(io_tlb_nslabs * sizeof(int)));
151 for (i = 0; i < io_tlb_nslabs; i++) 156 for (i = 0; i < io_tlb_nslabs; i++)
152 io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); 157 io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
153 io_tlb_index = 0; 158 io_tlb_index = 0;
154 io_tlb_orig_addr = alloc_bootmem(io_tlb_nslabs * sizeof(phys_addr_t)); 159 io_tlb_orig_addr = alloc_bootmem_pages(PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)));
155 160
156 /* 161 /*
157 * Get the overflow emergency buffer 162 * Get the overflow emergency buffer
158 */ 163 */
159 io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow); 164 io_tlb_overflow_buffer = alloc_bootmem_low_pages(PAGE_ALIGN(io_tlb_overflow));
160 if (!io_tlb_overflow_buffer) 165 if (!io_tlb_overflow_buffer)
161 panic("Cannot allocate SWIOTLB overflow buffer!\n"); 166 panic("Cannot allocate SWIOTLB overflow buffer!\n");
162 if (verbose) 167 if (verbose)
@@ -182,7 +187,7 @@ swiotlb_init_with_default_size(size_t default_size, int verbose)
182 /* 187 /*
183 * Get IO TLB memory from the low pages 188 * Get IO TLB memory from the low pages
184 */ 189 */
185 io_tlb_start = alloc_bootmem_low_pages(bytes); 190 io_tlb_start = alloc_bootmem_low_pages(PAGE_ALIGN(bytes));
186 if (!io_tlb_start) 191 if (!io_tlb_start)
187 panic("Cannot allocate SWIOTLB buffer"); 192 panic("Cannot allocate SWIOTLB buffer");
188 193
@@ -308,13 +313,13 @@ void __init swiotlb_free(void)
308 get_order(io_tlb_nslabs << IO_TLB_SHIFT)); 313 get_order(io_tlb_nslabs << IO_TLB_SHIFT));
309 } else { 314 } else {
310 free_bootmem_late(__pa(io_tlb_overflow_buffer), 315 free_bootmem_late(__pa(io_tlb_overflow_buffer),
311 io_tlb_overflow); 316 PAGE_ALIGN(io_tlb_overflow));
312 free_bootmem_late(__pa(io_tlb_orig_addr), 317 free_bootmem_late(__pa(io_tlb_orig_addr),
313 io_tlb_nslabs * sizeof(phys_addr_t)); 318 PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)));
314 free_bootmem_late(__pa(io_tlb_list), 319 free_bootmem_late(__pa(io_tlb_list),
315 io_tlb_nslabs * sizeof(int)); 320 PAGE_ALIGN(io_tlb_nslabs * sizeof(int)));
316 free_bootmem_late(__pa(io_tlb_start), 321 free_bootmem_late(__pa(io_tlb_start),
317 io_tlb_nslabs << IO_TLB_SHIFT); 322 PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
318 } 323 }
319} 324}
320 325
@@ -686,8 +691,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
686 /* 691 /*
687 * Ensure that the address returned is DMA'ble 692 * Ensure that the address returned is DMA'ble
688 */ 693 */
689 if (!dma_capable(dev, dev_addr, size)) 694 if (!dma_capable(dev, dev_addr, size)) {
690 panic("map_single: bounce buffer is not DMA'ble"); 695 swiotlb_tbl_unmap_single(dev, map, size, dir);
696 dev_addr = swiotlb_virt_to_bus(dev, io_tlb_overflow_buffer);
697 }
691 698
692 return dev_addr; 699 return dev_addr;
693} 700}