msm_mmu.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. int (*set_attribute)(struct msm_mmu *mmu,
  49. enum iommu_attr attr, void *data);
  50. int (*one_to_one_map)(struct msm_mmu *mmu, uint32_t iova,
  51. uint32_t dest_address, uint32_t size, int prot);
  52. int (*one_to_one_unmap)(struct msm_mmu *mmu, uint32_t dest_address,
  53. uint32_t size);
  54. struct device *(*get_dev)(struct msm_mmu *mmu);
  55. };
  56. struct msm_mmu {
  57. const struct msm_mmu_funcs *funcs;
  58. struct device *dev;
  59. int (*handler)(void *arg, unsigned long iova, int flags);
  60. void *arg;
  61. };
  62. static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev,
  63. const struct msm_mmu_funcs *funcs)
  64. {
  65. mmu->dev = dev;
  66. mmu->funcs = funcs;
  67. }
  68. struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain);
  69. struct msm_mmu *msm_smmu_new(struct device *dev,
  70. enum msm_mmu_domain_type domain);
  71. static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg,
  72. int (*handler)(void *arg, unsigned long iova, int flags))
  73. {
  74. mmu->arg = arg;
  75. mmu->handler = handler;
  76. }
  77. /* SDE smmu driver initialize and cleanup functions */
  78. int __init msm_smmu_driver_init(void);
  79. void __exit msm_smmu_driver_cleanup(void);
  80. #endif /* __MSM_MMU_H__ */