ASoC: Sound Open Firmware (SOF) core
Subsystems (3)
v4 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 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/soc.h | 3 + include/sound/sof.h | 100 + include/sound/sof/control.h | 125 ++ 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 | 149 ++ include/sound/sof/topology.h | 256 +++ include/sound/sof/trace.h | 66 + include/sound/sof/xtensa.h | 44 + include/uapi/sound/sof/abi.h | 62 + include/uapi/sound/sof/eq.h | 164 ++ 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 | 98 + include/uapi/sound/sof/tone.h | 21 + include/uapi/sound/sof/trace.h | 93 + sound/soc/sof/control.c | 361 ++++ sound/soc/sof/core.c | 473 +++++ sound/soc/sof/debug.c | 219 +++ sound/soc/sof/ipc.c | 842 +++++++++ sound/soc/sof/loader.c | 363 ++++ sound/soc/sof/nocodec.c | 109 ++ sound/soc/sof/ops.c | 204 +++ sound/soc/sof/ops.h | 414 +++++ sound/soc/sof/pcm.c | 710 ++++++++ sound/soc/sof/pm.c | 381 ++++ sound/soc/sof/sof-priv.h | 599 ++++++ sound/soc/sof/topology.c | 2808 +++++++++++++++++++++++++++++ sound/soc/sof/trace.c | 298 +++ sound/soc/sof/utils.c | 109 ++ sound/soc/sof/xtensa/Kconfig | 2 + sound/soc/sof/xtensa/Makefile | 5 + sound/soc/sof/xtensa/core.c | 138 ++ 37 files changed, 10086 insertions(+) create mode 100644 include/sound/sof.h create mode 100644 include/sound/sof/control.h create mode 100644 include/sound/sof/dai-intel.h create mode 100644 include/sound/sof/dai.h create mode 100644 include/sound/sof/header.h create mode 100644 include/sound/sof/info.h create mode 100644 include/sound/sof/pm.h create mode 100644 include/sound/sof/stream.h create mode 100644 include/sound/sof/topology.h create mode 100644 include/sound/sof/trace.h create mode 100644 include/sound/sof/xtensa.h create mode 100644 include/uapi/sound/sof/abi.h create mode 100644 include/uapi/sound/sof/eq.h create mode 100644 include/uapi/sound/sof/fw.h create mode 100644 include/uapi/sound/sof/header.h create mode 100644 include/uapi/sound/sof/manifest.h create mode 100644 include/uapi/sound/sof/tokens.h create mode 100644 include/uapi/sound/sof/tone.h create mode 100644 include/uapi/sound/sof/trace.h create mode 100644 sound/soc/sof/control.c create mode 100644 sound/soc/sof/core.c create mode 100644 sound/soc/sof/debug.c create mode 100644 sound/soc/sof/ipc.c create mode 100644 sound/soc/sof/loader.c create mode 100644 sound/soc/sof/nocodec.c create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h create mode 100644 sound/soc/sof/pcm.c create mode 100644 sound/soc/sof/pm.c create mode 100644 sound/soc/sof/sof-priv.h create mode 100644 sound/soc/sof/topology.c create mode 100644 sound/soc/sof/trace.c create mode 100644 sound/soc/sof/utils.c create mode 100644 sound/soc/sof/xtensa/Kconfig create mode 100644 sound/soc/sof/xtensa/Makefile create mode 100644 sound/soc/sof/xtensa/core.c
Signature · 1 line
2.17.1
PATCH v4 1/14 ASoC: SOF: Add Sound Open Firmware driver core
From: Liam Girdwood <[email protected]>
The Sound Open Firmware driver core is a generic architecture independent layer that allows SOF to be used on many different different architectures and platforms. It abstracts DSP operations and IO methods so that the target DSP can be an internal memory mapped or external SPI or I2C based device. This abstraction also allows SOF to be run on many different VMs on the same physical HW.
SOF also requires some data in ASoC PCM runtime data for looking up SOF data during ASoC PCM operations.
--- include/sound/soc.h | 3 + include/sound/sof.h | 94 ++++++ sound/soc/sof/core.c | 473 +++++++++++++++++++++++++++++++ sound/soc/sof/sof-priv.h | 599 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1169 insertions(+) create mode 100644 include/sound/sof.h create mode 100644 sound/soc/sof/core.c create mode 100644 sound/soc/sof/sof-priv.h
include/sound/soc.h +3 -0
@@ -1232,6 +1232,9 @@ struct snd_soc_pcm_runtime {/* bit field */ unsigned int dev_registered:1; unsigned int pop_wait:1; + +/* private data - core does not touch */ +void *private;/* FIXME: still SOF-specific, needs to less ambiguous */ };#define for_each_rtd_codec_dai (rtd, i, dai)\ for ((i) = 0; \
include/sound/sof.h new file +94 -0
94 lines not on this page · raw message
sound/soc/sof/core.c new file +473 -0
473 lines not on this page · raw message
sound/soc/sof/sof-priv.h new file +599 -0
599 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
include/sound/soc.h struct snd_soc_pcm_runtime { · line 1237
Quoted 12 lines · Pierre-Louis Bossart
include/sound/soc.h +3
-0@@ -1232,6 +1232,9 @@ struct snd_soc_pcm_runtime {/* bit field */ unsigned int dev_registered:1; unsigned int pop_wait:1; + +/* private data - core does not touch */ +void *private;/* FIXME: still SOF-specific, needs to less ambiguous */
Then better to name it sof_private?
Quoted 21 lines
include/sound/soc.h +21
-0+int snd_sof_create_page_table (struct snd_sof_dev *sdev, +struct snd_dma_buffer *dmab, +unsigned char *page_table,size_t size) +{ +int i, pages; + + pages =snd_sgbuf_aligned_pages (size); + +dev_dbg (sdev->dev,"generating page table for %p size 0x%zx pages %d\n" , + dmab->area, size, pages); + +for (i =0 ; i < pages; i++) { +/* +* The number of valid address bits for each page is 20. +* idx determines the byte position within page_table +* where the current page's address is stored +* in the compressed page_table. +* This can be calculated by multiplying the page number by 2.5. +*/ +u32 idx = (5 * i) >>1 ; +u32 pfn =snd_sgbuf_get_addr (dmab, i *PAGE_SIZE ) >>PAGE_SHIFT ;
include/sound/soc.h struct snd_soc_pcm_runtime {
Quoted 10 lines
include/sound/soc.h +10
-0+u32 *pg_table; + +dev_vdbg (sdev->dev,"pfn i %i idx %d pfn %x\n" , i, idx, pfn); + + pg_table = (u32 *)(page_table + idx); + +if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn;
I guess this is OK for now, but better to give some notes that it's x86-specific. To be more generic, we'd have to consider endianess and the unaligned access in the code above.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Thanks for the quick reviews Takashi!
Quoted 16 lines · Takashi Iwai
include/sound/soc.h struct snd_soc_pcm_runtime { · line 1237
Quoted 12 lines · Pierre-Louis Bossart
include/sound/soc.h +3
-0@@ -1232,6 +1232,9 @@ struct snd_soc_pcm_runtime {/* bit field */ unsigned int dev_registered:1; unsigned int pop_wait:1; + +/* private data - core does not touch */ +void *private;/* FIXME: still SOF-specific, needs to less ambiguous */ Then better to name it
sof_private?
Ah, this is a mistake in the FIXME comment.
initially we had a field called "sof" and Mark made the following comment:
"
Review struct snd_soc_pcm_runtime { · line 1138
Quoted 8 lines
+++
b/include/sound/soc.h(quoted diff) +1
-0@@ -1133,6 +1133,7 @@ struct snd_soc_pcm_runtime { /* runtime devices */ struct snd_pcm *pcm; struct snd_compr *compr; + struct snd_sof_pcm *sof; struct snd_soc_dai *codec_dai; struct snd_soc_dai *cpu_dai;
Can we rename this somehow to be less specific to SoF or move it to be somewhere other than the runtime structure? I can see why you've done this but I can also see every DSP vendor turning up and trying to add their own field in here.
"
so we added a FIXME to track this, then later we moved the field and renamed it 'private' so that it can be used by others if needed but didn't remove the FIXME. Will fix this.
Quoted 29 lines
(quoted diff) +0
-0> +int snd_sof_create_page_table(struct snd_sof_dev *sdev,Quoted 26 lines
include/sound/soc.h +26
-0+struct snd_dma_buffer *dmab, + unsigned char *page_table, size_t size) +{ + int i, pages; + + pages =snd_sgbuf_aligned_pages (size); + +dev_dbg (sdev->dev,"generating page table for %p size 0x%zx pages %d\n" , + dmab->area, size, pages); + +for (i =0 ; i < pages; i++) { +/* +* The number of valid address bits for each page is 20. +* idx determines the byte position within page_table +* where the current page's address is stored +* in the compressed page_table. +* This can be calculated by multiplying the page number by 2.5. +*/ +u32 idx = (5 * i) >>1 ; +u32 pfn =snd_sgbuf_get_addr (dmab, i *PAGE_SIZE ) >>PAGE_SHIFT ; +u32 *pg_table; + +dev_vdbg (sdev->dev,"pfn i %i idx %d pfn %x\n" , i, idx, pfn); + + pg_table = (u32 *)(page_table + idx); +
Quoted 8 lines
include/sound/soc.h
Quoted 4 lines
include/sound/soc.h +4
-0+if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn;I guess this is OK for now, but better to give some notes that it's x86-specific. To be more generic, we'd have to consider endianess and the unaligned access in the code above.
yes indeed, will check if we can make this more generic, and add notes in any case.
Mark Brown
maintainerRe: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 11 lines · Pierre-Louis Bossart
Quoted 7 lines · Takashi Iwai
include/sound/soc.h struct snd_soc_pcm_runtime { · line 1237
Quoted 2 lines · Pierre-Louis Bossart
include/sound/soc.h +2
-0+/* private data - core does not touch */ +void *private;/* FIXME: still SOF-specific, needs to less ambiguous */ Then better to name it
sof_private?Ah, this is a mistake in the FIXME comment.
initially we had a field called "sof" and Mark made the following comment:
...
Quoted 3 lines
so we added a FIXME to track this, then later we moved the field and renamed it 'private' so that it can be used by others if needed but didn't remove the FIXME. Will fix this.
That doesn't really address the issue - there's multiple drivers using any given runtime so none of them can safely use a generically named private data field. Conversely putting a field specific to a given driver into the core data structures opens the door to everyone wanting their custom stuff in the core which is also a problem for different reasons. This would be a lot easier with the DSP represented as a first class device in the system...
Re: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
include/sound/soc.h struct snd_soc_pcm_runtime { · line 1237
Quoted 3 lines
include/sound/soc.h +2
-0+/* private data - core does not touch */ +void *private;/* FIXME: still SOF-specific, needs to less ambiguous */ Then better to name it
sof_private?Ah, this is a mistake in the FIXME comment.
initially we had a field called "sof" and Mark made the following comment:...
Quoted 3 lines
so we added a FIXME to track this, then later we moved the field and renamed it 'private' so that it can be used by others if needed but didn't remove the FIXME. Will fix this.
Quoted 7 lines
That doesn't really address the issue - there's multiple drivers using any given runtime so none of them can safely use a generically named private data field. Conversely putting a field specific to a given driver into the core data structures opens the door to everyone wanting their custom stuff in the core which is also a problem for different reasons. This would be a lot easier with the DSP represented as a first class device in the system...
I see your point and agree the current direction isn't scalable, but I am not sure about the definition of 'first class device'.
Did you mean 'component' at the same level as the 'platforms' and 'codecs', with all the DSP stuff nicely packaged and maintained in a self-contained way?
Or a subcomponent that might be part of those platforms and codecs?
Mark Brown
maintainerRe: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 8 lines · Pierre-Louis Bossart
I see your point and agree the current direction isn't scalable, but I am not sure about the definition of 'first class device'.
Did you mean 'component' at the same level as the 'platforms' and 'codecs', with all the DSP stuff nicely packaged and maintained in a self-contained way?
Or a subcomponent that might be part of those platforms and codecs?
As far as I can see for the Intel systems it's looking like a first class component - there will be some systems where the DSP is embedded in something (like the big CODECs) but even there it's easier as it's contained within the device rather than affecting multiple devices which is the big issue here.
Re: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 8 lines · Mark Brown
Quoted 6 lines · Pierre-Louis Bossart
I see your point and agree the current direction isn't scalable, but I am not sure about the definition of 'first class device'.
Did you mean 'component' at the same level as the 'platforms' and 'codecs', with all the DSP stuff nicely packaged and maintained in a self-contained way?
Or a subcomponent that might be part of those platforms and codecs?
Quoted 5 lines
As far as I can see for the Intel systems it's looking like a first class component - there will be some systems where the DSP is embedded in something (like the big CODECs) but even there it's easier as it's contained within the device rather than affecting multiple devices which is the big issue here.
Sorry Mark, I am struggling with the 'first class' idea.
Allow me to go back to the practical issue we faced here, and maybe/hopefully this will help us converge on a consensus.
The only reason for extending the struct snd_soc_pcm_runtime was to enable the use of a 'context' in PCM operations, see e.g in patch 5/14 the repeated pattern to get an 'SOF PCM' context:
struct snd_sof_pcm *spcm = rtd->private;
Managing a context for PCM ops is typically done in other drivers by using the substream->private_data aka snd_pcm_substream_chip(substream).
In ASoC/DPCM, unfortunately this substream->private_data field was reclaimed to store a pointer to a 'struct snd_soc_pcm_runtime', see e.g. in soc-pcm.c:
pcm->private_data = rtd;
if (playback) pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream->private_data = rtd; if (capture) pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream->private_data = rtd;
So ironically in ASoC we don't have a means to use a private_data field for the substreams since it's used for a 'standard' mechanism.
The extension suggested in this patch 1/14 was really trying to come back to a practical means to store a context in a substream, and make the PCM operations manageable. I totally agree that extending the PCM runtime might not recommended or safe, but at this point I don't have any slack in the existing data structures to add a context in a substream.
Does this help clarify the problem statement?
Mark Brown
maintainerRe: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 5 lines · Pierre-Louis Bossart
The only reason for extending the struct
snd_soc_pcm_runtimewas to enable the use of a 'context' in PCM operations, see e.g in patch 5/14 the repeated pattern to get an 'SOF PCM' context:struct
snd_sof_pcm*spcm =rtd->private;
The reason you're having trouble with this is that the DSP isn't really properly visible in the system, it's pushed in on the side with DPCM coexisting with multiple other drivers so as far as I can see it's hard for it to fit in anywhere in Intel systems.
Quoted 2 lines
So ironically in ASoC we don't have a means to use a
private_datafield for the substreams since it's used for a 'standard' mechanism.
This is why there's things like snd_soc_dai_get_dma_data() and snd_soc_component_get_drvdata() - if you're a fully visible component in the system there's ways to get to your ASoC specific driver data. For something like SoF that'd mean cooperating with the drivers for the devices with the SoF using DSPs in some way.
Quoted 7 lines
The extension suggested in this patch 1/14 was really trying to come back to a practical means to store a context in a substream, and make the PCM operations manageable. I totally agree that extending the PCM runtime might not recommended or safe, but at this point I don't have any slack in the existing data structures to add a context in a substream.
Does this help clarify the problem statement?
It is fairly clear what driver data is useful for. The issue is that instead of getting to it through the relevant hardware component you're adding something directly in the core data structure, whatever way we look at it that's going to be awkward. Consider for example what happens if someone integrates a system with a SoF DSP in the SoC and another SoF DSP in the CODEC - there will be two separate copies of SoF on a single DAI so a SoF specific value directly in the runtime isn't going to work.
If there were a component for the DSP (or the DSP was fully part of some other existing component) then it should be possible to arrange to get to the DSP data using that but with it just floating there unattached to anything it's harder.
Re: [Sound-open-firmware] [PATCH v4 01/14] ASoC: SOF: Add Sound Open Firmware driver core
Quoted 34 lines · Mark Brown
Quoted 4 lines · Pierre-Louis Bossart
The only reason for extending the struct
snd_soc_pcm_runtimewas to enable the use of a 'context' in PCM operations, see e.g in patch 5/14 the repeated pattern to get an 'SOF PCM' context:
structsnd_sof_pcm*spcm =rtd->private;The reason you're having trouble with this is that the DSP isn't really properly visible in the system, it's pushed in on the side with DPCM coexisting with multiple other drivers so as far as I can see it's hard for it to fit in anywhere in Intel systems.
Quoted 2 lines
So ironically in ASoC we don't have a means to use a
private_datafield for the substreams since it's used for a 'standard' mechanism.This is why there's things like
snd_soc_dai_get_dma_data()andsnd_soc_component_get_drvdata()- if you're a fully visible component in the system there's ways to get to your ASoC specific driver data. For something like SoF that'd mean cooperating with the drivers for the devices with the SoF using DSPs in some way.Quoted 6 lines
The extension suggested in this patch 1/14 was really trying to come back to a practical means to store a context in a substream, and make the PCM operations manageable. I totally agree that extending the PCM runtime might not recommended or safe, but at this point I don't have any slack in the existing data structures to add a context in a substream.
Does this help clarify the problem statement?It is fairly clear what driver data is useful for. The issue is that instead of getting to it through the relevant hardware component you're adding something directly in the core data structure, whatever way we look at it that's going to be awkward. Consider for example what happens if someone integrates a system with a SoF DSP in the SoC and another SoF DSP in the CODEC - there will be two separate copies of SoF on a single DAI so a SoF specific value directly in the runtime isn't going to work.
Quoted 4 lines
If there were a component for the DSP (or the DSP was fully part of some other existing component) then it should be possible to arrange to get to the DSP data using that but with it just floating there unattached to anything it's harder.
After spending a bit more time on this, I agree it's possible to retrieve the required information without any change to the rtd structure. There are existing precedents using substream->runtime->private_data, e.g. to store an HDAudio stream tag, and SOF already has a list of contexts that can be searched for with a simple list walk.
Modeling the DSP differently is something I'll add to my growing-by-the-day TODO list.
PATCH v4 2/14 ASoC: SOF: Add Sound Open Firmware KControl support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
SOF exposes regular ALSA Kcontrols that are defined by topology. This patch converts the Kcontrol IO to DSP IPC.
The current implementation is aligned with previous Intel solutions, but is not optimal and can be improved:
a) for every get/put the host wakes up the DSP and generates an IPC. The kernel should cache the values and generate an IPC only when strictly necessary.
b) the firmware can be implemented to only instantiate the pipelines and related control-related parts that are needed at a given time, and power-gate the relevant SRAM blocks.
The development tasks for these two improvements has started, once validated they willl be provided in an update.
--- sound/soc/sof/control.c | 361 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 361 insertions(+) create mode 100644 sound/soc/sof/control.c
sound/soc/sof/control.c new file +361 -0
@@ -0,0 +1,361 @@ +// 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); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +/* read back each channel */ +for (i =0 ; i < channels; i++) + ucontrol->value.integer.value[i] = +ipc_to_mixer (cdata->chanv[i].value, + scontrol->volume_table, sm->max +1 ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: volume get failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_volume_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_mixer_control *sm = + (struct soc_mixer_control *)kcontrol->private_value; +struct snd_sof_control *scontrol = sm->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +unsigned int i, channels = scontrol->num_channels; +int ret, err; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev,"error: volume put failed to resume %d\n" , + ret); +return ret; + } + +/* update each channel */ +for (i =0 ; i < channels; i++) { + cdata->chanv[i].value = +mixer_to_ipc (ucontrol->value.integer.value[i], + scontrol->volume_table, sm->max +1 ); + cdata->chanv[i].channel = i; + } + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_VALUE , +SOF_CTRL_TYPE_VALUE_CHAN_GET , +SOF_CTRL_CMD_VOLUME ); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: volume put failed to idle %d\n" , + err); +return 0 ; +} + +int snd_sof_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); +return ret; + } + +/* get all the mixer data from DSP */ +snd_sof_ipc_get_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , scontrol->cmd); + size = data->size +sizeof (*data); +if (size > be->max) { +dev_err_ratelimited (sdev->dev,"error: DSP sent %zu bytes max is %d\n" , + size, be->max); + ret = -EINVAL ; + goto out; + } + +/* copy back to kcontrol */ +memcpy (ucontrol->value.bytes.data, data, size); + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: bytes get failed to idle %d\n" , + err); +return ret; +} + +int snd_sof_bytes_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct sof_abi_hdr *data = cdata->data; +int ret, err; + +if (be->max >sizeof (ucontrol->value.bytes.data)) { +dev_err_ratelimited (sdev->dev,"error: data max %d exceeds ucontrol data array size\n" , + be->max); +return -EINVAL ; + } + +if (data->size > be->max) { +dev_err_ratelimited (sdev->dev,"error: size too big %d bytes max is %d\n" , + data->size, be->max); +return -EINVAL ; + } + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev,"error: bytes put failed to resume %d\n" , + ret); +return ret; + } + +/* copy from kcontrol */ +memcpy (data, ucontrol->value.bytes.data, data->size); + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , scontrol->cmd); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: bytes put failed to idle %d\n" , + err); +return ret; +} + +int snd_sof_bytes_ext_put (struct snd_kcontrol *kcontrol, +const unsigned int __user *binary_data, +unsigned int size) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct snd_ctl_tlv header; +const struct snd_ctl_tlv __user *tlvd = + (const struct snd_ctl_tlv __user *)binary_data; +int ret; +int err; +int max_size =SOF_IPC_MSG_MAX_SIZE - +sizeof (const struct sof_ipc_ctrl_data ); + +/* +* The beginning of bytes data contains a header from where +* the length (as bytes) is needed to know the correct copy +* length of data from tlvd->tlv. +*/ +if (copy_from_user (&header, tlvd,sizeof (const struct snd_ctl_tlv ))) +return -EFAULT ; + +/* +* The maximum length that can be copied is limited by IPC max +* length and topology defined length for ext bytes control. +*/ +if (be->max < max_size)/* min() not used to avoid sparse warnings */ + max_size = be->max; +if (header.length > max_size) { +dev_err_ratelimited (sdev->dev,"error: Bytes data size %d exceeds max %d.\n" , + header.length, max_size); +return -EINVAL ; + } + +/* Check that header id matches the command */ +if (header.numid != scontrol->cmd) { +dev_err_ratelimited (sdev->dev,"error: incorrect numid %d\n" , + header.numid); +return -EINVAL ; + } + +if (copy_from_user (cdata->data, tlvd->tlv, header.length)) +return -EFAULT ; + +if (cdata->data->magic !=SOF_ABI_MAGIC ) { +dev_err_ratelimited (sdev->dev,"error: Wrong ABI magic 0x%08x.\n" , + cdata->data->magic); +return -EINVAL ; + } + +if (SOF_ABI_VERSION_INCOMPATIBLE (SOF_ABI_VERSION , cdata->data->abi)) { +dev_err_ratelimited (sdev->dev,"error: Incompatible ABI version 0x%08x.\n" , + cdata->data->abi); +return -EINVAL ; + } + +if (cdata->data->size +sizeof (const struct sof_abi_hdr ) > max_size) { +dev_err_ratelimited (sdev->dev,"error: Mismatch in ABI data size (truncated?).\n" ); +return -EINVAL ; + } + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev,"error: bytes_ext put failed to resume %d\n" , + ret); +return ret; + } + +/* notify DSP of mixer updates */ +snd_sof_ipc_set_comp_data (sdev->ipc, scontrol,SOF_IPC_COMP_SET_DATA , +SOF_CTRL_TYPE_DATA_SET , scontrol->cmd); + +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: bytes_ext put failed to idle %d\n" , + err); + +return ret; +} + +int snd_sof_bytes_ext_get (struct snd_kcontrol *kcontrol, +unsigned int __user *binary_data, +unsigned int size) +{ +struct soc_bytes_ext *be = + (struct soc_bytes_ext *)kcontrol->private_value; +struct snd_sof_control *scontrol = be->dobj.private; +struct snd_sof_dev *sdev = scontrol->sdev; +struct sof_ipc_ctrl_data *cdata = scontrol->control_data; +struct snd_ctl_tlv header; +struct snd_ctl_tlv __user *tlvd = + (struct snd_ctl_tlv __user *)binary_data; +int max_size =SOF_IPC_MSG_MAX_SIZE - +sizeof (const struct sof_ipc_ctrl_data ); +int data_size; +int err; +int ret; + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err_ratelimited (sdev->dev,"error: bytes_ext get failed to resume %d\n" , + ret); +return ret; + } + +/* +* Decrement the limit by ext bytes header size to +* ensure the user space buffer is not exceeded. +*/ + size -=sizeof (const struct snd_ctl_tlv ); + +/* set the ABI header values */ + cdata->data->magic =SOF_ABI_MAGIC ; + cdata->data->abi =SOF_ABI_VERSION ; + +/* get all the component data from DSP */ + ret =snd_sof_ipc_get_comp_data (sdev->ipc, scontrol, +SOF_IPC_COMP_GET_DATA , +SOF_CTRL_TYPE_DATA_GET , scontrol->cmd); + +/* Prevent read of other kernel data or possibly corrupt response */ + data_size = cdata->data->size +sizeof (const struct sof_abi_hdr ); + +/* check size. min3() is not used to avoid sparse warnings */ +if (size < max_size) + max_size = size; +if (be->max < max_size) + max_size = be->max; +if (data_size > max_size) { +dev_err_ratelimited (sdev->dev,"error: user data size %d exceeds max size %d.\n" , + data_size, max_size); + ret = -EINVAL ; + goto out; + } + + header.numid = scontrol->cmd; + header.length = data_size; +if (copy_to_user (tlvd, &header,sizeof (const struct snd_ctl_tlv ))) { + ret = -EFAULT ; + goto out; + } + +if (copy_to_user (tlvd->tlv, cdata->data, data_size)) +return -EFAULT ; + +out: +pm_runtime_mark_last_busy (sdev->dev); + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err_ratelimited (sdev->dev,"error: bytes_ext get failed to idle %d\n" , + err); +return ret; +}
Signature · 1 line
2.17.1
Re: [PATCH v4 02/14] ASoC: SOF: Add Sound Open Firmware KControl support
sound/soc/sof/control.c line 216
Quoted 13 lines · Pierre-Louis Bossart
sound/soc/sof/control.c new file +12
-0+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;
....
Do we keep supporting TLV-typed ext access in SOF?
This seems to be disliked nowadays (since it's a sort of abuse of TLV API), and we agreed for dropping / reducing it.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 02/14] ASoC: SOF: Add Sound Open Firmware KControl support
Quoted 17 lines · Takashi Iwai
Quoted 13 lines · Pierre-Louis Bossart
sound/soc/sof/control.c new file +12
-0+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;....
Quoted 3 lines
Do we keep supporting TLV-typed ext access in SOF?
This seems to be disliked nowadays (since it's a sort of abuse of TLV API), and we agreed for dropping / reducing it.
I started working on a replacement of the TLV w/ the hw-dep and showed it could be introduced fairly easily in the topology with minor changes to the kernel interfaces.
https://github.com/plbossart/sound/commits/proto/hwdep
https://github.com/plbossart/alsa-lib/tree/proto/hwdep
However the big open is linking this hw-dep element in DAPM, so that it's handled in the same way as existing controls - specifically that the state is restored on resume. That part looked really invasive and complicated. I was even tempted to consider flipping the approach and define a new control that would expose a hw-dep interface to reuse a lot of the DAPM integration.
In short, we know the TLV is not the path forward, and as soon as we have a replacement we'll switch. For now we have no alternative.
Re: [Sound-open-firmware] [PATCH v4 02/14] ASoC: SOF: Add Sound Open Firmware KControl support
Quoted 37 lines · Pierre-Louis Bossart
Quoted 17 lines · Takashi Iwai
Quoted 13 lines · Pierre-Louis Bossart
sound/soc/sof/control.c new file +12
-0+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;....
Quoted 3 lines
Do we keep supporting TLV-typed ext access in SOF?
This seems to be disliked nowadays (since it's a sort of abuse of TLV API), and we agreed for dropping / reducing it.I started working on a replacement of the TLV w/ the hw-dep and showed it could be introduced fairly easily in the topology with minor changes to the kernel interfaces.
https://github.com/plbossart/sound/commits/proto/hwdep
https://github.com/plbossart/alsa-lib/tree/proto/hwdepHowever the big open is linking this hw-dep element in DAPM, so that it's handled in the same way as existing controls - specifically that the state is restored on resume. That part looked really invasive and complicated. I was even tempted to consider flipping the approach and define a new control that would expose a hw-dep interface to reuse a lot of the DAPM integration.
Quoted 2 lines
In short, we know the TLV is not the path forward, and as soon as we have a replacement we'll switch. For now we have no alternative.
OK, then let's add some comments that this interface is subject to change / drop in future.
thanks,
Takashi
PATCH v4 3/14 ASoC: SOF: Add driver debug support.
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add debugFS files that can be used to expose DSP memories and and peripherals to userspace to assist with firmware debugging.
Since we cannot rely on debugFS, errors are logged but don't stop execution.
When a resource cannot be read in D3, it is optionally cached on suspend. Copying memories from IO will increase the suspend latency, this should only used in engineering builds w/ debug options. This part will have to be enhanced when support for D0ix states is provided, currently only D0 and D3 are supported.
--- sound/soc/sof/debug.c | 219 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 sound/soc/sof/debug.c
sound/soc/sof/debug.c new file +219 -0
@@ -0,0 +1,219 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// Generic debug routines used to export DSP MMIO and memories to userspace +// for firmware debugging. +// + +#include <linux/debugfs.h> +#include <linux/io.h> +#include <linux/pm_runtime.h> +#include "sof-priv.h" +#include "ops.h" + +static ssize_t sof_dfsentry_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +struct dentry *dfsentry = dfse->dfsentry; +int size; +u32 *buf; +loff_t pos = *ppos; +size_t size_ret; + + size = dfse->size; + +/* validate position & count */ +if (pos <0 ) +return -EINVAL ; +if (pos >= size || !count) +return 0 ; +/* find the minimum. min() is not used since it adds sparse warnings */ +if (count > size - pos) + count = size - pos; + +/* intermediate buffer size must be u32 multiple */ + size =round_up (count,4 ); + buf =kzalloc (size,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +if (dfse->type ==SOF_DFSENTRY_TYPE_IOMEM ) { +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +/* +* If the DSP is active: copy from IO. +* If the DSP is suspended: +* - Copy from IO if the memory is always accessible. +* - Otherwise, copy from cached buffer. +*/ +if (pm_runtime_active (sdev->dev) || + dfse->access_type ==SOF_DEBUGFS_ACCESS_ALWAYS ) { +memcpy_fromio (buf, dfse->io_mem + pos, size); + }else { +dev_info (sdev->dev, +"Copying cached debugfs data\n" ); +memcpy (buf, dfse->cache_buf + pos, size); + } +#else +/* if the DSP is in D3 */ +if (!pm_runtime_active (sdev->dev) && + dfse->access_type ==SOF_DEBUGFS_ACCESS_D0_ONLY ) { +dev_err (sdev->dev, +"error: debugfs entry %s cannot be read in DSP D3\n" , + dfsentry->d_name.name); +return -EINVAL ; + } + +memcpy_fromio (buf, dfse->io_mem + pos, size); +#endif + }else { +memcpy (buf, dfse->buf + pos, size); + } + +/* copy to userspace */ + size_ret =copy_to_user (buffer, buf, count); +kfree (buf); + +/* update count & position if copy succeeded */ +if (size_ret == count) +return -EFAULT ; + count -= size_ret; + *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
PATCH v4 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 | 125 +++++ 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 | 149 ++++++ include/sound/sof/trace.h | 66 +++ sound/soc/sof/ipc.c | 842 ++++++++++++++++++++++++++++++++++ 9 files changed, 1759 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 +125 -0
@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_SOUND_SOF_CONTROL_H__ +#define __INCLUDE_SOUND_SOF_CONTROL_H__ + +#include <uapi/sound/sof/header.h> +#include <sound/sof/header.h> + +/* +* Component Mixers and Controls +*/ + +/* channel positions - uses same values as ALSA */ +enum sof_ipc_chmap { +SOF_CHMAP_UNKNOWN =0 , +SOF_CHMAP_NA ,/**< N/A, silent */ +SOF_CHMAP_MONO ,/**< mono stream */ +SOF_CHMAP_FL ,/**< front left */ +SOF_CHMAP_FR ,/**< front right */ +SOF_CHMAP_RL ,/**< rear left */ +SOF_CHMAP_RR ,/**< rear right */ +SOF_CHMAP_FC ,/**< front centre */ +SOF_CHMAP_LFE ,/**< LFE */ +SOF_CHMAP_SL ,/**< side left */ +SOF_CHMAP_SR ,/**< side right */ +SOF_CHMAP_RC ,/**< rear centre */ +SOF_CHMAP_FLC ,/**< front left centre */ +SOF_CHMAP_FRC ,/**< front right centre */ +SOF_CHMAP_RLC ,/**< rear left centre */ +SOF_CHMAP_RRC ,/**< rear right centre */ +SOF_CHMAP_FLW ,/**< front left wide */ +SOF_CHMAP_FRW ,/**< front right wide */ +SOF_CHMAP_FLH ,/**< front left high */ +SOF_CHMAP_FCH ,/**< front centre high */ +SOF_CHMAP_FRH ,/**< front right high */ +SOF_CHMAP_TC ,/**< top centre */ +SOF_CHMAP_TFL ,/**< top front left */ +SOF_CHMAP_TFR ,/**< top front right */ +SOF_CHMAP_TFC ,/**< top front centre */ +SOF_CHMAP_TRL ,/**< top rear left */ +SOF_CHMAP_TRR ,/**< top rear right */ +SOF_CHMAP_TRC ,/**< top rear centre */ +SOF_CHMAP_TFLC ,/**< top front left centre */ +SOF_CHMAP_TFRC ,/**< top front right centre */ +SOF_CHMAP_TSL ,/**< top side left */ +SOF_CHMAP_TSR ,/**< top side right */ +SOF_CHMAP_LLFE ,/**< left LFE */ +SOF_CHMAP_RLFE ,/**< right LFE */ +SOF_CHMAP_BC ,/**< bottom centre */ +SOF_CHMAP_BLC ,/**< bottom left centre */ +SOF_CHMAP_BRC ,/**< bottom right centre */ +SOF_CHMAP_LAST =SOF_CHMAP_BRC , +}; + +/* control data type and direction */ +enum sof_ipc_ctrl_type { +/* per channel data - uses struct sof_ipc_ctrl_value_chan */ +SOF_CTRL_TYPE_VALUE_CHAN_GET =0 , +SOF_CTRL_TYPE_VALUE_CHAN_SET , +/* component data - uses struct sof_ipc_ctrl_value_comp */ +SOF_CTRL_TYPE_VALUE_COMP_GET , +SOF_CTRL_TYPE_VALUE_COMP_SET , +/* bespoke data - struct struct sof_abi_hdr */ +SOF_CTRL_TYPE_DATA_GET , +SOF_CTRL_TYPE_DATA_SET , +}; + +/* control command type */ +enum sof_ipc_ctrl_cmd { +SOF_CTRL_CMD_VOLUME =0 ,/**< maps to ALSA volume style controls */ +SOF_CTRL_CMD_ENUM ,/**< maps to ALSA enum style controls */ +SOF_CTRL_CMD_SWITCH ,/**< maps to ALSA switch style controls */ +SOF_CTRL_CMD_BINARY ,/**< maps to ALSA binary style controls */ +}; + +/* generic channel mapped value data */ +struct sof_ipc_ctrl_value_chan { +uint32_t channel;/**< channel map - enum sof_ipc_chmap */ +uint32_t value; +} __packed; + +/* generic component mapped value data */ +struct sof_ipc_ctrl_value_comp { +uint32_t index;/**< component source/sink/control index in control */ +union { +uint32_t uvalue; +int32_t svalue; + }; +} __packed; + +/* generic control data */ +struct sof_ipc_ctrl_data { +struct sof_ipc_reply rhdr; +uint32_t comp_id; + +/* control access and data type */ +uint32_t type;/**< enum sof_ipc_ctrl_type */ +uint32_t cmd;/**< enum sof_ipc_ctrl_cmd */ +uint32_t index;/**< control index for comps > 1 control */ + +/* control data - can either be appended or DMAed from host */ +struct sof_ipc_host_buffer buffer; +uint32_t num_elems;/**< in array elems or bytes for data type */ + +/* reserved for future use */ +uint32_t reserved[8 ]; + +/* 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; + +#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 +149 -0
149 lines not on this page · raw message
include/sound/sof/trace.h new file +66 -0
66 lines not on this page · raw message
sound/soc/sof/ipc.c new file +842 -0
842 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 04/14] ASoC: SOF: Add support for IPC IO between DSP and Host
Quoted 20 lines · Pierre-Louis Bossart
sound/soc/sof/ipc.c new file +20
-0+/* wait for IPC message reply */ +static int tx_wait_done (struct snd_sof_ipc *ipc,struct snd_sof_ipc_msg *msg, +void *reply_data) +{ +struct snd_sof_dev *sdev = ipc->sdev; +struct sof_ipc_cmd_hdr *hdr = (struct sof_ipc_cmd_hdr *)msg->msg_data; +int ret; + +/* wait for DSP IPC completion */ + ret =wait_event_timeout (msg->waitq, msg->ipc_complete, +msecs_to_jiffies (IPC_TIMEOUT_MS )); + +/* +* ipc_lock is used to protect ipc message list shared by user +* contexts and a workqueue. There is no need to save interrupt +* status with spin_lock_irqsave. +*/ +spin_lock_irq (&sdev->ipc_lock); + +if (ret ==0 ) {
sound/soc/sof/ipc.c line 223
Quoted 10 lines
sound/soc/sof/ipc.c new file +10
-0+dev_err (sdev->dev,"error: ipc timed out for 0x%x size 0x%x\n" , + hdr->cmd, hdr->size); +snd_sof_dsp_dbg_dump (ipc->sdev,SOF_DBG_REGS |SOF_DBG_MBOX ); +snd_sof_trace_notify_for_error (ipc->sdev); + ret = -ETIMEDOUT ; + }else { +/* copy the data returned from DSP */ + ret =snd_sof_dsp_get_reply (sdev, msg); +if (msg->reply_size) +memcpy (reply_data, msg->reply_data, msg->reply_size);
I'd add a sanity check here for avoiding a buffer overflow. The reply buffer seems to be allocated in PAGE_SIZE. Will it be more than that?
sound/soc/sof/ipc.c line 338
Quoted 13 lines
sound/soc/sof/ipc.c new file +13
-0+/* find original TX message from DSP reply */ +static struct snd_sof_ipc_msg *sof_ipc_reply_find_msg (struct snd_sof_ipc *ipc, +u32 header) +{ +struct snd_sof_dev *sdev = ipc->sdev; +struct snd_sof_ipc_msg *msg; + + header =SOF_IPC_MESSAGE_ID (header); + +list_for_each_entry (msg, &ipc->reply_list, list) { +if (SOF_IPC_MESSAGE_ID (msg->header) == header) +return msg; + }
Is it safe to traverse the list without lock here? There seems no lock in this and relevant code.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 04/14] ASoC: SOF: Add support for IPC IO between DSP and Host
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Pierre-Louis Bossart
sound/soc/sof/ipc.c new file +26
-0+/* wait for IPC message reply */ +static int tx_wait_done (struct snd_sof_ipc *ipc,struct snd_sof_ipc_msg *msg, +void *reply_data) +{ +struct snd_sof_dev *sdev = ipc->sdev; +struct sof_ipc_cmd_hdr *hdr = (struct sof_ipc_cmd_hdr *)msg->msg_data; +int ret; + +/* wait for DSP IPC completion */ + ret =wait_event_timeout (msg->waitq, msg->ipc_complete, +msecs_to_jiffies (IPC_TIMEOUT_MS )); + +/* +* ipc_lock is used to protect ipc message list shared by user +* contexts and a workqueue. There is no need to save interrupt +* status with spin_lock_irqsave. +*/ +spin_lock_irq (&sdev->ipc_lock); + +if (ret ==0 ) { +dev_err (sdev->dev,"error: ipc timed out for 0x%x size 0x%x\n" , + hdr->cmd, hdr->size); +snd_sof_dsp_dbg_dump (ipc->sdev,SOF_DBG_REGS |SOF_DBG_MBOX ); +snd_sof_trace_notify_for_error (ipc->sdev); + ret = -ETIMEDOUT ; + }else {
Quoted 8 lines
sound/soc/sof/ipc.c line 223
Quoted 4 lines
sound/soc/sof/ipc.c new file +4
-0+/* copy the data returned from DSP */ + ret =snd_sof_dsp_get_reply (sdev, msg); +if (msg->reply_size) +memcpy (reply_data, msg->reply_data, msg->reply_size);I'd add a sanity check here for avoiding a buffer overflow. The reply buffer seems to be allocated in
PAGE_SIZE. Will it be more than that?
Good point, we'll check all the info returned by the DSP and see if they need to be range-checked or size-checked.
Quoted 18 lines
Quoted 5 lines
sound/soc/sof/ipc.c new file +3
-0+/* find original TX message from DSP reply */ +static struct snd_sof_ipc_msg *sof_ipc_reply_find_msg (struct snd_sof_ipc *ipc, +u32 header)sound/soc/sof/ipc.c line 338
Quoted 10 lines
sound/soc/sof/ipc.c new file +10
-0+{ +struct snd_sof_dev *sdev = ipc->sdev; +struct snd_sof_ipc_msg *msg; + + header =SOF_IPC_MESSAGE_ID (header); + +list_for_each_entry (msg, &ipc->reply_list, list) { +if (SOF_IPC_MESSAGE_ID (msg->header) == header) +return msg; + }Is it safe to traverse the list without lock here? There seems no lock in this and relevant code.
will double-check and add a note. We tried to state when a lock is needed and when it's not but this one was missed.
Mark Brown
maintainerRe: [Sound-open-firmware] [PATCH v4 04/14] ASoC: SOF: Add support for IPC IO between DSP and Host
Quoted 11 lines · Pierre-Louis Bossart
Quoted 9 lines · Takashi Iwai
sound/soc/sof/ipc.c line 223
Quoted 3 lines · Pierre-Louis Bossart
sound/soc/sof/ipc.c new file +3
-0+ ret =snd_sof_dsp_get_reply (sdev, msg); +if (msg->reply_size) +memcpy (reply_data, msg->reply_data, msg->reply_size);I'd add a sanity check here for avoiding a buffer overflow. The reply buffer seems to be allocated in
PAGE_SIZE. Will it be more than that?
Quoted 2 lines
Good point, we'll check all the info returned by the DSP and see if they need to be range-checked or size-checked.
I think it's better to just do the range checks even if they're not needed right now, it's safer in case someone adds bigger messages or there's some bug that corrupts the size.
PATCH v4 5/14 ASoC: SOF: Add PCM operations support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add support for exposing PCMs to userspace. PCMs are defined by topology and the operations in this patch map to SOF IPC calls.
The .ignore_module_refcount field is set to allow for module load/unload tests. There is no risk of the sof-pci/acpi-dev module being removed while the platform components are in use. This may need to be revisited when DT platforms are supported.
--- sound/soc/sof/pcm.c | 710 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 710 insertions(+) create mode 100644 sound/soc/sof/pcm.c
sound/soc/sof/pcm.c new file +710 -0
@@ -0,0 +1,710 @@ +// 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 = rtd->private; +struct snd_dma_buffer *dmab =snd_pcm_get_dma_buf (substream); +int stream = substream->stream; + +return snd_sof_create_page_table (sdev, dmab, + spcm->stream[stream].page_table.area, size); +} + +/* this may get called several times by oss emulation */ +static int sof_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct sof_ipc_pcm_params pcm; +struct sof_ipc_pcm_params_reply ipc_params_reply; +int posn_offset; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: hw params stream %d dir %d\n" , + spcm->pcm.pcm_id, substream->stream); + +memset (&pcm,0 ,sizeof (pcm)); + +/* allocate audio buffer pages */ + ret =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (params)); +if (ret <0 ) { +dev_err (sdev->dev,"error: could not allocate %d bytes for PCM %d\n" , +params_buffer_bytes (params), spcm->pcm.pcm_id); +return ret; + } + +/* create compressed page table for audio firmware */ + ret =create_page_table (substream, runtime->dma_area, + runtime->dma_bytes); +if (ret <0 ) +return ret; + +/* number of pages should be rounded up */ + pcm.params.buffer.pages =DIV_ROUND_UP (runtime->dma_bytes,PAGE_SIZE ); + +/* set IPC PCM parameters */ + pcm.hdr.size =sizeof (pcm); + pcm.hdr.cmd =SOF_IPC_GLB_STREAM_MSG |SOF_IPC_STREAM_PCM_PARAMS ; + pcm.comp_id = spcm->stream[substream->stream].comp_id; + pcm.params.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.buffer.offset =0 ; + pcm.params.direction = substream->stream; + pcm.params.sample_valid_bytes =params_width (params) >>3 ; + pcm.params.buffer_fmt =SOF_IPC_BUFFER_INTERLEAVED ; + pcm.params.rate =params_rate (params); + pcm.params.channels =params_channels (params); + pcm.params.host_period_bytes =params_period_bytes (params); + +/* container size */ +switch (params_width (params)) { +case 16 : + pcm.params.sample_container_bytes =2 ; +break ; +case 24 : + pcm.params.sample_container_bytes =4 ; +break ; +case 32 : + pcm.params.sample_container_bytes =4 ; +break ; +default : +return -EINVAL ; + } + +/* format */ +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S16_LE ; +break ; +case SNDRV_PCM_FORMAT_S24 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S24_4LE ; +break ; +case SNDRV_PCM_FORMAT_S32 : + pcm.params.frame_fmt =SOF_IPC_FRAME_S32_LE ; +break ; +case SNDRV_PCM_FORMAT_FLOAT : + pcm.params.frame_fmt =SOF_IPC_FRAME_FLOAT ; +break ; +default : +return -EINVAL ; + } + +/* firmware already configured host stream */ + ret =snd_sof_pcm_platform_hw_params (sdev, + substream, + params, + &pcm.params); +if (ret <0 ) { +dev_err (sdev->dev,"error: platform hw params failed\n" ); +return ret; + } + +dev_dbg (sdev->dev,"stream_tag %d" , pcm.params.stream_tag); + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, pcm.hdr.cmd, &pcm,sizeof (pcm), + &ipc_params_reply,sizeof (ipc_params_reply)); +if (ret <0 ) { +dev_err (sdev->dev,"error: hw params ipc failed for stream %d\n" , + pcm.params.stream_tag); +return ret; + } + +/* validate offset */ + posn_offset = ipc_params_reply.posn_offset; + +/* check if offset is overflow or it is not aligned */ +if (posn_offset > sdev->stream_box.size || + posn_offset %sizeof (struct sof_ipc_stream_posn ) !=0 ) { +dev_err (sdev->dev,"error: got wrong posn offset 0x%x for PCM %d\n" , + posn_offset, spcm->pcm.pcm_id); +return -EINVAL ; + } + spcm->posn_offset[substream->stream] = + sdev->stream_box.offset + posn_offset; + +/* save pcm hw_params */ +memcpy (&spcm->params[substream->stream], params,sizeof (*params)); + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +return ret; +} + +static int sof_pcm_hw_free (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: free stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + + stream.hdr.size =sizeof (stream); + stream.hdr.cmd =SOF_IPC_GLB_STREAM_MSG |SOF_IPC_STREAM_PCM_FREE ; + stream.comp_id = spcm->stream[substream->stream].comp_id; + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +snd_pcm_lib_free_pages (substream); +return ret; +} + +static int sof_restore_hw_params (struct snd_pcm_substream *substream, +struct snd_sof_pcm *spcm, +struct snd_sof_dev *sdev) +{ +snd_pcm_uframes_t host =0 ; +u64 host_posn; +int ret =0 ; + +/* resume stream */ + host_posn = spcm->stream[substream->stream].posn.host_posn; + host =bytes_to_frames (substream->runtime, host_posn); +dev_dbg (sdev->dev, +"PCM: resume stream %d dir %d DMA position %lu\n" , + spcm->pcm.pcm_id, substream->stream, host); + +/* set hw_params */ + ret =sof_pcm_hw_params (substream, + &spcm->params[substream->stream]); +if (ret <0 ) { +dev_err (sdev->dev, +"error: set pcm hw_params after resume\n" ); +return ret; + } + +return 0 ; +} + +/* +* 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 = rtd->private; +struct sof_ipc_stream stream; +struct sof_ipc_reply reply; +int ret =0 ; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: trigger stream %d dir %d cmd %d\n" , + spcm->pcm.pcm_id, substream->stream, cmd); + + stream.hdr.size =sizeof (stream); + stream.hdr.cmd =SOF_IPC_GLB_STREAM_MSG ; + stream.comp_id = spcm->stream[substream->stream].comp_id; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_PAUSE ; +break ; +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* trigger start */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + }else { + +/* trigger pause release */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_RELEASE ; + } +break ; +case SNDRV_PCM_TRIGGER_START : +/* fall through */ +case SNDRV_PCM_TRIGGER_RESUME : + +/* check if the stream hw_params needs to be restored */ +if (spcm->restore_stream[substream->stream]) { + +/* restore hw_params */ + ret =sof_restore_hw_params (substream, spcm, sdev); +if (ret <0 ) +return ret; + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + } + +/* trigger stream */ + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_START ; + +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +/* fallthrough */ +case SNDRV_PCM_TRIGGER_STOP : + +/* Check if stream was marked for restore before suspend */ +if (spcm->restore_stream[substream->stream]) { + +/* unset restore_stream */ + spcm->restore_stream[substream->stream] =0 ; + +/* do not send ipc as the stream hasn't been set up */ +return 0 ; + } + + stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_STOP ; +break ; +default : +dev_err (sdev->dev,"error: unhandled trigger cmd %d\n" , cmd); +return -EINVAL ; + } + +snd_sof_pcm_platform_trigger (sdev, substream, cmd); + +/* send IPC to the DSP */ + ret =sof_ipc_tx_message (sdev->ipc, stream.hdr.cmd, &stream, +sizeof (stream), &reply,sizeof (reply)); + +return ret; +} + +static snd_pcm_uframes_t sof_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +snd_pcm_uframes_t host =0 , dai =0 ; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +/* if have dsp ops pointer callback, use that directly */ +if (sof_ops (sdev)->pcm_pointer) +return sof_ops (sdev)->pcm_pointer (sdev, substream); + +/* read position from DSP */ + host =bytes_to_frames (substream->runtime, + spcm->stream[substream->stream].posn.host_posn); + dai =bytes_to_frames (substream->runtime, + spcm->stream[substream->stream].posn.dai_posn); + +dev_dbg (sdev->dev,"PCM: stream %d dir %d DMA position %lu DAI position %lu\n" , + spcm->pcm.pcm_id, substream->stream, host, dai); + +return host; +} + +static int sof_pcm_open (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +struct snd_soc_tplg_stream_caps *caps = + &spcm->pcm.caps[substream->stream]; +int ret; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +mutex_lock (&spcm->mutex); + + ret =pm_runtime_get_sync (sdev->dev); +if (ret <0 ) { +dev_err (sdev->dev,"error: pcm open failed to resume %d\n" , + ret); +mutex_unlock (&spcm->mutex); +return ret; + } + +/* set any runtime constraints based on topology */ +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_BUFFER_SIZE , +le32_to_cpu (caps->period_size_min)); +snd_pcm_hw_constraint_step (substream->runtime,0 , +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +le32_to_cpu (caps->period_size_min)); + +/* set runtime config */ + runtime->hw.info =SNDRV_PCM_INFO_MMAP | +SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_INTERLEAVED | +SNDRV_PCM_INFO_PAUSE | +SNDRV_PCM_INFO_RESUME | +SNDRV_PCM_INFO_NO_PERIOD_WAKEUP ; + runtime->hw.formats =le64_to_cpu (caps->formats); + runtime->hw.period_bytes_min =le32_to_cpu (caps->period_size_min); + runtime->hw.period_bytes_max =le32_to_cpu (caps->period_size_max); + runtime->hw.periods_min =le32_to_cpu (caps->periods_min); + runtime->hw.periods_max =le32_to_cpu (caps->periods_max); + runtime->hw.buffer_bytes_max =le32_to_cpu (caps->buffer_size_max); + +dev_dbg (sdev->dev,"period min %zd max %zd bytes\n" , + runtime->hw.period_bytes_min, + runtime->hw.period_bytes_max); +dev_dbg (sdev->dev,"period count %d max %d\n" , + runtime->hw.periods_min, + runtime->hw.periods_max); +dev_dbg (sdev->dev,"buffer max %zd bytes\n" , + runtime->hw.buffer_bytes_max); + +/* set wait time - TODO: come from topology */ + substream->wait_time =500 ; + + spcm->stream[substream->stream].posn.host_posn =0 ; + spcm->stream[substream->stream].posn.dai_posn =0 ; + spcm->stream[substream->stream].substream = substream; + +snd_sof_pcm_platform_open (sdev, substream); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static int sof_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private; +int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: close stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +snd_sof_pcm_platform_close (sdev, substream); + +mutex_lock (&spcm->mutex); +pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static struct snd_pcm_ops sof_pcm_ops = { + .open = sof_pcm_open, + .close = sof_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sof_pcm_hw_params, + .hw_free = sof_pcm_hw_free, + .trigger = sof_pcm_trigger, + .pointer = sof_pcm_pointer, + .page = snd_pcm_sgbuf_ops_page, +}; + +/* +* Pre-allocate playback/capture audio buffer pages. +* no need to explicitly release memory preallocated by sof_pcm_new in pcm_free +* snd_pcm_lib_preallocate_free_for_all() is called by the core. +*/ +static int sof_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct snd_pcm *pcm = rtd->pcm; +struct snd_soc_tplg_stream_caps *caps; +int ret =0 , stream =SNDRV_PCM_STREAM_PLAYBACK ; + +/* find SOF PCM for this RTD */ + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) { +dev_warn (sdev->dev,"warn: can't find PCM with DAI ID %d\n" , + rtd->dai_link->id); +return 0 ; + } + rtd->private = spcm; + +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); + + ret =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)); +if (ret) { +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); +return ret; + } + +capture: + stream =SNDRV_PCM_STREAM_CAPTURE ; + +/* do we need to pre-allocate capture audio buffer pages */ +if (!spcm->pcm.capture) +return ret; + + caps = &spcm->pcm.caps[stream]; + +/* pre-allocate capture audio buffer pages */ +dev_dbg (sdev->dev,"spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n" , + caps->name, caps->buffer_size_min, caps->buffer_size_max); + + ret =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)); +if (ret) +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); + +return ret; +} + +/* 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 (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); + +return 0 ; + } + +/* read format from topology */ +snd_mask_none (fmt); + +switch (dai->comp_dai.config.frame_fmt) { +case SOF_IPC_FRAME_S16_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); +break ; +case SOF_IPC_FRAME_S24_4LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S24_LE ); +break ; +case SOF_IPC_FRAME_S32_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S32_LE ); +break ; +default : +dev_err (sdev->dev,"error: No available DAI format!\n" ); +return -EINVAL ; + } + +/* read rate and channels from topology */ +switch (dai->dai_config->type) { +case SOF_DAI_INTEL_SSP : + rate->min = dai->dai_config->ssp.fsync_rate; + rate->max = dai->dai_config->ssp.fsync_rate; + channels->min = dai->dai_config->ssp.tdm_slots; + channels->max = dai->dai_config->ssp.tdm_slots; + +dev_dbg (sdev->dev, +"rate_min: %d rate_max: %d\n" , rate->min, rate->max); +dev_dbg (sdev->dev, +"channels_min: %d channels_max: %d\n" , + channels->min, channels->max); + +break ; +case SOF_DAI_INTEL_DMIC : +/* DMIC only supports 16 or 32 bit formats */ +if (dai->comp_dai.config.frame_fmt ==SOF_IPC_FRAME_S24_4LE ) { +dev_err (sdev->dev, +"error: invalid fmt %d for DAI type %d\n" , + dai->comp_dai.config.frame_fmt, + dai->dai_config->type); + } +/* TODO: add any other DMIC specific fixups */ +break ; +case SOF_DAI_INTEL_HDA : +/* do nothing for HDA dai_link */ +break ; +default : +dev_err (sdev->dev,"error: invalid DAI type %d\n" , + dai->dai_config->type); +break ; + } + +return 0 ; +} + +static int sof_pcm_probe (struct snd_soc_component *component) +{ +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pdata *plat_data = sdev->pdata; +const char *tplg_filename; +int ret; + +/* load the default topology */ + sdev->component = component; + + tplg_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->tplg_filename_prefix, + plat_data->tplg_filename); +if (!tplg_filename) +return -ENOMEM ; + + ret =snd_sof_load_topology (sdev, tplg_filename); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to load DSP topology %d\n" , + ret); +return ret; + } + +/* +* Some platforms in SOF, ex: BYT, may not have their platform PM +* callbacks set. Skip decrementing the usage count so as to +* prevent their runtime PM callbacks from being invoked. +*/ +if (!sof_ops (sdev)->runtime_suspend || !sof_ops (sdev)->runtime_resume) +return ret; + +/* +* Decrement the usage count to enable the device to enter +* runtime suspend after probe() completes. +*/ +pm_runtime_put_noidle (sdev->dev); + +return ret; +} + +static void sof_pcm_remove (struct snd_soc_component *component) +{ +} + +void snd_sof_new_platform_drv (struct snd_sof_dev *sdev) +{ +struct snd_soc_component_driver *pd = &sdev->plat_drv; +struct snd_sof_pdata *plat_data = sdev->pdata; +const char *drv_name; + + drv_name = plat_data->machine->drv_name; + + pd->name ="sof-audio-component" ; + pd->probe = sof_pcm_probe; + pd->remove = sof_pcm_remove; + pd->ops = &sof_pcm_ops; +#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS ) + pd->compr_ops = &sof_compressed_ops; +#endif + pd->pcm_new = sof_pcm_new; + pd->ignore_machine = drv_name; + pd->be_hw_params_fixup = sof_pcm_dai_link_fixup; + pd->be_pcm_base =SOF_BE_PCM_BASE ; + pd->use_dai_pcm_id = true; + pd->topology_name_prefix ="sof" ; + +/* do not increase the refcount in core */ + pd->ignore_module_refcount =1 ; +}
Signature · 1 line
2.17.1
Re: [PATCH v4 05/14] ASoC: SOF: Add PCM operations support
Quoted 2 lines · Pierre-Louis Bossart
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{
....
sound/soc/sof/pcm.c line 430
Quoted 1 line
sound/soc/sof/pcm.c new file +1
-0+snd_sof_pcm_platform_open (sdev, substream);
No error check?
Quoted 13 lines
sound/soc/sof/pcm.c new file +13
-0+ +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static int sof_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private;
sound/soc/sof/pcm.c line 453
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: close stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +snd_sof_pcm_platform_close (sdev, substream);
Doesn't it need spcm->mutex lock while open is called inside mutex? Or, better to reconsider: what does spcm->mutex protect?
Quoted 61 lines
sound/soc/sof/pcm.c new file +61
-0+ +mutex_lock (&spcm->mutex); +pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static struct snd_pcm_ops sof_pcm_ops = { + .open = sof_pcm_open, + .close = sof_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sof_pcm_hw_params, + .hw_free = sof_pcm_hw_free, + .trigger = sof_pcm_trigger, + .pointer = sof_pcm_pointer, + .page = snd_pcm_sgbuf_ops_page, +}; + +/* +* Pre-allocate playback/capture audio buffer pages. +* no need to explicitly release memory preallocated by sof_pcm_new in pcm_free +* snd_pcm_lib_preallocate_free_for_all() is called by the core. +*/ +static int sof_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct snd_pcm *pcm = rtd->pcm; +struct snd_soc_tplg_stream_caps *caps; +int ret =0 , stream =SNDRV_PCM_STREAM_PLAYBACK ; + +/* find SOF PCM for this RTD */ + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) { +dev_warn (sdev->dev,"warn: can't find PCM with DAI ID %d\n" , + rtd->dai_link->id); +return 0 ; + } + rtd->private = spcm; + +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); +
sound/soc/sof/pcm.c line 524
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ ret =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)); +if (ret) { +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); +return ret; + }
The error check here is redundant, please drop. snd_pcm_lib_preallocate_pages() was changed to be void function recently, so it'll be a build error.
Quoted 12 lines
sound/soc/sof/pcm.c new file +12
-0+ +capture: + stream =SNDRV_PCM_STREAM_CAPTURE ; + +/* do we need to pre-allocate capture audio buffer pages */ +if (!spcm->pcm.capture) +return ret; + + caps = &spcm->pcm.caps[stream]; + +/* pre-allocate capture audio buffer pages */ + dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
sound/soc/sof/pcm.c line 546
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ caps->name, caps->buffer_size_min, caps->buffer_size_max); + + ret =snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->dev, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); +if (ret) +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret);
Ditto.
Quoted 24 lines
sound/soc/sof/pcm.c new file +24
-0+ +return ret; +} + +/* fixup the BE DAI link to match any values from topology */ +static int sof_pcm_dai_link_fixup (struct snd_soc_pcm_runtime *rtd, +struct snd_pcm_hw_params *params) +{ +struct snd_interval *rate =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_RATE ); +struct snd_interval *channels =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_CHANNELS ); +struct snd_mask *fmt =hw_param_mask (params,SNDRV_PCM_HW_PARAM_FORMAT ); +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_dai *dai = +snd_sof_find_dai (sdev, (char *)rtd->dai_link->name); + +/* no topology exists for this BE, try a common configuration */ +if (!dai) { +dev_warn (sdev->dev,"warning: no topology found for BE DAI %s config\n" , + rtd->dai_link->name);
sound/soc/sof/pcm.c line 580
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ +/* set 48k, stereo, 16bits by default */ + rate->min =48000 ; + rate->max =48000 ; + + channels->min =2 ; + channels->max =2 ; + +snd_mask_none (fmt); +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE );
Use snd_mask_set_format() macro. That avoids the ugly cast.
Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+ +return 0 ; + } + +/* read format from topology */ +snd_mask_none (fmt); +
sound/soc/sof/pcm.c line 597
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+switch (dai->comp_dai.config.frame_fmt) { +case SOF_IPC_FRAME_S16_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); +break ; +case SOF_IPC_FRAME_S24_4LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S24_LE ); +break ; +case SOF_IPC_FRAME_S32_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S32_LE ); +break ;
Ditto for these three, too.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 05/14] ASoC: SOF: Add PCM operations support
Quoted 8 lines · Takashi Iwai
Quoted 2 lines · Pierre-Louis Bossart
sound/soc/sof/pcm.c new file +2
-0+static int sof_pcm_open (struct snd_pcm_substream *substream) +{....
sound/soc/sof/pcm.c line 430
Quoted 1 line
sound/soc/sof/pcm.c new file +1
-0+snd_sof_pcm_platform_open (sdev, substream);No error check?
Wow, nice catch!
The only explanation I have is that this is implemented with an optional callback that's not set for baytrail, so in the initial development this was not needed. It is definitively used for ApolloLake+, will fix this.
Quoted 29 lines
Quoted 15 lines
sound/soc/sof/pcm.c new file +13
-0+ +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static int sof_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm = rtd->private;sound/soc/sof/pcm.c line 453
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+int err; + +/* nothing todo for BE */ +if (rtd->dai_link->no_pcm) +return 0 ; + +dev_dbg (sdev->dev,"pcm: close stream %d dir %d\n" , spcm->pcm.pcm_id, + substream->stream); + +snd_sof_pcm_platform_close (sdev, substream);Doesn't it need
spcm->mutexlock while open is called inside mutex? Or, better to reconsider: what doesspcm->mutexprotect?
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + mutex_lock(&spcm->mutex);
Indeed the position of the mutex makes no sense. it should be taken before the close or it's not needed. Will look into this.
Quoted 168 lines
Quoted 59 lines
sound/soc/sof/pcm.c new file +59
-0+pm_runtime_mark_last_busy (sdev->dev); + + err =pm_runtime_put_autosuspend (sdev->dev); +if (err <0 ) +dev_err (sdev->dev,"error: pcm close failed to idle %d\n" , + err); + +mutex_unlock (&spcm->mutex); +return 0 ; +} + +static struct snd_pcm_ops sof_pcm_ops = { + .open = sof_pcm_open, + .close = sof_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = sof_pcm_hw_params, + .hw_free = sof_pcm_hw_free, + .trigger = sof_pcm_trigger, + .pointer = sof_pcm_pointer, + .page = snd_pcm_sgbuf_ops_page, +}; + +/* +* Pre-allocate playback/capture audio buffer pages. +* no need to explicitly release memory preallocated by sof_pcm_new in pcm_free +* snd_pcm_lib_preallocate_free_for_all() is called by the core. +*/ +static int sof_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_pcm *spcm; +struct snd_pcm *pcm = rtd->pcm; +struct snd_soc_tplg_stream_caps *caps; +int ret =0 , stream =SNDRV_PCM_STREAM_PLAYBACK ; + +/* find SOF PCM for this RTD */ + spcm =snd_sof_find_spcm_dai (sdev, rtd); +if (!spcm) { +dev_warn (sdev->dev,"warn: can't find PCM with DAI ID %d\n" , + rtd->dai_link->id); +return 0 ; + } + rtd->private = spcm; + +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); +sound/soc/sof/pcm.c line 524
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ ret =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)); +if (ret) { +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret); +return ret; + }The error check here is redundant, please drop.
snd_pcm_lib_preallocate_pages()was changed to be void function recently, so it'll be a build error.Quoted 12 lines
sound/soc/sof/pcm.c new file +12
-0+ +capture: + stream =SNDRV_PCM_STREAM_CAPTURE ; + +/* do we need to pre-allocate capture audio buffer pages */ +if (!spcm->pcm.capture) +return ret; + + caps = &spcm->pcm.caps[stream]; + +/* pre-allocate capture audio buffer pages */ + dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",sound/soc/sof/pcm.c line 546
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ caps->name, caps->buffer_size_min, caps->buffer_size_max); + + ret =snd_pcm_lib_preallocate_pages (pcm->streams[stream].substream, +SNDRV_DMA_TYPE_DEV_SG , sdev->dev, +le32_to_cpu (caps->buffer_size_min), +le32_to_cpu (caps->buffer_size_max)); +if (ret) +dev_err (sdev->dev,"error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n" , + caps->buffer_size_min, caps->buffer_size_max, + caps->name, ret);Ditto.
Quoted 24 lines
sound/soc/sof/pcm.c new file +24
-0+ +return ret; +} + +/* fixup the BE DAI link to match any values from topology */ +static int sof_pcm_dai_link_fixup (struct snd_soc_pcm_runtime *rtd, +struct snd_pcm_hw_params *params) +{ +struct snd_interval *rate =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_RATE ); +struct snd_interval *channels =hw_param_interval (params, +SNDRV_PCM_HW_PARAM_CHANNELS ); +struct snd_mask *fmt =hw_param_mask (params,SNDRV_PCM_HW_PARAM_FORMAT ); +struct snd_soc_component *component = +snd_soc_rtdcom_lookup (rtd,DRV_NAME ); +struct snd_sof_dev *sdev = +snd_soc_component_get_drvdata (component); +struct snd_sof_dai *dai = +snd_sof_find_dai (sdev, (char *)rtd->dai_link->name); + +/* no topology exists for this BE, try a common configuration */ +if (!dai) { +dev_warn (sdev->dev,"warning: no topology found for BE DAI %s config\n" , + rtd->dai_link->name);sound/soc/sof/pcm.c line 580
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+ +/* set 48k, stereo, 16bits by default */ + rate->min =48000 ; + rate->max =48000 ; + + channels->min =2 ; + channels->max =2 ; + +snd_mask_none (fmt); +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE );Use
snd_mask_set_format()macro. That avoids the ugly cast.Quoted 7 lines
sound/soc/sof/pcm.c new file +7
-0+ +return 0 ; + } + +/* read format from topology */ +snd_mask_none (fmt); +sound/soc/sof/pcm.c line 597
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+switch (dai->comp_dai.config.frame_fmt) { +case SOF_IPC_FRAME_S16_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S16_LE ); +break ; +case SOF_IPC_FRAME_S24_4LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S24_LE ); +break ; +case SOF_IPC_FRAME_S32_LE : +snd_mask_set (fmt, (__force int )SNDRV_PCM_FORMAT_S32_LE ); +break ;Ditto for these three, too.
thanks,
Takashi
_______________________________________________
Sound-open-firmware mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
Re: [Sound-open-firmware] [PATCH v4 05/14] ASoC: SOF: Add PCM operations support
Missed the comments below in my earlier answer.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
+ ret = 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));
+ if (ret) {
+ dev_err(sdev->dev, "error: can't alloc DMA buffer size 0x%x/0x%x for %s %d\n",
+caps->buffer_size_min,caps->buffer_size_max, +caps->name, ret);
+ return ret;
+ }
Quoted 3 lines
Quoted 3 lines
The error check here is redundant, please drop.
snd_pcm_lib_preallocate_pages()was changed to be void function recently, so it'll be a build error.
yes indeed. It's not on Mark's for-next branch so I missed it. Fixed now, thanks
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
+
+snd_mask_none(fmt);
+snd_mask_set(fmt, (__force int)SNDRV_PCM_FORMAT_S16_LE);Use
snd_mask_set_format()macro. That avoids the ugly cast.
Ah yes. Ironically I was the one who reported this ugly cast and didn't update our code with the new helper. Oops. Fixed now.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH v4 05/14] ASoC: SOF: Add PCM operations support
In reply to Pierre-Louis BossartHi Pierre,
One comment inline:
Quoted 37 lines · Pierre-Louis Bossart
From: Liam Girdwood <[email protected]>
Add support for exposing PCMs to userspace. PCMs are defined by topology and the operations in this patch map to SOF IPC calls.
The .ignore_module_refcount field is set to allow for module load/unload tests. There is no risk of the sof-pci/acpi-dev module being removed while the platform components are in use. This may need to be revisited when DT platforms are supported.
Signed-off-by Liam Girdwood <[email protected]>Signed-off-by Pierre-Louis Bossart <[email protected]>--- sound/soc/sof/pcm.c | 710 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 710 insertions(+) create mode 100644 sound/soc/sof/pcm.csound/soc/sof/pcm.c new file +13
-0@@ -0,0 +1,710 @@ +// 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>
sound/soc/sof/pcm.c line 23
Quoted 10 lines
sound/soc/sof/pcm.c new file +10
-0+#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)
dma_area is the virtual address of the DMA-able buffer. Currently, it is not used and it is confusing. Does it makes sense to remove it?
Also, can you explain better the whole concept of page tables? As far as I understand the only "Shared Memory" between host and DSP is the mailbox area, right? And it is small 4k.
Now, as for transferring audio buffers: It seems that because DSP has no direct access to host memory a DMA controller is involved? This can be programmed to copy buffers from host "address space" to DSP "address space"
Information for the host audio buffers is sent via compressed physical addresses, right?
PATCH v4 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 | 2808 ++++++++++++++++++++++++++++++++++ 2 files changed, 3064 insertions(+) create mode 100644 include/sound/sof/topology.h create mode 100644 sound/soc/sof/topology.c
include/sound/sof/topology.h new file +256 -0
@@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* +* This file is provided under a dual BSD/GPLv2 license. When using or +* redistributing this file, you may do so under either license. +* +* Copyright(c) 2018 Intel Corporation. All rights reserved. +*/ + +#ifndef __INCLUDE_SOUND_SOF_TOPOLOGY_H__ +#define __INCLUDE_SOUND_SOF_TOPOLOGY_H__ + +#include <sound/sof/header.h> + +/* +* Component +*/ + +/* types of component */ +enum sof_comp_type { +SOF_COMP_NONE =0 , +SOF_COMP_HOST , +SOF_COMP_DAI , +SOF_COMP_SG_HOST ,/**< scatter gather variant */ +SOF_COMP_SG_DAI ,/**< scatter gather variant */ +SOF_COMP_VOLUME , +SOF_COMP_MIXER , +SOF_COMP_MUX , +SOF_COMP_SRC , +SOF_COMP_SPLITTER , +SOF_COMP_TONE , +SOF_COMP_SWITCH , +SOF_COMP_BUFFER , +SOF_COMP_EQ_IIR , +SOF_COMP_EQ_FIR , +SOF_COMP_FILEREAD ,/**< host test based file IO */ +SOF_COMP_FILEWRITE ,/**< host test based file IO */ +}; + +/* XRUN action for component */ +#define SOF_XRUN_STOP 1/**< stop stream */ +#define SOF_XRUN_UNDER_ZERO 2/**< send 0s to sink */ +#define SOF_XRUN_OVER_NULL 4/**< send data to NULL */ + +/* create new generic component - SOF_IPC_TPLG_COMP_NEW */ +struct sof_ipc_comp { +struct sof_ipc_cmd_hdr hdr; +uint32_t id; +enum sof_comp_type type; +uint32_t pipeline_id; + +/* reserved for future use */ +uint32_t reserved[2 ]; +} __packed; + +/* +* Component Buffers +*/ + +/* +* SOF memory capabilities, add new ones at the end +*/ +#define SOF_MEM_CAPS_RAM (1 << 0) +#define SOF_MEM_CAPS_ROM (1 << 1) +#define SOF_MEM_CAPS_EXT (1 << 2)/**< external */ +#define SOF_MEM_CAPS_LP (1 << 3)/**< low power */ +#define SOF_MEM_CAPS_HP (1 << 4)/**< high performance */ +#define SOF_MEM_CAPS_DMA (1 << 5)/**< DMA'able */ +#define SOF_MEM_CAPS_CACHE (1 << 6)/**< cacheable */ +#define SOF_MEM_CAPS_EXEC (1 << 7)/**< executable */ + +/* create new component buffer - SOF_IPC_TPLG_BUFFER_NEW */ +struct sof_ipc_buffer { +struct sof_ipc_comp comp; +uint32_t size;/**< buffer size in bytes */ +uint32_t caps;/**< SOF_MEM_CAPS_ */ +} __packed; + +/* generic component config data - must always be after struct sof_ipc_comp */ +struct sof_ipc_comp_config { +struct sof_ipc_cmd_hdr hdr; +uint32_t periods_sink;/**< 0 means variable */ +uint32_t periods_source;/**< 0 means variable */ +uint32_t preload_count;/**< how many periods to preload */ +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 dmac_config;/**< DMA engine specific */ +} __packed; + +/* generic mixer component */ +struct sof_ipc_comp_mixer { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __packed; + +/* volume ramping types */ +enum sof_volume_ramp { +SOF_VOLUME_LINEAR =0 , +SOF_VOLUME_LOG , +SOF_VOLUME_LINEAR_ZC , +SOF_VOLUME_LOG_ZC , +}; + +/* generic volume component */ +struct sof_ipc_comp_volume { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t channels; +uint32_t min_value; +uint32_t max_value; +uint32_t ramp;/**< SOF_VOLUME_ */ +uint32_t initial_ramp;/**< ramp space in ms */ +} __packed; + +/* generic SRC component */ +struct sof_ipc_comp_src { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +/* either source or sink rate must be non zero */ +uint32_t source_rate;/**< source rate or 0 for variable */ +uint32_t sink_rate;/**< sink rate or 0 for variable */ +uint32_t rate_mask;/**< SOF_RATE_ supported rates */ +} __packed; + +/* generic MUX component */ +struct sof_ipc_comp_mux { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +} __packed; + +/* generic tone generator component */ +struct sof_ipc_comp_tone { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +int32_t sample_rate; +int32_t frequency; +int32_t amplitude; +int32_t freq_mult; +int32_t ampl_mult; +int32_t length; +int32_t period; +int32_t repeats; +int32_t ramp_step; +} __packed; + +/** \brief Types of EFFECT */ +enum sof_ipc_effect_type { +SOF_EFFECT_NONE =0 ,/**< None */ +SOF_EFFECT_INTEL_EQFIR ,/**< Intel FIR */ +SOF_EFFECT_INTEL_EQIIR ,/**< Intel IIR */ +}; + +/* general purpose EFFECT configuration */ +struct sof_ipc_comp_effect { +struct sof_ipc_hdr hdr; +uint32_t type;/** sof_ipc_effect_type */ +} __packed; + +/* FIR equalizer component */ +struct sof_ipc_comp_eq_fir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size; + +/* reserved for future use */ +uint32_t reserved[8 ]; + +unsigned char data[0 ]; +} __packed; + +/* IIR equalizer component */ +struct sof_ipc_comp_eq_iir { +struct sof_ipc_comp comp; +struct sof_ipc_comp_config config; +uint32_t size; + +/* reserved for future use */ +uint32_t reserved[8 ]; + +unsigned char data[0 ]; +} __packed; + +/* frees components, buffers and pipelines +* SOF_IPC_TPLG_COMP_FREE, SOF_IPC_TPLG_PIPE_FREE, SOF_IPC_TPLG_BUFFER_FREE +*/ +struct sof_ipc_free { +struct sof_ipc_cmd_hdr hdr; +uint32_t id; +} __packed; + +struct sof_ipc_comp_reply { +struct sof_ipc_reply rhdr; +uint32_t id; +uint32_t offset; +} __packed; + +/* +* Pipeline +*/ + +/* new pipeline - SOF_IPC_TPLG_PIPE_NEW */ +struct sof_ipc_pipe_new { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id;/**< component id for pipeline */ +uint32_t pipeline_id;/**< pipeline id */ +uint32_t sched_id;/**< Scheduling component id */ +uint32_t core;/**< core we run on */ +uint32_t deadline;/**< execution completion deadline in us*/ +uint32_t priority;/**< priority level 0 (low) to 10 (max) */ +uint32_t period_mips;/**< worst case instruction count per period */ +uint32_t frames_per_sched;/**< output frames of pipeline, 0 is variable */ +uint32_t xrun_limit_usecs;/**< report xruns greater than limit */ + +/* non zero if timer scheduled, otherwise DAI DMA irq scheduled */ +uint32_t timer_delay; +} __packed; + +/* pipeline construction complete - SOF_IPC_TPLG_PIPE_COMPLETE */ +struct sof_ipc_pipe_ready { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id; +} __packed; + +struct sof_ipc_pipe_free { +struct sof_ipc_cmd_hdr hdr; +uint32_t comp_id; +} __packed; + +/* connect two components in pipeline - SOF_IPC_TPLG_COMP_CONNECT */ +struct sof_ipc_pipe_comp_connect { +struct sof_ipc_cmd_hdr hdr; +uint32_t source_id; +uint32_t sink_id; +} __packed; + +#endif
sound/soc/sof/topology.c new file +2808 -0
2,744 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH v4 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 | 298 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 sound/soc/sof/trace.c
sound/soc/sof/trace.c new file +298 -0
@@ -0,0 +1,298 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/debugfs.h> +#include <linux/sched/signal.h> +#include "sof-priv.h" +#include "ops.h" + +static size_t sof_wait_trace_avail (struct snd_sof_dev *sdev, +loff_t pos,size_t buffer_size) +{ +wait_queue_entry_t wait; + +/* +* If host offset is less than local pos, it means write pointer of +* host DMA buffer has been wrapped. We should output the trace data +* at the end of host DMA buffer at first. +*/ +if (sdev->host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (sdev->host_offset > pos) +return sdev->host_offset - pos; + +/* wait for available trace data from FW */ +init_waitqueue_entry (&wait, current); +set_current_state (TASK_INTERRUPTIBLE ); +add_wait_queue (&sdev->trace_sleep, &wait); + +if (signal_pending (current)) { +remove_wait_queue (&sdev->trace_sleep, &wait); + }else { +/* set timeout to max value, no error code */ +schedule_timeout (MAX_SCHEDULE_TIMEOUT ); +remove_wait_queue (&sdev->trace_sleep, &wait); + } + +/* return bytes available for copy */ +if (sdev->host_offset < pos) +return buffer_size - pos; + +return sdev->host_offset - pos; +} + +static ssize_t sof_dfsentry_trace_read (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct snd_sof_dfsentry *dfse = file->private_data; +struct snd_sof_dev *sdev = dfse->sdev; +unsigned long rem; +loff_t lpos = *ppos; +size_t avail, buffer_size = dfse->size; +u64 lpos_64; + +/* make sure we know about any failures on the DSP side */ + sdev->dtrace_error = false; + +/* check pos and count */ +if (lpos <0 ) +return -EINVAL ; +if (!count) +return 0 ; + +/* check for buffer wrap and count overflow */ + lpos_64 = lpos; + lpos =do_div (lpos_64, buffer_size); + +if (count > buffer_size - lpos)/* min() not used to avoid sparse warnings */ + count = buffer_size - lpos; + +/* get available count based on current host offset */ + avail =sof_wait_trace_avail (sdev, lpos, buffer_size); +if (sdev->dtrace_error) { +dev_err (sdev->dev,"error: trace IO error\n" ); +return -EIO ; + } + +/* make sure count is <= avail */ + count = avail > count ? count : avail; + +/* copy available trace data to debugfs */ + rem =copy_to_user (buffer, dfse->buf + lpos, count); +if (rem == count) +return -EFAULT ; + + *ppos += count; + +/* move debugfs reading position */ +return count; +} + +static const struct file_operations sof_dfs_trace_fops = { + .open = simple_open, + .read = sof_dfsentry_trace_read, + .llseek = default_llseek, +}; + +static int trace_debugfs_create (struct snd_sof_dev *sdev) +{ +struct snd_sof_dfsentry *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.offset =0 ; + 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
Re: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
Quoted 20 lines · Pierre-Louis Bossart
sound/soc/sof/trace.c new file +19
-0+static size_t sof_wait_trace_avail (struct snd_sof_dev *sdev, +loff_t pos,size_t buffer_size) +{ +wait_queue_entry_t wait; + +/* +* If host offset is less than local pos, it means write pointer of +* host DMA buffer has been wrapped. We should output the trace data +* at the end of host DMA buffer at first. +*/ +if (sdev->host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (sdev->host_offset > pos) +return sdev->host_offset - pos; + +/* wait for available trace data from FW */ +init_waitqueue_entry (&wait, current);
sound/soc/sof/trace.c line 44
Quoted 10 lines
sound/soc/sof/trace.c new file +10
-0+set_current_state (TASK_INTERRUPTIBLE ); +add_wait_queue (&sdev->trace_sleep, &wait); + +if (signal_pending (current)) { +remove_wait_queue (&sdev->trace_sleep, &wait); + }else { +/* set timeout to max value, no error code */ +schedule_timeout (MAX_SCHEDULE_TIMEOUT ); +remove_wait_queue (&sdev->trace_sleep, &wait); + }
Can be slightly optimized here, e.g. no need of two remove_wait_queue() calls.
sound/soc/sof/trace.c line 50
Quoted 6 lines
sound/soc/sof/trace.c new file +6
-0+ +/* return bytes available for copy */ +if (sdev->host_offset < pos) +return buffer_size - pos; + +return sdev->host_offset - pos;
Are these sdev->host_offset accesses race-free?
If I understand correctly, snd_sof_trace_update_pos() can be called at any time, and the offset might become inconsistent during these multiple references.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
Quoted 27 lines · Takashi Iwai
Quoted 25 lines · Pierre-Louis Bossart
sound/soc/sof/trace.c new file +24
-0+static size_t sof_wait_trace_avail (struct snd_sof_dev *sdev, +loff_t pos,size_t buffer_size) +{ +wait_queue_entry_t wait; + +/* +* If host offset is less than local pos, it means write pointer of +* host DMA buffer has been wrapped. We should output the trace data +* at the end of host DMA buffer at first. +*/ +if (sdev->host_offset < pos) +return buffer_size - pos; + +/* If there is available trace data now, it is unnecessary to wait. */ +if (sdev->host_offset > pos) +return sdev->host_offset - pos; + +/* wait for available trace data from FW */ +init_waitqueue_entry (&wait, current); +set_current_state (TASK_INTERRUPTIBLE ); +add_wait_queue (&sdev->trace_sleep, &wait); + +if (signal_pending (current)) { +remove_wait_queue (&sdev->trace_sleep, &wait);
Quoted 8 lines
sound/soc/sof/trace.c line 44
Quoted 5 lines
sound/soc/sof/trace.c new file +5
-0+ }else { +/* set timeout to max value, no error code */ +schedule_timeout (MAX_SCHEDULE_TIMEOUT ); +remove_wait_queue (&sdev->trace_sleep, &wait); + }Can be slightly optimized here, e.g. no need of two
remove_wait_queue()calls.
Yes. This was cleaned-up to remove a goto but we missed the common code. will fix
Quoted 10 lines
sound/soc/sof/trace.c line 50
Quoted 7 lines
sound/soc/sof/trace.c new file +6
-0+ +/* return bytes available for copy */ +if (sdev->host_offset < pos) +return buffer_size - pos; + +return sdev->host_offset - pos;Are these
sdev->host_offsetaccesses race-free?
Quoted 3 lines
If I understand correctly,
snd_sof_trace_update_pos()can be called at any time, and the offset might become inconsistent during these multiple references.
It's my understanding that there is a single trace stream and a single consumer (via a debugfs file), but will double check.
Mark Brown
maintainerRe: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
In reply to Pierre-Louis Bossartsound/soc/sof/trace.c line 87
Quoted 2 lines · Pierre-Louis Bossart
sound/soc/sof/trace.c new file +2
-0+/* make sure count is <= avail */ + count = avail > count ? count : avail;
count = min(avail, count)?
Re: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
Quoted 5 lines · Mark Brown
sound/soc/sof/trace.c line 87
Quoted 2 lines · Pierre-Louis Bossart
sound/soc/sof/trace.c new file +2
-0+/* make sure count is <= avail */ + count = avail > count ? count : avail;count =
min(avail, count)?
as discussed in the last review, we didn't use min() since it adds a number of obscure warnings with sparse. I haven't found any time to look into this so for now left the code as is. Sparse is a useful tool for the address checks (topology/DMAs with _le32, __iomem, etc), the fewer warnings we get the better.
Re: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
Quoted 11 lines · Pierre-Louis Bossart
Quoted 5 lines · Mark Brown
sound/soc/sof/trace.c line 87
Quoted 2 lines · Pierre-Louis Bossart
sound/soc/sof/trace.c new file +2
-0+/* make sure count is <= avail */ + count = avail > count ? count : avail;count =
min(avail, count)?as discussed in the last review, we didn't use
min()since it adds a number of obscure warnings with sparse. I haven't found any time to look into this so for now left the code as is. Sparse is a useful tool for the address checks (topology/DMAs with_le32,__iomem, etc), the fewer warnings we get the better.
Shouldn't be sparse itself get fixed?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
sound/soc/sof/trace.c line 87
Quoted 2 lines
sound/soc/sof/trace.c new file +2
-0+/* make sure count is <= avail */ + count = avail > count ? count : avail;count =
min(avail, count)?as discussed in the last review, we didn't use
min()since it adds a number of obscure warnings with sparse. I haven't found any time to look into this so for now left the code as is. Sparse is a useful tool for the address checks (topology/DMAs with_le32,__iomem, etc), the fewer warnings we get the better.Shouldn't be sparse itself get fixed?
Absolutely. I just don't have time to even look into it given all the feedback on the kernel patches I have to deal with :-)
Mark Brown
maintainerRe: [PATCH v4 07/14] ASoC: SOF: Add DSP firmware logger support
In reply to Andy ShevchenkoQuoted 9 lines · Andy Shevchenko
Quoted 5 lines · Pierre-Louis Bossart
as discussed in the last review, we didn't use
min()since it adds a number of obscure warnings with sparse. I haven't found any time to look into this so for now left the code as is. Sparse is a useful tool for the address checks (topology/DMAs with_le32,__iomem, etc), the fewer warnings we get the better.Shouldn't be sparse itself get fixed?
Ideally. We had this discussion last time :/
PATCH v4 8/14 ASoC: SOF: Add DSP HW abstraction operations
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add operation pointers that can be called by core to control a wide variety of DSP targets. The DSP HW drivers will fill in these operations.
--- sound/soc/sof/ops.c | 204 ++++++++++++++++++++++ sound/soc/sof/ops.h | 414 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 618 insertions(+) create mode 100644 sound/soc/sof/ops.c create mode 100644 sound/soc/sof/ops.h
sound/soc/sof/ops.c new file +204 -0
@@ -0,0 +1,204 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include <linux/pci.h> +#include "ops.h" + +int 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 = ~0 ;/* explicit init to remove uninitialized use warnings */ + +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; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits_unlocked); + +int snd_sof_pci_update_bits (struct snd_sof_dev *sdev,u32 offset, +u32 mask,u32 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_pci_update_bits_unlocked (sdev, offset, mask, value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits); + +int snd_sof_dsp_update_bits_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +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); + +int 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 */ +void snd_sof_dsp_update_bits_forced_unlocked (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +unsigned int old, new; +u32 ret; + + ret =snd_sof_dsp_read (sdev, bar, offset); + + old = ret; + new = (old & (~mask)) | (value & mask); + +snd_sof_dsp_write (sdev, bar, offset, new); +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_forced_unlocked); + +int snd_sof_dsp_update_bits (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u32 mask,u32 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_dsp_update_bits_unlocked (sdev, bar, offset, mask, + value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits); + +int snd_sof_dsp_update_bits64 (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u64 mask,u64 value) +{ +unsigned long flags; +bool change; + +spin_lock_irqsave (&sdev->hw_lock, flags); + change =snd_sof_dsp_update_bits64_unlocked (sdev, bar, offset, mask, + value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +return change; +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits64); + +/* This is for registers bits with attribute RWC */ +void snd_sof_dsp_update_bits_forced (struct snd_sof_dev *sdev,u32 bar, +u32 offset,u32 mask,u32 value) +{ +unsigned long flags; + +spin_lock_irqsave (&sdev->hw_lock, flags); +snd_sof_dsp_update_bits_forced_unlocked (sdev, bar, offset, mask, value); +spin_unlock_irqrestore (&sdev->hw_lock, flags); +} +EXPORT_SYMBOL (snd_sof_dsp_update_bits_forced); + +int snd_sof_dsp_register_poll (struct snd_sof_dev *sdev,u32 bar,u32 offset, +u32 mask,u32 target,u32 timeout_ms, +u32 interval_us) +{ +u32 reg; +unsigned long tout_jiff; +int k =0 , s = interval_us; + +/* +* Split the loop into 2 sleep stages with varying resolution. +* To do it more accurately, the range of wakeups are: +* In case of interval_us = 500, +* Phase 1(first 5ms): min sleep 0.5ms; max sleep 1ms. +* Phase 2(beyond 5ms): min sleep 5ms; max sleep 10ms. +*/ + + tout_jiff = jiffies +msecs_to_jiffies (timeout_ms); +do { + reg =snd_sof_dsp_read (sdev, bar, offset); +if ((reg & mask) == target) +break ; + +/* Phase 2 after 5ms(500us * 10) */ +if (++k >10 ) + s = interval_us *10 ; + +usleep_range (s,2 * s); + }while (time_before (jiffies, tout_jiff)); + +if ((reg & mask) == target) { +dev_dbg (sdev->dev,"FW Poll Status: reg=%#x successful\n" , reg); + +return 0 ; + } + +dev_dbg (sdev->dev,"FW Poll Status: reg=%#x timedout\n" , reg); +return -ETIME ; +} +EXPORT_SYMBOL (snd_sof_dsp_register_poll); + +void snd_sof_dsp_panic (struct snd_sof_dev *sdev,u32 offset) +{ +dev_err (sdev->dev,"error : DSP panic!\n" ); + +/* +* check if DSP is not ready and did not set the dsp_oops_offset. +* if the dsp_oops_offset is not set, set it from the panic message. +* Also add a check to memory window setting with panic message. +*/ +if (!sdev->dsp_oops_offset) + sdev->dsp_oops_offset = offset; +else +dev_dbg (sdev->dev,"panic: dsp_oops_offset %zu offset %d\n" , + sdev->dsp_oops_offset, offset); + +snd_sof_dsp_dbg_dump (sdev,SOF_DBG_REGS |SOF_DBG_MBOX ); +snd_sof_trace_notify_for_error (sdev); +snd_sof_dsp_cmd_done (sdev,SOF_IPC_HOST_REPLY ); +} +EXPORT_SYMBOL (snd_sof_dsp_panic);
sound/soc/sof/ops.h new file +414 -0
414 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v4 08/14] ASoC: SOF: Add DSP HW abstraction operations
Quoted 13 lines · Pierre-Louis Bossart
sound/soc/sof/ops.c new file +13
-0+int 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 = ~0 ;/* explicit init to remove uninitialized use warnings */ + +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); +
sound/soc/sof/ops.c line 36
Quoted 10 lines
sound/soc/sof/ops.c new file +10
-0+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; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits_unlocked);
Better to change the return type to bool to make clearer.
thanks,
Takashi
Re: [Sound-open-firmware] [PATCH v4 08/14] ASoC: SOF: Add DSP HW abstraction operations
Quoted 19 lines · Takashi Iwai
Quoted 17 lines · Pierre-Louis Bossart
sound/soc/sof/ops.c new file +17
-0+int 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 = ~0 ;/* explicit init to remove uninitialized use warnings */ + +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);
Quoted 8 lines
sound/soc/sof/ops.c line 36
Quoted 6 lines
sound/soc/sof/ops.c new file +6
-0+dev_dbg (sdev->dev,"Debug PCIW: %8.8x at %8.8x\n" , value, + offset); + +return true; +} +EXPORT_SYMBOL (snd_sof_pci_update_bits_unlocked);Better to change the return type to bool to make clearer.
will rework this to make both Andy and Takashi happy :-)
Re: [PATCH v4 08/14] ASoC: SOF: Add DSP HW abstraction operations
In reply to Pierre-Louis Bossartsound/soc/sof/ops.c line 19
Quoted 13 lines · Pierre-Louis Bossart
From: 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 new file +6
-0+int 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 = ~0 ;/* explicit init to remove uninitialized use warnings */
In case you handle pci_read_config_dword() errors, would you get same warning?
Something like
unsigned int old, new;
int ret;
ret = pci_read_config_dword(..., &old);
if (ret)
return -ENXIO;
...
I really don't like such assignments that potentially can shadow a real corner cases.
sound/soc/sof/ops.c line 25
Quoted 7 lines
sound/soc/sof/ops.c new file +6
-0+ +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);
(~mask) -> ~mask.
Quoted 13 lines
sound/soc/sof/ops.c new file +10
-0+ +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; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [Sound-open-firmware] [PATCH v4 08/14] ASoC: SOF: Add DSP HW abstraction operations
Quoted 19 lines · Andy Shevchenko
sound/soc/sof/ops.c line 19
Quoted 13 lines · Pierre-Louis Bossart
From: 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 new file +6
-0+int 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 = ~0 ;/* explicit init to remove uninitialized use warnings */ In case you handle
pci_read_config_dword()errors, would you get same warning?Something like
Quoted 8 lines
unsigned int old, new;
int ret;ret =
pci_read_config_dword(..., &old);
if (ret)return -ENXIO;...
will give it a try again, I remember trying when we cleaned-up the code but can't recall this part.
I just did a git grep pci_read_config_dword and 99% of the calls don't check for any errors. Not an excuse but there isn't a clear pattern here.
Quoted 4 lines
I really don't like such assignments that potentially can shadow a real corner cases.
Me neither, we've removed a lot of those assignments that were unnecessary. cppcheck was the most useful tool for these local variables.
Quoted 10 lines
sound/soc/sof/ops.c line 25
Quoted 8 lines
sound/soc/sof/ops.c new file +6
-0+ +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);(~mask) -> ~mask.
yes, will fix.
PATCH v4 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 | 363 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 sound/soc/sof/loader.c
sound/soc/sof/loader.c new file +363 -0
@@ -0,0 +1,363 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// +// Generic firmware loader. +// + +#include <linux/firmware.h> +#include <sound/sof.h> +#include "ops.h" + +static int get_ext_windows (struct snd_sof_dev *sdev, +struct sof_ipc_ext_data_hdr *ext_hdr) +{ +struct sof_ipc_window *w = (struct sof_ipc_window *)ext_hdr; +size_t size; + +if (w->num_windows ==0 || w->num_windows >SOF_IPC_MAX_ELEMS ) +return -EINVAL ; + + size =sizeof (*w) +sizeof (struct sof_ipc_window_elem ) * w->num_windows; + +/* keep a local copy of the data */ + sdev->info_window =kmemdup (w, size,GFP_KERNEL ); +if (!sdev->info_window) +return -ENOMEM ; + +return 0 ; +} + +/* parse the extended FW boot data structures from FW boot message */ +int snd_sof_fw_parse_ext_data (struct snd_sof_dev *sdev,u32 bar,u32 offset) +{ +struct sof_ipc_ext_data_hdr *ext_hdr; +void *ext_data; +int ret =0 ; + + ext_data =kzalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!ext_data) +return -ENOMEM ; + +/* get first header */ +snd_sof_dsp_block_read (sdev, bar, offset, ext_data, +sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data; + +while (ext_hdr->hdr.cmd ==SOF_IPC_FW_READY ) { +/* read in ext structure */ + offset +=sizeof (*ext_hdr); +snd_sof_dsp_block_read (sdev, bar, offset, + ext_data +sizeof (*ext_hdr), + ext_hdr->hdr.size -sizeof (*ext_hdr)); + +dev_dbg (sdev->dev,"found ext header type %d size 0x%x\n" , + ext_hdr->type, ext_hdr->hdr.size); + +/* process structure data */ +switch (ext_hdr->type) { +case SOF_IPC_EXT_DMA_BUFFER : +break ; +case SOF_IPC_EXT_WINDOW : + ret =get_ext_windows (sdev, ext_hdr); +break ; +default : +break ; + } + +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to parse ext data type %d\n" , + ext_hdr->type); +break ; + } + +/* move to next header */ + offset += ext_hdr->hdr.size; +snd_sof_dsp_block_read (sdev, bar, offset, ext_data, +sizeof (*ext_hdr)); + ext_hdr = (struct sof_ipc_ext_data_hdr *)ext_data; + } + +kfree (ext_data); +return ret; +} +EXPORT_SYMBOL (snd_sof_fw_parse_ext_data); + +/* generic module parser for mmaped DSPs */ +int snd_sof_parse_module_memcpy (struct snd_sof_dev *sdev, +struct snd_sof_mod_hdr *module) +{ +struct snd_sof_blk_hdr *block; +int count; +u32 offset; +size_t remaining; + +dev_dbg (sdev->dev,"new module size 0x%x blocks 0x%x type 0x%x\n" , + module->size, module->num_blocks, module->type); + + block = (void *)module +sizeof (*module); + +/* module->size doesn't include header size */ + remaining = module->size; +for (count =0 ; count < module->num_blocks; count++) { +/* minus header size of block */ + remaining -=sizeof (*block); +if (remaining < block->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } + +if (block->size ==0 ) { +dev_warn (sdev->dev, +"warning: block %d size zero\n" , count); +dev_warn (sdev->dev," type 0x%x offset 0x%x\n" , + block->type, block->offset); +continue ; + } + +switch (block->type) { +case SOF_FW_BLK_TYPE_RSRVD0 : + case SOF_FW_BLK_TYPE_SRAM...SOF_FW_BLK_TYPE_RSRVD14: +continue ;/* not handled atm */ +case SOF_FW_BLK_TYPE_IRAM : +case SOF_FW_BLK_TYPE_DRAM : + offset = block->offset; +break ; +default : +dev_err (sdev->dev,"error: bad type 0x%x for block 0x%x\n" , + block->type, count); +return -EINVAL ; + } + +dev_dbg (sdev->dev, +"block %d type 0x%x size 0x%x ==> offset 0x%x\n" , + count, block->type, block->size, offset); + +/* checking block->size to avoid unaligned access */ +if (block->size %sizeof (u32)) { +dev_err (sdev->dev,"error: invalid block size 0x%x\n" , + block->size); +return -EINVAL ; + } +snd_sof_dsp_block_write (sdev, sdev->mmio_bar, offset, + (void *)block +sizeof (*block), + block->size); + +/* minus body size of block */ + remaining -= block->size; +/* next block */ + block = (void *)block +sizeof (*block) + block->size; + } + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_parse_module_memcpy); + +static int check_header (struct snd_sof_dev *sdev,const struct firmware *fw) +{ +struct snd_sof_fw_header *header; + +/* Read the header information from the data pointer */ + header = (struct snd_sof_fw_header *)fw->data; + +/* verify FW sig */ +if (strncmp (header->sig,SND_SOF_FW_SIG ,SND_SOF_FW_SIG_SIZE ) !=0 ) { +dev_err (sdev->dev,"error: invalid firmware signature\n" ); +return -EINVAL ; + } + +/* check size is valid */ +if (fw->size != header->file_size +sizeof (*header)) { +dev_err (sdev->dev,"error: invalid filesize mismatch got 0x%zx expected 0x%zx\n" , + fw->size, header->file_size +sizeof (*header)); +return -EINVAL ; + } + +dev_dbg (sdev->dev,"header size=0x%x modules=0x%x abi=0x%x size=%zu\n" , + header->file_size, header->num_modules, + header->abi,sizeof (*header)); + +return 0 ; +} + +static int load_modules (struct snd_sof_dev *sdev,const struct firmware *fw) +{ +struct snd_sof_fw_header *header; +struct snd_sof_mod_hdr *module; +int (*load_module)(struct snd_sof_dev *sof_dev, +struct snd_sof_mod_hdr *hdr); +int ret, count; +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 = (void *)fw->data +sizeof (*header); + remaining = fw->size -sizeof (*header); +for (count =0 ; count < header->num_modules; count++) { +/* minus header size of module */ + remaining -=sizeof (*module); +if (remaining < module->size) { +dev_err (sdev->dev,"error: not enough data remaining\n" ); +return -EINVAL ; + } +/* module */ + ret =load_module (sdev, module); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid module %d\n" , count); +return ret; + } +/* minus body size of module */ + remaining -= module->size; + module = (void *)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 ; + + fw_filename =devm_kasprintf (sdev->dev,GFP_KERNEL , +"%s/%s" , + plat_data->fw_filename_prefix, + plat_data->fw_filename); +if (!fw_filename) +return -ENOMEM ; + + ret =request_firmware (&plat_data->fw, fw_filename, sdev->dev); + +if (ret <0 ) { +dev_err (sdev->dev,"error: request firmware %s failed err: %d\n" , + fw_filename, ret); + } +return ret; +} +EXPORT_SYMBOL (snd_sof_load_firmware_raw); + +int snd_sof_load_firmware_memcpy (struct snd_sof_dev *sdev) +{ +struct snd_sof_pdata *plat_data = sdev->pdata; +int ret; + + ret =snd_sof_load_firmware_raw (sdev); +if (ret <0 ) +return ret; + +/* make sure the FW header and file is valid */ + ret =check_header (sdev, plat_data->fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW header\n" ); + goto error; + } + +/* prepare the DSP for FW loading */ + ret =snd_sof_dsp_reset (sdev); +if (ret <0 ) { +dev_err (sdev->dev,"error: failed to reset DSP\n" ); + goto error; + } + +/* parse and load firmware modules to DSP */ + ret =load_modules (sdev, plat_data->fw); +if (ret <0 ) { +dev_err (sdev->dev,"error: invalid FW modules\n" ); + goto error; + } + +return 0 ; + +error: +release_firmware (plat_data->fw); +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; + +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; + } + +/* 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; + } + +return 0 ; +} +EXPORT_SYMBOL (snd_sof_run_firmware); + +void snd_sof_fw_unload (struct snd_sof_dev *sdev) +{ +/* TODO: support module unloading at runtime */ +} +EXPORT_SYMBOL (snd_sof_fw_unload);
Signature · 1 line
2.17.1
PATCH v4 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 | 164 ++++++++++++++++++++++++++ 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 | 98 ++++++++++++++++ include/uapi/sound/sof/tone.h | 21 ++++ include/uapi/sound/sof/trace.h | 93 +++++++++++++++ 8 files changed, 731 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 1 +#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 +164 -0
164 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 +98 -0
98 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 +93 -0
93 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v4 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 | 381 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100644 sound/soc/sof/pm.c
sound/soc/sof/pm.c new file +381 -0
@@ -0,0 +1,381 @@ +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) +// +// This file is provided under a dual BSD/GPLv2 license. When using or +// redistributing this file, you may do so under either license. +// +// Copyright(c) 2018 Intel Corporation. All rights reserved. +// +// Author: Liam Girdwood <[email protected]> +// + +#include "ops.h" +#include "sof-priv.h" + +static int sof_restore_kcontrols (struct snd_sof_dev *sdev) +{ +struct snd_sof_control *scontrol =NULL ; +int ipc_cmd, ctrl_type; +int ret =0 ; + +/* restore kcontrol values */ +list_for_each_entry (scontrol, &sdev->kcontrol_list, list) { +/* reset readback offset for scontrol after resuming */ + scontrol->readback_offset =0 ; + +/* notify DSP of kcontrol values */ +switch (scontrol->cmd) { +case SOF_CTRL_CMD_VOLUME : + ipc_cmd =SOF_IPC_COMP_SET_VALUE ; + ctrl_type =SOF_CTRL_TYPE_VALUE_CHAN_SET ; + ret =snd_sof_ipc_set_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd); +break ; +case SOF_CTRL_CMD_BINARY : + ipc_cmd =SOF_IPC_COMP_SET_DATA ; + ctrl_type =SOF_CTRL_TYPE_DATA_SET ; + ret =snd_sof_ipc_set_comp_data (sdev->ipc, scontrol, + ipc_cmd, ctrl_type, + scontrol->cmd); +break ; + +default : +break ; + } +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed kcontrol value set for widget: %d\n" , + scontrol->comp_id); + +return ret; + } + } + +return 0 ; +} + +static int sof_restore_pipelines (struct snd_sof_dev *sdev) +{ +struct snd_sof_widget *swidget =NULL ; +struct snd_sof_route *sroute =NULL ; +struct sof_ipc_pipe_new *pipeline; +struct snd_sof_dai *dai; +struct sof_ipc_comp_dai *comp_dai; +struct sof_ipc_cmd_hdr *hdr; +int ret =0 ; + +/* restore pipeline components */ +list_for_each_entry_reverse (swidget, &sdev->widget_list, list) { +struct sof_ipc_comp_reply r; + +/* skip if there is no private data */ +if (!swidget->private) +continue ; + +switch (swidget->id) { +case snd_soc_dapm_dai_in: +/* fallthrough */ +case snd_soc_dapm_dai_out: + dai = (struct snd_sof_dai *)swidget->private; + comp_dai = &dai->comp_dai; + ret =sof_ipc_tx_message (sdev->ipc, + comp_dai->comp.hdr.cmd, + comp_dai,sizeof (*comp_dai), + &r,sizeof (r)); +break ; +case snd_soc_dapm_scheduler: + +/* +* During suspend, all DSP cores are powered off. +* Therefore upon resume, create the pipeline comp +* and power up the core that the pipeline is +* scheduled on. +*/ + pipeline = (struct sof_ipc_pipe_new *)swidget->private; + ret =sof_load_pipeline_ipc (sdev, pipeline, &r); +break ; +default : + hdr = (struct sof_ipc_cmd_hdr *)swidget->private; + ret =sof_ipc_tx_message (sdev->ipc, hdr->cmd, + swidget->private, hdr->size, + &r,sizeof (r)); +break ; + } +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load widget type %d with ID: %d\n" , + swidget->widget->id, swidget->comp_id); + +return ret; + } + } + +/* restore pipeline connections */ +list_for_each_entry_reverse (sroute, &sdev->route_list, list) { +struct sof_ipc_pipe_comp_connect *connect; +struct sof_ipc_reply reply; + +/* skip if there's no private data */ +if (!sroute->private) +continue ; + + connect = sroute->private; + +/* send ipc */ + ret =sof_ipc_tx_message (sdev->ipc, + connect->hdr.cmd, + connect,sizeof (*connect), + &reply,sizeof (reply)); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load route sink %s control %s source %s\n" , + sroute->route->sink, + sroute->route->control ? sroute->route->control + :"none" , + sroute->route->source); + +return ret; + } + } + +/* restore dai links */ +list_for_each_entry_reverse (dai, &sdev->dai_list, list) { +struct sof_ipc_reply reply; +struct sof_ipc_dai_config *config = dai->dai_config; + +if (!config) { +dev_err (sdev->dev,"error: no config for DAI %s\n" , + dai->name); +continue ; + } + + ret =sof_ipc_tx_message (sdev->ipc, + config->hdr.cmd, config, + config->hdr.size, + &reply,sizeof (reply)); + +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to set dai config for %s\n" , + dai->name); + +return ret; + } + } + +/* complete pipeline */ +list_for_each_entry (swidget, &sdev->widget_list, list) { +switch (swidget->id) { +case snd_soc_dapm_scheduler: + swidget->complete = +snd_sof_complete_pipeline (sdev, swidget); +break ; +default : +break ; + } + } + +/* restore pipeline kcontrols */ + ret =sof_restore_kcontrols (sdev); +if (ret <0 ) +dev_err (sdev->dev, +"error: restoring kcontrols after resume\n" ); + +return ret; +} + +static int sof_send_pm_ipc (struct snd_sof_dev *sdev,int cmd) +{ +struct sof_ipc_pm_ctx pm_ctx; +struct sof_ipc_reply reply; + +memset (&pm_ctx,0 ,sizeof (pm_ctx)); + +/* configure ctx save ipc message */ + pm_ctx.hdr.size =sizeof (pm_ctx); + pm_ctx.hdr.cmd =SOF_IPC_GLB_PM_MSG | cmd; + +/* send ctx save ipc to dsp */ +return sof_ipc_tx_message (sdev->ipc, pm_ctx.hdr.cmd, &pm_ctx, +sizeof (pm_ctx), &reply,sizeof (reply)); +} + +static void sof_set_restore_stream (struct snd_sof_dev *sdev) +{ +struct snd_sof_pcm *spcm; + +/* suspend all running streams */ +list_for_each_entry (spcm, &sdev->pcm_list, list) { +mutex_lock (&spcm->mutex); + + spcm->restore_stream[0 ] =1 ; + spcm->restore_stream[1 ] =1 ; + +mutex_unlock (&spcm->mutex); + } +} + +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +static void sof_cache_debugfs (struct snd_sof_dev *sdev) +{ +struct snd_sof_dfsentry *dfse; + +list_for_each_entry (dfse, &sdev->dfsentry_list, list) { + +/* nothing to do if debugfs buffer is not IO mem */ +if (dfse->type ==SOF_DFSENTRY_TYPE_BUF ) +continue ; + +/* cache memory that is only accessible in D0 */ +if (dfse->access_type ==SOF_DEBUGFS_ACCESS_D0_ONLY ) +memcpy_fromio (dfse->cache_buf, dfse->io_mem, + dfse->size); + } +} +#endif + +static int sof_resume (struct device *dev,bool runtime_resume) +{ +struct snd_sof_dev *sdev =dev_get_drvdata (dev); +int ret =0 ; + +/* do nothing if dsp resume callbacks are not set */ +if (!sof_ops (sdev)->resume || !sof_ops (sdev)->runtime_resume) +return 0 ; + +/* +* if the runtime_resume flag is set, call the runtime_resume routine +* or else call the system resume routine +*/ +if (runtime_resume) + ret =snd_sof_dsp_runtime_resume (sdev); +else + ret =snd_sof_dsp_resume (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to power up DSP after resume\n" ); +return ret; + } + +/* load the firmware */ + ret =snd_sof_load_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to load DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* boot the firmware */ + ret =snd_sof_run_firmware (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to boot DSP firmware after resume %d\n" , + ret); +return ret; + } + +/* resume DMA trace, only need send ipc */ + ret =snd_sof_init_trace_ipc (sdev); +if (ret <0 ) { +/* non fatal */ +dev_warn (sdev->dev, +"warning: failed to init trace after resume %d\n" , + ret); + } + +/* restore pipelines */ + ret =sof_restore_pipelines (sdev); +if (ret <0 ) { +dev_err (sdev->dev, +"error: failed to restore pipeline after resume %d\n" , + ret); +return ret; + } + +/* notify DSP of system resume */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_RESTORE ); +if (ret <0 ) +dev_err (sdev->dev, +"error: ctx_restore ipc error during resume %d\n" , + ret); + +return ret; +} + +static int sof_suspend (struct device *dev,bool runtime_suspend) +{ +struct snd_sof_dev *sdev =dev_get_drvdata (dev); +int ret =0 ; + +/* do nothing if dsp suspend callback is not set */ +if (!sof_ops (sdev)->suspend) +return 0 ; + +/* release trace */ +snd_sof_release_trace (sdev); + +/* set restore_stream for all streams during system suspend */ +if (!runtime_suspend) +sof_set_restore_stream (sdev); + +#if IS_ENABLED (CONFIG_SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE ) +/* cache debugfs contents during runtime suspend */ +if (runtime_suspend) +sof_cache_debugfs (sdev); +#endif +/* notify DSP of upcoming power down */ + ret =sof_send_pm_ipc (sdev,SOF_IPC_PM_CTX_SAVE ); +if (ret <0 ) { + +/* +* FIXME: CTX_SAVE ipc should not time-out. +* But if it happens, just report the error +* and continue powering off the DSP for now. +* This will allow the DSP to power up +* normally upon system resume. +*/ +dev_err (sdev->dev, +"error: ctx_save ipc error during suspend %d\n" , + ret); + } + +/* drop all ipc */ +sof_ipc_drop_all (sdev->ipc); + +/* 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
PATCH v4 12/14 ASoC: SOF: Add Nocodec machine driver support
In reply to Pierre-Louis BossartFrom: Liam Girdwood <[email protected]>
Add a simple "fallback" machine driver that can be used to enable SOF on boards with no codec device. This machine driver can also be forced for debug/development.
--- include/sound/sof.h | 6 +++ sound/soc/sof/nocodec.c | 109 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 sound/soc/sof/nocodec.c
include/sound/sof.h +6 -0
@@ -12,6 +12,7 @@#define __INCLUDE_SOUND_SOF_H#include <linux/pci.h> +#include <sound/soc.h> #include <sound/soc-acpi.h> struct snd_sof_dsp_ops ;
@@ -91,4 +92,9 @@ struct sof_dev_desc { const struct sof_arch_ops *arch_ops; }; +int sof_nocodec_setup (struct device *dev, +struct snd_sof_pdata *sof_pdata, +struct snd_soc_acpi_mach *mach, +const struct sof_dev_desc *desc, +const struct snd_sof_dsp_ops *ops);#endif
sound/soc/sof/nocodec.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v4 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] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH v4 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 | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 sound/soc/sof/utils.c
sound/soc/sof/utils.c new file +109 -0
@@ -0,0 +1,109 @@ +// 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 +*/ + +void sof_io_write (struct snd_sof_dev *sdev,void __iomem *addr,u32 value) +{ +writel (value, addr); +} +EXPORT_SYMBOL (sof_io_write); + +u32 sof_io_read (struct snd_sof_dev *sdev,void __iomem *addr) +{ +return readl (addr); +} +EXPORT_SYMBOL (sof_io_read); + +void sof_io_write64 (struct snd_sof_dev *sdev,void __iomem *addr,u64 value) +{ +writeq (value, addr); +} +EXPORT_SYMBOL (sof_io_write64); + +u64 sof_io_read64 (struct snd_sof_dev *sdev,void __iomem *addr) +{ +return readq (addr); +} +EXPORT_SYMBOL (sof_io_read64); + +/* +* IPC Mailbox IO +*/ + +void sof_mailbox_write (struct snd_sof_dev *sdev,u32 offset, +void *message,size_t bytes) +{ +void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset; + +memcpy_toio (dest, message, bytes); +} +EXPORT_SYMBOL (sof_mailbox_write); + +void sof_mailbox_read (struct snd_sof_dev *sdev,u32 offset, +void *message,size_t bytes) +{ +void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset; + +memcpy_fromio (message, src, bytes); +} +EXPORT_SYMBOL (sof_mailbox_read); + +/* +* Memory copy. +*/ + +void sof_block_write (struct snd_sof_dev *sdev,u32 bar,u32 offset,void *src, +size_t size) +{ +void __iomem *dest = sdev->bar[bar] + offset; +const u8 *src_byte = src; +u32 affected_mask; +u32 tmp; +int m, n; + + m = size /4 ; + n = size %4 ; + +/* __iowrite32_copy use 32bit size values so divide by 4 */ +__iowrite32_copy (dest, src, m); + +if (n) { + affected_mask = (1 << (8 * n)) -1 ; + +/* first read the 32bit data of dest, then change affected +* bytes, and write back to dest. For unaffected bytes, it +* should not be changed +*/ + tmp =ioread32 (dest + m *4 ); + tmp &= ~affected_mask; + + tmp |= *(u32 *)(src_byte + m *4 ) & affected_mask; +iowrite32 (tmp, dest + m *4 ); + } +} +EXPORT_SYMBOL (sof_block_write); + +void sof_block_read (struct snd_sof_dev *sdev,u32 bar,u32 offset,void *dest, +size_t size) +{ +void __iomem *src = sdev->bar[bar] + offset; + +memcpy_fromio (dest, src, size); +} +EXPORT_SYMBOL (sof_block_read);
Signature · 1 line
2.17.1
Re: [PATCH v4 14/14] ASoC: SOF: Add utils
Quoted 14 lines · Pierre-Louis Bossart
sound/soc/sof/utils.c new file +13
-0+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)
sound/soc/sof/utils.c line 43
Quoted 10 lines
sound/soc/sof/utils.c new file +10
-0+{ +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);
What's the merit of these wrappers?
Even if they are good for consistency, they can be well inlined.
thanks,
Takashi
Re: [PATCH v4 14/14] ASoC: SOF: Add utils
Quoted 22 lines · Takashi Iwai
Quoted 19 lines · Pierre-Louis Bossart
sound/soc/sof/utils.c new file +18
-0+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); +
Quoted 8 lines
sound/soc/sof/utils.c line 43
Quoted 5 lines
sound/soc/sof/utils.c new file +5
-0+u64 sof_io_read64 (struct snd_sof_dev *sdev,void __iomem *addr) +{ +return readq (addr); +} +EXPORT_SYMBOL (sof_io_read64);What's the merit of these wrappers?
Even if they are good for consistency, they can be well inlined.
OK, now it's clear after reading the other series.
It'd be helpful to add some notes mentioning that these are commonly set to snd_sof_dsp_ops.
thanks,
Takashi
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware by drivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication through drivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Many vendor(TI, Qualcomm, ST, NXP, Xilinx...) migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism? Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel driver model(rpsmg_bus, rpmsg_device and rpmsg_driver).
4.Support by many RTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...) for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.
Thanks
Xiang
Quoted 6 lines · Xiang Xiao
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Quoted 14 lines
Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel drivermodel(rpsmg_bus, rpmsg_device and rpmsg_driver). 4.Support by manyRTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...)for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.
Quoted 7 lines
Thanks
Xiang
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
--srini
Quoted 11 lines · Srinivas Kandagatla
Quoted 6 lines · Xiang Xiao
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?
Quoted 5 lines
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystem
Quoted 22 lines
Quoted 14 lines
Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel drivermodel(rpsmg_bus, rpmsg_device and rpmsg_driver). 4.Support by manyRTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...)for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.Quoted 7 lines
Thanks
Xiang
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel--srini
Quoted 16 lines · xiang xiao
Quoted 9 lines · Srinivas Kandagatla
Quoted 6 lines · Xiang Xiao
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?Quoted 5 lines
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Quoted 14 lines
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystem
The IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
There are other paths such as using the mailbox framework, and at the end of the day the IPC is likely going to be a configurable element where integrators pick what's best for them. If you strongly believe that the RPMSG framework is the way to go, there is a public github and you can contribute the relevant changes with both kernel and firmware patches.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel drivermodel(rpsmg_bus, rpmsg_device and rpmsg_driver). 4.Support by manyRTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...)for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.
As stated above there is no opposition to using fancier/more generic IPC solutions, but they have to be considered as evolutions and follow the due process of contributions/reviews plus be aligned with product timelines.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Hi Pierre,
Quoted 39 lines · Pierre-Louis Bossart
Quoted 16 lines · xiang xiao
Quoted 9 lines · Srinivas Kandagatla
Quoted 6 lines · Xiang Xiao
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?Quoted 5 lines
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Quoted 14 lines
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
Quoted 7 lines
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
Quoted 16 lines
There are other paths such as using the mailbox framework, and at the end of the day the IPC is likely going to be a configurable element where integrators pick what's best for them. If you strongly believe that the RPMSG framework is the way to go, there is a public github and you can contribute the relevant changes with both kernel and firmware patches.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel drivermodel(rpsmg_bus, rpmsg_device and rpmsg_driver). 4.Support by manyRTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...)for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite
^^^
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.As stated above there is no opposition to using fancier/more generic IPC solutions, but they have to be considered as evolutions and follow the due process of contributions/reviews plus be aligned with product timelines.
Sorry but upstream cares more about doing the right things rather than vendor timelines..
Signature · 1 line
~Vinod
Hello,
Quoted 55 lines · Vinod Koul
Hi Pierre,
Quoted 39 lines · Pierre-Louis Bossart
Quoted 16 lines · xiang xiao
Quoted 9 lines · Srinivas Kandagatla
Quoted 6 lines · Xiang Xiao
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?Quoted 5 lines
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Quoted 14 lines
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if other vendor already adopt remote/rpmsg(this is already a trend!). b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
Quoted 7 lines
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
Quoted 7 lines
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
Just for information... ST Microelectronics plans to port SOF to at least one of its platforms (based on ARM cores). Today, for the co-processor management we use the rpmsg and remoteproc frameworks on the Linux kernel side and OpenAMP on the remote processor side. We are therefore interested in xiang's work.
An advantage we see in this generic solution is that compatibility between the Linux kernel frameworks and the OpenAMP library is ensured through discussions in the Linux and OpenAMP communities, involving maintainers and several vendors.
Regards
Arnaud
Quoted 25 lines
Quoted 17 lines
There are other paths such as using the mailbox framework, and at the end of the day the IPC is likely going to be a configurable element where integrators pick what's best for them. If you strongly believe that the RPMSG framework is the way to go, there is a public github and you can contribute the relevant changes with both kernel and firmware patches.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Actually, remoteproc/rpmsg is much better than SOF IPC because:
1.Completely isolate the firmware load and message transfer:
The same rpmsg driver could run on any remote processor
2.Separate the application protocol from transfer layer:
One remote processor could host many rpmsg services
3.Completely follow kernel drivermodel(rpsmg_bus, rpmsg_device and rpmsg_driver). 4.Support by manyRTOS(Bare Metal, FreeRTOS, Zephyr, NuttX, Nucleus, uC/OS...)for remote side:
https://github.com/OpenAMP/open-amp
https://github.com/NXPmicro/rpmsg-lite^^^
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
5.Maintained by the standard committee:
https://www.multicore-association.org/workgroup/oamp.php
https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=virtio
Since the keypoint of SOF is the platform agnostic and modular, please use the standard technique here.
Quoted 9 lines
Quoted 3 lines
As stated above there is no opposition to using fancier/more generic IPC solutions, but they have to be considered as evolutions and follow the due process of contributions/reviews plus be aligned with product timelines.
Sorry but upstream cares more about doing the right things rather than vendor timelines..
Signature · 1 line
~Vinod
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerQuoted 17 lines · Arnaud Pouliquen
Quoted 8 lines · Vinod Koul
Quoted 1 line · Pierre-Louis Bossart
On 2/19/19 9:09 AM, xiang xiao wrote:
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
Quoted 7 lines
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
Quoted 9 lines
Just for information... ST Microelectronics plans to port SOF to at least one of its platforms (based on ARM cores). Today, for the co-processor management we use the rpmsg and remoteproc frameworks on the Linux kernel side and OpenAMP on the remote processor side. We are therefore interested in xiang's work.
An advantage we see in this generic solution is that compatibility between the Linux kernel frameworks and the OpenAMP library is ensured through discussions in the Linux and OpenAMP communities, involving maintainers and several vendors.
This is a very good point, especially with people actually jumping on it if we can avoid having multiple ABIs to worry about that would make life a lot easier. We should at least figure out if it will be disruptive to adapt it later on, even if Intel ends up continuing to use a custom system integration.
Quoted 10 lines
Quoted 10 lines
Just for information... ST Microelectronics plans to port SOF to at least one of its platforms (based on ARM cores). Today, for the co-processor management we use the rpmsg and remoteproc frameworks on the Linux kernel side and OpenAMP on the remote processor side. We are therefore interested in xiang's work.
An advantage we see in this generic solution is that compatibility between the Linux kernel frameworks and the OpenAMP library is ensured through discussions in the Linux and OpenAMP communities, involving maintainers and several vendors.
Thanks Arnaud for sharing this information. You made my day. We've had to deal with a number of hurdles related to platform and tools availability, so it's good news indeed if there are more platforms endorsing SOF.
Quoted 5 lines
This is a very good point, especially with people actually jumping on it if we can avoid having multiple ABIs to worry about that would make life a lot easier. We should at least figure out if it will be disruptive to adapt it later on, even if Intel ends up continuing to use a custom system integration.
Yes indeed. At a high level we only have very generic send/receive IPC messages, and it really shouldn't matter how the transport happens. However the actual contents/semantics of the messages do matter, and I'll have to run a check to make sure it scales.
Quoted 44 lines
Quoted 32 lines
Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?Quoted 5 lines
It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Quoted 14 lines
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
Quoted 7 lines
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
Quoted 7 lines
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication. The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
In short, I don't mind looking at RPMsg as an option and would welcome contributions, but making it the default raises a number of technical challenges that can't be dismissed just yet, and such a transition isn't going to happen overnight. There are other evolutions that were mentioned as well, such as using the MFD framework to split the driver in 'core/hardware' support and application-specific parts (audio, sensors, etc), and likewise we need time to make it happen - just like we need time to move to the modern dailinks, add multi-cpu and SoundWire support, add digital domains, etc.
[1] http://processors.wiki.ti.com/index.php/PRU-ICSS_Remoteproc_and_RPMsg
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 50 lines · Pierre-Louis Bossart
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Quoted 7 lines
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication.
rpmsg support to define the custom mechanism(see rpmsg_endpoint_ops in drivers\rpmsg\rpmsg_internal.h) but keep the upper layer API, qcomm utilize this for glink and smd actually.
Quoted 2 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)
Quoted 6 lines
In short, I don't mind looking at RPMsg as an option and would welcome contributions, but making it the default raises a number of technical challenges that can't be dismissed just yet, and such a transition isn't going to happen overnight. There are other evolutions that were mentioned as well, such as using the MFD framework to split the driver in 'core/hardware' support and application-specific parts (audio, sensors, etc), and likewise we need time to make it happen - just like we need time to move to the modern dailinks, add multi-cpu and SoundWire support, add digital domains, etc.
[1] http://processors.wiki.ti.com/index.php/PRU-ICSS_Remoteproc_and_RPMsg
Quoted 55 lines · xiang xiao
Quoted 53 lines · Pierre-Louis Bossart
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
Quoted 8 lines
Quoted 4 lines
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication.
rpmsg support to define the custom
mechanism(see rpmsg_endpoint_ops in drivers\rpmsg\rpmsg_internal.h)but keep the upper layer API, qcomm utilize this for glink and smd actually.
Then this looks doable, thanks for sharing Xiang.
I have several questions:
1. Is virtio device and vring buffer access support in remote proc(Audio DSP in our case) side mandatory? Which means we have to porting libraries like libAMP into FW(not uses Zephyr or freeRTOS yet)?
2. About the resource table in FW binary, is this mandatory or it could be empty?
As you may know, we uses SOF-similar IPC framework(which is quite different with rpmsg/remoteproc) on Intel SoC platforms for long on tens of platforms of several generations(we have enabled and verified SOF on most of them), so the transition may take time.
Thanks,
~Keyon
Quoted 20 lines
Quoted 3 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)Quoted 6 lines
In short, I don't mind looking at RPMsg as an option and would welcome contributions, but making it the default raises a number of technical challenges that can't be dismissed just yet, and such a transition isn't going to happen overnight. There are other evolutions that were mentioned as well, such as using the MFD framework to split the driver in 'core/hardware' support and application-specific parts (audio, sensors, etc), and likewise we need time to make it happen - just like we need time to move to the modern dailinks, add multi-cpu and SoundWire support, add digital domains, etc.
[1] http://processors.wiki.ti.com/index.php/PRU-ICSS_Remoteproc_and_RPMsg
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 68 lines · Keyon Jie
Quoted 55 lines · xiang xiao
Quoted 53 lines · Pierre-Louis Bossart
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
Quoted 8 lines
Quoted 4 lines
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication.
rpmsg support to define the custom
mechanism(see rpmsg_endpoint_ops in drivers\rpmsg\rpmsg_internal.h)but keep the upper layer API, qcomm utilize this for glink and smd actually.
Quoted 6 lines
Then this looks doable, thanks for sharing Xiang.
I have several questions:
1. Is virtio device and vring buffer access support in remote proc(Audio DSP in our case) side mandatory? Which means we have to porting libraries like libAMP into FW(not uses Zephyr or freeRTOS yet)?
If you go through viritio/rpmsg path, virtio/vring are required, but if you implement the new rpmsg_endpoint_ops, both shouldn't be needed. But both OpenAMP/RPMsg-Lite support the bare metal environment, actually since both library define the clean and thin port layer, it's very easy to port(I just spend 2-3 days for NuttX port).
Quoted 2 lines
2. About the resource table in FW binary, is this mandatory or it could be empty?
Again virtio/rpmsg path is required, but custom implementation mayn't needed. Actually, remoteproc layer support the custom firmware format, so SOF can migrate to remoteproc without changing firmware format.
Quoted 6 lines
As you may know, we uses SOF-similar IPC framework(which is quite different with rpmsg/remoteproc) on Intel SoC platforms for long on tens of platforms of several generations(we have enabled and verified SOF on most of them), so the transition may take time.
Yes, I understand. But Intel still could provide the current version to the customer before the new IPC version is stable if many people think the generic IPC is the good direction to go.
Quoted 23 lines
Thanks,
~KeyonQuoted 20 lines
Quoted 3 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)Quoted 6 lines
In short, I don't mind looking at RPMsg as an option and would welcome contributions, but making it the default raises a number of technical challenges that can't be dismissed just yet, and such a transition isn't going to happen overnight. There are other evolutions that were mentioned as well, such as using the MFD framework to split the driver in 'core/hardware' support and application-specific parts (audio, sensors, etc), and likewise we need time to make it happen - just like we need time to move to the modern dailinks, add multi-cpu and SoundWire support, add digital domains, etc.
[1] http://processors.wiki.ti.com/index.php/PRU-ICSS_Remoteproc_and_RPMsg
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 8 lines · xiang xiao
Quoted 6 lines · Keyon Jie
Then this looks doable, thanks for sharing Xiang.
I have several questions:
1. Is virtio device and vring buffer access support in remote proc(Audio DSP in our case) side mandatory? Which means we have to porting libraries like libAMP into FW(not uses Zephyr or freeRTOS yet)?
Quoted 5 lines
If you go through viritio/rpmsg path, virtio/vring are required, but if you implement the new
rpmsg_endpoint_ops, both shouldn't be needed. But both OpenAMP/RPMsg-Lite support the bare metal environment, actually since both library define the clean and thin port layer, it's very easy to port(I just spend 2-3 days for NuttX port).
Thanks for sharing, that's good if it is possible to go without virtio support at the first step, we will do investigation based on code you shared.
Quoted 7 lines
Quoted 3 lines
2. About the resource table in FW binary, is this mandatory or it could be empty?
Again virtio/rpmsg path is required, but custom implementation mayn't needed. Actually, remoteproc layer support the custom firmware format, so SOF can migrate to remoteproc without changing firmware format.
Good to know this, thanks.
Thanks,
~Keyon
Quoted 18 lines
Quoted 7 lines
As you may know, we uses SOF-similar IPC framework(which is quite different with rpmsg/remoteproc) on Intel SoC platforms for long on tens of platforms of several generations(we have enabled and verified SOF on most of them), so the transition may take time.
Yes, I understand. But Intel still could provide the current version to the customer before the new IPC version is stable if many people think the generic IPC is the good direction to go.
Quoted 6 lines
Thanks,
~KeyonQuoted 3 lines
Quoted 3 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
Quoted 54 lines · xiang xiao
Quoted 52 lines · Pierre-Louis Bossart
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
Quoted 7 lines
Quoted 4 lines
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication.
rpmsg support to define the custom
mechanism(see rpmsg_endpoint_ops in drivers\rpmsg\rpmsg_internal.h)but keep the upper layer API, qcomm utilize this for glink and smd actually.
That's interesting. Can anyone at Qualcomm/Linaro point to actual examples of the implementation, so that we get a better picture of the split between 'upper layer API' and 'custom mechanism'?
Quoted 7 lines
Quoted 3 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)
Sure. Where's the code? What's the license?
Most of the SOF code is really in hardware-specific .ops callbacks and topology handling, the generic IPC layer is only ~800 lines of code. rpmsg would allow for easier portability but a significant reduction of the code size is unlikely.
Quoted 70 lines · Pierre-Louis Bossart
Quoted 54 lines · xiang xiao
Quoted 52 lines · Pierre-Louis Bossart
Should we utilize official IPC frameowrk instead reinverting the wheel?
1.Load firmware bydrivers/remoteproc
https://www.kernel.org/doc/Documentation/remoteproc.txt
2.Do the comunication throughdrivers/rpmsg
https://www.kernel.org/doc/Documentation/rpmsg.txt
Manyvendor(TI, Qualcomm, ST, NXP, Xilinx...)migrate to remoteproc/rpmsg, why Intel provide an other IPC mechanism?It definitely makes more sense to use rpmsg for Generic IPC driver here.
Qualcomm DSP audio drivers (non SOF) already use rpmsg. This will definitely help everyone in future while immigrating to SOF.
Actually, Xiaomi also build DSP audio driver on top of rpmsg, but fully integrate with the ASoC topology framework, and the firmware is base on FreeRTOS and OpenMAX.
SOF initiative is very good and exciting, our team members(include me) spend a couple weeks to study the current code base on both firmware and kernel side, we even port SOF to our DSP/MCU and make it run, but I have to point out that:
SOF IPC is too simple and rigid, tightly couple with Intel platform and audio domain, which make:
a.It's difficult to integrate with other vendor SoC, especially if
other vendor already adopt remote/rpmsg(this is already a trend!).
b.It's difficult to add other IPC services for example:
i.Audio DSP talk to power MCU to adjust clock and voltage ii.Export ultrasonic distance measurement to IIO subsystemThe IPC scheme suggested in this patchset is only a first pass that works on 3 generations on Intel platforms + the QEMU parts. There are no claims that the current solution is set-in-stone, and this is already an area where things are already changing to support notifications and low-power transitions.
There will clearly be evolutions to make the IPC more flexible/generic, but we've got to start somewhere and bear in mind that we also have to support memory-constrained legacy devices where such generic frameworks aren't needed or even implementable. Some of your proposals such as changing power/clocks with a firmware request aren't necessarily possible or recommended on all platforms - i can already hear security folks howling, this was already mentioned in the GitHub thread.
Rather than evolve the IPC, i would say it makes more sense that we "reuse" existing upstream frameworks.. As given below by xiang this seems to have support for RTOSes (see point 4 below) and looking at below it seems to have much better coverage across systems.
This should also help in easy adoption of SoF for non Intel people...
Also looking at it, lot of IPC code, DSP loading etc would go away making SoF code lesser in footprint.
Quoted 7 lines
Quoted 4 lines
I think benefits outweigh the effort of porting to a framework which is already upstream and used on many platforms for different vendors!
There is no free lunch. There are 'features' of RPMsg which aren't necessarily great for all platforms, e.g. the concepts of virtio-like rings for IPC with available/used buffers for both directions are not a good match or replacement for the memory-window-based IPC on Intel platforms, where there is no DDR access, a small window allocated by firmware and only a couple of doorbell registers for essentially serial communication.
rpmsg support to define the custom
mechanism(see rpmsg_endpoint_ops in drivers\rpmsg\rpmsg_internal.h)but keep the upper layer API, qcomm utilize this for glink and smd actually.That's interesting. Can anyone at Qualcomm/Linaro point to actual examples of the implementation, so that we get a better picture of the split between 'upper layer API' and 'custom mechanism'?
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
The resources embedded in a firmware file is another capability that doesn't align with the way the SOF firmware is generated. I also don't know where the topology file would be handled, nor how to deal with suspend-resume where the DSP needs to be restarted. For folks who need an introduction to RPMsg, the link [1] is the best I found to scope out the work required.
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)Sure. Where's the code? What's the license?
The code is base on 4.19 kernel, I could upstream the code basing on the latest kernel in the next couple days for reference. the license is GPL, of course.
Quoted 5 lines
Most of the SOF code is really in hardware-specific .ops callbacks and topology handling, the generic IPC layer is only ~800 lines of code. rpmsg would allow for easier portability but a significant reduction of the code size is unlikely.
The reduce come from:
1.Move firmware load and dsp start/stop to remoteproc layer.
2.Move IPC buffer/mailbox to rpmsg layer.
3.Reuse ASoC topology parser to generate the audio graph.
4.Reuse ASoC DAMP to control the graph node state change(run/stop/pause/resume). 5.Use the general machine driver glue all individual components.
Quoted 1 line
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)Sure. Where's the code? What's the license?
The code is base on 4.19 kernel, I could upstream the code basing on the latest kernel in the next couple days for reference. the license is GPL, of course.
I'll be looking forward to the code. My turn to provide comments :-)
Quoted 9 lines
Quoted 6 lines
Most of the SOF code is really in hardware-specific .ops callbacks and topology handling, the generic IPC layer is only ~800 lines of code. rpmsg would allow for easier portability but a significant reduction of the code size is unlikely.
The reduce come from:
1.Move firmware load and dsp start/stop to remoteproc layer. 2.Move IPC buffer/mailbox to rpmsg layer.
You are not going to see a lot of code reduction here, at the end of the day most of the code comes from hardware-specific register access...
Quoted 3 lines
3.Reuse ASoC topology parser to generate the audio graph.
4.Reuse ASoC DAMP to control the graph node state change(run/stop/pause/resume). 5.Use the general machine driver glue all individual components
the last 3 points are already how SOF works, wondering if there is a misunderstanding... We are using topology/DAPM directly without any reinvention or duplication, as measured by the multiple fixes we provided to the frameworks in the last few weeks. Also when dedicated/custom topology tokens are needed, you still need code to deal with them and send the relevant configuration to firmware, whatever the transport format might be.
Quoted 28 lines · Pierre-Louis Bossart
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
We can share our rpmsg based topology implementation as reference which:
1.About 2500 lines(much less than SOF)
2.Support pcm and compress playback/capture
3.No any vendor dependence(thanks for rpmsg/remoteproc)Sure. Where's the code? What's the license?
The code is base on 4.19 kernel, I could upstream the code basing on the latest kernel in the next couple days for reference. the license is GPL, of course.
I'll be looking forward to the code. My turn to provide comments :-)
Quoted 9 lines
Quoted 6 lines
Most of the SOF code is really in hardware-specific .ops callbacks and topology handling, the generic IPC layer is only ~800 lines of code. rpmsg would allow for easier portability but a significant reduction of the code size is unlikely.
The reduce come from:
1.Move firmware load and dsp start/stop to remoteproc layer. 2.Move IPC buffer/mailbox to rpmsg layer.You are not going to see a lot of code reduction here, at the end of the day most of the code comes from hardware-specific register access...
Quoted 3 lines
3.Reuse ASoC topology parser to generate the audio graph.
4.Reuse ASoC DAMP to control the graph node state change(run/stop/pause/resume). 5.Use the general machine driver glue all individual components
Quoted 7 lines
the last 3 points are already how SOF works, wondering if there is a misunderstanding... We are using topology/DAPM directly without any reinvention or duplication, as measured by the multiple fixes we provided to the frameworks in the last few weeks. Also when dedicated/custom topology tokens are needed, you still need code to deal with them and send the relevant configuration to firmware, whatever the transport format might be.
Here is the patch(~2800 lines) just for reference only:
https://github.com/xiaoxiang781216/linux/commit/077aad71ef153212ddb25cba71082d3ecd684f02
I attach a presentation in the commit to help understand the whole picture:
1.There is a tplg rpmsg driver for each machine:
a.DSP create a rpmsg channel named "rpmsg-audio"
b.rpmsg subsystem create a new rpmsg device and bind to tplg rpmsg driver c.tplg rpmsg probe callback load the topology file from user space d.Forward widget create and route to DSP for graph generation e.Forward kcontrol get/set to DSP for widget parameter operation
Note: widget name is used to locate the widget in DSP.
2.For each FE/BE/COMPR, a new rpmsg based platform driver is created:
a.Each platform driver create a new rpmsg channel to talk with the
remote peer
b.Forward snd_pcm_ops/snd_compr_ops to the remote peer
Note: widget name is used here as the channel name
Basically, 1(TPLG)+n(FE/BE/COMPR) rpmsg channels exist.
Quoted 5 lines · Pierre-Louis Bossart
Quoted 2 lines
drivers\rpmsg\rpmsg_internal.h) but keep the upper layer API, qcomm utilize this for glink and smd actually.
That's interesting. Can anyone at Qualcomm/Linaro point to actual examples of the implementation, so that we get a better picture of the split between 'upper layer API' and 'custom mechanism'?
Here is an example of Qualcomm Audio Hexagon DSP :
Remoteproc driver to start dsp is at:
Which registers rpmsg channels based of glink or SMD transport once dsp is booted at:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/rpmsg/qcom_glink_smem.c?h=v5.0-rc8 and few other files in drivers/rpmsg/
This rpmsg driver driver will create and destroy endpoints/edges/channels/services based on dsp services and dsp notifications. These notifications are passed to service drivers via rpmsg device driver model.
One example of audio service driver is:
and the audio drivers are at:
An example Device Tree of audio and DSP compute offload would look like this:
adsp-pil {
compatible = "qcom,msm8996-adsp-pil";
smd-edge {
label = "lpass";
mboxes = <&apcs_glb 8>;
qcom,smd-edge = <1>;
qcom,remote-pid = <2>;
apr {
compatible = "qcom,apr-v2";
qcom,smd-channels = "apr_audio_svc";
...
};
fastrpc {
qcom,smd-channels = "fastrpcsmd-apps-dsp";
compatible = "qcom,fastrpc";
...
}
...
};
};thanks,
srini