This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resourcemgr.c
835 lines (731 loc) · 25.7 KB
/
resourcemgr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
/****************************************************************************
* Copyright (c) 2011 Texas Instruments Incorporated - http://www.ti.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
/*
* @file resourcemgr.c
*
* @brief
* This file implements the common configuration of the resource manager for
* the application to use.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "ti/platform/resource_mgr.h"
/* PASS RL file */
#include <ti/csl/cslr_pa_ss.h>
/* Firmware images */
#include <ti/drv/qmss/qmss_firmware.h>
#include <ti/drv/pa/fw/classify1_bin.c>
#include <ti/drv/pa/fw/classify2_bin.c>
#include <ti/drv/pa/fw/pam_bin.c>
/* PA definitions */
#define MAX_NUM_L2_HANDLES 10
#define MAX_NUM_L3_HANDLES 20
#define MAX_NUM_L4_HANDLES 40
#define BUFSIZE_PA_INST 256
#define BUFSIZE_L2_TABLE 1000
#define BUFSIZE_L3_TABLE 4000
/**********************************************************************
************************** Global Variables **************************
**********************************************************************/
/* Host Descriptor Region - [Size of descriptor * Number of descriptors]
*
* MUST be cache line byte aligned.
*/
#pragma DATA_SECTION(gHostDesc, ".resmgr_memregion");
#pragma DATA_ALIGN (gHostDesc, 128)
uint8_t gHostDesc[MAX_DESC_SIZE * MAX_NUM_DESC];
/* This is the global free queue for QMSS. It holds all free descriptors which can be used */
#pragma DATA_SECTION(gGlobalFreeQHnd, ".resmgr_handles");
Qmss_QueueHnd gGlobalFreeQHnd;
/* Channels handles for CPPI DMA support of the Packet Accelerator (PA) */
#pragma DATA_SECTION(gPassCpdmaTxChanHnd, ".resmgr_handles");
#pragma DATA_SECTION(gPassCpdmaRxChanHnd, ".resmgr_handles");
#pragma DATA_SECTION(gPassCpdmaHnd, ".resmgr_handles");
Cppi_ChHnd gPassCpdmaTxChanHnd [NUM_PA_TX_QUEUES];
Cppi_ChHnd gPassCpdmaRxChanHnd [NUM_PA_RX_CHANNELS];
Cppi_Handle gPassCpdmaHnd;
/* PA Driver Handle */
#pragma DATA_SECTION(gPAInstHnd, ".resmgr_handles");
Pa_Handle gPAInstHnd;
/* PA instance */
#pragma DATA_SECTION(gPAInst, ".resmgr_pa");
#pragma DATA_ALIGN(gPAInst, 8)
uint8_t gPAInst[BUFSIZE_PA_INST];
/* Memory used for PA handles */
#pragma DATA_SECTION(gMemL2Ram, ".resmgr_pa");
#pragma DATA_ALIGN(gMemL2Ram, 8)
uint8_t gMemL2Ram[BUFSIZE_L2_TABLE];
#pragma DATA_SECTION(gMemL3Ram, ".resmgr_pa");
#pragma DATA_ALIGN(gMemL3Ram, 8)
uint8_t gMemL3Ram[BUFSIZE_L3_TABLE];
/* Global debug counters */
#pragma DATA_SECTION(gQPopErrorCounter, ".resmgr_handles");
uint32_t gQPopErrorCounter;
#pragma DATA_SECTION(gQPushErrorCounter, ".resmgr_handles")
uint32_t gQPushErrorCounter;
/* Configuration Information */
CPPI_CFG_T gCppiCfg[MAX_CPPI_CFG];
/*
* The device specific configuration and initialization routines
* for QMSS Low Level Driver. If the user wants to change the
* default configurations, the below file needs to be modified.
*/
#if defined(DEVICE_K2H)
#include "ti/drv/qmss/device/k2h/src/qmss_device.c"
#else
#if defined(DEVICE_K2K)
#include "ti/drv/qmss/device/k2k/src/qmss_device.c"
#else
#include "ti/drv/qmss/device/qmss_device.c"
#endif
#endif
/*
* The device specific configuration and initialization routines
* for CPPI Low Level Driver. If the user wants to change the
* default configurations, the below file needs to be modified.
*/
#if defined(DEVICE_K2H)
#include "ti/drv/cppi/device/k2h/src/cppi_device.c"
#else
#if defined(DEVICE_K2K)
#include "ti/drv/cppi/device/k2k/src/cppi_device.c"
#else
#include "ti/drv/cppi/device/cppi_device.c"
#endif
#endif
/**********************************************************************
************ Resource Manager QMSS configuration Functions ************
**********************************************************************/
/** ============================================================================
* @n@b res_mgr_qmss_freeq
*
* @b Description
* @n This API returns the handle to the global free queue for QMSS. The global free
* queue maintains all usable descriptors for anyone using QMSS.
*
* @param[in] None
*
* @return
* =============================================================================
*/
Qmss_QueueHnd
res_mgr_qmss_get_freeq (void)
{
return gGlobalFreeQHnd;
}
/** ============================================================================
* @n@b QMSS_QPOP
*
* @b Description
* @n This API implements a the queue pop logic with the Cache Management
*
* @param[in] handler
* Queue handler
* @param[in] type
* Queue handler type
* @param[in] pHostDescriptor
* pointer to descriptor
*
* @return
* @n None
* =============================================================================
*/
int32_t
QMSS_QPOP
(
Qmss_QueueHnd handler,
QHANDLER_TYPE type,
Cppi_HostDesc** pHostDescriptor
)
{
Cppi_HostDesc* pHostDesc = *pHostDescriptor;
pHostDesc = Qmss_queuePop (handler);
/* Get a Tx free descriptor to send a command to the PA PDSP */
if (pHostDesc == NULL)
{
gQPopErrorCounter++;
return -1;
}
/* The descriptor address returned from the hardware has the
* descriptor size appended to the address in the last 4 bits.
*
* To get the true descriptor size, always mask off the last
* 4 bits of the address.
*/
pHostDesc = (Cppi_HostDesc *) ((uint32_t) pHostDesc & 0xFFFFFFF0);
*pHostDescriptor = pHostDesc;
/* Inv cache based on the qhandler type*/
CACHE_invL1d((void *)pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
CACHE_invL2((void *) pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
if (type != QHANDLER_QPOP_FDQ_NO_ATTACHEDBUF) {
/* Not needed for FDQ with no attached buffers pop */
CACHE_invL1d((void *)pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
CACHE_invL2((void *) pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
}
asm (" MFENCE " );
return 0;
}
/** ============================================================================
* @n@b QMSS_QPUSH
*
* @b Description
* @n This API implements a the queue push logic with the Cache Management
*
* @param[in] handler
* Queue handler
* @param[in] descAddr
* Descriptor address
* @param[in] packetSize
* packet Size
* @param[in] descSize
* descriptor Size
* @param[in] location
* Qmss_Location location
* @return
* @n None
* =============================================================================
*/
void
QMSS_QPUSH
(
Qmss_QueueHnd handler,
void *descAddr,
uint32_t packetSize,
uint32_t descSize,
Qmss_Location location
)
{
Cppi_HostDesc* pHostDesc = (Cppi_HostDesc *) descAddr;
if ( descAddr == NULL ) {
gQPushErrorCounter ++;
return;
}
/* Wb data cache */
CACHE_wbL1d((void *)pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
CACHE_wbL2((void *) pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
CACHE_wbL1d((void *)pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
CACHE_wbL2((void *) pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
asm (" MFENCE " );
Qmss_queuePushDescSize (handler,
pHostDesc,
descSize
);
}
/** ============================================================================
* @n@b QMSS_QPUSHDESCSIZE
*
* @b Description
* @n This API implements a the queue push logic with the Cache Management
*
* @param[in] handler
* Queue handler
* @param[in] descAddr
* Descriptor address
* @param[in] descSize
* descriptor Size
* @return
* @n None
* =============================================================================
*/
void
QMSS_QPUSHDESCSIZE
(
Qmss_QueueHnd handler,
void *descAddr,
uint32_t descSize
)
{
Cppi_HostDesc* pHostDesc = (Cppi_HostDesc *) descAddr;
if ( descAddr == NULL ) {
gQPushErrorCounter++;
return;
}
/* Wb data cache */
CACHE_wbL1d((void *)pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
CACHE_wbL2((void *) pHostDesc->buffPtr, pHostDesc->buffLen, CACHE_WAIT);
CACHE_wbL1d((void *)pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
CACHE_wbL2((void *) pHostDesc, sizeof(Cppi_HostDesc), CACHE_WAIT);
asm (" MFENCE " );
Qmss_queuePushDescSize (handler,
pHostDesc,
descSize
);
}
/** ============================================================================
* @n@b res_mgr_init_qmss
*
* @b Description
* @n This API initializes the QMSS LLD.
*
* @param[in] p_qmss_cfg
* Pointer to QMSS_CFG_T
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
int32_t
res_mgr_init_qmss
(
QMSS_CFG_T *p_qmss_cfg
)
{
int32_t result;
Qmss_MemRegInfo memCfg;
Qmss_InitCfg qmssInitConfig;
Cppi_DescCfg cppiDescCfg;
uint32_t numAllocated;
if (p_qmss_cfg->master_core)
{
/* Initialize QMSS */
memset (&qmssInitConfig, 0, sizeof (Qmss_InitCfg));
/* Set up QMSS configuration */
/* Use internal linking RAM */
qmssInitConfig.linkingRAM0Base = 0;
qmssInitConfig.linkingRAM0Size = 0;
qmssInitConfig.linkingRAM1Base = 0x0;
qmssInitConfig.maxDescNum = p_qmss_cfg->max_num_desc;
qmssInitConfig.pdspFirmware[0].pdspId = Qmss_PdspId_PDSP1;
#ifdef _LITTLE_ENDIAN
qmssInitConfig.pdspFirmware[0].firmware = (void *) &acc48_le;
qmssInitConfig.pdspFirmware[0].size = sizeof (acc48_le);
#else
qmssInitConfig.pdspFirmware[0].firmware = (void *) &acc48_be;
qmssInitConfig.pdspFirmware[0].size = sizeof (acc48_be);
#endif
/* Initialize the Queue Manager */
#if defined(DEVICE_K2H) || defined(DEVICE_K2K)
result = Qmss_init (&qmssInitConfig, &qmssGblCfgParams);
#else
result = Qmss_init (&qmssInitConfig, &qmssGblCfgParams[0]);
#endif
if (result != QMSS_SOK)
{
platform_write ("Error initializing Queue Manager SubSystem, Error code : %d\n", result);
return -1;
}
}
/* Start Queue manager on this core */
Qmss_start ();
/* Setup the descriptor memory regions.
*
* The Descriptor base addresses MUST be global addresses and
* all memory regions MUST be setup in ascending order of the
* descriptor base addresses.
*/
/* Initialize and setup CPSW Host Descriptors required for example */
memset (gHostDesc, 0, p_qmss_cfg->desc_size * p_qmss_cfg->max_num_desc);
memCfg.descBase = (uint32_t *) Convert_CoreLocal2GlobalAddr ((uint32_t) gHostDesc);
memCfg.descSize = p_qmss_cfg->desc_size;
memCfg.descNum = p_qmss_cfg->max_num_desc;
memCfg.manageDescFlag = Qmss_ManageDesc_MANAGE_DESCRIPTOR;
memCfg.memRegion = p_qmss_cfg->mem_region;
memCfg.startIndex = 0;
/* Insert Host Descriptor memory region */
result = Qmss_insertMemoryRegion(&memCfg);
if (result == QMSS_MEMREGION_ALREADY_INITIALIZED)
{
platform_write ("Memory Region %d already Initialized \n", memCfg.memRegion);
}
else if (result < QMSS_SOK)
{
platform_write ("Error: Inserting memory region %d, Error code : %d\n", memCfg.memRegion, result);
return -1;
}
/* Initialize all the descriptors we just allocated on the
* memory region above. Setup the descriptors with some well
* known values before we use them for data transfers.
*/
memset (&cppiDescCfg, 0, sizeof (cppiDescCfg));
cppiDescCfg.memRegion = p_qmss_cfg->mem_region;
cppiDescCfg.descNum = p_qmss_cfg->max_num_desc;
cppiDescCfg.destQueueNum = QMSS_PARAM_NOT_SPECIFIED;
cppiDescCfg.queueType = Qmss_QueueType_GENERAL_PURPOSE_QUEUE;
cppiDescCfg.initDesc = Cppi_InitDesc_INIT_DESCRIPTOR;
cppiDescCfg.descType = Cppi_DescType_HOST;
/* By default:
* (1) Return descriptors to tail of queue
* (2) Always return entire packet to this free queue
* (3) Set that PS Data is always present in start of SOP buffer
* (4) Configure free q num < 4K, hence qMgr = 0
* (5) Recycle back to the same Free queue by default.
*/
cppiDescCfg.returnPushPolicy = Qmss_Location_TAIL;
cppiDescCfg.cfg.host.returnPolicy = Cppi_ReturnPolicy_RETURN_ENTIRE_PACKET;
cppiDescCfg.cfg.host.psLocation = Cppi_PSLoc_PS_IN_DESC;
cppiDescCfg.returnQueue.qMgr = 0;
cppiDescCfg.returnQueue.qNum = QMSS_PARAM_NOT_SPECIFIED;
cppiDescCfg.epibPresent = Cppi_EPIB_EPIB_PRESENT;
/* Initialize the descriptors, create a free queue and push descriptors to a global free queue */
if ((gGlobalFreeQHnd = Cppi_initDescriptor (&cppiDescCfg, &numAllocated)) <= 0)
{
platform_write ("Error Initializing Free Descriptors, Error: %d \n", gGlobalFreeQHnd);
return -1;
}
if (numAllocated != cppiDescCfg.descNum) {
platform_write ("function Init_Qmss: expected %d descriptors to be initialized, only %d are initialized\n", cppiDescCfg.descNum, numAllocated);
return (-1);
}
/* Queue Manager Initialization Done */
return 0;
}
/** ============================================================================
* @n@b res_mgr_stop_qmss
*
* @b Description
* @n This API de-initializes the QMSS LLD.
*
* @param[in]
* @n None
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
int32_t
res_mgr_stop_qmss
(
void
)
{
Qmss_queueClose (gGlobalFreeQHnd);
return 0;
}
/**********************************************************************
************ Resoure Manager CPPI configuration Functions ************
**********************************************************************/
/** ============================================================================
* @n@b res_mgr_cppi_get_passhandle
*
* @b Description
* @n This API returns the handle to the the CPPI DMA for the Packet Accelerator (PA).
*
* @param[in] None
*
* @return Cppi_Handle
* =============================================================================
*/
Cppi_Handle
res_mgr_cppi_get_passhandle (void){
return gPassCpdmaHnd;
}
/** ============================================================================
* @n@b res_mgr_init_cppi
*
* @b Description
* @n This API initializes the CPPI LLD, opens the PDMA and opens up
* the Tx, Rx channels required for data transfers.
*
* @param[in] p_qmss_cfg
* Pointer to CPPI_CFG_T
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
int32_t
res_mgr_init_cppi
(
CPPI_CFG_T *p_cppi_cfg
)
{
int32_t result, i;
Cppi_CpDmaInitCfg cpdmaCfg;
uint8_t isAllocated;
Cppi_TxChInitCfg txChCfg;
Cppi_RxChInitCfg rxChInitCfg;
Cppi_Handle *p_handle = NULL;
Cppi_ChHnd *p_ch_handle = NULL;
if (p_cppi_cfg->master_core)
{
/* Initialize CPPI LLD */
#if defined(DEVICE_K2H) || defined(DEVICE_K2K)
result = Cppi_init (&cppiGblCfgParams);
#else
result = Cppi_init (&cppiGblCfgParams[0]);
#endif
if (result != CPPI_SOK)
{
platform_write ("Error initializing CPPI LLD, Error code : %d\n", result);
return -1;
}
}
/* Initialize CPDMA */
memset (&cpdmaCfg, 0, sizeof (Cppi_CpDmaInitCfg));
cpdmaCfg.dmaNum = p_cppi_cfg->dma_num;
if (cpdmaCfg.dmaNum == Cppi_CpDma_PASS_CPDMA)
{
p_handle = &gPassCpdmaHnd;
memcpy(&gCppiCfg[CPPI_CFG_PASS], p_cppi_cfg, sizeof(CPPI_CFG_T));
}
if (p_handle)
{
if ((*p_handle = Cppi_open (&cpdmaCfg)) == NULL)
{
platform_write ("Error initializing CPPI for CPDMA %d \n", cpdmaCfg.dmaNum);
return -1;
}
}
else
{
return -1;
}
/* Open all CPPI Tx Channels. These will be used to send data to PASS/CPSW */
for (i = 0; i < p_cppi_cfg->num_tx_queues; i ++)
{
txChCfg.channelNum = i; /* CPPI channels are mapped one-one to the PA Tx queues */
txChCfg.txEnable = Cppi_ChState_CHANNEL_DISABLE; /* Disable the channel for now. */
txChCfg.filterEPIB = 0;
txChCfg.filterPS = 0;
txChCfg.aifMonoMode = 0;
txChCfg.priority = 2;
if (cpdmaCfg.dmaNum == Cppi_CpDma_PASS_CPDMA)
{
p_ch_handle = &gPassCpdmaTxChanHnd[i];
}
if (p_ch_handle == NULL)
{
return -1;
}
if ((*p_ch_handle = Cppi_txChannelOpen (*p_handle, &txChCfg, &isAllocated)) == NULL)
{
platform_write ("Error opening Tx channel %d\n", txChCfg.channelNum);
return -1;
}
Cppi_channelEnable (*p_ch_handle);
}
/* Open all CPPI Rx channels. These will be used by PA to stream data out. */
for (i = 0; i < p_cppi_cfg->num_rx_channels; i++)
{
/* Open a CPPI Rx channel that will be used by PA to stream data out. */
rxChInitCfg.channelNum = i;
rxChInitCfg.rxEnable = Cppi_ChState_CHANNEL_DISABLE;
if ((gPassCpdmaRxChanHnd[i] = Cppi_rxChannelOpen (*p_handle, &rxChInitCfg, &isAllocated)) == NULL)
{
platform_write("Error opening Rx channel: %d \n", rxChInitCfg.channelNum);
return -1;
}
/* Also enable Rx Channel */
Cppi_channelEnable (gPassCpdmaRxChanHnd[i]);
}
/* Clear CPPI Loobpack bit in PASS CDMA Global Emulation Control Register */
Cppi_setCpdmaLoopback(*p_handle, 0);
/* CPPI Init Done. Return success */
return 0;
}
/** ============================================================================
* @n@b res_mgr_stop_cppi
*
* @b Description
* @n This API de-initializes the CPPI LLD.
*
* @param[in]
* @n None
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
int32_t
res_mgr_stop_cppi
(
CPPI_CFG_TYPE cfg_type
)
{
uint32_t i;
if (cfg_type == CPPI_CFG_PASS)
{
for (i = 0; i < gCppiCfg[cfg_type].num_rx_channels; i++)
Cppi_channelClose (gPassCpdmaRxChanHnd[i]);
for (i = 0; i < gCppiCfg[cfg_type].num_tx_queues; i++)
Cppi_channelClose (gPassCpdmaTxChanHnd[i]);
}
return 0;
}
/**********************************************************************
************ Resource Manager PA configuration Functions ************
**********************************************************************/
/** ============================================================================
* @n@b Download_PAFirmware
*
* @b Description
* @n This API downloads the PA firmware required for PDSP operation.
*
* @param[in]
* @n None
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
static int32_t Download_PAFirmware (Void)
{
int32_t i;
/* Hold the PA in reset state during download */
Pa_resetControl (gPAInstHnd, pa_STATE_RESET);
/* PDPSs 0-2 use image c1 */
for (i = 0; i < 3; i++)
{
Pa_downloadImage (gPAInstHnd, i, (Ptr)c1, sizeof(c1));
}
/* PDSP 3 uses image c2 */
Pa_downloadImage (gPAInstHnd, 3, (Ptr)c2, sizeof(c2));
/* PDSPs 4-5 use image m */
for (i = 4; i < 6; i++)
{
Pa_downloadImage (gPAInstHnd, i, (Ptr)m, sizeof(m));
}
/* Enable the PA back */
Pa_resetControl (gPAInstHnd, pa_STATE_ENABLE);
return 0;
}
/** ============================================================================
* @n@b res_mgr_get_painstance
*
* @b Description
* @n This API returns the handle to the PA.
*
* @param[in] None
*
* @return Pa_Handle
* =============================================================================
*/
Pa_Handle
res_mgr_get_painstance (void) {
return gPAInstHnd;
}
/* ============================================================================
* @n@b res_mgr_init_pass
*
* @b Description
* @n This API initializes the PASS/PDSP.
*
* @param[in]
* @n None
*
* @return int32_t
* -1 - Error
* 0 - Success
* =============================================================================
*/
int32_t
res_mgr_init_pass
(
void
)
{
paSizeInfo_t paSize = {0};
paConfig_t paCfg = {0};
int32_t retVal;
int32_t sizes[pa_N_BUFS];
int32_t aligns[pa_N_BUFS];
void* bases[pa_N_BUFS];
/* Allocate space for the PA LLD buffers. The buffers we need to
* allocate space are:
* (1) PA LLD Instance Info Handle
* (2) PA LLD L2 Handle database
* (3) PA LLD L3 Handle database
*/
paSize.nMaxL2 = MAX_NUM_L2_HANDLES;
paSize.nMaxL3 = MAX_NUM_L3_HANDLES;
if ((retVal = Pa_getBufferReq(&paSize, sizes, aligns)) != pa_OK)
{
platform_write ("Pa_getBufferReq returned error %d\n", retVal);
return -1;
}
/* Validate the buffer allocations */
/* The first buffer is always the instance buffer */
if ((uint32_t)gPAInst & (aligns[0] - 1))
{
platform_write("Pa_getBufferReq requires %d alignment for instance buffer, but address is 0x%08x\n", aligns[0], (uint32_t)gPAInst);
return -1;
}
if (sizeof(gPAInst) < sizes[0])
{
platform_write ("Pa_getBufferReq requires %d bytes for instance buffer, have only %d\n", sizes[0], sizeof(gPAInst));
return -1;
}
bases[0] = (Void *)gPAInst;
/* The second buffer is the L2 table */
if ((uint32_t)gMemL2Ram & (aligns[1] - 1))
{
platform_write ("Pa_getBufferReq requires %d alignment for buffer 1, but address is 0x%08x\n", aligns[1], (uint32_t)gMemL2Ram);
return (-1);
}
if (sizeof(gMemL2Ram) < sizes[1])
{
platform_write ("Pa_getBufferReq requires %d bytes for buffer 1, have only %d\n", sizes[1], sizeof(gMemL2Ram));
return -1;
}
bases[1] = (Void *)gMemL2Ram;
/* The third buffer is the L3 table */
if ((uint32_t)gMemL3Ram & (aligns[2] - 1))
{
platform_write ("Pa_alloc requires %d alignment for buffer 1, but address is 0x%08x\n", aligns[2], (uint32_t)gMemL3Ram);
return (-1);
}
if (sizeof(gMemL3Ram) < sizes[2])
{
platform_write ("Pa_alloc requires %d bytes for buffer 1, have only %d\n", sizes[2], sizeof(gMemL3Ram));
return (-1);
}
bases[2] = (Void *)gMemL3Ram;
/* Finally initialize the PA LLD */
paCfg.initTable = TRUE;
paCfg.initDefaultRoute = TRUE;
#if defined(DEVICE_K2H) || defined(DEVICE_K2K)
paCfg.baseAddr = CSL_NETCP_CFG_REGS;
#else
paCfg.baseAddr = CSL_PA_SS_CFG_REGS;
#endif
paCfg.sizeCfg = &paSize;
if ((retVal = Pa_create (&paCfg, bases, &gPAInstHnd)) != pa_OK)
{
platform_write ("Pa_create returned with error code %d\n", retVal);
return -1;
}
/* Download the PASS PDSP firmware */
if (Download_PAFirmware ())
{
return -1;
}
/* PA Init Done. Return success */
return 0;
}