Skip to content

Commit

Permalink
buf: move is_shared flag to audio_buffer structure
Browse files Browse the repository at this point in the history
is_shared is a flag indicating that a buffer is shared
between cores.
This property is common for all types of audio buffers and
should be kept in a base structure

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
marcinszkudlinski committed Sep 20, 2024
1 parent 2d92b98 commit c56abe1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, u
return NULL;
}

buffer->is_shared = is_shared;
buffer->caps = caps;

audio_buffer_init(&buffer->audio_buffer, BUFFER_TYPE_LEGACY_BUFFER, is_shared,
Expand Down
14 changes: 6 additions & 8 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ static void ring_buffer_free(struct sof_audio_buffer *buffer)
}

/**
* @brief return true if the queue is shared between 2 cores
* @brief return true if the ring buffer is shared between 2 cores
*/
static inline
bool ring_buffer_is_shared(struct ring_buffer *ring_buffer)
{
return !!(ring_buffer->_flags & RING_BUFFER_MODE_SHARED);
return audio_buffer_is_shared(&ring_buffer->audio_buffer);
}

static inline uint8_t __sparse_cache *ring_buffer_buffer_end(struct ring_buffer *ring_buffer)
Expand Down Expand Up @@ -278,13 +278,13 @@ static const struct audio_buffer_ops audio_buffer_ops = {
.free = ring_buffer_free,
};

struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, uint32_t flags,
struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, bool is_shared,
uint32_t id)
{
struct ring_buffer *ring_buffer;

/* allocate ring_buffer structure */
if (flags & RING_BUFFER_MODE_SHARED)
if (is_shared)
ring_buffer = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM,
sizeof(*ring_buffer));
else
Expand All @@ -293,17 +293,15 @@ struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_spa
if (!ring_buffer)
return NULL;

ring_buffer->_flags = flags;

/* init base structure. The audio_stream_params is NULL because ring_buffer
* is currently used as a secondary buffer for DP only
*
* pointer in audio_buffer will be overwritten when attaching ring_buffer as a
* secondary buffer
*/
audio_buffer_init(&ring_buffer->audio_buffer, BUFFER_TYPE_RING_BUFFER,
flags & RING_BUFFER_MODE_SHARED, &ring_buffer_source_ops,
&ring_buffer_sink_ops, &audio_buffer_ops, NULL);
is_shared, &ring_buffer_source_ops, &ring_buffer_sink_ops,
&audio_buffer_ops, NULL);

/* set obs/ibs in sink/source interfaces */
sink_set_min_free_space(audio_buffer_get_sink(&ring_buffer->audio_buffer),
Expand Down
8 changes: 8 additions & 0 deletions src/include/sof/audio/audio_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct sof_audio_buffer {
/* type of the buffer BUFFER_TYPE_* */
uint32_t buffer_type;

bool is_shared; /* buffer structure is shared between 2 cores */

#if CONFIG_PIPELINE_2_0
/**
* sink API of an additional buffer
Expand Down Expand Up @@ -166,6 +168,11 @@ struct sof_source *audio_buffer_get_source(struct sof_audio_buffer *buffer)

#endif /* CONFIG_PIPELINE_2_0 */

static inline bool audio_buffer_is_shared(struct sof_audio_buffer *buffer)
{
return buffer->is_shared;
}

/**
* @brief return a handler to stream params structure
*/
Expand Down Expand Up @@ -216,6 +223,7 @@ void audio_buffer_init(struct sof_audio_buffer *buffer, uint32_t buffer_type, bo
buffer->buffer_type = buffer_type;
buffer->ops = audio_buffer_ops;
buffer->audio_stream_params = audio_stream_params;
buffer->is_shared = is_shared;
source_init(audio_buffer_get_source(buffer), source_ops,
audio_buffer_get_stream_params(buffer));
sink_init(audio_buffer_get_sink(buffer), sink_ops,
Expand Down
5 changes: 2 additions & 3 deletions src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ struct comp_buffer {
uint32_t caps;
uint32_t core;
struct tr_ctx tctx; /* trace settings */
bool is_shared; /* buffer structure is shared between 2 cores */

/* connected components */
struct comp_dev *source; /* source component */
Expand Down Expand Up @@ -227,15 +226,15 @@ bool buffer_params_match(struct comp_buffer *buffer,
static inline void buffer_stream_invalidate(struct comp_buffer *buffer, uint32_t bytes)
{
#if CONFIG_INCOHERENT
if (buffer->is_shared)
if (audio_buffer_is_shared(&buffer->audio_buffer))
audio_stream_invalidate(&buffer->stream, bytes);
#endif
}

static inline void buffer_stream_writeback(struct comp_buffer *buffer, uint32_t bytes)
{
#if CONFIG_INCOHERENT
if (buffer->is_shared)
if (audio_buffer_is_shared(&buffer->audio_buffer))
audio_stream_writeback(&buffer->stream, bytes);
#endif
}
Expand Down
12 changes: 2 additions & 10 deletions src/include/sof/audio/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,13 @@
struct ring_buffer;
struct sof_audio_stream_params;

/* buffer flags */
#define RING_BUFFER_MODE_LOCAL 0
#define RING_BUFFER_MODE_SHARED BIT(1)

/* the ring_buffer structure */
struct ring_buffer {
/* public: read only */
struct sof_audio_buffer audio_buffer;

size_t data_buffer_size;

uint32_t _flags; /* RING_BUFFER_MODE_* */

uint8_t __sparse_cache *_data_buffer;
size_t _write_offset; /* private: to be modified by data producer using API */
size_t _read_offset; /* private: to be modified by data consumer using API */
Expand All @@ -126,13 +120,11 @@ struct ring_buffer {
* ring_buffer's source api
* @param min_free_space minimum buffer space in queue required by the module using
* ring_buffer's sink api
*
* @param flags a combinatin of RING_BUFFER_MODE_* flags determining working mode
*
* @param is_shared indicates if the buffer will be shared between cores
* @param id a stream ID, accessible later by sink_get_id/source_get_id
*
*/
struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, uint32_t flags,
struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, bool is_shared,
uint32_t id);

#endif /* __SOF_RING_BUFFER_H__ */
4 changes: 2 additions & 2 deletions src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ int comp_buffer_connect(struct comp_dev *comp, uint32_t comp_core,
if (buffer->core != comp_core) {
#if CONFIG_INCOHERENT
/* buffer must be shared */
assert(buffer->is_shared);
assert(audio_buffer_is_shared(&buffer->audio_buffer));
#else
buffer->is_shared = true;
buffer->audio_buffer.is_shared = true;
#endif
if (!comp->is_shared)
comp_make_shared(comp);
Expand Down
3 changes: 1 addition & 2 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,7 @@ int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)

ring_buffer = ring_buffer_create(source_get_min_available(source),
sink_get_min_free_space(sink),
buffer->is_shared ?
RING_BUFFER_MODE_SHARED : RING_BUFFER_MODE_LOCAL,
audio_buffer_is_shared(&buffer->audio_buffer),
buf_get_id(buffer));
if (!ring_buffer)
goto free;
Expand Down

0 comments on commit c56abe1

Please sign in to comment.