1 |
8 |
alfik |
#ifndef __ALT_DMA_H__
|
2 |
|
|
#define __ALT_DMA_H__
|
3 |
|
|
|
4 |
|
|
/******************************************************************************
|
5 |
|
|
* *
|
6 |
|
|
* License Agreement *
|
7 |
|
|
* *
|
8 |
|
|
* Copyright (c) 2004-2005 Altera Corporation, San Jose, California, USA. *
|
9 |
|
|
* All rights reserved. *
|
10 |
|
|
* *
|
11 |
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
12 |
|
|
* copy of this software and associated documentation files (the "Software"), *
|
13 |
|
|
* to deal in the Software without restriction, including without limitation *
|
14 |
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
|
15 |
|
|
* and/or sell copies of the Software, and to permit persons to whom the *
|
16 |
|
|
* Software is furnished to do so, subject to the following conditions: *
|
17 |
|
|
* *
|
18 |
|
|
* The above copyright notice and this permission notice shall be included in *
|
19 |
|
|
* all copies or substantial portions of the Software. *
|
20 |
|
|
* *
|
21 |
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
22 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
23 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
24 |
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
25 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
26 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
|
27 |
|
|
* DEALINGS IN THE SOFTWARE. *
|
28 |
|
|
* *
|
29 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
30 |
|
|
* of California and by the laws of the United States of America. *
|
31 |
|
|
* *
|
32 |
|
|
* Altera does not recommend, suggest or require that this reference design *
|
33 |
|
|
* file be used in conjunction or combination with any other product. *
|
34 |
|
|
******************************************************************************/
|
35 |
|
|
|
36 |
|
|
/******************************************************************************
|
37 |
|
|
* *
|
38 |
|
|
* THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
|
39 |
|
|
* *
|
40 |
|
|
******************************************************************************/
|
41 |
|
|
|
42 |
|
|
#include "sys/alt_dma_dev.h"
|
43 |
|
|
#include "alt_types.h"
|
44 |
|
|
|
45 |
|
|
#include <errno.h>
|
46 |
|
|
|
47 |
|
|
#ifdef __cplusplus
|
48 |
|
|
extern "C"
|
49 |
|
|
{
|
50 |
|
|
#endif /* __cplusplus */
|
51 |
|
|
|
52 |
|
|
/*
|
53 |
|
|
* This header contains the application side interface for accessing DMA
|
54 |
|
|
* resources. See alt_dma_dev.h for the dma device driver interface.
|
55 |
|
|
*
|
56 |
|
|
* The interface model treats a DMA transaction as being composed of two
|
57 |
|
|
* halves (read and write).
|
58 |
|
|
*
|
59 |
|
|
* The application can supply data for transmit using an "alt_dma_txchan"
|
60 |
|
|
* descriptor. Alternatively an "alt_dma_rxchan" descriptor can be used to
|
61 |
|
|
* receive data.
|
62 |
|
|
*/
|
63 |
|
|
|
64 |
|
|
/*
|
65 |
|
|
* alt_dma_txchan_open() is used to obtain an "alt_dma_txchan" descriptor for
|
66 |
|
|
* a DMA transmit device. The name is the name of the associated physical
|
67 |
|
|
* device (e.g. "/dev/dma_0").
|
68 |
|
|
*
|
69 |
|
|
* The return value will be NULL on failure, and non-NULL otherwise.
|
70 |
|
|
*/
|
71 |
|
|
|
72 |
|
|
extern alt_dma_txchan alt_dma_txchan_open (const char* name);
|
73 |
|
|
|
74 |
|
|
/*
|
75 |
|
|
* alt_dma_txchan_close() is provided so that an application can notify the
|
76 |
|
|
* system that it has finished with a given DMA transmit channel. This is only
|
77 |
|
|
* provided for completness.
|
78 |
|
|
*/
|
79 |
|
|
|
80 |
|
|
static ALT_INLINE int alt_dma_txchan_close (alt_dma_txchan dma)
|
81 |
|
|
{
|
82 |
|
|
return 0;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/*
|
86 |
|
|
* alt_dma_txchan_send() posts a transmit request to a DMA transmit channel.
|
87 |
|
|
* The input arguments are:
|
88 |
|
|
*
|
89 |
|
|
* dma: the channel to use.
|
90 |
|
|
* from: a pointer to the start of the data to send.
|
91 |
|
|
* length: the length of the data to send in bytes.
|
92 |
|
|
* done: callback function that will be called once the data has been sent.
|
93 |
|
|
* handle: opaque value passed to "done".
|
94 |
|
|
*
|
95 |
|
|
* The return value will be negative if the request cannot be posted, and
|
96 |
|
|
* zero otherwise.
|
97 |
|
|
*/
|
98 |
|
|
|
99 |
|
|
static ALT_INLINE int alt_dma_txchan_send (alt_dma_txchan dma,
|
100 |
|
|
const void* from,
|
101 |
|
|
alt_u32 length,
|
102 |
|
|
alt_txchan_done* done,
|
103 |
|
|
void* handle)
|
104 |
|
|
{
|
105 |
|
|
return dma ? dma->dma_send (dma,
|
106 |
|
|
from,
|
107 |
|
|
length,
|
108 |
|
|
done,
|
109 |
|
|
handle) : -ENODEV;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/*
|
113 |
|
|
* alt_dma_txchan_space() returns the number of tranmit requests that can be
|
114 |
|
|
* posted to the specified DMA transmit channel.
|
115 |
|
|
*
|
116 |
|
|
* A negative value indicates that the value could not be determined.
|
117 |
|
|
*/
|
118 |
|
|
|
119 |
|
|
static ALT_INLINE int alt_dma_txchan_space (alt_dma_txchan dma)
|
120 |
|
|
{
|
121 |
|
|
return dma ? dma->space (dma) : -ENODEV;
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
/*
|
125 |
|
|
* alt_dma_txchan_ioctl() can be used to perform device specific I/O
|
126 |
|
|
* operations on the indicated DMA transmit channel. For example some drivers
|
127 |
|
|
* support options to control the width of the transfer operations. See
|
128 |
|
|
* alt_dma_dev.h for the list of generic requests.
|
129 |
|
|
*
|
130 |
|
|
* A negative return value indicates failure, otherwise the interpretation
|
131 |
|
|
* of the return value is request specific.
|
132 |
|
|
*/
|
133 |
|
|
|
134 |
|
|
static ALT_INLINE int alt_dma_txchan_ioctl (alt_dma_txchan dma,
|
135 |
|
|
int req,
|
136 |
|
|
void* arg)
|
137 |
|
|
{
|
138 |
|
|
return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
/*
|
142 |
|
|
* alt_dma_rxchan_open() is used to obtain an "alt_dma_rxchan" descriptor for
|
143 |
|
|
* a DMA receive channel. The name is the name of the associated physical
|
144 |
|
|
* device (e.g. "/dev/dma_0").
|
145 |
|
|
*
|
146 |
|
|
* The return value will be NULL on failure, and non-NULL otherwise.
|
147 |
|
|
*/
|
148 |
|
|
|
149 |
|
|
extern alt_dma_rxchan alt_dma_rxchan_open (const char* dev);
|
150 |
|
|
|
151 |
|
|
/*
|
152 |
|
|
* alt_dma_rxchan_close() is provided so that an application can notify the
|
153 |
|
|
* system that it has finished with a given DMA receive channel. This is only
|
154 |
|
|
* provided for completness.
|
155 |
|
|
*/
|
156 |
|
|
|
157 |
|
|
static ALT_INLINE int alt_dma_rxchan_close (alt_dma_rxchan dma)
|
158 |
|
|
{
|
159 |
|
|
return 0;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
/*
|
163 |
|
|
*
|
164 |
|
|
*/
|
165 |
|
|
|
166 |
|
|
/*
|
167 |
|
|
* alt_dma_rxchan_prepare() posts a receive request to a DMA receive channel.
|
168 |
|
|
*
|
169 |
|
|
* The input arguments are:
|
170 |
|
|
*
|
171 |
|
|
* dma: the channel to use.
|
172 |
|
|
* data: a pointer to the location that data is to be received to.
|
173 |
|
|
* len: the maximum length of the data to receive.
|
174 |
|
|
* done: callback function that will be called once the data has been
|
175 |
|
|
* received.
|
176 |
|
|
* handle: opaque value passed to "done".
|
177 |
|
|
*
|
178 |
|
|
* The return value will be negative if the request cannot be posted, and
|
179 |
|
|
* zero otherwise.
|
180 |
|
|
*/
|
181 |
|
|
|
182 |
|
|
static ALT_INLINE int alt_dma_rxchan_prepare (alt_dma_rxchan dma,
|
183 |
|
|
void* data,
|
184 |
|
|
alt_u32 len,
|
185 |
|
|
alt_rxchan_done* done,
|
186 |
|
|
void* handle)
|
187 |
|
|
{
|
188 |
|
|
return dma ? dma->prepare (dma, data, len, done, handle) : -ENODEV;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
/*
|
192 |
|
|
* alt_dma_rxchan_ioctl() can be used to perform device specific I/O
|
193 |
|
|
* operations on the indicated DMA receive channel. For example some drivers
|
194 |
|
|
* support options to control the width of the transfer operations. See
|
195 |
|
|
* alt_dma_dev.h for the list of generic requests.
|
196 |
|
|
*
|
197 |
|
|
* A negative return value indicates failure, otherwise the interpretation
|
198 |
|
|
* of the return value is request specific.
|
199 |
|
|
*/
|
200 |
|
|
|
201 |
|
|
static ALT_INLINE int alt_dma_rxchan_ioctl (alt_dma_rxchan dma,
|
202 |
|
|
int req,
|
203 |
|
|
void* arg)
|
204 |
|
|
{
|
205 |
|
|
return dma ? dma->ioctl (dma, req, arg) : -ENODEV;
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
/*
|
209 |
|
|
* alt_dma_rxchan_depth() returns the depth of the receive FIFO used to store
|
210 |
|
|
* receive requests.
|
211 |
|
|
*/
|
212 |
|
|
|
213 |
|
|
static ALT_INLINE alt_u32 alt_dma_rxchan_depth(alt_dma_rxchan dma)
|
214 |
|
|
{
|
215 |
|
|
return dma->depth;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
/*
|
219 |
|
|
*
|
220 |
|
|
*/
|
221 |
|
|
|
222 |
|
|
#ifdef __cplusplus
|
223 |
|
|
}
|
224 |
|
|
#endif /* __cplusplus */
|
225 |
|
|
|
226 |
|
|
#endif /* __ALT_DMA_H__ */
|