qcom-dma-iommu-generic.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __QCOM_DMA_IOMMU_GENERIC_H
  6. #define __QCOM_DMA_IOMMU_GENERIC_H
  7. #include <linux/device.h>
  8. #include <linux/dma-direction.h>
  9. #include <linux/pci.h>
  10. #ifdef CONFIG_IOMMU_IO_PGTABLE_FAST
  11. bool qcom_dma_iommu_is_ready(void);
  12. extern int __init qcom_dma_iommu_generic_driver_init(void);
  13. extern void qcom_dma_iommu_generic_driver_exit(void);
  14. struct pci_host_bridge *qcom_pci_find_host_bridge(struct pci_bus *bus);
  15. void qcom_arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
  16. enum dma_data_direction dir);
  17. void qcom_arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
  18. enum dma_data_direction dir);
  19. void qcom_arch_dma_prep_coherent(struct page *page, size_t size);
  20. /* kernel/dma/contiguous.c */
  21. struct page *qcom_dma_alloc_from_contiguous(struct device *dev, size_t count,
  22. unsigned int align, bool no_warn);
  23. bool qcom_dma_release_from_contiguous(struct device *dev, struct page *pages,
  24. int count);
  25. struct page *qcom_dma_alloc_contiguous(struct device *dev, size_t size,
  26. gfp_t gfp);
  27. void qcom_dma_free_contiguous(struct device *dev, struct page *page,
  28. size_t size);
  29. /* kernel/dma/remap.c */
  30. struct page **qcom_dma_common_find_pages(void *cpu_addr);
  31. void *qcom_dma_common_pages_remap(struct page **pages, size_t size,
  32. pgprot_t prot, const void *caller);
  33. void *qcom_dma_common_contiguous_remap(struct page *page, size_t size,
  34. pgprot_t prot, const void *caller);
  35. void qcom_dma_common_free_remap(void *cpu_addr, size_t size);
  36. void *qcom_dma_alloc_from_pool(struct device *dev, size_t size,
  37. struct page **ret_page, gfp_t flags);
  38. bool qcom_dma_free_from_pool(struct device *dev, void *start, size_t size);
  39. int qcom_dma_mmap_from_dev_coherent(struct device *dev,
  40. struct vm_area_struct *vma, void *vaddr, size_t size, int *ret);
  41. /* kernel/dma/mapping.c */
  42. pgprot_t qcom_dma_pgprot(struct device *dev, pgprot_t prot,
  43. unsigned long attrs);
  44. /* DMA-IOMMU utilities */
  45. int qcom_dma_info_to_prot(enum dma_data_direction dir, bool coherent,
  46. unsigned long attrs);
  47. size_t qcom_iommu_dma_prepare_map_sg(struct device *dev, struct iova_domain *iovad,
  48. struct scatterlist *sg, int nents);
  49. int qcom_iommu_dma_finalise_sg(struct device *dev, struct scatterlist *sg, int nents,
  50. dma_addr_t dma_addr);
  51. void qcom_iommu_dma_invalidate_sg(struct scatterlist *sg, int nents);
  52. int qcom_iommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
  53. void *cpu_addr, dma_addr_t dma_addr, size_t size,
  54. unsigned long attrs);
  55. int qcom_iommu_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
  56. void *cpu_addr, dma_addr_t dma_addr, size_t size,
  57. unsigned long attrs);
  58. #else /*CONFIG_IOMMU_IO_PGTABLE_FAST*/
  59. static inline bool qcom_dma_iommu_is_ready(void)
  60. {
  61. return true;
  62. }
  63. static inline int __init qcom_dma_iommu_generic_driver_init(void)
  64. {
  65. return 0;
  66. }
  67. static inline void qcom_dma_iommu_generic_driver_exit(void) {}
  68. #endif /*CONFIG_IOMMU_IO_PGTABLE_FAST*/
  69. #endif /* __QCOM_DMA_IOMMU_GENERIC_H */