Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 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 | */ |
| 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 | */ |
| 51 | void imx8_dump(struct snd_sof_dev *sdev, u32 flags) |
| 52 | { |
| 53 | struct sof_ipc_dsp_oops_xtensa xoops; |
| 54 | struct sof_ipc_panic_info panic_info; |
| 55 | u32 stack[IMX8_STACK_DUMP_SIZE]; |
| 56 | u32 status; |
| 57 | |
| 58 | /* Get information about the panic status from the debug box area. |
| 59 | * Compute the trace point based on the status. |
| 60 | */ |
| 61 | sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4); |
| 62 | |
| 63 | /* Get information about the registers, the filename and line |
| 64 | * number and the stack. |
| 65 | */ |
| 66 | imx8_get_registers(sdev, &xoops, &panic_info, stack, |
| 67 | IMX8_STACK_DUMP_SIZE); |
| 68 | |
| 69 | /* Print the information to the console */ |
| 70 | snd_sof_get_status(sdev, status, status, &xoops, &panic_info, stack, |
| 71 | IMX8_STACK_DUMP_SIZE); |
| 72 | } |
| 73 | EXPORT_SYMBOL(imx8_dump); |
| 74 | |
| 75 | MODULE_LICENSE("Dual BSD/GPL"); |