core.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2018 Intel Corporation
  7. //
  8. // Author: Pan Xiuli <xiuli.pan@linux.intel.com>
  9. //
  10. #include <linux/module.h>
  11. #include <sound/sof.h>
  12. #include <sound/sof/xtensa.h>
  13. #include "../sof-priv.h"
  14. struct xtensa_exception_cause {
  15. u32 id;
  16. const char *msg;
  17. const char *description;
  18. };
  19. /*
  20. * From 4.4.1.5 table 4-64 Exception Causes of Xtensa
  21. * Instruction Set Architecture (ISA) Reference Manual
  22. */
  23. static const struct xtensa_exception_cause xtensa_exception_causes[] = {
  24. {0, "IllegalInstructionCause", "Illegal instruction"},
  25. {1, "SyscallCause", "SYSCALL instruction"},
  26. {2, "InstructionFetchErrorCause",
  27. "Processor internal physical address or data error during instruction fetch"},
  28. {3, "LoadStoreErrorCause",
  29. "Processor internal physical address or data error during load or store"},
  30. {4, "Level1InterruptCause",
  31. "Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register"},
  32. {5, "AllocaCause",
  33. "MOVSP instruction, if caller’s registers are not in the register file"},
  34. {6, "IntegerDivideByZeroCause",
  35. "QUOS, QUOU, REMS, or REMU divisor operand is zero"},
  36. {8, "PrivilegedCause",
  37. "Attempt to execute a privileged operation when CRING ? 0"},
  38. {9, "LoadStoreAlignmentCause", "Load or store to an unaligned address"},
  39. {12, "InstrPIFDataErrorCause",
  40. "PIF data error during instruction fetch"},
  41. {13, "LoadStorePIFDataErrorCause",
  42. "Synchronous PIF data error during LoadStore access"},
  43. {14, "InstrPIFAddrErrorCause",
  44. "PIF address error during instruction fetch"},
  45. {15, "LoadStorePIFAddrErrorCause",
  46. "Synchronous PIF address error during LoadStore access"},
  47. {16, "InstTLBMissCause", "Error during Instruction TLB refill"},
  48. {17, "InstTLBMultiHitCause",
  49. "Multiple instruction TLB entries matched"},
  50. {18, "InstFetchPrivilegeCause",
  51. "An instruction fetch referenced a virtual address at a ring level less than CRING"},
  52. {20, "InstFetchProhibitedCause",
  53. "An instruction fetch referenced a page mapped with an attribute that does not permit instruction fetch"},
  54. {24, "LoadStoreTLBMissCause",
  55. "Error during TLB refill for a load or store"},
  56. {25, "LoadStoreTLBMultiHitCause",
  57. "Multiple TLB entries matched for a load or store"},
  58. {26, "LoadStorePrivilegeCause",
  59. "A load or store referenced a virtual address at a ring level less than CRING"},
  60. {28, "LoadProhibitedCause",
  61. "A load referenced a page mapped with an attribute that does not permit loads"},
  62. {32, "Coprocessor0Disabled",
  63. "Coprocessor 0 instruction when cp0 disabled"},
  64. {33, "Coprocessor1Disabled",
  65. "Coprocessor 1 instruction when cp1 disabled"},
  66. {34, "Coprocessor2Disabled",
  67. "Coprocessor 2 instruction when cp2 disabled"},
  68. {35, "Coprocessor3Disabled",
  69. "Coprocessor 3 instruction when cp3 disabled"},
  70. {36, "Coprocessor4Disabled",
  71. "Coprocessor 4 instruction when cp4 disabled"},
  72. {37, "Coprocessor5Disabled",
  73. "Coprocessor 5 instruction when cp5 disabled"},
  74. {38, "Coprocessor6Disabled",
  75. "Coprocessor 6 instruction when cp6 disabled"},
  76. {39, "Coprocessor7Disabled",
  77. "Coprocessor 7 instruction when cp7 disabled"},
  78. };
  79. /* only need xtensa atm */
  80. static void xtensa_dsp_oops(struct snd_sof_dev *sdev, const char *level, void *oops)
  81. {
  82. struct sof_ipc_dsp_oops_xtensa *xoops = oops;
  83. int i;
  84. dev_printk(level, sdev->dev, "error: DSP Firmware Oops\n");
  85. for (i = 0; i < ARRAY_SIZE(xtensa_exception_causes); i++) {
  86. if (xtensa_exception_causes[i].id == xoops->exccause) {
  87. dev_printk(level, sdev->dev,
  88. "error: Exception Cause: %s, %s\n",
  89. xtensa_exception_causes[i].msg,
  90. xtensa_exception_causes[i].description);
  91. }
  92. }
  93. dev_printk(level, sdev->dev,
  94. "EXCCAUSE 0x%8.8x EXCVADDR 0x%8.8x PS 0x%8.8x SAR 0x%8.8x\n",
  95. xoops->exccause, xoops->excvaddr, xoops->ps, xoops->sar);
  96. dev_printk(level, sdev->dev,
  97. "EPC1 0x%8.8x EPC2 0x%8.8x EPC3 0x%8.8x EPC4 0x%8.8x",
  98. xoops->epc1, xoops->epc2, xoops->epc3, xoops->epc4);
  99. dev_printk(level, sdev->dev,
  100. "EPC5 0x%8.8x EPC6 0x%8.8x EPC7 0x%8.8x DEPC 0x%8.8x",
  101. xoops->epc5, xoops->epc6, xoops->epc7, xoops->depc);
  102. dev_printk(level, sdev->dev,
  103. "EPS2 0x%8.8x EPS3 0x%8.8x EPS4 0x%8.8x EPS5 0x%8.8x",
  104. xoops->eps2, xoops->eps3, xoops->eps4, xoops->eps5);
  105. dev_printk(level, sdev->dev,
  106. "EPS6 0x%8.8x EPS7 0x%8.8x INTENABL 0x%8.8x INTERRU 0x%8.8x",
  107. xoops->eps6, xoops->eps7, xoops->intenable, xoops->interrupt);
  108. }
  109. static void xtensa_stack(struct snd_sof_dev *sdev, const char *level, void *oops,
  110. u32 *stack, u32 stack_words)
  111. {
  112. struct sof_ipc_dsp_oops_xtensa *xoops = oops;
  113. u32 stack_ptr = xoops->plat_hdr.stackptr;
  114. /* 4 * 8chars + 3 ws + 1 terminating NUL */
  115. unsigned char buf[4 * 8 + 3 + 1];
  116. int i;
  117. dev_printk(level, sdev->dev, "stack dump from 0x%8.8x\n", stack_ptr);
  118. /*
  119. * example output:
  120. * 0x0049fbb0: 8000f2d0 0049fc00 6f6c6c61 00632e63
  121. */
  122. for (i = 0; i < stack_words; i += 4) {
  123. hex_dump_to_buffer(stack + i, 16, 16, 4,
  124. buf, sizeof(buf), false);
  125. dev_printk(level, sdev->dev, "0x%08x: %s\n", stack_ptr + i * 4, buf);
  126. }
  127. if (!xoops->plat_hdr.numaregs)
  128. return;
  129. dev_printk(level, sdev->dev, "AR registers:\n");
  130. /* the number of ar registers is a multiple of 4 */
  131. for (i = 0; i < xoops->plat_hdr.numaregs; i += 4) {
  132. hex_dump_to_buffer(xoops->ar + i, 16, 16, 4,
  133. buf, sizeof(buf), false);
  134. dev_printk(level, sdev->dev, "%#x: %s\n", i * 4, buf);
  135. }
  136. }
  137. const struct dsp_arch_ops sof_xtensa_arch_ops = {
  138. .dsp_oops = xtensa_dsp_oops,
  139. .dsp_stack = xtensa_stack,
  140. };
  141. EXPORT_SYMBOL_NS(sof_xtensa_arch_ops, "SND_SOC_SOF_XTENSA");
  142. MODULE_LICENSE("Dual BSD/GPL");
  143. MODULE_DESCRIPTION("SOF Xtensa DSP support");