mtk-adsp-common.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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) 2022 MediaTek Inc. All rights reserved.
  7. //
  8. // Author: YC Hung <[email protected]>
  9. /*
  10. * Common helpers for the audio DSP on MediaTek platforms
  11. */
  12. #include <linux/module.h>
  13. #include <sound/sof/xtensa.h>
  14. #include "../ops.h"
  15. #include "mtk-adsp-common.h"
  16. /**
  17. * mtk_adsp_get_registers() - This function is called in case of DSP oops
  18. * in order to gather information about the registers, filename and
  19. * linenumber and stack.
  20. * @sdev: SOF device
  21. * @xoops: Stores information about registers.
  22. * @panic_info: Stores information about filename and line number.
  23. * @stack: Stores the stack dump.
  24. * @stack_words: Size of the stack dump.
  25. */
  26. static void mtk_adsp_get_registers(struct snd_sof_dev *sdev,
  27. struct sof_ipc_dsp_oops_xtensa *xoops,
  28. struct sof_ipc_panic_info *panic_info,
  29. u32 *stack, size_t stack_words)
  30. {
  31. u32 offset = sdev->dsp_oops_offset;
  32. /* first read registers */
  33. sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
  34. /* then get panic info */
  35. if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
  36. dev_err(sdev->dev, "invalid header size 0x%x\n",
  37. xoops->arch_hdr.totalsize);
  38. return;
  39. }
  40. offset += xoops->arch_hdr.totalsize;
  41. sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
  42. /* then get the stack */
  43. offset += sizeof(*panic_info);
  44. sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
  45. }
  46. /**
  47. * mtk_adsp_dump() - This function is called when a panic message is
  48. * received from the firmware.
  49. * @sdev: SOF device
  50. * @flags: parameter not used but required by ops prototype
  51. */
  52. void mtk_adsp_dump(struct snd_sof_dev *sdev, u32 flags)
  53. {
  54. char *level = (flags & SOF_DBG_DUMP_OPTIONAL) ? KERN_DEBUG : KERN_ERR;
  55. struct sof_ipc_dsp_oops_xtensa xoops;
  56. struct sof_ipc_panic_info panic_info = {};
  57. u32 stack[MTK_ADSP_STACK_DUMP_SIZE];
  58. u32 status;
  59. /* Get information about the panic status from the debug box area.
  60. * Compute the trace point based on the status.
  61. */
  62. sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);
  63. /* Get information about the registers, the filename and line
  64. * number and the stack.
  65. */
  66. mtk_adsp_get_registers(sdev, &xoops, &panic_info, stack,
  67. MTK_ADSP_STACK_DUMP_SIZE);
  68. /* Print the information to the console */
  69. sof_print_oops_and_stack(sdev, level, status, status, &xoops, &panic_info,
  70. stack, MTK_ADSP_STACK_DUMP_SIZE);
  71. }
  72. EXPORT_SYMBOL(mtk_adsp_dump);
  73. MODULE_LICENSE("Dual BSD/GPL");