1 /*
2 * edma3_drv_init.c
3 *
4 * EDMA3 Driver Initialization Interface Implementation. This file contains
5 * EDMA3 Driver APIs used to:
6 * a) Create/delete EDMA3 Driver Object
7 * b) Open/close EDMA3 Driver Instance.
8 * These APIs are required to initialize EDMA3 properly.
9 *
10 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the
23 * distribution.
24 *
25 * Neither the name of Texas Instruments Incorporated nor the names of
26 * its contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 */
43 /* EDMA3 Driver Internal Header Files */
44 #include <ti/sdo/edma3/drv/src/edma3.h>
45 /* Resource Manager Internal Header Files */
46 #include <ti/sdo/edma3/rm/src/edma3resmgr.h>
48 /* For assert() */
49 /**
50 * Define NDEBUG to ignore assert().
51 * NDEBUG should be defined before including assert.h header file.
52 */
53 #include <assert.h>
56 /* Externel Variables */
57 /*---------------------------------------------------------------------------*/
58 /**
59 * Maximum Resource Manager Instances supported by the EDMA3 Package.
60 */
61 extern const uint32_t EDMA3_MAX_RM_INSTANCES;
64 /**
65 * \brief EDMA3 Resource Manager Objects, tied to each EDMA3 HW Controller.
66 *
67 * Typically one RM object will cater to one EDMA3 HW controller
68 * and will have all the global config information.
69 */
70 extern EDMA3_RM_Obj resMgrObj[EDMA3_MAX_EDMA3_INSTANCES];
73 /**
74 * \brief Region Specific Configuration structure for
75 * EDMA3 controller, to provide region specific Information.
76 *
77 * This configuration info can also be provided by the user at run-time,
78 * while calling EDMA3_RM_open (). If not provided at run-time,
79 * this info will be taken from the config file "edma3_<PLATFORM_NAME>_cfg.c",
80 * for the specified platform.
81 */
82 #ifdef BUILD_C6XDSP
83 extern far EDMA3_RM_InstanceInitConfig *ptrInitCfgArray;
84 #else
85 extern EDMA3_RM_InstanceInitConfig *ptrInitCfgArray;
86 #endif
88 /**
89 * Handles of EDMA3 Resource Manager Instances.
90 *
91 * Used to maintain information of the EDMA3 RM Instances
92 * for each HW controller.
93 * There could be a maximum of EDMA3_MAX_RM_INSTANCES instances per
94 * EDMA3 HW.
95 */
96 #ifdef BUILD_C6XDSP
97 extern far EDMA3_RM_Instance *ptrRMIArray;
98 #else
99 extern EDMA3_RM_Instance *ptrRMIArray;
100 #endif
101 /** Local MemZero function */
102 extern void edma3MemZero(void *dst, uint32_t len);
103 /** Local MemCpy function */
104 extern void edma3MemCpy(void *dst, const void *src, uint32_t len);
106 /**
107 * \brief EDMA3 Driver Objects, tied to each EDMA3 HW Controller.
108 *
109 * Typically one object will cater to one EDMA3 HW controller
110 * and will have all regions' (ARM, DSP etc) specific config information.
111 */
112 #ifdef BUILD_C6XDSP
113 #pragma DATA_SECTION(drvObj, ".fardata:.edma3Globals");
114 #endif
115 EDMA3_DRV_Object drvObj [EDMA3_MAX_EDMA3_INSTANCES];
118 /**
119 * Handles of EDMA3 Driver Instances.
120 *
121 * Used to maintain information of the EDMA3 Driver Instances for
122 * each region, for each HW controller.
123 * There could be as many Driver Instances as there are shadow
124 * regions. Multiple EDMA3 Driver instances on the same shadow
125 * region are NOT allowed.
126 */
127 #ifdef BUILD_C6XDSP
128 #pragma DATA_SECTION(drvInstance, ".fardata:.edma3Globals");
129 #endif
130 EDMA3_DRV_Instance drvInstance [EDMA3_MAX_EDMA3_INSTANCES][EDMA3_MAX_REGIONS];
133 /**
134 * \brief Resources bound to a Channel
135 *
136 * When a request for a channel is made, the resources PaRAM Set and TCC
137 * get bound to that channel. This information is needed internally by the
138 * driver when a request is made to free the channel (Since it is the
139 * responsibility of the driver to free up the channel-associated resources
140 * from the Resource Manager layer).
141 */
142 #ifdef BUILD_C6XDSP
143 #pragma DATA_SECTION(edma3DrvChBoundRes, ".fardata:.edma3Globals");
144 #endif
145 EDMA3_DRV_ChBoundResources edma3DrvChBoundRes [EDMA3_MAX_EDMA3_INSTANCES][EDMA3_MAX_LOGICAL_CH];
148 /**
149 * \brief Event Queue Number for DMA/QDMA Channels.
150 *
151 * If EDMA3_PROGRAM_QUEUE_NUM_REGISTER_INIT_TIME is defined, then the queue
152 * number registers for DMA/QDMA channels will be programmed during init time
153 * only; the queue number registers will NOT be changed during run-time to
154 * avoid (potential) race conditions. The following arrays will be used to
155 * program the DMA/QDMA queue number registers.
156 *
157 * User has to provide the array values depending on the resources'
158 * availability and the system requirements.
159 *
160 */
161 #ifdef EDMA3_PROGRAM_QUEUE_NUM_REGISTER_INIT_TIME
162 #ifdef BUILD_C6XDSP
163 #pragma DATA_SECTION(edma3DmaQdmaQueueNumConfig, ".fardata:.edma3Globals");
164 #endif
165 EDMA3_DRV_DmaQdmaQueueNum edma3DmaQdmaQueueNumConfig = {
166 {
167 /* DMA Channels 0-63 */
168 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
169 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
170 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
171 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
172 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
173 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
174 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
175 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
176 },
178 {
179 /* QDMA Channels 0-7 */
180 0u, 1u, 0u, 1u, 0u, 1u, 0u, 1u,
181 },
182 };
183 #endif
185 /**
186 * Used to reset the Internal EDMA3 Driver Data Structures for the first time.
187 */
188 #ifdef BUILD_C6XDSP
189 #pragma DATA_SECTION(drvInitDone, ".fardata:.edma3Globals");
190 #endif
191 static uint16_t drvInitDone = FALSE;
193 /* Local functions prototypes */
194 /*---------------------------------------------------------------------------*/
195 /**
196 * Local function to prepare the init config structure for
197 * open of Resource Manager
198 */
199 static EDMA3_DRV_Result edma3OpenResMgr (uint32_t instId,
200 uint32_t regionId,
201 uint16_t flag);
203 /*---------------------------------------------------------------------------*/
205 EDMA3_DRV_Result EDMA3_DRV_create (uint32_t phyCtrllerInstId,
206 const EDMA3_DRV_GblConfigParams *gblCfgParams,
207 const void *miscParam)
208 {
209 uint32_t count = 0;
210 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
211 EDMA3_RM_GblConfigParams rmGblCfgParams;
213 /**
214 * We are NOT checking 'gblCfgParams' for NULL. Whatever user has passed
215 * is given to RM. If user passed NULL, config info from config file will be
216 * taken else user specific info will be passed to the RM.
217 * Similarly, 'miscParam' is not being checked and passed as it is to the
218 * Resource Manager layer.
219 */
220 /* If parameter checking is enabled... */
221 #ifndef EDMA3_DRV_PARAM_CHECK_DISABLE
222 if (phyCtrllerInstId >= EDMA3_MAX_EDMA3_INSTANCES)
223 {
224 result = EDMA3_DRV_E_INVALID_PARAM;
225 }
226 #endif
228 /* Check if the parameters are OK. */
229 if (EDMA3_DRV_SOK == result)
230 {
231 /* Initialize the global variables for the first time */
232 if (FALSE == drvInitDone)
233 {
234 for (count = 0; count < EDMA3_MAX_EDMA3_INSTANCES; count++)
235 {
236 edma3MemZero((void *)&(drvObj[count]),
237 sizeof(EDMA3_DRV_Object));
238 }
239 drvInitDone = TRUE;
240 }
242 /* Initialization has been done */
243 if (drvObj[phyCtrllerInstId].state != EDMA3_DRV_DELETED)
244 {
245 result = EDMA3_DRV_E_OBJ_NOT_DELETED;
246 }
247 else
248 {
249 if (NULL != gblCfgParams)
250 {
251 /* User has passed the configuration info */
252 /* copy the global info */
253 edma3MemCpy((void *)(&drvObj[phyCtrllerInstId].gblCfgParams),
254 (const void *)(gblCfgParams),
255 sizeof (EDMA3_DRV_GblConfigParams));
257 /* Reset the RM global info struct first */
258 edma3MemZero((void *)&(rmGblCfgParams) ,
259 sizeof (EDMA3_RM_GblConfigParams));
261 /* Fill the RM global info struct with the DRV global info */
262 edma3MemCpy((void *)(&rmGblCfgParams),
263 (const void *)(&drvObj[phyCtrllerInstId].gblCfgParams),
264 sizeof (EDMA3_RM_GblConfigParams));
266 result = EDMA3_RM_create(phyCtrllerInstId, (EDMA3_RM_GblConfigParams *)&rmGblCfgParams, miscParam);
267 }
268 else
269 {
270 /* User has not passed any global info. */
271 result = EDMA3_RM_create(phyCtrllerInstId, NULL, miscParam);
273 if (EDMA3_RM_SOK == result)
274 {
275 /**
276 * Copy the global config info from the RM object to the
277 * driver object for future use.
278 */
279 /* Fill the RM global info struct with the DRV global info */
280 edma3MemCpy((void *)(&drvObj[phyCtrllerInstId].gblCfgParams),
281 (const void *)(&resMgrObj[phyCtrllerInstId].gblCfgParams),
282 sizeof (EDMA3_RM_GblConfigParams));
283 }
284 }
286 if (EDMA3_RM_SOK == result)
287 {
288 drvObj[phyCtrllerInstId].state = EDMA3_DRV_CREATED;
289 drvObj[phyCtrllerInstId].numOpens = 0;
290 drvObj[phyCtrllerInstId].phyCtrllerInstId = phyCtrllerInstId;
292 /* Make all the Driver instances for this EDMA3 HW NULL */
293 for (count = 0; count < drvObj[phyCtrllerInstId].gblCfgParams.numRegions; count++)
294 {
295 edma3MemZero((void *)&(drvInstance[phyCtrllerInstId][count]),
296 sizeof(EDMA3_DRV_Instance));
297 }
299 /* Reset edma3DrvChBoundRes Array*/
300 for (count = 0; count < EDMA3_MAX_LOGICAL_CH; count++)
301 {
302 edma3DrvChBoundRes[phyCtrllerInstId][count].paRAMId = -1;
303 edma3DrvChBoundRes[phyCtrllerInstId][count].tcc = EDMA3_MAX_TCC;
304 edma3DrvChBoundRes[phyCtrllerInstId][count].trigMode =
305 EDMA3_DRV_TRIG_MODE_NONE;
306 }
307 }
310 /* Initialize the Queue Number Registers, if required. */
311 #ifdef EDMA3_PROGRAM_QUEUE_NUM_REGISTER_INIT_TIME
312 if (EDMA3_RM_SOK == result)
313 {
314 volatile EDMA3_CCRL_Regs *globalRegs = NULL;
316 globalRegs = (volatile EDMA3_CCRL_Regs *)(drvObj[phyCtrllerInstId].gblCfgParams.globalRegs);
318 if (NULL != globalRegs)
319 {
320 /* Initialize DMA Queue Num Registers */
321 for (count = 0;
322 count < drvObj[phyCtrllerInstId].gblCfgParams.numDmaChannels;
323 count++)
324 {
325 globalRegs->DMAQNUM[count >> 3u] &= EDMA3_DRV_DMAQNUM_CLR_MASK(count);
326 globalRegs->DMAQNUM[count >> 3u] |= EDMA3_DRV_DMAQNUM_SET_MASK(count,
327 edma3DmaQdmaQueueNumConfig.dmaChannelQueueNum[count]);
328 }
330 /* Initialize QDMA Queue Num Registers */
331 for (count = 0;
332 count < drvObj[phyCtrllerInstId].gblCfgParams.numQdmaChannels;
333 count++)
334 {
335 globalRegs->QDMAQNUM &= EDMA3_DRV_QDMAQNUM_CLR_MASK(count);
336 globalRegs->QDMAQNUM |= EDMA3_DRV_QDMAQNUM_SET_MASK(count,
337 edma3DmaQdmaQueueNumConfig.qdmaChannelQueueNum[count]);
338 }
339 }
340 }
341 #endif
342 }
343 }
345 return result;
346 }
348 EDMA3_DRV_Result EDMA3_DRV_delete(uint32_t phyCtrllerInstId,
349 const void *param)
350 {
351 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
353 /*to remove CCS remark: parameter "param" was never referenced */
354 (void)param;
356 /* If parameter checking is enabled... */
357 #ifndef EDMA3_DRV_PARAM_CHECK_DISABLE
358 if (phyCtrllerInstId >= EDMA3_MAX_EDMA3_INSTANCES)
359 {
360 result = EDMA3_DRV_E_INVALID_PARAM;
361 }
362 #endif
364 /* Check if the parameters are OK. */
365 if (EDMA3_DRV_SOK == result)
366 {
367 /**
368 * If number of Driver Instances is 0, then state should be
369 * EDMA3_DRV_CLOSED OR EDMA3_DRV_CREATED.
370 */
371 if ((NULL == drvObj[phyCtrllerInstId].numOpens)
372 && ((drvObj[phyCtrllerInstId].state != EDMA3_DRV_CLOSED)
373 && (drvObj[phyCtrllerInstId].state != EDMA3_DRV_CREATED)))
374 {
375 result = EDMA3_DRV_E_OBJ_NOT_CLOSED;
376 }
377 else
378 {
379 /**
380 * If number of Driver Instances is NOT 0, then this function
381 * SHOULD NOT be called by anybody.
382 */
383 if (NULL != drvObj[phyCtrllerInstId].numOpens)
384 {
385 result = EDMA3_DRV_E_INVALID_STATE;
386 }
387 else
388 {
389 /**
390 * State is correct. Delete the RM Object.
391 */
392 result = EDMA3_RM_delete (phyCtrllerInstId, NULL);
394 if (EDMA3_RM_SOK == result)
395 {
396 /** Change state to EDMA3_DRV_DELETED */
397 drvObj[phyCtrllerInstId].state = EDMA3_DRV_DELETED;
399 /* Also, reset the Driver Object Global Config Info */
400 edma3MemZero((void *)&(drvObj[phyCtrllerInstId].gblCfgParams),
401 sizeof(EDMA3_DRV_GblConfigParams));
402 }
403 }
404 }
405 }
407 return result;
408 }
410 EDMA3_DRV_Handle EDMA3_DRV_open (uint32_t phyCtrllerInstId,
411 const EDMA3_DRV_InitConfig *initCfg,
412 EDMA3_DRV_Result *errorCode)
413 {
414 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
415 EDMA3_DRV_Object *drvObject = NULL;
416 EDMA3_DRV_Instance *drvInstanceHandle = NULL;
417 uint32_t intState = 0;
418 volatile EDMA3_CCRL_Regs *globalRegs = NULL;
419 uint16_t flag = 0;
421 /* If parameter checking is enabled... */
422 #ifndef EDMA3_DRV_PARAM_CHECK_DISABLE
423 if (((initCfg == NULL) || (phyCtrllerInstId >= EDMA3_MAX_EDMA3_INSTANCES))
424 || (errorCode == NULL))
425 {
426 result = EDMA3_DRV_E_INVALID_PARAM;
427 }
428 #endif
430 /* Check if the parameters are OK. */
431 if (EDMA3_DRV_SOK == result)
432 {
433 /* Check whether the semaphore handle is null or not */
434 if (NULL== initCfg->drvSemHandle)
435 {
436 result = EDMA3_DRV_E_INVALID_PARAM;
437 }
438 else
439 {
440 drvObject = &drvObj[phyCtrllerInstId];
441 if (NULL == drvObject)
442 {
443 result = EDMA3_DRV_E_INVALID_PARAM;
444 }
445 else
446 {
447 if (initCfg->regionId >= drvObject->gblCfgParams.numRegions)
448 {
449 result = EDMA3_DRV_E_INVALID_PARAM;
450 }
451 else
452 {
453 /* if no instance is opened and this is the first one,
454 * then state should be created/closed.
455 */
456 if (((drvObject->numOpens == NULL) && (drvObject->state != EDMA3_DRV_CREATED))
457 && (drvObject->state != EDMA3_DRV_CLOSED))
458 {
459 result = EDMA3_DRV_E_INVALID_STATE;
460 }
461 else
462 {
463 /* if num of instances opened is more than 0 and less than no of regions,
464 * then state should be opened.
465 */
466 if (((drvObject->numOpens > 0) && (drvObject->numOpens < drvObject->gblCfgParams.numRegions))
467 && (drvObject->state != EDMA3_DRV_OPENED))
468 {
469 result = EDMA3_DRV_E_INVALID_STATE;
470 }
471 else
472 {
473 /* if a driver instance is already there for a specific region,
474 * it should return an error.
475 */
476 drvInstanceHandle = &drvInstance[phyCtrllerInstId][initCfg->regionId];
477 if (drvInstanceHandle->pDrvObjectHandle != NULL)
478 {
479 drvInstanceHandle = NULL;
480 result = EDMA3_DRV_E_INST_ALREADY_EXISTS;
481 }
482 }
483 }
484 }
485 }
486 }
487 }
489 if (EDMA3_DRV_SOK == result)
490 {
491 /* Save the region specific information in the region specific drv instance*/
492 drvInstanceHandle->regionId = initCfg->regionId;
493 drvInstanceHandle->isMaster = initCfg->isMaster;
494 drvInstanceHandle->drvSemHandle = initCfg->drvSemHandle;
495 drvInstanceHandle->gblerrCbParams.gblerrCb = initCfg->gblerrCb;
496 drvInstanceHandle->gblerrCbParams.gblerrData = initCfg->gblerrData;
498 if (NULL != initCfg->drvInstInitConfig)
499 {
500 edma3MemCpy((void *)(&drvInstanceHandle->drvInstInitConfig),
501 (const void *)(initCfg->drvInstInitConfig),
502 sizeof (EDMA3_DRV_InstanceInitConfig));
504 /* Flag to remember that driver has passed config info to RM */
505 flag = 1u;
506 }
508 if (NULL == drvObject->gblCfgParams.globalRegs)
509 {
510 drvInstanceHandle = NULL;
511 result = EDMA3_DRV_E_INVALID_PARAM;
512 }
513 else
514 {
515 globalRegs = (volatile EDMA3_CCRL_Regs *)drvObject->gblCfgParams.globalRegs;
517 /* Update shadowRegs */
518 drvInstanceHandle->shadowRegs = (EDMA3_CCRL_ShadowRegs *)
519 (&(globalRegs->SHADOW[initCfg->regionId]));
521 result = edma3OpenResMgr (phyCtrllerInstId, initCfg->regionId, flag);
522 if (EDMA3_DRV_SOK != result)
523 {
524 drvInstanceHandle = NULL;
525 }
526 else
527 {
528 drvObject->state = EDMA3_DRV_OPENED;
529 edma3OsProtectEntry (phyCtrllerInstId,
530 EDMA3_OS_PROTECT_INTERRUPT,
531 &intState);
532 drvObject->numOpens++;
533 edma3OsProtectExit (phyCtrllerInstId,
534 EDMA3_OS_PROTECT_INTERRUPT,
535 intState);
536 }
537 }
538 }
540 if (errorCode)
541 *errorCode = result;
542 return (EDMA3_DRV_Handle)drvInstanceHandle;
543 }
545 EDMA3_DRV_Result EDMA3_DRV_close(EDMA3_DRV_Handle hEdma,
546 const void *param)
547 {
548 uint32_t intState = 0;
549 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
550 EDMA3_DRV_Instance *drvInst = NULL;
551 EDMA3_DRV_Object *drvObject = NULL;
553 /*to remove CCS remark: parameter "param" was never referenced */
554 (void)param;
556 /* If parameter checking is enabled... */
557 #ifndef EDMA3_DRV_PARAM_CHECK_DISABLE
558 if (hEdma == NULL)
559 {
560 result = EDMA3_DRV_E_INVALID_PARAM;
561 }
562 #endif
564 /* Check if the parameters are OK. */
565 if (EDMA3_DRV_SOK == result)
566 {
567 drvInst = (EDMA3_DRV_Instance *)hEdma;
568 drvObject = drvInst->pDrvObjectHandle;
570 if (drvObject == NULL)
571 {
572 result = EDMA3_DRV_E_INVALID_PARAM;
573 }
574 else
575 {
576 /* Check state of driver */
577 if (drvObject->state != EDMA3_DRV_OPENED)
578 {
579 result = EDMA3_DRV_E_OBJ_NOT_OPENED;
580 }
581 else
582 {
583 result = EDMA3_RM_close (drvInst->resMgrInstance, NULL);
585 if (result != EDMA3_RM_SOK)
586 {
587 result = EDMA3_DRV_E_RM_CLOSE_FAIL;
588 }
589 else
590 {
591 /* Set the driver instance specific info null */
592 drvInst->resMgrInstance = NULL;
593 drvInst->pDrvObjectHandle = NULL;
594 edma3MemZero((void *)&(drvInst->drvInstInitConfig),
595 sizeof (EDMA3_DRV_InstanceInitConfig));
596 drvInst->shadowRegs = NULL;
598 edma3OsProtectEntry (drvObject->phyCtrllerInstId,
599 EDMA3_OS_PROTECT_INTERRUPT,
600 &intState);
601 /* Decrease the Number of Opens */
602 --drvObject->numOpens;
603 if (NULL == drvObject->numOpens)
604 {
605 drvObject->state = EDMA3_DRV_CLOSED;
606 }
607 edma3OsProtectExit (drvObject->phyCtrllerInstId,
608 EDMA3_OS_PROTECT_INTERRUPT,
609 intState);
610 }
611 }
612 }
613 }
615 return (result);
616 }
619 /* Definitions of Local functions - Start */
620 /* Local function to prepare the init config structure for open of Resource Manager */
621 static EDMA3_DRV_Result edma3OpenResMgr (uint32_t instId,
622 uint32_t regionId,
623 uint16_t flag)
624 {
625 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
626 EDMA3_RM_Param initParam;
627 EDMA3_RM_InstanceInitConfig rmInstanceCfg;
628 EDMA3_RM_Handle hResMgr = NULL;
629 EDMA3_RM_Result rmResult;
630 uint32_t resMgrIdx = 0u;
631 EDMA3_RM_Instance *temp_rm_instance = NULL;
633 assert ((instId < EDMA3_MAX_EDMA3_INSTANCES)
634 && (regionId < drvObj[instId].gblCfgParams.numRegions));
636 initParam.regionId = regionId;
637 initParam.rmSemHandle = drvInstance[instId][regionId].drvSemHandle;
638 /*
639 * If the EDMA driver instance is MASTER, do the
640 * (global + region_specific) init. For all other instances,
641 * only do the (region_specific) init.
642 */
643 initParam.isMaster = drvInstance[instId][regionId].isMaster;
644 initParam.regionInitEnable = TRUE;
646 initParam.gblerrCbParams.gblerrCb = drvInstance[instId][regionId].gblerrCbParams.gblerrCb;
647 initParam.gblerrCbParams.gblerrData = drvInstance[instId][regionId].gblerrCbParams.gblerrData;
649 if (flag == 1u)
650 {
651 /**
652 * User has passed the instance initialization specific info,
653 * which we have saved previously too, so use it.
654 */
655 edma3MemCpy((void *)(&rmInstanceCfg),
656 (const void *)(&drvInstance[instId][regionId].drvInstInitConfig),
657 sizeof (EDMA3_RM_InstanceInitConfig));
659 initParam.rmInstInitConfig = &rmInstanceCfg;
661 hResMgr = EDMA3_RM_open (instId, (EDMA3_RM_Param *)&initParam, &rmResult);
663 if (NULL == hResMgr)
664 {
665 result = rmResult;
666 }
667 }
668 else
669 {
670 /**
671 * User has NOT passed the instance initialization specific info.
672 * Pass NULL to the Resource Manager.
673 */
674 initParam.rmInstInitConfig = NULL;
676 hResMgr = EDMA3_RM_open (instId, (EDMA3_RM_Param *)&initParam, &rmResult);
678 if (NULL == hResMgr)
679 {
680 result = rmResult;
681 }
682 else
683 {
684 /**
685 * Save the RM Instance specific information in the driver.
686 * Earlier this was easier, now a bit tricky.
687 * Search for the RM instance number based on the handle
688 * just returned, to fetch the correct config info from the
689 * userInitConfig[].
690 */
691 for (resMgrIdx = 0u; resMgrIdx < EDMA3_MAX_RM_INSTANCES; resMgrIdx++)
692 {
693 temp_rm_instance = ((EDMA3_RM_Instance *)(ptrRMIArray) + (instId*EDMA3_MAX_RM_INSTANCES) + resMgrIdx);
695 if (hResMgr == temp_rm_instance)
696 {
697 /* RM Id found. Copy the specific config info to the drvInstance [] */
698 edma3MemCpy((void *)(&drvInstance[instId][regionId].drvInstInitConfig),
699 (const void *)((EDMA3_RM_InstanceInitConfig *)(ptrInitCfgArray) + (instId*EDMA3_MAX_RM_INSTANCES) + resMgrIdx),
700 sizeof (EDMA3_RM_InstanceInitConfig));
701 break;
702 }
703 }
705 if (EDMA3_MAX_RM_INSTANCES == resMgrIdx)
706 {
707 /* RM Id not found, report error... */
708 result = EDMA3_DRV_E_INVALID_PARAM;
709 }
710 }
711 }
714 if (EDMA3_RM_SOK == result)
715 {
716 /* Save handle to Resource Manager Instance */
717 drvInstance[instId][regionId].resMgrInstance = hResMgr;
718 /* Save handle to EDMA Driver Object */
719 drvInstance[instId][regionId].pDrvObjectHandle = &drvObj[instId];
720 }
722 return result;
723 }
725 EDMA3_DRV_Result EDMA3_DRV_initXbarEventMap (EDMA3_DRV_Handle hEdma,
726 const EDMA3_DRV_GblXbarToChanConfigParams * edmaGblXbarConfig,
727 EDMA3_DRV_mapXbarEvtToChan mapXbarEvtFunc,
728 EDMA3_DRV_xbarConfigScr configXbarScr)
729 {
730 EDMA3_DRV_Result result = EDMA3_DRV_SOK;
731 EDMA3_DRV_Instance *drvInst = NULL;
733 /* If parameter checking is enabled... */
734 #ifndef EDMA3_DRV_PARAM_CHECK_DISABLE
735 if (hEdma == NULL)
736 {
737 result = EDMA3_DRV_E_INVALID_PARAM;
738 }
739 #endif
741 /* Check if the parameters are OK. */
742 if (EDMA3_DRV_SOK == result)
743 {
744 drvInst = (EDMA3_DRV_Instance *)hEdma;
746 if (mapXbarEvtFunc != NULL)
747 {
748 drvInst->mapXbarToChan = mapXbarEvtFunc;
749 }
750 if (configXbarScr != NULL)
751 {
752 drvInst->configScrMapXbarToEvt = configXbarScr;
753 }
754 if (edmaGblXbarConfig != NULL)
755 {
756 edma3MemCpy((void *)(&drvInst->drvXbarToEvtMapConfig),
757 (const void *)(edmaGblXbarConfig),
758 sizeof (EDMA3_DRV_GblXbarToChanConfigParams));
759 }
760 result = EDMA3_RM_initXbarEventMap(drvInst->resMgrInstance,
761 (const EDMA3_RM_GblXbarToChanConfigParams *)&drvInst->drvXbarToEvtMapConfig,
762 (EDMA3_RM_mapXbarEvtToChan)drvInst->mapXbarToChan,
763 (EDMA3_RM_xbarConfigScr)drvInst->configScrMapXbarToEvt);
764 }
766 return (result);
767 }
768 /* Definitions of Local functions - End */
770 /* End of File */