1 /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
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.
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.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <linux/list.h>
26 #include <linux/spinlock.h>
27 #include <linux/slab.h>
28 #include <linux/iommu.h>
29 #include <linux/clk.h>
30 #include <linux/err.h>
32 #include <asm/cacheflush.h>
33 #include <asm/sizes.h>
35 #include "msm_iommu_hw-8xxx.h"
36 #include "msm_iommu.h"
38 #define MRC(reg, processor, op1, crn, crm, op2) \
39 __asm__ __volatile__ ( \
40 " mrc " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
43 #define RCP15_PRRR(reg) MRC(reg, p15, 0, c10, c2, 0)
44 #define RCP15_NMRR(reg) MRC(reg, p15, 0, c10, c2, 1)
46 /* bitmap of the page sizes currently supported */
47 #define MSM_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M)
49 static int msm_iommu_tex_class[4];
51 DEFINE_SPINLOCK(msm_iommu_lock);
52 static LIST_HEAD(qcom_iommu_devices);
55 unsigned long *pgtable;
56 struct list_head list_attached;
57 struct iommu_domain domain;
60 static struct msm_priv *to_msm_priv(struct iommu_domain *dom)
62 return container_of(dom, struct msm_priv, domain);
65 static int __enable_clocks(struct msm_iommu_dev *iommu)
69 ret = clk_enable(iommu->pclk);
74 ret = clk_enable(iommu->clk);
76 clk_disable(iommu->pclk);
82 static void __disable_clocks(struct msm_iommu_dev *iommu)
85 clk_disable(iommu->clk);
86 clk_disable(iommu->pclk);
89 static void msm_iommu_reset(void __iomem *base, int ncb)
95 SET_ESRRESTORE(base, 0);
99 SET_TESTBUSCR(base, 0);
101 SET_GLOBAL_TLBIALL(base, 0);
102 SET_RPU_ACR(base, 0);
103 SET_TLBLKCRWE(base, 1);
105 for (ctx = 0; ctx < ncb; ctx++) {
106 SET_BPRCOSH(base, ctx, 0);
107 SET_BPRCISH(base, ctx, 0);
108 SET_BPRCNSH(base, ctx, 0);
109 SET_BPSHCFG(base, ctx, 0);
110 SET_BPMTCFG(base, ctx, 0);
111 SET_ACTLR(base, ctx, 0);
112 SET_SCTLR(base, ctx, 0);
113 SET_FSRRESTORE(base, ctx, 0);
114 SET_TTBR0(base, ctx, 0);
115 SET_TTBR1(base, ctx, 0);
116 SET_TTBCR(base, ctx, 0);
117 SET_BFBCR(base, ctx, 0);
118 SET_PAR(base, ctx, 0);
119 SET_FAR(base, ctx, 0);
120 SET_CTX_TLBIALL(base, ctx, 0);
121 SET_TLBFLPTER(base, ctx, 0);
122 SET_TLBSLPTER(base, ctx, 0);
123 SET_TLBLKCR(base, ctx, 0);
124 SET_PRRR(base, ctx, 0);
125 SET_NMRR(base, ctx, 0);
126 SET_CONTEXTIDR(base, ctx, 0);
130 static int __flush_iotlb(struct iommu_domain *domain)
132 struct msm_priv *priv = to_msm_priv(domain);
133 struct msm_iommu_dev *iommu = NULL;
134 struct msm_iommu_ctx_dev *master;
137 #ifndef CONFIG_IOMMU_PGTABLES_L2
138 unsigned long *fl_table = priv->pgtable;
141 if (!list_empty(&priv->list_attached)) {
142 dmac_flush_range(fl_table, fl_table + SZ_16K);
144 for (i = 0; i < NUM_FL_PTE; i++)
145 if ((fl_table[i] & 0x03) == FL_TYPE_TABLE) {
146 void *sl_table = __va(fl_table[i] &
148 dmac_flush_range(sl_table, sl_table + SZ_4K);
153 list_for_each_entry(iommu, &priv->list_attached, dom_node) {
154 ret = __enable_clocks(iommu);
158 list_for_each_entry(master, &iommu->ctx_list, list)
159 SET_CTX_TLBIALL(iommu->base, master->num, 0);
161 __disable_clocks(iommu);
167 static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end)
172 idx = find_next_zero_bit(map, end, start);
175 } while (test_and_set_bit(idx, map));
180 static void msm_iommu_free_ctx(unsigned long *map, int idx)
185 static void config_mids(struct msm_iommu_dev *iommu,
186 struct msm_iommu_ctx_dev *master)
190 for (i = 0; i < master->num_mids; i++) {
191 mid = master->mids[i];
194 SET_M2VCBR_N(iommu->base, mid, 0);
195 SET_CBACR_N(iommu->base, ctx, 0);
198 SET_VMID(iommu->base, mid, 0);
200 /* Set the context number for that MID to this context */
201 SET_CBNDX(iommu->base, mid, ctx);
203 /* Set MID associated with this context bank to 0*/
204 SET_CBVMID(iommu->base, ctx, 0);
206 /* Set the ASID for TLB tagging for this context */
207 SET_CONTEXTIDR_ASID(iommu->base, ctx, ctx);
209 /* Set security bit override to be Non-secure */
210 SET_NSCFG(iommu->base, mid, 3);
214 static void __reset_context(void __iomem *base, int ctx)
216 SET_BPRCOSH(base, ctx, 0);
217 SET_BPRCISH(base, ctx, 0);
218 SET_BPRCNSH(base, ctx, 0);
219 SET_BPSHCFG(base, ctx, 0);
220 SET_BPMTCFG(base, ctx, 0);
221 SET_ACTLR(base, ctx, 0);
222 SET_SCTLR(base, ctx, 0);
223 SET_FSRRESTORE(base, ctx, 0);
224 SET_TTBR0(base, ctx, 0);
225 SET_TTBR1(base, ctx, 0);
226 SET_TTBCR(base, ctx, 0);
227 SET_BFBCR(base, ctx, 0);
228 SET_PAR(base, ctx, 0);
229 SET_FAR(base, ctx, 0);
230 SET_CTX_TLBIALL(base, ctx, 0);
231 SET_TLBFLPTER(base, ctx, 0);
232 SET_TLBSLPTER(base, ctx, 0);
233 SET_TLBLKCR(base, ctx, 0);
234 SET_PRRR(base, ctx, 0);
235 SET_NMRR(base, ctx, 0);
238 static void __program_context(void __iomem *base, int ctx, phys_addr_t pgtable)
240 unsigned int prrr, nmrr;
241 __reset_context(base, ctx);
243 /* Set up HTW mode */
244 /* TLB miss configuration: perform HTW on miss */
245 SET_TLBMCFG(base, ctx, 0x3);
247 /* V2P configuration: HTW for access */
248 SET_V2PCFG(base, ctx, 0x3);
250 SET_TTBCR(base, ctx, 0);
251 SET_TTBR0_PA(base, ctx, (pgtable >> 14));
253 /* Invalidate the TLB for this context */
254 SET_CTX_TLBIALL(base, ctx, 0);
256 /* Set interrupt number to "secure" interrupt */
257 SET_IRPTNDX(base, ctx, 0);
259 /* Enable context fault interrupt */
260 SET_CFEIE(base, ctx, 1);
262 /* Stall access on a context fault and let the handler deal with it */
263 SET_CFCFG(base, ctx, 1);
265 /* Redirect all cacheable requests to L2 slave port. */
266 SET_RCISH(base, ctx, 1);
267 SET_RCOSH(base, ctx, 1);
268 SET_RCNSH(base, ctx, 1);
270 /* Turn on TEX Remap */
271 SET_TRE(base, ctx, 1);
273 /* Set TEX remap attributes */
276 SET_PRRR(base, ctx, prrr);
277 SET_NMRR(base, ctx, nmrr);
279 /* Turn on BFB prefetch */
280 SET_BFBDFE(base, ctx, 1);
282 #ifdef CONFIG_IOMMU_PGTABLES_L2
283 /* Configure page tables as inner-cacheable and shareable to reduce
284 * the TLB miss penalty.
286 SET_TTBR0_SH(base, ctx, 1);
287 SET_TTBR1_SH(base, ctx, 1);
289 SET_TTBR0_NOS(base, ctx, 1);
290 SET_TTBR1_NOS(base, ctx, 1);
292 SET_TTBR0_IRGNH(base, ctx, 0); /* WB, WA */
293 SET_TTBR0_IRGNL(base, ctx, 1);
295 SET_TTBR1_IRGNH(base, ctx, 0); /* WB, WA */
296 SET_TTBR1_IRGNL(base, ctx, 1);
298 SET_TTBR0_ORGN(base, ctx, 1); /* WB, WA */
299 SET_TTBR1_ORGN(base, ctx, 1); /* WB, WA */
306 static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)
308 struct msm_priv *priv;
310 if (type != IOMMU_DOMAIN_UNMANAGED)
313 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
317 INIT_LIST_HEAD(&priv->list_attached);
318 priv->pgtable = (unsigned long *)__get_free_pages(GFP_KERNEL,
324 memset(priv->pgtable, 0, SZ_16K);
326 priv->domain.geometry.aperture_start = 0;
327 priv->domain.geometry.aperture_end = (1ULL << 32) - 1;
328 priv->domain.geometry.force_aperture = true;
330 return &priv->domain;
337 static void msm_iommu_domain_free(struct iommu_domain *domain)
339 struct msm_priv *priv;
341 unsigned long *fl_table;
344 spin_lock_irqsave(&msm_iommu_lock, flags);
345 priv = to_msm_priv(domain);
347 fl_table = priv->pgtable;
349 for (i = 0; i < NUM_FL_PTE; i++)
350 if ((fl_table[i] & 0x03) == FL_TYPE_TABLE)
351 free_page((unsigned long) __va(((fl_table[i]) &
354 free_pages((unsigned long)priv->pgtable, get_order(SZ_16K));
355 priv->pgtable = NULL;
358 spin_unlock_irqrestore(&msm_iommu_lock, flags);
361 static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
365 struct msm_iommu_dev *iommu;
366 struct msm_priv *priv = to_msm_priv(domain);
367 struct msm_iommu_ctx_dev *master;
369 spin_lock_irqsave(&msm_iommu_lock, flags);
370 list_for_each_entry(iommu, &qcom_iommu_devices, dev_node) {
371 master = list_first_entry(&iommu->ctx_list,
372 struct msm_iommu_ctx_dev,
374 if (master->of_node == dev->of_node) {
375 ret = __enable_clocks(iommu);
379 list_for_each_entry(master, &iommu->ctx_list, list) {
381 dev_err(dev, "domain already attached");
386 msm_iommu_alloc_ctx(iommu->context_map,
388 if (IS_ERR_VALUE(master->num)) {
392 config_mids(iommu, master);
393 __program_context(iommu->base, master->num,
394 __pa(priv->pgtable));
396 __disable_clocks(iommu);
397 list_add(&iommu->dom_node, &priv->list_attached);
401 ret = __flush_iotlb(domain);
403 spin_unlock_irqrestore(&msm_iommu_lock, flags);
408 static void msm_iommu_detach_dev(struct iommu_domain *domain,
411 struct msm_priv *priv = to_msm_priv(domain);
413 struct msm_iommu_dev *iommu;
414 struct msm_iommu_ctx_dev *master;
417 spin_lock_irqsave(&msm_iommu_lock, flags);
418 ret = __flush_iotlb(domain);
422 list_for_each_entry(iommu, &priv->list_attached, dom_node) {
423 ret = __enable_clocks(iommu);
427 list_for_each_entry(master, &iommu->ctx_list, list) {
428 msm_iommu_free_ctx(iommu->context_map, master->num);
429 __reset_context(iommu->base, master->num);
431 __disable_clocks(iommu);
434 spin_unlock_irqrestore(&msm_iommu_lock, flags);
437 static int msm_iommu_map(struct iommu_domain *domain, unsigned long va,
438 phys_addr_t pa, size_t len, int prot)
440 struct msm_priv *priv;
442 unsigned long *fl_table;
443 unsigned long *fl_pte;
444 unsigned long fl_offset;
445 unsigned long *sl_table;
446 unsigned long *sl_pte;
447 unsigned long sl_offset;
449 int ret = 0, tex, sh;
451 spin_lock_irqsave(&msm_iommu_lock, flags);
453 sh = (prot & MSM_IOMMU_ATTR_SH) ? 1 : 0;
454 tex = msm_iommu_tex_class[prot & MSM_IOMMU_CP_MASK];
456 if (tex < 0 || tex > NUM_TEX_CLASS - 1) {
461 priv = to_msm_priv(domain);
463 fl_table = priv->pgtable;
465 if (len != SZ_16M && len != SZ_1M &&
466 len != SZ_64K && len != SZ_4K) {
467 pr_debug("Bad size: %d\n", len);
473 pr_debug("Null page table\n");
478 if (len == SZ_16M || len == SZ_1M) {
479 pgprot = sh ? FL_SHARED : 0;
480 pgprot |= tex & 0x01 ? FL_BUFFERABLE : 0;
481 pgprot |= tex & 0x02 ? FL_CACHEABLE : 0;
482 pgprot |= tex & 0x04 ? FL_TEX0 : 0;
484 pgprot = sh ? SL_SHARED : 0;
485 pgprot |= tex & 0x01 ? SL_BUFFERABLE : 0;
486 pgprot |= tex & 0x02 ? SL_CACHEABLE : 0;
487 pgprot |= tex & 0x04 ? SL_TEX0 : 0;
490 fl_offset = FL_OFFSET(va); /* Upper 12 bits */
491 fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
495 for (i = 0; i < 16; i++)
496 *(fl_pte+i) = (pa & 0xFF000000) | FL_SUPERSECTION |
497 FL_AP_READ | FL_AP_WRITE | FL_TYPE_SECT |
498 FL_SHARED | FL_NG | pgprot;
502 *fl_pte = (pa & 0xFFF00000) | FL_AP_READ | FL_AP_WRITE | FL_NG |
503 FL_TYPE_SECT | FL_SHARED | pgprot;
505 /* Need a 2nd level table */
506 if ((len == SZ_4K || len == SZ_64K) && (*fl_pte) == 0) {
508 sl = (unsigned long *) __get_free_pages(GFP_ATOMIC,
512 pr_debug("Could not allocate second level table\n");
517 memset(sl, 0, SZ_4K);
518 *fl_pte = ((((int)__pa(sl)) & FL_BASE_MASK) | FL_TYPE_TABLE);
521 sl_table = (unsigned long *) __va(((*fl_pte) & FL_BASE_MASK));
522 sl_offset = SL_OFFSET(va);
523 sl_pte = sl_table + sl_offset;
527 *sl_pte = (pa & SL_BASE_MASK_SMALL) | SL_AP0 | SL_AP1 | SL_NG |
528 SL_SHARED | SL_TYPE_SMALL | pgprot;
533 for (i = 0; i < 16; i++)
534 *(sl_pte+i) = (pa & SL_BASE_MASK_LARGE) | SL_AP0 |
535 SL_NG | SL_AP1 | SL_SHARED | SL_TYPE_LARGE | pgprot;
538 ret = __flush_iotlb(domain);
540 spin_unlock_irqrestore(&msm_iommu_lock, flags);
544 static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long va,
547 struct msm_priv *priv;
549 unsigned long *fl_table;
550 unsigned long *fl_pte;
551 unsigned long fl_offset;
552 unsigned long *sl_table;
553 unsigned long *sl_pte;
554 unsigned long sl_offset;
557 spin_lock_irqsave(&msm_iommu_lock, flags);
559 priv = to_msm_priv(domain);
561 fl_table = priv->pgtable;
563 if (len != SZ_16M && len != SZ_1M &&
564 len != SZ_64K && len != SZ_4K) {
565 pr_debug("Bad length: %d\n", len);
570 pr_debug("Null page table\n");
574 fl_offset = FL_OFFSET(va); /* Upper 12 bits */
575 fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
578 pr_debug("First level PTE is 0\n");
582 /* Unmap supersection */
584 for (i = 0; i < 16; i++)
590 sl_table = (unsigned long *) __va(((*fl_pte) & FL_BASE_MASK));
591 sl_offset = SL_OFFSET(va);
592 sl_pte = sl_table + sl_offset;
595 for (i = 0; i < 16; i++)
602 if (len == SZ_4K || len == SZ_64K) {
605 for (i = 0; i < NUM_SL_PTE; i++)
609 free_page((unsigned long)sl_table);
614 ret = __flush_iotlb(domain);
617 spin_unlock_irqrestore(&msm_iommu_lock, flags);
619 /* the IOMMU API requires us to return how many bytes were unmapped */
624 static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
627 struct msm_priv *priv;
628 struct msm_iommu_dev *iommu;
629 struct msm_iommu_ctx_dev *master;
634 spin_lock_irqsave(&msm_iommu_lock, flags);
636 priv = to_msm_priv(domain);
637 iommu = list_first_entry(&priv->list_attached,
638 struct msm_iommu_dev, dom_node);
640 if (list_empty(&iommu->ctx_list))
643 master = list_first_entry(&iommu->ctx_list,
644 struct msm_iommu_ctx_dev, list);
648 ret = __enable_clocks(iommu);
652 /* Invalidate context TLB */
653 SET_CTX_TLBIALL(iommu->base, master->num, 0);
654 SET_V2PPR(iommu->base, master->num, va & V2Pxx_VA);
656 par = GET_PAR(iommu->base, master->num);
658 /* We are dealing with a supersection */
659 if (GET_NOFAULT_SS(iommu->base, master->num))
660 ret = (par & 0xFF000000) | (va & 0x00FFFFFF);
661 else /* Upper 20 bits from PAR, lower 12 from VA */
662 ret = (par & 0xFFFFF000) | (va & 0x00000FFF);
664 if (GET_FAULT(iommu->base, master->num))
667 __disable_clocks(iommu);
669 spin_unlock_irqrestore(&msm_iommu_lock, flags);
673 static bool msm_iommu_capable(enum iommu_cap cap)
678 static void print_ctx_regs(void __iomem *base, int ctx)
680 unsigned int fsr = GET_FSR(base, ctx);
681 pr_err("FAR = %08x PAR = %08x\n",
682 GET_FAR(base, ctx), GET_PAR(base, ctx));
683 pr_err("FSR = %08x [%s%s%s%s%s%s%s%s%s%s]\n", fsr,
684 (fsr & 0x02) ? "TF " : "",
685 (fsr & 0x04) ? "AFF " : "",
686 (fsr & 0x08) ? "APF " : "",
687 (fsr & 0x10) ? "TLBMF " : "",
688 (fsr & 0x20) ? "HTWDEEF " : "",
689 (fsr & 0x40) ? "HTWSEEF " : "",
690 (fsr & 0x80) ? "MHF " : "",
691 (fsr & 0x10000) ? "SL " : "",
692 (fsr & 0x40000000) ? "SS " : "",
693 (fsr & 0x80000000) ? "MULTI " : "");
695 pr_err("FSYNR0 = %08x FSYNR1 = %08x\n",
696 GET_FSYNR0(base, ctx), GET_FSYNR1(base, ctx));
697 pr_err("TTBR0 = %08x TTBR1 = %08x\n",
698 GET_TTBR0(base, ctx), GET_TTBR1(base, ctx));
699 pr_err("SCTLR = %08x ACTLR = %08x\n",
700 GET_SCTLR(base, ctx), GET_ACTLR(base, ctx));
701 pr_err("PRRR = %08x NMRR = %08x\n",
702 GET_PRRR(base, ctx), GET_NMRR(base, ctx));
705 irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
707 struct msm_iommu_dev *iommu = dev_id;
711 spin_lock(&msm_iommu_lock);
714 pr_err("Invalid device ID in context interrupt handler\n");
718 pr_err("Unexpected IOMMU page fault!\n");
719 pr_err("base = %08x\n", (unsigned int)iommu->base);
721 ret = __enable_clocks(iommu);
725 for (i = 0; i < iommu->ncb; i++) {
726 fsr = GET_FSR(iommu->base, i);
728 pr_err("Fault occurred in context %d.\n", i);
729 pr_err("Interesting registers:\n");
730 print_ctx_regs(iommu->base, i);
731 SET_FSR(iommu->base, i, 0x4000000F);
734 __disable_clocks(iommu);
736 spin_unlock(&msm_iommu_lock);
740 static const struct iommu_ops msm_iommu_ops = {
741 .capable = msm_iommu_capable,
742 .domain_alloc = msm_iommu_domain_alloc,
743 .domain_free = msm_iommu_domain_free,
744 .attach_dev = msm_iommu_attach_dev,
745 .detach_dev = msm_iommu_detach_dev,
746 .map = msm_iommu_map,
747 .unmap = msm_iommu_unmap,
748 .map_sg = default_iommu_map_sg,
749 .iova_to_phys = msm_iommu_iova_to_phys,
750 .pgsize_bitmap = MSM_IOMMU_PGSIZES,
753 static int msm_iommu_probe(struct platform_device *pdev)
756 struct msm_iommu_dev *iommu;
759 iommu = devm_kzalloc(&pdev->dev, sizeof(*iommu), GFP_KERNEL);
763 iommu->dev = &pdev->dev;
764 INIT_LIST_HEAD(&iommu->ctx_list);
766 iommu->pclk = devm_clk_get(iommu->dev, "smmu_pclk");
767 if (IS_ERR(iommu->pclk)) {
768 dev_err(iommu->dev, "could not get smmu_pclk\n");
769 return PTR_ERR(iommu->pclk);
772 ret = clk_prepare(iommu->pclk);
774 dev_err(iommu->dev, "could not prepare smmu_pclk\n");
778 iommu->clk = devm_clk_get(iommu->dev, "iommu_clk");
779 if (IS_ERR(iommu->clk)) {
780 dev_err(iommu->dev, "could not get iommu_clk\n");
781 clk_unprepare(iommu->pclk);
782 return PTR_ERR(iommu->clk);
785 ret = clk_prepare(iommu->clk);
787 dev_err(iommu->dev, "could not prepare iommu_clk\n");
788 clk_unprepare(iommu->pclk);
792 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
793 iommu->base = devm_ioremap_resource(iommu->dev, r);
794 if (IS_ERR(iommu->base)) {
795 dev_err(iommu->dev, "could not get iommu base\n");
796 ret = PTR_ERR(iommu->base);
800 iommu->irq = platform_get_irq(pdev, 0);
801 if (iommu->irq < 0) {
802 dev_err(iommu->dev, "could not get iommu irq\n");
807 ret = of_property_read_u32(iommu->dev->of_node, "qcom,ncb", &val);
809 dev_err(iommu->dev, "could not get ncb\n");
814 msm_iommu_reset(iommu->base, iommu->ncb);
815 SET_M(iommu->base, 0, 1);
816 SET_PAR(iommu->base, 0, 0);
817 SET_V2PCFG(iommu->base, 0, 1);
818 SET_V2PPR(iommu->base, 0, 0);
819 par = GET_PAR(iommu->base, 0);
820 SET_V2PCFG(iommu->base, 0, 0);
821 SET_M(iommu->base, 0, 0);
824 pr_err("Invalid PAR value detected\n");
829 ret = devm_request_threaded_irq(iommu->dev, iommu->irq, NULL,
830 msm_iommu_fault_handler,
831 IRQF_ONESHOT | IRQF_SHARED,
832 "msm_iommu_secure_irpt_handler",
835 pr_err("Request IRQ %d failed with ret=%d\n", iommu->irq, ret);
839 list_add(&iommu->dev_node, &qcom_iommu_devices);
841 pr_info("device mapped at %p, irq %d with %d ctx banks\n",
842 iommu->base, iommu->irq, iommu->ncb);
846 clk_unprepare(iommu->clk);
847 clk_unprepare(iommu->pclk);
851 static const struct of_device_id msm_iommu_dt_match[] = {
852 { .compatible = "qcom,apq8064-iommu" },
856 static int msm_iommu_remove(struct platform_device *pdev)
858 struct msm_iommu_dev *iommu = platform_get_drvdata(pdev);
860 clk_unprepare(iommu->clk);
861 clk_unprepare(iommu->pclk);
865 static struct platform_driver msm_iommu_driver = {
868 .of_match_table = msm_iommu_dt_match,
870 .probe = msm_iommu_probe,
871 .remove = msm_iommu_remove,
874 static int __init msm_iommu_driver_init(void)
878 ret = platform_driver_register(&msm_iommu_driver);
880 pr_err("Failed to register IOMMU driver\n");
885 static void __exit msm_iommu_driver_exit(void)
887 platform_driver_unregister(&msm_iommu_driver);
890 subsys_initcall(msm_iommu_driver_init);
891 module_exit(msm_iommu_driver_exit);
893 static int __init get_tex_class(int icp, int ocp, int mt, int nos)
896 unsigned int prrr = 0;
897 unsigned int nmrr = 0;
898 int c_icp, c_ocp, c_mt, c_nos;
903 for (i = 0; i < NUM_TEX_CLASS; i++) {
904 c_nos = PRRR_NOS(prrr, i);
905 c_mt = PRRR_MT(prrr, i);
906 c_icp = NMRR_ICP(nmrr, i);
907 c_ocp = NMRR_OCP(nmrr, i);
909 if (icp == c_icp && ocp == c_ocp && c_mt == mt && c_nos == nos)
916 static void __init setup_iommu_tex_classes(void)
918 msm_iommu_tex_class[MSM_IOMMU_ATTR_NONCACHED] =
919 get_tex_class(CP_NONCACHED, CP_NONCACHED, MT_NORMAL, 1);
921 msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WB_WA] =
922 get_tex_class(CP_WB_WA, CP_WB_WA, MT_NORMAL, 1);
924 msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WB_NWA] =
925 get_tex_class(CP_WB_NWA, CP_WB_NWA, MT_NORMAL, 1);
927 msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WT] =
928 get_tex_class(CP_WT, CP_WT, MT_NORMAL, 1);
931 static int __init msm_iommu_init(void)
933 setup_iommu_tex_classes();
934 bus_set_iommu(&platform_bus_type, &msm_iommu_ops);
938 subsys_initcall(msm_iommu_init);
940 MODULE_LICENSE("GPL v2");
941 MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");