RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
bsps
include
grlib
grpci2dma.h
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
3
/*
4
* GRPCI2 DMA Driver
5
*
6
* COPYRIGHT (c) 2017
7
* Cobham Gaisler AB
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
* POSSIBILITY OF SUCH DAMAGE.
29
*
30
* OVERVIEW
31
* ========
32
* This driver controls the DMA on the GRPCI2 device, located
33
* at an on-chip AMBA.
34
*/
35
36
#ifndef __GRPCI2DMA_H__
37
#define __GRPCI2DMA_H__
38
39
#include <stdint.h>
40
#include <stdio.h>
41
42
#ifdef __cplusplus
43
extern
"C"
{
44
#endif
45
46
/* Error return codes */
47
#define GRPCI2DMA_ERR_OK 0
48
#define GRPCI2DMA_ERR_WRONGPTR -1
49
#define GRPCI2DMA_ERR_NOINIT -2
50
#define GRPCI2DMA_ERR_TOOMANY -3
51
#define GRPCI2DMA_ERR_ERROR -4
52
#define GRPCI2DMA_ERR_STOPDMA -5
53
#define GRPCI2DMA_ERR_NOTFOUND -6
54
55
/* Size of a dma descriptors */
56
#define GRPCI2DMA_BD_CHAN_SIZE 0x10
57
#define GRPCI2DMA_BD_DATA_SIZE 0x10
58
59
/* Alignment of dma descriptors */
60
#define GRPCI2DMA_BD_CHAN_ALIGN 0x10
61
#define GRPCI2DMA_BD_DATA_ALIGN 0x10
62
63
/* User-helper functions to allocate/deallocate
64
* channel and data descriptors
65
*/
66
extern
void
* grpci2dma_channel_new(
int
number);
67
extern
void
grpci2dma_channel_delete(
void
* chanbd);
68
extern
void
* grpci2dma_data_new(
int
number);
69
extern
void
grpci2dma_data_delete(
void
* databd);
70
71
/* Function:
72
* -grpci2dma_prepare
73
* Description:
74
* -Prepare a transfer, initializing the required data descriptors
75
* Parameters:
76
* -pci_start: Where in PCI/remote starts the transfer
77
* -ahb_start: Where in AHB/local starts the transfer
78
* -dir: Direction of the transfer (AHBTOPCI or PCITOAHB)
79
* -endianness: Endianness of the transfer (LITTLEENDIAN or BIGENDIAN)
80
* -size: Size in bytes of the transfer (the function will calculate if there
81
* are enough descriptors)
82
* -databd: Pointer to the data descriptor buffer
83
* -bdindex: Where in the buffer to start the transfer
84
* -bdmax: Maximum index for the data descriptor buffer
85
* -block_size: Size in bytes for each PCI transaction (or block). Guaranteed
86
* to be at least smaller that this value. Put 0 to use default.
87
* Default is maximum, which is 0x10000*4 bytes.
88
* Returns:
89
* -WRONGPTR: Wrong input parameters
90
* -TOOMANY: Not enough data descriptors in the buffer
91
* -value > 0: A positive return value means the number of data descriptors
92
* prepared/used in the buffer, starting from index.
93
*/
94
#define GRPCI2DMA_AHBTOPCI 1
95
#define GRPCI2DMA_PCITOAHB 0
96
#define GRPCI2DMA_LITTLEENDIAN 1
97
#define GRPCI2DMA_BIGENDIAN 0
98
extern
int
grpci2dma_prepare(
99
uint32_t pci_start, uint32_t ahb_start,
int
dir,
int
endianness,
100
int
size,
void
* databd,
int
bdindex,
int
bdmax,
int
block_size);
101
102
/* Function:
103
* -grpci2dma_status
104
* Description:
105
* -Status of an transfer:
106
* Parameters:
107
* -databd: Pointer to the data descriptor buffer
108
* -bdindex: Where in the buffer starts the transfer
109
* -bdsize: Number of descriptors used by the transfer
110
* Returns:
111
* -WRONGPTR: Wrong input parameters
112
* -GRPCI2DMA_BD_DATA_STATUS_ERR: If at least one of the descriptors has an
113
* error
114
* -GRPCI2DMA_BD_DATA_STATUS_ENABLED: If at least one of the descriptors is
115
* enabled, which means that the transfer is still not finished.
116
* -GRPCI2DMA_BD_DATA_STATUS_DISABLED: If all the descriptors are disabled,
117
* which means that either the transfer finished or it was never prepared.
118
*/
119
#define GRPCI2DMA_BD_STATUS_DISABLED 0
120
#define GRPCI2DMA_BD_STATUS_ENABLED 1
121
#define GRPCI2DMA_BD_STATUS_ERR 2
122
extern
int
grpci2dma_status(
void
*databd,
int
bdindex,
int
bdsize);
123
124
/* Function Interrupt-Code ISR callback prototype.
125
* arg - Custom arg provided by user
126
* cid - Channel ID that got the interrupt
127
* status - Error status of the DMA core
128
*/
129
typedef
void (*grpci2dma_isr_t)(
void
*arg,
int
cid,
unsigned
int
status);
130
131
/* Function:
132
* -grpci2dma_isr_register
133
* Description:
134
* -Register an ISR for a channel (and enable interrupts if disabled)
135
* Parameters:
136
* -chan_no: ID of the channel
137
* -dmaisr: ISR
138
* -arg: Argument to pass to the ISR when called
139
* Returns:
140
* -NOINIT: GRPCI2 DMA not initialized
141
* -WRONGPTR: Wrong input parameters
142
* -OK (=0): Done
143
*/
144
extern
int
grpci2dma_isr_register(
145
int
chan_no, grpci2dma_isr_t dmaisr,
void
*arg);
146
147
/* Function:
148
* -grpci2dma_isr_unregister
149
* Description:
150
* -Unregister an ISR for a channel (and enable interrupts if disabled)
151
* Parameters:
152
* -chan_no: ID of the channel
153
* Returns:
154
* -NOINIT: GRPCI2 DMA not initialized
155
* -WRONGPTR: Wrong input parameters
156
* -OK (=0): Done
157
*/
158
extern
int
grpci2dma_isr_unregister(
int
chan_no);
159
160
/* Function:
161
* -grpci2dma_open
162
* Description:
163
* -Open a channel (and allocate the descriptor if the user does not provide
164
* one).
165
* Parameters:
166
* -chan: Descriptor for the channel (must be aligned to 0x10)
167
* Returns:
168
* -NOINIT: GRPCI2 DMA not initialized
169
* -TOOMANY: Maximum number of channels already opened.
170
* -WRONGPTR: Wrong input parameters
171
* -ERROR: Inconsistent state found in driver
172
* -value > 0: A positive return value means the id for the channel.
173
*/
174
extern
int
grpci2dma_open(
void
* chan);
175
176
/* Function:
177
* -grpci2dma_close
178
* Description:
179
* -Stop and close a channel (and deallocate it if the user did not provide a
180
* pointer when opening it)
181
* Parameters:
182
* -chan_no: Id of the channel
183
* Returns:
184
* -NOINIT: GRPCI2 DMA not initialized
185
* -NOTFOUND: Channel not opened.
186
* -STOPDMA: Cannot stop channel.
187
* -WRONGPTR: Wrong input parameters
188
* -OK (=0): Done.
189
*/
190
extern
int
grpci2dma_close(
int
chan_no);
191
192
/* Function:
193
* -grpci2dma_start
194
* Description:
195
* -Start a channel
196
* Parameters:
197
* -chan_no: Id of the channel
198
* -options: Maximum number of data descriptors to be executed before moving
199
* to next channel (up to 0x10000)
200
* Returns:
201
* -NOINIT: GRPCI2 DMA not initialized
202
* -WRONGPTR: Wrong input parameters
203
* -ERROR: Inconsistent state found in driver
204
* -OK (=0): Done.
205
*/
206
extern
int
grpci2dma_start(
int
chan_no,
int
options);
207
208
/* Function:
209
* -grpci2dma_stop
210
* Description:
211
* -Start a channel
212
* Parameters:
213
* -chan_no: Id of the channel
214
* Returns:
215
* -NOINIT: GRPCI2 DMA not initialized
216
* -WRONGPTR: Wrong input parameters
217
* -ERROR: Inconsistent state found in driver
218
* -OK (=0): Done.
219
*/
220
extern
int
grpci2dma_stop(
int
chan_no);
221
222
/* Function:
223
* -grpci2dma_push
224
* Description:
225
* -Push a transfer into a channel (already started or not)
226
* Parameters:
227
* -chan_no: Id of the channel
228
* -databd: Pointer to the data descriptor buffer
229
* -bdindex: Where in the buffer starts the transfer
230
* -bdsize: Number of descriptors used by the transfer
231
* Returns:
232
* -NOINIT: GRPCI2 DMA not initialized
233
* -WRONGPTR: Wrong input parameters
234
* -NOTFOUND: Channel not opened.
235
* -OK (=0): Done.
236
*/
237
extern
int
grpci2dma_push(
int
chan_no,
void
*databd,
int
bdindex,
int
bdsize);
238
239
/* Function:
240
* -grpci2dma_active
241
* Description:
242
* -Check if dma is active
243
* Parameters:
244
* Returns:
245
* -(!=0): Active.
246
* -(=0): Not active.
247
*/
248
extern
int
grpci2dma_active(
void
);
249
250
/* Function:
251
* -grpci2dma_interrupt_enable
252
* Description:
253
* -Enable interrupt for a transfer
254
* Parameters:
255
* -databd: Pointer to the data descriptor buffer
256
* -bdindex: Where in the buffer starts the transfer
257
* -bdmax: Upper limit for index. index < bdmax
258
* -options:
259
* (=GRPCI2DMA_OPTIONS_ALL)=Enable interrupt on all transfer descriptors.
260
* (=GRPCI2DMA_OPTIONS_ONE)=Enable interrupt on transfer descriptor
261
* indicated by bdindex.
262
* Returns:
263
* -NOINIT: GRPCI2 DMA not initialized
264
* -WRONGPTR: Wrong input parameters
265
* -ERROR: Inconsistent state found in driver
266
* -OK (=0): Done.
267
*/
268
#define GRPCI2DMA_OPTIONS_ALL 1
269
#define GRPCI2DMA_OPTIONS_ONE 0
270
extern
int
grpci2dma_interrupt_enable(
271
void
*databd,
int
bdindex,
int
bdmax,
int
options);
272
273
/* Debug function: print dma channel and associated data descriptors.
274
* Only prints if driver internal DEBUG flag is defined. */
275
extern
int
grpci2dma_print(
int
chan_no);
276
extern
int
grpci2dma_print_bd(
void
* data);
277
278
#ifdef __cplusplus
279
}
280
#endif
281
282
#endif
/* __GRPCI2DMA_H__ */
Generated by
1.18.0