blob: 9524452ee12c810e56e3ab40e2b0ec7bfefa8f63 [file] [log] [blame]
Santosh Shilimkar2722e562011-03-07 20:53:10 +05301/*
Sricharan Rc10d5c92014-04-11 13:09:36 -05002 * OMAP L3 Interconnect error handling driver
sricharaned0e3522011-08-24 20:07:45 +05303 *
Nishanth Menonc5f2aea2014-04-11 13:15:43 -05004 * Copyright (C) 2011-2014 Texas Instruments Incorporated - http://www.ti.com/
sricharaned0e3522011-08-24 20:07:45 +05305 * 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
Nishanth Menonc5f2aea2014-04-11 13:15:43 -05009 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
sricharaned0e3522011-08-24 20:07:45 +053011 *
Nishanth Menonc5f2aea2014-04-11 13:15:43 -050012 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
sricharaned0e3522011-08-24 20:07:45 +053015 * GNU General Public License for more details.
sricharaned0e3522011-08-24 20:07:45 +053016 */
Santosh Shilimkar2722e562011-03-07 20:53:10 +053017#include <linux/init.h>
Santosh Shilimkar2722e562011-03-07 20:53:10 +053018#include <linux/interrupt.h>
Sricharan R06594522013-11-26 07:38:23 -060019#include <linux/io.h>
Santosh Shilimkar2722e562011-03-07 20:53:10 +053020#include <linux/kernel.h>
Sricharan R06594522013-11-26 07:38:23 -060021#include <linux/module.h>
22#include <linux/of_device.h>
23#include <linux/of.h>
24#include <linux/platform_device.h>
Santosh Shilimkar2722e562011-03-07 20:53:10 +053025#include <linux/slab.h>
26
27#include "omap_l3_noc.h"
28
29/*
30 * Interrupt Handler for L3 error detection.
31 * 1) Identify the L3 clockdomain partition to which the error belongs to.
32 * 2) Identify the slave where the error information is logged
33 * 3) Print the logged information.
34 * 4) Add dump stack to provide kernel trace.
35 *
36 * Two Types of errors :
37 * 1) Custom errors in L3 :
38 * Target like DMM/FW/EMIF generates SRESP=ERR error
39 * 2) Standard L3 error:
40 * - Unsupported CMD.
41 * L3 tries to access target while it is idle
42 * - OCP disconnect.
43 * - Address hole error:
44 * If DSS/ISS/FDIF/USBHOSTFS access a target where they
45 * do not have connectivity, the error is logged in
46 * their default target which is DMM2.
47 *
48 * On High Secure devices, firewall errors are possible and those
49 * can be trapped as well. But the trapping is implemented as part
50 * secure software and hence need not be implemented here.
51 */
52static irqreturn_t l3_interrupt_handler(int irq, void *_l3)
53{
54
Sricharan Rc10d5c92014-04-11 13:09:36 -050055 struct omap_l3 *l3 = _l3;
sricharan551a9fa2011-09-07 17:25:16 +053056 int inttype, i, k;
Santosh Shilimkar2722e562011-03-07 20:53:10 +053057 int err_src = 0;
sricharan551a9fa2011-09-07 17:25:16 +053058 u32 std_err_main, err_reg, clear, masterid;
sricharan6616aac2011-08-23 12:58:48 +053059 void __iomem *base, *l3_targ_base;
Nishanth Menon9e224c82014-04-11 11:21:47 -050060 void __iomem *l3_targ_stderr, *l3_targ_slvofslsb, *l3_targ_mstaddr;
sricharan551a9fa2011-09-07 17:25:16 +053061 char *target_name, *master_name = "UN IDENTIFIED";
Nishanth Menon3ae9af72014-04-11 11:38:10 -050062 struct l3_target_data *l3_targ_inst;
Nishanth Menon97708c02014-04-14 09:57:50 -050063 struct l3_flagmux_data *flag_mux;
Sricharan R06594522013-11-26 07:38:23 -060064 struct l3_masters_data *master;
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
Sricharan R06594522013-11-26 07:38:23 -060069 for (i = 0; i < l3->num_modules; i++) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +053070 /*
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];
Nishanth Menon97708c02014-04-14 09:57:50 -050075 flag_mux = l3->l3_flagmux[i];
76 err_reg = readl_relaxed(base + flag_mux->offset +
Nishanth Menon9e224c82014-04-11 11:21:47 -050077 L3_FLAGMUX_REGERR0 + (inttype << 3));
Santosh Shilimkar2722e562011-03-07 20:53:10 +053078
79 /* Get the corresponding error and analyse */
80 if (err_reg) {
81 /* Identify the source from control status register */
Todd Poynor342fd142011-08-24 19:11:39 +053082 err_src = __ffs(err_reg);
Rajendra Nayak3340d732014-04-10 11:31:33 -050083
84 /* We DONOT expect err_src to go out of bounds */
85 BUG_ON(err_src > MAX_CLKDM_TARGETS);
86
Nishanth Menon97708c02014-04-14 09:57:50 -050087 if (err_src < flag_mux->num_targ_data) {
88 l3_targ_inst = &flag_mux->l3_targ[err_src];
89 target_name = l3_targ_inst->name;
90 l3_targ_base = base + l3_targ_inst->offset;
91 } else {
92 target_name = L3_TARGET_NOT_SUPPORTED;
93 }
Santosh Shilimkar2722e562011-03-07 20:53:10 +053094
Rajendra Nayak3340d732014-04-10 11:31:33 -050095 /*
96 * If we do not know of a register offset to decode
97 * and clear, then mask.
98 */
99 if (target_name == L3_TARGET_NOT_SUPPORTED) {
100 u32 mask_val;
101 void __iomem *mask_reg;
102
103 /*
104 * Certain plaforms may have "undocumented"
105 * status pending on boot.. So dont generate
106 * a severe warning here.
107 */
108 dev_err(l3->dev,
109 "L3 %s error: target %d mod:%d %s\n",
110 inttype ? "debug" : "application",
111 err_src, i, "(unclearable)");
112
Nishanth Menon97708c02014-04-14 09:57:50 -0500113 mask_reg = base + flag_mux->offset +
Rajendra Nayak3340d732014-04-10 11:31:33 -0500114 L3_FLAGMUX_MASK0 + (inttype << 3);
115 mask_val = readl_relaxed(mask_reg);
116 mask_val &= ~(1 << err_src);
117 writel_relaxed(mask_val, mask_reg);
118
119 break;
120 }
121
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530122 /* Read the stderrlog_main_source from clk domain */
Nishanth Menon9e224c82014-04-11 11:21:47 -0500123 l3_targ_stderr = l3_targ_base + L3_TARG_STDERRLOG_MAIN;
124 l3_targ_slvofslsb = l3_targ_base +
125 L3_TARG_STDERRLOG_SLVOFSLSB;
126 l3_targ_mstaddr = l3_targ_base +
127 L3_TARG_STDERRLOG_MSTADDR;
128
129 std_err_main = readl_relaxed(l3_targ_stderr);
130 masterid = readl_relaxed(l3_targ_mstaddr);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530131
omar ramirez35f7b962011-04-18 16:39:42 +0000132 switch (std_err_main & CUSTOM_ERROR) {
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530133 case STANDARD_ERROR:
sricharan551a9fa2011-09-07 17:25:16 +0530134 WARN(true, "L3 standard error: TARGET:%s at address 0x%x\n",
135 target_name,
Nishanth Menon9e224c82014-04-11 11:21:47 -0500136 readl_relaxed(l3_targ_slvofslsb));
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530137 /* clear the std error log*/
138 clear = std_err_main | CLEAR_STDERR_LOG;
Nishanth Menon9e224c82014-04-11 11:21:47 -0500139 writel_relaxed(clear, l3_targ_stderr);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530140 break;
141
142 case CUSTOM_ERROR:
Sricharan R06594522013-11-26 07:38:23 -0600143 for (k = 0, master = l3->l3_masters;
144 k < l3->num_masters; k++, master++) {
145 if (masterid == master->id) {
146 master_name = master->name;
147 break;
148 }
sricharan551a9fa2011-09-07 17:25:16 +0530149 }
150 WARN(true, "L3 custom error: MASTER:%s TARGET:%s\n",
151 master_name, target_name);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530152 /* clear the std error log*/
153 clear = std_err_main | CLEAR_STDERR_LOG;
Nishanth Menon9e224c82014-04-11 11:21:47 -0500154 writel_relaxed(clear, l3_targ_stderr);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530155 break;
156
157 default:
158 /* Nothing to be handled here as of now */
159 break;
160 }
161 /* Error found so break the for loop */
162 break;
163 }
164 }
165 return IRQ_HANDLED;
166}
167
Sricharan R06594522013-11-26 07:38:23 -0600168static const struct of_device_id l3_noc_match[] = {
169 {.compatible = "ti,omap4-l3-noc", .data = &omap_l3_data},
170 {},
171};
172MODULE_DEVICE_TABLE(of, l3_noc_match);
173
Sricharan Rc10d5c92014-04-11 13:09:36 -0500174static int omap_l3_probe(struct platform_device *pdev)
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530175{
Sricharan R06594522013-11-26 07:38:23 -0600176 const struct of_device_id *of_id;
Sricharan Rc10d5c92014-04-11 13:09:36 -0500177 static struct omap_l3 *l3;
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300178 int ret, i;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530179
Sricharan R06594522013-11-26 07:38:23 -0600180 of_id = of_match_device(l3_noc_match, &pdev->dev);
181 if (!of_id) {
182 dev_err(&pdev->dev, "OF data missing\n");
183 return -EINVAL;
184 }
185
Peter Ujfalusibae74512014-04-01 16:23:46 +0300186 l3 = devm_kzalloc(&pdev->dev, sizeof(*l3), GFP_KERNEL);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530187 if (!l3)
omar ramirez7529b702011-04-18 16:39:41 +0000188 return -ENOMEM;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530189
Sricharan R06594522013-11-26 07:38:23 -0600190 memcpy(l3, of_id->data, sizeof(*l3));
Nishanth Menonca6a3492014-04-11 12:04:01 -0500191 l3->dev = &pdev->dev;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530192 platform_set_drvdata(pdev, l3);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530193
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300194 /* Get mem resources */
Sricharan R06594522013-11-26 07:38:23 -0600195 for (i = 0; i < l3->num_modules; i++) {
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300196 struct resource *res = platform_get_resource(pdev,
197 IORESOURCE_MEM, i);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530198
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300199 l3->l3_base[i] = devm_ioremap_resource(&pdev->dev, res);
200 if (IS_ERR(l3->l3_base[i])) {
Nishanth Menonca6a3492014-04-11 12:04:01 -0500201 dev_err(l3->dev, "ioremap %d failed\n", i);
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300202 return PTR_ERR(l3->l3_base[i]);
203 }
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530204 }
205
206 /*
207 * Setup interrupt Handlers
208 */
Todd Poynorc1df2dc2011-08-29 17:42:23 +0530209 l3->debug_irq = platform_get_irq(pdev, 0);
Nishanth Menonca6a3492014-04-11 12:04:01 -0500210 ret = devm_request_irq(l3->dev, l3->debug_irq, l3_interrupt_handler,
Peter Ujfalusia0ef78f2014-04-01 16:23:48 +0300211 IRQF_DISABLED, "l3-dbg-irq", l3);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530212 if (ret) {
Nishanth Menonca6a3492014-04-11 12:04:01 -0500213 dev_err(l3->dev, "request_irq failed for %d\n",
Peter Ujfalusiae225982014-04-01 16:23:50 +0300214 l3->debug_irq);
Peter Ujfalusi56c4a022014-04-01 16:23:47 +0300215 return ret;
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530216 }
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530217
Todd Poynorc1df2dc2011-08-29 17:42:23 +0530218 l3->app_irq = platform_get_irq(pdev, 1);
Nishanth Menonca6a3492014-04-11 12:04:01 -0500219 ret = devm_request_irq(l3->dev, l3->app_irq, l3_interrupt_handler,
Peter Ujfalusia0ef78f2014-04-01 16:23:48 +0300220 IRQF_DISABLED, "l3-app-irq", l3);
221 if (ret)
Nishanth Menonca6a3492014-04-11 12:04:01 -0500222 dev_err(l3->dev, "request_irq failed for %d\n", l3->app_irq);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530223
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530224 return ret;
225}
226
Sricharan Rc10d5c92014-04-11 13:09:36 -0500227static struct platform_driver omap_l3_driver = {
228 .probe = omap_l3_probe,
Benoit Coussond039c5b2011-08-12 13:52:50 +0200229 .driver = {
230 .name = "omap_l3_noc",
231 .owner = THIS_MODULE,
Sricharan R06594522013-11-26 07:38:23 -0600232 .of_match_table = of_match_ptr(l3_noc_match),
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530233 },
234};
235
Sricharan Rc10d5c92014-04-11 13:09:36 -0500236static int __init omap_l3_init(void)
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530237{
Sricharan Rc10d5c92014-04-11 13:09:36 -0500238 return platform_driver_register(&omap_l3_driver);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530239}
Sricharan Rc10d5c92014-04-11 13:09:36 -0500240postcore_initcall_sync(omap_l3_init);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530241
Sricharan Rc10d5c92014-04-11 13:09:36 -0500242static void __exit omap_l3_exit(void)
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530243{
Sricharan Rc10d5c92014-04-11 13:09:36 -0500244 platform_driver_unregister(&omap_l3_driver);
Santosh Shilimkar2722e562011-03-07 20:53:10 +0530245}
Sricharan Rc10d5c92014-04-11 13:09:36 -0500246module_exit(omap_l3_exit);