Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions posix/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,20 @@

/**
* Allocates memory block.
* @param zone Zone to allocate memory from, see enum mem_zone.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes Size in bytes.
* @return Pointer to the allocated memory or NULL if failed.
*
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone).
* Use rballoc(), rballoc_align() to allocate memory for buffers.
*/
void *rmalloc(uint32_t flags, size_t bytes);

/**
* Similar to rmalloc(), guarantees that returned block is zeroed.
*
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone).
* rballoc(), rballoc_align() to allocate memory for buffers.
*/
void *rzalloc(uint32_t flags, size_t bytes);

/**
* Allocates memory block from SOF_MEM_ZONE_BUFFER.
* Allocates memory block.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes Size in bytes.
* @param alignment Alignment in bytes.
* @return Pointer to the allocated memory or NULL if failed.
Expand All @@ -90,10 +81,9 @@ static inline void *rballoc(uint32_t flags, size_t bytes)
}

/**
* Changes size of the memory block allocated from SOF_MEM_ZONE_BUFFER.
* Changes size of the memory block allocated.
* @param ptr Address of the block to resize.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes New size in bytes.
* @param old_bytes Old size in bytes.
* @param alignment Alignment in bytes.
Expand All @@ -116,9 +106,6 @@ static inline void *rbrealloc(void *ptr, uint32_t flags,
/**
* Frees the memory block.
* @param ptr Pointer to the memory block.
*
* @note Blocks from SOF_MEM_ZONE_SYS cannot be freed, such a call causes
* panic.
*/
void rfree(void *ptr);

Expand Down
5 changes: 3 additions & 2 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
audio_stream_get_size(&buffer->stream), alignment);
/* we couldn't allocate bigger chunk */
if (!new_ptr && size > audio_stream_get_size(&buffer->stream)) {
buf_err(buffer, "resize can't alloc %u bytes type 0x%x",
buf_err(buffer, "resize can't alloc %u bytes of flags 0x%x",
audio_stream_get_size(&buffer->stream), buffer->flags);
return -ENOMEM;
}
Expand Down Expand Up @@ -388,7 +388,8 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz

/* we couldn't allocate bigger chunk */
if (!new_ptr && new_size > actual_size) {
buf_err(buffer, "resize can't alloc %zu bytes type 0x%x", new_size, buffer->flags);
buf_err(buffer, "resize can't alloc %zu bytes of flags 0x%x", new_size,
buffer->flags);
return -ENOMEM;
}

Expand Down
10 changes: 7 additions & 3 deletions src/audio/google/google_rtc_audio_processing_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct GoogleRtcAudioProcessingState {
float *aec_reference;
};

static void SetFormats(GoogleRtcAudioProcessingState *const state,
static int SetFormats(GoogleRtcAudioProcessingState *const state,
int capture_sample_rate_hz,
int num_capture_input_channels,
int num_capture_output_channels,
Expand All @@ -45,6 +45,9 @@ static void SetFormats(GoogleRtcAudioProcessingState *const state,
sizeof(state->aec_reference[0]) *
state->num_frames *
state->num_aec_reference_channels);
if (!state->aec_reference)
return -ENOMEM;
return 0;
}

void GoogleRtcAudioProcessingAttachMemoryBuffer(uint8_t *const buffer,
Expand All @@ -64,20 +67,21 @@ GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreateWithConfig(int capt
const uint8_t *const config,
int config_size)
{
int err;
struct GoogleRtcAudioProcessingState *s =
rballoc(SOF_MEM_FLAG_USER, sizeof(GoogleRtcAudioProcessingState));
if (!s)
return NULL;

s->aec_reference = NULL;
SetFormats(s,
err = SetFormats(s,
capture_sample_rate_hz,
num_capture_input_channels,
num_capture_output_channels,
render_sample_rate_hz,
num_render_channels);

if (!s->aec_reference) {
if (err) {
rfree(s);
return NULL;
}
Expand Down
2 changes: 0 additions & 2 deletions src/include/sof/audio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ struct comp_ops {
* @param spec Pointer to initialization data
* @return Pointer to the new component device.
*
* All required data objects should be allocated from the run-time
* heap (SOF_MEM_ZONE_RUNTIME).
* Any component-specific private data is allocated separately and
* pointer is connected to the comp_dev::private by using
* comp_set_drvdata() and later retrieved by comp_get_drvdata().
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/lib/dai-legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct sof_ipc_stream_params;
* If a single DAI instance can have multiple DMA links and/or there is
* some other possibility of the same instance being used in multiple
* contexts at the same time, the private data should be allocated in the
* SOF_MEM_ZONE_SHARED.
* SOF_MEM_FLAG_COHERENT.
*/
struct dai_ops {
int (*set_config)(struct dai *dai, struct ipc_config_dai *config,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ace30/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xD0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
2 changes: 1 addition & 1 deletion src/platform/lunarlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xF0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
2 changes: 1 addition & 1 deletion src/platform/meteorlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xF0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
2 changes: 1 addition & 1 deletion src/probe/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int probe_dma_init(struct probe_dma_ext *dma, uint32_t direction)
dma->config.dest_width = sizeof(uint32_t);
dma->config.cyclic = 0;

err = dma_sg_alloc(&dma->config.elem_array, SOF_MEM_ZONE_RUNTIME,
err = dma_sg_alloc(&dma->config.elem_array, SOF_MEM_FLAG_USER,
dma->config.direction, elem_num, elem_size, elem_addr, 0);
if (err < 0)
return err;
Expand Down
2 changes: 1 addition & 1 deletion src/trace/dma-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static int dma_trace_buffer_init(struct dma_trace_data *d)
config->dest_width = sizeof(uint32_t);
config->cyclic = 0;

ret = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_SYS,
ret = dma_sg_alloc(&config->elem_array, SOF_MEM_FLAG_USER,
config->direction, elem_num, elem_size,
elem_addr, 0);
if (ret < 0) {
Expand Down
31 changes: 31 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ config SOF_STAGING

rsource "../Kconfig.sof"

config SOF_USERSPACE
bool "Enable SOF support for userspace modules"
default n
help
SOF userspace modules support will enable modules to run in DP
processing mode as userspace code and data. This feature is WIP
and is not yet ready for production, for developers only.

config SOF_ZEPHYR_HEAP_CACHED
bool "Cached Zephyr heap for SOF memory non-shared zones"
default y if CAVS || ACE
Expand All @@ -19,6 +27,29 @@ config SOF_ZEPHYR_HEAP_CACHED
Enable cached heap by mapping cached SOF memory zones to different
Zephyr sys_heap objects and enable caching for non-shared zones.

config SOF_ZEPHYR_HEAP_SIZE
hex "Size of the Zephyr heap for SOF"
default 0xF0000 if SOC_INTEL_ACE15_MTPM || SOC_INTEL_ACE20_LNL
default 0xD0000 if SOC_INTEL_ACE30
default 0x0
help
Support scaling of the heap size for different platforms and different types
of heaps. This is the default heap size for most users.
TODO: Currently this setting is only available on platforms with a
simplified heap size configuration. i.e. a single macro that defines the
heap size. This is not the case for all platforms.
NOTE: Keep in mind that the heap size should not be greater than the physical
memory size of the system defined in DT (and this includes baseFW text/data).

config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
hex "Size of the Zephyr virtual heap for SOF"
depends on VIRTUAL_HEAP
default 0x40000
help
Support scaling of the virtual address heap size for different platforms.
NOTE: Keep in mind that the heap size should not be greater than the physical
memory size of the system defined in DT (and this includes baseFW text/data).

config ZEPHYR_NATIVE_DRIVERS
bool "Use Zephyr native drivers"
default n
Expand Down
18 changes: 3 additions & 15 deletions zephyr/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,21 @@

/**
* Allocates memory block.
* @param zone Zone to allocate memory from, see enum mem_zone.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param flags Flags, see SOF_MEM_FLAG_....
Copy link

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ellipsis '....' should use three dots '...' for consistency with other parameter docs.

Copilot uses AI. Check for mistakes.
* @param bytes Size in bytes.
* @return Pointer to the allocated memory or NULL if failed.
*
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone).
* Use rballoc(), rballoc_align() to allocate memory for buffers.
*/
void *rmalloc(uint32_t flags, size_t bytes);

/**
* Similar to rmalloc(), guarantees that returned block is zeroed.
*
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone).
* rballoc(), rballoc_align() to allocate memory for buffers.
*/
void *rzalloc(uint32_t flags, size_t bytes);

/**
* Allocates memory block from SOF_MEM_ZONE_BUFFER.
* Allocates memory block.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes Size in bytes.
* @param alignment Alignment in bytes.
* @return Pointer to the allocated memory or NULL if failed.
Expand All @@ -81,10 +73,9 @@ static inline void *rballoc(uint32_t flags, size_t bytes)
}

/**
* Changes size of the memory block allocated from SOF_MEM_ZONE_BUFFER.
* Changes size of the memory block allocated.
* @param ptr Address of the block to resize.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes New size in bytes.
* @param old_bytes Old size in bytes.
* @param alignment Alignment in bytes.
Expand All @@ -107,9 +98,6 @@ static inline void *rbrealloc(void *ptr, uint32_t flags,
/**
* Frees the memory block.
* @param ptr Pointer to the memory block.
*
* @note Blocks from SOF_MEM_ZONE_SYS cannot be freed, such a call causes
* panic.
*/
void rfree(void *ptr);

Expand Down
13 changes: 4 additions & 9 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sof/trace/trace.h>
#include <rtos/symbol.h>
#include <rtos/wait.h>

#if CONFIG_VIRTUAL_HEAP
#include <sof/lib/regions_mm.h>

Expand All @@ -27,7 +28,7 @@ struct vmh_heap *virtual_buffers_heap;
#undef HEAPMEM_SIZE
/* Buffers are allocated from virtual space so we can safely reduce the heap size.
*/
#define HEAPMEM_SIZE 0x40000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
#endif /* CONFIG_VIRTUAL_HEAP */


Expand Down Expand Up @@ -384,7 +385,7 @@ void *rmalloc(uint32_t flags, size_t bytes)
heap = &l3_heap;
/* Uncached L3_HEAP should not be used */
if (flags & SOF_MEM_FLAG_COHERENT) {
tr_err(&zephyr_tr, "L3_HEAP available for cached zones only!");
tr_err(&zephyr_tr, "L3_HEAP available for cached addresses only!");
return NULL;
}
ptr = (__sparse_force void *)l3_heap_alloc_aligned(heap, 0, bytes);
Expand All @@ -411,14 +412,12 @@ void *rmalloc(uint32_t flags, size_t bytes)
}
EXPORT_SYMBOL(rmalloc);

/* Use SOF_MEM_ZONE_BUFFER at the moment */
void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes,
size_t old_bytes, uint32_t alignment)
{
void *new_ptr;

if (!ptr) {
/* TODO: Use correct zone */
return rballoc_align(flags, bytes, alignment);
}

Expand All @@ -445,9 +444,6 @@ void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes,

/**
* Similar to rmalloc(), guarantees that returned block is zeroed.
*
* @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone).
* rballoc(), rballoc_align() to allocate memory for buffers.
*/
void *rzalloc(uint32_t flags, size_t bytes)
{
Expand All @@ -461,9 +457,8 @@ void *rzalloc(uint32_t flags, size_t bytes)
EXPORT_SYMBOL(rzalloc);

/**
* Allocates memory block from SOF_MEM_ZONE_BUFFER.
* Allocates memory block.
* @param flags see SOF_MEM_FLAG_...
* @param caps Capabilities, see SOF_MEM_CAPS_...
* @param bytes Size in bytes.
* @param align Alignment in bytes.
* @return Pointer to the allocated memory or NULL if failed.
Expand Down
Loading