1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvSYS.c
98 /// @brief System Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
103 //-------------------------------------------------------------------------------------------------
104 // Include Files
105 //-------------------------------------------------------------------------------------------------
106 #if defined (MSOS_TYPE_LINUX)
107 #include <errno.h>
108 #include <pthread.h>
109 #include <sys/ioctl.h>
110 #include <fcntl.h>
111 #include <unistd.h>
112 #endif
113
114 #include "MsCommon.h"
115 #include "MsVersion.h"
116 #ifndef MSOS_TYPE_LINUX_KERNEL
117 #include <string.h>
118 #endif
119 #include "regCHIP.h"
120 #include "halCHIP.h"
121 #include "drvSYS.h"
122 #include "drvMMIO.h"
123 #include "halSYS.h"
124
125 #include "tee_client_api.h"
126 #include "tee_ioc.h"
127 //#include "teec_trace.h"
128 #include "utopia_dapi.h"
129 #include "drvSYS_priv.h"
130 #include "utopia.h"
131
132 #include "label.h"
133
134
135 #include "drvMIU.h"
136 #include "drvMBX.h"
137 #include "apiMBX.h"
138 #include "drvBDMA.h"
139 #include "drvSEM.h"
140 #include "ULog.h"
141
142 //-------------------------------------------------------------------------------------------------
143 // Driver Compiler Options
144 //-------------------------------------------------------------------------------------------------
145
146
147 //-------------------------------------------------------------------------------------------------
148 // Local Defines
149 //-------------------------------------------------------------------------------------------------
150
151 #ifndef MS_NOSAPI
152 #define SYS_DIS_ALL_INT(x) { x = MsOS_DisableAllInterrupts(); }
153 #define SYS_RES_ALL_INT(x) { MsOS_RestoreAllInterrupts(x); }
154 #else // MS_NOSAPI
155 #define SYS_DIS_ALL_INT(x) { }
156 #define SYS_RES_ALL_INT(x) { }
157 #endif // MS_NOSAPI
158
159 #define TAG_SYS "SYS"
160
161 //-------------------------------------------------------------------------------------------------
162 // Local Structurs
163 //-------------------------------------------------------------------------------------------------
164
165
166 //-------------------------------------------------------------------------------------------------
167 // Global Variables
168 //-------------------------------------------------------------------------------------------------
169
170
171 //-------------------------------------------------------------------------------------------------
172 // Local Variables
173 //-------------------------------------------------------------------------------------------------
174 static MSIF_Version _sysVersion =
175 {
176 .DDI = { SYS_DRV_VERSION, },
177 };
178
179 static SYS_Status _sysStatus =
180 {
181 .WDT_Active = FALSE,
182 };
183
184 const char* _Change = "$Change$";
185 const char* _Revision = "$Revision$";
186 static MS_U8 u8IsSysInit = 0;
187
188 #ifdef CONFIG_MSTAR_DVFS_ENABLE
189 MS_U32 g_bDvfsInitFlag = 0;
190 #endif
191
192 SYS_IO_PROC g_SysIoProc =
193 {
194 .SysSwI2CReadBytes = 0,
195 .SysSwI2CWriteBytes = 0,
196 };
197
198 static MS_U8 u8IsGlobalInit = 0;
199 static MS_S32 s32SysMutexId = -1;
200 //-------------------------------------------------------------------------------------------------
201 // Debug Functions
202 //-------------------------------------------------------------------------------------------------
203 #define SYS_DBG_FUNC() if (_gu8DbgLevel >= E_SYS_DBGLV_ALL) \
204 {MS_DEBUG_MSG(ULOGD(TAG_SYS, "\t==== %s ====\n", __FUNCTION__));}
205 #define SYS_DBG_INFO(x, args...) if (_gu8DbgLevel >= E_SYS_DBGLV_INFO ) \
206 {MS_DEBUG_MSG(ULOGI(TAG_SYS, x, ##args));}
207 #define SYS_DBG_ERR(x, args...) if (_gu8DbgLevel >= E_SYS_DBGLV_ERR_ONLY) \
208 {MS_DEBUG_MSG(ULOGE(TAG_SYS, x, ##args));}
209 #if defined (MSOS_TYPE_LINUX)
210
211 //prevetn MDrv_SYS_GlobalInit called twice
212 static pthread_mutex_t teec_mutex = PTHREAD_MUTEX_INITIALIZER;
213
214 #ifdef MS_DEBUG
215 #include "string.h"
216 #define PTH_RET_CHK(_pf_) \
217 ({ \
218 int r = _pf_; \
219 if ((r != 0) && (r != ETIMEDOUT)) \
220 fprintf(stderr, "[PTHREAD] %s: %d: %s: %s\n", __FILE__, __LINE__, #_pf_, strerror(r)); \
221 r; \
222 })
223 #else
224 #define PTH_RET_CHK(_pf_) _pf_
225 #endif
226 #endif
227
228 static MS_U8 _gu8DbgLevel = E_SYS_DBGLV_ERR_ONLY;
229
230 //-------------------------------------------------------------------------------------------------
231 // Local Functions
232 //-------------------------------------------------------------------------------------------------
233 E_SYS_ReturnValue _MDrv_SYS_GetXcByPartConfg (MS_U32 u32SourceType, SYS_XC_BYPART_TIMING_t *stInfo, MS_BOOL *retEn);
234 E_SYS_ReturnValue _MDrv_SYS_XcInputMapping (MS_U32 u32SourceType, E_SYS_SOURCE_TYPE *retSrcType);
235 E_SYS_ReturnValue _MDrv_SYS_XcTimingMapping (MS_U32 u32Width, MS_U32 u32Height, MS_U32 u32FrameRate, E_SYS_INPUT_TIMING *retTimingType);
236
237 //-------------------------------------------------------------------------------------------------
238 // Global Functions
239 //-------------------------------------------------------------------------------------------------
240 void* pInstantSys = NULL;
241 void* pAttributeSys = NULL;
242
243 //-------------------------------------------------------------------------------------------------
244 /// System initialzation
245 /// @return TRUE(Success), FALSE(Failure)
246 //-------------------------------------------------------------------------------------------------
MDrv_SYS_Init(void)247 MS_BOOL MDrv_SYS_Init(void)
248 {
249 MS_PHY u32size;
250 MS_VIRT u32addr;
251
252 if (!u8IsSysInit)
253 {
254 if(UtopiaOpen(MODULE_SYS, &pInstantSys, 0, pAttributeSys) != UTOPIA_STATUS_SUCCESS)
255 {
256 ULOGE(TAG_SYS, "Open SYS fail\n");
257 return FALSE;
258 }
259
260 if(!MDrv_MMIO_GetBASE(&u32addr, &u32size, MS_MODULE_PM))
261 {
262 SYS_DBG_INFO("%s Get IOMAP Base faill!\n",__FUNCTION__);
263 return 0;
264 }
265 else
266 {
267 SYS_Init(u32addr);
268 }
269
270 //
271 // Init for efuse usage
272 //
273 if(!MDrv_MMIO_GetBASE(&u32addr, &u32size, MS_MODULE_EFUSE))
274 {
275 // efuse not implemented
276 }
277 else
278 {
279 HAL_SYS_SetEfuseIOMapBase(u32addr);
280 }
281
282
283 if(!MDrv_MMIO_GetBASE(&u32addr, &u32size, MS_MODULE_OTP2))
284 {
285 // efuse not implemented
286 }
287 else
288 {
289 HAL_SYS_SetOtpIOMapBase(u32addr);
290 }
291 u8IsSysInit = 1;
292 }
293
294
295 return TRUE;
296 }
297 #if defined(MSOS_TYPE_LINUX_KERNEL)
298 EXPORT_SYMBOL(MDrv_SYS_Init);
299 #endif
300
301
302 #ifdef MSOS_TYPE_LINUX_KERNEL
MDrv_SYS_GlobalInit(void)303 MS_BOOL MDrv_SYS_GlobalInit(void)
304 {
305 MS_BOOL bRet = TRUE;
306 /* Create mutex. */
307 if ((s32SysMutexId == -1) &&
308 ((s32SysMutexId = MsOS_CreateMutex(E_MSOS_FIFO, "Mutex_drvSYS", MSOS_PROCESS_SHARED)) < 0))
309 {
310 return FALSE;
311 }
312
313
314 MsOS_ObtainMutex(s32SysMutexId, MSOS_WAIT_FOREVER);
315 /* Check init. */
316 if (u8IsGlobalInit)
317 {
318 goto MDrv_SYS_GlobalInit_End;
319 }
320
321 /* Init. */
322 if (!MDrv_MMIO_Init() || !MsOS_Init() ||
323 !MsOS_MPool_Init() || !MDrv_SEM_Init() ||
324 !MDrv_MIU_Init() || !MDrv_SYS_Init())
325 {
326 bRet = FALSE;
327 goto MDrv_SYS_GlobalInit_End;
328 }
329
330 #if defined(ANDROID)
331 MApi_MBX_Init(E_MBX_CPU_MIPS, E_MBX_ROLE_HK, 5000);
332 MApi_MBX_Enable(TRUE);
333 #endif
334
335 /* Init done. */
336 u8IsGlobalInit = 1;
337
338 MDrv_SYS_GlobalInit_End:
339 MsOS_ReleaseMutex(s32SysMutexId);
340 return bRet;
341 }
342 #else
343
344 #if defined (MSOS_TYPE_LINUX)
teec_mutex_lock(pthread_mutex_t * mu)345 static void teec_mutex_lock(pthread_mutex_t *mu)
346 {
347 int e = pthread_mutex_lock(mu);
348
349 if (e != 0)
350 printf("pthread_mutex_lock failed: %d\n", e);
351 }
352
teec_mutex_unlock(pthread_mutex_t * mu)353 static void teec_mutex_unlock(pthread_mutex_t *mu)
354 {
355 int e = pthread_mutex_unlock(mu);
356
357 if (e != 0)
358 printf("pthread_mutex_unlock failed: %d\n", e);
359 }
360
teec_resetTeeCmd(struct tee_cmd_io * cmd)361 static void teec_resetTeeCmd(struct tee_cmd_io *cmd)
362 {
363 cmd->fd_sess = -1;
364 cmd->cmd = 0;
365 cmd->uuid = NULL;
366 cmd->origin = TEEC_ORIGIN_API;
367 cmd->err = TEEC_SUCCESS;
368 cmd->data = NULL;
369 cmd->data_size = 0;
370 cmd->op = NULL;
371 }
372
373 /*
374 * This function initializes a new TEE Context, connecting this Client
375 * application to the TEE identified by the name name.
376 *
377 * name == NULL will give the default TEE.
378 */
MDrv_SYS_TEEC_InitializeContext(const char * name,TEEC_Context * context)379 MS_U32 MDrv_SYS_TEEC_InitializeContext(const char *name, TEEC_Context *context)
380 {
381 int name_size = 0;
382 const char* _name = name;
383
384 ULOGW (TAG_SYS, "TEEC initial Context: %s\n", name);
385
386 if (context == NULL) {
387 ULOGE (TAG_SYS,"\033[1;31m[%s] NULL context\033[m\n", __FUNCTION__);
388 return TEEC_ERROR_BAD_PARAMETERS;
389 }
390
391 /*
392 * Specification says that when no name is provided it should fall back
393 * on a predefined TEE.
394 */
395 if (name == NULL) {
396 ULOGE (TAG_SYS,"\033[1;31m[%s] Name null\033[m\n", __FUNCTION__);
397 return TEEC_ERROR_BAD_PARAMETERS; /* Device name truncated */
398 }
399
400 name_size = snprintf(context->devname, TEEC_MAX_DEVNAME_SIZE,
401 "/dev/%s", _name);
402
403 if (name_size >= TEEC_MAX_DEVNAME_SIZE) {
404 ULOGE (TAG_SYS,"\033[1;31m[%s] Name size over %u\033[m\n", __FUNCTION__, TEEC_MAX_DEVNAME_SIZE);
405 return TEEC_ERROR_BAD_PARAMETERS; /* Device name truncated */
406 }
407
408 context->fd = open(context->devname, O_RDWR);
409 if (context->fd == -1) {
410 ULOGE (TAG_SYS, "\033[1;31m[%s]open %s fail \033[m\n", __FUNCTION__, context->devname);
411 return TEEC_ERROR_ITEM_NOT_FOUND;
412 }
413 return TEEC_SUCCESS;
414 }
415
416 /*
417 * This function opens a new Session between the Client application and the
418 * specified TEE application.
419 *
420 * Only connection_method == TEEC_LOGIN_PUBLIC is supported connection_data and
421 * operation shall be set to NULL.
422 */
MDrv_SYS_TEEC_Open(TEEC_Context * context,TEEC_Session * session,const TEEC_UUID * destination,MS_U32 connection_method,const void * connection_data,TEEC_Operation * operation,MS_U32 * error_origin)423 MS_U32 MDrv_SYS_TEEC_Open(TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, MS_U32 connection_method, const void *connection_data, TEEC_Operation *operation, MS_U32 *error_origin)
424 {
425 TEEC_Operation dummy_op;
426 uint32_t origin = TEEC_ORIGIN_API;
427 TEEC_Result res = TEEC_SUCCESS;
428 (void)connection_data;
429 struct tee_cmd_io cmd;
430
431 memset(&dummy_op, 0, sizeof(TEEC_Operation));
432 memset(&cmd, 0, sizeof(struct tee_cmd_io));
433
434 if (session != NULL)
435 session->fd = -1;
436
437 if ((context == NULL) || (session == NULL)) {
438 ULOGE (TAG_SYS, "\033[1;31m[%s] Null context or session\033[m\n", __FUNCTION__);
439 res = TEEC_ERROR_BAD_PARAMETERS;
440 goto error;
441 }
442
443 if (connection_method != TEEC_LOGIN_PUBLIC) {
444 ULOGE (TAG_SYS, "\033[1;31m[%s] connection_method not public\033[m\n", __FUNCTION__);
445 res = TEEC_ERROR_NOT_SUPPORTED;
446 goto error;
447 }
448
449 teec_resetTeeCmd(&cmd);
450 cmd.uuid = (TEEC_UUID *)destination;
451
452 if (operation == NULL) {
453 /*
454 * The code here exist because Global Platform API states that
455 * it is allowed to give operation as a NULL pointer. In kernel
456 * and secure world we in most cases don't want this to be NULL,
457 * hence we use this dummy operation when a client doesn't
458 * provide any operation.
459 */
460 memset(&dummy_op, 0, sizeof(TEEC_Operation));
461 operation = &dummy_op;
462 }
463
464 cmd.op = operation;
465
466 errno = 0;
467 if (ioctl(context->fd, TEE_OPEN_SESSION_IOC, &cmd) != 0) {
468 ULOGD(TAG_SYS, "Ioctl(TEE_OPEN_SESSION_IOC) failed! (%s) err %08x ori %08x\n",
469 strerror(errno), cmd.err, cmd.origin);
470 if (cmd.origin)
471 origin = cmd.origin;
472 else
473 origin = TEEC_ORIGIN_COMMS;
474 if (cmd.err)
475 res = cmd.err;
476 else
477 res = TEEC_ERROR_COMMUNICATION;
478 goto error;
479 }
480 session->fd = cmd.fd_sess;
481
482 if (cmd.err != 0) {
483 ULOGD(TAG_SYS, "open session to TA UUID %x %x %x failed\n",
484 destination->timeLow,
485 destination->timeMid, destination->timeHiAndVersion);
486 }
487 origin = cmd.origin;
488 res = cmd.err;
489
490 error:
491 // printf("**** res=0x%08x, org=%d, seeid=%d ***\n", res, origin, cmd.fd_sess)
492
493 /*
494 * We do this check at the end instead of checking on every place where
495 * we set the error origin.
496 */
497 if (res != TEEC_SUCCESS) {
498 if (session != NULL && session->fd != -1) {
499 close(session->fd);
500 session->fd = -1;
501 }
502 }
503
504 if (error_origin != NULL)
505 *error_origin = origin;
506
507 return res;
508 }
509
510 /*
511 * This function destroys an initialized TEE Context, closing the connection
512 * between the Client and the TEE.
513 * The function implementation MUST do nothing if context is NULL
514 */
MDrv_SYS_TEEC_FinalizeContext(TEEC_Context * context)515 void MDrv_SYS_TEEC_FinalizeContext(TEEC_Context *context)
516 {
517 if (context)
518 close(context->fd);
519 }
520
521 /*
522 * This function closes a session which has been opened with a TEE
523 * application.
524 */
MDrv_SYS_TEEC_Close(TEEC_Session * session)525 void MDrv_SYS_TEEC_Close(TEEC_Session *session)
526 {
527 if (session == NULL)
528 return;
529
530 close(session->fd);
531 }
532
533 /*
534 * Invokes a TEE command (secure service, sub-PA or whatever).
535 */
MDrv_SYS_TEEC_InvokeCmd(TEEC_Session * session,MS_U32 cmd_id,TEEC_Operation * operation,MS_U32 * error_origin)536 MS_U32 MDrv_SYS_TEEC_InvokeCmd(TEEC_Session *session, MS_U32 cmd_id, TEEC_Operation *operation, MS_U32 *error_origin)
537 {
538 //INMSG("session: [%p], cmd_id: [%d]", session, cmd_id);
539 struct tee_cmd_io cmd;
540 TEEC_Operation dummy_op;
541 TEEC_Result result = TEEC_SUCCESS;
542 uint32_t origin = TEEC_ORIGIN_API;
543
544 memset(&dummy_op, 0, sizeof(TEEC_Operation));
545 memset(&cmd, 0, sizeof(struct tee_cmd_io));
546
547 if (session == NULL) {
548 ULOGE (TAG_SYS, "\033[1;31m[%s] Null session\033[m\n", __FUNCTION__);
549 origin = TEEC_ORIGIN_API;
550 result = TEEC_ERROR_BAD_PARAMETERS;
551 goto error;
552 }
553
554 if (operation == NULL) {
555 /*
556 * The code here exist because Global Platform API states that
557 * it is allowed to give operation as a NULL pointer. In kernel
558 * and secure world we in most cases don't want this to be NULL,
559 * hence we use this dummy operation when a client doesn't
560 * provide any operation.
561 */
562 memset(&dummy_op, 0, sizeof(TEEC_Operation));
563 operation = &dummy_op;
564 }
565
566 teec_mutex_lock(&teec_mutex);
567 operation->session = session;
568 teec_mutex_unlock(&teec_mutex);
569
570 teec_resetTeeCmd(&cmd);
571
572 cmd.cmd = cmd_id;
573 cmd.op = operation;
574
575 if (ioctl(session->fd, TEE_INVOKE_COMMAND_IOC, &cmd) != 0)
576 ULOGD(TAG_SYS, "Ioctl(TEE_INVOKE_COMMAND_IOC) failed! (%s)\n",strerror(errno));
577
578 if (operation != NULL) {
579 teec_mutex_lock(&teec_mutex);
580
581 operation->session = NULL;
582
583 teec_mutex_unlock(&teec_mutex);
584 }
585
586 origin = cmd.origin;
587 result = cmd.err;
588
589 error:
590
591 if (error_origin != NULL)
592 *error_origin = origin;
593
594 ULOGD(TAG_SYS, "result:%d\n",result);
595 return result;
596 }
597 #endif
598
MDrv_SYS_GlobalInit(void)599 MS_BOOL MDrv_SYS_GlobalInit(void)
600 {
601 MS_BOOL bRet = TRUE;
602
603 #if defined (MSOS_TYPE_LINUX)
604 PTH_RET_CHK(pthread_mutex_lock(&_SYS_Global_Init_Mutex));
605 if(u8IsInit)
606 {
607 ULOGD(TAG_SYS, "%s successfully called one time,call %s again in the same process will cause error",__func__,__func__);
608 PTH_RET_CHK(pthread_mutex_unlock(&_SYS_Global_Init_Mutex));
609 return TRUE;
610 }
611 #endif
612
613 #if defined (ANDROID)
614 bRet = MDrv_MMIO_Init();
615 if(bRet == FALSE)
616 goto err_return;
617
618 bRet = MsOS_Init();
619 if(bRet == FALSE)
620 goto err_return;
621
622 MsOS_MPool_Init();
623
624 bRet = MDrv_SEM_Init();
625 if(bRet == FALSE)
626 goto err_return;
627
628 bRet = MDrv_MIU_Init();
629 if(bRet == FALSE)
630 goto err_return;
631
632 bRet = MDrv_SYS_Init();
633 if(bRet == FALSE)
634 goto err_return;
635
636 MApi_MBX_Init(E_MBX_CPU_MIPS, E_MBX_ROLE_HK, 5000);
637 MApi_MBX_Enable(TRUE);
638
639 goto pass;
640
641 err_return:
642 PTH_RET_CHK(pthread_mutex_unlock(&_SYS_Global_Init_Mutex));
643 return bRet;
644 #else
645 if(MDrv_MMIO_Init() == FALSE)
646 bRet = FALSE;
647 if(MsOS_Init() == FALSE)
648 bRet = FALSE;
649 if(MsOS_MPool_Init() == FALSE)
650 bRet = FALSE;
651 if(MDrv_SEM_Init() == FALSE)
652 bRet = FALSE;
653 if(MDrv_MIU_Init() == FALSE)
654 bRet = FALSE;
655 if(MDrv_SYS_Init() == FALSE)
656 bRet = FALSE;
657
658 goto pass;
659 #endif
660
661 pass:
662 #if defined (MSOS_TYPE_LINUX)
663 u8IsInit = 1;
664 PTH_RET_CHK(pthread_mutex_unlock(&_SYS_Global_Init_Mutex));
665 #endif
666
667 ULOGD(TAG_SYS, "%s finished", __func__);
668 return bRet;
669 }
670 #endif //#ifndef MSOS_TYPE_LINUX_KERNEL
671
672 #if defined(MSOS_TYPE_LINUX_KERNEL)
673 EXPORT_SYMBOL(MDrv_SYS_GlobalInit);
674 #endif
675
676 //-------------------------------------------------------------------------------------------------
677 /// Get system information
678 /// @return Chip Revision ID
679 //-------------------------------------------------------------------------------------------------
MDrv_SYS_GetChipRev(void)680 MS_U8 MDrv_SYS_GetChipRev(void)
681 {
682 return SYS_GetChipRev();
683 }
684
685 //-------------------------------------------------------------------------------------------------
686 /// Get system information
687 /// @return Chip Device ID
688 //-------------------------------------------------------------------------------------------------
MDrv_SYS_GetChipID(void)689 MS_U16 MDrv_SYS_GetChipID(void)
690 {
691 return SYS_GetChipID();
692 }
693
694 //-------------------------------------------------------------------------------------------------
695 /// Get system information
696 /// @return @ref SYS_Info
697 //-------------------------------------------------------------------------------------------------
MDrv_SYS_GetInfo(void)698 const SYS_Info* MDrv_SYS_GetInfo(void)
699 {
700 return SYS_GetInfo();
701 }
702
MDrv_SYS_GetLibVer(void)703 const MSIF_Version* MDrv_SYS_GetLibVer(void)
704 {
705 return (const MSIF_Version*)(&_sysVersion);
706 }
707
MDrv_SYS_GetStatus(SYS_Status * pStatus)708 MS_BOOL MDrv_SYS_GetStatus(SYS_Status *pStatus)
709 {
710 memcpy(pStatus, &_sysStatus, sizeof(SYS_Status));
711 return TRUE;
712 }
713
MDrv_SYS_GetSoftwareVersion(MS_SW_VERSION_INFO * pSoftwareVersionInfo)714 void MDrv_SYS_GetSoftwareVersion(MS_SW_VERSION_INFO *pSoftwareVersionInfo)
715 {
716 memset(pSoftwareVersionInfo, '\0', sizeof(MS_SW_VERSION_INFO));
717
718 strncpy(
719 pSoftwareVersionInfo->MajorVersion,
720 (char *) _sysVersion.DDI.version,
721 sizeof(_sysVersion.DDI.version)
722 );
723
724 strncpy(
725 pSoftwareVersionInfo->MinorVersion,
726 (char *) _sysVersion.DDI.build,
727 sizeof(_sysVersion.DDI.build)
728 );
729
730 #ifdef UTOPIA_BSP_VERSION
731 snprintf(
732 pSoftwareVersionInfo->UtopiaBspVersion,
733 sizeof(pSoftwareVersionInfo->UtopiaBspVersion),
734 "%d",
735 UTOPIA_BSP_VERSION
736 );
737 #endif
738
739 #ifdef SW_VERSION_API_SYS
740 snprintf(
741 pSoftwareVersionInfo->ChangeList_API,
742 sizeof(pSoftwareVersionInfo->ChangeList_API),
743 "%d",
744 SW_VERSION_API_SYS
745 );
746 #endif
747
748 #ifdef SW_VERSION_DRV_SYS
749 snprintf(
750 pSoftwareVersionInfo->ChangeList_DRV,
751 sizeof(pSoftwareVersionInfo->ChangeList_DRV),
752 "%d",
753 SW_VERSION_DRV_SYS
754 );
755 #endif
756
757 #ifdef SW_VERSION_HAL_SYS
758 snprintf(
759 pSoftwareVersionInfo->ChangeList_HAL,
760 sizeof(pSoftwareVersionInfo->ChangeList_HAL),
761 "%d",
762 SW_VERSION_HAL_SYS
763 );
764 #endif
765
766 return;
767 }
768
769 //-------------------------------------------------------------------------------------------------
770 /// Enable/Disable watchdog timer
771 /// @param bEnable \b IN: Enable/disable
772 /// @return None
773 //-------------------------------------------------------------------------------------------------
MDrv_SYS_WDTEnable(MS_BOOL bEnable)774 void MDrv_SYS_WDTEnable(MS_BOOL bEnable)
775 {
776 if (bEnable)
777 {
778 #if 0 //TODO: Utopia & HAL
779 WDT_REG(REG_WDT_DISABLEWORD_L) = 0;
780 WDT_REG(REG_WDT_DISABLEWORD_H) = 0;
781 #endif
782 _sysStatus.WDT_Active = TRUE;
783 }
784 else
785 {
786 #if 0 //TODO: Utopia & HAL
787 WDT_REG(REG_WDT_DISABLEWORD_L) = 0xaa55;
788 WDT_REG(REG_WDT_DISABLEWORD_H) = 0x55aa;
789 #endif
790 _sysStatus.WDT_Active = FALSE;
791 }
792 }
793
794
795 //-------------------------------------------------------------------------------------------------
796 /// Clear watchdog timer
797 /// @return None
798 /// @note The monitor task should call this API regularly
799 //-------------------------------------------------------------------------------------------------
MDrv_SYS_WDTClear(void)800 void MDrv_SYS_WDTClear(void)
801 {
802 #if 0 //TODO: Utopia & HAL
803 WDT_REG(REG_WDT_CLEAR_STATUS) = 0x0001;
804 #endif
805 }
806
807
808 //-------------------------------------------------------------------------------------------------
809 /// Query whether Watchdog timer was triggered last time and clear the last status
810 /// @return @ref MS_BOOL
811 //-------------------------------------------------------------------------------------------------
MDrv_SYS_WDTLastStatus(void)812 MS_BOOL MDrv_SYS_WDTLastStatus(void)
813 {
814 MS_BOOL bRet = FALSE;
815
816 #if 0 //TODO: Utopia & HAL
817 if (WDT_REG(REG_WDT_CLEAR_STATUS) & 0x0004)
818 {
819 bRet = TRUE;
820 }
821
822 WDT_REG(REG_WDT_CLEAR_STATUS) = 0x0002;
823 #endif
824
825 return bRet;
826 }
827
828
829 //-------------------------------------------------------------------------------------------------
830 /// Set tigger time of watchdog timer
831 /// @param u32Ms \b IN: msec (350~357564 ms at 12 MHz; 146~148958 ms at 28.8 MHz)
832 /// @return None
833 //-------------------------------------------------------------------------------------------------
MDrv_SYS_WDTSetTime(MS_U32 u32Ms)834 void MDrv_SYS_WDTSetTime(MS_U32 u32Ms)
835 {
836 #if 0 //TODO: Utopia & HAL
837 WDT_REG(REG_WDT_SETTIME) = (u32Ms * (XTAL_CLOCK_FREQ / 1000)) >> 22; //1 ~ 0x3FF
838 #endif
839 }
840
841
842 //-------------------------------------------------------------------------------------------------
843 /// Reset whole chip
844 /// @return None
845 //-------------------------------------------------------------------------------------------------
MDrv_SYS_ResetChip(void)846 void MDrv_SYS_ResetChip(void)
847 {
848 #if 0 //TODO: Utopia & HAL
849 WDT_REG(REG_WDT_PROGRAMKEY_L) = 0x5678;
850 WDT_REG(REG_WDT_PROGRAMKEY_H) = 0x1234;
851 WDT_REG(REG_WDT_ENABLEMCURESET) = 0;
852 WDT_REG(REG_WDT_DISABLEWORD_L) = 0;
853 WDT_REG(REG_WDT_DISABLEWORD_H) = 0;
854 WDT_REG(REG_WDT_SETTIME) = 0;
855 while(1);
856 #endif
857 }
858
859
860 //-------------------------------------------------------------------------------------------------
861 /// Reset CPU only
862 /// @return None
863 //-------------------------------------------------------------------------------------------------
MDrv_SYS_ResetCPU(void)864 void MDrv_SYS_ResetCPU(void)
865 {
866 #if 0 //TODO: Utopia & HAL
867 #ifndef MS_NOSAPI
868 MS_U32 u32OldIntr;
869 #endif
870
871 SYS_DIS_ALL_INT(u32OldIntr);
872
873 SYS_ResetCPU();
874
875 // SYS_RES_ALL_INT(u32OldInts)
876 while(1);
877 #endif
878 }
879
880
TINY_SYS_Reset(void)881 void TINY_SYS_Reset(void)
882 {
883 #if 0 //TODO: Utopia & HAL
884 SYS_ResetCPU();
885 while (1);
886 #endif
887 }
888
889 //-------------------------------------------------------------------------------------------------
890 /// Set RFAGC and TAGC PAD MUX
891 /// @return None
892 //-------------------------------------------------------------------------------------------------
MDrv_SYS_SetAGCPadMux(SYS_AGC_PAD_SET eAgcPadMux)893 void MDrv_SYS_SetAGCPadMux(SYS_AGC_PAD_SET eAgcPadMux)
894 {
895 HAL_SYS_SetAGCPadMux(eAgcPadMux);
896 }
897
MDrv_SYS_SetPCMCardDetectMode(SYS_PCM_CD_MODE ePCMCDMode)898 MS_BOOL MDrv_SYS_SetPCMCardDetectMode(SYS_PCM_CD_MODE ePCMCDMode)
899 {
900 MS_BOOL ret = FALSE;
901
902 if(ePCMCDMode >= E_PCM_CD_MAX)
903 return ret;
904 ret = HAL_SYS_SetPCMCardDetectMode(ePCMCDMode);
905 return ret;
906 }
907
MDrv_SYS_DisableDebugPort(void)908 MS_BOOL MDrv_SYS_DisableDebugPort(void)
909 {
910 return HAL_SYS_DisableDebugPort();
911 }
912
MDrv_SYS_EnableDebugPort(void)913 MS_BOOL MDrv_SYS_EnableDebugPort(void)
914 {
915 return HAL_SYS_EnableDebugPort();
916 }
917
MDrv_SYS_SetPadMux(SYS_PAD_MUX_SET ePadMuxType,SYS_PAD_SEL ePadSel)918 MS_BOOL MDrv_SYS_SetPadMux(SYS_PAD_MUX_SET ePadMuxType,SYS_PAD_SEL ePadSel)
919 {
920 MS_BOOL ret = FALSE;
921 if((ePadMuxType >= E_PAD_SET_MAX) || (ePadSel >= E_PAD_SEL_MAX))
922 return ret;
923 ret = HAL_SYS_SetPadMux(ePadMuxType,ePadSel);
924 return ret;
925 }
926
MDrv_SYS_PackMode(void)927 MS_BOOL MDrv_SYS_PackMode(void)
928 {
929 #ifdef CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_STRUCT_PACKED
930 return TRUE;
931 #else
932 return FALSE;
933 #endif
934 }
935
MDrv_SYS_SetTSOutClockPhase(MS_U16 u16Val)936 MS_BOOL MDrv_SYS_SetTSOutClockPhase(MS_U16 u16Val)
937 {
938 return HAL_SYS_SetTSOutClockPhase(u16Val);
939 }
940
MDrv_SYS_SetTSClockPhase(SYS_PAD_MUX_SET ePadMuxType,MS_U16 u16Val)941 MS_BOOL MDrv_SYS_SetTSClockPhase(SYS_PAD_MUX_SET ePadMuxType, MS_U16 u16Val)
942 {
943 return HAL_SYS_SetTSClockPhase(ePadMuxType, u16Val);
944 }
945
MDrv_SYS_PadMuxTableSuspend(void)946 MS_BOOL MDrv_SYS_PadMuxTableSuspend(void)
947 {
948 return HAL_SYS_PadMuxTableSuspend();
949 }
950
MDrv_SYS_PadMuxTableResume(void)951 MS_BOOL MDrv_SYS_PadMuxTableResume(void)
952 {
953 return HAL_SYS_PadMuxTableResume();
954 }
955 //-------------------------------------------------------------------------------------------------
956 /// @brief \b Function \b Name: MDrv_SYS_SetDbgLevel
957 /// @brief \b Function \b Description: Set debug level for debug message
958 /// @param eLevel \b IN: E_SYS_DBGLV_NONE/E_SYS_DBGLV_ERR_ONLY/E_SYS_DBGLV_INFO/E_SYS_DBGLV_ALL
959 /// @return \b SYS_Result
960 //-------------------------------------------------------------------------------------------------
MDrv_SYS_SetDbgLevel(SYS_DbgLv eLevel)961 void MDrv_SYS_SetDbgLevel(SYS_DbgLv eLevel)
962 {
963 _gu8DbgLevel = eLevel;
964 }
965
MDrv_SYS_VIFWriteByteByVDMbox(MS_U32 u32Reg,MS_U8 u8Val)966 void MDrv_SYS_VIFWriteByteByVDMbox(MS_U32 u32Reg, MS_U8 u8Val)
967 {
968 SYS_VIF_WriteByteByVDMbox(u32Reg,u8Val);
969 }
970
MDrv_SYS_VIFWriteByteMaskByVDMbox(MS_U32 u32Reg,MS_U8 u8Val,MS_U8 u8Mask)971 void MDrv_SYS_VIFWriteByteMaskByVDMbox(MS_U32 u32Reg, MS_U8 u8Val, MS_U8 u8Mask)
972 {
973 SYS_VIF_WriteByteMaskByVDMbox(u32Reg,u8Val,u8Mask);
974 }
MDrv_SYS_VIFWriteRegBitByVDMbox(MS_U32 u32Reg,MS_U8 bEnable,MS_U8 u8Mask)975 void MDrv_SYS_VIFWriteRegBitByVDMbox(MS_U32 u32Reg, MS_U8 bEnable, MS_U8 u8Mask)
976 {
977 SYS_VIF_WriteRegBitByVDMbox(u32Reg,bEnable,u8Mask);
978 }
MDrv_SYS_VIFReadByteByVDMbox(MS_U32 u32Reg)979 MS_U8 MDrv_SYS_VIFReadByteByVDMbox(MS_U32 u32Reg)
980 {
981 return SYS_VIF_ReadByteByVDMbox(u32Reg);
982 }
MDrv_SYS_VIFRead2ByteByVDMbox(MS_U32 u32Reg)983 MS_U16 MDrv_SYS_VIFRead2ByteByVDMbox(MS_U32 u32Reg)
984 {
985 return SYS_VIF_Read2ByteByVDMbox(u32Reg);
986 }
987
MDrv_SYS_Query(E_SYS_QUERY id)988 MS_BOOL MDrv_SYS_Query(E_SYS_QUERY id)
989 {
990 return HAL_SYS_Query(id);
991 }
992
993 #ifdef _SYS_DAC_GAIN_CTRL_
994 //-------------------------------------------------------------------------------------------------
995 /// Set DAC 1/2 enhance gain.
996 /// @param u8DAC_ID \b IN: 1: DAC1, 2: DAC2, Other: Invalid DAC ID.
997 /// @param bEnable \b IN: enable/disable enhance gain.
998 /// @return void
999 //-------------------------------------------------------------------------------------------------
MDrv_SYS_EnhanceDACGain(MS_U8 u8DAC_ID,MS_BOOL bEnable)1000 void MDrv_SYS_EnhanceDACGain(MS_U8 u8DAC_ID, MS_BOOL bEnable)
1001 {
1002 HAL_SYS_EnhanceDACGain(u8DAC_ID, bEnable);
1003 }
1004 #endif
1005
1006
1007 //-------------------------------------------------------------------------------------------------
1008 /// Quert Dolby Hash Info.
1009 /// @param index \b IN: E_SYS_DOLBY_VERSION: Dolby version, E_SYS_DOLBY_CONTROL_BIT: Dolby control bit, E_SYS_DOLBY_REBERSE_BIT: Dolby reverse bit.
1010 /// @return The info about Dolby hash info accroding to the input param index.
1011 //------------------------------------------------------------------------------------------------
MDrv_SYS_QueryDolbyHashInfo(E_SYS_DOLBY_HASH_INFO index)1012 MS_U32 MDrv_SYS_QueryDolbyHashInfo(E_SYS_DOLBY_HASH_INFO index)
1013 {
1014 return HAL_SYS_QueryDolbyHashInfo(index);
1015 }
1016
1017 //-------------------------------------------------------------------------------------------------
1018 /// @brief \b Function \b Name: MDrv_SYS_GetChipType
1019 /// @brief \b Function \b Description: get the TV/STB chip type
1020 /// @param eLevel \b IN: E_SYS_DBGLV_NONE/E_SYS_DBGLV_ERR_ONLY/E_SYS_DBGLV_INFO/E_SYS_DBGLV_ALL
1021 /// @return \b E_SYS_CHIP_TYPE E_SYS_CHIP_TV:TV chip set / E_SYS_CHIP_STB : STB chip set
1022 //-------------------------------------------------------------------------------------------------
MDrv_SYS_GetChipType(void)1023 E_SYS_CHIP_TYPE MDrv_SYS_GetChipType(void)
1024 {
1025 return HAL_SYS_GetChipType();
1026 }
1027
MDrv_SYS_SetChipType(E_SYS_CHIP_TYPE Type)1028 void MDrv_SYS_SetChipType(E_SYS_CHIP_TYPE Type)
1029 {
1030 }
1031
1032
1033 static volatile MS_U8 u8gDolbyKeyCustomer[24] =
1034 {'H','K','C','S',
1035 0x44,0x10,0x91,0x68,0xff,0x0e,0x4c,0x28,0x77,0x0e,0xf5,0x57,0xe0,0x20,0x02,0xdf
1036 ,'H','K','C','E'};
1037
1038 //-------------------------------------------------------------------------------------------------
1039 /// @brief \b Function \b Name: MDrv_SYS_GetDolbyKeyCustomer
1040 /// @brief \b Function \b Description: get the Key Customer
1041 /// @param eLevel \b IN/OUT: The point of key customer
1042 /// @return \b void
1043 //-------------------------------------------------------------------------------------------------
MDrv_SYS_GetDolbyKeyCustomer(MS_U8 * u8pkey)1044 void MDrv_SYS_GetDolbyKeyCustomer(MS_U8 * u8pkey)
1045 {
1046 MS_U8 u8index;
1047
1048 for(u8index =4; u8index <(16+4); u8index ++)
1049 {
1050
1051 u8pkey[u8index-4] = u8gDolbyKeyCustomer [u8index];
1052
1053 }
1054
1055 }
1056
MDrv_SYS_ReadBrickTerminatorStatus(void)1057 MS_U16 MDrv_SYS_ReadBrickTerminatorStatus(void)
1058 {
1059 return HAL_SYS_ReadBrickTerminatorStatus();
1060 }
1061
MDrv_SYS_WriteBrickTerminatorStatus(MS_U16 u16Status)1062 void MDrv_SYS_WriteBrickTerminatorStatus(MS_U16 u16Status)
1063 {
1064 HAL_SYS_WriteBrickTerminatorStatus(u16Status);
1065 }
1066
MDrv_SYS_GetEfuseDid(MS_U16 * u16efuse_did)1067 MS_BOOL MDrv_SYS_GetEfuseDid(MS_U16 *u16efuse_did)
1068 {
1069 if(NULL == u16efuse_did)
1070 {
1071 SYS_DBG_INFO("%s NULL pointer is invalid!\n",__FUNCTION__);
1072 return FALSE;
1073 }
1074
1075 HAL_SYS_GetEfuseDid(u16efuse_did);
1076
1077 return TRUE;
1078 }
1079
MDrv_SYS_ReadEfuseHDCPKey(MS_U16 u16ReadAddr,MS_U32 * u32HDCPKey)1080 MS_BOOL MDrv_SYS_ReadEfuseHDCPKey(MS_U16 u16ReadAddr, MS_U32 *u32HDCPKey)
1081 {
1082 return HAL_SYS_ReadEfuseHDCPKey(u16ReadAddr,u32HDCPKey);
1083 }
1084
MDrv_SYS_EnableWOL(MS_BOOL bEnable)1085 MS_BOOL MDrv_SYS_EnableWOL(MS_BOOL bEnable)
1086 {
1087 if(bEnable)
1088 HAL_SYS_EnableWkEventWOL();
1089 else
1090 HAL_SYS_DisableWkEventWOL();
1091
1092 return TRUE;
1093 }
1094
MDrv_SYS_GetStatusWOL(void)1095 MS_BOOL MDrv_SYS_GetStatusWOL(void)
1096 {
1097 return HAL_SYS_GetStatusWOL();
1098 }
1099
MDrv_SYS_ResetStatusWOL(void)1100 void MDrv_SYS_ResetStatusWOL(void)
1101 {
1102 HAL_SYS_ResetStatusWOL();
1103 }
1104
1105
1106 /////////////////////////////////////////////////////////////////
1107 //////// UTOPIA2 CODE ///////////////////////////////////////////
1108 /////////////////////////////////////////////////////////////////
1109 enum
1110 {
1111 SYS_POOL_ID_SYS0=0
1112 } eSYS_PoolID;
1113
1114 //--------------------------------------------------------------------------------------------------
1115 // Utopia2.0 will call this function to register module
1116 //--------------------------------------------------------------------------------------------------
SYSRegisterToUtopia(FUtopiaOpen ModuleType)1117 void SYSRegisterToUtopia(FUtopiaOpen ModuleType)
1118 {
1119 // 1. create a module(module_name, SHM_size), and register to utopia2.0
1120 void* pUtopiaModule = NULL;
1121 UtopiaModuleCreate(MODULE_SYS, 0, &pUtopiaModule);
1122 UtopiaModuleRegister(pUtopiaModule);
1123
1124 // register func for module, after register here, then ap call UtopiaOpen/UtopiaIoctl/UtopiaClose can call to these registered standard func
1125 UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)SYSOpen, (FUtopiaClose)SYSClose, (FUtopiaIOctl)SYSIoctl);
1126
1127 // 2. Resource register
1128 void* psResource = NULL;
1129
1130 // start func to add resources of a certain Resource_Pool
1131 UtopiaModuleAddResourceStart(pUtopiaModule, SYS_POOL_ID_SYS0);
1132
1133 // create a resouce and regiter it to a certain Resource_Pool, resource can alloc private for internal use
1134 UtopiaResourceCreate("sys0", sizeof(SYS_RESOURCE_PRIVATE), &psResource);
1135 #ifdef CONFIG_MSTAR_DVFS_ENABLE
1136 ((SYS_RESOURCE_PRIVATE*) psResource)->bDvfsInitFlag = 0;
1137 #endif
1138 UtopiaResourceRegister(pUtopiaModule, psResource, SYS_POOL_ID_SYS0);
1139
1140 //UtopiaResourceCreate("sys1", sizeof(SYS_RESOURCE_PRIVATE), &psResource);
1141 //UtopiaResourceRegister(pUtopiaModule, psResource, SYS_POOL_ID_SYS0);
1142
1143 // end func to add resources of a certain Resource_Pool(this will set the ResourceSemaphore of this ResourcePool)
1144 UtopiaModuleAddResourceEnd(pUtopiaModule, SYS_POOL_ID_SYS0);
1145 }
1146
1147 //--------------------------------------------------------------------------------------------------
1148 // Utopia2.0 will call this function to get a instance to use SYS
1149 // @ \b in: 32ModuleVersion => this is for checking if API version is the same
1150 //--------------------------------------------------------------------------------------------------
SYSOpen(void ** ppInstance,void * pAttribute)1151 MS_U32 SYSOpen(void** ppInstance, void* pAttribute)
1152 {
1153 // for multi-process safe, check if already other Instance exist
1154 // 1. use moduleID to get module, then try to get resource
1155 void *pModule = NULL;
1156 void *pResource = NULL;
1157 UtopiaModuleGetPtr(MODULE_SYS, &pModule);
1158
1159 if(UtopiaResourceObtain(pModule, SYS_POOL_ID_SYS0, &pResource) != 0)
1160 {
1161 ULOGE(TAG_SYS, "UtopiaResourceObtainToInstant fail\n");
1162 return UTOPIA_STATUS_FAIL;
1163 }
1164
1165 // if get a resource, check the module private SHM(default to be 0, only create at the first time) to decide whether this process can open instance
1166 void *pSYSResPri = NULL;
1167 UtopiaResourceGetPrivate(pResource, &pSYSResPri);
1168
1169 ULOGD(TAG_SYS, "\033[35mFunction = %s, Line = %d, current resource pri_shm content is: %u\033[m\n", __PRETTY_FUNCTION__, __LINE__, *(unsigned int *)pSYSResPri);
1170
1171 //if(*(MS_U32 *)pSYSResPri == 0)
1172 {
1173 #ifdef CONFIG_MSTAR_DVFS_ENABLE
1174 if(((SYS_RESOURCE_PRIVATE*) pSYSResPri)->bDvfsInitFlag == 0)
1175 {
1176 ((SYS_RESOURCE_PRIVATE*) pSYSResPri)->bDvfsInitFlag = 0;
1177 g_bDvfsInitFlag = 0;
1178 }
1179 else
1180 {
1181 g_bDvfsInitFlag = 1;
1182 }
1183 #endif
1184 }
1185
1186 UtopiaResourceRelease(pResource);
1187
1188 ULOGD(TAG_SYS, "\033[35mFunction = %s, Line = %d, [SYS INFO] OPEN INSTANCE...\033[m\n", __PRETTY_FUNCTION__, __LINE__);
1189 SYS_INSTANT_PRIVATE *pSYSPri = NULL;
1190
1191 // instance is allocated here, also can allocate private for internal use, ex, SYS_INSTANT_PRIVATE, ppInstance will point to a pointer of the created UTOPIA_INSTANCE
1192 UtopiaInstanceCreate(sizeof(SYS_INSTANT_PRIVATE), ppInstance);
1193 // set the pSYSPri point to the private of UTOPIA_INSTANCE
1194 UtopiaInstanceGetPrivate(*ppInstance, (void**)&pSYSPri);
1195
1196 // setup func in private and assign the calling func in func ptr in instance private
1197 pSYSPri->fpSYS_GetChipRev = (IOCTL_SYS_GETCHIPREV)MDrv_SYS_GetChipRev;
1198 pSYSPri->fpSYS_GetChipID = (IOCTL_SYS_GETCHIPID)MDrv_SYS_GetChipID;
1199 pSYSPri->fpSYS_GetInfo = (IOCTL_SYS_GETINFO)MDrv_SYS_GetInfo;
1200 pSYSPri->fpSYS_GetLibVer = (IOCTL_SYS_GETLIBVER)MDrv_SYS_GetLibVer;
1201 pSYSPri->fpSYS_GetStatus = (IOCTL_SYS_GETSTATUS)MDrv_SYS_GetStatus;
1202 pSYSPri->fpSYS_GetSoftwareVersion = (IOCTL_SYS_GETSOFTWAREVERSION)MDrv_SYS_GetSoftwareVersion;
1203 pSYSPri->fpSYS_DisableDebugPort = (IOCTL_SYS_DISABLEDEBUGPORT)MDrv_SYS_DisableDebugPort;
1204 pSYSPri->fpSYS_EnableDebugPort = (IOCTL_SYS_ENABLEDEBUGPORT)MDrv_SYS_EnableDebugPort;
1205 pSYSPri->fpSYS_SetDbgLevel = (IOCTL_SYS_SETDBGLEVEL)MDrv_SYS_SetDbgLevel;
1206 pSYSPri->fpSYS_VIFWriteByteByVDMbox = (IOCTL_SYS_VIFWRITEBYTEBYVDMBOX)MDrv_SYS_VIFWriteByteByVDMbox;
1207 pSYSPri->fpSYS_VIFWriteByteMaskByVDMbox = (IOCTL_SYS_VIFWRITEBYTEMASKBYVDMBOX)MDrv_SYS_VIFWriteByteMaskByVDMbox;
1208 pSYSPri->fpSYS_VIFWriteRegBitByVDMbox = (IOCTL_SYS_VIFWRITEREGBITBYVDMBOX)MDrv_SYS_VIFWriteRegBitByVDMbox;
1209 pSYSPri->fpSYS_VIFReadByteByVDMbox = (IOCTL_SYS_VIFREADBYTEBYVDMBOX)MDrv_SYS_VIFReadByteByVDMbox;
1210 pSYSPri->fpSYS_VIFRead2ByteByVDMbox = (IOCTL_SYS_VIFREAD2BYTEBYVDMBOX)MDrv_SYS_VIFRead2ByteByVDMbox;
1211 pSYSPri->fpSYS_WDTEnable = (IOCTL_SYS_WDTENABLE)MDrv_SYS_WDTEnable;
1212 pSYSPri->fpSYS_WDTClear = (IOCTL_SYS_WDTCLEAR)MDrv_SYS_WDTClear;
1213 pSYSPri->fpSYS_WDTLastStatus = (IOCTL_SYS_WDTLASTSTATUS)MDrv_SYS_WDTLastStatus;
1214 pSYSPri->fpSYS_WDTSetTime = (IOCTL_SYS_WDTSETTIME)MDrv_SYS_WDTSetTime;
1215 pSYSPri->fpSYS_ResetChip = (IOCTL_SYS_RESETCHIP)MDrv_SYS_ResetChip;
1216 pSYSPri->fpSYS_ResetCPU = (IOCTL_SYS_RESETCPU)MDrv_SYS_ResetCPU;
1217 pSYSPri->fpSYS_SetAGCPadMux = (IOCTL_SYS_SETAGCPADMUX)MDrv_SYS_SetAGCPadMux;
1218 pSYSPri->fpSYS_SetPCMCardDetectMode = (IOCTL_SYS_SETPCMCARDDETECTMODE)MDrv_SYS_SetPCMCardDetectMode;
1219 pSYSPri->fpSYS_SetPadMux = (IOCTL_SYS_SETPADMUX)MDrv_SYS_SetPadMux;
1220 pSYSPri->fpSYS_SetTSOutClockPhase = (IOCTL_SYS_SETTSOUTCLOCKPHASE)MDrv_SYS_SetTSOutClockPhase;
1221 pSYSPri->fpSYS_Query = (IOCTL_SYS_QUERY)MDrv_SYS_Query;
1222 #ifdef _SYS_DAC_GAIN_CTRL
1223 pSYSPri->fpSYS_EnhanceDACGain = (IOCTL_SYS_ENHANCEDACGAIN)MDrv_SYS_EnhanceDACGain;
1224 #endif
1225 pSYSPri->fpSYS_Init = (IOCTL_SYS_INIT)MDrv_SYS_Init;
1226 pSYSPri->fpSYS_GlobalInit = (IOCTL_SYS_GLOBALINIT)MDrv_SYS_GlobalInit;
1227 #if defined (MSOS_TYPE_LINUX)
1228 pSYSPri->fpSYS_TeecInitContext = (IOCTL_SYS_TEEC_INIT_CONTEXT)MDrv_SYS_TEEC_InitializeContext;
1229 pSYSPri->fpSYS_TeecOpen = (IOCTL_SYS_TEEC_OPEN)MDrv_SYS_TEEC_Open;
1230 pSYSPri->fpSYS_TeecClose = (IOCTL_SYS_TEEC_CLOSE)MDrv_SYS_TEEC_Close;
1231 pSYSPri->fpSYS_TeecInvokeCmd = (IOCTL_SYS_TEEC_INVOKE_CMD)MDrv_SYS_TEEC_InvokeCmd;
1232 pSYSPri->fpSYS_TeecFinalizeContext = (IOCTL_SYS_TEEC_FINAL_CONTEXT)MDrv_SYS_TEEC_FinalizeContext;
1233 #endif
1234
1235 return UTOPIA_STATUS_SUCCESS;
1236 }
1237
SYSIoctl(void * pInstance,MS_U32 u32Cmd,void * pArgs)1238 MS_U32 SYSIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
1239 {
1240 void* pModule = NULL;
1241 UtopiaInstanceGetModule(pInstance, &pModule);
1242
1243 SYS_INSTANT_PRIVATE *psSYSInstPri = NULL;
1244 UtopiaInstanceGetPrivate(pInstance, (void**)&psSYSInstPri);
1245
1246 PSYS_GETSTATUS_PARAM pGetStatusParam = NULL;
1247 PSYS_GETSOFTWAREVERSION_PARAM pGetSoftwareVersionParam = NULL;
1248 PSYS_SETDBGLEVEL_PARAM pSetDbgLevelParam = NULL;
1249 PSYS_VIFWRITEBYTEBYVDMBOX_PARAM pVIFWriteByteByVDMboxParam = NULL;
1250 PSYS_VIFWRITEBYTEMASKBYVDMBOX_PARAM pVIFWriteByteMaskByVDMboxParam = NULL;
1251 PSYS_VIFWRITEREGBITBYVDMBOX_PARAM pVIFWriteRegBitByVDMboxParam = NULL;
1252 PSYS_VIFREADBYTEBYVDMBOX_PARAM pVIFReadByteByVDMboxParam = NULL;
1253 PSYS_VIFREAD2BYTEBYVDMBOX_PARAM pVIFRead2ByteByVDMboxParam = NULL;
1254 PSYS_WDTENABLE_PARAM pWDTEnableParam = NULL;
1255 PSYS_WDTSETTIME_PARAM pWDTSetTimeParam = NULL;
1256 PSYS_SETAGCPADMUX_PARAM pSetAGCPadMuxParam = NULL;
1257 PSYS_SETPCMCARDDETECT_PARAM pSetPCMCardDetectModeParam = NULL;
1258 PSYS_SETPADMUX_PARAM pSetPadMuxParam = NULL;
1259 PSYS_SETTSOUTCLOCKPHASE_PARAM pSetTSOutClockPhaseParam = NULL;
1260 PSYS_QUERY_PARAM pQueryParam = NULL;
1261 #ifdef _SYS_DAC_GAIN_CTRL
1262 PSYS_ENHANCEDACGAIN_PARAM pEnhanceDACGainParam = NULL;
1263 #endif
1264 #if defined (MSOS_TYPE_LINUX)
1265 PSYS_SYS_TEECOPEN_PARAM pTeecOpenParam = NULL;
1266 PSYS_SYS_TEECCLOSE_PARAM pTeecCloseParam = NULL;
1267 PSYS_SYS_TEECINVOKECMD_PARAM pTeecInvokeCmdParam = NULL;
1268 PSYS_SYS_TEECINITCONTEXT_PARAM pTeecInitContextParam = NULL;
1269 #endif
1270
1271 MS_U32 u32Ret;
1272
1273 switch(u32Cmd)
1274 {
1275 case MDrv_CMD_SYS_GetChipRev:
1276 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetChipRev\n");
1277 *((MS_U8 *)(pArgs)) = psSYSInstPri->fpSYS_GetChipRev();
1278 return TRUE;
1279 case MDrv_CMD_SYS_GetChipID:
1280 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetChipID\n");
1281 *((MS_U16 *)(pArgs)) = psSYSInstPri->fpSYS_GetChipID();
1282 return TRUE;
1283 case MDrv_CMD_SYS_GetInfo:
1284 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetInfo\n");
1285 memcpy(pArgs, psSYSInstPri->fpSYS_GetInfo(), sizeof(const SYS_Info));
1286 return TRUE;
1287 case MDrv_CMD_SYS_GetLibVer:
1288 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetLibVer\n");
1289 memcpy(pArgs, psSYSInstPri->fpSYS_GetLibVer(), sizeof(const MSIF_Version));
1290 return TRUE;
1291 case MDrv_CMD_SYS_GetStatus:
1292 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetStatus\n");
1293 pGetStatusParam = (PSYS_GETSTATUS_PARAM)pArgs;
1294 u32Ret = (MS_U32)psSYSInstPri->fpSYS_GetStatus(pGetStatusParam->pStatus);
1295 return u32Ret;
1296 case MDrv_CMD_SYS_GetSoftwareVersion:
1297 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GetSoftwareVersion\n");
1298 pGetSoftwareVersionParam = (PSYS_GETSOFTWAREVERSION_PARAM)pArgs;
1299 psSYSInstPri->fpSYS_GetSoftwareVersion(pGetSoftwareVersionParam->pSoftwareVersionInfo);
1300 return TRUE;
1301 case MDrv_CMD_SYS_DisableDebugPort:
1302 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_DisableDebugPort\n");
1303 u32Ret = (MS_U32)psSYSInstPri->fpSYS_DisableDebugPort();
1304 return u32Ret;
1305 case MDrv_CMD_SYS_EnableDebugPort:
1306 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_EnableDebugPort\n");
1307 u32Ret = (MS_U32)psSYSInstPri->fpSYS_EnableDebugPort();
1308 return u32Ret;
1309 case MDrv_CMD_SYS_SetDbgLevel:
1310 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_SetDbgLevel\n");
1311 pSetDbgLevelParam = (PSYS_SETDBGLEVEL_PARAM)pArgs;
1312 psSYSInstPri->fpSYS_SetDbgLevel(pSetDbgLevelParam->eLevel);
1313 return TRUE;
1314 case MDrv_CMD_SYS_VIFWriteByteByVDMbox:
1315 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_VIFWriteByteByVDMbox\n");
1316 pVIFWriteByteByVDMboxParam = (PSYS_VIFWRITEBYTEBYVDMBOX_PARAM)pArgs;
1317 psSYSInstPri->fpSYS_VIFWriteByteByVDMbox(pVIFWriteByteByVDMboxParam->u32Reg, pVIFWriteByteByVDMboxParam->u8Val);
1318 return TRUE;
1319 case MDrv_CMD_SYS_VIFWriteByteMaskByVDMbox:
1320 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_VIFWriteByteMaskByVDMbox\n");
1321 pVIFWriteByteMaskByVDMboxParam = (PSYS_VIFWRITEBYTEMASKBYVDMBOX_PARAM)pArgs;
1322 psSYSInstPri->fpSYS_VIFWriteByteMaskByVDMbox(pVIFWriteByteMaskByVDMboxParam->u32Reg, pVIFWriteByteMaskByVDMboxParam->u8Val, pVIFWriteByteMaskByVDMboxParam->u8Mask);
1323 return TRUE;
1324 case MDrv_CMD_SYS_VIFWriteRegBitByVDMbox:
1325 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_VIFWriteRegBitByVDMbox\n");
1326 pVIFWriteRegBitByVDMboxParam = (PSYS_VIFWRITEREGBITBYVDMBOX_PARAM)pArgs;
1327 psSYSInstPri->fpSYS_VIFWriteRegBitByVDMbox(pVIFWriteRegBitByVDMboxParam->u32Reg, pVIFWriteRegBitByVDMboxParam->bEnable, pVIFWriteRegBitByVDMboxParam->u8Mask);
1328 return TRUE;
1329 case MDrv_CMD_SYS_VIFReadByteByVDMbox:
1330 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_VIFReadByteByVDMbox\n");
1331 pVIFReadByteByVDMboxParam = (PSYS_VIFREADBYTEBYVDMBOX_PARAM)pArgs;
1332 u32Ret = (MS_U32)psSYSInstPri->fpSYS_VIFReadByteByVDMbox(pVIFReadByteByVDMboxParam->u32Reg);
1333 return u32Ret;
1334 case MDrv_CMD_SYS_VIFRead2ByteByVDMbox:
1335 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_VIFRead2ByteByVDMbox\n");
1336 pVIFRead2ByteByVDMboxParam = (PSYS_VIFREAD2BYTEBYVDMBOX_PARAM)pArgs;
1337 u32Ret = (MS_U32)psSYSInstPri->fpSYS_VIFRead2ByteByVDMbox(pVIFRead2ByteByVDMboxParam->u32Reg);
1338 return u32Ret;
1339 case MDrv_CMD_SYS_WDTEnable:
1340 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_WDTEnable\n");
1341 pWDTEnableParam = (PSYS_WDTENABLE_PARAM)pArgs;
1342 psSYSInstPri->fpSYS_WDTEnable(pWDTEnableParam->bEnable);
1343 return TRUE;
1344 case MDrv_CMD_SYS_WDTClear:
1345 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_WDTClear\n");
1346 psSYSInstPri->fpSYS_WDTClear();
1347 return TRUE;
1348 case MDrv_CMD_SYS_WDTLastStatus:
1349 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_WDTLastStatus\n");
1350 u32Ret = (MS_U32)psSYSInstPri->fpSYS_WDTLastStatus();
1351 return u32Ret;
1352 case MDrv_CMD_SYS_WDTSetTime:
1353 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_WDTSetTime\n");
1354 pWDTSetTimeParam = (PSYS_WDTSETTIME_PARAM)pArgs;
1355 psSYSInstPri->fpSYS_WDTSetTime(pWDTSetTimeParam->u32Ms);
1356 return TRUE;
1357 case MDrv_CMD_SYS_ResetChip:
1358 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_ResetChip\n");
1359 psSYSInstPri->fpSYS_ResetChip();
1360 return TRUE;
1361 case MDrv_CMD_SYS_ResetCPU:
1362 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_ResetCPU\n");
1363 psSYSInstPri->fpSYS_ResetCPU();
1364 return TRUE;
1365 case MDrv_CMD_SYS_SetAGCPadMux:
1366 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_SetAGCPadMux\n");
1367 pSetAGCPadMuxParam = (PSYS_SETAGCPADMUX_PARAM)pArgs;
1368 psSYSInstPri->fpSYS_SetAGCPadMux(pSetAGCPadMuxParam->eAgcPadMux);
1369 return TRUE;
1370 case MDrv_CMD_SYS_SetPCMCardDetectMode:
1371 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_SetPCMCardDetectMode\n");
1372 pSetPCMCardDetectModeParam = (PSYS_SETPCMCARDDETECT_PARAM)pArgs;
1373 u32Ret = (MS_U32)psSYSInstPri->fpSYS_SetPCMCardDetectMode(pSetPCMCardDetectModeParam->ePCMCDMode);
1374 return u32Ret;
1375 case MDrv_CMD_SYS_SetPadMux:
1376 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_SetPadMux\n");
1377 pSetPadMuxParam = (PSYS_SETPADMUX_PARAM)pArgs;
1378 u32Ret = (MS_U32)psSYSInstPri->fpSYS_SetPadMux(pSetPadMuxParam->ePadMuxType, pSetPadMuxParam->ePadSel);
1379 return u32Ret;
1380 case MDrv_CMD_SYS_SetTSOutClockPhase:
1381 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_SetTSOutClockPhase\n");
1382 pSetTSOutClockPhaseParam = (PSYS_SETTSOUTCLOCKPHASE_PARAM)pArgs;
1383 u32Ret = (MS_U32)psSYSInstPri->fpSYS_SetTSOutClockPhase(pSetTSOutClockPhaseParam->u16Val);
1384 return u32Ret;
1385 case MDrv_CMD_SYS_Query:
1386 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_Query\n");
1387 pQueryParam = (PSYS_QUERY_PARAM)pArgs;
1388 u32Ret = (MS_U32)psSYSInstPri->fpSYS_Query(pQueryParam->id);
1389 return u32Ret;
1390 #ifdef _SYS_DAC_GAIN_CTRL
1391 case MDrv_CMD_SYS_EnhanceDACGain:
1392 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_EnhanceDACGain\n");
1393 pEnhanceDACGainParam = (PSYS_ENHANCEDACGAIN_PARAM)pArgs;
1394 psSYSInstPri->fpSYS_EnhanceDACGain(pEnhanceDACGainParam->u8DAC_ID, pEnhanceDACGainParam->bEnable);
1395 return TRUE;
1396 #endif
1397 case MDrv_CMD_SYS_Init:
1398 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_Init\n");
1399 u32Ret = (MS_U32)psSYSInstPri->fpSYS_Init();
1400 return u32Ret;
1401 case MDrv_CMD_SYS_GlobalInit:
1402 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_GlobalInit\n");
1403 psSYSInstPri->fpSYS_GlobalInit();
1404 return TRUE;
1405 #if defined (MSOS_TYPE_LINUX)
1406 case MDrv_CMD_SYS_TeecInitContext:
1407 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_TeecInitContext\n");
1408 pTeecInitContextParam = (PSYS_SYS_TEECINITCONTEXT_PARAM)pArgs;
1409 u32Ret = psSYSInstPri->fpSYS_TeecInitContext(pTeecInitContextParam->name, pTeecInitContextParam->context);
1410 return u32Ret;
1411 case MDrv_CMD_SYS_TeecOpen:
1412 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_TeecOpen\n");
1413 pTeecOpenParam = (PSYS_SYS_TEECOPEN_PARAM)pArgs;
1414 u32Ret = psSYSInstPri->fpSYS_TeecOpen(pTeecOpenParam->context, pTeecOpenParam->session, pTeecOpenParam->destination, pTeecOpenParam->connection_method, pTeecOpenParam->connection_data, pTeecOpenParam->operation, pTeecOpenParam->error_origin);
1415 return u32Ret;
1416 case MDrv_CMD_SYS_TeecClose:
1417 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_TeecClose\n");
1418 pTeecCloseParam = (PSYS_SYS_TEECCLOSE_PARAM)pArgs;
1419 psSYSInstPri->fpSYS_TeecClose(pTeecCloseParam->session);
1420 return TRUE;
1421 case MDrv_CMD_SYS_TeecInvokeCmd:
1422 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_TeecInvokeCmd\n");
1423 pTeecInvokeCmdParam = (PSYS_SYS_TEECINVOKECMD_PARAM)pArgs;
1424 u32Ret = psSYSInstPri->fpSYS_TeecInvokeCmd(pTeecInvokeCmdParam->session, pTeecInvokeCmdParam->cmd_id, pTeecInvokeCmdParam->operation, pTeecInvokeCmdParam->error_origin);
1425 return u32Ret;
1426 case MDrv_CMD_SYS_TeecFinalContext:
1427 ULOGD(TAG_SYS, "SYSIoctl - MDrv_CMD_SYS_TeecFinalContext\n");
1428 pTeecInitContextParam = (PSYS_SYS_TEECINITCONTEXT_PARAM)pArgs;
1429 psSYSInstPri->fpSYS_TeecFinalizeContext(pTeecInitContextParam->context);
1430 return TRUE;
1431 #endif
1432 default:
1433 break;
1434 };
1435
1436 return 0; // FIXME: error code
1437 }
1438
SYSClose(void * pInstance)1439 MS_U32 SYSClose(void* pInstance)
1440 {
1441 UtopiaInstanceDelete(pInstance);
1442
1443 // Restore resource pri_shm content
1444 // 1. use moduleID to get module, then try to get resource
1445 void *pModule = NULL;
1446 void *pResource = NULL;
1447 UtopiaModuleGetPtr(MODULE_SYS, &pModule);
1448
1449 if(UtopiaResourceObtain(pModule, SYS_POOL_ID_SYS0, &pResource) != 0)
1450 {
1451 ULOGE(TAG_SYS, "UtopiaResourceObtainToInstant fail\n");
1452 return FALSE;
1453 }
1454
1455 // if get a resource, check the module private SHM(default to be 0, only create at the first time) to decide whether this process can open instance
1456 void *pSYSResPri = NULL;
1457 UtopiaResourceGetPrivate(pResource, &pSYSResPri);
1458
1459 if(*(MS_U32 *)pSYSResPri == 0)
1460 {
1461 ULOGE(TAG_SYS, "\033[35mFunction = %s, Line = %d, [SYSClose] Strange resource pri_shm content!!\033[m\n", __PRETTY_FUNCTION__, __LINE__);
1462 UtopiaResourceRelease(pResource);
1463 return FALSE;
1464 }
1465 else
1466 {
1467 ULOGD(TAG_SYS, "\033[35mFunction = %s, Line = %d, [Multi-process Safe] Release an Instance!!\033[m\n", __PRETTY_FUNCTION__, __LINE__);
1468 *(MS_U32 *)pSYSResPri = 0;
1469 UtopiaResourceRelease(pResource);
1470 return TRUE;
1471 }
1472 }
1473
1474
MDrv_SYS_SetPowerState(EN_POWER_MODE u16PowerState)1475 MS_U32 MDrv_SYS_SetPowerState(EN_POWER_MODE u16PowerState)
1476 {
1477 static EN_POWER_MODE _prev_u16PowerState = E_POWER_MECHANICAL;
1478 MS_U16 u32Return = UTOPIA_STATUS_FAIL;
1479
1480 if (u16PowerState == E_POWER_SUSPEND)
1481 {
1482 _prev_u16PowerState = u16PowerState;
1483 u32Return = UTOPIA_STATUS_SUCCESS; //SUSPEND_OK
1484 }
1485 else if (u16PowerState == E_POWER_RESUME)
1486 {
1487 if (_prev_u16PowerState == E_POWER_SUSPEND)
1488 {
1489 MDrv_SYS_Init();
1490
1491 _prev_u16PowerState = u16PowerState;
1492 u32Return = UTOPIA_STATUS_SUCCESS; //RESUME_OK
1493 }
1494 else
1495 {
1496 ULOGE(TAG_SYS, "[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__);
1497 u32Return = UTOPIA_STATUS_FAIL; //SUSPEND_FAILED
1498 }
1499 }
1500 else
1501 {
1502 ULOGE(TAG_SYS, "[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__,u16PowerState);
1503 u32Return = UTOPIA_STATUS_FAIL;
1504 }
1505
1506 return u32Return;
1507 }
1508
1509 //-------------------------------------------------------------------------------------------------
1510 /// Get System Hardware List
1511 //-------------------------------------------------------------------------------------------------
1512
MDrv_SYS_GetIpList(E_SYS_IP_TYPE TYPE)1513 MS_U32 MDrv_SYS_GetIpList(E_SYS_IP_TYPE TYPE)
1514 {
1515 MS_U32 ret = 0;
1516 switch(TYPE)
1517 {
1518 case E_SYS_IP_ENCODER:
1519 if(CHIP_IP_MFE)
1520 ret |= SYS_ENCODER_MFE;
1521 if(CHIP_IP_VE)
1522 ret |= SYS_ENCODER_VE;
1523 return ret;
1524
1525 case E_SYS_IP_FRONTEND:
1526 if(CHIP_IP_AVD)
1527 ret |= SYS_FRONTEND_AVD;
1528 if(CHIP_IP_DEMOD)
1529 ret |= SYS_FRONTEND_DEMOD;
1530 if(CHIP_IP_VBI)
1531 ret |= SYS_FRONTEND_VBI;
1532 if(CHIP_IP_VIF)
1533 ret |= SYS_FRONTEND_VIF;
1534 return ret;
1535
1536 case E_SYS_IP_DEMUX:
1537 if(CHIP_IP_DMX)
1538 ret |= SYS_DEMUX_DMX;
1539 return ret;
1540
1541 case E_SYS_IP_SYSTEM:
1542 if(CHIP_IP_CEC)
1543 ret |= SYS_SYSTEM_CEC;
1544 if(CHIP_IP_MBX)
1545 ret |= SYS_SYSTEM_MBX;
1546 if(CHIP_IP_SWI2C)
1547 ret |= SYS_SYSTEM_SWI2C;
1548 if(CHIP_IP_BDMA)
1549 ret |= SYS_SYSTEM_BDMA;
1550 if(CHIP_IP_CPU)
1551 ret |= SYS_SYSTEM_CPU;
1552 if(CHIP_IP_GPIO)
1553 ret |= SYS_SYSTEM_GPIO;
1554 if(CHIP_IP_HWI2C)
1555 ret |= SYS_SYSTEM_HWI2C;
1556 if(CHIP_IP_IR)
1557 ret |= SYS_SYSTEM_IR;
1558 if(CHIP_IP_MIU)
1559 ret |= SYS_SYSTEM_MIU;
1560 if(CHIP_IP_MPIF)
1561 ret |= SYS_SYSTEM_MPIF;
1562 if(CHIP_IP_MSPI)
1563 ret |= SYS_SYSTEM_MSPI;
1564 if(CHIP_IP_PM)
1565 ret |= SYS_SYSTEM_PM;
1566 if(CHIP_IP_PWM)
1567 ret |= SYS_SYSTEM_PWM;
1568 if(CHIP_IP_PWS)
1569 ret |= SYS_SYSTEM_PWS;
1570 if(CHIP_IP_RTC)
1571 ret |= SYS_SYSTEM_RTC;
1572 if(CHIP_IP_SAR)
1573 ret |= SYS_SYSTEM_SAR;
1574 if(CHIP_IP_URDMA)
1575 ret |= SYS_SYSTEM_URDMA;
1576 if(CHIP_IP_WDT)
1577 ret |= SYS_SYSTEM_WDT;
1578 return ret;
1579
1580 case E_SYS_IP_CA:
1581 if(CHIP_IP_AESDMA)
1582 ret |= SYS_CA_AESDMA;
1583 if(CHIP_IP_CA)
1584 ret |= SYS_CA_CA;
1585 if(CHIP_IP_PCMCIA)
1586 ret |= SYS_CA_PCMCIA;
1587 if(CHIP_IP_SC)
1588 ret |= SYS_CA_SC;
1589 return ret;
1590
1591 case E_SYS_IP_CODEC:
1592 if(CHIP_IP_GPD)
1593 ret |= SYS_CODEC_GPD;
1594 if(CHIP_IP_JPEG)
1595 ret |= SYS_CODEC_JPEG;
1596 if(CHIP_IP_VDEC)
1597 ret |= SYS_CODEC_VDEC;
1598 return ret;
1599
1600 case E_SYS_IP_DISPLAY:
1601 if(CHIP_IP_ACE)
1602 ret |= SYS_DISPLAY_ACE;
1603 if(CHIP_IP_DAC)
1604 ret |= SYS_DISPLAY_DAC;
1605 if(CHIP_IP_DDC2BI)
1606 ret |= SYS_DISPLAY_DDC2BI;
1607 if(CHIP_IP_DIP)
1608 ret |= SYS_DISPLAY_DIP;
1609 if(CHIP_IP_DLC)
1610 ret |= SYS_DISPLAY_DLC;
1611 if(CHIP_IP_GOP)
1612 ret |= SYS_DISPLAY_GOP;
1613 if(CHIP_IP_HDMITX)
1614 ret |= SYS_DISPLAY_HDMITX;
1615 if(CHIP_IP_MHL)
1616 ret |= SYS_DISPLAY_MHL;
1617 if(CHIP_IP_MVOP)
1618 ret |= SYS_DISPLAY_MVOP;
1619 if(CHIP_IP_PNL)
1620 ret |= SYS_DISPLAY_PNL;
1621 if(CHIP_IP_XC)
1622 ret |= SYS_DISPLAY_XC;
1623 return ret;
1624
1625 case E_SYS_IP_GFX:
1626 if(CHIP_IP_GFX)
1627 ret |= SYS_GFX_GFX;
1628 return ret;
1629
1630 case E_SYS_IP_AUDIO:
1631 if(CHIP_IP_AUDIO)
1632 ret |= SYS_AUDIO_AUDIO;
1633 return ret;
1634
1635 case E_SYS_IP_STORAGE:
1636 if(CHIP_IP_SERFLASH)
1637 ret |= SYS_STORAGE_SERFLASH;
1638 return ret;
1639
1640 default:
1641 SYS_DBG_INFO("Not Support IP type %d\n",TYPE);
1642 break;
1643 }
1644
1645 return ret;
1646 }
1647
1648 //FOR INTERNAL USE ONLY
MDrv_SYS_RegisterIoProc(E_SYS_IO_PROC dwIoType,void * pdwIoFunction)1649 MS_U32 MDrv_SYS_RegisterIoProc(E_SYS_IO_PROC dwIoType, void *pdwIoFunction)
1650 {
1651 MS_U32 dwReturnStatus = TRUE;
1652
1653 switch(dwIoType)
1654 {
1655 case E_SYS_IO_SWI2C_READ:
1656 {
1657 //Register the Function Pointer of SWI2C Read Procedure
1658 g_SysIoProc.SysSwI2CReadBytes = pdwIoFunction;
1659 }
1660 break;
1661
1662 case E_SYS_IO_SWI2C_WRITE:
1663 {
1664 //Register the Function Pointer of SWI2C Write Procedure
1665 g_SysIoProc.SysSwI2CWriteBytes = pdwIoFunction;
1666 }
1667 break;
1668
1669 default:
1670 {
1671 SYS_DBG_INFO("Unknown IO Type\n");
1672 dwReturnStatus = FALSE;
1673 }
1674 break;
1675 }
1676
1677 return dwReturnStatus;
1678 }
1679
MDrv_SYS_GetUtopiaReleaseLabel(void)1680 char* MDrv_SYS_GetUtopiaReleaseLabel(void)
1681 {
1682 return UTOPIA_RELEASE_LABEL;
1683 }
1684
1685 char utopia_mode[10] = {""};
1686 char tee_mode[10] = {""};
1687
1688 #if defined (MSOS_TYPE_LINUX)
_MDrv_SYS_ParserCmdLine(char * name)1689 static void _MDrv_SYS_ParserCmdLine(char *name)
1690 {
1691 char *value = strchr(name, '=');
1692
1693 if (value == 0) return;
1694 *value++ = 0;
1695 if (*name == 0) return;
1696
1697 if (!strcmp(name,"utopia_mode")) {
1698 strncpy(utopia_mode, value, sizeof(utopia_mode)-1);
1699 utopia_mode[sizeof(utopia_mode)-1] = '\n';
1700 } else if (!strcmp(name,"tee_mode")) {
1701 strncpy(tee_mode, value, sizeof(tee_mode)-1);
1702 tee_mode[sizeof(utopia_mode)-1] = '\n';
1703 }
1704 //printu("utopia_mode = %s \n",utopia_mode);
1705 //printu("tee_mode = %s \n",tee_mode);
1706 }
1707
MDrv_SYS_ReadKernelCmdLine(void)1708 void MDrv_SYS_ReadKernelCmdLine(void)
1709 {
1710 char cmdline[1024];
1711 char *ptr;
1712 int fd;
1713 fd = open("/proc/cmdline", O_RDONLY);
1714 if (fd >= 0) {
1715 int n = read(fd, cmdline, 1023);
1716 if (n < 0) n = 0;
1717
1718 /* get rid of trailing newline, it happens */
1719 if (n > 0 && cmdline[n-1] == '\n') n--;
1720
1721 cmdline[n] = 0;
1722 close(fd);
1723 } else {
1724 SYS_DBG_INFO("MDrv_SYS_ReadKernelCmdLine can't open /proc/cmdline\n");
1725 cmdline[0] = 0;
1726 }
1727
1728 ptr = cmdline;
1729 while (ptr && *ptr) {
1730 char *x = strchr(ptr, ' ');
1731 if (x != 0) *x++ = 0;
1732 _MDrv_SYS_ParserCmdLine(ptr);
1733 ptr = x;
1734 }
1735 }
1736 #else
MDrv_SYS_ReadKernelCmdLine(void)1737 void MDrv_SYS_ReadKernelCmdLine(void)
1738 {
1739 SYS_DBG_INFO("Not Support\n");
1740 }
1741 #endif
1742
MDrv_SYS_SetTEEInfo(MS_U32 osType)1743 MS_U32 MDrv_SYS_SetTEEInfo(MS_U32 osType)
1744 {
1745 if (osType == SYS_TEEINFO_OSTYPE_OPTEE) {
1746 strncpy(tee_mode, "optee", sizeof(tee_mode)-1);
1747 tee_mode[sizeof(tee_mode)-1] = '\n';
1748 } else if (osType == SYS_TEEINFO_OSTYPE_NUTTX) {
1749 strncpy(tee_mode, "nuttx", sizeof(tee_mode)-1);
1750 tee_mode[sizeof(tee_mode)-1] = '\n';
1751 } else {
1752 strncpy(tee_mode, "notee", sizeof(tee_mode)-1);
1753 tee_mode[sizeof(tee_mode)-1] = '\n';
1754 }
1755
1756 return 0;
1757 }
1758
MDrv_SYS_GetTEEInfo(SYS_TEEINFO * TeeInfo)1759 MS_U32 MDrv_SYS_GetTEEInfo(SYS_TEEINFO* TeeInfo)
1760 {
1761 if (!strcmp(tee_mode,"optee")) {
1762 TeeInfo->OsType = SYS_TEEINFO_OSTYPE_OPTEE;
1763 } else if (!strcmp(tee_mode,"nuttx")) {
1764 TeeInfo->OsType = SYS_TEEINFO_OSTYPE_NUTTX;
1765 }else{
1766 TeeInfo->OsType = SYS_TEEINFO_OSTYPE_NOTEE;
1767 }
1768
1769 return 0;
1770 }
1771
_MDrv_SYS_XcInputMapping(MS_U32 u32SourceType,E_SYS_SOURCE_TYPE * retSrcType)1772 E_SYS_ReturnValue _MDrv_SYS_XcInputMapping (MS_U32 u32SourceType, E_SYS_SOURCE_TYPE *retSrcType)
1773 {
1774 //
1775 // Input Source Mapping,
1776 //
1777 switch (u32SourceType)
1778 {
1779 case E_SYS_INPUT_SOURCE_DTV:
1780 case E_SYS_INPUT_SOURCE_DTV2:
1781 case E_SYS_INPUT_SOURCE_DTV3:
1782 *retSrcType = E_SYS_SOURCE_DTV;
1783 break;
1784
1785 case E_SYS_INPUT_SOURCE_HDMI:
1786 case E_SYS_INPUT_SOURCE_HDMI2:
1787 case E_SYS_INPUT_SOURCE_HDMI3:
1788 case E_SYS_INPUT_SOURCE_HDMI4:
1789 *retSrcType = E_SYS_SOURCE_HDMI;
1790 break;
1791
1792 case E_SYS_INPUT_SOURCE_STORAGE:
1793 *retSrcType = E_SYS_SOURCE_MM;
1794 break;
1795
1796 case E_SYS_INPUT_SOURCE_GOOGLE_CAST:
1797 *retSrcType = E_SYS_SOURCE_GOOGLE_CAST;
1798 break;
1799
1800 default:
1801 SYS_DBG_ERR ("Not support! Source type: %d\n", u32SourceType);
1802 return E_SYS_ERROR_PARAMETER;
1803 }
1804 return E_SYS_OK;
1805 }
1806
_MDrv_SYS_XcTimingMapping(MS_U32 u32Width,MS_U32 u32Height,MS_U32 u32FrameRate,E_SYS_INPUT_TIMING * retTimingType)1807 E_SYS_ReturnValue _MDrv_SYS_XcTimingMapping (MS_U32 u32Width, MS_U32 u32Height, MS_U32 u32FrameRate, E_SYS_INPUT_TIMING *retTimingType)
1808 {
1809 #define TIMING_TOLERANCE 20
1810 #define TIMING_FHD_W 1920
1811 #define TIMING_FHD_H 1080
1812 #define TIMING_4K_W 3840
1813 #define TIMING_4K_H 2160
1814
1815 MS_U32 _u32Width = 0x0, _u32Height = 0x0;
1816
1817 if ( u32Width <= (TIMING_FHD_W+TIMING_TOLERANCE) &&
1818 u32Width >= (TIMING_FHD_W-TIMING_TOLERANCE))
1819 {
1820 _u32Width = TIMING_FHD_W;
1821 }
1822 else if ( u32Width >= (TIMING_4K_W-TIMING_TOLERANCE))
1823 {
1824 //To set the width to 4K_W if the width is large than TIMING_4K_W
1825 _u32Width = TIMING_4K_W;
1826 }
1827
1828 if ( u32Height <= (TIMING_FHD_H+TIMING_TOLERANCE) &&
1829 u32Height >= (TIMING_FHD_H-TIMING_TOLERANCE))
1830 {
1831 _u32Height = TIMING_FHD_H;
1832 }
1833 else if ( u32Height >= (TIMING_4K_H-TIMING_TOLERANCE))
1834 {
1835 //To set the height to 4K_W if the height is large than TIMING_4K_H
1836 _u32Height = TIMING_4K_H;
1837 }
1838
1839 if (_u32Width == TIMING_FHD_W && _u32Height == TIMING_FHD_H)
1840 {
1841 switch (u32FrameRate)
1842 {
1843 case 24:
1844 case 25:
1845 case 30:
1846 *retTimingType = E_SYS_INPUT_FHD24_25_30;
1847 break;
1848 case 48:
1849 *retTimingType = E_SYS_INPUT_FHD48;
1850 break;
1851 case 50:
1852 case 59:
1853 case 60:
1854 *retTimingType = E_SYS_INPUT_FHD50_60;
1855 break;
1856 default:
1857 SYS_DBG_ERR ("FHD with unknown frame rate: %d\n", u32FrameRate);
1858 *retTimingType = E_SYS_INPUT_FHD_UNKNOWN;
1859 break;
1860 }
1861 }
1862 else if (_u32Width == TIMING_4K_W && _u32Height == TIMING_4K_H)
1863 {
1864 switch (u32FrameRate)
1865 {
1866 case 24:
1867 case 25:
1868 case 30:
1869 *retTimingType = E_SYS_INPUT_4K2K24_25_30;
1870 break;
1871 case 48:
1872 *retTimingType = E_SYS_INPUT_4K2K48;
1873 break;
1874 case 50:
1875 case 59:
1876 case 60:
1877 *retTimingType = E_SYS_INPUT_4K2K50_60;
1878 break;
1879 case 120:
1880 *retTimingType = E_SYS_INPUT_4K2K120;
1881 break;
1882 default:
1883 //Special Case
1884 if (u32FrameRate >=100 && u32FrameRate < 120)
1885 {
1886 *retTimingType = E_SYS_INPUT_4K2K120;
1887 }
1888 else
1889 {
1890 SYS_DBG_ERR ("4k2k with unknown frame rate: %d\n", u32FrameRate);
1891 *retTimingType = E_SYS_INPUT_4K2K_UNKNOWN;
1892 }
1893 SYS_DBG_ERR ("4k2k with unknown frame rate: %d\n", u32FrameRate);
1894 break;
1895 }
1896 }
1897 else
1898 {
1899 SYS_DBG_ERR ("Not Mapped timing! W: %d, H: %d, F: %d\n", u32Width, u32Height, u32FrameRate);
1900 return E_SYS_NOT_SUPPORT;
1901 }
1902
1903 return E_SYS_OK;
1904 }
1905
MDrv_SYS_GetMemcConfg(MS_U32 u32SourceType,SYS_XC_TIMING_t * stXCTiming,MS_BOOL * retEnMemc)1906 E_SYS_ReturnValue MDrv_SYS_GetMemcConfg(MS_U32 u32SourceType, SYS_XC_TIMING_t *stXCTiming, MS_BOOL *retEnMemc)
1907 {
1908 E_SYS_SOURCE_TYPE eSource = E_SYS_SOURCE_DTV;
1909 E_SYS_INPUT_TIMING eTiming = E_SYS_INPUT_MAX;
1910
1911 if (stXCTiming == NULL || retEnMemc == NULL)
1912 {
1913 SYS_DBG_ERR ("stXCTiming == NULL || retEnMemc == NULL\n");
1914 return E_SYS_ERROR_PARAMETER;
1915 }
1916
1917 if (stXCTiming->u32TimingVersion <= MDRV_SYS_XC_TIMING_VERSION &&
1918 stXCTiming->u32StructLength <= sizeof (SYS_XC_TIMING_t))
1919 {
1920
1921 SYS_DBG_INFO ("Source: %d, u32Width: %d, u32Height: %d, u16Framerate: %d\n",
1922 u32SourceType, stXCTiming->u32Width, stXCTiming->u32Height, stXCTiming->u16Framerate);
1923
1924 //
1925 // Input Source Type Mapping
1926 //
1927 if ( _MDrv_SYS_XcInputMapping (u32SourceType, &eSource) != E_SYS_OK)
1928 {
1929 SYS_DBG_ERR ("Unmapped source type: %d\n", u32SourceType);
1930 return E_SYS_ERROR_PARAMETER;
1931 }
1932
1933 //
1934 // Input Timing Mapping
1935 //
1936 if ( _MDrv_SYS_XcTimingMapping (stXCTiming->u32Width, stXCTiming->u32Height, stXCTiming->u16Framerate, &eTiming) != E_SYS_OK)
1937 {
1938 //
1939 //Error Handling,
1940 //Unable to determeternate the timing,
1941 //Config is up to frame rate only.
1942 //
1943 SYS_DBG_ERR ("Not support! Timing, W:%d, H:%d, F:%d\n", stXCTiming->u32Width, stXCTiming->u32Height, stXCTiming->u16Framerate);
1944 if (stXCTiming->u16Framerate > 30 )
1945 {
1946 eTiming = E_SYS_INPUT_ALWAYS_OFF;
1947 }
1948 else
1949 {
1950 eTiming = E_SYS_INPUT_ALWAYS_ON;
1951 }
1952 }
1953 } //End of Version check, #define MDRV_SYS_XC_TIMING_VERSION 0x00000001UL
1954 else
1955 {
1956 SYS_DBG_ERR ("Version Error! Please update drvSYS\n");
1957 return E_SYS_FAIL;
1958 }
1959
1960 return HAL_SYS_GetMemcConfg (eSource, eTiming, retEnMemc);
1961 }
1962
_MDrv_SYS_GetXcByPartConfg(MS_U32 u32SourceType,SYS_XC_BYPART_TIMING_t * stInfo,MS_BOOL * retEn)1963 E_SYS_ReturnValue _MDrv_SYS_GetXcByPartConfg(MS_U32 u32SourceType, SYS_XC_BYPART_TIMING_t *stInfo, MS_BOOL *retEn)
1964 {
1965 E_SYS_SOURCE_TYPE eSource = E_SYS_SOURCE_DTV;
1966 E_SYS_INPUT_TIMING eInputTiming = E_SYS_INPUT_MAX;
1967 E_SYS_INPUT_TIMING eOutputTiming = E_SYS_INPUT_MAX;
1968
1969 if (stInfo == NULL || retEn == NULL)
1970 {
1971 SYS_DBG_ERR ("stInfo == NULL || retEnMemc == NULL\n");
1972 return E_SYS_ERROR_PARAMETER;
1973 }
1974
1975 if (stInfo->u32TimingVersion <= MDRV_SYS_XC_BYPART_TIMING_VERSION &&
1976 stInfo->u32StructLength <= sizeof (SYS_XC_BYPART_TIMING_t))
1977 {
1978 SYS_DBG_INFO ("Source: %d, Input(W: %d, H: %d, F: %d), Output(W: %d, H: %d, F: %d)\n",
1979 u32SourceType, stInfo->stInput.u32Width, stInfo->stInput.u32Height, stInfo->stInput.u16Framerate,
1980 stInfo->stOutput.u32Width, stInfo->stOutput.u32Height, stInfo->stOutput.u16Framerate);
1981
1982 //
1983 // Input Source Type Mapping
1984 //
1985 if ( _MDrv_SYS_XcInputMapping (u32SourceType, &eSource) != E_SYS_OK)
1986 {
1987 SYS_DBG_ERR ("Unmapped source type: %d\n", u32SourceType);
1988 return E_SYS_ERROR_PARAMETER;
1989 }
1990
1991 //
1992 // Input Timing Mapping
1993 //
1994 _MDrv_SYS_XcTimingMapping (stInfo->stInput.u32Width, stInfo->stInput.u32Height, stInfo->stInput.u16Framerate, &eInputTiming);
1995 _MDrv_SYS_XcTimingMapping (stInfo->stOutput.u32Width, stInfo->stOutput.u32Height, stInfo->stOutput.u16Framerate, &eOutputTiming);
1996
1997 }
1998 return HAL_SYS_GetXcByPartConfg (eSource, eInputTiming, eOutputTiming, retEn);
1999 }
2000
MDrv_SYS_GetQoSConfig(E_SYS_QOS_QUERY_TYPE eQueryType,MS_U32 u32SourceType,void * stInfo,MS_BOOL * retEn)2001 E_SYS_ReturnValue MDrv_SYS_GetQoSConfig(E_SYS_QOS_QUERY_TYPE eQueryType, MS_U32 u32SourceType, void *stInfo, MS_BOOL *retEn)
2002 {
2003 E_SYS_ReturnValue eRet = E_SYS_NOT_SUPPORT;
2004
2005 if (stInfo == NULL || retEn == NULL)
2006 {
2007 SYS_DBG_ERR ("Error Parameters\n");
2008 return E_SYS_ERROR_PARAMETER;
2009 }
2010
2011 switch (eQueryType)
2012 {
2013 case E_SYS_QOS_QUERY_XC_BYPART_EN:
2014 eRet = _MDrv_SYS_GetXcByPartConfg (u32SourceType, (SYS_XC_BYPART_TIMING_t *)stInfo, retEn);
2015 break;
2016
2017 case E_SYS_QOS_QUERY_MEMC_EN:
2018 eRet = MDrv_SYS_GetMemcConfg (u32SourceType, (SYS_XC_TIMING_t *)stInfo, retEn);
2019 break;
2020
2021 default:
2022 SYS_DBG_ERR ("Unknown Query Type: %d\n", eQueryType);
2023 eRet = E_SYS_ERROR_PARAMETER;
2024 break;
2025 };
2026
2027 return eRet;
2028 }
2029