Skip to content

Commit 4803b44

Browse files
author
Christoph Hellwig
committed
swiotlb: use swiotlb_map_page in swiotlb_map_sg_attrs
No need to duplicate the code - map_sg is equivalent to map_page for each page in the scatterlist. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 27744e0 commit 4803b44

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

kernel/dma/swiotlb.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -845,37 +845,27 @@ swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
845845
* same here.
846846
*/
847847
int
848-
swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
848+
swiotlb_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nelems,
849849
enum dma_data_direction dir, unsigned long attrs)
850850
{
851851
struct scatterlist *sg;
852852
int i;
853853

854-
BUG_ON(dir == DMA_NONE);
855-
856854
for_each_sg(sgl, sg, nelems, i) {
857-
phys_addr_t paddr = sg_phys(sg);
858-
dma_addr_t dev_addr = phys_to_dma(hwdev, paddr);
859-
860-
if (swiotlb_force == SWIOTLB_FORCE ||
861-
!dma_capable(hwdev, dev_addr, sg->length)) {
862-
phys_addr_t map = map_single(hwdev, sg_phys(sg),
863-
sg->length, dir, attrs);
864-
if (map == SWIOTLB_MAP_ERROR) {
865-
/* Don't panic here, we expect map_sg users
866-
to do proper error handling. */
867-
attrs |= DMA_ATTR_SKIP_CPU_SYNC;
868-
swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir,
869-
attrs);
870-
sg_dma_len(sgl) = 0;
871-
return 0;
872-
}
873-
sg->dma_address = __phys_to_dma(hwdev, map);
874-
} else
875-
sg->dma_address = dev_addr;
855+
sg->dma_address = swiotlb_map_page(dev, sg_page(sg), sg->offset,
856+
sg->length, dir, attrs);
857+
if (sg->dma_address == DIRECT_MAPPING_ERROR)
858+
goto out_error;
876859
sg_dma_len(sg) = sg->length;
877860
}
861+
878862
return nelems;
863+
864+
out_error:
865+
swiotlb_unmap_sg_attrs(dev, sgl, i, dir,
866+
attrs | DMA_ATTR_SKIP_CPU_SYNC);
867+
sg_dma_len(sgl) = 0;
868+
return 0;
879869
}
880870

881871
/*

0 commit comments

Comments
 (0)