1 #ifndef __ALT_DMA_DEV_H__
2 #define __ALT_DMA_DEV_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 * *
30 * Altera does not recommend, suggest or require that this reference design *
31 * file be used in conjunction or combination with any other product. *
32 ******************************************************************************/
33
34 /******************************************************************************
35 * *
36 * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
37 * *
38 ******************************************************************************/
39
40 #include "priv/alt_dev_llist.h"
41
42 #include "alt_types.h"
43
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #endif /* __cplusplus */
48
49 /*
50 * This header contains the device driver interface for accessing DMA
51 * resources. See alt_dma.h for the DMA application side interface.
52 *
53 * The interface model treats a DMA transaction as being composed of two
54 * halves (read and write).
55 *
56 * An "alt_dma_txchan_dev" is used to describe the device associated with a
57 * DMA transmit channel. An "alt_dma_rxchan_dev" is used to describe the
58 * device associated with a DMA receive channel.
59 */
60
61 /*
62 * List of generic ioctl requests that may be supported by a DMA device.
63 *
64 * ALT_DMA_RX_ONLY_ON: This causes a DMA channel to operate in a mode
65 * where only the receiver is under software control.
66 * The other side reads continously from a single
67 * location. The address to read is the argument to
68 * this request.
69 * ALT_DMA_RX_ONLY_OFF: Return to the default mode where both the receive
70 * and transmit sides of the DMA can be under software
71 * control.
72 * ALT_DMA_TX_ONLY_ON: This causes a DMA channel to operate in a mode
73 * where only the transmitter is under software control.
74 * The other side writes continously to a single
75 * location. The address to write to is the argument to
76 * this request.
77 * ALT_DMA_TX_ONLY_OFF: Return to the default mode where both the receive
78 * and transmit sides of the DMA can be under software
79 * control.
80 * ALT_DMA_SET_MODE_8: Transfer data in units of 8 bits.
81 * ALT_DMA_SET_MODE_16: Transfer data in units of 16 bits.
82 * ALT_DMA_SET_MODE_32: Transfer data in units of 32 bits.
83 * ALT_DMA_SET_MODE_64: Transfer data in units of 64 bits.
84 * ALT_DMA_SET_MODE_128: Transfer data in units of 128 bits.
85 * ALT_DMA_GET_MODE: Get the current transfer mode.
86 *
87 * The use of the macros: ALT_DMA_TX_STREAM_ON, ALT_DMA_TX_STREAM_OFF
88 * ALT_DMA_RX_STREAM_OFF and ALT_DMA_RX_STREAM_ON are depreciated. You should
89 * instead use the macros: ALT_DMA_RX_ONLY_ON, ALT_DMA_RX_ONLY_OFF,
90 * ALT_DMA_TX_ONLY_ON and ALT_DMA_TX_ONLY_OFF.
91 */
92
93 #define ALT_DMA_TX_STREAM_ON (0x1)
94 #define ALT_DMA_TX_STREAM_OFF (0x2)
95 #define ALT_DMA_RX_STREAM_ON (0x3)
96 #define ALT_DMA_RX_STREAM_OFF (0x4)
97 #define ALT_DMA_SET_MODE_8 (0x5)
98 #define ALT_DMA_SET_MODE_16 (0x6)
99 #define ALT_DMA_SET_MODE_32 (0x7)
100 #define ALT_DMA_SET_MODE_64 (0x8)
101 #define ALT_DMA_SET_MODE_128 (0x9)
102 #define ALT_DMA_GET_MODE (0xa)
103
104 #define ALT_DMA_RX_ONLY_ON ALT_DMA_TX_STREAM_ON
105 #define ALT_DMA_RX_ONLY_OFF ALT_DMA_TX_STREAM_OFF
106 #define ALT_DMA_TX_ONLY_ON ALT_DMA_RX_STREAM_ON
107 #define ALT_DMA_TX_ONLY_OFF ALT_DMA_RX_STREAM_OFF
108
109 /*
110 *
111 */
112
113 typedef struct alt_dma_txchan_dev_s alt_dma_txchan_dev;
114 typedef struct alt_dma_rxchan_dev_s alt_dma_rxchan_dev;
115
116 typedef alt_dma_txchan_dev* alt_dma_txchan;
117 typedef alt_dma_rxchan_dev* alt_dma_rxchan;
118
119 typedef void (alt_txchan_done)(void* handle);
120 typedef void (alt_rxchan_done)(void* handle, void* data);
121
122 /*
123 * devices that provide a DMA transmit channel are required to provide an
124 * instance of the "alt_dma_txchan_dev" structure.
125 */
126
127 struct alt_dma_txchan_dev_s {
128 alt_llist llist; /* for internal use */
129 const char* name; /* name of the device instance
130 * (e.g. "/dev/dma_0").
131 */
132 int (*space) (alt_dma_txchan dma); /* returns the maximum number of
133 * transmit requests that can be posted
134 */
135 int (*dma_send) (alt_dma_txchan dma,
136 const void* from,
137 alt_u32 len,
138 alt_txchan_done* done,
139 void* handle); /* post a transmit request */
140 int (*ioctl) (alt_dma_txchan dma, int req, void* arg); /* perform device
141 * specific I/O control.
142 */
143 };
144
145 /*
146 * devices that provide a DMA receive channel are required to provide an
147 * instance of the "alt_dma_rxchan_dev" structure.
148 */
149
150 struct alt_dma_rxchan_dev_s {
151 alt_llist list; /* for internal use */
152 const char* name; /* name of the device instance
153 * (e.g. "/dev/dma_0").
154 */
155 alt_u32 depth; /* maximum number of receive requests that
156 * can be posted.
157 */
158 int (*prepare) (alt_dma_rxchan dma,
159 void* data,
160 alt_u32 len,
161 alt_rxchan_done* done,
162 void* handle); /* post a receive request */
163 int (*ioctl) (alt_dma_rxchan dma, int req, void* arg); /* perform device
164 * specific I/O control.
165 */
166 };
167
168 /*
169 * Register a DMA transmit channel with the system.
170 */
171
alt_dma_txchan_reg(alt_dma_txchan_dev * dev)172 static ALT_INLINE int alt_dma_txchan_reg (alt_dma_txchan_dev* dev)
173 {
174 extern alt_llist alt_dma_txchan_list;
175
176 return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_txchan_list);
177 }
178
179 /*
180 * Register a DMA receive channel with the system.
181 */
182
alt_dma_rxchan_reg(alt_dma_rxchan_dev * dev)183 static ALT_INLINE int alt_dma_rxchan_reg (alt_dma_rxchan_dev* dev)
184 {
185 extern alt_llist alt_dma_rxchan_list;
186
187 return alt_dev_llist_insert((alt_dev_llist*) dev, &alt_dma_rxchan_list);
188 }
189
190 /*
191 *
192 */
193
194 #ifdef __cplusplus
195 }
196 #endif /* __cplusplus */
197
198 #endif /* __ALT_DMA_DEV_H__ */
199