Stepan Moskovchenko | 80acab9 | 2012-02-14 15:41:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -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. |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/clk.h> |
| 20 | #include <linux/iommu.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/slab.h> |
| 24 | |
| 25 | #include <mach/iommu_hw-8xxx.h> |
| 26 | #include <mach/iommu.h> |
| 27 | |
| 28 | struct iommu_ctx_iter_data { |
| 29 | /* input */ |
| 30 | const char *name; |
| 31 | |
| 32 | /* output */ |
| 33 | struct device *dev; |
| 34 | }; |
| 35 | |
| 36 | static struct platform_device *msm_iommu_root_dev; |
| 37 | |
| 38 | static int each_iommu_ctx(struct device *dev, void *data) |
| 39 | { |
| 40 | struct iommu_ctx_iter_data *res = data; |
| 41 | struct msm_iommu_ctx_dev *c = dev->platform_data; |
| 42 | |
| 43 | if (!res || !c || !c->name || !res->name) |
| 44 | return -EINVAL; |
| 45 | |
| 46 | if (!strcmp(res->name, c->name)) { |
| 47 | res->dev = dev; |
| 48 | return 1; |
| 49 | } |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int each_iommu(struct device *dev, void *data) |
| 54 | { |
| 55 | return device_for_each_child(dev, data, each_iommu_ctx); |
| 56 | } |
| 57 | |
| 58 | struct device *msm_iommu_get_ctx(const char *ctx_name) |
| 59 | { |
| 60 | struct iommu_ctx_iter_data r; |
| 61 | int found; |
| 62 | |
| 63 | if (!msm_iommu_root_dev) { |
| 64 | pr_err("No root IOMMU device.\n"); |
| 65 | goto fail; |
| 66 | } |
| 67 | |
| 68 | r.name = ctx_name; |
| 69 | found = device_for_each_child(&msm_iommu_root_dev->dev, &r, each_iommu); |
| 70 | |
Stepan Moskovchenko | 53b152f | 2011-10-31 18:24:59 -0700 | [diff] [blame] | 71 | if (!found || !dev_get_drvdata(r.dev)) { |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 72 | pr_err("Could not find context <%s>\n", ctx_name); |
| 73 | goto fail; |
| 74 | } |
| 75 | |
| 76 | return r.dev; |
| 77 | fail: |
| 78 | return NULL; |
| 79 | } |
| 80 | EXPORT_SYMBOL(msm_iommu_get_ctx); |
| 81 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 82 | static void msm_iommu_reset(void __iomem *base, int ncb) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 83 | { |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 84 | int ctx; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 85 | |
| 86 | SET_RPUE(base, 0); |
| 87 | SET_RPUEIE(base, 0); |
| 88 | SET_ESRRESTORE(base, 0); |
| 89 | SET_TBE(base, 0); |
| 90 | SET_CR(base, 0); |
| 91 | SET_SPDMBE(base, 0); |
| 92 | SET_TESTBUSCR(base, 0); |
| 93 | SET_TLBRSW(base, 0); |
| 94 | SET_GLOBAL_TLBIALL(base, 0); |
| 95 | SET_RPU_ACR(base, 0); |
| 96 | SET_TLBLKCRWE(base, 1); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 97 | |
| 98 | for (ctx = 0; ctx < ncb; ctx++) { |
| 99 | SET_BPRCOSH(base, ctx, 0); |
| 100 | SET_BPRCISH(base, ctx, 0); |
| 101 | SET_BPRCNSH(base, ctx, 0); |
| 102 | SET_BPSHCFG(base, ctx, 0); |
| 103 | SET_BPMTCFG(base, ctx, 0); |
| 104 | SET_ACTLR(base, ctx, 0); |
| 105 | SET_SCTLR(base, ctx, 0); |
| 106 | SET_FSRRESTORE(base, ctx, 0); |
| 107 | SET_TTBR0(base, ctx, 0); |
| 108 | SET_TTBR1(base, ctx, 0); |
| 109 | SET_TTBCR(base, ctx, 0); |
| 110 | SET_BFBCR(base, ctx, 0); |
| 111 | SET_PAR(base, ctx, 0); |
| 112 | SET_FAR(base, ctx, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 113 | SET_TLBFLPTER(base, ctx, 0); |
| 114 | SET_TLBSLPTER(base, ctx, 0); |
| 115 | SET_TLBLKCR(base, ctx, 0); |
Stepan Moskovchenko | 0272fd6 | 2011-09-26 15:06:40 -0700 | [diff] [blame] | 116 | SET_CTX_TLBIALL(base, ctx, 0); |
| 117 | SET_TLBIVA(base, ctx, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 118 | SET_PRRR(base, ctx, 0); |
| 119 | SET_NMRR(base, ctx, 0); |
| 120 | SET_CONTEXTIDR(base, ctx, 0); |
| 121 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 122 | mb(); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int msm_iommu_probe(struct platform_device *pdev) |
| 126 | { |
Vasiliy Kulikov | a86c44d | 2010-10-17 18:51:37 +0400 | [diff] [blame] | 127 | struct resource *r, *r2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 128 | struct clk *iommu_clk = NULL; |
| 129 | struct clk *iommu_pclk = NULL; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 130 | struct msm_iommu_drvdata *drvdata; |
| 131 | struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data; |
| 132 | void __iomem *regs_base; |
| 133 | resource_size_t len; |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 134 | int ret, irq, par; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 135 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 136 | if (pdev->id == -1) { |
| 137 | msm_iommu_root_dev = pdev; |
| 138 | return 0; |
| 139 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 140 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 141 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 142 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 143 | if (!drvdata) { |
| 144 | ret = -ENOMEM; |
| 145 | goto fail; |
| 146 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 147 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 148 | if (!iommu_dev) { |
| 149 | ret = -ENODEV; |
| 150 | goto fail; |
| 151 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 152 | |
Matt Wagantall | e604d71 | 2011-10-21 15:38:18 -0700 | [diff] [blame] | 153 | iommu_pclk = clk_get_sys("msm_iommu", "iface_clk"); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 154 | if (IS_ERR(iommu_pclk)) { |
| 155 | ret = -ENODEV; |
| 156 | goto fail; |
| 157 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 158 | |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 159 | ret = clk_prepare_enable(iommu_pclk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 160 | if (ret) |
| 161 | goto fail_enable; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 162 | |
Matt Wagantall | e604d71 | 2011-10-21 15:38:18 -0700 | [diff] [blame] | 163 | iommu_clk = clk_get(&pdev->dev, "core_clk"); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 164 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 165 | if (!IS_ERR(iommu_clk)) { |
Matt Wagantall | 9985822 | 2011-11-08 14:31:27 -0800 | [diff] [blame] | 166 | if (clk_get_rate(iommu_clk) == 0) { |
| 167 | ret = clk_round_rate(iommu_clk, 1); |
| 168 | clk_set_rate(iommu_clk, ret); |
| 169 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 170 | |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 171 | ret = clk_prepare_enable(iommu_clk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 172 | if (ret) { |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 173 | clk_put(iommu_clk); |
| 174 | goto fail_pclk; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 175 | } |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 176 | } else |
| 177 | iommu_clk = NULL; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 178 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 179 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "physbase"); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 180 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 181 | if (!r) { |
| 182 | ret = -ENODEV; |
| 183 | goto fail_clk; |
| 184 | } |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 185 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 186 | len = resource_size(r); |
| 187 | |
| 188 | r2 = request_mem_region(r->start, len, r->name); |
| 189 | if (!r2) { |
| 190 | pr_err("Could not request memory region: start=%p, len=%d\n", |
| 191 | (void *) r->start, len); |
| 192 | ret = -EBUSY; |
| 193 | goto fail_clk; |
| 194 | } |
| 195 | |
| 196 | regs_base = ioremap(r2->start, len); |
| 197 | |
| 198 | if (!regs_base) { |
| 199 | pr_err("Could not ioremap: start=%p, len=%d\n", |
| 200 | (void *) r2->start, len); |
| 201 | ret = -EBUSY; |
| 202 | goto fail_mem; |
| 203 | } |
| 204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | irq = platform_get_irq_byname(pdev, "nonsecure_irq"); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 206 | if (irq < 0) { |
| 207 | ret = -ENODEV; |
| 208 | goto fail_io; |
| 209 | } |
| 210 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 211 | msm_iommu_reset(regs_base, iommu_dev->ncb); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 212 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 213 | SET_M(regs_base, 0, 1); |
| 214 | SET_PAR(regs_base, 0, 0); |
| 215 | SET_V2PCFG(regs_base, 0, 1); |
| 216 | SET_V2PPR(regs_base, 0, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 217 | mb(); |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 218 | par = GET_PAR(regs_base, 0); |
| 219 | SET_V2PCFG(regs_base, 0, 0); |
| 220 | SET_M(regs_base, 0, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | mb(); |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 222 | |
| 223 | if (!par) { |
| 224 | pr_err("%s: Invalid PAR value detected\n", iommu_dev->name); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 225 | ret = -ENODEV; |
| 226 | goto fail_io; |
| 227 | } |
| 228 | |
Stepan Moskovchenko | 80acab9 | 2012-02-14 15:41:12 -0800 | [diff] [blame] | 229 | ret = request_threaded_irq(irq, NULL, msm_iommu_fault_handler, |
| 230 | IRQF_ONESHOT, "msm_iommu_secure_irpt_handler", drvdata); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 231 | if (ret) { |
| 232 | pr_err("Request IRQ %d failed with ret=%d\n", irq, ret); |
| 233 | goto fail_io; |
| 234 | } |
| 235 | |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 236 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 237 | drvdata->pclk = iommu_pclk; |
| 238 | drvdata->clk = iommu_clk; |
| 239 | drvdata->base = regs_base; |
| 240 | drvdata->irq = irq; |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 241 | drvdata->ncb = iommu_dev->ncb; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 242 | drvdata->name = iommu_dev->name; |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 243 | |
| 244 | pr_info("device %s mapped at %p, irq %d with %d ctx banks\n", |
Stepan Moskovchenko | a43d8c1 | 2011-02-24 18:00:42 -0800 | [diff] [blame] | 245 | iommu_dev->name, regs_base, irq, iommu_dev->ncb); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 246 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 247 | platform_set_drvdata(pdev, drvdata); |
| 248 | |
| 249 | if (iommu_clk) |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 250 | clk_disable_unprepare(iommu_clk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 251 | |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 252 | clk_disable_unprepare(iommu_pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 253 | |
| 254 | return 0; |
Vasiliy Kulikov | a86c44d | 2010-10-17 18:51:37 +0400 | [diff] [blame] | 255 | fail_io: |
| 256 | iounmap(regs_base); |
| 257 | fail_mem: |
| 258 | release_mem_region(r->start, len); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 259 | fail_clk: |
| 260 | if (iommu_clk) { |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 261 | clk_disable_unprepare(iommu_clk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 262 | clk_put(iommu_clk); |
| 263 | } |
| 264 | fail_pclk: |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 265 | clk_disable_unprepare(iommu_pclk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 266 | fail_enable: |
| 267 | clk_put(iommu_pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 268 | fail: |
| 269 | kfree(drvdata); |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | static int msm_iommu_remove(struct platform_device *pdev) |
| 274 | { |
| 275 | struct msm_iommu_drvdata *drv = NULL; |
| 276 | |
| 277 | drv = platform_get_drvdata(pdev); |
| 278 | if (drv) { |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 279 | if (drv->clk) |
| 280 | clk_put(drv->clk); |
| 281 | clk_put(drv->pclk); |
| 282 | memset(drv, 0, sizeof(*drv)); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 283 | kfree(drv); |
| 284 | platform_set_drvdata(pdev, NULL); |
| 285 | } |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int msm_iommu_ctx_probe(struct platform_device *pdev) |
| 290 | { |
| 291 | struct msm_iommu_ctx_dev *c = pdev->dev.platform_data; |
| 292 | struct msm_iommu_drvdata *drvdata; |
| 293 | struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL; |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 294 | int i, ret; |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 295 | if (!c || !pdev->dev.parent) { |
| 296 | ret = -EINVAL; |
| 297 | goto fail; |
| 298 | } |
| 299 | |
| 300 | drvdata = dev_get_drvdata(pdev->dev.parent); |
| 301 | |
| 302 | if (!drvdata) { |
| 303 | ret = -ENODEV; |
| 304 | goto fail; |
| 305 | } |
| 306 | |
| 307 | ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL); |
| 308 | if (!ctx_drvdata) { |
| 309 | ret = -ENOMEM; |
| 310 | goto fail; |
| 311 | } |
| 312 | ctx_drvdata->num = c->num; |
| 313 | ctx_drvdata->pdev = pdev; |
| 314 | |
| 315 | INIT_LIST_HEAD(&ctx_drvdata->attached_elm); |
| 316 | platform_set_drvdata(pdev, ctx_drvdata); |
| 317 | |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 318 | ret = clk_prepare_enable(drvdata->pclk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 319 | if (ret) |
| 320 | goto fail; |
| 321 | |
| 322 | if (drvdata->clk) { |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 323 | ret = clk_prepare_enable(drvdata->clk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 324 | if (ret) { |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 325 | clk_disable_unprepare(drvdata->pclk); |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 326 | goto fail; |
| 327 | } |
| 328 | } |
| 329 | |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 330 | /* Program the M2V tables for this context */ |
| 331 | for (i = 0; i < MAX_NUM_MIDS; i++) { |
| 332 | int mid = c->mids[i]; |
| 333 | if (mid == -1) |
| 334 | break; |
| 335 | |
| 336 | SET_M2VCBR_N(drvdata->base, mid, 0); |
| 337 | SET_CBACR_N(drvdata->base, c->num, 0); |
| 338 | |
Stepan Moskovchenko | 01720e7 | 2011-10-21 14:27:29 -0700 | [diff] [blame] | 339 | /* Route page faults to the non-secure interrupt */ |
| 340 | SET_IRPTNDX(drvdata->base, c->num, 1); |
| 341 | |
Stepan Moskovchenko | 2e8c8ba | 2011-02-24 18:00:41 -0800 | [diff] [blame] | 342 | /* Set VMID = 0 */ |
| 343 | SET_VMID(drvdata->base, mid, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 344 | |
| 345 | /* Set the context number for that MID to this context */ |
| 346 | SET_CBNDX(drvdata->base, mid, c->num); |
| 347 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 348 | /* Set MID associated with this context bank to 0 */ |
Stepan Moskovchenko | 2e8c8ba | 2011-02-24 18:00:41 -0800 | [diff] [blame] | 349 | SET_CBVMID(drvdata->base, c->num, 0); |
| 350 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 351 | /* Set the ASID for TLB tagging for this context to 0 */ |
| 352 | SET_CONTEXTIDR_ASID(drvdata->base, c->num, 0); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 353 | |
| 354 | /* Set security bit override to be Non-secure */ |
| 355 | SET_NSCFG(drvdata->base, mid, 3); |
| 356 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 357 | mb(); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 358 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 359 | if (drvdata->clk) |
Stepan Moskovchenko | bbf95e1 | 2012-02-14 15:42:27 -0800 | [diff] [blame] | 360 | clk_disable_unprepare(drvdata->clk); |
| 361 | clk_disable_unprepare(drvdata->pclk); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 362 | |
Stepan Moskovchenko | b61401a | 2011-02-28 16:03:02 -0800 | [diff] [blame] | 363 | dev_info(&pdev->dev, "context %s using bank %d\n", c->name, c->num); |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 364 | return 0; |
| 365 | fail: |
| 366 | kfree(ctx_drvdata); |
| 367 | return ret; |
| 368 | } |
| 369 | |
| 370 | static int msm_iommu_ctx_remove(struct platform_device *pdev) |
| 371 | { |
| 372 | struct msm_iommu_ctx_drvdata *drv = NULL; |
| 373 | drv = platform_get_drvdata(pdev); |
| 374 | if (drv) { |
| 375 | memset(drv, 0, sizeof(struct msm_iommu_ctx_drvdata)); |
| 376 | kfree(drv); |
| 377 | platform_set_drvdata(pdev, NULL); |
| 378 | } |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static struct platform_driver msm_iommu_driver = { |
| 383 | .driver = { |
| 384 | .name = "msm_iommu", |
| 385 | }, |
| 386 | .probe = msm_iommu_probe, |
| 387 | .remove = msm_iommu_remove, |
| 388 | }; |
| 389 | |
| 390 | static struct platform_driver msm_iommu_ctx_driver = { |
| 391 | .driver = { |
| 392 | .name = "msm_iommu_ctx", |
| 393 | }, |
| 394 | .probe = msm_iommu_ctx_probe, |
| 395 | .remove = msm_iommu_ctx_remove, |
| 396 | }; |
| 397 | |
Stepan Moskovchenko | 516cbc7 | 2010-11-12 19:29:53 -0800 | [diff] [blame] | 398 | static int __init msm_iommu_driver_init(void) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 399 | { |
| 400 | int ret; |
| 401 | ret = platform_driver_register(&msm_iommu_driver); |
| 402 | if (ret != 0) { |
| 403 | pr_err("Failed to register IOMMU driver\n"); |
| 404 | goto error; |
| 405 | } |
| 406 | |
| 407 | ret = platform_driver_register(&msm_iommu_ctx_driver); |
| 408 | if (ret != 0) { |
| 409 | pr_err("Failed to register IOMMU context driver\n"); |
| 410 | goto error; |
| 411 | } |
| 412 | |
| 413 | error: |
| 414 | return ret; |
| 415 | } |
| 416 | |
Stepan Moskovchenko | 516cbc7 | 2010-11-12 19:29:53 -0800 | [diff] [blame] | 417 | static void __exit msm_iommu_driver_exit(void) |
Stepan Moskovchenko | c6a5951 | 2010-08-24 18:32:38 -0700 | [diff] [blame] | 418 | { |
| 419 | platform_driver_unregister(&msm_iommu_ctx_driver); |
| 420 | platform_driver_unregister(&msm_iommu_driver); |
| 421 | } |
| 422 | |
| 423 | subsys_initcall(msm_iommu_driver_init); |
| 424 | module_exit(msm_iommu_driver_exit); |
| 425 | |
| 426 | MODULE_LICENSE("GPL v2"); |
| 427 | MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>"); |