ASoC: Sound Open Firmware (SOF) core
Subsystems (3)
v6 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.
Changes since v5:
In addition to addressing feedback from Takashi, the major change in this series is the IPC rework. We reverted some optimizations to help Daniel Baluta @ NXP submit support for i.MX platforms, additional IPC core refactorization will start once we have two platforms supported on github. Hopefully by then the code will be accepted in the ASoC tree and we can submit delta patches, hint hint wink wink.
All feedback from Takashi addressed:
Tabify/align Kconfigs
Remove INFO_RESUME flag
Add const char* for core prototypes
Fix snd_sof_get_status return value
Use smd_pcm_format_physical_width()
Fix hw_constraints and BUFFER_BYTES/SIZE confusion Remove useless fallthrough statements
Fix typos and duplicate words in comments and commit messages Remove unnecessary casts, use container_of
Remove superfluous initializations
Fix potential race condition in debugfs
Check for wrap-arounds in loader
Fix alignment in debugfs read
Don't use devm_kasprintf for firmware name string.
Other updates:
Major refactor of IPC handling (support for large messages, code optimization, better abstraction to push Intel-specific code out of the core).
Regenerate compressed page table only if needed
Support for multiple DAI hw_config (from <[email protected]>) Use iopoll macros (with small change due to indirection) Fix PM refcount handling on errors
Rename/unify all definitions for effects (now 'process') Added basic support for keyword/hotword detection and binding widgets with external events
Fix release of topology resources
Support new IPC_PANIC message
Clean-up mandatory/optional callbacks, simplify wrappers Add topology ABI check
Fix acpi/machine driver handling
Fix memory leak in debugfs error handling
Alignment with firmware header files
Fixed topology endianness issues
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 | 67 + 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 | 107 + include/uapi/sound/sof/tone.h | 21 + include/uapi/sound/sof/trace.h | 66 + sound/soc/sof/control.c | 552 +++++ sound/soc/sof/core.c | 506 +++++ sound/soc/sof/debug.c | 232 +++ sound/soc/sof/ipc.c | 832 ++++++++ sound/soc/sof/loader.c | 400 ++++ sound/soc/sof/nocodec.c | 109 + sound/soc/sof/ops.c | 163 ++ sound/soc/sof/ops.h | 399 ++++ sound/soc/sof/pcm.c | 719 +++++++ sound/soc/sof/pm.c | 385 ++++ sound/soc/sof/sof-priv.h | 632 ++++++ sound/soc/sof/topology.c | 3164 +++++++++++++++++++++++++++++ sound/soc/sof/trace.c | 297 +++ 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, 10718 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
base-commit: 5f2ab35fe853f4886da490de8bc47637f5fc2921
Signature · 1 line
2.17.1
PATCH v6 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 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 | 506 +++++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 632 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 1232 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 +506 -0
506 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +632 -0
632 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: SOF: Add Sound Open Firmware driver core" to the asoc tree
The patch
ASoC: SOF: Add Sound Open Firmware driver core
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
c16211d6226dbde8819b84da07508083a1138a06Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:06 -0500
Subject: [PATCH] ASoC: SOF: Add Sound Open Firmware driver core
The Sound Open Firmware driver core is a generic architecture independent layer that allows SOF to be used on many different 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 | 506 +++++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 632 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 1232 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 +506 -0
506 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +632 -0
632 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 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 will be provided in an update.
--- sound/soc/sof/control.c | 552 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 552 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +552 -0
@@ -0,0 +1,552 @@ +// 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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME , + false); + +/* 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_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME , + true); + +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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_SWITCH , + false); + +/* 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_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_SWITCH , + true); + +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 enum data from DSP */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM , + false); + +/* 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 enum updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM , + true); + +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 binary data from DSP */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , + scontrol->cmd, + false); + + 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 byte control updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , + scontrol->cmd, + true); + +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; + +/* +* 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 ; + +/* be->max is coming from topology */ +if (header.length > be->max) { +dev_err_ratelimited (sdev->dev,"error: Bytes data size %d exceeds max %d.\n" , + header.length, be->max); +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 ) > be->max) { +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 byte control updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , + scontrol->cmd, + true); + +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 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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , + scontrol->cmd, + false); + +/* Prevent read of other kernel data or possibly corrupt response */ + data_size = cdata->data->size +sizeof (const struct sof_abi_hdr ); + +/* check data size doesn't exceed max coming from topology */ +if (data_size > be->max) { +dev_err_ratelimited (sdev->dev,"error: user data size %d exceeds max size %d.\n" , + data_size, be->max); + 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)) + ret = -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
Mark Brown
maintainerApplied "ASoC: SOF: Add Sound Open Firmware KControl support" to the asoc tree
The patch
ASoC: SOF: Add Sound Open Firmware KControl support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
c3078f5397046755ddcd0447d202124c398469c5Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:07 -0500
Subject: [PATCH] ASoC: SOF: Add Sound Open Firmware KControl support
SOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
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 will be provided in an update.
--- sound/soc/sof/control.c | 552 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 552 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +552 -0
@@ -0,0 +1,552 @@ +// 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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME , + false); + +/* 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_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME , + true); + +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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_SWITCH , + false); + +/* 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_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_SWITCH , + true); + +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 enum data from DSP */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM , + false); + +/* 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 enum updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_ENUM , + true); + +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 binary data from DSP */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , + scontrol->cmd, + false); + + 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 byte control updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , + scontrol->cmd, + true); + +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; + +/* +* 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 ; + +/* be->max is coming from topology */ +if (header.length > be->max) { +dev_err_ratelimited (sdev->dev,"error: Bytes data size %d exceeds max %d.\n" , + header.length, be->max); +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 ) > be->max) { +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 byte control updates */ +snd_sof_ipc_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , + scontrol->cmd, + true); + +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 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_set_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , + scontrol->cmd, + false); + +/* Prevent read of other kernel data or possibly corrupt response */ + data_size = cdata->data->size +sizeof (const struct sof_abi_hdr ); + +/* check data size doesn't exceed max coming from topology */ +if (data_size > be->max) { +dev_err_ratelimited (sdev->dev,"error: user data size %d exceeds max size %d.\n" , + data_size, be->max); + 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)) + ret = -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.20.1
PATCH v6 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 | 232 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +232 -0
@@ -0,0 +1,232 @@ +// 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; +loff_t pos = *ppos; +size_t size_ret; +int skip =0 ; +int size; +u8 *buf; + + 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; + +/* align io read start to u32 multiple */ + pos =ALIGN_DOWN (pos,4 ); + +/* intermediate buffer size must be u32 multiple */ + size =ALIGN (count,4 ); + +/* if start position is unaligned, read extra u32 */ +if (unlikely (pos != *ppos)) { + skip = *ppos - pos; +if (pos + size +4 < dfse->size) + size +=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); +kfree (buf); +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 + skip, 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
Mark Brown
maintainerRe: [PATCH v6 03/14] ASoC: SOF: Add driver debug support.
sound/soc/sof/debug.c line 74
Quoted 8 lines · Pierre-Louis Bossart
sound/soc/sof/debug.c new file +8
-0+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); + }
Might this get a bit noisy if we start hitting the info case?
Re: [PATCH v6 03/14] ASoC: SOF: Add driver debug support.
Thanks for the review Mark
Quoted 12 lines · Mark Brown
sound/soc/sof/debug.c line 74
Quoted 8 lines · Pierre-Louis Bossart
sound/soc/sof/debug.c new file +8
-0+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); + }Might this get a bit noisy if we start hitting the info case?
Indeed, I recall we discussed removing this log but it's still there. We can fix this with a follow-up patch or in a v7 depending if there are other comments.
Mark Brown
maintainerApplied "ASoC: SOF: Add driver debug support." to the asoc tree
In reply to Pierre-Louis BossartThe patch
ASoC: SOF: Add driver debug support.
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
86b02f71ccf320727473448733503e6f9378102dMon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:08 -0500
Subject: [PATCH] ASoC: SOF: Add driver debug support.
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 | 232 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +232 -0
@@ -0,0 +1,232 @@ +// 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; +loff_t pos = *ppos; +size_t size_ret; +int skip =0 ; +int size; +u8 *buf; + + 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; + +/* align io read start to u32 multiple */ + pos =ALIGN_DOWN (pos,4 ); + +/* intermediate buffer size must be u32 multiple */ + size =ALIGN (count,4 ); + +/* if start position is unaligned, read extra u32 */ +if (unlikely (pos != *ppos)) { + skip = *ppos - pos; +if (pos + size +4 < dfse->size) + size +=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); +kfree (buf); +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 + skip, 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.20.1
PATCH v6 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 | 67 +++ sound/soc/sof/ipc.c | 832 ++++++++++++++++++++++++++++++++++ 9 files changed, 1782 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 - uses 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 +67 -0
67 lines not on this page · raw message
sound/soc/sof/ipc.c new file +832 -0
832 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: SOF: Add support for IPC IO between DSP and Host" to the asoc tree
The patch
ASoC: SOF: Add support for IPC IO between DSP and Host
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
53e0c72d98ba3eae314c32476103eac47612aa58Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:09 -0500
Subject: [PATCH] ASoC: SOF: Add support for IPC IO between DSP and Host
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 | 67 +++ sound/soc/sof/ipc.c | 832 ++++++++++++++++++++++++++++++++++ 9 files changed, 1782 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 - uses 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 +67 -0
67 lines not on this page · raw message
sound/soc/sof/ipc.c new file +832 -0
832 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 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 .get_module_upon_open 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 | 719 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 719 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +719 -0
@@ -0,0 +1,719 @@ +// 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); +} + +static int sof_pcm_dsp_params (struct snd_sof_pcm *spcm,struct snd_pcm_substream *substream, +const struct sof_ipc_pcm_params_reply *reply) +{ +struct snd_sof_dev *sdev = spcm->sdev; +/* validate offset */ +int ret =snd_sof_ipc_pcm_params (sdev, substream, reply); + +if (ret <0 ) +dev_err (sdev->dev,"error: got wrong reply for PCM %d\n" , + spcm->pcm.pcm_id); + +return ret; +} + +/* 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 ret; + +/* nothing to do 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; + } +if (ret) { +/* +* ret == 1 means the buffer is changed +* create compressed page table for audio firmware +* ret == 0 means the buffer is not changed +* so no need to regenerate the page table +*/ + 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 */ + ret =snd_pcm_format_physical_width (params_format (params)); +if (ret <0 ) +return ret; + pcm.params.sample_container_bytes = ret >>3 ; + +/* 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; + } + + ret =sof_pcm_dsp_params (spcm, substream, &ipc_params_reply); +if (ret <0 ) +return ret; + +/* save pcm hw_params */ +memcpy (&spcm->params[substream->stream], params,sizeof (*params)); + +return ret; +} + +static int sof_pcm_hw_free (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev =snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing to do 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_pcm_prepare (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 ret; + +/* nothing to do for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +/* +* check if hw_params needs to be set-up again. +* This is only needed when resuming from system sleep. +*/ +if (!spcm->hw_params_upon_resume[substream->stream]) +return 0 ; + +dev_dbg (sdev->dev,"pcm: prepare stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +/* 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 to do 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 : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; +break ; +case SNDRV_PCM_TRIGGER_RESUME : +/* set up hw_params */ + ret =sof_pcm_prepare (substream); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to set up hw_params upon resume\n" ); +return ret; + } + +/* fallthrough */ +case SNDRV_PCM_TRIGGER_START : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_STOP : + 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 */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +if (ret <0 || cmd !=SNDRV_PCM_TRIGGER_SUSPEND ) +return ret; + +/* +* The hw_free op is usually called when the pcm stream is closed. +* Since the stream is not closed during suspend, the DSP needs to be +* notified explicitly to free pcm to prevent errors upon resume. +*/ + 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 */ +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, dai; + +/* nothing to do for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +/* use dsp ops pointer callback directly if set */ +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 to do 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); + +/* clear hw_params_upon_resume flag */ + spcm->hw_params_upon_resume[substream->stream] =0 ; + + 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_BYTES , +le32_to_cpu (caps->period_size_min)); +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_PERIOD_BYTES , +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_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); + +/* +* caps->buffer_size_min is not used since the +* snd_pcm_hardware structure only defines buffer_bytes_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 to do 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, + .prepare = sof_pcm_prepare, + .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 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 0 ; + + 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 0 ; +} + +/* 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); + } +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 from 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) +{ +/* remove topology */ +snd_soc_tplg_component_remove (component,SND_SOC_TPLG_INDEX_ALL ); +} + +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" ; + +/* increment module refcount when a pcm is opened */ + pd->module_get_upon_open =1 ; +}
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: SOF: Add PCM operations support" to the asoc tree
The patch
ASoC: SOF: Add PCM operations support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
868bd00f495514630a52161052d2fe155af599feMon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:10 -0500
Subject: [PATCH] ASoC: SOF: Add PCM operations support
Add support for exposing PCMs to userspace. PCMs are defined by topology and the operations in this patch map to SOF IPC calls.
The .get_module_upon_open 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 | 719 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 719 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +719 -0
@@ -0,0 +1,719 @@ +// 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); +} + +static int sof_pcm_dsp_params (struct snd_sof_pcm *spcm,struct snd_pcm_substream *substream, +const struct sof_ipc_pcm_params_reply *reply) +{ +struct snd_sof_dev *sdev = spcm->sdev; +/* validate offset */ +int ret =snd_sof_ipc_pcm_params (sdev, substream, reply); + +if (ret <0 ) +dev_err (sdev->dev,"error: got wrong reply for PCM %d\n" , + spcm->pcm.pcm_id); + +return ret; +} + +/* 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 ret; + +/* nothing to do 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; + } +if (ret) { +/* +* ret == 1 means the buffer is changed +* create compressed page table for audio firmware +* ret == 0 means the buffer is not changed +* so no need to regenerate the page table +*/ + 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 */ + ret =snd_pcm_format_physical_width (params_format (params)); +if (ret <0 ) +return ret; + pcm.params.sample_container_bytes = ret >>3 ; + +/* 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; + } + + ret =sof_pcm_dsp_params (spcm, substream, &ipc_params_reply); +if (ret <0 ) +return ret; + +/* save pcm hw_params */ +memcpy (&spcm->params[substream->stream], params,sizeof (*params)); + +return ret; +} + +static int sof_pcm_hw_free (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev =snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing to do 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_pcm_prepare (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 ret; + +/* nothing to do for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) +return -EINVAL ; + +/* +* check if hw_params needs to be set-up again. +* This is only needed when resuming from system sleep. +*/ +if (!spcm->hw_params_upon_resume[substream->stream]) +return 0 ; + +dev_dbg (sdev->dev,"pcm: prepare stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +/* 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 to do 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 : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; +break ; +case SNDRV_PCM_TRIGGER_RESUME : +/* set up hw_params */ + ret =sof_pcm_prepare (substream); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to set up hw_params upon resume\n" ); +return ret; + } + +/* fallthrough */ +case SNDRV_PCM_TRIGGER_START : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_STOP : + 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 */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +if (ret <0 || cmd !=SNDRV_PCM_TRIGGER_SUSPEND ) +return ret; + +/* +* The hw_free op is usually called when the pcm stream is closed. +* Since the stream is not closed during suspend, the DSP needs to be +* notified explicitly to free pcm to prevent errors upon resume. +*/ + 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 */ +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, dai; + +/* nothing to do for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +/* use dsp ops pointer callback directly if set */ +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 to do 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); + +/* clear hw_params_upon_resume flag */ + spcm->hw_params_upon_resume[substream->stream] =0 ; + + 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_BYTES , +le32_to_cpu (caps->period_size_min)); +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_PERIOD_BYTES , +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_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); + +/* +* caps->buffer_size_min is not used since the +* snd_pcm_hardware structure only defines buffer_bytes_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 to do 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, + .prepare = sof_pcm_prepare, + .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 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 0 ; + + 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 0 ; +} + +/* 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); + } +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 from 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) +{ +/* remove topology */ +snd_soc_tplg_component_remove (component,SND_SOC_TPLG_INDEX_ALL ); +} + +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" ; + +/* increment module refcount when a pcm is opened */ + pd->module_get_upon_open =1 ; +}
Signature · 1 line
2.20.1
PATCH v6 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 | 3164 ++++++++++++++++++++++++++++++++++ 2 files changed, 3420 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_KEYWORD_DETECT , +SOF_COMP_KPB ,/* A key phrase buffer component */ +SOF_COMP_SELECTOR ,/**< channel selector component */ +/* keep FILEREAD/FILEWRITE as the last ones */ +SOF_COMP_FILEREAD =10000 ,/**< host test based file IO */ +SOF_COMP_FILEWRITE =10001 ,/**< 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 processing components */ +enum sof_ipc_process_type { +SOF_PROCESS_NONE =0 ,/**< None */ +SOF_PROCESS_EQFIR ,/**< Intel FIR */ +SOF_PROCESS_EQIIR ,/**< Intel IIR */ +SOF_PROCESS_KEYWORD_DETECT ,/**< Keyword Detection */ +SOF_PROCESS_KPB ,/**< KeyPhrase Buffer Manager */ +SOF_PROCESS_CHAN_SELECTOR ,/**< Channel Selector */ +}; + +/* generic "effect", "codec" or proprietary processing component */ +struct sof_ipc_comp_process { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size;/**< size of bespoke data section in bytes */ +uint32_t type;/**< sof_ipc_process_type */ + +/* reserved for future use */ +uint32_t reserved[7 ]; + +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 +*/ + +/** \brief Types of pipeline scheduling time domains */ +enum sof_ipc_pipe_sched_time_domain { +SOF_TIME_DOMAIN_DMA =0 ,/**< DMA interrupt */ +SOF_TIME_DOMAIN_TIMER ,/**< Timer interrupt */ +}; + +/* 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 period;/**< execution period 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 */ +uint32_t time_domain;/**< scheduling time domain */ +} __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; + +/* external events */ +enum sof_event_types { +SOF_EVENT_NONE =0 , +SOF_KEYWORD_DETECT_DAPM_EVENT , +}; + +#endif
sound/soc/sof/topology.c new file +3164 -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.
Mark Brown
maintainerApplied "ASoC: SOF: Add support for loading topologies" to the asoc tree
The patch
ASoC: SOF: Add support for loading topologies
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
311ce4fe7637d96608b6e57bf9ebbd8aabcf429eMon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:11 -0500
Subject: [PATCH] ASoC: SOF: Add support for loading topologies
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 | 3164 ++++++++++++++++++++++++++++++++++ 2 files changed, 3420 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_KEYWORD_DETECT , +SOF_COMP_KPB ,/* A key phrase buffer component */ +SOF_COMP_SELECTOR ,/**< channel selector component */ +/* keep FILEREAD/FILEWRITE as the last ones */ +SOF_COMP_FILEREAD =10000 ,/**< host test based file IO */ +SOF_COMP_FILEWRITE =10001 ,/**< 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 processing components */ +enum sof_ipc_process_type { +SOF_PROCESS_NONE =0 ,/**< None */ +SOF_PROCESS_EQFIR ,/**< Intel FIR */ +SOF_PROCESS_EQIIR ,/**< Intel IIR */ +SOF_PROCESS_KEYWORD_DETECT ,/**< Keyword Detection */ +SOF_PROCESS_KPB ,/**< KeyPhrase Buffer Manager */ +SOF_PROCESS_CHAN_SELECTOR ,/**< Channel Selector */ +}; + +/* generic "effect", "codec" or proprietary processing component */ +struct sof_ipc_comp_process { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size;/**< size of bespoke data section in bytes */ +uint32_t type;/**< sof_ipc_process_type */ + +/* reserved for future use */ +uint32_t reserved[7 ]; + +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 +*/ + +/** \brief Types of pipeline scheduling time domains */ +enum sof_ipc_pipe_sched_time_domain { +SOF_TIME_DOMAIN_DMA =0 ,/**< DMA interrupt */ +SOF_TIME_DOMAIN_TIMER ,/**< Timer interrupt */ +}; + +/* 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 period;/**< execution period 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 */ +uint32_t time_domain;/**< scheduling time domain */ +} __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; + +/* external events */ +enum sof_event_types { +SOF_EVENT_NONE =0 , +SOF_KEYWORD_DETECT_DAPM_EVENT , +}; + +#endif
sound/soc/sof/topology.c new file +3164 -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.20.1
Part of the diff is not shown here. View the raw message.
PATCH v6 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 | 297 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/trace.c new file +297 -0
@@ -0,0 +1,297 @@ +// 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; +loff_t host_offset =READ_ONCE (sdev->host_offset); + +/* +* 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 (host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (host_offset > pos) +return 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 */ + host_offset =READ_ONCE (sdev->host_offset); +if (host_offset < pos) +return buffer_size - pos; + +return 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, ((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
Mark Brown
maintainerApplied "ASoC: SOF: Add DSP firmware logger support" to the asoc tree
The patch
ASoC: SOF: Add DSP firmware logger support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
fd51c47b352b7da0e78fc88b9e4da7f298bfdd70Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:12 -0500
Subject: [PATCH] ASoC: SOF: Add DSP firmware logger support
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 | 297 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/trace.c new file +297 -0
@@ -0,0 +1,297 @@ +// 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; +loff_t host_offset =READ_ONCE (sdev->host_offset); + +/* +* 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 (host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (host_offset > pos) +return 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 */ + host_offset =READ_ONCE (sdev->host_offset); +if (host_offset < pos) +return buffer_size - pos; + +return 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, ((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.20.1
PATCH v6 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 | 163 ++++++++++++++++++ sound/soc/sof/ops.h | 399 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 562 insertions(+) create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h
sound/soc/sof/ops.c new file +163 -0
@@ -0,0 +1,163 @@ +// 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); + +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); +} +EXPORT_SYMBOL (snd_sof_dsp_panic);
sound/soc/sof/ops.h new file +399 -0
399 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: SOF: Add DSP HW abstraction operations" to the asoc tree
The patch
ASoC: SOF: Add DSP HW abstraction operations
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
d1d95fcb63e3b83245ad06484b6905ab6c21afc3Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:13 -0500
Subject: [PATCH] ASoC: SOF: Add DSP HW abstraction operations
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 | 163 ++++++++++++++++++ sound/soc/sof/ops.h | 399 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 562 insertions(+) create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h
sound/soc/sof/ops.c new file +163 -0
@@ -0,0 +1,163 @@ +// 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); + +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); +} +EXPORT_SYMBOL (snd_sof_dsp_panic);
sound/soc/sof/ops.h new file +399 -0
399 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 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 | 400 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 400 insertions(+) create mode 100644 sound/soc/sof/loader.c
sound/soc/sof/loader.c new file +400 -0
@@ -0,0 +1,400 @@ +// 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 = + container_of(ext_hdr, 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 = 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 = 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++) { +/* check for wrap */ +if (remaining <sizeof (*block)) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* minus header size of block */ + remaining -=sizeof (*block); + +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, + block +1 , block->size); + +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* 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); +/* check for wrap */ +if (remaining > fw->size) { +dev_err (sdev->dev,"error: fw size smaller than header size\n" ); +return -EINVAL ; + } + +for (count =0 ; count < header->num_modules; count++) { +/* check for wrap */ +if (remaining <sizeof (*module)) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* minus header size of module */ + remaining -=sizeof (*module); + +/* module */ + ret =load_module (sdev, module); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid module %d\n" , count); +return ret; + } + +if (remaining < module->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* 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 =kasprintf (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); + } + +kfree (fw_filename); + +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
Mark Brown
maintainerApplied "ASoC: SOF: Add firmware loader support" to the asoc tree
The patch
ASoC: SOF: Add firmware loader support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
70cd52544b95d02f8b20fadccb7400ce68a2cb84Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:14 -0500
Subject: [PATCH] ASoC: SOF: Add firmware loader support
The firmware loader exports APIs that can be called by core to load and process multiple different file formats.
--- sound/soc/sof/loader.c | 400 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 400 insertions(+) create mode 100644 sound/soc/sof/loader.c
sound/soc/sof/loader.c new file +400 -0
@@ -0,0 +1,400 @@ +// 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 = + container_of(ext_hdr, 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 = 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 = 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++) { +/* check for wrap */ +if (remaining <sizeof (*block)) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* minus header size of block */ + remaining -=sizeof (*block); + +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, + block +1 , block->size); + +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* 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); +/* check for wrap */ +if (remaining > fw->size) { +dev_err (sdev->dev,"error: fw size smaller than header size\n" ); +return -EINVAL ; + } + +for (count =0 ; count < header->num_modules; count++) { +/* check for wrap */ +if (remaining <sizeof (*module)) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* minus header size of module */ + remaining -=sizeof (*module); + +/* module */ + ret =load_module (sdev, module); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid module %d\n" , count); +return ret; + } + +if (remaining < module->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +/* 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 =kasprintf (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); + } + +kfree (fw_filename); + +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.20.1
PATCH v6 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 | 107 +++++++++++++++++ include/uapi/sound/sof/tone.h | 21 ++++ include/uapi/sound/sof/trace.h | 66 +++++++++++ 8 files changed, 721 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 4 +#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 +107 -0
107 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 +66 -0
66 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
Mark Brown
maintainerApplied "ASoC: SOF: Add userspace ABI support" to the asoc tree
The patch
ASoC: SOF: Add userspace ABI support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
4483151e765b5a7ffb823fe9bb11128101410427Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:15 -0500
Subject: [PATCH] ASoC: SOF: Add userspace ABI support
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 | 107 +++++++++++++++++ include/uapi/sound/sof/tone.h | 21 ++++ include/uapi/sound/sof/trace.h | 66 +++++++++++ 8 files changed, 721 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 4 +#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 +107 -0
107 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 +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v6 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 | 385 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 sound/soc/sof/pm.c
sound/soc/sof/pm.c new file +385 -0
@@ -0,0 +1,385 @@ +// 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; +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 : +case SOF_CTRL_CMD_ENUM : +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_get_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd, + true); +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_get_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd, + true); +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; +struct snd_sof_route *sroute; +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; + +/* 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: +case snd_soc_dapm_dai_out: + 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 = swidget->private; + ret =sof_load_pipeline_ipc (sdev, pipeline, &r); +break ; +default : + 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_hw_params_upon_resume (struct snd_sof_dev *sdev) +{ +struct snd_pcm_substream *substream; +struct snd_sof_pcm *spcm; +snd_pcm_state_t state; +int dir; + +/* +* SOF requires hw_params to be set-up internally upon resume. +* So, set the flag to indicate this for those streams that +* have been suspended. +*/ +list_for_each_entry (spcm, &sdev->pcm_list, list) { +for (dir =0 ; dir <=SNDRV_PCM_STREAM_CAPTURE ; dir++) { + substream = spcm->stream[dir].substream; +if (!substream || !substream->runtime) +continue ; + + state = substream->runtime->status->state; +if (state ==SNDRV_PCM_STATE_SUSPENDED ) + spcm->hw_params_upon_resume[dir] =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; + +/* 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; + +/* 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_hw_params_upon_resume (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
Mark Brown
maintainerApplied "ASoC: SOF: Add PM support" to the asoc tree
The patch
ASoC: SOF: Add PM support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
8920153c6461da69e49014a35275dc80cbf6ba14Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:16 -0500
Subject: [PATCH] ASoC: SOF: Add PM support
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 | 385 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 sound/soc/sof/pm.c
sound/soc/sof/pm.c new file +385 -0
@@ -0,0 +1,385 @@ +// 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; +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 : +case SOF_CTRL_CMD_ENUM : +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_get_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd, + true); +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_get_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd, + true); +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; +struct snd_sof_route *sroute; +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; + +/* 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: +case snd_soc_dapm_dai_out: + 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 = swidget->private; + ret =sof_load_pipeline_ipc (sdev, pipeline, &r); +break ; +default : + 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_hw_params_upon_resume (struct snd_sof_dev *sdev) +{ +struct snd_pcm_substream *substream; +struct snd_sof_pcm *spcm; +snd_pcm_state_t state; +int dir; + +/* +* SOF requires hw_params to be set-up internally upon resume. +* So, set the flag to indicate this for those streams that +* have been suspended. +*/ +list_for_each_entry (spcm, &sdev->pcm_list, list) { +for (dir =0 ; dir <=SNDRV_PCM_STREAM_CAPTURE ; dir++) { + substream = spcm->stream[dir].substream; +if (!substream || !substream->runtime) +continue ; + + state = substream->runtime->status->state; +if (state ==SNDRV_PCM_STATE_SUSPENDED ) + spcm->hw_params_upon_resume[dir] =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; + +/* 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; + +/* 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_hw_params_upon_resume (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.20.1
PATCH v6 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
Mark Brown
maintainerApplied "ASoC: SOF: Add Nocodec machine driver support" to the asoc tree
The patch
ASoC: SOF: Add Nocodec machine driver support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
8017b8fd37bf5ed4e9c0596f83295b019ff1c287Mon Sep 17 00:00:00 2001
From: Liam Girdwood <[email protected]>
Date: Fri, 12 Apr 2019 11:05:17 -0500
Subject: [PATCH] ASoC: SOF: Add Nocodec machine driver support
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.20.1
PATCH v6 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
Mark Brown
maintainerApplied "ASoC: SOF: Add xtensa support" to the asoc tree
The patch
ASoC: SOF: Add xtensa support
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
e657c18a01c85d2c4ec0e96d52be8ba42b956593Mon Sep 17 00:00:00 2001
From: Pierre-Louis Bossart <[email protected]>
Date: Fri, 12 Apr 2019 11:05:18 -0500
Subject: [PATCH] ASoC: SOF: Add xtensa support
Add 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 · 1 line
2.20.1
PATCH v6 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 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
Mark Brown
maintainerApplied "ASoC: SOF: Add utils" to the asoc tree
The patch
ASoC: SOF: Add utils
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
3bafac46065eb7ea6f3e3fcbdb8b70b66f6c71b4Mon Sep 17 00:00:00 2001
From: Pierre-Louis Bossart <[email protected]>
Date: Fri, 12 Apr 2019 11:05:19 -0500
Subject: [PATCH] ASoC: SOF: Add utils
Helpers 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 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.20.1
Quoted 148 lines · Pierre-Louis Bossart
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.
Changes since v5:
In addition to addressing feedback from Takashi, the major change in this series is the IPC rework. We reverted some optimizations to help Daniel Baluta @ NXP submit support for i.MX platforms, additional IPC core refactorization will start once we have two platforms supported on github. Hopefully by then the code will be accepted in the ASoC tree and we can submit delta patches, hint hint wink wink.
All feedback from Takashi addressed:
Tabify/align Kconfigs
RemoveINFO_RESUMEflag
Add const char* for core prototypes
Fixsnd_sof_get_statusreturn value
Usesmd_pcm_format_physical_width()
Fixhw_constraintsand BUFFER_BYTES/SIZE confusion Remove useless fallthrough statements
Fix typos and duplicate words in comments and commit messages Remove unnecessary casts, usecontainer_of
Remove superfluous initializations
Fix potential race condition in debugfs
Check for wrap-arounds in loader
Fix alignment in debugfs read
Don't usedevm_kasprintffor firmware name string.Other updates:
Major refactor of IPC handling (support for large messages, code optimization, better abstraction to push Intel-specific code out of the core).
Regenerate compressed page table only if needed
Support for multiple DAIhw_config(from <[email protected]>) Use iopoll macros (with small change due to indirection) Fix PM refcount handling on errors
Rename/unify all definitions for effects (now 'process') Added basic support for keyword/hotword detection and binding widgets with external events
Fix release of topology resources
Support newIPC_PANICmessage
Clean-up mandatory/optional callbacks, simplify wrappers Add topology ABI check
Fix acpi/machine driver handling
Fix memory leak in debugfs error handling
Alignment with firmware header files
Fixed topology endianness issuesChanges since v4:
feedback from Mark:
Removed need for private field insoc_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 Usesnd_mask_set_format()
Trace code flow optimization
Removed checks onpreallocate_pages()
Test status of open/close functions.Released reference when
pm_runtime_get_syncfails
Fixed multiple memory allocation issues
Fixed static analysis warnings
Fixed error checks withcopy_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 ofsuspend_late, now usingsnd_soc_pm_opsand standard flow
Fixed topology free (multiple patches already contributed for ASoC-core)
Fixed debugfs/pm_runtime interaction
Removed error checks on debugfs, changed toEXPORT_SYMBOL_GPLAdded filenames in debug messages, ueshex_dump_to_bufferRemoved "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) Fixedrelease_firmwarehandling (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 withKbuildwarnings on exotic architecturesPrecisions:
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_pmis being hardened and the use ofSMART_SUSPENDwas suggested.
Quoted 5 lines
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.
Do we want to merge them for 5.2?
If so, feel free to take my ack, for the whole series:
thanks,
Takashi
Quoted 4 lines
Do we want to merge them for 5.2?
If so, feel free to take my ack, for the whole series:Reviewed-by Takashi Iwai <[email protected]>
Thanks Takashi! I think Mark is still going through the series, not sure if there are any other reviewers?