118ebffe4SIulian Olaru // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 218ebffe4SIulian Olaru // 318ebffe4SIulian Olaru // Copyright 2020 NXP 418ebffe4SIulian Olaru // 518ebffe4SIulian Olaru // Common helpers for the audio DSP on i.MX8 618ebffe4SIulian Olaru 75b51b922SKai Vehmanen #include <linux/module.h> 818ebffe4SIulian Olaru #include <sound/sof/xtensa.h> 918ebffe4SIulian Olaru #include "../ops.h" 1018ebffe4SIulian Olaru 1118ebffe4SIulian Olaru #include "imx-common.h" 1218ebffe4SIulian Olaru 1318ebffe4SIulian Olaru /** 1418ebffe4SIulian Olaru * imx8_get_registers() - This function is called in case of DSP oops 1518ebffe4SIulian Olaru * in order to gather information about the registers, filename and 1618ebffe4SIulian Olaru * linenumber and stack. 1718ebffe4SIulian Olaru * @sdev: SOF device 1818ebffe4SIulian Olaru * @xoops: Stores information about registers. 1918ebffe4SIulian Olaru * @panic_info: Stores information about filename and line number. 2018ebffe4SIulian Olaru * @stack: Stores the stack dump. 2118ebffe4SIulian Olaru * @stack_words: Size of the stack dump. 2218ebffe4SIulian Olaru */ 2318ebffe4SIulian Olaru void imx8_get_registers(struct snd_sof_dev *sdev, 2418ebffe4SIulian Olaru struct sof_ipc_dsp_oops_xtensa *xoops, 2518ebffe4SIulian Olaru struct sof_ipc_panic_info *panic_info, 2618ebffe4SIulian Olaru u32 *stack, size_t stack_words) 2718ebffe4SIulian Olaru { 2818ebffe4SIulian Olaru u32 offset = sdev->dsp_oops_offset; 2918ebffe4SIulian Olaru 3018ebffe4SIulian Olaru /* first read registers */ 3118ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops)); 3218ebffe4SIulian Olaru 3318ebffe4SIulian Olaru /* then get panic info */ 3418ebffe4SIulian Olaru if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) { 3518ebffe4SIulian Olaru dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n", 3618ebffe4SIulian Olaru xoops->arch_hdr.totalsize); 3718ebffe4SIulian Olaru return; 3818ebffe4SIulian Olaru } 3918ebffe4SIulian Olaru offset += xoops->arch_hdr.totalsize; 4018ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info)); 4118ebffe4SIulian Olaru 4218ebffe4SIulian Olaru /* then get the stack */ 4318ebffe4SIulian Olaru offset += sizeof(*panic_info); 4418ebffe4SIulian Olaru sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32)); 4518ebffe4SIulian Olaru } 4618ebffe4SIulian Olaru 4718ebffe4SIulian Olaru /** 4818ebffe4SIulian Olaru * imx8_dump() - This function is called when a panic message is 4918ebffe4SIulian Olaru * received from the firmware. 50*45c29d9aSPierre-Louis Bossart * @sdev: SOF device 51*45c29d9aSPierre-Louis Bossart * @flags: parameter not used but required by ops prototype 5218ebffe4SIulian Olaru */ 5318ebffe4SIulian Olaru void imx8_dump(struct snd_sof_dev *sdev, u32 flags) 5418ebffe4SIulian Olaru { 5518ebffe4SIulian Olaru struct sof_ipc_dsp_oops_xtensa xoops; 5618ebffe4SIulian Olaru struct sof_ipc_panic_info panic_info; 5718ebffe4SIulian Olaru u32 stack[IMX8_STACK_DUMP_SIZE]; 5818ebffe4SIulian Olaru u32 status; 5918ebffe4SIulian Olaru 6018ebffe4SIulian Olaru /* Get information about the panic status from the debug box area. 6118ebffe4SIulian Olaru * Compute the trace point based on the status. 6218ebffe4SIulian Olaru */ 6318ebffe4SIulian Olaru sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4); 6418ebffe4SIulian Olaru 6518ebffe4SIulian Olaru /* Get information about the registers, the filename and line 6618ebffe4SIulian Olaru * number and the stack. 6718ebffe4SIulian Olaru */ 6818ebffe4SIulian Olaru imx8_get_registers(sdev, &xoops, &panic_info, stack, 6918ebffe4SIulian Olaru IMX8_STACK_DUMP_SIZE); 7018ebffe4SIulian Olaru 7118ebffe4SIulian Olaru /* Print the information to the console */ 7218ebffe4SIulian Olaru snd_sof_get_status(sdev, status, status, &xoops, &panic_info, stack, 7318ebffe4SIulian Olaru IMX8_STACK_DUMP_SIZE); 7418ebffe4SIulian Olaru } 7518ebffe4SIulian Olaru EXPORT_SYMBOL(imx8_dump); 765b51b922SKai Vehmanen 775b51b922SKai Vehmanen MODULE_LICENSE("Dual BSD/GPL"); 78