Skip to content

Commit 36f7b2f

Browse files
Claire Changkonradwilk
authored andcommitted
swiotlb: Move alloc_size to swiotlb_find_slots
Rename find_slots to swiotlb_find_slots and move the maintenance of alloc_size to it for better code reusability later. Signed-off-by: Claire Chang <tientzu@chromium.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Stefano Stabellini <sstabellini@kernel.org> Tested-by: Will Deacon <will@kernel.org> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 903cd0f commit 36f7b2f

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

kernel/dma/swiotlb.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index)
430430
* Find a suitable number of IO TLB entries size that will fit this request and
431431
* allocate a buffer from that IO TLB pool.
432432
*/
433-
static int find_slots(struct device *dev, phys_addr_t orig_addr,
434-
size_t alloc_size)
433+
static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
434+
size_t alloc_size)
435435
{
436436
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
437437
unsigned long boundary_mask = dma_get_seg_boundary(dev);
@@ -442,6 +442,7 @@ static int find_slots(struct device *dev, phys_addr_t orig_addr,
442442
dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1);
443443
unsigned int nslots = nr_slots(alloc_size), stride;
444444
unsigned int index, wrap, count = 0, i;
445+
unsigned int offset = swiotlb_align_offset(dev, orig_addr);
445446
unsigned long flags;
446447

447448
BUG_ON(!nslots);
@@ -486,8 +487,11 @@ static int find_slots(struct device *dev, phys_addr_t orig_addr,
486487
return -1;
487488

488489
found:
489-
for (i = index; i < index + nslots; i++)
490+
for (i = index; i < index + nslots; i++) {
490491
mem->slots[i].list = 0;
492+
mem->slots[i].alloc_size =
493+
alloc_size - (offset + ((i - index) << IO_TLB_SHIFT));
494+
}
491495
for (i = index - 1;
492496
io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 &&
493497
mem->slots[i].list; i--)
@@ -528,7 +532,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
528532
return (phys_addr_t)DMA_MAPPING_ERROR;
529533
}
530534

531-
index = find_slots(dev, orig_addr, alloc_size + offset);
535+
index = swiotlb_find_slots(dev, orig_addr, alloc_size + offset);
532536
if (index == -1) {
533537
if (!(attrs & DMA_ATTR_NO_WARN))
534538
dev_warn_ratelimited(dev,
@@ -542,11 +546,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
542546
* This is needed when we sync the memory. Then we sync the buffer if
543547
* needed.
544548
*/
545-
for (i = 0; i < nr_slots(alloc_size + offset); i++) {
549+
for (i = 0; i < nr_slots(alloc_size + offset); i++)
546550
mem->slots[index + i].orig_addr = slot_addr(orig_addr, i);
547-
mem->slots[index + i].alloc_size =
548-
alloc_size - (i << IO_TLB_SHIFT);
549-
}
550551
tlb_addr = slot_addr(mem->start, index) + offset;
551552
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
552553
(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))

0 commit comments

Comments
 (0)