![]() |
|
|||
File indexing completed on 2025-05-11 08:23:43
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * GRPCI2 DMA Driver 0005 * 0006 * COPYRIGHT (c) 2017 0007 * Cobham Gaisler AB 0008 * 0009 * Redistribution and use in source and binary forms, with or without 0010 * modification, are permitted provided that the following conditions 0011 * are met: 0012 * 1. Redistributions of source code must retain the above copyright 0013 * notice, this list of conditions and the following disclaimer. 0014 * 2. Redistributions in binary form must reproduce the above copyright 0015 * notice, this list of conditions and the following disclaimer in the 0016 * documentation and/or other materials provided with the distribution. 0017 * 0018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0028 * POSSIBILITY OF SUCH DAMAGE. 0029 * 0030 * OVERVIEW 0031 * ======== 0032 * This driver controls the DMA on the GRPCI2 device, located 0033 * at an on-chip AMBA. 0034 */ 0035 0036 #ifndef __GRPCI2DMA_H__ 0037 #define __GRPCI2DMA_H__ 0038 0039 #include <stdint.h> 0040 #include <stdio.h> 0041 0042 #ifdef __cplusplus 0043 extern "C" { 0044 #endif 0045 0046 /* Error return codes */ 0047 #define GRPCI2DMA_ERR_OK 0 0048 #define GRPCI2DMA_ERR_WRONGPTR -1 0049 #define GRPCI2DMA_ERR_NOINIT -2 0050 #define GRPCI2DMA_ERR_TOOMANY -3 0051 #define GRPCI2DMA_ERR_ERROR -4 0052 #define GRPCI2DMA_ERR_STOPDMA -5 0053 #define GRPCI2DMA_ERR_NOTFOUND -6 0054 0055 /* Size of a dma descriptors */ 0056 #define GRPCI2DMA_BD_CHAN_SIZE 0x10 0057 #define GRPCI2DMA_BD_DATA_SIZE 0x10 0058 0059 /* Alignment of dma descriptors */ 0060 #define GRPCI2DMA_BD_CHAN_ALIGN 0x10 0061 #define GRPCI2DMA_BD_DATA_ALIGN 0x10 0062 0063 /* User-helper functions to allocate/deallocate 0064 * channel and data descriptors 0065 */ 0066 extern void * grpci2dma_channel_new(int number); 0067 extern void grpci2dma_channel_delete(void * chanbd); 0068 extern void * grpci2dma_data_new(int number); 0069 extern void grpci2dma_data_delete(void * databd); 0070 0071 /* Function: 0072 * -grpci2dma_prepare 0073 * Description: 0074 * -Prepare a transfer, initializing the required data descriptors 0075 * Parameters: 0076 * -pci_start: Where in PCI/remote starts the transfer 0077 * -ahb_start: Where in AHB/local starts the transfer 0078 * -dir: Direction of the transfer (AHBTOPCI or PCITOAHB) 0079 * -endianness: Endianness of the transfer (LITTLEENDIAN or BIGENDIAN) 0080 * -size: Size in bytes of the transfer (the function will calculate if there 0081 * are enough descriptors) 0082 * -databd: Pointer to the data descriptor buffer 0083 * -bdindex: Where in the buffer to start the transfer 0084 * -bdmax: Maximum index for the data descriptor buffer 0085 * -block_size: Size in bytes for each PCI transaction (or block). Guaranteed 0086 * to be at least smaller that this value. Put 0 to use default. 0087 * Default is maximum, which is 0x10000*4 bytes. 0088 * Returns: 0089 * -WRONGPTR: Wrong input parameters 0090 * -TOOMANY: Not enough data descriptors in the buffer 0091 * -value > 0: A positive return value means the number of data descriptors 0092 * prepared/used in the buffer, starting from index. 0093 */ 0094 #define GRPCI2DMA_AHBTOPCI 1 0095 #define GRPCI2DMA_PCITOAHB 0 0096 #define GRPCI2DMA_LITTLEENDIAN 1 0097 #define GRPCI2DMA_BIGENDIAN 0 0098 extern int grpci2dma_prepare( 0099 uint32_t pci_start, uint32_t ahb_start, int dir, int endianness, 0100 int size, void * databd, int bdindex, int bdmax, int block_size); 0101 0102 /* Function: 0103 * -grpci2dma_status 0104 * Description: 0105 * -Status of an transfer: 0106 * Parameters: 0107 * -databd: Pointer to the data descriptor buffer 0108 * -bdindex: Where in the buffer starts the transfer 0109 * -bdsize: Number of descriptors used by the transfer 0110 * Returns: 0111 * -WRONGPTR: Wrong input parameters 0112 * -GRPCI2DMA_BD_DATA_STATUS_ERR: If at least one of the descriptors has an 0113 * error 0114 * -GRPCI2DMA_BD_DATA_STATUS_ENABLED: If at least one of the descriptors is 0115 * enabled, which means that the transfer is still not finished. 0116 * -GRPCI2DMA_BD_DATA_STATUS_DISABLED: If all the descriptors are disabled, 0117 * which means that either the transfer finished or it was never prepared. 0118 */ 0119 #define GRPCI2DMA_BD_STATUS_DISABLED 0 0120 #define GRPCI2DMA_BD_STATUS_ENABLED 1 0121 #define GRPCI2DMA_BD_STATUS_ERR 2 0122 extern int grpci2dma_status(void *databd, int bdindex, int bdsize); 0123 0124 /* Function Interrupt-Code ISR callback prototype. 0125 * arg - Custom arg provided by user 0126 * cid - Channel ID that got the interrupt 0127 * status - Error status of the DMA core 0128 */ 0129 typedef void (*grpci2dma_isr_t)(void *arg, int cid, unsigned int status); 0130 0131 /* Function: 0132 * -grpci2dma_isr_register 0133 * Description: 0134 * -Register an ISR for a channel (and enable interrupts if disabled) 0135 * Parameters: 0136 * -chan_no: ID of the channel 0137 * -dmaisr: ISR 0138 * -arg: Argument to pass to the ISR when called 0139 * Returns: 0140 * -NOINIT: GRPCI2 DMA not initialized 0141 * -WRONGPTR: Wrong input parameters 0142 * -OK (=0): Done 0143 */ 0144 extern int grpci2dma_isr_register( 0145 int chan_no, grpci2dma_isr_t dmaisr, void *arg); 0146 0147 /* Function: 0148 * -grpci2dma_isr_unregister 0149 * Description: 0150 * -Unregister an ISR for a channel (and enable interrupts if disabled) 0151 * Parameters: 0152 * -chan_no: ID of the channel 0153 * Returns: 0154 * -NOINIT: GRPCI2 DMA not initialized 0155 * -WRONGPTR: Wrong input parameters 0156 * -OK (=0): Done 0157 */ 0158 extern int grpci2dma_isr_unregister(int chan_no); 0159 0160 /* Function: 0161 * -grpci2dma_open 0162 * Description: 0163 * -Open a channel (and allocate the descriptor if the user does not provide 0164 * one). 0165 * Parameters: 0166 * -chan: Descriptor for the channel (must be aligned to 0x10) 0167 * Returns: 0168 * -NOINIT: GRPCI2 DMA not initialized 0169 * -TOOMANY: Maximum number of channels already opened. 0170 * -WRONGPTR: Wrong input parameters 0171 * -ERROR: Inconsistent state found in driver 0172 * -value > 0: A positive return value means the id for the channel. 0173 */ 0174 extern int grpci2dma_open(void * chan); 0175 0176 /* Function: 0177 * -grpci2dma_close 0178 * Description: 0179 * -Stop and close a channel (and deallocate it if the user did not provide a 0180 * pointer when opening it) 0181 * Parameters: 0182 * -chan_no: Id of the channel 0183 * Returns: 0184 * -NOINIT: GRPCI2 DMA not initialized 0185 * -NOTFOUND: Channel not opened. 0186 * -STOPDMA: Cannot stop channel. 0187 * -WRONGPTR: Wrong input parameters 0188 * -OK (=0): Done. 0189 */ 0190 extern int grpci2dma_close(int chan_no); 0191 0192 /* Function: 0193 * -grpci2dma_start 0194 * Description: 0195 * -Start a channel 0196 * Parameters: 0197 * -chan_no: Id of the channel 0198 * -options: Maximum number of data descriptors to be executed before moving 0199 * to next channel (up to 0x10000) 0200 * Returns: 0201 * -NOINIT: GRPCI2 DMA not initialized 0202 * -WRONGPTR: Wrong input parameters 0203 * -ERROR: Inconsistent state found in driver 0204 * -OK (=0): Done. 0205 */ 0206 extern int grpci2dma_start(int chan_no, int options); 0207 0208 /* Function: 0209 * -grpci2dma_stop 0210 * Description: 0211 * -Start a channel 0212 * Parameters: 0213 * -chan_no: Id of the channel 0214 * Returns: 0215 * -NOINIT: GRPCI2 DMA not initialized 0216 * -WRONGPTR: Wrong input parameters 0217 * -ERROR: Inconsistent state found in driver 0218 * -OK (=0): Done. 0219 */ 0220 extern int grpci2dma_stop(int chan_no); 0221 0222 /* Function: 0223 * -grpci2dma_push 0224 * Description: 0225 * -Push a transfer into a channel (already started or not) 0226 * Parameters: 0227 * -chan_no: Id of the channel 0228 * -databd: Pointer to the data descriptor buffer 0229 * -bdindex: Where in the buffer starts the transfer 0230 * -bdsize: Number of descriptors used by the transfer 0231 * Returns: 0232 * -NOINIT: GRPCI2 DMA not initialized 0233 * -WRONGPTR: Wrong input parameters 0234 * -NOTFOUND: Channel not opened. 0235 * -OK (=0): Done. 0236 */ 0237 extern int grpci2dma_push(int chan_no, void *databd, int bdindex, int bdsize); 0238 0239 /* Function: 0240 * -grpci2dma_active 0241 * Description: 0242 * -Check if dma is active 0243 * Parameters: 0244 * Returns: 0245 * -(!=0): Active. 0246 * -(=0): Not active. 0247 */ 0248 extern int grpci2dma_active(void); 0249 0250 /* Function: 0251 * -grpci2dma_interrupt_enable 0252 * Description: 0253 * -Enable interrupt for a transfer 0254 * Parameters: 0255 * -databd: Pointer to the data descriptor buffer 0256 * -bdindex: Where in the buffer starts the transfer 0257 * -bdmax: Upper limit for index. index < bdmax 0258 * -options: 0259 * (=GRPCI2DMA_OPTIONS_ALL)=Enable interrupt on all transfer descriptors. 0260 * (=GRPCI2DMA_OPTIONS_ONE)=Enable interrupt on transfer descriptor 0261 * indicated by bdindex. 0262 * Returns: 0263 * -NOINIT: GRPCI2 DMA not initialized 0264 * -WRONGPTR: Wrong input parameters 0265 * -ERROR: Inconsistent state found in driver 0266 * -OK (=0): Done. 0267 */ 0268 #define GRPCI2DMA_OPTIONS_ALL 1 0269 #define GRPCI2DMA_OPTIONS_ONE 0 0270 extern int grpci2dma_interrupt_enable( 0271 void *databd, int bdindex, int bdmax, int options); 0272 0273 /* Debug function: print dma channel and associated data descriptors. 0274 * Only prints if driver internal DEBUG flag is defined. */ 0275 extern int grpci2dma_print(int chan_no); 0276 extern int grpci2dma_print_bd(void * data); 0277 0278 #ifdef __cplusplus 0279 } 0280 #endif 0281 0282 #endif /* __GRPCI2DMA_H__ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |