diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-12-13 06:18:36 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-02-04 06:06:41 +0100 |
commit | eea21eaca117ecd98afea164e1808d6530ef487f (patch) | |
tree | ca4e15da28b71a5ecca5fc357798261a39b3f250 /bsps/powerpc | |
parent | 07e2eacf8977121ef342e2d3c323ea6c997307b8 (diff) |
bsps: Rework work area initialization
The work area initialization was done by the BSP through
bsp_work_area_initialize(). This approach predated the system
initialization through the system initialization linker set. The
workspace and C program heap were unconditionally initialized. The aim
is to support RTEMS application configurations which do not need the
workspace and C program heap. In these configurations, the workspace
and C prgram heap should not get initialized.
Change all bsp_work_area_initialize() to implement _Memory_Get()
instead. Move the dirty memory, sbrk(), per-CPU data, workspace, and
malloc() heap initialization into separate system initialization steps.
This makes it also easier to test the individual initialization steps.
This change adds a dependency to _Heap_Extend() to all BSPs. This
dependency will be removed in a follow up change.
Update #3838.
Diffstat (limited to 'bsps/powerpc')
-rw-r--r-- | bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c | 27 | ||||
-rw-r--r-- | bsps/powerpc/qoriq/start/mmu-config.c | 27 | ||||
-rw-r--r-- | bsps/powerpc/shared/start/bspgetworkarea.c | 30 | ||||
-rw-r--r-- | bsps/powerpc/shared/start/sbrk.c | 63 | ||||
-rw-r--r-- | bsps/powerpc/tqm8xx/start/bspgetworkarea.c | 26 |
5 files changed, 128 insertions, 45 deletions
diff --git a/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c b/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c index cb7cf6c7ec..915d13e7b6 100644 --- a/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c +++ b/bsps/powerpc/mpc55xxevb/start/bspgetworkarea.c @@ -23,22 +23,17 @@ #include <bsp/linker-symbols.h> LINKER_SYMBOL(bsp_section_work_bonus_begin); -LINKER_SYMBOL(bsp_section_work_bonus_size); +LINKER_SYMBOL(bsp_section_work_bonus_end); -void bsp_work_area_initialize(void) -{ - Heap_Area areas [] = { - { - bsp_section_work_begin, - (uintptr_t) bsp_section_work_size - }, { - bsp_section_work_bonus_begin, - (uintptr_t) bsp_section_work_bonus_size - } - }; +static Memory_Area _Memory_Areas[] = { + MEMORY_INITIALIZER(bsp_section_work_begin, bsp_section_work_end), + MEMORY_INITIALIZER(bsp_section_work_bonus_begin, bsp_section_work_bonus_end) +}; + +static const Memory_Information _Memory_Information = + MEMORY_INFORMATION_INITIALIZER(_Memory_Areas); - bsp_work_area_initialize_with_table( - areas, - sizeof(areas) / sizeof(areas [0]) - ); +const Memory_Information *_Memory_Get(void) +{ + return &_Memory_Information; } diff --git a/bsps/powerpc/qoriq/start/mmu-config.c b/bsps/powerpc/qoriq/start/mmu-config.c index d13325fbd2..296b071929 100644 --- a/bsps/powerpc/qoriq/start/mmu-config.c +++ b/bsps/powerpc/qoriq/start/mmu-config.c @@ -32,6 +32,7 @@ #include <libfdt.h> #include <rtems/config.h> +#include <rtems/sysinit.h> #define TEXT __attribute__((section(".bsp_start_text"))) #define DATA __attribute__((section(".bsp_start_data"))) @@ -338,11 +339,29 @@ void TEXT qoriq_mmu_config(bool boot_processor, int first_tlb, int scratch_tlb) qoriq_mmu_write_to_tlb1(&context, first_tlb); } -void TEXT bsp_work_area_initialize(void) +static Memory_Area _Memory_Areas[1]; + +static const Memory_Information _Memory_Information = + MEMORY_INFORMATION_INITIALIZER(_Memory_Areas); + +static void bsp_memory_initialize(void) { const entry *we = &config[WORKSPACE_ENTRY_INDEX]; - uintptr_t begin = we->begin; - uintptr_t end = begin + we->size; - bsp_work_area_initialize_default((void *) begin, end - begin); + _Memory_Initialize_by_size( + &_Memory_Areas[0], + (void *) we->begin, + we->size + ); +} + +RTEMS_SYSINIT_ITEM( + bsp_memory_initialize, + RTEMS_SYSINIT_MEMORY, + RTEMS_SYSINIT_ORDER_MIDDLE +); + +const Memory_Information *_Memory_Get(void) +{ + return &_Memory_Information; } diff --git a/bsps/powerpc/shared/start/bspgetworkarea.c b/bsps/powerpc/shared/start/bspgetworkarea.c index 8873ffe574..3d26a419a1 100644 --- a/bsps/powerpc/shared/start/bspgetworkarea.c +++ b/bsps/powerpc/shared/start/bspgetworkarea.c @@ -9,15 +9,33 @@ #include <libcpu/powerpc-utility.h> +#include <rtems/sysinit.h> + LINKER_SYMBOL(__rtems_end) -void bsp_work_area_initialize(void) +static Memory_Area _Memory_Areas[1]; + +static const Memory_Information _Memory_Information = + MEMORY_INFORMATION_INITIALIZER(_Memory_Areas); + +static void bsp_memory_initialize(void) { - uintptr_t work_size; - uintptr_t work_area; + uintptr_t size; + uintptr_t begin; - work_area = (uintptr_t)__rtems_end; - work_size = (uintptr_t)BSP_mem_size - work_area; + begin = (uintptr_t)__rtems_end; + size = (uintptr_t)BSP_mem_size - begin; - bsp_work_area_initialize_default((void *) work_area, work_size); + _Memory_Initialize_by_size(&_Memory_Areas[0], (void *) begin, size); +} + +RTEMS_SYSINIT_ITEM( + bsp_memory_initialize, + RTEMS_SYSINIT_MEMORY, + RTEMS_SYSINIT_ORDER_MIDDLE +); + +const Memory_Information *_Memory_Get(void) +{ + return &_Memory_Information; } diff --git a/bsps/powerpc/shared/start/sbrk.c b/bsps/powerpc/shared/start/sbrk.c index f17a1511e4..95104ba9c8 100644 --- a/bsps/powerpc/shared/start/sbrk.c +++ b/bsps/powerpc/shared/start/sbrk.c @@ -64,8 +64,13 @@ #include <errno.h> #include <unistd.h> +#include <bsp.h> #include <bsp/bootcard.h> +#include <rtems/sysinit.h> + +#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK + #define INVALID_REMAINING_START ((uintptr_t) -1) static uintptr_t remaining_start = INVALID_REMAINING_START; @@ -83,22 +88,35 @@ extern uintptr_t BSP_sbrk_policy[] __attribute__((weak)); #define LIMIT_32M 0x02000000 -ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size) +/** + * @brief Gives the BSP a chance to reduce the work area size with sbrk() + * adding more later. + * + * bsp_sbrk_init() may reduce the work area size passed in. The routine + * returns the 'sbrk_amount' to be used when extending the heap. Note that + * the return value may be zero. + * + * In case the @a mem area size is altered, then the remaining size of the + * @a mem area must be greater than or equal to @a min_size. + */ +static ptrdiff_t bsp_sbrk_init(const Memory_Information *mem, uintptr_t min_size) { uintptr_t rval = 0; uintptr_t policy; uintptr_t remaining_end; + Memory_Area *area; - remaining_start = (uintptr_t) area->begin; - remaining_size = area->size; - remaining_end = remaining_start + remaining_size; + area = &mem->areas[ 0 ]; + remaining_start = (uintptr_t) _Memory_Get_free_begin(area); + remaining_size = _Memory_Get_free_size(area); + remaining_end = (uintptr_t) _Memory_Get_end(area); if (remaining_start < LIMIT_32M && remaining_end > LIMIT_32M && min_size <= LIMIT_32M - remaining_start) { /* clip at LIMIT_32M */ rval = remaining_end - LIMIT_32M; - area->size = LIMIT_32M - remaining_start; + _Memory_Set_end(area, (void *) (LIMIT_32M - remaining_start)); remaining_start = LIMIT_32M; remaining_size = rval; } @@ -106,9 +124,9 @@ ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size) policy = (0 == BSP_sbrk_policy[0] ? (uintptr_t)(-1) : BSP_sbrk_policy[0]); switch ( policy ) { case (uintptr_t)(-1): - area->size += rval; - remaining_start = (uintptr_t) area->begin + area->size; - remaining_size = 0; + _Memory_Set_end(area, (const char *) _Memory_Get_end(area) + rval); + remaining_start = (uintptr_t) _Memory_Get_end(area); + remaining_size = 0; break; case 0: @@ -124,12 +142,7 @@ ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size) return (ptrdiff_t) (rval <= PTRDIFF_MAX ? rval : rval / 2); } -/* - * This is just so the sbrk test can force its magic. All normal applications - * should just use the default implementation in this file. - */ -void *sbrk(ptrdiff_t incr) __attribute__ (( weak, alias("bsp_sbrk") )); -static void *bsp_sbrk(ptrdiff_t incr) +void *sbrk(ptrdiff_t incr) { void *rval=(void*)-1; @@ -145,3 +158,25 @@ static void *bsp_sbrk(ptrdiff_t incr) #endif return rval; } + +static void bsp_sbrk_initialize(void) +{ + uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT); + uintptr_t work_space_size = rtems_configuration_get_work_space_size(); + ptrdiff_t sbrk_amount = bsp_sbrk_init( + _Memory_Get(), + work_space_size + + overhead + + (rtems_configuration_get_unified_work_area() ? 0 : overhead) + ); + + rtems_heap_set_sbrk_amount(sbrk_amount); +} + +RTEMS_SYSINIT_ITEM( + bsp_sbrk_initialize, + RTEMS_SYSINIT_SBRK, + RTEMS_SYSINIT_ORDER_MIDDLE +); + +#endif /* CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK */ diff --git a/bsps/powerpc/tqm8xx/start/bspgetworkarea.c b/bsps/powerpc/tqm8xx/start/bspgetworkarea.c index 4a0a4db534..e5cd59e0de 100644 --- a/bsps/powerpc/tqm8xx/start/bspgetworkarea.c +++ b/bsps/powerpc/tqm8xx/start/bspgetworkarea.c @@ -24,11 +24,27 @@ #include <bsp/bootcard.h> #include <bsp/linker-symbols.h> -void bsp_work_area_initialize(void) +#include <rtems/sysinit.h> + +static Memory_Area _Memory_Areas[1]; + +static const Memory_Information _Memory_Information = + MEMORY_INFORMATION_INITIALIZER(_Memory_Areas); + +static void bsp_memory_initialize(void) { - char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved); - void *area_start = bsp_section_work_begin; - uintptr_t area_size = (uintptr_t) ram_end - (uintptr_t) area_start; + void *end = (void *) (TQM_BD_INFO.sdram_size - (uintptr_t)TopRamReserved); - bsp_work_area_initialize_default( area_start, area_size ); + _Memory_Initialize(&_Memory_Areas[0], bsp_section_work_begin, end); +} + +RTEMS_SYSINIT_ITEM( + bsp_memory_initialize, + RTEMS_SYSINIT_MEMORY, + RTEMS_SYSINIT_ORDER_MIDDLE +); + +const Memory_Information *_Memory_Get(void) +{ + return &_Memory_Information; } |