Skip to content

Commit 1fd1e6c

Browse files
geertugregkh
authored andcommitted
swiotlb: Convert swiotlb_force from int to enum
commit ae7871b upstream. Convert the flag swiotlb_force from an int to an enum, to prepare for the advent of more possible values. Suggested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 776c2b2 commit 1fd1e6c

8 files changed

Lines changed: 27 additions & 18 deletions

File tree

‎arch/arm64/mm/dma-mapping.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ EXPORT_SYMBOL(dummy_dma_ops);
524524

525525
static int __init arm64_dma_init(void)
526526
{
527-
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
527+
if (swiotlb_force == SWIOTLB_FORCE ||
528+
max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
528529
swiotlb = 1;
529530

530531
return atomic_pool_init();

‎arch/arm64/mm/init.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ static void __init free_unused_memmap(void)
401401
*/
402402
void __init mem_init(void)
403403
{
404-
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
404+
if (swiotlb_force == SWIOTLB_FORCE ||
405+
max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
405406
swiotlb_init(1);
406407
else
407408
swiotlb_force = SWIOTLB_NO_FORCE;

‎arch/x86/kernel/pci-swiotlb.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int __init pci_swiotlb_detect_override(void)
7070
{
7171
int use_swiotlb = swiotlb | swiotlb_force;
7272

73-
if (swiotlb_force)
73+
if (swiotlb_force == SWIOTLB_FORCE)
7474
swiotlb = 1;
7575

7676
return use_swiotlb;

‎arch/x86/xen/pci-swiotlb-xen.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int __init pci_xen_swiotlb_detect(void)
4949
* activate this IOMMU. If running as PV privileged, activate it
5050
* irregardless.
5151
*/
52-
if ((xen_initial_domain() || swiotlb || swiotlb_force))
52+
if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
5353
xen_swiotlb = 1;
5454

5555
/* If we are running under Xen, we MUST disable the native SWIOTLB.

‎drivers/xen/swiotlb-xen.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
392392
if (dma_capable(dev, dev_addr, size) &&
393393
!range_straddles_page_boundary(phys, size) &&
394394
!xen_arch_need_swiotlb(dev, phys, dev_addr) &&
395-
!swiotlb_force) {
395+
(swiotlb_force != SWIOTLB_FORCE)) {
396396
/* we are not interested in the dma_addr returned by
397397
* xen_dma_map_page, only in the potential cache flushes executed
398398
* by the function. */
@@ -549,7 +549,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
549549
phys_addr_t paddr = sg_phys(sg);
550550
dma_addr_t dev_addr = xen_phys_to_bus(paddr);
551551

552-
if (swiotlb_force ||
552+
if (swiotlb_force == SWIOTLB_FORCE ||
553553
xen_arch_need_swiotlb(hwdev, paddr, dev_addr) ||
554554
!dma_capable(hwdev, dev_addr, sg->length) ||
555555
range_straddles_page_boundary(paddr, sg->length)) {

‎include/linux/swiotlb.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ struct device;
99
struct page;
1010
struct scatterlist;
1111

12-
extern int swiotlb_force;
12+
enum swiotlb_force {
13+
SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
14+
SWIOTLB_FORCE, /* swiotlb=force */
15+
};
16+
17+
extern enum swiotlb_force swiotlb_force;
1318

1419
/*
1520
* Maximum allowable number of contiguous slabs to map,

‎include/trace/events/swiotlb.h‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ TRACE_EVENT(swiotlb_bounced,
1111
TP_PROTO(struct device *dev,
1212
dma_addr_t dev_addr,
1313
size_t size,
14-
int swiotlb_force),
14+
enum swiotlb_force swiotlb_force),
1515

1616
TP_ARGS(dev, dev_addr, size, swiotlb_force),
1717

1818
TP_STRUCT__entry(
19-
__string( dev_name, dev_name(dev) )
20-
__field( u64, dma_mask )
21-
__field( dma_addr_t, dev_addr )
22-
__field( size_t, size )
23-
__field( int, swiotlb_force )
19+
__string( dev_name, dev_name(dev) )
20+
__field( u64, dma_mask )
21+
__field( dma_addr_t, dev_addr )
22+
__field( size_t, size )
23+
__field( enum swiotlb_force, swiotlb_force )
2424
),
2525

2626
TP_fast_assign(
@@ -37,7 +37,9 @@ TRACE_EVENT(swiotlb_bounced,
3737
__entry->dma_mask,
3838
(unsigned long long)__entry->dev_addr,
3939
__entry->size,
40-
__entry->swiotlb_force ? "swiotlb_force" : "" )
40+
__print_symbolic(__entry->swiotlb_force,
41+
{ SWIOTLB_NORMAL, "NORMAL" },
42+
{ SWIOTLB_FORCE, "FORCE" }))
4143
);
4244

4345
#endif /* _TRACE_SWIOTLB_H */

‎lib/swiotlb.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454
#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
5555

56-
int swiotlb_force;
56+
enum swiotlb_force swiotlb_force;
5757

5858
/*
5959
* Used to do a quick range check in swiotlb_tbl_unmap_single and
@@ -107,7 +107,7 @@ setup_io_tlb_npages(char *str)
107107
if (*str == ',')
108108
++str;
109109
if (!strcmp(str, "force"))
110-
swiotlb_force = 1;
110+
swiotlb_force = SWIOTLB_FORCE;
111111

112112
return 0;
113113
}
@@ -749,7 +749,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
749749
* we can safely return the device addr and not worry about bounce
750750
* buffering it.
751751
*/
752-
if (dma_capable(dev, dev_addr, size) && !swiotlb_force)
752+
if (dma_capable(dev, dev_addr, size) && swiotlb_force != SWIOTLB_FORCE)
753753
return dev_addr;
754754

755755
trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
@@ -888,7 +888,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
888888
phys_addr_t paddr = sg_phys(sg);
889889
dma_addr_t dev_addr = phys_to_dma(hwdev, paddr);
890890

891-
if (swiotlb_force ||
891+
if (swiotlb_force == SWIOTLB_FORCE ||
892892
!dma_capable(hwdev, dev_addr, sg->length)) {
893893
phys_addr_t map = map_single(hwdev, sg_phys(sg),
894894
sg->length, dir);

0 commit comments

Comments
 (0)