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>
This commit is contained in:
Geert Uytterhoeven 2016-12-16 14:28:41 +01:00 committed by Konrad Rzeszutek Wilk
parent 6c206e4d99
commit ae7871be18
8 changed files with 27 additions and 18 deletions

View File

@ -524,7 +524,8 @@ EXPORT_SYMBOL(dummy_dma_ops);
static int __init arm64_dma_init(void) static int __init arm64_dma_init(void)
{ {
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT)) if (swiotlb_force == SWIOTLB_FORCE ||
max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
swiotlb = 1; swiotlb = 1;
return atomic_pool_init(); return atomic_pool_init();

View File

@ -401,7 +401,8 @@ static void __init free_unused_memmap(void)
*/ */
void __init mem_init(void) void __init mem_init(void)
{ {
if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT)) if (swiotlb_force == SWIOTLB_FORCE ||
max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
swiotlb_init(1); swiotlb_init(1);
set_max_mapnr(pfn_to_page(max_pfn) - mem_map); set_max_mapnr(pfn_to_page(max_pfn) - mem_map);

View File

@ -68,7 +68,7 @@ static struct dma_map_ops swiotlb_dma_ops = {
*/ */
int __init pci_swiotlb_detect_override(void) int __init pci_swiotlb_detect_override(void)
{ {
if (swiotlb_force) if (swiotlb_force == SWIOTLB_FORCE)
swiotlb = 1; swiotlb = 1;
return swiotlb; return swiotlb;

View File

@ -48,7 +48,7 @@ int __init pci_xen_swiotlb_detect(void)
* activate this IOMMU. If running as PV privileged, activate it * activate this IOMMU. If running as PV privileged, activate it
* irregardless. * irregardless.
*/ */
if ((xen_initial_domain() || swiotlb || swiotlb_force)) if (xen_initial_domain() || swiotlb || swiotlb_force == SWIOTLB_FORCE)
xen_swiotlb = 1; xen_swiotlb = 1;
/* If we are running under Xen, we MUST disable the native SWIOTLB. /* If we are running under Xen, we MUST disable the native SWIOTLB.

View File

@ -392,7 +392,7 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
if (dma_capable(dev, dev_addr, size) && if (dma_capable(dev, dev_addr, size) &&
!range_straddles_page_boundary(phys, size) && !range_straddles_page_boundary(phys, size) &&
!xen_arch_need_swiotlb(dev, phys, dev_addr) && !xen_arch_need_swiotlb(dev, phys, dev_addr) &&
!swiotlb_force) { (swiotlb_force != SWIOTLB_FORCE)) {
/* we are not interested in the dma_addr returned by /* we are not interested in the dma_addr returned by
* xen_dma_map_page, only in the potential cache flushes executed * xen_dma_map_page, only in the potential cache flushes executed
* by the function. */ * by the function. */
@ -552,7 +552,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
phys_addr_t paddr = sg_phys(sg); phys_addr_t paddr = sg_phys(sg);
dma_addr_t dev_addr = xen_phys_to_bus(paddr); dma_addr_t dev_addr = xen_phys_to_bus(paddr);
if (swiotlb_force || if (swiotlb_force == SWIOTLB_FORCE ||
xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || xen_arch_need_swiotlb(hwdev, paddr, dev_addr) ||
!dma_capable(hwdev, dev_addr, sg->length) || !dma_capable(hwdev, dev_addr, sg->length) ||
range_straddles_page_boundary(paddr, sg->length)) { range_straddles_page_boundary(paddr, sg->length)) {

View File

@ -9,7 +9,12 @@ struct device;
struct page; struct page;
struct scatterlist; struct scatterlist;
extern int swiotlb_force; enum swiotlb_force {
SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
SWIOTLB_FORCE, /* swiotlb=force */
};
extern enum swiotlb_force swiotlb_force;
/* /*
* Maximum allowable number of contiguous slabs to map, * Maximum allowable number of contiguous slabs to map,

View File

@ -11,16 +11,16 @@ TRACE_EVENT(swiotlb_bounced,
TP_PROTO(struct device *dev, TP_PROTO(struct device *dev,
dma_addr_t dev_addr, dma_addr_t dev_addr,
size_t size, size_t size,
int swiotlb_force), enum swiotlb_force swiotlb_force),
TP_ARGS(dev, dev_addr, size, swiotlb_force), TP_ARGS(dev, dev_addr, size, swiotlb_force),
TP_STRUCT__entry( TP_STRUCT__entry(
__string( dev_name, dev_name(dev) ) __string( dev_name, dev_name(dev) )
__field( u64, dma_mask ) __field( u64, dma_mask )
__field( dma_addr_t, dev_addr ) __field( dma_addr_t, dev_addr )
__field( size_t, size ) __field( size_t, size )
__field( int, swiotlb_force ) __field( enum swiotlb_force, swiotlb_force )
), ),
TP_fast_assign( TP_fast_assign(
@ -37,7 +37,9 @@ TRACE_EVENT(swiotlb_bounced,
__entry->dma_mask, __entry->dma_mask,
(unsigned long long)__entry->dev_addr, (unsigned long long)__entry->dev_addr,
__entry->size, __entry->size,
__entry->swiotlb_force ? "swiotlb_force" : "" ) __print_symbolic(__entry->swiotlb_force,
{ SWIOTLB_NORMAL, "NORMAL" },
{ SWIOTLB_FORCE, "FORCE" }))
); );
#endif /* _TRACE_SWIOTLB_H */ #endif /* _TRACE_SWIOTLB_H */

View File

@ -53,7 +53,7 @@
*/ */
#define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
int swiotlb_force; enum swiotlb_force swiotlb_force;
/* /*
* Used to do a quick range check in swiotlb_tbl_unmap_single and * Used to do a quick range check in swiotlb_tbl_unmap_single and
@ -107,7 +107,7 @@ setup_io_tlb_npages(char *str)
if (*str == ',') if (*str == ',')
++str; ++str;
if (!strcmp(str, "force")) if (!strcmp(str, "force"))
swiotlb_force = 1; swiotlb_force = SWIOTLB_FORCE;
return 0; return 0;
} }
@ -763,7 +763,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
* we can safely return the device addr and not worry about bounce * we can safely return the device addr and not worry about bounce
* buffering it. * buffering it.
*/ */
if (dma_capable(dev, dev_addr, size) && !swiotlb_force) if (dma_capable(dev, dev_addr, size) && swiotlb_force != SWIOTLB_FORCE)
return dev_addr; return dev_addr;
trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force); 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,
phys_addr_t paddr = sg_phys(sg); phys_addr_t paddr = sg_phys(sg);
dma_addr_t dev_addr = phys_to_dma(hwdev, paddr); dma_addr_t dev_addr = phys_to_dma(hwdev, paddr);
if (swiotlb_force || if (swiotlb_force == SWIOTLB_FORCE ||
!dma_capable(hwdev, dev_addr, sg->length)) { !dma_capable(hwdev, dev_addr, sg->length)) {
phys_addr_t map = map_single(hwdev, sg_phys(sg), phys_addr_t map = map_single(hwdev, sg_phys(sg),
sg->length, dir, attrs); sg->length, dir, attrs);