omap_l3_smx.c 7.0 KB

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