XEN SWIOTLB dma operations extension
Subsystems (4)
v4 cover XEN SWIOTLB dma operations extension
From: Andrii Anisov <[email protected]>
Some drivers need additional dma ops to be provided by xen swiotlb. Because common operations implementation came from x86 world and does not suite ARM needs we have to provide needed XEN SWIOTLB for ARM callbacks.
dma_mmap patch is a port of an antique and lost patch discussed here:
http://marc.info/?l=xen-devel&m=139695901430667&w=4
Changes in V4:
- No functional changes
- '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad insisted
- Added more comments for the functions added and for the debug code
- fixed code alignment.
Changes in V3:
- dma ops are moved from ARM specific to generic code
- runtime operation verified for arm64 with LK 4.9
- compilation verified for arm, arm64, x86 with the current LK master HEAD 566cf877a1fcb6d6dc0126b076aad062054c2637
Changes in V2:
- patches are rebased and checked for compilation for x86, arm, arm64 with the current LK master HEAD 83346fbc07d267de777e2597552f785174ad0373
Andrii Anisov (1):
swiotlb-xen: implement xen_swiotlb_get_sgtable callback
Stefano Stabellini (1):
swiotlb-xen: implement xen_swiotlb_dma_mmap callback
arch/arm/xen/mm.c | 2 ++ drivers/xen/swiotlb-xen.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/xen/swiotlb-xen.h | 11 +++++++++++ 3 files changed, 60 insertions(+)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 1/2 swiotlb-xen: implement xen_swiotlb_dma_mmap callback
From: Stefano Stabellini <[email protected]>
This function creates userspace mapping for the DMA-coherent memory.
--- arch/arm/xen/mm.c | 1 + drivers/xen/swiotlb-xen.c | 19 +++++++++++++++++++ include/xen/swiotlb-xen.h | 5 +++++ 3 files changed, 25 insertions(+)
arch/arm/xen/mm.c +1 -0
@@ -198,6 +198,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = { .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, .set_dma_mask = xen_swiotlb_set_dma_mask, + .mmap = xen_swiotlb_dma_mmap, };int __init xen_mm_init (void )
drivers/xen/swiotlb-xen.c +19 -0
@@ -681,3 +681,22 @@ xen_swiotlb_set_dma_mask(struct device *dev, u64 dma_mask)return 0 ; }EXPORT_SYMBOL_GPL (xen_swiotlb_set_dma_mask); + +/* +* Create userspace mapping for the DMA-coherent memory. +* This function should be called with the pages from the current domain only, +* passing pages mapped from other domains would lead to memory corruption. +*/ +int +xen_swiotlb_dma_mmap (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t dma_addr,size_t size, +unsigned long attrs) +{ +#if defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) +if (__generic_dma_ops (dev)->mmap) +return __generic_dma_ops (dev)->mmap (dev, vma, cpu_addr, + dma_addr, size, attrs); +#endif +return dma_common_mmap (dev, vma, cpu_addr, dma_addr, size); +} +EXPORT_SYMBOL_GPL (xen_swiotlb_dma_mmap);
include/xen/swiotlb-xen.h +5 -0
@@ -55,4 +55,9 @@ xen_swiotlb_dma_supported(struct device *hwdev, u64 mask);extern int xen_swiotlb_set_dma_mask (struct device *dev,u64 dma_mask); + +extern int +xen_swiotlb_dma_mmap (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t dma_addr,size_t size, +unsigned long attrs);#endif /* __LINUX_SWIOTLB_XEN_H */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 2/2 swiotlb-xen: implement xen_swiotlb_get_sgtable callback
In reply to Andrii AnisovFrom: Andrii Anisov <[email protected]>
--- arch/arm/xen/mm.c | 1 + drivers/xen/swiotlb-xen.c | 28 ++++++++++++++++++++++++++++ include/xen/swiotlb-xen.h | 6 ++++++ 3 files changed, 35 insertions(+)
arch/arm/xen/mm.c +1 -0
@@ -199,6 +199,7 @@ static struct dma_map_ops xen_swiotlb_dma_ops = { .dma_supported = xen_swiotlb_dma_supported, .set_dma_mask = xen_swiotlb_set_dma_mask, .mmap = xen_swiotlb_dma_mmap, + .get_sgtable = xen_swiotlb_get_sgtable, };int __init xen_mm_init (void )
drivers/xen/swiotlb-xen.c +28 -0
@@ -700,3 +700,31 @@ xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma,return dma_common_mmap (dev, vma, cpu_addr, dma_addr, size); }EXPORT_SYMBOL_GPL (xen_swiotlb_dma_mmap); + +/* +* This function should be called with the pages from the current domain only, +* passing pages mapped from other domains would lead to memory corruption. +*/ +int +xen_swiotlb_get_sgtable (struct device *dev,struct sg_table *sgt, +void *cpu_addr,dma_addr_t handle,size_t size, +unsigned long attrs) +{ +#if defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) +if (__generic_dma_ops (dev)->get_sgtable) { +#if 0 +/* +* This check verifies that the page belongs to the current domain and +* is not one mapped from another domain. +* This check is for debug only, and should not go to production build +*/ +unsigned long bfn =PHYS_PFN (dma_to_phys (dev, handle)); +BUG_ON (!page_is_ram (bfn)); +#endif +return __generic_dma_ops (dev)->get_sgtable (dev, sgt, cpu_addr, + handle, size, attrs); + } +#endif +return dma_common_get_sgtable (dev, sgt, cpu_addr, handle, size); +} +EXPORT_SYMBOL_GPL (xen_swiotlb_get_sgtable);
include/xen/swiotlb-xen.h +6 -0
@@ -2,6 +2,7 @@#define __LINUX_SWIOTLB_XEN_H#include <linux/dma-direction.h> +#include <linux/scatterlist.h> #include <linux/swiotlb.h> extern int xen_swiotlb_init (int verbose,bool early);
@@ -60,4 +61,9 @@ extern int xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs); + +extern int +xen_swiotlb_get_sgtable (struct device *dev,struct sg_table *sgt, +void *cpu_addr,dma_addr_t handle,size_t size, +unsigned long attrs);#endif /* __LINUX_SWIOTLB_XEN_H */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Stefano Stabellini
maintainerBoth patches are fine by me.
Quoted 29 lines · Andrii Anisov
From: Andrii Anisov <[email protected]>
Some drivers need additional dma ops to be provided by xen swiotlb. Because common operations implementation came from x86 world and does not suite ARM needs we have to provide needed XEN SWIOTLB for ARM callbacks.
dma_mmappatch is a port of an antique and lost patch discussed here:
http://marc.info/?l=xen-devel&m=139695901430667&w=4Changes in V4:
- No functional changes
- '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad insisted
- Added more comments for the functions added and for the debug code
- fixed code alignment.Changes in V3:
- dma ops are moved from ARM specific to generic code
- runtime operation verified for arm64 with LK 4.9
- compilation verified for arm, arm64, x86 with the current LK master HEAD566cf877a1fcb6d6dc0126b076aad062054c2637Changes in V2:
- patches are rebased and checked for compilation for x86, arm, arm64 with the current LK master HEAD83346fbc07d267de777e2597552f785174ad0373Andrii Anisov (1):
swiotlb-xen: implementxen_swiotlb_get_sgtablecallback
Quoted 11 lines
Stefano Stabellini (1):
swiotlb-xen: implementxen_swiotlb_dma_mmapcallbackarch/arm/xen/mm.c | 2 ++ drivers/xen/swiotlb-xen.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/xen/swiotlb-xen.h | 11 +++++++++++ 3 files changed, 60 insertions(+)Signature · 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Konrad,
Any comments?
Sincerely,
Andrii Anisov.
Quoted 32 lines · Andrii Anisov
From: Andrii Anisov <[email protected]>
Some drivers need additional dma ops to be provided by xen swiotlb. Because common operations implementation came from x86 world and does not suite ARM needs we have to provide needed XEN SWIOTLB for ARM callbacks.
dma_mmappatch is a port of an antique and lost patch discussed here:
http://marc.info/?l=xen-devel&m=139695901430667&w=4Changes in V4:
- No functional changes
- '#ifdef DEBUG' is replaced with '#if 0' for a debug code because Konrad insisted
- Added more comments for the functions added and for the debug code
- fixed code alignment.Changes in V3:
- dma ops are moved from ARM specific to generic code
- runtime operation verified for arm64 with LK 4.9
- compilation verified for arm, arm64, x86 with the current LK master HEAD566cf877a1fcb6d6dc0126b076aad062054c2637Changes in V2:
- patches are rebased and checked for compilation for x86, arm, arm64 with the current LK master HEAD83346fbc07d267de777e2597552f785174ad0373Andrii Anisov (1):
swiotlb-xen: implementxen_swiotlb_get_sgtablecallbackStefano Stabellini (1):
swiotlb-xen: implementxen_swiotlb_dma_mmapcallback
Quoted 10 lines
arch/arm/xen/mm.c | 2 ++ drivers/xen/swiotlb-xen.c | 47 ++++++++++++++++++++++++++++++ +++++++++++++++++ include/xen/swiotlb-xen.h | 11 +++++++++++ 3 files changed, 60 insertions(+)--
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel