Skip to content

Commit

Permalink
Merge series "ASoC: SOF: small fixes for 5.10" from Kai Vehmanen <kai…
Browse files Browse the repository at this point in the history
….vehmanen@linux.intel.com>:

Series that adds debug support for IMX platforms, more details to
FW version information, adds missing -EACCESS handling to
pm_runtime_get_sync() calls and a set of minor cosmetic, trace
verbosity and coding style issues.

Guennadi Liakhovetski (3):
  ASoC: SOF: (cosmetic) remove redundant "ret" variable uses
  ASoC: SOF: remove several superfluous type-casts
  ASoC: SOF: fix range checks

Iulian Olaru (1):
  ASoC: SOF: imx: Add debug support for imx platforms

Karol Trzcinski (1):
  ASoC: SOF: Add `src_hash` to `sof_ipc_fw_version` structure

Pierre-Louis Bossart (3):
  ASoC: SOF: debug: update test for pm_runtime_get_sync()
  ASoC: SOF: control: update test for pm_runtime_get_sync()
  ASoC: SOF: Intel: hda: reduce verbosity of boot error logs

 include/sound/sof/info.h         |  4 +-
 sound/soc/sof/control.c          | 62 +++++++++++++--------------
 sound/soc/sof/debug.c            |  2 +-
 sound/soc/sof/imx/Kconfig        |  8 ++++
 sound/soc/sof/imx/Makefile       |  3 ++
 sound/soc/sof/imx/imx-common.c   | 72 ++++++++++++++++++++++++++++++++
 sound/soc/sof/imx/imx-common.h   | 16 +++++++
 sound/soc/sof/imx/imx8.c         | 23 +++++++++-
 sound/soc/sof/imx/imx8m.c        | 17 +++++++-
 sound/soc/sof/intel/hda-loader.c | 16 +++----
 sound/soc/sof/intel/hda.c        | 12 ++++--
 sound/soc/sof/intel/hda.h        |  2 +
 sound/soc/sof/sof-audio.c        |  6 +--
 sound/soc/sof/sof-priv.h         |  8 ++++
 sound/soc/sof/topology.c         | 44 ++++++++++---------
 15 files changed, 226 insertions(+), 69 deletions(-)
 create mode 100644 sound/soc/sof/imx/imx-common.c
 create mode 100644 sound/soc/sof/imx/imx-common.h

--
2.27.0
  • Loading branch information
Mark Brown committed Sep 17, 2020
2 parents 4c3021f + 776100a commit e6937b6
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 69 deletions.
4 changes: 3 additions & 1 deletion include/sound/sof/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ struct sof_ipc_fw_version {
uint8_t time[10];
uint8_t tag[6];
uint32_t abi_version;
/* used to check FW and ldc file compatibility, reproducible value */
uint32_t src_hash;

/* reserved for future use */
uint32_t reserved[4];
uint32_t reserved[3];
} __packed;

/* FW ready Message - sent by firmware when boot has completed */
Expand Down
62 changes: 30 additions & 32 deletions sound/soc/sof/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size;
int ret = 0;

if (be->max > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev,
Expand All @@ -230,20 +229,20 @@ int snd_sof_bytes_get(struct snd_kcontrol *kcontrol,
return -EINVAL;
}

size = data->size + sizeof(*data);
if (size > be->max) {
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > be->max - sizeof(*data)) {
dev_err_ratelimited(scomp->dev,
"error: DSP sent %zu bytes max is %d\n",
size, be->max);
ret = -EINVAL;
goto out;
"error: %u bytes of control data is invalid, max is %zu\n",
data->size, be->max - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);

/* copy back to kcontrol */
memcpy(ucontrol->value.bytes.data, data, size);

out:
return ret;
return 0;
}

int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
Expand All @@ -255,7 +254,7 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *scomp = scontrol->scomp;
struct sof_ipc_ctrl_data *cdata = scontrol->control_data;
struct sof_abi_hdr *data = cdata->data;
size_t size = data->size + sizeof(*data);
size_t size;

if (be->max > sizeof(ucontrol->value.bytes.data)) {
dev_err_ratelimited(scomp->dev,
Expand All @@ -264,13 +263,16 @@ int snd_sof_bytes_put(struct snd_kcontrol *kcontrol,
return -EINVAL;
}

if (size > be->max) {
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (data->size > be->max - sizeof(*data)) {
dev_err_ratelimited(scomp->dev,
"error: size too big %zu bytes max is %d\n",
size, be->max);
"error: data size too big %u bytes max is %zu\n",
data->size, be->max - sizeof(*data));
return -EINVAL;
}

size = data->size + sizeof(*data);

/* copy from kcontrol */
memcpy(data, ucontrol->value.bytes.data, size);

Expand Down Expand Up @@ -337,7 +339,8 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
return -EINVAL;
}

if (cdata->data->size + sizeof(const struct sof_abi_hdr) > be->max) {
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
if (cdata->data->size > be->max - sizeof(const struct sof_abi_hdr)) {
dev_err_ratelimited(scomp->dev, "error: Mismatch in ABI data size (truncated?).\n");
return -EINVAL;
}
Expand Down Expand Up @@ -367,7 +370,7 @@ int snd_sof_bytes_ext_volatile_get(struct snd_kcontrol *kcontrol, unsigned int _
int err;

ret = pm_runtime_get_sync(scomp->dev);
if (ret < 0) {
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(scomp->dev, "error: bytes_ext get failed to resume %d\n", ret);
pm_runtime_put_noidle(scomp->dev);
return ret;
Expand Down Expand Up @@ -423,8 +426,7 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_tlv header;
struct snd_ctl_tlv __user *tlvd =
(struct snd_ctl_tlv __user *)binary_data;
int data_size;
int ret = 0;
size_t data_size;

/*
* Decrement the limit by ext bytes header size to
Expand All @@ -436,27 +438,23 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
cdata->data->magic = SOF_ABI_MAGIC;
cdata->data->abi = SOF_ABI_VERSION;

/* Prevent read of other kernel data or possibly corrupt response */
data_size = cdata->data->size + sizeof(const struct sof_abi_hdr);

/* check data size doesn't exceed max coming from topology */
if (data_size > be->max) {
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %d.\n",
data_size, be->max);
ret = -EINVAL;
goto out;
if (cdata->data->size > be->max - sizeof(const struct sof_abi_hdr)) {
dev_err_ratelimited(scomp->dev, "error: user data size %d exceeds max size %zu.\n",
cdata->data->size,
be->max - sizeof(const struct sof_abi_hdr));
return -EINVAL;
}

data_size = cdata->data->size + sizeof(const struct sof_abi_hdr);

header.numid = scontrol->cmd;
header.length = data_size;
if (copy_to_user(tlvd, &header, sizeof(const struct snd_ctl_tlv))) {
ret = -EFAULT;
goto out;
}
if (copy_to_user(tlvd, &header, sizeof(const struct snd_ctl_tlv)))
return -EFAULT;

if (copy_to_user(tlvd->tlv, cdata->data, data_size))
ret = -EFAULT;
return -EFAULT;

out:
return ret;
return 0;
}
2 changes: 1 addition & 1 deletion sound/soc/sof/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
}

ret = pm_runtime_get_sync(sdev->dev);
if (ret < 0) {
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(sdev->dev,
"error: debugfs write failed to resume %d\n",
ret);
Expand Down
8 changes: 8 additions & 0 deletions sound/soc/sof/imx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ config SND_SOC_SOF_IMX_OF
This option is not user-selectable but automagically handled by
'select' statements at a higher level

config SND_SOC_SOF_IMX_COMMON
tristate
help
This option is not user-selectable but automagically handled by
'select' statements at a higher level.

config SND_SOC_SOF_IMX8_SUPPORT
bool "SOF support for i.MX8"
depends on IMX_SCU=y || IMX_SCU=SND_SOC_SOF_IMX_OF
Expand All @@ -30,6 +36,7 @@ config SND_SOC_SOF_IMX8_SUPPORT

config SND_SOC_SOF_IMX8
tristate
select SND_SOC_SOF_IMX_COMMON
select SND_SOC_SOF_XTENSA
help
This option is not user-selectable but automagically handled by
Expand All @@ -45,6 +52,7 @@ config SND_SOC_SOF_IMX8M_SUPPORT

config SND_SOC_SOF_IMX8M
tristate
select SND_SOC_SOF_IMX_COMMON
select SND_SOC_SOF_XTENSA
help
This option is not user-selectable but automagically handled by
Expand Down
3 changes: 3 additions & 0 deletions sound/soc/sof/imx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
snd-sof-imx8-objs := imx8.o
snd-sof-imx8m-objs := imx8m.o

snd-sof-imx-common-objs := imx-common.o

obj-$(CONFIG_SND_SOC_SOF_IMX8) += snd-sof-imx8.o
obj-$(CONFIG_SND_SOC_SOF_IMX8M) += snd-sof-imx8m.o
obj-$(CONFIG_SND_SOC_SOF_IMX_COMMON) += imx-common.o
72 changes: 72 additions & 0 deletions sound/soc/sof/imx/imx-common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// Copyright 2020 NXP
//
// Common helpers for the audio DSP on i.MX8

#include <sound/sof/xtensa.h>
#include "../ops.h"

#include "imx-common.h"

/**
* imx8_get_registers() - This function is called in case of DSP oops
* in order to gather information about the registers, filename and
* linenumber and stack.
* @sdev: SOF device
* @xoops: Stores information about registers.
* @panic_info: Stores information about filename and line number.
* @stack: Stores the stack dump.
* @stack_words: Size of the stack dump.
*/
void 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)
{
u32 offset = sdev->dsp_oops_offset;

/* first read registers */
sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));

/* then get panic info */
if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
xoops->arch_hdr.totalsize);
return;
}
offset += xoops->arch_hdr.totalsize;
sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));

/* then get the stack */
offset += sizeof(*panic_info);
sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
}

/**
* imx8_dump() - This function is called when a panic message is
* received from the firmware.
*/
void imx8_dump(struct snd_sof_dev *sdev, u32 flags)
{
struct sof_ipc_dsp_oops_xtensa xoops;
struct sof_ipc_panic_info panic_info;
u32 stack[IMX8_STACK_DUMP_SIZE];
u32 status;

/* Get information about the panic status from the debug box area.
* Compute the trace point based on the status.
*/
sof_mailbox_read(sdev, sdev->debug_box.offset + 0x4, &status, 4);

/* Get information about the registers, the filename and line
* number and the stack.
*/
imx8_get_registers(sdev, &xoops, &panic_info, stack,
IMX8_STACK_DUMP_SIZE);

/* Print the information to the console */
snd_sof_get_status(sdev, status, status, &xoops, &panic_info, stack,
IMX8_STACK_DUMP_SIZE);
}
EXPORT_SYMBOL(imx8_dump);
16 changes: 16 additions & 0 deletions sound/soc/sof/imx/imx-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */

#ifndef __IMX_COMMON_H__
#define __IMX_COMMON_H__

#define EXCEPT_MAX_HDR_SIZE 0x400
#define IMX8_STACK_DUMP_SIZE 32

void 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);

void imx8_dump(struct snd_sof_dev *sdev, u32 flags);

#endif
23 changes: 22 additions & 1 deletion sound/soc/sof/imx/imx8.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/firmware/imx/svc/misc.h>
#include <dt-bindings/firmware/imx/rsrc.h>
#include "../ops.h"
#include "imx-common.h"

/* DSP memories */
#define IRAM_OFFSET 0x10000
Expand Down Expand Up @@ -115,8 +116,16 @@ static void imx8_dsp_handle_reply(struct imx_dsp_ipc *ipc)
static void imx8_dsp_handle_request(struct imx_dsp_ipc *ipc)
{
struct imx8_priv *priv = imx_dsp_get_data(ipc);
u32 p; /* panic code */

snd_sof_ipc_msgs_rx(priv->sdev);
/* Read the message from the debug box. */
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, sizeof(p));

/* Check to see if the message is a panic code (0x0dead***) */
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
snd_sof_dsp_panic(priv->sdev, p);
else
snd_sof_ipc_msgs_rx(priv->sdev);
}

static struct imx_dsp_ops dsp_ops = {
Expand Down Expand Up @@ -409,6 +418,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
.block_read = sof_block_read,
.block_write = sof_block_write,

/* Module IO */
.read64 = sof_io_read64,

/* ipc */
.send_msg = imx8_send_msg,
.fw_ready = sof_fw_ready,
Expand All @@ -424,6 +436,9 @@ struct snd_sof_dsp_ops sof_imx8_ops = {
/* firmware loading */
.load_firmware = snd_sof_load_firmware_memcpy,

/* Debug information */
.dbg_dump = imx8_dump,

/* Firmware ops */
.arch_ops = &sof_xtensa_arch_ops,

Expand Down Expand Up @@ -452,6 +467,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
.block_read = sof_block_read,
.block_write = sof_block_write,

/* Module IO */
.read64 = sof_io_read64,

/* ipc */
.send_msg = imx8_send_msg,
.fw_ready = sof_fw_ready,
Expand All @@ -467,6 +485,9 @@ struct snd_sof_dsp_ops sof_imx8x_ops = {
/* firmware loading */
.load_firmware = snd_sof_load_firmware_memcpy,

/* Debug information */
.dbg_dump = imx8_dump,

/* Firmware ops */
.arch_ops = &sof_xtensa_arch_ops,

Expand Down
17 changes: 16 additions & 1 deletion sound/soc/sof/imx/imx8m.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/firmware/imx/dsp.h>

#include "../ops.h"
#include "imx-common.h"

#define MBOX_OFFSET 0x800000
#define MBOX_SIZE 0x1000
Expand Down Expand Up @@ -88,8 +89,16 @@ static void imx8m_dsp_handle_reply(struct imx_dsp_ipc *ipc)
static void imx8m_dsp_handle_request(struct imx_dsp_ipc *ipc)
{
struct imx8m_priv *priv = imx_dsp_get_data(ipc);
u32 p; /* Panic code */

snd_sof_ipc_msgs_rx(priv->sdev);
/* Read the message from the debug box. */
sof_mailbox_read(priv->sdev, priv->sdev->debug_box.offset + 4, &p, sizeof(p));

/* Check to see if the message is a panic code (0x0dead***) */
if ((p & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC)
snd_sof_dsp_panic(priv->sdev, p);
else
snd_sof_ipc_msgs_rx(priv->sdev);
}

static struct imx_dsp_ops imx8m_dsp_ops = {
Expand Down Expand Up @@ -262,6 +271,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
.block_read = sof_block_read,
.block_write = sof_block_write,

/* Module IO */
.read64 = sof_io_read64,

/* ipc */
.send_msg = imx8m_send_msg,
.fw_ready = sof_fw_ready,
Expand All @@ -277,6 +289,9 @@ struct snd_sof_dsp_ops sof_imx8m_ops = {
/* firmware loading */
.load_firmware = snd_sof_load_firmware_memcpy,

/* Debug information */
.dbg_dump = imx8_dump,

/* Firmware ops */
.arch_ops = &sof_xtensa_arch_ops,

Expand Down
Loading

0 comments on commit e6937b6

Please sign in to comment.