mtk_iommu.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2016 MediaTek Inc.
  4. * Author: Honghui Zhang <honghui.zhang@mediatek.com>
  5. */
  6. #ifndef _MTK_IOMMU_H_
  7. #define _MTK_IOMMU_H_
  8. #include <linux/clk.h>
  9. #include <linux/component.h>
  10. #include <linux/device.h>
  11. #include <linux/io.h>
  12. #include <linux/io-pgtable.h>
  13. #include <linux/iommu.h>
  14. #include <linux/list.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/dma-mapping.h>
  17. #include <soc/mediatek/smi.h>
  18. #include <dt-bindings/memory/mtk-memory-port.h>
  19. #define MTK_LARB_COM_MAX 8
  20. #define MTK_LARB_SUBCOM_MAX 4
  21. #define MTK_IOMMU_GROUP_MAX 8
  22. struct mtk_iommu_suspend_reg {
  23. union {
  24. u32 standard_axi_mode;/* v1 */
  25. u32 misc_ctrl;/* v2 */
  26. };
  27. u32 dcm_dis;
  28. u32 ctrl_reg;
  29. u32 int_control0;
  30. u32 int_main_control;
  31. u32 ivrp_paddr;
  32. u32 vld_pa_rng;
  33. u32 wr_len_ctrl;
  34. };
  35. enum mtk_iommu_plat {
  36. M4U_MT2701,
  37. M4U_MT2712,
  38. M4U_MT6779,
  39. M4U_MT8167,
  40. M4U_MT8173,
  41. M4U_MT8183,
  42. M4U_MT8192,
  43. };
  44. struct mtk_iommu_iova_region;
  45. struct mtk_iommu_plat_data {
  46. enum mtk_iommu_plat m4u_plat;
  47. u32 flags;
  48. u32 inv_sel_reg;
  49. unsigned int iova_region_nr;
  50. const struct mtk_iommu_iova_region *iova_region;
  51. unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX];
  52. };
  53. struct mtk_iommu_domain;
  54. struct mtk_iommu_data {
  55. void __iomem *base;
  56. int irq;
  57. struct device *dev;
  58. struct clk *bclk;
  59. phys_addr_t protect_base; /* protect memory base */
  60. struct mtk_iommu_suspend_reg reg;
  61. struct mtk_iommu_domain *m4u_dom;
  62. struct iommu_group *m4u_group[MTK_IOMMU_GROUP_MAX];
  63. bool enable_4GB;
  64. spinlock_t tlb_lock; /* lock for tlb range flush */
  65. struct iommu_device iommu;
  66. const struct mtk_iommu_plat_data *plat_data;
  67. struct device *smicomm_dev;
  68. struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
  69. struct list_head list;
  70. struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
  71. };
  72. static inline int compare_of(struct device *dev, void *data)
  73. {
  74. return dev->of_node == data;
  75. }
  76. static inline void release_of(struct device *dev, void *data)
  77. {
  78. of_node_put(data);
  79. }
  80. static inline int mtk_iommu_bind(struct device *dev)
  81. {
  82. struct mtk_iommu_data *data = dev_get_drvdata(dev);
  83. return component_bind_all(dev, &data->larb_imu);
  84. }
  85. static inline void mtk_iommu_unbind(struct device *dev)
  86. {
  87. struct mtk_iommu_data *data = dev_get_drvdata(dev);
  88. component_unbind_all(dev, &data->larb_imu);
  89. }
  90. #endif