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 13 extern OMX_U32 DUCATI_IN_SECURE_MODE; 14 extern OMX_U32 SECURE_COMPONENTS_RUNNING; 15 16 extern OMX_ERRORTYPE OMX_ProxyViddecInit(OMX_HANDLETYPE hComponent); 17 OMX_ERRORTYPE PROXY_VIDDEC_Secure_ComponentDeInit(OMX_HANDLETYPE hComponent); 18 19 OMX_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 eError = OMX_ErrorInsufficientResources; 69 goto EXIT; 70 } 71 72 ret = write(pComponentPrivate->secure_misc_drv_fd, &enable, sizeof(enable)); 73 if(ret != 1) 74 { 75 DOMX_ERROR("errno from setting secure mode = %x",errno); 76 ret = write(pComponentPrivate->secure_misc_drv_fd, &disable, sizeof(disable)); 77 if (ret < 0) 78 { 79 DOMX_ERROR("Setting unsecure mode failed"); 80 } 81 82 ret = close(pComponentPrivate->secure_misc_drv_fd); 83 if (ret < 0) 84 { 85 DOMX_ERROR("Can't close the driver"); 86 } 87 eError = OMX_ErrorInsufficientResources; 88 goto EXIT; 89 } 90 91 ret = read(pComponentPrivate->secure_misc_drv_fd, &mode, sizeof(mode)); 92 PROXY_assert(mode == enable, OMX_ErrorUndefined,"ERROR: We are not in secure mode"); 93 DOMX_DEBUG("secure mode recieved from Misc driver for secure playback = 0x%x\n", mode); 94 95 eError = OMX_ProxyViddecInit(hComponent); 96 pHandle->ComponentDeInit = PROXY_VIDDEC_Secure_ComponentDeInit; 97 98 #ifdef USE_ION 99 pComponentPrivate->bUseIon = OMX_TRUE; 100 pComponentPrivate->bMapIonBuffers = OMX_FALSE; 101 #endif 102 EXIT: 103 if (eError != OMX_ErrorNone) 104 { 105 DOMX_DEBUG("Error in Initializing Proxy"); 106 if (pComponentPrivate->cCompName != NULL) 107 { 108 TIMM_OSAL_Free(pComponentPrivate->cCompName); 109 pComponentPrivate->cCompName = NULL; 110 } 111 if (pComponentPrivate != NULL) 112 { 113 TIMM_OSAL_Free(pComponentPrivate); 114 pComponentPrivate = NULL; 115 } 116 } 117 return eError; 118 } 119 120 OMX_ERRORTYPE PROXY_VIDDEC_Secure_ComponentDeInit(OMX_HANDLETYPE hComponent) 121 { 122 OMX_ERRORTYPE eError = OMX_ErrorNone; 123 OMX_COMPONENTTYPE *pHandle = NULL; 124 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 125 int ret; 126 const OMX_U8 disable = 0; 127 int secure_misc_drv_fd; 128 129 pHandle = (OMX_COMPONENTTYPE *) hComponent; 130 131 pComponentPrivate = 132 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 133 134 secure_misc_drv_fd = pComponentPrivate->secure_misc_drv_fd; 135 136 eError = PROXY_ComponentDeInit(hComponent); 137 if(eError != OMX_ErrorNone) 138 { 139 DOMX_ERROR("Proxy common deinit returned error = %x",eError); 140 } 141 pComponentPrivate = NULL; 142 143 ret = write(secure_misc_drv_fd, &disable, sizeof(disable)); 144 if (ret < 0) 145 { 146 DOMX_ERROR("Setting unsecure mode failed"); 147 } 148 149 ret = close(secure_misc_drv_fd); 150 if (ret < 0) 151 { 152 DOMX_ERROR("Can't close the driver"); 153 } 154 155 return eError; 156 } 157 158