swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used
authorClaire Chang <tientzu@chromium.org>
Sat, 19 Jun 2021 03:40:34 +0000 (11:40 +0800)
committerKonrad Rzeszutek Wilk <konrad@kernel.org>
Wed, 14 Jul 2021 00:04:37 +0000 (20:04 -0400)
Always have the pointer to the swiotlb pool used in struct device. This
could help simplify the code for other 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>
drivers/base/core.c
include/linux/device.h
kernel/dma/swiotlb.c

index cadcade658253c3ca050c2906537f0ad714ab0ea..ea5b85354526f73b28d2f4c993e3267f36fe0d46 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/netdevice.h>
 #include <linux/sched/signal.h>
 #include <linux/sched/mm.h>
+#include <linux/swiotlb.h>
 #include <linux/sysfs.h>
 #include <linux/dma-map-ops.h> /* for dma_default_coherent */
 
@@ -2846,6 +2847,9 @@ void device_initialize(struct device *dev)
     defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
        dev->dma_coherent = dma_default_coherent;
 #endif
+#ifdef CONFIG_SWIOTLB
+       dev->dma_io_tlb_mem = io_tlb_default_mem;
+#endif
 }
 EXPORT_SYMBOL_GPL(device_initialize);
 
index 59940f1744c1979add88a25a684ec11ffeafe015..2a22875238a6fc6265ece01bec4b4f7bbadc0a6c 100644 (file)
@@ -423,6 +423,7 @@ struct dev_links_info {
  * @dma_pools: Dma pools (if dma'ble device).
  * @dma_mem:   Internal for coherent mem override.
  * @cma_area:  Contiguous memory area for dma allocations
+ * @dma_io_tlb_mem: Pointer to the swiotlb pool used.  Not for driver use.
  * @archdata:  For arch-specific additions.
  * @of_node:   Associated device tree node.
  * @fwnode:    Associated device node supplied by platform firmware.
@@ -531,6 +532,9 @@ struct device {
 #ifdef CONFIG_DMA_CMA
        struct cma *cma_area;           /* contiguous memory area for dma
                                           allocations */
+#endif
+#ifdef CONFIG_SWIOTLB
+       struct io_tlb_mem *dma_io_tlb_mem;
 #endif
        /* arch specific additions */
        struct dev_archdata     archdata;
index ae6a151d0a41196a2e7282007411d072fa9202c0..33d413beddd415d8ef3dbbd9c190df5eeb3fe948 100644 (file)
@@ -348,7 +348,7 @@ static unsigned int swiotlb_align_offset(struct device *dev, u64 addr)
 static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size,
                           enum dma_data_direction dir)
 {
-       struct io_tlb_mem *mem = io_tlb_default_mem;
+       struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
        int index = (tlb_addr - mem->start) >> IO_TLB_SHIFT;
        phys_addr_t orig_addr = mem->slots[index].orig_addr;
        size_t alloc_size = mem->slots[index].alloc_size;
@@ -429,7 +429,7 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index)
 static int find_slots(struct device *dev, phys_addr_t orig_addr,
                size_t alloc_size)
 {
-       struct io_tlb_mem *mem = io_tlb_default_mem;
+       struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
        unsigned long boundary_mask = dma_get_seg_boundary(dev);
        dma_addr_t tbl_dma_addr =
                phys_to_dma_unencrypted(dev, mem->start) & boundary_mask;
@@ -506,7 +506,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
                size_t mapping_size, size_t alloc_size,
                enum dma_data_direction dir, unsigned long attrs)
 {
-       struct io_tlb_mem *mem = io_tlb_default_mem;
+       struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
        unsigned int offset = swiotlb_align_offset(dev, orig_addr);
        unsigned int i;
        int index;
@@ -557,7 +557,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
                              size_t mapping_size, enum dma_data_direction dir,
                              unsigned long attrs)
 {
-       struct io_tlb_mem *mem = io_tlb_default_mem;
+       struct io_tlb_mem *mem = hwdev->dma_io_tlb_mem;
        unsigned long flags;
        unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr);
        int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT;