blob: 7b9f1909ddb2a3bc110d83b721a2466ec574f01a [file] [log] [blame]
Santosh Shilimkar2722e562011-03-07 20:53:10 +05301/*
2 * OMAP4XXX L3 Interconnect error handling driver
3 *
4 * Copyright (C) 2011 Texas Corporation
5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 * Sricharan <r.sricharan@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 */
23#include <linux/init.h>
24#include <linux/io.h>
25#include <linux/platform_device.h>
26#include <linux/interrupt.h>
27#include <linux/kernel.h>
28#include <linux/slab.h>
29
30#include "omap_l3_noc.h"
31
32/*
33 * Interrupt Handler for L3 error detection.
34 * 1) Identify the L3 clockdomain partition to which the error belongs to.
35 * 2) Identify the slave where the error information is logged
36 * 3) Print the logged information.
37 * 4) Add dump stack to provide kernel trace.
38 *
39 * Two Types of errors :
40 * 1) Custom errors in L3 :
41 * Target like DMM/FW/EMIF generates SRESP=ERR error
42 * 2) Standard L3 error:
43 * - Unsupported CMD.
44 * L3 tries to access target while it is idle
45 * - OCP disconnect.
46 * - Address hole error:
47 * If DSS/ISS/FDIF/USBHOSTFS access a target where they
48 * do not have connectivity, the error is logged in
49 * their default target which is DMM2.
50 *
51 * On High Secure devices, firewall errors are possible and those
52 * can be trapped as well. But the trapping is implemented as part
53 * secure software and hence need not be implemented here.
54 */
55static irqreturn_t l3_interrupt_handler(int irq, void *_l3)
56{
57
58 struct omap4_l3 *l3 = _l3;
59 int inttype, i, j;
60 int err_src = 0;
61 u32 std_err_main_addr, std_err_main, err_reg;
62 u32 base, slave_addr, clear;
63 char *source_name;
64
65 /* Get the Type of interrupt */
omar ramirez35f7b962011-04-18 16:39:42 +000066 inttype = irq == l3->app_irq ? L3_APPLICATION_ERROR : L3_DEBUG_ERROR;
Santosh Shilimkar2722e562011-03-07 20:53:10 +053067
68 for (i = 0; i < L3_MODULES; i++) {
69 /*
70 * Read the regerr register of the clock domain
71 * to determine the source
72 */
73 base = (u32)l3->l3_base[i];
74 err_reg = readl(base + l3_flagmux[i] + (inttype << 3));
75
76 /* Get the corresponding error and analyse */
77 if (err_reg) {
78 /* Identify the source from control status register */
79 for (j = 0; !(err_reg & (1 << j)); j++)
80 ;
81
82 err_src = j;
83 /* Read the stderrlog_main_source from clk domain */
omar ramirez35f7b962011-04-18 16:39:42 +000084 std_err_main_addr = base + *(l3_targ[i] + err_src);
85 std_err_main = readl(std_err_main_addr);
Santosh Shilimkar2722e562011-03-07 20:53:10 +053086
omar ramirez35f7b962011-04-18 16:39:42 +000087 switch (std_err_main & CUSTOM_ERROR) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +053088 case STANDARD_ERROR:
89 source_name =
90 l3_targ_stderrlog_main_name[i][err_src];
91
92 slave_addr = std_err_main_addr +
93 L3_SLAVE_ADDRESS_OFFSET;
94 WARN(true, "L3 standard error: SOURCE:%s at address 0x%x\n",
95 source_name, readl(slave_addr));
96 /* clear the std error log*/
97 clear = std_err_main | CLEAR_STDERR_LOG;
98 writel(clear, std_err_main_addr);
99 break;
100
101 case CUSTOM_ERROR:
102 source_name =
103 l3_targ_stderrlog_main_name[i][err_src];
104
105 WARN(true, "CUSTOM SRESP error with SOURCE:%s\n",
106 source_name);
107 /* clear the std error log*/
108 clear = std_err_main | CLEAR_STDERR_LOG;
109 writel(clear, std_err_main_addr);
110 break;
111
112 default:
113 /* Nothing to be handled here as of now */
114 break;
115 }
116 /* Error found so break the for loop */
117 break;
118 }
119 }
120 return IRQ_HANDLED;
121}
122
123static int __init omap4_l3_probe(struct platform_device *pdev)
124{
125 static struct omap4_l3 *l3;
126 struct resource *res;
127 int ret;
128 int irq;
129
130 l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
131 if (!l3)
omar ramirez7529b702011-04-18 16:39:41 +0000132 return -ENOMEM;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530133
134 platform_set_drvdata(pdev, l3);
135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
136 if (!res) {
137 dev_err(&pdev->dev, "couldn't find resource 0\n");
138 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000139 goto err0;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530140 }
141
142 l3->l3_base[0] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000143 if (!l3->l3_base[0]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530144 dev_err(&pdev->dev, "ioremap failed\n");
145 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000146 goto err0;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530147 }
148
149 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
150 if (!res) {
151 dev_err(&pdev->dev, "couldn't find resource 1\n");
152 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000153 goto err1;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530154 }
155
156 l3->l3_base[1] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000157 if (!l3->l3_base[1]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530158 dev_err(&pdev->dev, "ioremap failed\n");
159 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000160 goto err1;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530161 }
162
163 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
164 if (!res) {
165 dev_err(&pdev->dev, "couldn't find resource 2\n");
166 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000167 goto err2;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530168 }
169
170 l3->l3_base[2] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000171 if (!l3->l3_base[2]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530172 dev_err(&pdev->dev, "ioremap failed\n");
173 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000174 goto err2;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530175 }
176
177 /*
178 * Setup interrupt Handlers
179 */
180 irq = platform_get_irq(pdev, 0);
181 ret = request_irq(irq,
182 l3_interrupt_handler,
183 IRQF_DISABLED, "l3-dbg-irq", l3);
184 if (ret) {
185 pr_crit("L3: request_irq failed to register for 0x%x\n",
186 OMAP44XX_IRQ_L3_DBG);
omar ramirez7529b702011-04-18 16:39:41 +0000187 goto err3;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530188 }
189 l3->debug_irq = irq;
190
191 irq = platform_get_irq(pdev, 1);
192 ret = request_irq(irq,
193 l3_interrupt_handler,
194 IRQF_DISABLED, "l3-app-irq", l3);
195 if (ret) {
196 pr_crit("L3: request_irq failed to register for 0x%x\n",
197 OMAP44XX_IRQ_L3_APP);
omar ramirez7529b702011-04-18 16:39:41 +0000198 goto err4;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530199 }
200 l3->app_irq = irq;
201
omar ramirez7529b702011-04-18 16:39:41 +0000202 return 0;
203
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530204err4:
omar ramirez7529b702011-04-18 16:39:41 +0000205 free_irq(l3->debug_irq, l3);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530206err3:
omar ramirez7529b702011-04-18 16:39:41 +0000207 iounmap(l3->l3_base[2]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530208err2:
omar ramirez7529b702011-04-18 16:39:41 +0000209 iounmap(l3->l3_base[1]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530210err1:
omar ramirez7529b702011-04-18 16:39:41 +0000211 iounmap(l3->l3_base[0]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530212err0:
omar ramirez7529b702011-04-18 16:39:41 +0000213 kfree(l3);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530214 return ret;
215}
216
217static int __exit omap4_l3_remove(struct platform_device *pdev)
218{
219 struct omap4_l3 *l3 = platform_get_drvdata(pdev);
220
221 free_irq(l3->app_irq, l3);
222 free_irq(l3->debug_irq, l3);
223 iounmap(l3->l3_base[0]);
224 iounmap(l3->l3_base[1]);
225 iounmap(l3->l3_base[2]);
226 kfree(l3);
227
228 return 0;
229}
230
231static struct platform_driver omap4_l3_driver = {
232 .remove = __exit_p(omap4_l3_remove),
233 .driver = {
234 .name = "omap_l3_noc",
235 },
236};
237
238static int __init omap4_l3_init(void)
239{
240 return platform_driver_probe(&omap4_l3_driver, omap4_l3_probe);
241}
242postcore_initcall_sync(omap4_l3_init);
243
244static void __exit omap4_l3_exit(void)
245{
246 platform_driver_unregister(&omap4_l3_driver);
247}
248module_exit(omap4_l3_exit);