RTEMS  5.1
grpci2dma.h
1 /*
2  * GRPCI2 DMA Driver
3  *
4  * COPYRIGHT (c) 2017
5  * Cobham Gaisler AB
6  *
7  * The license and distribution terms for this file may be
8  * found in the file LICENSE in this distribution or at
9  * http://www.rtems.org/license/LICENSE.
10  *
11  * OVERVIEW
12  * ========
13  * This driver controls the DMA on the GRPCI2 device, located
14  * at an on-chip AMBA.
15  */
16 
17 #ifndef __GRPCI2DMA_H__
18 #define __GRPCI2DMA_H__
19 
20 #include <stdint.h>
21 #include <stdio.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Error return codes */
28 #define GRPCI2DMA_ERR_OK 0
29 #define GRPCI2DMA_ERR_WRONGPTR -1
30 #define GRPCI2DMA_ERR_NOINIT -2
31 #define GRPCI2DMA_ERR_TOOMANY -3
32 #define GRPCI2DMA_ERR_ERROR -4
33 #define GRPCI2DMA_ERR_STOPDMA -5
34 #define GRPCI2DMA_ERR_NOTFOUND -6
35 
36 /* Size of a dma descriptors */
37 #define GRPCI2DMA_BD_CHAN_SIZE 0x10
38 #define GRPCI2DMA_BD_DATA_SIZE 0x10
39 
40 /* Alignment of dma descriptors */
41 #define GRPCI2DMA_BD_CHAN_ALIGN 0x10
42 #define GRPCI2DMA_BD_DATA_ALIGN 0x10
43 
44 /* User-helper functions to allocate/deallocate
45  * channel and data descriptors
46  */
47 extern void * grpci2dma_channel_new(int number);
48 extern void grpci2dma_channel_delete(void * chanbd);
49 extern void * grpci2dma_data_new(int number);
50 extern void grpci2dma_data_delete(void * databd);
51 
52 /* Function:
53  * -grpci2dma_prepare
54  * Description:
55  * -Prepare a transfer, initializing the required data descriptors
56  * Parameters:
57  * -pci_start: Where in PCI/remote starts the transfer
58  * -ahb_start: Where in AHB/local starts the transfer
59  * -dir: Direction of the transfer (AHBTOPCI or PCITOAHB)
60  * -endianness: Endianness of the transfer (LITTLEENDIAN or BIGENDIAN)
61  * -size: Size in bytes of the transfer (the function will calculate if there
62  * are enough descriptors)
63  * -databd: Pointer to the data descriptor buffer
64  * -bdindex: Where in the buffer to start the transfer
65  * -bdmax: Maximum index for the data descriptor buffer
66  * -block_size: Size in bytes for each PCI transaction (or block). Guaranteed
67  * to be at least smaller that this value. Put 0 to use default.
68  * Default is maximum, which is 0x10000*4 bytes.
69  * Returns:
70  * -WRONGPTR: Wrong input parameters
71  * -TOOMANY: Not enough data descriptors in the buffer
72  * -value > 0: A positive return value means the number of data descriptors
73  * prepared/used in the buffer, starting from index.
74  */
75 #define GRPCI2DMA_AHBTOPCI 1
76 #define GRPCI2DMA_PCITOAHB 0
77 #define GRPCI2DMA_LITTLEENDIAN 1
78 #define GRPCI2DMA_BIGENDIAN 0
79 extern int grpci2dma_prepare(
80  uint32_t pci_start, uint32_t ahb_start, int dir, int endianness,
81  int size, void * databd, int bdindex, int bdmax, int block_size);
82 
83 /* Function:
84  * -grpci2dma_status
85  * Description:
86  * -Status of an transfer:
87  * Parameters:
88  * -databd: Pointer to the data descriptor buffer
89  * -bdindex: Where in the buffer starts the transfer
90  * -bdsize: Number of descriptors used by the transfer
91  * Returns:
92  * -WRONGPTR: Wrong input parameters
93  * -GRPCI2DMA_BD_DATA_STATUS_ERR: If at least one of the descriptors has an
94  * error
95  * -GRPCI2DMA_BD_DATA_STATUS_ENABLED: If at least one of the descriptors is
96  * enabled, which means that the transfer is still not finished.
97  * -GRPCI2DMA_BD_DATA_STATUS_DISABLED: If all the descriptors are disabled,
98  * which means that either the transfer finished or it was never prepared.
99  */
100 #define GRPCI2DMA_BD_STATUS_DISABLED 0
101 #define GRPCI2DMA_BD_STATUS_ENABLED 1
102 #define GRPCI2DMA_BD_STATUS_ERR 2
103 extern int grpci2dma_status(void *databd, int bdindex, int bdsize);
104 
105 /* Function Interrupt-Code ISR callback prototype.
106  * arg - Custom arg provided by user
107  * cid - Channel ID that got the interrupt
108  * status - Error status of the DMA core
109  */
110 typedef void (*grpci2dma_isr_t)(void *arg, int cid, unsigned int status);
111 
112 /* Function:
113  * -grpci2dma_isr_register
114  * Description:
115  * -Register an ISR for a channel (and enable interrupts if disabled)
116  * Parameters:
117  * -chan_no: ID of the channel
118  * -dmaisr: ISR
119  * -arg: Argument to pass to the ISR when called
120  * Returns:
121  * -NOINIT: GRPCI2 DMA not initialized
122  * -WRONGPTR: Wrong input parameters
123  * -OK (=0): Done
124  */
125 extern int grpci2dma_isr_register(
126  int chan_no, grpci2dma_isr_t dmaisr, void *arg);
127 
128 /* Function:
129  * -grpci2dma_isr_unregister
130  * Description:
131  * -Unregister an ISR for a channel (and enable interrupts if disabled)
132  * Parameters:
133  * -chan_no: ID of the channel
134  * Returns:
135  * -NOINIT: GRPCI2 DMA not initialized
136  * -WRONGPTR: Wrong input parameters
137  * -OK (=0): Done
138  */
139 extern int grpci2dma_isr_unregister(int chan_no);
140 
141 /* Function:
142  * -grpci2dma_open
143  * Description:
144  * -Open a channel (and allocate the descriptor if the user does not provide
145  * one).
146  * Parameters:
147  * -chan: Descriptor for the channel (must be aligned to 0x10)
148  * Returns:
149  * -NOINIT: GRPCI2 DMA not initialized
150  * -TOOMANY: Maximum number of channels already opened.
151  * -WRONGPTR: Wrong input parameters
152  * -ERROR: Inconsistent state found in driver
153  * -value > 0: A positive return value means the id for the channel.
154  */
155 extern int grpci2dma_open(void * chan);
156 
157 /* Function:
158  * -grpci2dma_close
159  * Description:
160  * -Stop and close a channel (and deallocate it if the user did not provide a
161  * pointer when opening it)
162  * Parameters:
163  * -chan_no: Id of the channel
164  * Returns:
165  * -NOINIT: GRPCI2 DMA not initialized
166  * -NOTFOUND: Channel not opened.
167  * -STOPDMA: Cannot stop channel.
168  * -WRONGPTR: Wrong input parameters
169  * -OK (=0): Done.
170  */
171 extern int grpci2dma_close(int chan_no);
172 
173 /* Function:
174  * -grpci2dma_start
175  * Description:
176  * -Start a channel
177  * Parameters:
178  * -chan_no: Id of the channel
179  * -options: Maximum number of data descriptors to be executed before moving
180  * to next channel (up to 0x10000)
181  * Returns:
182  * -NOINIT: GRPCI2 DMA not initialized
183  * -WRONGPTR: Wrong input parameters
184  * -ERROR: Inconsistent state found in driver
185  * -OK (=0): Done.
186  */
187 extern int grpci2dma_start(int chan_no, int options);
188 
189 /* Function:
190  * -grpci2dma_stop
191  * Description:
192  * -Start a channel
193  * Parameters:
194  * -chan_no: Id of the channel
195  * Returns:
196  * -NOINIT: GRPCI2 DMA not initialized
197  * -WRONGPTR: Wrong input parameters
198  * -ERROR: Inconsistent state found in driver
199  * -OK (=0): Done.
200  */
201 extern int grpci2dma_stop(int chan_no);
202 
203 /* Function:
204  * -grpci2dma_push
205  * Description:
206  * -Push a transfer into a channel (already started or not)
207  * Parameters:
208  * -chan_no: Id of the channel
209  * -databd: Pointer to the data descriptor buffer
210  * -bdindex: Where in the buffer starts the transfer
211  * -bdsize: Number of descriptors used by the transfer
212  * Returns:
213  * -NOINIT: GRPCI2 DMA not initialized
214  * -WRONGPTR: Wrong input parameters
215  * -NOTFOUND: Channel not opened.
216  * -OK (=0): Done.
217  */
218 extern int grpci2dma_push(int chan_no, void *databd, int bdindex, int bdsize);
219 
220 /* Function:
221  * -grpci2dma_active
222  * Description:
223  * -Check if dma is active
224  * Parameters:
225  * Returns:
226  * -(!=0): Active.
227  * -(=0): Not active.
228  */
229 extern int grpci2dma_active(void);
230 
231 /* Function:
232  * -grpci2dma_interrupt_enable
233  * Description:
234  * -Enable interrupt for a transfer
235  * Parameters:
236  * -databd: Pointer to the data descriptor buffer
237  * -bdindex: Where in the buffer starts the transfer
238  * -bdmax: Upper limit for index. index < bdmax
239  * -options:
240  * (=GRPCI2DMA_OPTIONS_ALL)=Enable interrupt on all transfer descriptors.
241  * (=GRPCI2DMA_OPTIONS_ONE)=Enable interrupt on transfer descriptor
242  * indicated by bdindex.
243  * Returns:
244  * -NOINIT: GRPCI2 DMA not initialized
245  * -WRONGPTR: Wrong input parameters
246  * -ERROR: Inconsistent state found in driver
247  * -OK (=0): Done.
248  */
249 #define GRPCI2DMA_OPTIONS_ALL 1
250 #define GRPCI2DMA_OPTIONS_ONE 0
251 extern int grpci2dma_interrupt_enable(
252  void *databd, int bdindex, int bdmax, int options);
253 
254 /* Debug function: print dma channel and associated data descriptors.
255  * Only prints if driver internal DEBUG flag is defined. */
256 extern int grpci2dma_print(int chan_no);
257 extern int grpci2dma_print_bd(void * data);
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif /* __GRPCI2DMA_H__ */
unsigned size
Definition: tte.h:74