Skip to content

Commit b20596b

Browse files
mem: workaround - make SOF working with and without zephyr changes
This commit add creation of virtual memory region for heap Called functions are not yet present in Zephyr (Zephyr is creating regions by itself now), so the commit also contains weaked aliases of zephyr functions. Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent a2a0123 commit b20596b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

zephyr/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
5050
NOTE: Keep in mind that the heap size should not be greater than the physical
5151
memory size of the system defined in DT (and this includes baseFW text/data).
5252

53+
config SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE
54+
hex "Size in bytes of virtual memory region for virtual heap shared for all cores"
55+
depends on MM_DRV_INTEL_ADSP_MTL_TLB
56+
default 0x100000
57+
help
58+
This config defines size of virtual heap region shared between all cores
59+
5360
config ZEPHYR_NATIVE_DRIVERS
5461
bool "Use Zephyr native drivers"
5562
default n

zephyr/include/sof/lib/regions_mm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <zephyr/init.h>
1818
#include <zephyr/sys/mem_blocks.h>
1919

20+
/* Attributes for memory regions */
21+
#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region dedicated for shared virtual heap */
22+
2023
/* Dependency on ipc/topology.h created due to memory capability definitions
2124
* that are defined there
2225
*/

zephyr/lib/alloc.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#include <sof/schedule/schedule.h>
1414
#include <sof/lib/notifier.h>
1515
#include <sof/lib/pm_runtime.h>
16+
#include <sof/lib/regions_mm.h>
1617
#include <sof/audio/pipeline.h>
1718
#include <sof/audio/component_ext.h>
1819
#include <sof/trace/trace.h>
20+
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>
1921
#include <rtos/symbol.h>
2022
#include <rtos/wait.h>
2123

@@ -288,8 +290,39 @@ static const struct vmh_heap_config static_hp_buffers = {
288290
},
289291
};
290292

293+
/* WA Stubs begin
294+
*
295+
* in order to merge a PR that moves initialization of virtual regions from Zephyr to SOF,
296+
* we need to create weak stubs for 2 functions that will need to be called once the PR is merged
297+
*/
298+
299+
__weak
300+
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
301+
{
302+
return 0;
303+
}
304+
305+
__weak
306+
int adsp_add_virtual_memory_region(uintptr_t region_address, uint32_t region_size, uint32_t attr)
307+
{
308+
return 0;
309+
}
310+
/* WA Stubs end */
311+
291312
static int virtual_heap_init(void)
292313
{
314+
int ret;
315+
316+
if (virtual_buffers_heap)
317+
return -EEXIST;
318+
319+
/* add a virtual memory region */
320+
ret = adsp_add_virtual_memory_region(adsp_mm_get_unused_l2_start_aligned(),
321+
CONFIG_SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE,
322+
VIRTUAL_REGION_SHARED_HEAP_ATTR);
323+
if (ret)
324+
return ret;
325+
293326
virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);
294327
if (!virtual_buffers_heap) {
295328
tr_err(&zephyr_tr, "Unable to init virtual heap");

0 commit comments

Comments
 (0)