xref: /utopia/UTPA2-700.0.x/modules/xc/utopia_adaption/xc/XC_ModeParse_adp.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// file    XC_ModeParse_adp.c
80 /// @brief  Scaler API layer Interface.
81 /// @author MStar Semiconductor Inc.
82 ////////////////////////////////////////////////////////////////////////////////
83 
84 #ifndef _XC_MODEPARSE_ADP_C_
85 #define _XC_MODEPARSE_ADP_C_
86 
87 //------------------------------------------------------------------------------
88 //  Include Files
89 //------------------------------------------------------------------------------
90 // Common Definition
91 #include <linux/kernel.h>
92 #include <linux/sched.h>
93 #include <linux/string.h>
94 #include <linux/slab.h>
95 #include <linux/uaccess.h>
96 #include <linux/compat.h>
97 #include "MsTypes.h"
98 #include "utopia.h"
99 #include "utopia_adp.h"
100 #include "MsOS.h"
101 
102 // Internal Definition
103 #include "drvXC_IOPort.h"
104 #include "apiXC.h"
105 #include "apiXC_ModeParse.h"
106 #include "apiXC_ModeParse_v2.h"
107 #include "apiXC_v2.h"
108 #include "XC_ModeParse_adp.h"
109 #include "XC_adp.h"
110 
111 
112 #define MAX_MODEPARSER_TAB_NUM 100
113 //------------------------------------------------------------------------------
114 //  Driver Compiler Options
115 //------------------------------------------------------------------------------
116 
117 //------------------------------------------------------------------------------
118 //  Local Defines
119 //------------------------------------------------------------------------------
120 
121 #ifdef MSOS_TYPE_LINUX_KERNEL
122 #define CPY_FROM_USER(a,b,c)                                    if(copy_from_user(a,b,c) != 0) { break; }
123 #define CPY_to_USER(a,b,c)                                      if(copy_to_user(a,b,c) != 0) { break; }
124 #else
125 #define CPY_FROM_USER                                           memcpy
126 #define CPY_to_USER                                             memcpy
127 #endif  //MSOS_TYPE_LINUX_KERNEL
128 
129 #if (defined(MSOS_TYPE_LINUX_KERNEL) && defined(CONFIG_COMPAT))
130 #define COMPAT_PTR(a)                                           compat_ptr(a)
131 #define COMPAT_NEXT_PTR(a)                                      (*((MS_U32*)compat_ptr((unsigned long)a)))
132 #define IS_CMP_TASK()                                             is_compat_task()
133 
134 #define CMP_CPY_FROM_USER(a,b,c)                                if(copy_from_user(a, compat_ptr((unsigned long)b), c) != 0)  {  break; }
135 #define CMP_CPY_TO_USER(a,b,c)                                  if(copy_to_user(compat_ptr((unsigned long)a), b, c) != 0) { break;  }
136 
137 #else
138 #define COMPAT_PTR(a)                                           (a)
139 #define COMPAT_NEXT_PTR(a)                                      (*((MS_U32*)a))
140 #define IS_CMP_TASK()                                             (FALSE)
141 #define CMP_CPY_FROM_USER                                       CPY_FROM_USER
142 #define CMP_CPY_TO_USER                                         CPY_to_USER
143 #endif //CONFIG_COMPAT
144 //------------------------------------------------------------------------------
145 //  Local Structurs
146 //------------------------------------------------------------------------------
147 
148 //------------------------------------------------------------------------------
149 //  Global Variables
150 //------------------------------------------------------------------------------
151 #ifdef CONFIG_COMPAT
152 typedef struct DLL_PACKED
153 {
154     compat_uptr_t ModeDB;
155     MS_U8 u8NumberOfItems;
156     compat_uptr_t psInputInfo;
157     XC_MODEPARSE_RESULT eReturnValue;
158 } _compat_stXC_MODEPARSE_MATCHMODE;
159 #endif
160 //Function parameter
161 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_INIT[5];
162 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_MATCHMODE[5];
163 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_MATCHMODEEX[5];
164 
165 //Function parameter's pointer
166 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_MODETABLE_TYPE[5];
167 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_INPUT_INFO[5];
168 UADP_STRUCT_POINTER_TABLE spt_XC_MODEPARSE_MODETABLE_TYPE_EX[5];
169 
170 
171 //------------------------------------------------------------------------------
172 //  Local Variables
173 //------------------------------------------------------------------------------
174 
175 //------------------------------------------------------------------------------
176 //  Debug Functions
177 //------------------------------------------------------------------------------
178 
179 //------------------------------------------------------------------------------
180 //  Local Functions
181 //------------------------------------------------------------------------------
182 
183 //------------------------------------------------------------------------------
184 //  Global Functions
185 //------------------------------------------------------------------------------
XC_MODEPARSE_adp_Init(void)186 MS_U32 XC_MODEPARSE_adp_Init(void)
187 {
188 
189 //set table
190     MS_U32 temp=0;
191 
192     //Function parameter
193     //pstXC_MODEPARSE_INIT         pXC_MODEPARSE_INIT        = (pstXC_MODEPARSE_INIT)temp;
194     pstXC_MODEPARSE_MATCHMODE    pXC_MODEPARSE_MATCHMODE   = (pstXC_MODEPARSE_MATCHMODE)temp;
195     pstXC_MODEPARSE_MATCHMODEEX  pXC_MODEPARSE_MATCHMODEEX = (pstXC_MODEPARSE_MATCHMODEEX)temp;
196 
197 
198     //Function parameter's pointer
199     //MS_PCADC_MODETABLE_TYPE*     pXC_MODEPARSE_ModeDB      = (MS_PCADC_MODETABLE_TYPE*)temp;
200     //XC_MODEPARSE_INPUT_INFO*     pXC_MODEPARSE_InputInfo   = (XC_MODEPARSE_INPUT_INFO*)temp;
201     //MS_PCADC_MODETABLE_TYPE_EX*  pXC_MODEPARSE_ModeDB_EX   = (MS_PCADC_MODETABLE_TYPE_EX*)temp;
202 
203     //Function parameter's pointer
204     UADPBypassSetSPT(&spt_XC_MODEPARSE_MODETABLE_TYPE[0],UADP_SPT_SELF_SIZE,0, sizeof(MS_PCADC_MODETABLE_TYPE)*100);
205     UADPBypassSetSPT(&spt_XC_MODEPARSE_MODETABLE_TYPE[1],UADP_SPT_END , 0, 0);
206 
207     UADPBypassSetSPT(&spt_XC_MODEPARSE_INPUT_INFO[0],UADP_SPT_SELF_SIZE,0, sizeof(XC_MODEPARSE_INPUT_INFO));
208     UADPBypassSetSPT(&spt_XC_MODEPARSE_INPUT_INFO[1],UADP_SPT_END , 0, 0);
209 
210     UADPBypassSetSPT(&spt_XC_MODEPARSE_MODETABLE_TYPE_EX[0],UADP_SPT_SELF_SIZE,0, sizeof(MS_PCADC_MODETABLE_TYPE_EX)*MAX_MODEPARSER_TAB_NUM);
211     UADPBypassSetSPT(&spt_XC_MODEPARSE_MODETABLE_TYPE_EX[1],UADP_SPT_END , 0, 0);
212 
213     //Function parameter
214     UADPBypassSetSPT(&spt_XC_MODEPARSE_INIT[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_MODEPARSE_INIT));
215     UADPBypassSetSPT(&spt_XC_MODEPARSE_INIT[1],UADP_SPT_END , 0, 0);
216 
217     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODE[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_MODEPARSE_MATCHMODE));
218     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODE[1],UADP_SPT_POINTER_TO_NEXT,
219         ((unsigned long)(&(pXC_MODEPARSE_MATCHMODE->ModeDB)) - (unsigned long)pXC_MODEPARSE_MATCHMODE), (unsigned long)spt_XC_MODEPARSE_MODETABLE_TYPE);
220     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODE[2],UADP_SPT_POINTER_TO_NEXT,
221         ((unsigned long)(&(pXC_MODEPARSE_MATCHMODE->psInputInfo)) - (unsigned long)pXC_MODEPARSE_MATCHMODE), (unsigned long)spt_XC_MODEPARSE_INPUT_INFO);
222     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODE[3],UADP_SPT_END , 0, 0);
223 
224     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODEEX[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_MODEPARSE_MATCHMODEEX));
225     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODEEX[1],UADP_SPT_POINTER_TO_NEXT,
226         ((unsigned long)(&(pXC_MODEPARSE_MATCHMODEEX->ModeDB)) - (unsigned long)pXC_MODEPARSE_MATCHMODEEX), (unsigned long)spt_XC_MODEPARSE_MODETABLE_TYPE_EX);
227     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODEEX[2],UADP_SPT_POINTER_TO_NEXT,
228         ((unsigned long)(&(pXC_MODEPARSE_MATCHMODEEX->psInputInfo)) - (unsigned long)pXC_MODEPARSE_MATCHMODEEX), (unsigned long)spt_XC_MODEPARSE_INPUT_INFO);
229     UADPBypassSetSPT(&spt_XC_MODEPARSE_MATCHMODEEX[3],UADP_SPT_END , 0, 0);
230 
231 
232     return 0;
233 
234 }
235 
XC_MODEPARSE_adp_Ioctl(void * pInstanceTmp,MS_U32 u32Cmd,void * const pArgs)236 MS_U32 XC_MODEPARSE_adp_Ioctl(void* pInstanceTmp, MS_U32 u32Cmd, void* const pArgs)
237 {
238     MS_U32 u32Ret;
239     char buffer_arg[2];
240 
241     switch(u32Cmd)
242     {
243 
244         case E_XC_MODEPARSE_CMD_INIT :
245         {
246             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,NULL, spt_XC_MODEPARSE_INIT,buffer_arg,sizeof(buffer_arg));
247             break;
248         }
249 
250         case E_XC_MODEPARSE_CMD_MATCHMODE:
251         {
252             stXC_MODEPARSE_MATCHMODE tmp;
253 #ifdef CONFIG_COMPAT
254             _compat_stXC_MODEPARSE_MATCHMODE tmp_compat;
255             if(IS_CMP_TASK())
256             {
257                 CMP_CPY_FROM_USER(&tmp_compat, pArgs, sizeof(_compat_stXC_MODEPARSE_MATCHMODE));
258                 tmp.ModeDB = malloc(sizeof(MS_PCADC_MODETABLE_TYPE)*tmp_compat.u8NumberOfItems);
259                 tmp.psInputInfo = malloc(sizeof(XC_MODEPARSE_INPUT_INFO));
260                 CMP_CPY_FROM_USER(tmp.ModeDB, tmp_compat.ModeDB, sizeof(MS_PCADC_MODETABLE_TYPE)*tmp_compat.u8NumberOfItems);
261                 CMP_CPY_FROM_USER(tmp.psInputInfo, tmp_compat.psInputInfo, sizeof(XC_MODEPARSE_INPUT_INFO));
262                 tmp.u8NumberOfItems=tmp_compat.u8NumberOfItems;
263                 tmp.eReturnValue=tmp_compat.eReturnValue;
264                 u32Ret = UtopiaIoctl(pInstanceTmp,u32Cmd,&tmp);
265                 tmp_compat.eReturnValue = tmp.eReturnValue;
266                 tmp_compat.u8NumberOfItems = tmp.u8NumberOfItems;
267                 //CMP_CPY_TO_USER(tmp_compat.ModeDB,tmp.ModeDB,sizeof(MS_PCADC_MODETABLE_TYPE));                //example
268                 CMP_CPY_TO_USER(tmp_compat.psInputInfo,tmp.psInputInfo,sizeof(XC_MODEPARSE_INPUT_INFO));
269                 CMP_CPY_TO_USER(pArgs,&tmp_compat,sizeof(_compat_stXC_MODEPARSE_MATCHMODE));
270                 free(tmp.ModeDB);
271                 free(tmp.psInputInfo);
272             }else
273             {
274 #endif
275                 void *ptr;
276                 void *ptr1;
277                 CPY_FROM_USER(&tmp, pArgs, sizeof(stXC_MODEPARSE_MATCHMODE));
278                 ptr=tmp.ModeDB;
279                 ptr1=tmp.psInputInfo;
280                 tmp.ModeDB = malloc(sizeof(MS_PCADC_MODETABLE_TYPE)*tmp.u8NumberOfItems);
281                 tmp.psInputInfo = malloc(sizeof(XC_MODEPARSE_INPUT_INFO));
282                 CPY_FROM_USER(tmp.ModeDB, ptr, sizeof(MS_PCADC_MODETABLE_TYPE)*tmp.u8NumberOfItems);
283                 CPY_FROM_USER(tmp.psInputInfo, ptr1, sizeof(XC_MODEPARSE_INPUT_INFO));
284                 u32Ret = UtopiaIoctl(pInstanceTmp,u32Cmd,&tmp);
285                 CPY_to_USER(pArgs,&tmp,sizeof(stXC_MODEPARSE_MATCHMODE));
286                 free(tmp.ModeDB);
287                 free(tmp.psInputInfo);
288 #ifdef CONFIG_COMPAT
289             }
290 #endif
291             break;
292         }
293 
294         case E_XC_MODEPARSE_CMD_MATCHMODEEX:
295         {
296             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_MODEPARSE_MATCHMODEEX, spt_XC_MODEPARSE_MATCHMODEEX,buffer_arg,sizeof(buffer_arg));
297             break;
298         }
299 
300         case E_XC_MODEPARSE_CMD_NONE:
301         case E_XC_MODEPARSE_CMD_MAX:
302         default:
303         {
304             printf("Command %ld is not existed\n",u32Cmd);
305             u32Ret = UTOPIA_STATUS_ERR_INVALID_HANDLE;
306             break;
307         }
308 
309     }
310 
311 	return u32Ret;
312    // return UtopiaIoctl(pModuleDDI->pInstant,u32Cmd,arg);
313 }
314 
315 #endif
316 
317 
318