1*4882a593Smuzhiyun // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2*4882a593Smuzhiyun //
3*4882a593Smuzhiyun // Copyright 2020 NXP
4*4882a593Smuzhiyun //
5*4882a593Smuzhiyun // Common helpers for the audio DSP on i.MX8
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #include <linux/module.h>
8*4882a593Smuzhiyun #include <sound/sof/xtensa.h>
9*4882a593Smuzhiyun #include "../ops.h"
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include "imx-common.h"
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun /**
14*4882a593Smuzhiyun * imx8_get_registers() - This function is called in case of DSP oops
15*4882a593Smuzhiyun * in order to gather information about the registers, filename and
16*4882a593Smuzhiyun * linenumber and stack.
17*4882a593Smuzhiyun * @sdev: SOF device
18*4882a593Smuzhiyun * @xoops: Stores information about registers.
19*4882a593Smuzhiyun * @panic_info: Stores information about filename and line number.
20*4882a593Smuzhiyun * @stack: Stores the stack dump.
21*4882a593Smuzhiyun * @stack_words: Size of the stack dump.
22*4882a593Smuzhiyun */
imx8_get_registers(struct snd_sof_dev * sdev,struct sof_ipc_dsp_oops_xtensa * xoops,struct sof_ipc_panic_info * panic_info,u32 * stack,size_t stack_words)23*4882a593Smuzhiyun void imx8_get_registers(struct snd_sof_dev *sdev,
24*4882a593Smuzhiyun struct sof_ipc_dsp_oops_xtensa *xoops,
25*4882a593Smuzhiyun struct sof_ipc_panic_info *panic_info,
26*4882a593Smuzhiyun u32 *stack, size_t stack_words)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun u32 offset = sdev->dsp_oops_offset;
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /* first read registers */
31*4882a593Smuzhiyun sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /* then get panic info */
34*4882a593Smuzhiyun if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
35*4882a593Smuzhiyun dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
36*4882a593Smuzhiyun xoops->arch_hdr.totalsize);
37*4882a593Smuzhiyun return;
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun offset += xoops->arch_hdr.totalsize;
40*4882a593Smuzhiyun sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /* then get the stack */
43*4882a593Smuzhiyun offset += sizeof(*panic_info);
44*4882a593Smuzhiyun sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun * imx8_dump() - This function is called when a panic message is
49*4882a593Smuzhiyun * received from the firmware.
50*4882a593Smuzhiyun */
imx8_dump(struct snd_sof_dev * sdev,u32 flags)51*4882a593Smuzhiyun void imx8_dump(struct snd_sof_dev *sdev, u32 flags)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun struct sof_ipc_dsp_oops_xtensa xoops;
54*4882a593Smuzhiyun struct sof_ipc_panic_info panic_info;
55*4882a593Smuzhiyun u32 stack[IMX8_STACK_DUMP_SIZE];
56*4882a593Smuzhiyun u32 status;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun /* Get information about the panic status from the debug box area.
59*4882a593Smuzhiyun * Compute the trace point based on the status.
60*4882a593Smuzhiyun */
61*4882a593Smuzhiyun sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun /* Get information about the registers, the filename and line
64*4882a593Smuzhiyun * number and the stack.
65*4882a593Smuzhiyun */
66*4882a593Smuzhiyun imx8_get_registers(sdev, &xoops, &panic_info, stack,
67*4882a593Smuzhiyun IMX8_STACK_DUMP_SIZE);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun /* Print the information to the console */
70*4882a593Smuzhiyun snd_sof_get_status(sdev, status, status, &xoops, &panic_info, stack,
71*4882a593Smuzhiyun IMX8_STACK_DUMP_SIZE);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun EXPORT_SYMBOL(imx8_dump);
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun MODULE_LICENSE("Dual BSD/GPL");
76