dma-mapping.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. * Author: Catalin Marinas <catalin.marinas@arm.com>
  5. */
  6. #include <linux/gfp.h>
  7. #include <linux/cache.h>
  8. #include <linux/dma-map-ops.h>
  9. #include <linux/dma-iommu.h>
  10. #include <xen/xen.h>
  11. #include <xen/swiotlb-xen.h>
  12. #include <trace/hooks/iommu.h>
  13. #include <asm/cacheflush.h>
  14. void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
  15. enum dma_data_direction dir)
  16. {
  17. __dma_map_area(phys_to_virt(paddr), size, dir);
  18. }
  19. void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
  20. enum dma_data_direction dir)
  21. {
  22. __dma_unmap_area(phys_to_virt(paddr), size, dir);
  23. }
  24. void arch_dma_prep_coherent(struct page *page, size_t size)
  25. {
  26. __dma_flush_area(page_address(page), size);
  27. }
  28. #ifdef CONFIG_IOMMU_DMA
  29. void arch_teardown_dma_ops(struct device *dev)
  30. {
  31. dev->dma_ops = NULL;
  32. }
  33. #endif
  34. void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
  35. const struct iommu_ops *iommu, bool coherent)
  36. {
  37. int cls = cache_line_size_of_cpu();
  38. WARN_TAINT(!coherent && cls > ARCH_DMA_MINALIGN,
  39. TAINT_CPU_OUT_OF_SPEC,
  40. "%s %s: ARCH_DMA_MINALIGN smaller than CTR_EL0.CWG (%d < %d)",
  41. dev_driver_string(dev), dev_name(dev),
  42. ARCH_DMA_MINALIGN, cls);
  43. dev->dma_coherent = coherent;
  44. if (iommu) {
  45. iommu_setup_dma_ops(dev, dma_base, size);
  46. trace_android_vh_iommu_setup_dma_ops(dev, dma_base, size);
  47. trace_android_rvh_iommu_setup_dma_ops(dev, dma_base, size);
  48. }
  49. #ifdef CONFIG_XEN
  50. if (xen_initial_domain())
  51. dev->dma_ops = &xen_swiotlb_dma_ops;
  52. #endif
  53. }