aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2016-12-16 08:28:41 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2016-12-19 09:05:20 -0500
commitae7871be189cb41184f1e05742b4a99e2c59774d (patch)
tree153af0699fabd19f238d80917ff1b18cac6bcc87
parent6c206e4d99f2ed2a5a59875858e3beecc69b6474 (diff)
swiotlb: Convert swiotlb_force from int to enum
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>
-rw-r--r--arch/arm64/mm/dma-mapping.c3
-rw-r--r--arch/arm64/mm/init.c3
-rw-r--r--arch/x86/kernel/pci-swiotlb.c2
-rw-r--r--arch/x86/xen/pci-swiotlb-xen.c2
-rw-r--r--drivers/xen/swiotlb-xen.c4
-rw-r--r--include/linux/swiotlb.h7
-rw-r--r--include/trace/events/swiotlb.h16
-rw-r--r--lib/swiotlb.c8
8 files changed, 27 insertions, 18 deletions
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 3f74d0d98de6..02265a589ef5 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -524,7 +524,8 @@ EXPORT_SYMBOL(dummy_dma_ops);
524 524
525static int __init arm64_dma_init(void) 525static int __init arm64_dma_init(void)
526{ 526{
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))
528 swiotlb = 1; 529 swiotlb = 1;
529 530
530 return atomic_pool_init(); 531 return atomic_pool_init();
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 212c4d1e2f26..716d1226ba69 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -401,7 +401,8 @@ static void __init free_unused_memmap(void)
401 */ 401 */
402void __init mem_init(void) 402void __init mem_init(void)
403{ 403{
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))
405 swiotlb_init(1); 406 swiotlb_init(1);
406 407
407 set_max_mapnr(pfn_to_page(max_pfn) - mem_map); 408 set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
index 36049af2715e..410efb2c7b80 100644
--- a/arch/x86/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb.c
@@ -68,7 +68,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
68 */ 68 */
69int __init pci_swiotlb_detect_override(void) 69int __init pci_swiotlb_detect_override(void)
70{ 70{
71 if (swiotlb_force) 71 if (swiotlb_force == SWIOTLB_FORCE)
72 swiotlb = 1; 72 swiotlb = 1;
73 73
74 return swiotlb; 74 return swiotlb;
diff --git a/arch/x86/xen/pci-swiotlb-xen.c b/arch/x86/xen/pci-swiotlb-xen.c
index a9fafb5c8738..a0b36a9d5df1 100644
--- a/arch/x86/xen/pci-swiotlb-xen.c
+++ b/arch/x86/xen/pci-swiotlb-xen.c
@@ -48,7 +48,7 @@ int __init pci_xen_swiotlb_detect(void)
48 * activate this IOMMU. If running as PV privileged, activate it 48 * activate this IOMMU. If running as PV privileged, activate it
49 * irregardless. 49 * irregardless.
50 */ 50 */
51 if ((xen_initial_domain() || swiotlb || swiotlb_force)) 51 if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
52 xen_swiotlb = 1; 52 xen_swiotlb = 1;
53 53
54 /* If we are running under Xen, we MUST disable the native SWIOTLB. 54 /* If we are running under Xen, we MUST disable the native SWIOTLB.
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 478fb91e3df2..aba12009422e 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -392,7 +392,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
392 if (dma_capable(dev, dev_addr, size) && 392 if (dma_capable(dev, dev_addr, size) &&
393 !range_straddles_page_boundary(phys, size) && 393 !range_straddles_page_boundary(phys, size) &&
394 !xen_arch_need_swiotlb(dev, phys, dev_addr) && 394 !xen_arch_need_swiotlb(dev, phys, dev_addr) &&
395 !swiotlb_force) { 395 (swiotlb_force != SWIOTLB_FORCE)) {
396 /* we are not interested in the dma_addr returned by 396 /* we are not interested in the dma_addr returned by
397 * xen_dma_map_page, only in the potential cache flushes executed 397 * xen_dma_map_page, only in the potential cache flushes executed
398 * by the function. */ 398 * by the function. */
@@ -552,7 +552,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
552 phys_addr_t paddr = sg_phys(sg); 552 phys_addr_t paddr = sg_phys(sg);
553 dma_addr_t dev_addr = xen_phys_to_bus(paddr); 553 dma_addr_t dev_addr = xen_phys_to_bus(paddr);
554 554
555 if (swiotlb_force || 555 if (swiotlb_force == SWIOTLB_FORCE ||
556 xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || 556 xen_arch_need_swiotlb(hwdev, paddr, dev_addr) ||
557 !dma_capable(hwdev, dev_addr, sg->length) || 557 !dma_capable(hwdev, dev_addr, sg->length) ||
558 range_straddles_page_boundary(paddr, sg->length)) { 558 range_straddles_page_boundary(paddr, sg->length)) {
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 183f37c8a5e1..71d104e4c849 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -9,7 +9,12 @@ struct device;
9struct page; 9struct page;
10struct scatterlist; 10struct scatterlist;
11 11
12extern int swiotlb_force; 12enum swiotlb_force {
13 SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
14 SWIOTLB_FORCE, /* swiotlb=force */
15};
16
17extern enum swiotlb_force swiotlb_force;
13 18
14/* 19/*
15 * Maximum allowable number of contiguous slabs to map, 20 * Maximum allowable number of contiguous slabs to map,
diff --git a/include/trace/events/swiotlb.h b/include/trace/events/swiotlb.h
index 7ea4c5e7c448..5e2e30a7efce 100644
--- a/include/trace/events/swiotlb.h
+++ b/include/trace/events/swiotlb.h
@@ -11,16 +11,16 @@ TRACE_EVENT(swiotlb_bounced,
11 TP_PROTO(struct device *dev, 11 TP_PROTO(struct device *dev,
12 dma_addr_t dev_addr, 12 dma_addr_t dev_addr,
13 size_t size, 13 size_t size,
14 int swiotlb_force), 14 enum swiotlb_force swiotlb_force),
15 15
16 TP_ARGS(dev, dev_addr, size, swiotlb_force), 16 TP_ARGS(dev, dev_addr, size, swiotlb_force),
17 17
18 TP_STRUCT__entry( 18 TP_STRUCT__entry(
19 __string( dev_name, dev_name(dev) ) 19 __string( dev_name, dev_name(dev) )
20 __field( u64, dma_mask ) 20 __field( u64, dma_mask )
21 __field( dma_addr_t, dev_addr ) 21 __field( dma_addr_t, dev_addr )
22 __field( size_t, size ) 22 __field( size_t, size )
23 __field( int, swiotlb_force ) 23 __field( enum swiotlb_force, swiotlb_force )
24 ), 24 ),
25 25
26 TP_fast_assign( 26 TP_fast_assign(
@@ -37,7 +37,9 @@ TRACE_EVENT(swiotlb_bounced,
37 __entry->dma_mask, 37 __entry->dma_mask,
38 (unsigned long long)__entry->dev_addr, 38 (unsigned long long)__entry->dev_addr,
39 __entry->size, 39 __entry->size,
40 __entry->swiotlb_force ? "swiotlb_force" : "" ) 40 __print_symbolic(__entry->swiotlb_force,
41 { SWIOTLB_NORMAL, "NORMAL" },
42 { SWIOTLB_FORCE, "FORCE" }))
41); 43);
42 44
43#endif /* _TRACE_SWIOTLB_H */ 45#endif /* _TRACE_SWIOTLB_H */
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index cb1b54ee8527..a32dce6d5101 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -53,7 +53,7 @@
53 */ 53 */
54#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) 54#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
55 55
56int swiotlb_force; 56enum swiotlb_force swiotlb_force;
57 57
58/* 58/*
59 * Used to do a quick range check in swiotlb_tbl_unmap_single and 59 * Used to do a quick range check in swiotlb_tbl_unmap_single and
@@ -107,7 +107,7 @@ setup_io_tlb_npages(char *str)
107 if (*str == ',') 107 if (*str == ',')
108 ++str; 108 ++str;
109 if (!strcmp(str, "force")) 109 if (!strcmp(str, "force"))
110 swiotlb_force = 1; 110 swiotlb_force = SWIOTLB_FORCE;
111 111
112 return 0; 112 return 0;
113} 113}
@@ -763,7 +763,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
763 * we can safely return the device addr and not worry about bounce 763 * we can safely return the device addr and not worry about bounce
764 * buffering it. 764 * buffering it.
765 */ 765 */
766 if (dma_capable(dev, dev_addr, size) && !swiotlb_force) 766 if (dma_capable(dev, dev_addr, size) && swiotlb_force != SWIOTLB_FORCE)
767 return dev_addr; 767 return dev_addr;
768 768
769 trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force); 769 trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force);
@@ -904,7 +904,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
904 phys_addr_t paddr = sg_phys(sg); 904 phys_addr_t paddr = sg_phys(sg);
905 dma_addr_t dev_addr = phys_to_dma(hwdev, paddr); 905 dma_addr_t dev_addr = phys_to_dma(hwdev, paddr);
906 906
907 if (swiotlb_force || 907 if (swiotlb_force == SWIOTLB_FORCE ||
908 !dma_capable(hwdev, dev_addr, sg->length)) { 908 !dma_capable(hwdev, dev_addr, sg->length)) {
909 phys_addr_t map = map_single(hwdev, sg_phys(sg), 909 phys_addr_t map = map_single(hwdev, sg_phys(sg),
910 sg->length, dir, attrs); 910 sg->length, dir, attrs);