diff mbox series

[05/40] spl: alloc: call full alloc functions if malloc pool is available

Message ID 20240724060224.3071065-6-sughosh.ganu@linaro.org
State New
Headers show
Series Make LMB memory map global and persistent | expand

Commit Message

Sughosh Ganu July 24, 2024, 6:01 a.m. UTC
If the malloc simple functionality is enabled in SPL, it is not
possible to call the full-implementation alloc functions even after
the heap is set-up in ram memory. Check for this condition and
call the functions when enabled.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
Changes since rfc: New patch

 common/malloc_simple.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Simon Glass July 25, 2024, 11:32 p.m. UTC | #1
Hi Sughosh,

On Wed, 24 Jul 2024 at 00:03, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> If the malloc simple functionality is enabled in SPL, it is not
> possible to call the full-implementation alloc functions even after
> the heap is set-up in ram memory. Check for this condition and
> call the functions when enabled.

Is this because you want to use lmb in SPL. Is that needed?

BTW I'll send a patch to allow alist to run without realloc().

>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
> Changes since rfc: New patch
>
>  common/malloc_simple.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)

Regards,
SImon
Sughosh Ganu July 29, 2024, 7:46 a.m. UTC | #2
hi Simon,

On Fri, 26 Jul 2024 at 05:02, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Sughosh,
>
> On Wed, 24 Jul 2024 at 00:03, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> >
> > If the malloc simple functionality is enabled in SPL, it is not
> > possible to call the full-implementation alloc functions even after
> > the heap is set-up in ram memory. Check for this condition and
> > call the functions when enabled.
>
> Is this because you want to use lmb in SPL. Is that needed?

Yes, there was a discussion on this, and Tom [1], and you also [2] had
mentioned on the earlier series that we do need lmb in SPL. You had
mentioned that this would subsequently be needed for VPL too.

-sughosh

[1] - https://lists.denx.de/pipermail/u-boot/2024-July/558250.html
[2] - https://lists.denx.de/pipermail/u-boot/2024-July/558644.html

>
> BTW I'll send a patch to allow alist to run without realloc().
>
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> > Changes since rfc: New patch
> >
> >  common/malloc_simple.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
>
> Regards,
> SImon
Simon Glass July 29, 2024, 3:26 p.m. UTC | #3
Hi Sughosh,

On Mon, 29 Jul 2024 at 01:46, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> hi Simon,
>
> On Fri, 26 Jul 2024 at 05:02, Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Sughosh,
> >
> > On Wed, 24 Jul 2024 at 00:03, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > >
> > > If the malloc simple functionality is enabled in SPL, it is not
> > > possible to call the full-implementation alloc functions even after
> > > the heap is set-up in ram memory. Check for this condition and
> > > call the functions when enabled.
> >
> > Is this because you want to use lmb in SPL. Is that needed?
>
> Yes, there was a discussion on this, and Tom [1], and you also [2] had
> mentioned on the earlier series that we do need lmb in SPL. You had
> mentioned that this would subsequently be needed for VPL too.

OK, well at least this way we can make sure it is disabled if not
needed. We can worry about how to pass information through the phases,
later.


>
> -sughosh
>
> [1] - https://lists.denx.de/pipermail/u-boot/2024-July/558250.html
> [2] - https://lists.denx.de/pipermail/u-boot/2024-July/558644.html
>
> >
> > BTW I'll send a patch to allow alist to run without realloc().
> >
> > >
> > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > ---
> > > Changes since rfc: New patch
> > >
> > >  common/malloc_simple.c | 13 +++++++++++++
> > >  1 file changed, 13 insertions(+)

Regards,
Simon
diff mbox series

Patch

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index 4e6d7952b3..982287defe 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -40,6 +40,10 @@  void *malloc_simple(size_t bytes)
 {
 	void *ptr;
 
+#if IS_ENABLED(CONFIG_SPL_SYS_MALLOC) && IS_ENABLED(CONFIG_SPL_LMB)
+	if (gd->flags & GD_FLG_FULL_MALLOC_INIT)
+		return mALLOc(bytes);
+#endif
 	ptr = alloc_simple(bytes, 1);
 	if (!ptr)
 		return ptr;
@@ -50,6 +54,15 @@  void *malloc_simple(size_t bytes)
 	return ptr;
 }
 
+void *realloc_simple(void *oldmem, size_t bytes)
+{
+#if IS_ENABLED(CONFIG_SPL_SYS_MALLOC) && IS_ENABLED(CONFIG_SPL_LMB)
+	if (gd->flags & GD_FLG_FULL_MALLOC_INIT)
+		return rEALLOc(oldmem, bytes);
+#endif
+	return NULL;
+}
+
 void *memalign_simple(size_t align, size_t bytes)
 {
 	void *ptr;