mtk_iommu_platform.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: YongWu <yong.wu@mediatek.com>
  4. * Honghui Zhang <honghui.zhang@mediatek.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef MTK_IOMMU_PLATFORM_H
  16. #define MTK_IOMMU_PLATFORM_H
  17. #include <linux/io.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/mm.h>
  21. enum {
  22. M4U_ID_0 = 0,
  23. M4U_ID_1,
  24. M4U_ID_ALL
  25. };
  26. #define MTK_IOMMU_PGT_SZ SZ_1M /*2M err*/
  27. #define MTK_PROTECT_PA_ALIGN 128
  28. #define MTK_IOMMU_LARB_MAX_NR 8
  29. #define MTK_IOMMU_PORT_MAX_NR 100
  30. #define MT2701_IOMMU_PAGE_SIZE 0x1000
  31. struct mtk_iommu_info {
  32. void __iomem *base;
  33. void __iomem *l2_base;
  34. int irq;
  35. int larb_nr;
  36. unsigned int iova_base;
  37. size_t iova_size;
  38. dma_addr_t pgt_basepa;
  39. struct device *dev;
  40. struct clk *bclk;
  41. dma_addr_t protect_base;
  42. unsigned int *protect_va;
  43. const struct mtk_iommu_cfg *imucfg;
  44. };
  45. struct mtk_iommu_domain {
  46. unsigned int *pgtableva;
  47. dma_addr_t pgtablepa;
  48. spinlock_t pgtlock;
  49. spinlock_t portlock;
  50. struct mtk_iommu_info *piommuinfo;
  51. struct iommu_domain *domain;
  52. };
  53. /*hw config*/
  54. struct mtk_iommu_cfg {
  55. unsigned int l2_offset;
  56. unsigned int m4u_port_in_larbx[MTK_IOMMU_LARB_MAX_NR];
  57. unsigned int m4u_port_nr;
  58. /*hw function*/
  59. int (*dt_parse)(struct platform_device *pdev,
  60. struct mtk_iommu_info *piommu);
  61. int (*hw_init)(const struct mtk_iommu_info *piommu);
  62. void (*hw_deinit)(const struct mtk_iommu_info *piommu);
  63. int (*map)(struct mtk_iommu_domain *mtkdomain, unsigned int iova,
  64. phys_addr_t paddr, size_t size);
  65. size_t (*unmap)(struct mtk_iommu_domain *mtkdomain, unsigned int iova,
  66. size_t size);
  67. phys_addr_t (*iova_to_phys)(struct mtk_iommu_domain *mtkdomain,
  68. unsigned int iova);
  69. int (*config_port)(struct mtk_iommu_info *piommu,
  70. int portid, bool enable);
  71. irq_handler_t iommu_isr;
  72. void (*invalid_tlb)(const struct mtk_iommu_info *piommu,
  73. unsigned int m4u_id, int isinvall,
  74. unsigned int iova_start,
  75. unsigned int iova_end);
  76. void (*clear_intr)(void __iomem *base);
  77. };
  78. extern const struct mtk_iommu_cfg mtk_iommu_mt2701_cfg;
  79. #endif