Olav Haugan | f378273 | 2013-01-11 11:23:30 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/list.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/iommu.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/scatterlist.h> |
| 26 | #include <linux/of.h> |
| 27 | #include <linux/of_device.h> |
Michael Bohan | 1834e7f | 2013-01-18 17:16:38 -0800 | [diff] [blame] | 28 | #include <linux/kmemleak.h> |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 29 | |
| 30 | #include <asm/sizes.h> |
| 31 | |
Olav Haugan | 64ffdf3 | 2013-01-24 17:20:24 -0800 | [diff] [blame] | 32 | #include <mach/iommu_perfmon.h> |
Olav Haugan | e6d01ef | 2013-01-25 16:55:44 -0800 | [diff] [blame] | 33 | #include <mach/iommu_hw-v1.h> |
Olav Haugan | 090614f | 2013-03-22 12:14:18 -0700 | [diff] [blame] | 34 | #include <mach/msm_iommu_priv.h> |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 35 | #include <mach/iommu.h> |
| 36 | #include <mach/scm.h> |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 37 | #include <mach/memory.h> |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 38 | |
| 39 | /* bitmap of the page sizes currently supported */ |
| 40 | #define MSM_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M) |
| 41 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 42 | /* commands for SCM_SVC_MP */ |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 43 | #define IOMMU_SECURE_CFG 2 |
| 44 | #define IOMMU_SECURE_PTBL_SIZE 3 |
| 45 | #define IOMMU_SECURE_PTBL_INIT 4 |
| 46 | #define IOMMU_SECURE_MAP 6 |
| 47 | #define IOMMU_SECURE_UNMAP 7 |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 48 | #define IOMMU_SECURE_MAP2 0x0B |
| 49 | #define IOMMU_SECURE_UNMAP2 0x0C |
| 50 | #define IOMMU_TLBINVAL_FLAG 0x00000001 |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 51 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 52 | /* commands for SCM_SVC_UTIL */ |
| 53 | #define IOMMU_DUMP_SMMU_FAULT_REGS 0X0C |
| 54 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 55 | static struct iommu_access_ops *iommu_access_ops; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 56 | |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 57 | struct msm_scm_paddr_list { |
| 58 | unsigned int list; |
| 59 | unsigned int list_size; |
| 60 | unsigned int size; |
| 61 | }; |
| 62 | |
| 63 | struct msm_scm_mapping_info { |
| 64 | unsigned int id; |
| 65 | unsigned int ctx_id; |
| 66 | unsigned int va; |
| 67 | unsigned int size; |
| 68 | }; |
| 69 | |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 70 | struct msm_scm_map2_req { |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 71 | struct msm_scm_paddr_list plist; |
| 72 | struct msm_scm_mapping_info info; |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 73 | unsigned int flags; |
| 74 | }; |
| 75 | |
| 76 | struct msm_scm_unmap2_req { |
| 77 | struct msm_scm_mapping_info info; |
| 78 | unsigned int flags; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 81 | #define NUM_DUMP_REGS 14 |
| 82 | /* |
| 83 | * some space to allow the number of registers returned by the secure |
| 84 | * environment to grow |
| 85 | */ |
| 86 | #define WIGGLE_ROOM (NUM_DUMP_REGS * 2) |
| 87 | /* Each entry is a (reg_addr, reg_val) pair, hence the * 2 */ |
| 88 | #define SEC_DUMP_SIZE ((NUM_DUMP_REGS * 2) + WIGGLE_ROOM) |
| 89 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 90 | struct msm_scm_fault_regs_dump { |
| 91 | uint32_t dump_size; |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 92 | uint32_t dump_data[SEC_DUMP_SIZE]; |
| 93 | } __packed; |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 94 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 95 | void msm_iommu_sec_set_access_ops(struct iommu_access_ops *access_ops) |
| 96 | { |
| 97 | iommu_access_ops = access_ops; |
| 98 | } |
| 99 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 100 | static int msm_iommu_dump_fault_regs(int smmu_id, int cb_num, |
| 101 | struct msm_scm_fault_regs_dump *regs) |
| 102 | { |
| 103 | int ret; |
| 104 | |
| 105 | struct msm_scm_fault_regs_dump_req { |
| 106 | uint32_t id; |
| 107 | uint32_t cb_num; |
| 108 | phys_addr_t buff; |
| 109 | uint32_t len; |
| 110 | } req_info; |
| 111 | int resp; |
| 112 | |
| 113 | req_info.id = smmu_id; |
| 114 | req_info.cb_num = cb_num; |
| 115 | req_info.buff = virt_to_phys(regs); |
| 116 | req_info.len = sizeof(*regs); |
| 117 | |
| 118 | ret = scm_call(SCM_SVC_UTIL, IOMMU_DUMP_SMMU_FAULT_REGS, |
| 119 | &req_info, sizeof(req_info), &resp, 1); |
| 120 | |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 121 | invalidate_caches((unsigned long) regs, sizeof(*regs), |
| 122 | (unsigned long)virt_to_phys(regs)); |
| 123 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 124 | return ret; |
| 125 | } |
| 126 | |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 127 | #define EXTRACT_DUMP_REG_KEY(addr, ctx) (addr & ((1 << CTX_SHIFT) - 1)) |
| 128 | |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 129 | static int msm_iommu_reg_dump_to_regs( |
| 130 | struct msm_iommu_context_reg ctx_regs[], |
| 131 | struct msm_scm_fault_regs_dump *dump, int cb_num) |
| 132 | { |
| 133 | int i, j, ret = 0; |
| 134 | const uint32_t nvals = (dump->dump_size / sizeof(uint32_t)); |
| 135 | uint32_t *it = (uint32_t *) dump->dump_data; |
| 136 | const uint32_t * const end = ((uint32_t *) dump) + nvals; |
| 137 | |
| 138 | for (i = 1; it < end; it += 2, i += 2) { |
| 139 | uint32_t addr = *it; |
| 140 | uint32_t val = *(it + 1); |
| 141 | struct msm_iommu_context_reg *reg = NULL; |
| 142 | |
| 143 | for (j = 0; j < MAX_DUMP_REGS; ++j) { |
| 144 | if (dump_regs_tbl[j].key == |
| 145 | EXTRACT_DUMP_REG_KEY(addr, cb_num)) { |
| 146 | reg = &ctx_regs[j]; |
| 147 | break; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (reg == NULL) { |
| 152 | pr_debug("Unknown register in secure CB dump: %x (%x)\n", |
| 153 | addr, EXTRACT_DUMP_REG_KEY(addr, cb_num)); |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | if (reg->valid) { |
| 158 | WARN(1, "Invalid (repeated?) register in CB dump: %x\n", |
| 159 | addr); |
| 160 | continue; |
| 161 | } |
| 162 | |
| 163 | reg->val = val; |
| 164 | reg->valid = true; |
| 165 | } |
| 166 | |
| 167 | if (i != nvals) { |
| 168 | pr_err("Invalid dump! %d != %d\n", i, nvals); |
| 169 | ret = 1; |
| 170 | goto out; |
| 171 | } |
| 172 | |
| 173 | for (i = 0; i < MAX_DUMP_REGS; ++i) { |
| 174 | if (!ctx_regs[i].valid) { |
Olav Haugan | cdb1311 | 2013-06-21 17:45:34 -0700 | [diff] [blame] | 175 | if (dump_regs_tbl[i].must_be_present) { |
| 176 | pr_err("Register missing from dump: %s, %lx\n", |
| 177 | dump_regs_tbl[i].name, |
| 178 | dump_regs_tbl[i].key); |
| 179 | ret = 1; |
| 180 | } |
| 181 | ctx_regs[i].val = 0; |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | out: |
| 186 | return ret; |
| 187 | } |
| 188 | |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 189 | irqreturn_t msm_iommu_secure_fault_handler_v2(int irq, void *dev_id) |
| 190 | { |
| 191 | struct platform_device *pdev = dev_id; |
| 192 | struct msm_iommu_drvdata *drvdata; |
| 193 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 194 | struct msm_scm_fault_regs_dump *regs; |
| 195 | int tmp, ret = IRQ_HANDLED; |
| 196 | |
| 197 | iommu_access_ops->iommu_lock_acquire(); |
| 198 | |
| 199 | BUG_ON(!pdev); |
| 200 | |
| 201 | drvdata = dev_get_drvdata(pdev->dev.parent); |
| 202 | BUG_ON(!drvdata); |
| 203 | |
| 204 | ctx_drvdata = dev_get_drvdata(&pdev->dev); |
| 205 | BUG_ON(!ctx_drvdata); |
| 206 | |
| 207 | regs = kmalloc(sizeof(*regs), GFP_KERNEL); |
| 208 | if (!regs) { |
| 209 | pr_err("%s: Couldn't allocate memory\n", __func__); |
| 210 | goto lock_release; |
| 211 | } |
| 212 | |
| 213 | if (!drvdata->ctx_attach_count) { |
| 214 | pr_err("Unexpected IOMMU page fault from secure context bank!\n"); |
| 215 | pr_err("name = %s\n", drvdata->name); |
| 216 | pr_err("Power is OFF. Unable to read page fault information\n"); |
| 217 | /* |
| 218 | * We cannot determine which context bank caused the issue so |
| 219 | * we just return handled here to ensure IRQ handler code is |
| 220 | * happy |
| 221 | */ |
| 222 | goto free_regs; |
| 223 | } |
| 224 | |
| 225 | iommu_access_ops->iommu_clk_on(drvdata); |
| 226 | tmp = msm_iommu_dump_fault_regs(drvdata->sec_id, |
| 227 | ctx_drvdata->num, regs); |
| 228 | iommu_access_ops->iommu_clk_off(drvdata); |
| 229 | |
| 230 | if (tmp) { |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 231 | pr_err("%s: Couldn't dump fault registers (%d) %s, ctx: %d\n", |
| 232 | __func__, tmp, drvdata->name, ctx_drvdata->num); |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 233 | goto free_regs; |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 234 | } else { |
Mitchel Humpherys | 2b6e5c5 | 2013-06-05 16:01:54 -0700 | [diff] [blame] | 235 | struct msm_iommu_context_reg ctx_regs[MAX_DUMP_REGS]; |
| 236 | memset(ctx_regs, 0, sizeof(ctx_regs)); |
| 237 | tmp = msm_iommu_reg_dump_to_regs(ctx_regs, regs, |
| 238 | ctx_drvdata->num); |
| 239 | if (!tmp && ctx_regs[DUMP_REG_FSR].val) { |
| 240 | if (!ctx_drvdata->attached_domain) { |
| 241 | pr_err("Bad domain in interrupt handler\n"); |
| 242 | tmp = -ENOSYS; |
| 243 | } else { |
| 244 | tmp = report_iommu_fault( |
| 245 | ctx_drvdata->attached_domain, |
| 246 | &ctx_drvdata->pdev->dev, |
| 247 | COMBINE_DUMP_REG( |
| 248 | ctx_regs[DUMP_REG_FAR1].val, |
| 249 | ctx_regs[DUMP_REG_FAR0].val), |
| 250 | 0); |
| 251 | } |
| 252 | |
| 253 | /* if the fault wasn't handled by someone else: */ |
| 254 | if (tmp == -ENOSYS) { |
| 255 | pr_err("Unexpected IOMMU page fault from secure context bank!\n"); |
| 256 | pr_err("name = %s\n", drvdata->name); |
| 257 | pr_err("context = %s (%d)\n", ctx_drvdata->name, |
| 258 | ctx_drvdata->num); |
| 259 | pr_err("Interesting registers:\n"); |
| 260 | print_ctx_regs(ctx_regs); |
| 261 | } |
| 262 | } else { |
| 263 | ret = IRQ_NONE; |
| 264 | } |
Mitchel Humpherys | f3b5091 | 2013-05-21 17:46:04 -0700 | [diff] [blame] | 265 | } |
| 266 | free_regs: |
| 267 | kfree(regs); |
| 268 | lock_release: |
| 269 | iommu_access_ops->iommu_lock_release(); |
| 270 | return ret; |
| 271 | } |
| 272 | |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 273 | static int msm_iommu_sec_ptbl_init(void) |
| 274 | { |
| 275 | struct device_node *np; |
| 276 | struct msm_scm_ptbl_init { |
| 277 | unsigned int paddr; |
| 278 | unsigned int size; |
| 279 | unsigned int spare; |
| 280 | } pinit; |
| 281 | unsigned int *buf; |
Mitchel Humpherys | 637cc53 | 2012-12-12 16:50:58 -0800 | [diff] [blame] | 282 | int psize[2] = {0, 0}; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 283 | unsigned int spare; |
Mitchel Humpherys | 637cc53 | 2012-12-12 16:50:58 -0800 | [diff] [blame] | 284 | int ret, ptbl_ret = 0; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 285 | |
Olav Haugan | 0e22c48 | 2013-01-28 17:39:36 -0800 | [diff] [blame] | 286 | for_each_compatible_node(np, NULL, "qcom,msm-smmu-v1") |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 287 | if (of_find_property(np, "qcom,iommu-secure-id", NULL)) |
| 288 | break; |
| 289 | |
| 290 | if (!np) |
| 291 | return 0; |
| 292 | |
| 293 | of_node_put(np); |
Syed Rameez Mustafa | 6ab6af3 | 2013-03-18 12:53:11 -0700 | [diff] [blame] | 294 | ret = scm_call(SCM_SVC_MP, IOMMU_SECURE_PTBL_SIZE, &spare, |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 295 | sizeof(spare), psize, sizeof(psize)); |
| 296 | if (ret) { |
| 297 | pr_err("scm call IOMMU_SECURE_PTBL_SIZE failed\n"); |
| 298 | goto fail; |
| 299 | } |
| 300 | |
| 301 | if (psize[1]) { |
| 302 | pr_err("scm call IOMMU_SECURE_PTBL_SIZE failed\n"); |
| 303 | goto fail; |
| 304 | } |
| 305 | |
| 306 | buf = kmalloc(psize[0], GFP_KERNEL); |
| 307 | if (!buf) { |
| 308 | pr_err("%s: Failed to allocate %d bytes for PTBL\n", |
| 309 | __func__, psize[0]); |
| 310 | ret = -ENOMEM; |
| 311 | goto fail; |
| 312 | } |
| 313 | |
| 314 | pinit.paddr = virt_to_phys(buf); |
| 315 | pinit.size = psize[0]; |
| 316 | |
Syed Rameez Mustafa | 6ab6af3 | 2013-03-18 12:53:11 -0700 | [diff] [blame] | 317 | ret = scm_call(SCM_SVC_MP, IOMMU_SECURE_PTBL_INIT, &pinit, |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 318 | sizeof(pinit), &ptbl_ret, sizeof(ptbl_ret)); |
| 319 | if (ret) { |
| 320 | pr_err("scm call IOMMU_SECURE_PTBL_INIT failed\n"); |
| 321 | goto fail_mem; |
| 322 | } |
| 323 | if (ptbl_ret) { |
| 324 | pr_err("scm call IOMMU_SECURE_PTBL_INIT extended ret fail\n"); |
| 325 | goto fail_mem; |
| 326 | } |
| 327 | |
Michael Bohan | 1834e7f | 2013-01-18 17:16:38 -0800 | [diff] [blame] | 328 | kmemleak_not_leak(buf); |
| 329 | |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | |
| 332 | fail_mem: |
| 333 | kfree(buf); |
| 334 | fail: |
| 335 | return ret; |
| 336 | } |
| 337 | |
Laura Abbott | f4daa69 | 2012-10-10 19:31:53 -0700 | [diff] [blame] | 338 | int msm_iommu_sec_program_iommu(int sec_id) |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 339 | { |
| 340 | struct msm_scm_sec_cfg { |
| 341 | unsigned int id; |
| 342 | unsigned int spare; |
| 343 | } cfg; |
Mitchel Humpherys | 637cc53 | 2012-12-12 16:50:58 -0800 | [diff] [blame] | 344 | int ret, scm_ret = 0; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 345 | |
| 346 | cfg.id = sec_id; |
| 347 | |
Syed Rameez Mustafa | 6ab6af3 | 2013-03-18 12:53:11 -0700 | [diff] [blame] | 348 | ret = scm_call(SCM_SVC_MP, IOMMU_SECURE_CFG, &cfg, sizeof(cfg), |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 349 | &scm_ret, sizeof(scm_ret)); |
| 350 | if (ret || scm_ret) { |
| 351 | pr_err("scm call IOMMU_SECURE_CFG failed\n"); |
| 352 | return ret ? ret : -EINVAL; |
| 353 | } |
| 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | static int msm_iommu_sec_ptbl_map(struct msm_iommu_drvdata *iommu_drvdata, |
| 359 | struct msm_iommu_ctx_drvdata *ctx_drvdata, |
| 360 | unsigned long va, phys_addr_t pa, size_t len) |
| 361 | { |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 362 | struct msm_scm_map2_req map; |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 363 | void *flush_va; |
| 364 | phys_addr_t flush_pa; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 365 | int ret = 0; |
| 366 | |
| 367 | map.plist.list = virt_to_phys(&pa); |
| 368 | map.plist.list_size = 1; |
| 369 | map.plist.size = len; |
| 370 | map.info.id = iommu_drvdata->sec_id; |
| 371 | map.info.ctx_id = ctx_drvdata->num; |
| 372 | map.info.va = va; |
| 373 | map.info.size = len; |
Chintan Pandya | 8da8a5a | 2013-07-11 18:17:50 +0530 | [diff] [blame] | 374 | map.flags = 0; |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 375 | flush_va = &pa; |
| 376 | flush_pa = virt_to_phys(&pa); |
| 377 | |
| 378 | /* |
| 379 | * Ensure that the buffer is in RAM by the time it gets to TZ |
| 380 | */ |
| 381 | clean_caches((unsigned long) flush_va, len, flush_pa); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 382 | |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 383 | if (scm_call(SCM_SVC_MP, IOMMU_SECURE_MAP2, &map, sizeof(map), &ret, |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 384 | sizeof(ret))) |
| 385 | return -EINVAL; |
| 386 | if (ret) |
| 387 | return -EINVAL; |
| 388 | |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 389 | /* Invalidate cache since TZ touched this address range */ |
| 390 | invalidate_caches((unsigned long) flush_va, len, flush_pa); |
| 391 | |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static unsigned int get_phys_addr(struct scatterlist *sg) |
| 396 | { |
| 397 | /* |
| 398 | * Try sg_dma_address first so that we can |
| 399 | * map carveout regions that do not have a |
| 400 | * struct page associated with them. |
| 401 | */ |
| 402 | unsigned int pa = sg_dma_address(sg); |
| 403 | if (pa == 0) |
| 404 | pa = sg_phys(sg); |
| 405 | return pa; |
| 406 | } |
| 407 | |
| 408 | static int msm_iommu_sec_ptbl_map_range(struct msm_iommu_drvdata *iommu_drvdata, |
| 409 | struct msm_iommu_ctx_drvdata *ctx_drvdata, |
| 410 | unsigned long va, struct scatterlist *sg, size_t len) |
| 411 | { |
| 412 | struct scatterlist *sgiter; |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 413 | struct msm_scm_map2_req map; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 414 | unsigned int *pa_list = 0; |
| 415 | unsigned int pa, cnt; |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 416 | void *flush_va; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 417 | unsigned int offset = 0, chunk_offset = 0; |
| 418 | int ret, scm_ret; |
| 419 | |
| 420 | map.info.id = iommu_drvdata->sec_id; |
| 421 | map.info.ctx_id = ctx_drvdata->num; |
| 422 | map.info.va = va; |
| 423 | map.info.size = len; |
Chintan Pandya | 8da8a5a | 2013-07-11 18:17:50 +0530 | [diff] [blame] | 424 | map.flags = 0; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 425 | |
| 426 | if (sg->length == len) { |
| 427 | pa = get_phys_addr(sg); |
| 428 | map.plist.list = virt_to_phys(&pa); |
| 429 | map.plist.list_size = 1; |
| 430 | map.plist.size = len; |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 431 | flush_va = &pa; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 432 | } else { |
| 433 | sgiter = sg; |
| 434 | cnt = sg->length / SZ_1M; |
| 435 | while ((sgiter = sg_next(sgiter))) |
| 436 | cnt += sgiter->length / SZ_1M; |
| 437 | |
| 438 | pa_list = kmalloc(cnt * sizeof(*pa_list), GFP_KERNEL); |
| 439 | if (!pa_list) |
| 440 | return -ENOMEM; |
| 441 | |
| 442 | sgiter = sg; |
| 443 | cnt = 0; |
| 444 | pa = get_phys_addr(sgiter); |
| 445 | while (offset < len) { |
| 446 | pa += chunk_offset; |
| 447 | pa_list[cnt] = pa; |
| 448 | chunk_offset += SZ_1M; |
| 449 | offset += SZ_1M; |
| 450 | cnt++; |
| 451 | |
| 452 | if (chunk_offset >= sgiter->length && offset < len) { |
| 453 | chunk_offset = 0; |
| 454 | sgiter = sg_next(sgiter); |
| 455 | pa = get_phys_addr(sgiter); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | map.plist.list = virt_to_phys(pa_list); |
| 460 | map.plist.list_size = cnt; |
| 461 | map.plist.size = SZ_1M; |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 462 | flush_va = pa_list; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 465 | /* |
| 466 | * Ensure that the buffer is in RAM by the time it gets to TZ |
| 467 | */ |
| 468 | clean_caches((unsigned long) flush_va, |
Laura Abbott | 8747306 | 2013-06-20 16:50:20 -0700 | [diff] [blame] | 469 | sizeof(unsigned long) * map.plist.list_size, |
| 470 | virt_to_phys(flush_va)); |
Mitchel Humpherys | 4ec93cb | 2013-06-12 12:25:43 -0700 | [diff] [blame] | 471 | |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 472 | ret = scm_call(SCM_SVC_MP, IOMMU_SECURE_MAP2, &map, sizeof(map), |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 473 | &scm_ret, sizeof(scm_ret)); |
| 474 | kfree(pa_list); |
| 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | static int msm_iommu_sec_ptbl_unmap(struct msm_iommu_drvdata *iommu_drvdata, |
| 479 | struct msm_iommu_ctx_drvdata *ctx_drvdata, |
| 480 | unsigned long va, size_t len) |
| 481 | { |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 482 | struct msm_scm_unmap2_req unmap; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 483 | int ret, scm_ret; |
| 484 | |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 485 | unmap.info.id = iommu_drvdata->sec_id; |
| 486 | unmap.info.ctx_id = ctx_drvdata->num; |
| 487 | unmap.info.va = va; |
| 488 | unmap.info.size = len; |
| 489 | unmap.flags = IOMMU_TLBINVAL_FLAG; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 490 | |
Adrian Alexei | bfe7c46 | 2013-04-01 14:36:24 -0700 | [diff] [blame] | 491 | ret = scm_call(SCM_SVC_MP, IOMMU_SECURE_UNMAP2, &unmap, sizeof(unmap), |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 492 | &scm_ret, sizeof(scm_ret)); |
| 493 | return ret; |
| 494 | } |
| 495 | |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 496 | static int msm_iommu_domain_init(struct iommu_domain *domain, int flags) |
| 497 | { |
Olav Haugan | 090614f | 2013-03-22 12:14:18 -0700 | [diff] [blame] | 498 | struct msm_iommu_priv *priv; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 499 | |
| 500 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 501 | if (!priv) |
| 502 | return -ENOMEM; |
| 503 | |
| 504 | INIT_LIST_HEAD(&priv->list_attached); |
| 505 | domain->priv = priv; |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | static void msm_iommu_domain_destroy(struct iommu_domain *domain) |
| 510 | { |
Olav Haugan | 090614f | 2013-03-22 12:14:18 -0700 | [diff] [blame] | 511 | struct msm_iommu_priv *priv; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 512 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 513 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 514 | priv = domain->priv; |
| 515 | domain->priv = NULL; |
| 516 | |
| 517 | kfree(priv); |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 518 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) |
| 522 | { |
Olav Haugan | 090614f | 2013-03-22 12:14:18 -0700 | [diff] [blame] | 523 | struct msm_iommu_priv *priv; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 524 | struct msm_iommu_drvdata *iommu_drvdata; |
| 525 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 526 | struct msm_iommu_ctx_drvdata *tmp_drvdata; |
| 527 | int ret = 0; |
| 528 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 529 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 530 | |
| 531 | priv = domain->priv; |
| 532 | if (!priv || !dev) { |
| 533 | ret = -EINVAL; |
| 534 | goto fail; |
| 535 | } |
| 536 | |
| 537 | iommu_drvdata = dev_get_drvdata(dev->parent); |
| 538 | ctx_drvdata = dev_get_drvdata(dev); |
| 539 | if (!iommu_drvdata || !ctx_drvdata) { |
| 540 | ret = -EINVAL; |
| 541 | goto fail; |
| 542 | } |
| 543 | |
| 544 | if (!list_empty(&ctx_drvdata->attached_elm)) { |
| 545 | ret = -EBUSY; |
| 546 | goto fail; |
| 547 | } |
| 548 | |
| 549 | list_for_each_entry(tmp_drvdata, &priv->list_attached, attached_elm) |
| 550 | if (tmp_drvdata == ctx_drvdata) { |
| 551 | ret = -EBUSY; |
| 552 | goto fail; |
| 553 | } |
| 554 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 555 | ret = iommu_access_ops->iommu_power_on(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 556 | if (ret) |
| 557 | goto fail; |
| 558 | |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 559 | /* We can only do this once */ |
| 560 | if (!iommu_drvdata->ctx_attach_count) { |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 561 | ret = iommu_access_ops->iommu_clk_on(iommu_drvdata); |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 562 | if (ret) { |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 563 | iommu_access_ops->iommu_power_off(iommu_drvdata); |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 564 | goto fail; |
| 565 | } |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 566 | |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 567 | ret = msm_iommu_sec_program_iommu(iommu_drvdata->sec_id); |
Olav Haugan | ce2eab9 | 2013-02-07 12:59:18 -0800 | [diff] [blame] | 568 | |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 569 | /* bfb settings are always programmed by HLOS */ |
| 570 | program_iommu_bfb_settings(iommu_drvdata->base, |
| 571 | iommu_drvdata->bfb_settings); |
Olav Haugan | f378273 | 2013-01-11 11:23:30 -0800 | [diff] [blame] | 572 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 573 | iommu_access_ops->iommu_clk_off(iommu_drvdata); |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 574 | if (ret) { |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 575 | iommu_access_ops->iommu_power_off(iommu_drvdata); |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 576 | goto fail; |
| 577 | } |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | list_add(&(ctx_drvdata->attached_elm), &priv->list_attached); |
| 581 | ctx_drvdata->attached_domain = domain; |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 582 | ++iommu_drvdata->ctx_attach_count; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 583 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 584 | iommu_access_ops->iommu_lock_release(); |
Olav Haugan | 64ffdf3 | 2013-01-24 17:20:24 -0800 | [diff] [blame] | 585 | |
| 586 | msm_iommu_attached(dev->parent); |
| 587 | return ret; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 588 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 589 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | static void msm_iommu_detach_dev(struct iommu_domain *domain, |
| 594 | struct device *dev) |
| 595 | { |
| 596 | struct msm_iommu_drvdata *iommu_drvdata; |
| 597 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 598 | |
Olav Haugan | 64ffdf3 | 2013-01-24 17:20:24 -0800 | [diff] [blame] | 599 | msm_iommu_detached(dev->parent); |
| 600 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 601 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 602 | if (!dev) |
| 603 | goto fail; |
| 604 | |
| 605 | iommu_drvdata = dev_get_drvdata(dev->parent); |
| 606 | ctx_drvdata = dev_get_drvdata(dev); |
| 607 | if (!iommu_drvdata || !ctx_drvdata || !ctx_drvdata->attached_domain) |
| 608 | goto fail; |
| 609 | |
| 610 | list_del_init(&ctx_drvdata->attached_elm); |
| 611 | ctx_drvdata->attached_domain = NULL; |
| 612 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 613 | iommu_access_ops->iommu_power_off(iommu_drvdata); |
Olav Haugan | e388539 | 2013-03-06 16:22:53 -0800 | [diff] [blame] | 614 | BUG_ON(iommu_drvdata->ctx_attach_count == 0); |
| 615 | --iommu_drvdata->ctx_attach_count; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 616 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 617 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static int get_drvdata(struct iommu_domain *domain, |
| 621 | struct msm_iommu_drvdata **iommu_drvdata, |
| 622 | struct msm_iommu_ctx_drvdata **ctx_drvdata) |
| 623 | { |
Olav Haugan | 090614f | 2013-03-22 12:14:18 -0700 | [diff] [blame] | 624 | struct msm_iommu_priv *priv = domain->priv; |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 625 | struct msm_iommu_ctx_drvdata *ctx; |
| 626 | |
| 627 | list_for_each_entry(ctx, &priv->list_attached, attached_elm) { |
| 628 | if (ctx->attached_domain == domain) |
| 629 | break; |
| 630 | } |
| 631 | |
| 632 | if (ctx->attached_domain != domain) |
| 633 | return -EINVAL; |
| 634 | |
| 635 | *ctx_drvdata = ctx; |
| 636 | *iommu_drvdata = dev_get_drvdata(ctx->pdev->dev.parent); |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int msm_iommu_map(struct iommu_domain *domain, unsigned long va, |
| 641 | phys_addr_t pa, size_t len, int prot) |
| 642 | { |
| 643 | struct msm_iommu_drvdata *iommu_drvdata; |
| 644 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 645 | int ret = 0; |
| 646 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 647 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 648 | |
| 649 | ret = get_drvdata(domain, &iommu_drvdata, &ctx_drvdata); |
| 650 | if (ret) |
| 651 | goto fail; |
| 652 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 653 | iommu_access_ops->iommu_clk_on(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 654 | ret = msm_iommu_sec_ptbl_map(iommu_drvdata, ctx_drvdata, |
| 655 | va, pa, len); |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 656 | iommu_access_ops->iommu_clk_off(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 657 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 658 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 659 | return ret; |
| 660 | } |
| 661 | |
| 662 | static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long va, |
| 663 | size_t len) |
| 664 | { |
| 665 | struct msm_iommu_drvdata *iommu_drvdata; |
| 666 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 667 | int ret = -ENODEV; |
| 668 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 669 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 670 | |
| 671 | ret = get_drvdata(domain, &iommu_drvdata, &ctx_drvdata); |
| 672 | if (ret) |
| 673 | goto fail; |
| 674 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 675 | iommu_access_ops->iommu_clk_on(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 676 | ret = msm_iommu_sec_ptbl_unmap(iommu_drvdata, ctx_drvdata, |
| 677 | va, len); |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 678 | iommu_access_ops->iommu_clk_off(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 679 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 680 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 681 | |
| 682 | /* the IOMMU API requires us to return how many bytes were unmapped */ |
| 683 | len = ret ? 0 : len; |
| 684 | return len; |
| 685 | } |
| 686 | |
| 687 | static int msm_iommu_map_range(struct iommu_domain *domain, unsigned int va, |
| 688 | struct scatterlist *sg, unsigned int len, |
| 689 | int prot) |
| 690 | { |
| 691 | int ret; |
| 692 | struct msm_iommu_drvdata *iommu_drvdata; |
| 693 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 694 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 695 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 696 | |
| 697 | ret = get_drvdata(domain, &iommu_drvdata, &ctx_drvdata); |
| 698 | if (ret) |
| 699 | goto fail; |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 700 | iommu_access_ops->iommu_clk_on(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 701 | ret = msm_iommu_sec_ptbl_map_range(iommu_drvdata, ctx_drvdata, |
| 702 | va, sg, len); |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 703 | iommu_access_ops->iommu_clk_off(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 704 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 705 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | |
| 710 | static int msm_iommu_unmap_range(struct iommu_domain *domain, unsigned int va, |
| 711 | unsigned int len) |
| 712 | { |
| 713 | struct msm_iommu_drvdata *iommu_drvdata; |
| 714 | struct msm_iommu_ctx_drvdata *ctx_drvdata; |
| 715 | int ret; |
| 716 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 717 | iommu_access_ops->iommu_lock_acquire(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 718 | |
| 719 | ret = get_drvdata(domain, &iommu_drvdata, &ctx_drvdata); |
| 720 | if (ret) |
| 721 | goto fail; |
| 722 | |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 723 | iommu_access_ops->iommu_clk_on(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 724 | ret = msm_iommu_sec_ptbl_unmap(iommu_drvdata, ctx_drvdata, va, len); |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 725 | iommu_access_ops->iommu_clk_off(iommu_drvdata); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 726 | |
| 727 | fail: |
Olav Haugan | eece7e5 | 2013-04-02 10:22:21 -0700 | [diff] [blame] | 728 | iommu_access_ops->iommu_lock_release(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain, |
| 733 | unsigned long va) |
| 734 | { |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static int msm_iommu_domain_has_cap(struct iommu_domain *domain, |
| 739 | unsigned long cap) |
| 740 | { |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static phys_addr_t msm_iommu_get_pt_base_addr(struct iommu_domain *domain) |
| 745 | { |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | static struct iommu_ops msm_iommu_ops = { |
| 750 | .domain_init = msm_iommu_domain_init, |
| 751 | .domain_destroy = msm_iommu_domain_destroy, |
| 752 | .attach_dev = msm_iommu_attach_dev, |
| 753 | .detach_dev = msm_iommu_detach_dev, |
| 754 | .map = msm_iommu_map, |
| 755 | .unmap = msm_iommu_unmap, |
| 756 | .map_range = msm_iommu_map_range, |
| 757 | .unmap_range = msm_iommu_unmap_range, |
| 758 | .iova_to_phys = msm_iommu_iova_to_phys, |
| 759 | .domain_has_cap = msm_iommu_domain_has_cap, |
| 760 | .get_pt_base_addr = msm_iommu_get_pt_base_addr, |
| 761 | .pgsize_bitmap = MSM_IOMMU_PGSIZES, |
| 762 | }; |
| 763 | |
| 764 | static int __init msm_iommu_sec_init(void) |
| 765 | { |
| 766 | int ret; |
| 767 | |
| 768 | ret = bus_register(&msm_iommu_sec_bus_type); |
| 769 | if (ret) |
| 770 | goto fail; |
| 771 | |
| 772 | bus_set_iommu(&msm_iommu_sec_bus_type, &msm_iommu_ops); |
| 773 | ret = msm_iommu_sec_ptbl_init(); |
Laura Abbott | 0d13565 | 2012-10-04 12:59:03 -0700 | [diff] [blame] | 774 | fail: |
| 775 | return ret; |
| 776 | } |
| 777 | |
| 778 | subsys_initcall(msm_iommu_sec_init); |
| 779 | |
| 780 | MODULE_LICENSE("GPL v2"); |
| 781 | MODULE_DESCRIPTION("MSM SMMU Secure Driver"); |