Sound Open Firmware Core
Subsystems (3)
v2 cover Sound Open Firmware Core
Sound Open Firmware (SOF) is a host and DSP architecture agnostic audio DSP firmware. SOF is not tied to any specific host architecture or any specific physical IO communication type (it will work with on SoC DSPs, or DSP connected via SPI/I2C).
SOF is also not coupled to any particular DSP architecture and has abstraction similar to Linux to allow porting to other DSP architectures.
This patch series introduces the SOF core, later series will add host platform support for SOF.
The SOF core manages all the core DSP services and ALSA/ASoC IO. The core is responsible for loading firmware, parsing topology, exposing PCMs and kcontrols, providing debug and trace mechanisms and performing IPC between host and DSP.
The SOF core also has logic to allow reuse of existing machine drivers for other platforms/machines without any code modification. i.e. DAI links can be modified at runtime to bind with SOF and SOF topologies instead of existing hard coded DAI links and topology.
Changes since V1 :-
o Added PM source.
o Updated header comments to C++ style
o Used generic private data in snd_soc_pcm_runtime
o remove sof_get_pages()
o Added comments for compressed SG pages.
o Check return values for runtime_pm calls.
Liam Girdwood (12):
ASoC: SOF: Add Sound Open Firmware driver core
ASoC: SOF: Add Sound Open Firmware KControl support
ASoC: SOF: Add driver debug support.
ASoC: SOF: Add support for IPC IO between DSP and Host
ASoC: SOF: Add PCM operations support
ASoC: SOF: Add support for loading topologies
ASoC: SOF: Add DSP firmware trace event support
ASoC: SOF: Add DSP HW abstraction operations
ASoC: SOF: Add firmware loader support
ASoC: SOF: Add PM support
ASoC: SOF: Add userspace ABI support
ASoC: SOF: Add Build support for SOF core
include/sound/soc.h | 3 + include/sound/sof.h | 82 ++ include/uapi/sound/sof-abi.h | 29 + include/uapi/sound/sof-eq.h | 102 ++ include/uapi/sound/sof-fw.h | 67 + include/uapi/sound/sof-ipc.h | 938 ++++++++++++ include/uapi/sound/sof-tone.h | 27 + include/uapi/sound/sof-topology.h | 94 ++ sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/sof/Kconfig | 36 + sound/soc/sof/Makefile | 6 + sound/soc/sof/control.c | 270 ++++ sound/soc/sof/core.c | 381 +++++ sound/soc/sof/debug.c | 157 ++ sound/soc/sof/ipc.c | 788 ++++++++++ sound/soc/sof/loader.c | 287 ++++ sound/soc/sof/ops.c | 210 +++ sound/soc/sof/ops.h | 298 ++++ sound/soc/sof/pcm.c | 733 ++++++++++ sound/soc/sof/pm.c | 345 +++++ sound/soc/sof/sof-priv.h | 519 +++++++ sound/soc/sof/topology.c | 2222 +++++++++++++++++++++++++++++ sound/soc/sof/trace.c | 293 ++++ 24 files changed, 7889 insertions(+) create mode 100644 include/sound/sof.h create mode 100644 include/uapi/sound/sof-abi.h create mode 100644 include/uapi/sound/sof-eq.h create mode 100644 include/uapi/sound/sof-fw.h create mode 100644 include/uapi/sound/sof-ipc.h create mode 100644 include/uapi/sound/sof-tone.h create mode 100644 include/uapi/sound/sof-topology.h create mode 100644 sound/soc/sof/Kconfig create mode 100644 sound/soc/sof/Makefile create mode 100644 sound/soc/sof/control.c create mode 100644 sound/soc/sof/core.c create mode 100644 sound/soc/sof/debug.c create mode 100644 sound/soc/sof/ipc.c create mode 100644 sound/soc/sof/loader.c create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h create mode 100644 sound/soc/sof/pcm.c create mode 100644 sound/soc/sof/pm.c create mode 100644 sound/soc/sof/sof-priv.h create mode 100644 sound/soc/sof/topology.c create mode 100644 sound/soc/sof/trace.c
Signature · 1 line
2.17.1
PATCH v2 1/12 ASoC: SOF: Add Sound Open Firmware driver core
The Sound Open Firmware driver core is a generic architecture independent layer that allows SOF to be used on many different different architectures and platforms. It abstracts DSP operations and IO methods so that the target DSP can be an internal memory mapped or external SPI or I2C based device. This abstraction also allows SOF to be run on many different VMs on the same physical HW.
SOF also requires some data in ASoC PCM runtime data for looking up SOF data during ASoC PCM operations.
--- include/sound/soc.h | 3 + include/sound/sof.h | 82 +++++++ sound/soc/sof/core.c | 381 +++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 517 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 983 insertions(+) create mode 100644 include/sound/sof.h create mode 100644 sound/soc/sof/core.c create mode 100644 sound/soc/sof/sof-priv.h
include/sound/soc.h +3 -0
@@ -1151,6 +1151,9 @@ struct snd_soc_pcm_runtime {/* bit field */ unsigned int dev_registered:1; unsigned int pop_wait:1; + +/* private data - core does not touch */ +void *private; };/* mixer control */
include/sound/sof.h new file +82 -0
82 lines not on this page · raw message
sound/soc/sof/core.c new file +381 -0
381 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +517 -0
517 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 01/12] ASoC: SOF: Add Sound Open Firmware driver core
include/sound/soc.h struct snd_soc_pcm_runtime { · line 1156
Quoted 2 lines · Liam Girdwood
include/sound/soc.h +2
-0+/* private data - core does not touch */ +void *private;
This is still a bit awkward - the name is now not SoF specific but it's not clear which of the several drivers in the system can use it. How about adding some sort of key/value thing, or making the DSP a first class object in the system (eg, parallel with the platforms)? This'd be a lot easier with the refactoring away from DPCM but progress on that is very slow so...
PATCH v2 2/12 ASoC: SOF: Add Sound Open Firmware KControl support
In reply to Liam GirdwoodSOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
--- sound/soc/sof/control.c | 270 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +270 -0
@@ -0,0 +1,270 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +/* Mixer Controls */ + +#include <linux/slab.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> +#include <sound/soc-topology.h> +#include <sound/soc.h> +#include <sound/control.h> +#include <uapi/sound/sof-ipc.h> +#include "sof-priv.h" + +static inline u32 mixer_to_ipc (unsigned int value,u32 *volume_map,int size) +{ +if (value >= size) +return volume_map[size -1 ]; +else +return volume_map[value]; +} + +static inline u32 ipc_to_mixer (u32 value,u32 *volume_map,int size) +{ +int i; + +for (i =0 ; i < size; i++) { +if (volume_map[i] >= value) +return i; + } + +return i -1 ; +} + +int snd_sof_volume_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int err, ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: volume get failed to resume %d\n" , + ret); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.integer.value[i] = +ipc_to_mixer (cdata->chanv[i].value, + scontrol->volume_table, sm->max +1 ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: volume get failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_volume_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: volume put failed to resume %d\n" , + ret); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) { + cdata->chanv[i].value = +mixer_to_ipc (ucontrol->value.integer.value[i], + scontrol->volume_table, sm->max +1 ); + cdata->chanv[i].channel = i; + } + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: volume put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_enum_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_enum *se = + (struct soc_enum *)kcontrol->private_value; +struct snd_sof_control *scontrol = se->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int err, ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: enum get failed to resume %d\n" , + ret); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.integer.value[i] = cdata->chanv[i].value; + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: enum get failed to idle %d\n" , + ret); +return 0 ; +} + +int snd_sof_enum_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_enum *se = + (struct soc_enum *)kcontrol->private_value; +struct snd_sof_control *scontrol = se->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: enum put failed to resume %d\n" , + ret); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) + cdata->chanv[i].value = ucontrol->value.integer.value[i]; + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_SET , +SOF_CTRL_CMD_ENUM ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: enum put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_bytes_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct sof_abi_hdr *data = cdata->data; +size_t size; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: bytes get failed to resume %d\n" , + ret); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , scontrol->cmd); + size = data->size +sizeof (*data); +if (size > be->max) { +dev_err (sdev->dev,"error: DSP sent %zu bytes max is %d\n" , + size, be->max); + ret = -EINVAL ; + goto out; + } + +/* copy back to kcontrol */ +memcpy (ucontrol->value.bytes.data, data, size); + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: bytes get failed to idle %d\n" , + err); +return ret; +} + +int snd_sof_bytes_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct sof_abi_hdr *data = cdata->data; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: bytes put failed to resume %d\n" , + ret); +return ret; + } + +if (data->size > be->max) { +dev_err (sdev->dev,"error: size too big %d bytes max is %d\n" , + data->size, be->max); + ret = -EINVAL ; + goto out; + } + +/* copy from kcontrol */ +memcpy (data, ucontrol->value.bytes.data, data->size); + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , scontrol->cmd); + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: volume get failed to idle %d\n" , + err); +return ret; +}
Signature · 1 line
2.17.1
PATCH v2 3/12 ASoC: SOF: Add driver debug support.
In reply to Liam GirdwoodAdd debugFS files that can be used to expose DSP memories and and peripherals to userspace to assist with firmware debugging.
--- sound/soc/sof/debug.c | 157 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +157 -0
@@ -0,0 +1,157 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// Yan Wang <[email protected]> +// +// Generic debug routines used to export DSP MMIO and memories to userspace +// for firmware debugging. +// + +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/slab.h> +#include <linux/device.h> +#include <linux/platform_device.h> +#include <linux/pm.h> +#include <linux/pm_runtime.h> +#include <linux/debugfs.h> +#include <linux/uaccess.h> +#include <uapi/sound/sof-ipc.h> +#include "sof-priv.h" +#include "ops.h" + +static int sof_dfsentry_open (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; + +return 0 ; +} + +static ssize_t sof_dfsentry_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry_io *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +int size, err; +u32 *buf; +loff_t pos = *ppos; +size_t ret; + + size = dfse->size; + +/* validate position & count */ +if (pos <0 ) +return -EINVAL ; +if (pos >= size || !count) +return 0 ; +if (count > size - pos) + count = size - pos; + +/* intermediate buffer size must be u32 multiple */ + size = (count +3 ) & ~3 ; + buf =kzalloc (size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +/* copy from DSP MMIO */ + err =pm_runtime_get_sync (sdev->dev); +if (err <0 ) { +dev_err (sdev->dev,"error: debugFS failed to resume %d\n" , + err); +return err; + } + +memcpy_fromio (buf, dfse->buf + pos, size); + + ret =pm_runtime_put (sdev->dev); +if (ret <0 ) +dev_err (sdev->dev,"error: debugFS failed to idle %zd\n" , + ret); + +/* copy to userspace */ + ret =copy_to_user (buffer, buf, count); +kfree (buf); + +/* update count & position if copy succeeded */ +if (ret == count) +return -EFAULT ; + count -= ret; + *ppos = pos + count; + +return count; +} + +static const struct file_operations sof_dfs_fops = { + .open = sof_dfsentry_open, + .read = sof_dfsentry_read, + .llseek = default_llseek, +}; + +int snd_sof_debugfs_create_item (struct snd_sof_dev *sdev, +void __iomem *base,size_t size, +const char *name) +{ +struct snd_sof_dfsentry_io *dfse; + +if (!sdev) +return -EINVAL ; + + dfse =kzalloc (sizeof (*dfse),GFP_KERNEL ); +if (!dfse) +return -ENOMEM ; + + dfse->buf = base; + dfse->size = size; + dfse->sdev = sdev; + + dfse->dfsentry =debugfs_create_file (name,0444 , sdev->debugfs_root, + dfse, &sof_dfs_fops); +if (!dfse->dfsentry) { +dev_err (sdev->dev,"cannot create debugfs entry.\n" ); +kfree (dfse); +return -ENODEV ; + } + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_debugfs_create_item); + +int snd_sof_dbg_init (struct snd_sof_dev *sdev) +{ +const struct snd_sof_dsp_ops *ops = sdev->ops; +const struct snd_sof_debugfs_map *map; +int err =0 , i; + +/* use "sof" as top level debugFS dir */ + sdev->debugfs_root =debugfs_create_dir ("sof" ,NULL ); +if (IS_ERR_OR_NULL (sdev->debugfs_root)) { +dev_err (sdev->dev,"error: failed to create debugfs directory\n" ); +return -EINVAL ; + } + +/* create debugFS files for platform specific MMIO/DSP memories */ +for (i =0 ; i < ops->debug_map_count; i++) { + map = &ops->debug_map[i]; + + err =snd_sof_debugfs_create_item (sdev, sdev->bar[map->bar] + + map->offset, map->size, + map->name); +if (err <0 ) +dev_err (sdev->dev,"cannot create debugfs for %s\n" , + map->name); + } + +return err; +} +EXPORT_SYMBOL (snd_sof_dbg_init); + +void snd_sof_free_debug (struct snd_sof_dev *sdev) +{ +debugfs_remove_recursive (sdev->debugfs_root); +} +EXPORT_SYMBOL (snd_sof_free_debug);
Signature · 1 line
2.17.1
PATCH v2 4/12 ASoC: SOF: Add support for IPC IO between DSP and Host
In reply to Liam GirdwoodDefine an IPC ABI for all host <--> DSP communication. This ABI should be transport agnostic. i.e. it should work on MMIO and SPI/I2C style interfaces.
--- include/uapi/sound/sof-ipc.h | 938 +++++++++++++++++++++++++++++++++++ sound/soc/sof/ipc.c | 788 +++++++++++++++++++++++++++++ 2 files changed, 1726 insertions(+) create mode 100644 include/uapi/sound/sof-ipc.h create mode 100644 sound/soc/sof/ipc.c
include/uapi/sound/sof-ipc.h new file +938 -0
@@ -0,0 +1,938 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note)) OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// Keyon Jie <[email protected]> +// + +#ifndef __INCLUDE_UAPI_SOF_IPC_H__ +#define __INCLUDE_UAPI_SOF_IPC_H__ + +#include <sound/sof-abi.h> + +/* +* IPC messages have a prefixed 32 bit identifier made up as follows :- +* +* 0xGCCCNNNN where +* G is global cmd type (4 bits) +* C is command type (12 bits) +* I is the ID number (16 bits) - monotonic and overflows +* +* This is sent at the start of the IPM message in the mailbox. Messages should +* not be sent in the doorbell (special exceptions for firmware . +*/ + +/* Global Message - Generic */ +#define SOF_GLB_TYPE_SHIFT 28 +#define SOF_GLB_TYPE_MASK (0xf << SOF_GLB_TYPE_SHIFT) +#define SOF_GLB_TYPE (x) ((x) << SOF_GLB_TYPE_SHIFT) + +/* Command Message - Generic */ +#define SOF_CMD_TYPE_SHIFT 16 +#define SOF_CMD_TYPE_MASK (0xfff << SOF_CMD_TYPE_SHIFT) +#define SOF_CMD_TYPE (x) ((x) << SOF_CMD_TYPE_SHIFT) + +/* Global Message Types */ +#define SOF_IPC_GLB_REPLY SOF_GLB_TYPE(0x1U) +#define SOF_IPC_GLB_COMPOUND SOF_GLB_TYPE(0x2U) +#define SOF_IPC_GLB_TPLG_MSG SOF_GLB_TYPE(0x3U) +#define SOF_IPC_GLB_PM_MSG SOF_GLB_TYPE(0x4U) +#define SOF_IPC_GLB_COMP_MSG SOF_GLB_TYPE(0x5U) +#define SOF_IPC_GLB_STREAM_MSG SOF_GLB_TYPE(0x6U) +#define SOF_IPC_FW_READY SOF_GLB_TYPE(0x7U) +#define SOF_IPC_GLB_DAI_MSG SOF_GLB_TYPE(0x8U) +#define SOF_IPC_GLB_TRACE_MSG SOF_GLB_TYPE(0x9U) + +/* +* DSP Command Message Types +*/ + +/* topology */ +#define SOF_IPC_TPLG_COMP_NEW SOF_CMD_TYPE(0x001) +#define SOF_IPC_TPLG_COMP_FREE SOF_CMD_TYPE(0x002) +#define SOF_IPC_TPLG_COMP_CONNECT SOF_CMD_TYPE(0x003) +#define SOF_IPC_TPLG_PIPE_NEW SOF_CMD_TYPE(0x010) +#define SOF_IPC_TPLG_PIPE_FREE SOF_CMD_TYPE(0x011) +#define SOF_IPC_TPLG_PIPE_CONNECT SOF_CMD_TYPE(0x012) +#define SOF_IPC_TPLG_PIPE_COMPLETE SOF_CMD_TYPE(0x013) +#define SOF_IPC_TPLG_BUFFER_NEW SOF_CMD_TYPE(0x020) +#define SOF_IPC_TPLG_BUFFER_FREE SOF_CMD_TYPE(0x021) + +/* PM */ +#define SOF_IPC_PM_CTX_SAVE SOF_CMD_TYPE(0x001) +#define SOF_IPC_PM_CTX_RESTORE SOF_CMD_TYPE(0x002) +#define SOF_IPC_PM_CTX_SIZE SOF_CMD_TYPE(0x003) +#define SOF_IPC_PM_CLK_SET SOF_CMD_TYPE(0x004) +#define SOF_IPC_PM_CLK_GET SOF_CMD_TYPE(0x005) +#define SOF_IPC_PM_CLK_REQ SOF_CMD_TYPE(0x006) + +/* component runtime config - multiple different types */ +#define SOF_IPC_COMP_SET_VALUE SOF_CMD_TYPE(0x001) +#define SOF_IPC_COMP_GET_VALUE SOF_CMD_TYPE(0x002) +#define SOF_IPC_COMP_SET_DATA SOF_CMD_TYPE(0x003) +#define SOF_IPC_COMP_GET_DATA SOF_CMD_TYPE(0x004) + +/* DAI messages */ +#define SOF_IPC_DAI_CONFIG SOF_CMD_TYPE(0x001) +#define SOF_IPC_DAI_LOOPBACK SOF_CMD_TYPE(0x002) + +/* stream */ +#define SOF_IPC_STREAM_PCM_PARAMS SOF_CMD_TYPE(0x001) +#define SOF_IPC_STREAM_PCM_PARAMS_REPLY SOF_CMD_TYPE(0x002) +#define SOF_IPC_STREAM_PCM_FREE SOF_CMD_TYPE(0x003) +#define SOF_IPC_STREAM_TRIG_START SOF_CMD_TYPE(0x004) +#define SOF_IPC_STREAM_TRIG_STOP SOF_CMD_TYPE(0x005) +#define SOF_IPC_STREAM_TRIG_PAUSE SOF_CMD_TYPE(0x006) +#define SOF_IPC_STREAM_TRIG_RELEASE SOF_CMD_TYPE(0x007) +#define SOF_IPC_STREAM_TRIG_DRAIN SOF_CMD_TYPE(0x008) +#define SOF_IPC_STREAM_TRIG_XRUN SOF_CMD_TYPE(0x009) +#define SOF_IPC_STREAM_POSITION SOF_CMD_TYPE(0x00a) +#define SOF_IPC_STREAM_VORBIS_PARAMS SOF_CMD_TYPE(0x010) +#define SOF_IPC_STREAM_VORBIS_FREE SOF_CMD_TYPE(0x011) + +/* trace and debug */ +#define SOF_IPC_TRACE_DMA_PARAMS SOF_CMD_TYPE(0x001) +#define SOF_IPC_TRACE_DMA_POSITION SOF_CMD_TYPE(0x002) + +/* Get message component id */ +#define SOF_IPC_MESSAGE_ID (x) ((x) & 0xffff) + +/* maximum message size for mailbox Tx/Rx */ +#define SOF_IPC_MSG_MAX_SIZE 128 + +/* +* SOF panic codes +*/ +#define SOF_IPC_PANIC_MAGIC 0x0dead000 +#define SOF_IPC_PANIC_MAGIC_MASK 0x0ffff000 +#define SOF_IPC_PANIC_CODE_MASK 0x00000fff +#define SOF_IPC_PANIC_MEM (SOF_IPC_PANIC_MAGIC | 0) +#define SOF_IPC_PANIC_WORK (SOF_IPC_PANIC_MAGIC | 1) +#define SOF_IPC_PANIC_IPC (SOF_IPC_PANIC_MAGIC | 2) +#define SOF_IPC_PANIC_ARCH (SOF_IPC_PANIC_MAGIC | 3) +#define SOF_IPC_PANIC_PLATFORM (SOF_IPC_PANIC_MAGIC | 4) +#define SOF_IPC_PANIC_TASK (SOF_IPC_PANIC_MAGIC | 5) +#define SOF_IPC_PANIC_EXCEPTION (SOF_IPC_PANIC_MAGIC | 6) +#define SOF_IPC_PANIC_DEADLOCK (SOF_IPC_PANIC_MAGIC | 7) +#define SOF_IPC_PANIC_STACK (SOF_IPC_PANIC_MAGIC | 8) +#define SOF_IPC_PANIC_IDLE (SOF_IPC_PANIC_MAGIC | 9) + +/* +* SOF memory capabilities, add new ones at the end +*/ +#define SOF_MEM_CAPS_RAM (1 << 0) +#define SOF_MEM_CAPS_ROM (1 << 1) +#define SOF_MEM_CAPS_EXT (1 << 2)/* external */ +#define SOF_MEM_CAPS_LP (1 << 3)/* low power */ +#define SOF_MEM_CAPS_HP (1 << 4)/* high performance */ +#define SOF_MEM_CAPS_DMA (1 << 5)/* DMA'able */ +#define SOF_MEM_CAPS_CACHE (1 << 6)/* cacheable */ +#define SOF_MEM_CAPS_EXEC (1 << 7)/* executable */ + +/* +* Command Header - Header for all IPC. Identifies IPC message. +* The size can be greater than the structure size and that means there is +* extended bespoke data beyond the end of the structure including variable +* arrays. +*/ + +struct sof_ipc_hdr { +uint32_t cmd;/* SOF_IPC_GLB_ + cmd */ +uint32_t size;/* size of structure */ +} __attribute__((packed)); + +/* +* Generic reply message. Some commands override this with their own reply +* types that must include this at start. +*/ +struct sof_ipc_reply { +struct sof_ipc_hdr hdr; +int32_t error;/* negative error numbers */ +} __attribute__((packed)); + +/* +* Compound commands - SOF_IPC_GLB_COMPOUND. +* +* Compound commands are sent to the DSP as a single IPC operation. The +* commands are split into blocks and each block has a header. This header +* identifies the command type and the number of commands before the next +* header. +*/ + +struct sof_ipc_compound_hdr { +struct sof_ipc_hdr hdr; +uint32_t count;/* count of 0 means end of compound sequence */ +} __attribute__((packed)); + +/* +* DAI Configuration. +* +* Each different DAI type will have it's own structure and IPC cmd. +*/ + +#define SOF_DAI_FMT_I2S 1/* I2S mode */ +#define SOF_DAI_FMT_RIGHT_J 2/* Right Justified mode */ +#define SOF_DAI_FMT_LEFT_J 3/* Left Justified mode */ +#define SOF_DAI_FMT_DSP_A 4/* L data MSB after FRM LRC */ +#define SOF_DAI_FMT_DSP_B 5/* L data MSB during FRM LRC */ +#define SOF_DAI_FMT_PDM 6/* Pulse density modulation */ + +#define SOF_DAI_FMT_CONT (1 << 4)/* continuous clock */ +#define SOF_DAI_FMT_GATED (0 << 4)/* clock is gated */ + +#define SOF_DAI_FMT_NB_NF (0 << 8)/* normal bit clock + frame */ +#define SOF_DAI_FMT_NB_IF (2 << 8)/* normal BCLK + inv FRM */ +#define SOF_DAI_FMT_IB_NF (3 << 8)/* invert BCLK + nor FRM */ +#define SOF_DAI_FMT_IB_IF (4 << 8)/* invert BCLK + FRM */ + +#define SOF_DAI_FMT_CBM_CFM (0 << 12)/* codec clk & FRM master */ +#define SOF_DAI_FMT_CBS_CFM (2 << 12)/* codec clk slave & FRM master */ +#define SOF_DAI_FMT_CBM_CFS (3 << 12)/* codec clk master & frame slave */ +#define SOF_DAI_FMT_CBS_CFS (4 << 12)/* codec clk & FRM slave */ + +#define SOF_DAI_FMT_FORMAT_MASK 0x000f +#define SOF_DAI_FMT_CLOCK_MASK 0x00f0 +#define SOF_DAI_FMT_INV_MASK 0x0f00 +#define SOF_DAI_FMT_MASTER_MASK 0xf000 + +/* ssc1: TINTE */ +#define SOF_DAI_INTEL_SSP_QUIRK_TINTE (1 << 0) +/* ssc1: PINTE */ +#define SOF_DAI_INTEL_SSP_QUIRK_PINTE (1 << 1) +/* ssc2: SMTATF */ +#define SOF_DAI_INTEL_SSP_QUIRK_SMTATF (1 << 2) +/* ssc2: MMRATF */ +#define SOF_DAI_INTEL_SSP_QUIRK_MMRATF (1 << 3) +/* ssc2: PSPSTWFDFD */ +#define SOF_DAI_INTEL_SSP_QUIRK_PSPSTWFDFD (1 << 4) +/* ssc2: PSPSRWFDFD */ +#define SOF_DAI_INTEL_SSP_QUIRK_PSPSRWFDFD (1 << 5) +/* here is the possibility to define others aux macros */ + +#define SOF_DAI_INTEL_SSP_FRAME_PULSE_WIDTH_MAX 38 +#define SOF_DAI_INTEL_SSP_SLOT_PADDING_MAX 31 + +/** \brief Types of DAI */ +enum sof_ipc_dai_type { +SOF_DAI_INTEL_NONE =0 ,/**< None */ +SOF_DAI_INTEL_SSP ,/**< Intel SSP */ +SOF_DAI_INTEL_DMIC ,/**< Intel DMIC */ +SOF_DAI_INTEL_HDA ,/**< Intel HD/A */ +}; + +/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */ +struct sof_ipc_dai_ssp_params { +uint16_t mode;// FIXME: do we need this? +uint16_t mclk_id; + +uint32_t mclk_rate;/* mclk frequency in Hz */ +uint32_t fsync_rate;/* fsync frequency in Hz */ +uint32_t bclk_rate;/* bclk frequency in Hz */ + +/* TDM */ +uint32_t tdm_slots; +uint32_t rx_slots; +uint32_t tx_slots; + +/* data */ +uint32_t sample_valid_bits; +uint16_t tdm_slot_width; +uint16_t reserved2;/* alignment */ + +/* MCLK */ +uint32_t mclk_direction; +uint32_t mclk_keep_active; +uint32_t bclk_keep_active; +uint32_t fs_keep_active; + +uint16_t frame_pulse_width; +uint32_t quirks;// FIXME: is 32 bits enough ? + +uint16_t tdm_per_slot_padding_flag; +/* private data, e.g. for quirks */ +//uint32_t pdata[10]; // FIXME: would really need ~16 u32 +} __attribute__((packed)); + +/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */ +struct sof_ipc_dai_hda_params { +struct sof_ipc_hdr hdr; +/* TODO */ +} __attribute__((packed)); + +/* DMIC Configuration Request - SOF_IPC_DAI_DMIC_CONFIG */ + +/* This struct is defined per 2ch PDM controller available in the platform. +* Normally it is sufficient to set the used microphone specific enables to 1 +* and keep other parameters as zero. The customizations are: +* +* 1. If a device mixes different microphones types with different polarity +* and/or the absolute polarity matters the PCM signal from a microphone +* can be inverted with the controls. +* +* 2. If the microphones in a stereo pair do not appear in captured stream +* in desired order due to board schematics choises they can be swapped with +* the clk_edge parameter. +* +* 3. If PDM bit errors are seen in capture (poor quality) the skew parameter +* that delays the sampling time of data by half cycles of DMIC source clock +* can be tried for improvement. However there is no guarantee for this to fix +* data integrity problems. +*/ +struct sof_ipc_dai_dmic_pdm_ctrl { +uint16_t id;/* PDM controller ID */ +uint16_t enable_mic_a;/* Use A (left) channel mic (0 or 1)*/ +uint16_t enable_mic_b;/* Use B (right) channel mic (0 or 1)*/ +uint16_t polarity_mic_a;/* Optionally invert mic A signal (0 or 1) */ +uint16_t polarity_mic_b;/* Optionally invert mic B signal (0 or 1) */ +uint16_t clk_edge;/* Optionally swap data clock edge (0 or 1) */ +uint16_t skew;/* Adjust PDM data sampling vs. clock (0..15) */ +uint16_t pad;/* Make sure the total size is 4 bytes aligned */ +} __attribute__((packed)); + +/* This struct contains the global settings for all 2ch PDM controllers. The +* version number used in configuration data is checked vs. version used by +* device driver src/drivers/dmic.c need to match. It is incremented from +* initial value 1 if updates done for the to driver would alter the operation +* of the microhone. +* +* Note: The microphone clock (pdmclk_min, pdmclk_max, duty_min, duty_max) +* parameters need to be set as defined in microphone data sheet. E.g. clock +* range 1.0 - 3.2 MHz is usually supported microphones. Some microphones are +* multi-mode capable and there may be denied mic clock frequencies between +* the modes. In such case set the clock range limits of the desired mode to +* avoid the driver to set clock to an illegal rate. +* +* The duty cycle could be set to 48-52% if not known. Generally these +* parameters can be altered within data sheet specified limits to match +* required audio application performance power. +* +* The microphone clock needs to be usually about 50-80 times the used audio +* sample rate. With highest sample rates above 48 kHz this can relaxed +* somewhat. +*/ +struct sof_ipc_dai_dmic_params { +uint32_t driver_ipc_version;/* Version (1..N) */ +uint32_t pdmclk_min;/* Minimum microphone clock in Hz (100000..N) */ +uint32_t pdmclk_max;/* Maximum microphone clock in Hz (min...N) */ +uint32_t fifo_fs_a;/* FIFO A sample rate in Hz (8000..96000) */ +uint32_t fifo_fs_b;/* FIFO B sample rate in Hz (8000..96000) */ +uint16_t fifo_bits_a;/* FIFO A word length (16 or 32) */ +uint16_t fifo_bits_b;/* FIFO B word length (16 or 32) */ +uint16_t duty_min;/* Min. mic clock duty cycle in % (20..80) */ +uint16_t duty_max;/* Max. mic clock duty cycle in % (min..80) */ +uint32_t num_pdm_active;/* Number of active pdm controllers */ +/* variable number of pdm controller config */ +struct sof_ipc_dai_dmic_pdm_ctrl pdm[0 ]; +} __attribute__((packed)); + +/* general purpose DAI configuration */ +struct sof_ipc_dai_config { +struct sof_ipc_hdr hdr; +enum sof_ipc_dai_type type; +uint32_t dai_index;/* index of this type dai */ + +/* physical protocol and clocking */ +uint16_t format;/* SOF_DAI_FMT_ */ +uint16_t reserved;/* alignment */ + +/* HW specific data */ +union { +struct sof_ipc_dai_ssp_params ssp; +struct sof_ipc_dai_hda_params hda; +struct sof_ipc_dai_dmic_params dmic; + }; +}; + +/* +* Stream configuration. +*/ + +#define SOF_IPC_MAX_CHANNELS 8 + +/* channel positions - uses same values as ALSA */ +enum sof_ipc_chmap { +SOF_CHMAP_UNKNOWN =0 , +SOF_CHMAP_NA ,/* N/A, silent */ +SOF_CHMAP_MONO ,/* mono stream */ +SOF_CHMAP_FL ,/* front left */ +SOF_CHMAP_FR ,/* front right */ +SOF_CHMAP_RL ,/* rear left */ +SOF_CHMAP_RR ,/* rear right */ +SOF_CHMAP_FC ,/* front centre */ +SOF_CHMAP_LFE ,/* LFE */ +SOF_CHMAP_SL ,/* side left */ +SOF_CHMAP_SR ,/* side right */ +SOF_CHMAP_RC ,/* rear centre */ +SOF_CHMAP_FLC ,/* front left centre */ +SOF_CHMAP_FRC ,/* front right centre */ +SOF_CHMAP_RLC ,/* rear left centre */ +SOF_CHMAP_RRC ,/* rear right centre */ +SOF_CHMAP_FLW ,/* front left wide */ +SOF_CHMAP_FRW ,/* front right wide */ +SOF_CHMAP_FLH ,/* front left high */ +SOF_CHMAP_FCH ,/* front centre high */ +SOF_CHMAP_FRH ,/* front right high */ +SOF_CHMAP_TC ,/* top centre */ +SOF_CHMAP_TFL ,/* top front left */ +SOF_CHMAP_TFR ,/* top front right */ +SOF_CHMAP_TFC ,/* top front centre */ +SOF_CHMAP_TRL ,/* top rear left */ +SOF_CHMAP_TRR ,/* top rear right */ +SOF_CHMAP_TRC ,/* top rear centre */ +SOF_CHMAP_TFLC ,/* top front left centre */ +SOF_CHMAP_TFRC ,/* top front right centre */ +SOF_CHMAP_TSL ,/* top side left */ +SOF_CHMAP_TSR ,/* top side right */ +SOF_CHMAP_LLFE ,/* left LFE */ +SOF_CHMAP_RLFE ,/* right LFE */ +SOF_CHMAP_BC ,/* bottom centre */ +SOF_CHMAP_BLC ,/* bottom left centre */ +SOF_CHMAP_BRC ,/* bottom right centre */ +SOF_CHMAP_LAST =SOF_CHMAP_BRC , +}; + +/* common sample rates for use in masks */ +#define SOF_RATE_8000 (1 << 0)/* 8000Hz */ +#define SOF_RATE_11025 (1 << 1)/* 11025Hz */ +#define SOF_RATE_12000 (1 << 2)/* 12000Hz */ +#define SOF_RATE_16000 (1 << 3)/* 16000Hz */ +#define SOF_RATE_22050 (1 << 4)/* 22050Hz */ +#define SOF_RATE_24000 (1 << 5)/* 24000Hz */ +#define SOF_RATE_32000 (1 << 6)/* 32000Hz */ +#define SOF_RATE_44100 (1 << 7)/* 44100Hz */ +#define SOF_RATE_48000 (1 << 8)/* 48000Hz */ +#define SOF_RATE_64000 (1 << 9)/* 64000Hz */ +#define SOF_RATE_88200 (1 << 10)/* 88200Hz */ +#define SOF_RATE_96000 (1 << 11)/* 96000Hz */ +#define SOF_RATE_176400 (1 << 12)/* 176400Hz */ +#define SOF_RATE_192000 (1 << 13)/* 192000Hz */ + +/* continuous and non-standard rates for flexibility */ +#define SOF_RATE_CONTINUOUS (1 << 30)/* range */ +#define SOF_RATE_KNOT (1 << 31)/* non-continuous */ + +/* stream PCM frame format */ +enum sof_ipc_frame { +SOF_IPC_FRAME_S16_LE =0 , +SOF_IPC_FRAME_S24_4LE , +SOF_IPC_FRAME_S32_LE , +SOF_IPC_FRAME_FLOAT , +/* other formats here */ +}; + +/* stream buffer format */ +enum sof_ipc_buffer_format { +SOF_IPC_BUFFER_INTERLEAVED , +SOF_IPC_BUFFER_NONINTERLEAVED , +/* other formats here */ +}; + +/* stream direction */ +enum sof_ipc_stream_direction { +SOF_IPC_STREAM_PLAYBACK =0 , +SOF_IPC_STREAM_CAPTURE , +}; + +/* stream ring info */ +struct sof_ipc_host_buffer { +uint32_t phy_addr; +uint32_t pages; +uint32_t size; +uint32_t offset; +} __attribute__((packed)); + +struct sof_ipc_stream_params { +struct sof_ipc_host_buffer buffer; +enum sof_ipc_stream_direction direction; +enum sof_ipc_frame frame_fmt; +enum sof_ipc_buffer_format buffer_fmt; +uint32_t stream_tag; +uint32_t rate; +uint32_t channels; +uint32_t sample_valid_bytes; +uint32_t sample_container_bytes; +/* for notifying host period has completed - 0 means no period IRQ */ +uint32_t host_period_bytes; +enum sof_ipc_chmap chmap[SOF_IPC_MAX_CHANNELS ];/* channel map */ +} __attribute__((packed)); + +/* PCM params info - SOF_IPC_STREAM_PCM_PARAMS */ +struct sof_ipc_pcm_params { +struct sof_ipc_hdr hdr; +uint32_t comp_id; +struct sof_ipc_stream_params params; +} __attribute__((packed)); + +/* PCM params info reply - SOF_IPC_STREAM_PCM_PARAMS_REPLY */ +struct sof_ipc_pcm_params_reply { +struct sof_ipc_reply rhdr; +uint32_t comp_id; +uint32_t posn_offset; +} __attribute__((packed)); + +/* compressed vorbis params - SOF_IPC_STREAM_VORBIS_PARAMS */ +struct sof_ipc_vorbis_params { +struct sof_ipc_hdr hdr; +uint32_t comp_id; +struct sof_ipc_stream_params params; +/* TODO */ +} __attribute__((packed)); + +/* free stream - SOF_IPC_STREAM_PCM_PARAMS */ +struct sof_ipc_stream { +struct sof_ipc_hdr hdr; +uint32_t comp_id; +} __attribute__((packed)); + +/* flags indicating which time stamps are in sync with each other */ +#define SOF_TIME_HOST_SYNC (1 << 0) +#define SOF_TIME_DAI_SYNC (1 << 1) +#define SOF_TIME_WALL_SYNC (1 << 2) +#define SOF_TIME_STAMP_SYNC (1 << 3) + +/* flags indicating which time stamps are valid */ +#define SOF_TIME_HOST_VALID (1 << 8) +#define SOF_TIME_DAI_VALID (1 << 9) +#define SOF_TIME_WALL_VALID (1 << 10) +#define SOF_TIME_STAMP_VALID (1 << 11) + +/* flags indicating time stamps are 64bit else 3use low 32bit */ +#define SOF_TIME_HOST_64 (1 << 16) +#define SOF_TIME_DAI_64 (1 << 17) +#define SOF_TIME_WALL_64 (1 << 18) +#define SOF_TIME_STAMP_64 (1 << 19) + +struct sof_ipc_stream_posn { +struct sof_ipc_reply rhdr; +uint32_t comp_id;/* host component ID */ +uint32_t flags;/* SOF_TIME_ */ +uint32_t wallclock_hz;/* frequency of wallclock in Hz */ +uint32_t timestamp_ns;/* resolution of timestamp in ns */ +uint64_t host_posn;/* host DMA position in bytes */ +uint64_t dai_posn;/* DAI DMA position in bytes */ +uint64_t comp_posn;/* comp position in bytes */ +uint64_t wallclock;/* audio wall clock */ +uint64_t timestamp;/* system time stamp */ +uint32_t xrun_comp_id;/* comp ID of XRUN component */ +int32_t xrun_size;/* XRUN size in bytes */ +} __attribute__((packed)); + +/* +* Component Mixers and Controls +*/ + +/* control data type and direction */ +enum sof_ipc_ctrl_type { +/* per channel data - uses struct sof_ipc_ctrl_value_chan */ +SOF_CTRL_TYPE_VALUE_CHAN_GET =0 , +SOF_CTRL_TYPE_VALUE_CHAN_SET , +/* component data - uses struct sof_ipc_ctrl_value_comp */ +SOF_CTRL_TYPE_VALUE_COMP_GET , +SOF_CTRL_TYPE_VALUE_COMP_SET , +/* bespoke data - struct struct sof_abi_hdr */ +SOF_CTRL_TYPE_DATA_GET , +SOF_CTRL_TYPE_DATA_SET , +}; + +/* control command type */ +enum sof_ipc_ctrl_cmd { +SOF_CTRL_CMD_VOLUME =0 ,/* maps to ALSA volume style controls */ +SOF_CTRL_CMD_ENUM ,/* maps to ALSA enum style controls */ +SOF_CTRL_CMD_SWITCH ,/* maps to ALSA switch style controls */ +SOF_CTRL_CMD_BINARY ,/* maps to ALSA binary style controls */ +}; + +/* generic channel mapped value data */ +struct sof_ipc_ctrl_value_chan { +enum sof_ipc_chmap channel; +uint32_t value; +} __attribute__((packed)); + +/* generic component mapped value data */ +struct sof_ipc_ctrl_value_comp { +uint32_t index;/* component source/sink/control index in control */ +union { +uint32_t uvalue; +int32_t svalue; + }; +} __attribute__((packed)); + +/* generic control data */ +struct sof_ipc_ctrl_data { +struct sof_ipc_reply rhdr; +uint32_t comp_id; + +/* control access and data type */ +enum sof_ipc_ctrl_type type; +enum sof_ipc_ctrl_cmd cmd; +uint32_t index;/* control index for comps > 1 control */ + +/* control data - can either be appended or DMAed from host */ +struct sof_ipc_host_buffer buffer; +uint32_t num_elems;/* in array elems or bytes */ + +/* control data - add new types if needed */ +union { +/* channel values can be used by volume type controls */ +struct sof_ipc_ctrl_value_chan chanv[0 ]; +/* component values used by routing controls like mux, mixer */ +struct sof_ipc_ctrl_value_comp compv[0 ]; +/* data can be used by binary controls */ +struct sof_abi_hdr data[0 ]; + }; +} __attribute__((packed)); + +/* +* Component +*/ + +/* types of component */ +enum sof_comp_type { +SOF_COMP_NONE =0 , +SOF_COMP_HOST , +SOF_COMP_DAI , +SOF_COMP_SG_HOST ,/* scatter gather variant */ +SOF_COMP_SG_DAI ,/* scatter gather variant */ +SOF_COMP_VOLUME , +SOF_COMP_MIXER , +SOF_COMP_MUX , +SOF_COMP_SRC , +SOF_COMP_SPLITTER , +SOF_COMP_TONE , +SOF_COMP_SWITCH , +SOF_COMP_BUFFER , +SOF_COMP_EQ_IIR , +SOF_COMP_EQ_FIR , +SOF_COMP_FILEREAD ,/* host test based file IO */ +SOF_COMP_FILEWRITE ,/* host test based file IO */ +}; + +/* XRUN action for component */ +#define SOF_XRUN_STOP 1/* stop stream */ +#define SOF_XRUN_UNDER_ZERO 2/* send 0s to sink */ +#define SOF_XRUN_OVER_NULL 4/* send data to NULL */ + +/* create new generic component - SOF_IPC_TPLG_COMP_NEW */ +struct sof_ipc_comp { +struct sof_ipc_hdr hdr; +uint32_t id; +enum sof_comp_type type; +uint32_t pipeline_id; +} __attribute__((packed)); + +/* +* Component Buffers +*/ + +/* create new component buffer - SOF_IPC_TPLG_BUFFER_NEW */ +struct sof_ipc_buffer { +struct sof_ipc_comp comp; +uint32_t size;/* buffer size in bytes */ +uint32_t caps;/* SOF_MEM_CAPS_ */ +} __attribute__((packed)); + +/* generic component config data - must always be after struct sof_ipc_comp */ +struct sof_ipc_comp_config { +uint32_t periods_sink;/* 0 means variable */ +uint32_t periods_source;/* 0 means variable */ +uint32_t preload_count;/* how many periods to preload */ +enum sof_ipc_frame frame_fmt; +uint32_t xrun_action; +} __attribute__((packed)); + +/* generic host component */ +struct sof_ipc_comp_host { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +enum sof_ipc_stream_direction direction; +uint32_t no_irq;/* don't send periodic IRQ to host/DSP */ +uint32_t dmac_config;/* DMA engine specific */ +} __attribute__((packed)); + +/* generic DAI component */ +struct sof_ipc_comp_dai { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +enum sof_ipc_stream_direction direction; +uint32_t dai_index;/* index of this type dai */ +enum sof_ipc_dai_type type; +uint32_t dmac_config;/* DMA engine specific */ +} __attribute__((packed)); + +/* generic mixer component */ +struct sof_ipc_comp_mixer { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* volume ramping types */ +enum sof_volume_ramp { +SOF_VOLUME_LINEAR =0 , +SOF_VOLUME_LOG , +SOF_VOLUME_LINEAR_ZC , +SOF_VOLUME_LOG_ZC , +}; + +/* generic volume component */ +struct sof_ipc_comp_volume { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t channels; +uint32_t min_value; +uint32_t max_value; +enum sof_volume_ramp ramp; +uint32_t initial_ramp;/* ramp space in ms */ +} __attribute__((packed)); + +/* generic SRC component */ +struct sof_ipc_comp_src { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +/* either source or sink rate must be non zero */ +uint32_t source_rate;/* source rate or 0 for variable */ +uint32_t sink_rate;/* sink rate or 0 for variable */ +uint32_t rate_mask;/* SOF_RATE_ supported rates */ +} __attribute__((packed)); + +/* generic MUX component */ +struct sof_ipc_comp_mux { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* generic tone generator component */ +struct sof_ipc_comp_tone { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +int32_t sample_rate; +int32_t frequency; +int32_t amplitude; +int32_t freq_mult; +int32_t ampl_mult; +int32_t length; +int32_t period; +int32_t repeats; +int32_t ramp_step; +} __attribute__((packed)); + +/* FIR equalizer component */ +struct sof_ipc_comp_eq_fir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* IIR equalizer component */ +struct sof_ipc_comp_eq_iir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* frees components, buffers and pipelines +* SOF_IPC_TPLG_COMP_FREE, SOF_IPC_TPLG_PIPE_FREE, SOF_IPC_TPLG_BUFFER_FREE +*/ +struct sof_ipc_free { +struct sof_ipc_hdr hdr; +uint32_t id; +} __attribute__((packed)); + +struct sof_ipc_comp_reply { +struct sof_ipc_reply rhdr; +uint32_t id; +uint32_t offset; +} __attribute__((packed)); + +/* +* Pipeline +*/ + +/* new pipeline - SOF_IPC_TPLG_PIPE_NEW */ +struct sof_ipc_pipe_new { +struct sof_ipc_hdr hdr; +uint32_t comp_id;/* component id for pipeline */ +uint32_t pipeline_id;/* pipeline id */ +uint32_t sched_id;/* sheduling component id */ +uint32_t core;/* core we run on */ +uint32_t deadline;/* execution completion deadline in us*/ +uint32_t priority;/* priority level 0 (low) to 10 (max) */ +uint32_t mips;/* worst case instruction count per period */ +uint32_t frames_per_sched;/* output frames of pipeline, 0 is variable */ +uint32_t xrun_limit_usecs;/* report xruns greater than limit */ +uint32_t timer;/* non zero if timer scheduled otherwise DAI scheduled */ +} __attribute__((packed)); + +/* pipeline construction complete - SOF_IPC_TPLG_PIPE_COMPLETE */ +struct sof_ipc_pipe_ready { +struct sof_ipc_hdr hdr; +uint32_t comp_id; +} __attribute__((packed)); + +struct sof_ipc_pipe_free { +struct sof_ipc_hdr hdr; +uint32_t comp_id; +} __attribute__((packed)); + +/* connect two components in pipeline - SOF_IPC_TPLG_COMP_CONNECT */ +struct sof_ipc_pipe_comp_connect { +struct sof_ipc_hdr hdr; +uint32_t source_id; +uint32_t sink_id; +} __attribute__((packed)); + +/* +* PM +*/ + +/* PM context element */ +struct sof_ipc_pm_ctx_elem { +uint32_t type; +uint32_t size; +uint64_t addr; +} __attribute__((packed)); + +/* +* PM context - SOF_IPC_PM_CTX_SAVE, SOF_IPC_PM_CTX_RESTORE, +* SOF_IPC_PM_CTX_SIZE +*/ +struct sof_ipc_pm_ctx { +struct sof_ipc_hdr hdr; +struct sof_ipc_host_buffer buffer; +uint32_t num_elems; +uint32_t size; +struct sof_ipc_pm_ctx_elem elems[]; +}; + +/* +* Firmware boot and version +*/ + +#define SOF_IPC_MAX_ELEMS 16 + +/* extended data types that can be appended onto end of sof_ipc_fw_ready */ +enum sof_ipc_ext_data { +SOF_IPC_EXT_DMA_BUFFER =0 , +SOF_IPC_EXT_WINDOW , +}; + +/* FW version - SOF_IPC_GLB_VERSION */ +struct sof_ipc_fw_version { +uint16_t major; +uint16_t minor; +uint16_t build; +uint8_t date[12 ]; +uint8_t time[10 ]; +uint8_t tag[6 ]; +uint8_t pad[2 ];/* Make sure the total size is 4 bytes aligned */ +} __attribute__((packed)); + +/* FW ready Message - sent by firmware when boot has completed */ +struct sof_ipc_fw_ready { +struct sof_ipc_hdr hdr; +uint32_t dspbox_offset;/* dsp initiated IPC mailbox */ +uint32_t hostbox_offset;/* host initiated IPC mailbox */ +uint32_t dspbox_size; +uint32_t hostbox_size; +struct sof_ipc_fw_version version; +} __attribute__((packed)); + +/* +* Extended Firmware data. All optional, depends on platform/arch. +*/ + +enum sof_ipc_region { +SOF_IPC_REGION_DOWNBOX =0 , +SOF_IPC_REGION_UPBOX , +SOF_IPC_REGION_TRACE , +SOF_IPC_REGION_DEBUG , +SOF_IPC_REGION_STREAM , +SOF_IPC_REGION_REGS , +SOF_IPC_REGION_EXCEPTION , +}; + +struct sof_ipc_ext_data_hdr { +struct sof_ipc_hdr hdr; +enum sof_ipc_ext_data type;/* SOF_IPC_EXT_ */ +}; + +struct sof_ipc_dma_buffer_elem { +enum sof_ipc_region type; +uint32_t id;/* platform specific - used to map to host memory */ +struct sof_ipc_host_buffer buffer; +}; + +/* extended data DMA buffers for IPC, trace and debug */ +struct sof_ipc_dma_buffer_data { +struct sof_ipc_ext_data_hdr ext_hdr; +uint32_t num_buffers; +/* host files in buffer[n].buffer */ +struct sof_ipc_dma_buffer_elem buffer[]; +} __attribute__((packed)); + +struct sof_ipc_window_elem { +enum sof_ipc_region type; +uint32_t id;/* platform specific - used to map to host memory */ +uint32_t flags;/* R, W, RW, etc - to define */ +uint32_t size;/* size of region in bytes */ +/* offset in window region as windows can be partitioned */ +uint32_t offset; +}; + +/* extended data memory windows for IPC, trace and debug */ +struct sof_ipc_window { +struct sof_ipc_ext_data_hdr ext_hdr; +uint32_t num_windows; +struct sof_ipc_window_elem window[]; +} __attribute__((packed)); + +/* +* DMA for Trace +*/ + +/* DMA for Trace params info - SOF_IPC_DEBUG_DMA_PARAMS */ +struct sof_ipc_dma_trace_params { +struct sof_ipc_hdr hdr; +struct sof_ipc_host_buffer buffer; +uint32_t stream_tag; +} __attribute__((packed)); + +/* DMA for Trace params info - SOF_IPC_DEBUG_DMA_PARAMS */ +struct sof_ipc_dma_trace_posn { +struct sof_ipc_reply rhdr; +uint32_t host_offset;/* Offset of DMA host buffer */ +uint32_t overflow;/* overflow bytes if any */ +uint32_t messages;/* total trace messages */ +} __attribute__((packed)); + +/* +* Architecture specific debug +*/ + +/* Xtensa Firmware Oops data */ +struct sof_ipc_dsp_oops_xtensa { +uint32_t exccause; +uint32_t excvaddr; +uint32_t ps; +uint32_t epc1; +uint32_t epc2; +uint32_t epc3; +uint32_t epc4; +uint32_t epc5; +uint32_t epc6; +uint32_t epc7; +uint32_t eps2; +uint32_t eps3; +uint32_t eps4; +uint32_t eps5; +uint32_t eps6; +uint32_t eps7; +uint32_t depc; +uint32_t intenable; +uint32_t interrupt; +uint32_t sar; +uint32_t stack; +} __attribute__((packed)); + +#endif
sound/soc/sof/ipc.c new file +788 -0
788 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 04/12] ASoC: SOF: Add support for IPC IO between DSP and Host
include/uapi/sound/sof-ipc.h line 250
Quoted 8 lines · Liam Girdwood
include/uapi/sound/sof-ipc.h new file +7
-0+/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */ +struct sof_ipc_dai_ssp_params { +/* MCLK */ +uint32_t mclk_direction; +uint32_t mclk_keep_active; +uint32_t bclk_keep_active; +uint32_t fs_keep_active;
Is this assuming a 1:1 relationship between the serial port and the MCLK? That's not going to be true for all systems. This definition does feel a bit specific to the SSP (or I guess just general serial ports used for audio as opposed to fixed function I2S/PCM controllers). I don't know if it's worth splitting up though.
include/uapi/sound/sof-ipc.h line 253
Quoted 2 lines
include/uapi/sound/sof-ipc.h new file +2
-0+uint16_t frame_pulse_width; +uint32_t quirks;// FIXME: is 32 bits enough ?
Better go for 640K to be sure :) ...
include/uapi/sound/sof-ipc.h line 264
Quoted 5 lines
include/uapi/sound/sof-ipc.h new file +5
-0+/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */ +struct sof_ipc_dai_hda_params { +struct sof_ipc_hdr hdr; +/* TODO */ +} __attribute__((packed));
...more seriously I do notice a bunch of these FIXME and TODO comments in here, given that it's an ABI it seems like those all need sorting before things are merged. In this case perhaps just delete the HDA stuff until someone works out what to do?
Re: [PATCH v2 04/12] ASoC: SOF: Add support for IPC IO between DSP and Host
Quoted 12 lines · Mark Brown
include/uapi/sound/sof-ipc.h line 250
Quoted 7 lines · Liam Girdwood
include/uapi/sound/sof-ipc.h new file +7
-0+/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */ +struct sof_ipc_dai_ssp_params { +/* MCLK */ +uint32_t mclk_direction; +uint32_t mclk_keep_active; +uint32_t bclk_keep_active; +uint32_t fs_keep_active;Is this assuming a 1:1 relationship between the serial port and the MCLK?
Yes just for SSP atm.
Quoted 5 lines
That's not going to be true for all systems. This definition does feel a bit specific to the SSP (or I guess just general serial ports used for audio as opposed to fixed function I2S/PCM controllers). I don't know if it's worth splitting up though.
Yeah, that's the intention is that we have a different structure for each DAI IP type. We currently have :-
struct sof_ipc_dai_config {
struct sof_ipc_hdr hdr;
enum sof_ipc_dai_type type;
...
union {
struct dai_type_X;
struct dai_type_Y;
};
};So we can add future DAI IPs as part of this union alongside a new type ID.
Quoted 4 lines
include/uapi/sound/sof-ipc.h line 253
Quoted 2 lines
include/uapi/sound/sof-ipc.h new file +2
-0+uint16_t frame_pulse_width; +uint32_t quirks;// FIXME: is 32 bits enough ? Better go for 640K to be sure :) ...
Yep, you never know :)
Quoted 11 lines
include/uapi/sound/sof-ipc.h line 264
Quoted 6 lines
include/uapi/sound/sof-ipc.h new file +5
-0+/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */ +struct sof_ipc_dai_hda_params { +struct sof_ipc_hdr hdr; +/* TODO */ +} __attribute__((packed));...more seriously I do notice a bunch of these FIXME and TODO comments in here, given that it's an ABI it seems like those all need sorting before things are merged. In this case perhaps just delete the HDA stuff until someone works out what to do?
Will do.
Liam
PATCH v2 5/12 ASoC: SOF: Add PCM operations support
In reply to Liam GirdwoodAdd support for exposing PCMs to userspace. PCMs are defined by topology and the operations in this patch map to SOF IPC calls.
--- sound/soc/sof/pcm.c | 733 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 733 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +733 -0
@@ -0,0 +1,733 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// PCM Layer, interface between ALSA and IPC. +// + +#include <linux/module.h> +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/pm_runtime.h> +#include <asm/page.h> +#include <asm/pgtable.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/dmaengine_pcm.h> +#include <sound/soc.h> +#include <sound/tlv.h> +#include <sound/compress_driver.h> +#include <sound/sof.h> +#include <uapi/sound/sof-ipc.h> +#include "sof-priv.h" +#include "ops.h" + +#define DRV_NAME "sof-audio" + +/* Create DMA buffer page table for DSP */ +static int create_page_table (struct snd_pcm_substream *substream, +unsigned char *dma_area,size_t size) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct snd_dma_buffer *dmab =snd_pcm_get_dma_buf (substream); +int stream = substream->stream; + +return snd_sof_create_page_table (sdev, dmab, + spcm->stream[stream].page_table.area, size); +} + +/* this may get called several times by oss emulation */ +static int sof_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct sof_ipc_pcm_params pcm; +struct sof_ipc_pcm_params_reply ipc_params_reply; +int posn_offset; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: hw params stream %d dir %d\n" , + spcm->pcm.pcm_id, substream->stream); + +memset (&pcm,0 ,sizeof (pcm)); + +/* allocate audio buffer pages */ + ret =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (params)); +if (ret <0 ) { +dev_err (sdev->dev,"error: could not allocate %d bytes for PCM %d\n" , +params_buffer_bytes (params), ret); +return ret; + } + +/* craete compressed page table for audio firmware */ + ret =create_page_table (substream, runtime->dma_area, + runtime->dma_bytes); +if (ret <0 ) +return ret; + +/* number of pages should be rounded up */ +if (runtime->dma_bytes %PAGE_SIZE ) + pcm.params.buffer.pages = (runtime->dma_bytes /PAGE_SIZE ) +1 ; +else + pcm.params.buffer.pages = runtime->dma_bytes /PAGE_SIZE ; + +/* set IPC PCM parameters */ + pcm.hdr.size =sizeof (pcm); + pcm.hdr.cmd =SOF_IPC_GLB_STREAM_MSG |SOF_IPC_STREAM_PCM_PARAMS ; + pcm.comp_id = spcm->stream[substream->stream].comp_id; + pcm.params.buffer.phy_addr = + spcm->stream[substream->stream].page_table.addr; + pcm.params.buffer.size = runtime->dma_bytes; + pcm.params.buffer.offset =0 ; + pcm.params.direction = substream->stream; + pcm.params.sample_valid_bytes =params_width (params) >>3 ; + pcm.params.buffer_fmt =SOF_IPC_BUFFER_INTERLEAVED ; + pcm.params.rate =params_rate (params); + pcm.params.channels =params_channels (params); + pcm.params.host_period_bytes =params_period_bytes (params); + +/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ; +break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + } + +/* format */ +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S16_LE ; +break ; +case SNDRV_PCM_FORMAT_S24 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S24_4LE ; +break ; +case SNDRV_PCM_FORMAT_S32 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S32_LE ; +break ; +case SNDRV_PCM_FORMAT_FLOAT : + pcm.params.frame_fmt =SOF_IPC_FRAME_FLOAT ; +break ; +default : +return -EINVAL ; + } + +/* firmware already configured host stream */ + pcm.params.stream_tag =snd_sof_pcm_platform_hw_params (sdev, + substream, + params); +dev_dbg (sdev->dev,"stream_tag %d" , pcm.params.stream_tag); + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, pcm.hdr.cmd, &pcm,sizeof (pcm), + &ipc_params_reply,sizeof (ipc_params_reply)); + +/* validate offset */ + posn_offset = ipc_params_reply.posn_offset; + +/* check if offset is overflow or it is not aligned */ +if (posn_offset > sdev->stream_box.size || + posn_offset %sizeof (struct sof_ipc_stream_posn ) !=0 ) { +dev_err (sdev->dev,"error: got wrong posn offset 0x%x for PCM %d\n" , + posn_offset, ret); +return ret; + } + spcm->posn_offset[substream->stream] = + sdev->stream_box.offset + posn_offset; + +/* save pcm hw_params */ +memcpy (&spcm->params[substream->stream], params,sizeof (*params)); + +return ret; +} + +static int sof_pcm_hw_free (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: free stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + + stream.hdr.size =sizeof (stream); + stream.hdr.cmd =SOF_IPC_GLB_STREAM_MSG |SOF_IPC_STREAM_PCM_FREE ; + stream.comp_id = spcm->stream[substream->stream].comp_id; + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +snd_pcm_lib_free_pages (substream); +return ret; +} + +static int sof_restore_hw_params (struct snd_pcm_substream *substream, +struct snd_sof_pcm *spcm, +struct snd_sof_dev *sdev) +{ +snd_pcm_uframes_t host =0 ; +u64 host_posn; +int ret =0 ; + +/* resume stream */ + host_posn = spcm->stream[substream->stream].posn.host_posn; + host =bytes_to_frames (substream->runtime, host_posn); +dev_dbg (sdev->dev, +"PCM: resume stream %d dir %d DMA position %lu\n" , + spcm->pcm.pcm_id, substream->stream, host); + +/* set hw_params */ + ret =sof_pcm_hw_params (substream, + &spcm->params[substream->stream]); +if (ret <0 ) { +dev_err (sdev->dev, +"error: set pcm hw_params after resume\n" ); +return ret; + } + +return 0 ; +} + +static int sof_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret =0 ; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: trigger stream %d dir %d cmd %d\n" , + spcm->pcm.pcm_id, substream->stream, cmd); + + stream.hdr.size =sizeof (stream); + stream.hdr.cmd =SOF_IPC_GLB_STREAM_MSG ; + stream.comp_id = spcm->stream[substream->stream].comp_id; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_STOP : + +/* +* Check if stream was marked for restore before suspend +*/ +if (spcm->restore_stream[substream->stream]) { + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* do not send ipc as the stream hasn't been set up */ +return 0 ; + } + + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_STOP ; +break ; +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_PAUSE ; +break ; +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* trigger start */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + }else { + +/* trigger pause release */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; + } +break ; +case SNDRV_PCM_TRIGGER_START : +/* fall through */ +case SNDRV_PCM_TRIGGER_RESUME : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + } + +/* trigger stream */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +break ; +default : +dev_err (sdev->dev,"error: unhandled trigger cmd %d\n" , cmd); +return -EINVAL ; + } + +snd_sof_pcm_platform_trigger (sdev, substream, cmd); + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +return ret; +} + +static snd_pcm_uframes_t sof_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +snd_pcm_uframes_t host =0 , dai =0 ; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +/* read position from DSP */ + host =bytes_to_frames (substream->runtime, + spcm->stream[substream->stream].posn.host_posn); + dai =bytes_to_frames (substream->runtime, + spcm->stream[substream->stream].posn.dai_posn); + +dev_dbg (sdev->dev,"PCM: stream %d dir %d DMA position %lu DAI position %lu\n" , + spcm->pcm.pcm_id, substream->stream, host, dai); + +return host; +} + +static int sof_pcm_open (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct snd_soc_tplg_stream_caps *caps = + &spcm->pcm.caps[substream->stream]; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +mutex_lock (&spcm->mutex); + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: pcm open failed to resume %d\n" , + ret); +mutex_unlock (&spcm->mutex); +return ret; + } + +/* set any runtime constraints based on topology */ +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_BUFFER_SIZE , +le32_to_cpu (caps->period_size_min)); +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +le32_to_cpu (caps->period_size_min)); + +/* set runtime config */ + runtime->hw.info =SNDRV_PCM_INFO_MMAP | +SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_INTERLEAVED | +SNDRV_PCM_INFO_PAUSE | +SNDRV_PCM_INFO_RESUME | +SNDRV_PCM_INFO_NO_PERIOD_WAKEUP ; + runtime->hw.formats =le64_to_cpu (caps->formats); + runtime->hw.period_bytes_min =le32_to_cpu (caps->period_size_min); + runtime->hw.period_bytes_max =le32_to_cpu (caps->period_size_max); + runtime->hw.periods_min =le32_to_cpu (caps->periods_min); + runtime->hw.periods_max =le32_to_cpu (caps->periods_max); + runtime->hw.buffer_bytes_max =le32_to_cpu (caps->buffer_size_max); + +dev_dbg (sdev->dev,"period min %zd max %zd bytes\n" , + runtime->hw.period_bytes_min, + runtime->hw.period_bytes_max); +dev_dbg (sdev->dev,"period count %d max %d\n" , + runtime->hw.periods_min, + runtime->hw.periods_max); +dev_dbg (sdev->dev,"buffer max %zd bytes\n" , + runtime->hw.buffer_bytes_max); + +/* set wait time - TODO: come from topology */ + substream->wait_time =500 ; + + spcm->stream[substream->stream].posn.host_posn =0 ; + spcm->stream[substream->stream].posn.dai_posn =0 ; + spcm->stream[substream->stream].substream = substream; + +snd_sof_pcm_platform_open (sdev, substream); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static int sof_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: close stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +snd_sof_pcm_platform_close (sdev, substream); + +mutex_lock (&spcm->mutex); +pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static struct snd_pcm_ops sof_pcm_ops = { + .open = sof_pcm_open, + .close = sof_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sof_pcm_hw_params, + .hw_free = sof_pcm_hw_free, + .trigger = sof_pcm_trigger, + .pointer = sof_pcm_pointer, + .page = snd_pcm_sgbuf_ops_page, +}; + +static int sof_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct snd_pcm *pcm = rtd->pcm; +struct snd_soc_tplg_stream_caps *caps; +int ret =0 , stream =SNDRV_PCM_STREAM_PLAYBACK ; + +/* find SOF PCM for this RTD */ + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) { +dev_warn (sdev->dev,"warn: can't find PCM with DAI ID %d\n" , + rtd->dai_link->id); +return 0 ; + } + rtd->private = spcm; + +dev_dbg (sdev->dev,"creating new PCM %s\n" , spcm->pcm.pcm_name); + +/* do we need to allocate playback PCM DMA pages */ +if (!spcm->pcm.playback) + goto capture; + + caps = &spcm->pcm.caps[stream]; + +/* pre-allocate playback audio buffer pages */ +dev_dbg (sdev->dev,"spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n" , + caps->name, caps->buffer_size_min, caps->buffer_size_max); + + ret =snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->parent, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); +if (ret) { +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); +return ret; + } + +/* allocate playback page table buffer */ + ret =snd_dma_alloc_pages (SNDRV_DMA_TYPE_DEV , sdev->parent, +PAGE_SIZE , &spcm->stream[stream].page_table); +if (ret <0 ) { +dev_err (sdev->dev,"error: can't alloc page table for %s %d\n" , + caps->name, ret); +return ret; + } + +capture: + stream =SNDRV_PCM_STREAM_CAPTURE ; + +/* do we need to allocate capture PCM DMA pages */ +if (!spcm->pcm.capture) +return ret; + + caps = &spcm->pcm.caps[stream]; + +/* pre-allocate capture audio buffer pages */ +dev_dbg (sdev->dev,"spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n" , + caps->name, caps->buffer_size_min, caps->buffer_size_max); + + ret =snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->parent, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); +if (ret) { +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); +snd_dma_free_pages (&spcm->stream[stream].page_table); +return ret; + } + +/* allocate capture page table buffer */ + ret =snd_dma_alloc_pages (SNDRV_DMA_TYPE_DEV , sdev->parent, +PAGE_SIZE , &spcm->stream[stream].page_table); +if (ret <0 ) { +dev_err (sdev->dev,"error: can't alloc page table for %s %d\n" , + caps->name, ret); +snd_dma_free_pages (&spcm->stream[stream].page_table); +return ret; + } + +/* TODO: assign channel maps from topology */ + +return ret; +} + +static void sof_pcm_free (struct snd_pcm *pcm) +{ +struct snd_sof_pcm *spcm; +struct snd_soc_pcm_runtime *rtd = pcm->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) { +dev_warn (sdev->dev,"warn: can't find PCM with DAI ID %d\n" , + rtd->dai_link->id); +return ; + } + +if (spcm->pcm.playback) +snd_dma_free_pages (&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].page_table); + +if (spcm->pcm.capture) +snd_dma_free_pages (&spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].page_table); + +snd_sof_free_topology (sdev); +} + +/* fixup the BE DAI link to match any values from topology */ +static int sof_pcm_dai_link_fixup (struct snd_soc_pcm_runtime *rtd, +struct snd_pcm_hw_params *params) +{ +struct snd_interval *rate =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_RATE ); +struct snd_interval *channels =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_CHANNELS ); +struct snd_mask *fmt =hw_param_mask (params,SNDRV_PCM_HW_PARAM_FORMAT ); +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_dai *dai = +snd_sof_find_dai (sdev, (char *)rtd->dai_link->name); + +/* no topology exists for this BE, try a common configuration */ +if (!dai) { +dev_err (sdev->dev,"error: no topology found for BE DAI %s config\n" , + rtd->dai_link->name); + +/* set 48k, stereo, 16bits by default */ + rate->min =48000 ; + rate->max =48000 ; + + channels->min =2 ; + channels->max =2 ; + +snd_mask_none (fmt); +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); + +return 0 ; + } + +/* read format from topology */ +snd_mask_none (fmt); + +switch (dai->comp_dai.config.frame_fmt) { +case SOF_IPC_FRAME_S16_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); +break ; +case SOF_IPC_FRAME_S24_4LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S24_LE ); +break ; +case SOF_IPC_FRAME_S32_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S32_LE ); +break ; +default : +dev_err (sdev->dev,"No available DAI format!\n" ); +return -EINVAL ; + } + +/* read rate and channels from topology */ +switch (dai->dai_config.type) { +case SOF_DAI_INTEL_SSP : + rate->min = dai->dai_config.ssp.fsync_rate; + rate->max = dai->dai_config.ssp.fsync_rate; + channels->min = dai->dai_config.ssp.tdm_slots; + channels->max = dai->dai_config.ssp.tdm_slots; + +dev_dbg (sdev->dev, +"rate_min: %d rate_max: %d\n" , rate->min, rate->max); +dev_dbg (sdev->dev, +"channels_min: %d channels_max: %d\n" , + channels->min, channels->max); + +break ; +case SOF_DAI_INTEL_DMIC : +/* DMIC only supports 16 or 32 bit formats */ +if (dai->comp_dai.config.frame_fmt ==SOF_IPC_FRAME_S24_4LE ) { +dev_err (sdev->dev, +"error: invalid fmt %d for DAI type %d\n" , + dai->comp_dai.config.frame_fmt, + dai->dai_config.type); + } +/* TODO: add any other DMIC specific fixups */ +break ; +case SOF_DAI_INTEL_HDA : +/* fallthrough */ +default : +dev_err (sdev->dev,"error: invalid DAI type %d\n" , + dai->dai_config.type); +break ; + } + +return 0 ; +} + +static int sof_pcm_probe (struct snd_soc_component *component) +{ +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pdata *plat_data =dev_get_platdata (component->dev); +int ret, err; + +/* load the default topology */ + sdev->component = component; + ret =snd_sof_load_topology (sdev, + plat_data->machine->sof_tplg_filename); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to load DSP topology %d\n" , + ret); + goto err; + } + +/* enable runtime PM with auto suspend */ +pm_runtime_set_autosuspend_delay (component->dev, +SND_SOF_SUSPEND_DELAY ); +pm_runtime_use_autosuspend (component->dev); +pm_runtime_enable (component->dev); + err =pm_runtime_idle (component->dev); +if (err <0 ) +dev_err (sdev->dev,"error: failed to enter PM idle %d\n" , err); + +err: +return ret; +} + +static void sof_pcm_remove (struct snd_soc_component *component) +{ +pm_runtime_disable (component->dev); +} + +void snd_sof_new_platform_drv (struct snd_sof_dev *sdev) +{ +struct snd_soc_component_driver *pd = &sdev->plat_drv; +struct snd_sof_pdata *plat_data = sdev->pdata; + +dev_dbg (sdev->dev,"using platform alias %s\n" , + plat_data->machine->asoc_plat_name); + + pd->name ="sof-audio" ; + pd->probe = sof_pcm_probe; + pd->remove = sof_pcm_remove; + pd->ops = &sof_pcm_ops; + pd->pcm_new = sof_pcm_new; + pd->pcm_free = sof_pcm_free; + pd->ignore_machine = plat_data->machine->drv_name; + pd->be_hw_params_fixup = sof_pcm_dai_link_fixup; + pd->be_pcm_base =SOF_BE_PCM_BASE ; + pd->use_dai_pcm_id = true; + pd->topology_name_prefix ="sof" ; +} +
Signature · 1 line
2.17.1
PATCH v2 6/12 ASoC: SOF: Add support for loading topologies
In reply to Liam GirdwoodSOF uses topology to define the DAPM graphs and widgets, DAIs, PCMs and set parameters for init and run time usage. This patch loads topology and maps it to IPC commands that are build the topology on the DSP.
--- include/uapi/sound/sof-topology.h | 94 ++ sound/soc/sof/sof-priv.h | 1 + sound/soc/sof/topology.c | 2222 +++++++++++++++++++++++++++++ 3 files changed, 2317 insertions(+) create mode 100644 include/uapi/sound/sof-topology.h create mode 100644 sound/soc/sof/topology.c
include/uapi/sound/sof-topology.h new file +94 -0
@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note)) OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// Author: Liam Girdwood <[email protected]> +// Keyon Jie <[email protected]> +// + +/* +* Topology IDs and tokens. +* +* ** MUST BE ALIGNED WITH TOPOLOGY CONFIGURATION TOKEN VALUES ** +*/ + +#ifndef __INCLUDE_UAPI_SOF_TOPOLOGY_H__ +#define __INCLUDE_UAPI_SOF_TOPOLOGY_H__ + +/* +* Kcontrol IDs +*/ +#define SOF_TPLG_KCTL_VOL_ID 256 +#define SOF_TPLG_KCTL_ENUM_ID 257 +#define SOF_TPLG_KCTL_BYTES_ID 258 + +/* +* Tokens - must match values in topology configurations +*/ + +/* buffers */ +#define SOF_TKN_BUF_SIZE 100 +#define SOF_TKN_BUF_CAPS 101 + +/* DAI */ +#define SOF_TKN_DAI_DMAC_CONFIG 153 +#define SOF_TKN_DAI_TYPE 154 +#define SOF_TKN_DAI_INDEX 155 + +/* scheduling */ +#define SOF_TKN_SCHED_DEADLINE 200 +#define SOF_TKN_SCHED_PRIORITY 201 +#define SOF_TKN_SCHED_MIPS 202 +#define SOF_TKN_SCHED_CORE 203 +#define SOF_TKN_SCHED_FRAMES 204 +#define SOF_TKN_SCHED_TIMER 205 + +/* volume */ +#define SOF_TKN_VOLUME_RAMP_STEP_TYPE 250 +#define SOF_TKN_VOLUME_RAMP_STEP_MS 251 + +/* SRC */ +#define SOF_TKN_SRC_RATE_IN 300 +#define SOF_TKN_SRC_RATE_OUT 301 + +/* PCM */ +#define SOF_TKN_PCM_DMAC_CONFIG 353 + +/* Generic components */ +#define SOF_TKN_COMP_PERIOD_SINK_COUNT 400 +#define SOF_TKN_COMP_PERIOD_SOURCE_COUNT 401 +#define SOF_TKN_COMP_FORMAT 402 +#define SOF_TKN_COMP_PRELOAD_COUNT 403 + +/* SSP */ +#define SOF_TKN_INTEL_SSP_MCLK_KEEP_ACTIVE 500 +#define SOF_TKN_INTEL_SSP_BCLK_KEEP_ACTIVE 501 +#define SOF_TKN_INTEL_SSP_FS_KEEP_ACTIVE 502 +#define SOF_TKN_INTEL_SSP_MCLK_ID 503 +#define SOF_TKN_INTEL_SSP_SAMPLE_BITS 504 +#define SOF_TKN_INTEL_SSP_FRAME_PULSE_WIDTH 505 +#define SOF_TKN_INTEL_SSP_QUIRKS 506 +#define SOF_TKN_INTEL_SSP_TDM_PADDING_PER_SLOT 507 + +/* DMIC */ +#define SOF_TKN_INTEL_DMIC_DRIVER_VERSION 600 +#define SOF_TKN_INTEL_DMIC_CLK_MIN 601 +#define SOF_TKN_INTEL_DMIC_CLK_MAX 602 +#define SOF_TKN_INTEL_DMIC_DUTY_MIN 603 +#define SOF_TKN_INTEL_DMIC_DUTY_MAX 604 +#define SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE 605 +#define SOF_TKN_INTEL_DMIC_SAMPLE_RATE 608 +#define SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH 609 + +/* DMIC PDM */ +#define SOF_TKN_INTEL_DMIC_PDM_CTRL_ID 700 +#define SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable 701 +#define SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable 702 +#define SOF_TKN_INTEL_DMIC_PDM_POLARITY_A 703 +#define SOF_TKN_INTEL_DMIC_PDM_POLARITY_B 704 +#define SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE 705 +#define SOF_TKN_INTEL_DMIC_PDM_SKEW 706 + +#endif
sound/soc/sof/sof-priv.h +1 -0
@@ -242,6 +242,7 @@ struct snd_sof_control {struct sof_ipc_ctrl_data *control_data;u32 size;/* cdata size */ enum sof_ipc_ctrl_cmd cmd; +u32 *volume_table;/* volume table computed from tlv data*/ struct mutex mutex;/* access mutex */ struct list_head list;/* list in sdev control list */
sound/soc/sof/topology.c new file +2222 -0
2,222 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 06/12] ASoC: SOF: Add support for loading topologies
sound/soc/sof/topology.c line 1360
Quoted 13 lines · Liam Girdwood
sound/soc/sof/topology.c new file +12
-0+static int sof_widget_load (struct snd_soc_component *scomp,int index, +struct snd_soc_dapm_widget *w, +struct snd_soc_tplg_dapm_widget *tw) +{ +/* nothing todo atm */ +return 0 ; +} +static int sof_link_unload (struct snd_soc_component *scomp, +struct snd_soc_dobj *dobj) +{ +return 0 ; +}
Missing implementation here as well? If these functions can sensibly be optional shouldn't the framework support that?
sound/soc/sof/topology.c line 2051
Quoted 6 lines
sound/soc/sof/topology.c new file +6
-0+static int sof_route_unload (struct snd_soc_component *scomp, +struct snd_soc_dobj *dobj) +{ +/* TODO: unload routes when topology is changed */ +return 0 ; +}
This seems like it should at least return an error.
PATCH v2 7/12 ASoC: SOF: Add DSP firmware trace event support
In reply to Liam GirdwoodAdd a trace event buffer that can be used by userspace to read DSP runtime trace events alongside bespoke trace data in realtime for firmware debug.
--- sound/soc/sof/sof-priv.h | 1 + sound/soc/sof/trace.c | 293 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/sof-priv.h +1 -0
@@ -357,6 +357,7 @@ struct snd_sof_dev {wait_queue_head_t trace_sleep;u32 host_offset;bool dtrace_is_enabled; +bool dtrace_error;void *private;/* core does not touch this */ };
sound/soc/sof/trace.c new file +293 -0
293 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 2 lines · Liam Girdwood
Add a trace event buffer that can be used by userspace to read DSP runtime trace events alongside bespoke trace data in realtime for firmware debug.
Should this be integrated into the Linux trace event mechanism rather than open coded? It would at least be nice to not call this a trace event buffer - when I initially read this I was expecting it to be for the standard Linux stuff which obviously it isn't.
Re: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 9 lines · Mark Brown
Quoted 2 lines · Liam Girdwood
Add a trace event buffer that can be used by userspace to read DSP runtime trace events alongside bespoke trace data in realtime for firmware debug.
Should this be integrated into the Linux trace event mechanism rather than open coded? It would at least be nice to not call this a trace event buffer - when I initially read this I was expecting it to be for the standard Linux stuff which obviously it isn't.
Your right, I'll rename. The eventual aim is to make it more like Linux trace but we are constrained somewhat as some DSPs only 96kB or instruction RAM, hence it's a simple and raw trace infrastructure.
Liam
Mark Brown
maintainerRe: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 10 lines · Liam Girdwood
Quoted 4 lines · Mark Brown
Should this be integrated into the Linux trace event mechanism rather than open coded? It would at least be nice to not call this a trace event buffer - when I initially read this I was expecting it to be for the standard Linux stuff which obviously it isn't.
Your right, I'll rename. The eventual aim is to make it more like Linux trace but we are constrained somewhat as some DSPs only 96kB or instruction RAM, hence it's a simple and raw trace infrastructure.
I was thinking the code could read it like it's doing now and then just have a trace event to dump it into the core trace infrastructure as it reads things in.
Re: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 12 lines · Mark Brown
Quoted 10 lines · Liam Girdwood
Quoted 4 lines · Mark Brown
Should this be integrated into the Linux trace event mechanism rather than open coded? It would at least be nice to not call this a trace event buffer - when I initially read this I was expecting it to be for the standard Linux stuff which obviously it isn't.
Your right, I'll rename. The eventual aim is to make it more like Linux trace
but we are constrained somewhat as some DSPs only 96kB or instruction RAM, hence
it's a simple and raw trace infrastructure.
Quoted 3 lines
I was thinking the code could read it like it's doing now and then just have a trace event to dump it into the core trace infrastructure as it reads things in.
Most of the data is binary atm, so we were decoding in userspace. Any objection to decoding in the kernel as different trace events ?
Thanks
Liam
Mark Brown
maintainerRe: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 8 lines · Liam Girdwood
Quoted 3 lines · Mark Brown
I was thinking the code could read it like it's doing now and then just have a trace event to dump it into the core trace infrastructure as it reads things in.
Most of the data is binary atm, so we were decoding in userspace. Any objection to decoding in the kernel as different trace events ?
I wouldn't think so.
The way the trace stuff works is that the writer dumps blocks of data into the trace buffer in raw binary form in a structured block tagged with the event type and then later on when something reads out the buffer they can be formatted as desired, including things like hex dumps (IIRC there's facilities to just get the raw buffer entries too, I've only ever used the human readable interface myself, writing software is hard). This gives very fast writes which is really nice for anything performance sensitive and means you can leave trace on a lot more than you would otherwise. I'd guess if you were decoding it'd just be splitting the buffer up into per message chunks.
Re: [PATCH v2 07/12] ASoC: SOF: Add DSP firmware trace event support
Quoted 11 lines · Mark Brown
Quoted 7 lines · Liam Girdwood
Quoted 3 lines · Mark Brown
I was thinking the code could read it like it's doing now and then just have a trace event to dump it into the core trace infrastructure as it reads things in.
Most of the data is binary atm, so we were decoding in userspace. Any objection
to decoding in the kernel as different trace events ?I wouldn't think so.
I was initially thinking about a partial decode. The FW has many subsystems for trace that can be individually switched on/off via IPC. e.g. driver would read the trace packet class and then call the appropriate trace event for that class (note that class is not decoded any further). But I'm not so sure now as these classes can change at runtime based on topologies.
Quoted 7 lines
The way the trace stuff works is that the writer dumps blocks of data into the trace buffer in raw binary form in a structured block tagged with the event type and then later on when something reads out the buffer they can be formatted as desired, including things like hex dumps (IIRC there's facilities to just get the raw buffer entries too, I've only ever used the human readable interface myself, writing software is hard).
Yeah, I'm just reading up on this now, human readable is easy.
Quoted 4 lines
This gives very fast writes which is really nice for anything
performance sensitive and means you can leave trace on a lot more than you would otherwise. I'd guess if you were decoding it'd just be splitting the buffer up into per message chunks.
So I think now we will trace the driver side (easy) and then trace event firmware trace packets as ASCII text (which userspace would decode).
I will delay upstreaming the trace part so v4 will be sent minus trace.
I will probably have some debugFS interface that would export dynamic firmware trace tuning controls.
Liam
Quoted 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v2 8/12 ASoC: SOF: Add DSP HW abstraction operations
In reply to Liam GirdwoodAdd operation pointers that can be called by core to control a wide variety of DSP targets. The DSP HW drivers will fill in these operations.
--- sound/soc/sof/ops.c | 210 +++++++++++++++++++++++++++++++ sound/soc/sof/ops.h | 298 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 508 insertions(+) create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h
sound/soc/sof/ops.c new file +210 -0
@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/interrupt.h> +#include <linux/device.h> +#include <linux/pci.h> +#include <linux/delay.h> +#include <uapi/sound/sof-ipc.h> +#include "ops.h" +#include "sof-priv.h" + +int snd_sof_pci_update_bits_unlocked (struct snd_sof_dev *sdev,u32 offset, +u32 mask,u32 value) +{ +bool change; +unsigned int old, new; +u32 ret = ~0 ;/* explicit init to remove uninitialized use warnings */ + +pci_read_config_dword (sdev->pci, offset, &ret); +dev_dbg (sdev->dev,"Debug PCIR: %8.8x at %8.8x\n" , +pci_read_config_dword (sdev->pci, offset, &ret), offset); + + old = ret; + new = (old & (~mask)) | (value & mask); + + change = (old != new); +if (change) { +pci_write_config_dword (sdev->pci, offset, new); +dev_dbg (sdev->dev,"Debug PCIW: %8.8x at %8.8x\n" , value, + offset); + } + +return change; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits_unlocked); + +int snd_sof_pci_update_bits (struct snd_sof_dev *sdev,u32 offset, +u32 mask,u32 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_pci_update_bits_unlocked (sdev, offset, mask, value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits); + +int snd_sof_dsp_update_bits_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +bool change; +unsigned int old, new; +u32 ret; + + ret =snd_sof_dsp_read (sdev, bar, offset); + + old = ret; + new = (old & (~mask)) | (value & mask); + + change = (old != new); +if (change) +snd_sof_dsp_write (sdev, bar, offset, new); + +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_unlocked); + +int snd_sof_dsp_update_bits64_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u64 mask,u64 value) +{ +bool change; +u64 old, new; + + old =snd_sof_dsp_read64 (sdev, bar, offset); + + new = (old & (~mask)) | (value & mask); + + change = (old != new); +if (change) +snd_sof_dsp_write64 (sdev, bar, offset, new); + +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits64_unlocked); + +/* This is for registers bits with attribute RWC */ +void snd_sof_dsp_update_bits_forced_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +unsigned int old, new; +u32 ret; + + ret =snd_sof_dsp_read (sdev, bar, offset); + + old = ret; + new = (old & (~mask)) | (value & mask); + +snd_sof_dsp_write (sdev, bar, offset, new); +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_forced_unlocked); + +int snd_sof_dsp_update_bits (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u32 mask,u32 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_dsp_update_bits_unlocked (sdev, bar, offset, mask, + value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits); + +int snd_sof_dsp_update_bits64 (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u64 mask,u64 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_dsp_update_bits64_unlocked (sdev, bar, offset, mask, + value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits64); + +/* This is for registers bits with attribute RWC */ +void snd_sof_dsp_update_bits_forced (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +unsigned long flags; + +spin_lock_irqsave (&sdev->hw_lock, flags); +snd_sof_dsp_update_bits_forced_unlocked (sdev, bar, offset, mask, value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_forced); + +int snd_sof_dsp_register_poll (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u32 mask,u32 target,u32 timeout) +{ +int time, ret; +bool done = false; + +/* +* we will poll for couple of ms using mdelay, if not successful +* then go to longer sleep using usleep_range +*/ + +/* check if set state successful */ +for (time =0 ; time <5 ; time++) { +if ((snd_sof_dsp_read (sdev, bar, offset) & mask) == target) { + done = true; +break ; + } +msleep (20 ); + } + +if (!done) { +/* sleeping in 10ms steps so adjust timeout value */ + timeout /=10 ; + +for (time =0 ; time < timeout; time++) { +if ((snd_sof_dsp_read (sdev, bar, offset) & mask) == + target) +break ; + +usleep_range (5000 ,10000 ); + } + } + + ret = time < timeout ?0 : -ETIME ; + +return ret; +} +EXPORT_SYMBOL (snd_sof_dsp_register_poll); + +void snd_sof_dsp_panic (struct snd_sof_dev *sdev,u32 offset) +{ +dev_err (sdev->dev,"error : DSP panic!\n" ); + +/* check if DSP is not ready and did not set the dsp_oops_offset. +* if the dsp_oops_offset is not set, set it from the panic message. +* Also add a check to memory window setting with panic message. +*/ +if (!sdev->dsp_oops_offset) + sdev->dsp_oops_offset = offset; +else +dev_dbg (sdev->dev,"panic: dsp_oops_offset %zu offset %d\n" , + sdev->dsp_oops_offset, offset); + +snd_sof_dsp_dbg_dump (sdev,SOF_DBG_REGS |SOF_DBG_MBOX ); +snd_sof_trace_notify_for_error (sdev); +snd_sof_dsp_cmd_done (sdev,SOF_IPC_HOST_REPLY ); +} +EXPORT_SYMBOL (snd_sof_dsp_panic);
sound/soc/sof/ops.h new file +298 -0
298 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 9/12 ASoC: SOF: Add firmware loader support
In reply to Liam GirdwoodThe firmware loader exports APIs that can be called by core to load and process multiple different file formats.
--- sound/soc/sof/loader.c | 287 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 sound/soc/sof/loader.c
sound/soc/sof/loader.c new file +287 -0
@@ -0,0 +1,287 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// Generic firmware loader. +// + +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/slab.h> +#include <linux/device.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/dma-mapping.h> +#include <linux/platform_device.h> +#include <linux/firmware.h> +#include <uapi/sound/sof-fw.h> +#include "sof-priv.h" +#include "ops.h" + +static int get_ext_windows (struct snd_sof_dev *sdev, +struct sof_ipc_ext_data_hdr *ext_hdr) +{ +struct sof_ipc_window *w = (struct sof_ipc_window *)ext_hdr; + +int ret =0 ; +size_t size; + +if (w->num_windows ==0 || w->num_windows >SOF_IPC_MAX_ELEMS ) +return -EINVAL ; + + size =sizeof (*w) +sizeof (struct sof_ipc_window_elem ) * w->num_windows; + +/* keep a local copy of the data */ + sdev->info_window =kmemdup (w, size,GFP_KERNEL ); +if (!sdev->info_window) +return -ENOMEM ; + +return ret; +} + +/* parse the extended FW boot data structures from FW boot message */ +int snd_sof_fw_parse_ext_data (struct snd_sof_dev *sdev,u32 offset) +{ +struct sof_ipc_ext_data_hdr *ext_hdr; +void *ext_data; +int ret =0 ; + + ext_data =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!ext_data) +return -ENOMEM ; + +/* get first header */ +snd_sof_dsp_block_read (sdev, offset, ext_data,sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data; + +while (ext_hdr->hdr.cmd ==SOF_IPC_FW_READY ) { +/* read in ext structure */ + offset +=sizeof (*ext_hdr); +snd_sof_dsp_block_read (sdev, offset, + ext_data +sizeof (*ext_hdr), + ext_hdr->hdr.size -sizeof (*ext_hdr)); + +dev_dbg (sdev->dev,"found ext header type %d size 0x%x\n" , + ext_hdr->type, ext_hdr->hdr.size); + +/* process structure data */ +switch (ext_hdr->type) { +case SOF_IPC_EXT_DMA_BUFFER : +break ; +case SOF_IPC_EXT_WINDOW : + ret =get_ext_windows (sdev, ext_hdr); +break ; +default : +break ; + } + +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to parse ext data type %d\n" , + ext_hdr->type); + } + +/* move to next header */ + offset += ext_hdr->hdr.size; +snd_sof_dsp_block_read (sdev, offset, ext_data, +sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data; + } + +kfree (ext_data); +return ret; +} +EXPORT_SYMBOL (snd_sof_fw_parse_ext_data); + +/* generic module parser for mmaped DSPs */ +int snd_sof_parse_module_memcpy (struct snd_sof_dev *sdev, +struct snd_sof_mod_hdr *module) +{ +struct snd_sof_blk_hdr *block; +int count; +u32 offset; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (void *)module +sizeof (*module); + +for (count =0 ; count < module->num_blocks; count++) { +if (block->size ==0 ) { +dev_warn (sdev->dev, +"warning: block %d size zero\n" , count); +dev_warn (sdev->dev," type 0x%x offset 0x%x\n" , + block->type, block->offset); +continue ; + } + +switch (block->type) { +case SOF_BLK_IMAGE : +case SOF_BLK_CACHE : +case SOF_BLK_REGS : +case SOF_BLK_SIG : +case SOF_BLK_ROM : +continue ;/* not handled atm */ +case SOF_BLK_TEXT : +case SOF_BLK_DATA : + offset = block->offset; +break ; +default : +dev_err (sdev->dev,"error: bad type 0x%x for block 0x%x\n" , + block->type, count); +return -EINVAL ; + } + +dev_dbg (sdev->dev, +"block %d type 0x%x size 0x%x ==> offset 0x%x\n" , + count, block->type, block->size, offset); + +snd_sof_dsp_block_write (sdev, offset, + (void *)block +sizeof (*block), + block->size); + +/* next block */ + block = (void *)block +sizeof (*block) + block->size; + } + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_parse_module_memcpy); + +static int check_header (struct snd_sof_dev *sdev,const struct firmware *fw) +{ +struct snd_sof_fw_header *header; + +/* Read the header information from the data pointer */ + header = (struct snd_sof_fw_header *)fw->data; + +/* verify FW sig */ +if (strncmp (header->sig,SND_SOF_FW_SIG ,SND_SOF_FW_SIG_SIZE ) !=0 ) { +dev_err (sdev->dev,"error: invalid firmware signature\n" ); +return -EINVAL ; + } + +/* check size is valid */ +if (fw->size != header->file_size +sizeof (*header)) { +dev_err (sdev->dev,"error: invalid filesize mismatch got 0x%zx expected 0x%zx\n" , + fw->size, header->file_size +sizeof (*header)); +return -EINVAL ; + } + +dev_dbg (sdev->dev,"header size=0x%x modules=0x%x abi=0x%x size=%zu\n" , + header->file_size, header->num_modules, + header->abi,sizeof (*header)); + +return 0 ; +} + +static int load_modules (struct snd_sof_dev *sdev,const struct firmware *fw) +{ +struct snd_sof_fw_header *header; +struct snd_sof_mod_hdr *module; +int (*load_module)(struct snd_sof_dev *sof_dev, +struct snd_sof_mod_hdr *hdr); +int ret, count; + + header = (struct snd_sof_fw_header *)fw->data; + load_module = sdev->ops->load_module; +if (!load_module) +return -EINVAL ; + +/* parse each module */ + module = (void *)fw->data +sizeof (*header); +for (count =0 ; count < header->num_modules; count++) { +/* module */ + ret =load_module (sdev, module); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid module %d\n" , count); +return ret; + } + module = (void *)module +sizeof (*module) + module->size; + } + +return 0 ; +} + +int snd_sof_load_firmware_memcpy (struct snd_sof_dev *sdev, +const struct firmware *fw,bool first_boot) +{ +int ret; + +/* make sure the FW header and file is valid */ + ret =check_header (sdev, fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW header\n" ); +return ret; + } + +/* prepare the DSP for FW loading */ + ret =snd_sof_dsp_reset (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to reset DSP\n" ); +return ret; + } + +/* parse and load firmware modules to DSP */ + ret =load_modules (sdev, fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW modules\n" ); +return ret; + } + +return ret; +} +EXPORT_SYMBOL (snd_sof_load_firmware_memcpy); + +int snd_sof_load_firmware (struct snd_sof_dev *sdev, +const struct firmware *fw,bool first_boot) +{ +dev_dbg (sdev->dev,"loading firmware\n" ); + +if (sdev->ops->load_firmware) +return sdev->ops->load_firmware (sdev, fw, first_boot); +return 0 ; +} +EXPORT_SYMBOL (snd_sof_load_firmware); + +int snd_sof_run_firmware (struct snd_sof_dev *sdev) +{ +int ret; + +init_waitqueue_head (&sdev->boot_wait); + sdev->boot_complete = false; + +dev_dbg (sdev->dev,"booting DSP firmware\n" ); + +/* boot the firmware on the DSP */ + ret =snd_sof_dsp_run (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to reset DSP\n" ); +return ret; + } + +/* now wait for the DSP to boot */ + ret =wait_event_timeout (sdev->boot_wait, sdev->boot_complete, +msecs_to_jiffies (sdev->boot_timeout)); +if (ret ==0 ) { +dev_err (sdev->dev,"error: firmware boot timeout\n" ); +snd_sof_dsp_dbg_dump (sdev,SOF_DBG_REGS |SOF_DBG_MBOX | +SOF_DBG_TEXT |SOF_DBG_PCI ); +return -EIO ; + } + +dev_info (sdev->dev,"firmware boot complete\n" ); + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_run_firmware); + +void snd_sof_fw_unload (struct snd_sof_dev *sdev) +{ +/* TODO: support module unloading at runtime */ +} +EXPORT_SYMBOL (snd_sof_fw_unload);
Signature · 1 line
2.17.1
PATCH v2 10/12 ASoC: SOF: Add PM support
In reply to Liam GirdwoodAdd support for saving and restoring DSP context in D3 to host DDR.
The suspend callback includes: suspend all pcm's stream that are running, send CTX_SAVE ipc, drop all ipc's, release trace dma and then power off the DSP.
And the resume callback performs the following steps: load FW, run FW, re-initialize trace, restore pipeline, restore the kcontrol values and finally send the ctx restore ipc to the dsp.
The streams that are suspended are resumed by the ALSA resume trigger. If the streams are paused during system suspend, they are marked explicitly so they can be restored during PAUSE_RELEASE.
--- sound/soc/sof/pm.c | 345 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 sound/soc/sof/pm.c
sound/soc/sof/pm.c new file +345 -0
@@ -0,0 +1,345 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/mm.h> +#include <linux/pm_runtime.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <asm/page.h> +#include <asm/pgtable.h> +#include <sound/core.h> +#include <sound/soc.h> +#include <sound/sof.h> +#include "ops.h" +#include "sof-priv.h" + +static int sof_restore_pipelines (struct snd_sof_dev *sdev) +{ +struct snd_sof_widget *swidget =NULL ; +struct snd_sof_route *sroute =NULL ; +struct snd_sof_dai *dai; +struct sof_ipc_comp_dai *comp_dai; +struct sof_ipc_hdr *hdr; +struct snd_sof_control *scontrol =NULL ; +int ret =0 ; + +/* restore pipeline components */ +list_for_each_entry_reverse (swidget, &sdev->widget_list, list) { +struct sof_ipc_comp_reply r; + +/* skip if there is no private data */ +if (!swidget->private) +continue ; + +switch (swidget->id) { +case snd_soc_dapm_dai_in: +/* fallthrough */ +case snd_soc_dapm_dai_out: + dai = (struct snd_sof_dai *)swidget->private; + comp_dai = &dai->comp_dai; + ret =sof_ipc_tx_message (sdev->ipc, + comp_dai->comp.hdr.cmd, + comp_dai,sizeof (*comp_dai), + &r,sizeof (r)); +break ; +default : + hdr = (struct sof_ipc_hdr *)swidget->private; + ret =sof_ipc_tx_message (sdev->ipc, hdr->cmd, + swidget->private, hdr->size, + &r,sizeof (r)); +break ; + } +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load widget type %d with ID: %d\n" , + swidget->widget->id, swidget->comp_id); + +return ret; + } + } + +/* restore pipeline connections */ +list_for_each_entry_reverse (sroute, &sdev->route_list, list) { +struct sof_ipc_pipe_comp_connect *connect; +struct sof_ipc_reply reply; + +/* skip if there's no private data */ +if (!sroute->private) +continue ; + + connect = sroute->private; + +/* send ipc */ + ret =sof_ipc_tx_message (sdev->ipc, + connect->hdr.cmd, + connect,sizeof (*connect), + &reply,sizeof (reply)); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load route sink %s control %s source %s\n" , + sroute->route.sink, + sroute->route.control ? sroute->route.control + :"none" , + sroute->route.source); + +return ret; + } + } + +/* restore dai links */ +list_for_each_entry_reverse (dai, &sdev->dai_list, list) { +struct sof_ipc_reply reply; +struct sof_ipc_dai_config *config = &dai->dai_config; + + ret =sof_ipc_tx_message (sdev->ipc, + config->hdr.cmd, config, +sizeof (*config), + &reply,sizeof (reply)); + +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to set dai config for %s\n" , + dai->name); + +return ret; + } + } + +/* complete pipeline */ +list_for_each_entry (swidget, &sdev->widget_list, list) { +switch (swidget->id) { +case snd_soc_dapm_scheduler: + swidget->complete = +snd_sof_complete_pipeline (sdev, swidget); +break ; +default : +break ; + } + } + +/* restore kcontrol values */ +list_for_each_entry (scontrol, &sdev->kcontrol_list, list) { + +/* notify DSP of kcontrol values */ + ret =snd_sof_ipc_set_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_SET , + scontrol->cmd); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed kcontrol value set for widget: %d\n" , + scontrol->comp_id); + +return ret; + } + } + +return 0 ; +} + +static int sof_send_pm_ipc (struct snd_sof_dev *sdev,int cmd) +{ +struct sof_ipc_pm_ctx pm_ctx; + +memset (&pm_ctx,0 ,sizeof (pm_ctx)); + +/* configure ctx save ipc message */ + pm_ctx.hdr.size =sizeof (pm_ctx); + pm_ctx.hdr.cmd =SOF_IPC_GLB_PM_MSG | cmd; + +/* send ctx save ipc to dsp */ +return sof_ipc_tx_message (sdev->ipc, pm_ctx.hdr.cmd, &pm_ctx, +sizeof (pm_ctx), &pm_ctx,sizeof (pm_ctx)); +} + +static void sof_suspend_streams (struct snd_sof_dev *sdev) +{ +struct snd_sof_pcm *spcm; +struct snd_pcm_substream *substream; +int dir; + +/* suspend all running streams */ +list_for_each_entry (spcm, &sdev->pcm_list, list) { + +mutex_lock (&spcm->mutex); + +/* suspend running playback stream */ + dir =SNDRV_PCM_STREAM_PLAYBACK ; + substream = spcm->stream[dir].substream; + +if (substream && substream->runtime) { + +snd_pcm_suspend (substream); + +/* +* set restore_stream so that hw_params can be +* restored during resume +*/ + spcm->restore_stream[dir] =1 ; + } + +/* suspend running capture stream */ + dir =SNDRV_PCM_STREAM_CAPTURE ; + substream = spcm->stream[dir].substream; + +if (substream && substream->runtime) { + +snd_pcm_suspend (substream); + +/* +* set restore_stream so that hw_params can be +* restored during resume +*/ + spcm->restore_stream[dir] =1 ; + } + +mutex_unlock (&spcm->mutex); + } +} + +static int sof_resume (struct device *dev) +{ +struct sof_platform_priv *priv =dev_get_drvdata (dev); +struct snd_sof_dev *sdev =dev_get_drvdata (&priv->pdev_pcm->dev); +int ret =0 ; + +/* do nothing if dsp resume callback is not set */ +if (!sdev->ops->resume) +return 0 ; + +/* power up DSP */ + ret =snd_sof_dsp_resume (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to power up DSP after resume\n" ); +return ret; + } + +/* load the firmware */ + ret =snd_sof_load_firmware (sdev, sdev->pdata->fw, false); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* boot the firmware */ + ret =snd_sof_run_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to boot DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* init DMA trace */ + ret =snd_sof_init_trace_ipc (sdev); +if (ret <0 ) { +/* non fatal */ +dev_warn (sdev->dev, +"warning: failed to init trace after resume %d\n" , + ret); + } + +/* restore pipelines */ + ret =sof_restore_pipelines (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to restore pipeline after resume %d\n" , + ret); +return ret; + } + +/* notify DSP of system resume */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_RESTORE ); +if (ret <0 ) +dev_err (sdev->dev, +"error: ctx_restore ipc error during resume %d\n" , + ret); + +return ret; +} + +static int sof_suspend (struct device *dev) +{ +struct sof_platform_priv *priv =dev_get_drvdata (dev); +struct snd_sof_dev *sdev =dev_get_drvdata (&priv->pdev_pcm->dev); +int ret =0 ; + +/* do nothing if dsp suspend callback is not set */ +if (!sdev->ops->suspend) +return 0 ; + +/* +* Suspend running pcm streams. +* They will be restarted by ALSA resume trigger call. +*/ +sof_suspend_streams (sdev); + +/* notify DSP of upcoming power down */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_SAVE ); +if (ret <0 ) { +dev_err (sdev->dev, +"error: ctx_save ipc error during suspend %d\n" , + ret); +return ret; + } + +/* drop all ipc */ +sof_ipc_drop_all (sdev->ipc); + +/* release trace */ +snd_sof_dma_trace_release (sdev); + +/* power down DSP */ + ret =snd_sof_dsp_suspend (sdev,0 ); +if (ret <0 ) +dev_err (sdev->dev, +"error: failed to power down DSP during suspend %d\n" , + ret); + +return ret; +} + +int snd_sof_runtime_suspend (struct device *dev) +{ +return sof_suspend (dev); +} +EXPORT_SYMBOL (snd_sof_runtime_suspend); + +int snd_sof_runtime_resume (struct device *dev) +{ +return sof_resume (dev); +} +EXPORT_SYMBOL (snd_sof_runtime_resume); + +int snd_sof_resume (struct device *dev) +{ +return sof_resume (dev); +} +EXPORT_SYMBOL (snd_sof_resume); + +int snd_sof_suspend (struct device *dev) +{ +/* suspend if dev is runtime_active */ +if (pm_runtime_active (dev)) +return sof_suspend (dev); + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_suspend); + +int snd_sof_suspend_late (struct device *dev) +{ +return 0 ; +} +EXPORT_SYMBOL (snd_sof_suspend_late);
Signature · 1 line
2.17.1
PATCH v2 11/12 ASoC: SOF: Add userspace ABI support
In reply to Liam GirdwoodAdd userspace ABI for audio userspace application IO outside of regular ALSA PCM and kcontrols. This is intended to be used to format coefficients and data for custom processing components.
--- include/uapi/sound/sof-abi.h | 29 ++++++++++ include/uapi/sound/sof-eq.h | 102 ++++++++++++++++++++++++++++++++++ include/uapi/sound/sof-fw.h | 67 ++++++++++++++++++++++ include/uapi/sound/sof-tone.h | 27 +++++++++ 4 files changed, 225 insertions(+) create mode 100644 include/uapi/sound/sof-abi.h create mode 100644 include/uapi/sound/sof-eq.h create mode 100644 include/uapi/sound/sof-fw.h create mode 100644 include/uapi/sound/sof-tone.h
include/uapi/sound/sof-abi.h new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note)) OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// + +#ifndef __INCLUDE_UAPI_ABI_H__ +#define __INCLUDE_UAPI_ABI_H__ + +#define SOF_ABI_VERSION 1 +#define SOF_ABI_MAGIC 0x00464F53/* "SOF\0" */ + +/* +* Header for all non IPC ABI data. Identifies data type, size and ABI. +* Used by any bespoke component data structures or binary blobs. +*/ + +struct sof_abi_hdr { +uint32_t magic;/* 'S', 'O', 'F', '\0' */ +uint32_t type;/* component specific type */ +uint32_t size;/* size in bytes of data excluding this struct */ +uint32_t abi;/* SOF ABI version */ +uint32_t comp_abi;/* component specific ABI version */ +char data[0 ]; +} __attribute__((packed)); + +#endif
include/uapi/sound/sof-eq.h new file +102 -0
102 lines not on this page · raw message
include/uapi/sound/sof-fw.h new file +67 -0
67 lines not on this page · raw message
include/uapi/sound/sof-tone.h new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note)) OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// Author: Seppo Ingalsuo <[email protected]> +// + +#ifndef TONE_H +#define TONE_H + +/* Component will reject non-matching configuration. The version number need +* to be incremented with any ABI changes in function fir_cmd(). +*/ +#define SOF_TONE_ABI_VERSION 1 + +#define SOF_TONE_IDX_FREQUENCY 0 +#define SOF_TONE_IDX_AMPLITUDE 1 +#define SOF_TONE_IDX_FREQ_MULT 2 +#define SOF_TONE_IDX_AMPL_MULT 3 +#define SOF_TONE_IDX_LENGTH 4 +#define SOF_TONE_IDX_PERIOD 5 +#define SOF_TONE_IDX_REPEATS 6 +#define SOF_TONE_IDX_LIN_RAMP_STEP 7 + +#endif /* TONE_ABI_H */
Signature · 1 line
2.17.1
PATCH v2 12/12 ASoC: SOF: Add Build support for SOF core
In reply to Liam GirdwoodBuild SOF core and Intel-specific drivers.
--- sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/sof/Kconfig | 36 ++++++++++++++++++++++++++++++++++++ sound/soc/sof/Makefile | 6 ++++++ 4 files changed, 44 insertions(+) create mode 100644 sound/soc/sof/Kconfig create mode 100644 sound/soc/sof/Makefile
sound/soc/Kconfig +1 -0
@@ -65,6 +65,7 @@ source "sound/soc/rockchip/Kconfig" source "sound/soc/samsung/Kconfig" source "sound/soc/sh/Kconfig" source "sound/soc/sirf/Kconfig" +source "sound/soc/sof/Kconfig" source "sound/soc/spear/Kconfig" source "sound/soc/sti/Kconfig" source "sound/soc/stm/Kconfig"
sound/soc/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_SND_SOC) += rockchip/ obj-$(CONFIG_SND_SOC) += samsung/ obj-$(CONFIG_SND_SOC) += sh/ obj-$(CONFIG_SND_SOC) += sirf/ +obj-$(CONFIG_SND_SOC) += sof/ obj-$(CONFIG_SND_SOC) += spear/ obj-$(CONFIG_SND_SOC) += sti/ obj-$(CONFIG_SND_SOC) += stm/
sound/soc/sof/Kconfig new file +36 -0
@@ -0,0 +1,36 @@ +config SND_SOC_SOF + tristate "Sound Open Firmware Support" + select SND_SOC_TOPOLOGY + select SND_SOC_COMPRESS + help + This adds support for Sound Open Firmware (SOF). SOF is a free and + generic open source audio DSP firmware for multiple devices. + Say Y if you have such a device that is supported by SOF. + If unsure select "N". + +config SND_SOC_SOF_DEBUG + bool "SOF debugging features" + depends on SND_SOC_SOF + help + This option can be used to enable or disable individual SOF firmware + and driver debugging options. + Say Y if you are debugging SOF FW or drivers. + If unsure select "N". + +config SND_SOC_SOF_DEBUG_XRUN_STOP + bool "SOF stop on XRUN" + depends on SND_SOC_SOF_DEBUG + help + This option forces PCMs to stop on any XRUN event. This is useful to + preserve any trace data ond pipeline status prior to the XRUN. + Say Y if you are debugging SOF FW pipeline XRUNs. + If unsure select "N". + +config SND_SOC_SOF_DEBUG_VERBOSE_IPC + bool "SOF verbose IPC logs" + depends on SND_SOC_SOF_DEBUG + help + This option enables more verbose IPC logs, with command types in + human-readable form instead of just 32-bit hex dumps. This is useful + if you are trying to debug IPC with the DSP firmware. + If unsure select "N".
sound/soc/sof/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) + +snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\ + control.o trace.o + +obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
Signature · 1 line
2.17.1