1*53ee8cc1Swenshuai.xi #include "utopia_private.h"
2*53ee8cc1Swenshuai.xi #include <stdio.h>
3*53ee8cc1Swenshuai.xi #include "utopia.h"
4*53ee8cc1Swenshuai.xi #include "utopia_module.h"
5*53ee8cc1Swenshuai.xi #include "utopia_dapi.h"
6*53ee8cc1Swenshuai.xi #include "string.h"
7*53ee8cc1Swenshuai.xi #include "MsOS.h"
8*53ee8cc1Swenshuai.xi #include "MsCommon.h"
9*53ee8cc1Swenshuai.xi
10*53ee8cc1Swenshuai.xi //Global Variable===================================================
11*53ee8cc1Swenshuai.xi UTOPIA_PRIVATE* psUtopiaPrivate;
12*53ee8cc1Swenshuai.xi
13*53ee8cc1Swenshuai.xi char moduleNames[][40] = {
14*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "MODULE_"#MODULE,
15*53ee8cc1Swenshuai.xi INCLUDED_MODULE
16*53ee8cc1Swenshuai.xi #undef PREFIX
17*53ee8cc1Swenshuai.xi };
18*53ee8cc1Swenshuai.xi
19*53ee8cc1Swenshuai.xi char rpoolNames[][40] = {
20*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "RPOOL_"#MODULE,
21*53ee8cc1Swenshuai.xi INCLUDED_MODULE
22*53ee8cc1Swenshuai.xi #undef PREFIX
23*53ee8cc1Swenshuai.xi };
24*53ee8cc1Swenshuai.xi
25*53ee8cc1Swenshuai.xi char ResourceNames[][40] = {
26*53ee8cc1Swenshuai.xi #define PREFIX(MODULE) "RESOURCE_"#MODULE,
27*53ee8cc1Swenshuai.xi INCLUDED_MODULE
28*53ee8cc1Swenshuai.xi #undef PREFIX
29*53ee8cc1Swenshuai.xi };
30*53ee8cc1Swenshuai.xi
31*53ee8cc1Swenshuai.xi void BDMARegisterToUtopia(FUtopiaOpen ModuleType);
32*53ee8cc1Swenshuai.xi void CPURegisterToUtopia(FUtopiaOpen ModuleType);
33*53ee8cc1Swenshuai.xi void FLASHRegisterToUtopia(FUtopiaOpen ModuleType);
34*53ee8cc1Swenshuai.xi void IRRegisterToUtopia(FUtopiaOpen ModuleType);
35*53ee8cc1Swenshuai.xi void MBXRegisterToUtopia(FUtopiaOpen ModuleType);
36*53ee8cc1Swenshuai.xi void MVOPRegisterToUtopia(FUtopiaOpen ModuleType);
37*53ee8cc1Swenshuai.xi void MSPIRegisterToUtopia(FUtopiaOpen ModuleType);
38*53ee8cc1Swenshuai.xi void PWMRegisterToUtopia(FUtopiaOpen ModuleType);
39*53ee8cc1Swenshuai.xi void PWSRegisterToUtopia(FUtopiaOpen ModuleType);
40*53ee8cc1Swenshuai.xi void RTCRegisterToUtopia(FUtopiaOpen ModuleType);
41*53ee8cc1Swenshuai.xi #ifdef CONFIG_MSTAR_UTPA2K_SAR_ENABLE
42*53ee8cc1Swenshuai.xi void SARRegisterToUtopia(FUtopiaOpen ModuleType);
43*53ee8cc1Swenshuai.xi #endif
44*53ee8cc1Swenshuai.xi void ACERegisterToUtopia(FUtopiaOpen ModuleType);
45*53ee8cc1Swenshuai.xi void DLCRegisterToUtopia(FUtopiaOpen ModuleType);
46*53ee8cc1Swenshuai.xi void DMXRegisterToUtopia(FUtopiaOpen ModuleType);
47*53ee8cc1Swenshuai.xi void GFXRegisterToUtopia(FUtopiaOpen ModuleType);
48*53ee8cc1Swenshuai.xi void GOPRegisterToUtopia(FUtopiaOpen ModuleType);
49*53ee8cc1Swenshuai.xi void PNLRegisterToUtopia(FUtopiaOpen ModuleType);
50*53ee8cc1Swenshuai.xi void XCRegisterToUtopia(FUtopiaOpen ModuleType);
51*53ee8cc1Swenshuai.xi void CECRegisterToUtopia(FUtopiaOpen ModuleType);
52*53ee8cc1Swenshuai.xi
53*53ee8cc1Swenshuai.xi void HDMIRXRegisterToUtopia(FUtopiaOpen ModuleType);
54*53ee8cc1Swenshuai.xi void PQRegisterToUtopia(FUtopiaOpen ModuleType);
55*53ee8cc1Swenshuai.xi
56*53ee8cc1Swenshuai.xi void VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType);
57*53ee8cc1Swenshuai.xi void SYSRegisterToUtopia(FUtopiaOpen ModuleType);
58*53ee8cc1Swenshuai.xi void UARTRegisterToUtopia(FUtopiaOpen ModuleType);
59*53ee8cc1Swenshuai.xi void TVENCODERRegisterToUtopia(FUtopiaOpen ModuleType);
60*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_JPEG_EX
61*53ee8cc1Swenshuai.xi void JPEG_EXRegisterToUtopia(FUtopiaOpen ModuleType);
62*53ee8cc1Swenshuai.xi #endif
63*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_NJPEG_EX
64*53ee8cc1Swenshuai.xi void NJPEG_EXRegisterToUtopia(FUtopiaOpen ModuleType);
65*53ee8cc1Swenshuai.xi #endif
66*53ee8cc1Swenshuai.xi void GPDRegisterToUtopia(FUtopiaOpen ModuleType);
67*53ee8cc1Swenshuai.xi
68*53ee8cc1Swenshuai.xi void DACRegisterToUtopia(void);
69*53ee8cc1Swenshuai.xi void SEMRegisterToUtopia(void);
70*53ee8cc1Swenshuai.xi void DSCMBRegisterToUtopia(void);
71*53ee8cc1Swenshuai.xi void AESDMARegisterToUtopia(FUtopiaOpen ModuleType);
72*53ee8cc1Swenshuai.xi void HDMITXRegisterToUtopia(FUtopiaOpen ModuleType);
73*53ee8cc1Swenshuai.xi void CARegisterToUtopia(void);
74*53ee8cc1Swenshuai.xi void CIPHERRegisterToUtopia(void);
75*53ee8cc1Swenshuai.xi
76*53ee8cc1Swenshuai.xi void MIURegisterToUtopia(FUtopiaOpen ModuleType);
77*53ee8cc1Swenshuai.xi
UtopiaInit()78*53ee8cc1Swenshuai.xi MS_U32 UtopiaInit()
79*53ee8cc1Swenshuai.xi {
80*53ee8cc1Swenshuai.xi MS_U32 u32Ret = 0;
81*53ee8cc1Swenshuai.xi printf("\033[35m[eCos] UtopiaInit\033[m\n\n");
82*53ee8cc1Swenshuai.xi
83*53ee8cc1Swenshuai.xi psUtopiaPrivate = (UTOPIA_PRIVATE*)malloc(sizeof(UTOPIA_PRIVATE));
84*53ee8cc1Swenshuai.xi memset(psUtopiaPrivate, 0, sizeof(UTOPIA_PRIVATE));
85*53ee8cc1Swenshuai.xi psUtopiaPrivate->u32MutexID = MsOS_CreateMutex(E_MSOS_FIFO, "UtopiaPrivateMutex", MSOS_PROCESS_SHARED);
86*53ee8cc1Swenshuai.xi
87*53ee8cc1Swenshuai.xi MsOS_ObtainMutex(psUtopiaPrivate->u32MutexID, MSOS_WAIT_FOREVER);
88*53ee8cc1Swenshuai.xi
89*53ee8cc1Swenshuai.xi /*
90*53ee8cc1Swenshuai.xi * to avoid weak attribute malfunction in static lib,
91*53ee8cc1Swenshuai.xi * we explicitly call needed functions
92*53ee8cc1Swenshuai.xi */
93*53ee8cc1Swenshuai.xi UTOPIARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_UTOPIA_FULL);
94*53ee8cc1Swenshuai.xi BDMARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_BDMA_FULL);
95*53ee8cc1Swenshuai.xi
96*53ee8cc1Swenshuai.xi CPURegisterToUtopia((FUtopiaOpen)MODULE_TYPE_CPU_FULL);
97*53ee8cc1Swenshuai.xi FLASHRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_FLASH_FULL);
98*53ee8cc1Swenshuai.xi IRRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_IR_FULL);
99*53ee8cc1Swenshuai.xi MBXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MBX_FULL);
100*53ee8cc1Swenshuai.xi MVOPRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MVOP_FULL);
101*53ee8cc1Swenshuai.xi MSPIRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MSPI_FULL);
102*53ee8cc1Swenshuai.xi PWMRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PWM_FULL);
103*53ee8cc1Swenshuai.xi PWSRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PWS_FULL);
104*53ee8cc1Swenshuai.xi RTCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_RTC_FULL);
105*53ee8cc1Swenshuai.xi #ifdef CONFIG_MSTAR_UTPA2K_SAR_ENABLE
106*53ee8cc1Swenshuai.xi SARRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_SAR_FULL);
107*53ee8cc1Swenshuai.xi #endif
108*53ee8cc1Swenshuai.xi CECRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_CEC_FULL);
109*53ee8cc1Swenshuai.xi
110*53ee8cc1Swenshuai.xi ACERegisterToUtopia((FUtopiaOpen)MODULE_TYPE_ACE_FULL);
111*53ee8cc1Swenshuai.xi DLCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_DLC_FULL);
112*53ee8cc1Swenshuai.xi DMXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_DMX_FULL);
113*53ee8cc1Swenshuai.xi GFXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GFX_FULL);
114*53ee8cc1Swenshuai.xi GOPRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GOP_FULL);
115*53ee8cc1Swenshuai.xi PNLRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_PNL_FULL);
116*53ee8cc1Swenshuai.xi XCRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_XC_FULL);
117*53ee8cc1Swenshuai.xi
118*53ee8cc1Swenshuai.xi HDMIRXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_XC_FULL);
119*53ee8cc1Swenshuai.xi PQRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_XC_FULL);
120*53ee8cc1Swenshuai.xi
121*53ee8cc1Swenshuai.xi VDEC_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_VDEC_EX_FULL);
122*53ee8cc1Swenshuai.xi SYSRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_SYS_FULL);
123*53ee8cc1Swenshuai.xi UARTRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_UART_FULL);
124*53ee8cc1Swenshuai.xi TVENCODERRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_TVENCODER_FULL);
125*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_JPEG_EX
126*53ee8cc1Swenshuai.xi JPEG_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_NJPEG_EX_FULL);
127*53ee8cc1Swenshuai.xi #endif
128*53ee8cc1Swenshuai.xi #ifdef CONFIG_API_NJPEG_EX
129*53ee8cc1Swenshuai.xi NJPEG_EXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_NJPEG_EX_FULL);
130*53ee8cc1Swenshuai.xi #endif
131*53ee8cc1Swenshuai.xi GPDRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_GPD_FULL);
132*53ee8cc1Swenshuai.xi
133*53ee8cc1Swenshuai.xi DACRegisterToUtopia();
134*53ee8cc1Swenshuai.xi SEMRegisterToUtopia();
135*53ee8cc1Swenshuai.xi DSCMBRegisterToUtopia();
136*53ee8cc1Swenshuai.xi AESDMARegisterToUtopia((FUtopiaOpen)MODULE_TYPE_AESDMA_FULL);
137*53ee8cc1Swenshuai.xi HDMITXRegisterToUtopia((FUtopiaOpen)MODULE_TYPE_HDMITX_FULL);
138*53ee8cc1Swenshuai.xi CARegisterToUtopia();
139*53ee8cc1Swenshuai.xi CIPHERRegisterToUtopia();
140*53ee8cc1Swenshuai.xi
141*53ee8cc1Swenshuai.xi MIURegisterToUtopia((FUtopiaOpen)MODULE_TYPE_MIU_FULL);
142*53ee8cc1Swenshuai.xi
143*53ee8cc1Swenshuai.xi DVBSRegisterToUtopia();
144*53ee8cc1Swenshuai.xi DVBCRegisterToUtopia();
145*53ee8cc1Swenshuai.xi
146*53ee8cc1Swenshuai.xi MsOS_ReleaseMutex(psUtopiaPrivate->u32MutexID);
147*53ee8cc1Swenshuai.xi
148*53ee8cc1Swenshuai.xi return u32Ret;
149*53ee8cc1Swenshuai.xi }
150*53ee8cc1Swenshuai.xi
UtopiaOpen(MS_U32 u32ModuleID,void ** ppInstanceTmp,MS_U32 u32ModuleVersion,const void * const pAttribute)151*53ee8cc1Swenshuai.xi MS_U32 UtopiaOpen(MS_U32 u32ModuleID, void** ppInstanceTmp
152*53ee8cc1Swenshuai.xi , MS_U32 u32ModuleVersion, const void* const pAttribute)
153*53ee8cc1Swenshuai.xi {
154*53ee8cc1Swenshuai.xi UTOPIA_MODULE* psUtopiaModule = psUtopiaPrivate->psModuleHead;
155*53ee8cc1Swenshuai.xi UTOPIA_INSTANCE** ppInstance = (UTOPIA_INSTANCE**)ppInstanceTmp;
156*53ee8cc1Swenshuai.xi
157*53ee8cc1Swenshuai.xi while(psUtopiaModule != NULL)
158*53ee8cc1Swenshuai.xi {
159*53ee8cc1Swenshuai.xi if(psUtopiaModule->u32ModuleID == u32ModuleID)
160*53ee8cc1Swenshuai.xi {
161*53ee8cc1Swenshuai.xi int ret = psUtopiaModule->fpOpen((void**)ppInstance, pAttribute);
162*53ee8cc1Swenshuai.xi
163*53ee8cc1Swenshuai.xi if(ret)
164*53ee8cc1Swenshuai.xi {
165*53ee8cc1Swenshuai.xi printf("[utopia error] fail to create instance\n");
166*53ee8cc1Swenshuai.xi return ret;
167*53ee8cc1Swenshuai.xi }
168*53ee8cc1Swenshuai.xi
169*53ee8cc1Swenshuai.xi (*ppInstance)->psModule = psUtopiaModule;
170*53ee8cc1Swenshuai.xi (*ppInstance)->u32AppRequireModuleVersion = u32ModuleVersion;
171*53ee8cc1Swenshuai.xi return ret;
172*53ee8cc1Swenshuai.xi }
173*53ee8cc1Swenshuai.xi psUtopiaModule = psUtopiaModule->psNext;
174*53ee8cc1Swenshuai.xi }
175*53ee8cc1Swenshuai.xi
176*53ee8cc1Swenshuai.xi printf("\033[35mFunction = %s, Line = %d, UtopiaOpen strange failed\033[m\n", __FUNCTION__, __LINE__);
177*53ee8cc1Swenshuai.xi
178*53ee8cc1Swenshuai.xi return UTOPIA_STATUS_FAIL;
179*53ee8cc1Swenshuai.xi }
180*53ee8cc1Swenshuai.xi
UtopiaIoctl(void * pInstanceTmp,MS_U32 u32Cmd,void * const pArgs)181*53ee8cc1Swenshuai.xi MS_U32 UtopiaIoctl(void* pInstanceTmp, MS_U32 u32Cmd, void* const pArgs)
182*53ee8cc1Swenshuai.xi {
183*53ee8cc1Swenshuai.xi UTOPIA_INSTANCE* pInstance = (UTOPIA_INSTANCE*)pInstanceTmp;
184*53ee8cc1Swenshuai.xi /* check param. */
185*53ee8cc1Swenshuai.xi if (pInstance == NULL)
186*53ee8cc1Swenshuai.xi {
187*53ee8cc1Swenshuai.xi printf("[utopia error] instance pointer should not be null\n");
188*53ee8cc1Swenshuai.xi return UTOPIA_STATUS_FAIL;
189*53ee8cc1Swenshuai.xi }
190*53ee8cc1Swenshuai.xi
191*53ee8cc1Swenshuai.xi return TO_INSTANCE_PTR(pInstance)->psModule->fpIoctl(pInstance, u32Cmd, pArgs);
192*53ee8cc1Swenshuai.xi }
193*53ee8cc1Swenshuai.xi
UtopiaClose(void * pInstantTmp)194*53ee8cc1Swenshuai.xi MS_U32 UtopiaClose(void* pInstantTmp)
195*53ee8cc1Swenshuai.xi {
196*53ee8cc1Swenshuai.xi UTOPIA_INSTANCE* pInstant = (UTOPIA_INSTANCE*)pInstantTmp;
197*53ee8cc1Swenshuai.xi
198*53ee8cc1Swenshuai.xi printf("\n[utopia info] close module id: %s\n",
199*53ee8cc1Swenshuai.xi moduleNames[pInstant->psModule->u32ModuleID]);
200*53ee8cc1Swenshuai.xi
201*53ee8cc1Swenshuai.xi UTOPIA_MODULE* psUtopiaModule = psUtopiaPrivate->psModuleHead;
202*53ee8cc1Swenshuai.xi while(psUtopiaModule != NULL)
203*53ee8cc1Swenshuai.xi {
204*53ee8cc1Swenshuai.xi if(psUtopiaModule->u32ModuleID == pInstant->psModule->u32ModuleID)
205*53ee8cc1Swenshuai.xi {
206*53ee8cc1Swenshuai.xi return psUtopiaModule->fpClose(pInstant);
207*53ee8cc1Swenshuai.xi }
208*53ee8cc1Swenshuai.xi psUtopiaModule = psUtopiaModule->psNext;
209*53ee8cc1Swenshuai.xi }
210*53ee8cc1Swenshuai.xi return 0;
211*53ee8cc1Swenshuai.xi }
212*53ee8cc1Swenshuai.xi
213