xref: /rk3399_rockchip-uboot/include/bouncebuf.h (revision 84d35b2863455bedb9986c2b076241e8a441fc3e)
1b660df3cSMarek Vasut /*
2b660df3cSMarek Vasut  * Generic bounce buffer implementation
3b660df3cSMarek Vasut  *
4b660df3cSMarek Vasut  * Copyright (C) 2012 Marek Vasut <marex@denx.de>
5b660df3cSMarek Vasut  *
6b660df3cSMarek Vasut  * See file CREDITS for list of people who contributed to this
7b660df3cSMarek Vasut  * project.
8b660df3cSMarek Vasut  *
9b660df3cSMarek Vasut  * This program is free software; you can redistribute it and/or
10b660df3cSMarek Vasut  * modify it under the terms of the GNU General Public License as
11b660df3cSMarek Vasut  * published by the Free Software Foundation; either version 2 of
12b660df3cSMarek Vasut  * the License, or (at your option) any later version.
13b660df3cSMarek Vasut  *
14b660df3cSMarek Vasut  * This program is distributed in the hope that it will be useful,
15b660df3cSMarek Vasut  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16b660df3cSMarek Vasut  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17b660df3cSMarek Vasut  * GNU General Public License for more details.
18b660df3cSMarek Vasut  *
19b660df3cSMarek Vasut  * You should have received a copy of the GNU General Public License
20b660df3cSMarek Vasut  * along with this program; if not, write to the Free Software
21b660df3cSMarek Vasut  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22b660df3cSMarek Vasut  * MA 02111-1307 USA
23b660df3cSMarek Vasut  */
24b660df3cSMarek Vasut 
25b660df3cSMarek Vasut #ifndef __INCLUDE_BOUNCEBUF_H__
26b660df3cSMarek Vasut #define __INCLUDE_BOUNCEBUF_H__
27b660df3cSMarek Vasut 
28*84d35b28SStephen Warren #include <linux/types.h>
29*84d35b28SStephen Warren 
30b660df3cSMarek Vasut /*
31b660df3cSMarek Vasut  * GEN_BB_READ -- Data are read from the buffer eg. by DMA hardware.
32b660df3cSMarek Vasut  * The source buffer is copied into the bounce buffer (if unaligned, otherwise
33b660df3cSMarek Vasut  * the source buffer is used directly) upon start() call, then the operation
34b660df3cSMarek Vasut  * requiring the aligned transfer happens, then the bounce buffer is lost upon
35b660df3cSMarek Vasut  * stop() call.
36b660df3cSMarek Vasut  */
37b660df3cSMarek Vasut #define GEN_BB_READ	(1 << 0)
38b660df3cSMarek Vasut /*
39b660df3cSMarek Vasut  * GEN_BB_WRITE -- Data are written into the buffer eg. by DMA hardware.
40b660df3cSMarek Vasut  * The source buffer starts in an undefined state upon start() call, then the
41b660df3cSMarek Vasut  * operation requiring the aligned transfer happens, then the bounce buffer is
42b660df3cSMarek Vasut  * copied into the destination buffer (if unaligned, otherwise destination
43b660df3cSMarek Vasut  * buffer is used directly) upon stop() call.
44b660df3cSMarek Vasut  */
45b660df3cSMarek Vasut #define GEN_BB_WRITE	(1 << 1)
46b660df3cSMarek Vasut /*
47b660df3cSMarek Vasut  * GEN_BB_RW -- Data are read and written into the buffer eg. by DMA hardware.
48b660df3cSMarek Vasut  * The source buffer is copied into the bounce buffer (if unaligned, otherwise
49b660df3cSMarek Vasut  * the source buffer is used directly) upon start() call, then the  operation
50b660df3cSMarek Vasut  * requiring the aligned transfer happens, then the bounce buffer is  copied
51b660df3cSMarek Vasut  * into the destination buffer (if unaligned, otherwise destination buffer is
52b660df3cSMarek Vasut  * used directly) upon stop() call.
53b660df3cSMarek Vasut  */
54b660df3cSMarek Vasut #define GEN_BB_RW	(GEN_BB_READ | GEN_BB_WRITE)
55b660df3cSMarek Vasut 
56*84d35b28SStephen Warren struct bounce_buffer {
57*84d35b28SStephen Warren 	/* Copy of data parameter passed to start() */
58*84d35b28SStephen Warren 	void *user_buffer;
59*84d35b28SStephen Warren 	/*
60*84d35b28SStephen Warren 	 * DMA-aligned buffer. This field is always set to the value that
61*84d35b28SStephen Warren 	 * should be used for DMA; either equal to .user_buffer, or to a
62*84d35b28SStephen Warren 	 * freshly allocated aligned buffer.
63*84d35b28SStephen Warren 	 */
64*84d35b28SStephen Warren 	void *bounce_buffer;
65*84d35b28SStephen Warren 	/* Copy of len parameter passed to start() */
66*84d35b28SStephen Warren 	size_t len;
67*84d35b28SStephen Warren 	/* DMA-aligned buffer length */
68*84d35b28SStephen Warren 	size_t len_aligned;
69*84d35b28SStephen Warren 	/* Copy of flags parameter passed to start() */
70*84d35b28SStephen Warren 	unsigned int flags;
71*84d35b28SStephen Warren };
72*84d35b28SStephen Warren 
73b660df3cSMarek Vasut /**
74b660df3cSMarek Vasut  * bounce_buffer_start() -- Start the bounce buffer session
75*84d35b28SStephen Warren  * state:	stores state passed between bounce_buffer_{start,stop}
76b660df3cSMarek Vasut  * data:	pointer to buffer to be aligned
77b660df3cSMarek Vasut  * len:		length of the buffer
78b660df3cSMarek Vasut  * flags:	flags describing the transaction, see above.
79b660df3cSMarek Vasut  */
80*84d35b28SStephen Warren int bounce_buffer_start(struct bounce_buffer *state, void *data,
81*84d35b28SStephen Warren 			size_t len, unsigned int flags);
82b660df3cSMarek Vasut /**
83b660df3cSMarek Vasut  * bounce_buffer_stop() -- Finish the bounce buffer session
84*84d35b28SStephen Warren  * state:	stores state passed between bounce_buffer_{start,stop}
85b660df3cSMarek Vasut  */
86*84d35b28SStephen Warren int bounce_buffer_stop(struct bounce_buffer *state);
87b660df3cSMarek Vasut 
88b660df3cSMarek Vasut #endif
89