diff --git a/Kconfig.xtos-dbg b/Kconfig.xtos-dbg index 3082d7cfad04..6994d2271994 100644 --- a/Kconfig.xtos-dbg +++ b/Kconfig.xtos-dbg @@ -12,3 +12,12 @@ config DEBUG_BLOCK_FREE already freed block of memory. Enabling this feature increases number of memory writes and reads, due to checks for memory patterns that may be performed on allocation and deallocation. + +config DEBUG_FORCE_COHERENT_BUFFER + bool "Force the allocator to allocate coherent buffer only" + default n + help + Select if we want to force the allocator to return coherent/uncached + buffer only. + This should be selected for debug purpose only, as accessing buffer + without caching it will reduce the read/write performance. diff --git a/rimage b/rimage index 9a26e4558094..246ea6469abd 160000 --- a/rimage +++ b/rimage @@ -1 +1 @@ -Subproject commit 9a26e4558094f19f3f7becd89eb9e8a9a9dd82b9 +Subproject commit 246ea6469abdc677b7038285654fd64fc387c5f1 diff --git a/src/arch/xtensa/lib/cpu.c b/src/arch/xtensa/lib/cpu.c index dcbe811f2476..575c7f414e60 100644 --- a/src/arch/xtensa/lib/cpu.c +++ b/src/arch/xtensa/lib/cpu.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ static void alloc_shared_secondary_cores_objects(void) { uint8_t *dynamic_vectors; - dynamic_vectors = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, 0, SOF_DYNAMIC_VECTORS_SIZE); + dynamic_vectors = rballoc(SOF_MEM_FLAG_COHERENT, 0, SOF_DYNAMIC_VECTORS_SIZE); if (dynamic_vectors == NULL) panic(SOF_IPC_PANIC_MEM); diff --git a/src/audio/buffer.c b/src/audio/buffer.c index 5cb439c181be..62e9b70c7138 100644 --- a/src/audio/buffer.c +++ b/src/audio/buffer.c @@ -31,21 +31,20 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align) tr_dbg(&buffer_tr, "buffer_alloc()"); /* validate request */ - if (size == 0 || size > HEAP_BUFFER_SIZE) { + if (size == 0) { tr_err(&buffer_tr, "buffer_alloc(): new size = %u is invalid", size); return NULL; } /* allocate new buffer */ - buffer = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, - sizeof(*buffer)); + buffer = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*buffer)); if (!buffer) { tr_err(&buffer_tr, "buffer_alloc(): could not alloc structure"); return NULL; } - buffer->lock = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + buffer->lock = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*buffer->lock)); if (!buffer->lock) { rfree(buffer); @@ -85,7 +84,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size) void *new_ptr = NULL; /* validate request */ - if (size == 0 || size > HEAP_BUFFER_SIZE) { + if (size == 0) { buf_err(buffer, "resize size = %u is invalid", size); return -EINVAL; } diff --git a/src/audio/dai.c b/src/audio/dai.c index bc437939b36e..08f05bd3d225 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -164,7 +164,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*dd)); if (!dd) { rfree(dev); return NULL; diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index ba830ddf2461..710c25ad1386 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -173,7 +173,8 @@ static struct comp_dev *mux_new(const struct comp_driver *drv, return NULL; dev->ipc_config = *config; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, + /* allocate quite a big buffer, use rballoc to make sure it will succeed */ + cd = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(*cd) + MUX_MAX_STREAMS * sizeof(struct mux_stream_data)); if (!cd) { rfree(dev); diff --git a/src/drivers/dw/dma.c b/src/drivers/dw/dma.c index 317def9fc289..03485f4dffdd 100644 --- a/src/drivers/dw/dma.c +++ b/src/drivers/dw/dma.c @@ -437,9 +437,6 @@ static int dw_dma_stop(struct dma_chan_data *channel) lli->ctrl_hi &= ~DW_CTLH_DONE(1); lli++; } - - dcache_writeback_region(dw_chan->lli, - sizeof(struct dw_lli) * channel->desc_count); #endif /* disable linear link position */ @@ -557,9 +554,9 @@ static int dw_dma_set_config(struct dma_chan_data *channel, if (dw_chan->lli) rfree(dw_chan->lli); - dw_chan->lli = rballoc_align(0, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, - sizeof(struct dw_lli) * channel->desc_count, - PLATFORM_DCACHE_ALIGN); + dw_chan->lli = rballoc(SOF_MEM_FLAG_COHERENT, + SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_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", channel->dma->plat_data.id, @@ -767,10 +764,6 @@ static int dw_dma_set_config(struct dma_chan_data *channel, #endif } - /* write back descriptors so DMA engine can read them directly */ - dcache_writeback_region(dw_chan->lli, - sizeof(struct dw_lli) * channel->desc_count); - channel->status = COMP_STATE_PREPARE; dw_chan->lli_current = dw_chan->lli; @@ -810,8 +803,9 @@ static void dw_dma_verify_transfer(struct dma_chan_data *channel, #if defined __ZEPHYR__ int i; #else - struct dw_lli *lli = platform_dw_dma_lli_get(dw_chan->lli_current); + struct dw_lli *lli = dw_chan->lli_current; #endif + switch (next->status) { case DMA_CB_STATUS_END: channel->status = COMP_STATE_PREPARE; @@ -823,20 +817,14 @@ static void dw_dma_verify_transfer(struct dma_chan_data *channel, * sure the cache is coherent between DSP and DMAC. */ #if defined __ZEPHYR__ - dcache_invalidate_region(dw_chan->lli, - sizeof(struct dw_lli) * channel->desc_count); - for (i = 0; i < channel->desc_count; i++) dw_chan->lli[i].ctrl_hi &= ~DW_CTLH_DONE(1); - - dcache_writeback_region(dw_chan->lli, - sizeof(struct dw_lli) * channel->desc_count); #else while (lli->ctrl_hi & DW_CTLH_DONE(1)) { lli->ctrl_hi &= ~DW_CTLH_DONE(1); dw_chan->lli_current = (struct dw_lli *)dw_chan->lli_current->llp; - lli = platform_dw_dma_lli_get(dw_chan->lli_current); + lli = dw_chan->lli_current; } #endif break; @@ -966,9 +954,8 @@ 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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct dma_chan_data) * dma->plat_data.channels); - if (!dma->chan) { tr_err(&dwdma_tr, "dw_dma_probe(): dma %d allocaction of channels failed", dma->plat_data.id); @@ -987,9 +974,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, - sizeof(*dw_chan)); - + dw_chan = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*dw_chan)); if (!dw_chan) { tr_err(&dwdma_tr, "dw_dma_probe(): dma %d allocaction of channel %d private data failed", dma->plat_data.id, i); diff --git a/src/drivers/generic/dummy-dma.c b/src/drivers/generic/dummy-dma.c index 7e3165120ad4..1c8245981e72 100644 --- a/src/drivers/generic/dummy-dma.c +++ b/src/drivers/generic/dummy-dma.c @@ -435,7 +435,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, dma->plat_data.channels * sizeof(dma->chan[0])); if (!dma->chan) { tr_err(&ddma_tr, "dummy-dmac %d: Out of memory!", diff --git a/src/drivers/imx/esai.c b/src/drivers/imx/esai.c index 26e7bfd3f944..71db8764fc14 100644 --- a/src/drivers/imx/esai.c +++ b/src/drivers/imx/esai.c @@ -394,7 +394,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*pdata)); if (!pdata) { dai_err(dai, "ESAI probe failure, out of memory"); return -ENOMEM; diff --git a/src/drivers/imx/sai.c b/src/drivers/imx/sai.c index 2c013b5b5d3d..13c9ed0a2c58 100644 --- a/src/drivers/imx/sai.c +++ b/src/drivers/imx/sai.c @@ -367,7 +367,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sai)); if (!sai) { dai_err(dai, "sai_probe(): alloc failed"); return -ENOMEM; diff --git a/src/drivers/intel/alh.c b/src/drivers/intel/alh.c index 2e241eed8b4f..c6704f7b0295 100644 --- a/src/drivers/intel/alh.c +++ b/src/drivers/intel/alh.c @@ -117,7 +117,7 @@ static int alh_probe(struct dai *dai) if (dai_get_drvdata(dai)) return -EEXIST; - alh = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*alh)); + alh = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*alh)); if (!alh) { dai_err(dai, "alh_probe() error: alloc failed"); return -ENOMEM; diff --git a/src/drivers/intel/baytrail/ssp.c b/src/drivers/intel/baytrail/ssp.c index c4c0ba0ce972..0e44de88e431 100644 --- a/src/drivers/intel/baytrail/ssp.c +++ b/src/drivers/intel/baytrail/ssp.c @@ -617,7 +617,7 @@ static int ssp_probe(struct dai *dai) struct ssp_pdata *ssp; /* allocate private data */ - ssp = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*ssp)); + ssp = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*ssp)); dai_set_drvdata(dai, ssp); ssp->state[DAI_DIR_PLAYBACK] = COMP_STATE_READY; diff --git a/src/drivers/intel/dmic/dmic.c b/src/drivers/intel/dmic/dmic.c index 139e7fa0b0b0..2a5c0f79a7da 100644 --- a/src/drivers/intel/dmic/dmic.c +++ b/src/drivers/intel/dmic/dmic.c @@ -554,7 +554,7 @@ static int dmic_probe(struct dai *dai) if (dai_get_drvdata(dai)) return -EEXIST; /* already created */ - dmic = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dmic)); + dmic = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*dmic)); if (!dmic) { dai_err(dai, "dmic_probe(): alloc failed"); return -ENOMEM; diff --git a/src/drivers/intel/haswell/ssp.c b/src/drivers/intel/haswell/ssp.c index dae4104eb532..b47e25abf448 100644 --- a/src/drivers/intel/haswell/ssp.c +++ b/src/drivers/intel/haswell/ssp.c @@ -540,7 +540,7 @@ static int ssp_probe(struct dai *dai) struct ssp_pdata *ssp; /* allocate private data */ - ssp = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*ssp)); + ssp = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*ssp)); dai_set_drvdata(dai, ssp); ssp->state[DAI_DIR_PLAYBACK] = COMP_STATE_READY; diff --git a/src/drivers/intel/hda/hda-dma.c b/src/drivers/intel/hda/hda-dma.c index 8d3e56b40bb6..f6a1f4c2da12 100644 --- a/src/drivers/intel/hda/hda-dma.c +++ b/src/drivers/intel/hda/hda-dma.c @@ -792,9 +792,8 @@ static int hda_dma_probe(struct dma *dma) if (dma->chan) return -EEXIST; /* already created */ - dma->chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + dma->chan = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct dma_chan_data) * dma->plat_data.channels); - if (!dma->chan) { tr_err(&hdma_tr, "hda-dmac: %d channels alloc failed", dma->plat_data.id); @@ -810,8 +809,7 @@ static int hda_dma_probe(struct dma *dma) chan->status = COMP_STATE_INIT; chan->core = DMA_CORE_INVALID; - hda_chan = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, - SOF_MEM_CAPS_RAM, + hda_chan = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct hda_chan_data)); if (!hda_chan) { tr_err(&hdma_tr, "hda-dma: %d channel %d private data alloc failed", diff --git a/src/drivers/intel/hda/hda.c b/src/drivers/intel/hda/hda.c index da4be0a696c4..6040b9eea271 100644 --- a/src/drivers/intel/hda/hda.c +++ b/src/drivers/intel/hda/hda.c @@ -71,7 +71,7 @@ static int hda_probe(struct dai *dai) if (dai_get_drvdata(dai)) return -EEXIST; - hda = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*hda)); + hda = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*hda)); if (!hda) { dai_err(dai, "hda_probe() error: alloc failed"); return -ENOMEM; diff --git a/src/drivers/intel/ssp/ssp.c b/src/drivers/intel/ssp/ssp.c index 70b7f2e3ef7c..861c8e116c43 100644 --- a/src/drivers/intel/ssp/ssp.c +++ b/src/drivers/intel/ssp/ssp.c @@ -1132,7 +1132,7 @@ static int ssp_probe(struct dai *dai) return -EEXIST; /* already created */ /* allocate private data */ - ssp = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*ssp)); + ssp = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*ssp)); if (!ssp) { dai_err(dai, "ssp_probe(): alloc failed"); return -ENOMEM; diff --git a/src/drivers/interrupt.c b/src/drivers/interrupt.c index 60c7d7b103df..1928b065df5f 100644 --- a/src/drivers/interrupt.c +++ b/src/drivers/interrupt.c @@ -72,7 +72,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(**cascade)); spinlock_init(&(*cascade)->lock); @@ -204,7 +204,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct irq_desc)); if (!child) { ret = -ENOMEM; diff --git a/src/drivers/mediatek/mt8195/afe-drv.c b/src/drivers/mediatek/mt8195/afe-drv.c index 3ae30e718c1b..162d76e2fb32 100644 --- a/src/drivers/mediatek/mt8195/afe-drv.c +++ b/src/drivers/mediatek/mt8195/afe-drv.c @@ -352,7 +352,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct mtk_base_afe_memif) * afe->memifs_size); if (!afe->memif) return -ENOMEM; @@ -362,14 +362,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, 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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct mtk_base_afe_irq) * afe->irqs_size); if (!afe->irqs) goto err_alloc_dais; diff --git a/src/include/sof/ipc/msg.h b/src/include/sof/ipc/msg.h index 4c5cea20e586..f34d3edfa4ec 100644 --- a/src/include/sof/ipc/msg.h +++ b/src/include/sof/ipc/msg.h @@ -45,11 +45,11 @@ static inline struct ipc_msg *ipc_msg_init(uint32_t header, uint32_t size) { struct ipc_msg *msg; - msg = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*msg)); + msg = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*msg)); if (!msg) return NULL; - msg->tx_data = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, size); + msg->tx_data = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, size); if (!msg->tx_data) { rfree(msg); return NULL; diff --git a/src/include/sof/lib/alloc.h b/src/include/sof/lib/alloc.h index 43142963b5d3..dcab84d49a56 100644 --- a/src/include/sof/lib/alloc.h +++ b/src/include/sof/lib/alloc.h @@ -44,12 +44,6 @@ * * 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 { @@ -57,8 +51,6 @@ enum mem_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 @@ -67,6 +59,8 @@ enum mem_zone { /** \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) /** @} */ @@ -92,9 +86,12 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); void *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes); /** - * Allocates memory block from SOF_MEM_ZONE_BUFFER. + * The recommended helper for buffer allocation. + * It allocates memory block in the buffer zone, and return either cached + * or uncached address, according the requirement from the flag * @param flags Flags, see SOF_MEM_FLAG_... - * @param caps Capabilities, see SOF_MEM_CAPS_... + * @param caps Capabilities, e.g. if _CAPS_DMA is specified, allocate + * buffer from uncacheable memory. See SOF_MEM_CAPS_... * @param bytes Size in bytes. * @param alignment Alignment in bytes. * @return Pointer to the allocated memory or NULL if failed. @@ -113,7 +110,8 @@ static inline void *rballoc(uint32_t flags, uint32_t caps, size_t bytes) /** * Changes size of the memory block allocated from SOF_MEM_ZONE_BUFFER. * @param ptr Address of the block to resize. - * @param flags Flags, see SOF_MEM_FLAG_... + * @param flags Flags, return uncached address if SOF_MEM_FLAG_COHERENT + * is specified, see SOF_MEM_FLAG_... * @param caps Capabilities, see SOF_MEM_CAPS_... * @param bytes New size in bytes. * @param old_bytes Old size in bytes. diff --git a/src/include/sof/lib/mm_heap.h b/src/include/sof/lib/mm_heap.h index 1d570863bd75..e6970b372615 100644 --- a/src/include/sof/lib/mm_heap.h +++ b/src/include/sof/lib/mm_heap.h @@ -62,17 +62,11 @@ struct mm_heap { /* heap block memory map */ struct mm { /* system heap - used during init cannot be freed */ - struct mm_heap system[PLATFORM_HEAP_SYSTEM]; + struct mm_heap system[CONFIG_CORE_COUNT]; /* system runtime heap - used for runtime system components */ - struct mm_heap system_runtime[PLATFORM_HEAP_SYSTEM_RUNTIME]; -#if CONFIG_CORE_COUNT > 1 - /* object shared between different cores - used during init cannot be freed */ - struct mm_heap system_shared[PLATFORM_HEAP_SYSTEM_SHARED]; - /* object shared between different cores */ - struct mm_heap runtime_shared[PLATFORM_HEAP_RUNTIME_SHARED]; -#endif + struct mm_heap system_runtime[CONFIG_CORE_COUNT]; /* general heap for components */ - struct mm_heap runtime[PLATFORM_HEAP_RUNTIME]; + struct mm_heap runtime; /* general component buffer heap */ struct mm_heap buffer[PLATFORM_HEAP_BUFFER]; diff --git a/src/include/sof/schedule/ll_schedule_domain.h b/src/include/sof/schedule/ll_schedule_domain.h index 4dd9ecfac041..dd20c5dda2e1 100644 --- a/src/include/sof/schedule/ll_schedule_domain.h +++ b/src/include/sof/schedule/ll_schedule_domain.h @@ -80,7 +80,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, 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 3848ee133748..3bf87e07463b 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -238,9 +238,9 @@ int ipc_init(struct sof *sof) tr_info(&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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sof->ipc)); + sof->ipc->comp_data = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, + SOF_IPC_MSG_MAX_SIZE); spinlock_init(&sof->ipc->lock); list_init(&sof->ipc->msg_list); diff --git a/src/ipc/ipc3/dai.c b/src/ipc/ipc3/dai.c index 7d1628f742ce..682da6265b43 100644 --- a/src/ipc/ipc3/dai.c +++ b/src/ipc/ipc3/dai.c @@ -287,7 +287,7 @@ int dai_config(struct comp_dev *dev, struct ipc_config_dai *common_config, /* 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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, 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 a87dd30ef9d7..5b68cda2c8dc 100644 --- a/src/ipc/ipc3/handler.c +++ b/src/ipc/ipc3/handler.c @@ -1368,18 +1368,11 @@ static int fill_mem_usage_elems(enum mem_zone zone, enum sof_ipc_dbg_mem_zone ip 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; + int elem_cnt = CONFIG_CORE_COUNT + CONFIG_CORE_COUNT + + 1 + PLATFORM_HEAP_BUFFER; 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; @@ -1396,20 +1389,14 @@ static int ipc_glb_test_mem_usage(uint32_t header) /* 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); + CONFIG_CORE_COUNT, elems); elems += fill_mem_usage_elems(SOF_MEM_ZONE_SYS_RUNTIME, SOF_IPC_MEM_ZONE_SYS_RUNTIME, - PLATFORM_HEAP_SYSTEM_RUNTIME, elems); + CONFIG_CORE_COUNT, elems); elems += fill_mem_usage_elems(SOF_MEM_ZONE_RUNTIME, SOF_IPC_MEM_ZONE_RUNTIME, - PLATFORM_HEAP_RUNTIME, elems); + 1, 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); diff --git a/src/ipc/ipc3/helper.c b/src/ipc/ipc3/helper.c index 8521b09c25da..9e455a3374e7 100644 --- a/src/ipc/ipc3/helper.c +++ b/src/ipc/ipc3/helper.c @@ -361,7 +361,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct ipc_comp_dev)); if (!ipc_pipe) { pipeline_free(pipe); @@ -427,7 +427,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct ipc_comp_dev)); if (!ibd) { buffer_free(buffer); @@ -634,7 +634,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct ipc_comp_dev)); if (!icd) { tr_err(&ipc_tr, "ipc_comp_new(): alloc failed"); diff --git a/src/ipc/ipc4/helper.c b/src/ipc/ipc4/helper.c index 801acc6bcb91..4e347e218943 100644 --- a/src/ipc/ipc4/helper.c +++ b/src/ipc/ipc4/helper.c @@ -117,7 +117,7 @@ int ipc_pipeline_new(struct ipc *ipc, ipc_pipe_new *_pipe_desc) pipe->period = 1000; /* allocate the IPC pipeline container */ - ipc_pipe = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + ipc_pipe = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct ipc_comp_dev)); if (!ipc_pipe) { pipeline_free(pipe); @@ -392,7 +392,7 @@ int ipc4_add_comp_dev(struct comp_dev *dev) struct ipc_comp_dev *icd; /* allocate the IPC component container */ - icd = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, + icd = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(struct ipc_comp_dev)); if (!icd) { tr_err(&ipc_tr, "ipc_comp_new(): alloc failed"); diff --git a/src/lib/agent.c b/src/lib/agent.c index ce9c0f75b007..6e4b98c7b0b4 100644 --- a/src/lib/agent.c +++ b/src/lib/agent.c @@ -94,7 +94,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sof->sa)); /* set default timeouts */ #ifdef __ZEPHYR__ diff --git a/src/lib/alloc.c b/src/lib/alloc.c index dac835605397..5be5039ab15a 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -354,26 +354,37 @@ static inline struct mm_heap *find_in_heap_arr(struct mm_heap *heap_arr, int arr return NULL; } +static bool in_heap_range(void *ptr, struct mm_heap *heap) +{ + return (ptr >= (void *)heap->heap && + (char *)ptr < (char *)heap->heap + heap->size); +} + static struct mm_heap *get_heap_from_ptr(void *ptr) { struct mm *memmap = memmap_get(); struct mm_heap *heap; + int i; + + /* check and panic if freeing system heap */ + for (i = 0; i < CONFIG_CORE_COUNT; i++) { + heap = &memmap->system[i]; + if (in_heap_range(ptr, heap)) { + tr_err(&mem_tr, "attempt to free system heap %d with %p", + i, ptr); + panic(SOF_IPC_PANIC_MEM); + } + } /* 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); + heap = find_in_heap_arr(&memmap->runtime, 1, 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; @@ -451,30 +462,27 @@ 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); int i; int block; int used_blocks; bool heap_is_full; - /* caller uses the direct address got from the allocator, free it directly */ - heap = get_heap_from_ptr(ptr); - - /* some caller uses uncached address while allocated from cached - * address, e.g. SOF_MEM_ZONE_RUNTIME_SHARED region on cAVS platform, - * one more try to free the momory from the corresponding cached - * address. - */ - if (!heap && is_uncached(ptr)) { - tr_dbg(&mem_tr, "free_block(): uncached buffer %p, try freeing from its cached address", - ptr); - ptr = uncache_to_cache(ptr); - heap = get_heap_from_ptr(ptr); - } + /* try cached_ptr first */ + heap = get_heap_from_ptr(cached_ptr); + /* try uncached_ptr if needed */ if (!heap) { - tr_err(&mem_tr, "free_block(): invalid heap = %p, cpu = %d", - ptr, cpu_get_id()); - return; + heap = get_heap_from_ptr(uncached_ptr); + if (!heap) { + tr_err(&mem_tr, "free_block(): invalid heap = %p, cpu = %d", + ptr, cpu_get_id()); + return; + } + ptr = uncached_ptr; + } else { + ptr = cached_ptr; } /* find block that ptr belongs to */ @@ -586,39 +594,21 @@ static void alloc_trace_heap(enum mem_zone zone, uint32_t caps, size_t bytes) switch (zone) { case SOF_MEM_ZONE_SYS: heap_base = memmap->system; - heap_count = PLATFORM_HEAP_SYSTEM; + heap_count = CONFIG_CORE_COUNT; break; case SOF_MEM_ZONE_SYS_RUNTIME: heap_base = memmap->system_runtime; - heap_count = PLATFORM_HEAP_SYSTEM_RUNTIME; + heap_count = CONFIG_CORE_COUNT; break; case SOF_MEM_ZONE_RUNTIME: - heap_base = memmap->runtime; - heap_count = PLATFORM_HEAP_RUNTIME; + heap_base = &memmap->runtime; + heap_count = 1; break; case SOF_MEM_ZONE_BUFFER: heap_base = memmap->buffer; heap_count = PLATFORM_HEAP_BUFFER; break; -#if CONFIG_CORE_COUNT > 1 - case SOF_MEM_ZONE_RUNTIME_SHARED: - heap_base = memmap->runtime_shared; - heap_count = PLATFORM_HEAP_RUNTIME_SHARED; - break; - case SOF_MEM_ZONE_SYS_SHARED: - heap_base = memmap->system_shared; - heap_count = PLATFORM_HEAP_SYSTEM_SHARED; break; -#else - case SOF_MEM_ZONE_RUNTIME_SHARED: - heap_base = memmap->runtime; - heap_count = PLATFORM_HEAP_RUNTIME; - break; - case SOF_MEM_ZONE_SYS_SHARED: - heap_base = memmap->system; - heap_count = PLATFORM_HEAP_SYSTEM; - break; -#endif default: tr_err(&mem_tr, "alloc trace: unsupported mem zone"); goto out; @@ -683,42 +673,19 @@ static void *rmalloc_runtime(uint32_t flags, uint32_t caps, size_t bytes) struct mm_heap *heap; /* check runtime heap for capabilities */ - heap = get_heap_from_caps(memmap->runtime, PLATFORM_HEAP_RUNTIME, caps); + heap = get_heap_from_caps(&memmap->runtime, 1, 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); - + if (!heap) 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) { @@ -735,22 +702,6 @@ static void *_malloc_unlocked(enum mem_zone zone, uint32_t flags, uint32_t caps, 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"); panic(SOF_IPC_PANIC_MEM); /* logic non recoverable problem */ @@ -780,7 +731,9 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes) spin_unlock_irq(&memmap->lock, lock_flags); DEBUG_TRACE_PTR(ptr, bytes, zone, caps, flags); - return ptr; + + return (flags & SOF_MEM_FLAG_COHERENT) ? + cache_to_uncache(ptr) : uncache_to_cache(ptr); } /* allocates and clears memory - not for direct use, clients use rzalloc() */ @@ -946,7 +899,12 @@ static void *_balloc_unlocked(uint32_t flags, uint32_t caps, size_t bytes, n = PLATFORM_HEAP_BUFFER - i; } - return ptr; +#ifdef CONFIG_DEBUG_FORCE_COHERENT_BUFFER + return cache_to_uncache(ptr); +#else + return (flags & SOF_MEM_FLAG_COHERENT) ? + cache_to_uncache(ptr) : uncache_to_cache(ptr); +#endif } /* allocates continuous buffers - not for direct use, clients use rballoc() */ @@ -963,6 +921,9 @@ void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, spin_unlock_irq(&memmap->lock, lock_flags); + if (ptr) + bzero(ptr, bytes); + DEBUG_TRACE_PTR(ptr, bytes, SOF_MEM_ZONE_BUFFER, caps, flags); return ptr; } @@ -970,7 +931,6 @@ void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, static void _rfree_unlocked(void *ptr) { struct mm *memmap = memmap_get(); - struct mm_heap *heap; /* sanity check - NULL ptrs are fine */ if (!ptr) @@ -979,24 +939,6 @@ static void _rfree_unlocked(void *ptr) /* 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()); - panic(SOF_IPC_PANIC_MEM); - } - /* free the block */ free_block(ptr); memmap->heap_trace_updated = 1; @@ -1122,19 +1064,13 @@ void heap_trace_all(int force) /* 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); + heap_trace(memmap->system, CONFIG_CORE_COUNT); tr_info(&mem_tr, "heap: system runtime status"); - heap_trace(memmap->system_runtime, PLATFORM_HEAP_SYSTEM_RUNTIME); + heap_trace(memmap->system_runtime, CONFIG_CORE_COUNT); 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 + heap_trace(&memmap->runtime, 1); } memmap->heap_trace_updated = 0; @@ -1158,20 +1094,16 @@ void init_heap(struct sof *sof) panic(SOF_IPC_PANIC_MEM); #endif - init_heap_map(memmap->system_runtime, PLATFORM_HEAP_SYSTEM_RUNTIME); + init_heap_map(memmap->system_runtime, CONFIG_CORE_COUNT); - 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->runtime, 1); init_heap_map(memmap->buffer, PLATFORM_HEAP_BUFFER); #if CONFIG_DEBUG_BLOCK_FREE - write_pattern((struct mm_heap *)&memmap->buffer, PLATFORM_HEAP_BUFFER, + 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, + write_pattern((struct mm_heap *)&memmap->runtime, 1, DEBUG_BLOCK_FREE_VALUE_8BIT); #endif @@ -1190,37 +1122,25 @@ int heap_info(enum mem_zone zone, int index, struct mm_info *out) switch (zone) { case SOF_MEM_ZONE_SYS: - if (index >= PLATFORM_HEAP_SYSTEM) + if (index >= CONFIG_CORE_COUNT) goto error; heap = memmap->system + index; break; case SOF_MEM_ZONE_SYS_RUNTIME: - if (index >= PLATFORM_HEAP_SYSTEM_RUNTIME) + if (index >= CONFIG_CORE_COUNT) goto error; heap = memmap->system_runtime + index; break; case SOF_MEM_ZONE_RUNTIME: - if (index >= PLATFORM_HEAP_RUNTIME) + if (index >= 1) goto error; - heap = memmap->runtime + index; + heap = &memmap->runtime; 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; } diff --git a/src/lib/pm_runtime.c b/src/lib/pm_runtime.c index d5111b80c88d..a4cbdd479dad 100644 --- a/src/lib/pm_runtime.c +++ b/src/lib/pm_runtime.c @@ -28,7 +28,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sof->prd)); spinlock_init(&sof->prd->lock); platform_pm_runtime_init(sof->prd); @@ -142,7 +142,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*r_counters)); prd->r_counters = r_counters; r_counters->ts = platform_timer_get(timer_get()); diff --git a/src/platform/amd/renoir/include/platform/lib/memory.h b/src/platform/amd/renoir/include/platform/lib/memory.h index 02d68ad6610d..18add5fe30bb 100644 --- a/src/platform/amd/renoir/include/platform/lib/memory.h +++ b/src/platform/amd/renoir/include/platform/lib/memory.h @@ -117,9 +117,6 @@ #define HEAP_BUFFER_BLOCK_SIZE 0x180 #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Vector and literal sizes - not in core-isa.h */ diff --git a/src/platform/amd/renoir/lib/memory.c b/src/platform/amd/renoir/lib/memory.c index 39031655eac1..cdfa89f75931 100644 --- a/src/platform/amd/renoir/lib/memory.c +++ b/src/platform/amd/renoir/lib/memory.c @@ -68,7 +68,7 @@ static SHARED_DATA struct mm memmap = { .info = {.free = HEAP_SYS_RUNTIME_SIZE,}, .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/apollolake/apollolake.x.in b/src/platform/apollolake/apollolake.x.in index df0996a57780..a2de00a8c088 100644 --- a/src/platform/apollolake/apollolake.x.in +++ b/src/platform/apollolake/apollolake.x.in @@ -486,16 +486,6 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) - . = ALIGN (HEAP_BUF_ALIGNMENT); - _runtime_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SIZE; - _runtime_heap_end = ABSOLUTE(.); - - . = ALIGN (HEAP_BUF_ALIGNMENT); - _buffer_heap_start = ABSOLUTE(.); - . = . + HEAP_BUFFER_SIZE; - _buffer_heap_end = ABSOLUTE(.); - . = ALIGN (HEAP_BUF_ALIGNMENT); _system_heap_start = ABSOLUTE(.); . = . + HEAP_SYSTEM_M_SIZE; @@ -506,27 +496,27 @@ SECTIONS . = . + HEAP_SYS_RUNTIME_M_SIZE; _system_runtime_heap_end = ABSOLUTE(.); - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_end = ABSOLUTE(.); - - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_SYSTEM_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_end = ABSOLUTE(.); - . = ALIGN (4096); _sof_stack_start = ABSOLUTE(.); . = . + SOF_STACK_SIZE; _sof_stack_end = ABSOLUTE(.); + . = ALIGN (PLATFORM_DCACHE_ALIGN); +#if CONFIG_CORE_COUNT > 1 . = ALIGN (HEAP_BUF_ALIGNMENT); _sof_core_s_start = ABSOLUTE(.); . = . + SOF_CORE_S_T_SIZE; _sof_core_s_end = ABSOLUTE(.); + . = ALIGN (SRAM_BANK_SIZE); +#endif + _runtime_heap_start = ABSOLUTE(.); + . = . + HEAP_RUNTIME_SIZE; + _runtime_heap_end = ABSOLUTE(.); + + . = ALIGN (PLATFORM_DCACHE_ALIGN); + _buffer_heap_start = ABSOLUTE(.); + . = . + SOF_FW_END - _buffer_heap_start; + _buffer_heap_end = ABSOLUTE(.); _bss_end = ABSOLUTE(.); } >sof_fw :sof_fw_phdr @@ -546,10 +536,6 @@ SECTIONS /* system runtime heap */ _system_runtime_heap = _system_runtime_heap_start; - /* Shared Heap */ - _runtime_shared_heap = _runtime_shared_heap_start; - _system_shared_heap = _system_shared_heap_start; - /* module heap */ _module_heap = _runtime_heap_start; diff --git a/src/platform/apollolake/include/platform/lib/memory.h b/src/platform/apollolake/include/platform/lib/memory.h index 2d3b38483388..ce39bdac56c8 100644 --- a/src/platform/apollolake/include/platform/lib/memory.h +++ b/src/platform/apollolake/include/platform/lib/memory.h @@ -149,17 +149,9 @@ * +------------------+-------------------------+-----------------------------+ * | SOF_FW_START | text | | * | | data | | - * | | ----------------------- | | + * | |+-----------------------+| | * | ||BSS: || | * | ||-----------------------++-----------------------------+ - * | ||Runtime Heap || HEAP_RUNTIME_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Runtime shared Heap || HEAP_RUNTIME_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||System shared Heap || HEAP_SYSTEM_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Module Buffers || HEAP_BUFFER_SIZE | - * | ||-----------------------++-----------------------------+ * | ||Primary core Sys Heap || HEAP_SYSTEM_M_SIZE | * | ||-----------------------++-----------------------------+ * | ||Pri. Sys Runtime Heap || HEAP_SYS_RUNTIME_M_SIZE | @@ -169,7 +161,11 @@ * | ||Sec. core Sys Heap || SOF_CORE_S_T_SIZE | * | ||Sec. Sys Runtime Heap || | * | ||Secondary core Stack || | - * | | ----------------------- | | + * | ||-----------------------++-----------------------------+ + * | ||Runtime Heap || HEAP_RUNTIME_SIZE | + * | ||-----------------------++-----------------------------+ + * | ||Module Buffers || HEAP_BUFFER_SIZE | + * | |+-----------------------+| | * +------------------+-------------------------+-----------------------------+ */ @@ -249,6 +245,9 @@ /* max size for all var-size sections (text/rodata/bss) */ #define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE) +/* TODO: the last 4KB is not usable with QEMU, need to debug it. */ +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE - 0x1000) + #define SOF_TEXT_START (SOF_FW_START) #define SOF_TEXT_BASE (SOF_FW_START) @@ -262,56 +261,26 @@ #define HEAP_SYS_RT_X_COUNT512 4 #define HEAP_SYS_RT_X_COUNT1024 2 -/* Heap section counts base */ -#define HEAP_COUNT64 128 -#define HEAP_COUNT128 128 -#define HEAP_COUNT256 96 -#define HEAP_COUNT512 12 -#define HEAP_COUNT1024 3 -#define HEAP_COUNT2048 1 +/* Heap runtime block counts */ +#define HEAP_COUNT64 48 +#define HEAP_COUNT128 64 +#define HEAP_COUNT256 64 +#define HEAP_COUNT512 6 +#define HEAP_COUNT1024 0 +#define HEAP_COUNT2048 0 #define HEAP_COUNT4096 0 -#define RT_TIMES 1 -#define RT_SHARED_TIMES 1 - -/* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 (HEAP_COUNT64 * RT_TIMES) -#define HEAP_RT_COUNT128 (HEAP_COUNT128 * RT_TIMES) -#define HEAP_RT_COUNT256 (HEAP_COUNT256 * RT_TIMES) -#define HEAP_RT_COUNT512 (HEAP_COUNT512 * RT_TIMES) -#define HEAP_RT_COUNT1024 (HEAP_COUNT1024 * RT_TIMES) -#define HEAP_RT_COUNT2048 (HEAP_COUNT2048 * RT_TIMES) -#define HEAP_RT_COUNT4096 (HEAP_COUNT4096 * RT_TIMES) - -/* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (HEAP_COUNT64 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT128 (HEAP_COUNT128 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT256 (HEAP_COUNT256 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT512 (HEAP_COUNT512 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT1024 (HEAP_COUNT1024 * RT_SHARED_TIMES) - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 - -#define HEAP_BUFFER_SIZE 0x10000 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define HEAP_SYSTEM_M_SIZE 0x4000 /* heap primary core size */ -#define HEAP_SYSTEM_S_SIZE 0x3000 /* heap secondary core size */ +#define HEAP_SYSTEM_M_SIZE 0x3000 /* heap primary core size */ +#define HEAP_SYSTEM_S_SIZE 0x2000 /* heap secondary core size */ #define HEAP_SYSTEM_T_SIZE \ (HEAP_SYSTEM_M_SIZE + ((CONFIG_CORE_COUNT - 1) * HEAP_SYSTEM_S_SIZE)) @@ -398,11 +367,6 @@ #define HEAP_LP_BUFFER_COUNT 0 #endif -#define PLATFORM_HEAP_SYSTEM CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 #define PLATFORM_HEAP_BUFFER 2 /* Stack configuration */ diff --git a/src/platform/baytrail/include/platform/lib/memory.h b/src/platform/baytrail/include/platform/lib/memory.h index 6b0e942ef49b..c96caa2dd2a9 100644 --- a/src/platform/baytrail/include/platform/lib/memory.h +++ b/src/platform/baytrail/include/platform/lib/memory.h @@ -126,11 +126,11 @@ static inline void *platform_rfree_prepare(void *ptr) /* Heap section sizes for module pool */ #define HEAP_RT_COUNT8 0 -#define HEAP_RT_COUNT16 32 -#define HEAP_RT_COUNT32 32 -#define HEAP_RT_COUNT64 32 +#define HEAP_RT_COUNT16 0 +#define HEAP_RT_COUNT32 8 +#define HEAP_RT_COUNT64 4 #define HEAP_RT_COUNT128 32 -#define HEAP_RT_COUNT256 32 +#define HEAP_RT_COUNT256 18 #define HEAP_RT_COUNT512 2 #define HEAP_RT_COUNT1024 1 @@ -143,7 +143,7 @@ static inline void *platform_rfree_prepare(void *ptr) #define SOF_DATA_SIZE 0x9800 #define HEAP_SYSTEM_BASE (DRAM0_BASE + SOF_DATA_SIZE) -#define HEAP_SYSTEM_SIZE 0xA800 +#define HEAP_SYSTEM_SIZE 0x1000 #define HEAP_SYSTEM_0_BASE HEAP_SYSTEM_BASE @@ -167,9 +167,6 @@ static inline void *platform_rfree_prepare(void *ptr) #define HEAP_BUFFER_BLOCK_SIZE 0x100 #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Stack configuration */ diff --git a/src/platform/baytrail/lib/memory.c b/src/platform/baytrail/lib/memory.c index 59c467613bd7..0a3922561a21 100644 --- a/src/platform/baytrail/lib/memory.c +++ b/src/platform/baytrail/lib/memory.c @@ -67,7 +67,7 @@ static SHARED_DATA struct mm memmap = { .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/cannonlake/cannonlake.x.in b/src/platform/cannonlake/cannonlake.x.in index c8e60388ec15..1621f80ce319 100644 --- a/src/platform/cannonlake/cannonlake.x.in +++ b/src/platform/cannonlake/cannonlake.x.in @@ -451,16 +451,6 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) - . = ALIGN (SRAM_BANK_SIZE); - _runtime_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SIZE; - _runtime_heap_end = ABSOLUTE(.); - - . = ALIGN (HEAP_BUF_ALIGNMENT); - _buffer_heap_start = ABSOLUTE(.); - . = . + HEAP_BUFFER_SIZE; - _buffer_heap_end = ABSOLUTE(.); - . = ALIGN (SRAM_BANK_SIZE); _system_heap_start = ABSOLUTE(.); . = . + HEAP_SYSTEM_M_SIZE; @@ -471,27 +461,26 @@ SECTIONS . = . + HEAP_SYS_RUNTIME_M_SIZE; _system_runtime_heap_end = ABSOLUTE(.); - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_end = ABSOLUTE(.); - - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_SYSTEM_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_end = ABSOLUTE(.); - . = ALIGN (4096); _sof_stack_start = ABSOLUTE(.); . = . + SOF_STACK_SIZE; _sof_stack_end = ABSOLUTE(.); +#if CONFIG_CORE_COUNT > 1 . = ALIGN (SRAM_BANK_SIZE); _sof_core_s_start = ABSOLUTE(.); . = . + SOF_CORE_S_T_SIZE; _sof_core_s_end = ABSOLUTE(.); +#endif + . = ALIGN (SRAM_BANK_SIZE); + _runtime_heap_start = ABSOLUTE(.); + . = . + HEAP_RUNTIME_SIZE; + _runtime_heap_end = ABSOLUTE(.); + + . = ALIGN (PLATFORM_DCACHE_ALIGN); + _buffer_heap_start = ABSOLUTE(.); + . = . + SOF_FW_END - _buffer_heap_start; + _buffer_heap_end = ABSOLUTE(.); _bss_end = ABSOLUTE(.); } >sof_fw :sof_fw_phdr @@ -511,10 +500,6 @@ SECTIONS /* system runtime heap */ _system_runtime_heap = _system_runtime_heap_start; - /* Shared Heap */ - _runtime_shared_heap = _runtime_shared_heap_start; - _system_shared_heap = _system_shared_heap_start; - /* module heap */ _module_heap = _runtime_heap_start; diff --git a/src/platform/cannonlake/include/platform/lib/memory.h b/src/platform/cannonlake/include/platform/lib/memory.h index 346857017bb2..b07fb8697bd4 100644 --- a/src/platform/cannonlake/include/platform/lib/memory.h +++ b/src/platform/cannonlake/include/platform/lib/memory.h @@ -153,17 +153,9 @@ * +------------------+-------------------------+-----------------------------+ * | SOF_FW_START | text | | * | | data | | - * | | ----------------------- | | + * | |+-----------------------+| | * | ||BSS: || | * | ||-----------------------++-----------------------------+ - * | ||Runtime Heap || HEAP_RUNTIME_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Runtime shared Heap || HEAP_RUNTIME_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||System shared Heap || HEAP_SYSTEM_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Module Buffers || HEAP_BUFFER_SIZE | - * | ||-----------------------++-----------------------------+ * | ||Primary core Sys Heap || HEAP_SYSTEM_M_SIZE | * | ||-----------------------++-----------------------------+ * | ||Pri. Sys Runtime Heap || HEAP_SYS_RUNTIME_M_SIZE | @@ -173,7 +165,11 @@ * | ||Sec. core Sys Heap || SOF_CORE_S_T_SIZE | * | ||Sec. Sys Runtime Heap || | * | ||Secondary core Stack || | - * | | ----------------------- | | + * | ||-----------------------++-----------------------------+ + * | ||Runtime Heap || HEAP_RUNTIME_SIZE | + * | ||-----------------------++-----------------------------+ + * | ||Module Buffers || HEAP_BUFFER_SIZE | + * | |+-----------------------+| | * +------------------+-------------------------+-----------------------------+ */ @@ -230,6 +226,8 @@ /* max size for all var-size sections (text/rodata/bss) */ #define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE) +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) + #define SOF_TEXT_START (SOF_FW_START) #define SOF_TEXT_BASE (SOF_FW_START) @@ -243,7 +241,7 @@ #define HEAP_SYS_RT_X_COUNT512 8 #define HEAP_SYS_RT_X_COUNT1024 4 -/* Heap section counts base */ +/* Heap runtime block counts */ #define HEAP_COUNT64 128 #define HEAP_COUNT128 128 #define HEAP_COUNT256 96 @@ -252,48 +250,14 @@ #define HEAP_COUNT2048 2 #define HEAP_COUNT4096 1 -#if HP_SRAM_SIZE < 0x200000 -#define RT_TIMES 3 -#define RT_SHARED_TIMES 6 -#else -#define RT_TIMES 8 -#define RT_SHARED_TIMES 16 -#endif - -/* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 (HEAP_COUNT64 * RT_TIMES) -#define HEAP_RT_COUNT128 (HEAP_COUNT128 * RT_TIMES) -#define HEAP_RT_COUNT256 (HEAP_COUNT256 * RT_TIMES) -#define HEAP_RT_COUNT512 (HEAP_COUNT512 * RT_TIMES) -#define HEAP_RT_COUNT1024 (HEAP_COUNT1024 * RT_TIMES) -#define HEAP_RT_COUNT2048 (HEAP_COUNT2048 * RT_TIMES) -#define HEAP_RT_COUNT4096 (HEAP_COUNT4096 * RT_TIMES) - -/* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (HEAP_COUNT64 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT128 (HEAP_COUNT128 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT256 (HEAP_COUNT256 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT512 (HEAP_COUNT512 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT1024 (HEAP_COUNT1024 * RT_SHARED_TIMES) - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 - -#define HEAP_BUFFER_SIZE 0x50000 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) + #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) #define HEAP_SYSTEM_M_SIZE 0x8000 /* heap primary core size */ #define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ @@ -393,11 +357,6 @@ #define HEAP_LP_BUFFER_COUNT 0 #endif -#define PLATFORM_HEAP_SYSTEM CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 #define PLATFORM_HEAP_BUFFER 2 /* Stack configuration */ diff --git a/src/platform/haswell/include/platform/lib/memory.h b/src/platform/haswell/include/platform/lib/memory.h index 920130587f06..ac5497ed1f8a 100644 --- a/src/platform/haswell/include/platform/lib/memory.h +++ b/src/platform/haswell/include/platform/lib/memory.h @@ -166,9 +166,6 @@ static inline void *platform_rfree_prepare(void *ptr) #define HEAP_BUFFER_COUNT \ (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Stack configuration */ diff --git a/src/platform/haswell/lib/memory.c b/src/platform/haswell/lib/memory.c index 59c467613bd7..0a3922561a21 100644 --- a/src/platform/haswell/lib/memory.c +++ b/src/platform/haswell/lib/memory.c @@ -67,7 +67,7 @@ static SHARED_DATA struct mm memmap = { .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/icelake/icelake.x.in b/src/platform/icelake/icelake.x.in index 96874660b360..f6b159af9e2c 100644 --- a/src/platform/icelake/icelake.x.in +++ b/src/platform/icelake/icelake.x.in @@ -455,16 +455,6 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) - . = ALIGN (SRAM_BANK_SIZE); - _runtime_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SIZE; - _runtime_heap_end = ABSOLUTE(.); - - . = ALIGN (HEAP_BUF_ALIGNMENT); - _buffer_heap_start = ABSOLUTE(.); - . = . + HEAP_BUFFER_SIZE; - _buffer_heap_end = ABSOLUTE(.); - . = ALIGN (SRAM_BANK_SIZE); _system_heap_start = ABSOLUTE(.); . = . + HEAP_SYSTEM_M_SIZE; @@ -475,27 +465,26 @@ SECTIONS . = . + HEAP_SYS_RUNTIME_M_SIZE; _system_runtime_heap_end = ABSOLUTE(.); - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_end = ABSOLUTE(.); - - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_SYSTEM_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_end = ABSOLUTE(.); - . = ALIGN (4096); _sof_stack_start = ABSOLUTE(.); . = . + SOF_STACK_SIZE; _sof_stack_end = ABSOLUTE(.); +#if CONFIG_CORE_COUNT > 1 . = ALIGN (SRAM_BANK_SIZE); _sof_core_s_start = ABSOLUTE(.); . = . + SOF_CORE_S_T_SIZE; _sof_core_s_end = ABSOLUTE(.); +#endif + . = ALIGN (SRAM_BANK_SIZE); + _runtime_heap_start = ABSOLUTE(.); + . = . + HEAP_RUNTIME_SIZE; + _runtime_heap_end = ABSOLUTE(.); + + . = ALIGN (PLATFORM_DCACHE_ALIGN); + _buffer_heap_start = ABSOLUTE(.); + . = . + SOF_FW_END - _buffer_heap_start; + _buffer_heap_end = ABSOLUTE(.); _bss_end = ABSOLUTE(.); } >sof_fw :sof_fw_phdr @@ -515,10 +504,6 @@ SECTIONS /* system runtime heap */ _system_runtime_heap = _system_runtime_heap_start; - /* Shared Heap */ - _runtime_shared_heap = _runtime_shared_heap_start; - _system_shared_heap = _system_shared_heap_start; - /* module heap */ _module_heap = _runtime_heap_start; diff --git a/src/platform/icelake/include/platform/lib/memory.h b/src/platform/icelake/include/platform/lib/memory.h index 86135b2cdda2..1383b783e860 100644 --- a/src/platform/icelake/include/platform/lib/memory.h +++ b/src/platform/icelake/include/platform/lib/memory.h @@ -155,14 +155,6 @@ * | | data | | * | | BSS | | * +------------------+-------------------------+-----------------------------+ - * | | Runtime Heap | HEAP_RUNTIME_SIZE | - * +------------------+-------------------------+-----------------------------+ - * | | Runtime shared Heap | HEAP_RUNTIME_SHARED_SIZE | - * | |-------------------------+-----------------------------+ - * | | System shared Heap | HEAP_SYSTEM_SHARED_SIZE | - * | |-------------------------+-----------------------------+ - * | | Module Buffers | HEAP_BUFFER_SIZE | - * +------------------+-------------------------+-----------------------------+ * | | Primary core Sys Heap | HEAP_SYSTEM_M_SIZE | * +------------------+-------------------------+-----------------------------+ * | | Pri. Sys Runtime Heap | HEAP_SYS_RUNTIME_M_SIZE | @@ -173,6 +165,10 @@ * | | Sec. Sys Runtime Heap | | * | | Secondary core Stack | | * +------------------+-------------------------+-----------------------------+ + * | | Runtime Heap | HEAP_RUNTIME_SIZE | + * +------------------+-------------------------+-----------------------------+ + * | | Module Buffers | HEAP_BUFFER_SIZE | + * +------------------+-------------------------+-----------------------------+ */ /* HP SRAM */ @@ -227,6 +223,8 @@ /* max size for all var-size sections (text/rodata/bss) */ #define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE) +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) + #define SOF_TEXT_START (SOF_FW_START) #define SOF_TEXT_BASE (SOF_FW_START) @@ -240,7 +238,7 @@ #define HEAP_SYS_RT_X_COUNT512 8 #define HEAP_SYS_RT_X_COUNT1024 4 -/* Heap section counts base */ +/* Heap runtime block counts */ #define HEAP_COUNT64 128 #define HEAP_COUNT128 128 #define HEAP_COUNT256 96 @@ -249,48 +247,14 @@ #define HEAP_COUNT2048 2 #define HEAP_COUNT4096 1 -#if HP_SRAM_SIZE < 0x200000 -#define RT_TIMES 1 -#define RT_SHARED_TIMES 1 -#else -#define RT_TIMES 8 -#define RT_SHARED_TIMES 16 -#endif - -/* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 (HEAP_COUNT64 * RT_TIMES) -#define HEAP_RT_COUNT128 (HEAP_COUNT128 * RT_TIMES) -#define HEAP_RT_COUNT256 (HEAP_COUNT256 * RT_TIMES) -#define HEAP_RT_COUNT512 (HEAP_COUNT512 * RT_TIMES) -#define HEAP_RT_COUNT1024 (HEAP_COUNT1024 * RT_TIMES) -#define HEAP_RT_COUNT2048 (HEAP_COUNT2048 * RT_TIMES) -#define HEAP_RT_COUNT4096 (HEAP_COUNT4096 * RT_TIMES) - -/* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (HEAP_COUNT64 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT128 (HEAP_COUNT128 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT256 (HEAP_COUNT256 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT512 (HEAP_COUNT512 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT1024 (HEAP_COUNT1024 * RT_SHARED_TIMES) - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 - -#define HEAP_BUFFER_SIZE 0x50000 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) + #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) #define HEAP_SYSTEM_M_SIZE 0x8000 /* heap primary core size */ #define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ @@ -365,11 +329,6 @@ #define HEAP_LP_BUFFER_COUNT 0 #endif -#define PLATFORM_HEAP_SYSTEM CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 #define PLATFORM_HEAP_BUFFER 2 /* Stack configuration */ diff --git a/src/platform/imx8/include/platform/lib/memory.h b/src/platform/imx8/include/platform/lib/memory.h index d2186e0079a8..f9fd961017dd 100644 --- a/src/platform/imx8/include/platform/lib/memory.h +++ b/src/platform/imx8/include/platform/lib/memory.h @@ -148,9 +148,6 @@ #define HEAP_BUFFER_BLOCK_SIZE 0x100 #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Stack configuration */ diff --git a/src/platform/imx8/lib/memory.c b/src/platform/imx8/lib/memory.c index 57a434b4ba20..15a79260ec1c 100644 --- a/src/platform/imx8/lib/memory.c +++ b/src/platform/imx8/lib/memory.c @@ -70,7 +70,7 @@ static SHARED_DATA struct mm memmap = { .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/imx8m/include/platform/lib/memory.h b/src/platform/imx8m/include/platform/lib/memory.h index 0dc0d3f68e27..0be31fbe9d4e 100644 --- a/src/platform/imx8m/include/platform/lib/memory.h +++ b/src/platform/imx8m/include/platform/lib/memory.h @@ -152,9 +152,6 @@ #define HEAP_BUFFER_BLOCK_SIZE 0x100 #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Stack configuration */ diff --git a/src/platform/imx8m/lib/memory.c b/src/platform/imx8m/lib/memory.c index 91e10cce63dc..14d9d16fddb5 100644 --- a/src/platform/imx8m/lib/memory.c +++ b/src/platform/imx8m/lib/memory.c @@ -72,7 +72,7 @@ static SHARED_DATA struct mm memmap = { .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/imx8ulp/include/platform/lib/memory.h b/src/platform/imx8ulp/include/platform/lib/memory.h index cf44cbc85048..66f03a655b5a 100644 --- a/src/platform/imx8ulp/include/platform/lib/memory.h +++ b/src/platform/imx8ulp/include/platform/lib/memory.h @@ -151,9 +151,6 @@ #define HEAP_BUFFER_BLOCK_SIZE 0x100 #define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define PLATFORM_HEAP_SYSTEM 1 /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME 1 /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 1 /* Stack configuration */ diff --git a/src/platform/imx8ulp/lib/memory.c b/src/platform/imx8ulp/lib/memory.c index 56e77c0fdc40..8d184bcb87c3 100644 --- a/src/platform/imx8ulp/lib/memory.c +++ b/src/platform/imx8ulp/lib/memory.c @@ -71,7 +71,7 @@ static SHARED_DATA struct mm memmap = { .caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA, }, - .runtime[0] = { + .runtime = { .blocks = ARRAY_SIZE(rt_heap_map), .map = rt_heap_map, .heap = HEAP_RUNTIME_BASE, diff --git a/src/platform/intel/cavs/include/cavs/drivers/dw-dma.h b/src/platform/intel/cavs/include/cavs/drivers/dw-dma.h index b5306d62ded4..86c57f119b51 100644 --- a/src/platform/intel/cavs/include/cavs/drivers/dw-dma.h +++ b/src/platform/intel/cavs/include/cavs/drivers/dw-dma.h @@ -85,11 +85,6 @@ static inline void platform_dw_dma_llp_disable(struct dma *dma, shim_read(DW_CHLLPC(dma, chan)) & ~SHIM_GPDMA_CHLLPC_EN); } -static inline struct dw_lli *platform_dw_dma_lli_get(struct dw_lli *lli) -{ - return cache_to_uncache(lli); -} - #endif /* __CAVS_LIB_DW_DMA_H__ */ #else diff --git a/src/platform/intel/cavs/lib/memory.c b/src/platform/intel/cavs/lib/memory.c index aa2a5c60ffc9..2a47022e809f 100644 --- a/src/platform/intel/cavs/lib/memory.c +++ b/src/platform/intel/cavs/lib/memory.c @@ -20,9 +20,6 @@ extern uintptr_t _system_heap, _system_runtime_heap, _module_heap; extern uintptr_t _buffer_heap, _sof_core_s_start; -#if CONFIG_CORE_COUNT > 1 -extern uintptr_t _runtime_shared_heap, _system_shared_heap; -#endif /* Heap blocks for system runtime for primary core */ static SHARED_DATA struct block_hdr sys_rt_0_block64[HEAP_SYS_RT_0_COUNT64]; @@ -74,50 +71,32 @@ static SHARED_DATA struct block_map sys_rt_heap_map[CONFIG_CORE_COUNT][3] = { }; /* Heap blocks for modules */ -static SHARED_DATA struct block_hdr mod_block64[HEAP_RT_COUNT64]; -static SHARED_DATA struct block_hdr mod_block128[HEAP_RT_COUNT128]; -static SHARED_DATA struct block_hdr mod_block256[HEAP_RT_COUNT256]; -static SHARED_DATA struct block_hdr mod_block512[HEAP_RT_COUNT512]; -static SHARED_DATA struct block_hdr mod_block1024[HEAP_RT_COUNT1024]; -static SHARED_DATA struct block_hdr mod_block2048[HEAP_RT_COUNT2048]; -static SHARED_DATA struct block_hdr mod_block4096[HEAP_RT_COUNT4096]; +static SHARED_DATA struct block_hdr mod_block64[HEAP_COUNT64]; +static SHARED_DATA struct block_hdr mod_block128[HEAP_COUNT128]; +static SHARED_DATA struct block_hdr mod_block256[HEAP_COUNT256]; +static SHARED_DATA struct block_hdr mod_block512[HEAP_COUNT512]; +static SHARED_DATA struct block_hdr mod_block1024[HEAP_COUNT1024]; +static SHARED_DATA struct block_hdr mod_block2048[HEAP_COUNT2048]; +static SHARED_DATA struct block_hdr mod_block4096[HEAP_COUNT4096]; /* Heap memory map for modules */ static SHARED_DATA struct block_map rt_heap_map[] = { - BLOCK_DEF(64, HEAP_RT_COUNT64, uncached_block_hdr(mod_block64)), - BLOCK_DEF(128, HEAP_RT_COUNT128, uncached_block_hdr(mod_block128)), - BLOCK_DEF(256, HEAP_RT_COUNT256, uncached_block_hdr(mod_block256)), - BLOCK_DEF(512, HEAP_RT_COUNT512, uncached_block_hdr(mod_block512)), - BLOCK_DEF(1024, HEAP_RT_COUNT1024, uncached_block_hdr(mod_block1024)), - BLOCK_DEF(2048, HEAP_RT_COUNT2048, uncached_block_hdr(mod_block2048)), - BLOCK_DEF(4096, HEAP_RT_COUNT4096, uncached_block_hdr(mod_block4096)), -}; - -#if CONFIG_CORE_COUNT > 1 -/* Heap blocks for runtime shared */ -static SHARED_DATA struct block_hdr rt_shared_block64[HEAP_RUNTIME_SHARED_COUNT64]; -static SHARED_DATA struct block_hdr rt_shared_block128[HEAP_RUNTIME_SHARED_COUNT128]; -static SHARED_DATA struct block_hdr rt_shared_block256[HEAP_RUNTIME_SHARED_COUNT256]; -static SHARED_DATA struct block_hdr rt_shared_block512[HEAP_RUNTIME_SHARED_COUNT512]; -static SHARED_DATA struct block_hdr rt_shared_block1024[HEAP_RUNTIME_SHARED_COUNT1024]; - -/* Heap memory map for runtime shared */ -static SHARED_DATA struct block_map rt_shared_heap_map[] = { - BLOCK_DEF(64, HEAP_RUNTIME_SHARED_COUNT64, uncached_block_hdr(rt_shared_block64)), - BLOCK_DEF(128, HEAP_RUNTIME_SHARED_COUNT128, uncached_block_hdr(rt_shared_block128)), - BLOCK_DEF(256, HEAP_RUNTIME_SHARED_COUNT256, uncached_block_hdr(rt_shared_block256)), - BLOCK_DEF(512, HEAP_RUNTIME_SHARED_COUNT512, uncached_block_hdr(rt_shared_block512)), - BLOCK_DEF(1024, HEAP_RUNTIME_SHARED_COUNT1024, uncached_block_hdr(rt_shared_block1024)), + BLOCK_DEF(64, HEAP_COUNT64, uncached_block_hdr(mod_block64)), + BLOCK_DEF(128, HEAP_COUNT128, uncached_block_hdr(mod_block128)), + BLOCK_DEF(256, HEAP_COUNT256, uncached_block_hdr(mod_block256)), + BLOCK_DEF(512, HEAP_COUNT512, uncached_block_hdr(mod_block512)), + BLOCK_DEF(1024, HEAP_COUNT1024, uncached_block_hdr(mod_block1024)), + BLOCK_DEF(2048, HEAP_COUNT2048, uncached_block_hdr(mod_block2048)), + BLOCK_DEF(4096, HEAP_COUNT4096, uncached_block_hdr(mod_block4096)), }; -#endif /* Heap blocks for buffers */ -static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT]; +static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT_MAX]; static SHARED_DATA struct block_hdr lp_buf_block[HEAP_LP_BUFFER_COUNT]; /* Heap memory map for buffers */ static SHARED_DATA struct block_map buf_heap_map[] = { - BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT, + BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT_MAX, uncached_block_hdr(buf_block)), }; @@ -130,8 +109,26 @@ static SHARED_DATA struct mm memmap; void platform_init_memmap(struct sof *sof) { + uint32_t heap_buffer_size = SOF_FW_END - (uint32_t)&_buffer_heap; + uint32_t buffer_count; int i; + /* calculate the buffer heap size */ + buffer_count = heap_buffer_size / HEAP_BUFFER_BLOCK_SIZE; + heap_buffer_size = buffer_count * HEAP_BUFFER_BLOCK_SIZE; + + for (i = 0; i < ARRAY_SIZE(buf_heap_map); i++) { + buf_heap_map[i].count = buffer_count; + buf_heap_map[i].free_count = buffer_count; + } + dcache_writeback_region(buf_heap_map, + sizeof(struct block_map) * ARRAY_SIZE(buf_heap_map)); + + /* + * by default, use cached address for system and runtime zones, + * and uncached address for system_runtime and buffer zones. + */ + /* access memory map through uncached region */ sof->memory_map = cache_to_uncache(&memmap); @@ -139,8 +136,8 @@ void platform_init_memmap(struct sof *sof) sof->memory_map->system[0].heap = (uintptr_t)&_system_heap; sof->memory_map->system[0].size = HEAP_SYSTEM_M_SIZE; sof->memory_map->system[0].info.free = HEAP_SYSTEM_M_SIZE; - sof->memory_map->system[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; + sof->memory_map->system[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; /* .system_runtime primary core initialization */ sof->memory_map->system_runtime[0].blocks = @@ -151,9 +148,8 @@ void platform_init_memmap(struct sof *sof) (uintptr_t)&_system_runtime_heap; sof->memory_map->system_runtime[0].size = HEAP_SYS_RUNTIME_M_SIZE; sof->memory_map->system_runtime[0].info.free = HEAP_SYS_RUNTIME_M_SIZE; - sof->memory_map->system_runtime[0].caps = SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_EXT | SOF_MEM_CAPS_CACHE | - SOF_MEM_CAPS_DMA; + sof->memory_map->system_runtime[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; /* .system and .system_runtime secondary core initialization */ for (i = 1; i < CONFIG_CORE_COUNT; i++) { @@ -163,8 +159,8 @@ void platform_init_memmap(struct sof *sof) ((i - 1) * SOF_CORE_S_SIZE); sof->memory_map->system[i].size = HEAP_SYSTEM_S_SIZE; sof->memory_map->system[i].info.free = HEAP_SYSTEM_S_SIZE; - sof->memory_map->system[i].caps = SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_EXT | SOF_MEM_CAPS_CACHE; + sof->memory_map->system[i].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; /* .system_runtime init */ sof->memory_map->system_runtime[i].blocks = @@ -178,61 +174,41 @@ void platform_init_memmap(struct sof *sof) HEAP_SYS_RUNTIME_S_SIZE; sof->memory_map->system_runtime[i].info.free = HEAP_SYS_RUNTIME_S_SIZE; - sof->memory_map->system_runtime[i].caps = SOF_MEM_CAPS_RAM | - SOF_MEM_CAPS_EXT | SOF_MEM_CAPS_CACHE | - SOF_MEM_CAPS_DMA; + sof->memory_map->system_runtime[i].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; } -#if CONFIG_CORE_COUNT > 1 - /* .runtime_shared init */ - sof->memory_map->runtime_shared[0].blocks = ARRAY_SIZE(rt_shared_heap_map); - sof->memory_map->runtime_shared[0].map = uncached_block_map(rt_shared_heap_map); - sof->memory_map->runtime_shared[0].heap = - cache_to_uncache((uintptr_t)&_runtime_shared_heap); - sof->memory_map->runtime_shared[0].size = HEAP_RUNTIME_SHARED_SIZE; - sof->memory_map->runtime_shared[0].info.free = HEAP_RUNTIME_SHARED_SIZE; - sof->memory_map->runtime_shared[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; - - /* .system_shared init */ - sof->memory_map->system_shared[0].heap = cache_to_uncache((uintptr_t)&_system_shared_heap); - sof->memory_map->system_shared[0].size = HEAP_SYSTEM_SHARED_SIZE; - sof->memory_map->system_shared[0].info.free = HEAP_SYSTEM_SHARED_SIZE; - sof->memory_map->system_shared[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; - -#endif - /* .runtime init*/ - sof->memory_map->runtime[0].blocks = ARRAY_SIZE(rt_heap_map); - sof->memory_map->runtime[0].map = uncached_block_map(rt_heap_map); - sof->memory_map->runtime[0].heap = (uintptr_t)&_module_heap; - sof->memory_map->runtime[0].size = HEAP_RUNTIME_SIZE; - sof->memory_map->runtime[0].info.free = HEAP_RUNTIME_SIZE; - sof->memory_map->runtime[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; + sof->memory_map->runtime.blocks = ARRAY_SIZE(rt_heap_map); + sof->memory_map->runtime.map = uncached_block_map(rt_heap_map); + sof->memory_map->runtime.heap = (uintptr_t)&_module_heap; + sof->memory_map->runtime.size = HEAP_RUNTIME_SIZE; + sof->memory_map->runtime.info.free = HEAP_RUNTIME_SIZE; + sof->memory_map->runtime.caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; /* heap buffer init */ sof->memory_map->buffer[0].blocks = ARRAY_SIZE(buf_heap_map); sof->memory_map->buffer[0].map = uncached_block_map(buf_heap_map); - sof->memory_map->buffer[0].heap = (uintptr_t)&_buffer_heap; - sof->memory_map->buffer[0].size = HEAP_BUFFER_SIZE; - sof->memory_map->buffer[0].info.free = HEAP_BUFFER_SIZE; + sof->memory_map->buffer[0].heap = cache_to_uncache((uintptr_t)&_buffer_heap); + sof->memory_map->buffer[0].size = heap_buffer_size; + sof->memory_map->buffer[0].info.free = heap_buffer_size; sof->memory_map->buffer[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | - SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; +#if PLATFORM_HEAP_BUFFER >= 2 /* heap lp buffer init */ sof->memory_map->buffer[1].blocks = ARRAY_SIZE(lp_buf_heap_map); sof->memory_map->buffer[1].map = uncached_block_map(lp_buf_heap_map); - sof->memory_map->buffer[1].heap = HEAP_LP_BUFFER_BASE; + sof->memory_map->buffer[1].heap = cache_to_uncache((uintptr_t)HEAP_LP_BUFFER_BASE); sof->memory_map->buffer[1].size = HEAP_LP_BUFFER_SIZE; sof->memory_map->buffer[1].info.free = HEAP_LP_BUFFER_SIZE; sof->memory_map->buffer[1].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_LP | - SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; - + SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; +#endif /* .total init */ sof->memory_map->total.free = HEAP_SYSTEM_T_SIZE + - HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + HEAP_BUFFER_SIZE + + HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + heap_buffer_size + HEAP_LP_BUFFER_SIZE; } diff --git a/src/platform/intel/cavs/lib/pm_runtime.c b/src/platform/intel/cavs/lib/pm_runtime.c index 957e484ec2f9..419ece3993dd 100644 --- a/src/platform/intel/cavs/lib/pm_runtime.c +++ b/src/platform/intel/cavs/lib/pm_runtime.c @@ -471,7 +471,7 @@ void platform_pm_runtime_init(struct pm_runtime_data *prd) { struct cavs_pm_runtime_data *pprd; - pprd = rzalloc(SOF_MEM_ZONE_SYS_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*pprd)); + pprd = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*pprd)); prd->platform_data = pprd; } diff --git a/src/platform/library/include/platform/lib/memory.h b/src/platform/library/include/platform/lib/memory.h index 60963682604d..a5dc0adc424d 100644 --- a/src/platform/library/include/platform/lib/memory.h +++ b/src/platform/library/include/platform/lib/memory.h @@ -17,19 +17,13 @@ struct sof; #define PLATFORM_DCACHE_ALIGN sizeof(void *) -#define HEAP_BUFFER_SIZE (1024 * 128) #define SOF_STACK_SIZE 0x1000 uint8_t *get_library_mailbox(void); #define MAILBOX_BASE get_library_mailbox() -#define PLATFORM_HEAP_SYSTEM 2 -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT -#define PLATFORM_HEAP_RUNTIME 1 #define PLATFORM_HEAP_BUFFER 2 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 #define SHARED_DATA @@ -66,10 +60,12 @@ static inline uint32_t arch_get_stack_size(void) #define SRAM_BANK_SIZE 0x10000 #define LP_SRAM_SIZE SRAM_BANK_SIZE -#define HP_SRAM_SIZE SRAM_BANK_SIZE +#define HP_SRAM_SIZE (SRAM_BANK_SIZE * 47) -#define HP_SRAM_BASE 0 -#define LP_SRAM_BASE 0 +#define HP_SRAM_BASE 0xBE000000 +#define LP_SRAM_BASE 0xBE800000 + +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) /* Heap section sizes for system runtime heap for primary core */ #define HEAP_SYS_RT_0_COUNT64 128 @@ -82,41 +78,26 @@ static inline uint32_t arch_get_stack_size(void) #define HEAP_SYS_RT_X_COUNT1024 4 /* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 128 -#define HEAP_RT_COUNT128 64 -#define HEAP_RT_COUNT256 128 -#define HEAP_RT_COUNT512 8 -#define HEAP_RT_COUNT1024 4 -#define HEAP_RT_COUNT2048 1 -#define HEAP_RT_COUNT4096 1 +#define HEAP_COUNT64 128 +#define HEAP_COUNT128 64 +#define HEAP_COUNT256 128 +#define HEAP_COUNT512 8 +#define HEAP_COUNT1024 4 +#define HEAP_COUNT2048 1 +#define HEAP_COUNT4096 1 /* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (64 + 32 * CONFIG_CORE_COUNT) -#define HEAP_RUNTIME_SHARED_COUNT128 64 -#define HEAP_RUNTIME_SHARED_COUNT256 4 -#define HEAP_RUNTIME_SHARED_COUNT512 16 -#define HEAP_RUNTIME_SHARED_COUNT1024 4 - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) -#define HEAP_SYSTEM_M_SIZE 0x8000 /* heap primary core size */ -#define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ +#define HEAP_SYSTEM_M_SIZE 0x4000 /* heap primary core size */ +#define HEAP_SYSTEM_S_SIZE 0x3000 /* heap secondary core size */ #define HEAP_SYSTEM_T_SIZE \ (HEAP_SYSTEM_M_SIZE + ((CONFIG_CORE_COUNT - 1) * HEAP_SYSTEM_S_SIZE)) diff --git a/src/platform/library/lib/memory.c b/src/platform/library/lib/memory.c index e3c518d33463..889e8177ace9 100644 --- a/src/platform/library/lib/memory.c +++ b/src/platform/library/lib/memory.c @@ -19,6 +19,13 @@ #define uncached_block_hdr(hdr) cache_to_uncache_init((struct block_hdr *)(hdr)) #define uncached_block_map(map) cache_to_uncache((struct block_map *)(map)) +/* Memory mock for memmap */ +#define HEAP_SYSTEM_0_BASE 0xBE100000 +#define HEAP_SYS_RUNTIME_0_BASE 0xBE120000 +#define SOF_CORE_S_START 0xBE140000 +#define HEAP_RUNTIME_BASE 0xBE180000 +#define HEAP_BUFFER_BASE 0xBE1C0000 + /* Heap blocks for system runtime for primary core */ static SHARED_DATA struct block_hdr sys_rt_0_block64[HEAP_SYS_RT_0_COUNT64]; static SHARED_DATA struct block_hdr sys_rt_0_block512[HEAP_SYS_RT_0_COUNT512]; @@ -69,50 +76,32 @@ static SHARED_DATA struct block_map sys_rt_heap_map[CONFIG_CORE_COUNT][3] = { }; /* Heap blocks for modules */ -static SHARED_DATA struct block_hdr mod_block64[HEAP_RT_COUNT64]; -static SHARED_DATA struct block_hdr mod_block128[HEAP_RT_COUNT128]; -static SHARED_DATA struct block_hdr mod_block256[HEAP_RT_COUNT256]; -static SHARED_DATA struct block_hdr mod_block512[HEAP_RT_COUNT512]; -static SHARED_DATA struct block_hdr mod_block1024[HEAP_RT_COUNT1024]; -static SHARED_DATA struct block_hdr mod_block2048[HEAP_RT_COUNT2048]; -static SHARED_DATA struct block_hdr mod_block4096[HEAP_RT_COUNT4096]; +static SHARED_DATA struct block_hdr mod_block64[HEAP_COUNT64]; +static SHARED_DATA struct block_hdr mod_block128[HEAP_COUNT128]; +static SHARED_DATA struct block_hdr mod_block256[HEAP_COUNT256]; +static SHARED_DATA struct block_hdr mod_block512[HEAP_COUNT512]; +static SHARED_DATA struct block_hdr mod_block1024[HEAP_COUNT1024]; +static SHARED_DATA struct block_hdr mod_block2048[HEAP_COUNT2048]; +static SHARED_DATA struct block_hdr mod_block4096[HEAP_COUNT4096]; /* Heap memory map for modules */ static SHARED_DATA struct block_map rt_heap_map[] = { - BLOCK_DEF(64, HEAP_RT_COUNT64, uncached_block_hdr(mod_block64)), - BLOCK_DEF(128, HEAP_RT_COUNT128, uncached_block_hdr(mod_block128)), - BLOCK_DEF(256, HEAP_RT_COUNT256, uncached_block_hdr(mod_block256)), - BLOCK_DEF(512, HEAP_RT_COUNT512, uncached_block_hdr(mod_block512)), - BLOCK_DEF(1024, HEAP_RT_COUNT1024, uncached_block_hdr(mod_block1024)), - BLOCK_DEF(2048, HEAP_RT_COUNT2048, uncached_block_hdr(mod_block2048)), - BLOCK_DEF(4096, HEAP_RT_COUNT4096, uncached_block_hdr(mod_block4096)), -}; - -#if CONFIG_CORE_COUNT > 1 -/* Heap blocks for runtime shared */ -static SHARED_DATA struct block_hdr rt_shared_block64[HEAP_RUNTIME_SHARED_COUNT64]; -static SHARED_DATA struct block_hdr rt_shared_block128[HEAP_RUNTIME_SHARED_COUNT128]; -static SHARED_DATA struct block_hdr rt_shared_block256[HEAP_RUNTIME_SHARED_COUNT256]; -static SHARED_DATA struct block_hdr rt_shared_block512[HEAP_RUNTIME_SHARED_COUNT512]; -static SHARED_DATA struct block_hdr rt_shared_block1024[HEAP_RUNTIME_SHARED_COUNT1024]; - -/* Heap memory map for runtime shared */ -static SHARED_DATA struct block_map rt_shared_heap_map[] = { - BLOCK_DEF(64, HEAP_RUNTIME_SHARED_COUNT64, uncached_block_hdr(rt_shared_block64)), - BLOCK_DEF(128, HEAP_RUNTIME_SHARED_COUNT128, uncached_block_hdr(rt_shared_block128)), - BLOCK_DEF(256, HEAP_RUNTIME_SHARED_COUNT256, uncached_block_hdr(rt_shared_block256)), - BLOCK_DEF(512, HEAP_RUNTIME_SHARED_COUNT512, uncached_block_hdr(rt_shared_block512)), - BLOCK_DEF(1024, HEAP_RUNTIME_SHARED_COUNT1024, uncached_block_hdr(rt_shared_block1024)), + BLOCK_DEF(64, HEAP_COUNT64, uncached_block_hdr(mod_block64)), + BLOCK_DEF(128, HEAP_COUNT128, uncached_block_hdr(mod_block128)), + BLOCK_DEF(256, HEAP_COUNT256, uncached_block_hdr(mod_block256)), + BLOCK_DEF(512, HEAP_COUNT512, uncached_block_hdr(mod_block512)), + BLOCK_DEF(1024, HEAP_COUNT1024, uncached_block_hdr(mod_block1024)), + BLOCK_DEF(2048, HEAP_COUNT2048, uncached_block_hdr(mod_block2048)), + BLOCK_DEF(4096, HEAP_COUNT4096, uncached_block_hdr(mod_block4096)), }; -#endif /* Heap blocks for buffers */ -static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT]; +static SHARED_DATA struct block_hdr buf_block[HEAP_BUFFER_COUNT_MAX]; static SHARED_DATA struct block_hdr lp_buf_block[HEAP_LP_BUFFER_COUNT]; /* Heap memory map for buffers */ static SHARED_DATA struct block_map buf_heap_map[] = { - BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT, + BLOCK_DEF(HEAP_BUFFER_BLOCK_SIZE, HEAP_BUFFER_COUNT_MAX, uncached_block_hdr(buf_block)), }; @@ -125,8 +114,26 @@ static SHARED_DATA struct mm memmap; void platform_init_memmap(struct sof *sof) { + uint32_t heap_buffer_size = SOF_FW_END - HEAP_BUFFER_BASE; + uint32_t buffer_count; int i; + /* calculate the buffer heap size */ + buffer_count = heap_buffer_size / HEAP_BUFFER_BLOCK_SIZE; + heap_buffer_size = buffer_count * HEAP_BUFFER_BLOCK_SIZE; + + for (i = 0; i < ARRAY_SIZE(buf_heap_map); i++) { + buf_heap_map[i].count = buffer_count; + buf_heap_map[i].free_count = buffer_count; + } + dcache_writeback_region(buf_heap_map, + sizeof(struct block_map) * ARRAY_SIZE(buf_heap_map)); + + /* + * by default, use cached address for system and runtime zones, + * and uncached address for system_runtime and buffer zones. + */ + /* access memory map through uncached region */ sof->memory_map = cache_to_uncache(&memmap); @@ -178,42 +185,21 @@ void platform_init_memmap(struct sof *sof) SOF_MEM_CAPS_DMA; } -#if CONFIG_CORE_COUNT > 1 - /* .runtime_shared init */ - sof->memory_map->runtime_shared[0].blocks = ARRAY_SIZE(rt_shared_heap_map); - sof->memory_map->runtime_shared[0].map = uncached_block_map(rt_shared_heap_map); - sof->memory_map->runtime_shared[0].heap = - (unsigned long)cache_to_uncache(malloc(HEAP_RUNTIME_SHARED_SIZE)); - sof->memory_map->runtime_shared[0].size = HEAP_RUNTIME_SHARED_SIZE; - sof->memory_map->runtime_shared[0].info.free = HEAP_RUNTIME_SHARED_SIZE; - sof->memory_map->runtime_shared[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; - - /* .system_shared init */ - sof->memory_map->system_shared[0].heap = - (unsigned long)cache_to_uncache(malloc(HEAP_SYSTEM_SHARED_SIZE)); - sof->memory_map->system_shared[0].size = HEAP_SYSTEM_SHARED_SIZE; - sof->memory_map->system_shared[0].info.free = HEAP_SYSTEM_SHARED_SIZE; - sof->memory_map->system_shared[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | - SOF_MEM_CAPS_CACHE; - -#endif - /* .runtime init*/ - sof->memory_map->runtime[0].blocks = ARRAY_SIZE(rt_heap_map); - sof->memory_map->runtime[0].map = uncached_block_map(rt_heap_map); - sof->memory_map->runtime[0].heap = (unsigned long)malloc(HEAP_RUNTIME_SIZE); - sof->memory_map->runtime[0].size = HEAP_RUNTIME_SIZE; - sof->memory_map->runtime[0].info.free = HEAP_RUNTIME_SIZE; - sof->memory_map->runtime[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | + sof->memory_map->runtime.blocks = ARRAY_SIZE(rt_heap_map); + sof->memory_map->runtime.map = uncached_block_map(rt_heap_map); + sof->memory_map->runtime.heap = (unsigned long)malloc(HEAP_RUNTIME_SIZE); + sof->memory_map->runtime.size = HEAP_RUNTIME_SIZE; + sof->memory_map->runtime.info.free = HEAP_RUNTIME_SIZE; + sof->memory_map->runtime.caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_EXT | SOF_MEM_CAPS_CACHE; /* heap buffer init */ sof->memory_map->buffer[0].blocks = ARRAY_SIZE(buf_heap_map); sof->memory_map->buffer[0].map = uncached_block_map(buf_heap_map); - sof->memory_map->buffer[0].heap = (unsigned long)malloc(HEAP_BUFFER_SIZE); - sof->memory_map->buffer[0].size = HEAP_BUFFER_SIZE; - sof->memory_map->buffer[0].info.free = HEAP_BUFFER_SIZE; + sof->memory_map->buffer[0].heap = (unsigned long)malloc(heap_buffer_size); + sof->memory_map->buffer[0].size = heap_buffer_size; + sof->memory_map->buffer[0].info.free = heap_buffer_size; sof->memory_map->buffer[0].caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | SOF_MEM_CAPS_CACHE | SOF_MEM_CAPS_DMA; @@ -228,7 +214,7 @@ void platform_init_memmap(struct sof *sof) /* .total init */ sof->memory_map->total.free = HEAP_SYSTEM_T_SIZE + - HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + HEAP_BUFFER_SIZE + + HEAP_SYS_RUNTIME_T_SIZE + HEAP_RUNTIME_SIZE + heap_buffer_size + HEAP_LP_BUFFER_SIZE; } diff --git a/src/platform/suecreek/include/platform/lib/memory.h b/src/platform/suecreek/include/platform/lib/memory.h index c056e8a22851..c29e01feadc0 100644 --- a/src/platform/suecreek/include/platform/lib/memory.h +++ b/src/platform/suecreek/include/platform/lib/memory.h @@ -163,17 +163,9 @@ * +------------------+-------------------------+-----------------------------+ * | SOF_FW_START | text | | * | | data | | - * | | ----------------------- | | + * | |+-----------------------+| | * | ||BSS: || | * | ||-----------------------++-----------------------------+ - * | ||Runtime Heap || HEAP_RUNTIME_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Runtime shared Heap || HEAP_RUNTIME_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||System shared Heap || HEAP_SYSTEM_SHARED_SIZE | - * | ||-----------------------++-----------------------------+ - * | ||Module Buffers || HEAP_BUFFER_SIZE | - * | ||-----------------------++-----------------------------+ * | ||Primary core Sys Heap || HEAP_SYSTEM_M_SIZE | * | ||-----------------------++-----------------------------+ * | ||Pri. Sys Runtime Heap || HEAP_SYS_RUNTIME_M_SIZE | @@ -183,7 +175,11 @@ * | ||Sec. core Sys Heap || SOF_CORE_S_T_SIZE | * | ||Sec. Sys Runtime Heap || | * | ||Secondary core Stack || | - * | | ----------------------- | | + * | ||-----------------------++-----------------------------+ + * | ||Runtime Heap || HEAP_RUNTIME_SIZE | + * | ||-----------------------++-----------------------------+ + * | ||Module Buffers || HEAP_BUFFER_SIZE | + * | |+-----------------------+| | * +------------------+-------------------------+-----------------------------+ */ @@ -236,6 +232,8 @@ /* max size for all var-size sections (text/rodata/bss) */ #define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE) +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) + /* Heap section sizes for system runtime heap for core */ #define HEAP_SYS_RT_0_COUNT64 64 #define HEAP_SYS_RT_0_COUNT512 16 @@ -246,40 +244,23 @@ #define HEAP_SYS_RT_X_COUNT512 8 #define HEAP_SYS_RT_X_COUNT1024 4 -/* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 192 -#define HEAP_RT_COUNT128 32 -#define HEAP_RT_COUNT256 80 -#define HEAP_RT_COUNT512 8 -#define HEAP_RT_COUNT1024 4 -#define HEAP_RT_COUNT2048 1 -#define HEAP_RT_COUNT4096 1 +/* Heap runtime block counts */ +#define HEAP_COUNT64 128 +#define HEAP_COUNT128 128 +#define HEAP_COUNT256 96 +#define HEAP_COUNT512 8 +#define HEAP_COUNT1024 4 +#define HEAP_COUNT2048 2 +#define HEAP_COUNT4096 1 -/* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (64 + 32 * CONFIG_CORE_COUNT) -#define HEAP_RUNTIME_SHARED_COUNT128 64 -#define HEAP_RUNTIME_SHARED_COUNT256 4 -#define HEAP_RUNTIME_SHARED_COUNT512 16 -#define HEAP_RUNTIME_SHARED_COUNT1024 4 - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 - -#define HEAP_BUFFER_SIZE 0x10000 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) + #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) #define HEAP_SYSTEM_M_SIZE 0x8000 /* heap core size */ #define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ @@ -371,11 +352,6 @@ #define HEAP_LP_BUFFER_COUNT 0 #endif -#define PLATFORM_HEAP_SYSTEM CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 #define PLATFORM_HEAP_BUFFER 2 /* Stack configuration */ diff --git a/src/platform/suecreek/suecreek.x.in b/src/platform/suecreek/suecreek.x.in index 8ce69243549c..20216eb11a6b 100644 --- a/src/platform/suecreek/suecreek.x.in +++ b/src/platform/suecreek/suecreek.x.in @@ -453,16 +453,6 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) - . = ALIGN (SRAM_BANK_SIZE); - _runtime_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SIZE; - _runtime_heap_end = ABSOLUTE(.); - - . = ALIGN (HEAP_BUF_ALIGNMENT); - _buffer_heap_start = ABSOLUTE(.); - . = . + HEAP_BUFFER_SIZE; - _buffer_heap_end = ABSOLUTE(.); - . = ALIGN (SRAM_BANK_SIZE); _system_heap_start = ABSOLUTE(.); . = . + HEAP_SYSTEM_M_SIZE; @@ -473,27 +463,26 @@ SECTIONS . = . + HEAP_SYS_RUNTIME_M_SIZE; _system_runtime_heap_end = ABSOLUTE(.); - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_end = ABSOLUTE(.); - - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_SYSTEM_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_end = ABSOLUTE(.); - . = ALIGN (4096); _sof_stack_start = ABSOLUTE(.); . = . + SOF_STACK_SIZE; _sof_stack_end = ABSOLUTE(.); +#if CONFIG_CORE_COUNT > 1 . = ALIGN (SRAM_BANK_SIZE); _sof_core_s_start = ABSOLUTE(.); . = . + SOF_CORE_S_T_SIZE; _sof_core_s_end = ABSOLUTE(.); +#endif + . = ALIGN (SRAM_BANK_SIZE); + _runtime_heap_start = ABSOLUTE(.); + . = . + HEAP_RUNTIME_SIZE; + _runtime_heap_end = ABSOLUTE(.); + + . = ALIGN (PLATFORM_DCACHE_ALIGN); + _buffer_heap_start = ABSOLUTE(.); + . = . + SOF_FW_END - _buffer_heap_start; + _buffer_heap_end = ABSOLUTE(.); _bss_end = ABSOLUTE(.); } >sof_fw :sof_fw_phdr @@ -513,10 +502,6 @@ SECTIONS /* system runtime heap */ _system_runtime_heap = _system_runtime_heap_start; - /* Shared Heap */ - _runtime_shared_heap = _runtime_shared_heap_start; - _system_shared_heap = _system_shared_heap_start; - /* module heap */ _module_heap = _runtime_heap_start; diff --git a/src/platform/tigerlake/include/platform/lib/memory.h b/src/platform/tigerlake/include/platform/lib/memory.h index a64f0cf63f2e..d9964adf485e 100644 --- a/src/platform/tigerlake/include/platform/lib/memory.h +++ b/src/platform/tigerlake/include/platform/lib/memory.h @@ -158,14 +158,6 @@ * | | data | | * | | BSS | | * +--------------------+-------------------------+-----------------------------+ - * | | Runtime Heap | HEAP_RUNTIME_SIZE | - * +--------------------+-------------------------+-----------------------------+ - * | | Runtime shared Heap | HEAP_RUNTIME_SHARED_SIZE | - * | |-------------------------+-----------------------------+ - * | | System shared Heap | HEAP_SYSTEM_SHARED_SIZE | - * | |-------------------------+-----------------------------+ - * | | Module Buffers | HEAP_BUFFER_SIZE | - * +--------------------+-------------------------+-----------------------------+ * | | Primary core Sys Heap | HEAP_SYSTEM_M_SIZE | * +--------------------+-------------------------+-----------------------------+ * | | Pri. Sys Runtime Heap | HEAP_SYS_RUNTIME_M_SIZE | @@ -176,6 +168,10 @@ * | | Sec. Sys Runtime Heap | | * | | Secondary core Stack | | * +--------------------+-------------------------+-----------------------------+ + * | | Runtime Heap | HEAP_RUNTIME_SIZE | + * +--------------------+-------------------------+-----------------------------+ + * | | Module Buffers | HEAP_BUFFER_SIZE | + * +--------------------+-------------------------+-----------------------------+ */ /* HP SRAM */ @@ -236,6 +232,8 @@ /* max size for all var-size sections (text/rodata/bss) */ #define SOF_FW_MAX_SIZE (HP_SRAM_BASE + HP_SRAM_SIZE - SOF_FW_BASE) +#define SOF_FW_END (HP_SRAM_BASE + HP_SRAM_SIZE) + #define SOF_TEXT_START (SOF_FW_START) #define SOF_TEXT_BASE (SOF_FW_START) @@ -249,7 +247,7 @@ #define HEAP_SYS_RT_X_COUNT512 8 #define HEAP_SYS_RT_X_COUNT1024 4 -/* Heap section counts base */ +/* Heap runtime block counts */ #define HEAP_COUNT64 128 #define HEAP_COUNT128 128 #define HEAP_COUNT256 96 @@ -258,53 +256,14 @@ #define HEAP_COUNT2048 2 #define HEAP_COUNT4096 1 -#if HP_SRAM_SIZE < 0x200000 -#define RT_TIMES 3 -#define RT_SHARED_TIMES 6 -#else -#ifdef CONFIG_COMP_RTNR -#define RT_TIMES 6 -#define RT_SHARED_TIMES 11 -#else -#define RT_TIMES 8 -#define RT_SHARED_TIMES 16 -#endif /* CONFIG_COMP_RTNR */ -#endif - -/* Heap section sizes for module pool */ -#define HEAP_RT_COUNT64 (HEAP_COUNT64 * RT_TIMES) -#define HEAP_RT_COUNT128 (HEAP_COUNT128 * RT_TIMES) -#define HEAP_RT_COUNT256 (HEAP_COUNT256 * RT_TIMES) -#define HEAP_RT_COUNT512 (HEAP_COUNT512 * RT_TIMES) -#define HEAP_RT_COUNT1024 (HEAP_COUNT1024 * RT_TIMES) -#define HEAP_RT_COUNT2048 (HEAP_COUNT2048 * RT_TIMES) -#define HEAP_RT_COUNT4096 (HEAP_COUNT4096 * RT_TIMES) - -/* Heap configuration */ #define HEAP_RUNTIME_SIZE \ - (HEAP_RT_COUNT64 * 64 + HEAP_RT_COUNT128 * 128 + \ - HEAP_RT_COUNT256 * 256 + HEAP_RT_COUNT512 * 512 + \ - HEAP_RT_COUNT1024 * 1024 + HEAP_RT_COUNT2048 * 2048 + \ - HEAP_RT_COUNT4096 * 4096) - -/* Heap section sizes for runtime shared heap */ -#define HEAP_RUNTIME_SHARED_COUNT64 (HEAP_COUNT64 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT128 (HEAP_COUNT128 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT256 (HEAP_COUNT256 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT512 (HEAP_COUNT512 * RT_SHARED_TIMES) -#define HEAP_RUNTIME_SHARED_COUNT1024 (HEAP_COUNT1024 * RT_SHARED_TIMES) - -#define HEAP_RUNTIME_SHARED_SIZE \ - (HEAP_RUNTIME_SHARED_COUNT64 * 64 + HEAP_RUNTIME_SHARED_COUNT128 * 128 + \ - HEAP_RUNTIME_SHARED_COUNT256 * 256 + HEAP_RUNTIME_SHARED_COUNT512 * 512 + \ - HEAP_RUNTIME_SHARED_COUNT1024 * 1024) - -/* Heap section sizes for system shared heap */ -#define HEAP_SYSTEM_SHARED_SIZE 0x1500 - -#define HEAP_BUFFER_SIZE 0x80000 + (HEAP_COUNT64 * 64 + HEAP_COUNT128 * 128 + \ + HEAP_COUNT256 * 256 + HEAP_COUNT512 * 512 + \ + HEAP_COUNT1024 * 1024 + HEAP_COUNT2048 * 2048 + \ + HEAP_COUNT4096 * 4096) + #define HEAP_BUFFER_BLOCK_SIZE 0x100 -#define HEAP_BUFFER_COUNT (HEAP_BUFFER_SIZE / HEAP_BUFFER_BLOCK_SIZE) +#define HEAP_BUFFER_COUNT_MAX (HP_SRAM_SIZE / HEAP_BUFFER_BLOCK_SIZE) #define HEAP_SYSTEM_M_SIZE 0x8000 /* heap primary core size */ #define HEAP_SYSTEM_S_SIZE 0x6000 /* heap secondary core size */ @@ -397,11 +356,6 @@ #define HEAP_LP_BUFFER_COUNT 0 #endif -#define PLATFORM_HEAP_SYSTEM CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_SYSTEM_RUNTIME CONFIG_CORE_COUNT /* one per core */ -#define PLATFORM_HEAP_RUNTIME 1 -#define PLATFORM_HEAP_RUNTIME_SHARED 1 -#define PLATFORM_HEAP_SYSTEM_SHARED 1 #define PLATFORM_HEAP_BUFFER 2 /* Stack configuration */ diff --git a/src/platform/tigerlake/tigerlake.x.in b/src/platform/tigerlake/tigerlake.x.in index 0317b5d51132..3227cdbc26db 100644 --- a/src/platform/tigerlake/tigerlake.x.in +++ b/src/platform/tigerlake/tigerlake.x.in @@ -529,16 +529,6 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) - . = ALIGN (SRAM_BANK_SIZE); - _runtime_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SIZE; - _runtime_heap_end = ABSOLUTE(.); - - . = ALIGN (HEAP_BUF_ALIGNMENT); - _buffer_heap_start = ABSOLUTE(.); - . = . + HEAP_BUFFER_SIZE; - _buffer_heap_end = ABSOLUTE(.); - . = ALIGN (SRAM_BANK_SIZE); _system_heap_start = ABSOLUTE(.); . = . + HEAP_SYSTEM_M_SIZE; @@ -549,27 +539,26 @@ SECTIONS . = . + HEAP_SYS_RUNTIME_M_SIZE; _system_runtime_heap_end = ABSOLUTE(.); - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_RUNTIME_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _runtime_shared_heap_end = ABSOLUTE(.); - - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_start = ABSOLUTE(.); - . = . + HEAP_SYSTEM_SHARED_SIZE; - . = ALIGN (PLATFORM_DCACHE_ALIGN); - _system_shared_heap_end = ABSOLUTE(.); - . = ALIGN (4096); _sof_stack_start = ABSOLUTE(.); . = . + SOF_STACK_SIZE; _sof_stack_end = ABSOLUTE(.); +#if CONFIG_CORE_COUNT > 1 . = ALIGN (SRAM_BANK_SIZE); _sof_core_s_start = ABSOLUTE(.); . = . + SOF_CORE_S_T_SIZE; _sof_core_s_end = ABSOLUTE(.); +#endif + . = ALIGN (SRAM_BANK_SIZE); + _runtime_heap_start = ABSOLUTE(.); + . = . + HEAP_RUNTIME_SIZE; + _runtime_heap_end = ABSOLUTE(.); + + . = ALIGN (PLATFORM_DCACHE_ALIGN); + _buffer_heap_start = ABSOLUTE(.); + . = . + SOF_FW_END - _buffer_heap_start; + _buffer_heap_end = ABSOLUTE(.); _bss_end = ABSOLUTE(.); } >sof_fw :sof_fw_phdr @@ -589,10 +578,6 @@ SECTIONS /* system runtime heap */ _system_runtime_heap = _system_runtime_heap_start; - /* Shared Heap */ - _runtime_shared_heap = _runtime_shared_heap_start; - _system_shared_heap = _system_shared_heap_start; - /* module heap */ _module_heap = _runtime_heap_start; diff --git a/src/schedule/dma_multi_chan_domain.c b/src/schedule/dma_multi_chan_domain.c index 33f9cb463e2d..8fd48e669e23 100644 --- a/src/schedule/dma_multi_chan_domain.c +++ b/src/schedule/dma_multi_chan_domain.c @@ -363,7 +363,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, 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 1d07867ce676..425ac6a31c55 100644 --- a/src/schedule/dma_single_chan_domain.c +++ b/src/schedule/dma_single_chan_domain.c @@ -542,7 +542,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, 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/timer_domain.c b/src/schedule/timer_domain.c index 48c7862033b4..b6798d075269 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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*timer_domain)); timer_domain->timer = timer; ll_sch_domain_set_pdata(domain, timer_domain); diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index 8381ca15b359..64d208cff0c4 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -227,8 +227,7 @@ struct ll_schedule_domain *zephyr_domain_init(struct timer *timer, 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, - sizeof(*zephyr_domain)); + zephyr_domain = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*zephyr_domain)); zephyr_domain->ll_timer = timer; zephyr_domain->ll_domain = domain; diff --git a/src/trace/dma-trace.c b/src/trace/dma-trace.c index 779480e49468..d18eaae6c399 100644 --- a/src/trace/dma-trace.c +++ b/src/trace/dma-trace.c @@ -137,7 +137,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sof->dmat)); dma_sg_init(&sof->dmat->config.elem_array); spinlock_init(&sof->dmat->lock); diff --git a/src/trace/trace.c b/src/trace/trace.c index fb21dc5ce229..32879d344f09 100644 --- a/src/trace/trace.c +++ b/src/trace/trace.c @@ -509,7 +509,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 = rballoc(SOF_MEM_FLAG_COHERENT, SOF_MEM_CAPS_RAM, sizeof(*sof->trace)); sof->trace->pos = 0; #if CONFIG_TRACE_FILTERING_ADAPTIVE sof->trace->user_filter_override = false; diff --git a/test/cmocka/include/mock_memory.h b/test/cmocka/include/mock_memory.h index 54db9ba06990..daa7b2e43781 100644 --- a/test/cmocka/include/mock_memory.h +++ b/test/cmocka/include/mock_memory.h @@ -6,10 +6,8 @@ */ /* Memory mock for memmap */ -#define HEAP_RUNTIME_BASE 0xBE200000 -#define HEAP_BUFFER_BASE 0xBE2F0000 -#define HEAP_SYSTEM_0_BASE 0xBE30F000 -#define HEAP_SYS_RUNTIME_0_BASE 0xBE32F000 -#define SOF_CORE_S_START 0xBE390000 -#define HEAP_RUNTIME_SHARED_BASE 0xBE3A0000 -#define HEAP_SYSTEM_SHARED_BASE 0xBE3B0000 +#define HEAP_SYSTEM_0_BASE 0xBE100000 +#define HEAP_SYS_RUNTIME_0_BASE 0xBE120000 +#define SOF_CORE_S_START 0xBE140000 +#define HEAP_RUNTIME_BASE 0xBE180000 +#define HEAP_BUFFER_BASE 0xBE1C0000 diff --git a/test/cmocka/memory_mock.x.in b/test/cmocka/memory_mock.x.in index e9f774ede825..60d217f3c56f 100644 --- a/test/cmocka/memory_mock.x.in +++ b/test/cmocka/memory_mock.x.in @@ -14,13 +14,11 @@ SECTIONS _comp_init_start = .; _comp_init_end = .; - _module_heap = HEAP_RUNTIME_BASE; - _buffer_heap = HEAP_BUFFER_BASE; _system_heap = HEAP_SYSTEM_0_BASE; _system_heap_start = HEAP_SYSTEM_0_BASE; _system_runtime_heap = HEAP_SYS_RUNTIME_0_BASE; _sof_core_s_start = SOF_CORE_S_START; - _runtime_shared_heap = HEAP_RUNTIME_SHARED_BASE; - _system_shared_heap = HEAP_SYSTEM_SHARED_BASE; + _module_heap = HEAP_RUNTIME_BASE; + _buffer_heap = HEAP_BUFFER_BASE; } INSERT AFTER .text; diff --git a/test/cmocka/src/common_mocks.c b/test/cmocka/src/common_mocks.c index 45a7190b4148..e2a98f47a6ab 100644 --- a/test/cmocka/src/common_mocks.c +++ b/test/cmocka/src/common_mocks.c @@ -44,7 +44,7 @@ void WEAK *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes, (void)flags; (void)caps; - return malloc(bytes); + return calloc(bytes, 1); } void WEAK *rzalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, diff --git a/test/cmocka/src/lib/alloc/alloc.c b/test/cmocka/src/lib/alloc/alloc.c index 3553ab8b9199..16a472c7f32e 100644 --- a/test/cmocka/src/lib/alloc/alloc.c +++ b/test/cmocka/src/lib/alloc/alloc.c @@ -65,8 +65,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 256, TEST_BULK, - "rmalloc"), /* * TODO: Due to recent changes in relation to multicore support @@ -96,8 +94,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_BULK, "rmalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 256, TEST_BULK, - "rmalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, 2, TEST_BULK, "rmalloc_dma"), @@ -133,8 +129,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_SYS, SOF_MEM_CAPS_RAM, 256, TEST_ZERO, - "rzalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 2, TEST_ZERO, "rzalloc"), @@ -159,8 +153,6 @@ static struct test_case test_cases[] = { TEST_CASE(16, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 128, TEST_ZERO, "rzalloc"), - TEST_CASE(4, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM, 256, TEST_ZERO, - "rzalloc"), TEST_CASE(1, SOF_MEM_ZONE_RUNTIME, SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_DMA, 2, TEST_ZERO, "rzalloc_dma"), diff --git a/zephyr/wrapper.c b/zephyr/wrapper.c index e99ee5c8a716..48086a9141f8 100644 --- a/zephyr/wrapper.c +++ b/zephyr/wrapper.c @@ -72,18 +72,33 @@ __section(".heap_mem") static uint8_t __aligned(64) heapmem[HEAPMEM_SIZE]; #else -#define HEAPMEM_SHARED_SIZE (HEAP_SYSTEM_SIZE + HEAP_RUNTIME_SIZE + \ - HEAP_RUNTIME_SHARED_SIZE + HEAP_SYSTEM_SHARED_SIZE) +/* TODO: heap size should be set based on linker output */ +#if (CONFIG_HP_MEMORY_BANKS < 16) +/* e.g. APL */ +#define HEAP_SIZE 0x30000 +#elif (CONFIG_HP_MEMORY_BANKS < 30) +/* e.g. JSL */ +#define HEAP_SIZE 0x80000 +#elif (CONFIG_HP_MEMORY_BANKS < 45) +/* e.g. TGL-H */ +#define HEAP_SIZE 0x100000 +#else +/* e.g. CNL/ICL/TGL */ +#define HEAP_SIZE 0x200000 +#endif + #ifdef ENABLE_CACHED_HEAP -#define HEAPMEM_SIZE HEAP_BUFFER_SIZE +/* hard code the cached portion at the moment */ +#define HEAP_SYSTEM_CACHED_SIZE (HEAP_SIZE / 2) #else -#define HEAPMEM_SIZE (HEAP_BUFFER_SIZE + HEAPMEM_SHARED_SIZE) +#define HEAP_SYSTEM_CACHED_SIZE 0 #endif +#define HEAPMEM_SIZE (HEAP_SIZE - HEAP_SYSTEM_CACHED_SIZE) static uint8_t __aligned(PLATFORM_DCACHE_ALIGN)heapmem[HEAPMEM_SIZE]; #ifdef ENABLE_CACHED_HEAP -static uint8_t __aligned(PLATFORM_DCACHE_ALIGN)heapmem_shared[HEAPMEM_SHARED_SIZE]; -static struct k_heap sof_heap_shared; +static uint8_t __aligned(PLATFORM_DCACHE_ALIGN)heapmem_cached[HEAP_SYSTEM_CACHED_SIZE]; +static struct k_heap sof_heap_cached; #endif #endif @@ -96,7 +111,7 @@ static int statics_init(const struct device *unused) sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE); #ifdef ENABLE_CACHED_HEAP - sys_heap_init(&sof_heap_shared.heap, heapmem_shared, HEAPMEM_SHARED_SIZE); + sys_heap_init(&sof_heap_cached.heap, heapmem_cached, HEAP_SYSTEM_CACHED_SIZE); #endif return 0; }