Skip to content

Commit

Permalink
cavs: memory: make full use of HPSRAM
Browse files Browse the repository at this point in the history
Make size of the buffer zone calculated at the linking stage, to make
full use of all HPSRAM memories.

Signed-off-by: Keyon Jie <[email protected]>
  • Loading branch information
keyonjie authored and lgirdwood committed Sep 10, 2021
1 parent 83e65d3 commit fc255ac
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 91 deletions.
33 changes: 18 additions & 15 deletions src/platform/apollolake/apollolake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -506,6 +496,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -518,15 +514,20 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = ALIGN (HEAP_BUF_ALIGNMENT);
_sof_core_s_start = ABSOLUTE(.);
. = . + SOF_CORE_S_T_SIZE;
_sof_core_s_end = ABSOLUTE(.);
#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
Expand All @@ -546,9 +547,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
7 changes: 4 additions & 3 deletions src/platform/apollolake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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)

Expand Down Expand Up @@ -305,10 +308,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x10000

#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 */
Expand Down
34 changes: 19 additions & 15 deletions src/platform/cannonlake/cannonlake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -471,6 +461,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -483,15 +479,21 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = 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 (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + SOF_FW_END - _buffer_heap_start;
_buffer_heap_end = ABSOLUTE(.);

_bss_end = ABSOLUTE(.);
} >sof_fw :sof_fw_phdr
Expand All @@ -511,9 +513,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/cannonlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,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)

Expand Down Expand Up @@ -291,9 +293,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x50000
#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 */
Expand Down
34 changes: 19 additions & 15 deletions src/platform/icelake/icelake.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -475,6 +465,12 @@ SECTIONS
. = . + HEAP_SYS_RUNTIME_M_SIZE;
_system_runtime_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

#if CONFIG_CORE_COUNT > 1
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_runtime_shared_heap_start = ABSOLUTE(.);
. = . + HEAP_RUNTIME_SHARED_SIZE;
Expand All @@ -487,15 +483,21 @@ SECTIONS
. = ALIGN (PLATFORM_DCACHE_ALIGN);
_system_shared_heap_end = ABSOLUTE(.);

. = ALIGN (4096);
_sof_stack_start = ABSOLUTE(.);
. = . + SOF_STACK_SIZE;
_sof_stack_end = ABSOLUTE(.);

. = 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 (HEAP_BUF_ALIGNMENT);
_buffer_heap_start = ABSOLUTE(.);
. = . + SOF_FW_END - _buffer_heap_start;
_buffer_heap_end = ABSOLUTE(.);

_bss_end = ABSOLUTE(.);
} >sof_fw :sof_fw_phdr
Expand All @@ -515,9 +517,11 @@ SECTIONS
/* system runtime heap */
_system_runtime_heap = _system_runtime_heap_start;

#if CONFIG_CORE_COUNT > 1
/* Shared Heap */
_runtime_shared_heap = _runtime_shared_heap_start;
_system_shared_heap = _system_shared_heap_start;
#endif

/* module heap */
_module_heap = _runtime_heap_start;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/icelake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,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)

Expand Down Expand Up @@ -288,9 +290,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x50000
#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 */
Expand Down
25 changes: 20 additions & 5 deletions src/platform/intel/cavs/lib/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ static SHARED_DATA struct block_map rt_shared_heap_map[] = {
#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)),
};

Expand All @@ -130,8 +130,21 @@ 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));

/* access memory map through uncached region */
sof->memory_map = cache_to_uncache(&memmap);

Expand Down Expand Up @@ -216,11 +229,12 @@ void platform_init_memmap(struct sof *sof)
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].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;

#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);
Expand All @@ -229,10 +243,11 @@ void platform_init_memmap(struct sof *sof)
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;
#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;

}
5 changes: 3 additions & 2 deletions src/platform/suecreek/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,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
Expand Down Expand Up @@ -277,9 +279,8 @@
/* Heap section sizes for system shared heap */
#define HEAP_SYSTEM_SHARED_SIZE 0x1500

#define HEAP_BUFFER_SIZE 0x10000
#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 */
Expand Down
Loading

0 comments on commit fc255ac

Please sign in to comment.