Skip to content

Commit 4ea7ba7

Browse files
lyakhkv2019i
authored andcommitted
heap: enable saving L3 heap over DSP reset
L3 heap allocates memory in DRAM. Usually this is done to preserve contents over DSP reset. This patch adds a method to do that. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 8bf4167 commit 4ea7ba7

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

posix/include/rtos/alloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ int rstrlen(const char *s);
167167
*/
168168
int rstrcmp(const char *s1, const char *s2);
169169

170+
static inline void l3_heap_save(void) {}
171+
170172
/** @}*/
171173

172174
#endif /* __SOF_LIB_ALLOC_H__ */

xtos/include/rtos/alloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ int rstrlen(const char *s);
167167
*/
168168
int rstrcmp(const char *s1, const char *s2);
169169

170+
static inline void l3_heap_save(void) {}
171+
170172
/** @}*/
171173

172174
#endif /* __SOF_LIB_ALLOC_H__ */

zephyr/include/rtos/alloc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ static inline void *rbrealloc(void *ptr, uint32_t flags, uint32_t caps,
136136
*/
137137
void rfree(void *ptr);
138138

139+
/**
140+
* Save L3 heap over DSP reset
141+
*/
142+
void l3_heap_save(void);
143+
139144
/* TODO: remove - debug only - only needed for linking */
140145
static inline void heap_trace_all(int force) {}
141146

zephyr/lib/alloc.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static struct k_heap sof_heap;
126126

127127
#if CONFIG_L3_HEAP
128128
static struct k_heap l3_heap;
129+
static struct k_heap l3_heap_copy __imrdata;
129130

130131
/**
131132
* Returns the start of L3 memory heap.
@@ -158,6 +159,16 @@ static inline size_t get_l3_heap_size(void)
158159
return ROUND_DOWN(IMR_L3_HEAP_SIZE, L3_MEM_PAGE_SIZE);
159160
}
160161

162+
void l3_heap_save(void)
163+
{
164+
l3_heap_copy = l3_heap;
165+
LOG_DBG("L3 heap copy: %p", (void *)l3_heap_copy.heap.heap);
166+
dcache_writeback_region((__sparse_force void __sparse_cache *)&l3_heap_copy,
167+
sizeof(l3_heap_copy));
168+
dcache_writeback_region((__sparse_force void __sparse_cache *)get_l3_heap_start(),
169+
get_l3_heap_size());
170+
}
171+
161172
/**
162173
* Checks whether pointer is from L3 heap memory range.
163174
* @param ptr Pointer to memory being checked.
@@ -387,7 +398,7 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes)
387398
if (caps & SOF_MEM_CAPS_L3) {
388399
#if CONFIG_L3_HEAP
389400
heap = &l3_heap;
390-
/* Uncached L3_HEAP should be not used */
401+
/* Uncached L3_HEAP should not be used */
391402
if (!zone_is_cached(zone)) {
392403
tr_err(&zephyr_tr, "L3_HEAP available for cached zones only!");
393404
return NULL;
@@ -541,7 +552,11 @@ static int heap_init(void)
541552
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE);
542553

543554
#if CONFIG_L3_HEAP
544-
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()), get_l3_heap_size());
555+
if (l3_heap_copy.heap.heap)
556+
l3_heap = l3_heap_copy;
557+
else
558+
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()),
559+
get_l3_heap_size());
545560
#endif
546561

547562
return 0;

0 commit comments

Comments
 (0)