550e85a3f2747ad9e85fe4c70c0c2d0a10a0db13
1 /*
2 * Copyright (c) 2013, 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 */
33 /*
34 ********************************** Notes ******************************************
35 *******
36 ********************************* Memory *****************************************
37 *
38 *******
39 ********************************* IPC 3.x *****************************************
40 * Two approaches are followed for IPC MmRpc calls.
41 * 1. All the parameters which need to be sent and received to/from IPU are coupled in a struct
42 * allocated from Shared Memory. Only the adrress of the struct is passed to MmRpc
43 * as a pointer argument. This approach is useful as MmRpc in some cases to avoid multiple
44 * translations.
45 * This approach is followed for :
46 * Engine_open(), Engine_close(), create(), control(), delete()
47 * For understanding refer to the Mmrpc_test.c in IPC 3.x
48 * 2. All the parameters which need to be sent are given as separate arguments to
49 * MmRpc. This appraoch is needed when you need to translate an address which is
50 * ofsetted from a pointer which in itself needs to be translated.
51 * This apporach is followed for : process()
52 * For understanding, take the example of inbufs argument in process call(). Inbufs
53 * allocated in Shared memory and needs to be translated, has the address of Input
54 * buffer (allocated from Tiler). It is not possible to give the Input buffer as an argument
55 * to Mmrpc for translation until inbufs is given as a parameter to Mmrpc. Therefore inbuf
56 * can't be populated inside another Shared memory struct.
57 * 3. This approach is a workaround to use approach [1] by solving the issue posed by [2].
58 * This approach is followed for : get_version()
59 * Taking the example of inbufs to explain, the Input buffer address will be one of the
60 * parameters of the struct (explained in [1]) along with inbufs address. Therefore the
61 * Input buffer address will get translated here. At the IPU, this address needs to be
62 * copied back to inbufs.
63 *********************************************************************************
64 */
66 #include <stdlib.h>
67 #include <string.h>
68 #include <stdio.h>
69 #include <pthread.h>
70 #include <errno.h>
72 #include <xdc/std.h>
74 #if defined(BUILDOS_GLP)
75 #include <xf86drm.h>
76 #include <omap_drm.h>
77 #include <omap_dce.h>
78 #include <omap_drmif.h>
79 #endif /* BUILDOS_GLP */
81 /* IPC Headers */
82 #include <MmRpc.h>
84 /*DCE Headers */
85 #include "libdce.h"
86 #include "dce_rpc.h"
87 #include "dce_priv.h"
88 #include "memplugin.h"
91 #if defined(BUILDOS_GLP)
92 #ifdef GLP_X11
93 int dce_auth_x11(int *fd);
94 #endif /* GLP_X11 */
95 #ifdef GLP_WAYLAND
96 int dce_auth_wayland(int *fd);
97 #endif /* GLP_WAYLAND */
99 static int fd = -1;
100 static struct omap_device *dev;
101 static int ioctl_base;
102 #define CMD(name) (ioctl_base + DRM_OMAP_DCE_##name)
104 uint32_t dce_debug = 3;
105 #endif /* BUILDOS_GLP */
108 /********************* GLOBALS ***********************/
109 /* Hande used for Remote Communication */
110 static MmRpc_Handle MmRpcHandle = NULL;
111 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
112 static int count = 0;
115 /****************** INLINE FUNCTIONS ********************/
117 static inline void Fill_MmRpc_fxnCtx(MmRpc_FxnCtx *fxnCtx, int fxn_id, int num_params, int num_xlts, MmRpc_Xlt *xltAry)
118 {
119 fxnCtx->fxn_id = fxn_id;
120 fxnCtx->num_params = num_params;
121 fxnCtx->num_xlts = num_xlts;
122 fxnCtx->xltAry = xltAry;
123 }
125 static inline void Fill_MmRpc_fxnCtx_Ptr_Params(MmRpc_Param *mmrpc_params, int size, void *addr, void *handle)
126 {
127 mmrpc_params->type = MmRpc_ParamType_Ptr;
128 mmrpc_params->param.ptr.size = size;
129 mmrpc_params->param.ptr.addr = (size_t)addr;
130 mmrpc_params->param.ptr.handle = (size_t)handle;
131 }
133 static inline void Fill_MmRpc_fxnCtx_Scalar_Params(MmRpc_Param *mmrpc_params, int size, int data)
134 {
135 mmrpc_params->type = MmRpc_ParamType_Scalar;
136 mmrpc_params->param.scalar.size = size;
137 mmrpc_params->param.scalar.data = (size_t)data;
138 }
140 static inline void Fill_MmRpc_fxnCtx_Xlt_Array(MmRpc_Xlt *mmrpc_xlt, int index, int32_t base, int32_t addr, void *handle)
141 {
142 /* index : index of params filled in FxnCtx */
143 /* offset : calculated from address of index */
144 mmrpc_xlt->index = index;
145 mmrpc_xlt->offset = MmRpc_OFFSET(base, addr);
146 mmrpc_xlt->handle = (size_t)handle;
147 }
149 /************************ FUNCTIONS **************************/
150 /* Interface for QNX for parameter buffer allocation */
151 /* These interfaces are implemented to maintain Backward Compatability */
152 void *dce_alloc(int sz)
153 {
154 return (memplugin_alloc(sz, 0, TILER_1D_BUFFER));
155 }
157 void dce_free(void *ptr)
158 {
159 memplugin_free(ptr, TILER_1D_BUFFER);
160 }
162 /*************** Startup/Shutdown Functions ***********************/
163 static int dce_init(void)
164 {
165 dce_error_status eError = DCE_EOK;
166 MmRpc_Params args;
168 printf(" >> dce_init\n");
170 pthread_mutex_lock(&mutex);
172 count++;
173 /* Check if already Initialized */
174 _ASSERT(count == 1, DCE_EOK);
176 /* Create remote server insance */
177 MmRpc_Params_init(&args);
179 eError = MmRpc_create(DCE_DEVICE_NAME, &args, &MmRpcHandle);
181 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CREATE_FAIL, count--);
183 printf("open(/dev/" DCE_DEVICE_NAME ") -> 0x%x\n", (int)MmRpcHandle);
184 EXIT:
185 pthread_mutex_unlock(&mutex);
186 return (eError);
187 }
189 static void dce_deinit(void)
190 {
191 pthread_mutex_lock(&mutex);
193 count--;
194 if( count > 0 ) {
195 goto EXIT;
196 }
198 if( MmRpcHandle != NULL ) {
199 MmRpc_delete(&MmRpcHandle);
200 }
201 MmRpcHandle = NULL;
202 EXIT:
203 pthread_mutex_unlock(&mutex);
204 return;
205 }
207 /*===============================================================*/
208 /** Engine_open : Open Codec Engine.
209 *
210 * @ param attrs [in] : Engine Attributes. This param is not passed to Remote core.
211 * @ param name [in] : Name of Encoder or Decoder codec.
212 * @ param ec [out] : Error returned by Codec Engine.
213 * @ return : Codec Engine Handle is returned to be used to create codec.
214 * In case of error, NULL is returned as Engine Handle.
215 */
216 Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec)
217 {
218 MmRpc_FxnCtx fxnCtx;
219 int32_t fxnRet;
220 dce_error_status eError = DCE_EOK;
221 dce_engine_open *engine_open_msg = NULL;
222 Engine_Handle eng_handle = NULL;
224 _ASSERT(name != '\0', DCE_EINVALID_INPUT);
226 /* Initialize DCE and IPC. In case of Error Deinitialize them */
227 _ASSERT_AND_EXECUTE(dce_init() == DCE_EOK, DCE_EIPC_CREATE_FAIL, dce_deinit());
229 printf(">> Engine_open Params::name = %s size = %d\n", name, strlen(name));
230 /* Allocate Shared memory for the engine_open rpc msg structure*/
231 /* Tiler Memory preferred for now for First level testing */
232 engine_open_msg = memplugin_alloc(sizeof(dce_engine_open), 0, TILER_1D_BUFFER);
234 _ASSERT_AND_EXECUTE(engine_open_msg != NULL, DCE_EOUT_OF_MEMORY, eng_handle = NULL);
236 /* Populating the msg structure with all the params */
237 /* Populating all params into a struct avoid individual address translations of name, ec */
238 strncpy(engine_open_msg->name, name, strlen(name));
239 engine_open_msg->eng_handle = NULL;
241 /* Marshall function arguments into the send buffer */
242 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_OPEN, 1, 0, NULL);
243 Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_engine_open), engine_open_msg, NULL);
245 /* Invoke the Remote function through MmRpc */
246 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
248 /* In case of Error, the Application will get a NULL Engine Handle */
249 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CALL_FAIL, eng_handle = NULL);
251 /* Populate return arguments */
252 eng_handle = engine_open_msg->eng_handle;
253 ec[0] = engine_open_msg->error_code;
255 EXIT:
256 memplugin_free(engine_open_msg, TILER_1D_BUFFER);
258 return (eng_handle);
259 }
261 /*===============================================================*/
262 /** Engine_close : Close Engine.
263 *
264 * @ param engine [in] : Engine Handle obtained in Engine_open() call.
265 */
266 Void Engine_close(Engine_Handle engine)
267 {
268 MmRpc_FxnCtx fxnCtx;
269 int32_t fxnRet;
270 dce_error_status eError = DCE_EOK;
271 dce_engine_close *engine_close_msg = NULL;
273 _ASSERT(engine != NULL, DCE_EINVALID_INPUT);
275 /* Allocate Shared/Tiler memory for the engine_close rpc msg structure*/
276 engine_close_msg = memplugin_alloc(sizeof(dce_engine_close), 0, TILER_1D_BUFFER);
278 _ASSERT(engine_close_msg != NULL, DCE_EOUT_OF_MEMORY);
280 /* Populating the msg structure with all the params */
281 engine_close_msg->eng_handle = engine;
283 /* Marshall function arguments into the send buffer */
284 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_CLOSE, 1, 0, NULL);
285 Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_engine_close), engine_close_msg, NULL);
287 /* Invoke the Remote function through MmRpc */
288 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
290 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
292 EXIT:
293 memplugin_free(engine_close_msg, TILER_1D_BUFFER);
295 dce_deinit();
296 return;
297 }
299 /*===============================================================*/
300 /** Functions create(), control(), get_version(), process(), delete() are common codec
301 * glue function signatures which are same for both encoder and decoder
302 */
303 /*===============================================================*/
304 /** create : Create Encoder/Decoder codec.
305 *
306 * @ param engine [in] : Engine Handle obtained in Engine_open() call.
307 * @ param name [in] : Name of Encoder or Decoder codec.
308 * @ param params [in] : Static parameters of codec.
309 * @ param codec_id [in] : To differentiate between Encoder and Decoder codecs.
310 * @ return : Codec Handle is returned to be used for control, process, delete calls.
311 * In case of error, NULL is returned.
312 */
313 static void *create(Engine_Handle engine, String name, void *params, dce_codec_type codec_id)
314 {
315 MmRpc_FxnCtx fxnCtx;
316 MmRpc_Xlt xltAry;
317 int32_t fxnRet;
318 dce_error_status eError = DCE_EOK;
319 dce_codec_create *codec_create_msg = NULL;
320 void *codec_handle = NULL;
322 _ASSERT(name != '\0', DCE_EINVALID_INPUT);
323 _ASSERT(engine != NULL, DCE_EINVALID_INPUT);
324 _ASSERT(params != NULL, DCE_EINVALID_INPUT);
326 /* Allocate Shared/Tiler memory for the codec_create rpc msg structure*/
327 codec_create_msg = memplugin_alloc(sizeof(dce_codec_create), 0, TILER_1D_BUFFER);
329 _ASSERT_AND_EXECUTE(codec_create_msg != NULL, DCE_EOUT_OF_MEMORY, codec_handle = NULL);
331 /* Populating the msg structure with all the params */
332 codec_create_msg->engine = engine;
333 strncpy(codec_create_msg->codec_name, name, strlen(name));
334 codec_create_msg->codec_id = codec_id;
335 codec_create_msg->codec_handle = NULL;
336 codec_create_msg->static_params = params;
338 /* Marshall function arguments into the send buffer */
339 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CREATE, 1, 1, &xltAry);
340 Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[0]), sizeof(dce_codec_create), codec_create_msg, NULL);
342 /* Mention the virtual pointers that need translation */
343 /* Allocations through dce_alloc need translation */
344 /* In this case the static params buffer need translation */
345 Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 0, (int32_t)codec_create_msg, (int32_t)&(codec_create_msg->static_params), NULL);
347 /* Invoke the Remote function through MmRpc */
348 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
350 /* In case of Error, the Application will get a NULL Codec Handle */
351 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CALL_FAIL, codec_handle = NULL);
353 codec_handle = codec_create_msg->codec_handle;
355 EXIT:
356 memplugin_free(codec_create_msg, TILER_1D_BUFFER);
358 return (codec_handle);
359 }
361 /*===============================================================*/
362 /** control : Codec control call.
363 *
364 * @ param codec [in] : Codec Handle obtained in create() call.
365 * @ param id [in] : Command id for XDM control operation.
366 * @ param dynParams [in] : Dynamic input parameters to Codec.
367 * @ param status [out] : Codec returned status parameters.
368 * @ param codec_id [in] : To differentiate between Encoder and Decoder codecs.
369 * @ return : Status of control() call is returned.
370 * #XDM_EOK [0] : Success.
371 * #XDM_EFAIL [-1] : Failure.
372 * #IPC_FAIL [-2] : MmRpc Call failed.
373 * #XDM_EUNSUPPORTED [-3] : Unsupported request.
374 * #OUT_OF_MEMORY [-4] : Out of Shared Memory.
375 */
376 static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dce_codec_type codec_id)
377 {
378 MmRpc_FxnCtx fxnCtx;
379 MmRpc_Xlt xltAry[2];
380 int32_t fxnRet;
381 dce_error_status eError = DCE_EOK;
382 dce_codec_control *codec_control_msg = NULL;
384 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
385 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT);
386 _ASSERT(status != NULL, DCE_EINVALID_INPUT);
388 /* Allocate Shared/Tiler memory for the codec_control rpc msg structure*/
389 codec_control_msg = memplugin_alloc(sizeof(dce_codec_control), 0, TILER_1D_BUFFER);
391 _ASSERT(codec_control_msg != NULL, DCE_EOUT_OF_MEMORY);
393 /* Populating the msg structure with all the params */
394 codec_control_msg->codec_handle = codec;
395 codec_control_msg->cmd_id = id;
396 codec_control_msg->codec_id = codec_id;
397 codec_control_msg->dyn_params = dynParams;
398 codec_control_msg->status = status;
400 /* Marshall function arguments into the send buffer */
401 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CONTROL, 1, 2, xltAry);
402 Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_codec_control), codec_control_msg, NULL);
404 /* Dynamic and status params buffer need translation */
405 Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 0, (int32_t)codec_control_msg, (int32_t)&(codec_control_msg->dyn_params), NULL);
406 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[1]), 0, (int32_t)codec_control_msg, (int32_t)&(codec_control_msg->status), NULL);
408 /* Invoke the Remote function through MmRpc */
409 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
411 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
413 eError = codec_control_msg->result;
415 EXIT:
416 memplugin_free(codec_control_msg, TILER_1D_BUFFER);
418 return (eError);
419 }
421 /*===============================================================*/
422 /** get_version : Codec control call to get the codec version. This call has been made
423 * separate from control call because it involves an additional version
424 * buffer translation.
425 *
426 * @ param codec [in] : Codec Handle obtained in create() call.
427 * @ param id [in] : Command id for XDM control operation.
428 * @ param dynParams [in] : Dynamic input parameters to Codec.
429 * @ param status [out] : Codec returned status parameters.
430 * @ param codec_id [in] : To differentiate between Encoder and Decoder codecs.
431 * @ return : Status of control() call is returned.
432 * #XDM_EOK [0] : Success.
433 * #XDM_EFAIL [-1] : Failure.
434 * #IPC_FAIL [-2] : MmRpc Call failed.
435 * #XDM_EUNSUPPORTED [-3] : Unsupported request.
436 * #OUT_OF_MEMORY [-4] : Out of Shared Memory.
437 */
438 static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_codec_type codec_id)
439 {
440 MmRpc_FxnCtx fxnCtx;
441 MmRpc_Xlt xltAry[3];
442 int32_t fxnRet;
443 dce_error_status eError = DCE_EOK;
444 dce_codec_get_version *codec_get_version_msg = NULL;
446 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
447 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT);
448 _ASSERT(status != NULL, DCE_EINVALID_INPUT);
450 /* Allocate Shared/Tiler memory for the codec_get_version rpc msg structure*/
451 codec_get_version_msg = memplugin_alloc(sizeof(dce_codec_get_version), 0, TILER_1D_BUFFER);
453 _ASSERT(codec_get_version_msg != NULL, DCE_EOUT_OF_MEMORY);
455 /* Populating the msg structure with all the params */
456 codec_get_version_msg->codec_handle = codec;
457 codec_get_version_msg->codec_id = codec_id;
458 codec_get_version_msg->dyn_params = dynParams;
459 codec_get_version_msg->status = status;
460 if( codec_id == OMAP_DCE_VIDDEC3 ) {
461 codec_get_version_msg->version = ((IVIDDEC3_Status *)status)->data.buf;
462 } else if( codec_id == OMAP_DCE_VIDENC2 ) {
463 codec_get_version_msg->version = ((IVIDDEC3_Status *)status)->data.buf;
464 }
466 /* Marshall function arguments into the send buffer */
467 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CONTROL, 1, 3, xltAry);
468 Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_codec_get_version), codec_get_version_msg, NULL);
470 /* Dynamic, status params and version info buffer need translation */
471 Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 0, (int32_t)codec_get_version_msg, (int32_t)&(codec_get_version_msg->dyn_params), NULL);
472 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[1]), 0, (int32_t)codec_get_version_msg, (int32_t)&(codec_get_version_msg->status), NULL);
473 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[2]), 0, (int32_t)codec_get_version_msg, (int32_t)&(codec_get_version_msg->version), NULL);
475 /* Invoke the Remote function through MmRpc */
476 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
478 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
480 eError = codec_get_version_msg->result;
482 EXIT:
483 memplugin_free(codec_get_version_msg, TILER_1D_BUFFER);
485 return (eError);
486 }
488 typedef enum process_call_params {
489 CODEC_HANDLE_INDEX = 0,
490 INBUFS_INDEX,
491 OUTBUFS_INDEX,
492 INARGS_INDEX,
493 OUTARGS_INDEX,
494 CODEC_ID_INDEX
495 } process_call_params;
497 /*===============================================================*/
498 /** process : Encode/Decode process.
499 *
500 * @ param codec [in] : Codec Handle obtained in create() call.
501 * @ param inBufs [in] : Input buffer details.
502 * @ param outBufs [in] : Output buffer details.
503 * @ param inArgs [in] : Input arguments.
504 * @ param outArgs [out] : Output arguments.
505 * @ param codec_id [in] : To differentiate between Encoder and Decoder codecs.
506 * @ return : Status of the process call.
507 * #XDM_EOK [0] : Success.
508 * #XDM_EFAIL [-1] : Failure.
509 * #IPC_FAIL [-2] : MmRpc Call failed.
510 * #XDM_EUNSUPPORTED [-3] : Unsupported request.
511 */
512 static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
513 void *inArgs, void *outArgs, dce_codec_type codec_id)
514 {
515 MmRpc_FxnCtx fxnCtx;
516 MmRpc_Xlt xltAry[MAX_TOTAl_BUF];
517 int fxnRet, count, total_count, numInBufs = 0, numOutBufs = 0, sz[5] = { 0 };
518 dce_error_status eError = DCE_EOK;
520 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
521 _ASSERT(inBufs != NULL, DCE_EINVALID_INPUT);
522 _ASSERT(outBufs != NULL, DCE_EINVALID_INPUT);
523 _ASSERT(inArgs != NULL, DCE_EINVALID_INPUT);
524 _ASSERT(outArgs != NULL, DCE_EINVALID_INPUT);
526 if( codec_id == OMAP_DCE_VIDDEC3 ) {
527 numInBufs = ((XDM2_BufDesc *)inBufs)->numBufs;
528 numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
529 sz[INBUFS_INDEX] = sizeof(XDM2_BufDesc);
530 sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
531 sz[INARGS_INDEX] = sizeof(VIDDEC3_InArgs);
532 sz[OUTARGS_INDEX] = sizeof(VIDDEC3_OutArgs);
533 } else if( codec_id == OMAP_DCE_VIDENC2 ) {
534 numInBufs = ((IVIDEO2_BufDesc *)inBufs)->numPlanes;
535 numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
536 sz[INBUFS_INDEX] = sizeof(IVIDEO2_BufDesc);
537 sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
538 sz[INARGS_INDEX] = sizeof(VIDENC2_InArgs);
539 sz[OUTARGS_INDEX] = sizeof(VIDENC2_OutArgs);
540 }
542 /* marshall function arguments into the send buffer */
543 /* Approach [2] as explained in "Notes" used for process */
544 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_PROCESS, 6, numInBufs + numOutBufs, xltAry);
545 Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_HANDLE_INDEX]), sizeof(int32_t), (int32_t)codec);
546 Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INBUFS_INDEX]), sz[INBUFS_INDEX], inBufs, NULL);
547 Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTBUFS_INDEX]), sz[OUTBUFS_INDEX], outBufs, NULL);
548 Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INARGS_INDEX]), sz[INARGS_INDEX], inArgs, NULL);
549 Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTARGS_INDEX]), sz[OUTARGS_INDEX], outArgs, NULL);
550 Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_ID_INDEX]), sizeof(int32_t), codec_id);
552 /* InBufs, OutBufs, InArgs, OutArgs buffer need translation but since they have been */
553 /* individually mentioned as fxnCtx Params, they need not be mentioned below again */
554 /* Input and Output Buffers have to be mentioned for translation */
555 for( count = 0, total_count = 0; count < numInBufs; count++, total_count++ ) {
556 if( codec_id == OMAP_DCE_VIDDEC3 ) {
557 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((XDM2_BufDesc *)inBufs)->descs[count].buf), NULL);
558 } else if( codec_id == OMAP_DCE_VIDENC2 ) {
559 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((IVIDEO2_BufDesc *)inBufs)->planeDesc[count].buf), NULL);
560 }
561 }
563 for( count = 0; count < numOutBufs; count++, total_count++ ) {
564 Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)outBufs, (int32_t)&(((XDM2_BufDesc *)outBufs)->descs[count].buf), NULL);
565 }
567 /* Invoke the Remote function through MmRpc */
568 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
570 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
572 eError = (dce_error_status)(fxnRet);
573 EXIT:
574 return (eError);
575 }
577 /*===============================================================*/
578 /** delete : Delete Encode/Decode codec instance.
579 *
580 * @ param codec [in] : Codec Handle obtained in create() call.
581 * @ param codec_id [in] : To differentiate between Encoder and Decoder codecs.
582 * @ return : NIL.
583 */
584 static void delete(void *codec, dce_codec_type codec_id)
585 {
586 MmRpc_FxnCtx fxnCtx;
587 int32_t fxnRet;
588 dce_error_status eError = DCE_EOK;
589 dce_codec_delete *codec_delete_msg = NULL;
591 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
593 /* Allocate Shared/Tiler memory for the codec_delete rpc msg structure*/
594 codec_delete_msg = memplugin_alloc(sizeof(dce_codec_delete), 0, TILER_1D_BUFFER);
596 _ASSERT(codec_delete_msg != NULL, DCE_EOUT_OF_MEMORY);
598 /* Populating the msg structure with all the params */
599 codec_delete_msg->codec_handle = codec;
600 codec_delete_msg->codec_id = codec_id;
602 /* Marshall function arguments into the send buffer */
603 Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_DELETE, 1, 0, NULL);
604 Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_codec_delete), codec_delete_msg, NULL);
606 /* Invoke the Remote function through MmRpc */
607 eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
609 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
611 EXIT:
612 memplugin_free(codec_delete_msg, TILER_1D_BUFFER);
614 return;
615 }
617 /*************** Deocder Codec Engine Functions ***********************/
618 VIDDEC3_Handle VIDDEC3_create(Engine_Handle engine, String name,
619 VIDDEC3_Params *params)
620 {
621 VIDDEC3_Handle codec;
623 DEBUG(">> engine=%p, name=%s, params=%p", engine, name, params);
624 codec = create(engine, name, params, OMAP_DCE_VIDDEC3);
625 DEBUG("<< codec=%p", codec);
626 return (codec);
627 }
629 XDAS_Int32 VIDDEC3_control(VIDDEC3_Handle codec, VIDDEC3_Cmd id,
630 VIDDEC3_DynamicParams *dynParams, VIDDEC3_Status *status)
631 {
632 XDAS_Int32 ret;
634 DEBUG(">> codec=%p, id=%d, dynParams=%p, status=%p",
635 codec, id, dynParams, status);
636 if( id == XDM_GETVERSION ) {
637 ret = get_version(codec, dynParams, status, OMAP_DCE_VIDDEC3);
638 } else {
639 ret = control(codec, id, dynParams, status, OMAP_DCE_VIDDEC3);
640 }
641 DEBUG("<< ret=%d", ret);
642 return (ret);
643 }
645 XDAS_Int32 VIDDEC3_process(VIDDEC3_Handle codec,
646 XDM2_BufDesc *inBufs, XDM2_BufDesc *outBufs,
647 VIDDEC3_InArgs *inArgs, VIDDEC3_OutArgs *outArgs)
648 {
649 XDAS_Int32 ret;
651 DEBUG(">> codec=%p, inBufs=%p, outBufs=%p, inArgs=%p, outArgs=%p",
652 codec, inBufs, outBufs, inArgs, outArgs);
653 ret = process(codec, inBufs, outBufs, inArgs, outArgs, OMAP_DCE_VIDDEC3);
654 DEBUG("<< ret=%d", ret);
655 return (ret);
656 }
658 Void VIDDEC3_delete(VIDDEC3_Handle codec)
659 {
660 DEBUG(">> codec=%p", codec);
661 delete(codec, OMAP_DCE_VIDDEC3);
662 DEBUG("<<");
663 }
665 /*************** Enocder Codec Engine Functions ***********************/
666 VIDENC2_Handle VIDENC2_create(Engine_Handle engine, String name,
667 VIDENC2_Params *params)
668 {
669 VIDENC2_Handle codec;
671 DEBUG(">> engine=%p, name=%s, params=%p", engine, name, params);
672 codec = create(engine, name, params, OMAP_DCE_VIDENC2);
673 DEBUG("<< codec=%p", codec);
674 return (codec);
675 }
677 XDAS_Int32 VIDENC2_control(VIDENC2_Handle codec, VIDENC2_Cmd id,
678 VIDENC2_DynamicParams *dynParams, VIDENC2_Status *status)
679 {
680 XDAS_Int32 ret;
682 DEBUG(">> codec=%p, id=%d, dynParams=%p, status=%p",
683 codec, id, dynParams, status);
684 ret = control(codec, id, dynParams, status, OMAP_DCE_VIDENC2);
685 DEBUG("<< ret=%d", ret);
686 return (ret);
687 }
689 XDAS_Int32 VIDENC2_process(VIDENC2_Handle codec,
690 IVIDEO2_BufDesc *inBufs, XDM2_BufDesc *outBufs,
691 VIDENC2_InArgs *inArgs, VIDENC2_OutArgs *outArgs)
692 {
693 XDAS_Int32 ret;
695 DEBUG(">> codec=%p, inBufs=%p, outBufs=%p, inArgs=%p, outArgs=%p",
696 codec, inBufs, outBufs, inArgs, outArgs);
697 ret = process(codec, inBufs, outBufs, inArgs, outArgs, OMAP_DCE_VIDENC2);
698 DEBUG("<< ret=%d", ret);
699 return (ret);
700 }
702 Void VIDENC2_delete(VIDENC2_Handle codec)
703 {
704 DEBUG(">> codec=%p", codec);
705 delete(codec, OMAP_DCE_VIDENC2);
706 DEBUG("<<");
707 }