1#include <stdio.h> 2#include <string.h> 3#include <assert.h> 4#include "omx_proxy_common.h" 5#include <timm_osal_interfaces.h> 6#include <sys/ioctl.h> 7#include <errno.h> 8#include <sys/stat.h> 9#include <fcntl.h> 10 11#define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.DECODER.secure" 12 13extern OMX_U32 DUCATI_IN_SECURE_MODE; 14extern OMX_U32 SECURE_COMPONENTS_RUNNING; 15 16extern OMX_ERRORTYPE OMX_ProxyViddecInit(OMX_HANDLETYPE hComponent); 17OMX_ERRORTYPE PROXY_VIDDEC_Secure_ComponentDeInit(OMX_HANDLETYPE hComponent); 18 19OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) 20{ 21 OMX_ERRORTYPE eError = OMX_ErrorNone; 22 OMX_COMPONENTTYPE *pHandle = NULL; 23 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 24 const OMX_U8 enable = 1, disable = 0; 25 OMX_U8 mode; 26 int ret; 27 28 pHandle = (OMX_COMPONENTTYPE *) hComponent; 29 30 DOMX_ENTER(""); 31 32 DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME); 33 34 pHandle->pComponentPrivate = 35 (PROXY_COMPONENT_PRIVATE *) 36 TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), TIMM_OSAL_TRUE, 37 0, TIMMOSAL_MEM_SEGMENT_INT); 38 39 PROXY_assert(pHandle->pComponentPrivate != NULL, 40 OMX_ErrorInsufficientResources, 41 "ERROR IN ALLOCATING PROXY COMPONENT PRIVATE STRUCTURE"); 42 43 pComponentPrivate = 44 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 45 46 TIMM_OSAL_Memset(pComponentPrivate, 0, 47 sizeof(PROXY_COMPONENT_PRIVATE)); 48 49 pComponentPrivate->cCompName = 50 TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8), 51 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 52 53 PROXY_assert(pComponentPrivate->cCompName != NULL, 54 OMX_ErrorInsufficientResources, 55 " Error in Allocating space for proxy component table"); 56 57 // Copying component Name - this will be picked up in the proxy common 58 PROXY_assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH, 59 OMX_ErrorInvalidComponentName, 60 "Length of component name is longer than the max allowed"); 61 TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME, 62 strlen(COMPONENT_NAME) + 1); 63 64 pComponentPrivate->secure_misc_drv_fd = open("/dev/rproc_user", O_SYNC | O_RDWR); 65 if (pComponentPrivate->secure_misc_drv_fd < 0) 66 { 67 DOMX_ERROR("Can't open rproc_user device 0x%x\n", errno); 68 return OMX_ErrorInsufficientResources; 69 } 70 71 ret = write(pComponentPrivate->secure_misc_drv_fd, &enable, sizeof(enable)); 72 if(ret != 1) 73 { 74 DOMX_ERROR("errno from setting secure mode = %x",errno); 75 ret = write(pComponentPrivate->secure_misc_drv_fd, &disable, sizeof(disable)); 76 if (ret < 0) 77 { 78 DOMX_ERROR("Setting unsecure mode failed"); 79 } 80 81 ret = close(pComponentPrivate->secure_misc_drv_fd); 82 if (ret < 0) 83 { 84 DOMX_ERROR("Can't close the driver"); 85 } 86 eError = OMX_ErrorInsufficientResources; 87 goto EXIT; 88 } 89 90 ret = read(pComponentPrivate->secure_misc_drv_fd, &mode, sizeof(mode)); 91 PROXY_assert(mode == enable, OMX_ErrorUndefined,"ERROR: We are not in secure mode"); 92 DOMX_DEBUG("secure mode recieved from Misc driver for secure playback = 0x%x\n", mode); 93 94 eError = OMX_ProxyViddecInit(hComponent); 95 pHandle->ComponentDeInit = PROXY_VIDDEC_Secure_ComponentDeInit; 96 97#ifdef USE_ION 98 pComponentPrivate->bUseIon = OMX_TRUE; 99 pComponentPrivate->bMapIonBuffers = OMX_FALSE; 100#endif 101 EXIT: 102 if(eError != OMX_ErrorNone) 103 { 104 TIMM_OSAL_Free(pHandle->pComponentPrivate); 105 pHandle->pComponentPrivate = NULL; 106 } 107 return eError; 108} 109 110OMX_ERRORTYPE PROXY_VIDDEC_Secure_ComponentDeInit(OMX_HANDLETYPE hComponent) 111{ 112 OMX_ERRORTYPE eError = OMX_ErrorNone; 113 OMX_COMPONENTTYPE *pHandle = NULL; 114 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 115 int ret; 116 const OMX_U8 disable = 0; 117 int secure_misc_drv_fd; 118 119 pHandle = (OMX_COMPONENTTYPE *) hComponent; 120 121 pComponentPrivate = 122 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 123 124 secure_misc_drv_fd = pComponentPrivate->secure_misc_drv_fd; 125 126 eError = PROXY_ComponentDeInit(hComponent); 127 if(eError != OMX_ErrorNone) 128 { 129 DOMX_ERROR("Proxy common deinit returned error = %x",eError); 130 } 131 pComponentPrivate = NULL; 132 133 ret = write(secure_misc_drv_fd, &disable, sizeof(disable)); 134 if (ret < 0) 135 { 136 DOMX_ERROR("Setting unsecure mode failed"); 137 } 138 139 ret = close(secure_misc_drv_fd); 140 if (ret < 0) 141 { 142 DOMX_ERROR("Can't close the driver"); 143 } 144 145 return eError; 146} 147 148