arch/arm: support kernel heap in BUILD_FLAT mode

Make umm & kmm heap alloc more clear, and possible support FLAT build to
enable kernel heap.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
yinshengkai
2024-08-01 12:05:22 +08:00
committed by Alan C. Assis
parent 874c0b002c
commit da6ddea8d4
+48 -38
View File
@@ -103,44 +103,37 @@
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL #ifndef CONFIG_BUILD_KERNEL
void up_allocate_kheap(void **heap_start, size_t *heap_size)
#else
void weak_function up_allocate_heap(void **heap_start, size_t *heap_size) void weak_function up_allocate_heap(void **heap_start, size_t *heap_size)
#endif
{ {
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
/* Get the unaligned size and position of the user-space heap. /* Get the unaligned size and position of the user-space heap.
* This heap begins after the user-space .bss section at an offset * This heap begins after the user-space .bss section at an offset
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment). * of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment).
*/ */
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + #ifdef CONFIG_BUILD_PROTECTED
CONFIG_MM_KERNEL_HEAPSIZE; uintptr_t base = (uintptr_t)USERSPACE->us_bssend;
size_t usize = CONFIG_RAM_END - ubase; #else
uintptr_t base = g_idle_topstack;
#endif
DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_END); #ifdef CONFIG_ARCH_PGPOOL_PBASE
size_t end = CONFIG_ARCH_PGPOOL_PBASE;
#else
size_t end = CONFIG_RAM_END;
#endif
#ifdef CONFIG_MM_KERNEL_HEAP
base += CONFIG_MM_KERNEL_HEAPSIZE;
#endif
/* Return the user-space heap settings */ /* Return the user-space heap settings */
board_autoled_on(LED_HEAPALLOCATE); board_autoled_on(LED_HEAPALLOCATE);
*heap_start = (void *)ubase; *heap_start = (void *)base;
*heap_size = usize; *heap_size = end - base;
#else
/* Return the heap settings */
board_autoled_on(LED_HEAPALLOCATE);
*heap_start = (void *)g_idle_topstack;
#ifdef CONFIG_ARCH_PGPOOL_PBASE
*heap_size = CONFIG_ARCH_PGPOOL_PBASE - g_idle_topstack;
#else
*heap_size = CONFIG_RAM_END - g_idle_topstack;
#endif
#endif
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: up_allocate_kheap * Name: up_allocate_kheap
@@ -153,23 +146,40 @@ void weak_function up_allocate_heap(void **heap_start, size_t *heap_size)
* *
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) #ifdef CONFIG_MM_KERNEL_HEAP
void up_allocate_kheap(void **heap_start, size_t *heap_size) void weak_function up_allocate_kheap(void **heap_start, size_t *heap_size)
{ {
/* Get the unaligned size and position of the user-space heap. /* Get the unaligned size and position of the kernel-space heap.
* This heap begins after the user-space .bss section at an offset * This heap begins after .bss section at an offset.
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment). * If not kernel build, have to work with CONFIG_MM_KERNEL_HEAPSIZE.
* And have to subject alignment.
*/ */
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + #ifdef CONFIG_BUILD_FLAT
CONFIG_MM_KERNEL_HEAPSIZE; uintptr_t base = g_idle_topstack;
DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_END); uintptr_t size = CONFIG_MM_KERNEL_HEAPSIZE;
/* Return the kernel heap settings (i.e., the part of the heap region #elif defined(CONFIG_BUILD_PROTECTED)
* that was not dedicated to the user heap). uintptr_t base = (uintptr_t)USERSPACE->us_bssend;
*/ uintptr_t size = CONFIG_MM_KERNEL_HEAPSIZE;
DEBUGASSERT(base < (uintptr_t)CONFIG_RAM_END);
*heap_start = (void *)USERSPACE->us_bssend; #elif defined(CONFIG_ARCH_PGPOOL_PBASE)
*heap_size = ubase - (uintptr_t)USERSPACE->us_bssend; /* CONFIG_BUILD_KERNEL && CONFIG_ARCH_PGPOOL_PBASE */
uintptr_t base = g_idle_topstack;
uintptr_t size = CONFIG_ARCH_PGPOOL_PBASE - g_idle_topstack;
# else
/* CONFIG_BUILD_KERNEL && !CONFIG_ARCH_PGPOOL_PBASE */
uintptr_t base = g_idle_topstack;
uintptr_t size = CONFIG_RAM_END - ubase;
#endif
/* Return the kernel-space heap settings */
board_autoled_on(LED_HEAPALLOCATE);
*heap_start = (void *)base;
*heap_size = size;
} }
#endif #endif