Skip to content

Conversation

@ranj063
Copy link
Collaborator

@ranj063 ranj063 commented Oct 30, 2022

Introduce SOF DAI ops to abstract the BE DAI widget DMA, codec_dai and dai_config ops. This change will allow adding the chained DMA mode or the DSP-less mode for the BE DAI widgets with a simple change like this:

diff --git a/sound/soc/sof/intel/hda-dai-ops.c b/sound/soc/sof/intel/hda-dai-ops.c
index 1d1e238d032e..1be992367a89 100644
--- a/sound/soc/sof/intel/hda-dai-ops.c
+++ b/sound/soc/sof/intel/hda-dai-ops.c
@@ -433,10 +433,19 @@ void hda_set_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swi
        }
        case SOF_INTEL_IPC4:
        {
+               struct snd_sof_widget *pipe_widget = swidget->pipe_widget;
                struct sof_ipc4_copier *ipc4_copier = sdai->private;
+               struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
+               struct snd_sof_dai_dma_ops *dma_ops = sdai->ops->dma_ops;
+
+               if (ipc4_copier->dai_type != SOF_DAI_INTEL_HDA)
+                       break;
+
+               if (pipeline->use_chain_dma) {
+                       dma_ops->pre_trigger = NULL;
+                       dma_ops->post_trigger = NULL;
+               }
 
-               if (ipc4_copier->dai_type == SOF_DAI_INTEL_HDA)
-                       sdai->ops = &hda_ipc4_dai_ops;
                break;
        }
        default:

Copy link
Member

@plbossart plbossart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063 I think you're on to something with the .pre and .post trigger.

I added a bunch of comments to try and help clarify the code, most of the changes are confusing due to naming aliases to different concepts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusion, if the ops are the same between IPC and IPC4 why do wee need the switch()?

Copy link
Collaborator Author

@ranj063 ranj063 Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for SSP and the NHLT for IPC4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really follow how the hw_free and post-trigger were related. The naming points to different phases in the ALSA world.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For IPC3, post_trigger does what hda_dai_hw_free_ipc(). For IPC4 also, we were doing the same and it made no sense. SO this patch actually fixes it

@ranj063 ranj063 force-pushed the fix/hda_dai_hw_params branch from e945284 to d56c49b Compare October 31, 2022 17:37
@ranj063 ranj063 requested a review from plbossart October 31, 2022 17:37
@ranj063 ranj063 force-pushed the fix/hda_dai_hw_params branch from d56c49b to ba07eb1 Compare October 31, 2022 18:08
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one variable per line?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are not initialized, so this is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's still better to have one variable per line for consistency.

plbossart
plbossart previously approved these changes Nov 17, 2022
Copy link
Member

@plbossart plbossart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we should probably do more testing overnight to see if we have any regressions, this is a rather intrusive patch.

Nice work @ranj063, I think this will help a lot clarify the sequences which were diluted with different ops and branches left and right.

@plbossart
Copy link
Member

@ujfalusi @RanderWang @bardliao @kv2019i @jsarha please prioritize this PR if you have a bit of time on Thursday 16, we are trying to complete this work before the Thanksgiving break. Friday will be too late for any interaction.

bardliao
bardliao previously approved these changes Nov 17, 2022
Copy link

@RanderWang RanderWang Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%#x to print hex number ? It does not block me.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the layout

unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS;
struct snd_sof_dai_config_data data = { 0 };
struct hdac_ext_stream *hext_stream;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to init nhlt in hda_set_dai_drv_ops ? It is not a issue in this PR. we remove the switch for ipc version but leave one if for ipc version

RanderWang
RanderWang previously approved these changes Nov 17, 2022
Copy link

@RanderWang RanderWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@ujfalusi ujfalusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063, this looks really nice!
The only thing holding me to Approve is that I can not follow optionality in struct hda_dai_widget_dma_ops.
assign_hext_stream is as mandatory as the get_hext_stream, which also brings the release_hext_stream as mandatory.
By the look, the other ops are really optional.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I would print error when the get_ext_stream is missing to make it more obvious.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got me here...
Only get_hext_stream is mandatory, which is to to retrieve the dma_data set by the optional assign_hext_stream.
If the assign_hext_stream is not set (optional!) and this is the first call here then the get_hext_stream is going to return with NULL and you are not going to get anything but NULL...

What I was saying is that most, if not all callbacks in struct hda_dai_widget_dma_ops are in fact mandatory, don't they?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also to note: you also must have the release_hext_stream defined if you have the assign_hext_stream, but you must need to have the assign_hext_stream in order to have working stack.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you should not return with error in line 118?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conclusion for this thread is that assign/release need to be optional because couple mode will not need them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: would look better two lines down..

ujfalusi
ujfalusi previously approved these changes Nov 17, 2022
Copy link
Collaborator

@ujfalusi ujfalusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063, I'm OK with few fixups (checkpatch).
Let's see how this will behave in the wild and under the DSPless and ChainDMA cases.

Introduce a new ops structure for HDA DAI widget DMA ops and add a new
field to struct snd_sof_dai that will be used to set the ops pointer for
DAI widgets.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define and set the get_hext_stream, assign_hext_stream and
release_hext_stream DMA ops for HDA DAIs.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
…A ops

Define and use the setup_hext_stream/reset_hext_stream DMA ops during link
hw_params and cleanup.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Use the topology IPC dai_config to update the dai_config for
HDA DAI widgets.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define and use the SOF widget's DMA pre_trigger/trigger/post_trigger ops in
ipc4_hda_dai_trigger().

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Define the post_trigger DMA op for IPC3 and unify the DAI driver ops for
IPC3 and IPC4 for HDA DAI's.

Also, use the post_trigger op to stop the paused streams properly in the
hda_dai_suspend() function. This fixes the suspend while paused case for
IPC4 because previously we weren't resetting the pipeline when suspending
the system with some paused streams.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Remove these functions and reuse hda_dai_config().

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
@ranj063 ranj063 dismissed stale reviews from ujfalusi, RanderWang, bardliao, and plbossart via ee710ae November 17, 2022 14:29
@ranj063 ranj063 force-pushed the fix/hda_dai_hw_params branch from 5c11a0f to ee710ae Compare November 17, 2022 14:29
@plbossart plbossart merged commit 1197769 into thesofproject:topic/sof-dev Nov 18, 2022
@ranj063 ranj063 deleted the fix/hda_dai_hw_params branch November 19, 2022 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants