Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
516cbc7
Documentation
arch
alpha
arm
boot
common
configs
include
kernel
lib
mach-aaec2000
mach-at91
mach-bcmring
mach-clps711x
mach-cns3xxx
mach-davinci
mach-dove
mach-ebsa110
mach-ep93xx
mach-footbridge
mach-gemini
mach-h720x
mach-imx
mach-integrator
mach-iop13xx
mach-iop32x
mach-iop33x
mach-ixp2000
mach-ixp23xx
mach-ixp4xx
mach-kirkwood
mach-ks8695
mach-l7200
mach-lh7a40x
mach-loki
mach-lpc32xx
mach-mmp
mach-msm
include
Kconfig
Makefile
Makefile.boot
acpuclock-arm11.c
acpuclock.h
board-halibut.c
board-mahimahi.c
board-msm7x27.c
board-msm7x30.c
board-msm8x60.c
board-qsd8x50.c
board-sapphire.c
board-trout-gpio.c
board-trout-mmc.c
board-trout.c
board-trout.h
clock-7x30.h
clock-dummy.c
clock-pcom.c
clock-pcom.h
clock.c
clock.h
devices-msm7x00.c
devices-msm7x30.c
devices-msm8x60-iommu.c
devices-qsd8x50.c
devices.h
dma.c
gpio-v2.c
gpio.c
gpio_hw.h
gpiomux-7x30.c
gpiomux-8x50.c
gpiomux-8x60.c
gpiomux-v1.c
gpiomux-v1.h
gpiomux-v2.c
gpiomux-v2.h
gpiomux.c
gpiomux.h
idle.S
io.c
iommu.c
iommu_dev.c
irq-vic.c
irq.c
last_radio_log.c
proc_comm.c
proc_comm.h
sirc.c
smd.c
smd_debug.c
smd_private.h
timer.c
vreg.c
mach-mv78xx0
mach-mx25
mach-mx3
mach-mx5
mach-mxc91231
mach-netx
mach-nomadik
mach-ns9xxx
mach-nuc93x
mach-omap1
mach-omap2
mach-orion5x
mach-pnx4008
mach-pxa
mach-realview
mach-rpc
mach-s3c2400
mach-s3c2410
mach-s3c2412
mach-s3c2416
mach-s3c2440
mach-s3c2443
mach-s3c24a0
mach-s3c64xx
mach-s5p6442
mach-s5p64x0
mach-s5pc100
mach-s5pv210
mach-s5pv310
mach-sa1100
mach-shark
mach-shmobile
mach-spear3xx
mach-spear6xx
mach-stmp378x
mach-stmp37xx
mach-tcc8k
mach-tegra
mach-u300
mach-ux500
mach-versatile
mach-vexpress
mach-w90x900
mm
nwfpe
oprofile
plat-iop
plat-mxc
plat-nomadik
plat-omap
plat-orion
plat-pxa
plat-s3c24xx
plat-s5p
plat-samsung
plat-spear
plat-stmp3xxx
plat-tcc
plat-versatile
tools
vfp
Kconfig
Kconfig-nommu
Kconfig.debug
Makefile
avr32
blackfin
cris
frv
h8300
ia64
m32r
m68k
m68knommu
microblaze
mips
mn10300
parisc
powerpc
s390
score
sh
sparc
tile
um
x86
xtensa
.gitignore
Kconfig
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
arch
/
arm
/
mach-msm
/
iommu_dev.c
Blame
Blame
Latest commit
History
History
378 lines (313 loc) · 8.11 KB
Breadcrumbs
linux
/
arch
/
arm
/
mach-msm
/
iommu_dev.c
Top
File metadata and controls
Code
Blame
378 lines (313 loc) · 8.11 KB
Raw
/* Copyright (c) 2010, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and * only version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/io.h> #include <linux/clk.h> #include <linux/iommu.h> #include <linux/interrupt.h> #include <linux/err.h> #include <linux/slab.h> #include <mach/iommu_hw-8xxx.h> #include <mach/iommu.h> struct iommu_ctx_iter_data { /* input */ const char *name; /* output */ struct device *dev; }; static struct platform_device *msm_iommu_root_dev; static int each_iommu_ctx(struct device *dev, void *data) { struct iommu_ctx_iter_data *res = data; struct msm_iommu_ctx_dev *c = dev->platform_data; if (!res || !c || !c->name || !res->name) return -EINVAL; if (!strcmp(res->name, c->name)) { res->dev = dev; return 1; } return 0; } static int each_iommu(struct device *dev, void *data) { return device_for_each_child(dev, data, each_iommu_ctx); } struct device *msm_iommu_get_ctx(const char *ctx_name) { struct iommu_ctx_iter_data r; int found; if (!msm_iommu_root_dev) { pr_err("No root IOMMU device.\n"); goto fail; } r.name = ctx_name; found = device_for_each_child(&msm_iommu_root_dev->dev, &r, each_iommu); if (!found) { pr_err("Could not find context <%s>\n", ctx_name); goto fail; } return r.dev; fail: return NULL; } EXPORT_SYMBOL(msm_iommu_get_ctx); static void msm_iommu_reset(void __iomem *base) { int ctx, ncb; SET_RPUE(base, 0); SET_RPUEIE(base, 0); SET_ESRRESTORE(base, 0); SET_TBE(base, 0); SET_CR(base, 0); SET_SPDMBE(base, 0); SET_TESTBUSCR(base, 0); SET_TLBRSW(base, 0); SET_GLOBAL_TLBIALL(base, 0); SET_RPU_ACR(base, 0); SET_TLBLKCRWE(base, 1); ncb = GET_NCB(base)+1; for (ctx = 0; ctx < ncb; ctx++) { SET_BPRCOSH(base, ctx, 0); SET_BPRCISH(base, ctx, 0); SET_BPRCNSH(base, ctx, 0); SET_BPSHCFG(base, ctx, 0); SET_BPMTCFG(base, ctx, 0); SET_ACTLR(base, ctx, 0); SET_SCTLR(base, ctx, 0); SET_FSRRESTORE(base, ctx, 0); SET_TTBR0(base, ctx, 0); SET_TTBR1(base, ctx, 0); SET_TTBCR(base, ctx, 0); SET_BFBCR(base, ctx, 0); SET_PAR(base, ctx, 0); SET_FAR(base, ctx, 0); SET_CTX_TLBIALL(base, ctx, 0); SET_TLBFLPTER(base, ctx, 0); SET_TLBSLPTER(base, ctx, 0); SET_TLBLKCR(base, ctx, 0); SET_PRRR(base, ctx, 0); SET_NMRR(base, ctx, 0); SET_CONTEXTIDR(base, ctx, 0); } } static int msm_iommu_probe(struct platform_device *pdev) { struct resource *r, *r2; struct clk *iommu_clk; struct msm_iommu_drvdata *drvdata; struct msm_iommu_dev *iommu_dev = pdev->dev.platform_data; void __iomem *regs_base; resource_size_t len; int ret = 0, ncb, nm2v, irq; if (pdev->id != -1) { drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); if (!drvdata) { ret = -ENOMEM; goto fail; } if (!iommu_dev) { ret = -ENODEV; goto fail; } if (iommu_dev->clk_rate != 0) { iommu_clk = clk_get(&pdev->dev, "iommu_clk"); if (IS_ERR(iommu_clk)) { ret = -ENODEV; goto fail; } if (iommu_dev->clk_rate > 0) { ret = clk_set_rate(iommu_clk, iommu_dev->clk_rate); if (ret) { clk_put(iommu_clk); goto fail; } } ret = clk_enable(iommu_clk); if (ret) { clk_put(iommu_clk); goto fail; } clk_put(iommu_clk); } r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "physbase"); if (!r) { ret = -ENODEV; goto fail; } len = r->end - r->start + 1; r2 = request_mem_region(r->start, len, r->name); if (!r2) { pr_err("Could not request memory region: " "start=%p, len=%d\n", (void *) r->start, len); ret = -EBUSY; goto fail; } regs_base = ioremap(r2->start, len); if (!regs_base) { pr_err("Could not ioremap: start=%p, len=%d\n", (void *) r2->start, len); ret = -EBUSY; goto fail_mem; } irq = platform_get_irq_byname(pdev, "secure_irq"); if (irq < 0) { ret = -ENODEV; goto fail_io; } mb(); if (GET_IDR(regs_base) == 0) { pr_err("Invalid IDR value detected\n"); ret = -ENODEV; goto fail_io; } ret = request_irq(irq, msm_iommu_fault_handler, 0, "msm_iommu_secure_irpt_handler", drvdata); if (ret) { pr_err("Request IRQ %d failed with ret=%d\n", irq, ret); goto fail_io; } msm_iommu_reset(regs_base); drvdata->base = regs_base; drvdata->irq = irq; nm2v = GET_NM2VCBMT((unsigned long) regs_base); ncb = GET_NCB((unsigned long) regs_base); pr_info("device %s mapped at %p, irq %d with %d ctx banks\n", iommu_dev->name, regs_base, irq, ncb+1); platform_set_drvdata(pdev, drvdata); } else msm_iommu_root_dev = pdev; return 0; fail_io: iounmap(regs_base); fail_mem: release_mem_region(r->start, len); fail: kfree(drvdata); return ret; } static int msm_iommu_remove(struct platform_device *pdev) { struct msm_iommu_drvdata *drv = NULL; drv = platform_get_drvdata(pdev); if (drv) { memset(drv, 0, sizeof(struct msm_iommu_drvdata)); kfree(drv); platform_set_drvdata(pdev, NULL); } return 0; } static int msm_iommu_ctx_probe(struct platform_device *pdev) { struct msm_iommu_ctx_dev *c = pdev->dev.platform_data; struct msm_iommu_drvdata *drvdata; struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL; int i, ret = 0; if (!c || !pdev->dev.parent) { ret = -EINVAL; goto fail; } drvdata = dev_get_drvdata(pdev->dev.parent); if (!drvdata) { ret = -ENODEV; goto fail; } ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL); if (!ctx_drvdata) { ret = -ENOMEM; goto fail; } ctx_drvdata->num = c->num; ctx_drvdata->pdev = pdev; INIT_LIST_HEAD(&ctx_drvdata->attached_elm); platform_set_drvdata(pdev, ctx_drvdata); /* Program the M2V tables for this context */ for (i = 0; i < MAX_NUM_MIDS; i++) { int mid = c->mids[i]; if (mid == -1) break; SET_M2VCBR_N(drvdata->base, mid, 0); SET_CBACR_N(drvdata->base, c->num, 0); /* Set VMID = MID */ SET_VMID(drvdata->base, mid, mid); /* Set the context number for that MID to this context */ SET_CBNDX(drvdata->base, mid, c->num); /* Set MID associated with this context bank */ SET_CBVMID(drvdata->base, c->num, mid); /* Set security bit override to be Non-secure */ SET_NSCFG(drvdata->base, mid, 3); } pr_info("context device %s with bank index %d\n", c->name, c->num); return 0; fail: kfree(ctx_drvdata); return ret; } static int msm_iommu_ctx_remove(struct platform_device *pdev) { struct msm_iommu_ctx_drvdata *drv = NULL; drv = platform_get_drvdata(pdev); if (drv) { memset(drv, 0, sizeof(struct msm_iommu_ctx_drvdata)); kfree(drv); platform_set_drvdata(pdev, NULL); } return 0; } static struct platform_driver msm_iommu_driver = { .driver = { .name = "msm_iommu", }, .probe = msm_iommu_probe, .remove = msm_iommu_remove, }; static struct platform_driver msm_iommu_ctx_driver = { .driver = { .name = "msm_iommu_ctx", }, .probe = msm_iommu_ctx_probe, .remove = msm_iommu_ctx_remove, }; static int __init msm_iommu_driver_init(void) { int ret; ret = platform_driver_register(&msm_iommu_driver); if (ret != 0) { pr_err("Failed to register IOMMU driver\n"); goto error; } ret = platform_driver_register(&msm_iommu_ctx_driver); if (ret != 0) { pr_err("Failed to register IOMMU context driver\n"); goto error; } error: return ret; } static void __exit msm_iommu_driver_exit(void) { platform_driver_unregister(&msm_iommu_ctx_driver); platform_driver_unregister(&msm_iommu_driver); } subsys_initcall(msm_iommu_driver_init); module_exit(msm_iommu_driver_exit); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
You can’t perform that action at this time.