blob: a05a62f9ee5b2e7bce17e9b89fc4ce6ff0f18d2b [file] [log] [blame]
sricharaned0e3522011-08-24 20:07:45 +05301/*
2 * OMAP3XXX L3 Interconnect Driver
3 *
4 * Copyright (C) 2011 Texas Corporation
5 * Felipe Balbi <balbi@ti.com>
6 * Santosh Shilimkar <santosh.shilimkar@ti.com>
7 * Sricharan <r.sricharan@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
Felipe Balbie2fa61d2011-03-07 19:35:20 +053024
25#include <linux/kernel.h>
26#include <linux/slab.h>
27#include <linux/platform_device.h>
28#include <linux/interrupt.h>
29#include <linux/io.h>
30#include "omap_l3_smx.h"
31
32static inline u64 omap3_l3_readll(void __iomem *base, u16 reg)
33{
34 return __raw_readll(base + reg);
35}
36
37static inline void omap3_l3_writell(void __iomem *base, u16 reg, u64 value)
38{
39 __raw_writell(value, base + reg);
40}
41
42static inline enum omap3_l3_code omap3_l3_decode_error_code(u64 error)
43{
44 return (error & 0x0f000000) >> L3_ERROR_LOG_CODE;
45}
46
47static inline u32 omap3_l3_decode_addr(u64 error_addr)
48{
49 return error_addr & 0xffffffff;
50}
51
52static inline unsigned omap3_l3_decode_cmd(u64 error)
53{
54 return (error & 0x07) >> L3_ERROR_LOG_CMD;
55}
56
57static inline enum omap3_l3_initiator_id omap3_l3_decode_initid(u64 error)
58{
59 return (error & 0xff00) >> L3_ERROR_LOG_INITID;
60}
61
62static inline unsigned omap3_l3_decode_req_info(u64 error)
63{
64 return (error >> 32) & 0xffff;
65}
66
67static char *omap3_l3_code_string(u8 code)
68{
69 switch (code) {
70 case OMAP_L3_CODE_NOERROR:
71 return "No Error";
72 case OMAP_L3_CODE_UNSUP_CMD:
73 return "Unsupported Command";
74 case OMAP_L3_CODE_ADDR_HOLE:
75 return "Address Hole";
76 case OMAP_L3_CODE_PROTECT_VIOLATION:
77 return "Protection Violation";
78 case OMAP_L3_CODE_IN_BAND_ERR:
79 return "In-band Error";
80 case OMAP_L3_CODE_REQ_TOUT_NOT_ACCEPT:
81 return "Request Timeout Not Accepted";
82 case OMAP_L3_CODE_REQ_TOUT_NO_RESP:
83 return "Request Timeout, no response";
84 default:
85 return "UNKNOWN error";
86 }
87}
88
89static char *omap3_l3_initiator_string(u8 initid)
90{
91 switch (initid) {
92 case OMAP_L3_LCD:
93 return "LCD";
94 case OMAP_L3_SAD2D:
95 return "SAD2D";
96 case OMAP_L3_IA_MPU_SS_1:
97 case OMAP_L3_IA_MPU_SS_2:
98 case OMAP_L3_IA_MPU_SS_3:
99 case OMAP_L3_IA_MPU_SS_4:
100 case OMAP_L3_IA_MPU_SS_5:
101 return "MPU";
102 case OMAP_L3_IA_IVA_SS_1:
103 case OMAP_L3_IA_IVA_SS_2:
104 case OMAP_L3_IA_IVA_SS_3:
105 return "IVA_SS";
106 case OMAP_L3_IA_IVA_SS_DMA_1:
107 case OMAP_L3_IA_IVA_SS_DMA_2:
108 case OMAP_L3_IA_IVA_SS_DMA_3:
109 case OMAP_L3_IA_IVA_SS_DMA_4:
110 case OMAP_L3_IA_IVA_SS_DMA_5:
111 case OMAP_L3_IA_IVA_SS_DMA_6:
112 return "IVA_SS_DMA";
113 case OMAP_L3_IA_SGX:
114 return "SGX";
115 case OMAP_L3_IA_CAM_1:
116 case OMAP_L3_IA_CAM_2:
117 case OMAP_L3_IA_CAM_3:
118 return "CAM";
119 case OMAP_L3_IA_DAP:
120 return "DAP";
121 case OMAP_L3_SDMA_WR_1:
122 case OMAP_L3_SDMA_WR_2:
123 return "SDMA_WR";
124 case OMAP_L3_SDMA_RD_1:
125 case OMAP_L3_SDMA_RD_2:
126 case OMAP_L3_SDMA_RD_3:
127 case OMAP_L3_SDMA_RD_4:
128 return "SDMA_RD";
129 case OMAP_L3_USBOTG:
130 return "USB_OTG";
131 case OMAP_L3_USBHOST:
132 return "USB_HOST";
133 default:
134 return "UNKNOWN Initiator";
135 }
136}
137
sricharaned0e3522011-08-24 20:07:45 +0530138/*
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530139 * omap3_l3_block_irq - handles a register block's irq
140 * @l3: struct omap3_l3 *
141 * @base: register block base address
142 * @error: L3_ERROR_LOG register of our block
143 *
144 * Called in hard-irq context. Caller should take care of locking
145 *
146 * OMAP36xx TRM gives, on page 2001, Figure 9-10, the Typical Error
147 * Analysis Sequence, we are following that sequence here, please
148 * refer to that Figure for more information on the subject.
149 */
150static irqreturn_t omap3_l3_block_irq(struct omap3_l3 *l3,
151 u64 error, int error_addr)
152{
sricharaned0e3522011-08-24 20:07:45 +0530153 u8 code = omap3_l3_decode_error_code(error);
154 u8 initid = omap3_l3_decode_initid(error);
155 u8 multi = error & L3_ERROR_LOG_MULTI;
156 u32 address = omap3_l3_decode_addr(error_addr);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530157
omar ramirez35f7b962011-04-18 16:39:42 +0000158 WARN(true, "%s seen by %s %s at address %x\n",
sricharaned0e3522011-08-24 20:07:45 +0530159 omap3_l3_code_string(code),
160 omap3_l3_initiator_string(initid),
161 multi ? "Multiple Errors" : "", address);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530162
163 return IRQ_HANDLED;
164}
165
166static irqreturn_t omap3_l3_app_irq(int irq, void *_l3)
167{
sricharaned0e3522011-08-24 20:07:45 +0530168 struct omap3_l3 *l3 = _l3;
169 u64 status, clear;
170 u64 error;
171 u64 error_addr;
172 u64 err_source = 0;
173 void __iomem *base;
174 int int_type;
175 irqreturn_t ret = IRQ_NONE;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530176
omar ramirez35f7b962011-04-18 16:39:42 +0000177 int_type = irq == l3->app_irq ? L3_APPLICATION_ERROR : L3_DEBUG_ERROR;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530178 if (!int_type) {
179 status = omap3_l3_readll(l3->rt, L3_SI_FLAG_STATUS_0);
180 /*
181 * if we have a timeout error, there's nothing we can
182 * do besides rebooting the board. So let's BUG on any
183 * of such errors and handle the others. timeout error
184 * is severe and not expected to occur.
185 */
186 BUG_ON(status & L3_STATUS_0_TIMEOUT_MASK);
187 } else {
188 status = omap3_l3_readll(l3->rt, L3_SI_FLAG_STATUS_1);
189 /* No timeout error for debug sources */
190 }
191
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530192 /* identify the error source */
Todd Poynor342fd142011-08-24 19:11:39 +0530193 err_source = __ffs(status);
omar ramirezbc16b372011-04-26 02:24:50 -0700194
Todd Poynor342fd142011-08-24 19:11:39 +0530195 base = l3->rt + omap3_l3_bases[int_type][err_source];
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530196 error = omap3_l3_readll(base, L3_ERROR_LOG);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530197 if (error) {
198 error_addr = omap3_l3_readll(base, L3_ERROR_LOG_ADDR);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530199 ret |= omap3_l3_block_irq(l3, error, error_addr);
200 }
201
202 /* Clear the status register */
omar ramirez35f7b962011-04-18 16:39:42 +0000203 clear = (L3_AGENT_STATUS_CLEAR_IA << int_type) |
204 L3_AGENT_STATUS_CLEAR_TA;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530205 omap3_l3_writell(base, L3_AGENT_STATUS, clear);
206
207 /* clear the error log register */
208 omap3_l3_writell(base, L3_ERROR_LOG, error);
209
210 return ret;
211}
212
213static int __init omap3_l3_probe(struct platform_device *pdev)
214{
sricharaned0e3522011-08-24 20:07:45 +0530215 struct omap3_l3 *l3;
216 struct resource *res;
217 int ret;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530218
219 l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
omar ramirez7529b702011-04-18 16:39:41 +0000220 if (!l3)
221 return -ENOMEM;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530222
223 platform_set_drvdata(pdev, l3);
224
225 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
226 if (!res) {
227 dev_err(&pdev->dev, "couldn't find resource\n");
228 ret = -ENODEV;
omar ramirez7529b702011-04-18 16:39:41 +0000229 goto err0;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530230 }
231 l3->rt = ioremap(res->start, resource_size(res));
omar ramirez35f7b962011-04-18 16:39:42 +0000232 if (!l3->rt) {
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530233 dev_err(&pdev->dev, "ioremap failed\n");
234 ret = -ENOMEM;
omar ramirez7529b702011-04-18 16:39:41 +0000235 goto err0;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530236 }
237
Aaro Koskinen18a81012011-03-18 16:53:20 -0700238 l3->debug_irq = platform_get_irq(pdev, 0);
239 ret = request_irq(l3->debug_irq, omap3_l3_app_irq,
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530240 IRQF_DISABLED | IRQF_TRIGGER_RISING,
241 "l3-debug-irq", l3);
242 if (ret) {
243 dev_err(&pdev->dev, "couldn't request debug irq\n");
omar ramirez7529b702011-04-18 16:39:41 +0000244 goto err1;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530245 }
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530246
Aaro Koskinen18a81012011-03-18 16:53:20 -0700247 l3->app_irq = platform_get_irq(pdev, 1);
248 ret = request_irq(l3->app_irq, omap3_l3_app_irq,
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530249 IRQF_DISABLED | IRQF_TRIGGER_RISING,
250 "l3-app-irq", l3);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530251 if (ret) {
252 dev_err(&pdev->dev, "couldn't request app irq\n");
omar ramirez7529b702011-04-18 16:39:41 +0000253 goto err2;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530254 }
255
omar ramirez7529b702011-04-18 16:39:41 +0000256 return 0;
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530257
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530258err2:
omar ramirez7529b702011-04-18 16:39:41 +0000259 free_irq(l3->debug_irq, l3);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530260err1:
omar ramirez7529b702011-04-18 16:39:41 +0000261 iounmap(l3->rt);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530262err0:
omar ramirez7529b702011-04-18 16:39:41 +0000263 kfree(l3);
Felipe Balbie2fa61d2011-03-07 19:35:20 +0530264 return ret;
265}
266
267static int __exit omap3_l3_remove(struct platform_device *pdev)
268{
269 struct omap3_l3 *l3 = platform_get_drvdata(pdev);
270
271 free_irq(l3->app_irq, l3);
272 free_irq(l3->debug_irq, l3);
273 iounmap(l3->rt);
274 kfree(l3);
275
276 return 0;
277}
278
279static struct platform_driver omap3_l3_driver = {
280 .remove = __exit_p(omap3_l3_remove),
281 .driver = {
282 .name = "omap_l3_smx",
283 },
284};
285
286static int __init omap3_l3_init(void)
287{
288 return platform_driver_probe(&omap3_l3_driver, omap3_l3_probe);
289}
290postcore_initcall_sync(omap3_l3_init);
291
292static void __exit omap3_l3_exit(void)
293{
294 platform_driver_unregister(&omap3_l3_driver);
295}
296module_exit(omap3_l3_exit);