From 41fecdc94e3b3714f33a28c139f61cfa48bf16f9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:26 +0200 Subject: common: Tidy up how malloc() is inited The call to malloc() is a bit strange. The naming of the arguments suggests that an address is passed, but in fact it is a pointer, at least in the board_init_r() function and SPL equivalent. Update it to work as described. Add a function comment as well. Note that this does adjustment does not extend into the malloc() implementation itself, apart from changing mem_malloc_init(), since there are lots of casts and pointers and integers are used interchangeably. Signed-off-by: Simon Glass Reviewed-by: Tom Rini Reviewed-by: Ilias Apalodimas --- include/malloc.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/malloc.h b/include/malloc.h index 07d3e90a855..9e0be482416 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -981,6 +981,14 @@ extern ulong mem_malloc_start; extern ulong mem_malloc_end; extern ulong mem_malloc_brk; +/** + * mem_malloc_init() - Set up the malloc() pool + * + * Sets the region of memory to be used for all future calls to malloc(), etc. + * + * @start: Start address + * @size: Size in bytes + */ void mem_malloc_init(ulong start, ulong size); #ifdef __cplusplus -- cgit v1.2.3 From 040ab117c79795ff2a13f70c3c3847fa66db7d04 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:27 +0200 Subject: global_data: Add some more accessors Add accessors for bloblist, bootstage, trace and video to avoid needing more #ifdefs in the C code. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 644a0d77873..9dc0f4308cc 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -544,6 +544,36 @@ static_assert(sizeof(struct global_data) == GD_SIZE); #define gd_set_upl(val) #endif +#if CONFIG_IS_ENABLED(BLOBLIST) +#define gd_bloblist() gd->bloblist +#else +#define gd_bloblist() NULL +#endif + +#if CONFIG_IS_ENABLED(BOOTSTAGE) +#define gd_bootstage() gd->bootstage +#else +#define gd_bootstage() NULL +#endif + +#if CONFIG_IS_ENABLED(TRACE) +#define gd_trace_buff() gd->trace_buff +#define gd_trace_size() CONFIG_TRACE_BUFFER_SIZE +#else +#define gd_trace_buff() NULL +#define gd_trace_size() 0 +#endif + +#if CONFIG_IS_ENABLED(VIDEO) +#define gd_video_top() gd->video_top +#define gd_video_bottom() gd->video_bottom +#define gd_video_size() (gd->video_top - gd->video_bottom) +#else +#define gd_video_top() 0 +#define gd_video_bottom() 0 +#define gd_video_size() 0 +#endif + /** * enum gd_flags - global data flags * -- cgit v1.2.3 From 48008ec71148c0749ff34f7036a0278d4d92ae7b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 21 Oct 2024 10:19:28 +0200 Subject: bootstage: Allow counting memory without strings The bootstage array includes pointers to strings but not the strings themselves. The strings are added when stashing, but including them in the size calculation gives an inflated view of the amount of space used by the array. Update this function so it can return the amount of memory used by the bootstage structures themselves, without the strings which they point to. Signed-off-by: Simon Glass --- include/bootstage.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bootstage.h b/include/bootstage.h index 57792648c49..3300ca0248a 100644 --- a/include/bootstage.h +++ b/include/bootstage.h @@ -371,9 +371,10 @@ int bootstage_unstash(const void *base, int size); /** * bootstage_get_size() - Get the size of the bootstage data * + * @add_strings: true to add the size of attached strings (for stashing) * Return: size of boostage data in bytes */ -int bootstage_get_size(void); +int bootstage_get_size(bool add_strings); /** * bootstage_init() - Prepare bootstage for use @@ -444,7 +445,7 @@ static inline int bootstage_unstash(const void *base, int size) return 0; /* Pretend to succeed */ } -static inline int bootstage_get_size(void) +static inline int bootstage_get_size(bool add_strings) { return 0; } -- cgit v1.2.3