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