diff --git a/posix/include/rtos/alloc.h b/posix/include/rtos/alloc.h index ad82b74d6ce7..294b27eaee9b 100644 --- a/posix/include/rtos/alloc.h +++ b/posix/include/rtos/alloc.h @@ -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. @@ -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. @@ -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); diff --git a/src/audio/buffers/comp_buffer.c b/src/audio/buffers/comp_buffer.c index 8ed862ac8e29..454f5f0a49e3 100644 --- a/src/audio/buffers/comp_buffer.c +++ b/src/audio/buffers/comp_buffer.c @@ -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; } @@ -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; } diff --git a/src/audio/google/google_rtc_audio_processing_mock.c b/src/audio/google/google_rtc_audio_processing_mock.c index 77b390452205..b931c3a85c7a 100644 --- a/src/audio/google/google_rtc_audio_processing_mock.c +++ b/src/audio/google/google_rtc_audio_processing_mock.c @@ -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, @@ -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, @@ -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; } diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index a768dd93a3a6..ef2c0fac108a 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -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(). diff --git a/src/include/sof/lib/dai-legacy.h b/src/include/sof/lib/dai-legacy.h index 9408b6c27414..44142412334b 100644 --- a/src/include/sof/lib/dai-legacy.h +++ b/src/include/sof/lib/dai-legacy.h @@ -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, diff --git a/src/platform/ace30/include/platform/lib/memory.h b/src/platform/ace30/include/platform/lib/memory.h index 8fa1f1229a59..70888798e22a 100644 --- a/src/platform/ace30/include/platform/lib/memory.h +++ b/src/platform/ace30/include/platform/lib/memory.h @@ -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)) diff --git a/src/platform/lunarlake/include/platform/lib/memory.h b/src/platform/lunarlake/include/platform/lib/memory.h index b5bda0ede464..276c61d17d58 100644 --- a/src/platform/lunarlake/include/platform/lib/memory.h +++ b/src/platform/lunarlake/include/platform/lib/memory.h @@ -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)) diff --git a/src/platform/meteorlake/include/platform/lib/memory.h b/src/platform/meteorlake/include/platform/lib/memory.h index 76b60f98fabb..cd279b603c64 100644 --- a/src/platform/meteorlake/include/platform/lib/memory.h +++ b/src/platform/meteorlake/include/platform/lib/memory.h @@ -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)) diff --git a/src/probe/probe.c b/src/probe/probe.c index 5c75eae8210b..6421d4b473c3 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -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; diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index 82f3cbd1e46f..f30007a89b6b 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -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) { diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 983c0f13c71c..d29ad00ad180 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -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 @@ -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 diff --git a/zephyr/include/rtos/alloc.h b/zephyr/include/rtos/alloc.h index 6166ae6de449..600852418693 100644 --- a/zephyr/include/rtos/alloc.h +++ b/zephyr/include/rtos/alloc.h @@ -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_.... * @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. @@ -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. @@ -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); diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index b9d970e34b8c..77c5aaeccf3e 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -18,6 +18,7 @@ #include #include #include + #if CONFIG_VIRTUAL_HEAP #include @@ -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 */ @@ -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); @@ -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); } @@ -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) { @@ -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.