2 * Generic bounce buffer implementation
4 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
6 * SPDX-License-Identifier: GPL-2.0+
9 #ifndef __INCLUDE_BOUNCEBUF_H__
10 #define __INCLUDE_BOUNCEBUF_H__
12 #include <linux/types.h>
15 * GEN_BB_READ -- Data are read from the buffer eg. by DMA hardware.
16 * The source buffer is copied into the bounce buffer (if unaligned, otherwise
17 * the source buffer is used directly) upon start() call, then the operation
18 * requiring the aligned transfer happens, then the bounce buffer is lost upon
21 #define GEN_BB_READ (1 << 0)
23 * GEN_BB_WRITE -- Data are written into the buffer eg. by DMA hardware.
24 * The source buffer starts in an undefined state upon start() call, then the
25 * operation requiring the aligned transfer happens, then the bounce buffer is
26 * copied into the destination buffer (if unaligned, otherwise destination
27 * buffer is used directly) upon stop() call.
29 #define GEN_BB_WRITE (1 << 1)
31 * GEN_BB_RW -- Data are read and written into the buffer eg. by DMA hardware.
32 * The source buffer is copied into the bounce buffer (if unaligned, otherwise
33 * the source buffer is used directly) upon start() call, then the operation
34 * requiring the aligned transfer happens, then the bounce buffer is copied
35 * into the destination buffer (if unaligned, otherwise destination buffer is
36 * used directly) upon stop() call.
38 #define GEN_BB_RW (GEN_BB_READ | GEN_BB_WRITE)
40 struct bounce_buffer {
41 /* Copy of data parameter passed to start() */
44 * DMA-aligned buffer. This field is always set to the value that
45 * should be used for DMA; either equal to .user_buffer, or to a
46 * freshly allocated aligned buffer.
49 /* Copy of len parameter passed to start() */
51 /* DMA-aligned buffer length */
53 /* Copy of flags parameter passed to start() */
58 * bounce_buffer_start() -- Start the bounce buffer session
59 * state: stores state passed between bounce_buffer_{start,stop}
60 * data: pointer to buffer to be aligned
61 * len: length of the buffer
62 * flags: flags describing the transaction, see above.
64 int bounce_buffer_start(struct bounce_buffer *state, void *data,
65 size_t len, unsigned int flags);
67 * bounce_buffer_stop() -- Finish the bounce buffer session
68 * state: stores state passed between bounce_buffer_{start,stop}
70 int bounce_buffer_stop(struct bounce_buffer *state);