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