00cf52acfc4138c166dd60e9e4650c4a2e72c460
[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 /**********************************************************************
144  ********************** Global Variables ******************************
145  **********************************************************************/
147 /* DSP core number according to IPC */
148 uint16_t            coreNum;
150 /* Task to configure application transport code for RM */
151 Task_Handle         rmStartupTskHandle;
152 /* High priority task for receiving RM packets */
153 Task_Handle         rmReceiveTskHandle;
154 /* RM server test task */
155 Task_Handle         rmServerTskHandle;
156 /* RM client delegate and client test task */
157 Task_Handle         rmClientTskHandle;
159 /* GateMP used to synchronize tests between the two RM test tasks */
160 GateMP_Handle       gateHandle = NULL;
161 /* GateMP key */
162 IArg                gateKey;
164 /* Handle for heap that RM packets will be allocated from */
165 HeapBufMP_Handle    rmPktHeapHandle = NULL;
167 /* MessageQ used by RM CD to send packets to RM Server */
168 char                serverFromCdQueueName[30] = "RM_Server_From_CD_Queue";
169 /* MessageQ used by RM Server to send packets to RM CD */
170 char                cdFromServerQueueName[30] = "RM_CD_From_Server_Queue";
171 /* MessageQ used by RM Client to send packets to RM CD */
172 char                cdFromClientQueueName[30] = "RM_CD_From_Client_Queue";
173 /* MessageQ used by RM CD to send packets to RM Client */
174 char                clientFromCdQueueName[30] = "RM_Client_From_CD_Queue";
176 /* RM Server instance name (must match with RM Global Resource List (GRL) and policies */
177 char                rmServerName[RM_NAME_MAX_CHARS] = "RM_Server";
178 /* RM CD instance name (must match with RM Global Resource List (GRL) and policies */
179 char                rmCdName[RM_NAME_MAX_CHARS]     = "RM_Client_Delegate";
180 /* RM Client instance name (must match with RM Global Resource List (GRL) and policies */
181 char                rmClientName[RM_NAME_MAX_CHARS] = "RM_Client";
183 /* RM instance handles */
184 Rm_Handle           rmServerHandle = NULL;
185 Rm_Handle           rmCdHandle     = NULL;
186 Rm_Handle           rmClientHandle = NULL;
188 /* RM instance service handles */
189 Rm_ServiceHandle   *rmServerServiceHandle = NULL;
190 Rm_ServiceHandle   *rmCdServiceHandle     = NULL;
191 Rm_ServiceHandle   *rmClientServiceHandle = NULL;
193 /* Transport map stores the RM transport handle to IPC MessageQ queue mapping */
194 Transport_MapEntry  rmTransportMap[MAX_MAPPING_ENTRIES];
196 /* Static allocation response queue */
197 Rm_ServiceRespInfo  staticResponseQueue[MAX_STATIC_ALLOCATION_RESPS];
198 /* Static allocation response queue index */
199 uint32_t            numStaticResponses;
202 /* RM response info queue used to store service responses received via the callback function */
203 Rm_ServiceRespInfo  responseInfoQueue[MAX_QUEUED_SERVICE_RESPONSES];
205 /* RM resource names (must match resource node names in GRL and policies */
206 char                resourceNameMemRegion[RM_NAME_MAX_CHARS]  = "memory-regions";
207 char                resourceNameAccumCh[RM_NAME_MAX_CHARS]    = "accumulator-ch";
208 char                resourceNameGpQ[RM_NAME_MAX_CHARS]        = "gp-queue";
209 char                resourceNameAifQ[RM_NAME_MAX_CHARS]       = "aif-queue";
210 char                resourceNameQosCluster[RM_NAME_MAX_CHARS] = "qos-cluster";
211 char                resourceNameAifRxCh[RM_NAME_MAX_CHARS]    = "aif-rx-ch";
212 char                resourceNameInfraQ[RM_NAME_MAX_CHARS]     = "infra-queue";
214 /* Test RM NameServer name */
215 char                nameServerNameFavQ[RM_NAME_MAX_CHARS]     = "My_Favorite_Queue";
217 /**********************************************************************
218  *************************** Test Functions ***************************
219  **********************************************************************/
221 void beginMemAccess (void *ptr, uint32_t size)
223     uint32_t key;
225     key = Hwi_disable();
227     /* Cleanup the prefetch buffer also. */
228     CSL_XMC_invalidatePrefetchBuffer();
229     /* Invalidate L1D cache and wait until operation is complete.
230      * Use this approach if L2 cache is not enabled */
231     CACHE_invL1d (ptr, size, CACHE_FENCE_WAIT);
232     asm   (" nop      4");
233     asm   (" nop      4");
234     asm   (" nop      4");
235     asm   (" nop      4");
236     Hwi_restore(key);
239 void endMemAccess (void *ptr, uint32_t size)
241     uint32_t key;
243     key = Hwi_disable();
245     /* Writeback L1D cache and wait until operation is complete.
246      * Use this approach if L2 cache is not enabled */
247     CACHE_wbL1d (ptr, size, CACHE_FENCE_WAIT);
248     asm   (" nop      4");
249     asm   (" nop      4");
250     asm   (" nop      4");
251     asm   (" nop      4");
252     Hwi_restore(key);
255 Rm_Packet *transportAlloc(Rm_AppTransportHandle appTransport, uint32_t pktSize, Rm_PacketHandle *pktHandle)
257     Rm_Packet     *rmPkt = NULL;
258     MsgQ_RmPacket *rmMsg = NULL;
260     /* Allocate a messageQ message for containing the RM packet */
261     rmMsg = (MsgQ_RmPacket *)MessageQ_alloc(MSGQ_HEAP_ID, sizeof(MsgQ_RmPacket));
262     if (rmMsg == NULL) {
263         System_printf("Core %d: MessageQ_alloc failed in TransportSend\n", coreNum);
264         *pktHandle = NULL;
265         return(NULL);
266     }
267     else {
268         /* Create and attach RM packet to MessageQ message.  All transports will allocate from the same heap */
269         rmPkt = HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
270         rmPkt->pktLenBytes = pktSize;
271         endMemAccess((void *)rmPkt, rmPkt->pktLenBytes);
272         rmMsg->rmPkt = rmPkt;
273         *pktHandle = (Rm_PacketHandle)rmMsg;
274     }
275     return (rmPkt);
278 void transportFree (MessageQ_Msg rmMsgQMsg, Rm_Packet *pkt)
280     uint32_t pktSize = pkt->pktLenBytes;
281     int32_t  status;
283     /* All transports will free rmPkts to the same heap */
284     HeapBufMP_free(rmPktHeapHandle, pkt, pktSize);
286     status = MessageQ_free(rmMsgQMsg);
287     if (status < 0) { 
288         System_printf("Core %d: MessageQ_free had a failure/error in transportFree\n", coreNum);
289     }     
292 int32_t transportSend (Rm_AppTransportHandle appTransport, Rm_PacketHandle pktHandle)
294     MessageQ_QueueId  remoteQueueId = (MessageQ_QueueId)appTransport;
295     MsgQ_RmPacket    *rmMsg = pktHandle;
296     int32_t           status;    
298     /* Write back data that was written by RM after alloc */
299     endMemAccess((void *)rmMsg->rmPkt, rmMsg->rmPkt->pktLenBytes);
301     /* Send the message to the remote side */
302     status = MessageQ_put(remoteQueueId, (MessageQ_Msg)rmMsg);
303     if (status < 0) {
304         transportFree((MessageQ_Msg)rmMsg, rmMsg->rmPkt);
305         System_printf("Core %d: MessageQ_put had a failure/error in TransportSend: error: %d\n", coreNum,
306                                                                                                  status);
307     }
308     return (status);
311 void transportReceive (uint32_t transportMapEntry)
313     MessageQ_Handle  receiveQ;
314     int32_t          numPkts;
315     MessageQ_Msg     rmMsg = NULL;
316     Rm_Packet       *rmPkt = NULL;
317     int32_t          status;
318     uint32_t         i;  
320     /* Check if any packets available */
321     receiveQ = rmTransportMap[transportMapEntry].receiveMsgQ;
322     numPkts = (int32_t) MessageQ_count(receiveQ);
324     /* Process all available packets */
325     for (i = 0; i < numPkts; i++) {
326         status = (int32_t) MessageQ_get(receiveQ, &rmMsg, MessageQ_FOREVER);
327         if (status < 0) {
328             System_abort("This should not happen since timeout is forever\n");
329         }
330         if (rmMsg == NULL) {
331             System_printf("Core %d: MessageQ_get failed returning a null packet in TransportReceive\n", coreNum);
332         }
334         /* Extract the Rm_Packet from the RM msg */
335         rmPkt = ((MsgQ_RmPacket *)rmMsg)->rmPkt;
336         beginMemAccess((void *) rmPkt, rmPkt->pktLenBytes);
338         /* Provide packet to RM for processing */
339         if (status = Rm_receivePacket(rmTransportMap[transportMapEntry].transportHandle, rmPkt)) {
340             System_printf("Core %d: RM encountered error processing received packet: %d\n", coreNum, status);
341         }
343         /* Free RM packet buffer and messageQ message */
344         transportFree(rmMsg, rmPkt);
345     }
348 void serviceCallback(Rm_ServiceRespInfo *serviceResponse)
350     uint32_t qIndex = 0;
351     
352     /* Populate next free entry in the responseInfoQueue */
353     while (responseInfoQueue[qIndex].serviceId != 0) {
354         qIndex++;
355         if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
356             qIndex = 0;
357         }
358     }
360     /* Save the response in the response queue for the test task to pick up */
361     memcpy((void *)&responseInfoQueue[qIndex], (void *)serviceResponse, sizeof(Rm_ServiceRespInfo));
364 bool waitForResponse(Rm_ServiceRespInfo *respInfo)
366     uint32_t qIndex = 0;
368     if (respInfo->serviceState == RM_SERVICE_PROCESSING) {
369         /* Scan responseInfoQueue for the response received via the callback function */
370         while((responseInfoQueue[qIndex].serviceId != respInfo->serviceId) ||
371               (responseInfoQueue[qIndex].rmHandle != respInfo->rmHandle)) {
372             qIndex++;
373             if (qIndex == MAX_QUEUED_SERVICE_RESPONSES) {
374                 qIndex = 0;
375             }
376             
377             /* Higher priority receive task will retrieve response */
378         }  
380         memcpy((void *)respInfo, (void *)&responseInfoQueue[qIndex], sizeof(Rm_ServiceRespInfo));
381         memset((void *)&responseInfoQueue[qIndex], 0, sizeof(Rm_ServiceRespInfo));
382     }
383     return(TRUE);
386 void setRmRequest(Rm_ServiceReqInfo *reqInfo, Rm_ServiceType type, const char *resName, int32_t resBase,
387                   uint32_t resLen, int32_t resAlign, const char *nsName, bool setCallback, Rm_ServiceRespInfo *respInfo)
388 {                                                                                
389     memset((void *)reqInfo, 0, sizeof(Rm_ServiceReqInfo));                                        
390     reqInfo->type = type;                                                                           
391     reqInfo->resourceName = resName;                                                                
392     reqInfo->resourceBase = resBase;                                                                
393     reqInfo->resourceLength = resLen;                                                               
394     reqInfo->resourceAlignment = resAlign;                                                          
395     reqInfo->resourceNsName = nsName;
396     if (setCallback) {
397         reqInfo->callback.serviceCallback = serviceCallback;  
398     }
399     memset((void *)respInfo, 0, sizeof(Rm_ServiceRespInfo));                                     
402 void rmCleanupTsk(UArg arg0, UArg arg1)
404     int32_t result;
405     
406     /* Delete the RM test tasks */
407     if (coreNum == 0) {
408         if (rmServerTskHandle) {
409             System_printf("Core %d: Deleting RM server task...\n", coreNum);
410             Task_delete(&rmServerTskHandle);
411             /* Set the task handle to be NULL so that the delete only occurs once */
412             rmServerTskHandle = NULL;
413         }
414     }
415     else if (coreNum == 1) {
416         if (rmClientTskHandle) {
417             System_printf("Core %d: Deleting RM client task...\n", coreNum);        
418             Task_delete(&rmClientTskHandle);
419             /* Set the task handle to be NULL so that the delete only occurs once */
420             rmClientTskHandle = NULL;
421         }
422     }
423     
424     /* Delete the RM receive task */
425     System_printf("Core %d: Deleting RM receive task...\n", coreNum);
426     if (rmReceiveTskHandle) {
427         Task_delete(&rmReceiveTskHandle);
428         /* Set the task handle to be NULL so that the delete only occurs once */
429         rmReceiveTskHandle = NULL;
430     }
432     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
433     if (coreNum == 0) {
434         Rm_serviceCloseHandle(rmServerServiceHandle);
436         Rm_transportUnregister(rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle);
438         result = Rm_delete(rmServerHandle, true);
439         if (result != RM_OK) {
440             System_printf("Core %d: RM server instance delete failed with error %d\n", coreNum, result);
441         }        
442     }
443     else if (coreNum == 1) {
444         Rm_serviceCloseHandle(rmCdServiceHandle);
445         Rm_serviceCloseHandle(rmClientServiceHandle);
447         Rm_transportUnregister(rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle);
448         Rm_transportUnregister(rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle);
449         Rm_transportUnregister(rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle);
451         result = Rm_delete(rmCdHandle, true);
452         if (result != RM_OK) {
453             System_printf("Core %d: RM cd instance delete failed with error %d\n", coreNum, result);
454         }  
455         result = Rm_delete(rmClientHandle, true);
456         if (result != RM_OK) {
457             System_printf("Core %d: RM client instance delete failed with error %d\n", coreNum, result);
458         }          
459     }
461     BIOS_exit(0);
464 /* Receive task has priority of 2 so that it pre-empts the RM instance test tasks */
465 void rmReceiveTsk(UArg arg0, UArg arg1)
467     while(1) {
468         if (coreNum == 0) {
469             transportReceive(SERVER_TO_CD_MAP_ENTRY);
470         }
471         else if (coreNum == 1) {
472             transportReceive(CD_TO_SERVER_MAP_ENTRY);
473             transportReceive(CD_TO_CLIENT_MAP_ENTRY);
474             transportReceive(CLIENT_TO_CD_MAP_ENTRY);
475         }
476         /* Sleep for 1ms so that the main test tasks can run */
477         Task_sleep(1);
478     }
481 void rmServerTsk(UArg arg0, UArg arg1)
483     Rm_ServiceReqInfo  requestInfo;
484     Rm_ServiceRespInfo responseInfo;
485     Task_Params        taskParams;
486        
487     /* Delete the RM startup task */
488     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
489     if (rmStartupTskHandle) {
490         Task_delete(&rmStartupTskHandle);
491         /* Set the task handle to be NULL so that the delete only occurs once */
492         rmStartupTskHandle = NULL;
493     }
495     Rm_printInstanceStatus(rmServerHandle);
497     /* BEGIN testing UNSPECIFIED base and alignment requests on Server */               
498     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
499                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 0, NULL, TRUE, &responseInfo);       
500     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
501     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
502                                                                                                   rmServerName,
503                                                                                                   resourceNameGpQ,
504                                                                                                   requestInfo.resourceLength, 
505                                                                                                   requestInfo.resourceAlignment);
506     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
507         System_printf("PASSED\n");
508     }
509     else {
510         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
511     }    
512                
513     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
514                  RM_RESOURCE_BASE_UNSPECIFIED, 1, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
515     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
516     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
517                                                                                                            rmServerName,
518                                                                                                            resourceNameGpQ,
519                                                                                                            requestInfo.resourceLength);
520     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
521         System_printf("PASSED\n");
522     }
523     else {
524         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
525     }     
527     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
528                  RM_RESOURCE_BASE_UNSPECIFIED, 1, 200, NULL, TRUE, &responseInfo);     
529     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
530     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
531                                                                                                   rmServerName,
532                                                                                                   resourceNameGpQ,
533                                                                                                   requestInfo.resourceLength,
534                                                                                                   requestInfo.resourceAlignment);
535     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
536         System_printf("PASSED\n");
537     }
538     else {
539         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
540     }      
541     /* END testing UNSPECIFIED base and alignment requests on Server */      
543     /* Create new NameServer object */                
544     setRmRequest(&requestInfo, Rm_service_RESOURCE_MAP_TO_NAME, resourceNameGpQ, 
545                  1002, 1, 0, nameServerNameFavQ, TRUE, &responseInfo);     
546     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
547     System_printf("Core %d : %s create name %s tied to %s %d - %d : ", coreNum,
548                                                                        rmServerName,
549                                                                        nameServerNameFavQ,
550                                                                        responseInfo.resourceName,
551                                                                        requestInfo.resourceBase, 
552                                                                        (requestInfo.resourceBase + requestInfo.resourceLength - 1));                                                                       
553     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
554         System_printf("PASSED\n");
555     }
556     else {
557         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
558     }     
560     /* Wait for CD and Client retrieve resource via name, allocate the resource, free resource via name, and 
561      * delete the NameServer object. */
562     gateKey = GateMP_enter(gateHandle);
563     GateMP_leave(gateHandle, gateKey);
565     /* Try to allocate the memory region taken by the Linux Kernel and not specified as shared */
566     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameMemRegion, 
567                  12, 1, 0, NULL, TRUE, &responseInfo);     
568     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo); 
569     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
570                                                                   rmServerName,
571                                                                   resourceNameMemRegion,
572                                                                   requestInfo.resourceBase, 
573                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
574     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
575         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
576     }
577     else {
578         System_printf("FAILED\n");
579     }    
581     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
582     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
583                  14, 5, 0, NULL, TRUE, &responseInfo);       
584     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
585     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
586                                                                   rmServerName,
587                                                                   resourceNameAifRxCh,
588                                                                   requestInfo.resourceBase, 
589                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
590     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
591         System_printf("PASSED\n");
592     }
593     else {
594         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
595     } 
596     
597     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
598                  19, 31, 0, NULL, TRUE, &responseInfo);      
599     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
600     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
601                                                                   rmServerName,
602                                                                   resourceNameAifRxCh,
603                                                                   requestInfo.resourceBase, 
604                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
605     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
606         System_printf("PASSED\n");
607     }
608     else {
609         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
610     }        
611     
612     /* Wait for Client and Client Delegate to do their allocations */
613     gateKey = GateMP_enter(gateHandle);
614     GateMP_leave(gateHandle, gateKey);       
616     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
617                  25, 3, 0, NULL, TRUE, &responseInfo);      
618     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
619     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
620                                                         rmServerName,
621                                                         resourceNameAifRxCh,
622                                                         requestInfo.resourceBase, 
623                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
624     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
625         System_printf("PASSED\n");
626     }
627     else {
628         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
629     }      
630     
631     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
632                  34, 3, 0, NULL, TRUE, &responseInfo);      
633     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
634     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
635                                                         rmServerName,
636                                                         resourceNameAifRxCh,
637                                                         requestInfo.resourceBase, 
638                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
639     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
640         System_printf("PASSED\n");
641     }
642     else {
643         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
644     }      
645  
646     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, resourceNameAifRxCh, 
647                  28, 6, 0, NULL, TRUE, &responseInfo);      
648     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);   
649     System_printf("Core %d : %s free of %s %d - %d : ", coreNum,
650                                                         rmServerName,
651                                                         resourceNameAifRxCh,
652                                                         requestInfo.resourceBase, 
653                                                         (requestInfo.resourceBase + requestInfo.resourceLength - 1));
654     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
655         System_printf("PASSED\n");
656     }
657     else {
658         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
659     }      
661     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
662                  53, 2, 0, NULL, TRUE, &responseInfo);      
663     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
664     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
665                                                                   rmServerName,
666                                                                   resourceNameAifRxCh,
667                                                                   requestInfo.resourceBase, 
668                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
669     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
670         System_printf("PASSED\n");
671     }
672     else {
673         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
674     }  
675     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */  
676     
677     /* Test execlusive rights to an allocated resource */
678     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
679                  2, 2, 0, NULL, TRUE, &responseInfo);      
680     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
681     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
682                                                                   rmServerName,
683                                                                   resourceNameAifRxCh,
684                                                                   requestInfo.resourceBase, 
685                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
686     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {
687         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
688     }
689     else {
690         System_printf("FAILED\n");
691     }      
693     /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
694     gateKey = GateMP_enter(gateHandle);
695     GateMP_leave(gateHandle, gateKey);
697     /* Test allocation of a resource twice from the same instance with init and use privileges.  Both
698      * should be approved but the instance should only be mentioned once in the resource's owner list */
699     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
700                  6543, 10, 0, NULL, TRUE, &responseInfo);      
701     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);  
702     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
703                                                                    rmServerName,
704                                                                    resourceNameGpQ,
705                                                                    requestInfo.resourceBase, 
706                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
707     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
708         System_printf("PASSED\n");
709     }
710     else {
711         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
712     }     
714     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameGpQ, 
715                  6543, 10, 0, NULL, TRUE, &responseInfo);      
716     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
717     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
718                                                                   rmServerName,
719                                                                   resourceNameGpQ,
720                                                                   requestInfo.resourceBase, 
721                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
722     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
723         System_printf("PASSED\n");
724     }
725     else {
726         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
727     }        
729     /* Allocate infrastructure queue taken by Linux kernel and shared with Rm_Client.  Expect error or denial. */
730     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
731                  805, 1, 0, NULL, TRUE, &responseInfo);     
732     rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
733     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
734                                                                    rmServerName,
735                                                                    resourceNameInfraQ,
736                                                                    requestInfo.resourceBase, 
737                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
738     if (responseInfo.serviceState != RM_SERVICE_APPROVED) {        
739         System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
740     }
741     else {
742         System_printf("FAILED\n");
743     }              
745     System_printf("Core %d: Testing is complete\n", coreNum);
747     Rm_printInstanceStatus(rmServerHandle);
748     Rm_printResourceStatus(rmServerHandle);   
749     
750     /* Create the RM cleanup task. */
751     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
752     Task_Params_init (&taskParams);
753     Task_create (rmCleanupTsk, &taskParams, NULL);
756 void rmClientTsk(UArg arg0, UArg arg1)
758     Rm_ServiceReqInfo  requestInfo;
759     Rm_ServiceRespInfo responseInfo;    
760     Task_Params        taskParams;
761     uint32_t           i, j;
762        
763     /* Delete the RM startup task */
764     System_printf("Core %d: Deleting RM startup task...\n", coreNum);
765     if (rmStartupTskHandle) {
766        Task_delete(&rmStartupTskHandle);
767        /* Set the task handle to be NULL so that the delete only occurs once */
768        rmStartupTskHandle = NULL;
769     }
771     Rm_printInstanceStatus(rmCdHandle);
772     Rm_printInstanceStatus(rmClientHandle);
774     /* Retrieve a resource via a NameServer name */
775     setRmRequest(&requestInfo, Rm_service_RESOURCE_GET_BY_NAME, NULL, 
776                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
777     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
778     System_printf("Core %d : %s get resource with name %s : ", coreNum,
779                                                                rmCdName,
780                                                                nameServerNameFavQ);
781     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
782         waitForResponse(&responseInfo);
783     }
784     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
785         System_printf("PASSED\n");
786     }
787     else {
788         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
789     } 
791     /* Allocate the resource returned from the NameServer request */
792     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo)); 
793     requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
794     requestInfo.resourceName = responseInfo.resourceName;
795     requestInfo.resourceBase = responseInfo.resourceBase;
796     requestInfo.resourceLength = responseInfo.resourceLength;
797     requestInfo.resourceNsName = NULL;
798     requestInfo.callback.serviceCallback = serviceCallback;     
799     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
800     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
801                                                                    rmClientName,
802                                                                    responseInfo.resourceName,
803                                                                    requestInfo.resourceBase, 
804                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
805     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
806         waitForResponse(&responseInfo);
807     }
808     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
809         System_printf("PASSED\n");
810     }
811     else {
812         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
813     }    
815     /* Free resource via a NameServer name */
816     setRmRequest(&requestInfo, Rm_service_RESOURCE_FREE, NULL, 
817                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
818     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
819     System_printf("Core %d : %s free resource with name %s : ", coreNum,
820                                                                 rmClientName,
821                                                                 nameServerNameFavQ);
822     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
823         waitForResponse(&responseInfo);
824     }
825     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
826         System_printf("PASSED\n");
827     }
828     else {
829         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
830     }      
832     /* Delete the NameServer name */
833     setRmRequest(&requestInfo, Rm_service_RESOURCE_UNMAP_NAME, NULL, 
834                  0, 0, 0, nameServerNameFavQ, TRUE, &responseInfo);     
835     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);     
836     System_printf("Core %d : %s delete name %s : ", coreNum,
837                                                     rmClientName,
838                                                     nameServerNameFavQ);
839     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
840         waitForResponse(&responseInfo);
841     }
842     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
843         System_printf("PASSED\n");
844     }
845     else {
846         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
847     }     
849     GateMP_leave(gateHandle, gateKey);
850     gateKey = GateMP_enter(gateHandle);
852     /* BEGIN testing expansion/contraction of resource nodes with the AIF RX CH resource */
853     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAifRxCh, 
854                  0, 6, 0, NULL, TRUE, &responseInfo);     
855     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
856     System_printf("Core %d : %s use allocation of %s %d - %d : ", coreNum,
857                                                                   rmClientName,
858                                                                   resourceNameAifRxCh,
859                                                                   requestInfo.resourceBase, 
860                                                                   (requestInfo.resourceBase + requestInfo.resourceLength - 1));
861     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
862         waitForResponse(&responseInfo);
863     }
864     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
865         System_printf("PASSED\n");
866     }
867     else {
868         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
869     }     
870     
871     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifRxCh, 
872                  50, 7, 0, NULL, TRUE, &responseInfo);        
873     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
874     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
875                                                                    rmCdName,
876                                                                    resourceNameAifRxCh,
877                                                                    requestInfo.resourceBase, 
878                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
879     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
880         waitForResponse(&responseInfo);
881     }
882     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
883         System_printf("PASSED\n");
884     }
885     else {
886         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
887     }       
888     /* END testing expansion/contraction of resource nodes with the AIF RX CH resource */
890     GateMP_leave(gateHandle, gateKey);    
891     gateKey = GateMP_enter(gateHandle);
893     /* BEGIN testing allocations with UNSPECIFIED base and alignment values */
894     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
895                  RM_RESOURCE_BASE_UNSPECIFIED, 5, 4, NULL, TRUE, &responseInfo);        
896     rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
897     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
898                                                                                                   rmCdName,
899                                                                                                   resourceNameAccumCh,
900                                                                                                   requestInfo.resourceLength, 
901                                                                                                   requestInfo.resourceAlignment);
902     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
903         waitForResponse(&responseInfo);
904     }
905     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
906         System_printf("PASSED\n");
907     }
908     else {
909         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
910     }        
912     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
913                  RM_RESOURCE_BASE_UNSPECIFIED, 2, 1, NULL, TRUE, &responseInfo);      
914     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo); 
915     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length %d alignment : ", coreNum,
916                                                                                                   rmClientName,
917                                                                                                   resourceNameAccumCh,
918                                                                                                   requestInfo.resourceLength, 
919                                                                                                   requestInfo.resourceAlignment);
920     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
921         waitForResponse(&responseInfo);
922     }
923     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
924         System_printf("PASSED\n");
925     }
926     else {
927         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
928     }     
930     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_USE, resourceNameAccumCh, 
931                  RM_RESOURCE_BASE_UNSPECIFIED, 2, RM_RESOURCE_ALIGNMENT_UNSPECIFIED, NULL, TRUE, &responseInfo);     
932     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
933     System_printf("Core %d : %s use allocation of %s UNSPECIFIED base %d length UNSPECIFIED alignment : ", coreNum,
934                                                                                                            rmClientName,
935                                                                                                            resourceNameAccumCh,
936                                                                                                            requestInfo.resourceLength);
937     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
938         waitForResponse(&responseInfo);
939     }
940     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
941         System_printf("PASSED\n");
942     }
943     else {
944         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
945     }     
946     /* END testing allocations with UNSPECIFIED base and alignment values */    
948     /* Allocate infrastructure queue shared between Linux kernel and Client */
949     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameInfraQ, 
950                  800, 1, 0, NULL, TRUE, &responseInfo);     
951     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
952     System_printf("Core %d : %s init allocation of %s %d - %d : ", coreNum,
953                                                                    rmClientName,
954                                                                    resourceNameInfraQ,
955                                                                    requestInfo.resourceBase, 
956                                                                    (requestInfo.resourceBase + requestInfo.resourceLength - 1));
957     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
958         waitForResponse(&responseInfo);
959     }
960     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
961         System_printf("PASSED\n");
962     }
963     else {
964         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
965     }     
967     /* Allocate a resource without providing a callback function.  RM should block and not return until the result
968      * is returned by the server. */
969     setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameGpQ, 
970                  7000, 1, 0, NULL, TRUE, &responseInfo);     
971     rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);   
972     System_printf("Core %d : %s init allocation (without callback specified) of %s %d - %d : ", coreNum,
973                                                                                                 rmClientName,
974                                                                                                 resourceNameGpQ,
975                                                                                                 requestInfo.resourceBase, 
976                                                                                                 (requestInfo.resourceBase + requestInfo.resourceLength - 1));
977     if (responseInfo.serviceState == RM_SERVICE_PROCESSING) {
978         waitForResponse(&responseInfo);
979     }
980     if (responseInfo.serviceState == RM_SERVICE_APPROVED) {
981         System_printf("PASSED\n");
982     }
983     else {
984         System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
985     }      
987     GateMP_leave(gateHandle, gateKey);           
989     /* Verify static allocations were validated.  Validation responses should have been received after the
990      * first service requests were made on the Client and CD post transport path registration. */
991     while (numStaticResponses > 0) {
992         /* Loop until all static request validations have been received */
993         for (i = 0; i < MAX_STATIC_ALLOCATION_RESPS; i++) {
994             if (staticResponseQueue[i].serviceId != 0) {
995                 for (j = 0; j < MAX_QUEUED_SERVICE_RESPONSES; j++) {
996                     if ((staticResponseQueue[i].serviceId == responseInfoQueue[j].serviceId) &&
997                         (staticResponseQueue[i].rmHandle == responseInfoQueue[j].rmHandle)) {
998                         System_printf("Core %d : static allocation validation of %s %d - %d : ", coreNum,
999                                                                                                  responseInfoQueue[j].resourceName,
1000                                                                                                  responseInfoQueue[j].resourceBase, 
1001                                                                                                  (responseInfoQueue[j].resourceBase + responseInfoQueue[j].resourceLength - 1));        
1002                         if (responseInfoQueue[j].serviceState == RM_SERVICE_APPROVED) {
1003                             System_printf("PASSED\n");
1004                         }
1005                         else {
1006                             System_printf("FAILED : denial or error : %d\n", responseInfoQueue[j].serviceState);
1007                         }  
1008                         memset((void *)&staticResponseQueue[i], 0, sizeof(Rm_ServiceRespInfo));
1009                         memset((void *)&responseInfoQueue[j], 0, sizeof(Rm_ServiceRespInfo));
1010                         numStaticResponses--;                        
1011                         break;
1012                     }
1013                 }
1014             }
1015         }    
1016     }   
1019     System_printf("Core %d: Testing is complete\n", coreNum);
1021     Rm_printInstanceStatus(rmCdHandle);
1022     Rm_printInstanceStatus(rmClientHandle);
1023     
1024     /* Create the RM cleanup task. */
1025     System_printf("Core %d: Creating RM cleanup task...\n", coreNum);
1026     Task_Params_init (&taskParams);
1027     Task_create (rmCleanupTsk, &taskParams, NULL);
1030 void rmStartupTsk(UArg arg0, UArg arg1)
1032     MessageQ_Handle    serverFromCdMsgQ, cdFromServerMsgQ, cdFromClientMsgQ, clientFromCdMsgQ;
1033     MessageQ_QueueId   serverToCdQId, cdToServerQId, cdToClientQId, clientToCdQId;    
1034     Int                status, i;
1035     GateMP_Params      gateParams;    
1036     HeapBufMP_Handle   msgQHeapHandle;
1037     HeapBufMP_Params   heapBufParams;
1038     Rm_TransportCfg    rmTransportCfg;
1039     int32_t            result = 0;
1040     Rm_TransportHandle serverCdHandle, cdServerHandle, cdClientHandle, clientCdHandle;
1041     Task_Params        taskParams;
1043     /* Initialize the transport map */
1044     for (i = 0; i < MAX_MAPPING_ENTRIES; i++) {
1045         rmTransportMap[i].transportHandle = NULL;
1046     }
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     
1276     /* Create the RM test tasks. */
1277     if (coreNum == 0) {
1278         System_printf("Core %d: Creating RM server task...\n", coreNum);
1279         Task_Params_init (&taskParams);
1280         taskParams.priority = 1;
1281         rmServerTskHandle = Task_create (rmServerTsk, &taskParams, NULL);
1282     }
1283     else if (coreNum) {
1284         System_printf("Core %d: Creating RM client task...\n", coreNum);
1285         Task_Params_init (&taskParams);
1286         taskParams.priority = 1;
1287         rmClientTskHandle = Task_create (rmClientTsk, &taskParams, NULL);
1288     }
1291 int main(Int argc, Char* argv[])
1293     Rm_InitCfg         rmInitCfg;
1294     Task_Params        taskParams; 
1295     int                status;
1296     Rm_ServiceReqInfo  requestInfo;
1297     Rm_ServiceRespInfo responseInfo;
1298     int32_t            result;
1300     System_printf ("*********************************************************\n");
1301     System_printf ("********************** RM Testing ***********************\n");
1302     System_printf ("*********************************************************\n");
1304     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
1306     coreNum = MultiProc_self();
1308     /* Initialize the RM instances - RM must be initialized before anything else in the system
1309      * Core 0: 1 RM Instance  - RM Server
1310      * Core 1: 2 RM Instances - RM Client Delegate
1311      *                          RM Client
1312      */
1313     if (coreNum == 0) {
1314         /* Create the Server instance */
1315         rmInitCfg.instName = rmServerName;
1316         rmInitCfg.instType = Rm_instType_SERVER;
1317         rmInitCfg.instCfg.serverCfg.globalResourceList = (void *)rmGrl;
1318         rmInitCfg.instCfg.serverCfg.linuxDtb = (void *)rmLinuxDtb;
1319         rmInitCfg.instCfg.serverCfg.globalPolicy = (void *)rmGlobalPolicy;
1320         rmServerHandle = Rm_init(&rmInitCfg, &result);
1321         ERROR_CHECK(RM_OK, result, rmServerName, "Initialization failed");
1323         /* Open Server service handle */
1324         rmServerServiceHandle = Rm_serviceOpenHandle(rmServerHandle, &result);
1325         ERROR_CHECK(RM_OK, result, rmServerName, "Service handle open failed");
1326     }
1327     else if (coreNum == 1) {
1328         /* Create the RM Client Delegate instance */
1329         rmInitCfg.instName = rmCdName;
1330         rmInitCfg.instType = Rm_instType_CLIENT_DELEGATE;
1331         rmInitCfg.instCfg.cdCfg.staticPolicy = (void *)rmStaticPolicy;
1332         rmCdHandle = Rm_init(&rmInitCfg, &result);
1333         ERROR_CHECK(RM_OK, result, rmCdName, "Initialization failed");
1335         /* Open CD service handle */
1336         rmCdServiceHandle = Rm_serviceOpenHandle(rmCdHandle, &result);
1337         ERROR_CHECK(RM_OK, result, rmCdName, "Service handle open failed");
1339         /* Create the RM Client instance */
1340         rmInitCfg.instName = &rmClientName[0];
1341         rmInitCfg.instType = Rm_instType_CLIENT;      
1342         rmInitCfg.instCfg.clientCfg.staticPolicy = (void *)rmStaticPolicy;
1343         rmClientHandle = Rm_init(&rmInitCfg, &result);
1344         ERROR_CHECK(RM_OK, result, rmClientName, "Initialization failed");
1346         /* Open Client service handle */
1347         rmClientServiceHandle = Rm_serviceOpenHandle(rmClientHandle, &result);
1348         ERROR_CHECK(RM_OK, result, rmClientName, "Service handle open failed");
1350         /* Initialize the static allocation response queue */
1351         for (numStaticResponses = 0; numStaticResponses < MAX_STATIC_ALLOCATION_RESPS; numStaticResponses++) {
1352             memset((void *)&staticResponseQueue[numStaticResponses], 0, sizeof(Rm_ServiceRespInfo));
1353         }
1354         numStaticResponses = 0;
1356         /* Static allocation tests */
1357         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1358                      0, 1, 0, NULL, TRUE, &responseInfo);
1359         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1360         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1361                                                                               rmCdName,
1362                                                                               resourceNameQosCluster,
1363                                                                               requestInfo.resourceBase, 
1364                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1365         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1366             System_printf("PASSED\n");
1367             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1368         }
1369         else {
1370             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1371         }        
1372         
1373         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1374                      2, 1, 0, NULL, TRUE, &responseInfo);        
1375         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1376         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1377                                                                               rmClientName,
1378                                                                               resourceNameQosCluster,
1379                                                                               requestInfo.resourceBase, 
1380                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1381         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1382             System_printf("PASSED\n");
1383             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1384         }
1385         else {
1386             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1387         }
1389         /* Request resource from Client that can only be allocated to CD according to static policy */
1390         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameQosCluster, 
1391                      1, 1, 0, NULL, TRUE, &responseInfo);        
1392         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1393         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1394                                                                               rmClientName,
1395                                                                               resourceNameQosCluster,
1396                                                                               requestInfo.resourceBase, 
1397                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1398         if (responseInfo.serviceState != RM_SERVICE_APPROVED_STATIC) {        
1399             System_printf("PASSED : denial or error : %d\n", responseInfo.serviceState);
1400         }
1401         else {
1402             System_printf("FAILED\n");
1403         }
1405         /* Request resource from both Client and CD that is shared according to static policy */
1406         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1407                      525, 1, 0, NULL, TRUE, &responseInfo);        
1408         rmCdServiceHandle->Rm_serviceHandler(rmCdServiceHandle->rmHandle, &requestInfo, &responseInfo);
1409         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1410                                                                               rmCdName,
1411                                                                               resourceNameAifQ,
1412                                                                               requestInfo.resourceBase, 
1413                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1414         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1415             System_printf("PASSED\n");
1416             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1417         }
1418         else {
1419             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1420         }
1422         setRmRequest(&requestInfo, Rm_service_RESOURCE_ALLOCATE_INIT, resourceNameAifQ, 
1423                      525, 1, 0, NULL, TRUE, &responseInfo);        
1424         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
1425         System_printf("Core %d : %s static init allocation of %s %d - %d : ", coreNum,
1426                                                                               rmClientName,
1427                                                                               resourceNameAifQ,
1428                                                                               requestInfo.resourceBase, 
1429                                                                               (requestInfo.resourceBase + requestInfo.resourceLength - 1));
1430         if (responseInfo.serviceState == RM_SERVICE_APPROVED_STATIC) {        
1431             System_printf("PASSED\n");
1432             memcpy((void *)&staticResponseQueue[numStaticResponses++], (void *)&responseInfo, sizeof(Rm_ServiceRespInfo));
1433         }
1434         else {
1435             System_printf("FAILED : denial or error : %d\n", responseInfo.serviceState);
1436         }    
1437     }
1439     System_printf("Core %d: Starting IPC...\n", coreNum);
1440     status = Ipc_start();
1441     if (status < 0) {
1442         System_abort("Ipc_start failed\n");
1443     }
1445     /* Create the RM startup task */
1446     System_printf("Core %d: Creating RM startup task...\n", coreNum);
1447     Task_Params_init (&taskParams);
1448     rmStartupTskHandle = Task_create (rmStartupTsk, &taskParams, NULL);
1450     System_printf("Core %d: Starting BIOS...\n", coreNum);
1451     BIOS_start();
1453     return (0);