Skip to content

Commit 597a211

Browse files
Merge branch 'main' into main
Signed-off-by: Sivasubramanian678 <sravisar@amd.com>
2 parents 6453feb + 8d75e2c commit 597a211

48 files changed

Lines changed: 889 additions & 594 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/audio/base_fw_intel.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static const struct device *uaol_devs[] = {
109109
DT_FOREACH_STATUS_OKAY(intel_adsp_uaol, DEV_AND_COMMA)
110110
};
111111

112-
static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
112+
#if !CONFIG_SOF_OS_LINUX_COMPAT_PRIORITY
113+
__cold static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
113114
{
114115
const size_t dev_count = ARRAY_SIZE(uaol_devs);
115116
struct uaol_capabilities dev_cap;
@@ -118,6 +119,8 @@ static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
118119
size_t i;
119120
int ret;
120121

122+
assert_can_be_cold();
123+
121124
memset(caps, 0, caps_size);
122125

123126
caps->link_count = dev_count;
@@ -135,12 +138,15 @@ static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
135138

136139
tlv_value_set(tuple, type, caps_size, caps);
137140
}
141+
#endif /* CONFIG_SOF_OS_LINUX_COMPAT_PRIORITY */
138142

139-
static int uaol_stream_id_to_hda_link_stream_id(int uaol_stream_id)
143+
__cold static int uaol_stream_id_to_hda_link_stream_id(int uaol_stream_id)
140144
{
141145
size_t dev_count = ARRAY_SIZE(uaol_devs);
142146
size_t i;
143147

148+
assert_can_be_cold();
149+
144150
for (i = 0; i < dev_count; i++) {
145151
int hda_link_stream_id = uaol_get_mapped_hda_link_stream_id(uaol_devs[i],
146152
uaol_stream_id);

src/audio/buffers/comp_buffer.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <rtos/interrupt.h>
1717
#include <rtos/alloc.h>
1818
#include <rtos/cache.h>
19+
#include <sof/lib/vregion.h>
1920
#include <sof/list.h>
2021
#include <sof/schedule/dp_schedule.h>
2122
#include <rtos/spinlock.h>
@@ -146,22 +147,22 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
146147

147148
struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);
148149

149-
buf_dbg(buffer, "buffer_free()");
150+
buf_dbg(buffer, "entry");
150151

151152
#if CONFIG_PROBE
152153
if (buffer->probe_cb_free)
153154
buffer->probe_cb_free(buffer->probe_cb_arg);
154155
#endif
155156

156-
struct k_heap *heap = buffer->audio_buffer.heap;
157+
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;
157158

158159
rfree(buffer->stream.addr);
159-
sof_heap_free(heap, buffer);
160-
if (heap) {
161-
struct dp_heap_user *mod_heap_user = container_of(heap, struct dp_heap_user, heap);
162-
163-
if (!--mod_heap_user->client_count)
164-
rfree(mod_heap_user);
160+
if (alloc && alloc->vreg) {
161+
vregion_free(alloc->vreg, buffer);
162+
if (!vregion_put(alloc->vreg))
163+
rfree(alloc);
164+
} else {
165+
sof_heap_free(alloc ? alloc->heap : NULL, buffer);
165166
}
166167
}
167168

@@ -192,19 +193,24 @@ static const struct audio_buffer_ops audio_buffer_ops = {
192193
.set_alignment_constants = comp_buffer_set_alignment_constants,
193194
};
194195

195-
static struct comp_buffer *buffer_alloc_struct(struct k_heap *heap,
196+
static struct comp_buffer *buffer_alloc_struct(struct mod_alloc_ctx *alloc,
196197
void *stream_addr, size_t size,
197198
uint32_t flags, bool is_shared)
198199
{
199200
struct comp_buffer *buffer;
200201

201-
tr_dbg(&buffer_tr, "buffer_alloc_struct()");
202+
tr_dbg(&buffer_tr, "entry");
202203

203204
/* allocate new buffer, but add coherent if shared with other cores */
204205
if (is_shared)
205206
flags |= SOF_MEM_FLAG_COHERENT;
206207

207-
buffer = sof_heap_alloc(heap, flags, sizeof(*buffer), 0);
208+
if (!alloc || !alloc->vreg)
209+
buffer = sof_heap_alloc(alloc ? alloc->heap : NULL, flags, sizeof(*buffer), 0);
210+
else if (is_shared)
211+
buffer = vregion_alloc_coherent(alloc->vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*buffer));
212+
else
213+
buffer = vregion_alloc(alloc->vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*buffer));
208214
if (!buffer) {
209215
tr_err(&buffer_tr, "could not alloc structure");
210216
return NULL;
@@ -226,21 +232,21 @@ static struct comp_buffer *buffer_alloc_struct(struct k_heap *heap,
226232

227233
audio_stream_set_underrun(&buffer->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
228234
audio_stream_set_overrun(&buffer->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));
229-
buffer->audio_buffer.heap = heap;
235+
buffer->audio_buffer.alloc = alloc;
230236

231237
comp_buffer_reset_source_list(buffer);
232238
comp_buffer_reset_sink_list(buffer);
233239

234240
return buffer;
235241
}
236242

237-
struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flags, uint32_t align,
238-
bool is_shared)
243+
struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint32_t flags,
244+
uint32_t align, bool is_shared)
239245
{
240246
struct comp_buffer *buffer;
241247
void *stream_addr;
242248

243-
tr_dbg(&buffer_tr, "buffer_alloc()");
249+
tr_dbg(&buffer_tr, "entry");
244250

245251
/* validate request */
246252
if (size == 0) {
@@ -255,7 +261,7 @@ struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flag
255261
return NULL;
256262
}
257263

258-
buffer = buffer_alloc_struct(heap, stream_addr, size, flags, is_shared);
264+
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
259265
if (!buffer) {
260266
tr_err(&buffer_tr, "could not alloc buffer structure");
261267
rfree(stream_addr);
@@ -264,7 +270,7 @@ struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flag
264270
return buffer;
265271
}
266272

267-
struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_size,
273+
struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t preferred_size,
268274
size_t minimum_size,
269275
uint32_t flags, uint32_t align, bool is_shared)
270276
{
@@ -299,7 +305,7 @@ struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_siz
299305
return NULL;
300306
}
301307

302-
buffer = buffer_alloc_struct(heap, stream_addr, size, flags, is_shared);
308+
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
303309
if (!buffer) {
304310
tr_err(&buffer_tr, "could not alloc buffer structure");
305311
rfree(stream_addr);
@@ -310,7 +316,7 @@ struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_siz
310316

311317
void buffer_zero(struct comp_buffer *buffer)
312318
{
313-
buf_dbg(buffer, "stream_zero()");
319+
buf_dbg(buffer, "entry");
314320
CORE_CHECK_STRUCT(&buffer->audio_buffer);
315321

316322
bzero(audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream));

src/audio/buffers/ring_buffer.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <sof/common.h>
77
#include <sof/trace/trace.h>
88
#include <sof/lib/uuid.h>
9+
#include <sof/lib/vregion.h>
910

1011
#include <sof/audio/module_adapter/module/generic.h>
1112
#include <sof/audio/ring_buffer.h>
@@ -96,9 +97,15 @@ static void ring_buffer_free(struct sof_audio_buffer *audio_buffer)
9697

9798
struct ring_buffer *ring_buffer = container_of(audio_buffer,
9899
struct ring_buffer, audio_buffer);
99-
100-
sof_heap_free(audio_buffer->heap, (__sparse_force void *)ring_buffer->_data_buffer);
101-
sof_heap_free(audio_buffer->heap, ring_buffer);
100+
struct mod_alloc_ctx *alloc = audio_buffer->alloc;
101+
102+
if (alloc->vreg) {
103+
vregion_free(alloc->vreg, (__sparse_force void *)ring_buffer->_data_buffer);
104+
vregion_free(alloc->vreg, ring_buffer);
105+
} else {
106+
sof_heap_free(alloc->heap, (__sparse_force void *)ring_buffer->_data_buffer);
107+
sof_heap_free(alloc->heap, ring_buffer);
108+
}
102109
}
103110

104111
static void ring_buffer_reset(struct sof_audio_buffer *audio_buffer)
@@ -287,12 +294,19 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
287294
uint32_t id)
288295
{
289296
struct ring_buffer *ring_buffer;
290-
struct k_heap *heap = dev->mod->priv.resources.heap;
297+
struct mod_alloc_ctx *alloc = dev->mod->priv.resources.alloc;
298+
struct k_heap *heap = alloc->heap;
299+
struct vregion *vreg = alloc->vreg;
291300
int memory_flags = (is_shared ? SOF_MEM_FLAG_COHERENT : 0) |
292301
user_get_buffer_memory_region(dev->drv);
293302

294303
/* allocate ring_buffer structure */
295-
ring_buffer = sof_heap_alloc(heap, memory_flags, sizeof(*ring_buffer), 0);
304+
if (!vreg)
305+
ring_buffer = sof_heap_alloc(heap, memory_flags, sizeof(*ring_buffer), 0);
306+
else if (is_shared)
307+
ring_buffer = vregion_alloc_coherent(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
308+
else
309+
ring_buffer = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
296310
if (!ring_buffer)
297311
return NULL;
298312

@@ -307,7 +321,8 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
307321
audio_buffer_init(&ring_buffer->audio_buffer, BUFFER_TYPE_RING_BUFFER,
308322
is_shared, &ring_buffer_source_ops, &ring_buffer_sink_ops,
309323
&audio_buffer_ops, NULL);
310-
ring_buffer->audio_buffer.heap = heap;
324+
ring_buffer->audio_buffer.alloc = alloc;
325+
ring_buffer->audio_buffer.alloc->heap = heap;
311326

312327
/* set obs/ibs in sink/source interfaces */
313328
sink_set_min_free_space(audio_buffer_get_sink(&ring_buffer->audio_buffer),
@@ -364,12 +379,21 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
364379
/* allocate data buffer - always in cached memory alias */
365380
ring_buffer->data_buffer_size = ALIGN_UP(ring_buffer->data_buffer_size,
366381
PLATFORM_DCACHE_ALIGN);
367-
ring_buffer->_data_buffer = (__sparse_force __sparse_cache void *)sof_heap_alloc(heap,
368-
user_get_buffer_memory_region(dev->drv),
369-
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);
370-
if (!ring_buffer->_data_buffer)
382+
383+
void *data_buf;
384+
385+
if (vreg)
386+
data_buf = vregion_alloc_align(vreg, VREGION_MEM_TYPE_INTERIM, ring_buffer->data_buffer_size,
387+
PLATFORM_DCACHE_ALIGN);
388+
else
389+
data_buf = sof_heap_alloc(heap, user_get_buffer_memory_region(dev->drv),
390+
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);
391+
392+
if (!data_buf)
371393
goto err;
372394

395+
ring_buffer->_data_buffer = (__sparse_force __sparse_cache void *)data_buf;
396+
373397
tr_info(&ring_buffer_tr, "Ring buffer created, id: %u shared: %u min_available: %u min_free_space %u, size %u",
374398
id, ring_buffer_is_shared(ring_buffer), min_available, min_free_space,
375399
ring_buffer->data_buffer_size);
@@ -378,6 +402,9 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
378402
return ring_buffer;
379403
err:
380404
tr_err(&ring_buffer_tr, "Ring buffer creation failure");
381-
sof_heap_free(heap, ring_buffer);
405+
if (vreg)
406+
vregion_free(vreg, ring_buffer);
407+
else
408+
sof_heap_free(heap, ring_buffer);
382409
return NULL;
383410
}

src/audio/dai-zephyr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev)
873873

874874
comp_dbg(dev, "entry");
875875

876-
dma_cfg = rballoc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA,
876+
dma_cfg = rmalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA,
877877
sizeof(struct dma_config));
878878
if (!dma_cfg) {
879879
comp_err(dev, "dma_cfg allocation failed");
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: BSD-3-Clause
3-
# Copyright(c) 2022 Intel Corporation. All rights reserved.
3+
# Copyright(c) 2022-2026 Intel Corporation. All rights reserved.
44

55
set -e
66

77
RAW_INPUT=in.raw
88
RAW_OUTPUT=mfcc.raw
99

10-
export LD_LIBRARY_PATH=../../testbench/build_testbench/sof_ep/install/lib:../../testbench/build_testbench/sof_parser/install/lib
11-
12-
TESTBENCH=../../testbench/build_testbench/install/bin/testbench
13-
OPT="-q -r 16000 -R 16000 -c 1 -n 1 -b S16_LE -t ../../build_tools/test/topology/test-playback-ssp5-mclk-0-I2S-mfcc-s16le-s16le-48k-24576k-codec.tplg"
10+
TESTBENCH=$SOF_WORKSPACE/sof/tools/testbench/build_testbench/install/bin/sof-testbench4
11+
TOPOLOGY=$SOF_WORKSPACE/sof/tools/build_tools/topology/topology2/development/sof-hda-benchmark-mfcc16.tplg
12+
OPT="-r 16000 -c 2 -b S16_LE -p 3,4 -t $TOPOLOGY -i $RAW_INPUT -o $RAW_OUTPUT"
1413

1514
# Convert input audio file raw 16 kHz 1 channel 16 bit
1615
sox --encoding signed-integer "$1" -L -r 16000 -c 1 -b 16 "$RAW_INPUT"
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
% below from code
66
%
77
% Create binary configuration blob for MFCC component. The hex data
8-
% is written to tools/topology/topology1/m4/mfcc/mfcc_config.m4
8+
% is written to tools/topology/topology2/include/components/mfcc and
9+
% tools/topology/topology1/m4/mfcc.
910

1011
% SPDX-License-Identifier: BSD-3-Clause
1112
%
12-
% Copyright (c) 2018-2020, Intel Corporation. All rights reserved.
13+
% Copyright (c) 2018-2026, Intel Corporation. All rights reserved.
1314

1415
function setup_mfcc(cfg)
1516

@@ -45,12 +46,14 @@ function setup_mfcc(cfg)
4546
cfg.top_db = 200; % Set to 80 for librosa
4647
end
4748

48-
cfg.tplg_fn = '../../topology/topology1/m4/mfcc/mfcc_config.m4';
49+
cfg.tools = '../../../../tools/';
50+
51+
cfg.tplg_fn = [cfg.tools 'topology/topology1/m4/mfcc/mfcc_config.m4'];
4952
cfg.tplg_ver = 1;
5053
cfg.ipc_ver = 3;
5154
export_mfcc_setup(cfg);
5255

53-
cfg.tplg_fn = '../../topology/topology2/include/components/mfcc/default.conf';
56+
cfg.tplg_fn = [cfg.tools 'topology/topology2/include/components/mfcc/default.conf'];
5457
cfg.tplg_ver = 2;
5558
cfg.ipc_ver = 4;
5659
export_mfcc_setup(cfg);
@@ -60,7 +63,7 @@ function setup_mfcc(cfg)
6063
function export_mfcc_setup(cfg)
6164

6265
%% Use blob tool from EQ
63-
addpath('../common');
66+
addpath([cfg.tools 'tune/common']);
6467

6568
%% Blob size, size plus reserved(8) + current parameters
6669
nbytes_data = 104;
@@ -122,16 +125,16 @@ function export_mfcc_setup(cfg)
122125
case 1
123126
sof_tplg_write(cfg.tplg_fn, b8, "DEF_MFCC_PRIV", ...
124127
"Exported with script setup_mfcc.m", ...
125-
"cd tools/tune/mfcc; octave setup_mfcc.m");
128+
"cd src/audio/mfcc/tune; octave setup_mfcc.m");
126129
case 2
127130
sof_tplg2_write(cfg.tplg_fn, b8, "mfcc_config", ...
128131
"Exported MFCC configuration", ...
129-
"cd tools/tune/mfcc; octave setup_mfcc.m");
132+
"cd src/audio/mfcc/tune; octave setup_mfcc.m");
130133
otherwise
131134
error("Illegal cfg.tplg_ver, use 1 for topology v1 or 2 topology v2.");
132135
end
133136

134-
rmpath('../common');
137+
rmpath([cfg.tools 'tune/common']);
135138

136139
end
137140

0 commit comments

Comments
 (0)