RM Blocking functionality when no callback provided is working
[keystone-rtos/rm-lld.git] / test / rm_test.c
1 /*
2  *   rm_test.c
3  *
4  *   Multicore Resource Manager test that uses IPC to an application
5  *   requesting RM services from a RM Server, Client Delegate, and Client.
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>
43 #include <stdbool.h>
45 /* XDC Includes */
46 #include <xdc/std.h>
47 #include <xdc/runtime/System.h>
49 /* IPC Includes */
50 #include <ti/ipc/Ipc.h>
51 #include <ti/ipc/MessageQ.h>
52 #include <ti/ipc/HeapBufMP.h>
53 #include <ti/ipc/MultiProc.h>
54 #include <ti/ipc/GateMP.h>
56 /* BIOS Includes */
57 #include <ti/sysbios/BIOS.h>
58 #include <ti/sysbios/knl/Task.h>
59 #include <ti/sysbios/family/c64p/Hwi.h>
61 /* CSL Includes */
62 #include <ti/csl/csl_semAux.h>
63 #include <ti/csl/csl_cacheAux.h>
64 #include <ti/csl/csl_xmcAux.h>
66 /* RM Includes */
67 #include <ti/drv/rm/rm.h>
68 #include <ti/drv/rm/rm_transport.h>
69 #include <ti/drv/rm/rm_services.h>
71 /**********************************************************************
72  ************************** RM Test Symbols ***************************
73  **********************************************************************/
75 /* IPC MessageQ heap name */
76 #define MSGQ_HEAP_NAME               "msgQHeapBuf"
77 /* IPC MessageQ heap ID */
78 #define MSGQ_HEAP_ID                 0
80 /* RM packet heap name */
81 #define RM_PKT_HEAP_NAME             "rmHeapBuf"
82 /* Name of GateMP used to synchronize the RM test tasks */
83 #define RM_TASK_GATE_NAME            "rmGateMP"
85 /* Application's core 0 registered RM transport indices */
86 #define SERVER_TO_CD_MAP_ENTRY       0
87 /* Application's core 1 registered RM transport indices */
88 #define CD_TO_SERVER_MAP_ENTRY       0
89 #define CD_TO_CLIENT_MAP_ENTRY       1
90 #define CLIENT_TO_CD_MAP_ENTRY       2
91 /* Maximum number of registered RM transports */
92 #define MAX_MAPPING_ENTRIES          3
94 /* Size of RM static allocation response queue.  Must be greater than number of APPROVED
95  * static allocations */
96 #define MAX_STATIC_ALLOCATION_RESPS  5 
98 /* Size of RM service response queue */
99 #define MAX_QUEUED_SERVICE_RESPONSES 10
101 /* Error checking macro */
102 #define ERROR_CHECK(checkVal, resultVal, rmInstName, printMsg)                   \
103     if (resultVal != checkVal) {                                                 \
104         char errorMsgToPrint[] = printMsg;                                       \
105         System_printf("Error Core %d : %s : ", coreNum, rmInstName);    \
106         System_printf("%s with error code : %d\n", errorMsgToPrint, resultVal);  \
107         System_abort("Test Failure\n");                                          \
108     }
110 /**********************************************************************
111  ********************** RM Test Data Structures ***********************
112  **********************************************************************/
114 /* IPC MessageQ RM packet encapsulation structure */
115 typedef struct {
116     /* IPC MessageQ header (must be first element in structure) */
117     MessageQ_MsgHeader  msgQHeader;
118     /* Pointer to RM packet */
119     Rm_Packet          *rmPkt;
120 } MsgQ_RmPacket;
122 /* RM registered transport mapping structure */
123 typedef struct {
124     /* Registered RM transport handle */
125     Rm_TransportHandle transportHandle;
126     /* MessageQ receive queue tied to the transport handle */
127     MessageQ_Handle    receiveMsgQ;
128 } Transport_MapEntry;
130 /**********************************************************************
131  ********************** Extern Variables ******************************
132  **********************************************************************/
134 /* RM test Global Resource List (GRL) */
135 extern const char rmGrl[];
136 /* Example Linux DTB file provided to RM Server for automatic Linux Kernel resource extraction */
137 extern const char rmLinuxDtb[];
138 /* RM test Global Policy provided to RM Server */
139 extern const char rmGlobalPolicy[];
140 /* RM test Static Policy provided to RM Client Delegate and Client */
141 extern const char rmStaticPolicy[];
143 /* OSAL RM Local Gate Initialization. */
144 extern void Osal_rmLocalGateInit (void);
146 /**********************************************************************
147  ********************** Global Variables ******************************
148  **********************************************************************/
150 /* DSP core number according to IPC */
151 uint16_t            coreNum;
153 /* Task to configure application transport code for RM */
154 Task_Handle         rmStartupTskHandle;
155 /* High priority task for receiving RM packets */
156 Task_Handle         rmReceiveTskHandle;
157 /* RM server test task */
158 Task_Handle         rmServerTskHandle;
159 /* RM client delegate and client test task */
160 Task_Handle         rmClientTskHandle;
162 /* GateMP used to synchronize tests between the two RM test tasks */
163 GateMP_Handle       gateHandle = NULL;
164 /* GateMP key */
165 IArg                gateKey;
167 /* Handle for heap that RM packets will be allocated from */
168 HeapBufMP_Handle    rmPktHeapHandle = NULL;
170 /* MessageQ used by RM CD to send packets to RM Server */
171 char                serverFromCdQueueName[30] = "RM_Server_From_CD_Queue";
172 /* MessageQ used by RM Server to send packets to RM CD */
173 char                cdFromServerQueueName[30] = "RM_CD_From_Server_Queue";
174 /* MessageQ used by RM Client to send packets to RM CD */
175 char                cdFromClientQueueName[30] = "RM_CD_From_Client_Queue";
176 /* MessageQ used by RM CD to send packets to RM Client */
177 char                clientFromCdQueueName[30] = "RM_Client_From_CD_Queue";
179 /* RM Server instance name (must match with RM Global Resource List (GRL) and policies */
180 char                rmServerName[RM_NAME_MAX_CHARS] = "RM_Server";
181 /* RM CD instance name (must match with RM Global Resource List (GRL) and policies */
182 char                rmCdName[RM_NAME_MAX_CHARS]     = "RM_Client_Delegate";
183 /* RM Client instance name (must match with RM Global Resource List (GRL) and policies */
184 char                rmClientName[RM_NAME_MAX_CHARS] = "RM_Client";
186 /* RM instance handles */
187 Rm_Handle           rmServerHandle = NULL;
188 Rm_Handle           rmCdHandle     = NULL;
189 Rm_Handle           rmClientHandle = NULL;
191 /* RM instance service handles */
192 Rm_ServiceHandle   *rmServerServiceHandle = NULL;
193 Rm_ServiceHandle   *rmCdServiceHandle     = NULL;
194 Rm_ServiceHandle   *rmClientServiceHandle = NULL;
196 /* Transport map stores the RM transport handle to IPC MessageQ queue mapping */
197 Transport_MapEntry  rmTransportMap[MAX_MAPPING_ENTRIES];
199 /* Static allocation response queue */
200 Rm_ServiceRespInfo  staticResponseQueue[MAX_STATIC_ALLOCATION_RESPS];
201 /* Static allocation response queue index */
202 uint32_t            numStaticResponses;
205 /* RM response info queue used to store service responses received via the callback function */
206 Rm_ServiceRespInfo  responseInfoQueue[MAX_QUEUED_SERVICE_RESPONSES];
208 /* RM resource names (must match resource node names in GRL and policies */
209 char                resourceNameMemRegion[RM_NAME_MAX_CHARS]  = "memory-regions";
210 char                resourceNameAccumCh[RM_NAME_MAX_CHARS]    = "accumulator-ch";
211 char                resourceNameGpQ[RM_NAME_MAX_CHARS]        = "gp-queue";
212 char                resourceNameAifQ[RM_NAME_MAX_CHARS]       = "aif-queue";
213 char                resourceNameQosCluster[RM_NAME_MAX_CHARS] = "qos-cluster";
214 char                resourceNameAifRxCh[RM_NAME_MAX_CHARS]    = "aif-rx-ch";
215 char                resourceNameInfraQ[RM_NAME_MAX_CHARS]     = "infra-queue";
217 /* Test RM NameServer name */
218 char                nameServerNameFavQ[RM_NAME_MAX_CHARS]     = "My_Favorite_Queue";
220 /**********************************************************************
221  *************************** Test Functions ***************************
222  **********************************************************************/
224 void beginMemAccess (void *ptr, uint32_t size)
226     uint32_t key;
228     key = Hwi_disable();
230     /* Cleanup the prefetch buffer also. */
231     CSL_XMC_invalidatePrefetchBuffer();
232     /* Invalidate L1D cache and wait until operation is complete.
233      * Use this approach if L2 cache is not enabled */
234     CACHE_invL1d (ptr, size, CACHE_FENCE_WAIT);
235     asm   (" nop      4");
236     asm   (" nop      4");
237     asm   (" nop      4");
238     asm   (" nop      4");
239     Hwi_restore(key);
242 void endMemAccess (void *ptr, uint32_t size)
244     uint32_t key;
246     key = Hwi_disable();
248     /* Writeback L1D cache and wait until operation is complete.
249      * Use this approach if L2 cache is not enabled */
250     CACHE_wbL1d (ptr, size, CACHE_FENCE_WAIT);
251     asm   (" nop      4");
252     asm   (" nop      4");
253     asm   (" nop      4");
254     asm   (" nop      4");
255     Hwi_restore(key);
258 Rm_Packet *transportAlloc(Rm_AppTransportHandle appTransport, uint32_t pktSize, Rm_PacketHandle *pktHandle)
260     Rm_Packet     *rmPkt = NULL;
261     MsgQ_RmPacket *rmMsg = NULL;
263     /* Allocate a messageQ message for containing the RM packet */
264     rmMsg = (MsgQ_RmPacket *)MessageQ_alloc(MSGQ_HEAP_ID, sizeof(MsgQ_RmPacket));
265     if (rmMsg == NULL) {
266         System_printf("Core %d: MessageQ_alloc failed in TransportSend\n", coreNum);
267         *pktHandle = NULL;
268         return(NULL);
269     }
270     else {
271         /* Create and attach RM packet to MessageQ message.  All transports will allocate from the same heap */
272         rmPkt = HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
273         rmPkt->pktLenBytes = pktSize;
274         endMemAccess((void *)rmPkt, rmPkt->pktLenBytes);
275         rmMsg->rmPkt = rmPkt;
276         *pktHandle = (Rm_PacketHandle)rmMsg;
277     }
278     return (rmPkt);
281 void transportFree (MessageQ_Msg rmMsgQMsg, Rm_Packet *pkt)
283     uint32_t pktSize = pkt->pktLenBytes;
284     int32_t  status;
286     /* All transports will free rmPkts to the same heap */
287     HeapBufMP_free(rmPktHeapHandle, pkt, pktSize);
289     status = MessageQ_free(rmMsgQMsg);
290     if (status < 0) { 
291         System_printf("Core %d: MessageQ_free had a failure/error in transportFree\n", coreNum);
292     }     
295 int32_t transportSend (Rm_AppTransportHandle appTransport, Rm_PacketHandle pktHandle)
297     MessageQ_QueueId  remoteQueueId = (MessageQ_QueueId)appTransport;
298     MsgQ_RmPacket    *rmMsg = pktHandle;
299     int32_t           status;    
301     /* Write back data that was written by RM after alloc */
302     endMemAccess((void *)rmMsg->rmPkt, rmMsg->rmPkt->pktLenBytes);
304     /* Send the message to the remote side */
305     status = MessageQ_put(remoteQueueId, (MessageQ_Msg)rmMsg);
306     if (status < 0) {
307         transportFree((MessageQ_Msg)rmMsg, rmMsg->rmPkt);
308         System_printf("Core %d: MessageQ_put had a failure/error in TransportSend: error: %d\n", coreNum,
309                                                                                                  status);
310     }
311     return (status);
314 void transportReceive (uint32_t transportMapEntry)
316     MessageQ_Handle  receiveQ;
317     int32_t          numPkts;
318     MessageQ_Msg     rmMsg = NULL;
319     Rm_Packet       *rmPkt = NULL;
320     int32_t          status;
321     uint32_t         i;  
323     /* Check if any packets available */
324     receiveQ = rmTransportMap[transportMapEntry].receiveMsgQ;
325     numPkts = (int32_t) MessageQ_count(receiveQ);
327     /* Process all available packets */
328     for (i = 0; i < numPkts; i++) {
329         status = (int32_t) MessageQ_get(receiveQ, &rmMsg, MessageQ_FOREVER);
330         if (status < 0) {
331             System_abort("This should not happen since timeout is forever\n");
332         }
333         if (rmMsg == NULL) {
334             System_printf("Core %d: MessageQ_get failed returning a null packet in TransportReceive\n", coreNum);
335         }
337         /* Extract the Rm_Packet from the RM msg */
338         rmPkt = ((MsgQ_RmPacket *)rmMsg)->rmPkt;
339         beginMemAccess((void *) rmPkt, rmPkt->pktLenBytes);
341         /* Provide packet to RM for processing */
342         if (status = Rm_receivePacket(rmTransportMap[transportMapEntry].transportHandle, rmPkt)) {
343             System_printf("Core %d: RM encountered error processing received packet: %d\n", coreNum, status);
344         }
346         /* Free RM packet buffer and messageQ message */
347         transportFree(rmMsg, rmPkt);
348     }
351 void serviceCallback(Rm_ServiceRespInfo *serviceResponse)
353     uint32_t qIndex = 0;
354     
355     /* Populate next free entry in the responseInfoQueue */
356     while (responseInfoQueue[qIndex].serviceId != 0) {
357         qIndex++;
358         if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
359             qIndex = 0;
360         }
361     }
363     /* Save the response in the response queue for the test task to pick up */
364     memcpy((void *)&responseInfoQueue[qIndex], (void *)serviceResponse, sizeof(Rm_ServiceRespInfo));
367 bool waitForResponse(Rm_ServiceRespInfo *respInfo)
369     uint32_t qIndex = 0;
371     if (respInfo->serviceState == RM_SERVICE_PROCESSING) {
372         /* Scan responseInfoQueue for the response received via the callback function */
373         while((responseInfoQueue[qIndex].serviceId != respInfo->serviceId) ||
374               (responseInfoQueue[qIndex].rmHandle != respInfo->rmHandle)) {
375             qIndex++;
376             if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
377                 qIndex = 0;
378             }
379             
380             /* Higher priority receive task will retrieve response */
381         }  
383         memcpy((void *)respInfo, (void *)&responseInfoQueue[qIndex], sizeof(Rm_ServiceRespInfo));
384         memset((void *)&responseInfoQueue[qIndex], 0, sizeof(Rm_ServiceRespInfo));
385     }
386     return(TRUE);
389 void setRmRequest(Rm_ServiceReqInfo *reqInfo, Rm_ServiceType type, const char *resName, int32_t resBase,
390                   uint32_t resLen, int32_t resAlign, const char *nsName, bool setCallback, Rm_ServiceRespInfo *respInfo)
391 {                                                                                
392     memset((void *)reqInfo, 0, sizeof(Rm_ServiceReqInfo));                                        
393     reqInfo->type = type;                                                                           
394     reqInfo->resourceName = resName;                                                                
395     reqInfo->resourceBase = resBase;                                                                
396     reqInfo->resourceLength = resLen;                                                               
397     reqInfo->resourceAlignment = resAlign;                                                          
398     reqInfo->resourceNsName = nsName;
399     if (setCallback) {
400         reqInfo->callback.serviceCallback = serviceCallback;  
401     }
402     memset((void *)respInfo, 0, sizeof(Rm_ServiceRespInfo));                                     
405 void rmCleanupTsk(UArg arg0, UArg arg1)
407     int32_t result;
408     
409     /* Delete the RM test tasks */
410     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
411     if (rmStartupTskHandle) {
412        Task_delete(&rmStartupTskHandle);
413        /* Set the task handle to be NULL so that the delete only occurs once */
414        rmStartupTskHandle = NULL;
415     }  
416     
417     if (coreNum == 0) {
418         if (rmServerTskHandle) {
419             System_printf("Core %d: Deleting RM server task...\n", coreNum);
420             Task_delete(&rmServerTskHandle);
421             /* Set the task handle to be NULL so that the delete only occurs once */
422             rmServerTskHandle = NULL;
423         }
424     }
425     else if (coreNum == 1) {
426         if (rmClientTskHandle) {
427             System_printf("Core %d: Deleting RM client task...\n", coreNum);        
428             Task_delete(&rmClientTskHandle);
429             /* Set the task handle to be NULL so that the delete only occurs once */
430             rmClientTskHandle = NULL;
431         }
432     }
433     
434     /* Delete the RM receive task */
435     System_printf("Core %d: Deleting RM receive task...\n", coreNum);
436     if (rmReceiveTskHandle) {
437         Task_delete(&rmReceiveTskHandle);
438         /* Set the task handle to be NULL so that the delete only occurs once */
439         rmReceiveTskHandle = NULL;
440     }
442     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
443     if (coreNum == 0) {
444         Rm_serviceCloseHandle(rmServerServiceHandle);
446         Rm_transportUnregister(rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle);
448         result = Rm_delete(rmServerHandle, true);
449         if (result != RM_OK) {
450             System_printf("Core %d: RM server instance delete failed with error %d\n", coreNum, result);
451         }        
452     }
453     else if (coreNum == 1) {
454         Rm_serviceCloseHandle(rmCdServiceHandle);
455         Rm_serviceCloseHandle(rmClientServiceHandle);
457         Rm_transportUnregister(rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle);
458         Rm_transportUnregister(rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle);
459         Rm_transportUnregister(rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle);
461         result = Rm_delete(rmCdHandle, true);
462         if (result != RM_OK) {
463             System_printf("Core %d: RM cd instance delete failed with error %d\n", coreNum, result);
464         }  
465         result = Rm_delete(rmClientHandle, true);
466         if (result != RM_OK) {
467             System_printf("Core %d: RM client instance delete failed with error %d\n", coreNum, result);
468         }          
469     }
471     BIOS_exit(0);
474 /* Receive task has priority of 2 so that it pre-empts the RM instance test tasks */
475 void rmReceiveTsk(UArg arg0, UArg arg1)
477     while(1) {
478         if (coreNum == 0) {
479             transportReceive(SERVER_TO_CD_MAP_ENTRY);
480         }
481         else if (coreNum == 1) {
482             transportReceive(CD_TO_SERVER_MAP_ENTRY);
483             transportReceive(CD_TO_CLIENT_MAP_ENTRY);
484             transportReceive(CLIENT_TO_CD_MAP_ENTRY);
485         }
486         /* Sleep for 1ms so that the main test tasks can run */
487         Task_sleep(1);
488     }
491 void rmServerTsk(UArg arg0, UArg arg1)
493     Rm_ServiceReqInfo  requestInfo;
494     Rm_ServiceRespInfo responseInfo;
495     Task_Params        taskParams;
497     Rm_printInstanceStatus(rmServerHandle);
499     /* BEGIN testing UNSPECIFIED base and alignment requests on Server */               
500     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
501                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 0, NULL, TRUE, &responseInfo);       
502     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
503     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
504                                                                                                   rmServerName,
505                                                                                                   resourceNameGpQ,
506                                                                                                   requestInfo.resourceLength, 
507                                                                                                   requestInfo.resourceAlignment);
508     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
509         System_printf("PASSED\n");
510     }
511     else {
512         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
513     }    
514                
515     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
516                  RM_RESOURCE_BASE_UNSPECIFIED, 1, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
517     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
518     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
519                                                                                                            rmServerName,
520                                                                                                            resourceNameGpQ,
521                                                                                                            requestInfo.resourceLength);
522     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
523         System_printf("PASSED\n");
524     }
525     else {
526         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
527     }     
529     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
530                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 200, NULL, TRUE, &responseInfo);     
531     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
532     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
533                                                                                                   rmServerName,
534                                                                                                   resourceNameGpQ,
535                                                                                                   requestInfo.resourceLength,
536                                                                                                   requestInfo.resourceAlignment);
537     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
538         System_printf("PASSED\n");
539     }
540     else {
541         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
542     }      
543     /* END testing UNSPECIFIED base and alignment requests on Server */      
545     /* Create new NameServer object */                
546     setRmRequest(&requestInfo, Rm_service_RESOURCE_MAP_TO_NAME, resourceNameGpQ, 
547                  1002, 1, 0, nameServerNameFavQ, TRUE, &responseInfo);     
548     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
549     System_printf("Core %d : %s create name %s tied to %s %d - %d : ", coreNum,
550                                                                        rmServerName,
551                                                                        nameServerNameFavQ,
552                                                                        responseInfo.resourceName,
553                                                                        requestInfo.resourceBase, 
554                                                                        (requestInfo.resourceBase + requestInfo.resourceLength - 1));                                                                       
555     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
556         System_printf("PASSED\n");
557     }
558     else {
559         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
560     }     
562     /* Wait for CD and Client retrieve resource via name, allocate the resource, free resource via name, and 
563      * delete the NameServer object. */
564     gateKey = GateMP_enter(gateHandle);
565     GateMP_leave(gateHandle, gateKey);
567     /* Try to allocate the memory region taken by the Linux Kernel and not specified as shared */
568     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameMemRegion, 
569                  12, 1, 0, NULL, TRUE, &responseInfo);     
570     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
571     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
572                                                                   rmServerName,
573                                                                   resourceNameMemRegion,
574                                                                   requestInfo.resourceBase, 
575                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
576     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
577         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
578     }
579     else {
580         System_printf("FAILED\n");
581     }    
583     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
584     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
585                  14, 5, 0, NULL, TRUE, &responseInfo);       
586     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
587     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
588                                                                   rmServerName,
589                                                                   resourceNameAifRxCh,
590                                                                   requestInfo.resourceBase, 
591                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
592     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
593         System_printf("PASSED\n");
594     }
595     else {
596         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
597     } 
598     
599     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
600                  19, 31, 0, NULL, TRUE, &responseInfo);      
601     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
602     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
603                                                                   rmServerName,
604                                                                   resourceNameAifRxCh,
605                                                                   requestInfo.resourceBase, 
606                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
607     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
608         System_printf("PASSED\n");
609     }
610     else {
611         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
612     }        
613     
614     /* Wait for Client and Client Delegate to do their allocations */
615     gateKey = GateMP_enter(gateHandle);
616     GateMP_leave(gateHandle, gateKey);       
618     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
619                  25, 3, 0, NULL, TRUE, &responseInfo);      
620     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
621     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
622                                                         rmServerName,
623                                                         resourceNameAifRxCh,
624                                                         requestInfo.resourceBase, 
625                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
626     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
627         System_printf("PASSED\n");
628     }
629     else {
630         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
631     }      
632     
633     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
634                  34, 3, 0, NULL, TRUE, &responseInfo);      
635     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
636     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
637                                                         rmServerName,
638                                                         resourceNameAifRxCh,
639                                                         requestInfo.resourceBase, 
640                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
641     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
642         System_printf("PASSED\n");
643     }
644     else {
645         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
646     }      
647  
648     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
649                  28, 6, 0, NULL, TRUE, &responseInfo);      
650     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);   
651     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
652                                                         rmServerName,
653                                                         resourceNameAifRxCh,
654                                                         requestInfo.resourceBase, 
655                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
656     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
657         System_printf("PASSED\n");
658     }
659     else {
660         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
661     }      
663     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
664                  53, 2, 0, NULL, TRUE, &responseInfo);      
665     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
666     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
667                                                                   rmServerName,
668                                                                   resourceNameAifRxCh,
669                                                                   requestInfo.resourceBase, 
670                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
671     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
672         System_printf("PASSED\n");
673     }
674     else {
675         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
676     }  
677     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */  
678     
679     /* Test execlusive rights to an allocated resource */
680     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
681                  2, 2, 0, NULL, TRUE, &responseInfo);      
682     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
683     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
684                                                                   rmServerName,
685                                                                   resourceNameAifRxCh,
686                                                                   requestInfo.resourceBase, 
687                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
688     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {
689         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
690     }
691     else {
692         System_printf("FAILED\n");
693     }      
695     /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
696     gateKey = GateMP_enter(gateHandle);
697     GateMP_leave(gateHandle, gateKey);
699     /* Test allocation of a resource twice from the same instance with init and use privileges.  Both
700      * should be approved but the instance should only be mentioned once in the resource's owner list */
701     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
702                  6543, 10, 0, NULL, TRUE, &responseInfo);      
703     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
704     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
705                                                                    rmServerName,
706                                                                    resourceNameGpQ,
707                                                                    requestInfo.resourceBase, 
708                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
709     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
710         System_printf("PASSED\n");
711     }
712     else {
713         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
714     }     
716     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
717                  6543, 10, 0, NULL, TRUE, &responseInfo);      
718     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
719     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
720                                                                   rmServerName,
721                                                                   resourceNameGpQ,
722                                                                   requestInfo.resourceBase, 
723                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
724     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
725         System_printf("PASSED\n");
726     }
727     else {
728         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
729     }        
731     /* Allocate infrastructure queue taken by Linux kernel and shared with Rm_Client.  Expect error or denial. */
732     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
733                  805, 1, 0, NULL, TRUE, &responseInfo);     
734     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
735     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
736                                                                    rmServerName,
737                                                                    resourceNameInfraQ,
738                                                                    requestInfo.resourceBase, 
739                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
740     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
741         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
742     }
743     else {
744         System_printf("FAILED\n");
745     }              
747     System_printf("Core %d: Testing is complete\n", coreNum);
749     Rm_printInstanceStatus(rmServerHandle);
750     Rm_printResourceStatus(rmServerHandle);   
751     
752     /* Create the RM cleanup task. */
753     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
754     Task_Params_init (&taskParams);
755     Task_create (rmCleanupTsk, &taskParams, NULL);
758 void rmClientTsk(UArg arg0, UArg arg1)
760     Rm_ServiceReqInfo  requestInfo;
761     Rm_ServiceRespInfo responseInfo;    
762     Task_Params        taskParams;
763     uint32_t           i, j;
765     Rm_printInstanceStatus(rmCdHandle);
766     Rm_printInstanceStatus(rmClientHandle);
768     /* Retrieve a resource via a NameServer name */
769     setRmRequest(&requestInfo, Rm_service_RESOURCE_GET_BY_NAME, NULL, 
770                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
771     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
772     System_printf("Core %d : %s get resource with name %s : ", coreNum,
773                                                                rmCdName,
774                                                                nameServerNameFavQ);
775     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
776         waitForResponse(&responseInfo);
777     }
778     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
779         System_printf("PASSED\n");
780     }
781     else {
782         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
783     } 
785     /* Allocate the resource returned from the NameServer request */
786     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo)); 
787     requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
788     requestInfo.resourceName = responseInfo.resourceName;
789     requestInfo.resourceBase = responseInfo.resourceBase;
790     requestInfo.resourceLength = responseInfo.resourceLength;
791     requestInfo.resourceNsName = NULL;
792     requestInfo.callback.serviceCallback = serviceCallback;     
793     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
794     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
795                                                                    rmClientName,
796                                                                    responseInfo.resourceName,
797                                                                    requestInfo.resourceBase, 
798                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
799     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
800         waitForResponse(&responseInfo);
801     }
802     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
803         System_printf("PASSED\n");
804     }
805     else {
806         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
807     }    
809     /* Free resource via a NameServer name */
810     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, NULL, 
811                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
812     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
813     System_printf("Core %d : %s free resource with name %s : ", coreNum,
814                                                                 rmClientName,
815                                                                 nameServerNameFavQ);
816     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
817         waitForResponse(&responseInfo);
818     }
819     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
820         System_printf("PASSED\n");
821     }
822     else {
823         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
824     }      
826     /* Delete the NameServer name */
827     setRmRequest(&requestInfo, Rm_service_RESOURCE_UNMAP_NAME, NULL, 
828                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
829     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);     
830     System_printf("Core %d : %s delete name %s : ", coreNum,
831                                                     rmClientName,
832                                                     nameServerNameFavQ);
833     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
834         waitForResponse(&responseInfo);
835     }
836     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
837         System_printf("PASSED\n");
838     }
839     else {
840         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
841     }     
843     GateMP_leave(gateHandle, gateKey);
844     gateKey = GateMP_enter(gateHandle);
846     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
847     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
848                  0, 6, 0, NULL, TRUE, &responseInfo);     
849     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
850     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
851                                                                   rmClientName,
852                                                                   resourceNameAifRxCh,
853                                                                   requestInfo.resourceBase, 
854                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
855     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
856         waitForResponse(&responseInfo);
857     }
858     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
859         System_printf("PASSED\n");
860     }
861     else {
862         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
863     }     
864     
865     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifRxCh, 
866                  50, 7, 0, NULL, TRUE, &responseInfo);        
867     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
868     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
869                                                                    rmCdName,
870                                                                    resourceNameAifRxCh,
871                                                                    requestInfo.resourceBase, 
872                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
873     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
874         waitForResponse(&responseInfo);
875     }
876     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
877         System_printf("PASSED\n");
878     }
879     else {
880         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
881     }       
882     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */
884     GateMP_leave(gateHandle, gateKey);    
885     gateKey = GateMP_enter(gateHandle);
887     /* BEGIN testing allocations with UNSPECIFIED base and alignment values */
888     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
889                  RM_RESOURCE_BASE_UNSPECIFIED, 5, 4, NULL, TRUE, &responseInfo);        
890     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
891     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
892                                                                                                   rmCdName,
893                                                                                                   resourceNameAccumCh,
894                                                                                                   requestInfo.resourceLength, 
895                                                                                                   requestInfo.resourceAlignment);
896     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
897         waitForResponse(&responseInfo);
898     }
899     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
900         System_printf("PASSED\n");
901     }
902     else {
903         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
904     }        
906     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
907                  RM_RESOURCE_BASE_UNSPECIFIED, 2, 1, NULL, TRUE, &responseInfo);      
908     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
909     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
910                                                                                                   rmClientName,
911                                                                                                   resourceNameAccumCh,
912                                                                                                   requestInfo.resourceLength, 
913                                                                                                   requestInfo.resourceAlignment);
914     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
915         waitForResponse(&responseInfo);
916     }
917     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
918         System_printf("PASSED\n");
919     }
920     else {
921         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
922     }     
924     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
925                  RM_RESOURCE_BASE_UNSPECIFIED, 2, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
926     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
927     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
928                                                                                                            rmClientName,
929                                                                                                            resourceNameAccumCh,
930                                                                                                            requestInfo.resourceLength);
931     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
932         waitForResponse(&responseInfo);
933     }
934     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
935         System_printf("PASSED\n");
936     }
937     else {
938         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
939     }     
940     /* END testing allocations with UNSPECIFIED base and alignment values */    
942     /* Allocate infrastructure queue shared between Linux kernel and Client */
943     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
944                  800, 1, 0, NULL, TRUE, &responseInfo);     
945     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
946     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
947                                                                    rmClientName,
948                                                                    resourceNameInfraQ,
949                                                                    requestInfo.resourceBase, 
950                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
951     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
952         waitForResponse(&responseInfo);
953     }
954     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
955         System_printf("PASSED\n");
956     }
957     else {
958         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
959     }     
961     /* Allocate a resource without providing a callback function.  RM should block and not return until the result
962      * is returned by the server. */
963     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
964                  7000, 1, 0, NULL, FALSE, &responseInfo);     
965     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);   
966     System_printf("Core %d : %s init allocation (without callback specified) of %s %d - %d : ", coreNum,
967                                                                                                 rmClientName,
968                                                                                                 resourceNameGpQ,
969                                                                                                 requestInfo.resourceBase, 
970                                                                                                 (requestInfo.resourceBase + requestInfo.resourceLength - 1));
971     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
972         waitForResponse(&responseInfo);
973     }
974     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
975         System_printf("PASSED\n");
976     }
977     else {
978         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
979     }      
981     GateMP_leave(gateHandle, gateKey);           
983     /* Verify static allocations were validated.  Validation responses should have been received after the
984      * first service requests were made on the Client and CD post transport path registration. */
985     while (numStaticResponses > 0) {
986         /* Loop until all static request validations have been received */
987         for (i = 0; i < MAX_STATIC_ALLOCATION_RESPS; i++) {
988             if (staticResponseQueue[i].serviceId != 0) {            
989                 for (j = 0; j < MAX_QUEUED_SERVICE_RESPONSES; j++) {
990                     if ((staticResponseQueue[i].serviceId == responseInfoQueue[j].serviceId) &&
991                         (staticResponseQueue[i].rmHandle == responseInfoQueue[j].rmHandle)) {
992                         System_printf("Core %d : static allocation validation of %s %d - %d : ", coreNum,
993                                                                                                  responseInfoQueue[j].resourceName,
994                                                                                                  responseInfoQueue[j].resourceBase, 
995                                                                                                  (responseInfoQueue[j].resourceBase + responseInfoQueue[j].resourceLength - 1));        
996                         if (responseInfoQueue[j].serviceState == RM_SERVICE_APPROVED) {
997                             System_printf("PASSED\n");
998                         }
999                         else {
1000                             System_printf("FAILED : denial or error : %d\n", responseInfoQueue[j].serviceState);
1001                         }  
1002                         memset((void *)&staticResponseQueue[i], 0, sizeof(Rm_ServiceRespInfo));
1003                         memset((void *)&responseInfoQueue[j], 0, sizeof(Rm_ServiceRespInfo));
1004                         numStaticResponses--;                        
1005                         break;
1006                     }
1007                 }
1008             }
1009         }    
1010     }   
1013     System_printf("Core %d: Testing is complete\n", coreNum);
1015     Rm_printInstanceStatus(rmCdHandle);
1016     Rm_printInstanceStatus(rmClientHandle);
1017     
1018     /* Create the RM cleanup task. */
1019     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
1020     Task_Params_init (&taskParams);
1021     Task_create (rmCleanupTsk, &taskParams, NULL);
1024 void rmStartupTsk(UArg arg0, UArg arg1)
1026     MessageQ_Handle    serverFromCdMsgQ, cdFromServerMsgQ, cdFromClientMsgQ, clientFromCdMsgQ;
1027     MessageQ_QueueId   serverToCdQId, cdToServerQId, cdToClientQId, clientToCdQId;    
1028     Int                status, i;
1029     GateMP_Params      gateParams;    
1030     HeapBufMP_Handle   msgQHeapHandle;
1031     HeapBufMP_Params   heapBufParams;
1032     Rm_TransportCfg    rmTransportCfg;
1033     int32_t            result = 0;
1034     Rm_TransportHandle serverCdHandle, cdServerHandle, cdClientHandle, clientCdHandle;
1035     Task_Params        taskParams;
1037     /* Initialize the transport map */
1038     for (i = 0; i < MAX_MAPPING_ENTRIES; i++) {
1039         rmTransportMap[i].transportHandle = NULL;
1040     }
1042     /* Create the gate internal to RM for service requests not specifying a callback function
1043      * and needing a blocking operation to complete.
1044      *
1045      * Must be created from a different task than the test tasks to allow proper blocking. */
1046     Osal_rmLocalGateInit();  
1048     if (coreNum == 0) {
1049         GateMP_Params_init(&gateParams);
1050         gateParams.name = RM_TASK_GATE_NAME;
1051         gateHandle = GateMP_create(&gateParams);
1052         
1053         /* Create the heap that will be used to allocate RM messages. This
1054          * heap is a multi-processor heap.  It will be shared amongst
1055          * all RM instances. */     
1056         HeapBufMP_Params_init(&heapBufParams);
1057         heapBufParams.regionId       = 0;
1058         heapBufParams.name           = RM_PKT_HEAP_NAME;
1059         heapBufParams.numBlocks      = 64;
1060         heapBufParams.blockSize      = sizeof(Rm_Packet);
1061         rmPktHeapHandle = HeapBufMP_create(&heapBufParams);
1062         if (rmPktHeapHandle == NULL) {
1063             System_abort("HeapBufMP_create failed for RM packet heap\n" );
1064         }
1065         System_printf("Core %d: RM packet heap created\n", coreNum);
1067         /* Create the heap that will be used to allocate messageQ messages. */     
1068         HeapBufMP_Params_init(&heapBufParams);
1069         heapBufParams.regionId       = 0;
1070         heapBufParams.name           = MSGQ_HEAP_NAME;
1071         heapBufParams.numBlocks      = 64;
1072         heapBufParams.blockSize      = sizeof(MsgQ_RmPacket);
1073         msgQHeapHandle = HeapBufMP_create(&heapBufParams);
1074         if (msgQHeapHandle == NULL) {
1075             System_abort("HeapBufMP_create failed MessageQ message heap\n" );
1076         } 
1077         System_printf("Core %d: IPC MessageQ message heap created\n", coreNum);
1078     }
1079     else {
1080         do {
1081             status = GateMP_open(RM_TASK_GATE_NAME, &gateHandle);
1082             /* 
1083              *  Sleep for 1 clock tick to avoid inundating remote processor
1084              *  with interrupts if open failed
1085              */
1086             if (status < 0) { 
1087                 Task_sleep(1);
1088             }
1089         } while (status < 0);
1090         /* Take the gate right away to prepare for RM testing */
1091         gateKey = GateMP_enter(gateHandle);
1092         
1093         /* Open the heaps created by the other processor. Loop until opened. */
1094         do {
1095             status = HeapBufMP_open(RM_PKT_HEAP_NAME, &rmPktHeapHandle);
1096             /* 
1097              *  Sleep for 1 clock tick to avoid inundating remote processor
1098              *  with interrupts if open failed
1099              */
1100             if (status < 0) { 
1101                 Task_sleep(1);
1102             }
1103         } while (status < 0);
1104         System_printf("Core %d: RM packet heap opened\n", coreNum);
1105         
1106         do {
1107             status = HeapBufMP_open(MSGQ_HEAP_NAME, &msgQHeapHandle);
1108             /* 
1109              *  Sleep for 1 clock tick to avoid inundating remote processor
1110              *  with interrupts if open failed
1111              */
1112             if (status < 0) { 
1113                 Task_sleep(1);
1114             }
1115         } while (status < 0);
1116         System_printf("Core %d: IPC MessageQ message heap opened\n", coreNum);
1117     }
1118     
1119     /* Register the MessageQ heap with MessageQ */
1120     MessageQ_registerHeap(msgQHeapHandle, MSGQ_HEAP_ID);
1122     /* Create the messageQ's for each RM instance connection
1123      * Need four queues.  Topology will be:
1124      * RM Server <---> RM Client Delegate <---> RM Client 
1125      * 1 queues on RM Server
1126      * 2 queues on RM Client Delegate
1127      * 1 queues on RM Client */
1128     if (coreNum == 0) {
1129         serverFromCdMsgQ = MessageQ_create(serverFromCdQueueName, NULL);
1130         if (serverFromCdMsgQ == NULL) {
1131             System_abort("MessageQ_create failed for RM Server - Client Delegate queue\n" );
1132         }
1133         System_printf("Core %d: RM Server MessageQ created for receiving packets from RM CD\n", coreNum);
1134     }
1135     else if (coreNum == 1) {
1136         cdFromServerMsgQ = MessageQ_create(cdFromServerQueueName, NULL);
1137         if (cdFromServerMsgQ == NULL) {
1138             System_abort("MessageQ_create failed for RM Client Delegate - Server queue\n" );
1139         }
1140         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Server\n", coreNum);
1141         
1142         cdFromClientMsgQ = MessageQ_create(cdFromClientQueueName, NULL);
1143         if (cdFromClientMsgQ == NULL) {
1144             System_abort("MessageQ_create failed for RM Client Delegate - Client queue\n" );
1145         } 
1146         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Client\n", coreNum);
1147         
1148         clientFromCdMsgQ = MessageQ_create(clientFromCdQueueName, NULL);
1149         if (clientFromCdMsgQ == NULL) 
1150         {
1151             System_abort("MessageQ_create failed for RM Client - Client Delegate queue\n" );
1152         }
1153         System_printf("Core %d: RM Client MessageQ created for receiving packets from RM CD\n", coreNum);
1154     }
1155     
1156     /* Open the remote message queues. Also register the RM transports with each RM instance */
1157     if (coreNum == 0) {
1158         /* Open the Client Delegate messageQ from the Server */
1159         do {
1160             status = MessageQ_open(cdFromServerQueueName, &serverToCdQId); 
1161             /* 
1162              *  Sleep for 1 clock tick to avoid inundating remote processor
1163              *  with interrupts if open failed
1164              */
1165             if (status < 0) { 
1166                 Task_sleep(1);
1167             }
1168         } while (status < 0);
1169         System_printf("Core %d: RM CD MessageQ opened from RM Server\n", coreNum);
1171         /* Register the Client Delegate with the RM Server Instance */
1172         rmTransportCfg.rmHandle = rmServerHandle;
1173         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) serverToCdQId;
1174         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1175         rmTransportCfg.remoteInstName = &rmCdName[0];
1176         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1177         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1178         serverCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1180         /* Store the mapping information in the transport map */
1181         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle = serverCdHandle;
1182         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].receiveMsgQ = serverFromCdMsgQ;
1183         System_printf("Core %d: Registered RM Server <=> RM CD transport with RM Server instance\n", coreNum);
1184     }
1185     else if (coreNum == 1) {
1186         /* Open the Server messageQ from the Client Delegate */
1187         do {
1188             status = MessageQ_open(serverFromCdQueueName, &cdToServerQId); 
1189             /* 
1190              *  Sleep for 1 clock tick to avoid inundating remote processor
1191              *  with interrupts if open failed
1192              */
1193             if (status < 0) { 
1194                 Task_sleep(1);
1195             }
1196         } while (status < 0);
1197         System_printf("Core %d: RM Server MessageQ opened from RM CD\n", coreNum);
1199         /* Register the Server with the RM Client Delegate Instance */
1200         rmTransportCfg.rmHandle = rmCdHandle;
1201         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToServerQId;
1202         rmTransportCfg.remoteInstType = Rm_instType_SERVER;
1203         rmTransportCfg.remoteInstName = &rmServerName[0];
1204         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1205         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1206         cdServerHandle = Rm_transportRegister(&rmTransportCfg, &result);
1208         /* Store the mapping information in the transport map */
1209         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle = cdServerHandle;
1210         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].receiveMsgQ = cdFromServerMsgQ;
1211         System_printf("Core %d: Registered RM CD <=> RM Server transport with RM CD instance\n", coreNum);
1212         
1213         /* Open the Client messageQ from the Client Delegate */
1214         do {
1215             status = MessageQ_open(clientFromCdQueueName, &cdToClientQId); 
1216             /* 
1217              *  Sleep for 1 clock tick to avoid inundating remote processor
1218              *  with interrupts if open failed
1219              */
1220             if (status < 0) { 
1221                 Task_sleep(1);
1222             }
1223         } while (status < 0);
1224         System_printf("Core %d: RM Client MessageQ opened from RM CD\n", coreNum);
1226         /* Register the Client with the RM Client Delegate Instance */
1227         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToClientQId;
1228         rmTransportCfg.remoteInstType = Rm_instType_CLIENT;
1229         rmTransportCfg.remoteInstName = &rmClientName[0];
1230         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1231         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1232         cdClientHandle = Rm_transportRegister(&rmTransportCfg, &result);
1234         /* Store the mapping information in the transport map */
1235         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle = cdClientHandle;
1236         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].receiveMsgQ = cdFromClientMsgQ;
1237         System_printf("Core %d: Registered RM CD <=> RM Client transport with RM CD instance\n", coreNum);
1239         /* Open the Client Delegate messageQ from the Client */        
1240         do {
1241             status = MessageQ_open(cdFromClientQueueName, &clientToCdQId); 
1242             /* 
1243              *  Sleep for 1 clock tick to avoid inundating remote processor
1244              *  with interrupts if open failed
1245              */
1246             if (status < 0) { 
1247                 Task_sleep(1);
1248             }
1249         } while (status < 0);
1250         System_printf("Core %d: RM CD MessageQ opened from RM Client\n", coreNum);
1252         /* Register the Client Delegate with the RM Client Instance */
1253         rmTransportCfg.rmHandle = rmClientHandle;
1254         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) clientToCdQId;
1255         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1256         rmTransportCfg.remoteInstName = &rmCdName[0];
1257         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1258         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1259         clientCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1261         /* Store the mapping information in the transport map */
1262         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle = clientCdHandle;
1263         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].receiveMsgQ = clientFromCdMsgQ;
1264         System_printf("Core %d: Registered RM Client <=> RM CD transport with RM Client instance\n", coreNum);
1265     }
1267     /* Create the RM receive task.  Assign higher priority than the test tasks so that
1268      * when they spin waiting for messages from other RM instances the receive task is
1269      * executed. */
1270     System_printf("Core %d: Creating RM receive task...\n", coreNum);
1271     Task_Params_init (&taskParams);
1272     taskParams.priority = 2;
1273     rmReceiveTskHandle = Task_create (rmReceiveTsk, &taskParams, NULL);
1274     
1275     /* Create the RM test tasks. */
1276     if (coreNum == 0) {
1277         System_printf("Core %d: Creating RM server task...\n", coreNum);
1278         Task_Params_init (&taskParams);
1279         taskParams.priority = 1;
1280         rmServerTskHandle = Task_create (rmServerTsk, &taskParams, NULL);
1281     }
1282     else if (coreNum) {
1283         System_printf("Core %d: Creating RM client task...\n", coreNum);
1284         Task_Params_init (&taskParams);
1285         taskParams.priority = 1;
1286         rmClientTskHandle = Task_create (rmClientTsk, &taskParams, NULL);
1287     }
1290 int main(Int argc, Char* argv[])
1292     Rm_InitCfg         rmInitCfg;
1293     Task_Params        taskParams; 
1294     int                status;
1295     Rm_ServiceReqInfo  requestInfo;
1296     Rm_ServiceRespInfo responseInfo;
1297     int32_t            result;
1299     System_printf ("*********************************************************\n");
1300     System_printf ("********************** RM Testing ***********************\n");
1301     System_printf ("*********************************************************\n");
1303     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
1305     coreNum = MultiProc_self();
1307     /* Initialize the RM instances - RM must be initialized before anything else in the system
1308      * Core 0: 1 RM Instance  - RM Server
1309      * Core 1: 2 RM Instances - RM Client Delegate
1310      *                          RM Client
1311      */
1312     if (coreNum == 0) {
1313         /* Create the Server instance */
1314         rmInitCfg.instName = rmServerName;
1315         rmInitCfg.instType = Rm_instType_SERVER;
1316         rmInitCfg.instCfg.serverCfg.globalResourceList = (void *)rmGrl;
1317         rmInitCfg.instCfg.serverCfg.linuxDtb = (void *)rmLinuxDtb;
1318         rmInitCfg.instCfg.serverCfg.globalPolicy = (void *)rmGlobalPolicy;
1319         rmServerHandle = Rm_init(&rmInitCfg, &result);
1320         ERROR_CHECK(RM_OK, result, rmServerName, "Initialization failed");
1322         /* Open Server service handle */
1323         rmServerServiceHandle = Rm_serviceOpenHandle(rmServerHandle, &result);
1324         ERROR_CHECK(RM_OK, result, rmServerName, "Service handle open failed");
1325     }
1326     else if (coreNum == 1) {
1327         /* Create the RM Client Delegate instance */
1328         rmInitCfg.instName = rmCdName;
1329         rmInitCfg.instType = Rm_instType_CLIENT_DELEGATE;
1330         rmInitCfg.instCfg.cdCfg.staticPolicy = (void *)rmStaticPolicy;
1331         rmCdHandle = Rm_init(&rmInitCfg, &result);
1332         ERROR_CHECK(RM_OK, result, rmCdName, "Initialization failed");
1334         /* Open CD service handle */
1335         rmCdServiceHandle = Rm_serviceOpenHandle(rmCdHandle, &result);
1336         ERROR_CHECK(RM_OK, result, rmCdName, "Service handle open failed");
1338         /* Create the RM Client instance */
1339         rmInitCfg.instName = &rmClientName[0];
1340         rmInitCfg.instType = Rm_instType_CLIENT;      
1341         rmInitCfg.instCfg.clientCfg.staticPolicy = (void *)rmStaticPolicy;
1342         rmClientHandle = Rm_init(&rmInitCfg, &result);
1343         ERROR_CHECK(RM_OK, result, rmClientName, "Initialization failed");
1345         /* Open Client service handle */
1346         rmClientServiceHandle = Rm_serviceOpenHandle(rmClientHandle, &result);
1347         ERROR_CHECK(RM_OK, result, rmClientName, "Service handle open failed");
1349         /* Initialize the static allocation response queue */
1350         for (numStaticResponses = 0; numStaticResponses < MAX_STATIC_ALLOCATION_RESPS; numStaticResponses++) {
1351             memset((void *)&staticResponseQueue[numStaticResponses], 0, sizeof(Rm_ServiceRespInfo));
1352         }
1353         numStaticResponses = 0;
1355         /* Static allocation tests */
1356         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1357                      0, 1, 0, NULL, TRUE, &responseInfo);
1358         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1359         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1360                                                                               rmCdName,
1361                                                                               resourceNameQosCluster,
1362                                                                               requestInfo.resourceBase, 
1363                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1364         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1365             System_printf("PASSED\n");
1366             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1367         }
1368         else {
1369             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1370         }        
1371         
1372         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1373                      2, 1, 0, NULL, TRUE, &responseInfo);        
1374         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1375         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1376                                                                               rmClientName,
1377                                                                               resourceNameQosCluster,
1378                                                                               requestInfo.resourceBase, 
1379                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1380         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1381             System_printf("PASSED\n");
1382             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1383         }
1384         else {
1385             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1386         }
1388         /* Request resource from Client that can only be allocated to CD according to static policy */
1389         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1390                      1, 1, 0, NULL, TRUE, &responseInfo);        
1391         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1392         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1393                                                                               rmClientName,
1394                                                                               resourceNameQosCluster,
1395                                                                               requestInfo.resourceBase, 
1396                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1397         if (responseInfo.serviceState != RM_SERVICE_APPROVED_STATIC) {        
1398             System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
1399         }
1400         else {
1401             System_printf("FAILED\n");
1402         }
1404         /* Request resource from both Client and CD that is shared according to static policy */
1405         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1406                      525, 1, 0, NULL, TRUE, &responseInfo);        
1407         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1408         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1409                                                                               rmCdName,
1410                                                                               resourceNameAifQ,
1411                                                                               requestInfo.resourceBase, 
1412                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1413         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1414             System_printf("PASSED\n");
1415             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1416         }
1417         else {
1418             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1419         }
1421         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1422                      525, 1, 0, NULL, TRUE, &responseInfo);        
1423         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1424         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1425                                                                               rmClientName,
1426                                                                               resourceNameAifQ,
1427                                                                               requestInfo.resourceBase, 
1428                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1429         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1430             System_printf("PASSED\n");
1431             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1432         }
1433         else {
1434             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1435         }    
1436     }
1438     System_printf("Core %d: Starting IPC...\n", coreNum);
1439     status = Ipc_start();
1440     if (status < 0) {
1441         System_abort("Ipc_start failed\n");
1442     }
1444     /* Create the RM startup task */
1445     System_printf("Core %d: Creating RM startup task...\n", coreNum);
1446     Task_Params_init (&taskParams);
1447     rmStartupTskHandle = Task_create (rmStartupTsk, &taskParams, NULL);
1449     System_printf("Core %d: Starting BIOS...\n", coreNum);
1450     BIOS_start();
1452     return (0);