Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 69031f5

Browse files
Claire Changkonradwilk
authored andcommitted
swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Tested-by: Stefano Stabellini <[email protected]> Tested-by: Will Deacon <[email protected]> Acked-by: Stefano Stabellini <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent 6e675a1 commit 69031f5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

drivers/base/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/netdevice.h>
2828
#include <linux/sched/signal.h>
2929
#include <linux/sched/mm.h>
30+
#include <linux/swiotlb.h>
3031
#include <linux/sysfs.h>
3132
#include <linux/dma-map-ops.h> /* for dma_default_coherent */
3233

@@ -2846,6 +2847,9 @@ void device_initialize(struct device *dev)
28462847
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
28472848
dev->dma_coherent = dma_default_coherent;
28482849
#endif
2850+
#ifdef CONFIG_SWIOTLB
2851+
dev->dma_io_tlb_mem = io_tlb_default_mem;
2852+
#endif
28492853
}
28502854
EXPORT_SYMBOL_GPL(device_initialize);
28512855

include/linux/device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ struct dev_links_info {
423423
* @dma_pools: Dma pools (if dma'ble device).
424424
* @dma_mem: Internal for coherent mem override.
425425
* @cma_area: Contiguous memory area for dma allocations
426+
* @dma_io_tlb_mem: Pointer to the swiotlb pool used. Not for driver use.
426427
* @archdata: For arch-specific additions.
427428
* @of_node: Associated device tree node.
428429
* @fwnode: Associated device node supplied by platform firmware.
@@ -531,6 +532,9 @@ struct device {
531532
#ifdef CONFIG_DMA_CMA
532533
struct cma *cma_area; /* contiguous memory area for dma
533534
allocations */
535+
#endif
536+
#ifdef CONFIG_SWIOTLB
537+
struct io_tlb_mem *dma_io_tlb_mem;
534538
#endif
535539
/* arch specific additions */
536540
struct dev_archdata archdata;

kernel/dma/swiotlb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static unsigned int swiotlb_align_offset(struct device *dev, u64 addr)
348348
static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size,
349349
enum dma_data_direction dir)
350350
{
351-
struct io_tlb_mem *mem = io_tlb_default_mem;
351+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
352352
int index = (tlb_addr - mem->start) >> IO_TLB_SHIFT;
353353
phys_addr_t orig_addr = mem->slots[index].orig_addr;
354354
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)
429429
static int find_slots(struct device *dev, phys_addr_t orig_addr,
430430
size_t alloc_size)
431431
{
432-
struct io_tlb_mem *mem = io_tlb_default_mem;
432+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
433433
unsigned long boundary_mask = dma_get_seg_boundary(dev);
434434
dma_addr_t tbl_dma_addr =
435435
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,
506506
size_t mapping_size, size_t alloc_size,
507507
enum dma_data_direction dir, unsigned long attrs)
508508
{
509-
struct io_tlb_mem *mem = io_tlb_default_mem;
509+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
510510
unsigned int offset = swiotlb_align_offset(dev, orig_addr);
511511
unsigned int i;
512512
int index;
@@ -557,7 +557,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,
557557
size_t mapping_size, enum dma_data_direction dir,
558558
unsigned long attrs)
559559
{
560-
struct io_tlb_mem *mem = io_tlb_default_mem;
560+
struct io_tlb_mem *mem = hwdev->dma_io_tlb_mem;
561561
unsigned long flags;
562562
unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr);
563563
int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT;

0 commit comments

Comments
 (0)