blob: d25d727e7cfbf4b01cffa49a73aeac4b752ed327 [file] [log] [blame]
Santosh Shilimkar2722e562011-03-07 20:53:10 +05301/*
sricharaned0e3522011-08-24 20:07:45 +05302 * 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 */
Axel Lind4fc7eb2011-11-02 09:40:11 +080023#include <linux/module.h>
Santosh Shilimkar2722e562011-03-07 20:53:10 +053024#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/platform_device.h>
27#include <linux/interrupt.h>
28#include <linux/kernel.h>
29#include <linux/slab.h>
30
31#include "omap_l3_noc.h"
32
33/*
34 * Interrupt Handler for L3 error detection.
35 * 1) Identify the L3 clockdomain partition to which the error belongs to.
36 * 2) Identify the slave where the error information is logged
37 * 3) Print the logged information.
38 * 4) Add dump stack to provide kernel trace.
39 *
40 * Two Types of errors :
41 * 1) Custom errors in L3 :
42 * Target like DMM/FW/EMIF generates SRESP=ERR error
43 * 2) Standard L3 error:
44 * - Unsupported CMD.
45 * L3 tries to access target while it is idle
46 * - OCP disconnect.
47 * - Address hole error:
48 * If DSS/ISS/FDIF/USBHOSTFS access a target where they
49 * do not have connectivity, the error is logged in
50 * their default target which is DMM2.
51 *
52 * On High Secure devices, firewall errors are possible and those
53 * can be trapped as well. But the trapping is implemented as part
54 * secure software and hence need not be implemented here.
55 */
56static irqreturn_t l3_interrupt_handler(int irq, void *_l3)
57{
58
sricharaned0e3522011-08-24 20:07:45 +053059 struct omap4_l3 *l3 = _l3;
sricharan551a9fa2011-09-07 17:25:16 +053060 int inttype, i, k;
Santosh Shilimkar2722e562011-03-07 20:53:10 +053061 int err_src = 0;
sricharan551a9fa2011-09-07 17:25:16 +053062 u32 std_err_main, err_reg, clear, masterid;
sricharan6616aac2011-08-23 12:58:48 +053063 void __iomem *base, *l3_targ_base;
sricharan551a9fa2011-09-07 17:25:16 +053064 char *target_name, *master_name = "UN IDENTIFIED";
Santosh Shilimkar2722e562011-03-07 20:53:10 +053065
66 /* Get the Type of interrupt */
omar ramirez35f7b962011-04-18 16:39:42 +000067 inttype = irq == l3->app_irq ? L3_APPLICATION_ERROR : L3_DEBUG_ERROR;
Santosh Shilimkar2722e562011-03-07 20:53:10 +053068
69 for (i = 0; i < L3_MODULES; i++) {
70 /*
71 * Read the regerr register of the clock domain
72 * to determine the source
73 */
sricharan6616aac2011-08-23 12:58:48 +053074 base = l3->l3_base[i];
75 err_reg = __raw_readl(base + l3_flagmux[i] +
Todd Poynor342fd142011-08-24 19:11:39 +053076 + L3_FLAGMUX_REGERR0 + (inttype << 3));
Santosh Shilimkar2722e562011-03-07 20:53:10 +053077
78 /* Get the corresponding error and analyse */
79 if (err_reg) {
80 /* Identify the source from control status register */
Todd Poynor342fd142011-08-24 19:11:39 +053081 err_src = __ffs(err_reg);
Santosh Shilimkar2722e562011-03-07 20:53:10 +053082
Santosh Shilimkar2722e562011-03-07 20:53:10 +053083 /* Read the stderrlog_main_source from clk domain */
Todd Poynor342fd142011-08-24 19:11:39 +053084 l3_targ_base = base + *(l3_targ[i] + err_src);
sricharan6616aac2011-08-23 12:58:48 +053085 std_err_main = __raw_readl(l3_targ_base +
Todd Poynor342fd142011-08-24 19:11:39 +053086 L3_TARG_STDERRLOG_MAIN);
sricharan551a9fa2011-09-07 17:25:16 +053087 masterid = __raw_readl(l3_targ_base +
88 L3_TARG_STDERRLOG_MSTADDR);
Santosh Shilimkar2722e562011-03-07 20:53:10 +053089
omar ramirez35f7b962011-04-18 16:39:42 +000090 switch (std_err_main & CUSTOM_ERROR) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +053091 case STANDARD_ERROR:
sricharan551a9fa2011-09-07 17:25:16 +053092 target_name =
Todd Poynor342fd142011-08-24 19:11:39 +053093 l3_targ_inst_name[i][err_src];
sricharan551a9fa2011-09-07 17:25:16 +053094 WARN(true, "L3 standard error: TARGET:%s at address 0x%x\n",
95 target_name,
sricharan6616aac2011-08-23 12:58:48 +053096 __raw_readl(l3_targ_base +
Todd Poynor342fd142011-08-24 19:11:39 +053097 L3_TARG_STDERRLOG_SLVOFSLSB));
Santosh Shilimkar2722e562011-03-07 20:53:10 +053098 /* clear the std error log*/
99 clear = std_err_main | CLEAR_STDERR_LOG;
Todd Poynor342fd142011-08-24 19:11:39 +0530100 writel(clear, l3_targ_base +
101 L3_TARG_STDERRLOG_MAIN);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530102 break;
103
104 case CUSTOM_ERROR:
sricharan551a9fa2011-09-07 17:25:16 +0530105 target_name =
Todd Poynor342fd142011-08-24 19:11:39 +0530106 l3_targ_inst_name[i][err_src];
sricharan551a9fa2011-09-07 17:25:16 +0530107 for (k = 0; k < NUM_OF_L3_MASTERS; k++) {
108 if (masterid == l3_masters[k].id)
109 master_name =
110 l3_masters[k].name;
111 }
112 WARN(true, "L3 custom error: MASTER:%s TARGET:%s\n",
113 master_name, target_name);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530114 /* clear the std error log*/
115 clear = std_err_main | CLEAR_STDERR_LOG;
Todd Poynor342fd142011-08-24 19:11:39 +0530116 writel(clear, l3_targ_base +
117 L3_TARG_STDERRLOG_MAIN);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530118 break;
119
120 default:
121 /* Nothing to be handled here as of now */
122 break;
123 }
124 /* Error found so break the for loop */
125 break;
126 }
127 }
128 return IRQ_HANDLED;
129}
130
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800131static int omap4_l3_probe(struct platform_device *pdev)
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530132{
sricharaned0e3522011-08-24 20:07:45 +0530133 static struct omap4_l3 *l3;
Todd Poynor342fd142011-08-24 19:11:39 +0530134 struct resource *res;
Todd Poynorc1df2dc2011-08-29 17:42:23 +0530135 int ret;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530136
Peter Ujfalusibae74512014-04-01 16:23:46 +0300137 l3 = devm_kzalloc(&pdev->dev, sizeof(*l3), GFP_KERNEL);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530138 if (!l3)
omar ramirez7529b702011-04-18 16:39:41 +0000139 return -ENOMEM;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530140
141 platform_set_drvdata(pdev, l3);
142 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
143 if (!res) {
144 dev_err(&pdev->dev, "couldn't find resource 0\n");
Peter Ujfalusibae74512014-04-01 16:23:46 +0300145 return -ENODEV;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530146 }
147
148 l3->l3_base[0] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000149 if (!l3->l3_base[0]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530150 dev_err(&pdev->dev, "ioremap failed\n");
Peter Ujfalusibae74512014-04-01 16:23:46 +0300151 return -ENOMEM;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530152 }
153
154 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
155 if (!res) {
156 dev_err(&pdev->dev, "couldn't find resource 1\n");
157 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000158 goto err1;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530159 }
160
161 l3->l3_base[1] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000162 if (!l3->l3_base[1]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530163 dev_err(&pdev->dev, "ioremap failed\n");
164 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000165 goto err1;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530166 }
167
168 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
169 if (!res) {
170 dev_err(&pdev->dev, "couldn't find resource 2\n");
171 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000172 goto err2;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530173 }
174
175 l3->l3_base[2] = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000176 if (!l3->l3_base[2]) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530177 dev_err(&pdev->dev, "ioremap failed\n");
178 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000179 goto err2;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530180 }
181
182 /*
183 * Setup interrupt Handlers
184 */
Todd Poynorc1df2dc2011-08-29 17:42:23 +0530185 l3->debug_irq = platform_get_irq(pdev, 0);
186 ret = request_irq(l3->debug_irq,
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530187 l3_interrupt_handler,
188 IRQF_DISABLED, "l3-dbg-irq", l3);
189 if (ret) {
190 pr_crit("L3: request_irq failed to register for 0x%x\n",
Olof Johansson2c2d1672012-09-20 16:10:02 -0700191 l3->debug_irq);
omar ramirez7529b702011-04-18 16:39:41 +0000192 goto err3;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530193 }
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530194
Todd Poynorc1df2dc2011-08-29 17:42:23 +0530195 l3->app_irq = platform_get_irq(pdev, 1);
196 ret = request_irq(l3->app_irq,
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530197 l3_interrupt_handler,
198 IRQF_DISABLED, "l3-app-irq", l3);
199 if (ret) {
200 pr_crit("L3: request_irq failed to register for 0x%x\n",
Olof Johansson2c2d1672012-09-20 16:10:02 -0700201 l3->app_irq);
omar ramirez7529b702011-04-18 16:39:41 +0000202 goto err4;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530203 }
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530204
omar ramirez7529b702011-04-18 16:39:41 +0000205 return 0;
206
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530207err4:
omar ramirez7529b702011-04-18 16:39:41 +0000208 free_irq(l3->debug_irq, l3);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530209err3:
omar ramirez7529b702011-04-18 16:39:41 +0000210 iounmap(l3->l3_base[2]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530211err2:
omar ramirez7529b702011-04-18 16:39:41 +0000212 iounmap(l3->l3_base[1]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530213err1:
omar ramirez7529b702011-04-18 16:39:41 +0000214 iounmap(l3->l3_base[0]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530215 return ret;
216}
217
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800218static int omap4_l3_remove(struct platform_device *pdev)
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530219{
sricharaned0e3522011-08-24 20:07:45 +0530220 struct omap4_l3 *l3 = platform_get_drvdata(pdev);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530221
222 free_irq(l3->app_irq, l3);
223 free_irq(l3->debug_irq, l3);
224 iounmap(l3->l3_base[0]);
225 iounmap(l3->l3_base[1]);
226 iounmap(l3->l3_base[2]);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530227
228 return 0;
229}
230
Benoit Coussond039c5b2011-08-12 13:52:50 +0200231#if defined(CONFIG_OF)
232static const struct of_device_id l3_noc_match[] = {
233 {.compatible = "ti,omap4-l3-noc", },
234 {},
Govindraj.R8770b072011-11-23 14:45:37 -0800235};
Benoit Coussond039c5b2011-08-12 13:52:50 +0200236MODULE_DEVICE_TABLE(of, l3_noc_match);
237#else
238#define l3_noc_match NULL
239#endif
240
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530241static struct platform_driver omap4_l3_driver = {
Benoit Coussond039c5b2011-08-12 13:52:50 +0200242 .probe = omap4_l3_probe,
Greg Kroah-Hartman0fe763c2012-12-21 15:14:44 -0800243 .remove = omap4_l3_remove,
Benoit Coussond039c5b2011-08-12 13:52:50 +0200244 .driver = {
245 .name = "omap_l3_noc",
246 .owner = THIS_MODULE,
247 .of_match_table = l3_noc_match,
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530248 },
249};
250
251static int __init omap4_l3_init(void)
252{
Benoit Coussond039c5b2011-08-12 13:52:50 +0200253 return platform_driver_register(&omap4_l3_driver);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530254}
255postcore_initcall_sync(omap4_l3_init);
256
257static void __exit omap4_l3_exit(void)
258{
259 platform_driver_unregister(&omap4_l3_driver);
260}
261module_exit(omap4_l3_exit);