5889b4fa81b31967e3ee77f6cb9474cfe874ddad
[keystone-rtos/rm-lld.git] / test / rm_test.c
1 /* 
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * */
32 /*
33  *  ======== rm_test.c ========
34  *  RM multicore test example
35  *
36  *  This is an example program that uses MessageQ to pass a message
37  *  from one processor to another.
38  *
39  *  Each processor creates its own MessageQ first and then will try to open
40  *  a remote processor's MessageQ.  
41  *
42  *  See message_multicore.k file for expected output.
43  */
45 #include <c6x.h>
46 #include <xdc/std.h>
47 #include <stdio.h>
48 #include <string.h>
49 #include <stdbool.h>
51 /*  -----------------------------------XDC.RUNTIME module Headers    */
52 #include <xdc/runtime/System.h>
53 #include <xdc/runtime/IHeap.h>
55 /*  ----------------------------------- IPC module Headers           */
56 #include <ti/ipc/Ipc.h>
57 #include <ti/ipc/MessageQ.h>
58 #include <ti/ipc/HeapBufMP.h>
59 #include <ti/ipc/MultiProc.h>
61 /*  ----------------------------------- BIOS6 module Headers         */
62 #include <ti/sysbios/BIOS.h>
63 #include <ti/sysbios/knl/Task.h>
65 /*  ----------------------------------- Resource Manager Headers         */
66 #include <ti/drv/rm/rm.h>
67 #include <ti/drv/rm/rm_osal.h>
68 #include <ti/drv/rm/rm_transport.h>
69 #include <ti/drv/rm/rm_services.h>
71 /* ======== Task Handles ======== */
72 Task_Handle startupRmTskHandle;
73 Task_Handle testReceiveTskHandle;
74 Task_Handle testRmTskHandle;
76 /* ======== Application Heaps ======== */
77 #define RM_PKT_HEAP_NAME   "rmHeapBuf"
78 HeapBufMP_Handle rmPktHeapHandle = NULL;
80 #define MSGQ_HEAP_NAME   "msgQHeapBuf"
81 #define MSGQ_HEAP_ID      0
83 /* ======== RM Instance Names ======== */
84 Char rmServerName[RM_NAME_MAX_CHARS] = "RM_Server";
85 Char rmClientDelegateName[RM_NAME_MAX_CHARS] = "RM_Client_Delegate";
86 Char rmClientName[RM_NAME_MAX_CHARS] = "RM_Client";
88 /* ======== RM IPC MessageQ Names ======== */
89 Char serverFromCdQueueName[30] = "RM_Server_From_CD_Queue";
90 Char cdFromServerQueueName[30] = "RM_CD_From_Server_Queue";
91 Char cdFromClientQueueName[30] = "RM_CD_From_Client_Queue";
92 Char clientFromCdQueueName[30] = "RM_Client_From_CD_Queue";
94 /* ======== RM Instance Handles ======== */
95 Rm_Handle rmServerHandle = NULL;
96 Rm_Handle rmClientDelegateHandle = NULL;
97 Rm_Handle rmClientHandle = NULL;
99 /* ======== RM Instance Service Ports ======== */
100 Rm_ServiceHandle *rmServerServiceHandle = NULL;
101 Rm_ServiceHandle *rmClientDelegateServiceHandle = NULL;
102 Rm_ServiceHandle *rmClientServiceHandle = NULL;
104 /* ======== RM Transport Packet Definition ======== */
105 typedef struct {
106   MessageQ_MsgHeader msgQHeader;
107   /* Pointer to packet provided by RM */
108   Rm_Packet *rmPkt;
109 } MsgQ_RmPacket;
111 /* ======== RM Transport Mapping Tables for Application ======== */
112 /* Core 0 Map Entry Indices */
113 #define SERVER_TO_CD_MAP_ENTRY 0
114 /* Core 1 Map Entry Indicies */
115 #define CD_TO_SERVER_MAP_ENTRY 0
116 #define CD_TO_CLIENT_MAP_ENTRY 1
117 #define CLIENT_TO_CD_MAP_ENTRY 2
119 /* Max map entries across all cores */
120 #define MAX_MAPPING_ENTRIES 3
122 typedef struct {
123     Rm_TransportHandle transportHandle;
124     MessageQ_Handle receiveMsgQ;
125 } Transport_MapEntry;
127 /* Core 1 will have three mapping entries
128  * Two map entries for the Client Delegate
129  * One map entry for the Client */
130 Transport_MapEntry rmTransportMap[MAX_MAPPING_ENTRIES];
132 uint32_t waitForBlockingOperation = 0;
133 Rm_ServiceRespInfo responseInfo;
135 /* ======== RM Application Sync APIs ======== */
137 typedef struct {
138     uint32_t sem;
139     uint32_t pad[31];
140 } syncObj;
142 #pragma DATA_SECTION (testSyncObj, ".syncObj");
143 #pragma DATA_ALIGN (testSyncObj, 16)
144 syncObj testSyncObj;
146 void initSyncObj(void)
148     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
149     testSyncObj.sem = 0;
150     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
153 void takeSyncObj(void)
155     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
156     testSyncObj.sem = 1;
157     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
160 void waitOnSyncObj(void)
162     do {
163         /* Yield for other tasks */
164         Task_yield();
165         Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
166     } while (testSyncObj.sem == 1);
169 void releaseSyncObj(void)
171     Rm_osalBeginMemAccess((void *) &testSyncObj, sizeof(syncObj));    
172     testSyncObj.sem = 0;
173     Rm_osalEndMemAccess((void *) &testSyncObj, sizeof(syncObj));
176 /* ======== RM Application Transport APIs ======== */
178 Rm_Packet *transportAlloc(Rm_AppTransportHandle appTransport, uint32_t pktSize, Rm_PacketHandle *pktHandle)
180     Rm_Packet     *rmPkt = NULL;
181     MsgQ_RmPacket *rmMsg = NULL;
183     /* Allocate a messageQ message for containing the RM packet */
184     rmMsg = (MsgQ_RmPacket *)MessageQ_alloc(MSGQ_HEAP_ID, sizeof(MsgQ_RmPacket));
185     if (rmMsg == NULL) {
186         System_printf("Core %d: MessageQ_alloc failed in TransportSend\n", MultiProc_self());
187         *pktHandle = NULL;
188         return(NULL);
189     }
190     else {
191         /* Create and attach RM packet to MessageQ message.  All transports will allocate from the same heap */
192         rmPkt = HeapBufMP_alloc(rmPktHeapHandle, pktSize, 0);
193         rmPkt->pktLenBytes = pktSize;
194         Rm_osalEndMemAccess((void *)rmPkt, rmPkt->pktLenBytes);
195         rmMsg->rmPkt = rmPkt;
196         *pktHandle = (Rm_PacketHandle)rmMsg;
197     }
198     return (rmPkt);
201 void transportFree (MessageQ_Msg rmMsgQMsg, Rm_Packet *pkt)
203     uint32_t pktSize = pkt->pktLenBytes;
204     int32_t  status;
206     /* All transports will free rmPkts to the same heap */
207     HeapBufMP_free(rmPktHeapHandle, pkt, pktSize);
209     status = MessageQ_free(rmMsgQMsg);
210     if (status < 0) { 
211         System_printf("Core %d: MessageQ_free had a failure/error in transportFree\n", MultiProc_self());
212     }     
215 int32_t transportSend (Rm_AppTransportHandle appTransport, Rm_PacketHandle pktHandle)
217     MessageQ_QueueId  remoteQueueId = (MessageQ_QueueId)appTransport;
218     MsgQ_RmPacket    *rmMsg = pktHandle;
219     int32_t           status;    
221     /* Write back data that was written by RM after alloc */
222     Rm_osalEndMemAccess((void *)rmMsg->rmPkt, rmMsg->rmPkt->pktLenBytes);
224     /* Send the message to the remote side */
225     status = MessageQ_put(remoteQueueId, (MessageQ_Msg)rmMsg);
226     if (status < 0) {
227         transportFree((MessageQ_Msg)rmMsg, rmMsg->rmPkt);
228         System_printf("Core %d: MessageQ_put had a failure/error in TransportSend: error: %d\n", MultiProc_self(),
229                                                                                                  status);
230     }
231     return (status);
234 void transportReceive (uint32_t transportMapEntry)
236     MessageQ_Handle  receiveQ;
237     int32_t          numPkts;
238     MessageQ_Msg     rmMsg = NULL;
239     Rm_Packet       *rmPkt = NULL;
240     int32_t          status;
241     uint32_t         i;  
243     /* Check if any packets available */
244     receiveQ = rmTransportMap[transportMapEntry].receiveMsgQ;
245     numPkts = (int32_t) MessageQ_count(receiveQ);
247     /* Process all available packets */
248     for (i = 0; i < numPkts; i++) {
249         status = (int32_t) MessageQ_get(receiveQ, &rmMsg, MessageQ_FOREVER);
250         if (status < 0) {
251             System_abort("This should not happen since timeout is forever\n");
252         }
253         if (rmMsg == NULL) {
254             System_printf("Core %d: MessageQ_get failed returning a null packet in TransportReceive\n", MultiProc_self());
255         }
257         /* Extract the Rm_Packet from the RM msg */
258         rmPkt = ((MsgQ_RmPacket *)rmMsg)->rmPkt;
259         Rm_osalBeginMemAccess((void *) rmPkt, rmPkt->pktLenBytes);
261         /* Provide packet to RM for processing */
262         if (status = Rm_receivePacket(rmTransportMap[transportMapEntry].transportHandle, rmPkt)) {
263             System_printf("Core %d: RM encountered error processing received packet: %d\n", MultiProc_self(), status);
264         }
266         /* Free RM packet buffer and messageQ message */
267         transportFree(rmMsg, rmPkt);
268     }
271 /*
272  *  ======== testServiceCallback ========
273  *  Application's callback function given to RM on service requests
274  */
275 void testServiceCallback(Rm_ServiceRespInfo *serviceResponse)
277     if (serviceResponse->serviceId == waitForBlockingOperation) {
278         waitForBlockingOperation = 0;
279         strcpy(responseInfo.resourceName, serviceResponse->resourceName);
280         responseInfo.resourceBase = serviceResponse->resourceBase;
281         responseInfo.resourceLength = serviceResponse->resourceLength;
282         responseInfo.serviceState = serviceResponse->serviceState;
283     }
286 bool blockForResponse(Rm_ServiceRespInfo *respInfo)
288     waitForBlockingOperation = respInfo->serviceId;
289     /* Block and wait for the response if the RM needed to perform a blocking operation
290      * to complete the request */
291     while(waitForBlockingOperation) {
292         /* Yield to receive task to see if there are any packets for RM instance */
293         Task_yield();
294     }       
296     if ((respInfo->serviceState != RM_SERVICE_PROCESSING) &&
297         (respInfo->serviceState != RM_SERVICE_APPROVED_AND_COMPLETED)) {
298         System_printf("Core %d: Service request encountered error or denial: %d\n", MultiProc_self(),
299                                                                                     respInfo->serviceState);
300         return(FALSE);
301     }
302     return(TRUE);
305 /*
306  *  ======== testRmTsk ========
307  *  RM cleanup task
308  */
309 void cleanupRmTsk(UArg arg0, UArg arg1)
311     /* Delete the RM test task */
312     System_printf("Core %d: Deleting RM test task...\n", MultiProc_self());
313     if (testRmTskHandle) {
314         Task_delete(&testRmTskHandle);
315         /* Set the task handle to be NULL so that the delete only occurs once */
316         testRmTskHandle = NULL;
317     }
318     /* Delete the RM receive task */
319     System_printf("Core %d: Deleting RM receive task...\n", MultiProc_self());
320     if (testReceiveTskHandle) {
321         Task_delete(&testReceiveTskHandle);
322         /* Set the task handle to be NULL so that the delete only occurs once */
323         testReceiveTskHandle = NULL;
324     }
326     /* Cleanup all service ports, transport handles, RM instances, and IPC constructs */
328     BIOS_exit(0);
331 /*
332  *  ======== testRmTsk ========
333  *  RM test task
334  */
335 void testReceiveTsk(UArg arg0, UArg arg1)
337     while(1) {
338         if (MultiProc_self() == 0) {
339             transportReceive(SERVER_TO_CD_MAP_ENTRY);
340         }
341         else if (MultiProc_self() == 1) {
342             transportReceive(CD_TO_SERVER_MAP_ENTRY);
343             transportReceive(CD_TO_CLIENT_MAP_ENTRY);
344             transportReceive(CLIENT_TO_CD_MAP_ENTRY);
345         }
346         /* Yield for main test task */
347         Task_yield();
348     }
351 /*
352  *  ======== testRmTsk ========
353  *  RM test task
354  */
355 void testRmTsk(UArg arg0, UArg arg1)
357     Rm_ServiceReqInfo requestInfo;
358     Task_Params taskParams;
359     int32_t result;
360        
361     /* Delete the RM startup task */
362     System_printf("Core %d: Deleting RM startup task...\n", MultiProc_self());
363     if (startupRmTskHandle)
364     {
365         Task_delete(&startupRmTskHandle);
366         /* Set the task handle to be NULL so that the delete only occurs once */
367         startupRmTskHandle = NULL;
368     }
370     /* Open service ports on all the RM instances to test service requests from the different
371      * RM instances */
372     if (MultiProc_self() == 0)
373     {
374         rmServerServiceHandle = Rm_serviceOpenHandle(rmServerHandle, &result);
375     }
376     else if (MultiProc_self() == 1)
377     {
378         rmClientDelegateServiceHandle = Rm_serviceOpenHandle(rmClientDelegateHandle, &result);
379         rmClientServiceHandle = Rm_serviceOpenHandle(rmClientHandle, &result);
380     }
382     memset((void *)&requestInfo, 0, sizeof(Rm_ServiceReqInfo));
383     memset((void *)&responseInfo, 0, sizeof(Rm_ServiceRespInfo));
385     System_printf("Core %d: Testing NameServer features...\n", MultiProc_self());
387     /* Use the service ports to test the service requests */
388     if (MultiProc_self() == 0)
389     {
390         char resourceName[RM_NAME_MAX_CHARS] = "gp-queue";
391         char resourceNsName[RM_NAME_MAX_CHARS] = "My_Favorite_Queue";
393         char aifName[RM_NAME_MAX_CHARS] = "aif-rx-ch";
394         char memRegionName[RM_NAME_MAX_CHARS] = "memory-regions";
396         /* Issue the service request create a new NameServer object via the service port */                
397         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
398         requestInfo.resourceName = resourceName;
399         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
400         requestInfo.resourceLength = 1;
401         requestInfo.resourceAlignment = 0;
402         requestInfo.callback.serviceCallback = testServiceCallback;
403         
404         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
405         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
406         if (blockForResponse(&responseInfo))
407         {
408             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
409                                                                                       rmServerName,
410                                                                                       responseInfo.resourceName, 
411                                                                                       responseInfo.resourceBase,
412                                                                                       responseInfo.resourceLength);            
413         }   
415         /* Issue the service request create a new NameServer object via the service port */                
416         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
417         requestInfo.resourceName = resourceName;
418         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
419         requestInfo.resourceLength = 1;
420         requestInfo.resourceAlignment = RM_RESOURCE_ALIGNMENT_UNSPECIFIED;
421         requestInfo.callback.serviceCallback = testServiceCallback;
422         
423         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
424         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
425         if (blockForResponse(&responseInfo))
426         {
427             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
428                                                                                       rmServerName,
429                                                                                       responseInfo.resourceName, 
430                                                                                       responseInfo.resourceBase,
431                                                                                       responseInfo.resourceLength);            
432         }         
434         /* Issue the service request create a new NameServer object via the service port */                
435         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
436         requestInfo.resourceName = resourceName;
437         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
438         requestInfo.resourceLength = 1;
439         requestInfo.resourceAlignment = 200;
440         requestInfo.callback.serviceCallback = testServiceCallback;
441         
442         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
443         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
444         if (blockForResponse(&responseInfo))
445         {
446             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
447                                                                                       rmServerName,
448                                                                                       responseInfo.resourceName, 
449                                                                                       responseInfo.resourceBase,
450                                                                                       responseInfo.resourceLength);            
451         }   
453         Rm_printResourceStatus(rmServerHandle);
456         /* Issue the service request create a new NameServer object via the service port */                
457         requestInfo.type = Rm_service_RESOURCE_MAP_TO_NAME;
458         requestInfo.resourceName = resourceName;
459         requestInfo.resourceBase = 1002;
460         requestInfo.resourceLength = 1;
461         requestInfo.resourceNsName = resourceNsName;
462         requestInfo.callback.serviceCallback = testServiceCallback;
463         
464         System_printf("Core %d: %s creating NameServer object...\n", MultiProc_self(), rmServerName);
465         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
466         if (blockForResponse(&responseInfo))
467         {
468             System_printf("Core %d: %s created NameServer object: %s base: %d length: %d\n", MultiProc_self(),
469                                                                                              rmServerName,
470                                                                                              resourceNsName, 
471                                                                                              requestInfo.resourceBase,
472                                                                                              requestInfo.resourceLength);            
473         }
475         /* Wait for Client Delegate and Client to retrieve resource via the name and allocate it */
476         waitOnSyncObj();
478         Rm_printResourceStatus(rmServerHandle);
480         /* Wait for Client to free resource via the NameServer and delete the NameServer object. */
481         waitOnSyncObj();
483         Rm_printResourceStatus(rmServerHandle);
485         /* Try to allocate the memory region taken by the Linux Kernel */
486         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
487         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
488         requestInfo.resourceName = memRegionName;
489         requestInfo.resourceBase = 12;
490         requestInfo.resourceLength = 1;
491         requestInfo.callback.serviceCallback = testServiceCallback;
492         
493         System_printf("Core %d: %s Trying to reserve memory region taken by Linux...\n", MultiProc_self(), rmServerName);
494         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
495         if (blockForResponse(&responseInfo))
496         {
497             System_printf("Core %d: %s allocated resource (SHOULD NOT HAPPEN): %s base: %d length: %d\n", MultiProc_self(),
498                                                                                                           rmServerName,
499                                                                                                           requestInfo.resourceName, 
500                                                                                                           requestInfo.resourceBase,
501                                                                                                           requestInfo.resourceLength);            
502         }  
504         /* Allocate some resources for testing tree interaction with multiple allocations from different instances */
505         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
506         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
507         requestInfo.resourceName = aifName;
508         requestInfo.resourceBase = 14;
509         requestInfo.resourceLength = 5;
510         requestInfo.callback.serviceCallback = testServiceCallback;
511         
512         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
513         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
514         if (blockForResponse(&responseInfo))
515         {
516             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
517                                                                                       rmServerName,
518                                                                                       requestInfo.resourceName, 
519                                                                                       requestInfo.resourceBase,
520                                                                                       requestInfo.resourceLength);            
521         }    
522         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
523         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
524         requestInfo.resourceName = aifName;
525         requestInfo.resourceBase = 19;
526         requestInfo.resourceLength = 31;
527         requestInfo.callback.serviceCallback = testServiceCallback;
528         
529         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmServerName);
530         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
531         if (blockForResponse(&responseInfo))
532         {
533             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
534                                                                                       rmServerName,
535                                                                                       requestInfo.resourceName, 
536                                                                                       requestInfo.resourceBase,
537                                                                                       requestInfo.resourceLength);            
538         }            
539         
540         /* Wait for Client and Client Delegate to do their allocates */
541         waitOnSyncObj();
543         Rm_printResourceStatus(rmServerHandle);        
545         /* Free resources to show tree handling of different frees */
546         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
547         requestInfo.type = Rm_service_RESOURCE_FREE;
548         requestInfo.resourceName = aifName;
549         requestInfo.resourceBase = 25;
550         requestInfo.resourceLength = 3;
551         requestInfo.callback.serviceCallback = testServiceCallback;
552         
553         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
554         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
555         if (blockForResponse(&responseInfo))
556         {
557             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
558                                                                                       rmServerName,
559                                                                                       requestInfo.resourceName, 
560                                                                                       requestInfo.resourceBase,
561                                                                                       requestInfo.resourceLength);            
562         }            
563         
564         Rm_printResourceStatus(rmServerHandle);   
565         
566         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
567         requestInfo.type = Rm_service_RESOURCE_FREE;
568         requestInfo.resourceName = aifName;
569         requestInfo.resourceBase = 34;
570         requestInfo.resourceLength = 3;
571         requestInfo.callback.serviceCallback = testServiceCallback;
572         
573         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
574         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
575         if (blockForResponse(&responseInfo))
576         {
577             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
578                                                                                       rmServerName,
579                                                                                       requestInfo.resourceName, 
580                                                                                       requestInfo.resourceBase,
581                                                                                       requestInfo.resourceLength);            
582         }            
583         
584         Rm_printResourceStatus(rmServerHandle);           
585      
586         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
587         requestInfo.type = Rm_service_RESOURCE_FREE;
588         requestInfo.resourceName = aifName;
589         requestInfo.resourceBase = 28;
590         requestInfo.resourceLength = 6;
591         requestInfo.callback.serviceCallback = testServiceCallback;
592         
593         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
594         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
595         if (blockForResponse(&responseInfo))
596         {
597             System_printf("Core %d: %s freed resource: %s base: %d length: %d\n", MultiProc_self(),
598                                                                                       rmServerName,
599                                                                                       requestInfo.resourceName, 
600                                                                                       requestInfo.resourceBase,
601                                                                                       requestInfo.resourceLength);            
602         }            
603         
604         Rm_printResourceStatus(rmServerHandle);     
606         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
607         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
608         requestInfo.resourceName = aifName;
609         requestInfo.resourceBase = 53;
610         requestInfo.resourceLength = 2;
611         requestInfo.callback.serviceCallback = testServiceCallback;
612         
613         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
614         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
615         if (blockForResponse(&responseInfo))
616         {
617             System_printf("Core %d: %s allocate resource: %s base: %d length: %d\n", MultiProc_self(),
618                                                                                       rmServerName,
619                                                                                       requestInfo.resourceName, 
620                                                                                       requestInfo.resourceBase,
621                                                                                       requestInfo.resourceLength);            
622         }    
623         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
624         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
625         requestInfo.resourceName = aifName;
626         requestInfo.resourceBase = 2;
627         requestInfo.resourceLength = 2;
628         requestInfo.callback.serviceCallback = testServiceCallback;
629         
630         System_printf("Core %d: %s freeing resource...\n", MultiProc_self(), rmServerName);
631         rmServerServiceHandle->Rm_serviceHandler(rmServerServiceHandle->rmHandle, &requestInfo, &responseInfo);
632         if (blockForResponse(&responseInfo))
633         {
634             System_printf("Core %d: %s allocate resource: %s base: %d length: %d\n", MultiProc_self(),
635                                                                                       rmServerName,
636                                                                                       requestInfo.resourceName, 
637                                                                                       requestInfo.resourceBase,
638                                                                                       requestInfo.resourceLength);            
639         }           
640         
641         Rm_printResourceStatus(rmServerHandle); 
643         /* Wait for Client and Client Delegate to do their UNSPECIFIED allocates */
644         waitOnSyncObj();
646         Rm_printResourceStatus(rmServerHandle);      
647         
648     }
649     else if (MultiProc_self() == 1)
650     {    
651         char resourceNsName[RM_NAME_MAX_CHARS] = "My_Favorite_Queue";
653         char aifName[RM_NAME_MAX_CHARS] = "aif-rx-ch";    
654         char accumChName[RM_NAME_MAX_CHARS] = "accumulator-ch";
656         /* Issue the service request for the resources tied to the name via the service port */                
657         requestInfo.type = Rm_service_RESOURCE_GET_BY_NAME;
658         requestInfo.resourceNsName = resourceNsName;
659         requestInfo.callback.serviceCallback = testServiceCallback;
660         
661         System_printf("Core %d: %s getting resources tied to NameServer object...\n", MultiProc_self(), 
662                                                                                       rmClientDelegateName);
663         rmClientDelegateServiceHandle->Rm_serviceHandler(rmClientDelegateServiceHandle->rmHandle, &requestInfo, &responseInfo);
664         if (blockForResponse(&responseInfo))
665         {
666             System_printf("Core %d: %s got Name: %s base: %d length: %d\n", MultiProc_self(),
667                                                                             rmClientDelegateName, 
668                                                                             resourceNsName, 
669                                                                             responseInfo.resourceBase,
670                                                                             responseInfo.resourceLength);
671         }
673         /* Allocate the resources via the service port from the Client */
674         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
675         requestInfo.resourceName = responseInfo.resourceName;
676         requestInfo.resourceBase = responseInfo.resourceBase;
677         requestInfo.resourceLength = responseInfo.resourceLength;
678         requestInfo.resourceNsName = NULL;
679         requestInfo.callback.serviceCallback = testServiceCallback;
680         
681         System_printf("Core %d: %s allocating resources...\n", MultiProc_self(), rmClientName);
682         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
683         if (blockForResponse(&responseInfo))
684         {
685             System_printf("Core %d: %s allocated resources: %s base: %d length: %d\n", MultiProc_self(),
686                                                                                        rmClientName, 
687                                                                                        resourceNsName, 
688                                                                                        responseInfo.resourceBase,
689                                                                                        responseInfo.resourceLength);
690         }
692         /* Release the syncObj so Server can print results of NameServer object add and resource allocate */
693         releaseSyncObj();
695         /* Take the syncObj to free the name resource via the name, rather than the base+length */
696         takeSyncObj();
698         /* Free the named resource using the name via the service port from the Client */
699         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));
700         requestInfo.type = Rm_service_RESOURCE_FREE;
701         requestInfo.resourceNsName = resourceNsName;
702         requestInfo.callback.serviceCallback = testServiceCallback;
703         
704         System_printf("Core %d: %s freeing resource via name...\n", MultiProc_self(), rmClientName);
705         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
706         if (blockForResponse(&responseInfo))
707         {
708             System_printf("Core %d: %s freed resource with name: %s\n", MultiProc_self(),
709                                                                         rmClientName, 
710                                                                         resourceNsName);
711         }
713         /* Delete the name object from the NameServer */
714         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));
715         requestInfo.type = Rm_service_RESOURCE_UNMAP_NAME;
716         requestInfo.resourceNsName = resourceNsName;
717         requestInfo.callback.serviceCallback = testServiceCallback;
718         
719         System_printf("Core %d: %s Deleting NameServer object: %s...\n", MultiProc_self(), 
720                                                                          rmClientName,
721                                                                          resourceNsName);
722         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
723         if (blockForResponse(&responseInfo))
724         {
725             System_printf("Core %d: %s deleted NameServer object: %s\n", MultiProc_self(),
726                                                                          rmClientName, 
727                                                                          resourceNsName);
728         }
730         /* Release the syncObj so Server can print results of resource free and NameServer object delete. */
731         releaseSyncObj();   
733         /* Take the syncObj to allocate resources for testing resource tree interactions. */
734         takeSyncObj();
736         /* Allocate some resources for testing tree interaction with multiple allocations from different instances */
737         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
738         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
739         requestInfo.resourceName = aifName;
740         requestInfo.resourceBase = 0;
741         requestInfo.resourceLength = 6;
742         requestInfo.callback.serviceCallback = testServiceCallback;
743         
744         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
745         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
746         if (blockForResponse(&responseInfo))
747         {
748             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
749                                                                                       rmClientName,
750                                                                                       requestInfo.resourceName, 
751                                                                                       requestInfo.resourceBase,
752                                                                                       requestInfo.resourceLength);            
753         }     
754         
755         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
756         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_INIT;
757         requestInfo.resourceName = aifName;
758         requestInfo.resourceBase = 50;
759         requestInfo.resourceLength = 7;
760         requestInfo.callback.serviceCallback = testServiceCallback;
761         
762         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientDelegateName);
763         rmClientDelegateServiceHandle->Rm_serviceHandler(rmClientDelegateServiceHandle->rmHandle, &requestInfo, &responseInfo);
764         if (blockForResponse(&responseInfo))
765         {
766             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
767                                                                                       rmClientDelegateName,
768                                                                                       requestInfo.resourceName, 
769                                                                                       requestInfo.resourceBase,
770                                                                                       requestInfo.resourceLength);            
771         }  
773         /* Release the syncObj so Server can print results of resource allocations */
774         releaseSyncObj();    
776         /* Take the syncObj to allocate resources using the UNSPECIFIED parameters. */
777         takeSyncObj();
779         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
780         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
781         requestInfo.resourceName = accumChName;
782         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
783         requestInfo.resourceLength = 5;
784         requestInfo.resourceAlignment = 4;
785         requestInfo.callback.serviceCallback = testServiceCallback;
786         
787         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientDelegateName);
788         rmClientDelegateServiceHandle->Rm_serviceHandler(rmClientDelegateServiceHandle->rmHandle, &requestInfo, &responseInfo);
789         if (blockForResponse(&responseInfo))
790         {
791             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
792                                                                                       rmClientDelegateName,
793                                                                                       responseInfo.resourceName, 
794                                                                                       responseInfo.resourceBase,
795                                                                                       responseInfo.resourceLength);            
796         }    
798         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
799         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
800         requestInfo.resourceName = accumChName;
801         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
802         requestInfo.resourceLength = 2;
803         requestInfo.resourceAlignment = 1;
804         requestInfo.callback.serviceCallback = testServiceCallback;
805         
806         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
807         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
808         if (blockForResponse(&responseInfo))
809         {
810             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
811                                                                                       rmClientName,
812                                                                                       responseInfo.resourceName, 
813                                                                                       responseInfo.resourceBase,
814                                                                                       responseInfo.resourceLength);            
815         }    
817         memset((void *) &requestInfo, 0, sizeof(Rm_ServiceReqInfo));        
818         requestInfo.type = Rm_service_RESOURCE_ALLOCATE_USE;
819         requestInfo.resourceName = accumChName;
820         requestInfo.resourceBase = RM_RESOURCE_BASE_UNSPECIFIED;
821         requestInfo.resourceLength = 2;
822         requestInfo.resourceAlignment = RM_RESOURCE_ALIGNMENT_UNSPECIFIED;
823         requestInfo.callback.serviceCallback = testServiceCallback;
824         
825         System_printf("Core %d: %s Allocating resource...\n", MultiProc_self(), rmClientName);
826         rmClientServiceHandle->Rm_serviceHandler(rmClientServiceHandle->rmHandle, &requestInfo, &responseInfo);
827         if (blockForResponse(&responseInfo))
828         {
829             System_printf("Core %d: %s allocated resource: %s base: %d length: %d\n", MultiProc_self(),
830                                                                                       rmClientName,
831                                                                                       responseInfo.resourceName, 
832                                                                                       responseInfo.resourceBase,
833                                                                                       responseInfo.resourceLength);            
834         }           
836         /* Release the syncObj so Server can print results of resource allocations */
837         releaseSyncObj();           
838     }
840     System_printf("Core %d: Testing is complete\n", MultiProc_self());
841     
842     /* Create the RM cleanup task. */
843     System_printf("Core %d: Creating RM cleanup task...\n", MultiProc_self());
844     Task_Params_init (&taskParams);
845     Task_create (cleanupRmTsk, &taskParams, NULL);
848 /*
849  *  ======== startupRmTsk ========
850  *  Configures application transports and registers them with RM
851  */
852 Void startupRmTsk(UArg arg0, UArg arg1)
854     MessageQ_Handle    serverFromCdMsgQ, cdFromServerMsgQ, cdFromClientMsgQ, clientFromCdMsgQ;
855     MessageQ_QueueId   serverToCdQId, cdToServerQId, cdToClientQId, clientToCdQId;    
856     Int                status, i;
857     HeapBufMP_Handle   msgQHeapHandle;
858     HeapBufMP_Params   heapBufParams;
859     Rm_TransportCfg    rmTransportCfg;
860     int32_t            result = 0;
861     Rm_TransportHandle serverCdHandle, cdServerHandle, cdClientHandle, clientCdHandle;
862     Task_Params        taskParams;
864     if (MultiProc_self() == 1) {
865         /* Take the syncObj on core 1, preparing for RM testing */
866         takeSyncObj();  
867     }
869     /* Initialize the transport map */
870     for (i = 0; i < MAX_MAPPING_ENTRIES; i++) {
871         rmTransportMap[i].transportHandle = NULL;
872     }
874     if (MultiProc_self() == 0) {
875         /* Create the heap that will be used to allocate RM messages. This
876          * heap is a multi-processor heap.  It will be shared amongst
877          * all RM instances. */     
878         HeapBufMP_Params_init(&heapBufParams);
879         heapBufParams.regionId       = 0;
880         heapBufParams.name           = RM_PKT_HEAP_NAME;
881         heapBufParams.numBlocks      = 64;
882         heapBufParams.blockSize      = sizeof(Rm_Packet);
883         rmPktHeapHandle = HeapBufMP_create(&heapBufParams);
884         if (rmPktHeapHandle == NULL) {
885             System_abort("HeapBufMP_create failed for RM packet heap\n" );
886         }
887         System_printf("Core %d: RM packet heap created\n", MultiProc_self());
889         /* Create the heap that will be used to allocate messageQ messages. */     
890         HeapBufMP_Params_init(&heapBufParams);
891         heapBufParams.regionId       = 0;
892         heapBufParams.name           = MSGQ_HEAP_NAME;
893         heapBufParams.numBlocks      = 64;
894         heapBufParams.blockSize      = sizeof(MsgQ_RmPacket);
895         msgQHeapHandle = HeapBufMP_create(&heapBufParams);
896         if (msgQHeapHandle == NULL) {
897             System_abort("HeapBufMP_create failed MessageQ message heap\n" );
898         } 
899         System_printf("Core %d: IPC MessageQ message heap created\n", MultiProc_self());
900     }
901     else {
902         /* Open the heaps created by the other processor. Loop until opened. */
903         do {
904             status = HeapBufMP_open(RM_PKT_HEAP_NAME, &rmPktHeapHandle);
905             /* 
906              *  Sleep for 1 clock tick to avoid inundating remote processor
907              *  with interrupts if open failed
908              */
909             if (status < 0) { 
910                 Task_sleep(1);
911             }
912         } while (status < 0);
913         System_printf("Core %d: RM packet heap opened\n", MultiProc_self());
914         
915         do {
916             status = HeapBufMP_open(MSGQ_HEAP_NAME, &msgQHeapHandle);
917             /* 
918              *  Sleep for 1 clock tick to avoid inundating remote processor
919              *  with interrupts if open failed
920              */
921             if (status < 0) { 
922                 Task_sleep(1);
923             }
924         } while (status < 0);
925         System_printf("Core %d: IPC MessageQ message heap opened\n", MultiProc_self());
926     }
927     
928     /* Register the MessageQ heap with MessageQ */
929     MessageQ_registerHeap((IHeap_Handle)msgQHeapHandle, MSGQ_HEAP_ID);
931     /* Create the messageQ's for each RM instance connection
932      * Need four queues.  Topology will be:
933      * RM Server <---> RM Client Delegate <---> RM Client 
934      * 1 queues on RM Server
935      * 2 queues on RM Client Delegate
936      * 1 queues on RM Client */
937     if (MultiProc_self() == 0) {
938         serverFromCdMsgQ = MessageQ_create(serverFromCdQueueName, NULL);
939         if (serverFromCdMsgQ == NULL) {
940             System_abort("MessageQ_create failed for RM Server - Client Delegate queue\n" );
941         }
942         System_printf("Core %d: RM Server MessageQ created for receiving packets from RM CD\n", MultiProc_self());
943     }
944     else if (MultiProc_self() == 1) {
945         cdFromServerMsgQ = MessageQ_create(cdFromServerQueueName, NULL);
946         if (cdFromServerMsgQ == NULL) {
947             System_abort("MessageQ_create failed for RM Client Delegate - Server queue\n" );
948         }
949         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Server\n", MultiProc_self());
950         
951         cdFromClientMsgQ = MessageQ_create(cdFromClientQueueName, NULL);
952         if (cdFromClientMsgQ == NULL) {
953             System_abort("MessageQ_create failed for RM Client Delegate - Client queue\n" );
954         } 
955         System_printf("Core %d: RM CD MessageQ created for receiving packets from RM Client\n", MultiProc_self());
956         
957         clientFromCdMsgQ = MessageQ_create(clientFromCdQueueName, NULL);
958         if (clientFromCdMsgQ == NULL) 
959         {
960             System_abort("MessageQ_create failed for RM Client - Client Delegate queue\n" );
961         }
962         System_printf("Core %d: RM Client MessageQ created for receiving packets from RM CD\n", MultiProc_self());
963     }
964     
965     /* Open the remote message queues. Also register the RM transports with each RM instance */
966     if (MultiProc_self() == 0) {
967         /* Open the Client Delegate messageQ from the Server */
968         do {
969             status = MessageQ_open(cdFromServerQueueName, &serverToCdQId); 
970             /* 
971              *  Sleep for 1 clock tick to avoid inundating remote processor
972              *  with interrupts if open failed
973              */
974             if (status < 0) { 
975                 Task_sleep(1);
976             }
977         } while (status < 0);
978         System_printf("Core %d: RM CD MessageQ opened from RM Server\n", MultiProc_self());
980         /* Register the Client Delegate with the RM Server Instance */
981         rmTransportCfg.rmHandle = rmServerHandle;
982         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) serverToCdQId;
983         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
984         rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
985         /* Set the callouts as valid for the first transport configuration on Server instance */
986         rmTransportCfg.transportCalloutsValid = true;
987         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
988         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
989         serverCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
991         /* Store the mapping information in the transport map */
992         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].transportHandle = serverCdHandle;
993         rmTransportMap[SERVER_TO_CD_MAP_ENTRY].receiveMsgQ = serverFromCdMsgQ;
994         System_printf("Core %d: Registered RM Server <=> RM CD transport with RM Server instance\n", MultiProc_self());
995     }
996     else if (MultiProc_self() == 1) {
997         /* Open the Server messageQ from the Client Delegate */
998         do {
999             status = MessageQ_open(serverFromCdQueueName, &cdToServerQId); 
1000             /* 
1001              *  Sleep for 1 clock tick to avoid inundating remote processor
1002              *  with interrupts if open failed
1003              */
1004             if (status < 0) { 
1005                 Task_sleep(1);
1006             }
1007         } while (status < 0);
1008         System_printf("Core %d: RM Server MessageQ opened from RM CD\n", MultiProc_self());
1010         /* Register the Server with the RM Client Delegate Instance */
1011         rmTransportCfg.rmHandle = rmClientDelegateHandle;
1012         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToServerQId;
1013         rmTransportCfg.remoteInstType = Rm_instType_SERVER;
1014         rmTransportCfg.remoteInstName = &rmServerName[0];
1015         /* Set the callouts as valid for the first transport configuration on Client Delegate instance */
1017         rmTransportCfg.transportCalloutsValid = true;
1018         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1019         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1020         cdServerHandle = Rm_transportRegister(&rmTransportCfg, &result);
1022         /* Store the mapping information in the transport map */
1023         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].transportHandle = cdServerHandle;
1024         rmTransportMap[CD_TO_SERVER_MAP_ENTRY].receiveMsgQ = cdFromServerMsgQ;
1025         System_printf("Core %d: Registered RM CD <=> RM Server transport with RM CD instance\n", MultiProc_self());
1026         
1027         /* Open the Client messageQ from the Client Delegate */
1028         do {
1029             status = MessageQ_open(clientFromCdQueueName, &cdToClientQId); 
1030             /* 
1031              *  Sleep for 1 clock tick to avoid inundating remote processor
1032              *  with interrupts if open failed
1033              */
1034             if (status < 0) { 
1035                 Task_sleep(1);
1036             }
1037         } while (status < 0);
1038         System_printf("Core %d: RM Client MessageQ opened from RM CD\n", MultiProc_self());
1040         /* Register the Client with the RM Client Delegate Instance */
1041         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) cdToClientQId;
1042         rmTransportCfg.remoteInstType = Rm_instType_CLIENT;
1043         rmTransportCfg.remoteInstName = &rmClientName[0];
1044         /* Callouts already set on the Client Delegate so set them as invalid */
1045         rmTransportCfg.transportCalloutsValid = false;
1046         cdClientHandle = Rm_transportRegister(&rmTransportCfg, &result);
1048         /* Store the mapping information in the transport map */
1049         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].transportHandle = cdClientHandle;
1050         rmTransportMap[CD_TO_CLIENT_MAP_ENTRY].receiveMsgQ = cdFromClientMsgQ;
1051         System_printf("Core %d: Registered RM CD <=> RM Client transport with RM CD instance\n", MultiProc_self());
1053         /* Open the Client Delegate messageQ from the Client */        
1054         do {
1055             status = MessageQ_open(cdFromClientQueueName, &clientToCdQId); 
1056             /* 
1057              *  Sleep for 1 clock tick to avoid inundating remote processor
1058              *  with interrupts if open failed
1059              */
1060             if (status < 0) { 
1061                 Task_sleep(1);
1062             }
1063         } while (status < 0);
1064         System_printf("Core %d: RM CD MessageQ opened from RM Client\n", MultiProc_self());
1066         /* Register the Client Delegate with the RM Client Instance */
1067         rmTransportCfg.rmHandle = rmClientHandle;
1068         rmTransportCfg.appTransportHandle = (Rm_AppTransportHandle) clientToCdQId;
1069         rmTransportCfg.remoteInstType = Rm_instType_CLIENT_DELEGATE;
1070         rmTransportCfg.remoteInstName = &rmClientDelegateName[0];
1071         /* Set the callouts as valid for the first transport configuration on Client instance */
1072         rmTransportCfg.transportCalloutsValid = true;
1073         rmTransportCfg.transportCallouts.rmAllocPkt = transportAlloc;
1074         rmTransportCfg.transportCallouts.rmSendPkt = transportSend;
1075         clientCdHandle = Rm_transportRegister(&rmTransportCfg, &result);
1077         /* Store the mapping information in the transport map */
1078         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].transportHandle = clientCdHandle;
1079         rmTransportMap[CLIENT_TO_CD_MAP_ENTRY].receiveMsgQ = clientFromCdMsgQ;
1080         System_printf("Core %d: Registered RM Client <=> RM CD transport with RM Client instance\n", MultiProc_self());
1081     }
1083     /* Creat the RM receive task. */
1084     System_printf("Core %d: Creating RM receive task...\n", MultiProc_self());
1085     Task_Params_init (&taskParams);
1086     testReceiveTskHandle = Task_create (testReceiveTsk, &taskParams, NULL);
1087     
1088     
1089     /* Create the RM test task. */
1090     System_printf("Core %d: Creating RM test task...\n", MultiProc_self());
1091     Task_Params_init (&taskParams);
1092     testRmTskHandle = Task_create (testRmTsk, &taskParams, NULL);
1095 /*
1096  *  ======== main ========
1097  *  Synchronizes all processors (in Ipc_start) and calls BIOS_start
1098  */
1099 Int main(Int argc, Char* argv[])
1101     Rm_InitCfg   rmInitCfg;
1102     Task_Params  taskParams;
1103     FILE        *globalResourceFp;
1104     FILE        *linuxDtbFp;
1105     FILE        *globalPolicyFp;
1106     Int          globalResourceFileSize;
1107     Int          linuxDtbFileSize;
1108     Int          globalPolicyFileSize;
1109     void        *globalResourceList = NULL;
1110     void        *linuxDtb = NULL;
1111     void        *globalPolicy = NULL;
1112     Int          status;
1113     Int          readSize;
1114     int32_t      result;
1116     System_printf ("*********************************************************\n");
1117     System_printf ("********************** RM Testing ***********************\n");
1118     System_printf ("*********************************************************\n");
1120     System_printf ("RM Version : 0x%08x\nVersion String: %s\n", Rm_getVersion(), Rm_getVersionStr());
1122     /* Initialize the RM instances - RM must be initialized before anything else in the system
1123      * Core 0: 1 RM Instance - RM Server
1124      * Core 1: 2 RM Instances - RM Client Delegate
1125      *                          RM Client
1126      */
1127     if (MultiProc_self()== 0) {
1128         initSyncObj();
1129         
1130         globalResourceFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-global-resources.dtb", "rb");
1131         linuxDtbFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-linux-evm.dtb", "rb");
1132         globalPolicyFp = fopen("C:\\ti\\pdk_tci6614_1_0_0_11\\packages\\ti\\drv\\rm\\device\\tci6614-server-policy.dtb", "rb");
1134         fseek(globalResourceFp, 0, SEEK_END);
1135         globalResourceFileSize = ftell(globalResourceFp);
1136         rewind(globalResourceFp);
1138         fseek(linuxDtbFp, 0, SEEK_END);
1139         linuxDtbFileSize = ftell(linuxDtbFp);
1140         rewind(linuxDtbFp);
1142         fseek(globalPolicyFp, 0, SEEK_END);
1143         globalPolicyFileSize = ftell(globalPolicyFp);
1144         rewind(globalPolicyFp);      
1146         globalResourceList = Osal_rmMalloc(globalResourceFileSize);
1147         linuxDtb = Osal_rmMalloc(linuxDtbFileSize);
1148         globalPolicy = Osal_rmMalloc(globalPolicyFileSize);
1150         readSize = fread(globalResourceList, 1, globalResourceFileSize, globalResourceFp);
1151         System_printf("Read Size compared to file size: %d : %d\n", readSize, globalResourceFileSize);
1152         readSize = fread(linuxDtb, 1, linuxDtbFileSize, linuxDtbFp);
1153         System_printf("Read Size compared to file size: %d : %d\n", readSize, linuxDtbFileSize);        
1154         readSize = fread(globalPolicy, 1, globalPolicyFileSize, globalPolicyFp);
1155         System_printf("Read Size compared to file size: %d : %d\n", readSize, globalPolicyFileSize);
1157         /* Create the Server instance */
1158         rmInitCfg.instName = &rmServerName[0];
1159         rmInitCfg.instType = Rm_instType_SERVER;
1160         rmInitCfg.globalResourceList = globalResourceList;
1161         rmInitCfg.linuxDtb = linuxDtb;
1162         rmInitCfg.policy = globalPolicy;
1163         rmServerHandle = Rm_init(&rmInitCfg, &result);
1164         System_printf("Core %d: RM Server instance created. Result = %d\n", MultiProc_self(), result);
1166         Rm_printResourceStatus(rmServerHandle);
1167     }
1168     else if (MultiProc_self()== 1) {
1169         /* Create the RM Client Delegate instance */
1170         rmInitCfg.instName = &rmClientDelegateName[0];
1171         rmInitCfg.instType = Rm_instType_CLIENT_DELEGATE;
1172         rmInitCfg.globalResourceList = NULL;
1173         rmInitCfg.linuxDtb = NULL;
1174         rmInitCfg.policy = NULL;
1175         rmClientDelegateHandle = Rm_init(&rmInitCfg, &result);
1176         System_printf("Core %d: RM Client Delegate instance created. Result = %d\n", MultiProc_self(), result);
1178         /* Create the RM Client instance */
1179         rmInitCfg.instName = &rmClientName[0];
1180         rmInitCfg.instType = Rm_instType_CLIENT;
1181         rmInitCfg.globalResourceList = NULL;
1182         rmInitCfg.linuxDtb = NULL;        
1183         rmInitCfg.policy = NULL;
1184         rmClientHandle = Rm_init(&rmInitCfg, &result);
1185         System_printf("Core %d: RM Client instance created. Result = %d\n", MultiProc_self(), result);
1186     }
1188     System_printf("Core %d: Starting IPC...\n", MultiProc_self());
1189     status = Ipc_start();
1190     if (status < 0) {
1191         System_abort("Ipc_start failed\n");
1192     }
1194     /* Create the RM startup task */
1195     System_printf("Core %d: Creating RM startup task...\n", MultiProc_self());
1196     Task_Params_init (&taskParams);
1197     startupRmTskHandle = Task_create (startupRmTsk, &taskParams, NULL);
1199     System_printf("Core %d: Starting BIOS...\n", MultiProc_self());
1200     BIOS_start();
1202     return (0);