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 #include <linux/kernel.h>
19 #include <linux/platform_device.h>
20 #include <linux/bootmem.h>
21 #include <mach/irqs.h>
22 #include <mach/iommu.h>
24 static struct resource msm_iommu_jpegd_resources[] = {
27 .end = 0x07300000 + SZ_1M - 1,
29 .flags = IORESOURCE_MEM,
32 .name = "nonsecure_irq",
33 .start = SMMU_JPEGD_CB_SC_NON_SECURE_IRQ,
34 .end = SMMU_JPEGD_CB_SC_NON_SECURE_IRQ,
35 .flags = IORESOURCE_IRQ,
39 .start = SMMU_JPEGD_CB_SC_SECURE_IRQ,
40 .end = SMMU_JPEGD_CB_SC_SECURE_IRQ,
41 .flags = IORESOURCE_IRQ,
45 static struct resource msm_iommu_vpe_resources[] = {
48 .end = 0x07400000 + SZ_1M - 1,
50 .flags = IORESOURCE_MEM,
53 .name = "nonsecure_irq",
54 .start = SMMU_VPE_CB_SC_NON_SECURE_IRQ,
55 .end = SMMU_VPE_CB_SC_NON_SECURE_IRQ,
56 .flags = IORESOURCE_IRQ,
60 .start = SMMU_VPE_CB_SC_SECURE_IRQ,
61 .end = SMMU_VPE_CB_SC_SECURE_IRQ,
62 .flags = IORESOURCE_IRQ,
66 static struct resource msm_iommu_mdp0_resources[] = {
69 .end = 0x07500000 + SZ_1M - 1,
71 .flags = IORESOURCE_MEM,
74 .name = "nonsecure_irq",
75 .start = SMMU_MDP0_CB_SC_NON_SECURE_IRQ,
76 .end = SMMU_MDP0_CB_SC_NON_SECURE_IRQ,
77 .flags = IORESOURCE_IRQ,
81 .start = SMMU_MDP0_CB_SC_SECURE_IRQ,
82 .end = SMMU_MDP0_CB_SC_SECURE_IRQ,
83 .flags = IORESOURCE_IRQ,
87 static struct resource msm_iommu_mdp1_resources[] = {
90 .end = 0x07600000 + SZ_1M - 1,
92 .flags = IORESOURCE_MEM,
95 .name = "nonsecure_irq",
96 .start = SMMU_MDP1_CB_SC_NON_SECURE_IRQ,
97 .end = SMMU_MDP1_CB_SC_NON_SECURE_IRQ,
98 .flags = IORESOURCE_IRQ,
101 .name = "secure_irq",
102 .start = SMMU_MDP1_CB_SC_SECURE_IRQ,
103 .end = SMMU_MDP1_CB_SC_SECURE_IRQ,
104 .flags = IORESOURCE_IRQ,
108 static struct resource msm_iommu_rot_resources[] = {
111 .end = 0x07700000 + SZ_1M - 1,
113 .flags = IORESOURCE_MEM,
116 .name = "nonsecure_irq",
117 .start = SMMU_ROT_CB_SC_NON_SECURE_IRQ,
118 .end = SMMU_ROT_CB_SC_NON_SECURE_IRQ,
119 .flags = IORESOURCE_IRQ,
122 .name = "secure_irq",
123 .start = SMMU_ROT_CB_SC_SECURE_IRQ,
124 .end = SMMU_ROT_CB_SC_SECURE_IRQ,
125 .flags = IORESOURCE_IRQ,
129 static struct resource msm_iommu_ijpeg_resources[] = {
132 .end = 0x07800000 + SZ_1M - 1,
134 .flags = IORESOURCE_MEM,
137 .name = "nonsecure_irq",
138 .start = SMMU_IJPEG_CB_SC_NON_SECURE_IRQ,
139 .end = SMMU_IJPEG_CB_SC_NON_SECURE_IRQ,
140 .flags = IORESOURCE_IRQ,
143 .name = "secure_irq",
144 .start = SMMU_IJPEG_CB_SC_SECURE_IRQ,
145 .end = SMMU_IJPEG_CB_SC_SECURE_IRQ,
146 .flags = IORESOURCE_IRQ,
150 static struct resource msm_iommu_vfe_resources[] = {
153 .end = 0x07900000 + SZ_1M - 1,
155 .flags = IORESOURCE_MEM,
158 .name = "nonsecure_irq",
159 .start = SMMU_VFE_CB_SC_NON_SECURE_IRQ,
160 .end = SMMU_VFE_CB_SC_NON_SECURE_IRQ,
161 .flags = IORESOURCE_IRQ,
164 .name = "secure_irq",
165 .start = SMMU_VFE_CB_SC_SECURE_IRQ,
166 .end = SMMU_VFE_CB_SC_SECURE_IRQ,
167 .flags = IORESOURCE_IRQ,
171 static struct resource msm_iommu_vcodec_a_resources[] = {
174 .end = 0x07A00000 + SZ_1M - 1,
176 .flags = IORESOURCE_MEM,
179 .name = "nonsecure_irq",
180 .start = SMMU_VCODEC_A_CB_SC_NON_SECURE_IRQ,
181 .end = SMMU_VCODEC_A_CB_SC_NON_SECURE_IRQ,
182 .flags = IORESOURCE_IRQ,
185 .name = "secure_irq",
186 .start = SMMU_VCODEC_A_CB_SC_SECURE_IRQ,
187 .end = SMMU_VCODEC_A_CB_SC_SECURE_IRQ,
188 .flags = IORESOURCE_IRQ,
192 static struct resource msm_iommu_vcodec_b_resources[] = {
195 .end = 0x07B00000 + SZ_1M - 1,
197 .flags = IORESOURCE_MEM,
200 .name = "nonsecure_irq",
201 .start = SMMU_VCODEC_B_CB_SC_NON_SECURE_IRQ,
202 .end = SMMU_VCODEC_B_CB_SC_NON_SECURE_IRQ,
203 .flags = IORESOURCE_IRQ,
206 .name = "secure_irq",
207 .start = SMMU_VCODEC_B_CB_SC_SECURE_IRQ,
208 .end = SMMU_VCODEC_B_CB_SC_SECURE_IRQ,
209 .flags = IORESOURCE_IRQ,
213 static struct resource msm_iommu_gfx3d_resources[] = {
216 .end = 0x07C00000 + SZ_1M - 1,
218 .flags = IORESOURCE_MEM,
221 .name = "nonsecure_irq",
222 .start = SMMU_GFX3D_CB_SC_NON_SECURE_IRQ,
223 .end = SMMU_GFX3D_CB_SC_NON_SECURE_IRQ,
224 .flags = IORESOURCE_IRQ,
227 .name = "secure_irq",
228 .start = SMMU_GFX3D_CB_SC_SECURE_IRQ,
229 .end = SMMU_GFX3D_CB_SC_SECURE_IRQ,
230 .flags = IORESOURCE_IRQ,
234 static struct resource msm_iommu_gfx2d0_resources[] = {
237 .end = 0x07D00000 + SZ_1M - 1,
239 .flags = IORESOURCE_MEM,
242 .name = "nonsecure_irq",
243 .start = SMMU_GFX2D0_CB_SC_NON_SECURE_IRQ,
244 .end = SMMU_GFX2D0_CB_SC_NON_SECURE_IRQ,
245 .flags = IORESOURCE_IRQ,
248 .name = "secure_irq",
249 .start = SMMU_GFX2D0_CB_SC_SECURE_IRQ,
250 .end = SMMU_GFX2D0_CB_SC_SECURE_IRQ,
251 .flags = IORESOURCE_IRQ,
255 static struct resource msm_iommu_gfx2d1_resources[] = {
258 .end = 0x07E00000 + SZ_1M - 1,
260 .flags = IORESOURCE_MEM,
263 .name = "nonsecure_irq",
264 .start = SMMU_GFX2D1_CB_SC_NON_SECURE_IRQ,
265 .end = SMMU_GFX2D1_CB_SC_NON_SECURE_IRQ,
266 .flags = IORESOURCE_IRQ,
269 .name = "secure_irq",
270 .start = SMMU_GFX2D1_CB_SC_SECURE_IRQ,
271 .end = SMMU_GFX2D1_CB_SC_SECURE_IRQ,
272 .flags = IORESOURCE_IRQ,
276 static struct platform_device msm_root_iommu_dev = {
281 static struct msm_iommu_dev jpegd_iommu = {
286 static struct msm_iommu_dev vpe_iommu = {
290 static struct msm_iommu_dev mdp0_iommu = {
294 static struct msm_iommu_dev mdp1_iommu = {
298 static struct msm_iommu_dev rot_iommu = {
302 static struct msm_iommu_dev ijpeg_iommu = {
306 static struct msm_iommu_dev vfe_iommu = {
311 static struct msm_iommu_dev vcodec_a_iommu = {
315 static struct msm_iommu_dev vcodec_b_iommu = {
319 static struct msm_iommu_dev gfx3d_iommu = {
324 static struct msm_iommu_dev gfx2d0_iommu = {
329 static struct msm_iommu_dev gfx2d1_iommu = {
334 static struct platform_device msm_device_iommu_jpegd = {
338 .parent = &msm_root_iommu_dev.dev,
340 .num_resources = ARRAY_SIZE(msm_iommu_jpegd_resources),
341 .resource = msm_iommu_jpegd_resources,
344 static struct platform_device msm_device_iommu_vpe = {
348 .parent = &msm_root_iommu_dev.dev,
350 .num_resources = ARRAY_SIZE(msm_iommu_vpe_resources),
351 .resource = msm_iommu_vpe_resources,
354 static struct platform_device msm_device_iommu_mdp0 = {
358 .parent = &msm_root_iommu_dev.dev,
360 .num_resources = ARRAY_SIZE(msm_iommu_mdp0_resources),
361 .resource = msm_iommu_mdp0_resources,
364 static struct platform_device msm_device_iommu_mdp1 = {
368 .parent = &msm_root_iommu_dev.dev,
370 .num_resources = ARRAY_SIZE(msm_iommu_mdp1_resources),
371 .resource = msm_iommu_mdp1_resources,
374 static struct platform_device msm_device_iommu_rot = {
378 .parent = &msm_root_iommu_dev.dev,
380 .num_resources = ARRAY_SIZE(msm_iommu_rot_resources),
381 .resource = msm_iommu_rot_resources,
384 static struct platform_device msm_device_iommu_ijpeg = {
388 .parent = &msm_root_iommu_dev.dev,
390 .num_resources = ARRAY_SIZE(msm_iommu_ijpeg_resources),
391 .resource = msm_iommu_ijpeg_resources,
394 static struct platform_device msm_device_iommu_vfe = {
398 .parent = &msm_root_iommu_dev.dev,
400 .num_resources = ARRAY_SIZE(msm_iommu_vfe_resources),
401 .resource = msm_iommu_vfe_resources,
404 static struct platform_device msm_device_iommu_vcodec_a = {
408 .parent = &msm_root_iommu_dev.dev,
410 .num_resources = ARRAY_SIZE(msm_iommu_vcodec_a_resources),
411 .resource = msm_iommu_vcodec_a_resources,
414 static struct platform_device msm_device_iommu_vcodec_b = {
418 .parent = &msm_root_iommu_dev.dev,
420 .num_resources = ARRAY_SIZE(msm_iommu_vcodec_b_resources),
421 .resource = msm_iommu_vcodec_b_resources,
424 static struct platform_device msm_device_iommu_gfx3d = {
428 .parent = &msm_root_iommu_dev.dev,
430 .num_resources = ARRAY_SIZE(msm_iommu_gfx3d_resources),
431 .resource = msm_iommu_gfx3d_resources,
434 static struct platform_device msm_device_iommu_gfx2d0 = {
438 .parent = &msm_root_iommu_dev.dev,
440 .num_resources = ARRAY_SIZE(msm_iommu_gfx2d0_resources),
441 .resource = msm_iommu_gfx2d0_resources,
444 struct platform_device msm_device_iommu_gfx2d1 = {
448 .parent = &msm_root_iommu_dev.dev,
450 .num_resources = ARRAY_SIZE(msm_iommu_gfx2d1_resources),
451 .resource = msm_iommu_gfx2d1_resources,
454 static struct msm_iommu_ctx_dev jpegd_src_ctx = {
460 static struct msm_iommu_ctx_dev jpegd_dst_ctx = {
466 static struct msm_iommu_ctx_dev vpe_src_ctx = {
472 static struct msm_iommu_ctx_dev vpe_dst_ctx = {
478 static struct msm_iommu_ctx_dev mdp_vg1_ctx = {
484 static struct msm_iommu_ctx_dev mdp_rgb1_ctx = {
487 .mids = {1, 3, 4, 5, 6, 7, 8, 9, 10, -1}
490 static struct msm_iommu_ctx_dev mdp_vg2_ctx = {
496 static struct msm_iommu_ctx_dev mdp_rgb2_ctx = {
499 .mids = {1, 3, 4, 5, 6, 7, 8, 9, 10, -1}
502 static struct msm_iommu_ctx_dev rot_src_ctx = {
508 static struct msm_iommu_ctx_dev rot_dst_ctx = {
514 static struct msm_iommu_ctx_dev ijpeg_src_ctx = {
520 static struct msm_iommu_ctx_dev ijpeg_dst_ctx = {
526 static struct msm_iommu_ctx_dev vfe_imgwr_ctx = {
529 .mids = {2, 3, 4, 5, 6, 7, 8, -1}
532 static struct msm_iommu_ctx_dev vfe_misc_ctx = {
535 .mids = {0, 1, 9, -1}
538 static struct msm_iommu_ctx_dev vcodec_a_stream_ctx = {
539 .name = "vcodec_a_stream",
544 static struct msm_iommu_ctx_dev vcodec_a_mm1_ctx = {
545 .name = "vcodec_a_mm1",
547 .mids = {0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}
550 static struct msm_iommu_ctx_dev vcodec_b_mm2_ctx = {
551 .name = "vcodec_b_mm2",
553 .mids = {0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}
556 static struct msm_iommu_ctx_dev gfx3d_user_ctx = {
557 .name = "gfx3d_user",
559 .mids = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1}
562 static struct msm_iommu_ctx_dev gfx3d_priv_ctx = {
563 .name = "gfx3d_priv",
565 .mids = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
569 static struct msm_iommu_ctx_dev gfx2d0_2d0_ctx = {
570 .name = "gfx2d0_2d0",
572 .mids = {0, 1, 2, 3, 4, 5, 6, 7, -1}
575 static struct msm_iommu_ctx_dev gfx2d1_2d1_ctx = {
576 .name = "gfx2d1_2d1",
578 .mids = {0, 1, 2, 3, 4, 5, 6, 7, -1}
581 static struct platform_device msm_device_jpegd_src_ctx = {
582 .name = "msm_iommu_ctx",
585 .parent = &msm_device_iommu_jpegd.dev,
589 static struct platform_device msm_device_jpegd_dst_ctx = {
590 .name = "msm_iommu_ctx",
593 .parent = &msm_device_iommu_jpegd.dev,
597 static struct platform_device msm_device_vpe_src_ctx = {
598 .name = "msm_iommu_ctx",
601 .parent = &msm_device_iommu_vpe.dev,
605 static struct platform_device msm_device_vpe_dst_ctx = {
606 .name = "msm_iommu_ctx",
609 .parent = &msm_device_iommu_vpe.dev,
613 static struct platform_device msm_device_mdp_vg1_ctx = {
614 .name = "msm_iommu_ctx",
617 .parent = &msm_device_iommu_mdp0.dev,
621 static struct platform_device msm_device_mdp_rgb1_ctx = {
622 .name = "msm_iommu_ctx",
625 .parent = &msm_device_iommu_mdp0.dev,
629 static struct platform_device msm_device_mdp_vg2_ctx = {
630 .name = "msm_iommu_ctx",
633 .parent = &msm_device_iommu_mdp1.dev,
637 static struct platform_device msm_device_mdp_rgb2_ctx = {
638 .name = "msm_iommu_ctx",
641 .parent = &msm_device_iommu_mdp1.dev,
645 static struct platform_device msm_device_rot_src_ctx = {
646 .name = "msm_iommu_ctx",
649 .parent = &msm_device_iommu_rot.dev,
653 static struct platform_device msm_device_rot_dst_ctx = {
654 .name = "msm_iommu_ctx",
657 .parent = &msm_device_iommu_rot.dev,
661 static struct platform_device msm_device_ijpeg_src_ctx = {
662 .name = "msm_iommu_ctx",
665 .parent = &msm_device_iommu_ijpeg.dev,
669 static struct platform_device msm_device_ijpeg_dst_ctx = {
670 .name = "msm_iommu_ctx",
673 .parent = &msm_device_iommu_ijpeg.dev,
677 static struct platform_device msm_device_vfe_imgwr_ctx = {
678 .name = "msm_iommu_ctx",
681 .parent = &msm_device_iommu_vfe.dev,
685 static struct platform_device msm_device_vfe_misc_ctx = {
686 .name = "msm_iommu_ctx",
689 .parent = &msm_device_iommu_vfe.dev,
693 static struct platform_device msm_device_vcodec_a_stream_ctx = {
694 .name = "msm_iommu_ctx",
697 .parent = &msm_device_iommu_vcodec_a.dev,
701 static struct platform_device msm_device_vcodec_a_mm1_ctx = {
702 .name = "msm_iommu_ctx",
705 .parent = &msm_device_iommu_vcodec_a.dev,
709 static struct platform_device msm_device_vcodec_b_mm2_ctx = {
710 .name = "msm_iommu_ctx",
713 .parent = &msm_device_iommu_vcodec_b.dev,
717 static struct platform_device msm_device_gfx3d_user_ctx = {
718 .name = "msm_iommu_ctx",
721 .parent = &msm_device_iommu_gfx3d.dev,
725 static struct platform_device msm_device_gfx3d_priv_ctx = {
726 .name = "msm_iommu_ctx",
729 .parent = &msm_device_iommu_gfx3d.dev,
733 static struct platform_device msm_device_gfx2d0_2d0_ctx = {
734 .name = "msm_iommu_ctx",
737 .parent = &msm_device_iommu_gfx2d0.dev,
741 static struct platform_device msm_device_gfx2d1_2d1_ctx = {
742 .name = "msm_iommu_ctx",
745 .parent = &msm_device_iommu_gfx2d1.dev,
749 static struct platform_device *msm_iommu_devs[] = {
750 &msm_device_iommu_jpegd,
751 &msm_device_iommu_vpe,
752 &msm_device_iommu_mdp0,
753 &msm_device_iommu_mdp1,
754 &msm_device_iommu_rot,
755 &msm_device_iommu_ijpeg,
756 &msm_device_iommu_vfe,
757 &msm_device_iommu_vcodec_a,
758 &msm_device_iommu_vcodec_b,
759 &msm_device_iommu_gfx3d,
760 &msm_device_iommu_gfx2d0,
761 &msm_device_iommu_gfx2d1,
764 static struct msm_iommu_dev *msm_iommu_data[] = {
779 static struct platform_device *msm_iommu_ctx_devs[] = {
780 &msm_device_jpegd_src_ctx,
781 &msm_device_jpegd_dst_ctx,
782 &msm_device_vpe_src_ctx,
783 &msm_device_vpe_dst_ctx,
784 &msm_device_mdp_vg1_ctx,
785 &msm_device_mdp_rgb1_ctx,
786 &msm_device_mdp_vg2_ctx,
787 &msm_device_mdp_rgb2_ctx,
788 &msm_device_rot_src_ctx,
789 &msm_device_rot_dst_ctx,
790 &msm_device_ijpeg_src_ctx,
791 &msm_device_ijpeg_dst_ctx,
792 &msm_device_vfe_imgwr_ctx,
793 &msm_device_vfe_misc_ctx,
794 &msm_device_vcodec_a_stream_ctx,
795 &msm_device_vcodec_a_mm1_ctx,
796 &msm_device_vcodec_b_mm2_ctx,
797 &msm_device_gfx3d_user_ctx,
798 &msm_device_gfx3d_priv_ctx,
799 &msm_device_gfx2d0_2d0_ctx,
800 &msm_device_gfx2d1_2d1_ctx,
803 static struct msm_iommu_ctx_dev *msm_iommu_ctx_data[] = {
818 &vcodec_a_stream_ctx,
827 static int __init msm8x60_iommu_init(void)
831 ret = platform_device_register(&msm_root_iommu_dev);
833 pr_err("Failed to register root IOMMU device!\n");
837 for (i = 0; i < ARRAY_SIZE(msm_iommu_devs); i++) {
838 ret = platform_device_add_data(msm_iommu_devs[i],
840 sizeof(struct msm_iommu_dev));
842 pr_err("platform_device_add_data failed, "
847 ret = platform_device_register(msm_iommu_devs[i]);
850 pr_err("platform_device_register iommu failed, "
856 for (i = 0; i < ARRAY_SIZE(msm_iommu_ctx_devs); i++) {
857 ret = platform_device_add_data(msm_iommu_ctx_devs[i],
858 msm_iommu_ctx_data[i],
859 sizeof(*msm_iommu_ctx_devs[i]));
861 pr_err("platform_device_add_data iommu failed, "
863 goto failure_unwind2;
866 ret = platform_device_register(msm_iommu_ctx_devs[i]);
868 pr_err("platform_device_register ctx failed, "
870 goto failure_unwind2;
877 platform_device_unregister(msm_iommu_ctx_devs[i]);
880 platform_device_unregister(msm_iommu_devs[i]);
882 platform_device_unregister(&msm_root_iommu_dev);
887 static void __exit msm8x60_iommu_exit(void)
891 for (i = 0; i < ARRAY_SIZE(msm_iommu_ctx_devs); i++)
892 platform_device_unregister(msm_iommu_ctx_devs[i]);
894 for (i = 0; i < ARRAY_SIZE(msm_iommu_devs); ++i)
895 platform_device_unregister(msm_iommu_devs[i]);
897 platform_device_unregister(&msm_root_iommu_dev);
900 subsys_initcall(msm8x60_iommu_init);
901 module_exit(msm8x60_iommu_exit);
903 MODULE_LICENSE("GPL v2");
904 MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");