Skip to content

Commit

Permalink
module: fix cache synchronisation
Browse files Browse the repository at this point in the history
Buffers, where modules are stored originally, don't need their caches
to be synchronised - they're only used as a data storage and only
accessed via cached aliases. But when final buffers are allocated,
from which modules are actually run, those buffers do indeed need
cache synchronisation.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh committed Jan 19, 2024
1 parent bd9a877 commit cb81f84
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,8 @@ static int lib_manager_load_data_from_storage(void __sparse_cache *vma, void *s_
return ret;
}

ret = memcpy_s((__sparse_force void *)vma, size, s_addr, size);
if (ret < 0)
return ret;

/* Some data can be accessed as uncached, in fact that's the default */
/* Both D- and I-caches have been invalidated */
dcache_writeback_region(vma, size);

/* TODO: Change attributes for memory to FLAGS */
return 0;
return memcpy_s((__sparse_force void *)vma, size, s_addr, size);
}

static int lib_manager_load_module(uint32_t module_id, struct sof_man_module *mod,
Expand Down Expand Up @@ -212,12 +204,19 @@ static int lib_manager_load_module(uint32_t module_id, struct sof_man_module *mo
if (ret < 0)
return ret;

/* .text contains instructions and it also often contains local data */
dcache_writeback_region(va_base_text, st_text_size);
icache_invalidate_region(va_base_text, st_text_size);

/* Copy RODATA */
ret = lib_manager_load_data_from_storage(va_base_rodata, src_rodata,
st_rodata_size, SYS_MM_MEM_PERM_RW);
if (ret < 0)
goto e_text;

/* Some data can be accessed as uncached, in fact that's the default */
dcache_writeback_region(va_base_rodata, st_rodata_size);

if (mod->type.load_type != SOF_MAN_MOD_TYPE_LLEXT) {
ret = lib_manager_load_aux(mod, desc, lib_id);
if (ret < 0)
Expand Down Expand Up @@ -621,9 +620,6 @@ static void __sparse_cache *lib_manager_allocate_store_mem(uint32_t size,
return NULL;
}

dcache_invalidate_region(local_add, size);
icache_invalidate_region(local_add, size);

return local_add;
}

Expand Down

0 comments on commit cb81f84

Please sign in to comment.