Added local gate for NULL service callback and fixed bug where resource node offset...
[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     if (coreNum == 0) {
411         if (rmServerTskHandle) {
412             System_printf("Core %d: Deleting RM server task...\n", coreNum);
413             Task_delete(&rmServerTskHandle);
414             /* Set the task handle to be NULL so that the delete only occurs once */
415             rmServerTskHandle = NULL;
416         }
417     }
418     else if (coreNum == 1) {
419         if (rmClientTskHandle) {
420             System_printf("Core %d: Deleting RM client task...\n", coreNum);        
421             Task_delete(&rmClientTskHandle);
422             /* Set the task handle to be NULL so that the delete only occurs once */
423             rmClientTskHandle = NULL;
424         }
425     }
426     
427     /* Delete the RM receive task */
428     System_printf("Core %d: Deleting RM receive task...\n", coreNum);
429     if (rmReceiveTskHandle) {
430         Task_delete(&rmReceiveTskHandle);
431         /* Set the task handle to be NULL so that the delete only occurs once */
432         rmReceiveTskHandle = NULL;
433     }
435     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
436     if (coreNum == 0) {
437         Rm_serviceCloseHandle(rmServerServiceHandle);
439         Rm_transportUnregister(rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle);
441         result = Rm_delete(rmServerHandle, true);
442         if (result != RM_OK) {
443             System_printf("Core %d: RM server instance delete failed with error %d\n", coreNum, result);
444         }        
445     }
446     else if (coreNum == 1) {
447         Rm_serviceCloseHandle(rmCdServiceHandle);
448         Rm_serviceCloseHandle(rmClientServiceHandle);
450         Rm_transportUnregister(rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle);
451         Rm_transportUnregister(rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle);
452         Rm_transportUnregister(rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle);
454         result = Rm_delete(rmCdHandle, true);
455         if (result != RM_OK) {
456             System_printf("Core %d: RM cd instance delete failed with error %d\n", coreNum, result);
457         }  
458         result = Rm_delete(rmClientHandle, true);
459         if (result != RM_OK) {
460             System_printf("Core %d: RM client instance delete failed with error %d\n", coreNum, result);
461         }          
462     }
464     BIOS_exit(0);
467 /* Receive task has priority of 2 so that it pre-empts the RM instance test tasks */
468 void rmReceiveTsk(UArg arg0, UArg arg1)
470     while(1) {
471         if (coreNum == 0) {
472             transportReceive(SERVER_TO_CD_MAP_ENTRY);
473         }
474         else if (coreNum == 1) {
475             transportReceive(CD_TO_SERVER_MAP_ENTRY);
476             transportReceive(CD_TO_CLIENT_MAP_ENTRY);
477             transportReceive(CLIENT_TO_CD_MAP_ENTRY);
478         }
479         /* Sleep for 1ms so that the main test tasks can run */
480         Task_sleep(1);
481     }
484 void rmServerTsk(UArg arg0, UArg arg1)
486     Rm_ServiceReqInfo  requestInfo;
487     Rm_ServiceRespInfo responseInfo;
488     Task_Params        taskParams;
489        
490     /* Delete the RM startup task */
491     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
492     if (rmStartupTskHandle) {
493         Task_delete(&rmStartupTskHandle);
494         /* Set the task handle to be NULL so that the delete only occurs once */
495         rmStartupTskHandle = NULL;
496     }
498     Rm_printInstanceStatus(rmServerHandle);
500     /* BEGIN testing UNSPECIFIED base and alignment requests on Server */               
501     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
502                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 0, NULL, TRUE, &responseInfo);       
503     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
504     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
505                                                                                                   rmServerName,
506                                                                                                   resourceNameGpQ,
507                                                                                                   requestInfo.resourceLength, 
508                                                                                                   requestInfo.resourceAlignment);
509     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
510         System_printf("PASSED\n");
511     }
512     else {
513         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
514     }    
515                
516     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
517                  RM_RESOURCE_BASE_UNSPECIFIED, 1, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
518     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
519     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
520                                                                                                            rmServerName,
521                                                                                                            resourceNameGpQ,
522                                                                                                            requestInfo.resourceLength);
523     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
524         System_printf("PASSED\n");
525     }
526     else {
527         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
528     }     
530     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
531                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 200, NULL, TRUE, &responseInfo);     
532     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
533     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
534                                                                                                   rmServerName,
535                                                                                                   resourceNameGpQ,
536                                                                                                   requestInfo.resourceLength,
537                                                                                                   requestInfo.resourceAlignment);
538     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
539         System_printf("PASSED\n");
540     }
541     else {
542         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
543     }      
544     /* END testing UNSPECIFIED base and alignment requests on Server */      
546     /* Create new NameServer object */                
547     setRmRequest(&requestInfo, Rm_service_RESOURCE_MAP_TO_NAME, resourceNameGpQ, 
548                  1002, 1, 0, nameServerNameFavQ, TRUE, &responseInfo);     
549     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
550     System_printf("Core %d : %s create name %s tied to %s %d - %d : ", coreNum,
551                                                                        rmServerName,
552                                                                        nameServerNameFavQ,
553                                                                        responseInfo.resourceName,
554                                                                        requestInfo.resourceBase, 
555                                                                        (requestInfo.resourceBase + requestInfo.resourceLength - 1));                                                                       
556     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
557         System_printf("PASSED\n");
558     }
559     else {
560         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
561     }     
563     /* Wait for CD and Client retrieve resource via name, allocate the resource, free resource via name, and 
564      * delete the NameServer object. */
565     gateKey = GateMP_enter(gateHandle);
566     GateMP_leave(gateHandle, gateKey);
568     /* Try to allocate the memory region taken by the Linux Kernel and not specified as shared */
569     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameMemRegion, 
570                  12, 1, 0, NULL, TRUE, &responseInfo);     
571     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
572     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
573                                                                   rmServerName,
574                                                                   resourceNameMemRegion,
575                                                                   requestInfo.resourceBase, 
576                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
577     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
578         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
579     }
580     else {
581         System_printf("FAILED\n");
582     }    
584     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
585     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
586                  14, 5, 0, NULL, TRUE, &responseInfo);       
587     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
588     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
589                                                                   rmServerName,
590                                                                   resourceNameAifRxCh,
591                                                                   requestInfo.resourceBase, 
592                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
593     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
594         System_printf("PASSED\n");
595     }
596     else {
597         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
598     } 
599     
600     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
601                  19, 31, 0, NULL, TRUE, &responseInfo);      
602     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
603     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
604                                                                   rmServerName,
605                                                                   resourceNameAifRxCh,
606                                                                   requestInfo.resourceBase, 
607                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
608     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
609         System_printf("PASSED\n");
610     }
611     else {
612         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
613     }        
614     
615     /* Wait for Client and Client Delegate to do their allocations */
616     gateKey = GateMP_enter(gateHandle);
617     GateMP_leave(gateHandle, gateKey);       
619     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
620                  25, 3, 0, NULL, TRUE, &responseInfo);      
621     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
622     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
623                                                         rmServerName,
624                                                         resourceNameAifRxCh,
625                                                         requestInfo.resourceBase, 
626                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
627     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
628         System_printf("PASSED\n");
629     }
630     else {
631         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
632     }      
633     
634     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
635                  34, 3, 0, NULL, TRUE, &responseInfo);      
636     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
637     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
638                                                         rmServerName,
639                                                         resourceNameAifRxCh,
640                                                         requestInfo.resourceBase, 
641                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
642     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
643         System_printf("PASSED\n");
644     }
645     else {
646         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
647     }      
648  
649     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
650                  28, 6, 0, NULL, TRUE, &responseInfo);      
651     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);   
652     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
653                                                         rmServerName,
654                                                         resourceNameAifRxCh,
655                                                         requestInfo.resourceBase, 
656                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
657     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
658         System_printf("PASSED\n");
659     }
660     else {
661         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
662     }      
664     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
665                  53, 2, 0, NULL, TRUE, &responseInfo);      
666     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
667     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
668                                                                   rmServerName,
669                                                                   resourceNameAifRxCh,
670                                                                   requestInfo.resourceBase, 
671                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
672     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
673         System_printf("PASSED\n");
674     }
675     else {
676         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
677     }  
678     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */  
679     
680     /* Test execlusive rights to an allocated resource */
681     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
682                  2, 2, 0, NULL, TRUE, &responseInfo);      
683     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
684     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
685                                                                   rmServerName,
686                                                                   resourceNameAifRxCh,
687                                                                   requestInfo.resourceBase, 
688                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
689     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {
690         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
691     }
692     else {
693         System_printf("FAILED\n");
694     }      
696     /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
697     gateKey = GateMP_enter(gateHandle);
698     GateMP_leave(gateHandle, gateKey);
700     /* Test allocation of a resource twice from the same instance with init and use privileges.  Both
701      * should be approved but the instance should only be mentioned once in the resource's owner list */
702     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
703                  6543, 10, 0, NULL, TRUE, &responseInfo);      
704     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
705     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
706                                                                    rmServerName,
707                                                                    resourceNameGpQ,
708                                                                    requestInfo.resourceBase, 
709                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
710     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
711         System_printf("PASSED\n");
712     }
713     else {
714         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
715     }     
717     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
718                  6543, 10, 0, NULL, TRUE, &responseInfo);      
719     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
720     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
721                                                                   rmServerName,
722                                                                   resourceNameGpQ,
723                                                                   requestInfo.resourceBase, 
724                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
725     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
726         System_printf("PASSED\n");
727     }
728     else {
729         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
730     }        
732     /* Allocate infrastructure queue taken by Linux kernel and shared with Rm_Client.  Expect error or denial. */
733     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
734                  805, 1, 0, NULL, TRUE, &responseInfo);     
735     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
736     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
737                                                                    rmServerName,
738                                                                    resourceNameInfraQ,
739                                                                    requestInfo.resourceBase, 
740                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
741     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
742         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
743     }
744     else {
745         System_printf("FAILED\n");
746     }              
748     System_printf("Core %d: Testing is complete\n", coreNum);
750     Rm_printInstanceStatus(rmServerHandle);
751     Rm_printResourceStatus(rmServerHandle);   
752     
753     /* Create the RM cleanup task. */
754     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
755     Task_Params_init (&taskParams);
756     Task_create (rmCleanupTsk, &taskParams, NULL);
759 void rmClientTsk(UArg arg0, UArg arg1)
761     Rm_ServiceReqInfo  requestInfo;
762     Rm_ServiceRespInfo responseInfo;    
763     Task_Params        taskParams;
764     uint32_t           i, j;
765        
766     /* Delete the RM startup task */
767     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
768     if (rmStartupTskHandle) {
769        Task_delete(&rmStartupTskHandle);
770        /* Set the task handle to be NULL so that the delete only occurs once */
771        rmStartupTskHandle = NULL;
772     }
774     Rm_printInstanceStatus(rmCdHandle);
775     Rm_printInstanceStatus(rmClientHandle);
777     /* Retrieve a resource via a NameServer name */
778     setRmRequest(&requestInfo, Rm_service_RESOURCE_GET_BY_NAME, NULL, 
779                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
780     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
781     System_printf("Core %d : %s get resource with name %s : ", coreNum,
782                                                                rmCdName,
783                                                                nameServerNameFavQ);
784     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
785         waitForResponse(&responseInfo);
786     }
787     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
788         System_printf("PASSED\n");
789     }
790     else {
791         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
792     } 
794     /* Allocate the resource returned from the NameServer request */
795     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo)); 
796     requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
797     requestInfo.resourceName = responseInfo.resourceName;
798     requestInfo.resourceBase = responseInfo.resourceBase;
799     requestInfo.resourceLength = responseInfo.resourceLength;
800     requestInfo.resourceNsName = NULL;
801     requestInfo.callback.serviceCallback = serviceCallback;     
802     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
803     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
804                                                                    rmClientName,
805                                                                    responseInfo.resourceName,
806                                                                    requestInfo.resourceBase, 
807                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
808     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
809         waitForResponse(&responseInfo);
810     }
811     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
812         System_printf("PASSED\n");
813     }
814     else {
815         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
816     }    
818     /* Free resource via a NameServer name */
819     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, NULL, 
820                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
821     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
822     System_printf("Core %d : %s free resource with name %s : ", coreNum,
823                                                                 rmClientName,
824                                                                 nameServerNameFavQ);
825     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
826         waitForResponse(&responseInfo);
827     }
828     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
829         System_printf("PASSED\n");
830     }
831     else {
832         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
833     }      
835     /* Delete the NameServer name */
836     setRmRequest(&requestInfo, Rm_service_RESOURCE_UNMAP_NAME, NULL, 
837                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
838     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);     
839     System_printf("Core %d : %s delete name %s : ", coreNum,
840                                                     rmClientName,
841                                                     nameServerNameFavQ);
842     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
843         waitForResponse(&responseInfo);
844     }
845     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
846         System_printf("PASSED\n");
847     }
848     else {
849         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
850     }     
852     GateMP_leave(gateHandle, gateKey);
853     gateKey = GateMP_enter(gateHandle);
855     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
856     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
857                  0, 6, 0, NULL, TRUE, &responseInfo);     
858     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
859     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
860                                                                   rmClientName,
861                                                                   resourceNameAifRxCh,
862                                                                   requestInfo.resourceBase, 
863                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
864     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
865         waitForResponse(&responseInfo);
866     }
867     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
868         System_printf("PASSED\n");
869     }
870     else {
871         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
872     }     
873     
874     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifRxCh, 
875                  50, 7, 0, NULL, TRUE, &responseInfo);        
876     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
877     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
878                                                                    rmCdName,
879                                                                    resourceNameAifRxCh,
880                                                                    requestInfo.resourceBase, 
881                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
882     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
883         waitForResponse(&responseInfo);
884     }
885     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
886         System_printf("PASSED\n");
887     }
888     else {
889         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
890     }       
891     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */
893     GateMP_leave(gateHandle, gateKey);    
894     gateKey = GateMP_enter(gateHandle);
896     /* BEGIN testing allocations with UNSPECIFIED base and alignment values */
897     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
898                  RM_RESOURCE_BASE_UNSPECIFIED, 5, 4, NULL, TRUE, &responseInfo);        
899     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
900     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
901                                                                                                   rmCdName,
902                                                                                                   resourceNameAccumCh,
903                                                                                                   requestInfo.resourceLength, 
904                                                                                                   requestInfo.resourceAlignment);
905     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
906         waitForResponse(&responseInfo);
907     }
908     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
909         System_printf("PASSED\n");
910     }
911     else {
912         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
913     }        
915     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
916                  RM_RESOURCE_BASE_UNSPECIFIED, 2, 1, NULL, TRUE, &responseInfo);      
917     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
918     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
919                                                                                                   rmClientName,
920                                                                                                   resourceNameAccumCh,
921                                                                                                   requestInfo.resourceLength, 
922                                                                                                   requestInfo.resourceAlignment);
923     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
924         waitForResponse(&responseInfo);
925     }
926     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
927         System_printf("PASSED\n");
928     }
929     else {
930         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
931     }     
933     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
934                  RM_RESOURCE_BASE_UNSPECIFIED, 2, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
935     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
936     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
937                                                                                                            rmClientName,
938                                                                                                            resourceNameAccumCh,
939                                                                                                            requestInfo.resourceLength);
940     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
941         waitForResponse(&responseInfo);
942     }
943     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
944         System_printf("PASSED\n");
945     }
946     else {
947         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
948     }     
949     /* END testing allocations with UNSPECIFIED base and alignment values */    
951     /* Allocate infrastructure queue shared between Linux kernel and Client */
952     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
953                  800, 1, 0, NULL, TRUE, &responseInfo);     
954     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
955     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
956                                                                    rmClientName,
957                                                                    resourceNameInfraQ,
958                                                                    requestInfo.resourceBase, 
959                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
960     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
961         waitForResponse(&responseInfo);
962     }
963     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
964         System_printf("PASSED\n");
965     }
966     else {
967         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
968     }     
970     /* Allocate a resource without providing a callback function.  RM should block and not return until the result
971      * is returned by the server. */
972     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
973                  7000, 1, 0, NULL, TRUE, &responseInfo);     
974     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);   
975     System_printf("Core %d : %s init allocation (without callback specified) of %s %d - %d : ", coreNum,
976                                                                                                 rmClientName,
977                                                                                                 resourceNameGpQ,
978                                                                                                 requestInfo.resourceBase, 
979                                                                                                 (requestInfo.resourceBase + requestInfo.resourceLength - 1));
980     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
981         waitForResponse(&responseInfo);
982     }
983     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
984         System_printf("PASSED\n");
985     }
986     else {
987         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
988     }      
990     GateMP_leave(gateHandle, gateKey);           
992     /* Verify static allocations were validated.  Validation responses should have been received after the
993      * first service requests were made on the Client and CD post transport path registration. */
994     while (numStaticResponses > 0) {
995         /* Loop until all static request validations have been received */
996         for (i = 0; i < MAX_STATIC_ALLOCATION_RESPS; i++) {
997             if (staticResponseQueue[i].serviceId != 0) {            
998                 for (j = 0; j < MAX_QUEUED_SERVICE_RESPONSES; j++) {
999                     if ((staticResponseQueue[i].serviceId == responseInfoQueue[j].serviceId) &&
1000                         (staticResponseQueue[i].rmHandle == responseInfoQueue[j].rmHandle)) {
1001                         System_printf("Core %d : static allocation validation of %s %d - %d : ", coreNum,
1002                                                                                                  responseInfoQueue[j].resourceName,
1003                                                                                                  responseInfoQueue[j].resourceBase, 
1004                                                                                                  (responseInfoQueue[j].resourceBase + responseInfoQueue[j].resourceLength - 1));        
1005                         if (responseInfoQueue[j].serviceState == RM_SERVICE_APPROVED) {
1006                             System_printf("PASSED\n");
1007                         }
1008                         else {
1009                             System_printf("FAILED : denial or error : %d\n", responseInfoQueue[j].serviceState);
1010                         }  
1011                         memset((void *)&staticResponseQueue[i], 0, sizeof(Rm_ServiceRespInfo));
1012                         memset((void *)&responseInfoQueue[j], 0, sizeof(Rm_ServiceRespInfo));
1013                         numStaticResponses--;                        
1014                         break;
1015                     }
1016                 }
1017             }
1018         }    
1019     }   
1022     System_printf("Core %d: Testing is complete\n", coreNum);
1024     Rm_printInstanceStatus(rmCdHandle);
1025     Rm_printInstanceStatus(rmClientHandle);
1026     
1027     /* Create the RM cleanup task. */
1028     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
1029     Task_Params_init (&taskParams);
1030     Task_create (rmCleanupTsk, &taskParams, NULL);
1033 void rmStartupTsk(UArg arg0, UArg arg1)
1035     MessageQ_Handle    serverFromCdMsgQ, cdFromServerMsgQ, cdFromClientMsgQ, clientFromCdMsgQ;
1036     MessageQ_QueueId   serverToCdQId, cdToServerQId, cdToClientQId, clientToCdQId;    
1037     Int                status, i;
1038     GateMP_Params      gateParams;    
1039     HeapBufMP_Handle   msgQHeapHandle;
1040     HeapBufMP_Params   heapBufParams;
1041     Rm_TransportCfg    rmTransportCfg;
1042     int32_t            result = 0;
1043     Rm_TransportHandle serverCdHandle, cdServerHandle, cdClientHandle, clientCdHandle;
1044     Task_Params        taskParams;
1046     /* Initialize the transport map */
1047     for (i = 0; i < MAX_MAPPING_ENTRIES; i++) {
1048         rmTransportMap[i].transportHandle = NULL;
1049     }
1051     if (coreNum == 0) {
1052         GateMP_Params_init(&gateParams);
1053         gateParams.name = RM_TASK_GATE_NAME;
1054         gateHandle = GateMP_create(&gateParams);
1055         
1056         /* Create the heap that will be used to allocate RM messages. This
1057          * heap is a multi-processor heap.  It will be shared amongst
1058          * all RM instances. */     
1059         HeapBufMP_Params_init(&heapBufParams);
1060         heapBufParams.regionId       = 0;
1061         heapBufParams.name           = RM_PKT_HEAP_NAME;
1062         heapBufParams.numBlocks      = 64;
1063         heapBufParams.blockSize      = sizeof(Rm_Packet);
1064         rmPktHeapHandle = HeapBufMP_create(&heapBufParams);
1065         if (rmPktHeapHandle == NULL) {
1066             System_abort("HeapBufMP_create failed for RM packet heap\n" );
1067         }
1068         System_printf("Core %d: RM packet heap created\n", coreNum);
1070         /* Create the heap that will be used to allocate messageQ messages. */     
1071         HeapBufMP_Params_init(&heapBufParams);
1072         heapBufParams.regionId       = 0;
1073         heapBufParams.name           = MSGQ_HEAP_NAME;
1074         heapBufParams.numBlocks      = 64;
1075         heapBufParams.blockSize      = sizeof(MsgQ_RmPacket);
1076         msgQHeapHandle = HeapBufMP_create(&heapBufParams);
1077         if (msgQHeapHandle == NULL) {
1078             System_abort("HeapBufMP_create failed MessageQ message heap\n" );
1079         } 
1080         System_printf("Core %d: IPC MessageQ message heap created\n", coreNum);
1081     }
1082     else {
1083         do {
1084             status = GateMP_open(RM_TASK_GATE_NAME, &gateHandle);
1085             /* 
1086              *  Sleep for 1 clock tick to avoid inundating remote processor
1087              *  with interrupts if open failed
1088              */
1089             if (status < 0) { 
1090                 Task_sleep(1);
1091             }
1092         } while (status < 0);
1093         /* Take the gate right away to prepare for RM testing */
1094         gateKey = GateMP_enter(gateHandle);
1095         
1096         /* Open the heaps created by the other processor. Loop until opened. */
1097         do {
1098             status = HeapBufMP_open(RM_PKT_HEAP_NAME, &rmPktHeapHandle);
1099             /* 
1100              *  Sleep for 1 clock tick to avoid inundating remote processor
1101              *  with interrupts if open failed
1102              */
1103             if (status < 0) { 
1104                 Task_sleep(1);
1105             }
1106         } while (status < 0);
1107         System_printf("Core %d: RM packet heap opened\n", coreNum);
1108         
1109         do {
1110             status = HeapBufMP_open(MSGQ_HEAP_NAME, &msgQHeapHandle);
1111             /* 
1112              *  Sleep for 1 clock tick to avoid inundating remote processor
1113              *  with interrupts if open failed
1114              */
1115             if (status < 0) { 
1116                 Task_sleep(1);
1117             }
1118         } while (status < 0);
1119         System_printf("Core %d: IPC MessageQ message heap opened\n", coreNum);
1120     }
1121     
1122     /* Register the MessageQ heap with MessageQ */
1123     MessageQ_registerHeap(msgQHeapHandle, MSGQ_HEAP_ID);
1125     /* Create the messageQ's for each RM instance connection
1126      * Need four queues.  Topology will be:
1127      * RM Server <---> RM Client Delegate <---> RM Client 
1128      * 1 queues on RM Server
1129      * 2 queues on RM Client Delegate
1130      * 1 queues on RM Client */
1131     if (coreNum == 0) {
1132         serverFromCdMsgQ = MessageQ_create(serverFromCdQueueName, NULL);
1133         if (serverFromCdMsgQ == NULL) {
1134             System_abort("MessageQ_create failed for RM Server - Client Delegate queue\n" );
1135         }
1136         System_printf("Core %d: RM Server MessageQ created for receiving packets from RM CD\n", coreNum);
1137     }
1138     else if (coreNum == 1) {
1139         cdFromServerMsgQ = MessageQ_create(cdFromServerQueueName, NULL);
1140         if (cdFromServerMsgQ == NULL) {
1141             System_abort("MessageQ_create failed for RM Client Delegate - Server queue\n" );
1142         }
1143         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Server\n", coreNum);
1144         
1145         cdFromClientMsgQ = MessageQ_create(cdFromClientQueueName, NULL);
1146         if (cdFromClientMsgQ == NULL) {
1147             System_abort("MessageQ_create failed for RM Client Delegate - Client queue\n" );
1148         } 
1149         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Client\n", coreNum);
1150         
1151         clientFromCdMsgQ = MessageQ_create(clientFromCdQueueName, NULL);
1152         if (clientFromCdMsgQ == NULL) 
1153         {
1154             System_abort("MessageQ_create failed for RM Client - Client Delegate queue\n" );
1155         }
1156         System_printf("Core %d: RM Client MessageQ created for receiving packets from RM CD\n", coreNum);
1157     }
1158     
1159     /* Open the remote message queues. Also register the RM transports with each RM instance */
1160     if (coreNum == 0) {
1161         /* Open the Client Delegate messageQ from the Server */
1162         do {
1163             status = MessageQ_open(cdFromServerQueueName, &serverToCdQId); 
1164             /* 
1165              *  Sleep for 1 clock tick to avoid inundating remote processor
1166              *  with interrupts if open failed
1167              */
1168             if (status < 0) { 
1169                 Task_sleep(1);
1170             }
1171         } while (status < 0);
1172         System_printf("Core %d: RM CD MessageQ opened from RM Server\n", coreNum);
1174         /* Register the Client Delegate with the RM Server Instance */
1175         rmTransportCfg.rmHandle = rmServerHandle;
1176         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) serverToCdQId;
1177         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1178         rmTransportCfg.remoteInstName = &rmCdName[0];
1179         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1180         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1181         serverCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1183         /* Store the mapping information in the transport map */
1184         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle = serverCdHandle;
1185         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].receiveMsgQ = serverFromCdMsgQ;
1186         System_printf("Core %d: Registered RM Server <=> RM CD transport with RM Server instance\n", coreNum);
1187     }
1188     else if (coreNum == 1) {
1189         /* Open the Server messageQ from the Client Delegate */
1190         do {
1191             status = MessageQ_open(serverFromCdQueueName, &cdToServerQId); 
1192             /* 
1193              *  Sleep for 1 clock tick to avoid inundating remote processor
1194              *  with interrupts if open failed
1195              */
1196             if (status < 0) { 
1197                 Task_sleep(1);
1198             }
1199         } while (status < 0);
1200         System_printf("Core %d: RM Server MessageQ opened from RM CD\n", coreNum);
1202         /* Register the Server with the RM Client Delegate Instance */
1203         rmTransportCfg.rmHandle = rmCdHandle;
1204         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToServerQId;
1205         rmTransportCfg.remoteInstType = Rm_instType_SERVER;
1206         rmTransportCfg.remoteInstName = &rmServerName[0];
1207         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1208         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1209         cdServerHandle = Rm_transportRegister(&rmTransportCfg, &result);
1211         /* Store the mapping information in the transport map */
1212         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle = cdServerHandle;
1213         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].receiveMsgQ = cdFromServerMsgQ;
1214         System_printf("Core %d: Registered RM CD <=> RM Server transport with RM CD instance\n", coreNum);
1215         
1216         /* Open the Client messageQ from the Client Delegate */
1217         do {
1218             status = MessageQ_open(clientFromCdQueueName, &cdToClientQId); 
1219             /* 
1220              *  Sleep for 1 clock tick to avoid inundating remote processor
1221              *  with interrupts if open failed
1222              */
1223             if (status < 0) { 
1224                 Task_sleep(1);
1225             }
1226         } while (status < 0);
1227         System_printf("Core %d: RM Client MessageQ opened from RM CD\n", coreNum);
1229         /* Register the Client with the RM Client Delegate Instance */
1230         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToClientQId;
1231         rmTransportCfg.remoteInstType = Rm_instType_CLIENT;
1232         rmTransportCfg.remoteInstName = &rmClientName[0];
1233         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1234         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1235         cdClientHandle = Rm_transportRegister(&rmTransportCfg, &result);
1237         /* Store the mapping information in the transport map */
1238         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle = cdClientHandle;
1239         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].receiveMsgQ = cdFromClientMsgQ;
1240         System_printf("Core %d: Registered RM CD <=> RM Client transport with RM CD instance\n", coreNum);
1242         /* Open the Client Delegate messageQ from the Client */        
1243         do {
1244             status = MessageQ_open(cdFromClientQueueName, &clientToCdQId); 
1245             /* 
1246              *  Sleep for 1 clock tick to avoid inundating remote processor
1247              *  with interrupts if open failed
1248              */
1249             if (status < 0) { 
1250                 Task_sleep(1);
1251             }
1252         } while (status < 0);
1253         System_printf("Core %d: RM CD MessageQ opened from RM Client\n", coreNum);
1255         /* Register the Client Delegate with the RM Client Instance */
1256         rmTransportCfg.rmHandle = rmClientHandle;
1257         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) clientToCdQId;
1258         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1259         rmTransportCfg.remoteInstName = &rmCdName[0];
1260         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1261         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1262         clientCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1264         /* Store the mapping information in the transport map */
1265         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle = clientCdHandle;
1266         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].receiveMsgQ = clientFromCdMsgQ;
1267         System_printf("Core %d: Registered RM Client <=> RM CD transport with RM Client instance\n", coreNum);
1268     }
1270     /* Create the gate internal to RM for service requests not specifying a callback function
1271      * and needing a blocking operation to complete */
1272     Osal_rmLocalGateInit();
1274     /* Create the RM receive task.  Assign higher priority than the test tasks so that
1275      * when they spin waiting for messages from other RM instances the receive task is
1276      * executed. */
1277     System_printf("Core %d: Creating RM receive task...\n", coreNum);
1278     Task_Params_init (&taskParams);
1279     taskParams.priority = 2;
1280     rmReceiveTskHandle = Task_create (rmReceiveTsk, &taskParams, NULL);
1281     
1282     /* Create the RM test tasks. */
1283     if (coreNum == 0) {
1284         System_printf("Core %d: Creating RM server task...\n", coreNum);
1285         Task_Params_init (&taskParams);
1286         taskParams.priority = 1;
1287         rmServerTskHandle = Task_create (rmServerTsk, &taskParams, NULL);
1288     }
1289     else if (coreNum) {
1290         System_printf("Core %d: Creating RM client task...\n", coreNum);
1291         Task_Params_init (&taskParams);
1292         taskParams.priority = 1;
1293         rmClientTskHandle = Task_create (rmClientTsk, &taskParams, NULL);
1294     }
1297 int main(Int argc, Char* argv[])
1299     Rm_InitCfg         rmInitCfg;
1300     Task_Params        taskParams; 
1301     int                status;
1302     Rm_ServiceReqInfo  requestInfo;
1303     Rm_ServiceRespInfo responseInfo;
1304     int32_t            result;
1306     System_printf ("*********************************************************\n");
1307     System_printf ("********************** RM Testing ***********************\n");
1308     System_printf ("*********************************************************\n");
1310     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
1312     coreNum = MultiProc_self();
1314     /* Initialize the RM instances - RM must be initialized before anything else in the system
1315      * Core 0: 1 RM Instance  - RM Server
1316      * Core 1: 2 RM Instances - RM Client Delegate
1317      *                          RM Client
1318      */
1319     if (coreNum == 0) {
1320         /* Create the Server instance */
1321         rmInitCfg.instName = rmServerName;
1322         rmInitCfg.instType = Rm_instType_SERVER;
1323         rmInitCfg.instCfg.serverCfg.globalResourceList = (void *)rmGrl;
1324         rmInitCfg.instCfg.serverCfg.linuxDtb = (void *)rmLinuxDtb;
1325         rmInitCfg.instCfg.serverCfg.globalPolicy = (void *)rmGlobalPolicy;
1326         rmServerHandle = Rm_init(&rmInitCfg, &result);
1327         ERROR_CHECK(RM_OK, result, rmServerName, "Initialization failed");
1329         /* Open Server service handle */
1330         rmServerServiceHandle = Rm_serviceOpenHandle(rmServerHandle, &result);
1331         ERROR_CHECK(RM_OK, result, rmServerName, "Service handle open failed");
1332     }
1333     else if (coreNum == 1) {
1334         /* Create the RM Client Delegate instance */
1335         rmInitCfg.instName = rmCdName;
1336         rmInitCfg.instType = Rm_instType_CLIENT_DELEGATE;
1337         rmInitCfg.instCfg.cdCfg.staticPolicy = (void *)rmStaticPolicy;
1338         rmCdHandle = Rm_init(&rmInitCfg, &result);
1339         ERROR_CHECK(RM_OK, result, rmCdName, "Initialization failed");
1341         /* Open CD service handle */
1342         rmCdServiceHandle = Rm_serviceOpenHandle(rmCdHandle, &result);
1343         ERROR_CHECK(RM_OK, result, rmCdName, "Service handle open failed");
1345         /* Create the RM Client instance */
1346         rmInitCfg.instName = &rmClientName[0];
1347         rmInitCfg.instType = Rm_instType_CLIENT;      
1348         rmInitCfg.instCfg.clientCfg.staticPolicy = (void *)rmStaticPolicy;
1349         rmClientHandle = Rm_init(&rmInitCfg, &result);
1350         ERROR_CHECK(RM_OK, result, rmClientName, "Initialization failed");
1352         /* Open Client service handle */
1353         rmClientServiceHandle = Rm_serviceOpenHandle(rmClientHandle, &result);
1354         ERROR_CHECK(RM_OK, result, rmClientName, "Service handle open failed");
1356         /* Initialize the static allocation response queue */
1357         for (numStaticResponses = 0; numStaticResponses < MAX_STATIC_ALLOCATION_RESPS; numStaticResponses++) {
1358             memset((void *)&staticResponseQueue[numStaticResponses], 0, sizeof(Rm_ServiceRespInfo));
1359         }
1360         numStaticResponses = 0;
1362         /* Static allocation tests */
1363         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1364                      0, 1, 0, NULL, TRUE, &responseInfo);
1365         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1366         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1367                                                                               rmCdName,
1368                                                                               resourceNameQosCluster,
1369                                                                               requestInfo.resourceBase, 
1370                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1371         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1372             System_printf("PASSED\n");
1373             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1374         }
1375         else {
1376             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1377         }        
1378         
1379         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1380                      2, 1, 0, NULL, TRUE, &responseInfo);        
1381         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1382         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1383                                                                               rmClientName,
1384                                                                               resourceNameQosCluster,
1385                                                                               requestInfo.resourceBase, 
1386                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1387         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1388             System_printf("PASSED\n");
1389             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1390         }
1391         else {
1392             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1393         }
1395         /* Request resource from Client that can only be allocated to CD according to static policy */
1396         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1397                      1, 1, 0, NULL, TRUE, &responseInfo);        
1398         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1399         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1400                                                                               rmClientName,
1401                                                                               resourceNameQosCluster,
1402                                                                               requestInfo.resourceBase, 
1403                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1404         if (responseInfo.serviceState != RM_SERVICE_APPROVED_STATIC) {        
1405             System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
1406         }
1407         else {
1408             System_printf("FAILED\n");
1409         }
1411         /* Request resource from both Client and CD that is shared according to static policy */
1412         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1413                      525, 1, 0, NULL, TRUE, &responseInfo);        
1414         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1415         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1416                                                                               rmCdName,
1417                                                                               resourceNameAifQ,
1418                                                                               requestInfo.resourceBase, 
1419                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1420         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1421             System_printf("PASSED\n");
1422             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1423         }
1424         else {
1425             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1426         }
1428         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1429                      525, 1, 0, NULL, TRUE, &responseInfo);        
1430         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1431         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1432                                                                               rmClientName,
1433                                                                               resourceNameAifQ,
1434                                                                               requestInfo.resourceBase, 
1435                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1436         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1437             System_printf("PASSED\n");
1438             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1439         }
1440         else {
1441             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1442         }    
1443     }
1445     System_printf("Core %d: Starting IPC...\n", coreNum);
1446     status = Ipc_start();
1447     if (status < 0) {
1448         System_abort("Ipc_start failed\n");
1449     }
1451     /* Create the RM startup task */
1452     System_printf("Core %d: Creating RM startup task...\n", coreNum);
1453     Task_Params_init (&taskParams);
1454     rmStartupTskHandle = Task_create (rmStartupTsk, &taskParams, NULL);
1456     System_printf("Core %d: Starting BIOS...\n", coreNum);
1457     BIOS_start();
1459     return (0);