Merge https://source.denx.de/u-boot/custodians/u-boot-usb
[platform/kernel/u-boot.git] / common / bouncebuf.c
index 054d9e0..6d98920 100644 (file)
@@ -1,15 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Generic bounce buffer implementation
  *
  * Copyright (C) 2012 Marek Vasut <marex@denx.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <log.h>
 #include <malloc.h>
 #include <errno.h>
 #include <bouncebuf.h>
+#include <asm/cache.h>
 
 static int addr_aligned(struct bounce_buffer *state)
 {
@@ -31,17 +33,19 @@ static int addr_aligned(struct bounce_buffer *state)
        return 1;
 }
 
-int bounce_buffer_start(struct bounce_buffer *state, void *data,
-                       size_t len, unsigned int flags)
+int bounce_buffer_start_extalign(struct bounce_buffer *state, void *data,
+                                size_t len, unsigned int flags,
+                                size_t alignment,
+                                int (*addr_is_aligned)(struct bounce_buffer *state))
 {
        state->user_buffer = data;
        state->bounce_buffer = data;
        state->len = len;
-       state->len_aligned = roundup(len, ARCH_DMA_MINALIGN);
+       state->len_aligned = roundup(len, alignment);
        state->flags = flags;
 
-       if (!addr_aligned(state)) {
-               state->bounce_buffer = memalign(ARCH_DMA_MINALIGN,
+       if (!addr_is_aligned(state)) {
+               state->bounce_buffer = memalign(alignment,
                                                state->len_aligned);
                if (!state->bounce_buffer)
                        return -ENOMEM;
@@ -62,6 +66,14 @@ int bounce_buffer_start(struct bounce_buffer *state, void *data,
        return 0;
 }
 
+int bounce_buffer_start(struct bounce_buffer *state, void *data,
+                       size_t len, unsigned int flags)
+{
+       return bounce_buffer_start_extalign(state, data, len, flags,
+                                           ARCH_DMA_MINALIGN,
+                                           addr_aligned);
+}
+
 int bounce_buffer_stop(struct bounce_buffer *state)
 {
        if (state->flags & GEN_BB_WRITE) {