Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015-2016 MediaTek Inc. |
| 4 | * Author: Honghui Zhang <honghui.zhang@mediatek.com> |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _MTK_IOMMU_H_ |
| 8 | #define _MTK_IOMMU_H_ |
| 9 | |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/component.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/io.h> |
Rob Herring | b77cf11 | 2019-02-05 10:37:31 -0600 | [diff] [blame] | 14 | #include <linux/io-pgtable.h> |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 15 | #include <linux/iommu.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/spinlock.h> |
Joerg Roedel | 397e18b | 2020-07-13 12:16:48 +0200 | [diff] [blame] | 18 | #include <linux/dma-mapping.h> |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 19 | #include <soc/mediatek/smi.h> |
Yong Wu | 66a2891 | 2021-01-11 19:18:49 +0800 | [diff] [blame] | 20 | #include <dt-bindings/memory/mtk-memory-port.h> |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 21 | |
Chao Hao | 37276e0 | 2020-07-03 12:41:23 +0800 | [diff] [blame] | 22 | #define MTK_LARB_COM_MAX 8 |
| 23 | #define MTK_LARB_SUBCOM_MAX 4 |
| 24 | |
Yong Wu | c3045f3 | 2021-01-11 19:19:09 +0800 | [diff] [blame] | 25 | #define MTK_IOMMU_GROUP_MAX 8 |
| 26 | |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 27 | struct mtk_iommu_suspend_reg { |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 28 | union { |
| 29 | u32 standard_axi_mode;/* v1 */ |
| 30 | u32 misc_ctrl;/* v2 */ |
| 31 | }; |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 32 | u32 dcm_dis; |
| 33 | u32 ctrl_reg; |
| 34 | u32 int_control0; |
| 35 | u32 int_main_control; |
Yong Wu | 70ca608 | 2018-03-18 09:52:54 +0800 | [diff] [blame] | 36 | u32 ivrp_paddr; |
Yong Wu | b9475b3 | 2019-08-24 11:02:06 +0800 | [diff] [blame] | 37 | u32 vld_pa_rng; |
Chao Hao | 35c1b48 | 2020-07-03 12:41:24 +0800 | [diff] [blame] | 38 | u32 wr_len_ctrl; |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 39 | }; |
| 40 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 41 | enum mtk_iommu_plat { |
| 42 | M4U_MT2701, |
| 43 | M4U_MT2712, |
Chao Hao | 068c86e | 2020-07-03 12:41:27 +0800 | [diff] [blame] | 44 | M4U_MT6779, |
Fabien Parent | 3c21356 | 2020-09-07 12:16:49 +0200 | [diff] [blame] | 45 | M4U_MT8167, |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 46 | M4U_MT8173, |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 47 | M4U_MT8183, |
Yong Wu | 9e3489e | 2021-01-11 19:19:13 +0800 | [diff] [blame] | 48 | M4U_MT8192, |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
Yong Wu | 585e58f | 2021-01-11 19:19:07 +0800 | [diff] [blame] | 51 | struct mtk_iommu_iova_region; |
| 52 | |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 53 | struct mtk_iommu_plat_data { |
| 54 | enum mtk_iommu_plat m4u_plat; |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 55 | u32 flags; |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame] | 56 | u32 inv_sel_reg; |
Yong Wu | 585e58f | 2021-01-11 19:19:07 +0800 | [diff] [blame] | 57 | |
| 58 | unsigned int iova_region_nr; |
| 59 | const struct mtk_iommu_iova_region *iova_region; |
Chao Hao | 37276e0 | 2020-07-03 12:41:23 +0800 | [diff] [blame] | 60 | unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX]; |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 61 | }; |
| 62 | |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 63 | struct mtk_iommu_domain; |
| 64 | |
| 65 | struct mtk_iommu_data { |
| 66 | void __iomem *base; |
| 67 | int irq; |
| 68 | struct device *dev; |
| 69 | struct clk *bclk; |
| 70 | phys_addr_t protect_base; /* protect memory base */ |
| 71 | struct mtk_iommu_suspend_reg reg; |
| 72 | struct mtk_iommu_domain *m4u_dom; |
Yong Wu | c3045f3 | 2021-01-11 19:19:09 +0800 | [diff] [blame] | 73 | struct iommu_group *m4u_group[MTK_IOMMU_GROUP_MAX]; |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 74 | bool enable_4GB; |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 75 | spinlock_t tlb_lock; /* lock for tlb range flush */ |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 76 | |
| 77 | struct iommu_device iommu; |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 78 | const struct mtk_iommu_plat_data *plat_data; |
Yong Wu | baf94e6 | 2021-01-11 19:18:59 +0800 | [diff] [blame] | 79 | struct device *smicomm_dev; |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 80 | |
Joerg Roedel | 5896017 | 2020-06-25 15:08:31 +0200 | [diff] [blame] | 81 | struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */ |
| 82 | |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 83 | struct list_head list; |
Yong Wu | 1ee9feb | 2019-08-24 11:02:08 +0800 | [diff] [blame] | 84 | struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX]; |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 85 | }; |
| 86 | |
Joerg Roedel | 9a8a5dc | 2016-08-09 15:46:46 +0200 | [diff] [blame] | 87 | static inline int compare_of(struct device *dev, void *data) |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 88 | { |
| 89 | return dev->of_node == data; |
| 90 | } |
| 91 | |
Russell King | 00c7c81 | 2016-10-19 11:30:34 +0100 | [diff] [blame] | 92 | static inline void release_of(struct device *dev, void *data) |
| 93 | { |
| 94 | of_node_put(data); |
| 95 | } |
| 96 | |
Joerg Roedel | 9a8a5dc | 2016-08-09 15:46:46 +0200 | [diff] [blame] | 97 | static inline int mtk_iommu_bind(struct device *dev) |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 98 | { |
| 99 | struct mtk_iommu_data *data = dev_get_drvdata(dev); |
| 100 | |
Yong Wu | 1ee9feb | 2019-08-24 11:02:08 +0800 | [diff] [blame] | 101 | return component_bind_all(dev, &data->larb_imu); |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 102 | } |
| 103 | |
Joerg Roedel | 9a8a5dc | 2016-08-09 15:46:46 +0200 | [diff] [blame] | 104 | static inline void mtk_iommu_unbind(struct device *dev) |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 105 | { |
| 106 | struct mtk_iommu_data *data = dev_get_drvdata(dev); |
| 107 | |
Yong Wu | 1ee9feb | 2019-08-24 11:02:08 +0800 | [diff] [blame] | 108 | component_unbind_all(dev, &data->larb_imu); |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | #endif |