@@ -37,6 +37,22 @@ struct sof_ipc4_timestamp_info {
3737 snd_pcm_sframes_t delay ;
3838};
3939
40+ /**
41+ * struct sof_ipc4_pcm_stream_priv - IPC4 specific private data
42+ * @time_info: pointer to time info struct if it is supported, otherwise NULL
43+ */
44+ struct sof_ipc4_pcm_stream_priv {
45+ struct sof_ipc4_timestamp_info * time_info ;
46+ };
47+
48+ static inline struct sof_ipc4_timestamp_info *
49+ sof_ipc4_sps_to_time_info (struct snd_sof_pcm_stream * sps )
50+ {
51+ struct sof_ipc4_pcm_stream_priv * stream_priv = sps -> private ;
52+
53+ return stream_priv -> time_info ;
54+ }
55+
4056static int sof_ipc4_set_multi_pipeline_state (struct snd_sof_dev * sdev , u32 state ,
4157 struct ipc4_pipeline_set_state_data * trigger_list )
4258{
@@ -452,7 +468,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
452468 * Invalidate the stream_start_offset to make sure that it is
453469 * going to be updated if the stream resumes
454470 */
455- time_info = spcm -> stream [substream -> stream ]. private ;
471+ time_info = sof_ipc4_sps_to_time_info ( & spcm -> stream [substream -> stream ]) ;
456472 if (time_info )
457473 time_info -> stream_start_offset = SOF_IPC4_INVALID_STREAM_POSITION ;
458474
@@ -706,12 +722,16 @@ static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
706722static void sof_ipc4_pcm_free (struct snd_sof_dev * sdev , struct snd_sof_pcm * spcm )
707723{
708724 struct snd_sof_pcm_stream_pipeline_list * pipeline_list ;
725+ struct sof_ipc4_pcm_stream_priv * stream_priv ;
709726 int stream ;
710727
711728 for_each_pcm_streams (stream ) {
712729 pipeline_list = & spcm -> stream [stream ].pipeline_list ;
713730 kfree (pipeline_list -> pipelines );
714731 pipeline_list -> pipelines = NULL ;
732+
733+ stream_priv = spcm -> stream [stream ].private ;
734+ kfree (stream_priv -> time_info );
715735 kfree (spcm -> stream [stream ].private );
716736 spcm -> stream [stream ].private = NULL ;
717737 }
@@ -721,6 +741,7 @@ static int sof_ipc4_pcm_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm
721741{
722742 struct snd_sof_pcm_stream_pipeline_list * pipeline_list ;
723743 struct sof_ipc4_fw_data * ipc4_data = sdev -> private ;
744+ struct sof_ipc4_pcm_stream_priv * stream_priv ;
724745 struct sof_ipc4_timestamp_info * time_info ;
725746 bool support_info = true;
726747 u32 abi_version ;
@@ -749,6 +770,14 @@ static int sof_ipc4_pcm_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm
749770 return - ENOMEM ;
750771 }
751772
773+ stream_priv = kzalloc (sizeof (* stream_priv ), GFP_KERNEL );
774+ if (!stream_priv ) {
775+ sof_ipc4_pcm_free (sdev , spcm );
776+ return - ENOMEM ;
777+ }
778+
779+ spcm -> stream [stream ].private = stream_priv ;
780+
752781 if (!support_info )
753782 continue ;
754783
@@ -758,7 +787,7 @@ static int sof_ipc4_pcm_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm
758787 return - ENOMEM ;
759788 }
760789
761- spcm -> stream [ stream ]. private = time_info ;
790+ stream_priv -> time_info = time_info ;
762791 }
763792
764793 return 0 ;
@@ -795,7 +824,7 @@ static void sof_ipc4_build_time_info(struct snd_sof_dev *sdev, struct snd_sof_pc
795824 return ;
796825 }
797826
798- time_info = sps -> private ;
827+ time_info = sof_ipc4_sps_to_time_info ( sps ) ;
799828 time_info -> host_copier = host_copier ;
800829 time_info -> dai_copier = dai_copier ;
801830 time_info -> llp_offset = offsetof(struct sof_ipc4_fw_registers ,
@@ -849,7 +878,7 @@ static int sof_ipc4_pcm_hw_params(struct snd_soc_component *component,
849878 if (!spcm )
850879 return - EINVAL ;
851880
852- time_info = spcm -> stream [substream -> stream ]. private ;
881+ time_info = sof_ipc4_sps_to_time_info ( & spcm -> stream [substream -> stream ]) ;
853882 /* delay calculation is not supported by current fw_reg ABI */
854883 if (!time_info )
855884 return 0 ;
@@ -928,7 +957,7 @@ static int sof_ipc4_pcm_pointer(struct snd_soc_component *component,
928957 return - EOPNOTSUPP ;
929958
930959 sps = & spcm -> stream [substream -> stream ];
931- time_info = sps -> private ;
960+ time_info = sof_ipc4_sps_to_time_info ( sps ) ;
932961 if (!time_info )
933962 return - EOPNOTSUPP ;
934963
@@ -1030,15 +1059,13 @@ static snd_pcm_sframes_t sof_ipc4_pcm_delay(struct snd_soc_component *component,
10301059{
10311060 struct snd_soc_pcm_runtime * rtd = snd_soc_substream_to_rtd (substream );
10321061 struct sof_ipc4_timestamp_info * time_info ;
1033- struct snd_sof_pcm_stream * sps ;
10341062 struct snd_sof_pcm * spcm ;
10351063
10361064 spcm = snd_sof_find_spcm_dai (component , rtd );
10371065 if (!spcm )
10381066 return 0 ;
10391067
1040- sps = & spcm -> stream [substream -> stream ];
1041- time_info = sps -> private ;
1068+ time_info = sof_ipc4_sps_to_time_info (& spcm -> stream [substream -> stream ]);
10421069 /*
10431070 * Report the stored delay value calculated in the pointer callback.
10441071 * In the unlikely event that the calculation was skipped/aborted, the
0 commit comments