omap_l3_smx.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  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. */
  24. #include <linux/kernel.h>
  25. #include <linux/slab.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/io.h>
  29. #include "omap_l3_smx.h"
  30. static inline u64 omap3_l3_readll(void __iomem *base, u16 reg)
  31. {
  32. return __raw_readll(base + reg);
  33. }
  34. static inline void omap3_l3_writell(void __iomem *base, u16 reg, u64 value)
  35. {
  36. __raw_writell(value, base + reg);
  37. }
  38. static inline enum omap3_l3_code omap3_l3_decode_error_code(u64 error)
  39. {
  40. return (error & 0x0f000000) >> L3_ERROR_LOG_CODE;
  41. }
  42. static inline u32 omap3_l3_decode_addr(u64 error_addr)
  43. {
  44. return error_addr & 0xffffffff;
  45. }
  46. static inline unsigned omap3_l3_decode_cmd(u64 error)
  47. {
  48. return (error & 0x07) >> L3_ERROR_LOG_CMD;
  49. }
  50. static inline enum omap3_l3_initiator_id omap3_l3_decode_initid(u64 error)
  51. {
  52. return (error & 0xff00) >> L3_ERROR_LOG_INITID;
  53. }
  54. static inline unsigned omap3_l3_decode_req_info(u64 error)
  55. {
  56. return (error >> 32) & 0xffff;
  57. }
  58. static char *omap3_l3_code_string(u8 code)
  59. {
  60. switch (code) {
  61. case OMAP_L3_CODE_NOERROR:
  62. return "No Error";
  63. case OMAP_L3_CODE_UNSUP_CMD:
  64. return "Unsupported Command";
  65. case OMAP_L3_CODE_ADDR_HOLE:
  66. return "Address Hole";
  67. case OMAP_L3_CODE_PROTECT_VIOLATION:
  68. return "Protection Violation";
  69. case OMAP_L3_CODE_IN_BAND_ERR:
  70. return "In-band Error";
  71. case OMAP_L3_CODE_REQ_TOUT_NOT_ACCEPT:
  72. return "Request Timeout Not Accepted";
  73. case OMAP_L3_CODE_REQ_TOUT_NO_RESP:
  74. return "Request Timeout, no response";
  75. default:
  76. return "UNKNOWN error";
  77. }
  78. }
  79. static char *omap3_l3_initiator_string(u8 initid)
  80. {
  81. switch (initid) {
  82. case OMAP_L3_LCD:
  83. return "LCD";
  84. case OMAP_L3_SAD2D:
  85. return "SAD2D";
  86. case OMAP_L3_IA_MPU_SS_1:
  87. case OMAP_L3_IA_MPU_SS_2:
  88. case OMAP_L3_IA_MPU_SS_3:
  89. case OMAP_L3_IA_MPU_SS_4:
  90. case OMAP_L3_IA_MPU_SS_5:
  91. return "MPU";
  92. case OMAP_L3_IA_IVA_SS_1:
  93. case OMAP_L3_IA_IVA_SS_2:
  94. case OMAP_L3_IA_IVA_SS_3:
  95. return "IVA_SS";
  96. case OMAP_L3_IA_IVA_SS_DMA_1:
  97. case OMAP_L3_IA_IVA_SS_DMA_2:
  98. case OMAP_L3_IA_IVA_SS_DMA_3:
  99. case OMAP_L3_IA_IVA_SS_DMA_4:
  100. case OMAP_L3_IA_IVA_SS_DMA_5:
  101. case OMAP_L3_IA_IVA_SS_DMA_6:
  102. return "IVA_SS_DMA";
  103. case OMAP_L3_IA_SGX:
  104. return "SGX";
  105. case OMAP_L3_IA_CAM_1:
  106. case OMAP_L3_IA_CAM_2:
  107. case OMAP_L3_IA_CAM_3:
  108. return "CAM";
  109. case OMAP_L3_IA_DAP:
  110. return "DAP";
  111. case OMAP_L3_SDMA_WR_1:
  112. case OMAP_L3_SDMA_WR_2:
  113. return "SDMA_WR";
  114. case OMAP_L3_SDMA_RD_1:
  115. case OMAP_L3_SDMA_RD_2:
  116. case OMAP_L3_SDMA_RD_3:
  117. case OMAP_L3_SDMA_RD_4:
  118. return "SDMA_RD";
  119. case OMAP_L3_USBOTG:
  120. return "USB_OTG";
  121. case OMAP_L3_USBHOST:
  122. return "USB_HOST";
  123. default:
  124. return "UNKNOWN Initiator";
  125. }
  126. }
  127. /**
  128. * omap3_l3_block_irq - handles a register block's irq
  129. * @l3: struct omap3_l3 *
  130. * @base: register block base address
  131. * @error: L3_ERROR_LOG register of our block
  132. *
  133. * Called in hard-irq context. Caller should take care of locking
  134. *
  135. * OMAP36xx TRM gives, on page 2001, Figure 9-10, the Typical Error
  136. * Analysis Sequence, we are following that sequence here, please
  137. * refer to that Figure for more information on the subject.
  138. */
  139. static irqreturn_t omap3_l3_block_irq(struct omap3_l3 *l3,
  140. u64 error, int error_addr)
  141. {
  142. u8 code = omap3_l3_decode_error_code(error);
  143. u8 initid = omap3_l3_decode_initid(error);
  144. u8 multi = error & L3_ERROR_LOG_MULTI;
  145. u32 address = omap3_l3_decode_addr(error_addr);
  146. WARN(true, "%s seen by %s %s at address %x\n",
  147. omap3_l3_code_string(code),
  148. omap3_l3_initiator_string(initid),
  149. multi ? "Multiple Errors" : "",
  150. address);
  151. return IRQ_HANDLED;
  152. }
  153. static irqreturn_t omap3_l3_app_irq(int irq, void *_l3)
  154. {
  155. struct omap3_l3 *l3 = _l3;
  156. u64 status, clear;
  157. u64 error;
  158. u64 error_addr;
  159. u64 err_source = 0;
  160. void __iomem *base;
  161. int int_type;
  162. irqreturn_t ret = IRQ_NONE;
  163. int_type = irq == l3->app_irq ? L3_APPLICATION_ERROR : L3_DEBUG_ERROR;
  164. if (!int_type) {
  165. status = omap3_l3_readll(l3->rt, L3_SI_FLAG_STATUS_0);
  166. /*
  167. * if we have a timeout error, there's nothing we can
  168. * do besides rebooting the board. So let's BUG on any
  169. * of such errors and handle the others. timeout error
  170. * is severe and not expected to occur.
  171. */
  172. BUG_ON(status & L3_STATUS_0_TIMEOUT_MASK);
  173. } else {
  174. status = omap3_l3_readll(l3->rt, L3_SI_FLAG_STATUS_1);
  175. /* No timeout error for debug sources */
  176. }
  177. /* identify the error source */
  178. for (err_source = 0; !(status & (1 << err_source)); err_source++)
  179. ;
  180. base = l3->rt + *(omap3_l3_bases[int_type] + err_source);
  181. error = omap3_l3_readll(base, L3_ERROR_LOG);
  182. if (error) {
  183. error_addr = omap3_l3_readll(base, L3_ERROR_LOG_ADDR);
  184. ret |= omap3_l3_block_irq(l3, error, error_addr);
  185. }
  186. /* Clear the status register */
  187. clear = (L3_AGENT_STATUS_CLEAR_IA << int_type) |
  188. L3_AGENT_STATUS_CLEAR_TA;
  189. omap3_l3_writell(base, L3_AGENT_STATUS, clear);
  190. /* clear the error log register */
  191. omap3_l3_writell(base, L3_ERROR_LOG, error);
  192. return ret;
  193. }
  194. static int __init omap3_l3_probe(struct platform_device *pdev)
  195. {
  196. struct omap3_l3 *l3;
  197. struct resource *res;
  198. int ret;
  199. l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
  200. if (!l3)
  201. return -ENOMEM;
  202. platform_set_drvdata(pdev, l3);
  203. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  204. if (!res) {
  205. dev_err(&pdev->dev, "couldn't find resource\n");
  206. ret = -ENODEV;
  207. goto err0;
  208. }
  209. l3->rt = ioremap(res->start, resource_size(res));
  210. if (!l3->rt) {
  211. dev_err(&pdev->dev, "ioremap failed\n");
  212. ret = -ENOMEM;
  213. goto err0;
  214. }
  215. l3->debug_irq = platform_get_irq(pdev, 0);
  216. ret = request_irq(l3->debug_irq, omap3_l3_app_irq,
  217. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  218. "l3-debug-irq", l3);
  219. if (ret) {
  220. dev_err(&pdev->dev, "couldn't request debug irq\n");
  221. goto err1;
  222. }
  223. l3->app_irq = platform_get_irq(pdev, 1);
  224. ret = request_irq(l3->app_irq, omap3_l3_app_irq,
  225. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  226. "l3-app-irq", l3);
  227. if (ret) {
  228. dev_err(&pdev->dev, "couldn't request app irq\n");
  229. goto err2;
  230. }
  231. return 0;
  232. err2:
  233. free_irq(l3->debug_irq, l3);
  234. err1:
  235. iounmap(l3->rt);
  236. err0:
  237. kfree(l3);
  238. return ret;
  239. }
  240. static int __exit omap3_l3_remove(struct platform_device *pdev)
  241. {
  242. struct omap3_l3 *l3 = platform_get_drvdata(pdev);
  243. free_irq(l3->app_irq, l3);
  244. free_irq(l3->debug_irq, l3);
  245. iounmap(l3->rt);
  246. kfree(l3);
  247. return 0;
  248. }
  249. static struct platform_driver omap3_l3_driver = {
  250. .remove = __exit_p(omap3_l3_remove),
  251. .driver = {
  252. .name = "omap_l3_smx",
  253. },
  254. };
  255. static int __init omap3_l3_init(void)
  256. {
  257. return platform_driver_probe(&omap3_l3_driver, omap3_l3_probe);
  258. }
  259. postcore_initcall_sync(omap3_l3_init);
  260. static void __exit omap3_l3_exit(void)
  261. {
  262. platform_driver_unregister(&omap3_l3_driver);
  263. }
  264. module_exit(omap3_l3_exit);