index d1ba031e92f4cb50489f2124eee30f95e4f6c7d8..410851d63536bf2424c82556c782c41e84148111 100644 (file)
/*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#define _linux_ linux
#undef linux
#endif
+
+#define linux_version_include(kd) <kd/include/generated/uapi/linux/version.h>
+#include linux_version_include(KERNEL_INSTALL_DIR)
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
#define linux_include(kd,m) <kd/include/linux/m.h>
+#else
+#define linux_include(kd,m) <kd/include/uapi/linux/m.h>
+#endif
+
#include linux_include(KERNEL_INSTALL_DIR,rpmsg_rpc)
+
#ifdef _linux_
#define linux _linux
#undef _linux_
#endif
-#elif defined(SYSLINK_BUILDOS_QNX)
+#elif defined(IPC_BUILDOS_QNX)
#include <ti/ipc/rpmsg_rpc.h>
+#elif defined(IPC_BUILDOS_ANDROID)
+#include <uapi/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 ========
MmRpc_Object * obj;
char cbuf[RPPC_MAX_INST_NAMELEN+16];
+ if (service == NULL || handlePtr == NULL) {
+ status = MmRpc_E_INVALIDPARAM;
+ goto leave;
+ }
+
/* allocate the instance object */
obj = (MmRpc_Object *)calloc(1, sizeof(MmRpc_Object));
if (obj != NULL) {
free(obj);
}
- *handlePtr = NULL;
+ if (handlePtr) {
+ *handlePtr = NULL;
+ }
}
else {
*handlePtr = (MmRpc_Handle)obj;
int status = MmRpc_S_SUCCESS;
MmRpc_Object *obj;
+ if (handlePtr == NULL) {
+ return MmRpc_E_INVALIDPARAM;
+ }
+
obj = (MmRpc_Object *)(*handlePtr);
/* close the device */
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. */
+ if (handle == NULL || ctx == NULL || ret == NULL) {
+ status = MmRpc_E_INVALIDPARAM;
+ goto leave;
+ }
+
+ /* 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));
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:
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;
case MmRpc_ParamType_OffPtr:
rpfxn->params[i].data = param->param.offPtr.base +
param->param.offPtr.offset;
rpfxn->params[i].base = param->param.offPtr.base;
- rpfxn->params[i].reserved = param->param.offPtr.handle;
+ rpfxn->params[i].fd = param->param.offPtr.handle;
break;
-#if 0 /* TBD */
- case MmRpc_ParamType_Elem:
- 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;
- break;
-#endif
default:
printf("MmRpc_call: Error: invalid parameter type\n");
status = MmRpc_E_INVALIDPARAM;
rpfxn->num_translations = ctx->num_xlts;
for (i = 0; i < ctx->num_xlts; i++) {
- uint32_t index;
- size_t ptr;
-
- /* compute base value */
- index = ctx->xltAry[i].index;
- ptr = rpfxn->params[index].base + ctx->xltAry[i].offset;
-
/* pack the pointer translation entry */
- rpfxn->translations[i].index = index;
- rpfxn->translations[i].offset = ctx->xltAry[i].offset;
- rpfxn->translations[i].base = (size_t)(*(void **)ptr);
- rpfxn->translations[i].reserved = ctx->xltAry[i].handle;
+ 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 */
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(IPC_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(IPC_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(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 };
+
+ if (handle == NULL || desc == NULL) {
+ stat = MmRpc_E_INVALIDPARAM;
+ goto leave;
+ }
+
+ 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, ®);
+
+ if (stat < 0) {
+ stat = MmRpc_E_SYS;
+ }
+
+leave:
+ if (reg.fds != NULL) {
+ free(reg.fds);
+ }
+
+ return(stat);
+}
+#endif