diff options
Diffstat (limited to 'drivers/xen/swiotlb-xen.c')
-rw-r--r-- | drivers/xen/swiotlb-xen.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index f8afc6dcc29f..e8cef1ad0fe3 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c | |||
@@ -681,3 +681,50 @@ xen_swiotlb_set_dma_mask(struct device *dev, u64 dma_mask) | |||
681 | return 0; | 681 | return 0; |
682 | } | 682 | } |
683 | EXPORT_SYMBOL_GPL(xen_swiotlb_set_dma_mask); | 683 | EXPORT_SYMBOL_GPL(xen_swiotlb_set_dma_mask); |
684 | |||
685 | /* | ||
686 | * Create userspace mapping for the DMA-coherent memory. | ||
687 | * This function should be called with the pages from the current domain only, | ||
688 | * passing pages mapped from other domains would lead to memory corruption. | ||
689 | */ | ||
690 | int | ||
691 | xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, | ||
692 | void *cpu_addr, dma_addr_t dma_addr, size_t size, | ||
693 | unsigned long attrs) | ||
694 | { | ||
695 | #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) | ||
696 | if (__generic_dma_ops(dev)->mmap) | ||
697 | return __generic_dma_ops(dev)->mmap(dev, vma, cpu_addr, | ||
698 | dma_addr, size, attrs); | ||
699 | #endif | ||
700 | return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); | ||
701 | } | ||
702 | EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mmap); | ||
703 | |||
704 | /* | ||
705 | * This function should be called with the pages from the current domain only, | ||
706 | * passing pages mapped from other domains would lead to memory corruption. | ||
707 | */ | ||
708 | int | ||
709 | xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, | ||
710 | void *cpu_addr, dma_addr_t handle, size_t size, | ||
711 | unsigned long attrs) | ||
712 | { | ||
713 | #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) | ||
714 | if (__generic_dma_ops(dev)->get_sgtable) { | ||
715 | #if 0 | ||
716 | /* | ||
717 | * This check verifies that the page belongs to the current domain and | ||
718 | * is not one mapped from another domain. | ||
719 | * This check is for debug only, and should not go to production build | ||
720 | */ | ||
721 | unsigned long bfn = PHYS_PFN(dma_to_phys(dev, handle)); | ||
722 | BUG_ON (!page_is_ram(bfn)); | ||
723 | #endif | ||
724 | return __generic_dma_ops(dev)->get_sgtable(dev, sgt, cpu_addr, | ||
725 | handle, size, attrs); | ||
726 | } | ||
727 | #endif | ||
728 | return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size); | ||
729 | } | ||
730 | EXPORT_SYMBOL_GPL(xen_swiotlb_get_sgtable); | ||