From 96d50688883566d9021e78e31577490971439a3d Mon Sep 17 00:00:00 2001 From: Baofeng Tian Date: Thu, 21 Dec 2023 15:50:12 +0800 Subject: [PATCH] Pipeline: move struct definition and inline function to header file This is a clean up, purpose is declutter headers, toml files, Readme.md etc per module basis, since today everything is scattered in current code base. Signed-off-by: Baofeng Tian --- src/audio/pipeline/pipeline-graph.c | 64 ---------------------------- src/include/sof/audio/pipeline.h | 65 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index 616d8349a1cf..9c48884b02cc 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -34,73 +34,9 @@ DECLARE_SOF_RT_UUID("pipe", pipe_uuid, 0x4e934adb, 0xb0ec, 0x4d33, DECLARE_TR_CTX(pipe_tr, SOF_UUID(pipe_uuid), LOG_LEVEL_INFO); -/* number of pipeline stream metadata objects we export in mailbox */ -#define PPL_POSN_OFFSETS \ - (MAILBOX_STREAM_SIZE / sizeof(struct sof_ipc_stream_posn)) - -/* lookup table to determine busy/free pipeline metadata objects */ -struct pipeline_posn { - bool posn_offset[PPL_POSN_OFFSETS]; /**< available offsets */ - struct k_spinlock lock; /**< lock mechanism */ -}; /* the pipeline position lookup table */ static SHARED_DATA struct pipeline_posn pipeline_posn_shared; -/** - * \brief Retrieves pipeline position structure. - * \return Pointer to pipeline position structure. - */ -static inline struct pipeline_posn *pipeline_posn_get(void) -{ - return sof_get()->pipeline_posn; -} - -/** - * \brief Retrieves first free pipeline position offset. - * \param[in,out] posn_offset Pipeline position offset to be set. - * \return Error code. - */ -static inline int pipeline_posn_offset_get(uint32_t *posn_offset) -{ - struct pipeline_posn *pipeline_posn = pipeline_posn_get(); - int ret = -EINVAL; - uint32_t i; - k_spinlock_key_t key; - - key = k_spin_lock(&pipeline_posn->lock); - - for (i = 0; i < PPL_POSN_OFFSETS; ++i) { - if (!pipeline_posn->posn_offset[i]) { - *posn_offset = i * sizeof(struct sof_ipc_stream_posn); - pipeline_posn->posn_offset[i] = true; - ret = 0; - break; - } - } - - - k_spin_unlock(&pipeline_posn->lock, key); - - return ret; -} - -/** - * \brief Frees pipeline position offset. - * \param[in] posn_offset Pipeline position offset to be freed. - */ -static inline void pipeline_posn_offset_put(uint32_t posn_offset) -{ - struct pipeline_posn *pipeline_posn = pipeline_posn_get(); - int i = posn_offset / sizeof(struct sof_ipc_stream_posn); - k_spinlock_key_t key; - - key = k_spin_lock(&pipeline_posn->lock); - - pipeline_posn->posn_offset[i] = false; - - k_spin_unlock(&pipeline_posn->lock, key); -} - void pipeline_posn_init(struct sof *sof) { sof->pipeline_posn = platform_shared_get(&pipeline_posn_shared, diff --git a/src/include/sof/audio/pipeline.h b/src/include/sof/audio/pipeline.h index 8dc5ea16d51d..593288313842 100644 --- a/src/include/sof/audio/pipeline.h +++ b/src/include/sof/audio/pipeline.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,16 @@ struct ipc_msg; #define PPL_DIR_DOWNSTREAM 0 #define PPL_DIR_UPSTREAM 1 +/* number of pipeline stream metadata objects we export in mailbox */ +#define PPL_POSN_OFFSETS \ + (MAILBOX_STREAM_SIZE / sizeof(struct sof_ipc_stream_posn)) + +/* lookup table to determine busy/free pipeline metadata objects */ +struct pipeline_posn { + bool posn_offset[PPL_POSN_OFFSETS]; /**< available offsets */ + struct k_spinlock lock; /**< lock mechanism */ +}; + /* * Audio pipeline. */ @@ -429,4 +440,58 @@ void pipeline_xrun(struct pipeline *p, struct comp_dev *dev, int32_t bytes); */ int pipeline_xrun_set_limit(struct pipeline *p, uint32_t xrun_limit_usecs); +/** + * \brief Retrieves pipeline position structure. + * \return Pointer to pipeline position structure. + */ +static inline struct pipeline_posn *pipeline_posn_get(void) +{ + return sof_get()->pipeline_posn; +} + +/** + * \brief Retrieves first free pipeline position offset. + * \param[in,out] posn_offset Pipeline position offset to be set. + * \return Error code. + */ +static inline int pipeline_posn_offset_get(uint32_t *posn_offset) +{ + struct pipeline_posn *pipeline_posn = pipeline_posn_get(); + int ret = -EINVAL; + uint32_t i; + k_spinlock_key_t key; + + key = k_spin_lock(&pipeline_posn->lock); + + for (i = 0; i < PPL_POSN_OFFSETS; ++i) { + if (!pipeline_posn->posn_offset[i]) { + *posn_offset = i * sizeof(struct sof_ipc_stream_posn); + pipeline_posn->posn_offset[i] = true; + ret = 0; + break; + } + } + + k_spin_unlock(&pipeline_posn->lock, key); + + return ret; +} + +/** + * \brief Frees pipeline position offset. + * \param[in] posn_offset Pipeline position offset to be freed. + */ +static inline void pipeline_posn_offset_put(uint32_t posn_offset) +{ + struct pipeline_posn *pipeline_posn = pipeline_posn_get(); + int i = posn_offset / sizeof(struct sof_ipc_stream_posn); + k_spinlock_key_t key; + + key = k_spin_lock(&pipeline_posn->lock); + + pipeline_posn->posn_offset[i] = false; + + k_spin_unlock(&pipeline_posn->lock, key); +} + #endif /* __SOF_AUDIO_PIPELINE_H__ */