1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2022 MediaTek Inc. All rights reserved.
8 // Author: YC Hung <yc.hung@mediatek.com>
11 * Common helpers for the audio DSP on MediaTek platforms
14 #include <linux/module.h>
15 #include <sound/sof/xtensa.h>
17 #include "mtk-adsp-common.h"
20 * mtk_adsp_get_registers() - This function is called in case of DSP oops
21 * in order to gather information about the registers, filename and
22 * linenumber and stack.
24 * @xoops: Stores information about registers.
25 * @panic_info: Stores information about filename and line number.
26 * @stack: Stores the stack dump.
27 * @stack_words: Size of the stack dump.
29 static void mtk_adsp_get_registers(struct snd_sof_dev *sdev,
30 struct sof_ipc_dsp_oops_xtensa *xoops,
31 struct sof_ipc_panic_info *panic_info,
32 u32 *stack, size_t stack_words)
34 u32 offset = sdev->dsp_oops_offset;
36 /* first read registers */
37 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
39 /* then get panic info */
40 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
41 dev_err(sdev->dev, "invalid header size 0x%x\n",
42 xoops->arch_hdr.totalsize);
45 offset += xoops->arch_hdr.totalsize;
46 sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
48 /* then get the stack */
49 offset += sizeof(*panic_info);
50 sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
54 * mtk_adsp_dump() - This function is called when a panic message is
55 * received from the firmware.
57 * @flags: parameter not used but required by ops prototype
59 void mtk_adsp_dump(struct snd_sof_dev *sdev, u32 flags)
61 char *level = (flags & SOF_DBG_DUMP_OPTIONAL) ? KERN_DEBUG : KERN_ERR;
62 struct sof_ipc_dsp_oops_xtensa xoops;
63 struct sof_ipc_panic_info panic_info;
64 u32 stack[MTK_ADSP_STACK_DUMP_SIZE];
67 /* Get information about the panic status from the debug box area.
68 * Compute the trace point based on the status.
70 sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);
72 /* Get information about the registers, the filename and line
73 * number and the stack.
75 mtk_adsp_get_registers(sdev, &xoops, &panic_info, stack,
76 MTK_ADSP_STACK_DUMP_SIZE);
78 /* Print the information to the console */
79 sof_print_oops_and_stack(sdev, level, status, status, &xoops, &panic_info,
80 stack, MTK_ADSP_STACK_DUMP_SIZE);
82 EXPORT_SYMBOL(mtk_adsp_dump);
84 MODULE_LICENSE("Dual BSD/GPL");