consolidate direct dma mapping and swiotlb support
Subsystems (41)
PATCH 39/67 iommu/amd_iommu: use dma_direct_* helpers for the direct mapping case
In reply to Christoph HellwigThis adds support for CMA allocations, but is otherwise identical.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/amd_iommu.c | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -107,6 +107,7 @@ config IOMMU_PGTABLES_L2 # AMD IOMMU support config AMD_IOMMU bool "AMD IOMMU support" + select DMA_DIRECT_OPS select SWIOTLB select PCI_MSI select PCI_ATS
drivers/iommu/amd_iommu.c +9 -18
@@ -2592,11 +2592,9 @@ static void *alloc_coherent(struct device *dev, size_t size,struct page *page; domain =get_domain (dev); -if (PTR_ERR (domain) == -EINVAL ) { - page =alloc_pages (flag,get_order (size)); - *dma_addr =page_to_phys (page); -return page_address (page); - }else if (IS_ERR (domain)) +if (PTR_ERR (domain) == -EINVAL ) +return dma_direct_alloc (dev, size, dma_addr, flag, attrs); +else if (IS_ERR (domain))return NULL ; dma_dom =to_dma_ops_domain (domain);
@@ -2642,24 +2640,17 @@ static void free_coherent(struct device *dev, size_t size, void *virt_addr, dma_addr_t dma_addr, unsigned long attrs) { - struct protection_domain *domain; -struct dma_ops_domain *dma_dom; -struct page *page; + struct protection_domain *domain = get_domain(dev); - page =virt_to_page (virt_addr); size =PAGE_ALIGN (size); - domain =get_domain (dev); -if (IS_ERR (domain)) - goto free_mem; - - dma_dom =to_dma_ops_domain (domain); +if (!IS_ERR (domain)) { +struct dma_ops_domain *dma_dom =to_dma_ops_domain (domain); -__unmap_single (dma_dom, dma_addr, size,DMA_BIDIRECTIONAL ); +__unmap_single (dma_dom, dma_addr, size,DMA_BIDIRECTIONAL ); + } -free_mem: -if (!dma_release_from_contiguous (dev, page, size >>PAGE_SHIFT )) -__free_pages (page,get_order (size)); +dma_direct_free (dev, size, virt_addr, dma_addr, attrs); }/*
Signature · 1 line
2.14.2
PATCH 39/67 iommu/amd_iommu: use dma_direct_* helpers for the direct mapping case
In reply to Christoph HellwigThis adds support for CMA allocations, but is otherwise identical.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/amd_iommu.c | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 18 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -107,6 +107,7 @@ config IOMMU_PGTABLES_L2 # AMD IOMMU support config AMD_IOMMU bool "AMD IOMMU support" + select DMA_DIRECT_OPS select SWIOTLB select PCI_MSI select PCI_ATS
drivers/iommu/amd_iommu.c +9 -18
@@ -2592,11 +2592,9 @@ static void *alloc_coherent(struct device *dev, size_t size,struct page *page; domain =get_domain (dev); -if (PTR_ERR (domain) == -EINVAL ) { - page =alloc_pages (flag,get_order (size)); - *dma_addr =page_to_phys (page); -return page_address (page); - }else if (IS_ERR (domain)) +if (PTR_ERR (domain) == -EINVAL ) +return dma_direct_alloc (dev, size, dma_addr, flag, attrs); +else if (IS_ERR (domain))return NULL ; dma_dom =to_dma_ops_domain (domain);
@@ -2642,24 +2640,17 @@ static void free_coherent(struct device *dev, size_t size, void *virt_addr, dma_addr_t dma_addr, unsigned long attrs) { - struct protection_domain *domain; -struct dma_ops_domain *dma_dom; -struct page *page; + struct protection_domain *domain = get_domain(dev); - page =virt_to_page (virt_addr); size =PAGE_ALIGN (size); - domain =get_domain (dev); -if (IS_ERR (domain)) - goto free_mem; - - dma_dom =to_dma_ops_domain (domain); +if (!IS_ERR (domain)) { +struct dma_ops_domain *dma_dom =to_dma_ops_domain (domain); -__unmap_single (dma_dom, dma_addr, size,DMA_BIDIRECTIONAL ); +__unmap_single (dma_dom, dma_addr, size,DMA_BIDIRECTIONAL ); + } -free_mem: -if (!dma_release_from_contiguous (dev, page, size >>PAGE_SHIFT )) -__free_pages (page,get_order (size)); +dma_direct_free (dev, size, virt_addr, dma_addr, attrs); }/*
Signature · 1 line
2.14.2
PATCH 40/67 iommu/intel-iommu: use dma_direct_* helpers for the direct mapping case
In reply to Christoph HellwigThis simplifies the code a bit, and prepares for future cleanups.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -143,6 +143,7 @@ config DMAR_TABLE config INTEL_IOMMU bool "Support for Intel IOMMU using DMA Remapping Devices" depends on PCI_MSI && ACPI && (X86 || IA64_GENERIC) + select DMA_DIRECT_OPS select IOMMU_API select IOMMU_IOVA select DMAR_TABLE
drivers/iommu/intel-iommu.c +8 -9
@@ -31,6 +31,7 @@#include <linux/pci.h> #include <linux/dmar.h> #include <linux/dma-mapping.h> +#include <linux/dma-direct.h> #include <linux/mempool.h> #include <linux/memory.h> #include <linux/cpu.h>
@@ -3712,17 +3713,12 @@ static void *intel_alloc_coherent(struct device *dev, size_t size,struct page *page =NULL ;int order; +if (iommu_no_mapping (dev)) +return dma_direct_alloc (dev, size, dma_handle, flags, attrs); + size =PAGE_ALIGN (size); order =get_order (size); - -if (!iommu_no_mapping (dev)) - flags &= ~(GFP_DMA |GFP_DMA32 ); -else if (dev->coherent_dma_mask <dma_get_required_mask (dev)) { -if (dev->coherent_dma_mask <DMA_BIT_MASK (32 )) - flags |=GFP_DMA ; -else - flags |=GFP_DMA32 ; - } + flags &= ~(GFP_DMA |GFP_DMA32 );if (gfpflags_allow_blocking (flags)) {unsigned int count = size >>PAGE_SHIFT ;
@@ -3758,6 +3754,9 @@ static void intel_free_coherent(struct device *dev, size_t size, void *vaddr,int order;struct page *page =virt_to_page (vaddr); +if (iommu_no_mapping (dev)) +return dma_direct_free (dev, size, vaddr, dma_handle, attrs); + size =PAGE_ALIGN (size); order =get_order (size);
Signature · 1 line
2.14.2
PATCH 40/67 iommu/intel-iommu: use dma_direct_* helpers for the direct mapping case
In reply to Christoph HellwigThis simplifies the code a bit, and prepares for future cleanups.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/intel-iommu.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -143,6 +143,7 @@ config DMAR_TABLE config INTEL_IOMMU bool "Support for Intel IOMMU using DMA Remapping Devices" depends on PCI_MSI && ACPI && (X86 || IA64_GENERIC) + select DMA_DIRECT_OPS select IOMMU_API select IOMMU_IOVA select DMAR_TABLE
drivers/iommu/intel-iommu.c +8 -9
@@ -31,6 +31,7 @@#include <linux/pci.h> #include <linux/dmar.h> #include <linux/dma-mapping.h> +#include <linux/dma-direct.h> #include <linux/mempool.h> #include <linux/memory.h> #include <linux/cpu.h>
@@ -3712,17 +3713,12 @@ static void *intel_alloc_coherent(struct device *dev, size_t size,struct page *page =NULL ;int order; +if (iommu_no_mapping (dev)) +return dma_direct_alloc (dev, size, dma_handle, flags, attrs); + size =PAGE_ALIGN (size); order =get_order (size); - -if (!iommu_no_mapping (dev)) - flags &= ~(GFP_DMA |GFP_DMA32 ); -else if (dev->coherent_dma_mask <dma_get_required_mask (dev)) { -if (dev->coherent_dma_mask <DMA_BIT_MASK (32 )) - flags |=GFP_DMA ; -else - flags |=GFP_DMA32 ; - } + flags &= ~(GFP_DMA |GFP_DMA32 );if (gfpflags_allow_blocking (flags)) {unsigned int count = size >>PAGE_SHIFT ;
@@ -3758,6 +3754,9 @@ static void intel_free_coherent(struct device *dev, size_t size, void *vaddr,int order;struct page *page =virt_to_page (vaddr); +if (iommu_no_mapping (dev)) +return dma_direct_free (dev, size, vaddr, dma_handle, attrs); + size =PAGE_ALIGN (size); order =get_order (size);
Signature · 1 line
2.14.2
PATCH 41/67 x86: remove dma_alloc_coherent_gfp_flags
In reply to Christoph HellwigAll dma_ops implementations used on x86 now take care of setting their own required GFP_ masks for the allocation. And given that the common code now clears harmful flags itself that means we can stop the flags in all the iommu implementations as well.
--- arch/x86/include/asm/dma-mapping.h | 11 ----------- arch/x86/kernel/amd_gart_64.c | 1 - arch/x86/kernel/pci-calgary_64.c | 2 -- arch/x86/kernel/pci-dma.c | 2 -- arch/x86/mm/mem_encrypt.c | 7 ------- drivers/iommu/amd_iommu.c | 1 - drivers/iommu/intel-iommu.c | 1 - 7 files changed, 25 deletions(-)
arch/x86/include/asm/dma-mapping.h +0 -11
@@ -36,15 +36,4 @@ int arch_dma_supported(struct device *dev, u64 mask);bool arch_dma_alloc_attrs (struct device **dev,gfp_t *gfp);#define arch_dma_alloc_attrs arch_dma_alloc_attrs -static inline gfp_t dma_alloc_coherent_gfp_flags (struct device *dev,gfp_t gfp) -{ -if (dev->coherent_dma_mask <=DMA_BIT_MASK (24 )) - gfp |=GFP_DMA ; -#ifdef CONFIG_X86_64 -if (dev->coherent_dma_mask <=DMA_BIT_MASK (32 ) && !(gfp &GFP_DMA )) - gfp |=GFP_DMA32 ; -#endif -return gfp; -} -#endif
arch/x86/kernel/amd_gart_64.c +0 -1
@@ -487,7 +487,6 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,if (!force_iommu || dev->coherent_dma_mask <=DMA_BIT_MASK (24 ))return dma_direct_alloc (dev, size, dma_addr, flag, attrs); - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); page =alloc_pages (flag | __GFP_ZERO,get_order (size));if (!page)return NULL ;
arch/x86/kernel/pci-calgary_64.c +0 -2
@@ -446,8 +446,6 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size, npages = size >>PAGE_SHIFT ; order =get_order (size); - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); -/* alloc enough pages (and possibly more) */ ret = (void *)__get_free_pages (flag, order);if (!ret)
arch/x86/kernel/pci-dma.c +0 -2
@@ -82,8 +82,6 @@ bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp)if (!*dev) *dev = &x86_dma_fallback_dev; - *gfp =dma_alloc_coherent_gfp_flags (*dev, *gfp); -if (!is_device_dma_capable (*dev))return false;return true;
arch/x86/mm/mem_encrypt.c +0 -7
@@ -208,13 +208,6 @@ static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,void *vaddr =NULL ; order =get_order (size); - -/* -* Memory will be memset to zero after marking decrypted, so don't -* bother clearing it before. -*/ - gfp &= ~__GFP_ZERO; - page =alloc_pages_node (dev_to_node (dev), gfp, order);if (page) {dma_addr_t addr;
drivers/iommu/amd_iommu.c +0 -1
@@ -2600,7 +2600,6 @@ static void *alloc_coherent(struct device *dev, size_t size, dma_dom =to_dma_ops_domain (domain); size =PAGE_ALIGN (size); dma_mask = dev->coherent_dma_mask; - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); flag |= __GFP_ZERO; page =alloc_pages (flag | __GFP_NOWARN,get_order (size));
drivers/iommu/intel-iommu.c +0 -1
@@ -3718,7 +3718,6 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, size =PAGE_ALIGN (size); order =get_order (size); - flags &= ~(GFP_DMA |GFP_DMA32 );if (gfpflags_allow_blocking (flags)) {unsigned int count = size >>PAGE_SHIFT ;
Signature · 1 line
2.14.2
PATCH 41/67 x86: remove dma_alloc_coherent_gfp_flags
In reply to Christoph HellwigAll dma_ops implementations used on x86 now take care of setting their own required GFP_ masks for the allocation. And given that the common code now clears harmful flags itself that means we can stop the flags in all the iommu implementations as well.
--- arch/x86/include/asm/dma-mapping.h | 11 ----------- arch/x86/kernel/amd_gart_64.c | 1 - arch/x86/kernel/pci-calgary_64.c | 2 -- arch/x86/kernel/pci-dma.c | 2 -- arch/x86/mm/mem_encrypt.c | 7 ------- drivers/iommu/amd_iommu.c | 1 - drivers/iommu/intel-iommu.c | 1 - 7 files changed, 25 deletions(-)
arch/x86/include/asm/dma-mapping.h +0 -11
@@ -36,15 +36,4 @@ int arch_dma_supported(struct device *dev, u64 mask);bool arch_dma_alloc_attrs (struct device **dev,gfp_t *gfp);#define arch_dma_alloc_attrs arch_dma_alloc_attrs -static inline gfp_t dma_alloc_coherent_gfp_flags (struct device *dev,gfp_t gfp) -{ -if (dev->coherent_dma_mask <=DMA_BIT_MASK (24 )) - gfp |=GFP_DMA ; -#ifdef CONFIG_X86_64 -if (dev->coherent_dma_mask <=DMA_BIT_MASK (32 ) && !(gfp &GFP_DMA )) - gfp |=GFP_DMA32 ; -#endif -return gfp; -} -#endif
arch/x86/kernel/amd_gart_64.c +0 -1
@@ -487,7 +487,6 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,if (!force_iommu || dev->coherent_dma_mask <=DMA_BIT_MASK (24 ))return dma_direct_alloc (dev, size, dma_addr, flag, attrs); - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); page =alloc_pages (flag | __GFP_ZERO,get_order (size));if (!page)return NULL ;
arch/x86/kernel/pci-calgary_64.c +0 -2
@@ -446,8 +446,6 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size, npages = size >>PAGE_SHIFT ; order =get_order (size); - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); -/* alloc enough pages (and possibly more) */ ret = (void *)__get_free_pages (flag, order);if (!ret)
arch/x86/kernel/pci-dma.c +0 -2
@@ -82,8 +82,6 @@ bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp)if (!*dev) *dev = &x86_dma_fallback_dev; - *gfp =dma_alloc_coherent_gfp_flags (*dev, *gfp); -if (!is_device_dma_capable (*dev))return false;return true;
arch/x86/mm/mem_encrypt.c +0 -7
@@ -208,13 +208,6 @@ static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,void *vaddr =NULL ; order =get_order (size); - -/* -* Memory will be memset to zero after marking decrypted, so don't -* bother clearing it before. -*/ - gfp &= ~__GFP_ZERO; - page =alloc_pages_node (dev_to_node (dev), gfp, order);if (page) {dma_addr_t addr;
drivers/iommu/amd_iommu.c +0 -1
@@ -2600,7 +2600,6 @@ static void *alloc_coherent(struct device *dev, size_t size, dma_dom =to_dma_ops_domain (domain); size =PAGE_ALIGN (size); dma_mask = dev->coherent_dma_mask; - flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); flag |= __GFP_ZERO; page =alloc_pages (flag | __GFP_NOWARN,get_order (size));
drivers/iommu/intel-iommu.c +0 -1
@@ -3718,7 +3718,6 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, size =PAGE_ALIGN (size); order =get_order (size); - flags &= ~(GFP_DMA |GFP_DMA32 );if (gfpflags_allow_blocking (flags)) {unsigned int count = size >>PAGE_SHIFT ;
Signature · 1 line
2.14.2
PATCH 42/67 arm64: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/arm64/mm/dma-mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/mm/dma-mapping.c +2 -2
@@ -368,7 +368,7 @@ static int __swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t addr)return 0 ; } -static const struct dma_map_ops swiotlb_dma_ops = { +static const struct dma_map_ops arm64_swiotlb_dma_ops = { .alloc = __dma_alloc, .free = __dma_free, .mmap = __swiotlb_mmap,
@@ -923,7 +923,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, const struct iommu_ops *iommu, bool coherent) { if (!dev->dma_ops) - dev->dma_ops = &swiotlb_dma_ops; + dev->dma_ops = &arm64_swiotlb_dma_ops; dev->archdata.dma_coherent = coherent;__iommu_setup_dma_ops (dev, dma_base, size, iommu);
Signature · 1 line
2.14.2
PATCH 42/67 arm64: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/arm64/mm/dma-mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/mm/dma-mapping.c +2 -2
@@ -368,7 +368,7 @@ static int __swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t addr)return 0 ; } -static const struct dma_map_ops swiotlb_dma_ops = { +static const struct dma_map_ops arm64_swiotlb_dma_ops = { .alloc = __dma_alloc, .free = __dma_free, .mmap = __swiotlb_mmap,
@@ -923,7 +923,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, const struct iommu_ops *iommu, bool coherent) { if (!dev->dma_ops) - dev->dma_ops = &swiotlb_dma_ops; + dev->dma_ops = &arm64_swiotlb_dma_ops; dev->archdata.dma_coherent = coherent;__iommu_setup_dma_ops (dev, dma_base, size, iommu);
Signature · 1 line
2.14.2
PATCH 43/67 ia64: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/ia64/hp/common/hwsw_iommu.c | 4 ++-- arch/ia64/hp/common/sba_iommu.c | 6 +++--- arch/ia64/kernel/pci-swiotlb.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-)
arch/ia64/hp/common/hwsw_iommu.c +2 -2
@@ -19,7 +19,7 @@#include <linux/export.h> #include <asm/machvec.h> -extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops; +extern const struct dma_map_ops sba_dma_ops, ia64_swiotlb_dma_ops;/* swiotlb declarations & definitions: */ extern int swiotlb_late_init_with_default_size (size_t size);
@@ -38,7 +38,7 @@ static inline int use_swiotlb(struct device *dev)const struct dma_map_ops *hwsw_dma_get_ops (struct device *dev) {if (use_swiotlb (dev)) -return &swiotlb_dma_ops; +return &ia64_swiotlb_dma_ops;return &sba_dma_ops; }EXPORT_SYMBOL (hwsw_dma_get_ops);
arch/ia64/hp/common/sba_iommu.c +3 -3
@@ -2093,7 +2093,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */ arch_initcall (acpi_sba_ioc_init_acpi); -extern const struct dma_map_ops swiotlb_dma_ops; +extern const struct dma_map_ops ia64_swiotlb_dma_ops;static int __init sba_init (void )
@@ -2108,7 +2108,7 @@ sba_init(void)* a successful kdump kernel boot is to use the swiotlb. */ if (is_kdump_kernel ()) { - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to initialize software I/O TLB:" " Try machvec=dig boot option" );
@@ -2130,7 +2130,7 @@ sba_init(void)* If we didn't find something sba_iommu can claim, we * need to setup the swiotlb and switch to the dig machvec. */ - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to find SBA IOMMU or initialize " "software I/O TLB: Try machvec=dig boot option" );
arch/ia64/kernel/pci-swiotlb.c +3 -3
@@ -31,7 +31,7 @@ static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,swiotlb_free_coherent (dev, size, vaddr, dma_addr); } -const struct dma_map_ops swiotlb_dma_ops = { +const struct dma_map_ops ia64_swiotlb_dma_ops = { .alloc = ia64_swiotlb_alloc_coherent, .free = ia64_swiotlb_free_coherent, .map_page = swiotlb_map_page,
@@ -48,7 +48,7 @@ const struct dma_map_ops swiotlb_dma_ops = {void __init swiotlb_dma_init (void ) { - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;swiotlb_init (1 ); }
@@ -60,7 +60,7 @@ void __init pci_swiotlb_init(void)printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" );machvec_init ("dig" );swiotlb_init (1 ); - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;#else panic ("Unable to find Intel IOMMU" );#endif
Signature · 1 line
2.14.2
PATCH 43/67 ia64: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/ia64/hp/common/hwsw_iommu.c | 4 ++-- arch/ia64/hp/common/sba_iommu.c | 6 +++--- arch/ia64/kernel/pci-swiotlb.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-)
arch/ia64/hp/common/hwsw_iommu.c +2 -2
@@ -19,7 +19,7 @@#include <linux/export.h> #include <asm/machvec.h> -extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops; +extern const struct dma_map_ops sba_dma_ops, ia64_swiotlb_dma_ops;/* swiotlb declarations & definitions: */ extern int swiotlb_late_init_with_default_size (size_t size);
@@ -38,7 +38,7 @@ static inline int use_swiotlb(struct device *dev)const struct dma_map_ops *hwsw_dma_get_ops (struct device *dev) {if (use_swiotlb (dev)) -return &swiotlb_dma_ops; +return &ia64_swiotlb_dma_ops;return &sba_dma_ops; }EXPORT_SYMBOL (hwsw_dma_get_ops);
arch/ia64/hp/common/sba_iommu.c +3 -3
@@ -2093,7 +2093,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */ arch_initcall (acpi_sba_ioc_init_acpi); -extern const struct dma_map_ops swiotlb_dma_ops; +extern const struct dma_map_ops ia64_swiotlb_dma_ops;static int __init sba_init (void )
@@ -2108,7 +2108,7 @@ sba_init(void)* a successful kdump kernel boot is to use the swiotlb. */ if (is_kdump_kernel ()) { - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to initialize software I/O TLB:" " Try machvec=dig boot option" );
@@ -2130,7 +2130,7 @@ sba_init(void)* If we didn't find something sba_iommu can claim, we * need to setup the swiotlb and switch to the dig machvec. */ - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to find SBA IOMMU or initialize " "software I/O TLB: Try machvec=dig boot option" );
arch/ia64/kernel/pci-swiotlb.c +3 -3
@@ -31,7 +31,7 @@ static void ia64_swiotlb_free_coherent(struct device *dev, size_t size,swiotlb_free_coherent (dev, size, vaddr, dma_addr); } -const struct dma_map_ops swiotlb_dma_ops = { +const struct dma_map_ops ia64_swiotlb_dma_ops = { .alloc = ia64_swiotlb_alloc_coherent, .free = ia64_swiotlb_free_coherent, .map_page = swiotlb_map_page,
@@ -48,7 +48,7 @@ const struct dma_map_ops swiotlb_dma_ops = {void __init swiotlb_dma_init (void ) { - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;swiotlb_init (1 ); }
@@ -60,7 +60,7 @@ void __init pci_swiotlb_init(void)printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" );machvec_init ("dig" );swiotlb_init (1 ); - dma_ops = &swiotlb_dma_ops; + dma_ops = &ia64_swiotlb_dma_ops;#else panic ("Unable to find Intel IOMMU" );#endif
Signature · 1 line
2.14.2
PATCH 44/67 powerpc: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/powerpc/include/asm/swiotlb.h | 2 +- arch/powerpc/kernel/dma-swiotlb.c | 4 ++-- arch/powerpc/kernel/dma.c | 2 +- arch/powerpc/sysdev/fsl_pci.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/swiotlb.h +1 -1
@@ -13,7 +13,7 @@#include <linux/swiotlb.h> -extern const struct dma_map_ops swiotlb_dma_ops; +extern const struct dma_map_ops powerpc_swiotlb_dma_ops;extern unsigned int ppc_swiotlb_enable;int __init swiotlb_setup_bus_notifier (void );
arch/powerpc/kernel/dma-swiotlb.c +2 -2
@@ -46,7 +46,7 @@ static u64 swiotlb_powerpc_get_required(struct device *dev)* map_page, and unmap_page on highmem, use normal dma_ops * for everything else. */ -const struct dma_map_ops swiotlb_dma_ops = { +const struct dma_map_ops powerpc_swiotlb_dma_ops = { .alloc = __dma_nommu_alloc_coherent, .free = __dma_nommu_free_coherent, .mmap = dma_nommu_mmap_coherent,
@@ -89,7 +89,7 @@ static int ppc_swiotlb_bus_notify(struct notifier_block *nb,/* May need to bounce if the device can't address all of DRAM */ if ((dma_get_mask (dev) +1 ) <memblock_end_of_DRAM ()) -set_dma_ops (dev, &swiotlb_dma_ops); +set_dma_ops (dev, &powerpc_swiotlb_dma_ops);return NOTIFY_DONE ; }
arch/powerpc/kernel/dma.c +1 -1
@@ -33,7 +33,7 @@ static u64 __maybe_unused get_pfn_limit(struct device *dev)struct dev_archdata __maybe_unused *sd = &dev->archdata;#ifdef CONFIG_SWIOTLB -if (sd->max_direct_dma_addr && dev->dma_ops == &swiotlb_dma_ops) +if (sd->max_direct_dma_addr && dev->dma_ops == &powerpc_swiotlb_dma_ops) pfn =min_t (u64, pfn, sd->max_direct_dma_addr >>PAGE_SHIFT );#endif
arch/powerpc/sysdev/fsl_pci.c +1 -1
@@ -118,7 +118,7 @@ static void setup_swiotlb_ops(struct pci_controller *hose) {if (ppc_swiotlb_enable) { hose->controller_ops.dma_dev_setup = pci_dma_dev_setup_swiotlb; -set_pci_dma_ops (&swiotlb_dma_ops); +set_pci_dma_ops (&powerpc_swiotlb_dma_ops); } }#else
Signature · 1 line
2.14.2
PATCH 44/67 powerpc: rename swiotlb_dma_ops
In reply to Christoph HellwigWe'll need that name for a generic implementation soon.
--- arch/powerpc/include/asm/swiotlb.h | 2 +- arch/powerpc/kernel/dma-swiotlb.c | 4 ++-- arch/powerpc/kernel/dma.c | 2 +- arch/powerpc/sysdev/fsl_pci.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/swiotlb.h +1 -1
@@ -13,7 +13,7 @@#include <linux/swiotlb.h> -extern const struct dma_map_ops swiotlb_dma_ops; +extern const struct dma_map_ops powerpc_swiotlb_dma_ops;extern unsigned int ppc_swiotlb_enable;int __init swiotlb_setup_bus_notifier (void );
arch/powerpc/kernel/dma-swiotlb.c +2 -2
@@ -46,7 +46,7 @@ static u64 swiotlb_powerpc_get_required(struct device *dev)* map_page, and unmap_page on highmem, use normal dma_ops * for everything else. */ -const struct dma_map_ops swiotlb_dma_ops = { +const struct dma_map_ops powerpc_swiotlb_dma_ops = { .alloc = __dma_nommu_alloc_coherent, .free = __dma_nommu_free_coherent, .mmap = dma_nommu_mmap_coherent,
@@ -89,7 +89,7 @@ static int ppc_swiotlb_bus_notify(struct notifier_block *nb,/* May need to bounce if the device can't address all of DRAM */ if ((dma_get_mask (dev) +1 ) <memblock_end_of_DRAM ()) -set_dma_ops (dev, &swiotlb_dma_ops); +set_dma_ops (dev, &powerpc_swiotlb_dma_ops);return NOTIFY_DONE ; }
arch/powerpc/kernel/dma.c +1 -1
@@ -33,7 +33,7 @@ static u64 __maybe_unused get_pfn_limit(struct device *dev)struct dev_archdata __maybe_unused *sd = &dev->archdata;#ifdef CONFIG_SWIOTLB -if (sd->max_direct_dma_addr && dev->dma_ops == &swiotlb_dma_ops) +if (sd->max_direct_dma_addr && dev->dma_ops == &powerpc_swiotlb_dma_ops) pfn =min_t (u64, pfn, sd->max_direct_dma_addr >>PAGE_SHIFT );#endif
arch/powerpc/sysdev/fsl_pci.c +1 -1
@@ -118,7 +118,7 @@ static void setup_swiotlb_ops(struct pci_controller *hose) {if (ppc_swiotlb_enable) { hose->controller_ops.dma_dev_setup = pci_dma_dev_setup_swiotlb; -set_pci_dma_ops (&swiotlb_dma_ops); +set_pci_dma_ops (&powerpc_swiotlb_dma_ops); } }#else
Signature · 1 line
2.14.2
PATCH 45/67 swiotlb: rename swiotlb_free to swiotlb_exit
In reply to Christoph Hellwig--- arch/powerpc/kernel/dma-swiotlb.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 2 +- include/linux/swiotlb.h | 4 ++-- lib/swiotlb.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/dma-swiotlb.c +1 -1
@@ -121,7 +121,7 @@ static int __init check_swiotlb_enabled(void)if (ppc_swiotlb_enable)swiotlb_print_info ();else -swiotlb_free (); +swiotlb_exit ();return 0 ; }
arch/x86/kernel/pci-swiotlb.c +1 -1
@@ -119,7 +119,7 @@ void __init pci_swiotlb_late_init(void) {/* An IOMMU turned us off. */ if (!swiotlb) -swiotlb_free (); +swiotlb_exit ();else {printk (KERN_INFO "PCI-DMA: " "Using software bounce buffering for IO (SWIOTLB)\n" );
include/linux/swiotlb.h +2 -2
@@ -115,10 +115,10 @@ extern int swiotlb_dma_supported(struct device *hwdev, u64 mask);#ifdef CONFIG_SWIOTLB -extern void __init swiotlb_free (void ); +extern void __init swiotlb_exit (void );unsigned int swiotlb_max_segment (void );#else -static inline void swiotlb_free (void ) { } +static inline void swiotlb_exit (void ) { }static inline unsigned int swiotlb_max_segment (void ) {return 0 ; }#endif
lib/swiotlb.c +1 -1
@@ -417,7 +417,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)return -ENOMEM ; } -void __init swiotlb_free (void ) +void __init swiotlb_exit (void ) {if (!io_tlb_orig_addr)return ;
Signature · 1 line
2.14.2
PATCH 45/67 swiotlb: rename swiotlb_free to swiotlb_exit
In reply to Christoph Hellwig--- arch/powerpc/kernel/dma-swiotlb.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 2 +- include/linux/swiotlb.h | 4 ++-- lib/swiotlb.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/dma-swiotlb.c +1 -1
@@ -121,7 +121,7 @@ static int __init check_swiotlb_enabled(void)if (ppc_swiotlb_enable)swiotlb_print_info ();else -swiotlb_free (); +swiotlb_exit ();return 0 ; }
arch/x86/kernel/pci-swiotlb.c +1 -1
@@ -119,7 +119,7 @@ void __init pci_swiotlb_late_init(void) {/* An IOMMU turned us off. */ if (!swiotlb) -swiotlb_free (); +swiotlb_exit ();else {printk (KERN_INFO "PCI-DMA: " "Using software bounce buffering for IO (SWIOTLB)\n" );
include/linux/swiotlb.h +2 -2
@@ -115,10 +115,10 @@ extern int swiotlb_dma_supported(struct device *hwdev, u64 mask);#ifdef CONFIG_SWIOTLB -extern void __init swiotlb_free (void ); +extern void __init swiotlb_exit (void );unsigned int swiotlb_max_segment (void );#else -static inline void swiotlb_free (void ) { } +static inline void swiotlb_exit (void ) { }static inline unsigned int swiotlb_max_segment (void ) {return 0 ; }#endif
lib/swiotlb.c +1 -1
@@ -417,7 +417,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)return -ENOMEM ; } -void __init swiotlb_free (void ) +void __init swiotlb_exit (void ) {if (!io_tlb_orig_addr)return ;
Signature · 1 line
2.14.2
PATCH 46/67 swiotlb: lift x86 swiotlb_dma_ops to common code
In reply to Christoph HellwigIncluding the useful helpers for coherent allocations that first try the full blown direct mapping.
--- arch/x86/include/asm/swiotlb.h | 8 -------- arch/x86/kernel/pci-swiotlb.c | 45 ------------------------------------------ arch/x86/pci/sta2x11-fixup.c | 4 ++-- include/linux/swiotlb.h | 8 ++++++++ lib/swiotlb.c | 43 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 55 deletions(-)
arch/x86/include/asm/swiotlb.h +0 -8
@@ -27,12 +27,4 @@ static inline void pci_swiotlb_late_init(void) { }#endif - -extern void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size, -dma_addr_t *dma_handle,gfp_t flags, -unsigned long attrs); -extern void x86_swiotlb_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs); -#endif /* _ASM_X86_SWIOTLB_H */
arch/x86/kernel/pci-swiotlb.c +0 -45
51 lines not on this page · raw message
arch/x86/pci/sta2x11-fixup.c +2 -2
@@ -175,7 +175,7 @@ static void *sta2x11_swiotlb_alloc_coherent(struct device *dev, {void *vaddr; - vaddr =x86_swiotlb_alloc_coherent (dev, size, dma_handle, flags, attrs); + vaddr =swiotlb_alloc (dev, size, dma_handle, flags, attrs); *dma_handle =p2a (*dma_handle,to_pci_dev (dev));return vaddr; }
@@ -183,7 +183,7 @@ static void *sta2x11_swiotlb_alloc_coherent(struct device *dev,/* We have our own dma_ops: the same as swiotlb but from alloc (above) */ static const struct dma_map_ops sta2x11_dma_ops = { .alloc = sta2x11_swiotlb_alloc_coherent, - .free = x86_swiotlb_free_coherent, + .free = swiotlb_free, .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = swiotlb_map_sg_attrs,
include/linux/swiotlb.h +8 -0
@@ -66,6 +66,12 @@ extern void swiotlb_tbl_sync_single(struct device *hwdev, enum dma_sync_target target);/* Accessory functions. */ + +void *swiotlb_alloc (struct device *hwdev,size_t size,dma_addr_t *dma_handle, +gfp_t flags,unsigned long attrs); +void swiotlb_free (struct device *dev,size_t size,void *vaddr, +dma_addr_t dma_addr,unsigned long attrs); +extern void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags);
@@ -126,4 +132,6 @@ extern void swiotlb_print_info(void);extern int is_swiotlb_buffer (phys_addr_t paddr);extern void swiotlb_set_max_segment (unsigned int ); +extern const struct dma_map_ops swiotlb_dma_ops; +#endif /* __LINUX_SWIOTLB_H */
lib/swiotlb.c +43 -0
46 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 47/67 swiotlb: wire up ->dma_supported in swiotlb_dma_ops
In reply to Christoph HellwigTo properly reject too small DMA masks based on the addressability of the bounce buffer.
--- lib/swiotlb.c | 1 + 1 file changed, 1 insertion(+)
lib/swiotlb.c +1 -0
@@ -1125,5 +1125,6 @@ const struct dma_map_ops swiotlb_dma_ops = { .unmap_sg = swiotlb_unmap_sg_attrs, .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, + .dma_supported = swiotlb_dma_supported, };#endif /* CONFIG_DMA_DIRECT_OPS */
Signature · 1 line
2.14.2
PATCH 47/67 swiotlb: wire up ->dma_supported in swiotlb_dma_ops
In reply to Christoph HellwigTo properly reject too small DMA masks based on the addressability of the bounce buffer.
--- lib/swiotlb.c | 1 + 1 file changed, 1 insertion(+)
lib/swiotlb.c +1 -0
@@ -1125,5 +1125,6 @@ const struct dma_map_ops swiotlb_dma_ops = { .unmap_sg = swiotlb_unmap_sg_attrs, .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, + .dma_supported = swiotlb_dma_supported, };#endif /* CONFIG_DMA_DIRECT_OPS */
Signature · 1 line
2.14.2
PATCH 48/67 swiotlb: rely on dev->coherent_dma_mask
In reply to Christoph HellwigThese days the coherent DMA mask is always set, so don't work around the lack of it.
--- lib/swiotlb.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
lib/swiotlb.c +3 -7
@@ -716,15 +716,11 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,dma_addr_t dev_addr;void *ret;int order =get_order (size); -u64 dma_mask =DMA_BIT_MASK (32 ); - -if (hwdev && hwdev->coherent_dma_mask) - dma_mask = hwdev->coherent_dma_mask; ret = (void *)__get_free_pages (flags, order);if (ret) { dev_addr =swiotlb_virt_to_bus (hwdev, ret); -if (dev_addr + size -1 > dma_mask) { +if (dev_addr + size -1 > hwdev->coherent_dma_mask) {/* * The allocated memory isn't reachable by the device. */
@@ -747,9 +743,9 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dev_addr =swiotlb_phys_to_dma (hwdev, paddr);/* Confirm address can be DMA'd by device */ -if (dev_addr + size -1 > dma_mask) { +if (dev_addr + size -1 > hwdev->coherent_dma_mask) {printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , - (unsigned long long )dma_mask, + (unsigned long long )hwdev->coherent_dma_mask, (unsigned long long )dev_addr);/*
Signature · 1 line
2.14.2
PATCH 48/67 swiotlb: rely on dev->coherent_dma_mask
In reply to Christoph HellwigThese days the coherent DMA mask is always set, so don't work around the lack of it.
--- lib/swiotlb.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
lib/swiotlb.c +3 -7
@@ -716,15 +716,11 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,dma_addr_t dev_addr;void *ret;int order =get_order (size); -u64 dma_mask =DMA_BIT_MASK (32 ); - -if (hwdev && hwdev->coherent_dma_mask) - dma_mask = hwdev->coherent_dma_mask; ret = (void *)__get_free_pages (flags, order);if (ret) { dev_addr =swiotlb_virt_to_bus (hwdev, ret); -if (dev_addr + size -1 > dma_mask) { +if (dev_addr + size -1 > hwdev->coherent_dma_mask) {/* * The allocated memory isn't reachable by the device. */
@@ -747,9 +743,9 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dev_addr =swiotlb_phys_to_dma (hwdev, paddr);/* Confirm address can be DMA'd by device */ -if (dev_addr + size -1 > dma_mask) { +if (dev_addr + size -1 > hwdev->coherent_dma_mask) {printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , - (unsigned long long )dma_mask, + (unsigned long long )hwdev->coherent_dma_mask, (unsigned long long )dev_addr);/*
Signature · 1 line
2.14.2
PATCH 49/67 swiotlb: refactor coherent buffer freeing
In reply to Christoph HellwigFactor out a new swiotlb_free_buffer helper that checks if an address is allocated from the swiotlb bounce buffer, and if yes frees it.
This allows to simplify the swiotlb_free implemenation that uses dma_direct_free to free the non-bounce buffer allocations.
--- lib/swiotlb.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
lib/swiotlb.c +21 -14
@@ -773,22 +773,31 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, }EXPORT_SYMBOL (swiotlb_alloc_coherent); +static bool swiotlb_free_buffer (struct device *dev,size_t size, +dma_addr_t dma_addr) +{ +phys_addr_t phys_addr =dma_to_phys (dev, dma_addr); + +WARN_ON_ONCE (irqs_disabled ()); + +if (!is_swiotlb_buffer (phys_addr)) +return false; + +/* +* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single. +* DMA_ATTR_SKIP_CPU_SYNC is optional. +*/ +swiotlb_tbl_unmap_single (dev, phys_addr, size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC ); +return true; +} +void swiotlb_free_coherent (struct device *hwdev,size_t size,void *vaddr,dma_addr_t dev_addr) { -phys_addr_t paddr =dma_to_phys (hwdev, dev_addr); - -WARN_ON (irqs_disabled ()); -if (!is_swiotlb_buffer (paddr)) +if (!swiotlb_free_buffer (hwdev, size, dev_addr))free_pages ((unsigned long )vaddr,get_order (size)); -else -/* -* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single. -* DMA_ATTR_SKIP_CPU_SYNC is optional. -*/ -swiotlb_tbl_unmap_single (hwdev, paddr, size,DMA_TO_DEVICE , -DMA_ATTR_SKIP_CPU_SYNC ); }EXPORT_SYMBOL (swiotlb_free_coherent);
@@ -1103,9 +1112,7 @@ void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,void swiotlb_free (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_addr,unsigned long attrs) { -if (is_swiotlb_buffer (dma_to_phys (dev, dma_addr))) -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -else +if (!swiotlb_free_buffer (dev, size, dma_addr))dma_direct_free (dev, size, vaddr, dma_addr, attrs); }
Signature · 1 line
2.14.2
PATCH 49/67 swiotlb: refactor coherent buffer freeing
In reply to Christoph HellwigFactor out a new swiotlb_free_buffer helper that checks if an address is allocated from the swiotlb bounce buffer, and if yes frees it.
This allows to simplify the swiotlb_free implemenation that uses dma_direct_free to free the non-bounce buffer allocations.
--- lib/swiotlb.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
lib/swiotlb.c +21 -14
@@ -773,22 +773,31 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, }EXPORT_SYMBOL (swiotlb_alloc_coherent); +static bool swiotlb_free_buffer (struct device *dev,size_t size, +dma_addr_t dma_addr) +{ +phys_addr_t phys_addr =dma_to_phys (dev, dma_addr); + +WARN_ON_ONCE (irqs_disabled ()); + +if (!is_swiotlb_buffer (phys_addr)) +return false; + +/* +* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single. +* DMA_ATTR_SKIP_CPU_SYNC is optional. +*/ +swiotlb_tbl_unmap_single (dev, phys_addr, size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC ); +return true; +} +void swiotlb_free_coherent (struct device *hwdev,size_t size,void *vaddr,dma_addr_t dev_addr) { -phys_addr_t paddr =dma_to_phys (hwdev, dev_addr); - -WARN_ON (irqs_disabled ()); -if (!is_swiotlb_buffer (paddr)) +if (!swiotlb_free_buffer (hwdev, size, dev_addr))free_pages ((unsigned long )vaddr,get_order (size)); -else -/* -* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single. -* DMA_ATTR_SKIP_CPU_SYNC is optional. -*/ -swiotlb_tbl_unmap_single (hwdev, paddr, size,DMA_TO_DEVICE , -DMA_ATTR_SKIP_CPU_SYNC ); }EXPORT_SYMBOL (swiotlb_free_coherent);
@@ -1103,9 +1112,7 @@ void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,void swiotlb_free (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_addr,unsigned long attrs) { -if (is_swiotlb_buffer (dma_to_phys (dev, dma_addr))) -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -else +if (!swiotlb_free_buffer (dev, size, dma_addr))dma_direct_free (dev, size, vaddr, dma_addr, attrs); }
Signature · 1 line
2.14.2
PATCH 50/67 swiotlb: refactor coherent buffer allocation
In reply to Christoph HellwigFactor out a new swiotlb_alloc_buffer helper that allocates DMA coherent memory from the swiotlb bounce buffer.
This allows to simplify the swiotlb_alloc implemenation that uses dma_direct_alloc to try to allocate a reachable buffer first.
--- lib/swiotlb.c | 100 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 49 deletions(-)
lib/swiotlb.c +51 -49
@@ -709,67 +709,69 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, }EXPORT_SYMBOL_GPL (swiotlb_tbl_sync_single); +static void * +swiotlb_alloc_buffer (struct device *dev,size_t size,dma_addr_t *dma_handle) +{ +phys_addr_t phys_addr; + +if (swiotlb_force ==SWIOTLB_NO_FORCE ) + goto out_warn; + + phys_addr =swiotlb_tbl_map_single (dev, +swiotlb_phys_to_dma (dev, io_tlb_start), +0 , size,DMA_FROM_DEVICE ,0 ); +if (phys_addr ==SWIOTLB_MAP_ERROR ) + goto out_warn; + + *dma_handle =swiotlb_phys_to_dma (dev, phys_addr); + +/* Confirm address can be DMA'd by device */ +if (*dma_handle + size -1 > dev->coherent_dma_mask) + goto out_unmap; + +memset (phys_to_virt (phys_addr),0 , size); +return phys_to_virt (phys_addr); + +out_unmap: +dev_warn (dev,"hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , + (unsigned long long )dev->coherent_dma_mask, + (unsigned long long )*dma_handle); + +/* +* DMA_TO_DEVICE to avoid memcpy in unmap_single. +* DMA_ATTR_SKIP_CPU_SYNC is optional. +*/ +swiotlb_tbl_unmap_single (dev, phys_addr, size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC ); +out_warn: +dev_warn (dev, +"swiotlb: coherent allocation failed, size=%zu\n" , size); +dump_stack (); +return NULL ; +} +void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) { -dma_addr_t dev_addr; -void *ret;int order =get_order (size); +void *ret; ret = (void *)__get_free_pages (flags, order);if (ret) { - dev_addr =swiotlb_virt_to_bus (hwdev, ret); -if (dev_addr + size -1 > hwdev->coherent_dma_mask) { -/* -* The allocated memory isn't reachable by the device. -*/ -free_pages ((unsigned long ) ret, order); - ret =NULL ; + *dma_handle =swiotlb_virt_to_bus (hwdev, ret); +if (*dma_handle + size -1 <= hwdev->coherent_dma_mask) { +memset (ret,0 , size); +return ret; } - } -if (!ret) { +/* -* We are either out of memory or the device can't DMA to -* GFP_DMA memory; fall back on map_single(), which -* will grab memory from the lowest available address range. +* The allocated memory isn't reachable by the device. */ -phys_addr_t paddr =map_single (hwdev,0 , size, -DMA_FROM_DEVICE ,0 ); -if (paddr ==SWIOTLB_MAP_ERROR ) - goto err_warn; - - ret =phys_to_virt (paddr); - dev_addr =swiotlb_phys_to_dma (hwdev, paddr); - -/* Confirm address can be DMA'd by device */ -if (dev_addr + size -1 > hwdev->coherent_dma_mask) { -printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , - (unsigned long long )hwdev->coherent_dma_mask, - (unsigned long long )dev_addr); - -/* -* DMA_TO_DEVICE to avoid memcpy in unmap_single. -* The DMA_ATTR_SKIP_CPU_SYNC is optional. -*/ -swiotlb_tbl_unmap_single (hwdev, paddr, - size,DMA_TO_DEVICE , -DMA_ATTR_SKIP_CPU_SYNC ); - goto err_warn; - } +free_pages ((unsigned long ) ret, order); } - *dma_handle = dev_addr; -memset (ret,0 , size); - -return ret; - -err_warn: -pr_warn ("swiotlb: coherent allocation failed for device %s size=%zu\n" , -dev_name (hwdev), size); -dump_stack (); - -return NULL ; +return swiotlb_alloc_buffer (hwdev, size, dma_handle); }EXPORT_SYMBOL (swiotlb_alloc_coherent);
@@ -1105,7 +1107,7 @@ void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, vaddr =dma_direct_alloc (dev, size, dma_handle, gfp, attrs);if (!vaddr) - vaddr =swiotlb_alloc_coherent (dev, size, dma_handle, gfp); + vaddr =swiotlb_alloc_buffer (dev, size, dma_handle);return vaddr; }
Signature · 1 line
2.14.2
PATCH 50/67 swiotlb: refactor coherent buffer allocation
In reply to Christoph HellwigFactor out a new swiotlb_alloc_buffer helper that allocates DMA coherent memory from the swiotlb bounce buffer.
This allows to simplify the swiotlb_alloc implemenation that uses dma_direct_alloc to try to allocate a reachable buffer first.
--- lib/swiotlb.c | 100 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 49 deletions(-)
lib/swiotlb.c +51 -49
@@ -709,67 +709,69 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, }EXPORT_SYMBOL_GPL (swiotlb_tbl_sync_single); +static void * +swiotlb_alloc_buffer (struct device *dev,size_t size,dma_addr_t *dma_handle) +{ +phys_addr_t phys_addr; + +if (swiotlb_force ==SWIOTLB_NO_FORCE ) + goto out_warn; + + phys_addr =swiotlb_tbl_map_single (dev, +swiotlb_phys_to_dma (dev, io_tlb_start), +0 , size,DMA_FROM_DEVICE ,0 ); +if (phys_addr ==SWIOTLB_MAP_ERROR ) + goto out_warn; + + *dma_handle =swiotlb_phys_to_dma (dev, phys_addr); + +/* Confirm address can be DMA'd by device */ +if (*dma_handle + size -1 > dev->coherent_dma_mask) + goto out_unmap; + +memset (phys_to_virt (phys_addr),0 , size); +return phys_to_virt (phys_addr); + +out_unmap: +dev_warn (dev,"hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , + (unsigned long long )dev->coherent_dma_mask, + (unsigned long long )*dma_handle); + +/* +* DMA_TO_DEVICE to avoid memcpy in unmap_single. +* DMA_ATTR_SKIP_CPU_SYNC is optional. +*/ +swiotlb_tbl_unmap_single (dev, phys_addr, size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC ); +out_warn: +dev_warn (dev, +"swiotlb: coherent allocation failed, size=%zu\n" , size); +dump_stack (); +return NULL ; +} +void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) { -dma_addr_t dev_addr; -void *ret;int order =get_order (size); +void *ret; ret = (void *)__get_free_pages (flags, order);if (ret) { - dev_addr =swiotlb_virt_to_bus (hwdev, ret); -if (dev_addr + size -1 > hwdev->coherent_dma_mask) { -/* -* The allocated memory isn't reachable by the device. -*/ -free_pages ((unsigned long ) ret, order); - ret =NULL ; + *dma_handle =swiotlb_virt_to_bus (hwdev, ret); +if (*dma_handle + size -1 <= hwdev->coherent_dma_mask) { +memset (ret,0 , size); +return ret; } - } -if (!ret) { +/* -* We are either out of memory or the device can't DMA to -* GFP_DMA memory; fall back on map_single(), which -* will grab memory from the lowest available address range. +* The allocated memory isn't reachable by the device. */ -phys_addr_t paddr =map_single (hwdev,0 , size, -DMA_FROM_DEVICE ,0 ); -if (paddr ==SWIOTLB_MAP_ERROR ) - goto err_warn; - - ret =phys_to_virt (paddr); - dev_addr =swiotlb_phys_to_dma (hwdev, paddr); - -/* Confirm address can be DMA'd by device */ -if (dev_addr + size -1 > hwdev->coherent_dma_mask) { -printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , - (unsigned long long )hwdev->coherent_dma_mask, - (unsigned long long )dev_addr); - -/* -* DMA_TO_DEVICE to avoid memcpy in unmap_single. -* The DMA_ATTR_SKIP_CPU_SYNC is optional. -*/ -swiotlb_tbl_unmap_single (hwdev, paddr, - size,DMA_TO_DEVICE , -DMA_ATTR_SKIP_CPU_SYNC ); - goto err_warn; - } +free_pages ((unsigned long ) ret, order); } - *dma_handle = dev_addr; -memset (ret,0 , size); - -return ret; - -err_warn: -pr_warn ("swiotlb: coherent allocation failed for device %s size=%zu\n" , -dev_name (hwdev), size); -dump_stack (); - -return NULL ; +return swiotlb_alloc_buffer (hwdev, size, dma_handle); }EXPORT_SYMBOL (swiotlb_alloc_coherent);
@@ -1105,7 +1107,7 @@ void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, vaddr =dma_direct_alloc (dev, size, dma_handle, gfp, attrs);if (!vaddr) - vaddr =swiotlb_alloc_coherent (dev, size, dma_handle, gfp); + vaddr =swiotlb_alloc_buffer (dev, size, dma_handle);return vaddr; }
Signature · 1 line
2.14.2
PATCH 51/67 set_memory.h: provide set_memory_{en,de}crypted stubs
In reply to Christoph Hellwig--- include/linux/set_memory.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/set_memory.h +12 -0
@@ -17,4 +17,16 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; }#endif +#ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT +static inline int set_memory_encrypted (unsigned long addr,int numpages) +{ +return 0 ; +} + +static inline int set_memory_decrypted (unsigned long addr,int numpages) +{ +return 0 ; +} +#endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */ +#endif /* _LINUX_SET_MEMORY_H_ */
Signature · 1 line
2.14.2
PATCH 51/67 set_memory.h: provide set_memory_{en,de}crypted stubs
In reply to Christoph Hellwig--- include/linux/set_memory.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/set_memory.h +12 -0
@@ -17,4 +17,16 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; }#endif +#ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT +static inline int set_memory_encrypted (unsigned long addr,int numpages) +{ +return 0 ; +} + +static inline int set_memory_decrypted (unsigned long addr,int numpages) +{ +return 0 ; +} +#endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */ +#endif /* _LINUX_SET_MEMORY_H_ */
Signature · 1 line
2.14.2
PATCH 52/67 dma-direct: handle the memory encryption bit in common code
In reply to Christoph HellwigGÑ–ve the basic phys_to_dma and dma_to_phys helpers a __-prefix and add the memory encryption mask to the non-prefixed versions. Use the __-prefixed versions directly instead of clearing the mask again in various places.
With that in place the generic dma-direct routines can be used to allocate non-encrypted bounce buffers, and the x86 SEV case can use the generic swiotlb ops.
--- arch/arm/include/asm/dma-direct.h | 4 +- arch/mips/cavium-octeon/dma-octeon.c | 10 +-- .../include/asm/mach-cavium-octeon/dma-coherence.h | 4 +- .../include/asm/mach-loongson64/dma-coherence.h | 10 +-- arch/mips/loongson64/common/dma-swiotlb.c | 4 +- arch/powerpc/include/asm/dma-direct.h | 4 +- arch/x86/Kconfig | 2 +- arch/x86/include/asm/dma-direct.h | 25 +------- arch/x86/mm/mem_encrypt.c | 73 +--------------------- arch/x86/pci/sta2x11-fixup.c | 6 +- include/linux/dma-direct.h | 23 ++++++- lib/dma-direct.c | 24 +++++-- lib/swiotlb.c | 25 +++----- 13 files changed, 76 insertions(+), 138 deletions(-)
arch/arm/include/asm/dma-direct.h +2 -2
@@ -2,13 +2,13 @@#ifndef ASM_ARM_DMA_DIRECT_H #define ASM_ARM_DMA_DIRECT_H 1 -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {unsigned int offset = paddr & ~PAGE_MASK ;return pfn_to_dma (dev,__phys_to_pfn (paddr)) + offset; } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t dev_addr) {unsigned int offset = dev_addr & ~PAGE_MASK ;return __pfn_to_phys (dma_to_pfn (dev, dev_addr)) + offset;
arch/mips/cavium-octeon/dma-octeon.c +5 -5
@@ -10,7 +10,7 @@* IP32 changes by Ilya. * Copyright (C) 2010 Cavium Networks, Inc. */ -#include <linux/dma-mapping.h> +#include <linux/dma-direct.h> #include <linux/scatterlist.h> #include <linux/bootmem.h> #include <linux/export.h>
@@ -202,7 +202,7 @@ struct octeon_dma_map_ops {phys_addr_t (*dma_to_phys)(struct device *dev,dma_addr_t daddr); }; -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) { struct octeon_dma_map_ops *ops = container_of(get_dma_ops(dev), struct octeon_dma_map_ops,
@@ -210,9 +210,9 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)return ops->phys_to_dma (dev, paddr); } -EXPORT_SYMBOL (phys_to_dma); +EXPORT_SYMBOL (__phys_to_dma); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) { struct octeon_dma_map_ops *ops = container_of(get_dma_ops(dev), struct octeon_dma_map_ops,
@@ -220,7 +220,7 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)return ops->dma_to_phys (dev, daddr); } -EXPORT_SYMBOL (dma_to_phys); +EXPORT_SYMBOL (__dma_to_phys);static struct octeon_dma_map_ops octeon_linear_dma_map_ops = { .dma_map_ops = {
arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h +2 -2
@@ -69,8 +69,8 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size <= *dev->dma_mask; } -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr);struct dma_map_ops ;extern const struct dma_map_ops *octeon_pci_dma_map_ops;
arch/mips/include/asm/mach-loongson64/dma-coherence.h +5 -5
@@ -25,13 +25,13 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size <= *dev->dma_mask; } -extern dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -extern phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); +extern dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +extern phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr);static inline dma_addr_t plat_map_dma_mem (struct device *dev,void *addr,size_t size) {#ifdef CONFIG_CPU_LOONGSON3 -return phys_to_dma (dev,virt_to_phys (addr)); +return __phys_to_dma (dev,virt_to_phys (addr));#else return virt_to_phys (addr) |0x80000000 ;#endif
@@ -41,7 +41,7 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page) {#ifdef CONFIG_CPU_LOONGSON3 -return phys_to_dma (dev,page_to_phys (page)); +return __phys_to_dma (dev,page_to_phys (page));#else return page_to_phys (page) |0x80000000 ;#endif
@@ -51,7 +51,7 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev, dma_addr_t dma_addr) {#if defined(CONFIG_CPU_LOONGSON3 ) && defined(CONFIG_64BIT ) -return dma_to_phys (dev, dma_addr); +return __dma_to_phys (dev, dma_addr);#elif defined(CONFIG_CPU_LOONGSON2F ) && defined(CONFIG_64BIT )return (dma_addr >0x8fffffff ) ? dma_addr : (dma_addr &0x0fffffff );#else
arch/mips/loongson64/common/dma-swiotlb.c +2 -2
@@ -80,7 +80,7 @@ static int loongson_dma_supported(struct device *dev, u64 mask)return swiotlb_dma_supported (dev, mask); } -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {long nid;#ifdef CONFIG_PHYS48_TO_HT40
@@ -92,7 +92,7 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)return paddr; } -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {long nid;#ifdef CONFIG_PHYS48_TO_HT40
arch/powerpc/include/asm/dma-direct.h +2 -2
@@ -17,12 +17,12 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size -1 <= *dev->dma_mask; } -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {return paddr +get_dma_offset (dev); } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {return daddr -get_dma_offset (dev); }
arch/x86/Kconfig +1 -1
@@ -54,7 +54,6 @@ config X86 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64 - select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_PMEM_API if X86_64 # Causing hangs/crashes, see the commit that added this change for details. select ARCH_HAS_REFCOUNT
@@ -675,6 +674,7 @@ config X86_SUPPORTS_MEMORY_FAILURE config STA2X11 bool "STA2X11 Companion Chip Support" depends on X86_32_NON_STANDARD && PCI + select ARCH_HAS_PHYS_TO_DMA select X86_DEV_DMA_OPS select X86_DMA_REMAP select SWIOTLB
arch/x86/include/asm/dma-direct.h +2 -23
@@ -2,29 +2,8 @@#ifndef ASM_X86_DMA_DIRECT_H #define ASM_X86_DMA_DIRECT_H 1 -#include <linux/mem_encrypt.h> - -#ifdef CONFIG_X86_DMA_REMAP /* Platform code defines bridge-specific code */ bool dma_capable (struct device *dev,dma_addr_t addr,size_t size); -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); -#else -static inline bool dma_capable (struct device *dev,dma_addr_t addr,size_t size) -{ -if (!dev->dma_mask) -return 0 ; - -return addr + size -1 <= *dev->dma_mask; -} - -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) -{ -return __sme_set (paddr); -} +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr); -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) -{ -return __sme_clr (daddr); -} -#endif /* CONFIG_X86_DMA_REMAP */ #endif /* ASM_X86_DMA_DIRECT_H */
arch/x86/mm/mem_encrypt.c +3 -70
93 lines not on this page · raw message
arch/x86/pci/sta2x11-fixup.c +3 -3
@@ -243,11 +243,11 @@ bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) }/** -* phys_to_dma - Return the DMA AMBA address used for this STA2x11 device +* __phys_to_dma - Return the DMA AMBA address used for this STA2x11 device * @dev: device for a PCI device * @paddr: Physical address */ -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {if (dev->dma_ops != &sta2x11_dma_ops)return paddr;
@@ -259,7 +259,7 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)* @dev: device for a PCI device * @daddr: STA2x11 AMBA DMA address */ -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {if (dev->dma_ops != &sta2x11_dma_ops)return daddr;
include/linux/dma-direct.h +21 -2
@@ -3,18 +3,19 @@#define _LINUX_DMA_DIRECT_H 1#include <linux/dma-mapping.h> +#include <linux/mem_encrypt.h> #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA #include <asm/dma-direct.h> #else -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {dma_addr_t dev_addr = (dma_addr_t )paddr;return dev_addr - ((dma_addr_t )dev->dma_pfn_offset <<PAGE_SHIFT ); } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t dev_addr) {phys_addr_t paddr = (phys_addr_t )dev_addr;
@@ -30,6 +31,24 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) }#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */ +/* +* If memory encryptition is supported, phys_to_dma will set the memory +* encryption bit in the DMA address, and dma_to_phys will clear it. +* The raw __phys_to_dma and __dma_to_phys should only be used on +* non-encrypted memory for special occasions like DMA coherent buffers. +*/ +static __always_inline dma_addr_t phys_to_dma(struct device *dev, +phys_addr_t paddr) +{ +return __sme_set (__phys_to_dma (dev, paddr)); +} + +static __always_inline phys_addr_t dma_to_phys(struct device *dev, +dma_addr_t daddr) +{ +return __sme_clr (__dma_to_phys (dev, daddr)); +} +#ifdef CONFIG_ARCH_HAS_DMA_MARK_CLEAN void dma_mark_clean (void *addr,size_t size);#else
lib/dma-direct.c +19 -5
@@ -9,6 +9,7 @@#include <linux/scatterlist.h> #include <linux/dma-contiguous.h> #include <linux/pfn.h> +#include <linux/set_memory.h> #define DIRECT_MAPPING_ERROR 0
@@ -36,9 +37,13 @@ check_addr(struct device *dev, dma_addr_t dma_addr, size_t size,return true; } +/* +* Since we will be clearing the encryption bit, check the mask with it already +* cleared. +*/ static bool dma_coherent_ok (struct device *dev,phys_addr_t phys,size_t size) { -return phys_to_dma (dev, phys) + size <= dev->coherent_dma_mask; +return __phys_to_dma (dev, phys) + size <= dev->coherent_dma_mask; } void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
@@ -47,6 +52,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,unsigned int count =PAGE_ALIGN (size) >>PAGE_SHIFT ;int page_order =get_order (size);struct page *page =NULL ; +void *ret;/* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */ if (dev->coherent_dma_mask <DMA_BIT_MASK (32 ))
@@ -79,19 +85,27 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,if (!page)return NULL ; + *dma_handle =__phys_to_dma (dev,page_to_phys (page)); + ret =page_address (page); - *dma_handle =phys_to_dma (dev,page_to_phys (page)); -memset (page_address (page),0 , size); -return page_address (page); +/* Clear the memory encryption bit */ +set_memory_decrypted ((unsigned long )ret, page_order); + +memset (ret,0 , size); +return ret; }void dma_direct_free (struct device *dev,size_t size,void *cpu_addr,dma_addr_t dma_addr,unsigned long attrs) {unsigned int count =PAGE_ALIGN (size) >>PAGE_SHIFT ; +unsigned int page_order =get_order (size); + +/* Set the SME encryption bit for re-use */ +set_memory_encrypted ((unsigned long )cpu_addr,1 << page_order);if (!dma_release_from_contiguous (dev,virt_to_page (cpu_addr), count)) -free_pages ((unsigned long )cpu_addr,get_order (size)); +free_pages ((unsigned long )cpu_addr, page_order); } static dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
lib/swiotlb.c +9 -16
@@ -158,13 +158,6 @@ unsigned long swiotlb_size_or_default(void)void __weak swiotlb_set_mem_attributes (void *vaddr,unsigned long size) { } -/* For swiotlb, clear memory encryption mask from dma addresses */ -static dma_addr_t swiotlb_phys_to_dma (struct device *hwdev, -phys_addr_t address) -{ -return __sme_clr (phys_to_dma (hwdev, address)); -} -/* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address)
@@ -623,7 +616,7 @@ map_single(struct device *hwdev, phys_addr_t phys, size_t size,return SWIOTLB_MAP_ERROR ; } - start_dma_addr =swiotlb_phys_to_dma (hwdev, io_tlb_start); + start_dma_addr =__phys_to_dma (hwdev, io_tlb_start);return swiotlb_tbl_map_single (hwdev, start_dma_addr, phys, size, dir, attrs); }
@@ -718,12 +711,12 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle) goto out_warn; phys_addr =swiotlb_tbl_map_single (dev, -swiotlb_phys_to_dma (dev, io_tlb_start), +__phys_to_dma (dev, io_tlb_start),0 , size,DMA_FROM_DEVICE ,0 );if (phys_addr ==SWIOTLB_MAP_ERROR ) goto out_warn; - *dma_handle =swiotlb_phys_to_dma (dev, phys_addr); + *dma_handle =__phys_to_dma (dev, phys_addr);/* Confirm address can be DMA'd by device */ if (*dma_handle + size -1 > dev->coherent_dma_mask)
@@ -861,10 +854,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, map =map_single (dev, phys, size, dir, attrs);if (map ==SWIOTLB_MAP_ERROR ) {swiotlb_full (dev, size, dir,1 ); -return swiotlb_phys_to_dma (dev, io_tlb_overflow_buffer); +return __phys_to_dma (dev, io_tlb_overflow_buffer); } - dev_addr =swiotlb_phys_to_dma (dev, map); + dev_addr =__phys_to_dma (dev, map);/* Ensure that the address returned is DMA'ble */ if (dma_capable (dev, dev_addr, size))
@@ -873,7 +866,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, attrs |=DMA_ATTR_SKIP_CPU_SYNC ;swiotlb_tbl_unmap_single (dev, map, size, dir, attrs); -return swiotlb_phys_to_dma (dev, io_tlb_overflow_buffer); +return __phys_to_dma (dev, io_tlb_overflow_buffer); }EXPORT_SYMBOL_GPL (swiotlb_map_page);
@@ -1007,7 +1000,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,sg_dma_len (sgl) =0 ;return 0 ; } - sg->dma_address =swiotlb_phys_to_dma (hwdev, map); + sg->dma_address =__phys_to_dma (hwdev, map); }else sg->dma_address = dev_addr;sg_dma_len (sg) = sg->length;
@@ -1075,7 +1068,7 @@ EXPORT_SYMBOL(swiotlb_sync_sg_for_device);int swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr) { -return (dma_addr ==swiotlb_phys_to_dma (hwdev, io_tlb_overflow_buffer)); +return (dma_addr ==__phys_to_dma (hwdev, io_tlb_overflow_buffer)); }EXPORT_SYMBOL (swiotlb_dma_mapping_error);
@@ -1088,7 +1081,7 @@ EXPORT_SYMBOL(swiotlb_dma_mapping_error);int swiotlb_dma_supported (struct device *hwdev,u64 mask) { -return swiotlb_phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; +return __phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; }EXPORT_SYMBOL (swiotlb_dma_supported);
Signature · 1 line
2.14.2
PATCH 52/67 dma-direct: handle the memory encryption bit in common code
In reply to Christoph HellwigGіve the basic phys_to_dma and dma_to_phys helpers a __-prefix and add the memory encryption mask to the non-prefixed versions. Use the __-prefixed versions directly instead of clearing the mask again in various places.
With that in place the generic dma-direct routines can be used to allocate non-encrypted bounce buffers, and the x86 SEV case can use the generic swiotlb ops.
--- arch/arm/include/asm/dma-direct.h | 4 +- arch/mips/cavium-octeon/dma-octeon.c | 10 +-- .../include/asm/mach-cavium-octeon/dma-coherence.h | 4 +- .../include/asm/mach-loongson64/dma-coherence.h | 10 +-- arch/mips/loongson64/common/dma-swiotlb.c | 4 +- arch/powerpc/include/asm/dma-direct.h | 4 +- arch/x86/Kconfig | 2 +- arch/x86/include/asm/dma-direct.h | 25 +------- arch/x86/mm/mem_encrypt.c | 73 +--------------------- arch/x86/pci/sta2x11-fixup.c | 6 +- include/linux/dma-direct.h | 23 ++++++- lib/dma-direct.c | 24 +++++-- lib/swiotlb.c | 25 +++----- 13 files changed, 76 insertions(+), 138 deletions(-)
arch/arm/include/asm/dma-direct.h +2 -2
@@ -2,13 +2,13 @@#ifndef ASM_ARM_DMA_DIRECT_H #define ASM_ARM_DMA_DIRECT_H 1 -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {unsigned int offset = paddr & ~PAGE_MASK ;return pfn_to_dma (dev,__phys_to_pfn (paddr)) + offset; } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t dev_addr) {unsigned int offset = dev_addr & ~PAGE_MASK ;return __pfn_to_phys (dma_to_pfn (dev, dev_addr)) + offset;
arch/mips/cavium-octeon/dma-octeon.c +5 -5
@@ -10,7 +10,7 @@* IP32 changes by Ilya. * Copyright (C) 2010 Cavium Networks, Inc. */ -#include <linux/dma-mapping.h> +#include <linux/dma-direct.h> #include <linux/scatterlist.h> #include <linux/bootmem.h> #include <linux/export.h>
@@ -202,7 +202,7 @@ struct octeon_dma_map_ops {phys_addr_t (*dma_to_phys)(struct device *dev,dma_addr_t daddr); }; -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) { struct octeon_dma_map_ops *ops = container_of(get_dma_ops(dev), struct octeon_dma_map_ops,
@@ -210,9 +210,9 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)return ops->phys_to_dma (dev, paddr); } -EXPORT_SYMBOL (phys_to_dma); +EXPORT_SYMBOL (__phys_to_dma); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) { struct octeon_dma_map_ops *ops = container_of(get_dma_ops(dev), struct octeon_dma_map_ops,
@@ -220,7 +220,7 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)return ops->dma_to_phys (dev, daddr); } -EXPORT_SYMBOL (dma_to_phys); +EXPORT_SYMBOL (__dma_to_phys);static struct octeon_dma_map_ops octeon_linear_dma_map_ops = { .dma_map_ops = {
arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h +2 -2
@@ -69,8 +69,8 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size <= *dev->dma_mask; } -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr);struct dma_map_ops ;extern const struct dma_map_ops *octeon_pci_dma_map_ops;
arch/mips/include/asm/mach-loongson64/dma-coherence.h +5 -5
@@ -25,13 +25,13 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size <= *dev->dma_mask; } -extern dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -extern phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); +extern dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +extern phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr);static inline dma_addr_t plat_map_dma_mem (struct device *dev,void *addr,size_t size) {#ifdef CONFIG_CPU_LOONGSON3 -return phys_to_dma (dev,virt_to_phys (addr)); +return __phys_to_dma (dev,virt_to_phys (addr));#else return virt_to_phys (addr) |0x80000000 ;#endif
@@ -41,7 +41,7 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page) {#ifdef CONFIG_CPU_LOONGSON3 -return phys_to_dma (dev,page_to_phys (page)); +return __phys_to_dma (dev,page_to_phys (page));#else return page_to_phys (page) |0x80000000 ;#endif
@@ -51,7 +51,7 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev, dma_addr_t dma_addr) {#if defined(CONFIG_CPU_LOONGSON3 ) && defined(CONFIG_64BIT ) -return dma_to_phys (dev, dma_addr); +return __dma_to_phys (dev, dma_addr);#elif defined(CONFIG_CPU_LOONGSON2F ) && defined(CONFIG_64BIT )return (dma_addr >0x8fffffff ) ? dma_addr : (dma_addr &0x0fffffff );#else
arch/mips/loongson64/common/dma-swiotlb.c +2 -2
@@ -80,7 +80,7 @@ static int loongson_dma_supported(struct device *dev, u64 mask)return swiotlb_dma_supported (dev, mask); } -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {long nid;#ifdef CONFIG_PHYS48_TO_HT40
@@ -92,7 +92,7 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)return paddr; } -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {long nid;#ifdef CONFIG_PHYS48_TO_HT40
arch/powerpc/include/asm/dma-direct.h +2 -2
@@ -17,12 +17,12 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)return addr + size -1 <= *dev->dma_mask; } -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {return paddr +get_dma_offset (dev); } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {return daddr -get_dma_offset (dev); }
arch/x86/Kconfig +1 -1
@@ -54,7 +54,6 @@ config X86 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64 - select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_PMEM_API if X86_64 # Causing hangs/crashes, see the commit that added this change for details. select ARCH_HAS_REFCOUNT
@@ -675,6 +674,7 @@ config X86_SUPPORTS_MEMORY_FAILURE config STA2X11 bool "STA2X11 Companion Chip Support" depends on X86_32_NON_STANDARD && PCI + select ARCH_HAS_PHYS_TO_DMA select X86_DEV_DMA_OPS select X86_DMA_REMAP select SWIOTLB
arch/x86/include/asm/dma-direct.h +2 -23
@@ -2,29 +2,8 @@#ifndef ASM_X86_DMA_DIRECT_H #define ASM_X86_DMA_DIRECT_H 1 -#include <linux/mem_encrypt.h> - -#ifdef CONFIG_X86_DMA_REMAP /* Platform code defines bridge-specific code */ bool dma_capable (struct device *dev,dma_addr_t addr,size_t size); -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr); -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr); -#else -static inline bool dma_capable (struct device *dev,dma_addr_t addr,size_t size) -{ -if (!dev->dma_mask) -return 0 ; - -return addr + size -1 <= *dev->dma_mask; -} - -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) -{ -return __sme_set (paddr); -} +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr); +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr); -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) -{ -return __sme_clr (daddr); -} -#endif /* CONFIG_X86_DMA_REMAP */ #endif /* ASM_X86_DMA_DIRECT_H */
arch/x86/mm/mem_encrypt.c +3 -70
93 lines not on this page · raw message
arch/x86/pci/sta2x11-fixup.c +3 -3
@@ -243,11 +243,11 @@ bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) }/** -* phys_to_dma - Return the DMA AMBA address used for this STA2x11 device +* __phys_to_dma - Return the DMA AMBA address used for this STA2x11 device * @dev: device for a PCI device * @paddr: Physical address */ -dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {if (dev->dma_ops != &sta2x11_dma_ops)return paddr;
@@ -259,7 +259,7 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)* @dev: device for a PCI device * @daddr: STA2x11 AMBA DMA address */ -phys_addr_t dma_to_phys (struct device *dev,dma_addr_t daddr) +phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t daddr) {if (dev->dma_ops != &sta2x11_dma_ops)return daddr;
include/linux/dma-direct.h +21 -2
@@ -3,18 +3,19 @@#define _LINUX_DMA_DIRECT_H 1#include <linux/dma-mapping.h> +#include <linux/mem_encrypt.h> #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA #include <asm/dma-direct.h> #else -static inline dma_addr_t phys_to_dma (struct device *dev,phys_addr_t paddr) +static inline dma_addr_t __phys_to_dma (struct device *dev,phys_addr_t paddr) {dma_addr_t dev_addr = (dma_addr_t )paddr;return dev_addr - ((dma_addr_t )dev->dma_pfn_offset <<PAGE_SHIFT ); } -static inline phys_addr_t dma_to_phys (struct device *dev,dma_addr_t dev_addr) +static inline phys_addr_t __dma_to_phys (struct device *dev,dma_addr_t dev_addr) {phys_addr_t paddr = (phys_addr_t )dev_addr;
@@ -30,6 +31,24 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) }#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */ +/* +* If memory encryptition is supported, phys_to_dma will set the memory +* encryption bit in the DMA address, and dma_to_phys will clear it. +* The raw __phys_to_dma and __dma_to_phys should only be used on +* non-encrypted memory for special occasions like DMA coherent buffers. +*/ +static __always_inline dma_addr_t phys_to_dma(struct device *dev, +phys_addr_t paddr) +{ +return __sme_set (__phys_to_dma (dev, paddr)); +} + +static __always_inline phys_addr_t dma_to_phys(struct device *dev, +dma_addr_t daddr) +{ +return __sme_clr (__dma_to_phys (dev, daddr)); +} +#ifdef CONFIG_ARCH_HAS_DMA_MARK_CLEAN void dma_mark_clean (void *addr,size_t size);#else
lib/dma-direct.c +19 -5
@@ -9,6 +9,7 @@#include <linux/scatterlist.h> #include <linux/dma-contiguous.h> #include <linux/pfn.h> +#include <linux/set_memory.h> #define DIRECT_MAPPING_ERROR 0
@@ -36,9 +37,13 @@ check_addr(struct device *dev, dma_addr_t dma_addr, size_t size,return true; } +/* +* Since we will be clearing the encryption bit, check the mask with it already +* cleared. +*/ static bool dma_coherent_ok (struct device *dev,phys_addr_t phys,size_t size) { -return phys_to_dma (dev, phys) + size <= dev->coherent_dma_mask; +return __phys_to_dma (dev, phys) + size <= dev->coherent_dma_mask; } void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
@@ -47,6 +52,7 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,unsigned int count =PAGE_ALIGN (size) >>PAGE_SHIFT ;int page_order =get_order (size);struct page *page =NULL ; +void *ret;/* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */ if (dev->coherent_dma_mask <DMA_BIT_MASK (32 ))
@@ -79,19 +85,27 @@ void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,if (!page)return NULL ; + *dma_handle =__phys_to_dma (dev,page_to_phys (page)); + ret =page_address (page); - *dma_handle =phys_to_dma (dev,page_to_phys (page)); -memset (page_address (page),0 , size); -return page_address (page); +/* Clear the memory encryption bit */ +set_memory_decrypted ((unsigned long )ret, page_order); + +memset (ret,0 , size); +return ret; }void dma_direct_free (struct device *dev,size_t size,void *cpu_addr,dma_addr_t dma_addr,unsigned long attrs) {unsigned int count =PAGE_ALIGN (size) >>PAGE_SHIFT ; +unsigned int page_order =get_order (size); + +/* Set the SME encryption bit for re-use */ +set_memory_encrypted ((unsigned long )cpu_addr,1 << page_order);if (!dma_release_from_contiguous (dev,virt_to_page (cpu_addr), count)) -free_pages ((unsigned long )cpu_addr,get_order (size)); +free_pages ((unsigned long )cpu_addr, page_order); } static dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
lib/swiotlb.c +9 -16
@@ -158,13 +158,6 @@ unsigned long swiotlb_size_or_default(void)void __weak swiotlb_set_mem_attributes (void *vaddr,unsigned long size) { } -/* For swiotlb, clear memory encryption mask from dma addresses */ -static dma_addr_t swiotlb_phys_to_dma (struct device *hwdev, -phys_addr_t address) -{ -return __sme_clr (phys_to_dma (hwdev, address)); -} -/* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address)
@@ -623,7 +616,7 @@ map_single(struct device *hwdev, phys_addr_t phys, size_t size,return SWIOTLB_MAP_ERROR ; } - start_dma_addr =swiotlb_phys_to_dma (hwdev, io_tlb_start); + start_dma_addr =__phys_to_dma (hwdev, io_tlb_start);return swiotlb_tbl_map_single (hwdev, start_dma_addr, phys, size, dir, attrs); }
@@ -718,12 +711,12 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle) goto out_warn; phys_addr =swiotlb_tbl_map_single (dev, -swiotlb_phys_to_dma (dev, io_tlb_start), +__phys_to_dma (dev, io_tlb_start),0 , size,DMA_FROM_DEVICE ,0 );if (phys_addr ==SWIOTLB_MAP_ERROR ) goto out_warn; - *dma_handle =swiotlb_phys_to_dma (dev, phys_addr); + *dma_handle =__phys_to_dma (dev, phys_addr);/* Confirm address can be DMA'd by device */ if (*dma_handle + size -1 > dev->coherent_dma_mask)
@@ -861,10 +854,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, map =map_single (dev, phys, size, dir, attrs);if (map ==SWIOTLB_MAP_ERROR ) {swiotlb_full (dev, size, dir,1 ); -return swiotlb_phys_to_dma (dev, io_tlb_overflow_buffer); +return __phys_to_dma (dev, io_tlb_overflow_buffer); } - dev_addr =swiotlb_phys_to_dma (dev, map); + dev_addr =__phys_to_dma (dev, map);/* Ensure that the address returned is DMA'ble */ if (dma_capable (dev, dev_addr, size))
@@ -873,7 +866,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, attrs |=DMA_ATTR_SKIP_CPU_SYNC ;swiotlb_tbl_unmap_single (dev, map, size, dir, attrs); -return swiotlb_phys_to_dma (dev, io_tlb_overflow_buffer); +return __phys_to_dma (dev, io_tlb_overflow_buffer); }EXPORT_SYMBOL_GPL (swiotlb_map_page);
@@ -1007,7 +1000,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,sg_dma_len (sgl) =0 ;return 0 ; } - sg->dma_address =swiotlb_phys_to_dma (hwdev, map); + sg->dma_address =__phys_to_dma (hwdev, map); }else sg->dma_address = dev_addr;sg_dma_len (sg) = sg->length;
@@ -1075,7 +1068,7 @@ EXPORT_SYMBOL(swiotlb_sync_sg_for_device);int swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr) { -return (dma_addr ==swiotlb_phys_to_dma (hwdev, io_tlb_overflow_buffer)); +return (dma_addr ==__phys_to_dma (hwdev, io_tlb_overflow_buffer)); }EXPORT_SYMBOL (swiotlb_dma_mapping_error);
@@ -1088,7 +1081,7 @@ EXPORT_SYMBOL(swiotlb_dma_mapping_error);int swiotlb_dma_supported (struct device *hwdev,u64 mask) { -return swiotlb_phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; +return __phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; }EXPORT_SYMBOL (swiotlb_dma_supported);
Signature · 1 line
2.14.2
PATCH 53/67 swiotlb: remove swiotlb_set_mem_attributes
In reply to Christoph HellwigNow that set_memory_decrypted is always available we can just call it directly.
--- arch/x86/include/asm/mem_encrypt.h | 2 -- arch/x86/mm/mem_encrypt.c | 9 --------- lib/swiotlb.c | 12 ++++++------ 3 files changed, 6 insertions(+), 17 deletions(-)
arch/x86/include/asm/mem_encrypt.h +0 -2
@@ -48,8 +48,6 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);/* Architecture __weak replacement functions */ void __init mem_encrypt_init (void ); -void swiotlb_set_mem_attributes (void *vaddr,unsigned long size); -bool sme_active (void );bool sev_active (void );
arch/x86/mm/mem_encrypt.c +0 -9
@@ -379,15 +379,6 @@ void __init mem_encrypt_init(void) : "Secure Memory Encryption (SME)"); } -void swiotlb_set_mem_attributes (void *vaddr,unsigned long size) -{ -WARN (PAGE_ALIGN (size) != size, -"size is not page-aligned (%#lx)\n" , size); - -/* Make the SWIOTLB buffer area decrypted */ -set_memory_decrypted ((unsigned long )vaddr, size >>PAGE_SHIFT ); -} -static void __init sme_clear_pgd (pgd_t *pgd_base,unsigned long start,unsigned long end) {
lib/swiotlb.c +6 -6
@@ -31,6 +31,7 @@#include <linux/gfp.h> #include <linux/scatterlist.h> #include <linux/mem_encrypt.h> +#include <linux/set_memory.h> #include <asm/io.h> #include <asm/dma.h>
@@ -156,8 +157,6 @@ unsigned long swiotlb_size_or_default(void)return size ? size : (IO_TLB_DEFAULT_SIZE ); } -void __weak swiotlb_set_mem_attributes (void *vaddr,unsigned long size) { } -/* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address)
@@ -202,12 +201,12 @@ void __init swiotlb_update_mem_attributes(void) vaddr =phys_to_virt (io_tlb_start); bytes =PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ); -swiotlb_set_mem_attributes (vaddr, bytes); +set_memory_decrypted ((unsigned long )vaddr, bytes >>PAGE_SHIFT );memset (vaddr,0 , bytes); vaddr =phys_to_virt (io_tlb_overflow_buffer); bytes =PAGE_ALIGN (io_tlb_overflow); -swiotlb_set_mem_attributes (vaddr, bytes); +set_memory_decrypted ((unsigned long )vaddr, bytes >>PAGE_SHIFT );memset (vaddr,0 , bytes); }
@@ -348,7 +347,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) io_tlb_start =virt_to_phys (tlb); io_tlb_end = io_tlb_start + bytes; -swiotlb_set_mem_attributes (tlb, bytes); +set_memory_decrypted ((unsigned long )tlb, bytes >>PAGE_SHIFT );memset (tlb,0 , bytes);/*
@@ -359,7 +358,8 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)if (!v_overflow_buffer) goto cleanup2; -swiotlb_set_mem_attributes (v_overflow_buffer, io_tlb_overflow); +set_memory_decrypted ((unsigned long )v_overflow_buffer, + io_tlb_overflow >>PAGE_SHIFT );memset (v_overflow_buffer,0 , io_tlb_overflow); io_tlb_overflow_buffer =virt_to_phys (v_overflow_buffer);
Signature · 1 line
2.14.2
PATCH 53/67 swiotlb: remove swiotlb_set_mem_attributes
In reply to Christoph HellwigNow that set_memory_decrypted is always available we can just call it directly.
--- arch/x86/include/asm/mem_encrypt.h | 2 -- arch/x86/mm/mem_encrypt.c | 9 --------- lib/swiotlb.c | 12 ++++++------ 3 files changed, 6 insertions(+), 17 deletions(-)
arch/x86/include/asm/mem_encrypt.h +0 -2
@@ -48,8 +48,6 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);/* Architecture __weak replacement functions */ void __init mem_encrypt_init (void ); -void swiotlb_set_mem_attributes (void *vaddr,unsigned long size); -bool sme_active (void );bool sev_active (void );
arch/x86/mm/mem_encrypt.c +0 -9
@@ -379,15 +379,6 @@ void __init mem_encrypt_init(void) : "Secure Memory Encryption (SME)"); } -void swiotlb_set_mem_attributes (void *vaddr,unsigned long size) -{ -WARN (PAGE_ALIGN (size) != size, -"size is not page-aligned (%#lx)\n" , size); - -/* Make the SWIOTLB buffer area decrypted */ -set_memory_decrypted ((unsigned long )vaddr, size >>PAGE_SHIFT ); -} -static void __init sme_clear_pgd (pgd_t *pgd_base,unsigned long start,unsigned long end) {
lib/swiotlb.c +6 -6
@@ -31,6 +31,7 @@#include <linux/gfp.h> #include <linux/scatterlist.h> #include <linux/mem_encrypt.h> +#include <linux/set_memory.h> #include <asm/io.h> #include <asm/dma.h>
@@ -156,8 +157,6 @@ unsigned long swiotlb_size_or_default(void)return size ? size : (IO_TLB_DEFAULT_SIZE ); } -void __weak swiotlb_set_mem_attributes (void *vaddr,unsigned long size) { } -/* Note that this doesn't work with highmem page */ static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address)
@@ -202,12 +201,12 @@ void __init swiotlb_update_mem_attributes(void) vaddr =phys_to_virt (io_tlb_start); bytes =PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ); -swiotlb_set_mem_attributes (vaddr, bytes); +set_memory_decrypted ((unsigned long )vaddr, bytes >>PAGE_SHIFT );memset (vaddr,0 , bytes); vaddr =phys_to_virt (io_tlb_overflow_buffer); bytes =PAGE_ALIGN (io_tlb_overflow); -swiotlb_set_mem_attributes (vaddr, bytes); +set_memory_decrypted ((unsigned long )vaddr, bytes >>PAGE_SHIFT );memset (vaddr,0 , bytes); }
@@ -348,7 +347,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) io_tlb_start =virt_to_phys (tlb); io_tlb_end = io_tlb_start + bytes; -swiotlb_set_mem_attributes (tlb, bytes); +set_memory_decrypted ((unsigned long )tlb, bytes >>PAGE_SHIFT );memset (tlb,0 , bytes);/*
@@ -359,7 +358,8 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)if (!v_overflow_buffer) goto cleanup2; -swiotlb_set_mem_attributes (v_overflow_buffer, io_tlb_overflow); +set_memory_decrypted ((unsigned long )v_overflow_buffer, + io_tlb_overflow >>PAGE_SHIFT );memset (v_overflow_buffer,0 , io_tlb_overflow); io_tlb_overflow_buffer =virt_to_phys (v_overflow_buffer);
Signature · 1 line
2.14.2
PATCH 54/67 x86: remove sta2x11_dma_ops
In reply to Christoph HellwigBoth the swiotlb and the dma-direct code already call into phys_to_dma to translate the DMA address. So the sta2x11 into phys_to_dma and dma_to_phys are enough to handle this "special" device, and we can use the plain old swiotlb ops.
--- arch/x86/include/asm/device.h | 3 +++ arch/x86/pci/sta2x11-fixup.c | 46 +++++-------------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-)
arch/x86/include/asm/device.h +3 -0
@@ -6,6 +6,9 @@ struct dev_archdata {#if defined(CONFIG_INTEL_IOMMU ) || defined(CONFIG_AMD_IOMMU )void *iommu;/* hook for IOMMU specific extension */ #endif +#ifdef CONFIG_STA2X11 + bool is_sta2x11 : 1; +#endif };#if defined(CONFIG_X86_DEV_DMA_OPS ) && defined(CONFIG_PCI_DOMAINS )
arch/x86/pci/sta2x11-fixup.c +5 -41
76 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 54/67 x86: remove sta2x11_dma_ops
In reply to Christoph HellwigBoth the swiotlb and the dma-direct code already call into phys_to_dma to translate the DMA address. So the sta2x11 into phys_to_dma and dma_to_phys are enough to handle this "special" device, and we can use the plain old swiotlb ops.
--- arch/x86/include/asm/device.h | 3 +++ arch/x86/pci/sta2x11-fixup.c | 46 +++++-------------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-)
arch/x86/include/asm/device.h +3 -0
@@ -6,6 +6,9 @@ struct dev_archdata {#if defined(CONFIG_INTEL_IOMMU ) || defined(CONFIG_AMD_IOMMU )void *iommu;/* hook for IOMMU specific extension */ #endif +#ifdef CONFIG_STA2X11 + bool is_sta2x11 : 1; +#endif };#if defined(CONFIG_X86_DEV_DMA_OPS ) && defined(CONFIG_PCI_DOMAINS )
arch/x86/pci/sta2x11-fixup.c +5 -41
76 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 55/67 ia64: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigia64 uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/ia64/Kconfig | 2 +- arch/ia64/kernel/pci-swiotlb.c | 2 +- arch/ia64/mm/contig.c | 4 ++-- arch/ia64/mm/discontig.c | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/ia64/Kconfig +1 -1
@@ -66,7 +66,7 @@ config 64BIT select ATA_NONSTANDARD if ATA default y -config ZONE_DMA +config ZONE_DMA32 def_bool y depends on !IA64_SGI_SN2
arch/ia64/kernel/pci-swiotlb.c +1 -1
@@ -20,7 +20,7 @@ static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size, unsigned long attrs) {if (dev->coherent_dma_mask !=DMA_BIT_MASK (64 )) - gfp |=GFP_DMA ; + gfp |=GFP_DMA32 ;return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); }
arch/ia64/mm/contig.c +2 -2
@@ -237,9 +237,9 @@ paging_init (void)unsigned long max_zone_pfns[MAX_NR_ZONES ];memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 max_dma =virt_to_phys ((void *)MAX_DMA_ADDRESS ) >>PAGE_SHIFT ; - max_zone_pfns[ZONE_DMA ] = max_dma; + max_zone_pfns[ZONE_DMA32 ] = max_dma;#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;
arch/ia64/mm/discontig.c +4 -4
@@ -38,7 +38,7 @@ struct early_node_data {struct ia64_node_data *node_data;unsigned long pernode_addr;unsigned long pernode_size; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 unsigned long num_dma_physpages;#endif unsigned long min_pfn;
@@ -669,7 +669,7 @@ static __init int count_node_pages(unsigned long start, unsigned long len, int n {unsigned long end = start + len; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 if (start <=__pa (MAX_DMA_ADDRESS )) mem_data[node].num_dma_physpages += (min (end,__pa (MAX_DMA_ADDRESS )) - start) >>PAGE_SHIFT ;
@@ -724,8 +724,8 @@ void __init paging_init(void) }memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA - max_zone_pfns[ZONE_DMA ] = max_dma; +#ifdef CONFIG_ZONE_DMA32 + max_zone_pfns[ZONE_DMA32 ] = max_dma;#endif max_zone_pfns[ZONE_NORMAL ] = max_pfn;free_area_init_nodes (max_zone_pfns);
Signature · 1 line
2.14.2
PATCH 55/67 ia64: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigia64 uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/ia64/Kconfig | 2 +- arch/ia64/kernel/pci-swiotlb.c | 2 +- arch/ia64/mm/contig.c | 4 ++-- arch/ia64/mm/discontig.c | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/ia64/Kconfig +1 -1
@@ -66,7 +66,7 @@ config 64BIT select ATA_NONSTANDARD if ATA default y -config ZONE_DMA +config ZONE_DMA32 def_bool y depends on !IA64_SGI_SN2
arch/ia64/kernel/pci-swiotlb.c +1 -1
@@ -20,7 +20,7 @@ static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size, unsigned long attrs) {if (dev->coherent_dma_mask !=DMA_BIT_MASK (64 )) - gfp |=GFP_DMA ; + gfp |=GFP_DMA32 ;return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); }
arch/ia64/mm/contig.c +2 -2
@@ -237,9 +237,9 @@ paging_init (void)unsigned long max_zone_pfns[MAX_NR_ZONES ];memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 max_dma =virt_to_phys ((void *)MAX_DMA_ADDRESS ) >>PAGE_SHIFT ; - max_zone_pfns[ZONE_DMA ] = max_dma; + max_zone_pfns[ZONE_DMA32 ] = max_dma;#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;
arch/ia64/mm/discontig.c +4 -4
@@ -38,7 +38,7 @@ struct early_node_data {struct ia64_node_data *node_data;unsigned long pernode_addr;unsigned long pernode_size; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 unsigned long num_dma_physpages;#endif unsigned long min_pfn;
@@ -669,7 +669,7 @@ static __init int count_node_pages(unsigned long start, unsigned long len, int n {unsigned long end = start + len; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 if (start <=__pa (MAX_DMA_ADDRESS )) mem_data[node].num_dma_physpages += (min (end,__pa (MAX_DMA_ADDRESS )) - start) >>PAGE_SHIFT ;
@@ -724,8 +724,8 @@ void __init paging_init(void) }memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA - max_zone_pfns[ZONE_DMA ] = max_dma; +#ifdef CONFIG_ZONE_DMA32 + max_zone_pfns[ZONE_DMA32 ] = max_dma;#endif max_zone_pfns[ZONE_NORMAL ] = max_pfn;free_area_init_nodes (max_zone_pfns);
Signature · 1 line
2.14.2
PATCH 56/67 ia64: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the ia64 ops, and would also support CMA if enabled on ia64.
--- arch/ia64/Kconfig | 5 +++++ arch/ia64/hp/common/hwsw_iommu.c | 4 ++-- arch/ia64/hp/common/sba_iommu.c | 6 +++--- arch/ia64/kernel/pci-swiotlb.c | 38 +++----------------------------------- 4 files changed, 13 insertions(+), 40 deletions(-)
arch/ia64/Kconfig +5 -0
@@ -146,6 +146,7 @@ config IA64_GENERIC bool "generic" select NUMA select ACPI_NUMA + select DMA_DIRECT_OPS select SWIOTLB select PCI_MSI help
@@ -166,6 +167,7 @@ config IA64_GENERIC config IA64_DIG bool "DIG-compliant" + select DMA_DIRECT_OPS select SWIOTLB config IA64_DIG_VTD
@@ -181,6 +183,7 @@ config IA64_HP_ZX1 config IA64_HP_ZX1_SWIOTLB bool "HP-zx1/sx1000 with software I/O TLB" + select DMA_DIRECT_OPS select SWIOTLB help Build a kernel that runs on HP zx1 and sx1000 systems even when they
@@ -204,6 +207,7 @@ config IA64_SGI_UV bool "SGI-UV" select NUMA select ACPI_NUMA + select DMA_DIRECT_OPS select SWIOTLB help Selecting this option will optimize the kernel for use on UV based
@@ -214,6 +218,7 @@ config IA64_SGI_UV config IA64_HP_SIM bool "Ski-simulator" + select DMA_DIRECT_OPS select SWIOTLB depends on !PM
arch/ia64/hp/common/hwsw_iommu.c +2 -2
@@ -19,7 +19,7 @@#include <linux/export.h> #include <asm/machvec.h> -extern const struct dma_map_ops sba_dma_ops, ia64_swiotlb_dma_ops; +extern const struct dma_map_ops sba_dma_ops;/* swiotlb declarations & definitions: */ extern int swiotlb_late_init_with_default_size (size_t size);
@@ -38,7 +38,7 @@ static inline int use_swiotlb(struct device *dev)const struct dma_map_ops *hwsw_dma_get_ops (struct device *dev) {if (use_swiotlb (dev)) -return &ia64_swiotlb_dma_ops; +return &swiotlb_dma_ops;return &sba_dma_ops; }EXPORT_SYMBOL (hwsw_dma_get_ops);
arch/ia64/hp/common/sba_iommu.c +3 -3
@@ -2093,7 +2093,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */ arch_initcall (acpi_sba_ioc_init_acpi); -extern const struct dma_map_ops ia64_swiotlb_dma_ops; +extern const struct dma_map_ops swiotlb_dma_ops;static int __init sba_init (void )
@@ -2108,7 +2108,7 @@ sba_init(void)* a successful kdump kernel boot is to use the swiotlb. */ if (is_kdump_kernel ()) { - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to initialize software I/O TLB:" " Try machvec=dig boot option" );
@@ -2130,7 +2130,7 @@ sba_init(void)* If we didn't find something sba_iommu can claim, we * need to setup the swiotlb and switch to the dig machvec. */ - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to find SBA IOMMU or initialize " "software I/O TLB: Try machvec=dig boot option" );
arch/ia64/kernel/pci-swiotlb.c +3 -35
@@ -6,8 +6,7 @@#include <linux/cache.h> #include <linux/module.h> #include <linux/dma-mapping.h> - -#include <asm/swiotlb.h> +#include <linux/swiotlb.h> #include <asm/dma.h> #include <asm/iommu.h> #include <asm/machvec.h>
@@ -15,40 +14,9 @@int swiotlb__read_mostly ;EXPORT_SYMBOL (swiotlb); -static void *ia64_swiotlb_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp, -unsigned long attrs) -{ -if (dev->coherent_dma_mask !=DMA_BIT_MASK (64 )) - gfp |=GFP_DMA32 ; -return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); -} - -static void ia64_swiotlb_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -} - -const struct dma_map_ops ia64_swiotlb_dma_ops = { - .alloc = ia64_swiotlb_alloc_coherent, - .free = ia64_swiotlb_free_coherent, - .map_page = swiotlb_map_page, - .unmap_page = swiotlb_unmap_page, - .map_sg = swiotlb_map_sg_attrs, - .unmap_sg = swiotlb_unmap_sg_attrs, - .sync_single_for_cpu = swiotlb_sync_single_for_cpu, - .sync_single_for_device = swiotlb_sync_single_for_device, - .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, - .sync_sg_for_device = swiotlb_sync_sg_for_device, - .dma_supported = swiotlb_dma_supported, - .mapping_error = swiotlb_dma_mapping_error, -}; -void __init swiotlb_dma_init (void ) { - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;swiotlb_init (1 ); }
@@ -60,7 +28,7 @@ void __init pci_swiotlb_init(void)printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" );machvec_init ("dig" );swiotlb_init (1 ); - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;#else panic ("Unable to find Intel IOMMU" );#endif
Signature · 1 line
2.14.2
PATCH 56/67 ia64: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the ia64 ops, and would also support CMA if enabled on ia64.
--- arch/ia64/Kconfig | 5 +++++ arch/ia64/hp/common/hwsw_iommu.c | 4 ++-- arch/ia64/hp/common/sba_iommu.c | 6 +++--- arch/ia64/kernel/pci-swiotlb.c | 38 +++----------------------------------- 4 files changed, 13 insertions(+), 40 deletions(-)
arch/ia64/Kconfig +5 -0
@@ -146,6 +146,7 @@ config IA64_GENERIC bool "generic" select NUMA select ACPI_NUMA + select DMA_DIRECT_OPS select SWIOTLB select PCI_MSI help
@@ -166,6 +167,7 @@ config IA64_GENERIC config IA64_DIG bool "DIG-compliant" + select DMA_DIRECT_OPS select SWIOTLB config IA64_DIG_VTD
@@ -181,6 +183,7 @@ config IA64_HP_ZX1 config IA64_HP_ZX1_SWIOTLB bool "HP-zx1/sx1000 with software I/O TLB" + select DMA_DIRECT_OPS select SWIOTLB help Build a kernel that runs on HP zx1 and sx1000 systems even when they
@@ -204,6 +207,7 @@ config IA64_SGI_UV bool "SGI-UV" select NUMA select ACPI_NUMA + select DMA_DIRECT_OPS select SWIOTLB help Selecting this option will optimize the kernel for use on UV based
@@ -214,6 +218,7 @@ config IA64_SGI_UV config IA64_HP_SIM bool "Ski-simulator" + select DMA_DIRECT_OPS select SWIOTLB depends on !PM
arch/ia64/hp/common/hwsw_iommu.c +2 -2
@@ -19,7 +19,7 @@#include <linux/export.h> #include <asm/machvec.h> -extern const struct dma_map_ops sba_dma_ops, ia64_swiotlb_dma_ops; +extern const struct dma_map_ops sba_dma_ops;/* swiotlb declarations & definitions: */ extern int swiotlb_late_init_with_default_size (size_t size);
@@ -38,7 +38,7 @@ static inline int use_swiotlb(struct device *dev)const struct dma_map_ops *hwsw_dma_get_ops (struct device *dev) {if (use_swiotlb (dev)) -return &ia64_swiotlb_dma_ops; +return &swiotlb_dma_ops;return &sba_dma_ops; }EXPORT_SYMBOL (hwsw_dma_get_ops);
arch/ia64/hp/common/sba_iommu.c +3 -3
@@ -2093,7 +2093,7 @@ static int __init acpi_sba_ioc_init_acpi(void)/* This has to run before acpi_scan_init(). */ arch_initcall (acpi_sba_ioc_init_acpi); -extern const struct dma_map_ops ia64_swiotlb_dma_ops; +extern const struct dma_map_ops swiotlb_dma_ops;static int __init sba_init (void )
@@ -2108,7 +2108,7 @@ sba_init(void)* a successful kdump kernel boot is to use the swiotlb. */ if (is_kdump_kernel ()) { - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to initialize software I/O TLB:" " Try machvec=dig boot option" );
@@ -2130,7 +2130,7 @@ sba_init(void)* If we didn't find something sba_iommu can claim, we * need to setup the swiotlb and switch to the dig machvec. */ - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;if (swiotlb_late_init_with_default_size (64 * (1 <<20 )) !=0 )panic ("Unable to find SBA IOMMU or initialize " "software I/O TLB: Try machvec=dig boot option" );
arch/ia64/kernel/pci-swiotlb.c +3 -35
@@ -6,8 +6,7 @@#include <linux/cache.h> #include <linux/module.h> #include <linux/dma-mapping.h> - -#include <asm/swiotlb.h> +#include <linux/swiotlb.h> #include <asm/dma.h> #include <asm/iommu.h> #include <asm/machvec.h>
@@ -15,40 +14,9 @@int swiotlb__read_mostly ;EXPORT_SYMBOL (swiotlb); -static void *ia64_swiotlb_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp, -unsigned long attrs) -{ -if (dev->coherent_dma_mask !=DMA_BIT_MASK (64 )) - gfp |=GFP_DMA32 ; -return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); -} - -static void ia64_swiotlb_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -} - -const struct dma_map_ops ia64_swiotlb_dma_ops = { - .alloc = ia64_swiotlb_alloc_coherent, - .free = ia64_swiotlb_free_coherent, - .map_page = swiotlb_map_page, - .unmap_page = swiotlb_unmap_page, - .map_sg = swiotlb_map_sg_attrs, - .unmap_sg = swiotlb_unmap_sg_attrs, - .sync_single_for_cpu = swiotlb_sync_single_for_cpu, - .sync_single_for_device = swiotlb_sync_single_for_device, - .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, - .sync_sg_for_device = swiotlb_sync_sg_for_device, - .dma_supported = swiotlb_dma_supported, - .mapping_error = swiotlb_dma_mapping_error, -}; -void __init swiotlb_dma_init (void ) { - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;swiotlb_init (1 ); }
@@ -60,7 +28,7 @@ void __init pci_swiotlb_init(void)printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" );machvec_init ("dig" );swiotlb_init (1 ); - dma_ops = &ia64_swiotlb_dma_ops; + dma_ops = &swiotlb_dma_ops;#else panic ("Unable to find Intel IOMMU" );#endif
Signature · 1 line
2.14.2
PATCH 57/67 ia64: clean up swiotlb support
In reply to Christoph HellwigMove the few remaining bits of swiotlb glue towards their callers, and remove the pointless on ia64 swiotlb variable.
--- arch/ia64/include/asm/dma-mapping.h | 1 - arch/ia64/include/asm/swiotlb.h | 18 ------------------ arch/ia64/kernel/dma-mapping.c | 9 +++++++++ arch/ia64/kernel/pci-dma.c | 12 ++++++++++-- arch/ia64/kernel/pci-swiotlb.c | 36 ------------------------------------ drivers/iommu/intel-iommu.c | 2 +- 6 files changed, 20 insertions(+), 58 deletions(-) delete mode 100644 arch/ia64/include/asm/swiotlb.h delete mode 100644 arch/ia64/kernel/pci-swiotlb.c
arch/ia64/include/asm/dma-mapping.h +0 -1
@@ -8,7 +8,6 @@*/ #include <asm/machvec.h> #include <linux/scatterlist.h> -#include <asm/swiotlb.h> #include <linux/dma-debug.h> #define ARCH_HAS_DMA_GET_REQUIRED_MASK
arch/ia64/include/asm/swiotlb.h deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef ASM_IA64__SWIOTLB_H -#define ASM_IA64__SWIOTLB_H - -#include <linux/dma-mapping.h> -#include <linux/swiotlb.h> - -#ifdef CONFIG_SWIOTLB -extern int swiotlb; -extern void pci_swiotlb_init (void ); -#else -#define swiotlb 0 -static inline void pci_swiotlb_init (void ) -{ -} -#endif - -#endif /* ASM_IA64__SWIOTLB_H */
arch/ia64/kernel/dma-mapping.c +9 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/dma-mapping.h> +#include <linux/swiotlb.h> #include <linux/export.h> /* Set this to 1 if there is a HW IOMMU in the system */
@@ -23,3 +24,11 @@ const struct dma_map_ops *dma_get_ops(struct device *dev)return dma_ops; }EXPORT_SYMBOL (dma_get_ops); + +#ifdef CONFIG_SWIOTLB +void __init swiotlb_dma_init (void ) +{ + dma_ops = &swiotlb_dma_ops; +swiotlb_init (1 ); +} +#endif
arch/ia64/kernel/pci-dma.c +10 -2
@@ -104,8 +104,16 @@ void __init pci_iommu_alloc(void)detect_intel_iommu ();#ifdef CONFIG_SWIOTLB -pci_swiotlb_init (); -#endif +if (!iommu_detected) { +#ifdef CONFIG_IA64_GENERIC +printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" ); +machvec_init ("dig" ); +swiotlb_dma_init (); +#else +panic ("Unable to find Intel IOMMU" ); +#endif /* CONFIG_IA64_GENERIC */ + } +#endif /* CONFIG_SWIOTLB */ }#endif
arch/ia64/kernel/pci-swiotlb.c deleted +0 -36
@@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Glue code to lib/swiotlb.c */ - -#include <linux/pci.h> -#include <linux/gfp.h> -#include <linux/cache.h> -#include <linux/module.h> -#include <linux/dma-mapping.h> -#include <linux/swiotlb.h> -#include <asm/dma.h> -#include <asm/iommu.h> -#include <asm/machvec.h> - -int swiotlb__read_mostly ; -EXPORT_SYMBOL (swiotlb); - -void __init swiotlb_dma_init (void ) -{ - dma_ops = &swiotlb_dma_ops; -swiotlb_init (1 ); -} - -void __init pci_swiotlb_init (void ) -{ -if (!iommu_detected) { -#ifdef CONFIG_IA64_GENERIC - swiotlb =1 ; -printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" ); -machvec_init ("dig" ); -swiotlb_init (1 ); - dma_ops = &swiotlb_dma_ops; -#else -panic ("Unable to find Intel IOMMU" ); -#endif - } -}
drivers/iommu/intel-iommu.c +1 -1
@@ -4807,7 +4807,7 @@ int __init intel_iommu_init(void)up_write (&dmar_global_lock);pr_info ("Intel(R) Virtualization Technology for Directed I/O\n" ); -#ifdef CONFIG_SWIOTLB +#if defined(CONFIG_X86 ) && defined(CONFIG_SWIOTLB ) swiotlb =0 ;#endif dma_ops = &intel_dma_ops;
Signature · 1 line
2.14.2
PATCH 57/67 ia64: clean up swiotlb support
In reply to Christoph HellwigMove the few remaining bits of swiotlb glue towards their callers, and remove the pointless on ia64 swiotlb variable.
--- arch/ia64/include/asm/dma-mapping.h | 1 - arch/ia64/include/asm/swiotlb.h | 18 ------------------ arch/ia64/kernel/dma-mapping.c | 9 +++++++++ arch/ia64/kernel/pci-dma.c | 12 ++++++++++-- arch/ia64/kernel/pci-swiotlb.c | 36 ------------------------------------ drivers/iommu/intel-iommu.c | 2 +- 6 files changed, 20 insertions(+), 58 deletions(-) delete mode 100644 arch/ia64/include/asm/swiotlb.h delete mode 100644 arch/ia64/kernel/pci-swiotlb.c
arch/ia64/include/asm/dma-mapping.h +0 -1
@@ -8,7 +8,6 @@*/ #include <asm/machvec.h> #include <linux/scatterlist.h> -#include <asm/swiotlb.h> #include <linux/dma-debug.h> #define ARCH_HAS_DMA_GET_REQUIRED_MASK
arch/ia64/include/asm/swiotlb.h deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef ASM_IA64__SWIOTLB_H -#define ASM_IA64__SWIOTLB_H - -#include <linux/dma-mapping.h> -#include <linux/swiotlb.h> - -#ifdef CONFIG_SWIOTLB -extern int swiotlb; -extern void pci_swiotlb_init (void ); -#else -#define swiotlb 0 -static inline void pci_swiotlb_init (void ) -{ -} -#endif - -#endif /* ASM_IA64__SWIOTLB_H */
arch/ia64/kernel/dma-mapping.c +9 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/dma-mapping.h> +#include <linux/swiotlb.h> #include <linux/export.h> /* Set this to 1 if there is a HW IOMMU in the system */
@@ -23,3 +24,11 @@ const struct dma_map_ops *dma_get_ops(struct device *dev)return dma_ops; }EXPORT_SYMBOL (dma_get_ops); + +#ifdef CONFIG_SWIOTLB +void __init swiotlb_dma_init (void ) +{ + dma_ops = &swiotlb_dma_ops; +swiotlb_init (1 ); +} +#endif
arch/ia64/kernel/pci-dma.c +10 -2
@@ -104,8 +104,16 @@ void __init pci_iommu_alloc(void)detect_intel_iommu ();#ifdef CONFIG_SWIOTLB -pci_swiotlb_init (); -#endif +if (!iommu_detected) { +#ifdef CONFIG_IA64_GENERIC +printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" ); +machvec_init ("dig" ); +swiotlb_dma_init (); +#else +panic ("Unable to find Intel IOMMU" ); +#endif /* CONFIG_IA64_GENERIC */ + } +#endif /* CONFIG_SWIOTLB */ }#endif
arch/ia64/kernel/pci-swiotlb.c deleted +0 -36
@@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Glue code to lib/swiotlb.c */ - -#include <linux/pci.h> -#include <linux/gfp.h> -#include <linux/cache.h> -#include <linux/module.h> -#include <linux/dma-mapping.h> -#include <linux/swiotlb.h> -#include <asm/dma.h> -#include <asm/iommu.h> -#include <asm/machvec.h> - -int swiotlb__read_mostly ; -EXPORT_SYMBOL (swiotlb); - -void __init swiotlb_dma_init (void ) -{ - dma_ops = &swiotlb_dma_ops; -swiotlb_init (1 ); -} - -void __init pci_swiotlb_init (void ) -{ -if (!iommu_detected) { -#ifdef CONFIG_IA64_GENERIC - swiotlb =1 ; -printk (KERN_INFO "PCI-DMA: Re-initialize machine vector.\n" ); -machvec_init ("dig" ); -swiotlb_init (1 ); - dma_ops = &swiotlb_dma_ops; -#else -panic ("Unable to find Intel IOMMU" ); -#endif - } -}
drivers/iommu/intel-iommu.c +1 -1
@@ -4807,7 +4807,7 @@ int __init intel_iommu_init(void)up_write (&dmar_global_lock);pr_info ("Intel(R) Virtualization Technology for Directed I/O\n" ); -#ifdef CONFIG_SWIOTLB +#if defined(CONFIG_X86 ) && defined(CONFIG_SWIOTLB ) swiotlb =0 ;#endif dma_ops = &intel_dma_ops;
Signature · 1 line
2.14.2
PATCH 58/67 ia64: remove an ifdef around the content of pci-dma.c
In reply to Christoph HellwigThe file is only compiled if CONFIG_INTEL_IOMMU is set to start with.
--- arch/ia64/kernel/pci-dma.c | 7 ------- 1 file changed, 7 deletions(-)
arch/ia64/kernel/pci-dma.c +0 -7
@@ -12,12 +12,7 @@#include <asm/iommu.h> #include <asm/machvec.h> #include <linux/dma-mapping.h> - - -#ifdef CONFIG_INTEL_IOMMU -#include <linux/kernel.h> -#include <asm/page.h> dma_addr_t bad_dma_address__read_mostly ;
@@ -115,5 +110,3 @@ void __init pci_iommu_alloc(void) }#endif /* CONFIG_SWIOTLB */ } - -#endif
Signature · 1 line
2.14.2
PATCH 58/67 ia64: remove an ifdef around the content of pci-dma.c
In reply to Christoph HellwigThe file is only compiled if CONFIG_INTEL_IOMMU is set to start with.
--- arch/ia64/kernel/pci-dma.c | 7 ------- 1 file changed, 7 deletions(-)
arch/ia64/kernel/pci-dma.c +0 -7
@@ -12,12 +12,7 @@#include <asm/iommu.h> #include <asm/machvec.h> #include <linux/dma-mapping.h> - - -#ifdef CONFIG_INTEL_IOMMU -#include <linux/kernel.h> -#include <asm/page.h> dma_addr_t bad_dma_address__read_mostly ;
@@ -115,5 +110,3 @@ void __init pci_iommu_alloc(void) }#endif /* CONFIG_SWIOTLB */ } - -#endif
Signature · 1 line
2.14.2
PATCH 59/67 unicore32: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the unicore32 ops, and would also support CMA if enabled on unicore32.
--- arch/unicore32/include/asm/dma-mapping.h | 9 +----- arch/unicore32/mm/Kconfig | 1 + arch/unicore32/mm/Makefile | 2 -- arch/unicore32/mm/dma-swiotlb.c | 48 -------------------------------- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 arch/unicore32/mm/dma-swiotlb.c
arch/unicore32/include/asm/dma-mapping.h +1 -8
@@ -12,18 +12,11 @@#ifndef __UNICORE_DMA_MAPPING_H__#define __UNICORE_DMA_MAPPING_H__ -#ifdef __KERNEL__ - -#include <linux/mm_types.h> -#include <linux/scatterlist.h> #include <linux/swiotlb.h> -extern const struct dma_map_ops swiotlb_dma_map_ops; -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) { -return &swiotlb_dma_map_ops; +return &swiotlb_dma_ops; } -#endif /* __KERNEL__ */ #endif
arch/unicore32/mm/Kconfig +1 -0
@@ -42,6 +42,7 @@ config CPU_TLB_SINGLE_ENTRY_DISABLE config SWIOTLB def_bool y + select DMA_DIRECT_OPS config IOMMU_HELPER def_bool SWIOTLB
arch/unicore32/mm/Makefile +0 -2
@@ -6,8 +6,6 @@ obj-y := extable.o fault.o init.o pgd.o mmu.o obj-y += flush.o ioremap.o -obj-$(CONFIG_SWIOTLB) += dma-swiotlb.o - obj-$(CONFIG_MODULES) += proc-syms.o obj-$(CONFIG_ALIGNMENT_TRAP) += alignment.o
arch/unicore32/mm/dma-swiotlb.c deleted +0 -48
48 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 59/67 unicore32: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the unicore32 ops, and would also support CMA if enabled on unicore32.
--- arch/unicore32/include/asm/dma-mapping.h | 9 +----- arch/unicore32/mm/Kconfig | 1 + arch/unicore32/mm/Makefile | 2 -- arch/unicore32/mm/dma-swiotlb.c | 48 -------------------------------- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 arch/unicore32/mm/dma-swiotlb.c
arch/unicore32/include/asm/dma-mapping.h +1 -8
@@ -12,18 +12,11 @@#ifndef __UNICORE_DMA_MAPPING_H__#define __UNICORE_DMA_MAPPING_H__ -#ifdef __KERNEL__ - -#include <linux/mm_types.h> -#include <linux/scatterlist.h> #include <linux/swiotlb.h> -extern const struct dma_map_ops swiotlb_dma_map_ops; -static inline const struct dma_map_ops *get_arch_dma_ops (struct bus_type *bus) { -return &swiotlb_dma_map_ops; +return &swiotlb_dma_ops; } -#endif /* __KERNEL__ */ #endif
arch/unicore32/mm/Kconfig +1 -0
@@ -42,6 +42,7 @@ config CPU_TLB_SINGLE_ENTRY_DISABLE config SWIOTLB def_bool y + select DMA_DIRECT_OPS config IOMMU_HELPER def_bool SWIOTLB
arch/unicore32/mm/Makefile +0 -2
@@ -6,8 +6,6 @@ obj-y := extable.o fault.o init.o pgd.o mmu.o obj-y += flush.o ioremap.o -obj-$(CONFIG_SWIOTLB) += dma-swiotlb.o - obj-$(CONFIG_MODULES) += proc-syms.o obj-$(CONFIG_ALIGNMENT_TRAP) += alignment.o
arch/unicore32/mm/dma-swiotlb.c deleted +0 -48
48 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 60/67 tile: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigtile uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/tile/Kconfig | 2 +- arch/tile/kernel/pci-dma.c | 4 ++-- arch/tile/kernel/setup.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
arch/tile/Kconfig +1 -1
@@ -249,7 +249,7 @@ config HIGHMEM If unsure, say "true". -config ZONE_DMA +config ZONE_DMA32 def_bool y config IOMMU_HELPER
arch/tile/kernel/pci-dma.c +2 -2
@@ -54,7 +54,7 @@ static void *tile_dma_alloc_coherent(struct device *dev, size_t size,* which case we will return NULL. But such devices are uncommon. */ if (dma_mask <=DMA_BIT_MASK (32 )) { - gfp |=GFP_DMA ; + gfp |=GFP_DMA32 ; node =0 ; }
@@ -515,7 +515,7 @@ static void *tile_swiotlb_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { - gfp |= GFP_DMA; + gfp |= GFP_DMA32;return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); }
arch/tile/kernel/setup.c +4 -4
@@ -814,11 +814,11 @@ static void __init zone_sizes_init(void)#endif if (start < dma_end) { - zones_size[ZONE_DMA ] =min (zones_size[ZONE_NORMAL ], + zones_size[ZONE_DMA32 ] =min (zones_size[ZONE_NORMAL ], dma_end - start); - zones_size[ZONE_NORMAL ] -= zones_size[ZONE_DMA ]; + zones_size[ZONE_NORMAL ] -= zones_size[ZONE_DMA32 ]; }else { - zones_size[ZONE_DMA ] =0 ; + zones_size[ZONE_DMA32 ] =0 ; }/* Take zone metadata from controller 0 if we're isolnode. */
@@ -830,7 +830,7 @@ static void __init zone_sizes_init(void) PFN_UP(node_percpu[i]));/* Track the type of memory on each node */ -if (zones_size[ZONE_NORMAL ] || zones_size[ZONE_DMA ]) +if (zones_size[ZONE_NORMAL ] || zones_size[ZONE_DMA32 ])node_set_state (i,N_NORMAL_MEMORY );#ifdef CONFIG_HIGHMEM if (end != start)
Signature · 1 line
2.14.2
PATCH 60/67 tile: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigtile uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/tile/Kconfig | 2 +- arch/tile/kernel/pci-dma.c | 4 ++-- arch/tile/kernel/setup.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
arch/tile/Kconfig +1 -1
@@ -249,7 +249,7 @@ config HIGHMEM If unsure, say "true". -config ZONE_DMA +config ZONE_DMA32 def_bool y config IOMMU_HELPER
arch/tile/kernel/pci-dma.c +2 -2
@@ -54,7 +54,7 @@ static void *tile_dma_alloc_coherent(struct device *dev, size_t size,* which case we will return NULL. But such devices are uncommon. */ if (dma_mask <=DMA_BIT_MASK (32 )) { - gfp |=GFP_DMA ; + gfp |=GFP_DMA32 ; node =0 ; }
@@ -515,7 +515,7 @@ static void *tile_swiotlb_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { - gfp |= GFP_DMA; + gfp |= GFP_DMA32;return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); }
arch/tile/kernel/setup.c +4 -4
@@ -814,11 +814,11 @@ static void __init zone_sizes_init(void)#endif if (start < dma_end) { - zones_size[ZONE_DMA ] =min (zones_size[ZONE_NORMAL ], + zones_size[ZONE_DMA32 ] =min (zones_size[ZONE_NORMAL ], dma_end - start); - zones_size[ZONE_NORMAL ] -= zones_size[ZONE_DMA ]; + zones_size[ZONE_NORMAL ] -= zones_size[ZONE_DMA32 ]; }else { - zones_size[ZONE_DMA ] =0 ; + zones_size[ZONE_DMA32 ] =0 ; }/* Take zone metadata from controller 0 if we're isolnode. */
@@ -830,7 +830,7 @@ static void __init zone_sizes_init(void) PFN_UP(node_percpu[i]));/* Track the type of memory on each node */ -if (zones_size[ZONE_NORMAL ] || zones_size[ZONE_DMA ]) +if (zones_size[ZONE_NORMAL ] || zones_size[ZONE_DMA32 ])node_set_state (i,N_NORMAL_MEMORY );#ifdef CONFIG_HIGHMEM if (end != start)
Signature · 1 line
2.14.2
PATCH 61/67 tile: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the tile ops, and would also support CMA if enabled on tile.
--- arch/tile/Kconfig | 1 + arch/tile/kernel/pci-dma.c | 36 +++--------------------------------- 2 files changed, 4 insertions(+), 33 deletions(-)
arch/tile/Kconfig +1 -0
@@ -261,6 +261,7 @@ config NEED_SG_DMA_LENGTH config SWIOTLB bool default TILEGX + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH select ARCH_HAS_DMA_SET_COHERENT_MASK
arch/tile/kernel/pci-dma.c +3 -33
@@ -511,39 +511,9 @@ EXPORT_SYMBOL(gx_pci_dma_map_ops);/* PCI DMA mapping functions for legacy PCI devices */ #ifdef CONFIG_SWIOTLB -static void *tile_swiotlb_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp, -unsigned long attrs) -{ - gfp |=GFP_DMA32 ; -return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); -} - -static void tile_swiotlb_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -} - -static const struct dma_map_ops pci_swiotlb_dma_ops = { - .alloc = tile_swiotlb_alloc_coherent, - .free = tile_swiotlb_free_coherent, - .map_page = swiotlb_map_page, - .unmap_page = swiotlb_unmap_page, - .map_sg = swiotlb_map_sg_attrs, - .unmap_sg = swiotlb_unmap_sg_attrs, - .sync_single_for_cpu = swiotlb_sync_single_for_cpu, - .sync_single_for_device = swiotlb_sync_single_for_device, - .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, - .sync_sg_for_device = swiotlb_sync_sg_for_device, - .dma_supported = swiotlb_dma_supported, - .mapping_error = swiotlb_dma_mapping_error, -}; -static const struct dma_map_ops pci_hybrid_dma_ops = { - .alloc = tile_swiotlb_alloc_coherent, - .free = tile_swiotlb_free_coherent, + .alloc = swiotlb_alloc, + .free = swiotlb_free, .map_page = tile_pci_dma_map_page, .unmap_page = tile_pci_dma_unmap_page, .map_sg = tile_pci_dma_map_sg,
@@ -554,7 +524,7 @@ static const struct dma_map_ops pci_hybrid_dma_ops = { .sync_sg_for_device = tile_pci_dma_sync_sg_for_device, }; -const struct dma_map_ops *gx_legacy_pci_dma_map_ops = &pci_swiotlb_dma_ops; +const struct dma_map_ops *gx_legacy_pci_dma_map_ops = &swiotlb_dma_ops;const struct dma_map_ops *gx_hybrid_pci_dma_map_ops = &pci_hybrid_dma_ops;#else const struct dma_map_ops *gx_legacy_pci_dma_map_ops;
Signature · 1 line
2.14.2
PATCH 61/67 tile: use generic swiotlb_ops
In reply to Christoph HellwigThese are identical to the tile ops, and would also support CMA if enabled on tile.
--- arch/tile/Kconfig | 1 + arch/tile/kernel/pci-dma.c | 36 +++--------------------------------- 2 files changed, 4 insertions(+), 33 deletions(-)
arch/tile/Kconfig +1 -0
@@ -261,6 +261,7 @@ config NEED_SG_DMA_LENGTH config SWIOTLB bool default TILEGX + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH select ARCH_HAS_DMA_SET_COHERENT_MASK
arch/tile/kernel/pci-dma.c +3 -33
@@ -511,39 +511,9 @@ EXPORT_SYMBOL(gx_pci_dma_map_ops);/* PCI DMA mapping functions for legacy PCI devices */ #ifdef CONFIG_SWIOTLB -static void *tile_swiotlb_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp, -unsigned long attrs) -{ - gfp |=GFP_DMA32 ; -return swiotlb_alloc_coherent (dev, size, dma_handle, gfp); -} - -static void tile_swiotlb_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_addr, -unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_addr); -} - -static const struct dma_map_ops pci_swiotlb_dma_ops = { - .alloc = tile_swiotlb_alloc_coherent, - .free = tile_swiotlb_free_coherent, - .map_page = swiotlb_map_page, - .unmap_page = swiotlb_unmap_page, - .map_sg = swiotlb_map_sg_attrs, - .unmap_sg = swiotlb_unmap_sg_attrs, - .sync_single_for_cpu = swiotlb_sync_single_for_cpu, - .sync_single_for_device = swiotlb_sync_single_for_device, - .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, - .sync_sg_for_device = swiotlb_sync_sg_for_device, - .dma_supported = swiotlb_dma_supported, - .mapping_error = swiotlb_dma_mapping_error, -}; -static const struct dma_map_ops pci_hybrid_dma_ops = { - .alloc = tile_swiotlb_alloc_coherent, - .free = tile_swiotlb_free_coherent, + .alloc = swiotlb_alloc, + .free = swiotlb_free, .map_page = tile_pci_dma_map_page, .unmap_page = tile_pci_dma_unmap_page, .map_sg = tile_pci_dma_map_sg,
@@ -554,7 +524,7 @@ static const struct dma_map_ops pci_hybrid_dma_ops = { .sync_sg_for_device = tile_pci_dma_sync_sg_for_device, }; -const struct dma_map_ops *gx_legacy_pci_dma_map_ops = &pci_swiotlb_dma_ops; +const struct dma_map_ops *gx_legacy_pci_dma_map_ops = &swiotlb_dma_ops;const struct dma_map_ops *gx_hybrid_pci_dma_map_ops = &pci_hybrid_dma_ops;#else const struct dma_map_ops *gx_legacy_pci_dma_map_ops;
Signature · 1 line
2.14.2
PATCH 62/67 mips/netlogic: remove swiotlb support
In reply to Christoph Hellwignlm_swiotlb_dma_ops is unused code, so the whole swiotlb support is dead. If it gets resurrected at some point it should use the generic swiotlb_dma_ops instead.
--- arch/mips/include/asm/netlogic/common.h | 3 -- arch/mips/netlogic/Kconfig | 5 -- arch/mips/netlogic/common/Makefile | 1 - arch/mips/netlogic/common/nlm-dma.c | 94 --------------------------------- 4 files changed, 103 deletions(-) delete mode 100644 arch/mips/netlogic/common/nlm-dma.c
arch/mips/include/asm/netlogic/common.h +0 -3
@@ -87,9 +87,6 @@ unsigned int nlm_get_cpu_frequency(void);extern const struct plat_smp_ops nlm_smp_ops;extern char nlm_reset_entry[], nlm_reset_entry_end[]; -/* SWIOTLB */ -extern const struct dma_map_ops nlm_swiotlb_dma_ops; -extern unsigned int nlm_threads_per_core;extern cpumask_t nlm_cpumask;
arch/mips/netlogic/Kconfig +0 -5
@@ -89,9 +89,4 @@ config IOMMU_HELPER config NEED_SG_DMA_LENGTH bool -config SWIOTLB - def_bool y - select NEED_SG_DMA_LENGTH - select IOMMU_HELPER - endif
arch/mips/netlogic/common/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-y += irq.o time.o -obj-y += nlm-dma.o obj-y += reset.o obj-$(CONFIG_SMP) += smp.o smpboot.o obj-$(CONFIG_EARLY_PRINTK) += earlycons.o
arch/mips/netlogic/common/nlm-dma.c deleted +0 -94
94 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 62/67 mips/netlogic: remove swiotlb support
In reply to Christoph Hellwignlm_swiotlb_dma_ops is unused code, so the whole swiotlb support is dead. If it gets resurrected at some point it should use the generic swiotlb_dma_ops instead.
--- arch/mips/include/asm/netlogic/common.h | 3 -- arch/mips/netlogic/Kconfig | 5 -- arch/mips/netlogic/common/Makefile | 1 - arch/mips/netlogic/common/nlm-dma.c | 94 --------------------------------- 4 files changed, 103 deletions(-) delete mode 100644 arch/mips/netlogic/common/nlm-dma.c
arch/mips/include/asm/netlogic/common.h +0 -3
@@ -87,9 +87,6 @@ unsigned int nlm_get_cpu_frequency(void);extern const struct plat_smp_ops nlm_smp_ops;extern char nlm_reset_entry[], nlm_reset_entry_end[]; -/* SWIOTLB */ -extern const struct dma_map_ops nlm_swiotlb_dma_ops; -extern unsigned int nlm_threads_per_core;extern cpumask_t nlm_cpumask;
arch/mips/netlogic/Kconfig +0 -5
@@ -89,9 +89,4 @@ config IOMMU_HELPER config NEED_SG_DMA_LENGTH bool -config SWIOTLB - def_bool y - select NEED_SG_DMA_LENGTH - select IOMMU_HELPER - endif
arch/mips/netlogic/common/Makefile +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-y += irq.o time.o -obj-y += nlm-dma.o obj-y += reset.o obj-$(CONFIG_SMP) += smp.o smpboot.o obj-$(CONFIG_EARLY_PRINTK) += earlycons.o
arch/mips/netlogic/common/nlm-dma.c deleted +0 -94
94 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 63/67 mips: use swiotlb_{alloc,free}
In reply to Christoph HellwigThese already include the GFP_DMA/GFP_DMA32 usage, and will use CMA memory if enabled, thus avoiding the GFP_NORETRY hack.
--- arch/mips/cavium-octeon/Kconfig | 1 + arch/mips/cavium-octeon/dma-octeon.c | 26 +++----------------------- arch/mips/loongson64/Kconfig | 1 + arch/mips/loongson64/common/dma-swiotlb.c | 21 ++------------------- 4 files changed, 7 insertions(+), 42 deletions(-)
arch/mips/cavium-octeon/Kconfig +1 -0
@@ -75,6 +75,7 @@ config NEED_SG_DMA_LENGTH config SWIOTLB def_bool y + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH
arch/mips/cavium-octeon/dma-octeon.c +3 -23
@@ -159,33 +159,13 @@ static void octeon_dma_sync_sg_for_device(struct device *dev,static void *octeon_dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs) { -void *ret; - -if (IS_ENABLED (CONFIG_ZONE_DMA ) && dev ==NULL ) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA ) && - dev->coherent_dma_mask <=DMA_BIT_MASK (24 )) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA32 ) && - dev->coherent_dma_mask <=DMA_BIT_MASK (32 )) - gfp |= __GFP_DMA32; - -/* Don't invoke OOM killer */ - gfp |= __GFP_NORETRY; - - ret =swiotlb_alloc_coherent (dev, size, dma_handle, gfp); +void *ret =swiotlb_alloc (dev, size, dma_handle, gfp, attrs);mb ();return ret; } -static void octeon_dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle,unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_handle); -} -static dma_addr_t octeon_unity_phys_to_dma (struct device *dev,phys_addr_t paddr) {return paddr;
@@ -225,7 +205,7 @@ EXPORT_SYMBOL(__dma_to_phys);static struct octeon_dma_map_ops octeon_linear_dma_map_ops = { .dma_map_ops = { .alloc = octeon_dma_alloc_coherent, - .free = octeon_dma_free_coherent, + .free = swiotlb_free, .map_page = octeon_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = octeon_dma_map_sg,
@@ -311,7 +291,7 @@ void __init plat_swiotlb_setup(void)static struct octeon_dma_map_ops _octeon_pci_dma_map_ops = { .dma_map_ops = { .alloc = octeon_dma_alloc_coherent, - .free = octeon_dma_free_coherent, + .free = swiotlb_free, .map_page = octeon_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = octeon_dma_map_sg,
arch/mips/loongson64/Kconfig +1 -0
@@ -136,6 +136,7 @@ config SWIOTLB bool "Soft IOMMU Support for All-Memory DMA" default y depends on CPU_LOONGSON3 + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH select NEED_DMA_MAP_STATE
arch/mips/loongson64/common/dma-swiotlb.c +2 -19
@@ -13,29 +13,12 @@static void *loongson_dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs) { -void *ret; +void *ret =swiotlb_alloc (dev, size, dma_handle, gfp, attrs); -if ((IS_ENABLED (CONFIG_ISA ) && dev ==NULL ) || - (IS_ENABLED (CONFIG_ZONE_DMA ) && - dev->coherent_dma_mask <DMA_BIT_MASK (32 ))) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA32 ) && - dev->coherent_dma_mask <DMA_BIT_MASK (40 )) - gfp |= __GFP_DMA32; - - gfp |= __GFP_NORETRY; - - ret =swiotlb_alloc_coherent (dev, size, dma_handle, gfp);mb ();return ret; } -static void loongson_dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle,unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_handle); -} - static dma_addr_t loongson_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,
@@ -106,7 +89,7 @@ phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)static const struct dma_map_ops loongson_dma_map_ops = { .alloc = loongson_dma_alloc_coherent, - .free = loongson_dma_free_coherent, + .free = swiotlb_free, .map_page = loongson_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = loongson_dma_map_sg,
Signature · 1 line
2.14.2
PATCH 63/67 mips: use swiotlb_{alloc,free}
In reply to Christoph HellwigThese already include the GFP_DMA/GFP_DMA32 usage, and will use CMA memory if enabled, thus avoiding the GFP_NORETRY hack.
--- arch/mips/cavium-octeon/Kconfig | 1 + arch/mips/cavium-octeon/dma-octeon.c | 26 +++----------------------- arch/mips/loongson64/Kconfig | 1 + arch/mips/loongson64/common/dma-swiotlb.c | 21 ++------------------- 4 files changed, 7 insertions(+), 42 deletions(-)
arch/mips/cavium-octeon/Kconfig +1 -0
@@ -75,6 +75,7 @@ config NEED_SG_DMA_LENGTH config SWIOTLB def_bool y + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH
arch/mips/cavium-octeon/dma-octeon.c +3 -23
@@ -159,33 +159,13 @@ static void octeon_dma_sync_sg_for_device(struct device *dev,static void *octeon_dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs) { -void *ret; - -if (IS_ENABLED (CONFIG_ZONE_DMA ) && dev ==NULL ) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA ) && - dev->coherent_dma_mask <=DMA_BIT_MASK (24 )) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA32 ) && - dev->coherent_dma_mask <=DMA_BIT_MASK (32 )) - gfp |= __GFP_DMA32; - -/* Don't invoke OOM killer */ - gfp |= __GFP_NORETRY; - - ret =swiotlb_alloc_coherent (dev, size, dma_handle, gfp); +void *ret =swiotlb_alloc (dev, size, dma_handle, gfp, attrs);mb ();return ret; } -static void octeon_dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle,unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_handle); -} -static dma_addr_t octeon_unity_phys_to_dma (struct device *dev,phys_addr_t paddr) {return paddr;
@@ -225,7 +205,7 @@ EXPORT_SYMBOL(__dma_to_phys);static struct octeon_dma_map_ops octeon_linear_dma_map_ops = { .dma_map_ops = { .alloc = octeon_dma_alloc_coherent, - .free = octeon_dma_free_coherent, + .free = swiotlb_free, .map_page = octeon_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = octeon_dma_map_sg,
@@ -311,7 +291,7 @@ void __init plat_swiotlb_setup(void)static struct octeon_dma_map_ops _octeon_pci_dma_map_ops = { .dma_map_ops = { .alloc = octeon_dma_alloc_coherent, - .free = octeon_dma_free_coherent, + .free = swiotlb_free, .map_page = octeon_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = octeon_dma_map_sg,
arch/mips/loongson64/Kconfig +1 -0
@@ -136,6 +136,7 @@ config SWIOTLB bool "Soft IOMMU Support for All-Memory DMA" default y depends on CPU_LOONGSON3 + select DMA_DIRECT_OPS select IOMMU_HELPER select NEED_SG_DMA_LENGTH select NEED_DMA_MAP_STATE
arch/mips/loongson64/common/dma-swiotlb.c +2 -19
@@ -13,29 +13,12 @@static void *loongson_dma_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp,unsigned long attrs) { -void *ret; +void *ret =swiotlb_alloc (dev, size, dma_handle, gfp, attrs); -if ((IS_ENABLED (CONFIG_ISA ) && dev ==NULL ) || - (IS_ENABLED (CONFIG_ZONE_DMA ) && - dev->coherent_dma_mask <DMA_BIT_MASK (32 ))) - gfp |= __GFP_DMA; -else if (IS_ENABLED (CONFIG_ZONE_DMA32 ) && - dev->coherent_dma_mask <DMA_BIT_MASK (40 )) - gfp |= __GFP_DMA32; - - gfp |= __GFP_NORETRY; - - ret =swiotlb_alloc_coherent (dev, size, dma_handle, gfp);mb ();return ret; } -static void loongson_dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle,unsigned long attrs) -{ -swiotlb_free_coherent (dev, size, vaddr, dma_handle); -} - static dma_addr_t loongson_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,
@@ -106,7 +89,7 @@ phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)static const struct dma_map_ops loongson_dma_map_ops = { .alloc = loongson_dma_alloc_coherent, - .free = loongson_dma_free_coherent, + .free = swiotlb_free, .map_page = loongson_dma_map_page, .unmap_page = swiotlb_unmap_page, .map_sg = loongson_dma_map_sg,
Signature · 1 line
2.14.2
PATCH 64/67 arm64: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigarm64 uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/arm64/Kconfig | 2 +- arch/arm64/mm/dma-mapping.c | 6 +++--- arch/arm64/mm/init.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -227,7 +227,7 @@ config GENERIC_CSUM config GENERIC_CALIBRATE_DELAY def_bool y -config ZONE_DMA +config ZONE_DMA32 def_bool y config HAVE_GENERIC_GUP
arch/arm64/mm/dma-mapping.c +3 -3
@@ -95,9 +95,9 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) { - if (IS_ENABLED(CONFIG_ZONE_DMA) && + if (IS_ENABLED(CONFIG_ZONE_DMA32) && dev->coherent_dma_mask <= DMA_BIT_MASK(32)) - flags |= GFP_DMA; + flags |= GFP_DMA32;if (dev_get_cma_area (dev) &&gfpflags_allow_blocking (flags)) {struct page *page;void *addr;
@@ -397,7 +397,7 @@ static int __init atomic_pool_init(void) page =dma_alloc_from_contiguous (NULL , nr_pages, pool_size_order,GFP_KERNEL ); else - page =alloc_pages (GFP_DMA , pool_size_order); + page =alloc_pages (GFP_DMA32 , pool_size_order);if (page) {int ret;
arch/arm64/mm/init.c +8 -8
@@ -217,7 +217,7 @@ static void __init reserve_elfcorehdr(void) }#endif /* CONFIG_CRASH_DUMP */ /* -* Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It +* Return the maximum physical address for ZONE_DMA32 (DMA_BIT_MASK(32)). It * currently assumes that for memory starting above 4G, 32-bit devices will * use a DMA offset. */
@@ -233,8 +233,8 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) {unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; -if (IS_ENABLED (CONFIG_ZONE_DMA )) - max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); +if (IS_ENABLED (CONFIG_ZONE_DMA32 )) + max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (max_zone_dma_phys ()); max_zone_pfns[ZONE_NORMAL ] = max;free_area_init_nodes (max_zone_pfns);
@@ -251,9 +251,9 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)memset (zone_size,0 ,sizeof (zone_size));/* 4GB maximum for 32-bit only capable devices */ -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 max_dma =PFN_DOWN (arm64_dma_phys_limit); - zone_size[ZONE_DMA ] = max_dma - min; + zone_size[ZONE_DMA32 ] = max_dma - min;#endif zone_size[ZONE_NORMAL ] = max - max_dma;
@@ -266,10 +266,10 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)if (start >= max)continue ; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 if (start < max_dma) {unsigned long dma_end =min (end, max_dma); - zhole_size[ZONE_DMA ] -= dma_end - start; + zhole_size[ZONE_DMA32 ] -= dma_end - start; }#endif if (end > max_dma) {
@@ -467,7 +467,7 @@ void __init arm64_memblock_init(void)early_init_fdt_scan_reserved_mem ();/* 4GB maximum for 32-bit only capable devices */ -if (IS_ENABLED (CONFIG_ZONE_DMA )) +if (IS_ENABLED (CONFIG_ZONE_DMA32 )) arm64_dma_phys_limit =max_zone_dma_phys ();else arm64_dma_phys_limit =PHYS_MASK +1 ;
Signature · 1 line
2.14.2
PATCH 64/67 arm64: replace ZONE_DMA with ZONE_DMA32
In reply to Christoph Hellwigarm64 uses ZONE_DMA for allocations below 32-bits. These days we name the zone for that ZONE_DMA32, which will allow to use the dma-direct and generic swiotlb code as-is, so rename it.
--- arch/arm64/Kconfig | 2 +- arch/arm64/mm/dma-mapping.c | 6 +++--- arch/arm64/mm/init.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -227,7 +227,7 @@ config GENERIC_CSUM config GENERIC_CALIBRATE_DELAY def_bool y -config ZONE_DMA +config ZONE_DMA32 def_bool y config HAVE_GENERIC_GUP
arch/arm64/mm/dma-mapping.c +3 -3
@@ -95,9 +95,9 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) { - if (IS_ENABLED(CONFIG_ZONE_DMA) && + if (IS_ENABLED(CONFIG_ZONE_DMA32) && dev->coherent_dma_mask <= DMA_BIT_MASK(32)) - flags |= GFP_DMA; + flags |= GFP_DMA32;if (dev_get_cma_area (dev) &&gfpflags_allow_blocking (flags)) {struct page *page;void *addr;
@@ -397,7 +397,7 @@ static int __init atomic_pool_init(void) page =dma_alloc_from_contiguous (NULL , nr_pages, pool_size_order,GFP_KERNEL ); else - page =alloc_pages (GFP_DMA , pool_size_order); + page =alloc_pages (GFP_DMA32 , pool_size_order);if (page) {int ret;
arch/arm64/mm/init.c +8 -8
@@ -217,7 +217,7 @@ static void __init reserve_elfcorehdr(void) }#endif /* CONFIG_CRASH_DUMP */ /* -* Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It +* Return the maximum physical address for ZONE_DMA32 (DMA_BIT_MASK(32)). It * currently assumes that for memory starting above 4G, 32-bit devices will * use a DMA offset. */
@@ -233,8 +233,8 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) {unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; -if (IS_ENABLED (CONFIG_ZONE_DMA )) - max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_dma_phys ()); +if (IS_ENABLED (CONFIG_ZONE_DMA32 )) + max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (max_zone_dma_phys ()); max_zone_pfns[ZONE_NORMAL ] = max;free_area_init_nodes (max_zone_pfns);
@@ -251,9 +251,9 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)memset (zone_size,0 ,sizeof (zone_size));/* 4GB maximum for 32-bit only capable devices */ -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 max_dma =PFN_DOWN (arm64_dma_phys_limit); - zone_size[ZONE_DMA ] = max_dma - min; + zone_size[ZONE_DMA32 ] = max_dma - min;#endif zone_size[ZONE_NORMAL ] = max - max_dma;
@@ -266,10 +266,10 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)if (start >= max)continue ; -#ifdef CONFIG_ZONE_DMA +#ifdef CONFIG_ZONE_DMA32 if (start < max_dma) {unsigned long dma_end =min (end, max_dma); - zhole_size[ZONE_DMA ] -= dma_end - start; + zhole_size[ZONE_DMA32 ] -= dma_end - start; }#endif if (end > max_dma) {
@@ -467,7 +467,7 @@ void __init arm64_memblock_init(void)early_init_fdt_scan_reserved_mem ();/* 4GB maximum for 32-bit only capable devices */ -if (IS_ENABLED (CONFIG_ZONE_DMA )) +if (IS_ENABLED (CONFIG_ZONE_DMA32 )) arm64_dma_phys_limit =max_zone_dma_phys ();else arm64_dma_phys_limit =PHYS_MASK +1 ;
Signature · 1 line
2.14.2
PATCH 65/67 arm64: use swiotlb_alloc and swiotlb_free
In reply to Christoph HellwigThe generic swiotlb_alloc and swiotlb_free routines already take care of CMA allocations and adding GFP_DMA32 where needed, so use them instead of the arm specific helpers.
--- arch/arm64/Kconfig | 1 + arch/arm64/mm/dma-mapping.c | 46 +++------------------------------------------ 2 files changed, 4 insertions(+), 43 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -59,6 +59,7 @@ config ARM64 select COMMON_CLK select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS + select DMA_DIRECT_OPS select EDAC_SUPPORT select FRAME_POINTER select GENERIC_ALLOCATOR
arch/arm64/mm/dma-mapping.c +3 -43
70 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 65/67 arm64: use swiotlb_alloc and swiotlb_free
In reply to Christoph HellwigThe generic swiotlb_alloc and swiotlb_free routines already take care of CMA allocations and adding GFP_DMA32 where needed, so use them instead of the arm specific helpers.
--- arch/arm64/Kconfig | 1 + arch/arm64/mm/dma-mapping.c | 46 +++------------------------------------------ 2 files changed, 4 insertions(+), 43 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -59,6 +59,7 @@ config ARM64 select COMMON_CLK select CPU_PM if (SUSPEND || CPU_IDLE) select DCACHE_WORD_ACCESS + select DMA_DIRECT_OPS select EDAC_SUPPORT select FRAME_POINTER select GENERIC_ALLOCATOR
arch/arm64/mm/dma-mapping.c +3 -43
70 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 66/67 swiotlb: remove swiotlb_{alloc,free}_coherent
In reply to Christoph HellwigUnused now that everyone uses swiotlb_{alloc,free}.
--- include/linux/swiotlb.h | 8 -------- lib/swiotlb.c | 41 ----------------------------------------- 2 files changed, 49 deletions(-)
include/linux/swiotlb.h +0 -8
@@ -72,14 +72,6 @@ void *swiotlb_alloc(struct device *hwdev, size_t size, dma_addr_t *dma_handle,void swiotlb_free (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_addr,unsigned long attrs); -extern void -*swiotlb_alloc_coherent (struct device *hwdev,size_t size, -dma_addr_t *dma_handle,gfp_t flags); - -extern void -swiotlb_free_coherent (struct device *hwdev,size_t size, -void *vaddr,dma_addr_t dma_handle); - extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,
lib/swiotlb.c +0 -41
59 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 66/67 swiotlb: remove swiotlb_{alloc,free}_coherent
In reply to Christoph HellwigUnused now that everyone uses swiotlb_{alloc,free}.
--- include/linux/swiotlb.h | 8 -------- lib/swiotlb.c | 41 ----------------------------------------- 2 files changed, 49 deletions(-)
include/linux/swiotlb.h +0 -8
@@ -72,14 +72,6 @@ void *swiotlb_alloc(struct device *hwdev, size_t size, dma_addr_t *dma_handle,void swiotlb_free (struct device *dev,size_t size,void *vaddr,dma_addr_t dma_addr,unsigned long attrs); -extern void -*swiotlb_alloc_coherent (struct device *hwdev,size_t size, -dma_addr_t *dma_handle,gfp_t flags); - -extern void -swiotlb_free_coherent (struct device *hwdev,size_t size, -void *vaddr,dma_addr_t dma_handle); - extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir,
lib/swiotlb.c +0 -41
59 lines not on this page · raw message
Signature · 1 line
2.14.2
PATCH 67/67 swiotlb: remove various exports
In reply to Christoph HellwigAll these symbols are only used by arch dma_ops implementations or xen-swiotlb. None of which can be modular.
--- lib/swiotlb.c | 13 ------------- 1 file changed, 13 deletions(-)
lib/swiotlb.c +0 -13
@@ -591,7 +591,6 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,return tlb_addr; } -EXPORT_SYMBOL_GPL (swiotlb_tbl_map_single);/* * Allocates bounce buffer and returns its kernel virtual address.
@@ -661,7 +660,6 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, }spin_unlock_irqrestore (&io_tlb_lock, flags); } -EXPORT_SYMBOL_GPL (swiotlb_tbl_unmap_single); void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, size_t size, enum dma_data_direction dir,
@@ -693,7 +691,6 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,BUG (); } } -EXPORT_SYMBOL_GPL (swiotlb_tbl_sync_single);static void *swiotlb_alloc_buffer (struct device *dev,size_t size,dma_addr_t *dma_handle)
@@ -827,7 +824,6 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,return __phys_to_dma (dev, io_tlb_overflow_buffer); } -EXPORT_SYMBOL_GPL (swiotlb_map_page);/* * Unmap a single streaming mode DMA translation. The dma_addr and size must
@@ -868,7 +864,6 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, {unmap_single (hwdev, dev_addr, size, dir, attrs); } -EXPORT_SYMBOL_GPL (swiotlb_unmap_page);/* * Make physical memory consistent for a single streaming mode DMA translation
@@ -906,7 +901,6 @@ swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, {swiotlb_sync_single (hwdev, dev_addr, size, dir,SYNC_FOR_CPU ); } -EXPORT_SYMBOL (swiotlb_sync_single_for_cpu); void swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
@@ -914,7 +908,6 @@ swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, {swiotlb_sync_single (hwdev, dev_addr, size, dir,SYNC_FOR_DEVICE ); } -EXPORT_SYMBOL (swiotlb_sync_single_for_device);/* * Map a set of buffers described by scatterlist in streaming mode for DMA.
@@ -966,7 +959,6 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems, }return nelems; } -EXPORT_SYMBOL (swiotlb_map_sg_attrs);/* * Unmap a set of streaming mode DMA translations. Again, cpu read rules
@@ -986,7 +978,6 @@ swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,unmap_single (hwdev, sg->dma_address,sg_dma_len (sg), dir, attrs); } -EXPORT_SYMBOL (swiotlb_unmap_sg_attrs);/* * Make physical memory consistent for a set of streaming mode DMA translations
@@ -1014,7 +1005,6 @@ swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, {swiotlb_sync_sg (hwdev, sg, nelems, dir,SYNC_FOR_CPU ); } -EXPORT_SYMBOL (swiotlb_sync_sg_for_cpu); void swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
@@ -1022,14 +1012,12 @@ swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, {swiotlb_sync_sg (hwdev, sg, nelems, dir,SYNC_FOR_DEVICE ); } -EXPORT_SYMBOL (swiotlb_sync_sg_for_device);int swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr) {return (dma_addr ==__phys_to_dma (hwdev, io_tlb_overflow_buffer)); } -EXPORT_SYMBOL (swiotlb_dma_mapping_error);/* * Return whether the given device DMA address mask can be supported
@@ -1042,7 +1030,6 @@ swiotlb_dma_supported(struct device *hwdev, u64 mask) {return __phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; } -EXPORT_SYMBOL (swiotlb_dma_supported);#ifdef CONFIG_DMA_DIRECT_OPS void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
Signature · 1 line
2.14.2
PATCH 67/67 swiotlb: remove various exports
In reply to Christoph HellwigAll these symbols are only used by arch dma_ops implementations or xen-swiotlb. None of which can be modular.
--- lib/swiotlb.c | 13 ------------- 1 file changed, 13 deletions(-)
lib/swiotlb.c +0 -13
@@ -591,7 +591,6 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,return tlb_addr; } -EXPORT_SYMBOL_GPL (swiotlb_tbl_map_single);/* * Allocates bounce buffer and returns its kernel virtual address.
@@ -661,7 +660,6 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, }spin_unlock_irqrestore (&io_tlb_lock, flags); } -EXPORT_SYMBOL_GPL (swiotlb_tbl_unmap_single); void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, size_t size, enum dma_data_direction dir,
@@ -693,7 +691,6 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,BUG (); } } -EXPORT_SYMBOL_GPL (swiotlb_tbl_sync_single);static void *swiotlb_alloc_buffer (struct device *dev,size_t size,dma_addr_t *dma_handle)
@@ -827,7 +824,6 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,return __phys_to_dma (dev, io_tlb_overflow_buffer); } -EXPORT_SYMBOL_GPL (swiotlb_map_page);/* * Unmap a single streaming mode DMA translation. The dma_addr and size must
@@ -868,7 +864,6 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, {unmap_single (hwdev, dev_addr, size, dir, attrs); } -EXPORT_SYMBOL_GPL (swiotlb_unmap_page);/* * Make physical memory consistent for a single streaming mode DMA translation
@@ -906,7 +901,6 @@ swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, {swiotlb_sync_single (hwdev, dev_addr, size, dir,SYNC_FOR_CPU ); } -EXPORT_SYMBOL (swiotlb_sync_single_for_cpu); void swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
@@ -914,7 +908,6 @@ swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, {swiotlb_sync_single (hwdev, dev_addr, size, dir,SYNC_FOR_DEVICE ); } -EXPORT_SYMBOL (swiotlb_sync_single_for_device);/* * Map a set of buffers described by scatterlist in streaming mode for DMA.
@@ -966,7 +959,6 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems, }return nelems; } -EXPORT_SYMBOL (swiotlb_map_sg_attrs);/* * Unmap a set of streaming mode DMA translations. Again, cpu read rules
@@ -986,7 +978,6 @@ swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,unmap_single (hwdev, sg->dma_address,sg_dma_len (sg), dir, attrs); } -EXPORT_SYMBOL (swiotlb_unmap_sg_attrs);/* * Make physical memory consistent for a set of streaming mode DMA translations
@@ -1014,7 +1005,6 @@ swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, {swiotlb_sync_sg (hwdev, sg, nelems, dir,SYNC_FOR_CPU ); } -EXPORT_SYMBOL (swiotlb_sync_sg_for_cpu); void swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
@@ -1022,14 +1012,12 @@ swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, {swiotlb_sync_sg (hwdev, sg, nelems, dir,SYNC_FOR_DEVICE ); } -EXPORT_SYMBOL (swiotlb_sync_sg_for_device);int swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr) {return (dma_addr ==__phys_to_dma (hwdev, io_tlb_overflow_buffer)); } -EXPORT_SYMBOL (swiotlb_dma_mapping_error);/* * Return whether the given device DMA address mask can be supported
@@ -1042,7 +1030,6 @@ swiotlb_dma_supported(struct device *hwdev, u64 mask) {return __phys_to_dma (hwdev, io_tlb_end -1 ) <= mask; } -EXPORT_SYMBOL (swiotlb_dma_supported);#ifdef CONFIG_DMA_DIRECT_OPS void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
Signature · 1 line
2.14.2
Quoted 11 lines · Christoph Hellwig
Almost every architecture supports a direct dma mapping implementation, where no iommu is used and the device dma address is a 1:1 mapping to the physical address or has a simple linear offset. Currently the code for this implementation is most duplicated over the architectures, and the duplicated again in the swiotlb code, and then duplicated again for special cases like the x86 memory encryption DMA ops.
This series takes the existing very simple dma-noop dma mapping implementation, enhances it with all the x86 features and quirks, and creates a common set of architecture hooks for it and the swiotlb code.
Quoted 6 lines
It then switches a large number of architectures to this generic direct map implement and the new generic swiotlb
dma_mapops.Note that for now this only handles architectures that do cache coherent DMA, but a similar consolidation for non-coherent architectures is in the work for later merge windows.
Is it available in your dma-mapping.git or somewhere else?
Cheers
Vladimir
Quoted 6 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 1 line · Vladimir Murzin
Is it available in your dma-mapping.git or somewhere else?
git://git.infradead.org/users/hch/misc.git dma-direct
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/dma-direct
Quoted 1 line · Vladimir Murzin
Is it available in your dma-mapping.git or somewhere else?
git://git.infradead.org/users/hch/misc.git dma-direct
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/dma-direct