ASoC: Sound Open Firmware (SOF) core
Subsystems (3)
v5 cover ASoC: Sound Open Firmware (SOF) core
Sound Open Firmware (SOF) is a host and DSP architecture agnostic audio DSP firmware. SOF is not tied to any specific host architecture or any specific physical IO communication type (it will work with on SoC DSPs, or DSP connected via SPI/I2C).
SOF is also not coupled to any particular DSP architecture and has abstraction similar to Linux to allow porting to other DSP architectures.
This patch series introduces the SOF core and utilities. Support for Intel devices is provided as a follow-up series.
The SOF core manages all the core DSP services and ALSA/ASoC IO. The core is responsible for loading firmware, parsing topology, exposing PCMs and kcontrols, providing debug and trace mechanisms and performing IPC between host and DSP.
The SOF core also has logic to allow reuse of existing machine drivers for other platforms/machines without any code modification. i.e. DAI links can be modified at runtime to bind with SOF and SOF topologies instead of existing hard coded DAI links and topology.
Future patches will simplify the IPC interface to allow e.g. for the use of RPMsg or mailboxes on other hardware, the changes are not included just yet.
This patchset is dependent on 3 patches already shared on alsa-devel but not yet merged:
ASoC: topology: Align tplg pointer increment across all kcontrols
ASoC: core: support driver alias names for FE topology overrides
ASoC: dapm: set power_check callback for widgets that shouldnt be always on
Changes since v4:
feedback from Mark:
Removed need for private field in soc_runtime
Completely reworked IPC, now much simpler and robust. IPC refactoring work will continue to e.g. allow for different types of IPC hardware and a better split between core and platform-specific drivers.
Feedback from Takashi:
Clarified endianness and alignment issues for page tables Removed useless mutexes
Removed unneeded initializations, return types and wrappers Use snd_mask_set_format()
Trace code flow optimization
Removed checks on preallocate_pages()
Test status of open/close functions.
Released reference when pm_runtime_get_sync fails
Fixed multiple memory allocation issues
Fixed static analysis warnings
Fixed error checks with copy_to_user()
Added support for multi-core DSPs
Fixed leaked references with firmware handling on resume Multiple topology fixes/improvements (enum/switch, mux, removal of duplicate connections, widget power not reported as ON) Code simplifications (removed set-but-unused, typecasts, etc).
Changes since v3:
Addressed dozens ofcomments from Takashi Iwai, Mark Brown, Andy Shevchenko, Daniel Baluta (Thanks!)
Hardened memory allocation, fixed module load/unload oops or errors (now at hundreds of cycles on ApolloLake devices)
Fixed suspend/resume and removed use of suspend_late, now using snd_soc_pm_ops and standard flow
Fixed topology free (multiple patches already contributed for ASoC-core)
Fixed debugfs/pm_runtime interaction
Removed error checks on debugfs, changed to EXPORT_SYMBOL_GPL Added filenames in debug messages, ues hex_dump_to_buffer Removed "sof-audio" platform device and added better error checks on probe
Reworked data structures to remove mix of const/variable fields and duplication of pointers for platform-specific changes Removed redundant ops tables
Fixed trace/logger issues
Fixed issues with loader (alignment and block size errors) Fixed release_firmware handling (was all over the place) Simplified PCI handling
Added comments on non-atomic triggers
Removed enum controls (not supported in topology) Simplified include file dependencies
Fix cppcheck warnings
Fixed Kconfigs to deal with Kbuild warnings on exotic architectures
Precisions:
The code in this patchset is directly squashed from the SOF development branch [1], which tracks Mark Brown's for-next branch on a weekly basis and the configurations used for testing are based on the defconfigs at [2]. The patches are also used backported for Chromebook devices.
Full disclosure on known limitation and issues (full list at [3])
a) the interaction with ASoC is not always perfect, there are a couple of points where a better solution is desired (use of private data, support for link DMA, etc). The known points are explicitly documented in the code and will be updated. To be clearer, it's our belief that SOF does not cripple ASoC in any way, and that merging this SOF core does not harm others. It's just complicated to get things right, especially on a couple of cases where the topology and DPCM frameworks generate complex flows that very few people understand.
b) The get/put methods for controls generate an IPC and possibly a wake-up. This is not optimal and is being fixed.
c) runtime_pm is being hardened and the use of SMART_SUSPEND was suggested.
Thank you for reviews and comments, we appreciate the time spent commenting on this large patchset. Thanks in particular to Alan Cox and Andy Shevchenko for their comments on an earlier version. This patchset also includes contributions from Daniel Baluta for loading code on non-Intel platforms.
Pierre
[1] https://github.com/thesofproject/linux
[2] https://github.com/thesofproject/kconfig
[3] https://github.com/thesofproject/linux/issues
Liam Girdwood (12):
ASoC: SOF: Add Sound Open Firmware driver core
ASoC: SOF: Add Sound Open Firmware KControl support
ASoC: SOF: Add driver debug support.
ASoC: SOF: Add support for IPC IO between DSP and Host
ASoC: SOF: Add PCM operations support
ASoC: SOF: Add support for loading topologies
ASoC: SOF: Add DSP firmware logger support
ASoC: SOF: Add DSP HW abstraction operations
ASoC: SOF: Add firmware loader support
ASoC: SOF: Add userspace ABI support
ASoC: SOF: Add PM support
ASoC: SOF: Add Nocodec machine driver support
Pierre-Louis Bossart (2):
ASoC: SOF: Add xtensa support
ASoC: SOF: Add utils
include/sound/sof.h | 100 + include/sound/sof/control.h | 158 ++ include/sound/sof/dai-intel.h | 178 ++ include/sound/sof/dai.h | 75 + include/sound/sof/header.h | 158 ++ include/sound/sof/info.h | 118 ++ include/sound/sof/pm.h | 48 + include/sound/sof/stream.h | 148 ++ include/sound/sof/topology.h | 256 +++ include/sound/sof/trace.h | 66 + include/sound/sof/xtensa.h | 44 + include/uapi/sound/sof/abi.h | 62 + include/uapi/sound/sof/eq.h | 172 ++ include/uapi/sound/sof/fw.h | 78 + include/uapi/sound/sof/header.h | 27 + include/uapi/sound/sof/manifest.h | 188 ++ include/uapi/sound/sof/tokens.h | 103 + include/uapi/sound/sof/tone.h | 21 + include/uapi/sound/sof/trace.h | 97 + sound/soc/sof/control.c | 544 ++++++ sound/soc/sof/core.c | 489 +++++ sound/soc/sof/debug.c | 219 +++ sound/soc/sof/ipc.c | 742 ++++++++ sound/soc/sof/loader.c | 376 ++++ sound/soc/sof/nocodec.c | 109 ++ sound/soc/sof/ops.c | 204 ++ sound/soc/sof/ops.h | 403 ++++ sound/soc/sof/pcm.c | 723 +++++++ sound/soc/sof/pm.c | 373 ++++ sound/soc/sof/sof-priv.h | 616 ++++++ sound/soc/sof/topology.c | 2913 +++++++++++++++++++++++++++++ sound/soc/sof/trace.c | 295 +++ sound/soc/sof/utils.c | 112 ++ sound/soc/sof/xtensa/Kconfig | 2 + sound/soc/sof/xtensa/Makefile | 5 + sound/soc/sof/xtensa/core.c | 138 ++ 36 files changed, 10360 insertions(+) create mode 100644 include/sound/sof.h create mode 100644 include/sound/sof/control.h create mode 100644 include/sound/sof/dai-intel.h create mode 100644 include/sound/sof/dai.h create mode 100644 include/sound/sof/header.h create mode 100644 include/sound/sof/info.h create mode 100644 include/sound/sof/pm.h create mode 100644 include/sound/sof/stream.h create mode 100644 include/sound/sof/topology.h create mode 100644 include/sound/sof/trace.h create mode 100644 include/sound/sof/xtensa.h create mode 100644 include/uapi/sound/sof/abi.h create mode 100644 include/uapi/sound/sof/eq.h create mode 100644 include/uapi/sound/sof/fw.h create mode 100644 include/uapi/sound/sof/header.h create mode 100644 include/uapi/sound/sof/manifest.h create mode 100644 include/uapi/sound/sof/tokens.h create mode 100644 include/uapi/sound/sof/tone.h create mode 100644 include/uapi/sound/sof/trace.h create mode 100644 sound/soc/sof/control.c create mode 100644 sound/soc/sof/core.c create mode 100644 sound/soc/sof/debug.c create mode 100644 sound/soc/sof/ipc.c create mode 100644 sound/soc/sof/loader.c create mode 100644 sound/soc/sof/nocodec.c create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h create mode 100644 sound/soc/sof/pcm.c create mode 100644 sound/soc/sof/pm.c create mode 100644 sound/soc/sof/sof-priv.h create mode 100644 sound/soc/sof/topology.c create mode 100644 sound/soc/sof/trace.c create mode 100644 sound/soc/sof/utils.c create mode 100644 sound/soc/sof/xtensa/Kconfig create mode 100644 sound/soc/sof/xtensa/Makefile create mode 100644 sound/soc/sof/xtensa/core.c
Signature · 1 line
2.17.1
PATCH v5 1/14 ASoC: SOF: Add Sound Open Firmware driver core
From: Liam Girdwood <[email protected]>
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/sof.h | 94 ++++++ sound/soc/sof/core.c | 489 +++++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 616 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 1199 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/sof.h new file +94 -0
@@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +* +* Author: Liam Girdwood <[email protected]> +*/ + +#ifndef __INCLUDE_SOUND_SOF_H +#define __INCLUDE_SOUND_SOF_H + +#include <linux/pci.h> +#include <sound/soc-acpi.h> + +struct snd_sof_dsp_ops ; + +/* +* SOF Platform data. +*/ +struct snd_sof_pdata { +const struct firmware *fw; +const char *drv_name; +const char *name; +const char *platform; + +struct device *dev; + +/* +* notification callback used if the hardware initialization +* can take time or is handled in a workqueue. This callback +* can be used by the caller to e.g. enable runtime_pm +* or limit functionality until all low-level inits are +* complete. +*/ +void (*sof_probe_complete)(struct device *dev); + +/* descriptor */ +const struct sof_dev_desc *desc; + +/* firmware and topology filenames */ +const char *fw_filename_prefix; +const char *fw_filename; +const char *tplg_filename_prefix; +const char *tplg_filename; + +/* machine */ +struct platform_device *pdev_mach; +const struct snd_soc_acpi_mach *machine; + +void *hw_pdata; +}; + +/* +* Descriptor used for setting up SOF platform data. This is used when +* ACPI/PCI data is missing or mapped differently. +*/ +struct sof_dev_desc { +/* list of machines using this configuration */ +struct snd_soc_acpi_mach *machines; + +/* Platform resource indexes in BAR / ACPI resources. */ +/* Must set to -1 if not used - add new items to end */ +int resindex_lpe_base; +int resindex_pcicfg_base; +int resindex_imr_base; +int irqindex_host_ipc; +int resindex_dma_base; + +/* DMA only valid when resindex_dma_base != -1*/ +int dma_engine; +int dma_size; + +/* IPC timeouts in ms */ +int ipc_timeout; +int boot_timeout; + +/* chip information for dsp */ +const void *chip_info; + +/* defaults for no codec mode */ +const char *nocodec_fw_filename; +const char *nocodec_tplg_filename; + +/* defaults paths for firmware and topology files */ +const char *default_fw_path; +const char *default_tplg_path; + +const struct snd_sof_dsp_ops *ops; +const struct sof_arch_ops *arch_ops; +}; + +#endif
sound/soc/sof/core.c new file +489 -0
489 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +616 -0
616 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v5 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 5 lines · Pierre-Louis Bossart
From: Liam Girdwood <[email protected]>
The Sound Open Firmware driver core is a generic architecture independent layer that allows SOF to be used on many different different
One different is enough.
Quoted 2 lines
sound/soc/sof/core.c new file +0
-0
....
sound/soc/sof/core.c
Quoted 2 lines
sound/soc/sof/core.c new file +2
-0+struct snd_sof_pcm *snd_sof_find_spcm_name (struct snd_sof_dev *sdev, +char *name)
Make it const char *.
sound/soc/sof/core.c
Quoted 2 lines
sound/soc/sof/core.c new file +2
-0+{ +struct snd_sof_pcm *spcm =NULL ;
Superfluous initialization.
Quoted 9 lines
sound/soc/sof/core.c new file +9
-0+list_for_each_entry (spcm, &sdev->pcm_list, list) { +if (strcmp (spcm->pcm.dai_name, name) ==0 ) +return spcm; + +if (strcmp (spcm->pcm.caps[0 ].name, name) ==0 ) +return spcm; + +if (strcmp (spcm->pcm.caps[1 ].name, name) ==0 ) +return spcm;
sound/soc/sof/core.c line 50
Quoted 10 lines
sound/soc/sof/core.c new file +10
-0+ } + +return NULL ; +} + +struct snd_sof_pcm *snd_sof_find_spcm_comp (struct snd_sof_dev *sdev, +unsigned int comp_id, +int *direction) +{ +struct snd_sof_pcm *spcm =NULL ;
Ditto, superfluous.
Quoted 8 lines
sound/soc/sof/core.c new file +8
-0+list_for_each_entry (spcm, &sdev->pcm_list, list) { +if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].comp_id == comp_id) { + *direction =SNDRV_PCM_STREAM_PLAYBACK ; +return spcm; + } +if (spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].comp_id == comp_id) { + *direction =SNDRV_PCM_STREAM_CAPTURE ; +return spcm;
sound/soc/sof/core.c line 69
Quoted 10 lines
sound/soc/sof/core.c new file +10
-0+ } + } + +return NULL ; +} + +struct snd_sof_pcm *snd_sof_find_spcm_pcm_id (struct snd_sof_dev *sdev, +unsigned int pcm_id) +{ +struct snd_sof_pcm *spcm =NULL ;
Ditto... I stop repeating.
sound/soc/sof/core.c line 80
Quoted 10 lines
sound/soc/sof/core.c new file +10
-0+list_for_each_entry (spcm, &sdev->pcm_list, list) { +if (le32_to_cpu (spcm->pcm.pcm_id) == pcm_id) +return spcm; + } + +return NULL ; +} + +struct snd_sof_widget *snd_sof_find_swidget (struct snd_sof_dev *sdev, +char *name)
const char *. Some other functions follow the similar pattern...
Quoted 14 lines
sound/soc/sof/core.c new file +14
-0+int snd_sof_get_status (struct snd_sof_dev *sdev,u32 panic_code, +u32 tracep_code,void *oops, +struct sof_ipc_panic_info *panic_info, +void *stack,size_t stack_words) +{ +u32 code; +int i; + +/* is firmware dead ? */ +if ((panic_code &SOF_IPC_PANIC_MAGIC_MASK ) !=SOF_IPC_PANIC_MAGIC ) { +dev_err (sdev->dev,"error: unexpected fault 0x%8.8x trace 0x%8.8x\n" , + panic_code, tracep_code); +return 0 ;/* no fault ? */ + }
....
sound/soc/sof/core.c line 185
Quoted 7 lines
sound/soc/sof/core.c new file +7
-0+out: +dev_err (sdev->dev,"error: panic happen at %s:%d\n" , + panic_info->filename, panic_info->linenum); +sof_oops (sdev, oops); +sof_stack (sdev, oops, stack, stack_words); +return -EFAULT ; +}
So this function returns -EFAULT for the normal operation while 0 for unexpected case? I see that no callers actually check the return value, but it's some what unintuitive. Worth for adding a comment about the return code.
thanks,
Takashi
Re: [PATCH v5 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Thanks Takashi for your review!
Quoted 4 lines
Quoted 2 lines
The Sound Open Firmware driver core is a generic architecture independent layer that allows SOF to be used on many different different
One different is enough.
Indeed
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_sof_dev *sdev, + char *name)Make it const char *.
yep, will fix all occurrences
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + struct snd_sof_pcm *spcm = NULL;Superfluous initialization.
indeed, that was missed. will fix all occurrences, thanks!
Quoted 15 lines
Quoted 14 lines
sound/soc/sof/core.c new file +14
-0+int snd_sof_get_status (struct snd_sof_dev *sdev,u32 panic_code, +u32 tracep_code,void *oops, +struct sof_ipc_panic_info *panic_info, +void *stack,size_t stack_words) +{ +u32 code; +int i; + +/* is firmware dead ? */ +if ((panic_code &SOF_IPC_PANIC_MAGIC_MASK ) !=SOF_IPC_PANIC_MAGIC ) { +dev_err (sdev->dev,"error: unexpected fault 0x%8.8x trace 0x%8.8x\n" , + panic_code, tracep_code); +return 0 ;/* no fault ? */ + }....
Quoted 12 lines
sound/soc/sof/core.c line 185
Quoted 7 lines
sound/soc/sof/core.c new file +7
-0+out: +dev_err (sdev->dev,"error: panic happen at %s:%d\n" , + panic_info->filename, panic_info->linenum); +sof_oops (sdev, oops); +sof_stack (sdev, oops, stack, stack_words); +return -EFAULT ; +}So this function returns
-EFAULTfor the normal operation while 0 for unexpected case? I see that no callers actually check the return value, but it's some what unintuitive. Worth for adding a comment about the return code.
Good point. Will need to re-look at the flow. At some point, this is the sort of error that should lead to firmware recovery, where the driver takes the initiative of resetting hardware and reinitializing. We know this is on the list of features to be implemented but it's not ready yet.
PATCH v5 2/14 ASoC: SOF: Add Sound Open Firmware KControl support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
SOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
The current implementation is aligned with previous Intel solutions, but is not optimal and can be improved:
a) for every get/put the host wakes up the DSP and generates an IPC. The kernel should cache the values and generate an IPC only when strictly necessary.
b) the firmware can be implemented to only instantiate the pipelines and related control-related parts that are needed at a given time, and power-gate the relevant SRAM blocks.
The development tasks for these two improvements has started, once validated they willl be provided in an update.
--- sound/soc/sof/control.c | 544 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 544 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +544 -0
@@ -0,0 +1,544 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +/* Mixer Controls */ + +#include <linux/pm_runtime.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 ]; + +return volume_map[value]; +} + +static inline u32 ipc_to_mixer (u32 value,u32 *volume_map,int size) +{ +int i; + +for (i =0 ; i < size; i++) { +if (volume_map[i] >= value) +return i; + } + +return i -1 ; +} + +int snd_sof_volume_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int err, ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: volume get failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.integer.value[i] = +ipc_to_mixer (cdata->chanv[i].value, + scontrol->volume_table, sm->max +1 ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: volume get failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_volume_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: volume put failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) { + cdata->chanv[i].value = +mixer_to_ipc (ucontrol->value.integer.value[i], + scontrol->volume_table, sm->max +1 ); + cdata->chanv[i].channel = i; + } + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: volume put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int err, ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: switch get failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_SWITCH ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.integer.value[i] = cdata->chanv[i].value; + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: switch get failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: switch put failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) { + cdata->chanv[i].value = ucontrol->value.integer.value[i]; + 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_SWITCH ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: switch put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_enum_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_enum *se = + (struct soc_enum *)kcontrol->private_value; +struct snd_sof_control *scontrol = se->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int err, ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: enum get failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.enumerated.item[i] = cdata->chanv[i].value; + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: enum get failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_enum_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_enum *se = + (struct soc_enum *)kcontrol->private_value; +struct snd_sof_control *scontrol = se->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: enum put failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) { + cdata->chanv[i].value = ucontrol->value.enumerated.item[i]; + 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_ENUM ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: enum put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_bytes_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct sof_abi_hdr *data = cdata->data; +size_t size; +int ret, err; + +if (be->max >sizeof (ucontrol->value.bytes.data)) { +dev_err_ratelimited (sdev->dev, +"error: data max %d exceeds ucontrol data array size\n" , + be->max); +return -EINVAL ; + } + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: bytes get failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , scontrol->cmd); + size = data->size +sizeof (*data); +if (size > be->max) { +dev_err_ratelimited (sdev->dev, +"error: DSP sent %zu bytes max is %d\n" , + size, be->max); + ret = -EINVAL ; + goto out; + } + +/* copy back to kcontrol */ +memcpy (ucontrol->value.bytes.data, data, size); + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: bytes get failed to idle %d\n" , + err); +return ret; +} + +int snd_sof_bytes_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct sof_abi_hdr *data = cdata->data; +int ret, err; + +if (be->max >sizeof (ucontrol->value.bytes.data)) { +dev_err_ratelimited (sdev->dev, +"error: data max %d exceeds ucontrol data array size\n" , + be->max); +return -EINVAL ; + } + +if (data->size > be->max) { +dev_err_ratelimited (sdev->dev, +"error: size too big %d bytes max is %d\n" , + data->size, be->max); +return -EINVAL ; + } + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: bytes put failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* 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); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: bytes put failed to idle %d\n" , + err); +return ret; +} + +int snd_sof_bytes_ext_put (struct snd_kcontrol *kcontrol, +const unsigned int __user *binary_data, +unsigned int size) +{ +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 snd_ctl_tlv header; +const struct snd_ctl_tlv __user *tlvd = + (const struct snd_ctl_tlv __user *)binary_data; +int ret; +int err; +int max_size =SOF_IPC_MSG_MAX_SIZE - +sizeof (const struct sof_ipc_ctrl_data ); + +/* +* The beginning of bytes data contains a header from where +* the length (as bytes) is needed to know the correct copy +* length of data from tlvd->tlv. +*/ +if (copy_from_user (&header, tlvd,sizeof (const struct snd_ctl_tlv ))) +return -EFAULT ; + +/* +* The maximum length that can be copied is limited by IPC max +* length and topology defined length for ext bytes control. +*/ +if (be->max < max_size)/* min() not used to avoid sparse warnings */ + max_size = be->max; +if (header.length > max_size) { +dev_err_ratelimited (sdev->dev, +"error: Bytes data size %d exceeds max %d.\n" , + header.length, max_size); +return -EINVAL ; + } + +/* Check that header id matches the command */ +if (header.numid != scontrol->cmd) { +dev_err_ratelimited (sdev->dev, +"error: incorrect numid %d\n" , + header.numid); +return -EINVAL ; + } + +if (copy_from_user (cdata->data, tlvd->tlv, header.length)) +return -EFAULT ; + +if (cdata->data->magic !=SOF_ABI_MAGIC ) { +dev_err_ratelimited (sdev->dev, +"error: Wrong ABI magic 0x%08x.\n" , + cdata->data->magic); +return -EINVAL ; + } + +if (SOF_ABI_VERSION_INCOMPATIBLE (SOF_ABI_VERSION , cdata->data->abi)) { +dev_err_ratelimited (sdev->dev,"error: Incompatible ABI version 0x%08x.\n" , + cdata->data->abi); +return -EINVAL ; + } + +if (cdata->data->size +sizeof (const struct sof_abi_hdr ) > max_size) { +dev_err_ratelimited (sdev->dev, +"error: Mismatch in ABI data size (truncated?).\n" ); +return -EINVAL ; + } + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: bytes_ext put failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* 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); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: bytes_ext put failed to idle %d\n" , + err); + +return ret; +} + +int snd_sof_bytes_ext_get (struct snd_kcontrol *kcontrol, +unsigned int __user *binary_data, +unsigned int size) +{ +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 snd_ctl_tlv header; +struct snd_ctl_tlv __user *tlvd = + (struct snd_ctl_tlv __user *)binary_data; +int max_size =SOF_IPC_MSG_MAX_SIZE - +sizeof (const struct sof_ipc_ctrl_data ); +int data_size; +int err; +int ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev, +"error: bytes_ext get failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* +* Decrement the limit by ext bytes header size to +* ensure the user space buffer is not exceeded. +*/ + size -=sizeof (const struct snd_ctl_tlv ); + +/* set the ABI header values */ + cdata->data->magic =SOF_ABI_MAGIC ; + cdata->data->abi =SOF_ABI_VERSION ; + +/* get all the component data from DSP */ + ret =snd_sof_ipc_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , scontrol->cmd); + +/* Prevent read of other kernel data or possibly corrupt response */ + data_size = cdata->data->size +sizeof (const struct sof_abi_hdr ); + +/* check size. min3() is not used to avoid sparse warnings */ +if (size < max_size) + max_size = size; +if (be->max < max_size) + max_size = be->max; +if (data_size > max_size) { +dev_err_ratelimited (sdev->dev, +"error: user data size %d exceeds max size %d.\n" , + data_size, max_size); + ret = -EINVAL ; + goto out; + } + + header.numid = scontrol->cmd; + header.length = data_size; +if (copy_to_user (tlvd, &header,sizeof (const struct snd_ctl_tlv ))) { + ret = -EFAULT ; + goto out; + } + +if (copy_to_user (tlvd->tlv, cdata->data, data_size)) +return -EFAULT ; + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev, +"error: bytes_ext get failed to idle %d\n" , + err); +return ret; +}
Signature · 1 line
2.17.1
Re: [PATCH v5 02/14] ASoC: SOF: Add Sound Open Firmware KControl support
Quoted 15 lines · Pierre-Louis Bossart
From: Liam Girdwood <[email protected]>
SOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
The current implementation is aligned with previous Intel solutions, but is not optimal and can be improved:
a) for every get/put the host wakes up the DSP and generates an IPC. The kernel should cache the values and generate an IPC only when strictly necessary.
b) the firmware can be implemented to only instantiate the pipelines and related control-related parts that are needed at a given time, and power-gate the relevant SRAM blocks.
Quoted 2 lines
The development tasks for these two improvements has started, once validated they willl be provided in an update.
will
thanks,
Takashi
Re: [PATCH v5 02/14] ASoC: SOF: Add Sound Open Firmware KControl support
Quoted 4 lines
Quoted 3 lines
The development tasks for these two improvements has started, once validated they willl be provided in an update.
will
will fix.
PATCH v5 3/14 ASoC: SOF: Add driver debug support.
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add debugFS files that can be used to expose DSP memories and and peripherals to userspace to assist with firmware debugging.
Since we cannot rely on debugFS, errors are logged but don't stop execution.
When a resource cannot be read in D3, it is optionally cached on suspend. Copying memories from IO will increase the suspend latency, this should only used in engineering builds w/ debug options. This part will have to be enhanced when support for D0ix states is provided, currently only D0 and D3 are supported.
--- sound/soc/sof/debug.c | 219 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +219 -0
@@ -0,0 +1,219 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// Generic debug routines used to export DSP MMIO and memories to userspace +// for firmware debugging. +// + +#include <linux/debugfs.h> +#include <linux/io.h> +#include <linux/pm_runtime.h> +#include "sof-priv.h" +#include "ops.h" + +static ssize_t sof_dfsentry_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +int size; +u32 *buf; +loff_t pos = *ppos; +size_t size_ret; + + size = dfse->size; + +/* validate position & count */ +if (pos <0 ) +return -EINVAL ; +if (pos >= size || !count) +return 0 ; +/* find the minimum. min() is not used since it adds sparse warnings */ +if (count > size - pos) + count = size - pos; + +/* intermediate buffer size must be u32 multiple */ + size =ALIGN (count,4 ); + + buf =kzalloc (size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +if (dfse->type ==SOF_DFSENTRY_TYPE_IOMEM ) { +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +/* +* If the DSP is active: copy from IO. +* If the DSP is suspended: +* - Copy from IO if the memory is always accessible. +* - Otherwise, copy from cached buffer. +*/ +if (pm_runtime_active (sdev->dev) || + dfse->access_type ==SOF_DEBUGFS_ACCESS_ALWAYS ) { +memcpy_fromio (buf, dfse->io_mem + pos, size); + }else { +dev_info (sdev->dev, +"Copying cached debugfs data\n" ); +memcpy (buf, dfse->cache_buf + pos, size); + } +#else +/* if the DSP is in D3 */ +if (!pm_runtime_active (sdev->dev) && + dfse->access_type ==SOF_DEBUGFS_ACCESS_D0_ONLY ) { +dev_err (sdev->dev, +"error: debugfs entry %s cannot be read in DSP D3\n" , + dfse->dfsentry->d_name.name); +return -EINVAL ; + } + +memcpy_fromio (buf, dfse->io_mem + pos, size); +#endif + }else { +memcpy (buf, ((u8 *)(dfse->buf) + pos), size); + } + +/* copy to userspace */ + size_ret =copy_to_user (buffer, buf, count); +kfree (buf); + +/* update count & position if copy succeeded */ +if (size_ret) +return -EFAULT ; + + *ppos = pos + count; + +return count; +} + +static const struct file_operations sof_dfs_fops = { + .open = simple_open, + .read = sof_dfsentry_read, + .llseek = default_llseek, +}; + +/* create FS entry for debug files that can expose DSP memories, registers */ +int snd_sof_debugfs_io_item (struct snd_sof_dev *sdev, +void __iomem *base,size_t size, +const char *name, +enum sof_debugfs_access_type access_type) +{ +struct snd_sof_dfsentry *dfse; + +if (!sdev) +return -EINVAL ; + + dfse =devm_kzalloc (sdev->dev,sizeof (*dfse),GFP_KERNEL ); +if (!dfse) +return -ENOMEM ; + + dfse->type =SOF_DFSENTRY_TYPE_IOMEM ; + dfse->io_mem = base; + dfse->size = size; + dfse->sdev = sdev; + dfse->access_type = access_type; + +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +/* +* allocate cache buffer that will be used to save the mem window +* contents prior to suspend +*/ +if (access_type ==SOF_DEBUGFS_ACCESS_D0_ONLY ) { + dfse->cache_buf =devm_kzalloc (sdev->dev, size,GFP_KERNEL ); +if (!dfse->cache_buf) +return -ENOMEM ; + } +#endif + + dfse->dfsentry =debugfs_create_file (name,0444 , sdev->debugfs_root, + dfse, &sof_dfs_fops); +if (!dfse->dfsentry) { +/* can't rely on debugfs, only log error and keep going */ +dev_err (sdev->dev,"error: cannot create debugfs entry %s\n" , + name); + }else { +/* add to dfsentry list */ +list_add (&dfse->list, &sdev->dfsentry_list); + + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_sof_debugfs_io_item); + +/* create FS entry for debug files to expose kernel memory */ +int snd_sof_debugfs_buf_item (struct snd_sof_dev *sdev, +void *base,size_t size, +const char *name) +{ +struct snd_sof_dfsentry *dfse; + +if (!sdev) +return -EINVAL ; + + dfse =devm_kzalloc (sdev->dev,sizeof (*dfse),GFP_KERNEL ); +if (!dfse) +return -ENOMEM ; + + dfse->type =SOF_DFSENTRY_TYPE_BUF ; + 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) { +/* can't rely on debugfs, only log error and keep going */ +dev_err (sdev->dev,"error: cannot create debugfs entry %s\n" , + name); + }else { +/* add to dfsentry list */ +list_add (&dfse->list, &sdev->dfsentry_list); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_sof_debugfs_buf_item); + +int snd_sof_dbg_init (struct snd_sof_dev *sdev) +{ +const struct snd_sof_dsp_ops *ops =sof_ops (sdev); +const struct snd_sof_debugfs_map *map; +int i; +int err; + +/* 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 0 ; + } + +/* init dfsentry list */ +INIT_LIST_HEAD (&sdev->dfsentry_list); + +/* 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_io_item (sdev, sdev->bar[map->bar] + + map->offset, map->size, + map->name, map->access_type); +/* errors are only due to memory allocation, not debugfs */ +if (err <0 ) +return err; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_sof_dbg_init); + +void snd_sof_free_debug (struct snd_sof_dev *sdev) +{ +debugfs_remove_recursive (sdev->debugfs_root); +} +EXPORT_SYMBOL_GPL (snd_sof_free_debug);
Signature · 1 line
2.17.1
Re: [PATCH v5 03/14] ASoC: SOF: Add driver debug support.
Quoted 14 lines · Pierre-Louis Bossart
sound/soc/sof/debug.c new file +13
-0+static ssize_t sof_dfsentry_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +int size; +u32 *buf; +loff_t pos = *ppos; +size_t size_ret; + + size = dfse->size; + +/* validate position & count */
sound/soc/sof/debug.c line 42
Quoted 10 lines
sound/soc/sof/debug.c new file +10
-0+if (pos <0 ) +return -EINVAL ; +if (pos >= size || !count) +return 0 ; +/* find the minimum. min() is not used since it adds sparse warnings */ +if (count > size - pos) + count = size - pos; + +/* intermediate buffer size must be u32 multiple */ + size =ALIGN (count,4 );
Doesn't pos need to be aligned to 32bit as well (at least at actually reading from iomem)?
thanks,
Takashi
Re: [PATCH v5 03/14] ASoC: SOF: Add driver debug support.
Quoted 21 lines · Takashi Iwai
Quoted 19 lines · Pierre-Louis Bossart
sound/soc/sof/debug.c new file +18
-0+static ssize_t sof_dfsentry_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +int size; +u32 *buf; +loff_t pos = *ppos; +size_t size_ret; + + size = dfse->size; + +/* validate position & count */ +if (pos <0 ) +return -EINVAL ; +if (pos >= size || !count) +return 0 ; +/* find the minimum. min() is not used since it adds sparse warnings */
Quoted 8 lines
sound/soc/sof/debug.c line 42
Quoted 5 lines
sound/soc/sof/debug.c new file +5
-0+if (count > size - pos) + count = size - pos; + +/* intermediate buffer size must be u32 multiple */ + size =ALIGN (count,4 );Doesn't pos need to be aligned to 32bit as well (at least at actually reading from iomem)?
Good point, we can either return an error if the count in both a multiple of 32 bits, or do some caching to allow for arbitrary size access. The former is very simple but not sure if this is accepted behavior for debugfs.
Mark Brown
maintainerRe: [PATCH v5 03/14] ASoC: SOF: Add driver debug support.
Quoted 8 lines · Pierre-Louis Bossart
Quoted 2 lines · Takashi Iwai
Doesn't pos need to be aligned to 32bit as well (at least at actually reading from iomem)?
Good point, we can either return an error if the count in both a multiple of 32 bits, or do some caching to allow for arbitrary size access. The former is very simple but not sure if this is accepted behavior for debugfs.
You really want something that will work with arbatrary userspace tools if you can rather than requiring special magic read sizes - things like cat and cp should probably work. A common thing is to do reads/writes of the correct sizes into a buffer and then pick the relevant bits out of the buffer to satisfy what userspace actually asked for.
Re: [PATCH v5 03/14] ASoC: SOF: Add driver debug support.
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Doesn't pos need to be aligned to 32bit as well (at least at actually reading from iomem)?
Good point, we can either return an error if the count in both a multiple of 32 bits, or do some caching to allow for arbitrary size access. The former is very simple but not sure if this is accepted behavior for debugfs.
You really want something that will work with arbatrary userspace tools if you can rather than requiring special magic read sizes - things like cat and cp should probably work. A common thing is to do reads/writes of the correct sizes into a buffer and then pick the relevant bits out of the buffer to satisfy what userspace actually asked for.
Thanks for the advice. The data is already in a buffer so it's not difficult to implement support for sizes that aren't multiple of 4 bytes.
PATCH v5 4/14 ASoC: SOF: Add support for IPC IO between DSP and Host
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Define 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/sound/sof/control.h | 158 ++++++++ include/sound/sof/dai-intel.h | 178 ++++++++ include/sound/sof/dai.h | 75 ++++ include/sound/sof/header.h | 158 ++++++++ include/sound/sof/info.h | 118 ++++++ include/sound/sof/pm.h | 48 +++ include/sound/sof/stream.h | 148 +++++++ include/sound/sof/trace.h | 66 +++ sound/soc/sof/ipc.c | 742 ++++++++++++++++++++++++++++++++++ 9 files changed, 1691 insertions(+) create mode 100644 include/sound/sof/control.h create mode 100644 include/sound/sof/dai-intel.h create mode 100644 include/sound/sof/dai.h create mode 100644 include/sound/sof/header.h create mode 100644 include/sound/sof/info.h create mode 100644 include/sound/sof/pm.h create mode 100644 include/sound/sof/stream.h create mode 100644 include/sound/sof/trace.h create mode 100644 sound/soc/sof/ipc.c
include/sound/sof/control.h new file +158 -0
@@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_SOUND_SOF_CONTROL_H__ +#define __INCLUDE_SOUND_SOF_CONTROL_H__ + +#include <uapi/sound/sof/header.h> +#include <sound/sof/header.h> + +/* +* Component Mixers and Controls +*/ + +/* 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 , +}; + +/* 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 { +uint32_t channel;/**< channel map - enum sof_ipc_chmap */ +uint32_t value; +} __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; + }; +} __packed; + +/* generic control data */ +struct sof_ipc_ctrl_data { +struct sof_ipc_reply rhdr; +uint32_t comp_id; + +/* control access and data type */ +uint32_t type;/**< enum sof_ipc_ctrl_type */ +uint32_t cmd;/**< enum sof_ipc_ctrl_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 for data type */ +uint32_t elems_remaining;/**< elems remaining if sent in parts */ + +uint32_t msg_index;/**< for large messages sent in parts */ + +/* reserved for future use */ +uint32_t reserved[6 ]; + +/* 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 ]; + }; +} __packed; + +/** Event type */ +enum sof_ipc_ctrl_event_type { +SOF_CTRL_EVENT_GENERIC =0 ,/**< generic event */ +SOF_CTRL_EVENT_GENERIC_METADATA ,/**< generic event with metadata */ +SOF_CTRL_EVENT_KD ,/**< keyword detection event */ +SOF_CTRL_EVENT_VAD ,/**< voice activity detection event */ +}; + +/** +* Generic notification data. +*/ +struct sof_ipc_comp_event { +struct sof_ipc_reply rhdr; +uint16_t src_comp_type;/**< COMP_TYPE_ */ +uint32_t src_comp_id;/**< source component id */ +uint32_t event_type;/**< event type - SOF_CTRL_EVENT_* */ +uint32_t num_elems;/**< in array elems or bytes for data type */ + +/* reserved for future use */ +uint32_t reserved[8 ]; + +/* control data - add new types if needed */ +union { +/* data can be used by binary controls */ +struct sof_abi_hdr data[0 ]; +/* event specific values */ +uint32_t event_value; + }; +} __packed; + +#endif
include/sound/sof/dai-intel.h new file +178 -0
178 lines not on this page · raw message
include/sound/sof/dai.h new file +75 -0
75 lines not on this page · raw message
include/sound/sof/header.h new file +158 -0
158 lines not on this page · raw message
include/sound/sof/info.h new file +118 -0
118 lines not on this page · raw message
include/sound/sof/pm.h new file +48 -0
48 lines not on this page · raw message
include/sound/sof/stream.h new file +148 -0
148 lines not on this page · raw message
include/sound/sof/trace.h new file +66 -0
66 lines not on this page · raw message
sound/soc/sof/ipc.c new file +742 -0
742 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 5/14 ASoC: SOF: Add PCM operations support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add support for exposing PCMs to userspace. PCMs are defined by topology and the operations in this patch map to SOF IPC calls.
The .ignore_module_refcount field is set to allow for module load/unload tests. There is no risk of the sof-pci/acpi-dev module being removed while the platform components are in use. This may need to be revisited when DT platforms are supported.
--- sound/soc/sof/pcm.c | 723 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 723 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +723 -0
@@ -0,0 +1,723 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// PCM Layer, interface between ALSA and IPC. +// + +#include <linux/pm_runtime.h> +#include <sound/pcm_params.h> +#include <sound/sof.h> +#include "sof-priv.h" +#include "ops.h" + +#define DRV_NAME "sof-audio-component" + +/* 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; +struct snd_dma_buffer *dmab =snd_pcm_get_dma_buf (substream); +int stream = substream->stream; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +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; +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 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +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), spcm->pcm.pcm_id); +return ret; + } + +/* create 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 */ + pcm.params.buffer.pages =PFN_UP (runtime->dma_bytes); + +/* 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.hdr.size =sizeof (pcm.params); + pcm.params.buffer.phy_addr = + spcm->stream[substream->stream].page_table.addr; + pcm.params.buffer.size = runtime->dma_bytes; + 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 */ + ret =snd_sof_pcm_platform_hw_params (sdev, + substream, + params, + &pcm.params); +if (ret <0 ) { +dev_err (sdev->dev,"error: platform hw params failed\n" ); +return ret; + } + +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)); +if (ret <0 ) { +dev_err (sdev->dev,"error: hw params ipc failed for stream %d\n" , + pcm.params.stream_tag); +return ret; + } + +/* 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, spcm->pcm.pcm_id); +return -EINVAL ; + } + spcm->posn_offset[substream->stream] = + sdev->stream_box.offset + posn_offset; + +/* save pcm hw_params */ +memcpy (&spcm->params[substream->stream], params,sizeof (*params)); + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +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; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +dev_dbg (sdev->dev,"pcm: free stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + + stream.hdr.size =sizeof (stream); + stream.hdr.cmd =SOF_IPC_GLB_STREAM_MSG |SOF_IPC_STREAM_PCM_FREE ; + stream.comp_id = spcm->stream[substream->stream].comp_id; + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +snd_pcm_lib_free_pages (substream); +return ret; +} + +static int sof_restore_hw_params (struct snd_pcm_substream *substream, +struct snd_sof_pcm *spcm, +struct snd_sof_dev *sdev) +{ +snd_pcm_uframes_t host; +u64 host_posn; +int ret; + +/* resume stream */ + host_posn = spcm->stream[substream->stream].posn.host_posn; + host =bytes_to_frames (substream->runtime, host_posn); +dev_dbg (sdev->dev, +"PCM: resume stream %d dir %d DMA position %lu\n" , + spcm->pcm.pcm_id, substream->stream, host); + +/* set hw_params */ + ret =sof_pcm_hw_params (substream, + &spcm->params[substream->stream]); +if (ret <0 ) { +dev_err (sdev->dev, +"error: set pcm hw_params after resume\n" ); +return ret; + } + +return 0 ; +} + +/* +* FE dai link trigger actions are always executed in non-atomic context because +* they involve IPC's. +*/ +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; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +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_PAUSE_PUSH : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_PAUSE ; +break ; +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* trigger start */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + }else { + +/* trigger pause release */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; + } +break ; +case SNDRV_PCM_TRIGGER_START : +/* fall through */ +case SNDRV_PCM_TRIGGER_RESUME : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + } + +/* trigger stream */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +/* fallthrough */ +case SNDRV_PCM_TRIGGER_STOP : + +/* Check if stream was marked for restore before suspend */ +if (spcm->restore_stream[substream->stream]) { + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* do not send ipc as the stream hasn't been set up */ +return 0 ; + } + + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_STOP ; +break ; +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 */ +return sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); +} + +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; +snd_pcm_uframes_t host =0 , dai =0 ; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +/* if have dsp ops pointer callback, use that directly */ +if (sof_ops (sdev)->pcm_pointer) +return sof_ops (sdev)->pcm_pointer (sdev, substream); + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +/* 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; +struct snd_soc_tplg_stream_caps *caps; +int ret; +int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +dev_dbg (sdev->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + + caps = &spcm->pcm.caps[substream->stream]; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: pcm open failed to resume %d\n" , + ret); +pm_runtime_put_noidle (sdev->dev); +return ret; + } + +/* set any runtime constraints based on topology */ +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_BUFFER_SIZE , +le32_to_cpu (caps->period_size_min)); +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +le32_to_cpu (caps->period_size_min)); + +/* set runtime config */ + runtime->hw.info =SNDRV_PCM_INFO_MMAP | +SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_INTERLEAVED | +SNDRV_PCM_INFO_PAUSE | +SNDRV_PCM_INFO_RESUME | +SNDRV_PCM_INFO_NO_PERIOD_WAKEUP ; + runtime->hw.formats =le64_to_cpu (caps->formats); + runtime->hw.period_bytes_min =le32_to_cpu (caps->period_size_min); + runtime->hw.period_bytes_max =le32_to_cpu (caps->period_size_max); + runtime->hw.periods_min =le32_to_cpu (caps->periods_min); + runtime->hw.periods_max =le32_to_cpu (caps->periods_max); + runtime->hw.buffer_bytes_max =le32_to_cpu (caps->buffer_size_max); + +dev_dbg (sdev->dev,"period min %zd max %zd bytes\n" , + runtime->hw.period_bytes_min, + runtime->hw.period_bytes_max); +dev_dbg (sdev->dev,"period count %d max %d\n" , + runtime->hw.periods_min, + runtime->hw.periods_max); +dev_dbg (sdev->dev,"buffer max %zd bytes\n" , + runtime->hw.buffer_bytes_max); + +/* set wait time - TODO: come from topology */ + substream->wait_time =500 ; + + spcm->stream[substream->stream].posn.host_posn =0 ; + spcm->stream[substream->stream].posn.dai_posn =0 ; + spcm->stream[substream->stream].substream = substream; + + ret =snd_sof_pcm_platform_open (sdev, substream); +if (ret <0 ) { +dev_err (sdev->dev,"error: pcm open failed %d\n" , + ret); + +pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + } + +return ret; +} + +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; +int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +dev_dbg (sdev->dev,"pcm: close stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + + err =snd_sof_pcm_platform_close (sdev, substream); +if (err <0 ) { +dev_err (sdev->dev,"error: pcm close failed %d\n" , + err); +/* +* keep going, no point in preventing the close +* from happening +*/ + } + +pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + +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, +}; + +/* +* Pre-allocate playback/capture audio buffer pages. +* no need to explicitly release memory preallocated by sof_pcm_new in pcm_free +* snd_pcm_lib_preallocate_free_for_all() is called by the core. +*/ +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 ; + } + +dev_dbg (sdev->dev,"creating new PCM %s\n" , spcm->pcm.pcm_name); + +/* do we need to pre-allocate playback audio buffer 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); + +snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->dev, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); +capture: + stream =SNDRV_PCM_STREAM_CAPTURE ; + +/* do we need to pre-allocate capture audio buffer 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); + +snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->dev, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); + +return ret; +} + +/* 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_warn (sdev->dev,"warning: 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_format (fmt,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_format (fmt,SNDRV_PCM_FORMAT_S16_LE ); +break ; +case SOF_IPC_FRAME_S24_4LE : +snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S24_LE ); +break ; +case SOF_IPC_FRAME_S32_LE : +snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S32_LE ); +break ; +default : +dev_err (sdev->dev,"error: 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 : +/* do nothing for HDA dai_link */ +break ; +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 = sdev->pdata; +const char *tplg_filename; +int ret; + +/* load the default topology */ + sdev->component = component; + + tplg_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->tplg_filename_prefix, + plat_data->tplg_filename); +if (!tplg_filename) +return -ENOMEM ; + + ret =snd_sof_load_topology (sdev, tplg_filename); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to load DSP topology %d\n" , + ret); +return ret; + } + +/* +* Some platforms in SOF, ex: BYT, may not have their platform PM +* callbacks set. Increment the usage count so as to +* prevent the device entering runtime suspend. +*/ +if (!sof_ops (sdev)->runtime_suspend || !sof_ops (sdev)->runtime_resume) +pm_runtime_get_noresume (sdev->dev); + +return ret; +} + +static void sof_pcm_remove (struct snd_soc_component *component) +{ +} + +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; +const char *drv_name; + + drv_name = plat_data->machine->drv_name; + + pd->name ="sof-audio-component" ; + pd->probe = sof_pcm_probe; + pd->remove = sof_pcm_remove; + pd->ops = &sof_pcm_ops; +#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS ) + pd->compr_ops = &sof_compressed_ops; +#endif + pd->pcm_new = sof_pcm_new; + pd->ignore_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" ; + +/* do not increase the refcount in core */ + pd->ignore_module_refcount =1 ; +}
Signature · 1 line
2.17.1
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 5 lines · Pierre-Louis Bossart
sound/soc/sof/pcm.c new file +4
-0+/* 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) +{
....
Quoted 4 lines
sound/soc/sof/pcm.c new file +4
-0+/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ;
sound/soc/sof/pcm.c line 114
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + }
This can be simply snd_pcm_format_physical_width() / 8.
Quoted 2 lines
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{
....
sound/soc/sof/pcm.c line 413
Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+/* 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));
Is period_size_min in frames or in bytes? The code below refers as byte size while this refers as frames, so they look inconsistent.
sound/soc/sof/pcm.c line 421
Quoted 8 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;
Does SOF support the full resume? That is, the stream gets resumed at the exact position that was suspended. Most devices can't, hence they don't set *_INFO_RESUME flag and let user-space restarting.
sound/soc/sof/pcm.c line 427
Quoted 5 lines
sound/soc/sof/pcm.c new file +5
-0+ 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);
These refer as bytes...
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 9 lines · Takashi Iwai
sound/soc/sof/pcm.c line 421
Quoted 8 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;
Quoted 3 lines
Does SOF support the full resume? That is, the stream gets resumed at the exact position that was suspended. Most devices can't, hence they don't set
*_INFO_RESUMEflag and let user-space restarting.
Not atm, and I don't see this as an ask in the near future either, but it's technically possible given the open firmware.
Liam
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
In reply to Takashi IwaiQuoted 28 lines · Takashi Iwai
Quoted 5 lines · Pierre-Louis Bossart
sound/soc/sof/pcm.c new file +4
-0+/* 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) +{....
Quoted 4 lines
sound/soc/sof/pcm.c new file +4
-0+/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ;sound/soc/sof/pcm.c line 114
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + }This can be simply
snd_pcm_format_physical_width()/ 8.Quoted 2 lines
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{....
Quoted 10 lines
sound/soc/sof/pcm.c line 413
Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+/* 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));Is
period_size_minin frames or in bytes? The code below refers as byte size while this refers as frames, so they look inconsistent.
Yep, you are right, we should use SNDRV_PCM_HW_PARAM_BUFFER_BYTES and SNDRV_PCM_HW_PARAM_PERIOD_BYTES here, thanks for pointing out.
They are configured(in tplg file) following comments in definition(somewhat confusion comparing to ALSA notion where 'size' means in frames?) of struct snd_soc_tplg_stream_caps:
__le32 period_size_min; /* min period size bytes */
__le32 period_size_max; /* max period size bytes */
__le32 buffer_size_min; /* min buffer size bytes */
__le32 buffer_size_max; /* max buffer size bytes */
Thanks,
~Keyon
Quoted 23 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at the exact position that was suspended. Most devices can't, hence they don't set
*_INFO_RESUMEflag and let user-space restarting.sound/soc/sof/pcm.c line 427
Quoted 5 lines
sound/soc/sof/pcm.c new file +5
-0+ 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);These refer as bytes...
Quoted 8 lines
thanks,
Takashi
_______________________________________________
Sound-open-firmware mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
In reply to Takashi IwaiQuoted 17 lines
Quoted 5 lines
sound/soc/sof/pcm.c new file +4
-0+/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ;sound/soc/sof/pcm.c line 114
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + }This can be simply
snd_pcm_format_physical_width()/ 8.
ok
Quoted 4 lines
Quoted 3 lines
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{....
Quoted 10 lines
sound/soc/sof/pcm.c line 413
Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+/* 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));Is
period_size_minin frames or in bytes? The code below refers as byte size while this refers as frames, so they look inconsistent.
need to check, the topology files always mention frames not bytes.
Quoted 13 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at the exact position that was suspended. Most devices can't, hence they don't set
*_INFO_RESUMEflag and let user-space restarting.
Ah this is interesting. All previous Intel drivers set this flag, baytrail/haswell/broadwell, atom-sst and skylake. Only Skylake+ devices can restart at exactly the right position, but it's my understanding that no one ever enabled this mode.
Now I see an awful amount of devices that set this INFO_RESUME flag, and I'd be surprised if they all supported a full resume, could it be that there's a requirement that fell between the cracks on this one?
Quoted 8 lines
sound/soc/sof/pcm.c line 427
Quoted 6 lines
sound/soc/sof/pcm.c new file +5
-0+ 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);These refer as bytes...
will check as well.
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 14 lines · Pierre-Louis Bossart
Quoted 13 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at the exact position that was suspended. Most devices can't, hence they don't set
*_INFO_RESUMEflag and let user-space restarting.
Quoted 8 lines
Ah this is interesting. All previous Intel drivers set this flag, baytrail/haswell/broadwell, atom-sst and skylake. Only Skylake+ devices can restart at exactly the right position, but it's my understanding that no one ever enabled this mode.
Now I see an awful amount of devices that set this
INFO_RESUMEflag, and I'd be surprised if they all supported a full resume, could it be that there's a requirement that fell between the cracks on this one?
The SNDRV_PCM_INFO_RESUME is merely a hint, so far, and user-space would eventually fall back to the default restart procedure even if something fails. That is, that's not that important, but it should be dropped if the general SOF framework doesn't support for it at all. But, the framework itself seems supporting the full resume feature, judging from your and others replies, so we can keep it.
thanks,
Takashi
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
In reply to Takashi IwaiQuoted 41 lines · Takashi Iwai
Quoted 5 lines · Pierre-Louis Bossart
sound/soc/sof/pcm.c new file +4
-0+/* 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) +{....
Quoted 4 lines
sound/soc/sof/pcm.c new file +4
-0+/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ;sound/soc/sof/pcm.c line 114
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + }This can be simply
snd_pcm_format_physical_width()/ 8.Quoted 2 lines
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{....
sound/soc/sof/pcm.c line 413
Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+/* 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));Is
period_size_minin frames or in bytes? The code below refers as byte size while this refers as frames, so they look inconsistent.
Quoted 14 lines
sound/soc/sof/pcm.c line 421
Quoted 8 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.
Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to resume from the exact same position due to the fact that triggers for the host dma and link dma are not synchronized and also IPC scheduling will affect this. So we should remove INOF_RESUME from hw.info.
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the hw_params in the SOF driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any insights on what we might be missing in the SOF driver?
Thanks,
Ranjani
Quoted 20 lines
Quoted 9 lines
(quoted diff) +1
-0+ runtime->hw.period_bytes_min = le32_to_cpu(caps-Quoted 1 line
period_size_min);(quoted diff) +1
-0+ runtime->hw.period_bytes_max = le32_to_cpu(caps-Quoted 1 line
period_size_max);sound/soc/sof/pcm.c new file +3
-0+ 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-Quoted 1 line
buffer_size_max);These refer as bytes...
thanks,
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 22 lines · Ranjani Sridharan
Quoted 15 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to resume from the exact same position due to the fact that triggers for the host dma and link dma are not synchronized and also IPC scheduling will affect this. So we should remove
INOF_RESUMEfrom hw.info.
Quoted 5 lines
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the
hw_paramsin the SOF driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any insights on what we might be missing in the SOF driver?
So, SOF mandates the re-setup of the hw params in BE at resume? Then the right place to do is in the prepare callback. Without SNDRV_PCM_INFO_RESUME flag, the PCM core won't trigger RESUME, but returns -ENOSYS. Then user-space will do prepare, and start with the normal trigger.
You'd need a flag indicating the BE hw_params resetup, and at the beginning of prepare function, the flag is checked and the (internal) hw_params is done accordingly.
Takashi
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 37 lines · Takashi Iwai
Quoted 27 lines · Ranjani Sridharan
Quoted 16 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed
at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to
resume from the exact same position due to the fact that triggers for
the host dma and link dma are not synchronized and also IPC scheduling
will affect this. So we should removeINOF_RESUMEfrom hw.info.Quoted 7 lines
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the
hw_paramsin the SOF
driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any
insights on what we might be missing in the SOF driver?
Quoted 1 line
So, SOF mandates the re-setup of the hw params in BE at resume?
Yes. That's correct.
Quoted 8 lines
Then the right place to do is in the prepare callback. Without
SNDRV_PCM_INFO_RESUMEflag, the PCM core won't trigger RESUME, but returns-ENOSYS. Then user-space will do prepare, and start with the normal trigger.You'd need a flag indicating the BE
hw_paramsresetup, and at the beginning of prepare function, the flag is checked and the (internal)hw_paramsis done accordingly.
This makes sense. Thank you for your help. We will change the flow accordingly.
Thanks,
Ranjani
Quoted 3 lines
Takashi
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
In reply to Takashi IwaiQuoted 30 lines · Takashi Iwai
Quoted 22 lines · Ranjani Sridharan
Quoted 15 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to resume from the exact same position due to the fact that triggers for the host dma and link dma are not synchronized and also IPC scheduling will affect this. So we should remove
INOF_RESUMEfrom hw.info.Quoted 5 lines
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the
hw_paramsin the SOF driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any insights on what we might be missing in the SOF driver?
Quoted 5 lines
So, SOF mandates the re-setup of the hw params in BE at resume? Then the right place to do is in the prepare callback. Without
SNDRV_PCM_INFO_RESUMEflag, the PCM core won't trigger RESUME, but returns-ENOSYS. Then user-space will do prepare, and start with the normal trigger.
Takashi, some of us at Intel are a bit nervous about returning an error to force the application to jump to its error-handling code (typically only done for xruns and not always rock-solid) and as a side effect get a prepare ioctl. I checked that e.g. CRAS does support this mode but I wonder how many application developers know about this. I personally didn't.
Moreover, it seems that the default behavior is rather to support RESUME, even if the hardware can't precisely restart from the same position, so we are concerned about exposing new errors when SOF is selected instead of legacy drivers (Baytrail, Atom-SST and Skylake-SST).
In short, is this really your recommendation to remove this INFO_RESUME flag? And if yes, should we demote all existing Intel drivers and remove this flag as well?
Thanks for your feedback
-Pierre
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 40 lines · Pierre-Louis Bossart
Quoted 30 lines · Takashi Iwai
Quoted 22 lines · Ranjani Sridharan
Quoted 15 lines
sound/soc/sof/pcm.c line 421
Quoted 9 lines
sound/soc/sof/pcm.c new file +8
-0+ +/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to resume from the exact same position due to the fact that triggers for the host dma and link dma are not synchronized and also IPC scheduling will affect this. So we should remove
INOF_RESUMEfrom hw.info.Quoted 5 lines
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the
hw_paramsin the SOF driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any insights on what we might be missing in the SOF driver?Quoted 5 lines
So, SOF mandates the re-setup of the hw params in BE at resume? Then the right place to do is in the prepare callback. Without
SNDRV_PCM_INFO_RESUMEflag, the PCM core won't trigger RESUME, but returns-ENOSYS. Then user-space will do prepare, and start with the normal trigger.
Quoted 6 lines
Takashi, some of us at Intel are a bit nervous about returning an error to force the application to jump to its error-handling code (typically only done for xruns and not always rock-solid) and as a side effect get a prepare ioctl. I checked that e.g. CRAS does support this mode but I wonder how many application developers know about this. I personally didn't.
Essentially all applications are supposed to do so. There are only few drivers that support really the full resume. Some drivers set the flag, but many of them must be incorrect, especially ASoC ones.
Quoted 9 lines
Moreover, it seems that the default behavior is rather to support RESUME, even if the hardware can't precisely restart from the same position, so we are concerned about exposing new errors when SOF is selected instead of legacy drivers (Baytrail, Atom-SST and Skylake-SST).
In short, is this really your recommendation to remove this
INFO_RESUMEflag? And if yes, should we demote all existing Intel drivers and remove this flag as well?
Yes, better to start with less -- especially if this allows us to simplify the code a lot.
Takashi
Re: [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 50 lines
Quoted 33 lines
Quoted 27 lines
Quoted 21 lines
Quoted 14 lines
sound/soc/sof/pcm.c line 421
Quoted 8 lines
sound/soc/sof/pcm.c new file +7
-0+/* 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 ;Does SOF support the full resume? That is, the stream gets resumed at
the exact position that was suspended. Most devices can't, hence they
don't set*_INFO_RESUMEflag and let user-space restarting.Hi Takashi,
Thanks for your comment. The SOF driver definitely cannot guarantee to resume from the exact same position due to the fact that triggers for the host dma and link dma are not synchronized and also IPC scheduling will affect this. So we should remove
INOF_RESUMEfrom hw.info.Quoted 5 lines
I do one follow up question for you. When a stream resumes/restarts after suspend, we have the need for restoring the
hw_paramsin the SOF driver prior to handling the START trigger. I noticed that the legacy/skylake driver does not seem to do this though. Do you have any insights on what we might be missing in the SOF driver?Quoted 5 lines
So, SOF mandates the re-setup of the hw params in BE at resume? Then the right place to do is in the prepare callback. Without
SNDRV_PCM_INFO_RESUMEflag, the PCM core won't trigger RESUME, but returns-ENOSYS. Then user-space will do prepare, and start with the normal trigger.Quoted 6 lines
Takashi, some of us at Intel are a bit nervous about returning an error to force the application to jump to its error-handling code (typically only done for xruns and not always rock-solid) and as a side effect get a prepare ioctl. I checked that e.g. CRAS does support this mode but I wonder how many application developers know about this. I personally didn't.
Essentially all applications are supposed to do so. There are only few drivers that support really the full resume. Some drivers set the flag, but many of them must be incorrect, especially ASoC ones.
Quoted 6 lines
Moreover, it seems that the default behavior is rather to support RESUME, even if the hardware can't precisely restart from the same position, so we are concerned about exposing new errors when SOF is selected instead of legacy drivers (Baytrail, Atom-SST and Skylake-SST).
Quoted 6 lines
Quoted 3 lines
In short, is this really your recommendation to remove this
INFO_RESUMEflag? And if yes, should we demote all existing Intel drivers and remove this flag as well?Yes, better to start with less -- especially if this allows us to simplify the code a lot.
ok, thanks for confirming. we'll remove the INFO_RESUME flag in SOF and follow-up with the removal on all other Intel drivers. Thanks for enlightening us on this. -Pierre
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 2 lines
ok, thanks for confirming. we'll remove the
INFO_RESUMEflag in SOF and follow-up with the removal on all other Intel drivers. Thanks for enlightening us on this.
Actually one more question related to the documentation, which reads
"Note that the trigger with SUSPEND can always be called when snd_pcm_suspend_all() is called, regardless of the SNDRV_PCM_INFO_RESUME flag. The RESUME flag affects only the behavior of snd_pcm_resume(). (Thus, in theory, SNDRV_PCM_TRIGGER_RESUME isn’t needed to be handled in the trigger callback when no SNDRV_PCM_INFO_RESUME flag is set. But, it’s better to keep it for compatibility reasons.)"
I could not figure out what the last sentence means. It's my understanding that the resume_trigger will never be called with the code flow below when INFO_RESUME isn't declared. Would you mind clarifying what this compatibility might be? Thanks!
static int snd_pcm_pre_resume(struct snd_pcm_substream *substream, int state)
{
struct snd_pcm_runtime *runtime = substream->runtime;
if (!(runtime->info & SNDRV_PCM_INFO_RESUME))
return -ENOSYS;res = ops->pre_action(substream, state);
if (res < 0)
return res; <<< return means trigger_resume is not called?
res = ops->do_action(substream, state);
static const struct action_ops snd_pcm_action_resume = {
.pre_action = snd_pcm_pre_resume, .do_action = snd_pcm_do_resume,
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines
ok, thanks for confirming. we'll remove the
INFO_RESUMEflag in SOF and follow-up with the removal on all other Intel drivers. Thanks for enlightening us on this.Actually one more question related to the documentation, which reads
"Note that the trigger with SUSPEND can always be called when
snd_pcm_suspend_all()is called, regardless of theSNDRV_PCM_INFO_RESUMEflag. The RESUME flag affects only the behavior ofsnd_pcm_resume(). (Thus, in theory,SNDRV_PCM_TRIGGER_RESUMEisn’t needed to be handled in the trigger callback when noSNDRV_PCM_INFO_RESUMEflag is set. But, it’s better to keep it for compatibility reasons.)"
Quoted 4 lines
I could not figure out what the last sentence means. It's my understanding that the
resume_triggerwill never be called with the code flow below whenINFO_RESUMEisn't declared. Would you mind clarifying what this compatibility might be? Thanks!
Well, in the above "better to keep it" text -- here "it" was meant as SNDRV_PCM_TRIGGER_RESUME case handling in the trigger callback, not as SNDRV_PCM_INFO_RESUME flag. That is, the above recommends a trigger callback like below would keep SNDRV_PCM_TRIGGER_RESUME although it won't be called practically:
static int foo_trigger(....)
{
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
do_start();
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
do_stop();
break;
....
}
....
}This text needs clearly a better rephrasing...
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 23 lines · Takashi Iwai
Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines
ok, thanks for confirming. we'll remove the
INFO_RESUMEflag in SOF and follow-up with the removal on all other Intel drivers. Thanks for enlightening us on this.Actually one more question related to the documentation, which reads
"Note that the trigger with SUSPEND can always be called when
snd_pcm_suspend_all()is called, regardless of theSNDRV_PCM_INFO_RESUMEflag. The RESUME flag affects only the behavior ofsnd_pcm_resume(). (Thus, in theory,SNDRV_PCM_TRIGGER_RESUMEisn’t needed to be handled in the trigger callback when noSNDRV_PCM_INFO_RESUMEflag is set. But, it’s better to keep it for compatibility reasons.)"Quoted 4 lines
I could not figure out what the last sentence means. It's my understanding that the
resume_triggerwill never be called with the code flow below whenINFO_RESUMEisn't declared. Would you mind clarifying what this compatibility might be? Thanks!
Quoted 5 lines
Well, in the above "better to keep it" text -- here "it" was meant as
SNDRV_PCM_TRIGGER_RESUMEcase handling in the trigger callback, not asSNDRV_PCM_INFO_RESUMEflag. That is, the above recommends a trigger callback like below would keepSNDRV_PCM_TRIGGER_RESUMEalthough it won't be called practically:
That's the part that I find odd. we keep the TRIGGER_RESUME but it will never be called, that's an unreachable/untestable switch case, no? Or we should trap it as an error case.
Quoted 17 lines
static int
foo_trigger(....){ switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: do_start(); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: do_stop(); break; .... } .... }
Quoted 5 lines
This text needs clearly a better rephrasing...
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [Sound-open-firmware] [PATCH v5 05/14] ASoC: SOF: Add PCM operations support
Quoted 33 lines · Pierre-Louis Bossart
Quoted 23 lines · Takashi Iwai
Quoted 16 lines · Pierre-Louis Bossart
Quoted 5 lines
ok, thanks for confirming. we'll remove the
INFO_RESUMEflag in SOF and follow-up with the removal on all other Intel drivers. Thanks for enlightening us on this.Actually one more question related to the documentation, which reads
"Note that the trigger with SUSPEND can always be called when
snd_pcm_suspend_all()is called, regardless of theSNDRV_PCM_INFO_RESUMEflag. The RESUME flag affects only the behavior ofsnd_pcm_resume(). (Thus, in theory,SNDRV_PCM_TRIGGER_RESUMEisn’t needed to be handled in the trigger callback when noSNDRV_PCM_INFO_RESUMEflag is set. But, it’s better to keep it for compatibility reasons.)"Quoted 4 lines
I could not figure out what the last sentence means. It's my understanding that the
resume_triggerwill never be called with the code flow below whenINFO_RESUMEisn't declared. Would you mind clarifying what this compatibility might be? Thanks!Quoted 5 lines
Well, in the above "better to keep it" text -- here "it" was meant as
SNDRV_PCM_TRIGGER_RESUMEcase handling in the trigger callback, not asSNDRV_PCM_INFO_RESUMEflag. That is, the above recommends a trigger callback like below would keepSNDRV_PCM_TRIGGER_RESUMEalthough it won't be called practically:
Quoted 3 lines
That's the part that I find odd. we keep the
TRIGGER_RESUMEbut it will never be called, that's an unreachable/untestable switch case, no? Or we should trap it as an error case.
It's just for consistency. But it might look confusing, yeah.
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v5 6/14 ASoC: SOF: Add support for loading topologies
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
SOF 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/sound/sof/topology.h | 256 +++ sound/soc/sof/topology.c | 2913 ++++++++++++++++++++++++++++++++++ 2 files changed, 3169 insertions(+) create mode 100644 include/sound/sof/topology.h create mode 100644 sound/soc/sof/topology.c
include/sound/sof/topology.h new file +256 -0
@@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_SOUND_SOF_TOPOLOGY_H__ +#define __INCLUDE_SOUND_SOF_TOPOLOGY_H__ + +#include <sound/sof/header.h> + +/* +* 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_cmd_hdr hdr; +uint32_t id; +enum sof_comp_type type; +uint32_t pipeline_id; + +/* reserved for future use */ +uint32_t reserved[2 ]; +} __packed; + +/* +* Component Buffers +*/ + +/* +* SOF memory capabilities, add new ones at the end +*/ +#define SOF_MEM_CAPS_RAM (1 << 0) +#define SOF_MEM_CAPS_ROM (1 << 1) +#define SOF_MEM_CAPS_EXT (1 << 2)/**< external */ +#define SOF_MEM_CAPS_LP (1 << 3)/**< low power */ +#define SOF_MEM_CAPS_HP (1 << 4)/**< high performance */ +#define SOF_MEM_CAPS_DMA (1 << 5)/**< DMA'able */ +#define SOF_MEM_CAPS_CACHE (1 << 6)/**< cacheable */ +#define SOF_MEM_CAPS_EXEC (1 << 7)/**< executable */ + +/* 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_ */ +} __packed; + +/* generic component config data - must always be after struct sof_ipc_comp */ +struct sof_ipc_comp_config { +struct sof_ipc_cmd_hdr hdr; +uint32_t periods_sink;/**< 0 means variable */ +uint32_t periods_source;/**< 0 means variable */ +uint32_t reserved1;/**< reserved */ +uint32_t frame_fmt;/**< SOF_IPC_FRAME_ */ +uint32_t xrun_action; + +/* reserved for future use */ +uint32_t reserved[2 ]; +} __packed; + +/* generic host component */ +struct sof_ipc_comp_host { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t direction;/**< SOF_IPC_STREAM_ */ +uint32_t no_irq;/**< don't send periodic IRQ to host/DSP */ +uint32_t dmac_config;/**< DMA engine specific */ +} __packed; + +/* generic DAI component */ +struct sof_ipc_comp_dai { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t direction;/**< SOF_IPC_STREAM_ */ +uint32_t dai_index;/**< index of this type dai */ +uint32_t type;/**< DAI type - SOF_DAI_ */ +uint32_t reserved;/**< reserved */ +} __packed; + +/* generic mixer component */ +struct sof_ipc_comp_mixer { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __packed; + +/* volume ramping types */ +enum sof_volume_ramp { +SOF_VOLUME_LINEAR =0 , +SOF_VOLUME_LOG , +SOF_VOLUME_LINEAR_ZC , +SOF_VOLUME_LOG_ZC , +}; + +/* generic volume component */ +struct sof_ipc_comp_volume { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t channels; +uint32_t min_value; +uint32_t max_value; +uint32_t ramp;/**< SOF_VOLUME_ */ +uint32_t initial_ramp;/**< ramp space in ms */ +} __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 */ +} __packed; + +/* generic MUX component */ +struct sof_ipc_comp_mux { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __packed; + +/* generic tone generator component */ +struct sof_ipc_comp_tone { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +int32_t sample_rate; +int32_t frequency; +int32_t amplitude; +int32_t freq_mult; +int32_t ampl_mult; +int32_t length; +int32_t period; +int32_t repeats; +int32_t ramp_step; +} __packed; + +/** \brief Types of EFFECT */ +enum sof_ipc_effect_type { +SOF_EFFECT_NONE =0 ,/**< None */ +SOF_EFFECT_INTEL_EQFIR ,/**< Intel FIR */ +SOF_EFFECT_INTEL_EQIIR ,/**< Intel IIR */ +}; + +/* general purpose EFFECT configuration */ +struct sof_ipc_comp_effect { +struct sof_ipc_hdr hdr; +uint32_t type;/** sof_ipc_effect_type */ +} __packed; + +/* FIR equalizer component */ +struct sof_ipc_comp_eq_fir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size; + +/* reserved for future use */ +uint32_t reserved[8 ]; + +unsigned char data[0 ]; +} __packed; + +/* IIR equalizer component */ +struct sof_ipc_comp_eq_iir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size; + +/* reserved for future use */ +uint32_t reserved[8 ]; + +unsigned char data[0 ]; +} __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_cmd_hdr hdr; +uint32_t id; +} __packed; + +struct sof_ipc_comp_reply { +struct sof_ipc_reply rhdr; +uint32_t id; +uint32_t offset; +} __packed; + +/* +* Pipeline +*/ + +/* new pipeline - SOF_IPC_TPLG_PIPE_NEW */ +struct sof_ipc_pipe_new { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id;/**< component id for pipeline */ +uint32_t pipeline_id;/**< pipeline id */ +uint32_t sched_id;/**< Scheduling 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 period_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 */ + +/* non zero if timer scheduled, otherwise DAI DMA irq scheduled */ +uint32_t timer_delay; +} __packed; + +/* pipeline construction complete - SOF_IPC_TPLG_PIPE_COMPLETE */ +struct sof_ipc_pipe_ready { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id; +} __packed; + +struct sof_ipc_pipe_free { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id; +} __packed; + +/* connect two components in pipeline - SOF_IPC_TPLG_COMP_CONNECT */ +struct sof_ipc_pipe_comp_connect { +struct sof_ipc_cmd_hdr hdr; +uint32_t source_id; +uint32_t sink_id; +} __packed; + +#endif
sound/soc/sof/topology.c new file +2913 -0
2,744 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH v5 7/14 ASoC: SOF: Add DSP firmware logger support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
This patch adds support for real-time DSP logging (timestamped events and bespoke binary data) for firmware debug. The current solution relies on DMA transfers to system memory that is then accessed by userspace tools such as sof-logger. For Intel platforms, two types of DMAs are currently used (GP-DMA for Baytrail/CherryTrail and HDaudio DMA for SKL+)
Due to historical reasons, the driver code follows the DSP firmware conventions and refers to 'traces', but it is currently unrelated to the Linux trace subsystem. Future solutions will include support for more advanced hardware (e.g. MIPI Sys-T), additional formats and the ability to enable/disable specific traces dynamically.
--- sound/soc/sof/trace.c | 295 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/trace.c new file +295 -0
@@ -0,0 +1,295 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/debugfs.h> +#include <linux/sched/signal.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)) { +/* set timeout to max value, no error code */ +schedule_timeout (MAX_SCHEDULE_TIMEOUT ); + } +remove_wait_queue (&sdev->trace_sleep, &wait); + +/* return bytes available for copy */ +if (sdev->host_offset < pos) +return buffer_size - pos; + +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 *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; +u64 lpos_64; + +/* 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_64 = lpos; + lpos =do_div (lpos_64, buffer_size); + +if (count > buffer_size - lpos)/* min() not used to avoid sparse warnings */ + 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, (void *)((u8 *)(dfse->buf) + lpos), count); +if (rem) +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 *dfse; + +if (!sdev) +return -EINVAL ; + + dfse =devm_kzalloc (sdev->dev,sizeof (*dfse),GFP_KERNEL ); +if (!dfse) +return -ENOMEM ; + + dfse->type =SOF_DFSENTRY_TYPE_BUF ; + 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) { +/* can't rely on debugfs, only log error and keep going */ +dev_err (sdev->dev, +"error: cannot create debugfs entry for trace\n" ); + } + +return 0 ; +} + +int snd_sof_init_trace_ipc (struct snd_sof_dev *sdev) +{ +struct sof_ipc_dma_trace_params params; +struct sof_ipc_reply ipc_reply; +int ret; + +if (sdev->dtrace_is_enabled || !sdev->dma_trace_pages) +return -EINVAL ; + +/* 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.pages = sdev->dma_trace_pages; + params.stream_tag =0 ; + + 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); +return ret; + } +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 trace_release; + } + + 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 trace_release; + } + + sdev->dtrace_is_enabled = true; + +return 0 ; + +trace_release: +snd_sof_dma_trace_release (sdev); +return ret; +} + +int snd_sof_init_trace (struct snd_sof_dev *sdev) +{ +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->dev, +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->dev, +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; + } + +/* create 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); + +if (sdev->first_boot) { + ret =trace_debugfs_create (sdev); +if (ret <0 ) + goto table_err; + } + +init_waitqueue_head (&sdev->trace_sleep); + + ret =snd_sof_init_trace_ipc (sdev); +if (ret <0 ) + goto table_err; + +return 0 ; +table_err: + sdev->dma_trace_pages =0 ; +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); + + sdev->dtrace_is_enabled = false; +} +EXPORT_SYMBOL (snd_sof_release_trace); + +void snd_sof_free_trace (struct snd_sof_dev *sdev) +{ +snd_sof_release_trace (sdev); + +snd_dma_free_pages (&sdev->dmatb); +snd_dma_free_pages (&sdev->dmatp); +} +EXPORT_SYMBOL (snd_sof_free_trace);
Signature · 1 line
2.17.1
PATCH v5 8/14 ASoC: SOF: Add DSP HW abstraction operations
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add 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 | 204 ++++++++++++++++++++++ sound/soc/sof/ops.h | 403 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 607 insertions(+) create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h
sound/soc/sof/ops.c new file +204 -0
@@ -0,0 +1,204 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/pci.h> +#include "ops.h" + +static +bool snd_sof_pci_update_bits_unlocked (struct snd_sof_dev *sdev,u32 offset, +u32 mask,u32 value) +{ +struct pci_dev *pci =to_pci_dev (sdev->dev); +unsigned int old, new; +u32 ret; + +pci_read_config_dword (pci, offset, &ret); + old = ret; +dev_dbg (sdev->dev,"Debug PCIR: %8.8x at %8.8x\n" , old & mask, offset); + + new = (old & ~mask) | (value & mask); + +if (old == new) +return false; + +pci_write_config_dword (pci, offset, new); +dev_dbg (sdev->dev,"Debug PCIW: %8.8x at %8.8x\n" , value, + offset); + +return true; +} + +bool 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); + +bool snd_sof_dsp_update_bits_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); + +if (old == new) +return false; + +snd_sof_dsp_write (sdev, bar, offset, new); + +return true; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_unlocked); + +bool snd_sof_dsp_update_bits64_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u64 mask,u64 value) +{ +u64 old, new; + + old =snd_sof_dsp_read64 (sdev, bar, offset); + + new = (old & ~mask) | (value & mask); + +if (old == new) +return false; + +snd_sof_dsp_write64 (sdev, bar, offset, new); + +return true; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits64_unlocked); + +/* This is for registers bits with attribute RWC */ +bool 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); + +bool 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); + +static +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); +} + +/* 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_ms, +u32 interval_us) +{ +u32 reg; +unsigned long tout_jiff; +int k =0 , s = interval_us; + +/* +* Split the loop into 2 sleep stages with varying resolution. +* To do it more accurately, the range of wakeups are: +* In case of interval_us = 500, +* Phase 1(first 5ms): min sleep 0.5ms; max sleep 1ms. +* Phase 2(beyond 5ms): min sleep 5ms; max sleep 10ms. +*/ + + tout_jiff = jiffies +msecs_to_jiffies (timeout_ms); +do { + reg =snd_sof_dsp_read (sdev, bar, offset); +if ((reg & mask) == target) +break ; + +/* Phase 2 after 5ms(500us * 10) */ +if (++k >10 ) + s = interval_us *10 ; + +usleep_range (s,2 * s); + }while (time_before (jiffies, tout_jiff)); + +if ((reg & mask) == target) { +dev_dbg (sdev->dev,"FW Poll Status: reg=%#x successful\n" , reg); + +return 0 ; + } + +dev_dbg (sdev->dev,"FW Poll Status: reg=%#x timedout\n" , reg); +return -ETIME ; +} +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 +403 -0
403 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 9/14 ASoC: SOF: Add firmware loader support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
The firmware loader exports APIs that can be called by core to load and process multiple different file formats.
--- sound/soc/sof/loader.c | 376 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100644 sound/soc/sof/loader.c
sound/soc/sof/loader.c new file +376 -0
@@ -0,0 +1,376 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// Generic firmware loader. +// + +#include <linux/firmware.h> +#include <sound/sof.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; +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 0 ; +} + +/* parse the extended FW boot data structures from FW boot message */ +int snd_sof_fw_parse_ext_data (struct snd_sof_dev *sdev,u32 bar,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, bar, 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, bar, offset, + (void *)((u8 *)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); +break ; + } + +/* move to next header */ + offset += ext_hdr->hdr.size; +snd_sof_dsp_block_read (sdev, bar, 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; +size_t remaining; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (struct snd_sof_blk_hdr *)((u8 *)module +sizeof (*module)); + +/* module->size doesn't include header size */ + remaining = module->size; +for (count =0 ; count < module->num_blocks; count++) { +/* minus header size of block */ + remaining -=sizeof (*block); +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +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_FW_BLK_TYPE_RSRVD0 : + case SOF_FW_BLK_TYPE_SRAM...SOF_FW_BLK_TYPE_RSRVD14: +continue ;/* not handled atm */ +case SOF_FW_BLK_TYPE_IRAM : +case SOF_FW_BLK_TYPE_DRAM : + 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); + +/* checking block->size to avoid unaligned access */ +if (block->size %sizeof (u32)) { +dev_err (sdev->dev,"error: invalid block size 0x%x\n" , + block->size); +return -EINVAL ; + } +snd_sof_dsp_block_write (sdev, sdev->mmio_bar, offset, + (void *)((u8 *)block +sizeof (*block)), + block->size); + +/* minus body size of block */ + remaining -= block->size; +/* next block */ + block = (struct snd_sof_blk_hdr *)((u8 *)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; +size_t remaining; + + header = (struct snd_sof_fw_header *)fw->data; + load_module =sof_ops (sdev)->load_module; +if (!load_module) +return -EINVAL ; + +/* parse each module */ + module = (struct snd_sof_mod_hdr *)((u8 *)(fw->data) +sizeof (*header)); + remaining = fw->size -sizeof (*header); +for (count =0 ; count < header->num_modules; count++) { +/* minus header size of module */ + remaining -=sizeof (*module); +if (remaining < module->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } +/* module */ + ret =load_module (sdev, module); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid module %d\n" , count); +return ret; + } +/* minus body size of module */ + remaining -= module->size; + module = (struct snd_sof_mod_hdr *)((u8 *)module + +sizeof (*module) + module->size); + } + +return 0 ; +} + +int snd_sof_load_firmware_raw (struct snd_sof_dev *sdev) +{ +struct snd_sof_pdata *plat_data = sdev->pdata; +const char *fw_filename; +int ret; + +/* set code loading condition to true */ + sdev->code_loading =1 ; + +/* Don't request firmware again if firmware is already requested */ +if (plat_data->fw) +return 0 ; + + fw_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->fw_filename_prefix, + plat_data->fw_filename); +if (!fw_filename) +return -ENOMEM ; + + ret =request_firmware (&plat_data->fw, fw_filename, sdev->dev); + +if (ret <0 ) { +dev_err (sdev->dev,"error: request firmware %s failed err: %d\n" , + fw_filename, ret); + } +return ret; +} +EXPORT_SYMBOL (snd_sof_load_firmware_raw); + +int snd_sof_load_firmware_memcpy (struct snd_sof_dev *sdev) +{ +struct snd_sof_pdata *plat_data = sdev->pdata; +int ret; + + ret =snd_sof_load_firmware_raw (sdev); +if (ret <0 ) +return ret; + +/* make sure the FW header and file is valid */ + ret =check_header (sdev, plat_data->fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW header\n" ); + goto error; + } + +/* 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" ); + goto error; + } + +/* parse and load firmware modules to DSP */ + ret =load_modules (sdev, plat_data->fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW modules\n" ); + goto error; + } + +return 0 ; + +error: +release_firmware (plat_data->fw); + plat_data->fw =NULL ; +return ret; + +} +EXPORT_SYMBOL (snd_sof_load_firmware_memcpy); + +int snd_sof_load_firmware (struct snd_sof_dev *sdev) +{ +dev_dbg (sdev->dev,"loading firmware\n" ); + +if (sof_ops (sdev)->load_firmware) +return sof_ops (sdev)->load_firmware (sdev); +return 0 ; +} +EXPORT_SYMBOL (snd_sof_load_firmware); + +int snd_sof_run_firmware (struct snd_sof_dev *sdev) +{ +int ret; +int init_core_mask; + +init_waitqueue_head (&sdev->boot_wait); + sdev->boot_complete = false; + +/* create fw_version debugfs to store boot version info */ +if (sdev->first_boot) { + ret =snd_sof_debugfs_buf_item (sdev, &sdev->fw_version, +sizeof (sdev->fw_version), +"fw_version" ); +/* errors are only due to memory allocation, not debugfs */ +if (ret <0 ) { +dev_err (sdev->dev,"error: snd_sof_debugfs_buf_item failed\n" ); +return ret; + } + } + +/* perform pre fw run operations */ + ret =snd_sof_dsp_pre_fw_run (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed pre fw run op\n" ); +return ret; + } + +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; + } + + init_core_mask = 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 failure\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" ); + +/* perform post fw run operations */ + ret =snd_sof_dsp_post_fw_run (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed post fw run op\n" ); +return ret; + } + +/* fw boot is complete. Update the active cores mask */ + sdev->enabled_cores_mask = init_core_mask; + +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
Re: [PATCH v5 09/14] ASoC: SOF: Add firmware loader support
sound/soc/sof/loader.c line 20
Quoted 5 lines · Pierre-Louis Bossart
sound/soc/sof/loader.c new file +4
-0+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;
In general it's safer to use container_of() than the forced cast, and...
Quoted 5 lines
sound/soc/sof/loader.c new file +5
-0+/* parse the extended FW boot data structures from FW boot message */ +int snd_sof_fw_parse_ext_data (struct snd_sof_dev *sdev,u32 bar,u32 offset) +{ +struct sof_ipc_ext_data_hdr *ext_hdr; +void *ext_data;
sound/soc/sof/loader.c line 50
Quoted 10 lines
sound/soc/sof/loader.c new file +10
-0+int ret =0 ; + + ext_data =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!ext_data) +return -ENOMEM ; + +/* get first header */ +snd_sof_dsp_block_read (sdev, bar, offset, ext_data, +sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data;
The cast isn't needed from a void pointer. The whole SOF codes have way too many unneeded cast. Let's reduce.
Quoted 13 lines
sound/soc/sof/loader.c new file +13
-0+/* 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; +size_t remaining; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (struct snd_sof_blk_hdr *)((u8 *)module +sizeof (*module));
sound/soc/sof/loader.c line 113
Quoted 10 lines
sound/soc/sof/loader.c new file +10
-0+ +/* module->size doesn't include header size */ + remaining = module->size; +for (count =0 ; count < module->num_blocks; count++) { +/* minus header size of block */ + remaining -=sizeof (*block); +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + }
remaining is unsigned, so a negative check doesn't work here. Hence you need the explicit underflow check.
Quoted 7 lines
sound/soc/sof/loader.c new file +7
-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;
sound/soc/sof/loader.c line 205
Quoted 10 lines
sound/soc/sof/loader.c new file +10
-0+size_t remaining; + + header = (struct snd_sof_fw_header *)fw->data; + load_module =sof_ops (sdev)->load_module; +if (!load_module) +return -EINVAL ; + +/* parse each module */ + module = (struct snd_sof_mod_hdr *)((u8 *)(fw->data) +sizeof (*header)); + remaining = fw->size -sizeof (*header);
The size check should be more strict (e.g. here remaining might become negative).
Quoted 17 lines
sound/soc/sof/loader.c new file +17
-0+int snd_sof_load_firmware_raw (struct snd_sof_dev *sdev) +{ +struct snd_sof_pdata *plat_data = sdev->pdata; +const char *fw_filename; +int ret; + +/* set code loading condition to true */ + sdev->code_loading =1 ; + +/* Don't request firmware again if firmware is already requested */ +if (plat_data->fw) +return 0 ; + + fw_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->fw_filename_prefix, + plat_data->fw_filename);
sound/soc/sof/loader.c line 254
Quoted 10 lines
sound/soc/sof/loader.c new file +10
-0+if (!fw_filename) +return -ENOMEM ; + + ret =request_firmware (&plat_data->fw, fw_filename, sdev->dev); + +if (ret <0 ) { +dev_err (sdev->dev,"error: request firmware %s failed err: %d\n" , + fw_filename, ret); + } +return ret;
Hrm, any need of devm_kasprintf() here? That is, do we need to keep this string after the call of request_firmware()? It doesn't make sense if we need it only temporarily.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v5 09/14] ASoC: SOF: Add firmware loader support
Quoted 7 lines
sound/soc/sof/loader.c line 20
Quoted 5 lines
sound/soc/sof/loader.c new file +4
-0+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;In general it's safer to use
container_of()than the forced cast, and...
yes
Quoted 11 lines
Quoted 11 lines
sound/soc/sof/loader.c new file +10
-0+/* parse the extended FW boot data structures from FW boot message */ +int snd_sof_fw_parse_ext_data (struct snd_sof_dev *sdev,u32 bar,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 ;
Quoted 8 lines
sound/soc/sof/loader.c line 50
Quoted 5 lines
sound/soc/sof/loader.c new file +5
-0+ +/* get first header */ +snd_sof_dsp_block_read (sdev, bar, offset, ext_data, +sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data;The cast isn't needed from a void pointer. The whole SOF codes have way too many unneeded cast. Let's reduce.
ok. we've removed quite a few casts but that's obviously not finished.
Quoted 19 lines
Quoted 19 lines
sound/soc/sof/loader.c new file +18
-0+/* 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; +size_t remaining; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (struct snd_sof_blk_hdr *)((u8 *)module +sizeof (*module)); + +/* module->size doesn't include header size */ + remaining = module->size; +for (count =0 ; count < module->num_blocks; count++) { +/* minus header size of block */
Quoted 8 lines
sound/soc/sof/loader.c line 113
Quoted 5 lines
sound/soc/sof/loader.c new file +5
-0+ remaining -=sizeof (*block); +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + }remaining is unsigned, so a negative check doesn't work here. Hence you need the explicit underflow check.
yes, probably need ssize_t here.
Quoted 13 lines
Quoted 13 lines
sound/soc/sof/loader.c new file +12
-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; +size_t remaining; + + header = (struct snd_sof_fw_header *)fw->data; + load_module =sof_ops (sdev)->load_module; +if (!load_module)
Quoted 8 lines
sound/soc/sof/loader.c line 205
Quoted 5 lines
sound/soc/sof/loader.c new file +5
-0+return -EINVAL ; + +/* parse each module */ + module = (struct snd_sof_mod_hdr *)((u8 *)(fw->data) +sizeof (*header)); + remaining = fw->size -sizeof (*header);The size check should be more strict (e.g. here remaining might become negative).
yes.
Quoted 24 lines
Quoted 24 lines
sound/soc/sof/loader.c new file +23
-0+int snd_sof_load_firmware_raw (struct snd_sof_dev *sdev) +{ +struct snd_sof_pdata *plat_data = sdev->pdata; +const char *fw_filename; +int ret; + +/* set code loading condition to true */ + sdev->code_loading =1 ; + +/* Don't request firmware again if firmware is already requested */ +if (plat_data->fw) +return 0 ; + + fw_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->fw_filename_prefix, + plat_data->fw_filename); +if (!fw_filename) +return -ENOMEM ; + + ret =request_firmware (&plat_data->fw, fw_filename, sdev->dev); + +if (ret <0 ) {
Quoted 8 lines
sound/soc/sof/loader.c line 254
Quoted 4 lines
sound/soc/sof/loader.c new file +4
-0+dev_err (sdev->dev,"error: request firmware %s failed err: %d\n" , + fw_filename, ret); + } +return ret;Hrm, any need of
devm_kasprintf()here? That is, do we need to keep this string after the call ofrequest_firmware()? It doesn't make sense if we need it only temporarily.
Good point, this can be simplified.
Re: [Sound-open-firmware] [PATCH v5 09/14] ASoC: SOF: Add firmware loader support
Quoted 28 lines · Pierre-Louis Bossart
Quoted 19 lines
Quoted 19 lines
sound/soc/sof/loader.c new file +18
-0+/* 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; +size_t remaining; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (struct snd_sof_blk_hdr *)((u8 *)module +sizeof (*module)); + +/* module->size doesn't include header size */ + remaining = module->size; +for (count =0 ; count < module->num_blocks; count++) { +/* minus header size of block */ Quoted 8 lines
sound/soc/sof/loader.c line 113
Quoted 5 lines
sound/soc/sof/loader.c new file +5
-0+ remaining -=sizeof (*block); +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + }remaining is unsigned, so a negative check doesn't work here. Hence you need the explicit underflow check.
Quoted 1 line
yes, probably need
ssize_there.
Be careful. If block->size is unsigned, the comparison is also done as unsigned in the code above.
Takashi
PATCH v5 10/14 ASoC: SOF: Add userspace ABI support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add 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 | 62 ++++++++++ include/uapi/sound/sof/eq.h | 172 +++++++++++++++++++++++++++ include/uapi/sound/sof/fw.h | 78 +++++++++++++ include/uapi/sound/sof/header.h | 27 +++++ include/uapi/sound/sof/manifest.h | 188 ++++++++++++++++++++++++++++++ include/uapi/sound/sof/tokens.h | 103 ++++++++++++++++ include/uapi/sound/sof/tone.h | 21 ++++ include/uapi/sound/sof/trace.h | 97 +++++++++++++++ 8 files changed, 748 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/header.h create mode 100644 include/uapi/sound/sof/manifest.h create mode 100644 include/uapi/sound/sof/tokens.h create mode 100644 include/uapi/sound/sof/tone.h create mode 100644 include/uapi/sound/sof/trace.h
include/uapi/sound/sof/abi.h new file +62 -0
@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +/** +* SOF ABI versioning is based on Semantic Versioning where we have a given +* MAJOR.MINOR.PATCH version number. See https://semver.org/ +* +* Rules for incrementing or changing version :- +* +* 1) Increment MAJOR version if you make incompatible API changes. MINOR and +* PATCH should be reset to 0. +* +* 2) Increment MINOR version if you add backwards compatible features or +* changes. PATCH should be reset to 0. +* +* 3) Increment PATCH version if you add backwards compatible bug fixes. +*/ + +#ifndef __INCLUDE_UAPI_SOUND_SOF_ABI_H__ +#define __INCLUDE_UAPI_SOUND_SOF_ABI_H__ + +/* SOF ABI version major, minor and patch numbers */ +#define SOF_ABI_MAJOR 3 +#define SOF_ABI_MINOR 3 +#define SOF_ABI_PATCH 0 + +/* SOF ABI version number. Format within 32bit word is MMmmmppp */ +#define SOF_ABI_MAJOR_SHIFT 24 +#define SOF_ABI_MAJOR_MASK 0xff +#define SOF_ABI_MINOR_SHIFT 12 +#define SOF_ABI_MINOR_MASK 0xfff +#define SOF_ABI_PATCH_SHIFT 0 +#define SOF_ABI_PATCH_MASK 0xfff + +#define SOF_ABI_VER (major, minor, patch) \ + (((major) << SOF_ABI_MAJOR_SHIFT) | \ + ((minor) << SOF_ABI_MINOR_SHIFT) | \ + ((patch) << SOF_ABI_PATCH_SHIFT)) + +#define SOF_ABI_VERSION_MAJOR (version) \ + (((version) >> SOF_ABI_MAJOR_SHIFT) & SOF_ABI_MAJOR_MASK) +#define SOF_ABI_VERSION_MINOR (version) \ + (((version) >> SOF_ABI_MINOR_SHIFT) & SOF_ABI_MINOR_MASK) +#define SOF_ABI_VERSION_PATCH (version) \ + (((version) >> SOF_ABI_PATCH_SHIFT) & SOF_ABI_PATCH_MASK) + +#define SOF_ABI_VERSION_INCOMPATIBLE (sof_ver, client_ver) \ + (SOF_ABI_VERSION_MAJOR((sof_ver)) != \ + SOF_ABI_VERSION_MAJOR((client_ver)) \ + ) + +#define SOF_ABI_VERSION SOF_ABI_VER(SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH) + +/* SOF ABI magic number "SOF\0". */ +#define SOF_ABI_MAGIC 0x00464F53 + +#endif
include/uapi/sound/sof/eq.h new file +172 -0
172 lines not on this page · raw message
include/uapi/sound/sof/fw.h new file +78 -0
78 lines not on this page · raw message
include/uapi/sound/sof/header.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_UAPI_SOUND_SOF_USER_HEADER_H__ +#define __INCLUDE_UAPI_SOUND_SOF_USER_HEADER_H__ + +/* +* 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 excl. this struct */ +uint32_t abi;/**< SOF ABI version */ +uint32_t reserved[4 ];/**< reserved for future use */ +uint32_t data[0 ];/**< Component data - opaque to core */ +} __packed; + +#endif
include/uapi/sound/sof/manifest.h new file +188 -0
188 lines not on this page · raw message
include/uapi/sound/sof/tokens.h new file +103 -0
103 lines not on this page · raw message
include/uapi/sound/sof/tone.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_UAPI_SOUND_SOF_USER_TONE_H__ +#define __INCLUDE_UAPI_SOUND_SOF_USER_TONE_H__ + +#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
include/uapi/sound/sof/trace.h new file +97 -0
97 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v5 11/14 ASoC: SOF: Add PM support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add support for saving and restoring DSP context in D3 to host DDR.
The suspend callback includes: suspend all pcm's stream that are running, send CTX_SAVE ipc, drop all ipc's, release trace dma and then power off the DSP.
And the resume callback performs the following steps: load FW, run FW, re-initialize trace, restore pipeline, restore the kcontrol values and finally send the ctx restore ipc to the dsp.
The streams that are suspended are resumed by the ALSA resume trigger. If the streams are paused during system suspend, they are marked explicitly so they can be restored during PAUSE_RELEASE.
--- sound/soc/sof/pm.c | 373 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 373 insertions(+) create mode 100644 sound/soc/sof/pm.c
sound/soc/sof/pm.c new file +373 -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 +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include "ops.h" +#include "sof-priv.h" + +static int sof_restore_kcontrols (struct snd_sof_dev *sdev) +{ +struct snd_sof_control *scontrol =NULL ; +int ipc_cmd, ctrl_type; +int ret =0 ; + +/* restore kcontrol values */ +list_for_each_entry (scontrol, &sdev->kcontrol_list, list) { +/* reset readback offset for scontrol after resuming */ + scontrol->readback_offset =0 ; + +/* notify DSP of kcontrol values */ +switch (scontrol->cmd) { +case SOF_CTRL_CMD_VOLUME : +/* fallthrough */ +case SOF_CTRL_CMD_ENUM : +/* fallthrough */ +case SOF_CTRL_CMD_SWITCH : + ipc_cmd =SOF_IPC_COMP_SET_VALUE ; + ctrl_type =SOF_CTRL_TYPE_VALUE_CHAN_SET ; + ret =snd_sof_ipc_set_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd); +break ; +case SOF_CTRL_CMD_BINARY : + ipc_cmd =SOF_IPC_COMP_SET_DATA ; + ctrl_type =SOF_CTRL_TYPE_DATA_SET ; + ret =snd_sof_ipc_set_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd); +break ; + +default : +break ; + } +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed kcontrol value set for widget: %d\n" , + scontrol->comp_id); + +return ret; + } + } + +return 0 ; +} + +static int sof_restore_pipelines (struct snd_sof_dev *sdev) +{ +struct snd_sof_widget *swidget =NULL ; +struct snd_sof_route *sroute =NULL ; +struct sof_ipc_pipe_new *pipeline; +struct snd_sof_dai *dai; +struct sof_ipc_comp_dai *comp_dai; +struct sof_ipc_cmd_hdr *hdr; +int ret =0 ; + +/* restore pipeline components */ +list_for_each_entry_reverse (swidget, &sdev->widget_list, list) { +struct sof_ipc_comp_reply r; + +/* skip if there is no private data */ +if (!swidget->private) +continue ; + +switch (swidget->id) { +case snd_soc_dapm_dai_in: +/* fallthrough */ +case snd_soc_dapm_dai_out: + dai = (struct snd_sof_dai *)swidget->private; + comp_dai = &dai->comp_dai; + ret =sof_ipc_tx_message (sdev->ipc, + comp_dai->comp.hdr.cmd, + comp_dai,sizeof (*comp_dai), + &r,sizeof (r)); +break ; +case snd_soc_dapm_scheduler: + +/* +* During suspend, all DSP cores are powered off. +* Therefore upon resume, create the pipeline comp +* and power up the core that the pipeline is +* scheduled on. +*/ + pipeline = (struct sof_ipc_pipe_new *)swidget->private; + ret =sof_load_pipeline_ipc (sdev, pipeline, &r); +break ; +default : + hdr = (struct sof_ipc_cmd_hdr *)swidget->private; + ret =sof_ipc_tx_message (sdev->ipc, hdr->cmd, + swidget->private, hdr->size, + &r,sizeof (r)); +break ; + } +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load widget type %d with ID: %d\n" , + swidget->widget->id, swidget->comp_id); + +return ret; + } + } + +/* restore pipeline connections */ +list_for_each_entry_reverse (sroute, &sdev->route_list, list) { +struct sof_ipc_pipe_comp_connect *connect; +struct sof_ipc_reply reply; + +/* skip if there's no private data */ +if (!sroute->private) +continue ; + + connect = sroute->private; + +/* send ipc */ + ret =sof_ipc_tx_message (sdev->ipc, + connect->hdr.cmd, + connect,sizeof (*connect), + &reply,sizeof (reply)); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load route sink %s control %s source %s\n" , + sroute->route->sink, + sroute->route->control ? sroute->route->control + :"none" , + sroute->route->source); + +return ret; + } + } + +/* restore dai links */ +list_for_each_entry_reverse (dai, &sdev->dai_list, list) { +struct sof_ipc_reply reply; +struct sof_ipc_dai_config *config = dai->dai_config; + +if (!config) { +dev_err (sdev->dev,"error: no config for DAI %s\n" , + dai->name); +continue ; + } + + ret =sof_ipc_tx_message (sdev->ipc, + config->hdr.cmd, config, + config->hdr.size, + &reply,sizeof (reply)); + +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to set dai config for %s\n" , + dai->name); + +return ret; + } + } + +/* complete pipeline */ +list_for_each_entry (swidget, &sdev->widget_list, list) { +switch (swidget->id) { +case snd_soc_dapm_scheduler: + swidget->complete = +snd_sof_complete_pipeline (sdev, swidget); +break ; +default : +break ; + } + } + +/* restore pipeline kcontrols */ + ret =sof_restore_kcontrols (sdev); +if (ret <0 ) +dev_err (sdev->dev, +"error: restoring kcontrols after resume\n" ); + +return ret; +} + +static int sof_send_pm_ipc (struct snd_sof_dev *sdev,int cmd) +{ +struct sof_ipc_pm_ctx pm_ctx; +struct sof_ipc_reply reply; + +memset (&pm_ctx,0 ,sizeof (pm_ctx)); + +/* configure ctx save ipc message */ + pm_ctx.hdr.size =sizeof (pm_ctx); + pm_ctx.hdr.cmd =SOF_IPC_GLB_PM_MSG | cmd; + +/* send ctx save ipc to dsp */ +return sof_ipc_tx_message (sdev->ipc, pm_ctx.hdr.cmd, &pm_ctx, +sizeof (pm_ctx), &reply,sizeof (reply)); +} + +static void sof_set_restore_stream (struct snd_sof_dev *sdev) +{ +struct snd_sof_pcm *spcm; + +/* suspend all running streams */ +list_for_each_entry (spcm, &sdev->pcm_list, list) { + + spcm->restore_stream[0 ] =1 ; + spcm->restore_stream[1 ] =1 ; + + } +} + +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +static void sof_cache_debugfs (struct snd_sof_dev *sdev) +{ +struct snd_sof_dfsentry *dfse; + +list_for_each_entry (dfse, &sdev->dfsentry_list, list) { + +/* nothing to do if debugfs buffer is not IO mem */ +if (dfse->type ==SOF_DFSENTRY_TYPE_BUF ) +continue ; + +/* cache memory that is only accessible in D0 */ +if (dfse->access_type ==SOF_DEBUGFS_ACCESS_D0_ONLY ) +memcpy_fromio (dfse->cache_buf, dfse->io_mem, + dfse->size); + } +} +#endif + +static int sof_resume (struct device *dev,bool runtime_resume) +{ +struct snd_sof_dev *sdev =dev_get_drvdata (dev); +int ret =0 ; + +/* do nothing if dsp resume callbacks are not set */ +if (!sof_ops (sdev)->resume || !sof_ops (sdev)->runtime_resume) +return 0 ; + +/* +* if the runtime_resume flag is set, call the runtime_resume routine +* or else call the system resume routine +*/ +if (runtime_resume) + ret =snd_sof_dsp_runtime_resume (sdev); +else + ret =snd_sof_dsp_resume (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to power up DSP after resume\n" ); +return ret; + } + +/* load the firmware */ + ret =snd_sof_load_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* boot the firmware */ + ret =snd_sof_run_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to boot DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* resume DMA trace, only need send ipc */ + ret =snd_sof_init_trace_ipc (sdev); +if (ret <0 ) { +/* non fatal */ +dev_warn (sdev->dev, +"warning: failed to init trace after resume %d\n" , + ret); + } + +/* restore pipelines */ + ret =sof_restore_pipelines (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to restore pipeline after resume %d\n" , + ret); +return ret; + } + +/* notify DSP of system resume */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_RESTORE ); +if (ret <0 ) +dev_err (sdev->dev, +"error: ctx_restore ipc error during resume %d\n" , + ret); + +return ret; +} + +static int sof_suspend (struct device *dev,bool runtime_suspend) +{ +struct snd_sof_dev *sdev =dev_get_drvdata (dev); +int ret =0 ; + +/* do nothing if dsp suspend callback is not set */ +if (!sof_ops (sdev)->suspend) +return 0 ; + +/* release trace */ +snd_sof_release_trace (sdev); + +/* set restore_stream for all streams during system suspend */ +if (!runtime_suspend) +sof_set_restore_stream (sdev); + +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +/* cache debugfs contents during runtime suspend */ +if (runtime_suspend) +sof_cache_debugfs (sdev); +#endif +/* notify DSP of upcoming power down */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_SAVE ); +if (ret <0 ) { +dev_err (sdev->dev, +"error: ctx_save ipc error during suspend %d\n" , + ret); +return ret; + } + +/* power down all DSP cores */ +if (runtime_suspend) + ret =snd_sof_dsp_runtime_suspend (sdev,0 ); +else + ret =snd_sof_dsp_suspend (sdev,0 ); +if (ret <0 ) +dev_err (sdev->dev, +"error: failed to power down DSP during suspend %d\n" , + ret); + +return ret; +} + +int snd_sof_runtime_suspend (struct device *dev) +{ +return sof_suspend (dev, true); +} +EXPORT_SYMBOL (snd_sof_runtime_suspend); + +int snd_sof_runtime_resume (struct device *dev) +{ +return sof_resume (dev, true); +} +EXPORT_SYMBOL (snd_sof_runtime_resume); + +int snd_sof_resume (struct device *dev) +{ +return sof_resume (dev, false); +} +EXPORT_SYMBOL (snd_sof_resume); + +int snd_sof_suspend (struct device *dev) +{ +return sof_suspend (dev, false); +} +EXPORT_SYMBOL (snd_sof_suspend);
Signature · 1 line
2.17.1
Re: [PATCH v5 11/14] ASoC: SOF: Add PM support
Quoted 52 lines · Pierre-Louis Bossart
From: Liam Girdwood <[email protected]>
Add support for saving and restoring DSP context in D3 to host DDR.
The suspend callback includes: suspend all pcm's stream that are running, send
CTX_SAVEipc, drop all ipc's, release trace dma and then power off the DSP.And the resume callback performs the following steps: load FW, run FW, re-initialize trace, restore pipeline, restore the kcontrol values and finally send the ctx restore ipc to the dsp.
The streams that are suspended are resumed by the ALSA resume trigger. If the streams are paused during system suspend, they are marked explicitly so they can be restored during
PAUSE_RELEASE.Signed-off-by Ranjani Sridharan <[email protected]>Signed-off-by Liam Girdwood <[email protected]>Signed-off-by Pierre-Louis Bossart <[email protected]>--- sound/soc/sof/pm.c | 373 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 373 insertions(+) create mode 100644 sound/soc/sof/pm.csound/soc/sof/pm.c new file +21
-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 +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include "ops.h" +#include "sof-priv.h" + +static int sof_restore_kcontrols (struct snd_sof_dev *sdev) +{ +struct snd_sof_control *scontrol =NULL ; +int ipc_cmd, ctrl_type; +int ret =0 ; + +/* restore kcontrol values */ +list_for_each_entry (scontrol, &sdev->kcontrol_list, list) {
sound/soc/sof/pm.c line 31
Quoted 10 lines
sound/soc/sof/pm.c new file +10
-0+/* reset readback offset for scontrol after resuming */ + scontrol->readback_offset =0 ; + +/* notify DSP of kcontrol values */ +switch (scontrol->cmd) { +case SOF_CTRL_CMD_VOLUME : +/* fallthrough */ +case SOF_CTRL_CMD_ENUM : +/* fallthrough */ +case SOF_CTRL_CMD_SWITCH :
In such an expression, fallthrough marker is superfluous.
switch (foo) {
case A:
case B:
case C:
....thanks,
Takashi
PATCH v5 12/14 ASoC: SOF: Add Nocodec machine driver support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add a simple "fallback" machine driver that can be used to enable SOF on boards with no codec device. This machine driver can also be forced for debug/development.
--- include/sound/sof.h | 6 +++ sound/soc/sof/nocodec.c | 109 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 sound/soc/sof/nocodec.c
include/sound/sof.h +6 -0
@@ -12,6 +12,7 @@#define __INCLUDE_SOUND_SOF_H#include <linux/pci.h> +#include <sound/soc.h> #include <sound/soc-acpi.h> struct snd_sof_dsp_ops ;
@@ -91,4 +92,9 @@ struct sof_dev_desc { const struct sof_arch_ops *arch_ops; }; +int sof_nocodec_setup (struct device *dev, +struct snd_sof_pdata *sof_pdata, +struct snd_soc_acpi_mach *mach, +const struct sof_dev_desc *desc, +const struct snd_sof_dsp_ops *ops);#endif
sound/soc/sof/nocodec.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v5 13/14 ASoC: SOF: Add xtensa support
In reply to Pierre-Louis BossartAdd common directory for xtensa architecture
--- include/sound/sof/xtensa.h | 44 +++++++++++ sound/soc/sof/xtensa/Kconfig | 2 + sound/soc/sof/xtensa/Makefile | 5 ++ sound/soc/sof/xtensa/core.c | 138 ++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+) create mode 100644 include/sound/sof/xtensa.h create mode 100644 sound/soc/sof/xtensa/Kconfig create mode 100644 sound/soc/sof/xtensa/Makefile create mode 100644 sound/soc/sof/xtensa/core.c
include/sound/sof/xtensa.h new file +44 -0
@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_SOUND_SOF_XTENSA_H__ +#define __INCLUDE_SOUND_SOF_XTENSA_H__ + +#include <sound/sof/header.h> + +/* +* Architecture specific debug +*/ + +/* Xtensa Firmware Oops data */ +struct sof_ipc_dsp_oops_xtensa { +struct sof_ipc_hdr hdr; +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; +} __packed; + +#endif
sound/soc/sof/xtensa/Kconfig new file +2 -0
@@ -0,0 +1,2 @@ +config SND_SOC_SOF_XTENSA + tristate
sound/soc/sof/xtensa/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) + +snd-sof-xtensa-dsp-objs := core.o + +obj-$(CONFIG_SND_SOC_SOF_XTENSA) += snd-sof-xtensa-dsp.o
sound/soc/sof/xtensa/core.c new file +138 -0
138 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v5 14/14 ASoC: SOF: Add utils
In reply to Pierre-Louis BossartHelpers to set-up back-ends, create platform devices and common IO/block read/write operations
--- sound/soc/sof/utils.c | 112 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 sound/soc/sof/utils.c
sound/soc/sof/utils.c new file +112 -0
@@ -0,0 +1,112 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Keyon Jie <[email protected]> +// + +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/platform_device.h> +#include <sound/soc.h> +#include <sound/sof.h> +#include "sof-priv.h" + +/* +* Register IO +* +* The sof_io_xyz() wrappers are typically referenced in snd_sof_dsp_ops +* structures and and cannot be inlined. +*/ + +void sof_io_write (struct snd_sof_dev *sdev,void __iomem *addr,u32 value) +{ +writel (value, addr); +} +EXPORT_SYMBOL (sof_io_write); + +u32 sof_io_read (struct snd_sof_dev *sdev,void __iomem *addr) +{ +return readl (addr); +} +EXPORT_SYMBOL (sof_io_read); + +void sof_io_write64 (struct snd_sof_dev *sdev,void __iomem *addr,u64 value) +{ +writeq (value, addr); +} +EXPORT_SYMBOL (sof_io_write64); + +u64 sof_io_read64 (struct snd_sof_dev *sdev,void __iomem *addr) +{ +return readq (addr); +} +EXPORT_SYMBOL (sof_io_read64); + +/* +* IPC Mailbox IO +*/ + +void sof_mailbox_write (struct snd_sof_dev *sdev,u32 offset, +void *message,size_t bytes) +{ +void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; + +memcpy_toio (dest, message, bytes); +} +EXPORT_SYMBOL (sof_mailbox_write); + +void sof_mailbox_read (struct snd_sof_dev *sdev,u32 offset, +void *message,size_t bytes) +{ +void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; + +memcpy_fromio (message, src, bytes); +} +EXPORT_SYMBOL (sof_mailbox_read); + +/* +* Memory copy. +*/ + +void sof_block_write (struct snd_sof_dev *sdev,u32 bar,u32 offset,void *src, +size_t size) +{ +void __iomem *dest = sdev->bar[bar] + offset; +const u8 *src_byte = src; +u32 affected_mask; +u32 tmp; +int m, n; + + m = size /4 ; + n = size %4 ; + +/* __iowrite32_copy use 32bit size values so divide by 4 */ +__iowrite32_copy (dest, src, m); + +if (n) { + affected_mask = (1 << (8 * n)) -1 ; + +/* first read the 32bit data of dest, then change affected +* bytes, and write back to dest. For unaffected bytes, it +* should not be changed +*/ + tmp =ioread32 (dest + m *4 ); + tmp &= ~affected_mask; + + tmp |= *(u32 *)(src_byte + m *4 ) & affected_mask; +iowrite32 (tmp, dest + m *4 ); + } +} +EXPORT_SYMBOL (sof_block_write); + +void sof_block_read (struct snd_sof_dev *sdev,u32 bar,u32 offset,void *dest, +size_t size) +{ +void __iomem *src = sdev->bar[bar] + offset; + +memcpy_fromio (dest, src, size); +} +EXPORT_SYMBOL (sof_block_read);
Signature · 1 line
2.17.1
Re: [PATCH v5 14/14] ASoC: SOF: Add utils
Quoted 6 lines · Pierre-Louis Bossart
+/*
+ * Register IO
+ *
+ * Thesof_io_xyz()wrappers are typically referenced insnd_sof_dsp_ops
+ * structures and and cannot be inlined.
Too many and.
Takashi