1b17336c5SHonghui Zhang /* 2d4cf5bbdSPaul Gortmaker * IOMMU API for MTK architected m4u v1 implementations 3d4cf5bbdSPaul Gortmaker * 4b17336c5SHonghui Zhang * Copyright (c) 2015-2016 MediaTek Inc. 5b17336c5SHonghui Zhang * Author: Honghui Zhang <honghui.zhang@mediatek.com> 6b17336c5SHonghui Zhang * 7b17336c5SHonghui Zhang * Based on driver/iommu/mtk_iommu.c 8b17336c5SHonghui Zhang * 9b17336c5SHonghui Zhang * This program is free software; you can redistribute it and/or modify 10b17336c5SHonghui Zhang * it under the terms of the GNU General Public License version 2 as 11b17336c5SHonghui Zhang * published by the Free Software Foundation. 12b17336c5SHonghui Zhang * 13b17336c5SHonghui Zhang * This program is distributed in the hope that it will be useful, 14b17336c5SHonghui Zhang * but WITHOUT ANY WARRANTY; without even the implied warranty of 15b17336c5SHonghui Zhang * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16b17336c5SHonghui Zhang * GNU General Public License for more details. 17b17336c5SHonghui Zhang */ 1857c8a661SMike Rapoport #include <linux/memblock.h> 19b17336c5SHonghui Zhang #include <linux/bug.h> 20b17336c5SHonghui Zhang #include <linux/clk.h> 21b17336c5SHonghui Zhang #include <linux/component.h> 22b17336c5SHonghui Zhang #include <linux/device.h> 23745b6e74SArnd Bergmann #include <linux/dma-mapping.h> 24b17336c5SHonghui Zhang #include <linux/dma-iommu.h> 25b17336c5SHonghui Zhang #include <linux/err.h> 26b17336c5SHonghui Zhang #include <linux/interrupt.h> 27b17336c5SHonghui Zhang #include <linux/io.h> 28b17336c5SHonghui Zhang #include <linux/iommu.h> 29b17336c5SHonghui Zhang #include <linux/iopoll.h> 30b17336c5SHonghui Zhang #include <linux/list.h> 31b17336c5SHonghui Zhang #include <linux/of_address.h> 32b17336c5SHonghui Zhang #include <linux/of_iommu.h> 33b17336c5SHonghui Zhang #include <linux/of_irq.h> 34b17336c5SHonghui Zhang #include <linux/of_platform.h> 35b17336c5SHonghui Zhang #include <linux/platform_device.h> 36b17336c5SHonghui Zhang #include <linux/slab.h> 37b17336c5SHonghui Zhang #include <linux/spinlock.h> 38b17336c5SHonghui Zhang #include <asm/barrier.h> 39b17336c5SHonghui Zhang #include <asm/dma-iommu.h> 40d4cf5bbdSPaul Gortmaker #include <linux/init.h> 41b17336c5SHonghui Zhang #include <dt-bindings/memory/mt2701-larb-port.h> 42b17336c5SHonghui Zhang #include <soc/mediatek/smi.h> 43b17336c5SHonghui Zhang #include "mtk_iommu.h" 44b17336c5SHonghui Zhang 45b17336c5SHonghui Zhang #define REG_MMU_PT_BASE_ADDR 0x000 46b17336c5SHonghui Zhang 47b17336c5SHonghui Zhang #define F_ALL_INVLD 0x2 48b17336c5SHonghui Zhang #define F_MMU_INV_RANGE 0x1 49b17336c5SHonghui Zhang #define F_INVLD_EN0 BIT(0) 50b17336c5SHonghui Zhang #define F_INVLD_EN1 BIT(1) 51b17336c5SHonghui Zhang 52b17336c5SHonghui Zhang #define F_MMU_FAULT_VA_MSK 0xfffff000 53b17336c5SHonghui Zhang #define MTK_PROTECT_PA_ALIGN 128 54b17336c5SHonghui Zhang 55b17336c5SHonghui Zhang #define REG_MMU_CTRL_REG 0x210 56b17336c5SHonghui Zhang #define F_MMU_CTRL_COHERENT_EN BIT(8) 57b17336c5SHonghui Zhang #define REG_MMU_IVRP_PADDR 0x214 58b17336c5SHonghui Zhang #define REG_MMU_INT_CONTROL 0x220 59b17336c5SHonghui Zhang #define F_INT_TRANSLATION_FAULT BIT(0) 60b17336c5SHonghui Zhang #define F_INT_MAIN_MULTI_HIT_FAULT BIT(1) 61b17336c5SHonghui Zhang #define F_INT_INVALID_PA_FAULT BIT(2) 62b17336c5SHonghui Zhang #define F_INT_ENTRY_REPLACEMENT_FAULT BIT(3) 63b17336c5SHonghui Zhang #define F_INT_TABLE_WALK_FAULT BIT(4) 64b17336c5SHonghui Zhang #define F_INT_TLB_MISS_FAULT BIT(5) 65b17336c5SHonghui Zhang #define F_INT_PFH_DMA_FIFO_OVERFLOW BIT(6) 66b17336c5SHonghui Zhang #define F_INT_MISS_DMA_FIFO_OVERFLOW BIT(7) 67b17336c5SHonghui Zhang 68b17336c5SHonghui Zhang #define F_MMU_TF_PROTECT_SEL(prot) (((prot) & 0x3) << 5) 69b17336c5SHonghui Zhang #define F_INT_CLR_BIT BIT(12) 70b17336c5SHonghui Zhang 71b17336c5SHonghui Zhang #define REG_MMU_FAULT_ST 0x224 72b17336c5SHonghui Zhang #define REG_MMU_FAULT_VA 0x228 73b17336c5SHonghui Zhang #define REG_MMU_INVLD_PA 0x22C 74b17336c5SHonghui Zhang #define REG_MMU_INT_ID 0x388 75b17336c5SHonghui Zhang #define REG_MMU_INVALIDATE 0x5c0 76b17336c5SHonghui Zhang #define REG_MMU_INVLD_START_A 0x5c4 77b17336c5SHonghui Zhang #define REG_MMU_INVLD_END_A 0x5c8 78b17336c5SHonghui Zhang 79b17336c5SHonghui Zhang #define REG_MMU_INV_SEL 0x5d8 80b17336c5SHonghui Zhang #define REG_MMU_STANDARD_AXI_MODE 0x5e8 81b17336c5SHonghui Zhang 82b17336c5SHonghui Zhang #define REG_MMU_DCM 0x5f0 83b17336c5SHonghui Zhang #define F_MMU_DCM_ON BIT(1) 84b17336c5SHonghui Zhang #define REG_MMU_CPE_DONE 0x60c 85b17336c5SHonghui Zhang #define F_DESC_VALID 0x2 86b17336c5SHonghui Zhang #define F_DESC_NONSEC BIT(3) 87b17336c5SHonghui Zhang #define MT2701_M4U_TF_LARB(TF) (6 - (((TF) >> 13) & 0x7)) 88b17336c5SHonghui Zhang #define MT2701_M4U_TF_PORT(TF) (((TF) >> 8) & 0xF) 89b17336c5SHonghui Zhang /* MTK generation one iommu HW only support 4K size mapping */ 90b17336c5SHonghui Zhang #define MT2701_IOMMU_PAGE_SHIFT 12 91b17336c5SHonghui Zhang #define MT2701_IOMMU_PAGE_SIZE (1UL << MT2701_IOMMU_PAGE_SHIFT) 92b17336c5SHonghui Zhang 93b17336c5SHonghui Zhang /* 94b17336c5SHonghui Zhang * MTK m4u support 4GB iova address space, and only support 4K page 95b17336c5SHonghui Zhang * mapping. So the pagetable size should be exactly as 4M. 96b17336c5SHonghui Zhang */ 97b17336c5SHonghui Zhang #define M2701_IOMMU_PGT_SIZE SZ_4M 98b17336c5SHonghui Zhang 99b17336c5SHonghui Zhang struct mtk_iommu_domain { 100b17336c5SHonghui Zhang spinlock_t pgtlock; /* lock for page table */ 101b17336c5SHonghui Zhang struct iommu_domain domain; 102b17336c5SHonghui Zhang u32 *pgt_va; 103b17336c5SHonghui Zhang dma_addr_t pgt_pa; 104b17336c5SHonghui Zhang struct mtk_iommu_data *data; 105b17336c5SHonghui Zhang }; 106b17336c5SHonghui Zhang 107b17336c5SHonghui Zhang static struct mtk_iommu_domain *to_mtk_domain(struct iommu_domain *dom) 108b17336c5SHonghui Zhang { 109b17336c5SHonghui Zhang return container_of(dom, struct mtk_iommu_domain, domain); 110b17336c5SHonghui Zhang } 111b17336c5SHonghui Zhang 112b17336c5SHonghui Zhang static const int mt2701_m4u_in_larb[] = { 113b17336c5SHonghui Zhang LARB0_PORT_OFFSET, LARB1_PORT_OFFSET, 114b17336c5SHonghui Zhang LARB2_PORT_OFFSET, LARB3_PORT_OFFSET 115b17336c5SHonghui Zhang }; 116b17336c5SHonghui Zhang 117b17336c5SHonghui Zhang static inline int mt2701_m4u_to_larb(int id) 118b17336c5SHonghui Zhang { 119b17336c5SHonghui Zhang int i; 120b17336c5SHonghui Zhang 121b17336c5SHonghui Zhang for (i = ARRAY_SIZE(mt2701_m4u_in_larb) - 1; i >= 0; i--) 122b17336c5SHonghui Zhang if ((id) >= mt2701_m4u_in_larb[i]) 123b17336c5SHonghui Zhang return i; 124b17336c5SHonghui Zhang 125b17336c5SHonghui Zhang return 0; 126b17336c5SHonghui Zhang } 127b17336c5SHonghui Zhang 128b17336c5SHonghui Zhang static inline int mt2701_m4u_to_port(int id) 129b17336c5SHonghui Zhang { 130b17336c5SHonghui Zhang int larb = mt2701_m4u_to_larb(id); 131b17336c5SHonghui Zhang 132b17336c5SHonghui Zhang return id - mt2701_m4u_in_larb[larb]; 133b17336c5SHonghui Zhang } 134b17336c5SHonghui Zhang 135b17336c5SHonghui Zhang static void mtk_iommu_tlb_flush_all(struct mtk_iommu_data *data) 136b17336c5SHonghui Zhang { 137b17336c5SHonghui Zhang writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 138b17336c5SHonghui Zhang data->base + REG_MMU_INV_SEL); 139b17336c5SHonghui Zhang writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE); 140b17336c5SHonghui Zhang wmb(); /* Make sure the tlb flush all done */ 141b17336c5SHonghui Zhang } 142b17336c5SHonghui Zhang 143b17336c5SHonghui Zhang static void mtk_iommu_tlb_flush_range(struct mtk_iommu_data *data, 144b17336c5SHonghui Zhang unsigned long iova, size_t size) 145b17336c5SHonghui Zhang { 146b17336c5SHonghui Zhang int ret; 147b17336c5SHonghui Zhang u32 tmp; 148b17336c5SHonghui Zhang 149b17336c5SHonghui Zhang writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0, 150b17336c5SHonghui Zhang data->base + REG_MMU_INV_SEL); 151b17336c5SHonghui Zhang writel_relaxed(iova & F_MMU_FAULT_VA_MSK, 152b17336c5SHonghui Zhang data->base + REG_MMU_INVLD_START_A); 153b17336c5SHonghui Zhang writel_relaxed((iova + size - 1) & F_MMU_FAULT_VA_MSK, 154b17336c5SHonghui Zhang data->base + REG_MMU_INVLD_END_A); 155b17336c5SHonghui Zhang writel_relaxed(F_MMU_INV_RANGE, data->base + REG_MMU_INVALIDATE); 156b17336c5SHonghui Zhang 157b17336c5SHonghui Zhang ret = readl_poll_timeout_atomic(data->base + REG_MMU_CPE_DONE, 158b17336c5SHonghui Zhang tmp, tmp != 0, 10, 100000); 159b17336c5SHonghui Zhang if (ret) { 160b17336c5SHonghui Zhang dev_warn(data->dev, 161b17336c5SHonghui Zhang "Partial TLB flush timed out, falling back to full flush\n"); 162b17336c5SHonghui Zhang mtk_iommu_tlb_flush_all(data); 163b17336c5SHonghui Zhang } 164b17336c5SHonghui Zhang /* Clear the CPE status */ 165b17336c5SHonghui Zhang writel_relaxed(0, data->base + REG_MMU_CPE_DONE); 166b17336c5SHonghui Zhang } 167b17336c5SHonghui Zhang 168b17336c5SHonghui Zhang static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) 169b17336c5SHonghui Zhang { 170b17336c5SHonghui Zhang struct mtk_iommu_data *data = dev_id; 171b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = data->m4u_dom; 172b17336c5SHonghui Zhang u32 int_state, regval, fault_iova, fault_pa; 173b17336c5SHonghui Zhang unsigned int fault_larb, fault_port; 174b17336c5SHonghui Zhang 175b17336c5SHonghui Zhang /* Read error information from registers */ 176b17336c5SHonghui Zhang int_state = readl_relaxed(data->base + REG_MMU_FAULT_ST); 177b17336c5SHonghui Zhang fault_iova = readl_relaxed(data->base + REG_MMU_FAULT_VA); 178b17336c5SHonghui Zhang 179b17336c5SHonghui Zhang fault_iova &= F_MMU_FAULT_VA_MSK; 180b17336c5SHonghui Zhang fault_pa = readl_relaxed(data->base + REG_MMU_INVLD_PA); 181b17336c5SHonghui Zhang regval = readl_relaxed(data->base + REG_MMU_INT_ID); 182b17336c5SHonghui Zhang fault_larb = MT2701_M4U_TF_LARB(regval); 183b17336c5SHonghui Zhang fault_port = MT2701_M4U_TF_PORT(regval); 184b17336c5SHonghui Zhang 185b17336c5SHonghui Zhang /* 186b17336c5SHonghui Zhang * MTK v1 iommu HW could not determine whether the fault is read or 187b17336c5SHonghui Zhang * write fault, report as read fault. 188b17336c5SHonghui Zhang */ 189b17336c5SHonghui Zhang if (report_iommu_fault(&dom->domain, data->dev, fault_iova, 190b17336c5SHonghui Zhang IOMMU_FAULT_READ)) 191b17336c5SHonghui Zhang dev_err_ratelimited(data->dev, 192b17336c5SHonghui Zhang "fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d\n", 193b17336c5SHonghui Zhang int_state, fault_iova, fault_pa, 194b17336c5SHonghui Zhang fault_larb, fault_port); 195b17336c5SHonghui Zhang 196b17336c5SHonghui Zhang /* Interrupt clear */ 197b17336c5SHonghui Zhang regval = readl_relaxed(data->base + REG_MMU_INT_CONTROL); 198b17336c5SHonghui Zhang regval |= F_INT_CLR_BIT; 199b17336c5SHonghui Zhang writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL); 200b17336c5SHonghui Zhang 201b17336c5SHonghui Zhang mtk_iommu_tlb_flush_all(data); 202b17336c5SHonghui Zhang 203b17336c5SHonghui Zhang return IRQ_HANDLED; 204b17336c5SHonghui Zhang } 205b17336c5SHonghui Zhang 206b17336c5SHonghui Zhang static void mtk_iommu_config(struct mtk_iommu_data *data, 207b17336c5SHonghui Zhang struct device *dev, bool enable) 208b17336c5SHonghui Zhang { 209b17336c5SHonghui Zhang struct mtk_smi_larb_iommu *larb_mmu; 210b17336c5SHonghui Zhang unsigned int larbid, portid; 211a9bf2eecSJoerg Roedel struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 21284672f19SRobin Murphy int i; 213b17336c5SHonghui Zhang 21484672f19SRobin Murphy for (i = 0; i < fwspec->num_ids; ++i) { 21584672f19SRobin Murphy larbid = mt2701_m4u_to_larb(fwspec->ids[i]); 21684672f19SRobin Murphy portid = mt2701_m4u_to_port(fwspec->ids[i]); 217b17336c5SHonghui Zhang larb_mmu = &data->smi_imu.larb_imu[larbid]; 218b17336c5SHonghui Zhang 219b17336c5SHonghui Zhang dev_dbg(dev, "%s iommu port: %d\n", 220b17336c5SHonghui Zhang enable ? "enable" : "disable", portid); 221b17336c5SHonghui Zhang 222b17336c5SHonghui Zhang if (enable) 223b17336c5SHonghui Zhang larb_mmu->mmu |= MTK_SMI_MMU_EN(portid); 224b17336c5SHonghui Zhang else 225b17336c5SHonghui Zhang larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid); 226b17336c5SHonghui Zhang } 227b17336c5SHonghui Zhang } 228b17336c5SHonghui Zhang 229b17336c5SHonghui Zhang static int mtk_iommu_domain_finalise(struct mtk_iommu_data *data) 230b17336c5SHonghui Zhang { 231b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = data->m4u_dom; 232b17336c5SHonghui Zhang 233b17336c5SHonghui Zhang spin_lock_init(&dom->pgtlock); 234b17336c5SHonghui Zhang 235750afb08SLuis Chamberlain dom->pgt_va = dma_alloc_coherent(data->dev, M2701_IOMMU_PGT_SIZE, 236b17336c5SHonghui Zhang &dom->pgt_pa, GFP_KERNEL); 237b17336c5SHonghui Zhang if (!dom->pgt_va) 238b17336c5SHonghui Zhang return -ENOMEM; 239b17336c5SHonghui Zhang 240b17336c5SHonghui Zhang writel(dom->pgt_pa, data->base + REG_MMU_PT_BASE_ADDR); 241b17336c5SHonghui Zhang 242b17336c5SHonghui Zhang dom->data = data; 243b17336c5SHonghui Zhang 244b17336c5SHonghui Zhang return 0; 245b17336c5SHonghui Zhang } 246b17336c5SHonghui Zhang 247b17336c5SHonghui Zhang static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type) 248b17336c5SHonghui Zhang { 249b17336c5SHonghui Zhang struct mtk_iommu_domain *dom; 250b17336c5SHonghui Zhang 251b17336c5SHonghui Zhang if (type != IOMMU_DOMAIN_UNMANAGED) 252b17336c5SHonghui Zhang return NULL; 253b17336c5SHonghui Zhang 254b17336c5SHonghui Zhang dom = kzalloc(sizeof(*dom), GFP_KERNEL); 255b17336c5SHonghui Zhang if (!dom) 256b17336c5SHonghui Zhang return NULL; 257b17336c5SHonghui Zhang 258b17336c5SHonghui Zhang return &dom->domain; 259b17336c5SHonghui Zhang } 260b17336c5SHonghui Zhang 261b17336c5SHonghui Zhang static void mtk_iommu_domain_free(struct iommu_domain *domain) 262b17336c5SHonghui Zhang { 263b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = to_mtk_domain(domain); 264b17336c5SHonghui Zhang struct mtk_iommu_data *data = dom->data; 265b17336c5SHonghui Zhang 266b17336c5SHonghui Zhang dma_free_coherent(data->dev, M2701_IOMMU_PGT_SIZE, 267b17336c5SHonghui Zhang dom->pgt_va, dom->pgt_pa); 268b17336c5SHonghui Zhang kfree(to_mtk_domain(domain)); 269b17336c5SHonghui Zhang } 270b17336c5SHonghui Zhang 271b17336c5SHonghui Zhang static int mtk_iommu_attach_device(struct iommu_domain *domain, 272b17336c5SHonghui Zhang struct device *dev) 273b17336c5SHonghui Zhang { 274b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = to_mtk_domain(domain); 275a9bf2eecSJoerg Roedel struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv; 276b17336c5SHonghui Zhang int ret; 277b17336c5SHonghui Zhang 27884672f19SRobin Murphy if (!data) 279b17336c5SHonghui Zhang return -ENODEV; 280b17336c5SHonghui Zhang 281b17336c5SHonghui Zhang if (!data->m4u_dom) { 282b17336c5SHonghui Zhang data->m4u_dom = dom; 283b17336c5SHonghui Zhang ret = mtk_iommu_domain_finalise(data); 284b17336c5SHonghui Zhang if (ret) { 285b17336c5SHonghui Zhang data->m4u_dom = NULL; 286b17336c5SHonghui Zhang return ret; 287b17336c5SHonghui Zhang } 288b17336c5SHonghui Zhang } 289b17336c5SHonghui Zhang 290b17336c5SHonghui Zhang mtk_iommu_config(data, dev, true); 291b17336c5SHonghui Zhang return 0; 292b17336c5SHonghui Zhang } 293b17336c5SHonghui Zhang 294b17336c5SHonghui Zhang static void mtk_iommu_detach_device(struct iommu_domain *domain, 295b17336c5SHonghui Zhang struct device *dev) 296b17336c5SHonghui Zhang { 297a9bf2eecSJoerg Roedel struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv; 298b17336c5SHonghui Zhang 29984672f19SRobin Murphy if (!data) 300b17336c5SHonghui Zhang return; 301b17336c5SHonghui Zhang 302b17336c5SHonghui Zhang mtk_iommu_config(data, dev, false); 303b17336c5SHonghui Zhang } 304b17336c5SHonghui Zhang 305b17336c5SHonghui Zhang static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, 306b17336c5SHonghui Zhang phys_addr_t paddr, size_t size, int prot) 307b17336c5SHonghui Zhang { 308b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = to_mtk_domain(domain); 309b17336c5SHonghui Zhang unsigned int page_num = size >> MT2701_IOMMU_PAGE_SHIFT; 310b17336c5SHonghui Zhang unsigned long flags; 311b17336c5SHonghui Zhang unsigned int i; 312b17336c5SHonghui Zhang u32 *pgt_base_iova = dom->pgt_va + (iova >> MT2701_IOMMU_PAGE_SHIFT); 313b17336c5SHonghui Zhang u32 pabase = (u32)paddr; 314b17336c5SHonghui Zhang int map_size = 0; 315b17336c5SHonghui Zhang 316b17336c5SHonghui Zhang spin_lock_irqsave(&dom->pgtlock, flags); 317b17336c5SHonghui Zhang for (i = 0; i < page_num; i++) { 318b17336c5SHonghui Zhang if (pgt_base_iova[i]) { 319b17336c5SHonghui Zhang memset(pgt_base_iova, 0, i * sizeof(u32)); 320b17336c5SHonghui Zhang break; 321b17336c5SHonghui Zhang } 322b17336c5SHonghui Zhang pgt_base_iova[i] = pabase | F_DESC_VALID | F_DESC_NONSEC; 323b17336c5SHonghui Zhang pabase += MT2701_IOMMU_PAGE_SIZE; 324b17336c5SHonghui Zhang map_size += MT2701_IOMMU_PAGE_SIZE; 325b17336c5SHonghui Zhang } 326b17336c5SHonghui Zhang 327b17336c5SHonghui Zhang spin_unlock_irqrestore(&dom->pgtlock, flags); 328b17336c5SHonghui Zhang 329b17336c5SHonghui Zhang mtk_iommu_tlb_flush_range(dom->data, iova, size); 330b17336c5SHonghui Zhang 331b17336c5SHonghui Zhang return map_size == size ? 0 : -EEXIST; 332b17336c5SHonghui Zhang } 333b17336c5SHonghui Zhang 334b17336c5SHonghui Zhang static size_t mtk_iommu_unmap(struct iommu_domain *domain, 335b17336c5SHonghui Zhang unsigned long iova, size_t size) 336b17336c5SHonghui Zhang { 337b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = to_mtk_domain(domain); 338b17336c5SHonghui Zhang unsigned long flags; 339b17336c5SHonghui Zhang u32 *pgt_base_iova = dom->pgt_va + (iova >> MT2701_IOMMU_PAGE_SHIFT); 340b17336c5SHonghui Zhang unsigned int page_num = size >> MT2701_IOMMU_PAGE_SHIFT; 341b17336c5SHonghui Zhang 342b17336c5SHonghui Zhang spin_lock_irqsave(&dom->pgtlock, flags); 343b17336c5SHonghui Zhang memset(pgt_base_iova, 0, page_num * sizeof(u32)); 344b17336c5SHonghui Zhang spin_unlock_irqrestore(&dom->pgtlock, flags); 345b17336c5SHonghui Zhang 346b17336c5SHonghui Zhang mtk_iommu_tlb_flush_range(dom->data, iova, size); 347b17336c5SHonghui Zhang 348b17336c5SHonghui Zhang return size; 349b17336c5SHonghui Zhang } 350b17336c5SHonghui Zhang 351b17336c5SHonghui Zhang static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain, 352b17336c5SHonghui Zhang dma_addr_t iova) 353b17336c5SHonghui Zhang { 354b17336c5SHonghui Zhang struct mtk_iommu_domain *dom = to_mtk_domain(domain); 355b17336c5SHonghui Zhang unsigned long flags; 356b17336c5SHonghui Zhang phys_addr_t pa; 357b17336c5SHonghui Zhang 358b17336c5SHonghui Zhang spin_lock_irqsave(&dom->pgtlock, flags); 359b17336c5SHonghui Zhang pa = *(dom->pgt_va + (iova >> MT2701_IOMMU_PAGE_SHIFT)); 360b17336c5SHonghui Zhang pa = pa & (~(MT2701_IOMMU_PAGE_SIZE - 1)); 361b17336c5SHonghui Zhang spin_unlock_irqrestore(&dom->pgtlock, flags); 362b17336c5SHonghui Zhang 363b17336c5SHonghui Zhang return pa; 364b17336c5SHonghui Zhang } 365b17336c5SHonghui Zhang 366b65f5016SArvind Yadav static const struct iommu_ops mtk_iommu_ops; 36784672f19SRobin Murphy 368b17336c5SHonghui Zhang /* 369b17336c5SHonghui Zhang * MTK generation one iommu HW only support one iommu domain, and all the client 370b17336c5SHonghui Zhang * sharing the same iova address space. 371b17336c5SHonghui Zhang */ 372b17336c5SHonghui Zhang static int mtk_iommu_create_mapping(struct device *dev, 373b17336c5SHonghui Zhang struct of_phandle_args *args) 374b17336c5SHonghui Zhang { 375a9bf2eecSJoerg Roedel struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 37684672f19SRobin Murphy struct mtk_iommu_data *data; 377b17336c5SHonghui Zhang struct platform_device *m4updev; 378b17336c5SHonghui Zhang struct dma_iommu_mapping *mtk_mapping; 379b17336c5SHonghui Zhang struct device *m4udev; 380b17336c5SHonghui Zhang int ret; 381b17336c5SHonghui Zhang 382b17336c5SHonghui Zhang if (args->args_count != 1) { 383b17336c5SHonghui Zhang dev_err(dev, "invalid #iommu-cells(%d) property for IOMMU\n", 384b17336c5SHonghui Zhang args->args_count); 385b17336c5SHonghui Zhang return -EINVAL; 386b17336c5SHonghui Zhang } 387b17336c5SHonghui Zhang 388a9bf2eecSJoerg Roedel if (!fwspec) { 38984672f19SRobin Murphy ret = iommu_fwspec_init(dev, &args->np->fwnode, &mtk_iommu_ops); 39084672f19SRobin Murphy if (ret) 39184672f19SRobin Murphy return ret; 392a9bf2eecSJoerg Roedel fwspec = dev_iommu_fwspec_get(dev); 393a9bf2eecSJoerg Roedel } else if (dev_iommu_fwspec_get(dev)->ops != &mtk_iommu_ops) { 39484672f19SRobin Murphy return -EINVAL; 39584672f19SRobin Murphy } 39684672f19SRobin Murphy 397a9bf2eecSJoerg Roedel if (!fwspec->iommu_priv) { 398b17336c5SHonghui Zhang /* Get the m4u device */ 399b17336c5SHonghui Zhang m4updev = of_find_device_by_node(args->np); 400b17336c5SHonghui Zhang if (WARN_ON(!m4updev)) 401b17336c5SHonghui Zhang return -EINVAL; 402b17336c5SHonghui Zhang 403a9bf2eecSJoerg Roedel fwspec->iommu_priv = platform_get_drvdata(m4updev); 404b17336c5SHonghui Zhang } 405b17336c5SHonghui Zhang 40684672f19SRobin Murphy ret = iommu_fwspec_add_ids(dev, args->args, 1); 40784672f19SRobin Murphy if (ret) 40884672f19SRobin Murphy return ret; 409b17336c5SHonghui Zhang 410a9bf2eecSJoerg Roedel data = fwspec->iommu_priv; 41184672f19SRobin Murphy m4udev = data->dev; 412b17336c5SHonghui Zhang mtk_mapping = m4udev->archdata.iommu; 413b17336c5SHonghui Zhang if (!mtk_mapping) { 414b17336c5SHonghui Zhang /* MTK iommu support 4GB iova address space. */ 415b17336c5SHonghui Zhang mtk_mapping = arm_iommu_create_mapping(&platform_bus_type, 416b17336c5SHonghui Zhang 0, 1ULL << 32); 41784672f19SRobin Murphy if (IS_ERR(mtk_mapping)) 41884672f19SRobin Murphy return PTR_ERR(mtk_mapping); 41984672f19SRobin Murphy 420b17336c5SHonghui Zhang m4udev->archdata.iommu = mtk_mapping; 421b17336c5SHonghui Zhang } 422b17336c5SHonghui Zhang 423b17336c5SHonghui Zhang return 0; 424b17336c5SHonghui Zhang } 425b17336c5SHonghui Zhang 426b17336c5SHonghui Zhang static int mtk_iommu_add_device(struct device *dev) 427b17336c5SHonghui Zhang { 428a9bf2eecSJoerg Roedel struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 429f3e827d7SYong Wu struct dma_iommu_mapping *mtk_mapping; 430b17336c5SHonghui Zhang struct of_phandle_args iommu_spec; 431b17336c5SHonghui Zhang struct of_phandle_iterator it; 4326f66ea09SJoerg Roedel struct mtk_iommu_data *data; 4336f66ea09SJoerg Roedel struct iommu_group *group; 434b17336c5SHonghui Zhang int err; 435b17336c5SHonghui Zhang 436b17336c5SHonghui Zhang of_for_each_phandle(&it, err, dev->of_node, "iommus", 437b17336c5SHonghui Zhang "#iommu-cells", 0) { 438b17336c5SHonghui Zhang int count = of_phandle_iterator_args(&it, iommu_spec.args, 439b17336c5SHonghui Zhang MAX_PHANDLE_ARGS); 440b17336c5SHonghui Zhang iommu_spec.np = of_node_get(it.node); 441b17336c5SHonghui Zhang iommu_spec.args_count = count; 442b17336c5SHonghui Zhang 443b17336c5SHonghui Zhang mtk_iommu_create_mapping(dev, &iommu_spec); 444da5d2748SJoerg Roedel 445da5d2748SJoerg Roedel /* dev->iommu_fwspec might have changed */ 446da5d2748SJoerg Roedel fwspec = dev_iommu_fwspec_get(dev); 447da5d2748SJoerg Roedel 448b17336c5SHonghui Zhang of_node_put(iommu_spec.np); 449b17336c5SHonghui Zhang } 450b17336c5SHonghui Zhang 451a9bf2eecSJoerg Roedel if (!fwspec || fwspec->ops != &mtk_iommu_ops) 45284672f19SRobin Murphy return -ENODEV; /* Not a iommu client device */ 453b17336c5SHonghui Zhang 454f3e827d7SYong Wu /* 455f3e827d7SYong Wu * This is a short-term bodge because the ARM DMA code doesn't 456f3e827d7SYong Wu * understand multi-device groups, but we have to call into it 457f3e827d7SYong Wu * successfully (and not just rely on a normal IOMMU API attach 458f3e827d7SYong Wu * here) in order to set the correct DMA API ops on @dev. 459f3e827d7SYong Wu */ 460f3e827d7SYong Wu group = iommu_group_alloc(); 461b17336c5SHonghui Zhang if (IS_ERR(group)) 462b17336c5SHonghui Zhang return PTR_ERR(group); 463b17336c5SHonghui Zhang 464f3e827d7SYong Wu err = iommu_group_add_device(group, dev); 465b17336c5SHonghui Zhang iommu_group_put(group); 466f3e827d7SYong Wu if (err) 467f3e827d7SYong Wu return err; 468f3e827d7SYong Wu 469a9bf2eecSJoerg Roedel data = fwspec->iommu_priv; 470f3e827d7SYong Wu mtk_mapping = data->dev->archdata.iommu; 471f3e827d7SYong Wu err = arm_iommu_attach_device(dev, mtk_mapping); 472f3e827d7SYong Wu if (err) { 473f3e827d7SYong Wu iommu_group_remove_device(dev); 474f3e827d7SYong Wu return err; 475f3e827d7SYong Wu } 476f3e827d7SYong Wu 477a947a45fSYang Wei return iommu_device_link(&data->iommu, dev); 478b17336c5SHonghui Zhang } 479b17336c5SHonghui Zhang 480b17336c5SHonghui Zhang static void mtk_iommu_remove_device(struct device *dev) 481b17336c5SHonghui Zhang { 482a9bf2eecSJoerg Roedel struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 4836f66ea09SJoerg Roedel struct mtk_iommu_data *data; 4846f66ea09SJoerg Roedel 485a9bf2eecSJoerg Roedel if (!fwspec || fwspec->ops != &mtk_iommu_ops) 486b17336c5SHonghui Zhang return; 487b17336c5SHonghui Zhang 488a9bf2eecSJoerg Roedel data = fwspec->iommu_priv; 4896f66ea09SJoerg Roedel iommu_device_unlink(&data->iommu, dev); 4906f66ea09SJoerg Roedel 491b17336c5SHonghui Zhang iommu_group_remove_device(dev); 49284672f19SRobin Murphy iommu_fwspec_free(dev); 493b17336c5SHonghui Zhang } 494b17336c5SHonghui Zhang 495b17336c5SHonghui Zhang static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) 496b17336c5SHonghui Zhang { 497b17336c5SHonghui Zhang u32 regval; 498b17336c5SHonghui Zhang int ret; 499b17336c5SHonghui Zhang 500b17336c5SHonghui Zhang ret = clk_prepare_enable(data->bclk); 501b17336c5SHonghui Zhang if (ret) { 502b17336c5SHonghui Zhang dev_err(data->dev, "Failed to enable iommu bclk(%d)\n", ret); 503b17336c5SHonghui Zhang return ret; 504b17336c5SHonghui Zhang } 505b17336c5SHonghui Zhang 506b17336c5SHonghui Zhang regval = F_MMU_CTRL_COHERENT_EN | F_MMU_TF_PROTECT_SEL(2); 507b17336c5SHonghui Zhang writel_relaxed(regval, data->base + REG_MMU_CTRL_REG); 508b17336c5SHonghui Zhang 509b17336c5SHonghui Zhang regval = F_INT_TRANSLATION_FAULT | 510b17336c5SHonghui Zhang F_INT_MAIN_MULTI_HIT_FAULT | 511b17336c5SHonghui Zhang F_INT_INVALID_PA_FAULT | 512b17336c5SHonghui Zhang F_INT_ENTRY_REPLACEMENT_FAULT | 513b17336c5SHonghui Zhang F_INT_TABLE_WALK_FAULT | 514b17336c5SHonghui Zhang F_INT_TLB_MISS_FAULT | 515b17336c5SHonghui Zhang F_INT_PFH_DMA_FIFO_OVERFLOW | 516b17336c5SHonghui Zhang F_INT_MISS_DMA_FIFO_OVERFLOW; 517b17336c5SHonghui Zhang writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL); 518b17336c5SHonghui Zhang 519b17336c5SHonghui Zhang /* protect memory,hw will write here while translation fault */ 520b17336c5SHonghui Zhang writel_relaxed(data->protect_base, 521b17336c5SHonghui Zhang data->base + REG_MMU_IVRP_PADDR); 522b17336c5SHonghui Zhang 523b17336c5SHonghui Zhang writel_relaxed(F_MMU_DCM_ON, data->base + REG_MMU_DCM); 524b17336c5SHonghui Zhang 525b17336c5SHonghui Zhang if (devm_request_irq(data->dev, data->irq, mtk_iommu_isr, 0, 526b17336c5SHonghui Zhang dev_name(data->dev), (void *)data)) { 527b17336c5SHonghui Zhang writel_relaxed(0, data->base + REG_MMU_PT_BASE_ADDR); 528b17336c5SHonghui Zhang clk_disable_unprepare(data->bclk); 529b17336c5SHonghui Zhang dev_err(data->dev, "Failed @ IRQ-%d Request\n", data->irq); 530b17336c5SHonghui Zhang return -ENODEV; 531b17336c5SHonghui Zhang } 532b17336c5SHonghui Zhang 533b17336c5SHonghui Zhang return 0; 534b17336c5SHonghui Zhang } 535b17336c5SHonghui Zhang 536b65f5016SArvind Yadav static const struct iommu_ops mtk_iommu_ops = { 537b17336c5SHonghui Zhang .domain_alloc = mtk_iommu_domain_alloc, 538b17336c5SHonghui Zhang .domain_free = mtk_iommu_domain_free, 539b17336c5SHonghui Zhang .attach_dev = mtk_iommu_attach_device, 540b17336c5SHonghui Zhang .detach_dev = mtk_iommu_detach_device, 541b17336c5SHonghui Zhang .map = mtk_iommu_map, 542b17336c5SHonghui Zhang .unmap = mtk_iommu_unmap, 543b17336c5SHonghui Zhang .iova_to_phys = mtk_iommu_iova_to_phys, 544b17336c5SHonghui Zhang .add_device = mtk_iommu_add_device, 545b17336c5SHonghui Zhang .remove_device = mtk_iommu_remove_device, 546b17336c5SHonghui Zhang .pgsize_bitmap = ~0UL << MT2701_IOMMU_PAGE_SHIFT, 547b17336c5SHonghui Zhang }; 548b17336c5SHonghui Zhang 549b17336c5SHonghui Zhang static const struct of_device_id mtk_iommu_of_ids[] = { 550b17336c5SHonghui Zhang { .compatible = "mediatek,mt2701-m4u", }, 551b17336c5SHonghui Zhang {} 552b17336c5SHonghui Zhang }; 553b17336c5SHonghui Zhang 554b17336c5SHonghui Zhang static const struct component_master_ops mtk_iommu_com_ops = { 555b17336c5SHonghui Zhang .bind = mtk_iommu_bind, 556b17336c5SHonghui Zhang .unbind = mtk_iommu_unbind, 557b17336c5SHonghui Zhang }; 558b17336c5SHonghui Zhang 559b17336c5SHonghui Zhang static int mtk_iommu_probe(struct platform_device *pdev) 560b17336c5SHonghui Zhang { 561b17336c5SHonghui Zhang struct mtk_iommu_data *data; 562b17336c5SHonghui Zhang struct device *dev = &pdev->dev; 563b17336c5SHonghui Zhang struct resource *res; 564b17336c5SHonghui Zhang struct component_match *match = NULL; 565b17336c5SHonghui Zhang struct of_phandle_args larb_spec; 566b17336c5SHonghui Zhang struct of_phandle_iterator it; 567b17336c5SHonghui Zhang void *protect; 568b17336c5SHonghui Zhang int larb_nr, ret, err; 569b17336c5SHonghui Zhang 570b17336c5SHonghui Zhang data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 571b17336c5SHonghui Zhang if (!data) 572b17336c5SHonghui Zhang return -ENOMEM; 573b17336c5SHonghui Zhang 574b17336c5SHonghui Zhang data->dev = dev; 575b17336c5SHonghui Zhang 576b17336c5SHonghui Zhang /* Protect memory. HW will access here while translation fault.*/ 577b17336c5SHonghui Zhang protect = devm_kzalloc(dev, MTK_PROTECT_PA_ALIGN * 2, 578b17336c5SHonghui Zhang GFP_KERNEL | GFP_DMA); 579b17336c5SHonghui Zhang if (!protect) 580b17336c5SHonghui Zhang return -ENOMEM; 581b17336c5SHonghui Zhang data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN); 582b17336c5SHonghui Zhang 583b17336c5SHonghui Zhang res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 584b17336c5SHonghui Zhang data->base = devm_ioremap_resource(dev, res); 585b17336c5SHonghui Zhang if (IS_ERR(data->base)) 586b17336c5SHonghui Zhang return PTR_ERR(data->base); 587b17336c5SHonghui Zhang 588b17336c5SHonghui Zhang data->irq = platform_get_irq(pdev, 0); 589b17336c5SHonghui Zhang if (data->irq < 0) 590b17336c5SHonghui Zhang return data->irq; 591b17336c5SHonghui Zhang 592b17336c5SHonghui Zhang data->bclk = devm_clk_get(dev, "bclk"); 593b17336c5SHonghui Zhang if (IS_ERR(data->bclk)) 594b17336c5SHonghui Zhang return PTR_ERR(data->bclk); 595b17336c5SHonghui Zhang 596b17336c5SHonghui Zhang larb_nr = 0; 597b17336c5SHonghui Zhang of_for_each_phandle(&it, err, dev->of_node, 598b17336c5SHonghui Zhang "mediatek,larbs", NULL, 0) { 599b17336c5SHonghui Zhang struct platform_device *plarbdev; 600b17336c5SHonghui Zhang int count = of_phandle_iterator_args(&it, larb_spec.args, 601b17336c5SHonghui Zhang MAX_PHANDLE_ARGS); 602b17336c5SHonghui Zhang 603b17336c5SHonghui Zhang if (count) 604b17336c5SHonghui Zhang continue; 605b17336c5SHonghui Zhang 606b17336c5SHonghui Zhang larb_spec.np = of_node_get(it.node); 607b17336c5SHonghui Zhang if (!of_device_is_available(larb_spec.np)) 608b17336c5SHonghui Zhang continue; 609b17336c5SHonghui Zhang 610b17336c5SHonghui Zhang plarbdev = of_find_device_by_node(larb_spec.np); 611b17336c5SHonghui Zhang if (!plarbdev) { 612b17336c5SHonghui Zhang plarbdev = of_platform_device_create( 613b17336c5SHonghui Zhang larb_spec.np, NULL, 614b17336c5SHonghui Zhang platform_bus_type.dev_root); 61500c7c81fSRussell King if (!plarbdev) { 61600c7c81fSRussell King of_node_put(larb_spec.np); 617b17336c5SHonghui Zhang return -EPROBE_DEFER; 618b17336c5SHonghui Zhang } 61900c7c81fSRussell King } 620b17336c5SHonghui Zhang 621b17336c5SHonghui Zhang data->smi_imu.larb_imu[larb_nr].dev = &plarbdev->dev; 62200c7c81fSRussell King component_match_add_release(dev, &match, release_of, 62300c7c81fSRussell King compare_of, larb_spec.np); 624b17336c5SHonghui Zhang larb_nr++; 625b17336c5SHonghui Zhang } 626b17336c5SHonghui Zhang 627b17336c5SHonghui Zhang data->smi_imu.larb_nr = larb_nr; 628b17336c5SHonghui Zhang 629b17336c5SHonghui Zhang platform_set_drvdata(pdev, data); 630b17336c5SHonghui Zhang 631b17336c5SHonghui Zhang ret = mtk_iommu_hw_init(data); 632b17336c5SHonghui Zhang if (ret) 633b17336c5SHonghui Zhang return ret; 634b17336c5SHonghui Zhang 6356f66ea09SJoerg Roedel ret = iommu_device_sysfs_add(&data->iommu, &pdev->dev, NULL, 6366f66ea09SJoerg Roedel dev_name(&pdev->dev)); 6376f66ea09SJoerg Roedel if (ret) 6386f66ea09SJoerg Roedel return ret; 6396f66ea09SJoerg Roedel 6406f66ea09SJoerg Roedel iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); 6416f66ea09SJoerg Roedel 6426f66ea09SJoerg Roedel ret = iommu_device_register(&data->iommu); 6436f66ea09SJoerg Roedel if (ret) 6446f66ea09SJoerg Roedel return ret; 6456f66ea09SJoerg Roedel 646b17336c5SHonghui Zhang if (!iommu_present(&platform_bus_type)) 647b17336c5SHonghui Zhang bus_set_iommu(&platform_bus_type, &mtk_iommu_ops); 648b17336c5SHonghui Zhang 649b17336c5SHonghui Zhang return component_master_add_with_match(dev, &mtk_iommu_com_ops, match); 650b17336c5SHonghui Zhang } 651b17336c5SHonghui Zhang 652b17336c5SHonghui Zhang static int mtk_iommu_remove(struct platform_device *pdev) 653b17336c5SHonghui Zhang { 654b17336c5SHonghui Zhang struct mtk_iommu_data *data = platform_get_drvdata(pdev); 655b17336c5SHonghui Zhang 6566f66ea09SJoerg Roedel iommu_device_sysfs_remove(&data->iommu); 6576f66ea09SJoerg Roedel iommu_device_unregister(&data->iommu); 6586f66ea09SJoerg Roedel 659b17336c5SHonghui Zhang if (iommu_present(&platform_bus_type)) 660b17336c5SHonghui Zhang bus_set_iommu(&platform_bus_type, NULL); 661b17336c5SHonghui Zhang 662b17336c5SHonghui Zhang clk_disable_unprepare(data->bclk); 663b17336c5SHonghui Zhang devm_free_irq(&pdev->dev, data->irq, data); 664b17336c5SHonghui Zhang component_master_del(&pdev->dev, &mtk_iommu_com_ops); 665b17336c5SHonghui Zhang return 0; 666b17336c5SHonghui Zhang } 667b17336c5SHonghui Zhang 668b17336c5SHonghui Zhang static int __maybe_unused mtk_iommu_suspend(struct device *dev) 669b17336c5SHonghui Zhang { 670b17336c5SHonghui Zhang struct mtk_iommu_data *data = dev_get_drvdata(dev); 671b17336c5SHonghui Zhang struct mtk_iommu_suspend_reg *reg = &data->reg; 672b17336c5SHonghui Zhang void __iomem *base = data->base; 673b17336c5SHonghui Zhang 674b17336c5SHonghui Zhang reg->standard_axi_mode = readl_relaxed(base + 675b17336c5SHonghui Zhang REG_MMU_STANDARD_AXI_MODE); 676b17336c5SHonghui Zhang reg->dcm_dis = readl_relaxed(base + REG_MMU_DCM); 677b17336c5SHonghui Zhang reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG); 678b17336c5SHonghui Zhang reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL); 679b17336c5SHonghui Zhang return 0; 680b17336c5SHonghui Zhang } 681b17336c5SHonghui Zhang 682b17336c5SHonghui Zhang static int __maybe_unused mtk_iommu_resume(struct device *dev) 683b17336c5SHonghui Zhang { 684b17336c5SHonghui Zhang struct mtk_iommu_data *data = dev_get_drvdata(dev); 685b17336c5SHonghui Zhang struct mtk_iommu_suspend_reg *reg = &data->reg; 686b17336c5SHonghui Zhang void __iomem *base = data->base; 687b17336c5SHonghui Zhang 688b17336c5SHonghui Zhang writel_relaxed(data->m4u_dom->pgt_pa, base + REG_MMU_PT_BASE_ADDR); 689b17336c5SHonghui Zhang writel_relaxed(reg->standard_axi_mode, 690b17336c5SHonghui Zhang base + REG_MMU_STANDARD_AXI_MODE); 691b17336c5SHonghui Zhang writel_relaxed(reg->dcm_dis, base + REG_MMU_DCM); 692b17336c5SHonghui Zhang writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); 693b17336c5SHonghui Zhang writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL); 694b17336c5SHonghui Zhang writel_relaxed(data->protect_base, base + REG_MMU_IVRP_PADDR); 695b17336c5SHonghui Zhang return 0; 696b17336c5SHonghui Zhang } 697b17336c5SHonghui Zhang 698131bc8ebSJoerg Roedel static const struct dev_pm_ops mtk_iommu_pm_ops = { 699b17336c5SHonghui Zhang SET_SYSTEM_SLEEP_PM_OPS(mtk_iommu_suspend, mtk_iommu_resume) 700b17336c5SHonghui Zhang }; 701b17336c5SHonghui Zhang 702b17336c5SHonghui Zhang static struct platform_driver mtk_iommu_driver = { 703b17336c5SHonghui Zhang .probe = mtk_iommu_probe, 704b17336c5SHonghui Zhang .remove = mtk_iommu_remove, 705b17336c5SHonghui Zhang .driver = { 706395df08dSMatthias Brugger .name = "mtk-iommu-v1", 707b17336c5SHonghui Zhang .of_match_table = mtk_iommu_of_ids, 708b17336c5SHonghui Zhang .pm = &mtk_iommu_pm_ops, 709b17336c5SHonghui Zhang } 710b17336c5SHonghui Zhang }; 711b17336c5SHonghui Zhang 712b17336c5SHonghui Zhang static int __init m4u_init(void) 713b17336c5SHonghui Zhang { 714b17336c5SHonghui Zhang return platform_driver_register(&mtk_iommu_driver); 715b17336c5SHonghui Zhang } 716b17336c5SHonghui Zhang subsys_initcall(m4u_init); 717