msm_iommu_dev-v0.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/io.h>
  17. #include <linux/clk.h>
  18. #include <linux/iommu.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/err.h>
  21. #include <linux/slab.h>
  22. #include <linux/list.h>
  23. #include <linux/mutex.h>
  24. #include <linux/of.h>
  25. #include <linux/of_address.h>
  26. #include <linux/of_device.h>
  27. #include <mach/iommu_perfmon.h>
  28. #include <mach/iommu_hw-v0.h>
  29. #include <mach/iommu.h>
  30. #include <mach/msm_bus.h>
  31. static struct of_device_id msm_iommu_v0_ctx_match_table[];
  32. static struct iommu_access_ops *msm_iommu_access_ops;
  33. static void msm_iommu_reset(void __iomem *base, void __iomem *glb_base, int ncb)
  34. {
  35. int ctx;
  36. SET_RPUE(glb_base, 0);
  37. SET_RPUEIE(glb_base, 0);
  38. SET_ESRRESTORE(glb_base, 0);
  39. SET_TBE(glb_base, 0);
  40. SET_CR(glb_base, 0);
  41. SET_SPDMBE(glb_base, 0);
  42. SET_TESTBUSCR(glb_base, 0);
  43. SET_TLBRSW(glb_base, 0);
  44. SET_GLOBAL_TLBIALL(glb_base, 0);
  45. SET_RPU_ACR(glb_base, 0);
  46. SET_TLBLKCRWE(glb_base, 1);
  47. for (ctx = 0; ctx < ncb; ctx++) {
  48. SET_BPRCOSH(glb_base, ctx, 0);
  49. SET_BPRCISH(glb_base, ctx, 0);
  50. SET_BPRCNSH(glb_base, ctx, 0);
  51. SET_BPSHCFG(glb_base, ctx, 0);
  52. SET_BPMTCFG(glb_base, ctx, 0);
  53. SET_ACTLR(base, ctx, 0);
  54. SET_SCTLR(base, ctx, 0);
  55. SET_FSRRESTORE(base, ctx, 0);
  56. SET_TTBR0(base, ctx, 0);
  57. SET_TTBR1(base, ctx, 0);
  58. SET_TTBCR(base, ctx, 0);
  59. SET_BFBCR(base, ctx, 0);
  60. SET_PAR(base, ctx, 0);
  61. SET_FAR(base, ctx, 0);
  62. SET_TLBFLPTER(base, ctx, 0);
  63. SET_TLBSLPTER(base, ctx, 0);
  64. SET_TLBLKCR(base, ctx, 0);
  65. SET_CTX_TLBIALL(base, ctx, 0);
  66. SET_TLBIVA(base, ctx, 0);
  67. SET_PRRR(base, ctx, 0);
  68. SET_NMRR(base, ctx, 0);
  69. SET_CONTEXTIDR(base, ctx, 0);
  70. }
  71. mb();
  72. }
  73. static int __get_clocks(struct platform_device *pdev,
  74. struct msm_iommu_drvdata *drvdata,
  75. int needs_alt_core_clk)
  76. {
  77. int ret = 0;
  78. drvdata->pclk = devm_clk_get(&pdev->dev, "iface_clk");
  79. if (IS_ERR(drvdata->pclk)) {
  80. ret = PTR_ERR(drvdata->pclk);
  81. drvdata->pclk = NULL;
  82. if (ret != -EPROBE_DEFER) {
  83. pr_err("Unable to get %s clock for %s IOMMU device\n",
  84. dev_name(&pdev->dev), drvdata->name);
  85. }
  86. goto fail;
  87. }
  88. drvdata->clk = devm_clk_get(&pdev->dev, "core_clk");
  89. if (!IS_ERR(drvdata->clk)) {
  90. if (clk_get_rate(drvdata->clk) == 0) {
  91. ret = clk_round_rate(drvdata->clk, 1000);
  92. clk_set_rate(drvdata->clk, ret);
  93. }
  94. } else {
  95. drvdata->clk = NULL;
  96. }
  97. if (needs_alt_core_clk) {
  98. drvdata->aclk = devm_clk_get(&pdev->dev, "alt_core_clk");
  99. if (IS_ERR(drvdata->aclk)) {
  100. ret = PTR_ERR(drvdata->aclk);
  101. goto fail;
  102. }
  103. }
  104. if (drvdata->aclk && clk_get_rate(drvdata->aclk) == 0) {
  105. ret = clk_round_rate(drvdata->aclk, 1000);
  106. clk_set_rate(drvdata->aclk, ret);
  107. }
  108. return 0;
  109. fail:
  110. return ret;
  111. }
  112. #ifdef CONFIG_OF_DEVICE
  113. static int __get_bus_vote_client(struct platform_device *pdev,
  114. struct msm_iommu_drvdata *drvdata)
  115. {
  116. int ret = 0;
  117. struct msm_bus_scale_pdata *bs_table;
  118. const char *dummy;
  119. /* Check whether bus scaling has been specified for this node */
  120. ret = of_property_read_string(pdev->dev.of_node, "qcom,msm-bus,name",
  121. &dummy);
  122. if (ret)
  123. return 0;
  124. bs_table = msm_bus_cl_get_pdata(pdev);
  125. if (bs_table) {
  126. drvdata->bus_client = msm_bus_scale_register_client(bs_table);
  127. if (IS_ERR(&drvdata->bus_client)) {
  128. pr_err("%s(): Bus client register failed.\n", __func__);
  129. ret = -EINVAL;
  130. }
  131. }
  132. return ret;
  133. }
  134. static void __put_bus_vote_client(struct msm_iommu_drvdata *drvdata)
  135. {
  136. msm_bus_scale_unregister_client(drvdata->bus_client);
  137. drvdata->bus_client = 0;
  138. }
  139. static int msm_iommu_parse_dt(struct platform_device *pdev,
  140. struct msm_iommu_drvdata *drvdata)
  141. {
  142. struct device_node *child;
  143. struct resource *r;
  144. u32 glb_offset = 0;
  145. int ret = 0;
  146. int needs_alt_core_clk;
  147. ret = __get_bus_vote_client(pdev, drvdata);
  148. if (ret)
  149. goto fail;
  150. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  151. if (!r) {
  152. pr_err("%s: Missing property reg\n", __func__);
  153. ret = -EINVAL;
  154. goto fail;
  155. }
  156. drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
  157. if (!drvdata->base) {
  158. pr_err("%s: Unable to ioremap %pr\n", __func__, r);
  159. ret = -ENOMEM;
  160. goto fail;
  161. }
  162. drvdata->glb_base = drvdata->base;
  163. if (!of_property_read_u32(pdev->dev.of_node, "qcom,glb-offset",
  164. &glb_offset)) {
  165. drvdata->glb_base += glb_offset;
  166. } else {
  167. pr_err("%s: Missing property qcom,glb-offset\n", __func__);
  168. ret = -EINVAL;
  169. goto fail;
  170. }
  171. for_each_child_of_node(pdev->dev.of_node, child)
  172. drvdata->ncb++;
  173. ret = of_property_read_string(pdev->dev.of_node, "label",
  174. &drvdata->name);
  175. if (ret) {
  176. pr_err("%s: Missing property label\n", __func__);
  177. ret = -EINVAL;
  178. goto fail;
  179. }
  180. needs_alt_core_clk = of_property_read_bool(pdev->dev.of_node,
  181. "qcom,needs-alt-core-clk");
  182. ret = __get_clocks(pdev, drvdata, needs_alt_core_clk);
  183. if (ret)
  184. goto fail;
  185. drvdata->sec_id = -1;
  186. drvdata->ttbr_split = 0;
  187. drvdata->needs_rem_spinlock = of_property_read_bool(pdev->dev.of_node,
  188. "qcom,msm-enable-remote-spinlock");
  189. if (drvdata->needs_rem_spinlock)
  190. pr_info("%s enabled remote spinlock\n", drvdata->name);
  191. ret = of_platform_populate(pdev->dev.of_node,
  192. msm_iommu_v0_ctx_match_table,
  193. NULL, &pdev->dev);
  194. if (ret) {
  195. pr_err("Failed to create iommu context device\n");
  196. goto fail;
  197. }
  198. return ret;
  199. fail:
  200. __put_bus_vote_client(drvdata);
  201. return ret;
  202. }
  203. #else
  204. static int msm_iommu_parse_dt(struct platform_device *pdev,
  205. struct msm_iommu_drvdata *drvdata)
  206. {
  207. return 0;
  208. }
  209. static void __put_bus_vote_client(struct msm_iommu_drvdata *drvdata)
  210. {
  211. }
  212. #endif
  213. /*
  214. * Do a basic check of the IOMMU by performing an ATS operation
  215. * on context bank 0.
  216. */
  217. static int iommu_sanity_check(struct msm_iommu_drvdata *drvdata)
  218. {
  219. int par;
  220. int ret = 0;
  221. SET_M(drvdata->base, 0, 1);
  222. SET_PAR(drvdata->base, 0, 0);
  223. SET_V2PCFG(drvdata->base, 0, 1);
  224. SET_V2PPR(drvdata->base, 0, 0);
  225. mb();
  226. par = GET_PAR(drvdata->base, 0);
  227. SET_V2PCFG(drvdata->base, 0, 0);
  228. SET_M(drvdata->base, 0, 0);
  229. mb();
  230. if (!par) {
  231. pr_err("%s: Invalid PAR value detected\n", drvdata->name);
  232. ret = -ENODEV;
  233. }
  234. return ret;
  235. }
  236. static int msm_iommu_pmon_parse_dt(struct platform_device *pdev,
  237. struct iommu_pmon *pmon_info)
  238. {
  239. int ret = 0;
  240. int irq = platform_get_irq(pdev, 0);
  241. unsigned int cls_prop_size;
  242. if (irq > 0) {
  243. pmon_info->iommu.evt_irq = platform_get_irq(pdev, 0);
  244. ret = of_property_read_u32(pdev->dev.of_node,
  245. "qcom,iommu-pmu-ngroups",
  246. &pmon_info->num_groups);
  247. if (ret) {
  248. pr_err("Error reading qcom,iommu-pmu-ngroups\n");
  249. goto fail;
  250. }
  251. ret = of_property_read_u32(pdev->dev.of_node,
  252. "qcom,iommu-pmu-ncounters",
  253. &pmon_info->num_counters);
  254. if (ret) {
  255. pr_err("Error reading qcom,iommu-pmu-ncounters\n");
  256. goto fail;
  257. }
  258. if (!of_get_property(pdev->dev.of_node,
  259. "qcom,iommu-pmu-event-classes",
  260. &cls_prop_size)) {
  261. pr_err("Error reading qcom,iommu-pmu-event-classes\n");
  262. return -EINVAL;
  263. }
  264. pmon_info->event_cls_supported =
  265. devm_kzalloc(&pdev->dev, cls_prop_size, GFP_KERNEL);
  266. if (!pmon_info->event_cls_supported) {
  267. pr_err("Unable to get memory for event class array\n");
  268. return -ENOMEM;
  269. }
  270. pmon_info->nevent_cls_supported = cls_prop_size / sizeof(u32);
  271. ret = of_property_read_u32_array(pdev->dev.of_node,
  272. "qcom,iommu-pmu-event-classes",
  273. pmon_info->event_cls_supported,
  274. pmon_info->nevent_cls_supported);
  275. if (ret) {
  276. pr_err("Error reading qcom,iommu-pmu-event-classes\n");
  277. return ret;
  278. }
  279. } else {
  280. pmon_info->iommu.evt_irq = -1;
  281. ret = irq;
  282. }
  283. fail:
  284. return ret;
  285. }
  286. static int msm_iommu_probe(struct platform_device *pdev)
  287. {
  288. struct iommu_pmon *pmon_info;
  289. struct msm_iommu_drvdata *drvdata;
  290. struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data;
  291. int ret;
  292. drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
  293. if (!drvdata) {
  294. ret = -ENOMEM;
  295. goto fail_mem;
  296. }
  297. if (pdev->dev.of_node) {
  298. ret = msm_iommu_parse_dt(pdev, drvdata);
  299. if (ret)
  300. goto fail;
  301. } else if (pdev->dev.platform_data) {
  302. struct resource *r, *r2;
  303. resource_size_t len;
  304. ret = __get_clocks(pdev, drvdata, 0);
  305. if (ret)
  306. goto fail;
  307. r = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  308. "physbase");
  309. if (!r) {
  310. ret = -ENODEV;
  311. goto fail;
  312. }
  313. len = resource_size(r);
  314. r2 = devm_request_mem_region(&pdev->dev, r->start,
  315. len, r->name);
  316. if (!r2) {
  317. pr_err("Could not request memory region: %pr\n", r);
  318. ret = -EBUSY;
  319. goto fail;
  320. }
  321. drvdata->base = devm_ioremap(&pdev->dev, r2->start, len);
  322. if (!drvdata->base) {
  323. pr_err("Could not ioremap: %pr\n", r);
  324. ret = -EBUSY;
  325. goto fail;
  326. }
  327. /*
  328. * Global register space offset for legacy IOMMUv1 hardware
  329. * is always 0xFF000
  330. */
  331. drvdata->glb_base = drvdata->base + 0xFF000;
  332. drvdata->name = iommu_dev->name;
  333. drvdata->dev = &pdev->dev;
  334. drvdata->ncb = iommu_dev->ncb;
  335. drvdata->ttbr_split = iommu_dev->ttbr_split;
  336. } else {
  337. ret = -ENODEV;
  338. goto fail;
  339. }
  340. drvdata->dev = &pdev->dev;
  341. msm_iommu_access_ops->iommu_clk_on(drvdata);
  342. msm_iommu_reset(drvdata->base, drvdata->glb_base, drvdata->ncb);
  343. ret = iommu_sanity_check(drvdata);
  344. if (ret)
  345. goto fail_clk;
  346. msm_iommu_access_ops->iommu_clk_off(drvdata);
  347. pr_info("device %s mapped at %p, with %d ctx banks\n",
  348. drvdata->name, drvdata->base, drvdata->ncb);
  349. msm_iommu_add_drv(drvdata);
  350. platform_set_drvdata(pdev, drvdata);
  351. pmon_info = msm_iommu_pm_alloc(&pdev->dev);
  352. if (pmon_info != NULL) {
  353. ret = msm_iommu_pmon_parse_dt(pdev, pmon_info);
  354. if (ret) {
  355. msm_iommu_pm_free(&pdev->dev);
  356. pr_info("%s: pmon not available.\n", drvdata->name);
  357. } else {
  358. pmon_info->iommu.base = drvdata->base;
  359. pmon_info->iommu.ops = msm_iommu_access_ops;
  360. pmon_info->iommu.hw_ops = iommu_pm_get_hw_ops_v0();
  361. pmon_info->iommu.iommu_name = drvdata->name;
  362. pmon_info->iommu.always_on = 1;
  363. ret = msm_iommu_pm_iommu_register(pmon_info);
  364. if (ret) {
  365. pr_err("%s iommu register fail\n",
  366. drvdata->name);
  367. msm_iommu_pm_free(&pdev->dev);
  368. } else {
  369. pr_debug("%s iommu registered for pmon\n",
  370. pmon_info->iommu.iommu_name);
  371. }
  372. }
  373. }
  374. return 0;
  375. fail_clk:
  376. msm_iommu_access_ops->iommu_clk_off(drvdata);
  377. fail:
  378. __put_bus_vote_client(drvdata);
  379. fail_mem:
  380. return ret;
  381. }
  382. static int msm_iommu_remove(struct platform_device *pdev)
  383. {
  384. struct msm_iommu_drvdata *drv = NULL;
  385. msm_iommu_pm_iommu_unregister(&pdev->dev);
  386. msm_iommu_pm_free(&pdev->dev);
  387. drv = platform_get_drvdata(pdev);
  388. if (drv) {
  389. __put_bus_vote_client(drv);
  390. msm_iommu_remove_drv(drv);
  391. platform_set_drvdata(pdev, NULL);
  392. }
  393. return 0;
  394. }
  395. static int msm_iommu_ctx_parse_dt(struct platform_device *pdev,
  396. struct msm_iommu_ctx_drvdata *ctx_drvdata)
  397. {
  398. struct resource *r, rp;
  399. int irq, ret;
  400. u32 nmid_array_size;
  401. u32 nmid;
  402. irq = platform_get_irq(pdev, 0);
  403. if (irq > 0) {
  404. ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
  405. msm_iommu_fault_handler,
  406. IRQF_ONESHOT | IRQF_SHARED,
  407. "msm_iommu_nonsecure_irq", ctx_drvdata);
  408. if (ret) {
  409. pr_err("Request IRQ %d failed with ret=%d\n", irq, ret);
  410. goto out;
  411. }
  412. }
  413. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  414. if (!r) {
  415. pr_err("Could not find reg property for context bank\n");
  416. ret = -EINVAL;
  417. goto out;
  418. }
  419. ret = of_address_to_resource(pdev->dev.parent->of_node, 0, &rp);
  420. if (ret) {
  421. pr_err("of_address_to_resource failed\n");
  422. ret = -EINVAL;
  423. goto out;
  424. }
  425. /* Calculate the context bank number using the base addresses. CB0
  426. * starts at the base address.
  427. */
  428. ctx_drvdata->num = ((r->start - rp.start) >> CTX_SHIFT);
  429. if (of_property_read_string(pdev->dev.of_node, "label",
  430. &ctx_drvdata->name)) {
  431. pr_err("Could not find label property\n");
  432. ret = -EINVAL;
  433. goto out;
  434. }
  435. if (!of_get_property(pdev->dev.of_node, "qcom,iommu-ctx-mids",
  436. &nmid_array_size)) {
  437. pr_err("Could not find iommu-ctx-mids property\n");
  438. ret = -EINVAL;
  439. goto out;
  440. }
  441. if (nmid_array_size >= sizeof(ctx_drvdata->sids)) {
  442. pr_err("Too many mids defined - array size: %u, mids size: %u\n",
  443. nmid_array_size, sizeof(ctx_drvdata->sids));
  444. ret = -EINVAL;
  445. goto out;
  446. }
  447. nmid = nmid_array_size / sizeof(*ctx_drvdata->sids);
  448. if (of_property_read_u32_array(pdev->dev.of_node, "qcom,iommu-ctx-mids",
  449. ctx_drvdata->sids, nmid)) {
  450. pr_err("Could not find iommu-ctx-mids property\n");
  451. ret = -EINVAL;
  452. goto out;
  453. }
  454. ctx_drvdata->nsid = nmid;
  455. out:
  456. return ret;
  457. }
  458. static void __program_m2v_tables(struct msm_iommu_drvdata *drvdata,
  459. struct msm_iommu_ctx_drvdata *ctx_drvdata)
  460. {
  461. int i;
  462. /* Program the M2V tables for this context */
  463. for (i = 0; i < ctx_drvdata->nsid; i++) {
  464. int sid = ctx_drvdata->sids[i];
  465. int num = ctx_drvdata->num;
  466. SET_M2VCBR_N(drvdata->glb_base, sid, 0);
  467. SET_CBACR_N(drvdata->glb_base, num, 0);
  468. /* Route page faults to the non-secure interrupt */
  469. SET_IRPTNDX(drvdata->glb_base, num, 1);
  470. /* Set VMID = 0 */
  471. SET_VMID(drvdata->glb_base, sid, 0);
  472. /* Set the context number for that SID to this context */
  473. SET_CBNDX(drvdata->glb_base, sid, num);
  474. /* Set SID associated with this context bank to 0 */
  475. SET_CBVMID(drvdata->glb_base, num, 0);
  476. /* Set the ASID for TLB tagging for this context to 0 */
  477. SET_CONTEXTIDR_ASID(drvdata->base, num, 0);
  478. /* Set security bit override to be Non-secure */
  479. SET_NSCFG(drvdata->glb_base, sid, 3);
  480. }
  481. mb();
  482. }
  483. static int msm_iommu_ctx_probe(struct platform_device *pdev)
  484. {
  485. struct msm_iommu_drvdata *drvdata;
  486. struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL;
  487. int i, ret, irq;
  488. if (!pdev->dev.parent) {
  489. ret = -EINVAL;
  490. goto fail;
  491. }
  492. drvdata = dev_get_drvdata(pdev->dev.parent);
  493. if (!drvdata) {
  494. ret = -EPROBE_DEFER;
  495. goto fail;
  496. }
  497. ctx_drvdata = devm_kzalloc(&pdev->dev, sizeof(*ctx_drvdata),
  498. GFP_KERNEL);
  499. if (!ctx_drvdata) {
  500. ret = -ENOMEM;
  501. goto fail;
  502. }
  503. ctx_drvdata->pdev = pdev;
  504. INIT_LIST_HEAD(&ctx_drvdata->attached_elm);
  505. platform_set_drvdata(pdev, ctx_drvdata);
  506. ctx_drvdata->attach_count = 0;
  507. if (pdev->dev.of_node) {
  508. ret = msm_iommu_ctx_parse_dt(pdev, ctx_drvdata);
  509. if (ret) {
  510. platform_set_drvdata(pdev, NULL);
  511. goto fail;
  512. }
  513. } else if (pdev->dev.platform_data) {
  514. struct msm_iommu_ctx_dev *c = pdev->dev.platform_data;
  515. ctx_drvdata->num = c->num;
  516. ctx_drvdata->name = c->name;
  517. for (i = 0; i < MAX_NUM_MIDS; ++i) {
  518. if (c->mids[i] == -1) {
  519. ctx_drvdata->nsid = i;
  520. break;
  521. }
  522. ctx_drvdata->sids[i] = c->mids[i];
  523. }
  524. irq = platform_get_irq_byname(
  525. to_platform_device(pdev->dev.parent),
  526. "nonsecure_irq");
  527. if (irq < 0) {
  528. ret = -ENODEV;
  529. goto fail;
  530. }
  531. ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
  532. msm_iommu_fault_handler,
  533. IRQF_ONESHOT | IRQF_SHARED,
  534. "msm_iommu_nonsecure_irq", ctx_drvdata);
  535. if (ret) {
  536. pr_err("request_threaded_irq %d failed: %d\n", irq,
  537. ret);
  538. goto fail;
  539. }
  540. } else {
  541. ret = -ENODEV;
  542. goto fail;
  543. }
  544. msm_iommu_access_ops->iommu_clk_on(drvdata);
  545. __program_m2v_tables(drvdata, ctx_drvdata);
  546. msm_iommu_access_ops->iommu_clk_off(drvdata);
  547. dev_info(&pdev->dev, "context %s using bank %d\n", ctx_drvdata->name,
  548. ctx_drvdata->num);
  549. return 0;
  550. fail:
  551. return ret;
  552. }
  553. static int __devexit msm_iommu_ctx_remove(struct platform_device *pdev)
  554. {
  555. platform_set_drvdata(pdev, NULL);
  556. return 0;
  557. }
  558. static struct of_device_id msm_iommu_match_table[] = {
  559. { .compatible = "qcom,msm-smmu-v0", },
  560. {}
  561. };
  562. static struct platform_driver msm_iommu_driver = {
  563. .driver = {
  564. .name = "msm_iommu-v0",
  565. .of_match_table = msm_iommu_match_table,
  566. },
  567. .probe = msm_iommu_probe,
  568. .remove = __devexit_p(msm_iommu_remove),
  569. };
  570. static struct of_device_id msm_iommu_v0_ctx_match_table[] = {
  571. { .compatible = "qcom,msm-smmu-v0-ctx", },
  572. {}
  573. };
  574. static struct platform_driver msm_iommu_ctx_driver = {
  575. .driver = {
  576. .name = "msm_iommu_ctx",
  577. .of_match_table = msm_iommu_v0_ctx_match_table,
  578. },
  579. .probe = msm_iommu_ctx_probe,
  580. .remove = __devexit_p(msm_iommu_ctx_remove),
  581. };
  582. static int __init msm_iommu_driver_init(void)
  583. {
  584. int ret;
  585. if (msm_soc_version_supports_iommu_v0()) {
  586. msm_set_iommu_access_ops(&iommu_access_ops_v0);
  587. msm_iommu_access_ops = msm_get_iommu_access_ops();
  588. }
  589. ret = platform_driver_register(&msm_iommu_driver);
  590. if (ret != 0) {
  591. pr_err("Failed to register IOMMU driver\n");
  592. goto error;
  593. }
  594. ret = platform_driver_register(&msm_iommu_ctx_driver);
  595. if (ret != 0) {
  596. pr_err("Failed to register IOMMU context driver\n");
  597. goto error;
  598. }
  599. error:
  600. return ret;
  601. }
  602. static void __exit msm_iommu_driver_exit(void)
  603. {
  604. platform_driver_unregister(&msm_iommu_ctx_driver);
  605. platform_driver_unregister(&msm_iommu_driver);
  606. }
  607. subsys_initcall(msm_iommu_driver_init);
  608. module_exit(msm_iommu_driver_exit);
  609. MODULE_LICENSE("GPL v2");
  610. MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");