Skip to content

Commit 3d8ae5f

Browse files
IulianOlaru249kv2019i
authored andcommitted
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 0f9b8fc commit 3d8ae5f

6 files changed

Lines changed: 137 additions & 2 deletions

File tree

sound/soc/sof/imx/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ config SND_SOC_SOF_IMX_OF
1919
This option is not user-selectable but automagically handled by
2020
'select' statements at a higher level
2121

22+
config SND_SOC_SOF_IMX_COMMON
23+
tristate
24+
help
25+
This option is not user-selectable but automagically handled by
26+
'select' statements at a higher level.
27+
2228
config SND_SOC_SOF_IMX8_SUPPORT
2329
bool "SOF support for i.MX8"
2430
depends on IMX_SCU=y || IMX_SCU=SND_SOC_SOF_IMX_OF
@@ -30,6 +36,7 @@ config SND_SOC_SOF_IMX8_SUPPORT
3036

3137
config SND_SOC_SOF_IMX8
3238
tristate
39+
select SND_SOC_SOF_IMX_COMMON
3340
select SND_SOC_SOF_XTENSA
3441
help
3542
This option is not user-selectable but automagically handled by
@@ -45,6 +52,7 @@ config SND_SOC_SOF_IMX8M_SUPPORT
4552

4653
config SND_SOC_SOF_IMX8M
4754
tristate
55+
select SND_SOC_SOF_IMX_COMMON
4856
select SND_SOC_SOF_XTENSA
4957
help
5058
This option is not user-selectable but automagically handled by

sound/soc/sof/imx/Makefile

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

5+
snd-sof-imx-common-objs := imx-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
9+
obj-$(CONFIG_SND_SOC_SOF_IMX_COMMON) += imx-common.o

sound/soc/sof/imx/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 "imx-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 registers */
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/imx-common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2+
3+
#ifndef __IMX_COMMON_H__
4+
#define __IMX_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+
16+
#endif

sound/soc/sof/imx/imx8.c

Lines changed: 22 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 "imx-common.h"
2425

2526
/* DSP memories */
2627
#define IRAM_OFFSET 0x10000
@@ -115,8 +116,16 @@ static void imx8_dsp_handle_reply(struct imx_dsp_ipc *ipc)
115116
static void imx8_dsp_handle_request(struct imx_dsp_ipc *ipc)
116117
{
117118
struct imx8_priv *priv = imx_dsp_get_data(ipc);
119+
u32 p; /* panic code */
118120

119-
snd_sof_ipc_msgs_rx(priv->sdev);
121+
/* Read the message from the debug box. */
122+
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, sizeof(p));
123+
124+
/* Check to see if the message is a panic code (0x0dead***) */
125+
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
126+
snd_sof_dsp_panic(priv->sdev, p);
127+
else
128+
snd_sof_ipc_msgs_rx(priv->sdev);
120129
}
121130

122131
static struct imx_dsp_ops dsp_ops = {
@@ -409,6 +418,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
409418
.block_read = sof_block_read,
410419
.block_write = sof_block_write,
411420

421+
/* Module IO */
422+
.read64 = sof_io_read64,
423+
412424
/* ipc */
413425
.send_msg = imx8_send_msg,
414426
.fw_ready = sof_fw_ready,
@@ -424,6 +436,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
424436
/* firmware loading */
425437
.load_firmware = snd_sof_load_firmware_memcpy,
426438

439+
/* Debug information */
440+
.dbg_dump = imx8_dump,
441+
427442
/* Firmware ops */
428443
.arch_ops = &sof_xtensa_arch_ops,
429444

@@ -452,6 +467,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
452467
.block_read = sof_block_read,
453468
.block_write = sof_block_write,
454469

470+
/* Module IO */
471+
.read64 = sof_io_read64,
472+
455473
/* ipc */
456474
.send_msg = imx8_send_msg,
457475
.fw_ready = sof_fw_ready,
@@ -467,6 +485,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
467485
/* firmware loading */
468486
.load_firmware = snd_sof_load_firmware_memcpy,
469487

488+
/* Debug information */
489+
.dbg_dump = imx8_dump,
490+
470491
/* Firmware ops */
471492
.arch_ops = &sof_xtensa_arch_ops,
472493

sound/soc/sof/imx/imx8m.c

Lines changed: 16 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 "imx-common.h"
2021

2122
#define MBOX_OFFSET 0x800000
2223
#define MBOX_SIZE 0x1000
@@ -88,8 +89,16 @@ static void imx8m_dsp_handle_reply(struct imx_dsp_ipc *ipc)
8889
static void imx8m_dsp_handle_request(struct imx_dsp_ipc *ipc)
8990
{
9091
struct imx8m_priv *priv = imx_dsp_get_data(ipc);
92+
u32 p; /* Panic code */
9193

92-
snd_sof_ipc_msgs_rx(priv->sdev);
94+
/* Read the message from the debug box. */
95+
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, sizeof(p));
96+
97+
/* Check to see if the message is a panic code (0x0dead***) */
98+
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
99+
snd_sof_dsp_panic(priv->sdev, p);
100+
else
101+
snd_sof_ipc_msgs_rx(priv->sdev);
93102
}
94103

95104
static struct imx_dsp_ops imx8m_dsp_ops = {
@@ -262,6 +271,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
262271
.block_read = sof_block_read,
263272
.block_write = sof_block_write,
264273

274+
/* Module IO */
275+
.read64 = sof_io_read64,
276+
265277
/* ipc */
266278
.send_msg = imx8m_send_msg,
267279
.fw_ready = sof_fw_ready,
@@ -277,6 +289,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
277289
/* firmware loading */
278290
.load_firmware = snd_sof_load_firmware_memcpy,
279291

292+
/* Debug information */
293+
.dbg_dump = imx8_dump,
294+
280295
/* Firmware ops */
281296
.arch_ops = &sof_xtensa_arch_ops,
282297

0 commit comments

Comments
 (0)