]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - test/rm_shared_test.c
Completed coding and testing of Shared Server feature
[keystone-rtos/rm-lld.git] / test / rm_shared_test.c
1 /*
2  *   rm_shared_test.c
3  *
4  *   Multicore Resource Manager test that uses the RM shared server to
5  *   request resources from multiple cores.
6  *
7  *  ============================================================================
8  *
9  * Copyright (c) 2012-2013, Texas Instruments Incorporated
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * *  Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  * *  Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * *  Neither the name of Texas Instruments Incorporated nor the names of
24  *    its contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  */
40  
41 /* Standard Includes */
42 #include <string.h>
44 /* XDC Includes */
45 #include <xdc/std.h>
46 #include <xdc/runtime/System.h>
48 /* IPC Includes */
49 #include <ti/ipc/Ipc.h>
50 #include <ti/ipc/GateMP.h>
52 /* BIOS Includes */
53 #include <ti/sysbios/BIOS.h>
54 #include <ti/sysbios/knl/Task.h>
55 #include <ti/sysbios/family/c64p/Hwi.h>
57 /* CSL Includes */
58 #include <ti/csl/csl_chip.h>
59 #include <ti/csl/csl_cacheAux.h>
60 #include <ti/csl/csl_xmcAux.h>
62 /* RM Includes */
63 #include <ti/drv/rm/rm.h>
64 #include <ti/drv/rm/rm_services.h>
65 #include <ti/drv/rm/rm_osal.h>
67 /**********************************************************************
68  ********************** RM Shared Test Symbols ************************
69  **********************************************************************/
71 #define SYSINIT                      0
72 #define NUM_CORES                    2
74 /* Test FALSE */
75 #define RM_TEST_FALSE                0
76 /* Test TRUE */
77 #define RM_TEST_TRUE                 1
79 /* Test cache align */
80 #define RM_TEST_MAX_CACHE_ALIGN      128
82 /* RM packet heap name */
83 #define RM_PKT_HEAP_NAME             "rmHeapBuf"
84 /* Name of GateMP used to synchronize the RM test tasks */
85 #define RM_TASK_GATE_NAME            "rmGateMP"
87 /* Error checking macro */
88 #define ERROR_CHECK(checkVal, resultVal, rmInstName, printMsg)                   \
89     if (resultVal != checkVal) {                                                 \
90         char errorMsgToPrint[] = printMsg;                                       \
91         System_printf("Error Core %d : %s : ", coreNum, rmInstName);    \
92         System_printf("%s with error code : %d\n", errorMsgToPrint, resultVal);  \
93         System_abort("Test Failure\n");                                          \
94     }
96 /**********************************************************************
97  ****************** RM Shared Test Data Structures ********************
98  **********************************************************************/
100 typedef struct {
101     /* RM shared server handle */
102     Rm_Handle sharedServerHandle;
103     /** Padding required to make sure linker doesn't put something else
104      * on the same cache line. */
105     uint8_t pad[RM_TEST_MAX_CACHE_ALIGN - sizeof(Rm_Handle)];
106 } Test_SharedRmHandle;
108 /**********************************************************************
109  ********************** Extern Variables ******************************
110  **********************************************************************/
112 /* RM test Global Resource List (GRL) */
113 extern const char rmGRL[];
114 /* Example Linux DTB file provided to RM Server for automatic Linux Kernel resource extraction */
115 extern const char rmLinuxDtb[];
116 /* RM test Global Policy provided to RM Server */
117 extern const char rmGlobalPolicy[];
119 /**********************************************************************
120  ********************** Global Variables ******************************
121  **********************************************************************/
123 /* DSP core number according to IPC */
124 uint16_t            coreNum;
126 /* Task to configure application transport code for RM */
127 Task_Handle         rmStartupTskHandle;
128 /* RM server test task */
129 Task_Handle         rmServerTskHandle;
130 /* RM client delegate and client test task */
131 Task_Handle         rmClientTskHandle;
133 /* GateMP used to synchronize tests between the two RM test tasks */
134 GateMP_Handle       gateHandle = NULL;
135 /* GateMP key */
136 IArg                gateKey;
138 /* RM Server instance name (must match with RM Global Resource List (GRL) and policies */
139 char                rmServerName[RM_NAME_MAX_CHARS] = "RM_Server";
141 /* RM shared server instance handle */
142 #pragma DATA_SECTION (rmSharedHandle, ".rmTestSharedHandle");
143 #pragma DATA_ALIGN (rmSharedHandle, RM_TEST_MAX_CACHE_ALIGN)
144 Test_SharedRmHandle rmSharedHandle = {NULL};
146 /* RM shared server instance service handle */
147 Rm_ServiceHandle   *rmSharedServiceHandle = NULL;
149 /* RM resource names (must match resource node names in GRL and policies */
150 char                resourceNameMemRegion[RM_NAME_MAX_CHARS]  = "memory-regions";
151 char                resourceNameAccumCh[RM_NAME_MAX_CHARS]    = "accumulator-ch";
152 char                resourceNameGpQ[RM_NAME_MAX_CHARS]        = "gp-queue";
153 char                resourceNameAifQ[RM_NAME_MAX_CHARS]       = "aif-queue";
154 char                resourceNameQosCluster[RM_NAME_MAX_CHARS] = "qos-cluster";
155 char                resourceNameAifRxCh[RM_NAME_MAX_CHARS]    = "aif-rx-ch";
156 char                resourceNameInfraQ[RM_NAME_MAX_CHARS]     = "infra-queue";
158 /* Test RM NameServer name */
159 char                nameServerNameFavQ[RM_NAME_MAX_CHARS]     = "My_Favorite_Queue";
161 /**********************************************************************
162  *************************** Test Functions ***************************
163  **********************************************************************/
165 void setRmRequest(Rm_ServiceReqInfo *reqInfo, Rm_ServiceType type, const char *resName, int32_t resBase,
166                   uint32_t resLen, int32_t resAlign, const char *nsName, int setCallback, Rm_ServiceRespInfo *respInfo)
167 {                                                                                
168     memset((void *)reqInfo, 0, sizeof(Rm_ServiceReqInfo));                                        
169     reqInfo->type = type;                                                                           
170     reqInfo->resourceName = resName;                                                                
171     reqInfo->resourceBase = resBase;                                                                
172     reqInfo->resourceLength = resLen;                                                               
173     reqInfo->resourceAlignment = resAlign;                                                          
174     reqInfo->resourceNsName = nsName;
175     if (setCallback) {
176         reqInfo->callback.serviceCallback = NULL;  
177     }
178     memset((void *)respInfo, 0, sizeof(Rm_ServiceRespInfo));                                     
181 void rmCleanupTsk(UArg arg0, UArg arg1)
183     int32_t result;
184     
185     /* Delete the RM test tasks */
186     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
187     if (rmStartupTskHandle) {
188        Task_delete(&rmStartupTskHandle);
189        /* Set the task handle to be NULL so that the delete only occurs once */
190        rmStartupTskHandle = NULL;
191     }  
192     
193     if (coreNum == SYSINIT) {
194         if (rmServerTskHandle) {
195             System_printf("Core %d: Deleting RM server task...\n", coreNum);
196             Task_delete(&rmServerTskHandle);
197             /* Set the task handle to be NULL so that the delete only occurs once */
198             rmServerTskHandle = NULL;
199         }
200     }
201     else {
202         if (rmClientTskHandle) {
203             System_printf("Core %d: Deleting RM client task...\n", coreNum);        
204             Task_delete(&rmClientTskHandle);
205             /* Set the task handle to be NULL so that the delete only occurs once */
206             rmClientTskHandle = NULL;
207         }
208     }
210     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
211     if (coreNum == SYSINIT) {
212         Rm_serviceCloseHandle(rmSharedServiceHandle);
214         result = Rm_delete(rmSharedHandle.sharedServerHandle, RM_TEST_TRUE);
215         ERROR_CHECK(RM_OK, result, rmServerName, "Instance deletion failed");       
216     }
218     BIOS_exit(0);
221 void rmServerTsk(UArg arg0, UArg arg1)
223     Rm_ServiceReqInfo  requestInfo;
224     Rm_ServiceRespInfo responseInfo;
225     Task_Params        taskParams;
227     Rm_instanceStatus(rmSharedHandle.sharedServerHandle);
229     /* BEGIN testing UNSPECIFIED base and alignment requests on Server */               
230     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
231                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);       
232     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
233     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
234                                                                                                   rmServerName,
235                                                                                                   resourceNameGpQ,
236                                                                                                   requestInfo.resourceLength, 
237                                                                                                   requestInfo.resourceAlignment);
238     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
239         System_printf("PASSED\n");
240     }
241     else {
242         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
243     }    
244                
245     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
246                  RM_RESOURCE_BASE_UNSPECIFIED, 1, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, RM_TEST_TRUE, &responseInfo);     
247     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);  
248     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
249                                                                                                            rmServerName,
250                                                                                                            resourceNameGpQ,
251                                                                                                            requestInfo.resourceLength);
252     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
253         System_printf("PASSED\n");
254     }
255     else {
256         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
257     }     
259     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
260                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 200, NULL, RM_TEST_TRUE, &responseInfo);     
261     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
262     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
263                                                                                                   rmServerName,
264                                                                                                   resourceNameGpQ,
265                                                                                                   requestInfo.resourceLength,
266                                                                                                   requestInfo.resourceAlignment);
267     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
268         System_printf("PASSED\n");
269     }
270     else {
271         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
272     }      
273     /* END testing UNSPECIFIED base and alignment requests on Server */      
275     /* Create new NameServer object */                
276     setRmRequest(&requestInfo, Rm_service_RESOURCE_MAP_TO_NAME, resourceNameGpQ, 
277                  1002, 1, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
278     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo); 
279     System_printf("Core %d : %s create name %s tied to %s %d - %d : ", coreNum,
280                                                                        rmServerName,
281                                                                        nameServerNameFavQ,
282                                                                        responseInfo.resourceName,
283                                                                        requestInfo.resourceBase, 
284                                                                        (requestInfo.resourceBase + requestInfo.resourceLength - 1));                                                                       
285     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
286         System_printf("PASSED\n");
287     }
288     else {
289         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
290     }     
292     /* Wait for CD and Client retrieve resource via name, allocate the resource, free resource via name, and 
293      * delete the NameServer object. */
294     gateKey = GateMP_enter(gateHandle);
295     GateMP_leave(gateHandle, gateKey);
297     /* Try to allocate the memory region taken by the Linux Kernel and not specified as shared */
298     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameMemRegion, 
299                  12, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
300     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo); 
301     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
302                                                                   rmServerName,
303                                                                   resourceNameMemRegion,
304                                                                   requestInfo.resourceBase, 
305                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
306     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
307         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
308     }
309     else {
310         System_printf("FAILED : expected denial or error\n");
311     }    
313     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
314     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
315                  14, 5, 0, NULL, RM_TEST_TRUE, &responseInfo);       
316     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
317     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
318                                                                   rmServerName,
319                                                                   resourceNameAifRxCh,
320                                                                   requestInfo.resourceBase, 
321                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
322     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
323         System_printf("PASSED\n");
324     }
325     else {
326         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
327     } 
328     
329     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
330                  19, 31, 0, NULL, RM_TEST_TRUE, &responseInfo);      
331     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
332     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
333                                                                   rmServerName,
334                                                                   resourceNameAifRxCh,
335                                                                   requestInfo.resourceBase, 
336                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
337     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
338         System_printf("PASSED\n");
339     }
340     else {
341         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
342     }        
343     
344     /* Wait for Client and Client Delegate to do their allocations */
345     gateKey = GateMP_enter(gateHandle);
346     GateMP_leave(gateHandle, gateKey);       
348     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
349                  25, 3, 0, NULL, RM_TEST_TRUE, &responseInfo);      
350     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);  
351     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
352                                                         rmServerName,
353                                                         resourceNameAifRxCh,
354                                                         requestInfo.resourceBase, 
355                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
356     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
357         System_printf("PASSED\n");
358     }
359     else {
360         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
361     }      
362     
363     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
364                  34, 3, 0, NULL, RM_TEST_TRUE, &responseInfo);      
365     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
366     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
367                                                         rmServerName,
368                                                         resourceNameAifRxCh,
369                                                         requestInfo.resourceBase, 
370                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
371     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
372         System_printf("PASSED\n");
373     }
374     else {
375         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
376     }      
377  
378     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
379                  28, 6, 0, NULL, RM_TEST_TRUE, &responseInfo);      
380     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);   
381     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
382                                                         rmServerName,
383                                                         resourceNameAifRxCh,
384                                                         requestInfo.resourceBase, 
385                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
386     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
387         System_printf("PASSED\n");
388     }
389     else {
390         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
391     }      
393     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
394                  53, 2, 0, NULL, RM_TEST_TRUE, &responseInfo);      
395     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);  
396     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
397                                                                   rmServerName,
398                                                                   resourceNameAifRxCh,
399                                                                   requestInfo.resourceBase, 
400                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
401     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
402         System_printf("PASSED\n");
403     }
404     else {
405         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
406     }  
407     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */       
409     /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
410     gateKey = GateMP_enter(gateHandle);
411     GateMP_leave(gateHandle, gateKey);
413     /* Test allocation of a resource twice from the same instance with init and use privileges.  Both
414      * should be approved but the instance should only be mentioned once in the resource's owner list */
415     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
416                  6543, 10, 0, NULL, RM_TEST_TRUE, &responseInfo);      
417     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);  
418     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
419                                                                    rmServerName,
420                                                                    resourceNameGpQ,
421                                                                    requestInfo.resourceBase, 
422                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
423     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
424         System_printf("PASSED\n");
425     }
426     else {
427         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
428     }     
430     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
431                  6543, 10, 0, NULL, RM_TEST_TRUE, &responseInfo);      
432     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
433     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
434                                                                   rmServerName,
435                                                                   resourceNameGpQ,
436                                                                   requestInfo.resourceBase, 
437                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
438     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
439         System_printf("PASSED\n");
440     }
441     else {
442         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
443     }        
445     /* Allocate infrastructure queue taken by Linux kernel and shared with Rm_Client.  Expect error or denial. */
446     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
447                  805, 1, 0, NULL, RM_TEST_TRUE, &responseInfo);     
448     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
449     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
450                                                                    rmServerName,
451                                                                    resourceNameInfraQ,
452                                                                    requestInfo.resourceBase, 
453                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
454     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
455         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
456     }
457     else {
458         System_printf("FAILED : expected denial or error\n");
459     }              
461     System_printf("Core %d: Testing is complete\n", coreNum);
463     Rm_instanceStatus(rmSharedHandle.sharedServerHandle);
464     Rm_resourceStatus(rmSharedHandle.sharedServerHandle, RM_TEST_TRUE);   
465     
466     /* Create the RM cleanup task. */
467     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
468     Task_Params_init (&taskParams);
469     Task_create (rmCleanupTsk, &taskParams, NULL);
472 void rmClientTsk(UArg arg0, UArg arg1)
474     Rm_ServiceReqInfo  requestInfo;
475     Rm_ServiceRespInfo responseInfo;    
476     Task_Params        taskParams;
478     Rm_instanceStatus(rmSharedHandle.sharedServerHandle);
480     /* Retrieve a resource via a NameServer name */
481     setRmRequest(&requestInfo, Rm_service_RESOURCE_GET_BY_NAME, NULL, 
482                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
483     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
484     System_printf("Core %d : %s get resource with name %s : ", coreNum,
485                                                                rmServerName,
486                                                                nameServerNameFavQ);
487     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
488         System_printf("PASSED\n");
489     }
490     else {
491         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
492     } 
494     /* Allocate the resource returned from the NameServer request */
495     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo)); 
496     requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
497     requestInfo.resourceName = responseInfo.resourceName;
498     requestInfo.resourceBase = responseInfo.resourceBase;
499     requestInfo.resourceLength = responseInfo.resourceLength;
500     requestInfo.resourceNsName = NULL;   
501     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
502     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
503                                                                    rmServerName,
504                                                                    responseInfo.resourceName,
505                                                                    requestInfo.resourceBase, 
506                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
507     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
508         System_printf("PASSED\n");
509     }
510     else {
511         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
512     }    
514     /* Free resource via a NameServer name */
515     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, NULL, 
516                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
517     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
518     System_printf("Core %d : %s free resource with name %s : ", coreNum,
519                                                                 rmServerName,
520                                                                 nameServerNameFavQ);
521     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
522         System_printf("PASSED\n");
523     }
524     else {
525         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
526     }      
528     /* Delete the NameServer name */
529     setRmRequest(&requestInfo, Rm_service_RESOURCE_UNMAP_NAME, NULL, 
530                  0, 0, 0, nameServerNameFavQ, RM_TEST_TRUE, &responseInfo);     
531     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);     
532     System_printf("Core %d : %s delete name %s : ", coreNum,
533                                                     rmServerName,
534                                                     nameServerNameFavQ);
535     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
536         System_printf("PASSED\n");
537     }
538     else {
539         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
540     }     
542     GateMP_leave(gateHandle, gateKey);
543     gateKey = GateMP_enter(gateHandle);
545     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
546     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
547                  0, 6, 0, NULL, RM_TEST_TRUE, &responseInfo);     
548     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
549     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
550                                                                   rmServerName,
551                                                                   resourceNameAifRxCh,
552                                                                   requestInfo.resourceBase, 
553                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
554     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
555         System_printf("PASSED\n");
556     }
557     else {
558         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
559     }     
560     
561     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifRxCh, 
562                  50, 7, 0, NULL, RM_TEST_TRUE, &responseInfo);        
563     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
564     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
565                                                                    rmServerName,
566                                                                    resourceNameAifRxCh,
567                                                                    requestInfo.resourceBase, 
568                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
569     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
570         System_printf("PASSED\n");
571     }
572     else {
573         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
574     }       
575     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */
577     GateMP_leave(gateHandle, gateKey);    
578     gateKey = GateMP_enter(gateHandle);
580     /* BEGIN testing allocations with UNSPECIFIED base and alignment values */
581     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
582                  RM_RESOURCE_BASE_UNSPECIFIED, 5, 4, NULL, RM_TEST_TRUE, &responseInfo);        
583     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
584     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
585                                                                                                   rmServerName,
586                                                                                                   resourceNameAccumCh,
587                                                                                                   requestInfo.resourceLength, 
588                                                                                                   requestInfo.resourceAlignment);
589     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
590         System_printf("PASSED\n");
591     }
592     else {
593         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
594     }        
596     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
597                  RM_RESOURCE_BASE_UNSPECIFIED, 2, 1, NULL, RM_TEST_TRUE, &responseInfo);      
598     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo); 
599     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
600                                                                                                   rmServerName,
601                                                                                                   resourceNameAccumCh,
602                                                                                                   requestInfo.resourceLength, 
603                                                                                                   requestInfo.resourceAlignment);
604     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
605         System_printf("PASSED\n");
606     }
607     else {
608         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
609     }     
611     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
612                  RM_RESOURCE_BASE_UNSPECIFIED, 2, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, RM_TEST_TRUE, &responseInfo);     
613     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);
614     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
615                                                                                                            rmServerName,
616                                                                                                            resourceNameAccumCh,
617                                                                                                            requestInfo.resourceLength);
618     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
619         System_printf("PASSED\n");
620     }
621     else {
622         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
623     }     
624     /* END testing allocations with UNSPECIFIED base and alignment values */       
626     /* BEGIN Allocating some resources without providing a callback function.  RM should block and not return until the result
627      * is returned by the server. */
628     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
629                  7000, 1, 0, NULL, FALSE, &responseInfo);     
630     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);   
631     System_printf("Core %d : %s init allocation (without callback specified) of %s %d - %d : ", coreNum,
632                                                                                                 rmServerName,
633                                                                                                 resourceNameGpQ,
634                                                                                                 requestInfo.resourceBase, 
635                                                                                                 (requestInfo.resourceBase + requestInfo.resourceLength - 1));
636     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
637         System_printf("PASSED\n");
638     }
639     else {
640         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
641     }   
643     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
644                  7005, 25, 0, NULL, FALSE, &responseInfo);     
645     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);   
646     System_printf("Core %d : %s use allocation (without callback specified) of %s %d - %d : ", coreNum,
647                                                                                                rmServerName,
648                                                                                                resourceNameGpQ,
649                                                                                                requestInfo.resourceBase, 
650                                                                                                (requestInfo.resourceBase + requestInfo.resourceLength - 1));
651     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
652         System_printf("PASSED\n");
653     }
654     else {
655         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
656     }
657     
658     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
659                  7010, 5, 0, NULL, FALSE, &responseInfo);     
660     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);   
661     System_printf("Core %d : %s use allocation (without callback specified) of %s %d - %d : ", coreNum,
662                                                                                                rmServerName,
663                                                                                                resourceNameGpQ,
664                                                                                                requestInfo.resourceBase, 
665                                                                                                (requestInfo.resourceBase + requestInfo.resourceLength - 1));
666     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
667         System_printf("PASSED\n");
668     }
669     else {
670         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
671     }
673     /* Init allocation of resource already owned by Client should return approved and the resource should
674      * only be shown as allocated once to the instance in the resource print out */
675     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
676                  7011, 1, 0, NULL, FALSE, &responseInfo);     
677     rmSharedServiceHandle->Rm_serviceHandler(rmSharedServiceHandle->rmHandle, &requestInfo, &responseInfo);   
678     System_printf("Core %d : %s use allocation (without callback specified) of %s %d - %d : ", coreNum,
679                                                                                                rmServerName,
680                                                                                                resourceNameGpQ,
681                                                                                                requestInfo.resourceBase, 
682                                                                                                (requestInfo.resourceBase + requestInfo.resourceLength - 1));
683     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
684         System_printf("PASSED\n");
685     }
686     else {
687         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
688     }
689     /* END Allocating some resources without providing a callback function.  RM should block and not return until the result
690      * is returned by the server. */    
692     GateMP_leave(gateHandle, gateKey);  
694     System_printf("Core %d: Testing is complete\n", coreNum);
696     Rm_instanceStatus(rmSharedHandle.sharedServerHandle);
697     
698     /* Create the RM cleanup task. */
699     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
700     Task_Params_init (&taskParams);
701     Task_create (rmCleanupTsk, &taskParams, NULL);
704 void rmStartupTsk(UArg arg0, UArg arg1)
705 {  
706     Int           status;
707     GateMP_Params gateParams;
708     Task_Params   taskParams;
710     if (coreNum == SYSINIT) {
711         GateMP_Params_init(&gateParams);
712         gateParams.name = RM_TASK_GATE_NAME;
713         gateHandle = GateMP_create(&gateParams);
714     }
715     else {
716         do {
717             status = GateMP_open(RM_TASK_GATE_NAME, &gateHandle);
718             /* 
719              *  Sleep for 1 clock tick to avoid inundating remote processor
720              *  with interrupts if open failed
721              */
722             if (status < 0) { 
723                 Task_sleep(1);
724             }
725         } while (status < 0);
726         /* Take the gate right away to prepare for RM testing */
727         gateKey = GateMP_enter(gateHandle);
728     }
729  
730     /* Create the RM test tasks. */
731     if (coreNum == SYSINIT) {
732         System_printf("Core %d: Creating RM server task...\n", coreNum);
733         Task_Params_init (&taskParams);
734         taskParams.priority = 1;
735         rmServerTskHandle = Task_create (rmServerTsk, &taskParams, NULL);
736     }
737     else if (coreNum) {
738         System_printf("Core %d: Creating RM client task...\n", coreNum);
739         Task_Params_init (&taskParams);
740         taskParams.priority = 1;
741         rmClientTskHandle = Task_create (rmClientTsk, &taskParams, NULL);
742     }
745 int main(Int argc, Char* argv[])
747     Rm_InitCfg         rmInitCfg;
748     Task_Params        taskParams; 
749     int                status;
750     int32_t            result;
752     System_printf ("*********************************************************\n");
753     System_printf ("***************** RM Shared Server Test *****************\n");
754     System_printf ("*********************************************************\n");
756     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
758     coreNum = CSL_chipReadReg(CSL_CHIP_DNUM);
759     
760     /* Initialize the heap in shared memory. Using IPC module to do that */ 
761     System_printf("Core %d: Starting IPC...\n", coreNum);
762     status = Ipc_start();
763     if (status < 0) {
764         System_abort("Ipc_start failed\n");
765     }
767     /* Initialize the RM instances - RM must be initialized before anything else in the system
768      * Core 0: 1 RM Instance  - RM Server
769      * Core 1: 2 RM Instances - RM Client Delegate
770      *                          RM Client
771      */
772     if (coreNum == SYSINIT) {
773         /* Create the Server instance */
774         rmInitCfg.instName = rmServerName;
775         rmInitCfg.instType = Rm_instType_SHARED_SERVER;
776         rmInitCfg.instCfg.serverCfg.globalResourceList = (void *)rmGRL;
777         rmInitCfg.instCfg.serverCfg.linuxDtb = (void *)rmLinuxDtb;
778         rmInitCfg.instCfg.serverCfg.globalPolicy = (void *)rmGlobalPolicy;
779         rmSharedHandle.sharedServerHandle = Rm_init(&rmInitCfg, &result);
780         ERROR_CHECK(RM_OK, result, rmServerName, "Initialization failed");
782         /* Open Server service handle */
783         rmSharedServiceHandle = Rm_serviceOpenHandle(rmSharedHandle.sharedServerHandle, &result);
784         ERROR_CHECK(RM_OK, result, rmServerName, "Service handle open failed");
786         Osal_rmEndMemAccess((void *)&rmSharedHandle, sizeof(Test_SharedRmHandle));
787     }
788     else {
789         do {
790             Osal_rmBeginMemAccess((void *)&rmSharedHandle, sizeof(Test_SharedRmHandle));
791         } while (!rmSharedHandle.sharedServerHandle);
792         rmSharedServiceHandle = Rm_serviceOpenHandle(rmSharedHandle.sharedServerHandle, &result);
793         ERROR_CHECK(RM_OK, result, rmServerName, "Service handle open failed");
794     }
796     /* Create the RM startup task */
797     System_printf("Core %d: Creating RM startup task...\n", coreNum);
798     Task_Params_init (&taskParams);
799     rmStartupTskHandle = Task_create (rmStartupTsk, &taskParams, NULL);
801     System_printf("Core %d: Starting BIOS...\n", coreNum);
802     BIOS_start();
804     return (0);