Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015-2016 MediaTek Inc. |
| 4 | * Author: Yong Wu <yong.wu@mediatek.com> |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 5 | */ |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 6 | #include <linux/memblock.h> |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 7 | #include <linux/bug.h> |
| 8 | #include <linux/clk.h> |
| 9 | #include <linux/component.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/dma-iommu.h> |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/iommu.h> |
| 16 | #include <linux/iopoll.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_iommu.h> |
| 20 | #include <linux/of_irq.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <asm/barrier.h> |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 26 | #include <soc/mediatek/smi.h> |
| 27 | |
Honghui Zhang | 9ca340c | 2016-06-08 17:50:58 +0800 | [diff] [blame] | 28 | #include "mtk_iommu.h" |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 29 | |
| 30 | #define REG_MMU_PT_BASE_ADDR 0x000 |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 31 | #define MMU_PT_ADDR_MASK GENMASK(31, 7) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 32 | |
| 33 | #define REG_MMU_INVALIDATE 0x020 |
| 34 | #define F_ALL_INVLD 0x2 |
| 35 | #define F_MMU_INV_RANGE 0x1 |
| 36 | |
| 37 | #define REG_MMU_INVLD_START_A 0x024 |
| 38 | #define REG_MMU_INVLD_END_A 0x028 |
| 39 | |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 40 | #define REG_MMU_INV_SEL_GEN1 0x038 |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 41 | #define F_INVLD_EN0 BIT(0) |
| 42 | #define F_INVLD_EN1 BIT(1) |
| 43 | |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 44 | #define REG_MMU_MISC_CTRL 0x048 |
Chao Hao | 4bb2bf4 | 2020-07-03 12:41:21 +0800 | [diff] [blame] | 45 | #define F_MMU_IN_ORDER_WR_EN_MASK (BIT(1) | BIT(17)) |
| 46 | #define F_MMU_STANDARD_AXI_MODE_MASK (BIT(3) | BIT(19)) |
| 47 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 48 | #define REG_MMU_DCM_DIS 0x050 |
| 49 | |
| 50 | #define REG_MMU_CTRL_REG 0x110 |
Yong Wu | acb3c92 | 2019-08-24 11:01:58 +0800 | [diff] [blame] | 51 | #define F_MMU_TF_PROT_TO_PROGRAM_ADDR (2 << 4) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 52 | #define F_MMU_PREFETCH_RT_REPLACE_MOD BIT(4) |
Yong Wu | acb3c92 | 2019-08-24 11:01:58 +0800 | [diff] [blame] | 53 | #define F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173 (2 << 5) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 54 | |
| 55 | #define REG_MMU_IVRP_PADDR 0x114 |
Yong Wu | 70ca608 | 2018-03-18 09:52:54 +0800 | [diff] [blame] | 56 | |
Yong Wu | 30e2fcc | 2017-08-21 19:00:20 +0800 | [diff] [blame] | 57 | #define REG_MMU_VLD_PA_RNG 0x118 |
| 58 | #define F_MMU_VLD_PA_RNG(EA, SA) (((EA) << 8) | (SA)) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 59 | |
| 60 | #define REG_MMU_INT_CONTROL0 0x120 |
| 61 | #define F_L2_MULIT_HIT_EN BIT(0) |
| 62 | #define F_TABLE_WALK_FAULT_INT_EN BIT(1) |
| 63 | #define F_PREETCH_FIFO_OVERFLOW_INT_EN BIT(2) |
| 64 | #define F_MISS_FIFO_OVERFLOW_INT_EN BIT(3) |
| 65 | #define F_PREFETCH_FIFO_ERR_INT_EN BIT(5) |
| 66 | #define F_MISS_FIFO_ERR_INT_EN BIT(6) |
| 67 | #define F_INT_CLR_BIT BIT(12) |
| 68 | |
| 69 | #define REG_MMU_INT_MAIN_CONTROL 0x124 |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 70 | /* mmu0 | mmu1 */ |
| 71 | #define F_INT_TRANSLATION_FAULT (BIT(0) | BIT(7)) |
| 72 | #define F_INT_MAIN_MULTI_HIT_FAULT (BIT(1) | BIT(8)) |
| 73 | #define F_INT_INVALID_PA_FAULT (BIT(2) | BIT(9)) |
| 74 | #define F_INT_ENTRY_REPLACEMENT_FAULT (BIT(3) | BIT(10)) |
| 75 | #define F_INT_TLB_MISS_FAULT (BIT(4) | BIT(11)) |
| 76 | #define F_INT_MISS_TRANSACTION_FIFO_FAULT (BIT(5) | BIT(12)) |
| 77 | #define F_INT_PRETETCH_TRANSATION_FIFO_FAULT (BIT(6) | BIT(13)) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 78 | |
| 79 | #define REG_MMU_CPE_DONE 0x12C |
| 80 | |
| 81 | #define REG_MMU_FAULT_ST1 0x134 |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 82 | #define F_REG_MMU0_FAULT_MASK GENMASK(6, 0) |
| 83 | #define F_REG_MMU1_FAULT_MASK GENMASK(13, 7) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 84 | |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 85 | #define REG_MMU0_FAULT_VA 0x13c |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 86 | #define F_MMU_FAULT_VA_WRITE_BIT BIT(1) |
| 87 | #define F_MMU_FAULT_VA_LAYER_BIT BIT(0) |
| 88 | |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 89 | #define REG_MMU0_INVLD_PA 0x140 |
| 90 | #define REG_MMU1_FAULT_VA 0x144 |
| 91 | #define REG_MMU1_INVLD_PA 0x148 |
| 92 | #define REG_MMU0_INT_ID 0x150 |
| 93 | #define REG_MMU1_INT_ID 0x154 |
| 94 | #define F_MMU_INT_ID_LARB_ID(a) (((a) >> 7) & 0x7) |
| 95 | #define F_MMU_INT_ID_PORT_ID(a) (((a) >> 2) & 0x1f) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 96 | |
| 97 | #define MTK_PROTECT_PA_ALIGN 128 |
| 98 | |
Yong Wu | a9467d9 | 2017-08-21 19:00:15 +0800 | [diff] [blame] | 99 | /* |
| 100 | * Get the local arbiter ID and the portid within the larb arbiter |
| 101 | * from mtk_m4u_id which is defined by MTK_M4U_ID. |
| 102 | */ |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 103 | #define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0xf) |
Yong Wu | a9467d9 | 2017-08-21 19:00:15 +0800 | [diff] [blame] | 104 | #define MTK_M4U_TO_PORT(id) ((id) & 0x1f) |
| 105 | |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 106 | #define HAS_4GB_MODE BIT(0) |
| 107 | /* HW will use the EMI clock if there isn't the "bclk". */ |
| 108 | #define HAS_BCLK BIT(1) |
| 109 | #define HAS_VLD_PA_RNG BIT(2) |
| 110 | #define RESET_AXI BIT(3) |
Chao Hao | 4bb2bf4 | 2020-07-03 12:41:21 +0800 | [diff] [blame] | 111 | #define OUT_ORDER_WR_EN BIT(4) |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 112 | |
| 113 | #define MTK_IOMMU_HAS_FLAG(pdata, _x) \ |
| 114 | ((((pdata)->flags) & (_x)) == (_x)) |
| 115 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 116 | struct mtk_iommu_domain { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 117 | struct io_pgtable_cfg cfg; |
| 118 | struct io_pgtable_ops *iop; |
| 119 | |
| 120 | struct iommu_domain domain; |
| 121 | }; |
| 122 | |
Arvind Yadav | b65f501 | 2018-10-18 19:13:38 +0800 | [diff] [blame] | 123 | static const struct iommu_ops mtk_iommu_ops; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 124 | |
Yong Wu | 76ce654 | 2019-08-24 11:01:50 +0800 | [diff] [blame] | 125 | /* |
| 126 | * In M4U 4GB mode, the physical address is remapped as below: |
| 127 | * |
| 128 | * CPU Physical address: |
| 129 | * ==================== |
| 130 | * |
| 131 | * 0 1G 2G 3G 4G 5G |
| 132 | * |---A---|---B---|---C---|---D---|---E---| |
| 133 | * +--I/O--+------------Memory-------------+ |
| 134 | * |
| 135 | * IOMMU output physical address: |
| 136 | * ============================= |
| 137 | * |
| 138 | * 4G 5G 6G 7G 8G |
| 139 | * |---E---|---B---|---C---|---D---| |
| 140 | * +------------Memory-------------+ |
| 141 | * |
| 142 | * The Region 'A'(I/O) can NOT be mapped by M4U; For Region 'B'/'C'/'D', the |
| 143 | * bit32 of the CPU physical address always is needed to set, and for Region |
| 144 | * 'E', the CPU physical address keep as is. |
| 145 | * Additionally, The iommu consumers always use the CPU phyiscal address. |
| 146 | */ |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 147 | #define MTK_IOMMU_4GB_MODE_REMAP_BASE 0x140000000UL |
Yong Wu | 76ce654 | 2019-08-24 11:01:50 +0800 | [diff] [blame] | 148 | |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 149 | static LIST_HEAD(m4ulist); /* List all the M4U HWs */ |
| 150 | |
| 151 | #define for_each_m4u(data) list_for_each_entry(data, &m4ulist, list) |
| 152 | |
| 153 | /* |
| 154 | * There may be 1 or 2 M4U HWs, But we always expect they are in the same domain |
| 155 | * for the performance. |
| 156 | * |
| 157 | * Here always return the mtk_iommu_data of the first probed M4U where the |
| 158 | * iommu domain information is recorded. |
| 159 | */ |
| 160 | static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void) |
| 161 | { |
| 162 | struct mtk_iommu_data *data; |
| 163 | |
| 164 | for_each_m4u(data) |
| 165 | return data; |
| 166 | |
| 167 | return NULL; |
| 168 | } |
| 169 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 170 | static struct mtk_iommu_domain *to_mtk_domain(struct iommu_domain *dom) |
| 171 | { |
| 172 | return container_of(dom, struct mtk_iommu_domain, domain); |
| 173 | } |
| 174 | |
| 175 | static void mtk_iommu_tlb_flush_all(void *cookie) |
| 176 | { |
| 177 | struct mtk_iommu_data *data = cookie; |
| 178 | |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 179 | for_each_m4u(data) { |
| 180 | writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 181 | data->base + data->plat_data->inv_sel_reg); |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 182 | writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); |
| 183 | wmb(); /* Make sure the tlb flush all done */ |
| 184 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 185 | } |
| 186 | |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 187 | static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, |
Yong Wu | 67caf7e | 2019-11-04 15:01:05 +0800 | [diff] [blame] | 188 | size_t granule, void *cookie) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 189 | { |
| 190 | struct mtk_iommu_data *data = cookie; |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 191 | unsigned long flags; |
| 192 | int ret; |
| 193 | u32 tmp; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 194 | |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 195 | for_each_m4u(data) { |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 196 | spin_lock_irqsave(&data->tlb_lock, flags); |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 197 | writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 198 | data->base + data->plat_data->inv_sel_reg); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 199 | |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 200 | writel_relaxed(iova, data->base + REG_MMU_INVLD_START_A); |
| 201 | writel_relaxed(iova + size - 1, |
| 202 | data->base + REG_MMU_INVLD_END_A); |
| 203 | writel_relaxed(F_MMU_INV_RANGE, |
| 204 | data->base + REG_MMU_INVALIDATE); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 205 | |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 206 | /* tlb sync */ |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 207 | ret = readl_poll_timeout_atomic(data->base + REG_MMU_CPE_DONE, |
Yong Wu | c90ae4a | 2019-11-04 15:01:08 +0800 | [diff] [blame] | 208 | tmp, tmp != 0, 10, 1000); |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 209 | if (ret) { |
| 210 | dev_warn(data->dev, |
| 211 | "Partial TLB flush timed out, falling back to full flush\n"); |
| 212 | mtk_iommu_tlb_flush_all(cookie); |
| 213 | } |
| 214 | /* Clear the CPE status */ |
| 215 | writel_relaxed(0, data->base + REG_MMU_CPE_DONE); |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 216 | spin_unlock_irqrestore(&data->tlb_lock, flags); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 217 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 218 | } |
| 219 | |
Will Deacon | 3951c41 | 2019-07-02 16:45:15 +0100 | [diff] [blame] | 220 | static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, |
| 221 | unsigned long iova, size_t granule, |
Will Deacon | abfd6fe | 2019-07-02 16:44:41 +0100 | [diff] [blame] | 222 | void *cookie) |
| 223 | { |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 224 | struct mtk_iommu_data *data = cookie; |
Yong Wu | a7a04ea | 2019-11-04 15:01:04 +0800 | [diff] [blame] | 225 | struct iommu_domain *domain = &data->m4u_dom->domain; |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 226 | |
Yong Wu | a7a04ea | 2019-11-04 15:01:04 +0800 | [diff] [blame] | 227 | iommu_iotlb_gather_add_page(domain, gather, iova, granule); |
Will Deacon | abfd6fe | 2019-07-02 16:44:41 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Will Deacon | 298f7889 | 2019-07-02 16:43:34 +0100 | [diff] [blame] | 230 | static const struct iommu_flush_ops mtk_iommu_flush_ops = { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 231 | .tlb_flush_all = mtk_iommu_tlb_flush_all, |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 232 | .tlb_flush_walk = mtk_iommu_tlb_flush_range_sync, |
| 233 | .tlb_flush_leaf = mtk_iommu_tlb_flush_range_sync, |
Will Deacon | abfd6fe | 2019-07-02 16:44:41 +0100 | [diff] [blame] | 234 | .tlb_add_page = mtk_iommu_tlb_flush_page_nosync, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) |
| 238 | { |
| 239 | struct mtk_iommu_data *data = dev_id; |
| 240 | struct mtk_iommu_domain *dom = data->m4u_dom; |
| 241 | u32 int_state, regval, fault_iova, fault_pa; |
| 242 | unsigned int fault_larb, fault_port; |
| 243 | bool layer, write; |
| 244 | |
| 245 | /* Read error info from registers */ |
| 246 | int_state = readl_relaxed(data->base + REG_MMU_FAULT_ST1); |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 247 | if (int_state & F_REG_MMU0_FAULT_MASK) { |
| 248 | regval = readl_relaxed(data->base + REG_MMU0_INT_ID); |
| 249 | fault_iova = readl_relaxed(data->base + REG_MMU0_FAULT_VA); |
| 250 | fault_pa = readl_relaxed(data->base + REG_MMU0_INVLD_PA); |
| 251 | } else { |
| 252 | regval = readl_relaxed(data->base + REG_MMU1_INT_ID); |
| 253 | fault_iova = readl_relaxed(data->base + REG_MMU1_FAULT_VA); |
| 254 | fault_pa = readl_relaxed(data->base + REG_MMU1_INVLD_PA); |
| 255 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 256 | layer = fault_iova & F_MMU_FAULT_VA_LAYER_BIT; |
| 257 | write = fault_iova & F_MMU_FAULT_VA_WRITE_BIT; |
Yong Wu | 15a01f4 | 2019-08-24 11:02:03 +0800 | [diff] [blame] | 258 | fault_larb = F_MMU_INT_ID_LARB_ID(regval); |
| 259 | fault_port = F_MMU_INT_ID_PORT_ID(regval); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 260 | |
Yong Wu | b3e5eee7 | 2019-08-24 11:01:57 +0800 | [diff] [blame] | 261 | fault_larb = data->plat_data->larbid_remap[fault_larb]; |
| 262 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 263 | if (report_iommu_fault(&dom->domain, data->dev, fault_iova, |
| 264 | write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) { |
| 265 | dev_err_ratelimited( |
| 266 | data->dev, |
| 267 | "fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n", |
| 268 | int_state, fault_iova, fault_pa, fault_larb, fault_port, |
| 269 | layer, write ? "write" : "read"); |
| 270 | } |
| 271 | |
| 272 | /* Interrupt clear */ |
| 273 | regval = readl_relaxed(data->base + REG_MMU_INT_CONTROL0); |
| 274 | regval |= F_INT_CLR_BIT; |
| 275 | writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL0); |
| 276 | |
| 277 | mtk_iommu_tlb_flush_all(data); |
| 278 | |
| 279 | return IRQ_HANDLED; |
| 280 | } |
| 281 | |
| 282 | static void mtk_iommu_config(struct mtk_iommu_data *data, |
| 283 | struct device *dev, bool enable) |
| 284 | { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 285 | struct mtk_smi_larb_iommu *larb_mmu; |
| 286 | unsigned int larbid, portid; |
Joerg Roedel | a9bf2ee | 2018-11-29 14:01:00 +0100 | [diff] [blame] | 287 | struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 288 | int i; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 289 | |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 290 | for (i = 0; i < fwspec->num_ids; ++i) { |
| 291 | larbid = MTK_M4U_TO_LARB(fwspec->ids[i]); |
| 292 | portid = MTK_M4U_TO_PORT(fwspec->ids[i]); |
Yong Wu | 1ee9feb | 2019-08-24 11:02:08 +0800 | [diff] [blame] | 293 | larb_mmu = &data->larb_imu[larbid]; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 294 | |
| 295 | dev_dbg(dev, "%s iommu port: %d\n", |
| 296 | enable ? "enable" : "disable", portid); |
| 297 | |
| 298 | if (enable) |
| 299 | larb_mmu->mmu |= MTK_SMI_MMU_EN(portid); |
| 300 | else |
| 301 | larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid); |
| 302 | } |
| 303 | } |
| 304 | |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 305 | static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 306 | { |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 307 | struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 308 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 309 | dom->cfg = (struct io_pgtable_cfg) { |
| 310 | .quirks = IO_PGTABLE_QUIRK_ARM_NS | |
| 311 | IO_PGTABLE_QUIRK_NO_PERMS | |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 312 | IO_PGTABLE_QUIRK_TLBI_ON_MAP | |
| 313 | IO_PGTABLE_QUIRK_ARM_MTK_EXT, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 314 | .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, |
| 315 | .ias = 32, |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 316 | .oas = 34, |
Will Deacon | 298f7889 | 2019-07-02 16:43:34 +0100 | [diff] [blame] | 317 | .tlb = &mtk_iommu_flush_ops, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 318 | .iommu_dev = data->dev, |
| 319 | }; |
| 320 | |
| 321 | dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data); |
| 322 | if (!dom->iop) { |
| 323 | dev_err(data->dev, "Failed to alloc io pgtable\n"); |
| 324 | return -EINVAL; |
| 325 | } |
| 326 | |
| 327 | /* Update our support page sizes bitmap */ |
Robin Murphy | d16e0fa | 2016-04-07 18:42:06 +0100 | [diff] [blame] | 328 | dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type) |
| 333 | { |
| 334 | struct mtk_iommu_domain *dom; |
| 335 | |
| 336 | if (type != IOMMU_DOMAIN_DMA) |
| 337 | return NULL; |
| 338 | |
| 339 | dom = kzalloc(sizeof(*dom), GFP_KERNEL); |
| 340 | if (!dom) |
| 341 | return NULL; |
| 342 | |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 343 | if (iommu_get_dma_cookie(&dom->domain)) |
| 344 | goto free_dom; |
| 345 | |
| 346 | if (mtk_iommu_domain_finalise(dom)) |
| 347 | goto put_dma_cookie; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 348 | |
| 349 | dom->domain.geometry.aperture_start = 0; |
| 350 | dom->domain.geometry.aperture_end = DMA_BIT_MASK(32); |
| 351 | dom->domain.geometry.force_aperture = true; |
| 352 | |
| 353 | return &dom->domain; |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 354 | |
| 355 | put_dma_cookie: |
| 356 | iommu_put_dma_cookie(&dom->domain); |
| 357 | free_dom: |
| 358 | kfree(dom); |
| 359 | return NULL; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static void mtk_iommu_domain_free(struct iommu_domain *domain) |
| 363 | { |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 364 | struct mtk_iommu_domain *dom = to_mtk_domain(domain); |
| 365 | |
| 366 | free_io_pgtable_ops(dom->iop); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 367 | iommu_put_dma_cookie(domain); |
| 368 | kfree(to_mtk_domain(domain)); |
| 369 | } |
| 370 | |
| 371 | static int mtk_iommu_attach_device(struct iommu_domain *domain, |
| 372 | struct device *dev) |
| 373 | { |
Joerg Roedel | 3524b55 | 2020-03-26 16:08:38 +0100 | [diff] [blame] | 374 | struct mtk_iommu_data *data = dev_iommu_priv_get(dev); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 375 | struct mtk_iommu_domain *dom = to_mtk_domain(domain); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 376 | |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 377 | if (!data) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 378 | return -ENODEV; |
| 379 | |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 380 | /* Update the pgtable base address register of the M4U HW */ |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 381 | if (!data->m4u_dom) { |
| 382 | data->m4u_dom = dom; |
Robin Murphy | d1e5f26 | 2019-10-25 19:08:37 +0100 | [diff] [blame] | 383 | writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 384 | data->base + REG_MMU_PT_BASE_ADDR); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 385 | } |
| 386 | |
Yong Wu | 4b00f5a | 2017-08-21 19:00:18 +0800 | [diff] [blame] | 387 | mtk_iommu_config(data, dev, true); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static void mtk_iommu_detach_device(struct iommu_domain *domain, |
| 392 | struct device *dev) |
| 393 | { |
Joerg Roedel | 3524b55 | 2020-03-26 16:08:38 +0100 | [diff] [blame] | 394 | struct mtk_iommu_data *data = dev_iommu_priv_get(dev); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 395 | |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 396 | if (!data) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 397 | return; |
| 398 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 399 | mtk_iommu_config(data, dev, false); |
| 400 | } |
| 401 | |
| 402 | static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, |
Tom Murphy | 781ca2d | 2019-09-08 09:56:38 -0700 | [diff] [blame] | 403 | phys_addr_t paddr, size_t size, int prot, gfp_t gfp) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 404 | { |
| 405 | struct mtk_iommu_domain *dom = to_mtk_domain(domain); |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 406 | struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 407 | |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 408 | /* The "4GB mode" M4U physically can not use the lower remap of Dram. */ |
| 409 | if (data->enable_4GB) |
| 410 | paddr |= BIT_ULL(32); |
| 411 | |
Yong Wu | 60829b4 | 2019-11-04 15:01:07 +0800 | [diff] [blame] | 412 | /* Synchronize with the tlb_lock */ |
| 413 | return dom->iop->map(dom->iop, iova, paddr, size, prot); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static size_t mtk_iommu_unmap(struct iommu_domain *domain, |
Will Deacon | 56f8af5 | 2019-07-02 16:44:06 +0100 | [diff] [blame] | 417 | unsigned long iova, size_t size, |
| 418 | struct iommu_iotlb_gather *gather) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 419 | { |
| 420 | struct mtk_iommu_domain *dom = to_mtk_domain(domain); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 421 | |
Yong Wu | 60829b4 | 2019-11-04 15:01:07 +0800 | [diff] [blame] | 422 | return dom->iop->unmap(dom->iop, iova, size, gather); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 423 | } |
| 424 | |
Will Deacon | 56f8af5 | 2019-07-02 16:44:06 +0100 | [diff] [blame] | 425 | static void mtk_iommu_flush_iotlb_all(struct iommu_domain *domain) |
| 426 | { |
Yong Wu | 2009122 | 2019-11-04 15:01:02 +0800 | [diff] [blame] | 427 | mtk_iommu_tlb_flush_all(mtk_iommu_get_m4u_data()); |
Will Deacon | 56f8af5 | 2019-07-02 16:44:06 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, |
| 431 | struct iommu_iotlb_gather *gather) |
Robin Murphy | 4d689b6 | 2017-09-28 15:55:02 +0100 | [diff] [blame] | 432 | { |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 433 | struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); |
Yong Wu | a7a04ea | 2019-11-04 15:01:04 +0800 | [diff] [blame] | 434 | size_t length = gather->end - gather->start; |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 435 | |
Yong Wu | a7a04ea | 2019-11-04 15:01:04 +0800 | [diff] [blame] | 436 | if (gather->start == ULONG_MAX) |
| 437 | return; |
| 438 | |
Yong Wu | 1f4fd62 | 2019-11-04 15:01:06 +0800 | [diff] [blame] | 439 | mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, |
Yong Wu | 67caf7e | 2019-11-04 15:01:05 +0800 | [diff] [blame] | 440 | data); |
Robin Murphy | 4d689b6 | 2017-09-28 15:55:02 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 443 | static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, |
| 444 | dma_addr_t iova) |
| 445 | { |
| 446 | struct mtk_iommu_domain *dom = to_mtk_domain(domain); |
Yong Wu | 30e2fcc | 2017-08-21 19:00:20 +0800 | [diff] [blame] | 447 | struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 448 | phys_addr_t pa; |
| 449 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 450 | pa = dom->iop->iova_to_phys(dom->iop, iova); |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 451 | if (data->enable_4GB && pa >= MTK_IOMMU_4GB_MODE_REMAP_BASE) |
| 452 | pa &= ~BIT_ULL(32); |
Yong Wu | 30e2fcc | 2017-08-21 19:00:20 +0800 | [diff] [blame] | 453 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 454 | return pa; |
| 455 | } |
| 456 | |
Joerg Roedel | 80e4592 | 2020-04-29 15:37:00 +0200 | [diff] [blame] | 457 | static struct iommu_device *mtk_iommu_probe_device(struct device *dev) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 458 | { |
Joerg Roedel | a9bf2ee | 2018-11-29 14:01:00 +0100 | [diff] [blame] | 459 | struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 460 | struct mtk_iommu_data *data; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 461 | |
Joerg Roedel | a9bf2ee | 2018-11-29 14:01:00 +0100 | [diff] [blame] | 462 | if (!fwspec || fwspec->ops != &mtk_iommu_ops) |
Joerg Roedel | 80e4592 | 2020-04-29 15:37:00 +0200 | [diff] [blame] | 463 | return ERR_PTR(-ENODEV); /* Not a iommu client device */ |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 464 | |
Joerg Roedel | 3524b55 | 2020-03-26 16:08:38 +0100 | [diff] [blame] | 465 | data = dev_iommu_priv_get(dev); |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 466 | |
Joerg Roedel | 80e4592 | 2020-04-29 15:37:00 +0200 | [diff] [blame] | 467 | return &data->iommu; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 468 | } |
| 469 | |
Joerg Roedel | 80e4592 | 2020-04-29 15:37:00 +0200 | [diff] [blame] | 470 | static void mtk_iommu_release_device(struct device *dev) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 471 | { |
Joerg Roedel | a9bf2ee | 2018-11-29 14:01:00 +0100 | [diff] [blame] | 472 | struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 473 | |
Joerg Roedel | a9bf2ee | 2018-11-29 14:01:00 +0100 | [diff] [blame] | 474 | if (!fwspec || fwspec->ops != &mtk_iommu_ops) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 475 | return; |
| 476 | |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 477 | iommu_fwspec_free(dev); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static struct iommu_group *mtk_iommu_device_group(struct device *dev) |
| 481 | { |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 482 | struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 483 | |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 484 | if (!data) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 485 | return ERR_PTR(-ENODEV); |
| 486 | |
| 487 | /* All the client devices are in the same m4u iommu-group */ |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 488 | if (!data->m4u_group) { |
| 489 | data->m4u_group = iommu_group_alloc(); |
| 490 | if (IS_ERR(data->m4u_group)) |
| 491 | dev_err(dev, "Failed to allocate M4U IOMMU group\n"); |
Robin Murphy | 3a8d40b | 2016-11-11 17:59:24 +0000 | [diff] [blame] | 492 | } else { |
| 493 | iommu_group_ref_get(data->m4u_group); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 494 | } |
| 495 | return data->m4u_group; |
| 496 | } |
| 497 | |
| 498 | static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) |
| 499 | { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 500 | struct platform_device *m4updev; |
| 501 | |
| 502 | if (args->args_count != 1) { |
| 503 | dev_err(dev, "invalid #iommu-cells(%d) property for IOMMU\n", |
| 504 | args->args_count); |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | |
Joerg Roedel | 3524b55 | 2020-03-26 16:08:38 +0100 | [diff] [blame] | 508 | if (!dev_iommu_priv_get(dev)) { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 509 | /* Get the m4u device */ |
| 510 | m4updev = of_find_device_by_node(args->np); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 511 | if (WARN_ON(!m4updev)) |
| 512 | return -EINVAL; |
| 513 | |
Joerg Roedel | 3524b55 | 2020-03-26 16:08:38 +0100 | [diff] [blame] | 514 | dev_iommu_priv_set(dev, platform_get_drvdata(m4updev)); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 515 | } |
| 516 | |
Robin Murphy | 58f0d1d | 2016-10-17 12:49:20 +0100 | [diff] [blame] | 517 | return iommu_fwspec_add_ids(dev, args->args, 1); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 518 | } |
| 519 | |
Arvind Yadav | b65f501 | 2018-10-18 19:13:38 +0800 | [diff] [blame] | 520 | static const struct iommu_ops mtk_iommu_ops = { |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 521 | .domain_alloc = mtk_iommu_domain_alloc, |
| 522 | .domain_free = mtk_iommu_domain_free, |
| 523 | .attach_dev = mtk_iommu_attach_device, |
| 524 | .detach_dev = mtk_iommu_detach_device, |
| 525 | .map = mtk_iommu_map, |
| 526 | .unmap = mtk_iommu_unmap, |
Will Deacon | 56f8af5 | 2019-07-02 16:44:06 +0100 | [diff] [blame] | 527 | .flush_iotlb_all = mtk_iommu_flush_iotlb_all, |
Robin Murphy | 4d689b6 | 2017-09-28 15:55:02 +0100 | [diff] [blame] | 528 | .iotlb_sync = mtk_iommu_iotlb_sync, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 529 | .iova_to_phys = mtk_iommu_iova_to_phys, |
Joerg Roedel | 80e4592 | 2020-04-29 15:37:00 +0200 | [diff] [blame] | 530 | .probe_device = mtk_iommu_probe_device, |
| 531 | .release_device = mtk_iommu_release_device, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 532 | .device_group = mtk_iommu_device_group, |
| 533 | .of_xlate = mtk_iommu_of_xlate, |
| 534 | .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, |
| 535 | }; |
| 536 | |
| 537 | static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) |
| 538 | { |
| 539 | u32 regval; |
| 540 | int ret; |
| 541 | |
| 542 | ret = clk_prepare_enable(data->bclk); |
| 543 | if (ret) { |
| 544 | dev_err(data->dev, "Failed to enable iommu bclk(%d)\n", ret); |
| 545 | return ret; |
| 546 | } |
| 547 | |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 548 | if (data->plat_data->m4u_plat == M4U_MT8173) |
Yong Wu | acb3c92 | 2019-08-24 11:01:58 +0800 | [diff] [blame] | 549 | regval = F_MMU_PREFETCH_RT_REPLACE_MOD | |
| 550 | F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173; |
| 551 | else |
| 552 | regval = F_MMU_TF_PROT_TO_PROGRAM_ADDR; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 553 | writel_relaxed(regval, data->base + REG_MMU_CTRL_REG); |
| 554 | |
| 555 | regval = F_L2_MULIT_HIT_EN | |
| 556 | F_TABLE_WALK_FAULT_INT_EN | |
| 557 | F_PREETCH_FIFO_OVERFLOW_INT_EN | |
| 558 | F_MISS_FIFO_OVERFLOW_INT_EN | |
| 559 | F_PREFETCH_FIFO_ERR_INT_EN | |
| 560 | F_MISS_FIFO_ERR_INT_EN; |
| 561 | writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL0); |
| 562 | |
| 563 | regval = F_INT_TRANSLATION_FAULT | |
| 564 | F_INT_MAIN_MULTI_HIT_FAULT | |
| 565 | F_INT_INVALID_PA_FAULT | |
| 566 | F_INT_ENTRY_REPLACEMENT_FAULT | |
| 567 | F_INT_TLB_MISS_FAULT | |
| 568 | F_INT_MISS_TRANSACTION_FIFO_FAULT | |
| 569 | F_INT_PRETETCH_TRANSATION_FIFO_FAULT; |
| 570 | writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL); |
| 571 | |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 572 | if (data->plat_data->m4u_plat == M4U_MT8173) |
Yong Wu | 70ca608 | 2018-03-18 09:52:54 +0800 | [diff] [blame] | 573 | regval = (data->protect_base >> 1) | (data->enable_4GB << 31); |
| 574 | else |
| 575 | regval = lower_32_bits(data->protect_base) | |
| 576 | upper_32_bits(data->protect_base); |
| 577 | writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR); |
| 578 | |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 579 | if (data->enable_4GB && |
| 580 | MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_VLD_PA_RNG)) { |
Yong Wu | 30e2fcc | 2017-08-21 19:00:20 +0800 | [diff] [blame] | 581 | /* |
| 582 | * If 4GB mode is enabled, the validate PA range is from |
| 583 | * 0x1_0000_0000 to 0x1_ffff_ffff. here record bit[32:30]. |
| 584 | */ |
| 585 | regval = F_MMU_VLD_PA_RNG(7, 4); |
| 586 | writel_relaxed(regval, data->base + REG_MMU_VLD_PA_RNG); |
| 587 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 588 | writel_relaxed(0, data->base + REG_MMU_DCM_DIS); |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 589 | |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 590 | if (MTK_IOMMU_HAS_FLAG(data->plat_data, RESET_AXI)) { |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 591 | /* The register is called STANDARD_AXI_MODE in this case */ |
Chao Hao | 4bb2bf4 | 2020-07-03 12:41:21 +0800 | [diff] [blame] | 592 | regval = 0; |
| 593 | } else { |
| 594 | regval = readl_relaxed(data->base + REG_MMU_MISC_CTRL); |
| 595 | regval &= ~F_MMU_STANDARD_AXI_MODE_MASK; |
| 596 | if (MTK_IOMMU_HAS_FLAG(data->plat_data, OUT_ORDER_WR_EN)) |
| 597 | regval &= ~F_MMU_IN_ORDER_WR_EN_MASK; |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 598 | } |
Chao Hao | 4bb2bf4 | 2020-07-03 12:41:21 +0800 | [diff] [blame] | 599 | writel_relaxed(regval, data->base + REG_MMU_MISC_CTRL); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 600 | |
| 601 | if (devm_request_irq(data->dev, data->irq, mtk_iommu_isr, 0, |
| 602 | dev_name(data->dev), (void *)data)) { |
| 603 | writel_relaxed(0, data->base + REG_MMU_PT_BASE_ADDR); |
| 604 | clk_disable_unprepare(data->bclk); |
| 605 | dev_err(data->dev, "Failed @ IRQ-%d Request\n", data->irq); |
| 606 | return -ENODEV; |
| 607 | } |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 612 | static const struct component_master_ops mtk_iommu_com_ops = { |
| 613 | .bind = mtk_iommu_bind, |
| 614 | .unbind = mtk_iommu_unbind, |
| 615 | }; |
| 616 | |
| 617 | static int mtk_iommu_probe(struct platform_device *pdev) |
| 618 | { |
| 619 | struct mtk_iommu_data *data; |
| 620 | struct device *dev = &pdev->dev; |
| 621 | struct resource *res; |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 622 | resource_size_t ioaddr; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 623 | struct component_match *match = NULL; |
| 624 | void *protect; |
Andrzej Hajda | 0b6c0ad | 2016-03-01 10:36:23 +0100 | [diff] [blame] | 625 | int i, larb_nr, ret; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 626 | |
| 627 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
| 628 | if (!data) |
| 629 | return -ENOMEM; |
| 630 | data->dev = dev; |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 631 | data->plat_data = of_device_get_match_data(dev); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 632 | |
| 633 | /* Protect memory. HW will access here while translation fault.*/ |
| 634 | protect = devm_kzalloc(dev, MTK_PROTECT_PA_ALIGN * 2, GFP_KERNEL); |
| 635 | if (!protect) |
| 636 | return -ENOMEM; |
| 637 | data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN); |
| 638 | |
Yong Wu | 01e23c9 | 2016-03-14 06:01:11 +0800 | [diff] [blame] | 639 | /* Whether the current dram is over 4GB */ |
Yong Wu | 4193998 | 2017-08-24 15:42:12 +0800 | [diff] [blame] | 640 | data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT)); |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 641 | if (!MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) |
Yong Wu | b4dad40 | 2019-08-24 11:01:55 +0800 | [diff] [blame] | 642 | data->enable_4GB = false; |
Yong Wu | 01e23c9 | 2016-03-14 06:01:11 +0800 | [diff] [blame] | 643 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 644 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 645 | data->base = devm_ioremap_resource(dev, res); |
| 646 | if (IS_ERR(data->base)) |
| 647 | return PTR_ERR(data->base); |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 648 | ioaddr = res->start; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 649 | |
| 650 | data->irq = platform_get_irq(pdev, 0); |
| 651 | if (data->irq < 0) |
| 652 | return data->irq; |
| 653 | |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 654 | if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) { |
Yong Wu | 2aa4c25 | 2019-08-24 11:01:56 +0800 | [diff] [blame] | 655 | data->bclk = devm_clk_get(dev, "bclk"); |
| 656 | if (IS_ERR(data->bclk)) |
| 657 | return PTR_ERR(data->bclk); |
| 658 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 659 | |
| 660 | larb_nr = of_count_phandle_with_args(dev->of_node, |
| 661 | "mediatek,larbs", NULL); |
| 662 | if (larb_nr < 0) |
| 663 | return larb_nr; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 664 | |
| 665 | for (i = 0; i < larb_nr; i++) { |
| 666 | struct device_node *larbnode; |
| 667 | struct platform_device *plarbdev; |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 668 | u32 id; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 669 | |
| 670 | larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); |
| 671 | if (!larbnode) |
| 672 | return -EINVAL; |
| 673 | |
Wen Yang | 1eb8e4e | 2019-04-17 10:41:19 +0800 | [diff] [blame] | 674 | if (!of_device_is_available(larbnode)) { |
| 675 | of_node_put(larbnode); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 676 | continue; |
Wen Yang | 1eb8e4e | 2019-04-17 10:41:19 +0800 | [diff] [blame] | 677 | } |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 678 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 679 | ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id); |
| 680 | if (ret)/* The id is consecutive if there is no this property */ |
| 681 | id = i; |
| 682 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 683 | plarbdev = of_find_device_by_node(larbnode); |
Wen Yang | 1eb8e4e | 2019-04-17 10:41:19 +0800 | [diff] [blame] | 684 | if (!plarbdev) { |
| 685 | of_node_put(larbnode); |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 686 | return -EPROBE_DEFER; |
Wen Yang | 1eb8e4e | 2019-04-17 10:41:19 +0800 | [diff] [blame] | 687 | } |
Yong Wu | 1ee9feb | 2019-08-24 11:02:08 +0800 | [diff] [blame] | 688 | data->larb_imu[id].dev = &plarbdev->dev; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 689 | |
Russell King | 00c7c81 | 2016-10-19 11:30:34 +0100 | [diff] [blame] | 690 | component_match_add_release(dev, &match, release_of, |
| 691 | compare_of, larbnode); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | platform_set_drvdata(pdev, data); |
| 695 | |
| 696 | ret = mtk_iommu_hw_init(data); |
| 697 | if (ret) |
| 698 | return ret; |
| 699 | |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 700 | ret = iommu_device_sysfs_add(&data->iommu, dev, NULL, |
| 701 | "mtk-iommu.%pa", &ioaddr); |
| 702 | if (ret) |
| 703 | return ret; |
| 704 | |
| 705 | iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); |
| 706 | iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode); |
| 707 | |
| 708 | ret = iommu_device_register(&data->iommu); |
| 709 | if (ret) |
| 710 | return ret; |
| 711 | |
Yong Wu | da3cc91 | 2019-11-04 15:01:03 +0800 | [diff] [blame] | 712 | spin_lock_init(&data->tlb_lock); |
Yong Wu | 7c3a2ec | 2017-08-21 19:00:17 +0800 | [diff] [blame] | 713 | list_add_tail(&data->list, &m4ulist); |
| 714 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 715 | if (!iommu_present(&platform_bus_type)) |
| 716 | bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); |
| 717 | |
| 718 | return component_master_add_with_match(dev, &mtk_iommu_com_ops, match); |
| 719 | } |
| 720 | |
| 721 | static int mtk_iommu_remove(struct platform_device *pdev) |
| 722 | { |
| 723 | struct mtk_iommu_data *data = platform_get_drvdata(pdev); |
| 724 | |
Joerg Roedel | b16c017 | 2017-02-03 12:57:32 +0100 | [diff] [blame] | 725 | iommu_device_sysfs_remove(&data->iommu); |
| 726 | iommu_device_unregister(&data->iommu); |
| 727 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 728 | if (iommu_present(&platform_bus_type)) |
| 729 | bus_set_iommu(&platform_bus_type, NULL); |
| 730 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 731 | clk_disable_unprepare(data->bclk); |
| 732 | devm_free_irq(&pdev->dev, data->irq, data); |
| 733 | component_master_del(&pdev->dev, &mtk_iommu_com_ops); |
| 734 | return 0; |
| 735 | } |
| 736 | |
Arnd Bergmann | fd99f79 | 2016-02-29 10:19:07 +0100 | [diff] [blame] | 737 | static int __maybe_unused mtk_iommu_suspend(struct device *dev) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 738 | { |
| 739 | struct mtk_iommu_data *data = dev_get_drvdata(dev); |
| 740 | struct mtk_iommu_suspend_reg *reg = &data->reg; |
| 741 | void __iomem *base = data->base; |
| 742 | |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 743 | reg->misc_ctrl = readl_relaxed(base + REG_MMU_MISC_CTRL); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 744 | reg->dcm_dis = readl_relaxed(base + REG_MMU_DCM_DIS); |
| 745 | reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); |
| 746 | reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0); |
| 747 | reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL); |
Yong Wu | 70ca608 | 2018-03-18 09:52:54 +0800 | [diff] [blame] | 748 | reg->ivrp_paddr = readl_relaxed(base + REG_MMU_IVRP_PADDR); |
Yong Wu | b9475b3 | 2019-08-24 11:02:06 +0800 | [diff] [blame] | 749 | reg->vld_pa_rng = readl_relaxed(base + REG_MMU_VLD_PA_RNG); |
Yong Wu | 6254b64 | 2017-08-21 19:00:19 +0800 | [diff] [blame] | 750 | clk_disable_unprepare(data->bclk); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 751 | return 0; |
| 752 | } |
| 753 | |
Arnd Bergmann | fd99f79 | 2016-02-29 10:19:07 +0100 | [diff] [blame] | 754 | static int __maybe_unused mtk_iommu_resume(struct device *dev) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 755 | { |
| 756 | struct mtk_iommu_data *data = dev_get_drvdata(dev); |
| 757 | struct mtk_iommu_suspend_reg *reg = &data->reg; |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 758 | struct mtk_iommu_domain *m4u_dom = data->m4u_dom; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 759 | void __iomem *base = data->base; |
Yong Wu | 6254b64 | 2017-08-21 19:00:19 +0800 | [diff] [blame] | 760 | int ret; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 761 | |
Yong Wu | 6254b64 | 2017-08-21 19:00:19 +0800 | [diff] [blame] | 762 | ret = clk_prepare_enable(data->bclk); |
| 763 | if (ret) { |
| 764 | dev_err(data->dev, "Failed to enable clk(%d) in resume\n", ret); |
| 765 | return ret; |
| 766 | } |
Chao Hao | 75eed35 | 2020-07-03 12:41:19 +0800 | [diff] [blame] | 767 | writel_relaxed(reg->misc_ctrl, base + REG_MMU_MISC_CTRL); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 768 | writel_relaxed(reg->dcm_dis, base + REG_MMU_DCM_DIS); |
| 769 | writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); |
| 770 | writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); |
| 771 | writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); |
Yong Wu | 70ca608 | 2018-03-18 09:52:54 +0800 | [diff] [blame] | 772 | writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR); |
Yong Wu | b9475b3 | 2019-08-24 11:02:06 +0800 | [diff] [blame] | 773 | writel_relaxed(reg->vld_pa_rng, base + REG_MMU_VLD_PA_RNG); |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 774 | if (m4u_dom) |
Robin Murphy | d1e5f26 | 2019-10-25 19:08:37 +0100 | [diff] [blame] | 775 | writel(m4u_dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 776 | base + REG_MMU_PT_BASE_ADDR); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 780 | static const struct dev_pm_ops mtk_iommu_pm_ops = { |
Yong Wu | 6254b64 | 2017-08-21 19:00:19 +0800 | [diff] [blame] | 781 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mtk_iommu_suspend, mtk_iommu_resume) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 782 | }; |
| 783 | |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 784 | static const struct mtk_iommu_plat_data mt2712_data = { |
| 785 | .m4u_plat = M4U_MT2712, |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 786 | .flags = HAS_4GB_MODE | HAS_BCLK | HAS_VLD_PA_RNG, |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 787 | .inv_sel_reg = REG_MMU_INV_SEL_GEN1, |
Yong Wu | b3e5eee7 | 2019-08-24 11:01:57 +0800 | [diff] [blame] | 788 | .larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 789 | }; |
| 790 | |
| 791 | static const struct mtk_iommu_plat_data mt8173_data = { |
| 792 | .m4u_plat = M4U_MT8173, |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 793 | .flags = HAS_4GB_MODE | HAS_BCLK | RESET_AXI, |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 794 | .inv_sel_reg = REG_MMU_INV_SEL_GEN1, |
Yong Wu | b3e5eee7 | 2019-08-24 11:01:57 +0800 | [diff] [blame] | 795 | .larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 796 | }; |
| 797 | |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 798 | static const struct mtk_iommu_plat_data mt8183_data = { |
| 799 | .m4u_plat = M4U_MT8183, |
Chao Hao | 6b71779 | 2020-07-03 12:41:20 +0800 | [diff] [blame] | 800 | .flags = RESET_AXI, |
Chao Hao | b053bc7 | 2020-07-03 12:41:22 +0800 | [diff] [blame^] | 801 | .inv_sel_reg = REG_MMU_INV_SEL_GEN1, |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 802 | .larbid_remap = {0, 4, 5, 6, 7, 2, 3, 1}, |
| 803 | }; |
| 804 | |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 805 | static const struct of_device_id mtk_iommu_of_ids[] = { |
Yong Wu | cecdce9 | 2019-08-24 11:01:47 +0800 | [diff] [blame] | 806 | { .compatible = "mediatek,mt2712-m4u", .data = &mt2712_data}, |
| 807 | { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, |
Yong Wu | 907ba6a | 2019-08-24 11:02:02 +0800 | [diff] [blame] | 808 | { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 809 | {} |
| 810 | }; |
| 811 | |
| 812 | static struct platform_driver mtk_iommu_driver = { |
| 813 | .probe = mtk_iommu_probe, |
| 814 | .remove = mtk_iommu_remove, |
| 815 | .driver = { |
| 816 | .name = "mtk-iommu", |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 817 | .of_match_table = of_match_ptr(mtk_iommu_of_ids), |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 818 | .pm = &mtk_iommu_pm_ops, |
| 819 | } |
| 820 | }; |
| 821 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 822 | static int __init mtk_iommu_init(void) |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 823 | { |
| 824 | int ret; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 825 | |
| 826 | ret = platform_driver_register(&mtk_iommu_driver); |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 827 | if (ret != 0) |
| 828 | pr_err("Failed to register MTK IOMMU driver\n"); |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 829 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 830 | return ret; |
Yong Wu | 0df4fab | 2016-02-23 01:20:50 +0800 | [diff] [blame] | 831 | } |
| 832 | |
Yong Wu | e6dec92 | 2017-08-21 19:00:16 +0800 | [diff] [blame] | 833 | subsys_initcall(mtk_iommu_init) |