History

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.

Claire Chang committed 5 years ago

Commit 7fd856a1 parent 69031f55 files · +17 −16Browse files

Unified · Split

5 files
  1. drivers/iommu/dma-iommu.c +6 −6
  2. drivers/xen/swiotlb-xen.c +1 −1
  3. include/linux/swiotlb.h +4 −3
  4. kernel/dma/direct.c +3 −3
  5. kernel/dma/direct.h +3 −3
drivers/iommu/dma-iommu.c+6−6
@@ -506,7 +506,7 @@ static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr, · 505 unmodified lines
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, · 64 unmodified lines
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, · 199 unmodified lines
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, · 6 unmodified lines
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, · 14 unmodified lines
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, · 10 unmodified lines
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+1−1
@@ -100,7 +100,7 @@ static int is_xen_swiotlb_buffer(struct device *dev, dma_addr_t dma_addr) · 99 unmodified lines
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+4−3
@@ -2,6 +2,7 @@ · 1 unmodified line
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 { · 93 unmodified lines
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); · 5 unmodified lines
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+3−3
@@ -343,7 +343,7 @@ void dma_direct_sync_sg_for_device(struct device *dev, · 342 unmodified lines
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, · 19 unmodified lines
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) · 128 unmodified lines
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+3−3
@@ -56,7 +56,7 @@ static inline void dma_direct_sync_single_for_device(struct device *dev, · 55 unmodified lines
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, · 10 unmodified lines
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, · 33 unmodified lines
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 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t