msm_mmu.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <[email protected]>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __MSM_MMU_H__
  18. #define __MSM_MMU_H__
  19. #include <linux/iommu.h>
  20. #include <linux/qcom-iommu-util.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/dma-map-ops.h>
  23. struct msm_mmu;
  24. enum msm_mmu_domain_type {
  25. MSM_SMMU_DOMAIN_UNSECURE,
  26. MSM_SMMU_DOMAIN_NRT_UNSECURE,
  27. MSM_SMMU_DOMAIN_SECURE,
  28. MSM_SMMU_DOMAIN_NRT_SECURE,
  29. MSM_SMMU_DOMAIN_MAX,
  30. };
  31. struct msm_mmu_funcs {
  32. int (*attach)(struct msm_mmu *mmu, const char * const *names, int cnt);
  33. void (*detach)(struct msm_mmu *mmu, const char * const *names, int cnt);
  34. int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
  35. unsigned int len, int prot);
  36. int (*unmap)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
  37. unsigned int len);
  38. int (*map_sg)(struct msm_mmu *mmu, struct sg_table *sgt,
  39. enum dma_data_direction dir);
  40. void (*unmap_sg)(struct msm_mmu *mmu, struct sg_table *sgt,
  41. enum dma_data_direction dir);
  42. int (*map_dma_buf)(struct msm_mmu *mmu, struct sg_table *sgt,
  43. int dir, u32 flags);
  44. void (*unmap_dma_buf)(struct msm_mmu *mmu, struct sg_table *sgt,
  45. int dir, u32 flags);
  46. void (*destroy)(struct msm_mmu *mmu);
  47. bool (*is_domain_secure)(struct msm_mmu *mmu);
  48. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  49. int (*enable_smmu_translations)(struct msm_mmu *mmu);
  50. #else
  51. int (*set_attribute)(struct msm_mmu *mmu,
  52. enum iommu_attr attr, void *data);
  53. #endif
  54. int (*one_to_one_map)(struct msm_mmu *mmu, uint32_t iova,
  55. uint32_t dest_address, uint32_t size, int prot);
  56. int (*one_to_one_unmap)(struct msm_mmu *mmu, uint32_t dest_address,
  57. uint32_t size);
  58. struct device *(*get_dev)(struct msm_mmu *mmu);
  59. };
  60. struct msm_mmu {
  61. const struct msm_mmu_funcs *funcs;
  62. struct device *dev;
  63. int (*handler)(void *arg, unsigned long iova, int flags);
  64. void *arg;
  65. };
  66. static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev,
  67. const struct msm_mmu_funcs *funcs)
  68. {
  69. mmu->dev = dev;
  70. mmu->funcs = funcs;
  71. }
  72. struct msm_mmu *msm_smmu_new(struct device *dev,
  73. enum msm_mmu_domain_type domain);
  74. /* SDE smmu driver initialize and cleanup functions */
  75. int __init msm_smmu_driver_init(void);
  76. void __exit msm_smmu_driver_cleanup(void);
  77. #endif /* __MSM_MMU_H__ */