[U-Boot] [PATCH 1/2] bouncebuf: Add static buffer allocation method for SPL.
Christoph Muellner
christoph.muellner at theobroma-systems.com
Tue May 7 09:09:35 UTC 2019
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.
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.muellner at 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,
--
2.11.0
More information about the U-Boot
mailing list