From 2af06f391441a1bfdf6092c8e9c3ab0fc7884aff Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Fri, 4 Jul 2025 15:57:31 +0100 Subject: [PATCH 1/2] heap: simplify heap API. Use a Linux kernel like heap API now that zephyr allocator deals with the complexity. This change removes the memory zone and memory capabilities fields from allocation APIs and rolls these into SOF_MEM_FLAG_ bitmask. This bitmask can be ORed to make any combination of memory needed. Additionally this change introduces the new SOF_MEM_FLAG_KERNEL and SOF_MEM_FLAG_USER flags that have no action today but are used as the base default allocation bits for all allocations. Signed-off-by: Liam Girdwood --- posix/include/rtos/alloc.h | 61 +- posix/include/sof/lib/dma.h | 2 +- posix/include/sof/lib/mm_heap.h | 4 +- src/audio/aria/aria.c | 4 +- src/audio/asrc/asrc.c | 10 +- src/audio/base_fw_intel.c | 2 +- src/audio/buffers/comp_buffer.c | 54 +- src/audio/buffers/ring_buffer.c | 7 +- src/audio/chain_dma.c | 5 +- src/audio/copier/copier.c | 6 +- src/audio/copier/copier_dai.c | 5 +- src/audio/copier/copier_host.c | 4 +- src/audio/copier/copier_ipcgtw.c | 2 +- src/audio/crossover/crossover.c | 6 +- src/audio/dai-legacy.c | 8 +- src/audio/dai-zephyr.c | 10 +- src/audio/data_blob.c | 4 +- src/audio/dcblock/dcblock.c | 2 +- src/audio/drc/drc.c | 4 +- src/audio/eq_fir/eq_fir.c | 4 +- src/audio/eq_iir/eq_iir.c | 2 +- src/audio/eq_iir/eq_iir_generic.c | 2 +- .../google/google_ctc_audio_processing.c | 6 +- .../google/google_ctc_audio_processing_mock.c | 4 +- src/audio/google/google_hotword_detect.c | 2 +- .../google/google_rtc_audio_processing.c | 4 +- .../google/google_rtc_audio_processing_mock.c | 5 +- src/audio/host-legacy.c | 8 +- src/audio/host-zephyr.c | 11 +- src/audio/igo_nr/igo_nr.c | 4 +- src/audio/kpb.c | 12 +- src/audio/mfcc/mfcc.c | 2 +- src/audio/mfcc/mfcc_setup.c | 6 +- src/audio/mixer/mixer.c | 2 +- src/audio/mixin_mixout/mixin_mixout.c | 4 +- src/audio/module_adapter/module/cadence.c | 12 +- src/audio/module_adapter/module/generic.c | 12 +- src/audio/module_adapter/module/passthrough.c | 4 +- src/audio/module_adapter/module_adapter.c | 20 +- .../module_adapter/module_adapter_ipc4.c | 3 +- src/audio/multiband_drc/multiband_drc.c | 6 +- src/audio/mux/mux.c | 2 +- src/audio/nxp/eap.c | 8 +- src/audio/pipeline/pipeline-graph.c | 2 +- src/audio/pipeline/pipeline-schedule.c | 2 +- src/audio/rtnr/rtnr.c | 4 +- src/audio/rtnr/rtnr_stub.c | 2 +- src/audio/selector/selector.c | 4 +- src/audio/smart_amp/smart_amp.c | 4 +- src/audio/smart_amp/smart_amp_maxim_dsm.c | 2 +- src/audio/smart_amp/smart_amp_passthru.c | 2 +- src/audio/src/src_common.c | 4 +- src/audio/src/src_ipc3.c | 2 +- src/audio/src/src_ipc4.c | 2 +- src/audio/tdfb/tdfb.c | 4 +- src/audio/tdfb/tdfb_direction.c | 6 +- src/audio/tdfb/tdfb_ipc3.c | 2 +- src/audio/template_comp/template.c | 2 +- src/audio/tensorflow/tflm-classify.c | 2 +- src/audio/tone.c | 2 +- src/audio/up_down_mixer/up_down_mixer.c | 6 +- src/audio/volume/volume_ipc3.c | 4 +- src/audio/volume/volume_ipc4.c | 6 +- .../debug_stream/debug_stream_thread_info.c | 4 +- src/debug/tester/tester.c | 2 +- src/debug/tester/tester_dummy_test.c | 2 +- src/debug/tester/tester_simple_dram_test.c | 2 +- src/drivers/amd/common/acp_dma.c | 5 +- src/drivers/amd/common/acp_dmic_dai.c | 2 +- src/drivers/amd/common/acp_dmic_dma.c | 4 +- src/drivers/amd/common/acp_sp_dma.c | 4 +- src/drivers/amd/rembrandt/acp_bt_dma.c | 4 +- src/drivers/amd/rembrandt/acp_hs_dai.c | 2 +- src/drivers/amd/rembrandt/acp_hs_dma.c | 4 +- src/drivers/amd/rembrandt/acp_sw_audio_dai.c | 2 +- src/drivers/amd/rembrandt/acp_sw_audio_dma.c | 4 +- src/drivers/amd/renoir/acp_bt_dma.c | 4 +- src/drivers/amd/renoir/acp_sp_dai.c | 2 +- src/drivers/amd/vangogh/acp_bt_dma.c | 4 +- src/drivers/amd/vangogh/acp_hs_dma.c | 4 +- src/drivers/dw/dma.c | 7 +- src/drivers/dw/ssi-spi.c | 6 +- src/drivers/generic/dummy-dma.c | 4 +- src/drivers/imx/edma.c | 2 +- src/drivers/imx/esai.c | 2 +- src/drivers/imx/ipc.c | 5 +- src/drivers/imx/micfil.c | 2 +- src/drivers/imx/sai.c | 2 +- src/drivers/imx/sdma.c | 10 +- src/drivers/interrupt.c | 4 +- src/drivers/mediatek/afe/afe-drv.c | 6 +- src/drivers/mediatek/afe/afe-memif.c | 4 +- src/drivers/mediatek/mt818x/ipc.c | 4 +- src/drivers/mediatek/mt8195/ipc.c | 4 +- src/drivers/mediatek/mt8196/ipc.c | 4 +- src/drivers/mediatek/mt8365/ipc.c | 4 +- src/idc/idc.c | 2 +- src/include/sof/audio/buffer.h | 6 +- src/include/sof/audio/component.h | 2 +- src/include/sof/audio/component_ext.h | 2 +- src/include/sof/audio/smart_amp/smart_amp.h | 2 +- src/include/sof/coherent.h | 8 +- src/include/sof/ipc/msg.h | 4 +- src/include/sof/math/matrix.h | 2 +- src/include/sof/schedule/ll_schedule_domain.h | 2 +- src/ipc/ipc-common.c | 6 +- src/ipc/ipc-helper.c | 14 +- src/ipc/ipc3/dai.c | 2 +- src/ipc/ipc3/handler.c | 75 +- src/ipc/ipc3/helper.c | 6 +- src/ipc/ipc3/host-page-table.c | 2 +- src/ipc/ipc4/dai.c | 2 +- src/ipc/ipc4/helper.c | 4 +- src/ipc/notification_pool.c | 2 +- src/lib/agent.c | 2 +- src/lib/alloc.c | 1091 +---------------- src/lib/ams.c | 2 +- src/lib/dai.c | 6 +- src/lib/dma.c | 6 +- src/lib/notifier.c | 4 +- src/lib/pm_runtime.c | 4 +- src/library_manager/lib_manager.c | 24 +- src/library_manager/lib_notification.c | 4 +- src/library_manager/llext_manager.c | 6 +- src/library_manager/llext_manager_dram.c | 15 +- src/math/auditory/auditory.c | 2 +- src/math/fft/fft_common.c | 4 +- src/platform/amd/acp_6_3/platform.c | 2 +- src/platform/amd/acp_7_0/platform.c | 2 +- src/platform/amd/rembrandt/platform.c | 2 +- src/platform/amd/renoir/platform.c | 2 +- src/platform/amd/vangogh/platform.c | 2 +- src/platform/library/lib/alloc.c | 8 +- src/probe/probe.c | 4 +- src/samples/audio/detect_test.c | 4 +- src/samples/audio/smart_amp_test_ipc3.c | 2 +- src/samples/audio/smart_amp_test_ipc4.c | 2 +- src/schedule/dma_multi_chan_domain.c | 2 +- src/schedule/dma_single_chan_domain.c | 2 +- src/schedule/edf_schedule.c | 4 +- src/schedule/ll_schedule.c | 4 +- src/schedule/schedule.c | 4 +- src/schedule/task.c | 2 +- src/schedule/timer_domain.c | 2 +- src/schedule/zephyr_dma_domain.c | 12 +- src/schedule/zephyr_domain.c | 2 +- src/schedule/zephyr_dp_schedule.c | 6 +- src/schedule/zephyr_ll.c | 4 +- src/schedule/zephyr_twb_schedule.c | 6 +- src/trace/dma-trace.c | 4 +- src/trace/trace.c | 2 +- test/cmocka/src/common_mocks.c | 10 +- test/cmocka/src/lib/alloc/alloc.c | 168 +-- test/cmocka/src/lib/fast-get/fast-get-tests.c | 12 +- test/cmocka/src/math/fft/fft.c | 20 +- test/cmocka/src/notifier_mocks.c | 2 +- tools/plugin/modules/alsa.c | 2 +- tools/plugin/modules/shm.c | 2 +- tools/testbench/file.c | 8 +- zephyr/include/rtos/alloc.h | 61 +- zephyr/include/sof/lib/dma.h | 2 +- zephyr/lib/alloc.c | 48 +- zephyr/lib/cpu.c | 2 +- zephyr/lib/fast-get.c | 4 +- zephyr/lib/regions_mm.c | 20 +- 165 files changed, 523 insertions(+), 1771 deletions(-) diff --git a/posix/include/rtos/alloc.h b/posix/include/rtos/alloc.h index 1ceaef3e8b8f..ad82b74d6ce7 100644 --- a/posix/include/rtos/alloc.h +++ b/posix/include/rtos/alloc.h @@ -28,47 +28,24 @@ * @{ */ -/** - * \brief Heap Memory Zones - * - * The heap has three different zones from where memory can be allocated :- - * - * 1) System Zone. Fixed size heap where alloc always succeeds and is never - * freed. Used by any init code that will never give up the memory. - * - * 2) System Runtime Zone. Heap zone intended for runtime objects allocated - * by the kernel part of the code. - * - * 3) Runtime Zone. Main and larger heap zone where allocs are not guaranteed to - * succeed. Memory can be freed here. - * - * 4) Buffer Zone. Largest heap zone intended for audio buffers. - * - * 5) Runtime Shared Zone. Similar to Runtime Zone, but content may be used and - * fred from any enabled core. - * - * 6) System Shared Zone. Similar to System Zone, but content may be used from - * any enabled core. - * - * See platform/memory.h for heap size configuration and mappings. - */ -enum mem_zone { - SOF_MEM_ZONE_SYS = 0, /**< System zone */ - SOF_MEM_ZONE_SYS_RUNTIME, /**< System-runtime zone */ - SOF_MEM_ZONE_RUNTIME, /**< Runtime zone */ - SOF_MEM_ZONE_BUFFER, /**< Buffer zone */ - SOF_MEM_ZONE_RUNTIME_SHARED, /**< Runtime shared zone */ - SOF_MEM_ZONE_SYS_SHARED, /**< System shared zone */ -}; - /** \name Heap zone flags * @{ */ + /** \brief Indicates we should return DMA-able memory. */ +#define SOF_MEM_FLAG_DMA BIT(0) /** \brief Indicates that original content should not be copied by realloc. */ #define SOF_MEM_FLAG_NO_COPY BIT(1) /** \brief Indicates that if we should return uncached address. */ -#define SOF_MEM_FLAG_COHERENT BIT(2) +#define SOF_MEM_FLAG_COHERENT BIT(2) +/** \brief Indicates that if we should return L3 address. */ +#define SOF_MEM_FLAG_L3 BIT(3) +/** \brief Indicates that if we should return Low power memory address. */ +#define SOF_MEM_FLAG_LOW_POWER BIT(4) +/** \brief Indicates that if we should return kernel memory address. */ +#define SOF_MEM_FLAG_KERNEL BIT(5) +/** \brief Indicates that if we should return user memory address. */ +#define SOF_MEM_FLAG_USER BIT(6) /** @} */ @@ -83,7 +60,7 @@ enum mem_zone { * @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). * Use rballoc(), rballoc_align() to allocate memory for buffers. */ -void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); +void *rmalloc(uint32_t flags, size_t bytes); /** * Similar to rmalloc(), guarantees that returned block is zeroed. @@ -91,7 +68,7 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); * @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). * rballoc(), rballoc_align() to allocate memory for buffers. */ -void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); +void *rzalloc(uint32_t flags, size_t bytes); /** * Allocates memory block from SOF_MEM_ZONE_BUFFER. @@ -101,15 +78,15 @@ void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); * @param alignment Alignment in bytes. * @return Pointer to the allocated memory or NULL if failed. */ -void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment); /** * Similar to rballoc_align(), returns buffer aligned to PLATFORM_DCACHE_ALIGN. */ -static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) +static inline void *rballoc(uint32_t flags, size_t bytes) { - return rballoc_align(flags, caps, bytes, PLATFORM_DCACHE_ALIGN); + return rballoc_align(flags, bytes, PLATFORM_DCACHE_ALIGN); } /** @@ -122,17 +99,17 @@ static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) * @param alignment Alignment in bytes. * @return Pointer to the resized memory of NULL if failed. */ -void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, +void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes, uint32_t alignment); /** * Similar to rballoc_align(), returns resized buffer aligned to * PLATFORM_DCACHE_ALIGN. */ -static inline void *rbrealloc(void *ptr, uint32_t flags, uint32_t caps, +static inline void *rbrealloc(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes) { - return rbrealloc_align(ptr, flags, caps, bytes, old_bytes, + return rbrealloc_align(ptr, flags, bytes, old_bytes, PLATFORM_DCACHE_ALIGN); } diff --git a/posix/include/sof/lib/dma.h b/posix/include/sof/lib/dma.h index 1ff90693926b..960cfd469215 100644 --- a/posix/include/sof/lib/dma.h +++ b/posix/include/sof/lib/dma.h @@ -512,7 +512,7 @@ static inline void dma_sg_init(struct dma_sg_elem_array *ea) } int dma_sg_alloc(struct dma_sg_elem_array *ea, - enum mem_zone zone, + uint32_t flags, uint32_t direction, uint32_t buffer_count, uint32_t buffer_bytes, uintptr_t dma_buffer_addr, uintptr_t external_addr); diff --git a/posix/include/sof/lib/mm_heap.h b/posix/include/sof/lib/mm_heap.h index 7bdab176eb5f..84bcc893d101 100644 --- a/posix/include/sof/lib/mm_heap.h +++ b/posix/include/sof/lib/mm_heap.h @@ -88,7 +88,7 @@ uint32_t mm_pm_context_size(void); void init_heap(struct sof *sof); /* frees entire heap (supported for secondary core system heap atm) */ -void free_heap(enum mem_zone zone); +void free_heap(void); /* status */ void heap_trace_all(int force); @@ -101,7 +101,7 @@ void heap_trace(struct mm_heap *heap, int size); * @param out output variable * @return error code or zero */ -int heap_info(enum mem_zone zone, int index, struct mm_info *out); +int heap_info(int index, struct mm_info *out); #endif /* retrieve memory map pointer */ diff --git a/src/audio/aria/aria.c b/src/audio/aria/aria.c index 32c13edc8a5a..7357475e92ae 100644 --- a/src/audio/aria/aria.c +++ b/src/audio/aria/aria.c @@ -126,7 +126,7 @@ static int aria_init(struct processing_module *mod) list_init(&dev->bsource_list); list_init(&dev->bsink_list); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { return -ENOMEM; } @@ -145,7 +145,7 @@ static int aria_init(struct processing_module *mod) } mod_data->private = cd; - buf = rballoc(0, SOF_MEM_CAPS_RAM, req_mem); + buf = rballoc(SOF_MEM_FLAG_USER, req_mem); if (!buf) { rfree(cd); diff --git a/src/audio/asrc/asrc.c b/src/audio/asrc/asrc.c index e8106d5112c9..5c1e71e6bf82 100644 --- a/src/audio/asrc/asrc.c +++ b/src/audio/asrc/asrc.c @@ -217,7 +217,7 @@ static int asrc_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -261,7 +261,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj) buffer_size = src_obj->buffer_length * sizeof(int32_t); for (ch = 0; ch < src_obj->num_channels; ch++) { - buf_32 = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, buffer_size); + buf_32 = rzalloc(SOF_MEM_FLAG_USER, buffer_size); if (!buf_32) return -ENOMEM; @@ -272,7 +272,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj) buffer_size = src_obj->buffer_length * sizeof(int16_t); for (ch = 0; ch < src_obj->num_channels; ch++) { - buf_16 = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, buffer_size); + buf_16 = rzalloc(SOF_MEM_FLAG_USER, buffer_size); if (!buf_16) return -ENOMEM; @@ -614,7 +614,7 @@ static int asrc_prepare(struct processing_module *mod, cd->buf_size = (cd->source_frames_max + cd->sink_frames_max) * frame_bytes; - cd->buf = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + cd->buf = rzalloc(SOF_MEM_FLAG_USER, cd->buf_size); if (!cd->buf) { cd->buf_size = 0; @@ -640,7 +640,7 @@ static int asrc_prepare(struct processing_module *mod, goto err_free_buf; } - cd->asrc_obj = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + cd->asrc_obj = rzalloc(SOF_MEM_FLAG_USER, cd->asrc_size); if (!cd->asrc_obj) { comp_err(dev, "asrc_prepare(), allocation fail for size %d", diff --git a/src/audio/base_fw_intel.c b/src/audio/base_fw_intel.c index 39d68d58118c..7a03c069349f 100644 --- a/src/audio/base_fw_intel.c +++ b/src/audio/base_fw_intel.c @@ -182,7 +182,7 @@ __cold static int basefw_mem_state_info(uint32_t *data_offset, char *data) info.page_alloc_struct.page_alloc_count * sizeof(uint32_t); size = ALIGN(size, 4); /* size is also saved as tuple length */ - tuple_data = rballoc(0, SOF_MEM_CAPS_RAM, size); + tuple_data = rballoc(SOF_MEM_FLAG_USER, size); /* save memory info in data array since info length is variable */ index = 0; diff --git a/src/audio/buffers/comp_buffer.c b/src/audio/buffers/comp_buffer.c index 232e26cbec8a..8ed862ac8e29 100644 --- a/src/audio/buffers/comp_buffer.c +++ b/src/audio/buffers/comp_buffer.c @@ -181,24 +181,25 @@ static const struct audio_buffer_ops audio_buffer_ops = { .set_alignment_constants = comp_buffer_set_alignment_constants }; -static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t caps, +static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t flags, bool is_shared) { struct comp_buffer *buffer; tr_dbg(&buffer_tr, "buffer_alloc_struct()"); - /* allocate new buffer */ - enum mem_zone zone = is_shared ? SOF_MEM_ZONE_RUNTIME_SHARED : SOF_MEM_ZONE_RUNTIME; + /* allocate new buffer, but add coherent if shared with other cores */ + if (is_shared) + flags |= SOF_MEM_FLAG_COHERENT; - buffer = rzalloc(zone, 0, SOF_MEM_CAPS_RAM, sizeof(*buffer)); + buffer = rzalloc(flags, sizeof(*buffer)); if (!buffer) { tr_err(&buffer_tr, "buffer_alloc_struct(): could not alloc structure"); return NULL; } - buffer->caps = caps; + buffer->flags = flags; /* Force channels to 2 for init to prevent bad call to clz in buffer_init_stream */ buffer->stream.runtime_stream_params.channels = 2; @@ -219,7 +220,7 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, u return buffer; } -struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uint32_t align, +struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align, bool is_shared) { struct comp_buffer *buffer; @@ -233,14 +234,14 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uin return NULL; } - stream_addr = rballoc_align(0, caps, size, align); + stream_addr = rballoc_align(flags, size, align); if (!stream_addr) { - tr_err(&buffer_tr, "buffer_alloc(): could not alloc size = %zu bytes of type = %u", - size, caps); + tr_err(&buffer_tr, "buffer_alloc(): could not alloc size = %zu bytes of flags = 0x%x", + size, flags); return NULL; } - buffer = buffer_alloc_struct(stream_addr, size, caps, flags, is_shared); + buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared); if (!buffer) { tr_err(&buffer_tr, "buffer_alloc(): could not alloc buffer structure"); rfree(stream_addr); @@ -249,7 +250,7 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uin return buffer; } -struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size, uint32_t caps, +struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size, uint32_t flags, uint32_t align, bool is_shared) { struct comp_buffer *buffer; @@ -270,7 +271,7 @@ struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_siz preferred_size += minimum_size - preferred_size % minimum_size; for (size = preferred_size; size >= minimum_size; size -= minimum_size) { - stream_addr = rballoc_align(0, caps, size, align); + stream_addr = rballoc_align(flags, size, align); if (stream_addr) break; } @@ -278,12 +279,12 @@ struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_siz tr_dbg(&buffer_tr, "buffer_alloc_range(): allocated %zu bytes", size); if (!stream_addr) { - tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc size = %zu bytes of type = %u", - minimum_size, caps); + tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc size = %zu bytes of type = 0x%x", + minimum_size, flags); return NULL; } - buffer = buffer_alloc_struct(stream_addr, size, caps, flags, is_shared); + buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared); if (!buffer) { tr_err(&buffer_tr, "buffer_alloc_range(): could not alloc buffer structure"); rfree(stream_addr); @@ -298,7 +299,7 @@ void buffer_zero(struct comp_buffer *buffer) CORE_CHECK_STRUCT(&buffer->audio_buffer); bzero(audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream)); - if (buffer->caps & SOF_MEM_CAPS_DMA) + if (buffer->flags & SOF_MEM_FLAG_DMA) dcache_writeback_region((__sparse_force void __sparse_cache *) audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream)); @@ -320,16 +321,17 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen return 0; if (!alignment) - new_ptr = rbrealloc(audio_stream_get_addr(&buffer->stream), SOF_MEM_FLAG_NO_COPY, - buffer->caps, size, audio_stream_get_size(&buffer->stream)); + new_ptr = rbrealloc(audio_stream_get_addr(&buffer->stream), + buffer->flags | SOF_MEM_FLAG_NO_COPY, + size, audio_stream_get_size(&buffer->stream)); else new_ptr = rbrealloc_align(audio_stream_get_addr(&buffer->stream), - SOF_MEM_FLAG_NO_COPY, buffer->caps, size, + buffer->flags | SOF_MEM_FLAG_NO_COPY, size, 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 %u", - audio_stream_get_size(&buffer->stream), buffer->caps); + buf_err(buffer, "resize can't alloc %u bytes type 0x%x", + audio_stream_get_size(&buffer->stream), buffer->flags); return -ENOMEM; } @@ -369,16 +371,16 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz if (!alignment) { for (new_size = preferred_size; new_size >= minimum_size; new_size -= minimum_size) { - new_ptr = rbrealloc(ptr, SOF_MEM_FLAG_NO_COPY, buffer->caps, new_size, - actual_size); + new_ptr = rbrealloc(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY, + new_size, actual_size); if (new_ptr) break; } } else { for (new_size = preferred_size; new_size >= minimum_size; new_size -= minimum_size) { - new_ptr = rbrealloc_align(ptr, SOF_MEM_FLAG_NO_COPY, buffer->caps, new_size, - actual_size, alignment); + new_ptr = rbrealloc_align(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY, + new_size, actual_size, alignment); if (new_ptr) break; } @@ -386,7 +388,7 @@ 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 %u", new_size, buffer->caps); + buf_err(buffer, "resize can't alloc %zu bytes type 0x%x", new_size, buffer->flags); return -ENOMEM; } diff --git a/src/audio/buffers/ring_buffer.c b/src/audio/buffers/ring_buffer.c index d7bd251b3c23..c245dec42d6f 100644 --- a/src/audio/buffers/ring_buffer.c +++ b/src/audio/buffers/ring_buffer.c @@ -280,11 +280,10 @@ struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_spa /* allocate ring_buffer structure */ if (is_shared) - ring_buffer = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + ring_buffer = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*ring_buffer)); else - ring_buffer = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, - sizeof(*ring_buffer)); + ring_buffer = rzalloc(SOF_MEM_FLAG_USER, sizeof(*ring_buffer)); if (!ring_buffer) return NULL; @@ -354,7 +353,7 @@ struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_spa ring_buffer->data_buffer_size = ALIGN_UP(ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN); ring_buffer->_data_buffer = (__sparse_force __sparse_cache void *) - rballoc_align(0, 0, ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN); + rballoc_align(SOF_MEM_FLAG_USER, ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN); if (!ring_buffer->_data_buffer) goto err; diff --git a/src/audio/chain_dma.c b/src/audio/chain_dma.c index 99eeaa62fca8..35be44951c7d 100644 --- a/src/audio/chain_dma.c +++ b/src/audio/chain_dma.c @@ -605,7 +605,8 @@ __cold static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uin fifo_size = ALIGN_UP_INTERNAL(fifo_size, addr_align); /* allocate not shared buffer */ - cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_CAPS_DMA, 0, addr_align, false); + cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, + addr_align, false); if (!cd->dma_buffer) { comp_err(dev, "chain_task_init(): failed to alloc dma buffer"); @@ -668,7 +669,7 @@ __cold static struct comp_dev *chain_task_create(const struct comp_driver *drv, if (!dev) return NULL; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) goto error; diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index 5d4b47a1d5fc..9aab0858a305 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -87,7 +87,7 @@ static int mic_privacy_configure(struct comp_dev *dev, struct copier_data *cd) struct mic_privacy_data *mic_priv_data; int ret; - mic_priv_data = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + mic_priv_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct mic_privacy_data)); if (!mic_priv_data) return -ENOMEM; @@ -144,7 +144,7 @@ __cold static int copier_init(struct processing_module *mod) assert_can_be_cold(); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -166,7 +166,7 @@ __cold static int copier_init(struct processing_module *mod) */ if (copier->gtw_cfg.config_length) { gtw_cfg_size = copier->gtw_cfg.config_length << 2; - gtw_cfg = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + gtw_cfg = rmalloc(SOF_MEM_FLAG_USER, gtw_cfg_size); if (!gtw_cfg) { ret = -ENOMEM; diff --git a/src/audio/copier/copier_dai.c b/src/audio/copier/copier_dai.c index c9740b8f9f4f..828ee259b79b 100644 --- a/src/audio/copier/copier_dai.c +++ b/src/audio/copier/copier_dai.c @@ -204,7 +204,7 @@ __cold static int copier_dai_init(struct comp_dev *dev, return ret; } - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); + dd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*dd)); if (!dd) return -ENOMEM; @@ -223,8 +223,7 @@ __cold static int copier_dai_init(struct comp_dev *dev, /* Allocate gain data if selected for this dai type and set basic params */ if (dai->apply_gain) { - struct copier_gain_params *gain_data = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, + struct copier_gain_params *gain_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*gain_data)); if (!gain_data) { ret = -ENOMEM; diff --git a/src/audio/copier/copier_host.c b/src/audio/copier/copier_host.c index f430803084a0..8315ad4535e2 100644 --- a/src/audio/copier/copier_host.c +++ b/src/audio/copier/copier_host.c @@ -62,7 +62,7 @@ __cold static int add_to_fpi_sync_group(struct comp_dev *parent_dev, group->ref_count++; } else { - group = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*group)); + group = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*group)); if (!group) { comp_err(parent_dev, "Failed to alloc memory for new group"); return -ENOMEM; @@ -177,7 +177,7 @@ __cold int copier_host_create(struct comp_dev *dev, struct copier_data *cd, ipc_host.dma_buffer_size = copier_cfg->gtw_cfg.dma_buffer_size; ipc_host.feature_mask = copier_cfg->copier_feature_mask; - hd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*hd)); + hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd)); if (!hd) return -ENOMEM; diff --git a/src/audio/copier/copier_ipcgtw.c b/src/audio/copier/copier_ipcgtw.c index 9c97ca2b9f7a..254b62ea29f7 100644 --- a/src/audio/copier/copier_ipcgtw.c +++ b/src/audio/copier/copier_ipcgtw.c @@ -231,7 +231,7 @@ __cold int copier_ipcgtw_create(struct comp_dev *dev, struct copier_data *cd, config->type = SOF_COMP_HOST; cd->gtw_type = ipc4_gtw_host; - ipcgtw_data = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*ipcgtw_data)); + ipcgtw_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(*ipcgtw_data)); if (!ipcgtw_data) return -ENOMEM; diff --git a/src/audio/crossover/crossover.c b/src/audio/crossover/crossover.c index c6b34acd1b45..af54bf8245fd 100644 --- a/src/audio/crossover/crossover.c +++ b/src/audio/crossover/crossover.c @@ -169,7 +169,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef, * in series due to identity. To maintain the structure of * iir_state_df1, it requires two copies of coefficients in a row. */ - lr4->coef = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + lr4->coef = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct sof_eq_iir_biquad) * 2); if (!lr4->coef) return -ENOMEM; @@ -189,7 +189,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef, * delay[0..1] -> state for first biquad * delay[2..3] -> state for second biquad */ - lr4->delay = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + lr4->delay = rzalloc(SOF_MEM_FLAG_USER, sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4); if (!lr4->delay) return -ENOMEM; @@ -312,7 +312,7 @@ static int crossover_init(struct processing_module *mod) return -ENOMEM; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/dai-legacy.c b/src/audio/dai-legacy.c index b212bb9ebdac..febd67cc8b77 100644 --- a/src/audio/dai-legacy.c +++ b/src/audio/dai-legacy.c @@ -196,7 +196,7 @@ static struct comp_dev *dai_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); + dd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*dd)); if (!dd) { rfree(dev); return NULL; @@ -381,7 +381,7 @@ static int dai_playback_params(struct comp_dev *dev, uint32_t period_bytes, comp_info(dev, "dai_playback_params() fifo 0x%x", fifo); - err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME, + err = dma_sg_alloc(&config->elem_array, SOF_MEM_FLAG_USER, config->direction, period_count, period_bytes, @@ -446,7 +446,7 @@ static int dai_capture_params(struct comp_dev *dev, uint32_t period_bytes, comp_info(dev, "dai_capture_params() fifo 0x%x", fifo); - err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME, + err = dma_sg_alloc(&config->elem_array, SOF_MEM_FLAG_USER, config->direction, period_count, period_bytes, @@ -561,7 +561,7 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev, return err; } } else { - dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0, + dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, addr_align, false); if (!dd->dma_buffer) { comp_err(dev, "dai_params(): failed to alloc dma buffer"); diff --git a/src/audio/dai-zephyr.c b/src/audio/dai-zephyr.c index 66aa69650c69..0512b92abc87 100644 --- a/src/audio/dai-zephyr.c +++ b/src/audio/dai-zephyr.c @@ -572,7 +572,7 @@ __cold static struct comp_dev *dai_new(const struct comp_driver *drv, dev->ipc_config = *config; - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); + dd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*dd)); if (!dd) goto e_data; @@ -826,7 +826,7 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t } while (--max_block_count > 0); } - err = dma_sg_alloc(&config->elem_array, SOF_MEM_ZONE_RUNTIME, + err = dma_sg_alloc(&config->elem_array, SOF_MEM_FLAG_USER, config->direction, period_count, period_bytes, @@ -852,7 +852,7 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev) comp_dbg(dev, "dai_set_dma_config()"); - dma_cfg = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, + dma_cfg = rballoc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA, sizeof(struct dma_config)); if (!dma_cfg) { comp_err(dev, "dma_cfg allocation failed"); @@ -882,7 +882,7 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev) else dma_cfg->dma_slot = config->src_dev; - dma_block_cfg = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, + dma_block_cfg = rballoc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA, sizeof(struct dma_block_config) * dma_cfg->block_count); if (!dma_block_cfg) { rfree(dma_cfg); @@ -1020,7 +1020,7 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev, } } else { dd->dma_buffer = buffer_alloc_range(buffer_size_preferred, buffer_size, - SOF_MEM_CAPS_DMA, 0, addr_align, false); + SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, addr_align, false); if (!dd->dma_buffer) { comp_err(dev, "failed to alloc dma buffer"); return -ENOMEM; diff --git a/src/audio/data_blob.c b/src/audio/data_blob.c index 7e1bc11f1f17..e66c43fdd309 100644 --- a/src/audio/data_blob.c +++ b/src/audio/data_blob.c @@ -623,7 +623,7 @@ EXPORT_SYMBOL(comp_data_blob_get_cmd); static void *default_alloc(size_t size) { - return rballoc(0, SOF_MEM_CAPS_RAM, size); + return rballoc(SOF_MEM_FLAG_USER, size); } static void default_free(void *buf) @@ -640,7 +640,7 @@ comp_data_blob_handler_new_ext(struct comp_dev *dev, bool single_blob, comp_dbg(dev, "comp_data_blob_handler_new_ext()"); - handler = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + handler = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct comp_data_blob_handler)); if (handler) { diff --git a/src/audio/dcblock/dcblock.c b/src/audio/dcblock/dcblock.c index e7d1a0b90420..704faa1fb6e9 100644 --- a/src/audio/dcblock/dcblock.c +++ b/src/audio/dcblock/dcblock.c @@ -89,7 +89,7 @@ static int dcblock_init(struct processing_module *mod) comp_info(dev, "dcblock_init()"); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index 0f06293fc243..3a6e3d32856b 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -76,7 +76,7 @@ int drc_init_pre_delay_buffers(struct drc_state *state, int i; /* Allocate pre-delay (lookahead) buffers */ - state->pre_delay_buffers[0] = rballoc(0, SOF_MEM_CAPS_RAM, bytes_total); + state->pre_delay_buffers[0] = rballoc(SOF_MEM_FLAG_USER, bytes_total); if (!state->pre_delay_buffers[0]) return -ENOMEM; @@ -164,7 +164,7 @@ __cold static int drc_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/eq_fir/eq_fir.c b/src/audio/eq_fir/eq_fir.c index 344e9e25b5af..d4767ff522e6 100644 --- a/src/audio/eq_fir/eq_fir.c +++ b/src/audio/eq_fir/eq_fir.c @@ -220,7 +220,7 @@ static int eq_fir_setup(struct comp_dev *dev, struct comp_data *cd, int nch) return 0; /* Allocate all FIR channels data in a big chunk and clear it */ - cd->fir_delay = rballoc(0, SOF_MEM_CAPS_RAM, delay_size); + cd->fir_delay = rballoc(SOF_MEM_FLAG_USER, delay_size); if (!cd->fir_delay) { comp_err(dev, "eq_fir_setup(), delay allocation failed for size %d", delay_size); return -ENOMEM; @@ -264,7 +264,7 @@ static int eq_fir_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/eq_iir/eq_iir.c b/src/audio/eq_iir/eq_iir.c index d369461c31e2..73ea4c17fd0f 100644 --- a/src/audio/eq_iir/eq_iir.c +++ b/src/audio/eq_iir/eq_iir.c @@ -60,7 +60,7 @@ static int eq_iir_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/eq_iir/eq_iir_generic.c b/src/audio/eq_iir/eq_iir_generic.c index 1941fbda3a8b..ff3cba8f4e0e 100644 --- a/src/audio/eq_iir/eq_iir_generic.c +++ b/src/audio/eq_iir/eq_iir_generic.c @@ -329,7 +329,7 @@ int eq_iir_setup(struct processing_module *mod, int nch) return 0; /* Allocate all IIR channels data in a big chunk and clear it */ - cd->iir_delay = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + cd->iir_delay = rzalloc(SOF_MEM_FLAG_USER, delay_size); if (!cd->iir_delay) { comp_err(mod->dev, "eq_iir_setup(), delay allocation fail"); diff --git a/src/audio/google/google_ctc_audio_processing.c b/src/audio/google/google_ctc_audio_processing.c index 463380e37f79..f3370d043aa1 100644 --- a/src/audio/google/google_ctc_audio_processing.c +++ b/src/audio/google/google_ctc_audio_processing.c @@ -265,7 +265,7 @@ static int ctc_init(struct processing_module *mod) comp_info(dev, "ctc_init()"); /* Create private component data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { comp_err(dev, "ctc_init(): Failed to create component data"); ctc_free(mod); @@ -277,13 +277,13 @@ static int ctc_init(struct processing_module *mod) cd->chunk_frames = kChunkFrames; buf_size = cd->chunk_frames * sizeof(cd->input[0]) * kMaxChannels; - cd->input = rballoc(0, SOF_MEM_CAPS_RAM, buf_size); + cd->input = rballoc(SOF_MEM_FLAG_USER, buf_size); if (!cd->input) { comp_err(dev, "ctc_init(): Failed to allocate input buffer"); ctc_free(mod); return -ENOMEM; } - cd->output = rballoc(0, SOF_MEM_CAPS_RAM, buf_size); + cd->output = rballoc(SOF_MEM_FLAG_USER, buf_size); if (!cd->output) { comp_err(dev, "ctc_init(): Failed to allocate output buffer"); ctc_free(mod); diff --git a/src/audio/google/google_ctc_audio_processing_mock.c b/src/audio/google/google_ctc_audio_processing_mock.c index ea962aa3a774..f3f004d38ebb 100644 --- a/src/audio/google/google_ctc_audio_processing_mock.c +++ b/src/audio/google/google_ctc_audio_processing_mock.c @@ -18,7 +18,7 @@ struct GoogleCtcAudioProcessingState { GoogleCtcAudioProcessingState *GoogleCtcAudioProcessingCreate(void) { struct GoogleCtcAudioProcessingState *s = - rballoc(0, SOF_MEM_CAPS_RAM, sizeof(GoogleCtcAudioProcessingState)); + rballoc(SOF_MEM_FLAG_USER, sizeof(GoogleCtcAudioProcessingState)); if (!s) return NULL; @@ -31,7 +31,7 @@ GoogleCtcAudioProcessingState *GoogleCtcAudioProcessingCreateWithConfig(int chun int config_size) { struct GoogleCtcAudioProcessingState *s = - rballoc(0, SOF_MEM_CAPS_RAM, sizeof(GoogleCtcAudioProcessingState)); + rballoc(SOF_MEM_FLAG_USER, sizeof(GoogleCtcAudioProcessingState)); if (!s) return NULL; diff --git a/src/audio/google/google_hotword_detect.c b/src/audio/google/google_hotword_detect.c index 920945209dbf..61d498ef9467 100644 --- a/src/audio/google/google_hotword_detect.c +++ b/src/audio/google/google_hotword_detect.c @@ -102,7 +102,7 @@ static struct comp_dev *ghd_create(const struct comp_driver *drv, dev->ipc_config = *config; /* Create private component data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) goto fail; diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index a856899888e6..330ce36e4101 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -107,7 +107,7 @@ static void *cached_ptr(void *p) void *GoogleRtcMalloc(size_t size) { - return rballoc(0, SOF_MEM_CAPS_RAM, size); + return rballoc(SOF_MEM_FLAG_USER, size); } void GoogleRtcFree(void *ptr) @@ -512,7 +512,7 @@ static int google_rtc_audio_processing_init(struct processing_module *mod) comp_info(dev, "google_rtc_audio_processing_init()"); /* Create private component data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { ret = -ENOMEM; goto fail; diff --git a/src/audio/google/google_rtc_audio_processing_mock.c b/src/audio/google/google_rtc_audio_processing_mock.c index 7d5d12f5bd88..77b390452205 100644 --- a/src/audio/google/google_rtc_audio_processing_mock.c +++ b/src/audio/google/google_rtc_audio_processing_mock.c @@ -41,8 +41,7 @@ static void SetFormats(GoogleRtcAudioProcessingState *const state, state->num_aec_reference_channels = num_render_channels; rfree(state->aec_reference); - state->aec_reference = rballoc(0, - SOF_MEM_CAPS_RAM, + state->aec_reference = rballoc(SOF_MEM_FLAG_USER, sizeof(state->aec_reference[0]) * state->num_frames * state->num_aec_reference_channels); @@ -66,7 +65,7 @@ GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreateWithConfig(int capt int config_size) { struct GoogleRtcAudioProcessingState *s = - rballoc(0, SOF_MEM_CAPS_RAM, sizeof(GoogleRtcAudioProcessingState)); + rballoc(SOF_MEM_FLAG_USER, sizeof(GoogleRtcAudioProcessingState)); if (!s) return NULL; diff --git a/src/audio/host-legacy.c b/src/audio/host-legacy.c index e8d62e17301d..c172b60bec3b 100644 --- a/src/audio/host-legacy.c +++ b/src/audio/host-legacy.c @@ -442,7 +442,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, uint32 elem_array = &hd->local.elem_array; /* config buffer will be used as proxy */ - err = dma_sg_alloc(&hd->config.elem_array, SOF_MEM_ZONE_RUNTIME, + err = dma_sg_alloc(&hd->config.elem_array, SOF_MEM_FLAG_USER, dir, 1, 0, 0, 0); if (err < 0) { comp_err(dev, "create_local_elems(): dma_sg_alloc() failed"); @@ -452,7 +452,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, uint32 elem_array = &hd->config.elem_array; } - err = dma_sg_alloc(elem_array, SOF_MEM_ZONE_RUNTIME, dir, buffer_count, + err = dma_sg_alloc(elem_array, SOF_MEM_FLAG_USER, dir, buffer_count, buffer_bytes, (uintptr_t)(audio_stream_get_addr(&hd->dma_buffer->stream)), 0); if (err < 0) { @@ -578,7 +578,7 @@ static struct comp_dev *host_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - hd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*hd)); + hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd)); if (!hd) goto e_data; @@ -759,7 +759,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, goto out; } } else { - hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0, + hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, addr_align, false); if (!hd->dma_buffer) { comp_err(dev, "host_params(): failed to alloc dma buffer"); diff --git a/src/audio/host-zephyr.c b/src/audio/host-zephyr.c index 0cf19b45b7a1..b7f203eea3a0 100644 --- a/src/audio/host-zephyr.c +++ b/src/audio/host-zephyr.c @@ -587,7 +587,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, elem_array = &hd->local.elem_array; /* config buffer will be used as proxy */ - err = dma_sg_alloc(&hd->config.elem_array, SOF_MEM_ZONE_RUNTIME, + err = dma_sg_alloc(&hd->config.elem_array, SOF_MEM_FLAG_USER, dir, 1, 0, 0, 0); if (err < 0) { comp_err(dev, "dma_sg_alloc() failed"); @@ -597,7 +597,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, elem_array = &hd->config.elem_array; } - err = dma_sg_alloc(elem_array, SOF_MEM_ZONE_RUNTIME, dir, buffer_count, + err = dma_sg_alloc(elem_array, SOF_MEM_FLAG_USER, dir, buffer_count, buffer_bytes, (uintptr_t)audio_stream_get_addr(&hd->dma_buffer->stream), 0); if (err < 0) { @@ -727,7 +727,7 @@ __cold static struct comp_dev *host_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - hd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*hd)); + hd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hd)); if (!hd) goto e_data; @@ -921,7 +921,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, } else { /* allocate not shared buffer */ hd->dma_buffer = buffer_alloc_range(buffer_size_preferred, buffer_size, - SOF_MEM_CAPS_DMA, 0, addr_align, false); + SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, addr_align, false); if (!hd->dma_buffer) { comp_err(dev, "failed to alloc dma buffer"); return -ENOMEM; @@ -982,8 +982,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev, memset(dma_cfg, 0, sizeof(*dma_cfg)); - dma_block_cfg = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, - SOF_MEM_CAPS_RAM, + dma_block_cfg = rzalloc(SOF_MEM_FLAG_USER, sizeof(*dma_block_cfg)); if (!dma_block_cfg) { diff --git a/src/audio/igo_nr/igo_nr.c b/src/audio/igo_nr/igo_nr.c index d06e867b6d93..d3edc28a8027 100644 --- a/src/audio/igo_nr/igo_nr.c +++ b/src/audio/igo_nr/igo_nr.c @@ -421,7 +421,7 @@ static int igo_nr_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; @@ -433,7 +433,7 @@ static int igo_nr_init(struct processing_module *mod) goto cd_fail; } - cd->p_handle = rballoc(0, SOF_MEM_CAPS_RAM, cd->igo_lib_info.handle_size); + cd->p_handle = rballoc(SOF_MEM_FLAG_USER, cd->igo_lib_info.handle_size); if (!cd->p_handle) { comp_err(dev, "igo_nr_init(): igo_handle memory rballoc error for size %d", cd->igo_lib_info.handle_size); diff --git a/src/audio/kpb.c b/src/audio/kpb.c index 5890f1fc9413..b4cbf228a18a 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -495,7 +495,7 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - kpb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*kpb)); + kpb = rzalloc(SOF_MEM_FLAG_USER, sizeof(*kpb)); if (!kpb) { rfree(dev); return NULL; @@ -553,8 +553,7 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb, /*! Current allocation size */ size_t ca_size = hb_size; /*! Memory caps priorites for history buffer */ - int hb_mcp[KPB_NO_OF_MEM_POOLS] = {SOF_MEM_CAPS_LP, SOF_MEM_CAPS_HP, - SOF_MEM_CAPS_RAM }; + int hb_mcp[KPB_NO_OF_MEM_POOLS] = {SOF_MEM_FLAG_USER | SOF_MEM_FLAG_LOW_POWER, SOF_MEM_FLAG_USER}; void *new_mem_block = NULL; size_t temp_ca_size; int i = 0; @@ -563,7 +562,7 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb, comp_cl_info(&comp_kpb, "kpb_allocate_history_buffer()"); /* Initialize history buffer */ - kpb->hd.c_hb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + kpb->hd.c_hb = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct history_buffer)); if (!kpb->hd.c_hb) return 0; @@ -580,7 +579,7 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb, /* Try to allocate ca_size (current allocation size). At first * attempt it will be equal to hb_size (history buffer size). */ - new_mem_block = rballoc(0, hb_mcp[i], ca_size); + new_mem_block = rballoc(hb_mcp[i], ca_size); if (new_mem_block) { /* We managed to allocate a block of ca_size. @@ -602,8 +601,7 @@ static size_t kpb_allocate_history_buffer(struct comp_data *kpb, /* Yes, we still need at least one more buffer. * Let's first create new container for it. */ - new_hb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, - SOF_MEM_CAPS_RAM, + new_hb = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct history_buffer)); if (!new_hb) return 0; diff --git a/src/audio/mfcc/mfcc.c b/src/audio/mfcc/mfcc.c index 3eef92db3bab..b7a6a99c13b8 100644 --- a/src/audio/mfcc/mfcc.c +++ b/src/audio/mfcc/mfcc.c @@ -88,7 +88,7 @@ static int mfcc_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/mfcc/mfcc_setup.c b/src/audio/mfcc/mfcc_setup.c index 7f88e0b6eb9b..fa93da29350f 100644 --- a/src/audio/mfcc/mfcc_setup.c +++ b/src/audio/mfcc/mfcc_setup.c @@ -171,7 +171,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i comp_info(dev, "mfcc_setup(), buffer_size = %d, prev_size = %d", state->buffer_size, state->prev_data_size); - state->buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + state->buffers = rzalloc(SOF_MEM_FLAG_USER, state->sample_buffers_size); if (!state->buffers) { comp_err(dev, "mfcc_setup(): Failed buffer allocate"); @@ -189,14 +189,14 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i #else fft->fft_buffer_size = fft->fft_padded_size * sizeof(struct icomplex32); #endif - fft->fft_buf = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, fft->fft_buffer_size); + fft->fft_buf = rzalloc(SOF_MEM_FLAG_USER, fft->fft_buffer_size); if (!fft->fft_buf) { comp_err(dev, "mfcc_setup(): Failed FFT buffer allocate"); ret = -ENOMEM; goto free_buffers; } - fft->fft_out = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, fft->fft_buffer_size); + fft->fft_out = rzalloc(SOF_MEM_FLAG_USER, fft->fft_buffer_size); if (!fft->fft_out) { comp_err(dev, "mfcc_setup(): Failed FFT output allocate"); ret = -ENOMEM; diff --git a/src/audio/mixer/mixer.c b/src/audio/mixer/mixer.c index 42d4c9e33fbc..703e87ecee43 100644 --- a/src/audio/mixer/mixer.c +++ b/src/audio/mixer/mixer.c @@ -47,7 +47,7 @@ static int mixer_init(struct processing_module *mod) comp_dbg(dev, "mixer_init()"); - md = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*md)); + md = rzalloc(SOF_MEM_FLAG_USER, sizeof(*md)); if (!md) return -ENOMEM; diff --git a/src/audio/mixin_mixout/mixin_mixout.c b/src/audio/mixin_mixout/mixin_mixout.c index 82ff7acfb030..92f887ee0979 100644 --- a/src/audio/mixin_mixout/mixin_mixout.c +++ b/src/audio/mixin_mixout/mixin_mixout.c @@ -139,7 +139,7 @@ static int mixin_init(struct processing_module *mod) comp_dbg(dev, "mixin_init()"); - md = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*md)); + md = rzalloc(SOF_MEM_FLAG_USER, sizeof(*md)); if (!md) return -ENOMEM; @@ -166,7 +166,7 @@ static int mixout_init(struct processing_module *mod) comp_dbg(dev, "mixout_new()"); - mo_data = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*mo_data)); + mo_data = rzalloc(SOF_MEM_FLAG_USER, sizeof(*mo_data)); if (!mo_data) return -ENOMEM; diff --git a/src/audio/module_adapter/module/cadence.c b/src/audio/module_adapter/module/cadence.c index 8a24573a92f1..87ee611eb19f 100644 --- a/src/audio/module_adapter/module/cadence.c +++ b/src/audio/module_adapter/module/cadence.c @@ -235,7 +235,7 @@ static int cadence_codec_post_init(struct processing_module *mod) return ret; } /* Allocate space for codec object */ - cd->self = rballoc(0, SOF_MEM_CAPS_RAM, obj_size); + cd->self = rballoc(SOF_MEM_FLAG_USER, obj_size); if (!cd->self) { comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object"); return -ENOMEM; @@ -268,7 +268,7 @@ static int cadence_codec_init(struct processing_module *mod) comp_dbg(dev, "cadence_codec_init() start"); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct cadence_codec_data)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct cadence_codec_data)); if (!cd) { comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data"); return -ENOMEM; @@ -284,7 +284,7 @@ static int cadence_codec_init(struct processing_module *mod) cfg = (const struct ipc4_cadence_module_cfg *)codec->cfg.init_data; /* allocate memory for set up config */ - setup_cfg->data = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + setup_cfg->data = rmalloc(SOF_MEM_FLAG_USER, cfg->param_size); if (!setup_cfg->data) { comp_err(dev, "cadence_codec_init(): failed to alloc setup config"); @@ -293,7 +293,7 @@ static int cadence_codec_init(struct processing_module *mod) } /* allocate memory for runtime set up config */ - codec->cfg.data = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + codec->cfg.data = rmalloc(SOF_MEM_FLAG_USER, cfg->param_size); if (!codec->cfg.data) { comp_err(dev, "cadence_codec_init(): failed to alloc runtime setup config"); @@ -345,7 +345,7 @@ static int cadence_codec_init(struct processing_module *mod) comp_dbg(dev, "cadence_codec_init() start"); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct cadence_codec_data)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct cadence_codec_data)); if (!cd) { comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data"); return -ENOMEM; @@ -359,7 +359,7 @@ static int cadence_codec_init(struct processing_module *mod) setup_cfg = &cd->setup_cfg; /* allocate memory for set up config */ - setup_cfg->data = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + setup_cfg->data = rmalloc(SOF_MEM_FLAG_USER, codec->cfg.size); if (!setup_cfg->data) { comp_err(dev, "cadence_codec_init(): failed to alloc setup config"); diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index 9e2974acec39..f7983cf67d53 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -37,13 +37,13 @@ int module_load_config(struct comp_dev *dev, const void *cfg, size_t size) if (!dst->data) { /* No space for config available yet, allocate now */ - dst->data = rballoc(0, SOF_MEM_CAPS_RAM, size); + dst->data = rballoc(SOF_MEM_FLAG_USER, size); } else if (dst->size != size) { /* The size allocated for previous config doesn't match the new one. * Free old container and allocate new one. */ rfree(dst->data); - dst->data = rballoc(0, SOF_MEM_CAPS_RAM, size); + dst->data = rballoc(SOF_MEM_FLAG_USER, size); } if (!dst->data) { comp_err(dev, "module_load_config(): failed to allocate space for setup config."); @@ -122,7 +122,7 @@ void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint3 } /* Allocate memory container */ - container = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + container = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct module_memory)); if (!container) { comp_err(dev, "module_allocate_memory: failed to allocate memory container."); @@ -131,9 +131,9 @@ void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint3 /* Allocate memory for module */ if (alignment) - ptr = rballoc_align(0, SOF_MEM_CAPS_RAM, size, alignment); + ptr = rballoc_align(SOF_MEM_FLAG_USER, size, alignment); else - ptr = rballoc(0, SOF_MEM_CAPS_RAM, size); + ptr = rballoc(SOF_MEM_FLAG_USER, size); if (!ptr) { comp_err(dev, "module_allocate_memory: failed to allocate memory for comp %x.", @@ -444,7 +444,7 @@ int module_set_configuration(struct processing_module *mod, } /* Allocate buffer for new params */ - md->runtime_params = rballoc(0, SOF_MEM_CAPS_RAM, md->new_cfg_size); + md->runtime_params = rballoc(SOF_MEM_FLAG_USER, md->new_cfg_size); if (!md->runtime_params) { comp_err(dev, "module_set_configuration(): space allocation for new params failed"); return -ENOMEM; diff --git a/src/audio/module_adapter/module/passthrough.c b/src/audio/module_adapter/module/passthrough.c index 1955e3bc487a..6b9f28e3060a 100644 --- a/src/audio/module_adapter/module/passthrough.c +++ b/src/audio/module_adapter/module/passthrough.c @@ -32,14 +32,14 @@ static int passthrough_codec_prepare(struct processing_module *mod, mod->period_bytes = audio_stream_period_bytes(&source->stream, dev->frames); - codec->mpd.in_buff = rballoc(0, SOF_MEM_CAPS_RAM, mod->period_bytes); + codec->mpd.in_buff = rballoc(SOF_MEM_FLAG_USER, mod->period_bytes); if (!codec->mpd.in_buff) { comp_err(dev, "passthrough_codec_prepare(): Failed to alloc in_buff"); return -ENOMEM; } codec->mpd.in_buff_size = mod->period_bytes; - codec->mpd.out_buff = rballoc(0, SOF_MEM_CAPS_RAM, mod->period_bytes); + codec->mpd.out_buff = rballoc(SOF_MEM_FLAG_USER, mod->period_bytes); if (!codec->mpd.out_buff) { comp_err(dev, "passthrough_codec_prepare(): Failed to alloc out_buff"); rfree(codec->mpd.in_buff); diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 30926bfe02cf..45dab7b02e19 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -68,10 +68,10 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv, * will be bound to. So we need to allocate shared memory for each DP module * To be removed when pipeline 2.0 is ready */ - enum mem_zone zone = config->proc_domain == COMP_PROCESSING_DOMAIN_DP ? - SOF_MEM_ZONE_RUNTIME_SHARED : SOF_MEM_ZONE_RUNTIME; + int flags = config->proc_domain == COMP_PROCESSING_DOMAIN_DP ? + SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT : SOF_MEM_FLAG_USER; - mod = rzalloc(zone, 0, SOF_MEM_CAPS_RAM, sizeof(*mod)); + mod = rzalloc(flags, sizeof(*mod)); if (!mod) { comp_err(dev, "module_adapter_new(), failed to allocate memory for module"); goto err; @@ -290,7 +290,7 @@ int module_adapter_prepare(struct comp_dev *dev) /* allocate memory for input buffers */ if (mod->max_sources) { mod->input_buffers = - rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + rzalloc(SOF_MEM_FLAG_USER, sizeof(*mod->input_buffers) * mod->max_sources); if (!mod->input_buffers) { comp_err(dev, "module_adapter_prepare(): failed to allocate input buffers"); @@ -303,7 +303,7 @@ int module_adapter_prepare(struct comp_dev *dev) /* allocate memory for output buffers */ if (mod->max_sinks) { mod->output_buffers = - rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + rzalloc(SOF_MEM_FLAG_USER, sizeof(*mod->output_buffers) * mod->max_sinks); if (!mod->output_buffers) { comp_err(dev, "module_adapter_prepare(): failed to allocate output buffers"); @@ -370,7 +370,7 @@ int module_adapter_prepare(struct comp_dev *dev) list_for_item(blist, &dev->bsource_list) { size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes); - mod->input_buffers[i].data = rballoc(0, SOF_MEM_CAPS_RAM, size); + mod->input_buffers[i].data = rballoc(SOF_MEM_FLAG_USER, size); if (!mod->input_buffers[i].data) { comp_err(mod->dev, "module_adapter_prepare(): Failed to alloc input buffer data"); ret = -ENOMEM; @@ -382,7 +382,7 @@ int module_adapter_prepare(struct comp_dev *dev) /* allocate memory for output buffer data */ i = 0; list_for_item(blist, &dev->bsink_list) { - mod->output_buffers[i].data = rballoc(0, SOF_MEM_CAPS_RAM, md->mpd.out_buff_size); + mod->output_buffers[i].data = rballoc(SOF_MEM_FLAG_USER, md->mpd.out_buff_size); if (!mod->output_buffers[i].data) { comp_err(mod->dev, "module_adapter_prepare(): Failed to alloc output buffer data"); ret = -ENOMEM; @@ -395,8 +395,8 @@ int module_adapter_prepare(struct comp_dev *dev) if (list_is_empty(&mod->raw_data_buffers_list)) { for (i = 0; i < mod->num_of_sinks; i++) { /* allocate not shared buffer */ - struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM, - 0, PLATFORM_DCACHE_ALIGN, false); + struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_FLAG_USER, + PLATFORM_DCACHE_ALIGN, false); uint32_t flags; if (!buffer) { @@ -479,7 +479,7 @@ int module_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *pa if (mod->stream_params) rfree(mod->stream_params); - mod->stream_params = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + mod->stream_params = rzalloc(SOF_MEM_FLAG_USER, sizeof(*mod->stream_params) + params->ext_data_length); if (!mod->stream_params) return -ENOMEM; diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index f41ed7f6556c..a4acf4727c41 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -136,8 +136,7 @@ int module_adapter_init_data(struct comp_dev *dev, if (cfgsz == (sizeof(*cfg) + pinsz)) { dst->nb_input_pins = n_in; dst->nb_output_pins = n_out; - dst->input_pins = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, pinsz); + dst->input_pins = rmalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, pinsz); if (!dst->input_pins) return -ENOMEM; diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index 45df154dfad6..97d2c0974d18 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -72,7 +72,7 @@ static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef, if (SOF_EMP_DEEMP_BIQUADS != SOF_IIR_DF1_4TH_NUM_BIQUADS) return -EINVAL; - eq->coef = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + eq->coef = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS); if (!eq->coef) return -ENOMEM; @@ -86,7 +86,7 @@ static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef, * delay[0..1] -> state for first biquad * delay[2..3] -> state for second biquad */ - eq->delay = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + eq->delay = rzalloc(SOF_MEM_FLAG_USER, sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4); if (!eq->delay) return -ENOMEM; @@ -243,7 +243,7 @@ static int multiband_drc_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 1b1e25314b16..fe8f6d881ab2 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -94,7 +94,7 @@ static int mux_demux_common_init(struct processing_module *mod, enum sof_comp_ty return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd) + MUX_BLOB_STREAMS_SIZE); if (!cd) return -ENOMEM; diff --git a/src/audio/nxp/eap.c b/src/audio/nxp/eap.c index 09c1f90a55f7..4e6e2c5eb535 100644 --- a/src/audio/nxp/eap.c +++ b/src/audio/nxp/eap.c @@ -93,7 +93,7 @@ static int nxp_eap_init(struct processing_module *mod) tr_info(mod->dev, "NXP EAP library, platform: %s version:%s", info.pPlatform, info.pVersionNumber); - eap = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(*eap)); + eap = rballoc(SOF_MEM_FLAG_USER, sizeof(*eap)); if (!eap) { comp_err(dev, "nxp_eap_init() failed to allocate module private data"); return -ENOMEM; @@ -115,7 +115,7 @@ static int nxp_eap_init(struct processing_module *mod) eap->mem_tab.Region[i].pBaseAddress = NULL; for (int i = 0; i < LVM_NR_MEMORY_REGIONS; i++) { - eap->mem_tab.Region[i].pBaseAddress = rballoc(0, SOF_MEM_CAPS_RAM, + eap->mem_tab.Region[i].pBaseAddress = rballoc(SOF_MEM_FLAG_USER, eap->mem_tab.Region[i].Size); if (!eap->mem_tab.Region[i].pBaseAddress) { comp_err(dev, "nxp_eap_init() failed to allocate memory for region %d", i); @@ -189,11 +189,11 @@ static int nxp_eap_prepare(struct processing_module *mod, */ eap->buffer_bytes = NXP_EAP_DEFAULT_MAX_BLOCK_SIZE; - md->mpd.in_buff = rballoc_align(0, SOF_MEM_CAPS_RAM, eap->buffer_bytes, 32); + md->mpd.in_buff = rballoc_align(SOF_MEM_FLAG_USER, eap->buffer_bytes, 32); if (!md->mpd.in_buff) return -ENOMEM; - md->mpd.out_buff = rballoc_align(0, SOF_MEM_CAPS_RAM, eap->buffer_bytes, 32); + md->mpd.out_buff = rballoc_align(SOF_MEM_FLAG_USER, eap->buffer_bytes, 32); if (!md->mpd.out_buff) { rfree(md->mpd.in_buff); return -ENOMEM; diff --git a/src/audio/pipeline/pipeline-graph.c b/src/audio/pipeline/pipeline-graph.c index 15ae9d84c2eb..e3c0163af1c0 100644 --- a/src/audio/pipeline/pipeline-graph.c +++ b/src/audio/pipeline/pipeline-graph.c @@ -120,7 +120,7 @@ struct pipeline *pipeline_new(uint32_t pipeline_id, uint32_t priority, uint32_t heap_trace_all(0); /* allocate new pipeline */ - p = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*p)); + p = rzalloc(SOF_MEM_FLAG_USER, sizeof(*p)); if (!p) { pipe_cl_err("pipeline_new(): Out of Memory"); return NULL; diff --git a/src/audio/pipeline/pipeline-schedule.c b/src/audio/pipeline/pipeline-schedule.c index b7697e0ddb9a..15f41759bbd3 100644 --- a/src/audio/pipeline/pipeline-schedule.c +++ b/src/audio/pipeline/pipeline-schedule.c @@ -240,7 +240,7 @@ static struct task *pipeline_task_init(struct pipeline *p, uint32_t type) { struct pipeline_task *task = NULL; - task = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + task = rzalloc(SOF_MEM_FLAG_USER, sizeof(*task)); if (!task) return NULL; diff --git a/src/audio/rtnr/rtnr.c b/src/audio/rtnr/rtnr.c index 3cb0cb484a8d..19652a8a40e0 100644 --- a/src/audio/rtnr/rtnr.c +++ b/src/audio/rtnr/rtnr.c @@ -105,7 +105,7 @@ void rtnr_printf(int a, int b, int c, int d, int e) void *rtk_rballoc(unsigned int flags, unsigned int caps, unsigned int bytes) { - return rballoc(flags, caps, bytes); + return rballoc(flags, bytes); } void rtk_rfree(void *ptr) @@ -241,7 +241,7 @@ static int rtnr_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/rtnr/rtnr_stub.c b/src/audio/rtnr/rtnr_stub.c index 1ce74a31b96d..a825396ece3f 100644 --- a/src/audio/rtnr/rtnr_stub.c +++ b/src/audio/rtnr/rtnr_stub.c @@ -73,7 +73,7 @@ void *RTKMA_API_Context_Create(int sample_rate) /* Allocate something, to avoid return NULL and cause error * in check of success of this. */ - return rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, RTNR_STUB_CONTEXT_SIZE); + return rzalloc(SOF_MEM_FLAG_USER, RTNR_STUB_CONTEXT_SIZE); } void RTKMA_API_Context_Free(void *Context) diff --git a/src/audio/selector/selector.c b/src/audio/selector/selector.c index 20ab3ff5b8c1..afb5d091575c 100644 --- a/src/audio/selector/selector.c +++ b/src/audio/selector/selector.c @@ -162,7 +162,7 @@ static struct comp_dev *selector_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { rfree(dev); return NULL; @@ -613,7 +613,7 @@ static int selector_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/smart_amp/smart_amp.c b/src/audio/smart_amp/smart_amp.c index c4c2642d0d67..db17bd8d571d 100644 --- a/src/audio/smart_amp/smart_amp.c +++ b/src/audio/smart_amp/smart_amp.c @@ -95,7 +95,7 @@ static inline void smart_amp_free_mod_memories(struct smart_amp_data *sad) static inline int smart_amp_buf_alloc(struct smart_amp_buf *buf, size_t size) { - buf->data = rballoc(0, SOF_MEM_CAPS_RAM, size); + buf->data = rballoc(SOF_MEM_FLAG_USER, size); if (!buf->data) return -ENOMEM; buf->size = size; @@ -189,7 +189,7 @@ static struct comp_dev *smart_amp_new(const struct comp_driver *drv, dev->ipc_config = *config; - sad = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*sad)); + sad = rzalloc(SOF_MEM_FLAG_USER, sizeof(*sad)); if (!sad) { rfree(dev); return NULL; diff --git a/src/audio/smart_amp/smart_amp_maxim_dsm.c b/src/audio/smart_amp/smart_amp_maxim_dsm.c index e45620248dd4..3360ff5c3b86 100644 --- a/src/audio/smart_amp/smart_amp_maxim_dsm.c +++ b/src/audio/smart_amp/smart_amp_maxim_dsm.c @@ -838,7 +838,7 @@ struct smart_amp_mod_data_base *mod_data_create(const struct comp_dev *dev) { struct smart_amp_mod_struct_t *hspk; - hspk = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*hspk)); + hspk = rzalloc(SOF_MEM_FLAG_USER, sizeof(*hspk)); if (!hspk) return NULL; diff --git a/src/audio/smart_amp/smart_amp_passthru.c b/src/audio/smart_amp/smart_amp_passthru.c index dd5c2fe3d789..d2e408a6ccd4 100644 --- a/src/audio/smart_amp/smart_amp_passthru.c +++ b/src/audio/smart_amp/smart_amp_passthru.c @@ -137,7 +137,7 @@ struct smart_amp_mod_data_base *mod_data_create(const struct comp_dev *dev) { struct passthru_mod_data *mod; - mod = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*mod)); + mod = rzalloc(SOF_MEM_FLAG_USER, sizeof(*mod)); if (!mod) return NULL; diff --git a/src/audio/src/src_common.c b/src/audio/src/src_common.c index 625077a57e4a..a2487314efa6 100644 --- a/src/audio/src/src_common.c +++ b/src/audio/src/src_common.c @@ -533,7 +533,7 @@ int src_params_general(struct processing_module *mod, /* free any existing delay lines. TODO reuse if same size */ rfree(cd->delay_lines); - cd->delay_lines = rballoc(0, SOF_MEM_CAPS_RAM, delay_lines_size); + cd->delay_lines = rballoc(SOF_MEM_FLAG_USER, delay_lines_size); if (!cd->delay_lines) { comp_err(dev, "src_params(): failed to alloc cd->delay_lines, delay_lines_size = %zu", delay_lines_size); @@ -607,7 +607,7 @@ int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm, size_t tap_size = sizeof(int32_t); #endif - stage_dst = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + stage_dst = rmalloc(SOF_MEM_FLAG_USER, 2 * sizeof(*stage_dst)); if (!stage_dst) { comp_err(dev, "failed to allocate stages"); diff --git a/src/audio/src/src_ipc3.c b/src/audio/src/src_ipc3.c index 175263deae7a..93b0348ba462 100644 --- a/src/audio/src/src_ipc3.c +++ b/src/audio/src/src_ipc3.c @@ -178,7 +178,7 @@ int src_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/src/src_ipc4.c b/src/audio/src/src_ipc4.c index ba6302dfc4ea..76ef1a50175c 100644 --- a/src/audio/src/src_ipc4.c +++ b/src/audio/src/src_ipc4.c @@ -209,7 +209,7 @@ __cold int src_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index b335b56ea47e..27136884cfde 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -514,7 +514,7 @@ static int tdfb_setup(struct processing_module *mod, int source_nch, int sink_nc tdfb_free_delaylines(cd); /* Allocate all FIR channels data in a big chunk and clear it */ - cd->fir_delay = rballoc(0, SOF_MEM_CAPS_RAM, delay_size); + cd->fir_delay = rballoc(SOF_MEM_FLAG_USER, delay_size); if (!cd->fir_delay) { comp_err(mod->dev, "tdfb_setup(), delay allocation failed for size %d", delay_size); @@ -554,7 +554,7 @@ static int tdfb_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/tdfb/tdfb_direction.c b/src/audio/tdfb/tdfb_direction.c index 413a5ea5be36..640fe4eaa06e 100644 --- a/src/audio/tdfb/tdfb_direction.c +++ b/src/audio/tdfb/tdfb_direction.c @@ -200,7 +200,7 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) /* Allocate delay lines for IIR filters and initialize them */ size = ch_count * iir_delay_size_df1(filt); - delay = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, size); + delay = rzalloc(SOF_MEM_FLAG_USER, size); if (!delay) return -ENOMEM; @@ -225,7 +225,7 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) cd->direction.max_lag = Q_MULTSR_32X32((int64_t)fs, t_max, 0, 15, 0) + 1; n = (cd->max_frames + (2 * cd->direction.max_lag + 1)) * ch_count; cd->direction.d_size = n * sizeof(int16_t); - cd->direction.d = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, cd->direction.d_size); + cd->direction.d = rzalloc(SOF_MEM_FLAG_USER, cd->direction.d_size); if (!cd->direction.d) goto err_free_iir; @@ -238,7 +238,7 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count) /* xcorr result is temporary but too large for stack so it is allocated here */ cd->direction.r_size = (2 * cd->direction.max_lag + 1) * sizeof(int32_t); - cd->direction.r = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, cd->direction.r_size); + cd->direction.r = rzalloc(SOF_MEM_FLAG_USER, cd->direction.r_size); if (!cd->direction.r) goto err_free_all; diff --git a/src/audio/tdfb/tdfb_ipc3.c b/src/audio/tdfb/tdfb_ipc3.c index cbeba12a983d..52662a141e56 100644 --- a/src/audio/tdfb/tdfb_ipc3.c +++ b/src/audio/tdfb/tdfb_ipc3.c @@ -30,7 +30,7 @@ static int init_get_ctl_ipc(struct processing_module *mod) struct tdfb_comp_data *cd = module_get_private_data(mod); int comp_id = dev_comp_id(mod->dev); - cd->ctrl_data = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, TDFB_GET_CTRL_DATA_SIZE); + cd->ctrl_data = rzalloc(SOF_MEM_FLAG_USER, TDFB_GET_CTRL_DATA_SIZE); if (!cd->ctrl_data) return -ENOMEM; diff --git a/src/audio/template_comp/template.c b/src/audio/template_comp/template.c index dd15288d9a19..7b15f1fbf591 100644 --- a/src/audio/template_comp/template.c +++ b/src/audio/template_comp/template.c @@ -40,7 +40,7 @@ __cold static int template_comp_init(struct processing_module *mod) comp_info(dev, "template_comp_init()"); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/tensorflow/tflm-classify.c b/src/audio/tensorflow/tflm-classify.c index b6f25849d87a..9dafe056110c 100644 --- a/src/audio/tensorflow/tflm-classify.c +++ b/src/audio/tensorflow/tflm-classify.c @@ -61,7 +61,7 @@ __cold static int tflm_init(struct processing_module *mod) comp_info(dev, "tflm_init()"); - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) return -ENOMEM; diff --git a/src/audio/tone.c b/src/audio/tone.c index 2cc3a82d8fcb..0a175b5ed1ee 100644 --- a/src/audio/tone.c +++ b/src/audio/tone.c @@ -392,7 +392,7 @@ static struct comp_dev *tone_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { rfree(dev); return NULL; diff --git a/src/audio/up_down_mixer/up_down_mixer.c b/src/audio/up_down_mixer/up_down_mixer.c index e1cb4d9e13bc..acfeb926b666 100644 --- a/src/audio/up_down_mixer/up_down_mixer.c +++ b/src/audio/up_down_mixer/up_down_mixer.c @@ -342,7 +342,7 @@ static int up_down_mixer_init(struct processing_module *mod) struct up_down_mixer_data *cd; int ret; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { comp_free(dev); return -ENOMEM; @@ -350,8 +350,8 @@ static int up_down_mixer_init(struct processing_module *mod) mod_data->private = cd; - cd->buf_in = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.ibs); - cd->buf_out = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.obs); + cd->buf_in = rballoc(SOF_MEM_FLAG_USER, mod->priv.cfg.base_cfg.ibs); + cd->buf_out = rballoc(SOF_MEM_FLAG_USER, mod->priv.cfg.base_cfg.obs); if (!cd->buf_in || !cd->buf_out) { ret = -ENOMEM; goto err; diff --git a/src/audio/volume/volume_ipc3.c b/src/audio/volume/volume_ipc3.c index 0e599a0dabd6..2b5adefbf067 100644 --- a/src/audio/volume/volume_ipc3.c +++ b/src/audio/volume/volume_ipc3.c @@ -81,7 +81,7 @@ int volume_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct vol_data)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data)); if (!cd) return -ENOMEM; @@ -89,7 +89,7 @@ int volume_init(struct processing_module *mod) * malloc memory to store current volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->vol = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, vol_size); + cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size); if (!cd->vol) { rfree(cd); comp_err(dev, "volume_init(): Failed to allocate %zu", vol_size); diff --git a/src/audio/volume/volume_ipc4.c b/src/audio/volume/volume_ipc4.c index 2424cbb13a76..39f343b004cc 100644 --- a/src/audio/volume/volume_ipc4.c +++ b/src/audio/volume/volume_ipc4.c @@ -128,7 +128,7 @@ int volume_init(struct processing_module *mod) return -EINVAL; } - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct vol_data)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct vol_data)); if (!cd) return -ENOMEM; @@ -136,7 +136,7 @@ int volume_init(struct processing_module *mod) * malloc memory to store current volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->vol = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, vol_size); + cd->vol = rmalloc(SOF_MEM_FLAG_USER, vol_size); if (!cd->vol) { rfree(cd); comp_err(dev, "volume_init(): Failed to allocate %d", vol_size); @@ -146,7 +146,7 @@ int volume_init(struct processing_module *mod) /* malloc memory to store temp peak volume 4 times to ensure the address * is 8-byte aligned for multi-way xtensa intrinsic operations. */ - cd->peak_vol = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, vol_size); + cd->peak_vol = rzalloc(SOF_MEM_FLAG_USER, vol_size); if (!cd->peak_vol) { rfree(cd->vol); rfree(cd); diff --git a/src/debug/debug_stream/debug_stream_thread_info.c b/src/debug/debug_stream/debug_stream_thread_info.c index a4cb056ec2ac..4b47df638158 100644 --- a/src/debug/debug_stream/debug_stream_thread_info.c +++ b/src/debug/debug_stream/debug_stream_thread_info.c @@ -173,7 +173,7 @@ static int thread_info_buf_realloc(struct record_buf *bufd, size_t req_size) size *= 2; if (size != bufd->size) { - uint8_t *buf = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, size); + uint8_t *buf = rmalloc(SOF_MEM_FLAG_USER, size); if (!buf) return -ENOMEM; @@ -321,7 +321,7 @@ static void thread_info_run(void *cnum, void *a, void *b) .w_ptr = 0, }; - bufd.buf = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, bufd.size); + bufd.buf = rmalloc(SOF_MEM_FLAG_USER, bufd.size); if (!bufd.buf) { LOG_ERR("malloc failed"); return; diff --git a/src/debug/tester/tester.c b/src/debug/tester/tester.c index 575e339646a8..73686ff49652 100644 --- a/src/debug/tester/tester.c +++ b/src/debug/tester/tester.c @@ -64,7 +64,7 @@ static int tester_init(struct processing_module *mod) /* allocate ctx for test module in shared memory - to allow all non-standard operations * without problems with cache */ - cd = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*cd)); if (!cd) { comp_err(dev, "Out of memory"); return -ENOMEM; diff --git a/src/debug/tester/tester_dummy_test.c b/src/debug/tester/tester_dummy_test.c index 138314e5a1df..6d9e2596b3f4 100644 --- a/src/debug/tester/tester_dummy_test.c +++ b/src/debug/tester/tester_dummy_test.c @@ -21,7 +21,7 @@ struct tester_module_dummy_test_data { static int dummy_test_case_init(struct processing_module *mod, void **ctx) { struct tester_module_dummy_test_data *data = - rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*data)); + rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*data)); if (!data) return -ENOMEM; diff --git a/src/debug/tester/tester_simple_dram_test.c b/src/debug/tester/tester_simple_dram_test.c index 5cf1917de3cd..1a32e0ff6440 100644 --- a/src/debug/tester/tester_simple_dram_test.c +++ b/src/debug/tester/tester_simple_dram_test.c @@ -34,7 +34,7 @@ __cold static int simple_dram_test_case_init(struct processing_module *mod, void return -EINVAL; #endif struct tester_module_simple_dram_test_data *data = - rzalloc(0, 0, SOF_MEM_CAPS_L3, sizeof(*data)); + rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_L3, sizeof(*data)); assert_can_be_cold(); diff --git a/src/drivers/amd/common/acp_dma.c b/src/drivers/amd/common/acp_dma.c index b6f8a7f116e3..bd1e6cba16a2 100644 --- a/src/drivers/amd/common/acp_dma.c +++ b/src/drivers/amd/common/acp_dma.c @@ -299,7 +299,7 @@ static int acp_dma_probe(struct dma *dma) tr_err(&acpdma_tr, "DMA: Already probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { @@ -310,8 +310,7 @@ static int acp_dma_probe(struct dma *dma) dma->chan[channel].dma = dma; dma->chan[channel].index = channel; dma->chan[channel].status = COMP_STATE_INIT; - acp_dma_chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, + acp_dma_chan = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct acp_dma_chan_data)); if (!acp_dma_chan) { rfree(dma->chan); diff --git a/src/drivers/amd/common/acp_dmic_dai.c b/src/drivers/amd/common/acp_dmic_dai.c index bce741cd92d3..f0c411141f03 100644 --- a/src/drivers/amd/common/acp_dmic_dai.c +++ b/src/drivers/amd/common/acp_dmic_dai.c @@ -87,7 +87,7 @@ static int acp_dmic_dai_probe(struct dai *dai) dai_info(dai, "dmic dai probe"); /* allocate private data */ - acp = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*acp)); + acp = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*acp)); if (!acp) { dai_err(dai, "dmic dai probe alloc failed"); return -ENOMEM; diff --git a/src/drivers/amd/common/acp_dmic_dma.c b/src/drivers/amd/common/acp_dmic_dma.c index 962ce7314c59..70d371d62784 100644 --- a/src/drivers/amd/common/acp_dmic_dma.c +++ b/src/drivers/amd/common/acp_dmic_dma.c @@ -152,8 +152,8 @@ static int acp_dmic_dma_probe(struct dma *dma) tr_err(&acp_dmic_dma_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_dmic_dma_tr, "unable to allocate channel descriptors"); diff --git a/src/drivers/amd/common/acp_sp_dma.c b/src/drivers/amd/common/acp_sp_dma.c index aaa40076c069..fd431ba7b4b7 100644 --- a/src/drivers/amd/common/acp_sp_dma.c +++ b/src/drivers/amd/common/acp_sp_dma.c @@ -113,8 +113,8 @@ static int acp_dai_sp_dma_probe(struct dma *dma) tr_err(&acp_sp_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_sp_tr, "Probe failure,unable to allocate channel descriptors"); diff --git a/src/drivers/amd/rembrandt/acp_bt_dma.c b/src/drivers/amd/rembrandt/acp_bt_dma.c index 4275a21331c7..ecf85027528a 100644 --- a/src/drivers/amd/rembrandt/acp_bt_dma.c +++ b/src/drivers/amd/rembrandt/acp_bt_dma.c @@ -297,8 +297,8 @@ static int acp_dai_bt_dma_probe(struct dma *dma) tr_err(&acp_bt_dma_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_bt_dma_tr, "Probe failure, unable to allocate channel descriptors"); diff --git a/src/drivers/amd/rembrandt/acp_hs_dai.c b/src/drivers/amd/rembrandt/acp_hs_dai.c index 6b51a1a248e5..780454f52c87 100644 --- a/src/drivers/amd/rembrandt/acp_hs_dai.c +++ b/src/drivers/amd/rembrandt/acp_hs_dai.c @@ -127,7 +127,7 @@ static int hsdai_probe(struct dai *dai) dai_info(dai, "HS dai probe"); /* allocate private data */ - acp = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*acp)); + acp = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*acp)); if (!acp) { dai_err(dai, "HS dai probe alloc failed"); return -ENOMEM; diff --git a/src/drivers/amd/rembrandt/acp_hs_dma.c b/src/drivers/amd/rembrandt/acp_hs_dma.c index 68b729af0fea..fbed6593ad55 100644 --- a/src/drivers/amd/rembrandt/acp_hs_dma.c +++ b/src/drivers/amd/rembrandt/acp_hs_dma.c @@ -294,8 +294,8 @@ static int acp_dai_hs_dma_probe(struct dma *dma) tr_err(&acp_hs_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_hs_tr, "Probe failure,unable to allocate channel descriptors"); diff --git a/src/drivers/amd/rembrandt/acp_sw_audio_dai.c b/src/drivers/amd/rembrandt/acp_sw_audio_dai.c index 5523a5717d20..1b31cffd59d8 100644 --- a/src/drivers/amd/rembrandt/acp_sw_audio_dai.c +++ b/src/drivers/amd/rembrandt/acp_sw_audio_dai.c @@ -37,7 +37,7 @@ static int swaudiodai_probe(struct dai *dai) dai_info(dai, "#$AMD$# SW dai probe"); /* allocate private data */ - acp = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*acp)); + acp = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*acp)); if (!acp) { dai_err(dai, "SW dai probe alloc failed"); return -ENOMEM; diff --git a/src/drivers/amd/rembrandt/acp_sw_audio_dma.c b/src/drivers/amd/rembrandt/acp_sw_audio_dma.c index 07c7b0d703c3..25c72c9c0fff 100644 --- a/src/drivers/amd/rembrandt/acp_sw_audio_dma.c +++ b/src/drivers/amd/rembrandt/acp_sw_audio_dma.c @@ -373,8 +373,8 @@ static int acp_dai_sw_audio_dma_probe(struct dma *dma) tr_err(&acp_sw_audio_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_sw_audio_tr, "Probe failure,unable to allocate channel descriptors"); diff --git a/src/drivers/amd/renoir/acp_bt_dma.c b/src/drivers/amd/renoir/acp_bt_dma.c index cab4d696ba46..d3e05fd77810 100644 --- a/src/drivers/amd/renoir/acp_bt_dma.c +++ b/src/drivers/amd/renoir/acp_bt_dma.c @@ -294,8 +294,8 @@ static int acp_dai_bt_dma_probe(struct dma *dma) tr_err(&acp_bt_dma_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_bt_dma_tr, "Probe failure, unable to allocate channel descriptors"); diff --git a/src/drivers/amd/renoir/acp_sp_dai.c b/src/drivers/amd/renoir/acp_sp_dai.c index 26932d00044a..0078b4d3a9d5 100644 --- a/src/drivers/amd/renoir/acp_sp_dai.c +++ b/src/drivers/amd/renoir/acp_sp_dai.c @@ -85,7 +85,7 @@ static int spdai_probe(struct dai *dai) dai_info(dai, "SP dai probe"); /* allocate private data */ - acp = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*acp)); + acp = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*acp)); if (!acp) { dai_err(dai, "SP dai probe alloc failed"); return -ENOMEM; diff --git a/src/drivers/amd/vangogh/acp_bt_dma.c b/src/drivers/amd/vangogh/acp_bt_dma.c index 1dee67b6b0ec..4f08bc69abee 100644 --- a/src/drivers/amd/vangogh/acp_bt_dma.c +++ b/src/drivers/amd/vangogh/acp_bt_dma.c @@ -292,8 +292,8 @@ static int acp_dai_bt_dma_probe(struct dma *dma) tr_err(&acp_bt_dma_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_bt_dma_tr, "Probe failure, unable to allocate channel descriptors"); diff --git a/src/drivers/amd/vangogh/acp_hs_dma.c b/src/drivers/amd/vangogh/acp_hs_dma.c index 532f53e32749..361f74170932 100644 --- a/src/drivers/amd/vangogh/acp_hs_dma.c +++ b/src/drivers/amd/vangogh/acp_hs_dma.c @@ -293,8 +293,8 @@ static int acp_dai_hs_dma_probe(struct dma *dma) tr_err(&acp_hs_tr, "Repeated probe"); return -EEXIST; } - dma->chan = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, - SOF_MEM_CAPS_RAM, dma->plat_data.channels * + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, + dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&acp_hs_tr, "Probe failure,unable to allocate channel descriptors"); diff --git a/src/drivers/dw/dma.c b/src/drivers/dw/dma.c index 8edd898eb25a..97ac6ddabbad 100644 --- a/src/drivers/dw/dma.c +++ b/src/drivers/dw/dma.c @@ -545,8 +545,7 @@ static int dw_dma_set_config(struct dma_chan_data *channel, if (dw_chan->lli) rfree(dw_chan->lli); - dw_chan->lli = rmalloc(SOF_MEM_ZONE_RUNTIME, SOF_MEM_FLAG_COHERENT, - SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, + dw_chan->lli = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA, sizeof(struct dw_lli) * channel->desc_count); if (!dw_chan->lli) { tr_err(&dwdma_tr, "dw_dma_set_config(): dma %d channel %d lli alloc failed", @@ -937,7 +936,7 @@ static int dw_dma_probe(struct dma *dma) pm_runtime_get_sync(DW_DMAC_CLK, dma->plat_data.id); /* allocate dma channels */ - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct dma_chan_data) * dma->plat_data.channels); if (!dma->chan) { @@ -958,7 +957,7 @@ static int dw_dma_probe(struct dma *dma) chan->index = i; chan->core = DMA_CORE_INVALID; - dw_chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dw_chan = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*dw_chan)); if (!dw_chan) { diff --git a/src/drivers/dw/ssi-spi.c b/src/drivers/dw/ssi-spi.c index 2ed54fe8ceee..364ea9d19b9c 100644 --- a/src/drivers/dw/ssi-spi.c +++ b/src/drivers/dw/ssi-spi.c @@ -451,14 +451,14 @@ int spi_probe(struct spi *spi) /* configure the spi clock */ io_reg_write(SSI_SLAVE_CLOCK_CTL, 0x00000001); - spi->rx_buffer = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_DMA, + spi->rx_buffer = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_DMA, SPI_BUFFER_SIZE); if (!spi->rx_buffer) { tr_err(&ipc_tr, "eSp"); return -ENOMEM; } - spi->tx_buffer = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_DMA, + spi->tx_buffer = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_DMA, SPI_BUFFER_SIZE); spi->buffer_size = SPI_BUFFER_SIZE; if (!spi->tx_buffer) { @@ -508,7 +508,7 @@ int spi_install(const struct spi_platform_data *plat, size_t n) goto unlock; } - spi_devices = rmalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + spi_devices = rmalloc(SOF_MEM_FLAG_KERNEL, sizeof(*spi) * n); if (!spi_devices) { ret = -ENOMEM; diff --git a/src/drivers/generic/dummy-dma.c b/src/drivers/generic/dummy-dma.c index 8b710d31b930..c088d9415d55 100644 --- a/src/drivers/generic/dummy-dma.c +++ b/src/drivers/generic/dummy-dma.c @@ -421,7 +421,7 @@ static int dummy_dma_probe(struct dma *dma) return -EEXIST; /* already created */ } - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, dma->plat_data.channels * sizeof(dma->chan[0])); if (!dma->chan) { tr_err(&ddma_tr, "dummy-dmac %d: Out of memory!", @@ -429,7 +429,7 @@ static int dummy_dma_probe(struct dma *dma) return -ENOMEM; } - chanp = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + chanp = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(chanp[0])); if (!chanp) { rfree(dma->chan); diff --git a/src/drivers/imx/edma.c b/src/drivers/imx/edma.c index a7b75efab7d7..f8e3fb1dcf7c 100644 --- a/src/drivers/imx/edma.c +++ b/src/drivers/imx/edma.c @@ -420,7 +420,7 @@ static int edma_probe(struct dma *dma) } tr_info(&edma_tr, "EDMA: probe"); - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { diff --git a/src/drivers/imx/esai.c b/src/drivers/imx/esai.c index d917b814893d..4c62009e56bc 100644 --- a/src/drivers/imx/esai.c +++ b/src/drivers/imx/esai.c @@ -338,7 +338,7 @@ static int esai_probe(struct dai *dai) dai_err(dai, "ESAI: Repeated probe, skipping"); return -EEXIST; } - pdata = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*pdata)); + pdata = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*pdata)); if (!pdata) { dai_err(dai, "ESAI probe failure, out of memory"); return -ENOMEM; diff --git a/src/drivers/imx/ipc.c b/src/drivers/imx/ipc.c index 1b398088cb1c..328ecec2e93c 100644 --- a/src/drivers/imx/ipc.c +++ b/src/drivers/imx/ipc.c @@ -184,7 +184,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE struct ipc_data *iipc; - iipc = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*iipc)); + iipc = rzalloc(SOF_MEM_FLAG_USER, sizeof(*iipc)); if (!iipc) { tr_err(&ipc_tr, "Unable to allocate IPC private data"); return -ENOMEM; @@ -200,8 +200,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE /* allocate page table buffer */ - iipc->dh_buffer.page_table = rzalloc(SOF_MEM_ZONE_SYS, 0, - SOF_MEM_CAPS_RAM, + iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_USER, PLATFORM_PAGE_TABLE_SIZE); if (iipc->dh_buffer.page_table) bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE); diff --git a/src/drivers/imx/micfil.c b/src/drivers/imx/micfil.c index 66cc88639e15..5cbf5c3e292b 100644 --- a/src/drivers/imx/micfil.c +++ b/src/drivers/imx/micfil.c @@ -290,7 +290,7 @@ static int micfil_probe(struct dai *dai) dai_info(dai, "micfil_probe()"); - micfil = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*micfil)); + micfil = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*micfil)); if (!micfil) { dai_err(dai, "micfil probe failed"); return -ENOMEM; diff --git a/src/drivers/imx/sai.c b/src/drivers/imx/sai.c index 7971b76a8b7f..eeb4555d3143 100644 --- a/src/drivers/imx/sai.c +++ b/src/drivers/imx/sai.c @@ -468,7 +468,7 @@ static int sai_probe(struct dai *dai) dai_info(dai, "SAI: sai_probe"); /* allocate private data */ - sai = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sai)); + sai = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*sai)); if (!sai) { dai_err(dai, "sai_probe(): alloc failed"); return -ENOMEM; diff --git a/src/drivers/imx/sdma.c b/src/drivers/imx/sdma.c index 6f24e9c0c8b4..3f47b34101b5 100644 --- a/src/drivers/imx/sdma.c +++ b/src/drivers/imx/sdma.c @@ -289,7 +289,7 @@ static int sdma_probe(struct dma *dma) tr_info(&sdma_tr, "SDMA: probe"); - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { @@ -297,7 +297,7 @@ static int sdma_probe(struct dma *dma) return -ENOMEM; } - pdata = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + pdata = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*pdata)); if (!pdata) { rfree(dma->chan); @@ -313,7 +313,7 @@ static int sdma_probe(struct dma *dma) dma->chan[channel].dma = dma; } - pdata->chan_pdata = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + pdata->chan_pdata = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct sdma_chan)); if (!pdata->chan_pdata) { @@ -322,7 +322,7 @@ static int sdma_probe(struct dma *dma) goto err; } - pdata->contexts = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + pdata->contexts = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct sdma_context)); if (!pdata->contexts) { @@ -331,7 +331,7 @@ static int sdma_probe(struct dma *dma) goto err; } - pdata->ccb_array = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + pdata->ccb_array = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct sdma_ccb)); if (!pdata->ccb_array) { diff --git a/src/drivers/interrupt.c b/src/drivers/interrupt.c index dd208a3cfb4e..03cfb29e1398 100644 --- a/src/drivers/interrupt.c +++ b/src/drivers/interrupt.c @@ -73,7 +73,7 @@ int interrupt_cascade_register(const struct irq_cascade_tmpl *tmpl) } - *cascade = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(**cascade)); + *cascade = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(**cascade)); k_spinlock_init(&(*cascade)->lock); @@ -205,7 +205,7 @@ static int irq_register_child(struct irq_cascade_desc *cascade, int irq, /* init child from run-time, may be registered and unregistered * many times at run-time */ - child = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + child = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct irq_desc)); if (!child) { ret = -ENOMEM; diff --git a/src/drivers/mediatek/afe/afe-drv.c b/src/drivers/mediatek/afe/afe-drv.c index c5b27f772b7b..bdf5bc1f5f07 100644 --- a/src/drivers/mediatek/afe/afe-drv.c +++ b/src/drivers/mediatek/afe/afe-drv.c @@ -362,7 +362,7 @@ int afe_probe(struct mtk_base_afe *afe) tr_dbg(&afedrv_tr, "afe_base:0x%x\n", afe->base); /* TODO how to get the memif number, how to sync with dmac lib */ afe->memifs_size = platform->memif_size; - afe->memif = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + afe->memif = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct mtk_base_afe_memif) * afe->memifs_size); if (!afe->memif) return -ENOMEM; @@ -372,14 +372,14 @@ int afe_probe(struct mtk_base_afe *afe) /* TODO how to get the dai number, how to sync with dai lib*/ afe->dais_size = platform->dais_size; - afe->dais = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + afe->dais = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct mtk_base_afe_dai) * afe->dais_size); if (!afe->dais) goto err_alloc_memif; /* TODO how to get the irq number */ afe->irqs_size = platform->irqs_size; - afe->irqs = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + afe->irqs = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct mtk_base_afe_irq) * afe->irqs_size); if (!afe->irqs && afe->irqs_size) goto err_alloc_dais; diff --git a/src/drivers/mediatek/afe/afe-memif.c b/src/drivers/mediatek/afe/afe-memif.c index 9fb691622a92..5ca7d201757f 100644 --- a/src/drivers/mediatek/afe/afe-memif.c +++ b/src/drivers/mediatek/afe/afe-memif.c @@ -360,7 +360,7 @@ static int memif_probe(struct dma *dma) return ret; } - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_KERNEL, dma->plat_data.channels * sizeof(struct dma_chan_data)); if (!dma->chan) { tr_err(&memif_tr, "MEMIF: Probe failure, unable to allocate channel descriptors"); @@ -373,7 +373,7 @@ static int memif_probe(struct dma *dma) dma->chan[channel].index = channel; dma->chan[channel].status = COMP_STATE_INIT; - memif = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + memif = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct afe_memif_dma)); if (!memif) { tr_err(&memif_tr, "afe-memif: %d channel %d private data alloc failed", diff --git a/src/drivers/mediatek/mt818x/ipc.c b/src/drivers/mediatek/mt818x/ipc.c index 20fc54c20f4a..914e0f99dbb9 100644 --- a/src/drivers/mediatek/mt818x/ipc.c +++ b/src/drivers/mediatek/mt818x/ipc.c @@ -127,7 +127,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE struct ipc_data *iipc; - iipc = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*iipc)); + iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -142,7 +142,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE /* allocate page table buffer */ iipc->dh_buffer.page_table = - rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, PLATFORM_PAGE_TABLE_SIZE); + rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8195/ipc.c b/src/drivers/mediatek/mt8195/ipc.c index a5766d68f385..b8b8c5acf445 100644 --- a/src/drivers/mediatek/mt8195/ipc.c +++ b/src/drivers/mediatek/mt8195/ipc.c @@ -126,7 +126,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE struct ipc_data *iipc; - iipc = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*iipc)); + iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -140,7 +140,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE /* allocate page table buffer */ iipc->dh_buffer.page_table = - rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, PLATFORM_PAGE_TABLE_SIZE); + rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8196/ipc.c b/src/drivers/mediatek/mt8196/ipc.c index cb47e25c1dd0..6118ba244fac 100644 --- a/src/drivers/mediatek/mt8196/ipc.c +++ b/src/drivers/mediatek/mt8196/ipc.c @@ -126,7 +126,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE struct ipc_data *iipc; - iipc = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*iipc)); + iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -141,7 +141,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE /* allocate page table buffer */ iipc->dh_buffer.page_table = - rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, PLATFORM_PAGE_TABLE_SIZE); + rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8365/ipc.c b/src/drivers/mediatek/mt8365/ipc.c index c97dd348a997..8ff9f779197c 100644 --- a/src/drivers/mediatek/mt8365/ipc.c +++ b/src/drivers/mediatek/mt8365/ipc.c @@ -140,7 +140,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE struct ipc_data *iipc; - iipc = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*iipc)); + iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); if (!iipc) { tr_err(&ipc_tr, "Unable to allocate IPC private data"); return -ENOMEM; @@ -158,7 +158,7 @@ int platform_ipc_init(struct ipc *ipc) #if CONFIG_HOST_PTABLE /* allocate page table buffer */ iipc->dh_buffer.page_table = - rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, PLATFORM_PAGE_TABLE_SIZE); + rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/idc/idc.c b/src/idc/idc.c index 8250175bfcb7..eeb52f19b1c5 100644 --- a/src/idc/idc.c +++ b/src/idc/idc.c @@ -184,7 +184,7 @@ static int idc_prepare(uint32_t comp_id) /* we're running LL on different core, so allocate our own task */ if (!dev->task && dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL) { /* allocate task for shared component */ - dev->task = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dev->task = rzalloc(SOF_MEM_FLAG_USER, sizeof(*dev->task)); if (!dev->task) { ret = -ENOMEM; diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index 8dbef5cc4654..c8b98255ed4f 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -130,7 +130,7 @@ struct comp_buffer { struct audio_stream stream; /* configuration */ - uint32_t caps; + uint32_t flags; uint32_t core; struct tr_ctx tctx; /* trace settings */ @@ -208,9 +208,9 @@ struct buffer_cb_free { } while (0) /* pipeline buffer creation and destruction */ -struct comp_buffer *buffer_alloc(size_t size, uint32_t caps, uint32_t flags, uint32_t align, +struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align, bool is_shared); -struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size, uint32_t caps, +struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size, uint32_t flags, uint32_t align, bool is_shared); struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared); diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index f8fb0bbdf928..a768dd93a3a6 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -863,7 +863,7 @@ static inline struct comp_dev *comp_alloc(const struct comp_driver *drv, * Use uncached address everywhere to access components to rule out * multi-core failures. TODO: verify if cached alias may be used in some cases */ - dev = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, bytes); + dev = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, bytes); if (!dev) return NULL; dev->size = bytes; diff --git a/src/include/sof/audio/component_ext.h b/src/include/sof/audio/component_ext.h index c33f792f075a..3370cc110d2e 100644 --- a/src/include/sof/audio/component_ext.h +++ b/src/include/sof/audio/component_ext.h @@ -227,7 +227,7 @@ static inline int comp_ipc4_get_attribute_remote(struct comp_dev *dev, uint32_t if (type != COMP_ATTR_BASE_CONFIG) return -EINVAL; - base_cfg = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*base_cfg)); + base_cfg = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*base_cfg)); if (!base_cfg) return -ENOMEM; diff --git a/src/include/sof/audio/smart_amp/smart_amp.h b/src/include/sof/audio/smart_amp/smart_amp.h index a7fead002ec4..e6007bf28729 100644 --- a/src/include/sof/audio/smart_amp/smart_amp.h +++ b/src/include/sof/audio/smart_amp/smart_amp.h @@ -86,7 +86,7 @@ struct inner_model_ops; * struct smart_amp_mod_data_base *mod_data_create(const struct comp_dev *dev) * { * struct solution_foo_mod_data *foo; - * foo = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*foo)); + * foo = rzalloc(SOF_MEM_FLAG_USER, sizeof(*foo)); * assert(foo); * foo->base.dev = dev; * foo->base.mod_ops = foo_ops; // declared somewhere as static const diff --git a/src/include/sof/coherent.h b/src/include/sof/coherent.h index d98739b92c6f..172e45b4ed92 100644 --- a/src/include/sof/coherent.h +++ b/src/include/sof/coherent.h @@ -182,7 +182,7 @@ static inline void *__coherent_init(size_t offset, const size_t size) * line boundary to avoid sharing a cache line with the adjacent * allocation */ - void *object = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + void *object = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, ALIGN_UP(size, PLATFORM_DCACHE_ALIGN)); struct coherent *c; @@ -272,7 +272,7 @@ static inline void coherent_release_thread(struct coherent __sparse_cache *c, static inline void *__coherent_init_thread(size_t offset, const size_t size) { /* As above - prevent cache line sharing */ - void *object = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + void *object = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, ALIGN_UP(size, PLATFORM_DCACHE_ALIGN)); struct coherent *c; @@ -348,7 +348,7 @@ static inline void coherent_release(struct coherent __sparse_cache *c, static inline void *__coherent_init(size_t offset, const size_t size) { /* As in CONFIG_INCOHERENT case - prevent cache line sharing */ - void *object = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + void *object = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, ALIGN_UP(size, PLATFORM_DCACHE_ALIGN)); struct coherent *c; @@ -401,7 +401,7 @@ static inline void coherent_release_thread(struct coherent __sparse_cache *c, static inline void *__coherent_init_thread(size_t offset, const size_t size) { /* As above - prevent cache line sharing */ - void *object = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + void *object = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, ALIGN_UP(size, PLATFORM_DCACHE_ALIGN)); struct coherent *c; diff --git a/src/include/sof/ipc/msg.h b/src/include/sof/ipc/msg.h index 83613db8d8fc..160a9be9ec7c 100644 --- a/src/include/sof/ipc/msg.h +++ b/src/include/sof/ipc/msg.h @@ -51,12 +51,12 @@ static inline struct ipc_msg *ipc_msg_w_ext_init(uint32_t header, uint32_t exten { struct ipc_msg *msg; - msg = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*msg)); + msg = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*msg)); if (!msg) return NULL; if (size) { - msg->tx_data = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, size); + msg->tx_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, size); if (!msg->tx_data) { rfree(msg); return NULL; diff --git a/src/include/sof/math/matrix.h b/src/include/sof/math/matrix.h index 67ce88c3fbde..74899371038a 100644 --- a/src/include/sof/math/matrix.h +++ b/src/include/sof/math/matrix.h @@ -37,7 +37,7 @@ static inline struct mat_matrix_16b *mat_matrix_alloc_16b(int16_t rows, int16_t struct mat_matrix_16b *mat; const int mat_size = sizeof(int16_t) * rows * columns + sizeof(struct mat_matrix_16b); - mat = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, mat_size); + mat = rzalloc(SOF_MEM_FLAG_USER, mat_size); if (mat) mat_init_16b(mat, rows, columns, fractions); diff --git a/src/include/sof/schedule/ll_schedule_domain.h b/src/include/sof/schedule/ll_schedule_domain.h index dbc32656dd2f..a790d710e3da 100644 --- a/src/include/sof/schedule/ll_schedule_domain.h +++ b/src/include/sof/schedule/ll_schedule_domain.h @@ -98,7 +98,7 @@ static inline struct ll_schedule_domain *domain_init { struct ll_schedule_domain *domain; - domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*domain)); + domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*domain)); domain->type = type; domain->clk = clk; domain->synchronous = synchronous; diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index 67eb47679e04..b126534d0330 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -292,9 +292,9 @@ __cold int ipc_init(struct sof *sof) tr_dbg(&ipc_tr, "ipc_init()"); /* init ipc data */ - sof->ipc = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->ipc)); - sof->ipc->comp_data = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, - SOF_MEM_CAPS_RAM, SOF_IPC_MSG_MAX_SIZE); + sof->ipc = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc)); + sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, + SOF_IPC_MSG_MAX_SIZE); k_spinlock_init(&sof->ipc->lock); list_init(&sof->ipc->msg_list); diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index c6666581e5d4..3cca95f74254 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -53,6 +53,7 @@ __cold static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc) __cold struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared) { struct comp_buffer *buffer; + uint32_t flags = desc->flags; assert_can_be_cold(); @@ -65,8 +66,19 @@ __cold struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is return NULL; } + /* memory zones and caps are deprecated - convert to flags */ + if (desc->caps & SOF_MEM_CAPS_DMA) + flags |= SOF_MEM_FLAG_DMA; + if (desc->caps & SOF_MEM_CAPS_LP) + flags |= SOF_MEM_FLAG_LOW_POWER; + if (desc->caps & SOF_MEM_CAPS_L3) + flags |= SOF_MEM_FLAG_L3; + if (desc->caps) + tr_warn(&buffer_tr, "Deprecated buffer caps 0x%x used, convert to flags 0x%x", + desc->caps, flags); + /* allocate buffer */ - buffer = buffer_alloc(desc->size, desc->caps, desc->flags, PLATFORM_DCACHE_ALIGN, + buffer = buffer_alloc(desc->size, flags, PLATFORM_DCACHE_ALIGN, is_shared); if (buffer) { buffer->stream.runtime_stream_params.id = desc->comp.id; diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index 17b12aeefc26..4d152deef28b 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -376,7 +376,7 @@ int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai /* allocated dai_config if not yet */ if (!dd->dai_spec_config) { - dd->dai_spec_config = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dd->dai_spec_config = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct sof_ipc_dai_config)); if (!dd->dai_spec_config) { comp_err(dev, "dai_config(): No memory for dai_config."); diff --git a/src/ipc/ipc3/handler.c b/src/ipc/ipc3/handler.c index eb812e58fce2..5e58c8ba9443 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -1422,85 +1422,12 @@ static int ipc_glb_tplg_message(uint32_t header) } } -#if CONFIG_DEBUG_MEMORY_USAGE_SCAN -static int fill_mem_usage_elems(enum mem_zone zone, enum sof_ipc_dbg_mem_zone ipc_zone, - int elem_number, struct sof_ipc_dbg_mem_usage_elem *elems) -{ - struct mm_info info; - int ret; - int i; - - for (i = 0; i < elem_number; ++i) { - ret = heap_info(zone, i, &info); - elems[i].zone = ipc_zone; - elems[i].id = i; - elems[i].used = ret < 0 ? UINT32_MAX : info.used; - elems[i].free = ret < 0 ? 0 : info.free; - } - - return elem_number; -} - -#if CONFIG_CORE_COUNT > 1 -#define PLATFORM_HEAP_SYSTEM_SHARED_CNT (PLATFORM_HEAP_SYSTEM_SHARED + PLATFORM_HEAP_RUNTIME_SHARED) -#else -#define PLATFORM_HEAP_SYSTEM_SHARED_CNT 0 -#endif - -static int ipc_glb_test_mem_usage(uint32_t header) -{ - /* count number heaps */ - int elem_cnt = PLATFORM_HEAP_SYSTEM + PLATFORM_HEAP_SYSTEM_RUNTIME + - PLATFORM_HEAP_RUNTIME + PLATFORM_HEAP_BUFFER + - PLATFORM_HEAP_SYSTEM_SHARED_CNT; - size_t size = sizeof(struct sof_ipc_dbg_mem_usage) + - elem_cnt * sizeof(struct sof_ipc_dbg_mem_usage_elem); - struct sof_ipc_dbg_mem_usage_elem *elems; - struct sof_ipc_dbg_mem_usage *mem_usage; - - mem_usage = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, 0, size); - if (!mem_usage) - return -ENOMEM; - - mem_usage->rhdr.hdr.cmd = header; - mem_usage->rhdr.hdr.size = size; - mem_usage->num_elems = elem_cnt; - - /* fill list of elems */ - elems = mem_usage->elems; - elems += fill_mem_usage_elems(SOF_MEM_ZONE_SYS, SOF_IPC_MEM_ZONE_SYS, - PLATFORM_HEAP_SYSTEM, elems); - elems += fill_mem_usage_elems(SOF_MEM_ZONE_SYS_RUNTIME, SOF_IPC_MEM_ZONE_SYS_RUNTIME, - PLATFORM_HEAP_SYSTEM_RUNTIME, elems); - elems += fill_mem_usage_elems(SOF_MEM_ZONE_RUNTIME, SOF_IPC_MEM_ZONE_RUNTIME, - PLATFORM_HEAP_RUNTIME, elems); - /* cppcheck-suppress unreadVariable */ - elems += fill_mem_usage_elems(SOF_MEM_ZONE_BUFFER, SOF_IPC_MEM_ZONE_BUFFER, - PLATFORM_HEAP_BUFFER, elems); -#if CONFIG_CORE_COUNT > 1 - elems += fill_mem_usage_elems(SOF_MEM_ZONE_SYS_SHARED, SOF_IPC_MEM_ZONE_SYS_SHARED, - PLATFORM_HEAP_SYSTEM_SHARED, elems); - elems += fill_mem_usage_elems(SOF_MEM_ZONE_RUNTIME_SHARED, SOF_IPC_MEM_ZONE_RUNTIME_SHARED, - PLATFORM_HEAP_RUNTIME_SHARED, elems); -#endif - - /* write component values to the outbox */ - mailbox_hostbox_write(0, mem_usage, mem_usage->rhdr.hdr.size); - - rfree(mem_usage); - return 1; -} -#endif - static int ipc_glb_debug_message(uint32_t header) { uint32_t cmd = iCS(header); switch (cmd) { -#if CONFIG_DEBUG_MEMORY_USAGE_SCAN - case SOF_IPC_DEBUG_MEM_USAGE: - return ipc_glb_test_mem_usage(header); -#endif + /* TODO: Zephyr heap debug needs to added for IPC3 using Zephyr APIs. */ default: ipc_cmd_err(&ipc_tr, "ipc: unknown debug header 0x%x", header); return -EINVAL; diff --git a/src/ipc/ipc3/helper.c b/src/ipc/ipc3/helper.c index 6eb708a55b91..f4b765988b14 100644 --- a/src/ipc/ipc3/helper.c +++ b/src/ipc/ipc3/helper.c @@ -418,7 +418,7 @@ int ipc_pipeline_new(struct ipc *ipc, ipc_pipe_new *_pipe_desc) } /* allocate the IPC pipeline container */ - ipc_pipe = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + ipc_pipe = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct ipc_comp_dev)); if (!ipc_pipe) { pipeline_free(pipe); @@ -491,7 +491,7 @@ int ipc_buffer_new(struct ipc *ipc, const struct sof_ipc_buffer *desc) return -ENOMEM; } - ibd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + ibd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct ipc_comp_dev)); if (!ibd) { buffer_free(buffer); @@ -692,7 +692,7 @@ int ipc_comp_new(struct ipc *ipc, ipc_comp *_comp) } /* allocate the IPC component container */ - icd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + icd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct ipc_comp_dev)); if (!icd) { tr_err(&ipc_tr, "ipc_comp_new(): alloc failed"); diff --git a/src/ipc/ipc3/host-page-table.c b/src/ipc/ipc3/host-page-table.c index 179a7f111f66..e4d36cc9640c 100644 --- a/src/ipc/ipc3/host-page-table.c +++ b/src/ipc/ipc3/host-page-table.c @@ -42,7 +42,7 @@ static int ipc_parse_page_descriptors(uint8_t *page_table, return -EINVAL; } - elem_array->elems = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + elem_array->elems = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct dma_sg_elem) * ring->pages); if (!elem_array->elems) { tr_err(&ipc_tr, "ipc_parse_page_descriptors(): There is no heap free with this block size: %zu", diff --git a/src/ipc/ipc4/dai.c b/src/ipc/ipc4/dai.c index b0e1905b6c81..ba25bd13a989 100644 --- a/src/ipc/ipc4/dai.c +++ b/src/ipc/ipc4/dai.c @@ -378,7 +378,7 @@ __cold int dai_config(struct dai_data *dd, struct comp_dev *dev, /* allocated dai_config if not yet */ if (!dd->dai_spec_config) { size = sizeof(*copier_cfg); - dd->dai_spec_config = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, size); + dd->dai_spec_config = rzalloc(SOF_MEM_FLAG_USER, size); if (!dd->dai_spec_config) { comp_err(dev, "dai_config(): No memory for dai_config size %d", size); return -ENOMEM; diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 2211c5009f97..bc195ace5b87 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -261,7 +261,7 @@ __cold static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc) pipe->core = pipe_desc->extension.r.core_id; /* allocate the IPC pipeline container */ - ipc_pipe = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + ipc_pipe = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct ipc_comp_dev)); if (!ipc_pipe) { pipeline_free(pipe); @@ -1092,7 +1092,7 @@ __cold static int ipc4_add_comp_dev(struct comp_dev *dev) } /* allocate the IPC component container */ - icd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + icd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct ipc_comp_dev)); if (!icd) { tr_err(&ipc_tr, "ipc_comp_new(): alloc failed"); diff --git a/src/ipc/notification_pool.c b/src/ipc/notification_pool.c index 2fb8dd78e37d..1627213f7829 100644 --- a/src/ipc/notification_pool.c +++ b/src/ipc/notification_pool.c @@ -46,7 +46,7 @@ static struct ipc_msg *ipc_notif_new(size_t size) { struct ipc_notif_pool_item *item; - item = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*item)); + item = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*item)); if (!item) { tr_err(¬if_tr, "Unable to allocate memory for notification message"); return NULL; diff --git a/src/lib/agent.c b/src/lib/agent.c index 8edc6ccb3123..1d96bc54bb7e 100644 --- a/src/lib/agent.c +++ b/src/lib/agent.c @@ -102,7 +102,7 @@ void sa_init(struct sof *sof, uint64_t timeout) else tr_info(&sa_tr, "sa_init(), timeout = %u", (unsigned int)timeout); - sof->sa = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->sa)); + sof->sa = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->sa)); /* set default timeouts */ ticks = k_us_to_cyc_ceil64(timeout); diff --git a/src/lib/alloc.c b/src/lib/alloc.c index c2db42a3173c..7d07677c9a65 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -5,1007 +5,49 @@ // Author: Liam Girdwood // Keyon Jie -#include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include #include #include #include #include +#include -LOG_MODULE_REGISTER(memory, CONFIG_SOF_LOG_LEVEL); +void *aligned_alloc(size_t alignment, size_t size); +void free_heap(void); -SOF_DEFINE_REG_UUID(mem); - -DECLARE_TR_CTX(mem_tr, SOF_UUID(mem_uuid), LOG_LEVEL_INFO); - -/* debug to set memory value on every allocation */ -#if CONFIG_DEBUG_BLOCK_FREE -#define DEBUG_BLOCK_FREE_VALUE_8BIT ((uint8_t)0xa5) -#define DEBUG_BLOCK_FREE_VALUE_32BIT ((uint32_t)0xa5a5a5a5) -#endif - -/* We have 3 memory pools - * - * 1) System memory pool does not have a map and it's size is fixed at build - * time. Memory cannot be freed from this pool. Used by device drivers - * and any system core. Saved as part of PM context. - * 2) Runtime memory pool has variable size allocation map and memory is freed - * on calls to rfree(). Saved as part of PM context. Global size - * set at build time. - * 3) Buffer memory pool has fixed size allocation map and can be freed on - * module removal or calls to rfree(). Saved as part of PM context. - */ - -#if CONFIG_DEBUG_BLOCK_FREE -/* Check whole memory region for debug pattern to find if memory was freed - * second time - */ -static void validate_memory(void *ptr, size_t size) -{ - uint32_t *ptr_32 = ptr; - int i, not_matching = 0; - - for (i = 0; i < size / 4; i++) { - if (ptr_32[i] != DEBUG_BLOCK_FREE_VALUE_32BIT) - not_matching = 1; - } - - if (not_matching) { - tr_info(&mem_tr, "validate_memory() pointer: %p freed pattern not detected", - ptr); - } else { - tr_err(&mem_tr, "validate_memory() freeing pointer: %p double free detected", - ptr); - } -} -#endif - -#if CONFIG_DEBUG_BLOCK_FREE -static void write_pattern(struct mm_heap *heap_map, int heap_depth, - uint8_t pattern) -{ - struct mm_heap *heap; - struct block_map *current_map; - int i, j; - - for (i = 0; i < heap_depth; i++) { - heap = &heap_map[i]; - - for (j = 0; j < heap->blocks; j++) { - current_map = &heap->map[j]; - memset( - (void *)current_map->base, pattern, - current_map->count * current_map->block_size); - } - - } -} -#endif - -static void init_heap_map(struct mm_heap *heap, int count) -{ - struct block_map *next_map; - struct block_map *current_map; - int i; - int j; - - for (i = 0; i < count; i++) { - /* init the map[0] */ - current_map = &heap[i].map[0]; - current_map->base = heap[i].heap; - - /* map[j]'s base is calculated based on map[j-1] */ - for (j = 1; j < heap[i].blocks; j++) { - next_map = &heap[i].map[j]; - next_map->base = current_map->base + - current_map->block_size * - current_map->count; - - current_map = &heap[i].map[j]; - } - - } -} - -/* allocate from system memory pool */ -static void *rmalloc_sys(struct mm_heap *heap, uint32_t flags, int caps, size_t bytes) -{ - void *ptr; - size_t alignment = 0; - - if ((heap->caps & caps) != caps) - sof_panic(SOF_IPC_PANIC_MEM); - - /* align address to dcache line size */ - if (heap->info.used % PLATFORM_DCACHE_ALIGN) - alignment = PLATFORM_DCACHE_ALIGN - - (heap->info.used % PLATFORM_DCACHE_ALIGN); - - /* always succeeds or panics */ - if (alignment + bytes > heap->info.free) { - tr_err(&mem_tr, "rmalloc_sys(): core = %d, bytes = %d", - cpu_get_id(), bytes); - sof_panic(SOF_IPC_PANIC_MEM); - } - heap->info.used += alignment; - - ptr = (void *)(heap->heap + heap->info.used); - - heap->info.used += bytes; - heap->info.free -= alignment + bytes; - - return ptr; -} - -/* At this point the pointer we have should be unaligned - * (it was checked level higher) and be power of 2 - */ -static void *align_ptr(struct mm_heap *heap, uint32_t alignment, - void *ptr, struct block_hdr *hdr) -{ - /* Save unaligned ptr to block hdr */ - hdr->unaligned_ptr = ptr; - - /* If ptr is not already aligned we calculate alignment shift */ - if (alignment <= 1) - return ptr; - - return (void *)ALIGN_UP((uintptr_t)ptr, alignment); -} - -/* allocate single block */ -static void *alloc_block_index(struct mm_heap *heap, int level, - uint32_t alignment, int index) -{ - struct block_map *map = &heap->map[level]; - struct block_hdr *hdr; - void *ptr; - int i; - - if (index < 0) - index = map->first_free; - - map->free_count--; - - hdr = &map->block[index]; - ptr = (void *)(map->base + index * map->block_size); - ptr = align_ptr(heap, alignment, ptr, hdr); - - hdr->size = 1; - hdr->used = 1; - - heap->info.used += map->block_size; - heap->info.free -= map->block_size; - - if (index == map->first_free) - /* find next free */ - for (i = map->first_free; i < map->count; ++i) { - hdr = &map->block[i]; - - if (hdr->used == 0) { - map->first_free = i; - break; - } - } - - return ptr; -} - -static void *alloc_block(struct mm_heap *heap, int level, - uint32_t caps, uint32_t alignment) -{ - return alloc_block_index(heap, level, alignment, -1); -} - -/* allocates continuous blocks */ -static void *alloc_cont_blocks(struct mm_heap *heap, int level, - uint32_t caps, size_t bytes, uint32_t alignment) -{ - struct block_map *map = &heap->map[level]; - struct block_hdr *hdr; - void *ptr = NULL, *unaligned_ptr; - unsigned int current; - unsigned int count = 0; /* keep compiler quiet */ - unsigned int start = 0; /* keep compiler quiet */ - uintptr_t blk_start = 0, aligned = 0; /* keep compiler quiet */ - size_t found = 0, total_bytes = bytes; - - /* check if we have enough consecutive blocks for requested - * allocation size. - */ - if ((map->count - map->first_free) * map->block_size < bytes) - return NULL; - - /* - * Walk all blocks in the map, beginning with the first free one, until - * a sufficiently large sequence is found, in which the first block - * contains an address with the requested alignment. - */ - for (current = map->first_free, hdr = map->block + current; - current < map->count && found < total_bytes; - current++, hdr++) { - if (hdr->used) { - /* Restart the search */ - found = 0; - count = 0; - total_bytes = bytes; - continue; - } - - if (!found) { - /* A possible beginning of a sequence */ - blk_start = map->base + current * map->block_size; - start = current; - - /* Check if we can start a sequence here */ - if (alignment) { - aligned = ALIGN_UP(blk_start, alignment); - - if (blk_start & (alignment - 1) && - aligned >= blk_start + map->block_size) - /* - * This block doesn't contain an address - * with required alignment, it is useless - * as the beginning of the sequence - */ - continue; - - /* - * Found a potentially suitable beginning of a - * sequence, from here we'll check if we get - * enough blocks - */ - total_bytes += aligned - blk_start; - } else { - aligned = blk_start; - } - } - - count++; - found += map->block_size; - } - - if (found < total_bytes) { - tr_err(&mem_tr, "failed to allocate %u", total_bytes); - goto out; - } - - ptr = (void *)aligned; - - /* we found enough space, let's allocate it */ - map->free_count -= count; - unaligned_ptr = (void *)blk_start; - - hdr = &map->block[start]; - hdr->size = count; - - heap->info.used += count * map->block_size; - heap->info.free -= count * map->block_size; - - /* - * if .first_free has to be updated, set it to first free block or past - * the end of the map - */ - if (map->first_free == start) { - for (current = map->first_free + count, hdr = &map->block[current]; - current < map->count && hdr->used; - current++, hdr++) - ; - - map->first_free = current; - } - - /* update each block */ - for (current = start; current < start + count; current++) { - hdr = &map->block[current]; - hdr->used = 1; - hdr->unaligned_ptr = unaligned_ptr; - } - -out: - - return ptr; -} - -static inline struct mm_heap *find_in_heap_arr(struct mm_heap *heap_arr, int arr_len, void *ptr) -{ - struct mm_heap *heap; - int i; - - for (i = 0; i < arr_len; i++) { - heap = &heap_arr[i]; - if ((uint32_t)ptr >= heap->heap && - (uint32_t)ptr < heap->heap + heap->size) - return heap; - } - return NULL; -} - -static struct mm_heap *get_heap_from_ptr(void *ptr) -{ - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - - /* find mm_heap that ptr belongs to */ - heap = find_in_heap_arr(memmap->system_runtime + cpu_get_id(), 1, ptr); - if (heap) - goto out; - - heap = find_in_heap_arr(memmap->runtime, PLATFORM_HEAP_RUNTIME, ptr); - if (heap) - goto out; - -#if CONFIG_CORE_COUNT > 1 - heap = find_in_heap_arr(memmap->runtime_shared, PLATFORM_HEAP_RUNTIME_SHARED, ptr); - if (heap) - goto out; -#endif - - heap = find_in_heap_arr(memmap->buffer, PLATFORM_HEAP_BUFFER, ptr); - if (heap) - goto out; - - return NULL; - -out: - - return heap; -} - -static struct mm_heap *get_heap_from_caps(struct mm_heap *heap, int count, - uint32_t caps) -{ - uint32_t mask; - int i; - - /* find first heap that support type */ - for (i = 0; i < count; i++) { - mask = heap[i].caps & caps; - if (mask == caps) - return &heap[i]; - } - - return NULL; -} - -static void *get_ptr_from_heap(struct mm_heap *heap, uint32_t flags, - uint32_t caps, size_t bytes, uint32_t alignment) -{ - struct block_map *map; - int i, temp_bytes = bytes; - void *ptr = NULL; - - /* Only allow alignment as a power of 2 */ - if ((alignment & (alignment - 1)) != 0) - sof_panic(SOF_IPC_PANIC_MEM); - - for (i = 0; i < heap->blocks; i++) { - map = &heap->map[i]; - - /* size of requested buffer is adjusted for alignment purposes - * we check if first free block is already aligned if not - * we need to allocate bigger size for alignment - */ - if (alignment && - ((map->base + (map->block_size * map->first_free)) % - alignment)) - temp_bytes += alignment; - - /* is block big enough */ - if (map->block_size < temp_bytes) { - temp_bytes = bytes; - continue; - } - - /* does block have free space */ - if (map->free_count == 0) { - temp_bytes = bytes; - continue; - } - - /* free block space exists */ - ptr = alloc_block(heap, i, caps, alignment); - - break; - } - - return ptr; -} - -/* free block(s) */ -static void free_block(void *ptr) -{ - struct mm_heap *heap; - struct block_map *block_map = NULL; - struct block_hdr *hdr; - void *cached_ptr = uncache_to_cache(ptr); - void *uncached_ptr = cache_to_uncache(ptr); - void *free_ptr; - int i; - int block; - int used_blocks; - bool heap_is_full; - - /* try cached_ptr first */ - heap = get_heap_from_ptr(cached_ptr); - - /* try uncached_ptr if needed */ - if (!heap) { - heap = get_heap_from_ptr(uncached_ptr); - if (!heap) { - tr_err(&mem_tr, "free_block(): invalid heap, ptr = %p, cpu = %d", - ptr, cpu_get_id()); - return; - } - free_ptr = uncached_ptr; - } else { - free_ptr = cached_ptr; - } - - /* find block that ptr belongs to */ - for (i = 0; i < heap->blocks; i++) { - block_map = &heap->map[i]; - - /* is ptr in this block */ - if ((uint32_t)free_ptr < (block_map->base + - (block_map->block_size * block_map->count))) - break; - - } - - if (i == heap->blocks) { - - /* not found */ - tr_err(&mem_tr, "free_block(): invalid free_ptr = %p cpu = %d", - free_ptr, cpu_get_id()); - return; - } - - /* calculate block header */ - block = ((uint32_t)free_ptr - block_map->base) / block_map->block_size; - - hdr = &block_map->block[block]; - - /* bring back original unaligned pointer position - * and calculate correct hdr for free operation (it could - * be from different block since we got user pointer here - * or null if header was not set) - */ - if (hdr->unaligned_ptr != free_ptr && hdr->unaligned_ptr) { - free_ptr = hdr->unaligned_ptr; - block = ((uint32_t)free_ptr - block_map->base) - / block_map->block_size; - hdr = &block_map->block[block]; - } - - /* report an error if ptr is not aligned to block */ - if (block_map->base + block_map->block_size * block != (uint32_t)free_ptr) - sof_panic(SOF_IPC_PANIC_MEM); - - /* There may still be live dirty cache lines in the region - * on the current core. Those must be invalidated, otherwise - * they will be evicted from the cache at some point in the - * future, on top of the memory region now being used for - * different purposes on another core. - */ - dcache_writeback_invalidate_region(ptr, block_map->block_size * hdr->size); - - heap_is_full = !block_map->free_count; - - /* free block header and continuous blocks */ - used_blocks = block + hdr->size; - - for (i = block; i < used_blocks; i++) { - hdr = &block_map->block[i]; - hdr->size = 0; - hdr->used = 0; - hdr->unaligned_ptr = NULL; - block_map->free_count++; - heap->info.used -= block_map->block_size; - heap->info.free += block_map->block_size; - } - - /* set first free block */ - if (block < block_map->first_free || heap_is_full) - block_map->first_free = block; - -#if CONFIG_DEBUG_BLOCK_FREE - /* memset the whole block in case of unaligned ptr */ - validate_memory( - (void *)(block_map->base + block_map->block_size * block), - block_map->block_size * (i - block)); - memset( - (void *)(block_map->base + block_map->block_size * block), - DEBUG_BLOCK_FREE_VALUE_8BIT, block_map->block_size * - (i - block)); -#endif -} - -#if CONFIG_TRACE -void heap_trace(struct mm_heap *heap, int size) -{ - struct block_map *current_map; - int i; - int j; - - for (i = 0; i < size; i++) { - tr_info(&mem_tr, " heap: 0x%x size %d blocks %d caps 0x%x", - heap->heap, heap->size, heap->blocks, - heap->caps); - tr_info(&mem_tr, " (In Bytes) used %d free %d", heap->info.used, - heap->info.free); - - /* map[j]'s base is calculated based on map[j-1] */ - for (j = 0; j < heap->blocks; j++) { - current_map = &heap->map[j]; - - tr_info(&mem_tr, " %d Bytes blocks ID:%d base 0x%x", - current_map->block_size, j, current_map->base); - tr_info(&mem_tr, " Number of Blocks: total %d used %d free %d", - current_map->count, - (current_map->count - current_map->free_count), - current_map->free_count); - } - - heap++; - } -} - -void heap_trace_all(int force) +void *rmalloc(uint32_t flags, size_t bytes) { - struct mm *memmap = memmap_get(); - - /* has heap changed since last shown */ - if (memmap->heap_trace_updated || force) { - tr_info(&mem_tr, "heap: system status"); - heap_trace(memmap->system, PLATFORM_HEAP_SYSTEM); - tr_info(&mem_tr, "heap: system runtime status"); - heap_trace(memmap->system_runtime, PLATFORM_HEAP_SYSTEM_RUNTIME); - tr_info(&mem_tr, "heap: buffer status"); - heap_trace(memmap->buffer, PLATFORM_HEAP_BUFFER); - tr_info(&mem_tr, "heap: runtime status"); - heap_trace(memmap->runtime, PLATFORM_HEAP_RUNTIME); -#if CONFIG_CORE_COUNT > 1 - tr_info(&mem_tr, "heap: runtime shared status"); - heap_trace(memmap->runtime_shared, PLATFORM_HEAP_RUNTIME_SHARED); - tr_info(&mem_tr, "heap: system shared status"); - heap_trace(memmap->system_shared, PLATFORM_HEAP_SYSTEM_SHARED); -#endif - } - - memmap->heap_trace_updated = 0; - + return malloc(bytes); } -#else -void heap_trace_all(int force) { } -void heap_trace(struct mm_heap *heap, int size) { } -#endif -#define _ALLOC_FAILURE(bytes, zone, caps, flags) \ - tr_err(&mem_tr, \ - "failed to alloc 0x%x bytes zone 0x%x caps 0x%x flags 0x%x", \ - bytes, zone, caps, flags) - -#if CONFIG_DEBUG_HEAP -#define DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags) do { \ - if (trace_get()) { \ - if (!(ptr)) \ - _ALLOC_FAILURE(bytes, zone, caps, flags); \ - heap_trace_all(0); \ - } \ - } while (0) -#else -#define DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags) do { \ - if (trace_get()) { \ - if (!(ptr)) { \ - _ALLOC_FAILURE(bytes, zone, caps, flags); \ - heap_trace_all(0); \ - } \ - } \ - } while (0) -#endif - -/* allocate single block for system runtime */ -static void *rmalloc_sys_runtime(uint32_t flags, int caps, int core, - size_t bytes) +void *rzalloc(uint32_t flags, size_t bytes) { - struct mm *memmap = memmap_get(); - struct mm_heap *cpu_heap; - void *ptr; - - /* use the heap dedicated for the selected core */ - cpu_heap = memmap->system_runtime + core; - if ((cpu_heap->caps & caps) != caps) - sof_panic(SOF_IPC_PANIC_MEM); - - ptr = get_ptr_from_heap(cpu_heap, flags, caps, bytes, - PLATFORM_DCACHE_ALIGN); - - return ptr; + return calloc(bytes, 1); } -/* allocate single block for runtime */ -static void *rmalloc_runtime(uint32_t flags, uint32_t caps, size_t bytes) -{ - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - - /* check runtime heap for capabilities */ - heap = get_heap_from_caps(memmap->runtime, PLATFORM_HEAP_RUNTIME, caps); - if (!heap) { - /* next check buffer heap for capabilities */ - heap = get_heap_from_caps(memmap->buffer, PLATFORM_HEAP_BUFFER, - caps); - if (!heap) { - - tr_err(&mem_tr, "rmalloc_runtime(): caps = %x, bytes = %d", - caps, bytes); - - return NULL; - } - } - - return get_ptr_from_heap(heap, flags, caps, bytes, - PLATFORM_DCACHE_ALIGN); -} - -#if CONFIG_CORE_COUNT > 1 -/* allocate single block for shared */ -static void *rmalloc_runtime_shared(uint32_t flags, uint32_t caps, size_t bytes) -{ - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - - /* check shared heap for capabilities */ - heap = get_heap_from_caps(memmap->runtime_shared, PLATFORM_HEAP_RUNTIME_SHARED, caps); - if (!heap) { - tr_err(&mem_tr, "rmalloc_runtime_shared(): caps = %x, bytes = %d", caps, bytes); - return NULL; - } - - return get_ptr_from_heap(heap, flags, caps, bytes, PLATFORM_DCACHE_ALIGN); -} -#endif - -static void *_malloc_unlocked(enum mem_zone zone, uint32_t flags, uint32_t caps, - size_t bytes) -{ - struct mm *memmap = memmap_get(); - void *ptr = NULL; - - switch (zone) { - case SOF_MEM_ZONE_SYS: - ptr = rmalloc_sys(memmap->system + cpu_get_id(), flags, caps, bytes); - break; - case SOF_MEM_ZONE_SYS_RUNTIME: - ptr = rmalloc_sys_runtime(flags, caps, cpu_get_id(), bytes); - break; - case SOF_MEM_ZONE_RUNTIME: - ptr = rmalloc_runtime(flags, caps, bytes); - break; -#if CONFIG_CORE_COUNT > 1 - case SOF_MEM_ZONE_RUNTIME_SHARED: - ptr = rmalloc_runtime_shared(flags, caps, bytes); - break; - case SOF_MEM_ZONE_SYS_SHARED: - ptr = rmalloc_sys(memmap->system_shared, flags, caps, bytes); - break; -#else - case SOF_MEM_ZONE_RUNTIME_SHARED: - ptr = rmalloc_runtime(flags, caps, bytes); - break; - case SOF_MEM_ZONE_SYS_SHARED: - ptr = rmalloc_sys(memmap->system, flags, caps, bytes); - break; -#endif - - default: - tr_err(&mem_tr, "rmalloc(): invalid zone"); - sof_panic(SOF_IPC_PANIC_MEM); /* logic non recoverable problem */ - break; - } - -#if CONFIG_DEBUG_BLOCK_FREE - if (ptr) - bzero(ptr, bytes); -#endif - - memmap->heap_trace_updated = 1; - - return ptr; -} - -void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) -{ - struct mm *memmap = memmap_get(); - k_spinlock_key_t key; - void *ptr = NULL; - - key = k_spin_lock(&memmap->lock); - - ptr = _malloc_unlocked(zone, flags, caps, bytes); - - k_spin_unlock(&memmap->lock, key); - - DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags); - return ptr; -} - -/* allocates and clears memory - not for direct use, clients use rzalloc() */ -void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) -{ - void *ptr; - - ptr = rmalloc(zone, flags, caps, bytes); - if (ptr) - bzero(ptr, bytes); - - return ptr; -} - -void *rzalloc_core_sys(int core, size_t bytes) -{ - struct mm *memmap = memmap_get(); - k_spinlock_key_t key; - void *ptr = NULL; - - key = k_spin_lock(&memmap->lock); - - ptr = rmalloc_sys(memmap->system + core, 0, 0, bytes); - if (ptr) - bzero(ptr, bytes); - - k_spin_unlock(&memmap->lock, key); - return ptr; -} - -/* allocates continuous buffers - not for direct use, clients use rballoc() */ -static void *alloc_heap_buffer(struct mm_heap *heap, uint32_t flags, - uint32_t caps, size_t bytes, uint32_t alignment) -{ - struct block_map *map; -#if CONFIG_DEBUG_BLOCK_FREE - unsigned int temp_bytes = bytes; -#endif - unsigned int j; - int i; - void *ptr = NULL; - - /* Only allow alignment as a power of 2 */ - if ((alignment & (alignment - 1)) != 0) - sof_panic(SOF_IPC_PANIC_MEM); - - /* - * There are several cases when a memory allocation request can be - * satisfied with one buffer: - * 1. allocate 30 bytes 32-byte aligned from 32 byte buffers. Any free - * buffer is acceptable, the beginning of the buffer is used. - * 2. allocate 30 bytes 256-byte aligned from 0x180 byte buffers. 1 - * buffer is also always enough, but in some buffers a part of the - * buffer has to be skipped. - * 3. allocate 200 bytes 256-byte aligned from 0x180 byte buffers. 1 - * buffer is enough, but not every buffer is suitable. - */ - - /* will request fit in single block */ - for (i = 0, map = heap->map; i < heap->blocks; i++, map++) { - struct block_hdr *hdr; - uintptr_t free_start; - - if (map->block_size < bytes || !map->free_count) - continue; - - if (alignment <= 1) { - /* found: grab a block */ - ptr = alloc_block(heap, i, caps, alignment); - break; - } - - /* - * Usually block sizes are a power of 2 and all blocks are - * respectively aligned. But it's also possible to have - * non-power of 2 sized blocks, e.g. to optimize for typical - * ALSA allocations a map with 0x180 byte buffers can be used. - * For performance reasons we could first check the power-of-2 - * case. This can be added as an optimization later. - */ - for (j = map->first_free, hdr = map->block + j, - free_start = map->base + map->block_size * j; - j < map->count; - j++, hdr++, free_start += map->block_size) { - uintptr_t aligned; - - if (hdr->used) - continue; - - aligned = ALIGN_UP(free_start, alignment); - - if (aligned + bytes > free_start + map->block_size) - continue; - - /* Found, alloc_block_index() cannot fail */ - ptr = alloc_block_index(heap, i, alignment, j); -#if CONFIG_DEBUG_BLOCK_FREE - temp_bytes += aligned - free_start; -#endif - break; - } - - if (ptr) - break; - } - - /* request spans > 1 block */ - if (!ptr) { - /* size of requested buffer is adjusted for alignment purposes - * since we span more blocks we have to assume worst case scenario - */ - bytes += alignment; - - if (heap->size < bytes) - return NULL; - - /* - * Find the best block size for request. We know, that we failed - * to find a single large enough block, so, skip those. - */ - for (i = heap->blocks - 1; i >= 0; i--) { - map = &heap->map[i]; - - /* allocate if block size is smaller than request */ - if (map->block_size < bytes) { - ptr = alloc_cont_blocks(heap, i, caps, - bytes, alignment); - if (ptr) - break; - } - } - } - -#if CONFIG_DEBUG_BLOCK_FREE - if (ptr) - bzero(ptr, temp_bytes); -#endif - - return ptr; -} - -static void *_balloc_unlocked(uint32_t flags, uint32_t caps, size_t bytes, - uint32_t alignment) -{ - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - unsigned int i, n; - void *ptr = NULL; - - for (i = 0, n = PLATFORM_HEAP_BUFFER, heap = memmap->buffer; - i < PLATFORM_HEAP_BUFFER; - i = heap - memmap->buffer + 1, n = PLATFORM_HEAP_BUFFER - i, - heap++) { - heap = get_heap_from_caps(heap, n, caps); - if (!heap) - break; - - ptr = alloc_heap_buffer(heap, flags, caps, bytes, alignment); - if (ptr) - break; - - /* Continue from the next heap */ - } - - /* return directly if allocation failed */ - if (!ptr) - return ptr; - -#ifdef CONFIG_DEBUG_FORCE_COHERENT_BUFFER - return cache_to_uncache(ptr); -#else - return (flags & SOF_MEM_FLAG_COHERENT) && (CONFIG_CORE_COUNT > 1) ? - cache_to_uncache(ptr) : uncache_to_cache(ptr); -#endif -} - -/* allocates continuous buffers - not for direct use, clients use rballoc() */ -void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment) { - struct mm *memmap = memmap_get(); - void *ptr = NULL; - k_spinlock_key_t key; - - key = k_spin_lock(&memmap->lock); - - ptr = _balloc_unlocked(flags, caps, bytes, alignment); - - k_spin_unlock(&memmap->lock, key); - - DEBUG_TRACE_PTR(ptr, bytes, SOF_MEM_ZONE_BUFFER, caps, flags); - return ptr; -} - -static void _rfree_unlocked(void *ptr) -{ - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - - /* sanity check - NULL ptrs are fine */ - if (!ptr) - return; - - /* prepare pointer if it's platform requirement */ - ptr = platform_rfree_prepare(ptr); - - /* use the heap dedicated for the core or shared memory */ -#if CONFIG_CORE_COUNT > 1 - if (is_uncached(ptr)) - heap = memmap->system_shared; - else - heap = memmap->system + cpu_get_id(); -#else - heap = memmap->system; -#endif - - /* panic if pointer is from system heap */ - if (ptr >= (void *)heap->heap && - (char *)ptr < (char *)heap->heap + heap->size) { - tr_err(&mem_tr, "rfree(): attempt to free system heap = %p, cpu = %d", - ptr, cpu_get_id()); - sof_panic(SOF_IPC_PANIC_MEM); - } - - /* free the block */ - free_block(ptr); - memmap->heap_trace_updated = 1; - + return aligned_alloc(alignment, bytes); } void rfree(void *ptr) { - struct mm *memmap = memmap_get(); - k_spinlock_key_t key; - - key = k_spin_lock(&memmap->lock); - _rfree_unlocked(ptr); - k_spin_unlock(&memmap->lock, key); + free(ptr); } -void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, +void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes, uint32_t alignment) { - struct mm *memmap = memmap_get(); - void *new_ptr = NULL; - k_spinlock_key_t key; - size_t copy_bytes = MIN(bytes, old_bytes); - - if (!bytes) - return new_ptr; + void *newptr = aligned_alloc(alignment, bytes); - key = k_spin_lock(&memmap->lock); - - new_ptr = _balloc_unlocked(flags, caps, bytes, alignment); - - if (new_ptr && ptr && !(flags & SOF_MEM_FLAG_NO_COPY)) - memcpy_s(new_ptr, copy_bytes, ptr, copy_bytes); - - if (new_ptr) - _rfree_unlocked(ptr); - - k_spin_unlock(&memmap->lock, key); - - DEBUG_TRACE_PTR(ptr, bytes, SOF_MEM_ZONE_BUFFER, caps, flags); - return new_ptr; + if (!newptr) + return NULL; + memcpy(newptr, ptr, bytes > old_bytes ? old_bytes : bytes); + free(ptr); + return newptr; } /* TODO: all mm_pm_...() routines to be implemented for IMR storage */ @@ -1014,113 +56,18 @@ uint32_t mm_pm_context_size(void) return 0; } -void free_heap(enum mem_zone zone) +void free_heap(void) { - struct mm *memmap = memmap_get(); - struct mm_heap *cpu_heap; - - /* to be called by secondary cores only for sys heap, - * otherwise this is critical flow issue. - */ - if (cpu_get_id() == PLATFORM_PRIMARY_CORE_ID || - zone != SOF_MEM_ZONE_SYS) { - tr_err(&mem_tr, "free_heap(): critical flow issue"); - sof_panic(SOF_IPC_PANIC_MEM); - } - - cpu_heap = memmap->system + cpu_get_id(); - cpu_heap->info.used = 0; - cpu_heap->info.free = cpu_heap->size; - } /* initialise map */ void init_heap(struct sof *sof) { - struct mm *memmap = sof->memory_map; - -#if !CONFIG_LIBRARY - extern uintptr_t _system_heap_start; - - /* sanity check for malformed images or loader issues */ - if (memmap->system[0].heap != (uintptr_t)&_system_heap_start) - sof_panic(SOF_IPC_PANIC_MEM); -#endif - - init_heap_map(memmap->system_runtime, PLATFORM_HEAP_SYSTEM_RUNTIME); - - init_heap_map(memmap->runtime, PLATFORM_HEAP_RUNTIME); - -#if CONFIG_CORE_COUNT > 1 - init_heap_map(memmap->runtime_shared, PLATFORM_HEAP_RUNTIME_SHARED); -#endif - - init_heap_map(memmap->buffer, PLATFORM_HEAP_BUFFER); - -#if CONFIG_DEBUG_BLOCK_FREE - write_pattern((struct mm_heap *)&memmap->buffer, PLATFORM_HEAP_BUFFER, - DEBUG_BLOCK_FREE_VALUE_8BIT); - write_pattern((struct mm_heap *)&memmap->runtime, PLATFORM_HEAP_RUNTIME, - DEBUG_BLOCK_FREE_VALUE_8BIT); -#endif - - k_spinlock_init(&memmap->lock); } #if CONFIG_DEBUG_MEMORY_USAGE_SCAN -int heap_info(enum mem_zone zone, int index, struct mm_info *out) +int heap_info(int index, struct mm_info *out) { - struct mm *memmap = memmap_get(); - struct mm_heap *heap; - k_spinlock_key_t key; - - if (!out) - goto error; - - switch (zone) { - case SOF_MEM_ZONE_SYS: - if (index >= PLATFORM_HEAP_SYSTEM) - goto error; - heap = memmap->system + index; - break; - case SOF_MEM_ZONE_SYS_RUNTIME: - if (index >= PLATFORM_HEAP_SYSTEM_RUNTIME) - goto error; - heap = memmap->system_runtime + index; - break; - case SOF_MEM_ZONE_RUNTIME: - if (index >= PLATFORM_HEAP_RUNTIME) - goto error; - heap = memmap->runtime + index; - break; - case SOF_MEM_ZONE_BUFFER: - if (index >= PLATFORM_HEAP_BUFFER) - goto error; - heap = memmap->buffer + index; - break; -#if CONFIG_CORE_COUNT > 1 - case SOF_MEM_ZONE_SYS_SHARED: - if (index >= PLATFORM_HEAP_SYSTEM_SHARED) - goto error; - heap = memmap->system_shared + index; - break; - case SOF_MEM_ZONE_RUNTIME_SHARED: - if (index >= PLATFORM_HEAP_RUNTIME_SHARED) - goto error; - heap = memmap->runtime_shared + index; - break; -#endif - default: - goto error; - } - - key = k_spin_lock(&memmap->lock); - *out = heap->info; - k_spin_unlock(&memmap->lock, key); return 0; -error: - tr_err(&mem_tr, "heap_info(): failed for zone 0x%x index %d out ptr 0x%x", zone, index, - (uint32_t)out); - return -EINVAL; } #endif diff --git a/src/lib/ams.c b/src/lib/ams.c index 9d2dc2d7a102..766c3bd96213 100644 --- a/src/lib/ams.c +++ b/src/lib/ams.c @@ -585,7 +585,7 @@ int ams_init(void) struct sof *sof; int ret = 0; - *ams = rzalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, + *ams = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(**ams)); if (!*ams) return -ENOMEM; diff --git a/src/lib/dai.c b/src/lib/dai.c index 9e07a4c66d54..0eab3c279b15 100644 --- a/src/lib/dai.c +++ b/src/lib/dai.c @@ -41,7 +41,7 @@ __cold static struct dai_group_list *dai_group_list_get(int core_id) assert_can_be_cold(); if (!group_list) { - group_list = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + group_list = rzalloc(SOF_MEM_FLAG_USER, sizeof(*group_list)); groups[core_id] = group_list; @@ -80,7 +80,7 @@ __cold static struct dai_group *dai_group_alloc(void) assert_can_be_cold(); - group = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + group = rzalloc(SOF_MEM_FLAG_USER, sizeof(*group)); list_item_prepend(&group->list, dai_groups); @@ -275,7 +275,7 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags) return NULL; } - d = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(struct dai)); + d = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dai)); if (!d) return NULL; diff --git a/src/lib/dma.c b/src/lib/dma.c index fc62e5e8f4f6..d24f730276b1 100644 --- a/src/lib/dma.c +++ b/src/lib/dma.c @@ -150,7 +150,7 @@ static int dma_init(struct sof_dma *dma) int i; /* allocate dma channels */ - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dma->chan = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dma_chan_data) * dma->plat_data.channels); if (!dma->chan) { @@ -291,14 +291,14 @@ EXPORT_SYMBOL(dma_put); #endif int dma_sg_alloc(struct dma_sg_elem_array *elem_array, - enum mem_zone zone, + uint32_t flags, uint32_t direction, uint32_t buffer_count, uint32_t buffer_bytes, uintptr_t dma_buffer_addr, uintptr_t external_addr) { int i; - elem_array->elems = rzalloc(zone, 0, SOF_MEM_CAPS_RAM, + elem_array->elems = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct dma_sg_elem) * buffer_count); if (!elem_array->elems) return -ENOMEM; diff --git a/src/lib/notifier.c b/src/lib/notifier.c index 4b096111019c..66b84e1c5910 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -59,7 +59,7 @@ int notifier_register(void *receiver, void *caller, enum notify_id type, goto out; } - handle = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + handle = rzalloc(SOF_MEM_FLAG_USER, sizeof(*handle)); if (!handle) { @@ -194,7 +194,7 @@ void init_system_notify(struct sof *sof) { struct notify **notify = arch_notify_get(); int i; - *notify = rzalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, + *notify = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(**notify)); k_spinlock_init(&(*notify)->lock); diff --git a/src/lib/pm_runtime.c b/src/lib/pm_runtime.c index 53ade0ac8a01..d4de85f6fb98 100644 --- a/src/lib/pm_runtime.c +++ b/src/lib/pm_runtime.c @@ -30,7 +30,7 @@ DECLARE_TR_CTX(pm_tr, SOF_UUID(pm_runtime_uuid), LOG_LEVEL_INFO); void pm_runtime_init(struct sof *sof) { - sof->prd = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->prd)); + sof->prd = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*sof->prd)); k_spinlock_init(&sof->prd->lock); platform_pm_runtime_init(sof->prd); @@ -146,7 +146,7 @@ void init_dsp_r_state(enum dsp_r_state r_state) struct pm_runtime_data *prd = pm_runtime_data_get(); struct r_counters_data *r_counters; - r_counters = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*r_counters)); + r_counters = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*r_counters)); prd->r_counters = r_counters; r_counters->ts = sof_cycle_get_64(); diff --git a/src/library_manager/lib_manager.c b/src/library_manager/lib_manager.c index 5831adfddefc..d2a8e37d772b 100644 --- a/src/library_manager/lib_manager.c +++ b/src/library_manager/lib_manager.c @@ -69,7 +69,7 @@ static int lib_manager_auth_init(struct auth_api_ctx *auth_ctx, void **auth_buff if (auth_api_version().major != AUTH_API_VERSION_MAJOR) return -EINVAL; - *auth_buffer = rballoc_align(0, SOF_MEM_CAPS_RAM, + *auth_buffer = rballoc_align(SOF_MEM_FLAG_KERNEL, AUTH_SCRATCH_BUFF_SZ, CONFIG_MM_DRV_PAGE_SIZE); if (!*auth_buffer) return -ENOMEM; @@ -446,8 +446,8 @@ static void lib_manager_update_sof_ctx(void *base_addr, uint32_t lib_id) { struct ext_library *_ext_lib = ext_lib_get(); /* Never freed, will panic if fails */ - struct lib_manager_mod_ctx *ctx = rzalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_COHERENT, - SOF_MEM_CAPS_RAM, sizeof(*ctx)); + struct lib_manager_mod_ctx *ctx = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(*ctx)); ctx->base_addr = base_addr; @@ -602,8 +602,7 @@ int lib_manager_register_module(const uint32_t component_id) } /* allocate new comp_driver_info */ - new_drv_info = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, - SOF_MEM_CAPS_RAM | SOF_MEM_FLAG_COHERENT, + new_drv_info = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct comp_driver_info)); if (!new_drv_info) { @@ -612,8 +611,7 @@ int lib_manager_register_module(const uint32_t component_id) goto cleanup; } - drv = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, - SOF_MEM_CAPS_RAM | SOF_MEM_FLAG_COHERENT, + drv = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct comp_driver)); if (!drv) { tr_err(&lib_manager_tr, "failed to allocate comp_driver"); @@ -680,7 +678,7 @@ static int lib_manager_dma_buffer_alloc(struct lib_manager_dma_ext *dma_ext, * allocate new buffer: this is the actual DMA buffer but we * traditionally allocate a cached address for it */ - dma_ext->dma_addr = (uintptr_t)rballoc_align(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_DMA, size, + dma_ext->dma_addr = (uintptr_t)rballoc_align(SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA, size, dma_ext->addr_align); if (!dma_ext->dma_addr) { tr_err(&lib_manager_tr, "alloc failed"); @@ -793,14 +791,14 @@ static void __sparse_cache *lib_manager_allocate_store_mem(uint32_t size, { void __sparse_cache *local_add; #if CONFIG_L3_HEAP - uint32_t caps = SOF_MEM_CAPS_L3 | SOF_MEM_CAPS_DMA; + uint32_t flags = SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_L3 | SOF_MEM_FLAG_DMA; #else - uint32_t caps = SOF_MEM_CAPS_DMA; + uint32_t flags = SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_DMA; #endif uint32_t addr_align = PAGE_SZ; /* allocate new buffer: cached alias */ - local_add = (__sparse_force void __sparse_cache *)rballoc_align(0, caps, size, addr_align); + local_add = (__sparse_force void __sparse_cache *)rballoc_align(flags, size, addr_align); if (!local_add) { tr_err(&lib_manager_tr, "alloc failed"); @@ -898,7 +896,7 @@ static int lib_manager_setup(uint32_t dma_id) if (_ext_lib->runtime_data) return 0; - dma_ext = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + dma_ext = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*dma_ext)); if (!dma_ext) return -ENOMEM; @@ -983,7 +981,7 @@ int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type) /* allocate temporary manifest buffer */ man_tmp_buffer = (__sparse_force void __sparse_cache *) - rballoc_align(0, SOF_MEM_CAPS_DMA, + rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, MAN_MAX_SIZE_V1_8, CONFIG_MM_DRV_PAGE_SIZE); if (!man_tmp_buffer) { ret = -ENOMEM; diff --git a/src/library_manager/lib_notification.c b/src/library_manager/lib_notification.c index eb144ebaa398..36aa85835e70 100644 --- a/src/library_manager/lib_notification.c +++ b/src/library_manager/lib_notification.c @@ -49,8 +49,8 @@ struct ipc_msg *lib_notif_msg_init(uint32_t header, uint32_t size) return NULL; } - msg_pool_elem = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, - SOF_MEM_CAPS_RAM, sizeof(*msg_pool_elem)); + msg_pool_elem = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, + sizeof(*msg_pool_elem)); if (!msg_pool_elem) return NULL; msg = ipc_msg_init(header, SRAM_OUTBOX_SIZE); diff --git a/src/library_manager/llext_manager.c b/src/library_manager/llext_manager.c index 0272b0280f8e..1ec0dd598db7 100644 --- a/src/library_manager/llext_manager.c +++ b/src/library_manager/llext_manager.c @@ -435,8 +435,8 @@ static int llext_manager_mod_init(struct lib_manager_mod_ctx *ctx, * Loadable modules are loaded to DRAM once and never unloaded from it. * Context, related to them, is never freed */ - ctx->mod = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, SOF_MEM_FLAG_COHERENT, - SOF_MEM_CAPS_RAM, n_mod * sizeof(ctx->mod[0])); + ctx->mod = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + n_mod * sizeof(ctx->mod[0])); if (!ctx->mod) return -ENOMEM; @@ -528,7 +528,7 @@ static int llext_manager_link_single(uint32_t module_id, const struct sof_man_fw if (!mctx->ebl) { /* allocate once, never freed */ - mctx->ebl = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + mctx->ebl = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(struct llext_buf_loader)); if (!mctx->ebl) { tr_err(&lib_manager_tr, "loader alloc failed"); diff --git a/src/library_manager/llext_manager_dram.c b/src/library_manager/llext_manager_dram.c index 7629da427462..9c134a3fcd81 100644 --- a/src/library_manager/llext_manager_dram.c +++ b/src/library_manager/llext_manager_dram.c @@ -69,7 +69,7 @@ int llext_manager_store_to_dram(void) sizeof(lib_manager_dram.sym[0]) * n_sym + (sizeof(lib_manager_dram.llext[0]) + sizeof(lib_manager_dram.bldr[0])) * n_llext; - lib_manager_dram.ctx = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_L3, + lib_manager_dram.ctx = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_L3, buf_size); if (!lib_manager_dram.ctx) return -ENOMEM; @@ -171,7 +171,7 @@ int llext_manager_restore_from_dram(void) } /* arrays of pointers for llext_restore() */ - void **ptr_array = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + void **ptr_array = rmalloc(SOF_MEM_FLAG_KERNEL, sizeof(*ptr_array) * lib_manager_dram.n_llext * 2); if (!ptr_array) @@ -191,15 +191,14 @@ int llext_manager_restore_from_dram(void) } /* Panics on failure - use the same zone as during the first boot */ - struct lib_manager_mod_ctx *ctx = rmalloc(SOF_MEM_ZONE_SYS, SOF_MEM_FLAG_COHERENT, - SOF_MEM_CAPS_RAM, sizeof(*ctx)); + struct lib_manager_mod_ctx *ctx = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(*ctx)); /* Restore the library context */ *ctx = lib_manager_dram.ctx[j++]; /* Allocate and restore all the modules in the library */ - struct lib_manager_module *mod = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, + struct lib_manager_module *mod = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, ctx->n_mod * sizeof(ctx->mod[0])); if (!mod) { @@ -220,8 +219,8 @@ int llext_manager_restore_from_dram(void) continue; /* Loaders are supplied by the caller */ - struct llext_buf_loader *bldr = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, sizeof(*bldr)); + struct llext_buf_loader *bldr = rmalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(*bldr)); if (!bldr) { tr_err(&lib_manager_tr, "loader allocation failure"); diff --git a/src/math/auditory/auditory.c b/src/math/auditory/auditory.c index edff8d38e6e6..dbfe47b1699c 100644 --- a/src/math/auditory/auditory.c +++ b/src/math/auditory/auditory.c @@ -200,7 +200,7 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb) } fb->data_length = &fb->scratch_data2[base_idx] - &fb->scratch_data2[0]; - fb->data = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + fb->data = rzalloc(SOF_MEM_FLAG_USER, sizeof(int16_t) * fb->data_length); if (!fb->data) return -ENOMEM; diff --git a/src/math/fft/fft_common.c b/src/math/fft/fft_common.c index e1c89b09d75c..a2afd09cf127 100644 --- a/src/math/fft/fft_common.c +++ b/src/math/fft/fft_common.c @@ -21,7 +21,7 @@ struct fft_plan *fft_plan_new(void *inb, void *outb, uint32_t size, int bits) if (!inb || !outb) return NULL; - plan = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(struct fft_plan)); + plan = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct fft_plan)); if (!plan) return NULL; @@ -48,7 +48,7 @@ struct fft_plan *fft_plan_new(void *inb, void *outb, uint32_t size, int bits) plan->size = lim; plan->len = len; - plan->bit_reverse_idx = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + plan->bit_reverse_idx = rzalloc(SOF_MEM_FLAG_USER, plan->size * sizeof(uint16_t)); if (!plan->bit_reverse_idx) { rfree(plan); diff --git a/src/platform/amd/acp_6_3/platform.c b/src/platform/amd/acp_6_3/platform.c index 753073a4dcb0..e0b1f2b8fe9f 100644 --- a/src/platform/amd/acp_6_3/platform.c +++ b/src/platform/amd/acp_6_3/platform.c @@ -173,7 +173,7 @@ int platform_init(struct sof *sof) /* Initialize DMA for Trace*/ trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE); sof->dmat->config.elem_array.elems = - rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct dma_sg_elem) * 1); sof->dmat->config.elem_array.count = 1; sof->dmat->config.elem_array.elems->dest = 0x03800000; diff --git a/src/platform/amd/acp_7_0/platform.c b/src/platform/amd/acp_7_0/platform.c index 2ea94c659d92..0111edd8a191 100644 --- a/src/platform/amd/acp_7_0/platform.c +++ b/src/platform/amd/acp_7_0/platform.c @@ -172,7 +172,7 @@ int platform_init(struct sof *sof) /* Initialize DMA for Trace*/ trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE); sof->dmat->config.elem_array.elems = - rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct dma_sg_elem) * 1); sof->dmat->config.elem_array.count = 1; sof->dmat->config.elem_array.elems->dest = 0x03800000; diff --git a/src/platform/amd/rembrandt/platform.c b/src/platform/amd/rembrandt/platform.c index 6b276df5188e..1c26e8e8fcfa 100644 --- a/src/platform/amd/rembrandt/platform.c +++ b/src/platform/amd/rembrandt/platform.c @@ -161,7 +161,7 @@ int platform_init(struct sof *sof) #if CONFIG_TRACE /* Initialize DMA for Trace*/ trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE); - sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct dma_sg_elem) * 1); sof->dmat->config.elem_array.count = 1; sof->dmat->config.elem_array.elems->dest = 0x03800000; diff --git a/src/platform/amd/renoir/platform.c b/src/platform/amd/renoir/platform.c index eecb8d61af56..ad2fa16cf0a0 100644 --- a/src/platform/amd/renoir/platform.c +++ b/src/platform/amd/renoir/platform.c @@ -167,7 +167,7 @@ int platform_init(struct sof *sof) #if CONFIG_TRACE /* Initialize DMA for Trace*/ trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE); - sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct dma_sg_elem) * 1); sof->dmat->config.elem_array.count = 1; sof->dmat->config.elem_array.elems->dest = 0x03800000; diff --git a/src/platform/amd/vangogh/platform.c b/src/platform/amd/vangogh/platform.c index ad06fbb4b3cd..300239a023be 100644 --- a/src/platform/amd/vangogh/platform.c +++ b/src/platform/amd/vangogh/platform.c @@ -166,7 +166,7 @@ int platform_init(struct sof *sof) #if CONFIG_TRACE /* Initialize DMA for Trace*/ trace_point(TRACE_BOOT_PLATFORM_DMA_TRACE); - sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + sof->dmat->config.elem_array.elems = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct dma_sg_elem) * 1); sof->dmat->config.elem_array.count = 1; sof->dmat->config.elem_array.elems->dest = 0x03800000; diff --git a/src/platform/library/lib/alloc.c b/src/platform/library/lib/alloc.c index 48bfd50431ce..ec7667b351be 100644 --- a/src/platform/library/lib/alloc.c +++ b/src/platform/library/lib/alloc.c @@ -16,12 +16,12 @@ /* testbench mem alloc definition */ -void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *rmalloc(uint32_t flags, size_t bytes) { return malloc(bytes); } -void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *rzalloc(uint32_t flags, size_t bytes) { return calloc(bytes, 1); } @@ -31,13 +31,13 @@ void rfree(void *ptr) free(ptr); } -void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment) { return malloc(bytes); } -void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, +void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes, uint32_t alignment) { return realloc(ptr, bytes); diff --git a/src/probe/probe.c b/src/probe/probe.c index 6892474c9354..7b4dce770638 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -98,7 +98,7 @@ static int probe_dma_buffer_init(struct probe_dma_buf *buffer, uint32_t size, uint32_t align) { /* allocate new buffer */ - buffer->addr = (uintptr_t)rballoc_align(0, SOF_MEM_CAPS_DMA, + buffer->addr = (uintptr_t)rballoc_align(0 | SOF_MEM_FLAG_DMA, size, align); if (!buffer->addr) { @@ -352,7 +352,7 @@ int probe_init(const struct probe_dma *probe_dma) } /* alloc probes main struct */ - sof_get()->probe = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + sof_get()->probe = rzalloc(SOF_MEM_FLAG_USER, sizeof(*_probe)); _probe = probe_get(); diff --git a/src/samples/audio/detect_test.c b/src/samples/audio/detect_test.c index 35270b60f275..746fa2b6ab8a 100644 --- a/src/samples/audio/detect_test.c +++ b/src/samples/audio/detect_test.c @@ -673,7 +673,7 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) goto fail; @@ -736,7 +736,7 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv, #if CONFIG_KWD_NN_SAMPLE_KEYPHRASE /* global buffer to accumulate data for processing */ - cd->input = rballoc_align(0, SOF_MEM_CAPS_RAM, + cd->input = rballoc_align(SOF_MEM_FLAG_USER, sizeof(int16_t) * KWD_NN_IN_BUFF_SIZE, 64); if (!cd->input) { comp_err(dev, "test_keyword_new(): input alloc failed"); diff --git a/src/samples/audio/smart_amp_test_ipc3.c b/src/samples/audio/smart_amp_test_ipc3.c index f02f6c5d9db7..610e38f6d753 100644 --- a/src/samples/audio/smart_amp_test_ipc3.c +++ b/src/samples/audio/smart_amp_test_ipc3.c @@ -61,7 +61,7 @@ static struct comp_dev *smart_amp_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - sad = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*sad)); + sad = rzalloc(SOF_MEM_FLAG_USER, sizeof(*sad)); if (!sad) goto fail; diff --git a/src/samples/audio/smart_amp_test_ipc4.c b/src/samples/audio/smart_amp_test_ipc4.c index b19a610fde88..53f42b43f03b 100644 --- a/src/samples/audio/smart_amp_test_ipc4.c +++ b/src/samples/audio/smart_amp_test_ipc4.c @@ -62,7 +62,7 @@ static int smart_amp_init(struct processing_module *mod) comp_dbg(dev, "entry"); - sad = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*sad)); + sad = rzalloc(SOF_MEM_FLAG_USER, sizeof(*sad)); if (!sad) return -ENOMEM; diff --git a/src/schedule/dma_multi_chan_domain.c b/src/schedule/dma_multi_chan_domain.c index 9bf41a8515dc..08ff6faafa49 100644 --- a/src/schedule/dma_multi_chan_domain.c +++ b/src/schedule/dma_multi_chan_domain.c @@ -371,7 +371,7 @@ struct ll_schedule_domain *dma_multi_chan_domain_init(struct dma *dma_array, domain = domain_init(SOF_SCHEDULE_LL_DMA, clk, true, &dma_multi_chan_domain_ops); - dma_domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dma_domain)); + dma_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*dma_domain)); dma_domain->dma_array = dma_array; dma_domain->num_dma = num_dma; dma_domain->aggregated_irq = aggregated_irq; diff --git a/src/schedule/dma_single_chan_domain.c b/src/schedule/dma_single_chan_domain.c index 7016bc64688a..45204fe454bd 100644 --- a/src/schedule/dma_single_chan_domain.c +++ b/src/schedule/dma_single_chan_domain.c @@ -544,7 +544,7 @@ struct ll_schedule_domain *dma_single_chan_domain_init(struct dma *dma_array, domain = domain_init(SOF_SCHEDULE_LL_DMA, clk, false, &dma_single_chan_domain_ops); - dma_domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dma_domain)); + dma_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*dma_domain)); dma_domain->dma_array = dma_array; dma_domain->num_dma = num_dma; dma_domain->owner = DMA_DOMAIN_OWNER_INVALID; diff --git a/src/schedule/edf_schedule.c b/src/schedule/edf_schedule.c index 11bf195dba7a..52e299d8cdaf 100644 --- a/src/schedule/edf_schedule.c +++ b/src/schedule/edf_schedule.c @@ -143,7 +143,7 @@ int schedule_task_init_edf(struct task *task, const struct sof_uuid_entry *uid, if (edf_sch_get_pdata(task)) return -EEXIST; - edf_pdata = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + edf_pdata = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*edf_pdata)); if (!edf_pdata) { tr_err(&edf_tr, "schedule_task_init_edf(): alloc failed"); @@ -256,7 +256,7 @@ int scheduler_init_edf(void) tr_info(&edf_tr, "edf_scheduler_init()"); - edf_sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + edf_sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*edf_sch)); list_init(&edf_sch->list); edf_sch->clock = PLATFORM_DEFAULT_CLOCK; diff --git a/src/schedule/ll_schedule.c b/src/schedule/ll_schedule.c index 7f5d0bca526f..1b703c81a204 100644 --- a/src/schedule/ll_schedule.c +++ b/src/schedule/ll_schedule.c @@ -621,7 +621,7 @@ int schedule_task_init_ll(struct task *task, if (ll_sch_get_pdata(task)) return -EEXIST; - ll_pdata = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + ll_pdata = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*ll_pdata)); if (!ll_pdata) { @@ -781,7 +781,7 @@ int scheduler_init_ll(struct ll_schedule_domain *domain) struct ll_schedule_data *sch; /* initialize scheduler private data */ - sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*sch)); + sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); list_init(&sch->tasks); atomic_init(&sch->num_tasks, 0); sch->domain = domain; diff --git a/src/schedule/schedule.c b/src/schedule/schedule.c index b8c6832b446b..b6ecd4af277b 100644 --- a/src/schedule/schedule.c +++ b/src/schedule/schedule.c @@ -50,7 +50,7 @@ static void scheduler_register(struct schedule_data *scheduler) if (!*sch) { /* init schedulers list */ - *sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + *sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(**sch)); list_init(&(*sch)->list); } @@ -66,7 +66,7 @@ void scheduler_init(int type, const struct scheduler_ops *ops, void *data) !ops->schedule_task_free) return; - sch = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*sch)); + sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); list_init(&sch->list); sch->type = type; sch->ops = ops; diff --git a/src/schedule/task.c b/src/schedule/task.c index bf55c70fec02..72dea02a3f64 100644 --- a/src/schedule/task.c +++ b/src/schedule/task.c @@ -74,7 +74,7 @@ void task_main_init(void) .get_deadline = task_main_deadline, }; - *main_task = rzalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, + *main_task = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(**main_task)); ret = schedule_task_init_edf(*main_task, SOF_UUID(main_task_uuid), diff --git a/src/schedule/timer_domain.c b/src/schedule/timer_domain.c index 25c37cfc4c3a..7b8baab8af38 100644 --- a/src/schedule/timer_domain.c +++ b/src/schedule/timer_domain.c @@ -159,7 +159,7 @@ struct ll_schedule_domain *timer_domain_init(struct timer *timer, int clk) domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false, &timer_domain_ops); - timer_domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*timer_domain)); + timer_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*timer_domain)); timer_domain->timer = timer; ll_sch_domain_set_pdata(domain, timer_domain); diff --git a/src/schedule/zephyr_dma_domain.c b/src/schedule/zephyr_dma_domain.c index 3f95da7a2476..161b4531b916 100644 --- a/src/schedule/zephyr_dma_domain.c +++ b/src/schedule/zephyr_dma_domain.c @@ -121,9 +121,7 @@ struct ll_schedule_domain *zephyr_dma_domain_init(struct dma *dma_array, &zephyr_dma_domain_ops); /* initialize domain pdata */ - zephyr_dma_domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, - 0, - SOF_MEM_CAPS_RAM, + zephyr_dma_domain = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*zephyr_dma_domain)); zephyr_dma_domain->dma_array = dma_array; @@ -308,8 +306,8 @@ static int register_dma_irq(struct zephyr_dma_domain *domain, * that IRQ hasn't been allocated yet so we need to do * so here. */ - crt_irq_data = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, - SOF_MEM_CAPS_RAM, sizeof(*crt_irq_data)); + crt_irq_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, + sizeof(*crt_irq_data)); if (!crt_irq_data) return -ENOMEM; @@ -321,8 +319,8 @@ static int register_dma_irq(struct zephyr_dma_domain *domain, list_item_append(&crt_irq_data->list, &domain->irqs); } - chan_data = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, - SOF_MEM_CAPS_RAM, sizeof(*chan_data)); + chan_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, + sizeof(*chan_data)); if (!chan_data) return -ENOMEM; diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index f4925e35b11a..99f490862df2 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -307,7 +307,7 @@ struct ll_schedule_domain *zephyr_domain_init(int clk) domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false, &zephyr_domain_ops); - zephyr_domain = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, + zephyr_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*zephyr_domain)); zephyr_domain->ll_domain = domain; diff --git a/src/schedule/zephyr_dp_schedule.c b/src/schedule/zephyr_dp_schedule.c index d35105616a0a..d8b66786d34c 100644 --- a/src/schedule/zephyr_dp_schedule.c +++ b/src/schedule/zephyr_dp_schedule.c @@ -445,7 +445,7 @@ static struct scheduler_ops schedule_dp_ops = { int scheduler_dp_init(void) { int ret; - struct scheduler_dp_data *dp_sch = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + struct scheduler_dp_data *dp_sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct scheduler_dp_data)); if (!dp_sch) return -ENOMEM; @@ -496,7 +496,7 @@ int scheduler_dp_task_init(struct task **task, * As the structure contains zephyr kernel specific data, it must be located in * shared, non cached memory */ - task_memory = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + task_memory = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*task_memory)); if (!task_memory) { tr_err(&dp_tr, "zephyr_dp_task_init(): memory alloc failed"); @@ -506,7 +506,7 @@ int scheduler_dp_task_init(struct task **task, /* allocate stack - must be aligned and cached so a separate alloc */ stack_size = Z_KERNEL_STACK_SIZE_ADJUST(stack_size); p_stack = (__sparse_force void __sparse_cache *) - rballoc_align(0, SOF_MEM_CAPS_RAM, stack_size, Z_KERNEL_STACK_OBJ_ALIGN); + rballoc_align(SOF_MEM_FLAG_KERNEL, stack_size, Z_KERNEL_STACK_OBJ_ALIGN); if (!p_stack) { tr_err(&dp_tr, "zephyr_dp_task_init(): stack alloc failed"); ret = -ENOMEM; diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index 8ce37c2dfddc..8cfb8516555f 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -510,7 +510,7 @@ int zephyr_ll_task_init(struct task *task, if (ret < 0) return ret; - pdata = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, + pdata = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*pdata)); if (!pdata) { tr_err(&ll_tr, "zephyr_ll_task_init(): alloc failed"); @@ -532,7 +532,7 @@ int zephyr_ll_scheduler_init(struct ll_schedule_domain *domain) struct zephyr_ll *sch; /* initialize per-core scheduler private data */ - sch = rmalloc(SOF_MEM_ZONE_SYS, 0, SOF_MEM_CAPS_RAM, sizeof(*sch)); + sch = rmalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); list_init(&sch->tasks); sch->ll_domain = domain; sch->core = cpu_get_id(); diff --git a/src/schedule/zephyr_twb_schedule.c b/src/schedule/zephyr_twb_schedule.c index 38a95f6c3b0f..011c0df1091b 100644 --- a/src/schedule/zephyr_twb_schedule.c +++ b/src/schedule/zephyr_twb_schedule.c @@ -350,7 +350,7 @@ static struct scheduler_ops schedule_twb_ops = { int scheduler_twb_init(void) { - struct scheduler_twb_data *twb_sch = rzalloc(SOF_MEM_ZONE_SYS_RUNTIME, 0, SOF_MEM_CAPS_RAM, + struct scheduler_twb_data *twb_sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(struct scheduler_twb_data)); int ret; @@ -414,7 +414,7 @@ int scheduler_twb_task_init(struct task **task, * As the structure contains zephyr kernel specific data, it must be located in * shared, non cached memory */ - task_memory = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + task_memory = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*task_memory)); if (!task_memory) { tr_err(&twb_tr, "scheduler_twb_task_init(): memory alloc failed"); @@ -424,7 +424,7 @@ int scheduler_twb_task_init(struct task **task, /* allocate stack - must be aligned and cached so a separate alloc */ stack_size = Z_KERNEL_STACK_SIZE_ADJUST(stack_size); p_stack = (__sparse_force void __sparse_cache *) - rballoc_align(0, SOF_MEM_CAPS_RAM, stack_size, Z_KERNEL_STACK_OBJ_ALIGN); + rballoc_align(SOF_MEM_FLAG_KERNEL, stack_size, Z_KERNEL_STACK_OBJ_ALIGN); if (!p_stack) { tr_err(&twb_tr, "scheduler_twb_task_init(): stack alloc failed"); ret = -ENOMEM; diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index a1dbda7d10bb..be2aeff3d05b 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -149,7 +149,7 @@ int dma_trace_init_early(struct sof *sof) */ assert(!dma_trace_initialized(sof->dmat)); - sof->dmat = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->dmat)); + sof->dmat = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->dmat)); dma_sg_init(&sof->dmat->config.elem_array); k_spinlock_init(&sof->dmat->lock); @@ -284,7 +284,7 @@ static int dma_trace_buffer_init(struct dma_trace_data *d) return err; /* For DMA to work properly the buffer must be correctly aligned */ - buf = rballoc_align(0, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, + buf = rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA, DMA_TRACE_LOCAL_SIZE, addr_align); if (!buf) { mtrace_printf(LOG_LEVEL_ERROR, "dma_trace_buffer_init(): alloc failed"); diff --git a/src/trace/trace.c b/src/trace/trace.c index dc0eaff0e5d6..88562c90d356 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -498,7 +498,7 @@ void trace_off(void) void trace_init(struct sof *sof) { - sof->trace = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*sof->trace)); + sof->trace = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->trace)); sof->trace->enable = 1; sof->trace->pos = 0; #if CONFIG_TRACE_FILTERING_ADAPTIVE diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index 0c404747083a..3d844b803268 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -42,30 +42,26 @@ WEAK struct tr_ctx ipc_tr; int host_trace_level = LOG_LEVEL_ERROR; -void WEAK *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void WEAK *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment) { (void)flags; - (void)caps; return calloc(bytes, 1); } -void WEAK *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, +void WEAK *rzalloc(uint32_t flags, size_t bytes) { - (void)zone; (void)flags; - (void)caps; return calloc(bytes, 1); } -void WEAK *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, +void WEAK *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes, uint32_t alignment) { (void)flags; - (void)caps; (void)old_bytes; return realloc(ptr, bytes); diff --git a/test/cmocka/src/lib/alloc/alloc.c b/test/cmocka/src/lib/alloc/alloc.c index a0c975664542..d666141c45b2 100644 --- a/test/cmocka/src/lib/alloc/alloc.c +++ b/test/cmocka/src/lib/alloc/alloc.c @@ -26,44 +26,43 @@ enum test_type { struct test_case { size_t alloc_size; - int alloc_zone; - uint32_t alloc_caps; + uint32_t alloc_flags; uint16_t alloc_num; enum test_type type; const char *name; }; -#define TEST_CASE(bytes, zone, caps, num, type, name_base) \ - {(bytes), (zone), (caps), (num), (type), \ - ("test_lib_alloc_" name_base "__" #zone "__" #bytes "x" #num)} +#define TEST_CASE(bytes, flags, num, type, name_base) \ + {(bytes), (flags), (num), (type), \ + ("test_lib_alloc_" name_base "__" #flags "__" #bytes "x" #num)} static struct test_case test_cases[] = { /* * rmalloc tests */ - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_BULK, + TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_BULK, "rmalloc"), /* @@ -71,135 +70,95 @@ static struct test_case test_cases[] = { * the RZONE_BUFFER and RZONE_RUNTIME tests will not work. */ - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_BULK, "rmalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_BULK, "rmalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_BULK, + TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_BULK, "rmalloc"), - TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_BULK, + TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_BULK, "rmalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_BULK, "rmalloc_dma"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_BULK, "rmalloc_dma"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_BULK, "rmalloc_dma"), + TEST_CASE(1, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_BULK, "rmalloc_dma"), + TEST_CASE(4, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_BULK, "rmalloc_dma"), + TEST_CASE(256, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_BULK, "rmalloc_dma"), /* * rzalloc tests */ - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, + TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 2, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 4, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 4, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(1, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(4, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 8, TEST_ZERO, + TEST_CASE(256, SOF_MEM_FLAG_USER, 8, TEST_ZERO, "rzalloc"), - TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, + TEST_CASE(16, SOF_MEM_FLAG_USER, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_ZERO, "rzalloc_dma"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_ZERO, "rzalloc_dma"), - TEST_CASE(256, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_DMA, 2, TEST_ZERO, "rzalloc_dma"), - - /* - * rballoc tests - */ - - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 1024, - TEST_IMMEDIATE_FREE, "rballoc"), - - TEST_CASE(1, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 2, TEST_BULK, - "rballoc"), - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 2, TEST_BULK, - "rballoc"), - TEST_CASE(256, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 2, TEST_BULK, - "rballoc"), - - TEST_CASE(1, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 4, TEST_BULK, - "rballoc"), - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 4, TEST_BULK, - "rballoc"), - TEST_CASE(256, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 4, TEST_BULK, - "rballoc"), - - TEST_CASE(1, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 8, TEST_BULK, - "rballoc"), - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 8, TEST_BULK, - "rballoc"), - TEST_CASE(256, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 8, TEST_BULK, - "rballoc"), - - TEST_CASE(16, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 64, TEST_BULK, - "rballoc"), - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM, 64, TEST_BULK, - "rballoc"), - - TEST_CASE(1, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, - 2, TEST_BULK, "rballoc_dma"), - TEST_CASE(4, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, - 2, TEST_BULK, "rballoc_dma"), - TEST_CASE(256, SOF_MEM_ZONE_BUFFER, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, - 2, TEST_BULK, "rballoc_dma"), + TEST_CASE(1, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_ZERO, "rzalloc_dma"), + TEST_CASE(4, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_ZERO, "rzalloc_dma"), + TEST_CASE(256, (SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA), + 2, TEST_ZERO, "rzalloc_dma"), }; static int setup(void **state) @@ -234,11 +193,8 @@ static void *alloc(struct test_case *tc) { void *mem; - if (tc->alloc_zone == SOF_MEM_ZONE_BUFFER) - mem = rballoc(0, tc->alloc_caps, tc->alloc_size); - else - mem = rmalloc(tc->alloc_zone, 0, tc->alloc_caps, - tc->alloc_size); + mem = rmalloc(tc->alloc_flags, + tc->alloc_size); return mem; } @@ -247,10 +203,8 @@ static void alloc_free(void **mem, struct test_case *tc) { int i; - if (tc->alloc_zone != SOF_MEM_ZONE_SYS) { - for (i = 0; i < tc->alloc_num; ++i) - rfree(mem[i]); - } + for (i = 0; i < tc->alloc_num; ++i) + rfree(mem[i]); } static void test_lib_alloc_bulk_free(struct test_case *tc) @@ -288,7 +242,7 @@ static void test_lib_alloc_zero(struct test_case *tc) int i; for (i = 0; i < tc->alloc_num; ++i) { - char *mem = rzalloc(tc->alloc_zone, 0, tc->alloc_caps, + char *mem = rzalloc(tc->alloc_flags, tc->alloc_size); int j; diff --git a/test/cmocka/src/lib/fast-get/fast-get-tests.c b/test/cmocka/src/lib/fast-get/fast-get-tests.c index d78bfae4744d..b7041abd827b 100644 --- a/test/cmocka/src/lib/fast-get/fast-get-tests.c +++ b/test/cmocka/src/lib/fast-get/fast-get-tests.c @@ -156,16 +156,14 @@ int main(void) return cmocka_run_group_tests(tests, NULL, NULL); } -void *__wrap_rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); -void *__wrap_rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); +void *__wrap_rzalloc(uint32_t flags, size_t bytes); +void *__wrap_rmalloc(uint32_t flags, size_t bytes); void __wrap_rfree(void *ptr); -void *__wrap_rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *__wrap_rzalloc(uint32_t flags, size_t bytes) { void *ret; - (void)zone; (void)flags; - (void)caps; ret = malloc(bytes); @@ -176,12 +174,10 @@ void *__wrap_rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t b return ret; } -void *__wrap_rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *__wrap_rmalloc(uint32_t flags, size_t bytes) { void *ret; - (void)zone; (void)flags; - (void)caps; ret = malloc(bytes); diff --git a/test/cmocka/src/math/fft/fft.c b/test/cmocka/src/math/fft/fft.c index cfb2ec8d98bb..7c3279c96b57 100644 --- a/test/cmocka/src/math/fft/fft.c +++ b/test/cmocka/src/math/fft/fft.c @@ -59,11 +59,11 @@ static void fft_real(struct comp_buffer *src, struct comp_buffer *dst, uint32_t dst->stream.size < size * sizeof(struct icomplex32)) return; - inb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + inb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!inb) return; - outb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + outb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!outb) goto err_outb; @@ -113,12 +113,12 @@ static void ifft_complex(struct comp_buffer *src, struct comp_buffer *dst, uint3 dst->stream.size < size * sizeof(struct icomplex32)) return; - inb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + inb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!inb) return; - outb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + outb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!outb) goto err_outb; @@ -171,12 +171,12 @@ static void fft_real_2(struct comp_buffer *src, struct comp_buffer *dst1, dst2->stream.size < size * sizeof(struct icomplex32)) return; - inb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + inb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!inb) return; - outb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + outb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex32)); if (!outb) goto err_outb; @@ -489,11 +489,11 @@ static void fft_real_16(struct comp_buffer *src, struct comp_buffer *dst, uint32 dst->stream.size < size * sizeof(struct icomplex16)) return; - inb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + inb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex16)); if (!inb) return; - outb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + outb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex16)); if (!outb) goto err_outb; @@ -543,12 +543,12 @@ static void ifft_complex_16(struct comp_buffer *src, struct comp_buffer *dst, ui dst->stream.size < size * sizeof(struct icomplex16)) return; - inb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + inb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex16)); if (!inb) return; - outb = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + outb = rzalloc(SOF_MEM_FLAG_USER, size * sizeof(struct icomplex16)); if (!outb) goto err_outb; diff --git a/test/cmocka/src/notifier_mocks.c b/test/cmocka/src/notifier_mocks.c index 1b82028b9515..bfdb0d488ffe 100644 --- a/test/cmocka/src/notifier_mocks.c +++ b/test/cmocka/src/notifier_mocks.c @@ -58,7 +58,7 @@ int notifier_register(void *receiver, void *caller, enum notify_id type, if (type >= NOTIFIER_ID_COUNT) return -EINVAL; - handle = rzalloc(0, 0, 0, sizeof(struct callback_handle)); + handle = rzalloc(SOF_MEM_FLAG_USER, sizeof(struct callback_handle)); if (!handle) return -ENOMEM; diff --git a/tools/plugin/modules/alsa.c b/tools/plugin/modules/alsa.c index b261de40ee80..69442c687136 100644 --- a/tools/plugin/modules/alsa.c +++ b/tools/plugin/modules/alsa.c @@ -147,7 +147,7 @@ static struct comp_dev *alsa_new(const struct comp_driver *drv, dev->ipc_config = *config; /* allocate memory for file comp data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) goto error; diff --git a/tools/plugin/modules/shm.c b/tools/plugin/modules/shm.c index 63f9e002e0d2..0ddf297adcd1 100644 --- a/tools/plugin/modules/shm.c +++ b/tools/plugin/modules/shm.c @@ -113,7 +113,7 @@ static struct comp_dev *shm_new(const struct comp_driver *drv, dev->ipc_config = *config; /* allocate memory for shm comp data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) goto error; diff --git a/tools/testbench/file.c b/tools/testbench/file.c index a6a768cf7355..282dc509cce0 100644 --- a/tools/testbench/file.c +++ b/tools/testbench/file.c @@ -534,7 +534,7 @@ static int file_init_set_dai_data(struct processing_module *mod) struct dai_data *dd; struct copier_data *ccd = module_get_private_data(mod); - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); + dd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*dd)); if (!dd) return -ENOMEM; @@ -559,7 +559,7 @@ static int file_init_set_dai_data(struct processing_module *mod) struct dai_data *dd; struct comp_dev *dev = mod->dev; - dd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dd)); + dd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*dd)); if (!dd) return -ENOMEM; @@ -601,14 +601,14 @@ static int file_init(struct processing_module *mod) tb_debug_print("file_init()\n"); - ccd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*ccd)); + ccd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*ccd)); if (!ccd) return -ENOMEM; mod_data->private = ccd; /* File component data is placed to copier's ipcgtw_data */ - cd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd)); if (!cd) { free(ccd); return -ENOMEM; diff --git a/zephyr/include/rtos/alloc.h b/zephyr/include/rtos/alloc.h index 18351ea44d1c..6166ae6de449 100644 --- a/zephyr/include/rtos/alloc.h +++ b/zephyr/include/rtos/alloc.h @@ -19,47 +19,24 @@ * @{ */ -/** - * \brief Heap Memory Zones - * - * The heap has three different zones from where memory can be allocated :- - * - * 1) System Zone. Fixed size heap where alloc always succeeds and is never - * freed. Used by any init code that will never give up the memory. - * - * 2) System Runtime Zone. Heap zone intended for runtime objects allocated - * by the kernel part of the code. - * - * 3) Runtime Zone. Main and larger heap zone where allocs are not guaranteed to - * succeed. Memory can be freed here. - * - * 4) Buffer Zone. Largest heap zone intended for audio buffers. - * - * 5) Runtime Shared Zone. Similar to Runtime Zone, but content may be used and - * fred from any enabled core. - * - * 6) System Shared Zone. Similar to System Zone, but content may be used from - * any enabled core. - * - * See platform/memory.h for heap size configuration and mappings. - */ -enum mem_zone { - SOF_MEM_ZONE_SYS = 0, /**< System zone */ - SOF_MEM_ZONE_SYS_RUNTIME, /**< System-runtime zone */ - SOF_MEM_ZONE_RUNTIME, /**< Runtime zone */ - SOF_MEM_ZONE_BUFFER, /**< Buffer zone */ - SOF_MEM_ZONE_RUNTIME_SHARED, /**< Runtime shared zone */ - SOF_MEM_ZONE_SYS_SHARED, /**< System shared zone */ -}; - /** \name Heap zone flags * @{ */ + /** \brief Indicates we should return DMA-able memory. */ +#define SOF_MEM_FLAG_DMA BIT(0) /** \brief Indicates that original content should not be copied by realloc. */ #define SOF_MEM_FLAG_NO_COPY BIT(1) /** \brief Indicates that if we should return uncached address. */ -#define SOF_MEM_FLAG_COHERENT BIT(2) +#define SOF_MEM_FLAG_COHERENT BIT(2) +/** \brief Indicates that if we should return L3 address. */ +#define SOF_MEM_FLAG_L3 BIT(3) +/** \brief Indicates that if we should return Low power memory address. */ +#define SOF_MEM_FLAG_LOW_POWER BIT(4) +/** \brief Indicates that if we should return kernel memory address. */ +#define SOF_MEM_FLAG_KERNEL BIT(5) +/** \brief Indicates that if we should return user memory address. */ +#define SOF_MEM_FLAG_USER BIT(6) /** @} */ @@ -74,7 +51,7 @@ enum mem_zone { * @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). * Use rballoc(), rballoc_align() to allocate memory for buffers. */ -void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); +void *rmalloc(uint32_t flags, size_t bytes); /** * Similar to rmalloc(), guarantees that returned block is zeroed. @@ -82,7 +59,7 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); * @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). * rballoc(), rballoc_align() to allocate memory for buffers. */ -void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); +void *rzalloc(uint32_t flags, size_t bytes); /** * Allocates memory block from SOF_MEM_ZONE_BUFFER. @@ -92,15 +69,15 @@ void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); * @param alignment Alignment in bytes. * @return Pointer to the allocated memory or NULL if failed. */ -void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment); /** * Similar to rballoc_align(), returns buffer aligned to PLATFORM_DCACHE_ALIGN. */ -static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) +static inline void *rballoc(uint32_t flags, size_t bytes) { - return rballoc_align(flags, caps, bytes, PLATFORM_DCACHE_ALIGN); + return rballoc_align(flags, bytes, PLATFORM_DCACHE_ALIGN); } /** @@ -113,17 +90,17 @@ static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) * @param alignment Alignment in bytes. * @return Pointer to the resized memory of NULL if failed. */ -void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, +void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes, uint32_t alignment); /** * Similar to rballoc_align(), returns resized buffer aligned to * PLATFORM_DCACHE_ALIGN. */ -static inline void *rbrealloc(void *ptr, uint32_t flags, uint32_t caps, +static inline void *rbrealloc(void *ptr, uint32_t flags, size_t bytes, size_t old_bytes) { - return rbrealloc_align(ptr, flags, caps, bytes, old_bytes, + return rbrealloc_align(ptr, flags, bytes, old_bytes, PLATFORM_DCACHE_ALIGN); } diff --git a/zephyr/include/sof/lib/dma.h b/zephyr/include/sof/lib/dma.h index bb3c63d5441c..1b384412b123 100644 --- a/zephyr/include/sof/lib/dma.h +++ b/zephyr/include/sof/lib/dma.h @@ -283,7 +283,7 @@ static inline void dma_sg_init(struct dma_sg_elem_array *ea) } int dma_sg_alloc(struct dma_sg_elem_array *ea, - enum mem_zone zone, + uint32_t flags, uint32_t direction, uint32_t buffer_count, uint32_t buffer_bytes, uintptr_t dma_buffer_addr, uintptr_t external_addr); diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 41d80aa9342a..b9d970e34b8c 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -226,7 +226,7 @@ static void l3_heap_free(struct k_heap *h, void *mem) #endif #if CONFIG_VIRTUAL_HEAP -static void *virtual_heap_alloc(struct vmh_heap *heap, uint32_t flags, uint32_t caps, size_t bytes, +static void *virtual_heap_alloc(struct vmh_heap *heap, uint32_t flags, size_t bytes, uint32_t align) { void *mem = vmh_alloc(heap, bytes); @@ -372,42 +372,23 @@ static void heap_free(struct k_heap *h, void *mem) k_spin_unlock(&h->lock, key); } -static inline bool zone_is_cached(enum mem_zone zone) -{ -#ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED - switch (zone) { - case SOF_MEM_ZONE_SYS: - case SOF_MEM_ZONE_SYS_RUNTIME: - case SOF_MEM_ZONE_RUNTIME: - case SOF_MEM_ZONE_BUFFER: - return true; - default: - break; - } -#endif - return false; -} - -void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *rmalloc(uint32_t flags, size_t bytes) { void *ptr; struct k_heap *heap; /* choose a heap */ - if (caps & SOF_MEM_CAPS_L3) { + if (flags & SOF_MEM_FLAG_L3) { #if CONFIG_L3_HEAP heap = &l3_heap; /* Uncached L3_HEAP should not be used */ - if (!zone_is_cached(zone)) { + if (flags & SOF_MEM_FLAG_COHERENT) { tr_err(&zephyr_tr, "L3_HEAP available for cached zones only!"); return NULL; } ptr = (__sparse_force void *)l3_heap_alloc_aligned(heap, 0, bytes); - if (!ptr && zone == SOF_MEM_ZONE_SYS) - k_panic(); - return ptr; #else k_panic(); @@ -416,7 +397,7 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) heap = &sof_heap; } - if (zone_is_cached(zone) && !(flags & SOF_MEM_FLAG_COHERENT)) { + if (!(flags & SOF_MEM_FLAG_COHERENT)) { ptr = (__sparse_force void *)heap_alloc_aligned_cached(heap, 0, bytes); } else { /* @@ -426,22 +407,19 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) ptr = heap_alloc_aligned(heap, PLATFORM_DCACHE_ALIGN, bytes); } - if (!ptr && zone == SOF_MEM_ZONE_SYS) - k_panic(); - return ptr; } EXPORT_SYMBOL(rmalloc); /* Use SOF_MEM_ZONE_BUFFER at the moment */ -void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, +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, caps, bytes, alignment); + return rballoc_align(flags, bytes, alignment); } /* Original version returns NULL without freeing this memory */ @@ -451,7 +429,7 @@ void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, return NULL; } - new_ptr = rballoc_align(flags, caps, bytes, alignment); + new_ptr = rballoc_align(flags, bytes, alignment); if (!new_ptr) return NULL; @@ -471,9 +449,9 @@ void *rbrealloc_align(void *ptr, uint32_t flags, uint32_t caps, size_t bytes, * @note Do not use for buffers (SOF_MEM_ZONE_BUFFER zone). * rballoc(), rballoc_align() to allocate memory for buffers. */ -void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) +void *rzalloc(uint32_t flags, size_t bytes) { - void *ptr = rmalloc(zone, flags, caps, bytes); + void *ptr = rmalloc(flags, bytes); if (ptr) memset(ptr, 0, bytes); @@ -490,13 +468,13 @@ EXPORT_SYMBOL(rzalloc); * @param align Alignment in bytes. * @return Pointer to the allocated memory or NULL if failed. */ -void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t align) { struct k_heap *heap; /* choose a heap */ - if (caps & SOF_MEM_CAPS_L3) { + if (flags & SOF_MEM_FLAG_L3) { #if CONFIG_L3_HEAP heap = &l3_heap; return (__sparse_force void *)l3_heap_alloc_aligned(heap, align, bytes); @@ -511,7 +489,7 @@ void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, #if CONFIG_VIRTUAL_HEAP /* Use virtual heap if it is available */ if (virtual_buffers_heap) - return virtual_heap_alloc(virtual_buffers_heap, flags, caps, bytes, align); + return virtual_heap_alloc(virtual_buffers_heap, flags, bytes, align); #endif /* CONFIG_VIRTUAL_HEAP */ if (flags & SOF_MEM_FLAG_COHERENT) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 97ac6cf6060f..16a583b2970a 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -173,7 +173,7 @@ void cpu_notify_state_entry(enum pm_state state) storage_buffer_size += LP_SRAM_SIZE; /* allocate IMR buffer and store it in the global pointer */ - global_imr_ram_storage = rballoc_align(0, SOF_MEM_CAPS_L3, + global_imr_ram_storage = rballoc_align(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_L3, storage_buffer_size, PLATFORM_DCACHE_ALIGN); diff --git a/zephyr/lib/fast-get.c b/zephyr/lib/fast-get.c index 8e576d688dee..3be9475ff90c 100644 --- a/zephyr/lib/fast-get.c +++ b/zephyr/lib/fast-get.c @@ -45,7 +45,7 @@ static int fast_get_realloc(struct sof_fast_get_data *data) const unsigned int init_n_entries = 8; unsigned int n_entries = data->num_entries ? data->num_entries * 2 : init_n_entries; - entries = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, + entries = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, n_entries * sizeof(*entries)); if (!entries) return -ENOMEM; @@ -116,7 +116,7 @@ const void *fast_get(const void *dram_ptr, size_t size) goto out; } - ret = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, size); + ret = rmalloc(SOF_MEM_FLAG_USER, size); if (!ret) goto out; entry->size = size; diff --git a/zephyr/lib/regions_mm.c b/zephyr/lib/regions_mm.c index 797e49d45af8..df4989c37106 100644 --- a/zephyr/lib/regions_mm.c +++ b/zephyr/lib/regions_mm.c @@ -54,7 +54,7 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin int i; struct vmh_heap *new_heap = - rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*new_heap)); + rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*new_heap)); if (!new_heap) return NULL; @@ -126,8 +126,8 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin * them in memory on sys_heap. * First create allocator - instance of sys_mem_blocks struct. */ - struct sys_mem_blocks *new_allocator = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, sizeof(sys_mem_blocks_t)); + struct sys_mem_blocks *new_allocator = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(sys_mem_blocks_t)); if (!new_allocator) goto fail; @@ -141,8 +141,8 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin new_allocator->buffer = (uint8_t *)new_heap->virtual_region->addr + offset; /* Create bit array that is a part of mem_block kept as a ptr */ - struct sys_bitarray *allocators_bitarray = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, sizeof(sys_bitarray_t)); + struct sys_bitarray *allocators_bitarray = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(sys_bitarray_t)); if (!allocators_bitarray) goto fail; @@ -158,8 +158,8 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin * Mechanism explained in detail in free and alloc function. */ struct sys_bitarray *allocation_sizes_bitarray = - rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, - 0, SOF_MEM_CAPS_RAM, sizeof(sys_bitarray_t)); + rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + sizeof(sys_bitarray_t)); if (!allocation_sizes_bitarray) goto fail; @@ -172,15 +172,15 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin * based on its size. */ uint32_t *allocator_bitarray_bitfield = - rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, bitfield_size); + rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, bitfield_size); if (!allocator_bitarray_bitfield) goto fail; allocators_bitarray->bundles = allocator_bitarray_bitfield; - uint32_t *sizes_bitarray_bitfield = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, - SOF_MEM_CAPS_RAM, bitfield_size); + uint32_t *sizes_bitarray_bitfield = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, + bitfield_size); if (!sizes_bitarray_bitfield) goto fail; From 78f5376eca7f04ce2902700ba9ac6f21b4ed972f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 7 Jul 2025 16:17:15 +0100 Subject: [PATCH 2/2] xtos: heap: check all SYS_ allocations Previously with xtos config the linker would reserve a guaranteed heap for init system allocations that were all guaranteed to succeed. These allocations never failed with Zephyr as they were all done at early boot. Be more mindful and check in the unlikely result of a failure. e.g. a Kconfig with heapsize == 0 Signed-off-by: Liam Girdwood --- src/audio/base_fw_intel.c | 4 +++ src/drivers/imx/ipc.c | 5 ++-- src/drivers/interrupt.c | 5 ++++ src/drivers/mediatek/mt818x/ipc.c | 8 ++++++ src/drivers/mediatek/mt8195/ipc.c | 8 ++++++ src/drivers/mediatek/mt8196/ipc.c | 8 ++++++ src/drivers/mediatek/mt8365/ipc.c | 6 ++++- src/include/sof/schedule/ll_schedule_domain.h | 2 ++ src/ipc/ipc-common.c | 9 +++++++ src/lib/dai.c | 27 +++++++++++++++++-- src/lib/notifier.c | 4 +++ src/lib/pm_runtime.c | 8 ++++++ src/library_manager/lib_manager.c | 4 +++ src/probe/probe.c | 4 +++ src/schedule/dma_multi_chan_domain.c | 9 +++++++ src/schedule/dma_single_chan_domain.c | 9 +++++++ src/schedule/edf_schedule.c | 19 +++++++++---- src/schedule/ll_schedule.c | 4 +++ src/schedule/schedule.c | 8 ++++++ src/schedule/task.c | 2 ++ src/schedule/timer_domain.c | 9 +++++++ src/schedule/zephyr_dma_domain.c | 9 +++++++ src/schedule/zephyr_domain.c | 9 +++++++ src/schedule/zephyr_ll.c | 6 ++++- src/trace/dma-trace.c | 9 ++++--- src/trace/trace.c | 5 ++++ 26 files changed, 186 insertions(+), 14 deletions(-) diff --git a/src/audio/base_fw_intel.c b/src/audio/base_fw_intel.c index 7a03c069349f..2642fd3f7368 100644 --- a/src/audio/base_fw_intel.c +++ b/src/audio/base_fw_intel.c @@ -183,6 +183,10 @@ __cold static int basefw_mem_state_info(uint32_t *data_offset, char *data) size = ALIGN(size, 4); /* size is also saved as tuple length */ tuple_data = rballoc(SOF_MEM_FLAG_USER, size); + if (!tuple_data) { + LOG_ERR("basefw_mem_state_info(): allocation failed"); + return IPC4_ERROR_INVALID_PARAM; + } /* save memory info in data array since info length is variable */ index = 0; diff --git a/src/drivers/imx/ipc.c b/src/drivers/imx/ipc.c index 328ecec2e93c..a124d20a9028 100644 --- a/src/drivers/imx/ipc.c +++ b/src/drivers/imx/ipc.c @@ -202,8 +202,9 @@ int platform_ipc_init(struct ipc *ipc) /* allocate page table buffer */ iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_USER, PLATFORM_PAGE_TABLE_SIZE); - if (iipc->dh_buffer.page_table) - bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE); + if (!iipc->dh_buffer.page_table) + sof_panic(SOF_IPC_PANIC_IPC); + bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE); #if CONFIG_ZEPHYR_NATIVE_DRIVERS iipc->dh_buffer.dmac = sof_dma_get(SOF_DMA_DIR_HMEM_TO_LMEM, 0, SOF_DMA_DEV_HOST, SOF_DMA_ACCESS_SHARED); diff --git a/src/drivers/interrupt.c b/src/drivers/interrupt.c index 03cfb29e1398..5bc1a26e53f7 100644 --- a/src/drivers/interrupt.c +++ b/src/drivers/interrupt.c @@ -74,6 +74,11 @@ int interrupt_cascade_register(const struct irq_cascade_tmpl *tmpl) } *cascade = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(**cascade)); + if (!*cascade) { + ret = -ENOMEM; + tr_err(&irq_tr, "cascading IRQ controller allocation failed!"); + goto unlock; + } k_spinlock_init(&(*cascade)->lock); diff --git a/src/drivers/mediatek/mt818x/ipc.c b/src/drivers/mediatek/mt818x/ipc.c index 914e0f99dbb9..e8a7ab3c22e5 100644 --- a/src/drivers/mediatek/mt818x/ipc.c +++ b/src/drivers/mediatek/mt818x/ipc.c @@ -128,6 +128,10 @@ int platform_ipc_init(struct ipc *ipc) struct ipc_data *iipc; iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); + if (!iipc) { + tr_err(&ipc_tr, "Unable to allocate memory for IPC data"); + sof_panic(SOF_IPC_PANIC_IPC); + } ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -143,6 +147,10 @@ int platform_ipc_init(struct ipc *ipc) /* allocate page table buffer */ iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); + if (!iipc->dh_buffer.page_table) { + tr_err(&ipc_tr, "Unable to allocate host page table buffer"); + sof_panic(SOF_IPC_PANIC_IPC); + } iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8195/ipc.c b/src/drivers/mediatek/mt8195/ipc.c index b8b8c5acf445..cb3734d0fbc3 100644 --- a/src/drivers/mediatek/mt8195/ipc.c +++ b/src/drivers/mediatek/mt8195/ipc.c @@ -127,6 +127,10 @@ int platform_ipc_init(struct ipc *ipc) struct ipc_data *iipc; iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); + if (!iipc) { + tr_err(&ipc_tr, "Unable to allocate memory for IPC data"); + sof_panic(SOF_IPC_PANIC_IPC); + } ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -141,6 +145,10 @@ int platform_ipc_init(struct ipc *ipc) /* allocate page table buffer */ iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); + if (!iipc->dh_buffer.page_table) { + tr_err(&ipc_tr, "Unable to allocate host page table buffer"); + sof_panic(SOF_IPC_PANIC_IPC); + } iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8196/ipc.c b/src/drivers/mediatek/mt8196/ipc.c index 6118ba244fac..dda51b495ab8 100644 --- a/src/drivers/mediatek/mt8196/ipc.c +++ b/src/drivers/mediatek/mt8196/ipc.c @@ -127,6 +127,10 @@ int platform_ipc_init(struct ipc *ipc) struct ipc_data *iipc; iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); + if (!iipc) { + tr_err(&ipc_tr, "Unable to allocate memory for IPC data"); + sof_panic(SOF_IPC_PANIC_IPC); + } ipc_set_drvdata(ipc, iipc); #else ipc_set_drvdata(ipc, NULL); @@ -142,6 +146,10 @@ int platform_ipc_init(struct ipc *ipc) /* allocate page table buffer */ iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); + if (!iipc->dh_buffer.page_table) { + tr_err(&ipc_tr, "Unable to allocate host page table buffer"); + sof_panic(SOF_IPC_PANIC_IPC); + } iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/drivers/mediatek/mt8365/ipc.c b/src/drivers/mediatek/mt8365/ipc.c index 8ff9f779197c..348cd6a51f45 100644 --- a/src/drivers/mediatek/mt8365/ipc.c +++ b/src/drivers/mediatek/mt8365/ipc.c @@ -143,7 +143,7 @@ int platform_ipc_init(struct ipc *ipc) iipc = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*iipc)); if (!iipc) { tr_err(&ipc_tr, "Unable to allocate IPC private data"); - return -ENOMEM; + sof_panic(SOF_IPC_PANIC_IPC); } ipc_set_drvdata(ipc, iipc); #else @@ -159,6 +159,10 @@ int platform_ipc_init(struct ipc *ipc) /* allocate page table buffer */ iipc->dh_buffer.page_table = rzalloc(SOF_MEM_FLAG_KERNEL, PLATFORM_PAGE_TABLE_SIZE); + if (!iipc->dh_buffer.page_table) { + tr_err(&ipc_tr, "Unable to allocate host page table buffer"); + sof_panic(SOF_IPC_PANIC_IPC); + } iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED); if (!iipc->dh_buffer.dmac) { diff --git a/src/include/sof/schedule/ll_schedule_domain.h b/src/include/sof/schedule/ll_schedule_domain.h index a790d710e3da..be8dcb477ce8 100644 --- a/src/include/sof/schedule/ll_schedule_domain.h +++ b/src/include/sof/schedule/ll_schedule_domain.h @@ -99,6 +99,8 @@ static inline struct ll_schedule_domain *domain_init struct ll_schedule_domain *domain; domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*domain)); + if (!domain) + return NULL; domain->type = type; domain->clk = clk; domain->synchronous = synchronous; diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index b126534d0330..4811d366a7ab 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -293,8 +293,17 @@ __cold int ipc_init(struct sof *sof) /* init ipc data */ sof->ipc = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->ipc)); + if (!sof->ipc) { + tr_err(&ipc_tr, "Unable to allocate IPC data"); + return -ENOMEM; + } sof->ipc->comp_data = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, SOF_IPC_MSG_MAX_SIZE); + if (!sof->ipc->comp_data) { + tr_err(&ipc_tr, "Unable to allocate IPC component data"); + rfree(sof->ipc); + return -ENOMEM; + } k_spinlock_init(&sof->ipc->lock); list_init(&sof->ipc->msg_list); diff --git a/src/lib/dai.c b/src/lib/dai.c index 0eab3c279b15..c4daf2b06918 100644 --- a/src/lib/dai.c +++ b/src/lib/dai.c @@ -43,6 +43,11 @@ __cold static struct dai_group_list *dai_group_list_get(int core_id) if (!group_list) { group_list = rzalloc(SOF_MEM_FLAG_USER, sizeof(*group_list)); + if (!group_list) { + tr_err(&dai_tr, "dai_group_list_get(): failed to allocate group_list for core %d", + core_id); + return NULL; + } groups[core_id] = group_list; list_init(&group_list->list); @@ -54,12 +59,19 @@ __cold static struct dai_group_list *dai_group_list_get(int core_id) __cold static struct dai_group *dai_group_find(uint32_t group_id) { struct list_item *dai_groups; + struct dai_group_list *group_list; struct list_item *group_item; struct dai_group *group = NULL; assert_can_be_cold(); - dai_groups = &dai_group_list_get(cpu_get_id())->list; + group_list = dai_group_list_get(cpu_get_id()); + if (!group_list) { + tr_err(&dai_tr, "dai_group_find(): failed to get group_list for core %d", + cpu_get_id()); + return NULL; + } + dai_groups = &group_list->list; list_for_item(group_item, dai_groups) { group = container_of(group_item, struct dai_group, list); @@ -75,13 +87,24 @@ __cold static struct dai_group *dai_group_find(uint32_t group_id) __cold static struct dai_group *dai_group_alloc(void) { - struct list_item *dai_groups = &dai_group_list_get(cpu_get_id())->list; + struct dai_group_list *group_list = dai_group_list_get(cpu_get_id()); + struct list_item *dai_groups; struct dai_group *group; assert_can_be_cold(); + if (!group_list) { + tr_err(&dai_tr, "dai_group_alloc(): failed to get group_list for core %d", + cpu_get_id()); + return NULL; + } + dai_groups = &group_list->list; group = rzalloc(SOF_MEM_FLAG_USER, sizeof(*group)); + if (!group) { + tr_err(&dai_tr, "dai_group_alloc(): failed to allocate dai group"); + return NULL; + } list_item_prepend(&group->list, dai_groups); diff --git a/src/lib/notifier.c b/src/lib/notifier.c index 66b84e1c5910..8ec3d02f8a82 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -196,6 +196,10 @@ void init_system_notify(struct sof *sof) int i; *notify = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(**notify)); + if (!*notify) { + tr_err(&nt_tr, "init_system_notify(): allocation failed"); + sof_panic(SOF_IPC_PANIC_IPC); + } k_spinlock_init(&(*notify)->lock); for (i = NOTIFIER_ID_CPU_FREQ; i < NOTIFIER_ID_COUNT; i++) diff --git a/src/lib/pm_runtime.c b/src/lib/pm_runtime.c index d4de85f6fb98..9d4f2492c8dd 100644 --- a/src/lib/pm_runtime.c +++ b/src/lib/pm_runtime.c @@ -31,6 +31,10 @@ DECLARE_TR_CTX(pm_tr, SOF_UUID(pm_runtime_uuid), LOG_LEVEL_INFO); void pm_runtime_init(struct sof *sof) { sof->prd = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*sof->prd)); + if (!sof->prd) { + tr_err(&pm_tr, "pm_runtime_init(): allocation failed"); + return; + } k_spinlock_init(&sof->prd->lock); platform_pm_runtime_init(sof->prd); @@ -147,6 +151,10 @@ void init_dsp_r_state(enum dsp_r_state r_state) struct r_counters_data *r_counters; r_counters = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*r_counters)); + if (!r_counters) { + tr_err(&pm_tr, "init_dsp_r_state(): allocation failed"); + return; + } prd->r_counters = r_counters; r_counters->ts = sof_cycle_get_64(); diff --git a/src/library_manager/lib_manager.c b/src/library_manager/lib_manager.c index d2a8e37d772b..5c3dfda83e0a 100644 --- a/src/library_manager/lib_manager.c +++ b/src/library_manager/lib_manager.c @@ -448,6 +448,10 @@ static void lib_manager_update_sof_ctx(void *base_addr, uint32_t lib_id) /* Never freed, will panic if fails */ struct lib_manager_mod_ctx *ctx = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*ctx)); + if (!ctx) { + tr_err(&lib_manager_tr, "lib_manager_update_sof_ctx(): allocation failed"); + sof_panic(SOF_IPC_PANIC_IPC); + } ctx->base_addr = base_addr; diff --git a/src/probe/probe.c b/src/probe/probe.c index 7b4dce770638..5c75eae8210b 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -354,6 +354,10 @@ int probe_init(const struct probe_dma *probe_dma) /* alloc probes main struct */ sof_get()->probe = rzalloc(SOF_MEM_FLAG_USER, sizeof(*_probe)); + if (!sof_get()->probe) { + tr_err(&pr_tr, "probe_init(): Alloc failed."); + return -ENOMEM; + } _probe = probe_get(); if (!_probe) { diff --git a/src/schedule/dma_multi_chan_domain.c b/src/schedule/dma_multi_chan_domain.c index 08ff6faafa49..cf6049571f55 100644 --- a/src/schedule/dma_multi_chan_domain.c +++ b/src/schedule/dma_multi_chan_domain.c @@ -370,8 +370,17 @@ struct ll_schedule_domain *dma_multi_chan_domain_init(struct dma *dma_array, domain = domain_init(SOF_SCHEDULE_LL_DMA, clk, true, &dma_multi_chan_domain_ops); + if (!domain) { + tr_err(&ll_tr, "dma_multi_chan_domain_init(): domain init failed"); + return NULL; + } dma_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*dma_domain)); + if (!dma_domain) { + tr_err(&ll_tr, "dma_multi_chan_domain_init(): allocation failed"); + rfree(domain); + return NULL; + } dma_domain->dma_array = dma_array; dma_domain->num_dma = num_dma; dma_domain->aggregated_irq = aggregated_irq; diff --git a/src/schedule/dma_single_chan_domain.c b/src/schedule/dma_single_chan_domain.c index 45204fe454bd..132930cb1a58 100644 --- a/src/schedule/dma_single_chan_domain.c +++ b/src/schedule/dma_single_chan_domain.c @@ -543,8 +543,17 @@ struct ll_schedule_domain *dma_single_chan_domain_init(struct dma *dma_array, domain = domain_init(SOF_SCHEDULE_LL_DMA, clk, false, &dma_single_chan_domain_ops); + if (!domain) { + tr_err(&ll_tr, "dma_single_chan_domain_init(): domain init failed"); + return NULL; + } dma_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*dma_domain)); + if (!dma_domain) { + tr_err(&ll_tr, "dma_single_chan_domain_init(): allocation failed"); + rfree(domain); + return NULL; + } dma_domain->dma_array = dma_array; dma_domain->num_dma = num_dma; dma_domain->owner = DMA_DOMAIN_OWNER_INVALID; diff --git a/src/schedule/edf_schedule.c b/src/schedule/edf_schedule.c index 52e299d8cdaf..5e601fea1bff 100644 --- a/src/schedule/edf_schedule.c +++ b/src/schedule/edf_schedule.c @@ -253,11 +253,17 @@ static int schedule_edf_task_free(void *data, struct task *task) int scheduler_init_edf(void) { struct edf_schedule_data *edf_sch; + int ret; tr_info(&edf_tr, "edf_scheduler_init()"); edf_sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*edf_sch)); + if (!edf_sch) { + tr_err(&edf_tr, "scheduler_init_edf(): allocation failed"); + return -ENOMEM; + } + list_init(&edf_sch->list); edf_sch->clock = PLATFORM_DEFAULT_CLOCK; @@ -267,15 +273,18 @@ int scheduler_init_edf(void) task_main_init(); /* configure EDF scheduler interrupt */ - edf_sch->irq = interrupt_get_irq(PLATFORM_SCHEDULE_IRQ, - PLATFORM_SCHEDULE_IRQ_NAME); - if (edf_sch->irq < 0) - return edf_sch->irq; + ret = interrupt_get_irq(PLATFORM_SCHEDULE_IRQ, + PLATFORM_SCHEDULE_IRQ_NAME); + if (ret < 0) { + free(edf_sch); + return ret; + } + edf_sch->irq = ret; interrupt_register(edf_sch->irq, edf_scheduler_run, edf_sch); interrupt_enable(edf_sch->irq, edf_sch); - return 0; + return ret; } static void scheduler_free_edf(void *data, uint32_t flags) diff --git a/src/schedule/ll_schedule.c b/src/schedule/ll_schedule.c index 1b703c81a204..cadf46d7ef0c 100644 --- a/src/schedule/ll_schedule.c +++ b/src/schedule/ll_schedule.c @@ -782,6 +782,10 @@ int scheduler_init_ll(struct ll_schedule_domain *domain) /* initialize scheduler private data */ sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); + if (!sch) { + tr_err(&ll_tr, "scheduler_init_ll(): allocation failed"); + return -ENOMEM; + } list_init(&sch->tasks); atomic_init(&sch->num_tasks, 0); sch->domain = domain; diff --git a/src/schedule/schedule.c b/src/schedule/schedule.c index b6ecd4af277b..48beb889ec61 100644 --- a/src/schedule/schedule.c +++ b/src/schedule/schedule.c @@ -52,6 +52,10 @@ static void scheduler_register(struct schedule_data *scheduler) /* init schedulers list */ *sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(**sch)); + if (!*sch) { + tr_err(&sch_tr, "scheduler_register(): allocation failed"); + return; + } list_init(&(*sch)->list); } @@ -67,6 +71,10 @@ void scheduler_init(int type, const struct scheduler_ops *ops, void *data) return; sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); + if (!sch) { + tr_err(&sch_tr, "scheduler_init(): allocation failed"); + sof_panic(SOF_IPC_PANIC_IPC); + } list_init(&sch->list); sch->type = type; sch->ops = ops; diff --git a/src/schedule/task.c b/src/schedule/task.c index 72dea02a3f64..9a728ba163a8 100644 --- a/src/schedule/task.c +++ b/src/schedule/task.c @@ -76,6 +76,8 @@ void task_main_init(void) *main_task = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(**main_task)); + if (!*main_task) + panic(SOF_IPC_PANIC_MEM); ret = schedule_task_init_edf(*main_task, SOF_UUID(main_task_uuid), &ops, NULL, cpu, 0); diff --git a/src/schedule/timer_domain.c b/src/schedule/timer_domain.c index 7b8baab8af38..b810a2fea4df 100644 --- a/src/schedule/timer_domain.c +++ b/src/schedule/timer_domain.c @@ -158,8 +158,17 @@ struct ll_schedule_domain *timer_domain_init(struct timer *timer, int clk) domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false, &timer_domain_ops); + if (!domain) { + r_err(&ll_tr, "timer_domain_init(): domain init failed"); + return NULL; + } timer_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*timer_domain)); + if (!timer_domain) { + tr_err(&ll_tr, "timer_domain_init(): allocation failed"); + rfree(domain); + return NULL; + } timer_domain->timer = timer; ll_sch_domain_set_pdata(domain, timer_domain); diff --git a/src/schedule/zephyr_dma_domain.c b/src/schedule/zephyr_dma_domain.c index 161b4531b916..1e05833c157f 100644 --- a/src/schedule/zephyr_dma_domain.c +++ b/src/schedule/zephyr_dma_domain.c @@ -119,10 +119,19 @@ struct ll_schedule_domain *zephyr_dma_domain_init(struct dma *dma_array, clk, true, &zephyr_dma_domain_ops); + if (!domain) { + tr_err(&ll_tr, "zephyr_dma_domain_init(): domain init failed"); + return NULL; + } /* initialize domain pdata */ zephyr_dma_domain = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*zephyr_dma_domain)); + if (!zephyr_dma_domain) { + tr_err(&ll_tr, "zephyr_dma_domain_init(): allocation failed"); + rfree(domain); + return NULL; + } zephyr_dma_domain->dma_array = dma_array; zephyr_dma_domain->num_dma = num_dma; diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index 99f490862df2..04351a35b4cc 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -306,9 +306,18 @@ struct ll_schedule_domain *zephyr_domain_init(int clk) domain = domain_init(SOF_SCHEDULE_LL_TIMER, clk, false, &zephyr_domain_ops); + if (!domain) { + tr_err(&ll_tr, "zephyr_domain_init: domain init failed"); + return NULL; + } zephyr_domain = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*zephyr_domain)); + if (!zephyr_domain) { + tr_err(&ll_tr, "zephyr_domain_init: domain allocation failed"); + rfree(domain); + return NULL; + } zephyr_domain->ll_domain = domain; diff --git a/src/schedule/zephyr_ll.c b/src/schedule/zephyr_ll.c index 8cfb8516555f..a0c3643eae84 100644 --- a/src/schedule/zephyr_ll.c +++ b/src/schedule/zephyr_ll.c @@ -532,7 +532,11 @@ int zephyr_ll_scheduler_init(struct ll_schedule_domain *domain) struct zephyr_ll *sch; /* initialize per-core scheduler private data */ - sch = rmalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); + sch = rzalloc(SOF_MEM_FLAG_KERNEL, sizeof(*sch)); + if (!sch) { + tr_err(&ll_tr, "zephyr_ll_scheduler_init(): allocation failed"); + return -ENOMEM; + } list_init(&sch->tasks); sch->ll_domain = domain; sch->core = cpu_get_id(); diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index be2aeff3d05b..82f3cbd1e46f 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -150,6 +150,11 @@ int dma_trace_init_early(struct sof *sof) assert(!dma_trace_initialized(sof->dmat)); sof->dmat = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->dmat)); + if (!sof->dmat) { + mtrace_printf(LOG_LEVEL_ERROR, + "dma_trace_init_early(): alloc failed"); + return -ENOMEM; + } dma_sg_init(&sof->dmat->config.elem_array); k_spinlock_init(&sof->dmat->lock); @@ -168,9 +173,7 @@ int dma_trace_init_early(struct sof *sof) mtrace_printf(LOG_LEVEL_ERROR, "dma_trace_init_early() failed: %d", ret); - /* Cannot rfree(sof->dmat) from the system memory pool, see - * comments in lib/alloc.c - */ + rfree(sof->dmat); sof->dmat = NULL; return ret; diff --git a/src/trace/trace.c b/src/trace/trace.c index 88562c90d356..f73474404e2b 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -499,6 +499,11 @@ void trace_off(void) void trace_init(struct sof *sof) { sof->trace = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(*sof->trace)); + if (!sof->trace) { + mtrace_printf(LOG_LEVEL_ERROR, "trace_init(): allocation failed"); + sof_panic(SOF_IPC_PANIC_IPC); + } + sof->trace->enable = 1; sof->trace->pos = 0; #if CONFIG_TRACE_FILTERING_ADAPTIVE