summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Müllner <christoph.muellner@theobroma-systems.com>2019-05-05 20:31:30 +0200
committerHeiko Stuebner <heiko@sntech.de>2019-08-11 11:26:41 +0200
commit3f5fcb7a241c97fed1b917a5ebd5983f608b06ce (patch)
treed35def5f8a3f3792f9e5b3c1b76fb38bac6a90b0
parentb8c899bdd30d8e8714553f0b88b0f14a2b49d252 (diff)
bouncebuf: Add static buffer allocation method for SPL.
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 Müllner <christoph.muellner@theobroma-systems.com>
-rw-r--r--common/Kconfig15
-rw-r--r--common/bouncebuf.c14
2 files changed, 29 insertions, 0 deletions
diff --git a/common/Kconfig b/common/Kconfig
index b556b59e9f..f076a9db8c 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -710,6 +710,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 5fd75989c3..cbfc0be7f3 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_bounce_buffer[CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE)];
+static const size_t static_bounce_buffer_size = CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE);
+#endif
+
static int addr_aligned(struct bounce_buffer *state)
{
const ulong align_mask = ARCH_DMA_MINALIGN - 1;
@@ -46,10 +51,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_bounce_buffer_size) {
+ debug("Static allocated bounce buffer too small.\n");
+ return -ENOMEM;
+ }
+
+ state->bounce_buffer = static_bounce_buffer;
+#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,