On 07.05.19 15:06, Marek Vasut wrote: > On 5/7/19 11:09 AM, Christoph Muellner wrote: >> If we are using malloc-simple, we get into the problem, that >> calls to free() won't free any memory. When using bouncebuf >> in SPL with malloc-simple this means, that every allocated buffer >> is lost. This can quickly consume the whole heap. > > When does such a scenario happen ?
RK3399 with mainline U-Boot and mainline ATF. We have 0x4000 bytes heap in SPL. For the SRAM part of ATF we need to allocate 0x2000-0x2200 bytes. For the PMUSRAM part about the same again. I tried to increase the heap size to 0x10000, but that seems to break some unchecked assumptions about the memory layout, because then SPL resets very early. > >> This patch addresses this memory wasting by introducing a static >> allocated memory location, which is used instead of dynamically >> allocated buffers. >> >> Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com> >> --- >> >> common/Kconfig | 15 +++++++++++++++ >> common/bouncebuf.c | 14 ++++++++++++++ >> 2 files changed, 29 insertions(+) >> >> diff --git a/common/Kconfig b/common/Kconfig >> index 1a1951f874..5fbca1e61a 100644 >> --- a/common/Kconfig >> +++ b/common/Kconfig >> @@ -702,6 +702,21 @@ config BOUNCE_BUFFER >> A second possible use of bounce buffers is their ability to >> provide aligned buffers for DMA operations. >> >> +config SPL_BOUNCE_BUFFER_STATIC >> + bool "Static bounce buffer in SPL" >> + depends on SPL && BOUNCE_BUFFER >> + default n >> + help >> + This option uses a static allocated memory area as >> + bounce buffer (i.e. no dynamic allocation). >> + >> +config SPL_BOUNCE_BUFFER_STATIC_SIZE >> + hex "Size of static bounce buffer in SPL" >> + depends on SPL_BOUNCE_BUFFER_STATIC >> + default 0x2800 >> + help >> + Size of the static allocated bounce buffer. >> + >> config BOARD_TYPES >> bool "Call get_board_type() to get and display the board type" >> help >> diff --git a/common/bouncebuf.c b/common/bouncebuf.c >> index a7098e2caf..92ee10fb93 100644 >> --- a/common/bouncebuf.c >> +++ b/common/bouncebuf.c >> @@ -10,6 +10,11 @@ >> #include <errno.h> >> #include <bouncebuf.h> >> >> +#if CONFIG_IS_ENABLED(BOUNCE_BUFFER_STATIC) >> +static u8 static_bb[CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE)]; >> +static const size_t static_bb_size = CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE); >> +#endif >> + >> static int addr_aligned(struct bounce_buffer *state) >> { >> const ulong align_mask = ARCH_DMA_MINALIGN - 1; >> @@ -40,10 +45,19 @@ int bounce_buffer_start(struct bounce_buffer *state, >> void *data, >> state->flags = flags; >> >> if (!addr_aligned(state)) { >> +#if CONFIG_IS_ENABLED(BOUNCE_BUFFER_STATIC) >> + if (state->len_aligned > static_bb_size) { >> + debug("Static allocated bounce buffer too small.\n"); >> + return -ENOMEM; >> + } >> + >> + state->bounce_buffer = static_bb; >> +#else >> state->bounce_buffer = memalign(ARCH_DMA_MINALIGN, >> state->len_aligned); >> if (!state->bounce_buffer) >> return -ENOMEM; >> +#endif >> >> if (state->flags & GEN_BB_READ) >> memcpy(state->bounce_buffer, state->user_buffer, >> > > _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot