blob: 5ffa99bc131f8b69be7fabf6e8377d992e3265d0 [file] [log] [blame]
Marek Vasutb660df32012-08-26 15:19:06 +00001/*
2 * Generic bounce buffer implementation
3 *
4 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Marek Vasutb660df32012-08-26 15:19:06 +00007 */
8
9#ifndef __INCLUDE_BOUNCEBUF_H__
10#define __INCLUDE_BOUNCEBUF_H__
11
Stephen Warren84d35b22012-11-06 11:27:29 +000012#include <linux/types.h>
13
Marek Vasutb660df32012-08-26 15:19:06 +000014/*
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
19 * stop() call.
20 */
21#define GEN_BB_READ (1 << 0)
22/*
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.
28 */
29#define GEN_BB_WRITE (1 << 1)
30/*
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.
37 */
38#define GEN_BB_RW (GEN_BB_READ | GEN_BB_WRITE)
39
Stephen Warren84d35b22012-11-06 11:27:29 +000040struct bounce_buffer {
41 /* Copy of data parameter passed to start() */
42 void *user_buffer;
43 /*
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.
47 */
48 void *bounce_buffer;
49 /* Copy of len parameter passed to start() */
50 size_t len;
51 /* DMA-aligned buffer length */
52 size_t len_aligned;
53 /* Copy of flags parameter passed to start() */
54 unsigned int flags;
55};
56
Marek Vasutb660df32012-08-26 15:19:06 +000057/**
58 * bounce_buffer_start() -- Start the bounce buffer session
Stephen Warren84d35b22012-11-06 11:27:29 +000059 * state: stores state passed between bounce_buffer_{start,stop}
Marek Vasutb660df32012-08-26 15:19:06 +000060 * data: pointer to buffer to be aligned
61 * len: length of the buffer
Marek Vasutb660df32012-08-26 15:19:06 +000062 * flags: flags describing the transaction, see above.
63 */
Stephen Warren84d35b22012-11-06 11:27:29 +000064int bounce_buffer_start(struct bounce_buffer *state, void *data,
65 size_t len, unsigned int flags);
Marek Vasutb660df32012-08-26 15:19:06 +000066/**
67 * bounce_buffer_stop() -- Finish the bounce buffer session
Stephen Warren84d35b22012-11-06 11:27:29 +000068 * state: stores state passed between bounce_buffer_{start,stop}
Marek Vasutb660df32012-08-26 15:19:06 +000069 */
Stephen Warren84d35b22012-11-06 11:27:29 +000070int bounce_buffer_stop(struct bounce_buffer *state);
Marek Vasutb660df32012-08-26 15:19:06 +000071
72#endif