]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - packages/ti/ipc/mm/MmRpc.c
Support in QNX MmRpc/MmServiceMgr to identify deleted instance during cleanup
[ipc/ipcdev.git] / packages / ti / ipc / mm / MmRpc.c
index 52ba15d6ab0541210c17ddb1b65b5399d4db95f5..9474875cd14c3cc1efb940df3c3834a3be6d13c0 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
 #undef _linux_
 #endif
 
-#define RPPC_MAX_INST_NAMELEN (48) /* in kernel part of rpmsg_rpc.h */
-
-/* this should be in rpmsg_rpc.h, currently in rpmsg_rpc_internal.h */
-struct rppc_create_instance {
-    char name[RPPC_MAX_INST_NAMELEN];
-};
-
 #elif defined(SYSLINK_BUILDOS_QNX)
 
 #include <ti/ipc/rpmsg_rpc.h>
 
+#elif defined(IPC_BUILDOS_ANDROID)
+#include <linux/rpmsg_rpc.h>
+
 #else
 #error Unsupported Operating System
 #endif
 
 #include "MmRpc.h"
 
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+static int MmRpc_bufHandle(MmRpc_Handle handle, int cmd, int num,
+        MmRpc_BufDesc *desc);
+#endif
+
 
 /*
  *  ======== MmRpc_Object ========
@@ -118,7 +119,7 @@ int MmRpc_create(const char *service, const MmRpc_Params *params,
     obj->fd = open(cbuf, O_RDWR);
 
     if (obj->fd < 0) {
-        printf("MmRpc_create: Error: open failed\n");
+        printf("MmRpc_create: Error: open failed, name=%s\n", cbuf);
         status = MmRpc_E_FAIL;
         goto leave;
     }
@@ -188,9 +189,7 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
     int len;
     int i;
 
-    /* Combine function parameters and translation array into one contiguous
-     * message. TODO, modify driver to accept two separate buffers in order
-     * to eliminate this step. */
+    /* combine params and translation array into one contiguous message */
     len = sizeof(struct rppc_function) +
                 (ctx->num_xlts * sizeof(struct rppc_param_translation));
     msg = (void *)calloc(len, sizeof(char));
@@ -215,7 +214,7 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
                 rpfxn->params[i].size = param->param.scalar.size;
                 rpfxn->params[i].data = param->param.scalar.data;
                 rpfxn->params[i].base = 0;
-                rpfxn->params[i].reserved = 0;
+                rpfxn->params[i].fd = 0;
                 break;
 
             case MmRpc_ParamType_Ptr:
@@ -223,18 +222,18 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
                 rpfxn->params[i].size = param->param.ptr.size;
                 rpfxn->params[i].data = param->param.ptr.addr;
                 rpfxn->params[i].base = param->param.ptr.addr;
-                rpfxn->params[i].reserved = param->param.ptr.handle;
+                rpfxn->params[i].fd = param->param.ptr.handle;
                 break;
 
-#if 0 /* TBD */
-            case MmRpc_ParamType_Elem:
+            case MmRpc_ParamType_OffPtr:
                 rpfxn->params[i].type = RPPC_PARAM_TYPE_PTR;
-                rpfxn->params[i].size = param->param.elem.size;
-                rpfxn->params[i].data = param->param.elem.offset;
-                rpfxn->params[i].base = param->param.elem.base;
-                rpfxn->params[i].reserved = param->param.elem.handle;
+                rpfxn->params[i].size = param->param.offPtr.size;
+                rpfxn->params[i].data = param->param.offPtr.base +
+                        param->param.offPtr.offset;
+                rpfxn->params[i].base = param->param.offPtr.base;
+                rpfxn->params[i].fd = param->param.offPtr.handle;
                 break;
-#endif
+
             default:
                 printf("MmRpc_call: Error: invalid parameter type\n");
                 status = MmRpc_E_INVALIDPARAM;
@@ -247,10 +246,11 @@ int MmRpc_call(MmRpc_Handle handle, MmRpc_FxnCtx *ctx, int32_t *ret)
     rpfxn->num_translations = ctx->num_xlts;
 
     for (i = 0; i < ctx->num_xlts; i++) {
-        rpfxn->translations[i].index    = ctx->xltAry[i].index;
-        rpfxn->translations[i].offset   = ctx->xltAry[i].offset;
-        rpfxn->translations[i].base     = ctx->xltAry[i].base;
-        rpfxn->translations[i].reserved = ctx->xltAry[i].handle;
+        /* pack the pointer translation entry */
+        rpfxn->translations[i].index = ctx->xltAry[i].index;
+        rpfxn->translations[i].offset = ctx->xltAry[i].offset;
+        rpfxn->translations[i].base = ctx->xltAry[i].base;
+        rpfxn->translations[i].fd = (int32_t)ctx->xltAry[i].handle;
     }
 
     /* send message for remote execution */
@@ -289,3 +289,116 @@ leave:
 
     return(status);
 }
+
+/*
+ *  ======== MmRcp_release ========
+ */
+int MmRpc_release(MmRpc_Handle handle, MmRpc_BufType type, int num,
+        MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+
+    switch (type) {
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+        case MmRpc_BufType_Handle:
+            stat = MmRpc_bufHandle(handle, RPPC_IOC_BUFUNREGISTER, num, desc);
+            break;
+
+#elif defined(SYSLINK_BUILDOS_QNX)
+        case MmRpc_BufType_Ptr:
+            break;
+#endif
+        default:
+            printf("MmRpc_release: Error: unsupported type value: %d\n", type);
+            stat = MmRpc_E_INVALIDPARAM;
+            break;
+    }
+
+    if (stat < 0) {
+        printf("MmRpc_release: Error: unable to release buffer\n");
+    }
+
+    return(stat);
+}
+
+/*
+ *  ======== MmRcp_use ========
+ */
+int MmRpc_use(MmRpc_Handle handle, MmRpc_BufType type, int num,
+        MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+
+    switch (type) {
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+        case MmRpc_BufType_Handle:
+            stat = MmRpc_bufHandle(handle, RPPC_IOC_BUFREGISTER, num, desc);
+            break;
+
+#elif defined(SYSLINK_BUILDOS_QNX)
+        case MmRpc_BufType_Ptr:
+            break;
+#endif
+        default:
+            printf("MmRpc_use: Error: unsupported type value: %d\n", type);
+            stat = MmRpc_E_INVALIDPARAM;
+            break;
+    }
+
+    if (stat < 0) {
+        printf("MmRpc_use: Error: unable to declare buffer use\n");
+    }
+
+    return(stat);
+}
+
+#if defined(SYSLINK_BUILDOS_QNX)
+/*
+ *  ======== MmRcp_getId ========
+ */
+uint32_t MmRpc_getId(MmRpc_Handle handle)
+{
+    MmRpc_Object *obj = (MmRpc_Object *)handle;
+
+    return obj->connect.id;
+}
+#endif
+
+#if defined(KERNEL_INSTALL_DIR) || defined(IPC_BUILDOS_ANDROID)
+/*
+ *  ======== MmRpc_bufHandle ========
+ */
+int MmRpc_bufHandle(MmRpc_Handle handle, int cmd, int num, MmRpc_BufDesc *desc)
+{
+    int stat = MmRpc_S_SUCCESS;
+    MmRpc_Object *obj = (MmRpc_Object *)handle;
+    int i;
+    struct rppc_buf_fds reg = { num, NULL };
+
+    reg.fds = (int32_t *)malloc(num * sizeof(int32_t));
+
+    if (reg.fds == NULL) {
+        stat = MmRpc_E_NOMEM;
+        goto leave;
+    }
+
+    for (i = 0; i < num; i++) {
+        reg.fds[i] = desc[i].handle;
+    }
+
+    stat = ioctl(obj->fd, cmd, &reg);
+
+    if (stat < 0) {
+        stat = MmRpc_E_SYS;
+    }
+
+leave:
+    if (reg.fds != NULL) {
+        free(reg.fds);
+    }
+
+    return(stat);
+}
+#endif