Skip to content

Commit 903cd0f

Browse files
Claire Changkonradwilk
Claire Chang
authored andcommitted
swiotlb: Use is_swiotlb_force_bounce for swiotlb data bouncing
Propagate the swiotlb_force into io_tlb_default_mem->force_bounce and use it to determine whether to bounce the data or not. This will be useful later to allow for different 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]> [v2: Includes Will's fix]
1 parent 6f2beb2 commit 903cd0f

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
374374
if (dma_capable(dev, dev_addr, size, true) &&
375375
!range_straddles_page_boundary(phys, size) &&
376376
!xen_arch_need_swiotlb(dev, phys, dev_addr) &&
377-
swiotlb_force != SWIOTLB_FORCE)
377+
!is_swiotlb_force_bounce(dev))
378378
goto done;
379379

380380
/*

include/linux/swiotlb.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern enum swiotlb_force swiotlb_force;
8484
* unmap calls.
8585
* @debugfs: The dentry to debugfs.
8686
* @late_alloc: %true if allocated using the page allocator
87+
* @force_bounce: %true if swiotlb bouncing is forced
8788
*/
8889
struct io_tlb_mem {
8990
phys_addr_t start;
@@ -94,6 +95,7 @@ struct io_tlb_mem {
9495
spinlock_t lock;
9596
struct dentry *debugfs;
9697
bool late_alloc;
98+
bool force_bounce;
9799
struct io_tlb_slot {
98100
phys_addr_t orig_addr;
99101
size_t alloc_size;
@@ -109,6 +111,13 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
109111
return mem && paddr >= mem->start && paddr < mem->end;
110112
}
111113

114+
static inline bool is_swiotlb_force_bounce(struct device *dev)
115+
{
116+
struct io_tlb_mem *mem = dev->dma_io_tlb_mem;
117+
118+
return mem && mem->force_bounce;
119+
}
120+
112121
void __init swiotlb_exit(void);
113122
unsigned int swiotlb_max_segment(void);
114123
size_t swiotlb_max_mapping_size(struct device *dev);
@@ -120,6 +129,10 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
120129
{
121130
return false;
122131
}
132+
static inline bool is_swiotlb_force_bounce(struct device *dev)
133+
{
134+
return false;
135+
}
123136
static inline void swiotlb_exit(void)
124137
{
125138
}

kernel/dma/direct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ size_t dma_direct_max_mapping_size(struct device *dev)
496496
{
497497
/* If SWIOTLB is active, use its maximum mapping size */
498498
if (is_swiotlb_active(dev) &&
499-
(dma_addressing_limited(dev) || swiotlb_force == SWIOTLB_FORCE))
499+
(dma_addressing_limited(dev) || is_swiotlb_force_bounce(dev)))
500500
return swiotlb_max_mapping_size(dev);
501501
return SIZE_MAX;
502502
}

kernel/dma/direct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev,
8787
phys_addr_t phys = page_to_phys(page) + offset;
8888
dma_addr_t dma_addr = phys_to_dma(dev, phys);
8989

90-
if (unlikely(swiotlb_force == SWIOTLB_FORCE))
90+
if (is_swiotlb_force_bounce(dev))
9191
return swiotlb_map(dev, phys, size, dir, attrs);
9292

9393
if (unlikely(!dma_capable(dev, dma_addr, size, true))) {

kernel/dma/swiotlb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
179179
mem->end = mem->start + bytes;
180180
mem->index = 0;
181181
mem->late_alloc = late_alloc;
182+
183+
if (swiotlb_force == SWIOTLB_FORCE)
184+
mem->force_bounce = true;
185+
182186
spin_lock_init(&mem->lock);
183187
for (i = 0; i < mem->nslabs; i++) {
184188
mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i);

0 commit comments

Comments
 (0)