ASoC: SOF: Add Sound Open Firmware driver core
Subsystems (3)
PATCH 1/11 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 | 1 + include/sound/sof.h | 92 +++++++ sound/soc/sof/core.c | 373 +++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 504 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 970 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 +1 -0
@@ -1133,6 +1133,7 @@ struct snd_soc_pcm_runtime {/* runtime devices */ struct snd_pcm *pcm;struct snd_compr *compr; +struct snd_sof_pcm *sof;struct snd_soc_dai *codec_dai;struct snd_soc_dai *cpu_dai;
include/sound/sof.h new file +92 -0
92 lines not on this page · raw message
sound/soc/sof/core.c new file +373 -0
373 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +504 -0
504 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/11 ASoC: SOF: Add Sound Open Firmware KControl support
SOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
--- sound/soc/sof/control.c | 218 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +218 -0
@@ -0,0 +1,218 @@ +// 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) 2017 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; + +pm_runtime_get_sync (sdev->dev); + +/* 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); +pm_runtime_put_autosuspend (sdev->dev); +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; + +pm_runtime_get_sync (sdev->dev); + +/* 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); +pm_runtime_put_autosuspend (sdev->dev); +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; + +pm_runtime_get_sync (sdev->dev); + +/* 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); +pm_runtime_put_autosuspend (sdev->dev); +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; + +pm_runtime_get_sync (sdev->dev); + +/* 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); +pm_runtime_put_autosuspend (sdev->dev); +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 =0 ; + +pm_runtime_get_sync (sdev->dev); + +/* 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 %ld 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); +pm_runtime_put_autosuspend (sdev->dev); +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 =0 ; + +pm_runtime_get_sync (sdev->dev); + +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); +pm_runtime_put_autosuspend (sdev->dev); +return ret; +}
Signature · 1 line
2.17.1
Mark Brown
maintainerRe: [PATCH 02/11] ASoC: SOF: Add Sound Open Firmware KControl support
Review
Quoted 1 line · Liam Girdwood
(quoted diff) +1
-0+ pm_runtime_get_sync(sdev->dev);
There's no error checking on any of the runtime PM calls...
PATCH 3/11 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 | 147 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +147 -0
@@ -0,0 +1,147 @@ +// 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) 2017 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; +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 */ +pm_runtime_get (sdev->dev); +memcpy_fromio (buf, dfse->buf + pos, size); +pm_runtime_put (sdev->dev); + +/* 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
Mark Brown
maintainerRe: [PATCH 03/11] ASoC: SOF: Add driver debug support.
sound/soc/sof/debug.c line 64
Quoted 4 lines · Liam Girdwood
sound/soc/sof/debug.c new file +4
-0+/* copy from DSP MMIO */ +pm_runtime_get (sdev->dev); +memcpy_fromio (buf, dfse->buf + pos, size); +pm_runtime_put (sdev->dev);
Doesn't this need to be a _get_sync()?
PATCH 4/11 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 | 915 +++++++++++++++++++++++++++++++++++ sound/soc/sof/ipc.c | 659 +++++++++++++++++++++++++ 2 files changed, 1574 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 +915 -0
@@ -0,0 +1,915 @@ +/* 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) 2017 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 */ + +/* +* 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 + +/** \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; + +//uint32_t quirks; // FIXME: is 32 bits enough ? + +/* 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) */ +} __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) */ +/* TODO: FIFO word lengths can be retrieved from SOF_DAI_FMT */ +uint16_t fifo_bits_a;/* FIFO A word length (16 or 24) */ +uint16_t fifo_bits_b;/* FIFO B word length (16 or 24) */ +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 controllers */ +struct sof_ipc_dai_dmic_pdm_ctrl pdm[]; +} __attribute__((packed)); + +/* general purpose DAI configuration */ +struct sof_ipc_dai_config { +struct sof_ipc_hdr hdr; +enum sof_ipc_dai_type type; +uint32_t id;/* physical number if more than 1 of this type */ + +/* 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 index; +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; +int32_t min_value; +int32_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 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 ]; +} __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 +659 -0
659 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 5/11 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 | 641 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 641 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +641 -0
@@ -0,0 +1,641 @@ +// 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) 2017 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->sof; +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->sof; +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; + +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->sof; +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_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->sof; +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_START : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; +break ; +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; +break ; +case SNDRV_PCM_TRIGGER_STOP : + 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_RESUME : +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->sof; +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->sof; +struct snd_soc_tplg_stream_caps *caps = + &spcm->pcm.caps[substream->stream]; + +/* 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); + +pm_runtime_get_sync (sdev->dev); + +/* 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->sof; + +/* 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); +pm_runtime_put_autosuspend (sdev->dev); +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->sof = 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; + +/* 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); +pm_runtime_idle (component->dev); + +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
Mark Brown
maintainerRe: [PATCH 05/11] ASoC: SOF: Add PCM operations support
sound/soc/sof/pcm.c line 37
Quoted 4 lines · Liam Girdwood
sound/soc/sof/pcm.c new file +4
-0+/* Create DMA buffer page table for DSP */ +static int create_page_table (struct snd_pcm_substream *substream, +unsigned char *dma_area,size_t size) +{
That's a very generic name!
sound/soc/sof/pcm.c line 49
Quoted 12 lines
sound/soc/sof/pcm.c new file +12
-0+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->sof; +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); +}
...for a super thin wrapper.
sound/soc/sof/pcm.c line 69
Quoted 3 lines
sound/soc/sof/pcm.c new file +3
-0+/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ;
Should these operations be defined for a back end or should back ends have their own set of operations? Do we even need to use DPCM here for that matter?
sound/soc/sof/pcm.c line 576
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+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 ;
We print an error but don't actually do anything about it?
PATCH 6/11 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 | 92 ++ sound/soc/sof/topology.c | 2036 +++++++++++++++++++++++++++++ 2 files changed, 2128 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 +92 -0
@@ -0,0 +1,92 @@ +/* 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) 2017 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_TOPOLGOY_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 + +/* 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/topology.c new file +2036 -0
2,036 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 7/11 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/trace.c | 279 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/trace.c new file +279 -0
@@ -0,0 +1,279 @@ +// 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) 2017 Intel Corporation. All rights reserved. +* +* Author: Liam Girdwood <[email protected]> +* Yan Wang <[email protected]> +*/ + +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/slab.h> +#include <linux/sched/signal.h> +#include <linux/time.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 <linux/debugfs.h> +#include <uapi/sound/sof-ipc.h> +#include <uapi/sound/sof-fw.h> +#include "sof-priv.h" +#include "ops.h" + +static size_t sof_wait_trace_avail (struct snd_sof_dev *sdev, +loff_t pos,size_t buffer_size) +{ +wait_queue_entry_t wait; + +/* +* If host offset is less than local pos, it means write pointer of +* host DMA buffer has been wrapped. We should output the trace data +* at the end of host DMA buffer at first. +*/ +if (sdev->host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (sdev->host_offset > pos) +return sdev->host_offset - pos; + +/* wait for available trace data from FW */ +init_waitqueue_entry (&wait, current); +set_current_state (TASK_INTERRUPTIBLE ); +add_wait_queue (&sdev->trace_sleep, &wait); + +if (signal_pending (current)) { +remove_wait_queue (&sdev->trace_sleep, &wait); + goto out; + } + +/* set timeout to max value, no error code */ +schedule_timeout (MAX_SCHEDULE_TIMEOUT ); +remove_wait_queue (&sdev->trace_sleep, &wait); + +out: +/* return bytes available for copy */ +if (sdev->host_offset < pos) +return buffer_size - pos; +else +return sdev->host_offset - pos; +} + +static ssize_t sof_dfsentry_trace_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry_buf *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +unsigned long rem; +loff_t lpos = *ppos; +size_t avail, buffer_size = dfse->size; + +/* make sure we know about any failures on the DSP side */ + sdev->dtrace_error = false; + +/* check pos and count */ +if (lpos <0 ) +return -EINVAL ; +if (!count) +return 0 ; + +/* check for buffer wrap and count overflow */ + lpos = lpos % buffer_size; +if (count > buffer_size - lpos) + count = buffer_size - lpos; + +/* get available count based on current host offset */ + avail =sof_wait_trace_avail (sdev, lpos, buffer_size); +if (sdev->dtrace_error) { +dev_err (sdev->dev,"error: trace IO error\n" ); +return -EIO ; + } + +/* make sure count is <= avail */ + count = avail > count ? count : avail; + +/* copy available trace data to debugfs */ + rem =copy_to_user (buffer, dfse->buf + lpos, count); +if (rem == count) +return -EFAULT ; + + *ppos += count; + +/* move debugfs reading position */ +return count; +} + +static const struct file_operations sof_dfs_trace_fops = { + .open = simple_open, + .read = sof_dfsentry_trace_read, + .llseek = default_llseek, +}; + +static int trace_debugfs_create (struct snd_sof_dev *sdev) +{ +struct snd_sof_dfsentry_buf *dfse; + +if (!sdev) +return -EINVAL ; + + dfse =kzalloc (sizeof (*dfse),GFP_KERNEL ); +if (!dfse) +return -ENOMEM ; + + dfse->buf = sdev->dmatb.area; + dfse->size = sdev->dmatb.bytes; + dfse->sdev = sdev; + + dfse->dfsentry =debugfs_create_file ("trace" ,0444 , sdev->debugfs_root, + dfse, &sof_dfs_trace_fops); +if (!dfse->dfsentry) { +dev_err (sdev->dev, +"error: cannot create debugfs entry for trace\n" ); +kfree (dfse); +return -ENODEV ; + } + +return 0 ; +} + +int snd_sof_init_trace (struct snd_sof_dev *sdev) +{ +struct sof_ipc_dma_trace_params params; +struct sof_ipc_reply ipc_reply; +int ret; + +/* set false before start initialization */ + sdev->dtrace_is_enabled = false; + +/* allocate trace page table buffer */ + ret =snd_dma_alloc_pages (SNDRV_DMA_TYPE_DEV , sdev->parent, +PAGE_SIZE , &sdev->dmatp); +if (ret <0 ) { +dev_err (sdev->dev, +"error: can't alloc page table for trace %d\n" , ret); +return ret; + } + +/* allocate trace data buffer */ + ret =snd_dma_alloc_pages (SNDRV_DMA_TYPE_DEV_SG , sdev->parent, +DMA_BUF_SIZE_FOR_TRACE , &sdev->dmatb); +if (ret <0 ) { +dev_err (sdev->dev, +"error: can't alloc buffer for trace %d\n" , ret); + goto page_err; + } + +/* craete compressed page table for audio firmware */ + ret =snd_sof_create_page_table (sdev, &sdev->dmatb, sdev->dmatp.area, + sdev->dmatb.bytes); +if (ret <0 ) + goto table_err; + + sdev->dma_trace_pages = ret; +dev_dbg (sdev->dev,"dma_trace_pages: %d\n" , sdev->dma_trace_pages); + + ret =trace_debugfs_create (sdev); +if (ret <0 ) + goto table_err; + +/* set IPC parameters */ + params.hdr.size =sizeof (params); + params.hdr.cmd =SOF_IPC_GLB_TRACE_MSG |SOF_IPC_TRACE_DMA_PARAMS ; + params.buffer.phy_addr = sdev->dmatp.addr; + params.buffer.size = sdev->dmatb.bytes; + params.buffer.offset =0 ; + params.buffer.pages = sdev->dma_trace_pages; + +init_waitqueue_head (&sdev->trace_sleep); + sdev->host_offset =0 ; + + ret =snd_sof_dma_trace_init (sdev, ¶ms.stream_tag); +if (ret <0 ) { +dev_err (sdev->dev, +"error: fail in snd_sof_dma_trace_init %d\n" , ret); + goto table_err; + } +dev_dbg (sdev->dev,"stream_tag: %d\n" , params.stream_tag); + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, + params.hdr.cmd, ¶ms,sizeof (params), + &ipc_reply,sizeof (ipc_reply)); +if (ret <0 ) { +dev_err (sdev->dev, +"error: can't set params for DMA for trace %d\n" , ret); + goto table_err; + } + + ret =snd_sof_dma_trace_trigger (sdev,SNDRV_PCM_TRIGGER_START ); +if (ret <0 ) { +dev_err (sdev->dev, +"error: snd_sof_dma_trace_trigger: start: %d\n" , ret); + goto table_err; + } + + sdev->dtrace_is_enabled = true; +return 0 ; + +table_err: +snd_dma_free_pages (&sdev->dmatb); +page_err: +snd_dma_free_pages (&sdev->dmatp); +return ret; +} +EXPORT_SYMBOL (snd_sof_init_trace); + +int snd_sof_trace_update_pos (struct snd_sof_dev *sdev, +struct sof_ipc_dma_trace_posn *posn) +{ +if (sdev->dtrace_is_enabled && sdev->host_offset != posn->host_offset) { + sdev->host_offset = posn->host_offset; +wake_up (&sdev->trace_sleep); + } + +if (posn->overflow !=0 ) +dev_err (sdev->dev, +"error: DSP trace buffer overflow %u bytes. Total messages %d\n" , + posn->overflow, posn->messages); + +return 0 ; +} + +/* an error has occurred within the DSP that prevents further trace */ +void snd_sof_trace_notify_for_error (struct snd_sof_dev *sdev) +{ +if (sdev->dtrace_is_enabled) { +dev_err (sdev->dev,"error: waking up any trace sleepers\n" ); + sdev->dtrace_error = true; +wake_up (&sdev->trace_sleep); + } +} +EXPORT_SYMBOL (snd_sof_trace_notify_for_error); + +void snd_sof_release_trace (struct snd_sof_dev *sdev) +{ +int ret; + +if (!sdev->dtrace_is_enabled) +return ; + + ret =snd_sof_dma_trace_trigger (sdev,SNDRV_PCM_TRIGGER_STOP ); +if (ret <0 ) +dev_err (sdev->dev, +"error: snd_sof_dma_trace_trigger: stop: %d\n" , ret); + + ret =snd_sof_dma_trace_release (sdev); +if (ret <0 ) +dev_err (sdev->dev, +"error: fail in snd_sof_dma_trace_release %d\n" , ret); + +snd_dma_free_pages (&sdev->dmatb); +snd_dma_free_pages (&sdev->dmatp); +} +EXPORT_SYMBOL (snd_sof_release_trace);
Signature · 1 line
2.17.1
PATCH 8/11 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) 2017 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
Mark Brown
maintainerRe: [PATCH 08/11] ASoC: SOF: Add DSP HW abstraction operations
sound/soc/sof/ops.c line 23
Quoted 3 lines · Liam Girdwood
sound/soc/sof/ops.c new file +3
-0+int snd_sof_pci_update_bits_unlocked (struct snd_sof_dev *sdev,u32 offset, +u32 mask,u32 value) +{
This stuff all looks a lot like regmap (we'd need a regmap-pci but I'm sure some other things could use it).
PATCH 9/11 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) 2017 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) +{ +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) +{ +dev_dbg (sdev->dev,"loading firmware\n" ); + +if (sdev->ops->load_firmware) +return sdev->ops->load_firmware (sdev, fw); +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 10/11 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 | 69 +++++++++++++++++++++++ include/uapi/sound/sof-tone.h | 28 ++++++++++ 4 files changed, 228 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) 2017 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 +69 -0
69 lines not on this page · raw message
include/uapi/sound/sof-tone.h new file +28 -0
@@ -0,0 +1,28 @@ +/* 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) 2017 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 11/11 ASoC: SOF: Add Build support for SOF core
In reply to Liam GirdwoodBuild SOF core.
--- sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/sof/Kconfig | 38 ++++++++++++++++++++++++++++++++++++++ sound/soc/sof/Makefile | 6 ++++++ 4 files changed, 46 insertions(+) create mode 100644 sound/soc/sof/Kconfig create mode 100644 sound/soc/sof/Makefile
sound/soc/Kconfig +1 -0
@@ -64,6 +64,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
@@ -48,6 +48,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 +38 -0
@@ -0,0 +1,38 @@ +config SND_SOC_SOF_PCI + tristate + +config SND_SOC_SOF_ACPI + tristate + +config SND_SOC_SOF_PLATFORM + tristate + +config SND_SOC_SOF + tristate "Sound Open Firmware Support" + default m + 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". +
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 debug.o topology.o\ + control.o trace.o + +obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
Signature · 1 line
2.17.1
Re: [PATCH 11/11] ASoC: SOF: Add Build support for SOF core
I doubled-checked the series and this is the only (minor) miss I could find. Maybe a doubt on the control sizes in patch 2.
sound/soc/sof/Kconfig line 12
Quoted 3 lines
sound/soc/sof/Kconfig new file +3
-0+config SND_SOC_SOF + tristate "Sound Open Firmware Support" + default m
we removed the default recently in topic/sof-dev, probably a miss while squashing the code and making it pretty.
sound/soc/sof/Kconfig line 18
Quoted 6 lines
sound/soc/sof/Kconfig new file +6
-0+ 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.
Y or m?
Quoted 8 lines · Liam Girdwood
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.
Quoted 4 lines
SOF also requires some data in ASoC PCM runtime data for looking up SOF data during ASoC PCM operations.
Signed-off-by Liam Girdwood <[email protected]>
Could you give a cover letter? It'd be helpful for digestion of such series.
thanks,
Takashi
Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Liam Girdwood
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.
Quoted 8 lines
Quoted 4 lines
SOF also requires some data in ASoC PCM runtime data for looking up SOF data during ASoC PCM operations.
Signed-off-by Liam Girdwood <[email protected]>Could you give a cover letter? It'd be helpful for digestion of such series.
Sure, will follow shortly.
Thanks
Liam
Mark Brown
maintainerinclude/sound/soc.h struct snd_soc_pcm_runtime { · line 1138
Quoted 12 lines · Liam Girdwood
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
+++
b/include/sound/soc.hinclude/sound/soc.h +1
-0@@ -1133,6 +1133,7 @@ struct snd_soc_pcm_runtime {/* runtime devices */ struct snd_pcm *pcm;struct snd_compr *compr; +struct snd_sof_pcm *sof;struct snd_soc_dai *codec_dai;struct snd_soc_dai *cpu_dai;
Can we rename this somehow to be less specific to SoF or move it to be somewhere other than the runtime structure? I can see why you've done this but I can also see every DSP vendor turning up and trying to add their own field in here.
include/sound/sof.h line 6
Quoted 5 lines
include/sound/sof.h new file +5
-0+/* +* 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) 2017 Intel Corporation. All rights reserved.
2017?
sound/soc/sof/core.c line 3
Quoted 7 lines
index 000000000000..29458909182a
sound/soc/sof/core.c new file +3
-0@@ -0,0 +1,373 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +/* +* This file is provided under a dual BSD/GPLv2 license. When using or
Please make the entire comment a C++ one, it makes it look more intentional.
sound/soc/sof/core.c line 129
Quoted 4 lines
sound/soc/sof/core.c new file +4
-0+static inline unsigned int sof_get_pages (size_t size) +{ +return (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +}
This feels like there should be a generic MM function for it?
Quoted 19 lines
sound/soc/sof/core.c new file +19
-0+/* +* Generic buffer page table creation. +*/ + +int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size); + +dev_dbg (sdev->dev,"generating page table for %p size 0x%zx pages %d\n" , + dmab->area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; +u32 pfn =snd_sgbuf_get_addr (dmab, i *PAGE_SIZE ) >>PAGE_SHIFT ; +u32 *pg_table;
sound/soc/sof/core.c line 219
Quoted 10 lines
sound/soc/sof/core.c new file +10
-0+ +dev_dbg (sdev->dev,"pfn i %i idx %d pfn %x\n" , i, idx, pfn); + + pg_table = (u32 *)(page_table + idx); + +if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn; + }
I'm not 100% clear what this is intended to do - lots of magic numbers and dependencies on the host memory configuration.
Quoted 1 line · Mark Brown
Quoted 1 line
Apologies for the delay.
Quoted 9 lines · Liam Girdwood
sound/soc/sof/core.c line 129
Quoted 6 lines
sound/soc/sof/core.c new file +4
-0+static inline unsigned int sof_get_pages (size_t size) +{ +return (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +}This feels like there should be a generic MM function for it?
There is and there is not even a user for this inline ! Removed.
Quoted 28 lines
Quoted 28 lines
sound/soc/sof/core.c new file +13
-0+/* +* Generic buffer page table creation. +*/ + +int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size); + + dev_dbg(sdev->dev, "generating page table for %p size 0x%zx pages%d\n",
sound/soc/sof/core.c new file +5
-0+ dmab->area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; + u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >>
PAGE_SHIFT;sound/soc/sof/core.c new file +3
-0+u32 *pg_table; + + dev_dbg(sdev->dev, "pfn i %i idx %d pfn %x\n", i, idx,pfn);
sound/soc/sof/core.c new file +3
-0+ + pg_table = (u32 *)(page_table + idx); +
Quoted 8 lines
sound/soc/sof/core.c line 219
Quoted 5 lines
sound/soc/sof/core.c new file +5
-0+if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn; + }I'm not 100% clear what this is intended to do - lots of magic numbers and dependencies on the host memory configuration.
I'll add some more detail in the comments here, but the general gist is that we compress PHY pages addresses (i.e. drop 12 lsb from each) and pack them into a buffer. The intention is to make this compressed PFN buffer as small as possible (so it cant describe a large set of SG pages in an architecture agnostic manner).
Liam
we seem to have a new 0-day report with randconfig related to the page/sgbuffer management. Not sure why it wasn't seen before, I've already fixed quite a few exotic configurations for non-Intel targets.
sound/soc/sof/core.c: In function 'snd_sof_create_page_table':sound/soc/sof/core.c:201:10: error: implicit declaration of function 'snd_sgbuf_aligned_pages' [-Werror=implicit-function-declaration] pages = snd_sgbuf_aligned_pages(size);
^
Looking at the code:
sound/soc/sof/core.c line 129
Quoted 4 lines
sound/soc/sof/core.c new file +4
-0+static inline unsigned int sof_get_pages (size_t size) +{ +return (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +}
this inline doesn't seem to be used but duplicates the code from
static inline unsigned int snd_sgbuf_aligned_pages(size_t size) {
return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
}
which is used below
sound/soc/sof/core.c line 201
Quoted 7 lines
sound/soc/sof/core.c new file +7
-0+int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size);
this code doesn't compile unless CONFIG_SND_DMA_SGBUF is defined (it is set for the intel-specific code but not for the SOF core). We can fix this in different ways
0. require SND_CMD_SGBUF for the core - likely not desirable
1. use sof_get_pages()
2. change include/sound/memalloc.h to make sure this snd_sgbuf_aligned_pages() inline is available whether CONFIG_SND_DMA_SGBUF is defined or not - maybe making sure while we are at it that the malloc and free functions are empty static inlines?
Thoughts?
Thanks
-Pierre
Quoted 11 lines
sound/soc/sof/core.c new file +11
-0+ +dev_dbg (sdev->dev,"generating page table for %p size 0x%zx pages %d\n" , + dmab->area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; +u32 pfn =snd_sgbuf_get_addr (dmab, i *PAGE_SIZE ) >>PAGE_SHIFT ; +u32 *pg_table; + +dev_dbg (sdev->dev,"pfn i %i idx %d pfn %x\n" , i, idx, pfn); +
sound/soc/sof/core.c line 222
Quoted 10 lines
sound/soc/sof/core.c new file +10
-0+ pg_table = (u32 *)(page_table + idx); + +if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn; + } + +return pages; +}
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 23 lines · Pierre-Louis Bossart
we seem to have a new 0-day report with randconfig related to the page/sgbuffer management. Not sure why it wasn't seen before, I've already fixed quite a few exotic configurations for non-Intel targets.
sound/soc/sof/core.c: In function 'snd_sof_create_page_table':sound/soc/sof/core.c:201:10: error: implicit declaration of function 'snd_sgbuf_aligned_pages' [-Werror=implicit-function-declaration] pages =snd_sgbuf_aligned_pages(size);
^
Looking at the code:sound/soc/sof/core.c line 129
Quoted 4 lines
sound/soc/sof/core.c new file +4
-0+static inline unsigned int sof_get_pages (size_t size) +{ +return (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +}this inline doesn't seem to be used but duplicates the code from
static inline unsigned int
snd_sgbuf_aligned_pages(size_t size){
return (size +PAGE_SIZE- 1) >>PAGE_SHIFT;
}which is used below
Quoted 16 lines
sound/soc/sof/core.c line 201
Quoted 7 lines
sound/soc/sof/core.c new file +7
-0+int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size);this code doesn't compile unless
CONFIG_SND_DMA_SGBUFis defined (it is set for the intel-specific code but not for the SOF core). We can fix this in different ways
0. requireSND_CMD_SGBUFfor the core - likely not desirable
1. usesof_get_pages()
2. changeinclude/sound/memalloc.hto make sure thissnd_sgbuf_aligned_pages()inline is available whetherCONFIG_SND_DMA_SGBUFis defined or not - maybe making sure while we are at it that the malloc and free functions are empty static inlines?
The latter sounds like a better choice to me.
Just move the function to outside ifdef.
thanks,
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 42 lines · Takashi Iwai
Quoted 23 lines · Pierre-Louis Bossart
we seem to have a new 0-day report with randconfig related to the page/sgbuffer management. Not sure why it wasn't seen before, I've already fixed quite a few exotic configurations for non-Intel targets.
sound/soc/sof/core.c: In function 'snd_sof_create_page_table':sound/soc/sof/core.c:201:10: error: implicit declaration of function 'snd_sgbuf_aligned_pages' [-Werror=implicit-function-declaration]
pages =snd_sgbuf_aligned_pages(size);
^
Looking at the code:sound/soc/sof/core.c line 129
Quoted 4 lines
sound/soc/sof/core.c new file +4
-0+static inline unsigned int sof_get_pages (size_t size) +{ +return (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +}this inline doesn't seem to be used but duplicates the code from
static inline unsigned int
snd_sgbuf_aligned_pages(size_t size){
return (size +PAGE_SIZE- 1) >>PAGE_SHIFT;
}which is used below
Quoted 16 lines
sound/soc/sof/core.c line 201
Quoted 7 lines
sound/soc/sof/core.c new file +7
-0+int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size);this code doesn't compile unless
CONFIG_SND_DMA_SGBUFis defined (it is set for the intel-specific code but not for the SOF core). We can fix this in different ways
0. requireSND_CMD_SGBUFfor the core - likely not desirable
1. usesof_get_pages()
2. changeinclude/sound/memalloc.hto make sure thissnd_sgbuf_aligned_pages()inline is available whetherCONFIG_SND_DMA_SGBUFis defined or not - maybe making sure while we are at it that the malloc and free functions are empty static inlines?
Quoted 2 lines
The latter sounds like a better choice to me.
Just move the function to outside ifdef.
Will do, thanks for the feedback.
-Pierre
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel