Skip to content

Commit 7034787

Browse files
Claire Changkonradwilk
authored andcommitted
swiotlb: Refactor swiotlb_tbl_unmap_single
Add a new function, swiotlb_release_slots, to make the code reusable for supporting different bounce buffer pools. 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 36f7b2f commit 7034787

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

kernel/dma/swiotlb.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -555,27 +555,15 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
555555
return tlb_addr;
556556
}
557557

558-
/*
559-
* tlb_addr is the physical address of the bounce buffer to unmap.
560-
*/
561-
void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
562-
size_t mapping_size, enum dma_data_direction dir,
563-
unsigned long attrs)
558+
static void swiotlb_release_slots(struct device *dev, phys_addr_t tlb_addr)
564559
{
565-
struct io_tlb_mem *mem = hwdev->dma_io_tlb_mem;
560+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
566561
unsigned long flags;
567-
unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr);
562+
unsigned int offset = swiotlb_align_offset(dev, tlb_addr);
568563
int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT;
569564
int nslots = nr_slots(mem->slots[index].alloc_size + offset);
570565
int count, i;
571566

572-
/*
573-
* First, sync the memory before unmapping the entry
574-
*/
575-
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
576-
(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL))
577-
swiotlb_bounce(hwdev, tlb_addr, mapping_size, DMA_FROM_DEVICE);
578-
579567
/*
580568
* Return the buffer to the free list by setting the corresponding
581569
* entries to indicate the number of contiguous entries available.
@@ -610,6 +598,23 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
610598
spin_unlock_irqrestore(&mem->lock, flags);
611599
}
612600

601+
/*
602+
* tlb_addr is the physical address of the bounce buffer to unmap.
603+
*/
604+
void swiotlb_tbl_unmap_single(struct device *dev, phys_addr_t tlb_addr,
605+
size_t mapping_size, enum dma_data_direction dir,
606+
unsigned long attrs)
607+
{
608+
/*
609+
* First, sync the memory before unmapping the entry
610+
*/
611+
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
612+
(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL))
613+
swiotlb_bounce(dev, tlb_addr, mapping_size, DMA_FROM_DEVICE);
614+
615+
swiotlb_release_slots(dev, tlb_addr);
616+
}
617+
613618
void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_addr,
614619
size_t size, enum dma_data_direction dir)
615620
{

0 commit comments

Comments
 (0)