Skip to content

Commit 51fde80

Browse files
ASoC: SOF: imx: Add debug support for imx platforms
This patch adds debug support for imx platforms. This is important in order to gather information about the state of the DSP in case of an oops and the reason for the oops. This is done by checking if a message with a panic code has been placed in the debug box, in the imx8_dsp_handle_request function from sof/imx. If positive, the function imx8_dump, added in common, will be called. The first step is to gather information about the registers, filename, line number and stack by calling the imx8_get_registers, added in common. Then the information will be printed to the console by calling the get_status function. Signed-off-by: Iulian Olaru <iulianolaru249@yahoo.com>
1 parent 9724bf0 commit 51fde80

5 files changed

Lines changed: 133 additions & 2 deletions

File tree

sound/soc/sof/imx/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
snd-sof-imx8-objs := imx8.o
33
snd-sof-imx8m-objs := imx8m.o
44

5+
snd-sof-imx-common-objs := common.o
6+
57
obj-$(CONFIG_SND_SOC_SOF_IMX8) += snd-sof-imx8.o
68
obj-$(CONFIG_SND_SOC_SOF_IMX8M) += snd-sof-imx8m.o

sound/soc/sof/imx/common.c

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

sound/soc/sof/imx/common.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2+
3+
#ifndef __COMMON_H__
4+
#define __COMMON_H__
5+
6+
#define EXCEPT_MAX_HDR_SIZE 0x400
7+
#define IMX8_STACK_DUMP_SIZE 32
8+
9+
void imx8_get_registers(struct snd_sof_dev *sdev,
10+
struct sof_ipc_dsp_oops_xtensa *xoops,
11+
struct sof_ipc_panic_info *panic_info,
12+
u32 *stack, size_t stack_words);
13+
14+
void imx8_dump(struct snd_sof_dev *sdev, u32 flags);
15+
#endif

sound/soc/sof/imx/imx8.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/firmware/imx/svc/misc.h>
2222
#include <dt-bindings/firmware/imx/rsrc.h>
2323
#include "../ops.h"
24+
#include "common.h"
2425

2526
/* DSP memories */
2627
#define IRAM_OFFSET 0x10000
@@ -116,7 +117,18 @@ static void imx8_dsp_handle_request(struct imx_dsp_ipc *ipc)
116117
{
117118
struct imx8_priv *priv = imx_dsp_get_data(ipc);
118119

119-
snd_sof_ipc_msgs_rx(priv->sdev);
120+
int p; /* panic code */
121+
122+
/* Read the message from the debug box. */
123+
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, 4);
124+
125+
/* Check to see if the message is a panic code (0x0dead***) */
126+
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
127+
/* Start panic routine */
128+
snd_sof_dsp_panic(priv->sdev, p);
129+
else
130+
/* If it is not a panic code, reply to the message. */
131+
snd_sof_ipc_msgs_rx(priv->sdev);
120132
}
121133

122134
static struct imx_dsp_ops dsp_ops = {
@@ -409,6 +421,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
409421
.block_read = sof_block_read,
410422
.block_write = sof_block_write,
411423

424+
/* Module IO */
425+
.read64 = sof_io_read64,
426+
412427
/* ipc */
413428
.send_msg = imx8_send_msg,
414429
.fw_ready = sof_fw_ready,
@@ -424,6 +439,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
424439
/* firmware loading */
425440
.load_firmware = snd_sof_load_firmware_memcpy,
426441

442+
/* Debug information */
443+
.dbg_dump = imx8_dump,
444+
427445
/* Firmware ops */
428446
.arch_ops = &sof_xtensa_arch_ops,
429447

@@ -452,6 +470,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
452470
.block_read = sof_block_read,
453471
.block_write = sof_block_write,
454472

473+
/* Module IO */
474+
.read64 = sof_io_read64,
475+
455476
/* ipc */
456477
.send_msg = imx8_send_msg,
457478
.fw_ready = sof_fw_ready,
@@ -467,6 +488,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
467488
/* firmware loading */
468489
.load_firmware = snd_sof_load_firmware_memcpy,
469490

491+
/* Debug information */
492+
.dbg_dump = imx8_dump,
493+
470494
/* Firmware ops */
471495
.arch_ops = &sof_xtensa_arch_ops,
472496

sound/soc/sof/imx/imx8m.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/firmware/imx/dsp.h>
1818

1919
#include "../ops.h"
20+
#include "common.h"
2021

2122
#define MBOX_OFFSET 0x800000
2223
#define MBOX_SIZE 0x1000
@@ -89,7 +90,18 @@ static void imx8m_dsp_handle_request(struct imx_dsp_ipc *ipc)
8990
{
9091
struct imx8m_priv *priv = imx_dsp_get_data(ipc);
9192

92-
snd_sof_ipc_msgs_rx(priv->sdev);
93+
int p; /* Panic code */
94+
95+
/* Read the message from the debug box. */
96+
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, 4);
97+
98+
/* Check to see if the message is a panic code (0x0dead***) */
99+
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
100+
/* Start panic routine */
101+
snd_sof_dsp_panic(priv->sdev, p);
102+
else
103+
/* If it is not a panic code, reply to the message. */
104+
snd_sof_ipc_msgs_rx(priv->sdev);
93105
}
94106

95107
static struct imx_dsp_ops imx8m_dsp_ops = {
@@ -262,6 +274,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
262274
.block_read = sof_block_read,
263275
.block_write = sof_block_write,
264276

277+
/* Module IO */
278+
.read64 = sof_io_read64,
279+
265280
/* ipc */
266281
.send_msg = imx8m_send_msg,
267282
.fw_ready = sof_fw_ready,
@@ -277,6 +292,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
277292
/* firmware loading */
278293
.load_firmware = snd_sof_load_firmware_memcpy,
279294

295+
/* Debug information */
296+
.dbg_dump = imx8_dump,
297+
280298
/* Firmware ops */
281299
.arch_ops = &sof_xtensa_arch_ops,
282300

0 commit comments

Comments
 (0)