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