[PATCH v6] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.
The maximum of SW-IOMMU is limited to 2^11*128 = 256K. And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL<<20) 64M now. While in different platform and different requirement this seems improper. So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE to io_tlb_default_size which can configure by kernel cmdline. This can meet different requirement. Signed-off-by: Chuansheng Liu Signed-off-by: Zhang Dongxing Signed-off-by: Wang Xiaoming --- patch v1 make this change at Kconfig which needs to edit the .config manually. https://lkml.org/lkml/2015/1/25/571 patch v2 only change IO_TLB_SEGSIZE configurable. https://lkml.org/lkml/2015/2/5/812 patch v3 parsing io_tlb_segsize and io_tlb_default_size independently. https://lkml.org/lkml/2015/2/15/217 patch v4 hasn't validated the data from command line. https://lkml.org/lkml/2015/2/17/114 patch v5 fix the postion of 'force'. https://lkml.org/lkml/2015/3/3/84 Documentation/kernel-parameters.txt |5 +- arch/mips/cavium-octeon/dma-octeon.c |2 +- arch/mips/netlogic/common/nlm-dma.c |2 +- drivers/xen/swiotlb-xen.c|6 +-- include/linux/swiotlb.h |8 +-- lib/swiotlb.c| 99 ++ 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 4df73da..8463ef4 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -3438,10 +3438,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted. it if 0 is given (See Documentation/cgroups/memory.txt) swiotlb=[ARM,IA-64,PPC,MIPS,X86] - Format: { | force } + Format: { ,force,,} -- Number of I/O TLB slabs force -- force using of bounce buffers even if they wouldn't be automatically used by the kernel +-- Maximum allowable number of contiguous slabs to map +-- The size of SW-MMU mapped. + "Use ',' to seperate them." switches= [HW,M68k] diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c index 3778655..a521af6 100644 --- a/arch/mips/cavium-octeon/dma-octeon.c +++ b/arch/mips/cavium-octeon/dma-octeon.c @@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void) swiotlbsize = 64 * (1<<20); #endif swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT; - swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE); + swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize); swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT; octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize); diff --git a/arch/mips/netlogic/common/nlm-dma.c b/arch/mips/netlogic/common/nlm-dma.c index f3d4ae8..eeffa8f 100644 --- a/arch/mips/netlogic/common/nlm-dma.c +++ b/arch/mips/netlogic/common/nlm-dma.c @@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void) swiotlbsize = 1 << 20; /* 1 MB for now */ swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT; - swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE); + swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize); swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT; nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 810ad41..3b3e9fe 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) dma_addr_t dma_handle; phys_addr_t p = virt_to_phys(buf); - dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT; + dma_bits = get_order(io_tlb_segsize << IO_TLB_SHIFT) + PAGE_SHIFT; i = 0; do { - int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE); + int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize); do { rc = xen_create_contiguous_region( @@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl) { if (!nr_tbl) { xen_io_tlb_nslabs = (64 * 1024 * 1024 >> IO_TLB_SHIFT); - xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE); + xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize); } else xen_io_tlb_nslabs = nr_tbl; diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index e7a018e..13506db 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -8,13 +8,7 @@ struct dma_attrs; struct scatterlist; extern int swiotlb_force; - -/* - * Maximum allowable number of contiguous slabs to map, - * must be a power of 2. What is the appropriate value ? - * The
[PATCH v6] modify the IO_TLB_SEGSIZE and IO_TLB_DEFAULT_SIZE configurable as flexible requirement about SW-IOMMU.
The maximum of SW-IOMMU is limited to 2^11*128 = 256K. And the size of IO_TLB_DEFAULT_SIZE is limited to (64UL20) 64M now. While in different platform and different requirement this seems improper. So modifing the IO_TLB_SEGSIZE to io_tlb_segsize and IO_TLB_DEFAULT_SIZE to io_tlb_default_size which can configure by kernel cmdline. This can meet different requirement. Signed-off-by: Chuansheng Liu chuansheng@intel.com Signed-off-by: Zhang Dongxing dongxing.zh...@intel.com Signed-off-by: Wang Xiaoming xiaoming.w...@intel.com --- patch v1 make this change at Kconfig which needs to edit the .config manually. https://lkml.org/lkml/2015/1/25/571 patch v2 only change IO_TLB_SEGSIZE configurable. https://lkml.org/lkml/2015/2/5/812 patch v3 parsing io_tlb_segsize and io_tlb_default_size independently. https://lkml.org/lkml/2015/2/15/217 patch v4 hasn't validated the data from command line. https://lkml.org/lkml/2015/2/17/114 patch v5 fix the postion of 'force'. https://lkml.org/lkml/2015/3/3/84 Documentation/kernel-parameters.txt |5 +- arch/mips/cavium-octeon/dma-octeon.c |2 +- arch/mips/netlogic/common/nlm-dma.c |2 +- drivers/xen/swiotlb-xen.c|6 +-- include/linux/swiotlb.h |8 +-- lib/swiotlb.c| 99 ++ 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 4df73da..8463ef4 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -3438,10 +3438,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted. it if 0 is given (See Documentation/cgroups/memory.txt) swiotlb=[ARM,IA-64,PPC,MIPS,X86] - Format: { int | force } + Format: { int,force,int,int} int -- Number of I/O TLB slabs force -- force using of bounce buffers even if they wouldn't be automatically used by the kernel + int -- Maximum allowable number of contiguous slabs to map + int -- The size of SW-MMU mapped. + Use ',' to seperate them. switches= [HW,M68k] diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c index 3778655..a521af6 100644 --- a/arch/mips/cavium-octeon/dma-octeon.c +++ b/arch/mips/cavium-octeon/dma-octeon.c @@ -312,7 +312,7 @@ void __init plat_swiotlb_setup(void) swiotlbsize = 64 * (120); #endif swiotlb_nslabs = swiotlbsize IO_TLB_SHIFT; - swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE); + swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize); swiotlbsize = swiotlb_nslabs IO_TLB_SHIFT; octeon_swiotlb = alloc_bootmem_low_pages(swiotlbsize); diff --git a/arch/mips/netlogic/common/nlm-dma.c b/arch/mips/netlogic/common/nlm-dma.c index f3d4ae8..eeffa8f 100644 --- a/arch/mips/netlogic/common/nlm-dma.c +++ b/arch/mips/netlogic/common/nlm-dma.c @@ -99,7 +99,7 @@ void __init plat_swiotlb_setup(void) swiotlbsize = 1 20; /* 1 MB for now */ swiotlb_nslabs = swiotlbsize IO_TLB_SHIFT; - swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE); + swiotlb_nslabs = ALIGN(swiotlb_nslabs, io_tlb_segsize); swiotlbsize = swiotlb_nslabs IO_TLB_SHIFT; nlm_swiotlb = alloc_bootmem_low_pages(swiotlbsize); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 810ad41..3b3e9fe 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -164,11 +164,11 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) dma_addr_t dma_handle; phys_addr_t p = virt_to_phys(buf); - dma_bits = get_order(IO_TLB_SEGSIZE IO_TLB_SHIFT) + PAGE_SHIFT; + dma_bits = get_order(io_tlb_segsize IO_TLB_SHIFT) + PAGE_SHIFT; i = 0; do { - int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE); + int slabs = min(nslabs - i, (unsigned long)io_tlb_segsize); do { rc = xen_create_contiguous_region( @@ -187,7 +187,7 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl) { if (!nr_tbl) { xen_io_tlb_nslabs = (64 * 1024 * 1024 IO_TLB_SHIFT); - xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE); + xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, io_tlb_segsize); } else xen_io_tlb_nslabs = nr_tbl; diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index e7a018e..13506db 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -8,13 +8,7 @@ struct dma_attrs; struct scatterlist; extern int swiotlb_force; - -/* - * Maximum allowable number of contiguous slabs to map, - *