Skip to content

Commit 7fd856a

Browse files
Claire Changkonradwilk
authored andcommitted
swiotlb: Update is_swiotlb_buffer to add a struct device argument
Update is_swiotlb_buffer to add a struct device argument. This will be useful later to allow for different 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> Acked-by: Stefano Stabellini <sstabellini@kernel.org> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 69031f5 commit 7fd856a

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

drivers/iommu/dma-iommu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr,
506506

507507
__iommu_dma_unmap(dev, dma_addr, size);
508508

509-
if (unlikely(is_swiotlb_buffer(phys)))
509+
if (unlikely(is_swiotlb_buffer(dev, phys)))
510510
swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
511511
}
512512

@@ -577,7 +577,7 @@ static dma_addr_t __iommu_dma_map_swiotlb(struct device *dev, phys_addr_t phys,
577577
}
578578

579579
iova = __iommu_dma_map(dev, phys, aligned_size, prot, dma_mask);
580-
if (iova == DMA_MAPPING_ERROR && is_swiotlb_buffer(phys))
580+
if (iova == DMA_MAPPING_ERROR && is_swiotlb_buffer(dev, phys))
581581
swiotlb_tbl_unmap_single(dev, phys, org_size, dir, attrs);
582582
return iova;
583583
}
@@ -783,7 +783,7 @@ static void iommu_dma_sync_single_for_cpu(struct device *dev,
783783
if (!dev_is_dma_coherent(dev))
784784
arch_sync_dma_for_cpu(phys, size, dir);
785785

786-
if (is_swiotlb_buffer(phys))
786+
if (is_swiotlb_buffer(dev, phys))
787787
swiotlb_sync_single_for_cpu(dev, phys, size, dir);
788788
}
789789

@@ -796,7 +796,7 @@ static void iommu_dma_sync_single_for_device(struct device *dev,
796796
return;
797797

798798
phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
799-
if (is_swiotlb_buffer(phys))
799+
if (is_swiotlb_buffer(dev, phys))
800800
swiotlb_sync_single_for_device(dev, phys, size, dir);
801801

802802
if (!dev_is_dma_coherent(dev))
@@ -817,7 +817,7 @@ static void iommu_dma_sync_sg_for_cpu(struct device *dev,
817817
if (!dev_is_dma_coherent(dev))
818818
arch_sync_dma_for_cpu(sg_phys(sg), sg->length, dir);
819819

820-
if (is_swiotlb_buffer(sg_phys(sg)))
820+
if (is_swiotlb_buffer(dev, sg_phys(sg)))
821821
swiotlb_sync_single_for_cpu(dev, sg_phys(sg),
822822
sg->length, dir);
823823
}
@@ -834,7 +834,7 @@ static void iommu_dma_sync_sg_for_device(struct device *dev,
834834
return;
835835

836836
for_each_sg(sgl, sg, nelems, i) {
837-
if (is_swiotlb_buffer(sg_phys(sg)))
837+
if (is_swiotlb_buffer(dev, sg_phys(sg)))
838838
swiotlb_sync_single_for_device(dev, sg_phys(sg),
839839
sg->length, dir);
840840

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr)
100100
* in our domain. Therefore _only_ check address within our domain.
101101
*/
102102
if (pfn_valid(PFN_DOWN(paddr)))
103-
return is_swiotlb_buffer(paddr);
103+
return is_swiotlb_buffer(dev, paddr);
104104
return 0;
105105
}
106106

include/linux/swiotlb.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef __LINUX_SWIOTLB_H
33
#define __LINUX_SWIOTLB_H
44

5+
#include <linux/device.h>
56
#include <linux/dma-direction.h>
67
#include <linux/init.h>
78
#include <linux/types.h>
@@ -101,9 +102,9 @@ struct io_tlb_mem {
101102
};
102103
extern struct io_tlb_mem *io_tlb_default_mem;
103104

104-
static inline bool is_swiotlb_buffer(phys_addr_t paddr)
105+
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
105106
{
106-
struct io_tlb_mem *mem = io_tlb_default_mem;
107+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
107108

108109
return mem && paddr >= mem->start && paddr < mem->end;
109110
}
@@ -115,7 +116,7 @@ bool is_swiotlb_active(void);
115116
void __init swiotlb_adjust_size(unsigned long size);
116117
#else
117118
#define swiotlb_force SWIOTLB_NO_FORCE
118-
static inline bool is_swiotlb_buffer(phys_addr_t paddr)
119+
static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
119120
{
120121
return false;
121122
}

kernel/dma/direct.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void dma_direct_sync_sg_for_device(struct device *dev,
343343
for_each_sg(sgl, sg, nents, i) {
344344
phys_addr_t paddr = dma_to_phys(dev, sg_dma_address(sg));
345345

346-
if (unlikely(is_swiotlb_buffer(paddr)))
346+
if (unlikely(is_swiotlb_buffer(dev, paddr)))
347347
swiotlb_sync_single_for_device(dev, paddr, sg->length,
348348
dir);
349349

@@ -369,7 +369,7 @@ void dma_direct_sync_sg_for_cpu(struct device *dev,
369369
if (!dev_is_dma_coherent(dev))
370370
arch_sync_dma_for_cpu(paddr, sg->length, dir);
371371

372-
if (unlikely(is_swiotlb_buffer(paddr)))
372+
if (unlikely(is_swiotlb_buffer(dev, paddr)))
373373
swiotlb_sync_single_for_cpu(dev, paddr, sg->length,
374374
dir);
375375

@@ -504,7 +504,7 @@ size_t dma_direct_max_mapping_size(struct device *dev)
504504
bool dma_direct_need_sync(struct device *dev, dma_addr_t dma_addr)
505505
{
506506
return !dev_is_dma_coherent(dev) ||
507-
is_swiotlb_buffer(dma_to_phys(dev, dma_addr));
507+
is_swiotlb_buffer(dev, dma_to_phys(dev, dma_addr));
508508
}
509509

510510
/**

kernel/dma/direct.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static inline void dma_direct_sync_single_for_device(struct device *dev,
5656
{
5757
phys_addr_t paddr = dma_to_phys(dev, addr);
5858

59-
if (unlikely(is_swiotlb_buffer(paddr)))
59+
if (unlikely(is_swiotlb_buffer(dev, paddr)))
6060
swiotlb_sync_single_for_device(dev, paddr, size, dir);
6161

6262
if (!dev_is_dma_coherent(dev))
@@ -73,7 +73,7 @@ static inline void dma_direct_sync_single_for_cpu(struct device *dev,
7373
arch_sync_dma_for_cpu_all();
7474
}
7575

76-
if (unlikely(is_swiotlb_buffer(paddr)))
76+
if (unlikely(is_swiotlb_buffer(dev, paddr)))
7777
swiotlb_sync_single_for_cpu(dev, paddr, size, dir);
7878

7979
if (dir == DMA_FROM_DEVICE)
@@ -113,7 +113,7 @@ static inline void dma_direct_unmap_page(struct device *dev, dma_addr_t addr,
113113
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
114114
dma_direct_sync_single_for_cpu(dev, addr, size, dir);
115115

116-
if (unlikely(is_swiotlb_buffer(phys)))
116+
if (unlikely(is_swiotlb_buffer(dev, phys)))
117117
swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
118118
}
119119
#endif /* _KERNEL_DMA_DIRECT_H */

0 commit comments

Comments
 (0)