Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8270f3f1 authored by John W. Linville's avatar John W. Linville Committed by Tony Luck
Browse files

[PATCH] swiotlb: cleanup some code duplication cruft



The implementations of swiotlb_sync_single_for_{cpu,device} are
identical. Likewise for swiotlb_syng_sg_for_{cpu,device}. This patch
move the guts of those functions to two new inline functions, and
calls the appropriate one from the bodies of those functions.

Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
parent 6c654b5f
Loading
Loading
Loading
Loading
+22 −23
Original line number Diff line number Diff line
@@ -594,8 +594,8 @@ swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size,
 * address back to the card, you must first perform a
 * swiotlb_dma_sync_for_device, and then the device again owns the buffer
 */
void
swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
static inline void
swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
		    size_t size, int dir)
{
	char *dma_addr = phys_to_virt(dev_addr);
@@ -609,17 +609,17 @@ swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
}

void
swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
			    size_t size, int dir)
{
	char *dma_addr = phys_to_virt(dev_addr);
	swiotlb_sync_single(hwdev, dev_addr, size, dir);
}

	if (dir == DMA_NONE)
		BUG();
	if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
		sync_single(hwdev, dma_addr, size, dir);
	else if (dir == DMA_FROM_DEVICE)
		mark_clean(dma_addr, size);
void
swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
			       size_t size, int dir)
{
	swiotlb_sync_single(hwdev, dev_addr, size, dir);
}

/*
@@ -696,8 +696,8 @@ swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nelems,
 * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules
 * and usage.
 */
void
swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
static inline void
swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sg,
		int nelems, int dir)
{
	int i;
@@ -712,18 +712,17 @@ swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
}

void
swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
			int nelems, int dir)
{
	int i;

	if (dir == DMA_NONE)
		BUG();
	swiotlb_sync_sg(hwdev, sg, nelems, dir);
}

	for (i = 0; i < nelems; i++, sg++)
		if (sg->dma_address != SG_ENT_PHYS_ADDRESS(sg))
			sync_single(hwdev, (void *) sg->dma_address,
				    sg->dma_length, dir);
void
swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
			   int nelems, int dir)
{
	swiotlb_sync_sg(hwdev, sg, nelems, dir);
}

int