xref: /openbmc/u-boot/include/bouncebuf.h (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2b660df3cSMarek Vasut /*
3b660df3cSMarek Vasut  * Generic bounce buffer implementation
4b660df3cSMarek Vasut  *
5b660df3cSMarek Vasut  * Copyright (C) 2012 Marek Vasut <marex@denx.de>
6b660df3cSMarek Vasut  */
7b660df3cSMarek Vasut 
8b660df3cSMarek Vasut #ifndef __INCLUDE_BOUNCEBUF_H__
9b660df3cSMarek Vasut #define __INCLUDE_BOUNCEBUF_H__
10b660df3cSMarek Vasut 
1184d35b28SStephen Warren #include <linux/types.h>
1284d35b28SStephen Warren 
13b660df3cSMarek Vasut /*
14b660df3cSMarek Vasut  * GEN_BB_READ -- Data are read from the buffer eg. by DMA hardware.
15b660df3cSMarek Vasut  * The source buffer is copied into the bounce buffer (if unaligned, otherwise
16b660df3cSMarek Vasut  * the source buffer is used directly) upon start() call, then the operation
17b660df3cSMarek Vasut  * requiring the aligned transfer happens, then the bounce buffer is lost upon
18b660df3cSMarek Vasut  * stop() call.
19b660df3cSMarek Vasut  */
20b660df3cSMarek Vasut #define GEN_BB_READ	(1 << 0)
21b660df3cSMarek Vasut /*
22b660df3cSMarek Vasut  * GEN_BB_WRITE -- Data are written into the buffer eg. by DMA hardware.
23b660df3cSMarek Vasut  * The source buffer starts in an undefined state upon start() call, then the
24b660df3cSMarek Vasut  * operation requiring the aligned transfer happens, then the bounce buffer is
25b660df3cSMarek Vasut  * copied into the destination buffer (if unaligned, otherwise destination
26b660df3cSMarek Vasut  * buffer is used directly) upon stop() call.
27b660df3cSMarek Vasut  */
28b660df3cSMarek Vasut #define GEN_BB_WRITE	(1 << 1)
29b660df3cSMarek Vasut /*
30b660df3cSMarek Vasut  * GEN_BB_RW -- Data are read and written into the buffer eg. by DMA hardware.
31b660df3cSMarek Vasut  * The source buffer is copied into the bounce buffer (if unaligned, otherwise
32b660df3cSMarek Vasut  * the source buffer is used directly) upon start() call, then the  operation
33b660df3cSMarek Vasut  * requiring the aligned transfer happens, then the bounce buffer is  copied
34b660df3cSMarek Vasut  * into the destination buffer (if unaligned, otherwise destination buffer is
35b660df3cSMarek Vasut  * used directly) upon stop() call.
36b660df3cSMarek Vasut  */
37b660df3cSMarek Vasut #define GEN_BB_RW	(GEN_BB_READ | GEN_BB_WRITE)
38b660df3cSMarek Vasut 
3984d35b28SStephen Warren struct bounce_buffer {
4084d35b28SStephen Warren 	/* Copy of data parameter passed to start() */
4184d35b28SStephen Warren 	void *user_buffer;
4284d35b28SStephen Warren 	/*
4384d35b28SStephen Warren 	 * DMA-aligned buffer. This field is always set to the value that
4484d35b28SStephen Warren 	 * should be used for DMA; either equal to .user_buffer, or to a
4584d35b28SStephen Warren 	 * freshly allocated aligned buffer.
4684d35b28SStephen Warren 	 */
4784d35b28SStephen Warren 	void *bounce_buffer;
4884d35b28SStephen Warren 	/* Copy of len parameter passed to start() */
4984d35b28SStephen Warren 	size_t len;
5084d35b28SStephen Warren 	/* DMA-aligned buffer length */
5184d35b28SStephen Warren 	size_t len_aligned;
5284d35b28SStephen Warren 	/* Copy of flags parameter passed to start() */
5384d35b28SStephen Warren 	unsigned int flags;
5484d35b28SStephen Warren };
5584d35b28SStephen Warren 
56b660df3cSMarek Vasut /**
57b660df3cSMarek Vasut  * bounce_buffer_start() -- Start the bounce buffer session
5884d35b28SStephen Warren  * state:	stores state passed between bounce_buffer_{start,stop}
59b660df3cSMarek Vasut  * data:	pointer to buffer to be aligned
60b660df3cSMarek Vasut  * len:		length of the buffer
61b660df3cSMarek Vasut  * flags:	flags describing the transaction, see above.
62b660df3cSMarek Vasut  */
6384d35b28SStephen Warren int bounce_buffer_start(struct bounce_buffer *state, void *data,
6484d35b28SStephen Warren 			size_t len, unsigned int flags);
65b660df3cSMarek Vasut /**
66b660df3cSMarek Vasut  * bounce_buffer_stop() -- Finish the bounce buffer session
6784d35b28SStephen Warren  * state:	stores state passed between bounce_buffer_{start,stop}
68b660df3cSMarek Vasut  */
6984d35b28SStephen Warren int bounce_buffer_stop(struct bounce_buffer *state);
70b660df3cSMarek Vasut 
71b660df3cSMarek Vasut #endif
72