msm_mmu.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. struct msm_mmu;
  21. enum msm_mmu_domain_type {
  22. MSM_SMMU_DOMAIN_UNSECURE,
  23. MSM_SMMU_DOMAIN_NRT_UNSECURE,
  24. MSM_SMMU_DOMAIN_SECURE,
  25. MSM_SMMU_DOMAIN_NRT_SECURE,
  26. MSM_SMMU_DOMAIN_MAX,
  27. };
  28. struct msm_mmu_funcs {
  29. int (*attach)(struct msm_mmu *mmu, const char * const *names, int cnt);
  30. void (*detach)(struct msm_mmu *mmu, const char * const *names, int cnt);
  31. int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
  32. unsigned int len, int prot);
  33. int (*unmap)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
  34. unsigned int len);
  35. int (*map_sg)(struct msm_mmu *mmu, struct sg_table *sgt,
  36. enum dma_data_direction dir);
  37. void (*unmap_sg)(struct msm_mmu *mmu, struct sg_table *sgt,
  38. enum dma_data_direction dir);
  39. int (*map_dma_buf)(struct msm_mmu *mmu, struct sg_table *sgt,
  40. int dir, u32 flags);
  41. void (*unmap_dma_buf)(struct msm_mmu *mmu, struct sg_table *sgt,
  42. int dir, u32 flags);
  43. void (*destroy)(struct msm_mmu *mmu);
  44. bool (*is_domain_secure)(struct msm_mmu *mmu);
  45. int (*set_attribute)(struct msm_mmu *mmu,
  46. enum iommu_attr attr, void *data);
  47. int (*one_to_one_map)(struct msm_mmu *mmu, uint32_t iova,
  48. uint32_t dest_address, uint32_t size, int prot);
  49. int (*one_to_one_unmap)(struct msm_mmu *mmu, uint32_t dest_address,
  50. uint32_t size);
  51. struct device *(*get_dev)(struct msm_mmu *mmu);
  52. };
  53. struct msm_mmu {
  54. const struct msm_mmu_funcs *funcs;
  55. struct device *dev;
  56. int (*handler)(void *arg, unsigned long iova, int flags);
  57. void *arg;
  58. };
  59. static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev,
  60. const struct msm_mmu_funcs *funcs)
  61. {
  62. mmu->dev = dev;
  63. mmu->funcs = funcs;
  64. }
  65. struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain);
  66. struct msm_mmu *msm_smmu_new(struct device *dev,
  67. enum msm_mmu_domain_type domain);
  68. static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg,
  69. int (*handler)(void *arg, unsigned long iova, int flags))
  70. {
  71. mmu->arg = arg;
  72. mmu->handler = handler;
  73. }
  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__ */