Skip to content

Commit

Permalink
Merge pull request #541 from libinyang/init_heap_in_right_way
Browse files Browse the repository at this point in the history
alloc: fix memory heap initialization
  • Loading branch information
lgirdwood authored Nov 8, 2018
2 parents 019eade + 159f118 commit 3256781
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions src/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ void init_heap(struct sof *sof)
struct block_map *current_map;
int i;
int j;
int k;

/* sanity check for malformed images or loader issues */
if (memmap.system[0].heap != HEAP_SYSTEM_0_BASE)
Expand All @@ -627,20 +626,19 @@ void init_heap(struct sof *sof)
for (i = 0; i < PLATFORM_HEAP_BUFFER; i++) {
heap = &memmap.buffer[i];

for (j = 0; j < heap->blocks; j++) {

/* init the map[0] */
current_map = &heap->map[0];
current_map->base = heap->heap;
flush_block_map(current_map);

/* map[j]'s base is calculated based on map[j-1] */
for (j = 1; j < heap->blocks; j++) {
next_map = &heap->map[j];
next_map->base = current_map->base +
current_map->block_size *
current_map->count;
current_map = &heap->map[j];
current_map->base = heap->heap;
flush_block_map(current_map);

for (k = 1; k < heap->blocks; k++) {
next_map = &heap->map[k];
next_map->base = current_map->base +
current_map->block_size *
current_map->count;
current_map = &heap->map[k];
flush_block_map(current_map);
}
}

dcache_writeback_invalidate_region(heap, sizeof(*heap));
Expand All @@ -650,20 +648,19 @@ void init_heap(struct sof *sof)
for (i = 0; i < PLATFORM_HEAP_RUNTIME; i++) {
heap = &memmap.runtime[i];

for (j = 0; j < heap->blocks; j++) {

/* init the map[0] */
current_map = &heap->map[0];
current_map->base = heap->heap;
flush_block_map(current_map);

/* map[j]'s base is calculated based on map[j-1] */
for (j = 1; j < heap->blocks; j++) {
next_map = &heap->map[j];
next_map->base = current_map->base +
current_map->block_size *
current_map->count;
current_map = &heap->map[j];
current_map->base = heap->heap;
flush_block_map(current_map);

for (k = 1; k < heap->blocks; k++) {
next_map = &heap->map[k];
next_map->base = current_map->base +
current_map->block_size *
current_map->count;
current_map = &heap->map[k];
flush_block_map(current_map);
}
}

dcache_writeback_invalidate_region(heap, sizeof(*heap));
Expand Down

0 comments on commit 3256781

Please sign in to comment.