]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - packages/ti/srvmgr/omaprpc/OmapRpc.c
Support in QNX MmRpc/MmServiceMgr to identify deleted instance during cleanup
[ipc/ipcdev.git] / packages / ti / srvmgr / omaprpc / OmapRpc.c
index 7035173d58454d7f09190e2a8b419dcd87ee268d..65c585accfee43cb08664246df0d875b5f46fb40 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2014, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include <ti/grcm/RcmTypes.h>
 #include <ti/grcm/RcmServer.h>
 
-#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-#include <ti/ipc/rpmsg/MessageQCopy.h>
+#include <ti/ipc/mm/MmType.h>
+#include <ti/ipc/rpmsg/RPMessage.h>
 #include <ti/ipc/rpmsg/NameMap.h>
 #include <ti/srvmgr/ServiceMgr.h>
 
 #include "OmapRpc.h"
 
 typedef struct OmapRpc_Object {
-    Char                    channelName[OMAPRPC_MAX_CHANNEL_NAMELEN];
-    UInt16                  dstProc;
-    UInt32                  port;
-    MessageQCopy_Handle     msgq;
-    UInt32                  localEndPt;
-    Task_Handle             taskHandle;
-    Bool                    shutdown;
-    Semaphore_Handle        exitSem;
-    OmapRpc_SrvDelNotifyFxn srvDelCB;
-    RcmServer_Params        rcmParams;
-    UInt32                  numFuncs;
-    OmapRpc_FuncSignature  *funcSigs;
+    Char                     channelName[OMAPRPC_MAX_CHANNEL_NAMELEN];
+    UInt16                   dstProc;
+    UInt32                   port;
+    RPMessage_Handle         msgq;
+    UInt32                   localEndPt;
+    Task_Handle              taskHandle;
+    Bool                     shutdown;
+    Semaphore_Handle         exitSem;
+    OmapRpc_SrvDelNotifyFxn  srvDelCB;
+    OmapRpc_SrvDelNotifyFxn2 srvDelCB2;
+    RcmServer_Params         rcmParams;
+    UInt32                   numFuncs;
+    OmapRpc_FuncSignature   *funcSigs;
 } OmapRpc_Object;
 
-static Int32 OmapRpc_GetSvrMgrHandle(Void *srvc, Int32 num, Int32 *params)
+static OmapRpc_Handle _OmapRpc_createChannel(String channelName, UInt16 dstProc,
+        UInt32 port, RcmServer_Params *rcmParams, MmType_FxnSigTab *fxnSigTab);
+
+Int32 OmapRpc_GetSvrMgrHandle(Void *srvc, Int32 num, Int32 *params)
 {
     System_printf("OMAPRPC: Calling RCM Service Manager Create Function!\n");
     return 0;
@@ -80,9 +84,18 @@ static Void omapRpcTask(UArg arg0, UArg arg1)
     UInt32 remote;
     Int status;
     UInt16 len;
-    UInt8  msg[512]; /* maximum rpmsg size is probably smaller, but we need to
-                      * be cautious */
-    OmapRpc_MsgHeader *hdr = (OmapRpc_MsgHeader *)&msg[0];
+    Char  * msg = NULL;
+    OmapRpc_MsgHeader *hdr = NULL;
+
+    msg = Memory_alloc(NULL, 512, 0, NULL); /* maximum rpmsg size is probably
+                                             * smaller, but we need to
+                                             * be cautious */
+    if (msg == NULL) {
+        System_printf("OMAPRPC: Failed to allocate msg!\n");
+        return;
+    }
+
+    hdr = (OmapRpc_MsgHeader *)&msg[0];
 
     if (obj == NULL) {
         System_printf("OMAPRPC: Failed to start task as arguments are NULL!\n");
@@ -111,10 +124,10 @@ static Void omapRpcTask(UArg arg0, UArg arg1)
         remote = 0;
 
         /* receive the message */
-        status = MessageQCopy_recv(obj->msgq, (Ptr)msg, &len, &remote,
-                                        MessageQCopy_FOREVER);
+        status = RPMessage_recv(obj->msgq, (Ptr)msg, &len, &remote,
+                                        RPMessage_FOREVER);
 
-        if (status == MessageQCopy_E_UNBLOCKED) {
+        if (status == RPMessage_E_UNBLOCKED) {
             System_printf("OMAPRPC: unblocked while waiting for messages\n");
             continue;
         }
@@ -158,6 +171,9 @@ static Void omapRpcTask(UArg arg0, UArg arg1)
                 if (obj->srvDelCB != NULL) {
                     obj->srvDelCB();
                 }
+                else if (obj->srvDelCB2 != NULL) {
+                    obj->srvDelCB2(handle->endpointAddress);
+                }
 
                 /* don't clear out the old data... */
                 System_printf("OMAPRPC: destroying instance addr: %d\n",
@@ -234,110 +250,183 @@ static Void omapRpcTask(UArg arg0, UArg arg1)
                       " from: %d len: %u\n", hdr->msgType, remote, local, len);
 
        /* send the response. All messages get responses! */
-       MessageQCopy_send(obj->dstProc, remote, local, msg, len);
+       RPMessage_send(obj->dstProc, remote, local, msg, len);
     }
 
     System_printf("OMAPRPC: destroying channel on port: %d\n", obj->port);
     NameMap_unregister("rpmsg-rpc", obj->channelName, obj->port);
+    if (msg != NULL) {
+       Memory_free(NULL, msg, 512);
+    }
     /* @TODO delete any outstanding ServiceMgr instances if no disconnect
      * was issued? */
 
     Semaphore_post(obj->exitSem);
 }
 
-OmapRpc_Handle OmapRpc_createChannel(String channelName,
-                                     UInt16 dstProc,
-                                     UInt32 port,
-                                     UInt32 numFuncs,
-                                     OmapRpc_FuncDeclaration *fxns,
-                                     OmapRpc_SrvDelNotifyFxn srvDelCBFunc)
+/*
+ *  ======== OmapRpc_createChannel ========
+ */
+OmapRpc_Handle OmapRpc_createChannel(String channelName, UInt16 dstProc,
+        UInt32 port, RcmServer_Params *rcmParams, MmType_FxnSigTab *fxnSigTab,
+        OmapRpc_SrvDelNotifyFxn srvDelCBFunc)
+{
+    OmapRpc_Object * obj;
+
+    obj = _OmapRpc_createChannel(channelName, dstProc, port, rcmParams,
+        fxnSigTab);
+    if (obj != NULL) {
+        obj->srvDelCB = srvDelCBFunc;
+    }
+
+    return (obj);
+}
+
+/*
+ *  ======== OmapRpc_createChannel2 ========
+ */
+OmapRpc_Handle OmapRpc_createChannel2(String channelName, UInt16 dstProc,
+        UInt32 port, RcmServer_Params *rcmParams, MmType_FxnSigTab *fxnSigTab,
+        OmapRpc_SrvDelNotifyFxn2 srvDelCBFunc2)
 {
-    Task_Params          taskParams;
-    UInt32               func;
+    OmapRpc_Object * obj;
+
+    obj = _OmapRpc_createChannel(channelName, dstProc, port, rcmParams,
+        fxnSigTab);
+    if (obj != NULL) {
+        obj->srvDelCB2 = srvDelCBFunc2;
+    }
+
+    return (obj);
+}
+
+
+/*
+ *  ======== _OmapRpc_createChannel ========
+ */
+static OmapRpc_Handle _OmapRpc_createChannel(String channelName, UInt16 dstProc,
+        UInt32 port, RcmServer_Params *rcmParams, MmType_FxnSigTab *fxnSigTab)
+{
+    Task_Params taskParams;
+    UInt32      func;
 
     OmapRpc_Object *obj = Memory_alloc(NULL, sizeof(OmapRpc_Object), 0, NULL);
+
     if (obj == NULL) {
         System_printf("OMAPRPC: Failed to allocate memory for object!\n");
         goto unload;
     }
     _memset(obj, 0, sizeof(OmapRpc_Object));
-    obj->numFuncs = numFuncs+1;
+    obj->numFuncs = fxnSigTab->count + 1;
+#if 0
     RcmServer_Params_init(&obj->rcmParams);
     obj->rcmParams.priority = Thread_Priority_ABOVE_NORMAL;
+    obj->rcmParams.stackSize = 0x1000;
+    obj->rcmParams.fxns.length = obj->numFuncs;
+    obj->rcmParams.fxns.elem = Memory_alloc(NULL,
+            sizeof(RcmServer_FxnDesc) * obj->numFuncs, 0, NULL);
+
+    if (obj->rcmParams.fxns.elem == NULL) {
+        System_printf("OMAPRPC: Failed to allocate RCM function list!\n");
+        goto unload;
+    }
+#else
+    memcpy(&obj->rcmParams, rcmParams, sizeof(RcmServer_Params));
     obj->rcmParams.fxns.length = obj->numFuncs;
-    obj->rcmParams.fxns.elem = Memory_alloc(NULL, sizeof(RcmServer_FxnDesc)*obj->numFuncs, 0, NULL);
+    obj->rcmParams.fxns.elem = Memory_calloc(NULL, obj->numFuncs *
+            sizeof(RcmServer_FxnDesc), 0, NULL);
+
     if (obj->rcmParams.fxns.elem == NULL) {
         System_printf("OMAPRPC: Failed to allocate RCM function list!\n");
         goto unload;
     }
-    // setup other variables...
+#endif
+
+    /* setup other variables... */
     obj->shutdown = FALSE;
     obj->dstProc = dstProc;
     obj->port = port;
     strncpy(obj->channelName, channelName, OMAPRPC_MAX_CHANNEL_NAMELEN-1);
     obj->channelName[OMAPRPC_MAX_CHANNEL_NAMELEN-1]='\0';
-    obj->srvDelCB = srvDelCBFunc;
-    obj->funcSigs = Memory_alloc(NULL, sizeof(OmapRpc_FuncSignature)*obj->numFuncs, 0, NULL);
+    obj->funcSigs = Memory_alloc(NULL, obj->numFuncs *
+            sizeof(OmapRpc_FuncSignature), 0, NULL);
+
     if (obj->funcSigs == NULL) {
         System_printf("OMAPRPC: Failed to allocate signtures list!\n");
         goto unload;
     }
-    // setup the RCM functions and Signatures
-    for (func = 0; func < obj->numFuncs; func++)
-    {
-        if (func == 0)
-        {
-            // assign the "first function"
-            obj->rcmParams.fxns.elem[func].name = OmapRpc_Stringerize(OmapRpc_GetSvrMgrHandle);
-            obj->rcmParams.fxns.elem[func].addr.createFxn = (RcmServer_MsgCreateFxn)OmapRpc_GetSvrMgrHandle;
 
-            strncpy(obj->funcSigs[func].name,
-                    obj->rcmParams.fxns.elem[0].name,
+    /* setup the RCM functions and Signatures */
+    for (func = 0; func < obj->numFuncs; func++) {
+        if (func == 0) {
+            /* assign the "first function" */
+            obj->rcmParams.fxns.elem[func].name =
+                    OmapRpc_Stringerize(OmapRpc_GetSvrMgrHandle);
+            obj->rcmParams.fxns.elem[func].addr.createFxn =
+                    (RcmServer_MsgCreateFxn)OmapRpc_GetSvrMgrHandle;
+
+            strncpy(obj->funcSigs[func].name, obj->rcmParams.fxns.elem[0].name,
                     OMAPRPC_MAX_CHANNEL_NAMELEN);
             obj->funcSigs[func].numParam = 0;
         }
-        else
-        {
-            // assign the other functions
-            obj->rcmParams.fxns.elem[func].name = fxns[func-1].signature.name;
-            obj->rcmParams.fxns.elem[func].addr.fxn = (RcmServer_MsgFxn)fxns[func-1].function;
-
-            // copy the signature
-            memcpy(&obj->funcSigs[func],
-                   &fxns[func-1].signature,
-                   sizeof(OmapRpc_FuncSignature));
+        else {
+            /* assign the other functions */
+/*          obj->rcmParams.fxns.elem[func].name = fxns[func-1].signature.name; */
+            obj->rcmParams.fxns.elem[func].name =
+                    rcmParams->fxns.elem[func-1].name;
+/*          obj->rcmParams.fxns.elem[func].addr.fxn =
+                    (RcmServer_MsgFxn)fxns[func-1].function; */
+            obj->rcmParams.fxns.elem[func].addr.fxn =
+                    rcmParams->fxns.elem[func-1].addr.fxn;
+
+            /* copy the signature */
+/*          memcpy(&obj->funcSigs[func], &fxns[func-1].signature,
+                    sizeof(OmapRpc_FuncSignature)); */
+            memcpy(&obj->funcSigs[func], &fxnSigTab->table[func - 1],
+                    sizeof(MmType_FxnSig));
         }
     }
 
     ServiceMgr_init();
+
     if (ServiceMgr_register(channelName, &obj->rcmParams) == TRUE) {
         System_printf("OMAPRPC: registered channel: %s\n", obj->channelName);
-        obj->msgq = MessageQCopy_create(obj->port, NULL, NULL,&obj->localEndPt);
+
+        obj->msgq = RPMessage_create(obj->port, NULL, NULL,&obj->localEndPt);
+
         if (obj->msgq == NULL) {
             goto unload;
         }
+
         Task_Params_init(&taskParams);
         taskParams.instance->name = channelName;
-        taskParams.priority = 1;   /* Lowest priority thread */
+        taskParams.stackSize = 0x2000; /* must cover all proxy stack usage */
+        taskParams.priority = 1;   /* lowest priority thread */
         taskParams.arg0 = (UArg)obj;
+
         obj->exitSem = Semaphore_create(0, NULL, NULL);
+
         if (obj->exitSem == NULL) {
             goto unload;
         }
+
         obj->taskHandle = Task_create(omapRpcTask, &taskParams, NULL);
+
         if (obj->taskHandle == NULL) {
             goto unload;
         }
     }
     else {
         System_printf("OMAPRPC: FAILED to register channel: %s\n",
-                                                            obj->channelName);
+                obj->channelName);
     }
+
     System_printf("OMAPRPC: Returning Object %p\n", obj);
-    return obj;
+    return(obj);
+
 unload:
     OmapRpc_deleteChannel(obj);
-    return NULL;
+    return(NULL);
 }
 
 Int OmapRpc_deleteChannel(OmapRpc_Handle handle)
@@ -351,10 +440,10 @@ Int OmapRpc_deleteChannel(OmapRpc_Handle handle)
     System_printf("OMAPRPC: deleting channel %s\n", obj->channelName);
     obj->shutdown = TRUE;
     if (obj->msgq) {
-        MessageQCopy_unblock(obj->msgq);
+        RPMessage_unblock(obj->msgq);
         if (obj->exitSem) {
             Semaphore_pend(obj->exitSem, BIOS_WAIT_FOREVER);
-            MessageQCopy_delete(&obj->msgq);
+            RPMessage_delete(&obj->msgq);
             Semaphore_delete(&obj->exitSem);
         }
         if (obj->taskHandle) {
@@ -370,3 +459,90 @@ Int OmapRpc_deleteChannel(OmapRpc_Handle handle)
     Memory_free(NULL, obj, sizeof(*obj));
     return OmapRpc_S_SUCCESS;
 }
+
+#if 0
+/*
+ *  ======== OmapRpc_start ========
+ */
+Int OmapRpc_start(const String name, Int port, Int aryLen,
+        OmapRpc_FuncSignature *sigAry)
+{
+    Int status = OmapRpc_S_SUCCESS;
+    Task_Params taskParams;
+    OmapRpc_Object *obj;
+
+    /* create an instance */
+    obj = Memory_calloc(NULL, sizeof(OmapRpc_Object), 0, NULL);
+
+    if (obj == NULL) {
+        System_printf("OMAPRPC: Failed to allocate memory for object!\n");
+        status = OmapRpc_E_FAIL;
+        goto leave;
+    }
+
+    obj->numFuncs = aryLen + 1;
+    obj->shutdown = FALSE;
+    obj->dstProc = MultiProc_getId("HOST");
+    obj->port = port;
+    strncpy(obj->channelName, name, OMAPRPC_MAX_CHANNEL_NAMELEN-1);
+    obj->channelName[OMAPRPC_MAX_CHANNEL_NAMELEN-1]='\0';
+    obj->srvDelCB = srvDelCBFunc;
+    obj->funcSigs = Memory_alloc(NULL,
+            sizeof(OmapRpc_FuncSignature) * obj->numFuncs, 0, NULL);
+
+    if (obj->funcSigs == NULL) {
+        System_printf("OMAPRPC: Failed to allocate signtures list!\n");
+        goto unload;
+    }
+
+    /* setup the functions and signatures */
+    for (func = 0; func < obj->numFuncs; func++) {
+        if (func == 0) {
+            /* assign the "first function" */
+/*          strncpy(obj->funcSigs[func].name, obj->rcmParams.fxns.elem[0].name,
+                    OMAPRPC_MAX_CHANNEL_NAMELEN); */
+            strncpy(obj->funcSigs[func].name,
+                    OmapRpc_Stringerize(OmapRpc_GetSvrMgrHandle),
+                    OMAPRPC_MAX_CHANNEL_NAMELEN);
+            obj->funcSigs[func].numParam = 0;
+        }
+        else {
+            /* copy the signature */
+            memcpy(&obj->funcSigs[func], &fxns[func-1].signature,
+                    sizeof(OmapRpc_FuncSignature));
+        }
+    }
+
+    obj->msgq = RPMessage_create(obj->port, NULL, NULL,&obj->localEndPt);
+
+    if (obj->msgq == NULL) {
+        goto unload;
+    }
+
+    Task_Params_init(&taskParams);
+    taskParams.instance->name = channelName;
+    taskParams.priority = 1;   /* Lowest priority thread */
+    taskParams.arg0 = (UArg)obj;
+
+    obj->exitSem = Semaphore_create(0, NULL, NULL);
+
+    if (obj->exitSem == NULL) {
+        goto unload;
+    }
+
+    obj->taskHandle = Task_create(omapRpcTask, &taskParams, NULL);
+
+    if (obj->taskHandle == NULL) {
+        goto unload;
+    }
+
+    System_printf("OMAPRPC: Returning Object %p\n", obj);
+    return(obj);
+
+leave:
+    if (status < 0) {
+        OmapRpc_deleteChannel(obj);
+    }
+    return(status);
+}
+#endif