Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (c) 2010, 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 /**
     34  *  @file  omx_rpc_utils.c
     35  *         This file contains methods that provides the functionality for
     36  *         the OpenMAX1.1 DOMX Framework RPC.
     37  *
     38  *  @path \WTSD_DucatiMMSW\framework\domx\omx_rpc\src
     39  *
     40  *  @rev 1.0
     41  */
     42 
     43 /*==============================================================
     44  *! Revision History
     45  *! ============================
     46  *! 29-Mar-2010 Abhishek Ranka : Revamped DOMX implementation
     47  *!
     48  *! 19-August-2009 B Ravi Kiran ravi.kiran (at) ti.com: Initial Version
     49  *================================================================*/
     50 /******************************************************************
     51  *   INCLUDE FILES
     52  ******************************************************************/
     53 #include <string.h>
     54 #include <stdio.h>
     55 
     56 #include "omx_rpc.h"
     57 #include "omx_rpc_internal.h"
     58 #include "omx_rpc_utils.h"
     59 #include <MultiProc.h>
     60 #include <ProcMgr.h>
     61 
     62 extern char rcmservertable[MAX_PROC][MAX_SERVER_NAME_LENGTH];
     63 extern char Core_Array[MAX_PROC][MAX_CORENAME_LENGTH];
     64 
     65 /* ===========================================================================*/
     66 /**
     67  * @name EMPTY-STUB
     68  * @brief
     69  * @param
     70  * @return
     71  *
     72  */
     73 /* ===========================================================================*/
     74 RPC_OMX_ERRORTYPE RPC_UTIL_GetTargetServerName(OMX_STRING ComponentName,
     75     OMX_STRING ServerName)
     76 {
     77 	OMX_U8 count = 0;
     78 	OMX_U8 i = 0;
     79 	OMX_U8 servertable_idx = 0;
     80 	OMX_STRING str;
     81 	char Core[MAX_CORENAME_LENGTH];
     82 
     83 	DOMX_ENTER("");
     84 	DOMX_DEBUG(" Calling Component Name %s", ComponentName);
     85 
     86 	while (*ComponentName != '\0')
     87 	{
     88 		if (*ComponentName == '.')
     89 		{
     90 			count++;
     91 			if (count == 2)
     92 			{
     93 				ComponentName++;
     94 				str = ComponentName;
     95 
     96 				while (*str != '.')
     97 				{
     98 					Core[i] = *str;
     99 					i++;
    100 					str++;
    101 				}
    102 				Core[i] = '\0';
    103 				break;
    104 			}
    105 
    106 		}
    107 
    108 		ComponentName++;
    109 	}
    110 
    111 	DOMX_DEBUG(" CORE NAME RECOVERED: %s", Core);
    112 	DOMX_DEBUG
    113 	    ("____________________________________________________________");
    114 	DOMX_DEBUG("Recovering Server Table Index");
    115 	for (i = 0; i < CORE_MAX; i++)
    116 	{
    117 
    118 		if (strcmp(Core, Core_Array[i]) == 0)
    119 		{
    120 			servertable_idx = i;
    121 			DOMX_DEBUG("Recovered Server table index = %d", i);
    122 			break;
    123 		}
    124 	}
    125 	strncpy(ServerName, (OMX_STRING) rcmservertable[servertable_idx],
    126 	    MAX_SERVER_NAME_LENGTH);
    127 	DOMX_DEBUG(" ServerName recovered = %s", ServerName);
    128 
    129 	return RPC_OMX_ErrorNone;
    130 }
    131 
    132 /* ===========================================================================*/
    133 /**
    134  * @name EMPTY-STUB
    135  * @brief
    136  * @param
    137  * @return
    138  *
    139  */
    140 /* ===========================================================================*/
    141 RPC_OMX_ERRORTYPE RPC_UTIL_GetLocalServerName(OMX_STRING ComponentName,
    142     OMX_STRING * ServerName)
    143 {
    144 /* Implementation returns only current core ID - But this is a place holder to abstract out the
    145 default server and other additional servers available on the current core. This additional servers
    146 should be available in the RPC global that is indexed using the calling component name*/
    147 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    148 	OMX_U8 servertable_idx = 0;
    149 
    150 	servertable_idx = MultiProc_getId(NULL);	//This can be replace with the mechanism to obtain new addition rcm servers
    151 	if (MultiProc_INVALIDID != servertable_idx)
    152 		*ServerName = rcmservertable[servertable_idx];
    153 	else
    154 		eRPCError = RPC_OMX_ErrorUndefined;
    155 
    156 	return eRPCError;
    157 }
    158 
    159 
    160 
    161 /* ===========================================================================*/
    162 /**
    163  * @name RPC_UTIL_GenerateLocalServerName()
    164  * @brief This function generates a server name to be used while creating the
    165  *        RCM server. The name is based on the pid so that eacj process gets a
    166  *        unique server name.
    167  * @param cServerName - This is filled in and returned with a valid value.
    168  * @return RPC_OMX_ErrorNone = Successful
    169  * @sa TBD
    170  *
    171  */
    172 /* ===========================================================================*/
    173 RPC_OMX_ERRORTYPE RPC_UTIL_GenerateLocalServerName(OMX_STRING cServerName)
    174 {
    175 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    176 	OMX_S32 pid = 0;
    177 	OMX_U32 nProcId = 0;
    178 
    179 	pid = getpid();
    180 	/*Using pid as the server name, thus limiting to only 1 server per process.
    181 	   This limitaion is partly enforce by syslink as well since max size of server
    182 	   name is 32 so only pid can fit into the name */
    183 	sprintf(cServerName, "%ld", pid);
    184 
    185 	nProcId = MultiProc_getId(NULL);
    186 	if (MultiProc_INVALIDID != nProcId)
    187 		/*Fill the server table with the newly generated name */
    188 		strncpy(rcmservertable[nProcId], cServerName,
    189 		    MAX_SERVER_NAME_LENGTH);
    190 	else
    191 		eRPCError = RPC_OMX_ErrorUndefined;
    192 
    193 	return eRPCError;
    194 }
    195 
    196 
    197 
    198 /* ===========================================================================*/
    199 /**
    200  * @name RPC_UTIL_GetTargetCore()
    201  * @brief This function gets the target core id by parsing the component name.
    202  *        It is assumed that component names follow the convention
    203  *        <OMX>.<Company Name>.<Core Name>.<Domain>.<Component Details> with
    204  *        all characters in upper case for e.g. OMX.TI.DUCATI1.VIDEO.H264E
    205  * @param cComponentName - Name of the component.
    206  * @param nCoreId - Core ID, this is filled in and returned.
    207  * @return RPC_OMX_ErrorNone = Successful
    208  * @sa TBD
    209  *
    210  */
    211 /* ===========================================================================*/
    212 RPC_OMX_ERRORTYPE RPC_UTIL_GetTargetCore(OMX_STRING cComponentName,
    213     OMX_U32 * nCoreId)
    214 {
    215 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    216 	OMX_S8 cCoreName[MAX_SERVER_NAME_LENGTH] = { 0 };
    217 	OMX_S32 ret = 0;
    218 	OMX_U32 i = 0;
    219 
    220 	ret =
    221 	    sscanf(cComponentName, "%*[^'.'].%*[^'.'].%[^'.'].%*s",
    222 	    cCoreName);
    223 	RPC_assert(ret == 1, RPC_OMX_ErrorBadParameter,
    224 	    "Incorrect component name");
    225 
    226 	for (i = 0; i < CORE_MAX; i++)
    227 	{
    228 		if (strcmp((char *)cCoreName, Core_Array[i]) == 0)
    229 			break;
    230 	}
    231 	RPC_assert(i < CORE_MAX, RPC_OMX_ErrorBadParameter,
    232 	    "Unknown core name");
    233 	*nCoreId = i;
    234 
    235       EXIT:
    236 	return eRPCError;
    237 }
    238 
    239 
    240 
    241 /* ===========================================================================*/
    242 /**
    243  * @name EMPTY-STUB
    244  * @brief  the Api creates the RCM client on the target core(where the component sits).
    245 This happens in the context of the Default RCM server on the target core.
    246 The RCM server name to connect for this client will be the default RCM server on the calling core.
    247 This can be provided as an option as the name that you pass in the string server is used as the RCM server name
    248 input to the client create call.
    249 @Default_RcmServer - The default rcm server on the target core
    250 @Server - The name of the server on the calling core to connect to
    251  * @param
    252  * @return
    253  *
    254  */
    255 /* ===========================================================================*/
    256 /*
    257 RPC_OMX_ERRORTYPE RPC_GetTargetClient(OMX_STRING Default_RcmServer, OMX_STRING server, rcmhHndl)
    258 {
    259 
    260 
    261 }
    262 */
    263 
    264 /* ===========================================================================*/
    265 /**
    266  * @name EMPTY-STUB
    267  * @brief
    268  * @param
    269  * @return
    270  *
    271  */
    272 /* ===========================================================================*/
    273 RPC_OMX_ERRORTYPE RPC_MapBuffer(OMX_U32 mappedBuffer)
    274 {
    275 	DOMX_ENTER("");
    276 	DOMX_DEBUG("Empty implementation ");
    277 	//PlaceHolder for Mapping Buffers - Cuurently no implementation here
    278 	return RPC_OMX_ErrorNone;
    279 }
    280 
    281 /* ===========================================================================*/
    282 /**
    283  * @name EMPTY-STUB
    284  * @brief
    285  * @param
    286  * @return
    287  *
    288  */
    289 /* ===========================================================================*/
    290 RPC_OMX_ERRORTYPE RPC_UnMapBuffer(OMX_U32 mappedBuffer)
    291 {
    292 	DOMX_ENTER("");
    293 	DOMX_DEBUG("Empty implementation ");
    294 	//PlaceHolder for UnMapping Buffers - Cuurently no implementation here
    295 	return RPC_OMX_ErrorNone;
    296 }
    297 
    298 /* ===========================================================================*/
    299 /**
    300  * @name RPC_FlushBuffer
    301  * @brief Used to flush buffers from cache to memory. Used when buffers are
    302  *        being transferred across processor boundaries.
    303  * @param pBuffer       : Pointer to the data that has to be flushed.
    304  *        size          : Size of the data to be flushed.
    305  *        nTargetCoreId : Core to which buffer is being transferred.
    306  * @return RPC_OMX_ErrorNone      : Success.
    307  *         RPC_OMX_ErrorUndefined : Flush operation failed.
    308  */
    309 /* ===========================================================================*/
    310 RPC_OMX_ERRORTYPE RPC_FlushBuffer(OMX_U8 * pBuffer, OMX_U32 size,
    311     OMX_U32 nTargetCoreId)
    312 {
    313 	DOMX_ENTER("");
    314 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    315 	OMX_S32 nStatus = 0;
    316 
    317 	DOMX_DEBUG("About to flush %d bytes", size);
    318 	nStatus = ProcMgr_flushMemory((OMX_PTR) pBuffer, size,
    319 	    (ProcMgr_ProcId) nTargetCoreId);
    320 	RPC_assert(nStatus >= 0, RPC_OMX_ErrorUndefined,
    321 	    "Cache flush failed");
    322 
    323       EXIT:
    324 	return eRPCError;
    325 }
    326 
    327 
    328 
    329 /* ===========================================================================*/
    330 /**
    331  * @name RPC_InvalidateBuffer
    332  * @brief Used to flush buffers from cache to memory. Used when buffers are
    333  *        being transferred across processor boundaries.
    334  * @param pBuffer       : Pointer to the data that has to be flushed.
    335  *        size          : Size of the data to be flushed.
    336  *        nTargetCoreId : Core to which buffer is being transferred.
    337  * @return RPC_OMX_ErrorNone      : Success.
    338  *         RPC_OMX_ErrorUndefined : Invalidate operation failed.
    339  */
    340 /* ===========================================================================*/
    341 RPC_OMX_ERRORTYPE RPC_InvalidateBuffer(OMX_U8 * pBuffer, OMX_U32 size,
    342     OMX_U32 nTargetCoreId)
    343 {
    344 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    345 	OMX_S32 nStatus = 0;
    346 	DOMX_ENTER("");
    347 
    348 	DOMX_DEBUG("About to invalidate %d bytes", size);
    349 	nStatus = ProcMgr_invalidateMemory((OMX_PTR) pBuffer, size,
    350 	    (ProcMgr_ProcId) nTargetCoreId);
    351 	RPC_assert(nStatus >= 0, RPC_OMX_ErrorUndefined,
    352 	    "Cache invalidate failed");
    353 
    354       EXIT:
    355 	return eRPCError;
    356 }
    357 
    358 
    359 
    360 /* ===========================================================================*/
    361 /**
    362  * @name RPC_Util_AcquireJobId
    363  * @brief Used to get a new job id from syslink - all messages sent with the
    364  *        same job id will be processed serially. Messages with different job id
    365  *        will be processed parallely.
    366  * @param hRPCCtx       : RPC context handle.
    367  *        pJobId        : Pointer to job id - this'll be filled in and returned.
    368  * @return RPC_OMX_ErrorNone      : Success.
    369  *         Any other              : Operation failed.
    370  */
    371 /* ===========================================================================*/
    372 RPC_OMX_ERRORTYPE RPC_Util_AcquireJobId(RPC_OMX_CONTEXT * hRPCCtx,
    373     OMX_U16 * pJobId)
    374 {
    375 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    376 	OMX_S32 nStatus = 0;
    377 	DOMX_ENTER("");
    378 
    379 	nStatus =
    380 	    RcmClient_acquireJobId(hRPCCtx->ClientHndl[RCM_DEFAULT_CLIENT],
    381 	    pJobId);
    382 	RPC_assert(nStatus >= 0, RPC_OMX_ErrorUndefined,
    383 	    "Acquire job id failed");
    384 
    385       EXIT:
    386 	DOMX_EXIT("eRPCError = %d", eRPCError);
    387 	return eRPCError;
    388 }
    389 
    390 
    391 
    392 /* ===========================================================================*/
    393 /**
    394  * @name RPC_Util_ReleaseJobId
    395  * @brief Used to release job id to syslink. Once release, this job id cannot be
    396  *        reused.
    397  * @param hRPCCtx       : RPC context handle.
    398  *        nJobId        : Job ID to be released.
    399  * @return RPC_OMX_ErrorNone      : Success.
    400  *         Any other              : Operation failed.
    401  */
    402 /* ===========================================================================*/
    403 RPC_OMX_ERRORTYPE RPC_Util_ReleaseJobId(RPC_OMX_CONTEXT * hRPCCtx,
    404     OMX_U16 nJobId)
    405 {
    406 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    407 	OMX_S32 nStatus = 0;
    408 	DOMX_ENTER("");
    409 
    410 	nStatus =
    411 	    RcmClient_releaseJobId(hRPCCtx->ClientHndl[RCM_DEFAULT_CLIENT],
    412 	    nJobId);
    413 	RPC_assert(nStatus >= 0, RPC_OMX_ErrorUndefined,
    414 	    "Release job id failed");
    415 
    416       EXIT:
    417 	DOMX_EXIT("eRPCError = %d", eRPCError);
    418 	return eRPCError;
    419 }
    420 
    421 
    422 
    423 /* ===========================================================================*/
    424 /**
    425  * @name RPC_Util_GetPoolId
    426  * @brief Used to get pool id. Messages sent with same pool id will get
    427  *        processed at the same priority on remote core.
    428  * @param hRPCCtx       : RPC context handle.
    429  *        pPoolId       : Pointer to pool id - this'll be filled in and
    430  *                        returned.
    431  * @return RPC_OMX_ErrorNone      : Success.
    432  *         Any other              : Operation failed.
    433  */
    434 /* ===========================================================================*/
    435 RPC_OMX_ERRORTYPE RPC_Util_GetPoolId(RPC_OMX_CONTEXT * hRPCCtx,
    436     OMX_U16 * pPoolId)
    437 {
    438 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    439 	DOMX_ENTER("");
    440 
    441 	*pPoolId = 0x8001;
    442 
    443 //EXIT:
    444 	DOMX_EXIT("eRPCError = %d", eRPCError);
    445 	return eRPCError;
    446 }
    447