@@ -27,7 +27,8 @@ DECLARE_SOF_RT_UUID("buffer", buffer_uuid, 0x42544c92, 0x8e92, 0x4e41,
2727 0xb6 , 0x79 , 0x34 , 0x51 , 0x9f , 0x1c , 0x1d , 0x28 );
2828DECLARE_TR_CTX (buffer_tr , SOF_UUID (buffer_uuid ), LOG_LEVEL_INFO );
2929
30- struct comp_buffer * buffer_alloc (uint32_t size , uint32_t caps , uint32_t flags , uint32_t align )
30+ struct comp_buffer * buffer_alloc (uint32_t size , uint32_t caps , uint32_t flags , uint32_t align ,
31+ bool is_shared )
3132{
3233 struct comp_buffer * buffer ;
3334 struct comp_buffer __sparse_cache * buffer_c ;
@@ -42,16 +43,17 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
4243 return NULL ;
4344 }
4445
45- /*
46- * allocate new buffer, align the allocation size to a cache line for
47- * the coherent API
48- */
49- buffer = coherent_init_thread ( struct comp_buffer , c );
46+ /* allocate new buffer */
47+ enum mem_zone zone = is_shared ? SOF_MEM_ZONE_RUNTIME_SHARED : SOF_MEM_ZONE_RUNTIME ;
48+
49+ buffer = rzalloc ( zone , 0 , SOF_MEM_CAPS_RAM , sizeof ( * buffer ));
50+
5051 if (!buffer ) {
5152 tr_err (& buffer_tr , "buffer_alloc(): could not alloc structure" );
5253 return NULL ;
5354 }
5455
56+ buffer -> is_shared = is_shared ;
5557 stream_addr = rballoc_align (0 , caps , size , align );
5658 if (!stream_addr ) {
5759 rfree (buffer );
@@ -70,18 +72,6 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u
7072
7173 buffer_release (buffer_c );
7274
73- /*
74- * The buffer hasn't yet been marked as shared, hence buffer_release()
75- * hasn't written back and invalidated the cache. Therefore we have to
76- * do this manually now before adding to the lists. Buffer list
77- * structures are always accessed uncached and they're never modified at
78- * run-time, i.e. buffers are never relinked. So we have to make sure,
79- * that what we have written into buffer's cache is in RAM before
80- * modifying that RAM bypassing cache, and that after this cache is
81- * re-loaded again.
82- */
83- dcache_writeback_invalidate_region (uncache_to_cache (buffer ), sizeof (* buffer ));
84-
8575 list_init (& buffer -> source_list );
8676 list_init (& buffer -> sink_list );
8777
@@ -303,30 +293,7 @@ void comp_update_buffer_consume(struct comp_buffer __sparse_cache *buffer, uint3
303293void buffer_attach (struct comp_buffer * buffer , struct list_item * head , int dir )
304294{
305295 struct list_item * list = buffer_comp_list (buffer , dir );
306- struct list_item __sparse_cache * needs_sync ;
307- bool further_buffers_exist ;
308-
309- /*
310- * There can already be buffers on the target list. If we just link this
311- * buffer, we modify the first buffer's list header via uncached alias,
312- * so its cached copy can later be written back, overwriting the
313- * modified header. FIXME: this is still a problem with different cores.
314- */
315- further_buffers_exist = !list_is_empty (head );
316- needs_sync = uncache_to_cache (head -> next );
317- if (further_buffers_exist )
318- dcache_writeback_region (needs_sync , sizeof (struct list_item ));
319- /* The cache line can be prefetched here, invalidate it after prepending */
320296 list_item_prepend (list , head );
321- if (further_buffers_exist )
322- dcache_invalidate_region (needs_sync , sizeof (struct list_item ));
323- #if CONFIG_INTEL
324- /*
325- * Until now the buffer object wasn't in cache, but uncached access to it could have
326- * triggered a cache prefetch. Drop that cache line to avoid using stale data in it.
327- */
328- dcache_invalidate_region (uncache_to_cache (list ), sizeof (* list ));
329- #endif
330297}
331298
332299/*
@@ -335,32 +302,6 @@ void buffer_attach(struct comp_buffer *buffer, struct list_item *head, int dir)
335302 */
336303void buffer_detach (struct comp_buffer * buffer , struct list_item * head , int dir )
337304{
338- struct list_item __sparse_cache * needs_sync_prev , * needs_sync_next ;
339- bool buffers_after_exist , buffers_before_exist ;
340305 struct list_item * buf_list = buffer_comp_list (buffer , dir );
341-
342- /*
343- * There can be more buffers linked together with this one, that will
344- * still be staying on their respective pipelines and might get used via
345- * their cached aliases. If we just unlink this buffer, we modify their
346- * list header via uncached alias, so their cached copy can later be
347- * written back, overwriting the modified header. FIXME: this is still a
348- * problem with different cores.
349- */
350- buffers_after_exist = head != buf_list -> next ;
351- buffers_before_exist = head != buf_list -> prev ;
352- needs_sync_prev = uncache_to_cache (buf_list -> prev );
353- needs_sync_next = uncache_to_cache (buf_list -> next );
354- if (buffers_after_exist )
355- dcache_writeback_region (needs_sync_next , sizeof (struct list_item ));
356- if (buffers_before_exist )
357- dcache_writeback_region (needs_sync_prev , sizeof (struct list_item ));
358- dcache_writeback_region (uncache_to_cache (buf_list ), sizeof (* buf_list ));
359- /* buffers before or after can be prefetched here */
360306 list_item_del (buf_list );
361- dcache_invalidate_region (uncache_to_cache (buf_list ), sizeof (* buf_list ));
362- if (buffers_after_exist )
363- dcache_invalidate_region (needs_sync_next , sizeof (struct list_item ));
364- if (buffers_before_exist )
365- dcache_invalidate_region (needs_sync_prev , sizeof (struct list_item ));
366307}
0 commit comments