xref: /utopia/UTPA2-700.0.x/modules/msos/utopia_adaption/utopia/utopia_dev.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 
2 //-------------------------------------------------------------------------------------------------
3 //  Include Files
4 //-------------------------------------------------------------------------------------------------
5 
6 #if !defined(MSOS_TYPE_LINUX_KERNEL)
7 #include <stdio.h>
8 #include <string.h>
9 
10 #else
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/slab.h>
14 #endif
15 
16 #include <linux/namei.h>
17 #include <linux/proc_fs.h>
18 #include <linux/uaccess.h>
19 #include <linux/ioctl.h>
20 #include <linux/seq_file.h>
21 
22 #include "utopia_private.h"
23 #include "utopia.h"
24 #include "utopia_dapi.h"
25 #include "MsOS.h"
26 #include "drvMMIO.h"
27 #include "utopia_driver_id.h"
28 #include "MsTypes.h"
29 #include "utopia_adp.h"
30 //#include "drvMIU.h"
31 #include "drvSYS.h"
32 #include "drvDMD_VD_MBX.h"
33 #include "utopia_dev.h"
34 #ifdef CONFIG_UTOPIA_GARBAGE_COLLECTION
35 #include <linux/sched.h>
36 #endif
37 //-------------------------------------------------------------------------------------------------
38 //  Macro and Define
39 //-------------------------------------------------------------------------------------------------
40 #if 1
41 #define PREFIX(MODULE) \
42 	extern __attribute__((weak)) MS_U32 MODULE##_adp_Init(FUtopiaIOctl* pIoctl);
43 INCLUDED_MODULE
44 #undef PREFIX
45 #endif
46 //u32Ret |= MODULE##_adp_Init(((UTOPIA2K_ADP*)filp->private_data)->fpIoctl);
47 
48 #define MPOOL_DIVIDE_32M_WORKAROUND_PATCH   0
49 
50 typedef unsigned char               MS_NULL;
51 UTOPIA_AUTH_IPCHECK_ARG* gIpAuthVars = NULL;
52 MS_U8 gCusID[] = {0x00,0x00};
53 MS_U8 gCusHash[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
54                      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
55 //-------------------------------------------------------------------------------------------------
56 //  Local Defines
57 //-------------------------------------------------------------------------------------------------
58 MS_U8 MDrv_AUTH_IPCheck(MS_U8 u8Bit);
59 void MDrv_AUTH_GetHashInfo (MS_U8 *hashinfo);
60 static DEFINE_MUTEX(_Msos_Mapping_Mutex);
61 static DEFINE_MUTEX(_MdbFpioctlList_Mutex);
62 
63 #if MPOOL_DIVIDE_32M_WORKAROUND_PATCH
64 #define DIVIDE_SIZE     (32<<20)
65 static MS_BOOL _MPOOL_Divide_Mapping(MS_U8 u8MiuSel, MS_U32 u32Offset, MS_U32 u32MapSize, MS_BOOL bNonCache);
66 #endif
67 
68 #ifdef CONFIG_UTOPIA_GARBAGE_COLLECTION
69 extern void Utopia2K_resource_collection_Register(void (*callback)(pid_t pid));
70 #endif
71 //--------------//
72 // Global Variable
73 //--------------//
74 UTOPIA_PID_LIST *g_Utopia_PID_root = NULL;
75 extern struct mutex _Utopia_Instance_Mutex;
76 
77 
78 #if defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_64BIT) || defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_32BIT)
79 
80 typedef MS_U32 (*FUIOCTLSetModule_adp_Init)(FUtopiaIOctl* pIoctl);
81 
emptyIoctlSetModule(FUtopiaIOctl * pIoctl)82 MS_U32 emptyIoctlSetModule(FUtopiaIOctl* pIoctl){
83     //printu("[utopia info] emptyIoctlSetModule\n" );
84     return 0;
85 }
86 
87 #define PREFIX(MODULE) \
88     FUIOCTLSetModule_adp_Init MODULE##IOCTLSetModule_adp_Init = emptyIoctlSetModule;
89     INCLUDED_MODULE
90 #undef PREFIX
91 
autoIoctlSetModule(void)92 MS_U32 autoIoctlSetModule(void)
93 {
94 
95 #define PREFIX(MODULE) \
96     if (MODULE##_adp_Init != NULL) \
97     { \
98         MODULE##IOCTLSetModule_adp_Init = MODULE##_adp_Init; \
99     }
100     INCLUDED_MODULE
101 #undef PREFIX
102 
103 
104     return 0;
105 }
106 
107 #endif
108 
109 #if defined(CONFIG_COMPAT)
utopia_proc_ioctl_compat(struct file * filp,unsigned int cmd,void * arg)110 static long utopia_proc_ioctl_compat(struct file *filp, unsigned int cmd, void* arg)
111 {
112 	int	err= 0;
113 	switch(cmd){
114 		case UTOPIA_IOCTL_SetMODULE_COMPAT :
115 		{
116 			//printk("\033[0;32;31m [Ian] %s %d Enter\033[m\n",__func__,__LINE__);
117 			compat_uint_t i;
118 			compat_uptr_t p;
119 			UTOPIA_DDI_OPEN_ARG_32 __user *data32;
120 			UTOPIA_DDI_OPEN_ARG __user *data;
121 			data = compat_alloc_user_space(sizeof(*data));
122 			if (data == NULL)
123 				return -EFAULT;
124 			data32 = compat_ptr(arg);
125 			err = get_user(i, &data32->u32ModuleID);
126 			err |= put_user(i, &data->u32ModuleID);
127 			err |= get_user(i, &data32->u32ModuleVersion);
128 			err |= put_user(i, &data->u32ModuleVersion);
129 			err |= get_user(p, &data32->pAttribute);
130 			err |= put_user(compat_ptr(p), &data->pAttribute);
131 			if (err)
132 				return err;
133 			//printk("\033[0;32;31m [Ian] %s %d Exit\033[m\n",__func__,__LINE__);
134 			return filp->f_op->unlocked_ioctl(filp, UTOPIA_IOCTL_SetMODULE,data);
135 		}
136 		case UTOPIA_IOCTL_IoctlMODULE_COMPAT :
137 		{
138 			//printk("\033[0;32;31m [Ian] %s %d Enter\033[m\n",__func__,__LINE__);
139 			compat_uint_t i;
140 			compat_uptr_t p;
141 			UTOPIA_DDI_IOCTL_ARG_32 __user *data32;
142 			UTOPIA_DDI_IOCTL_ARG __user *data;
143 			data = compat_alloc_user_space(sizeof(*data));
144 			if (data == NULL)
145 				return -EFAULT;
146 			data32 = compat_ptr(arg);
147 			err = get_user(i, &data32->u32Cmd);
148 			err |= put_user(i, &data->u32Cmd);
149 			err |= get_user(p, &data32->pArg);
150 			err |= put_user(compat_ptr(p), &data->pArg);
151 			if (err)
152 				return err;
153 			//printk("\033[0;32;31m [Ian] %s %d Exit\033[m\n",__func__,__LINE__);
154 			return filp->f_op->unlocked_ioctl(filp, UTOPIA_IOCTL_IoctlMODULE,data);
155 		}
156 
157 		case UTOPIA_IOCTL_MODULE_DYNAMIC_MAPPING_COMPAT :
158 		{
159 			//printk("\033[0;32;31m [Ian] %s %d Enter\033[m\n",__func__,__LINE__);
160 			compat_uint_t i;
161 			compat_uptr_t p;
162 			KDrvMPool_Info_t_ARG_32 __user *data32;
163 			KDrvMPool_Info_t __user *data;
164 			data = compat_alloc_user_space(sizeof(*data));
165 			if (data == NULL)
166 				return -EFAULT;
167 			data32 = compat_ptr(arg);
168 			err = get_user(i, &data32->u32Addr);
169 			err |= put_user(i, &data->u32Addr);
170 			err |= get_user(i, &data32->u32Size);
171 			err |= put_user(i, &data->u32Size);
172 			err |= get_user(i, &data32->u32Interval);
173 			err |= put_user(i, &data->u32Interval);
174 			err |= get_user(i, &data32->u8MiuSel);
175 			err |= put_user(i, &data->u8MiuSel);
176 			err |= get_user(i, &data32->bcached);
177 			err |= put_user(i, &data->bcached);
178 
179 			//err |= put_user(compat_ptr(p), &data->pArg);
180 			if (err)
181 				return err;
182 			//printk("\033[0;32;31m [Ian] %s %d Exit\033[m\n",__func__,__LINE__);
183 			return filp->f_op->unlocked_ioctl(filp, UTOPIA_IOCTL_MODULE_DYNAMIC_MAPPING,data);
184 		}
185 		default: //Other case
186 			return filp->f_op->unlocked_ioctl(filp, cmd,(unsigned long)compat_ptr(arg));
187 	}
188 }
189 #endif
190 
191 //-------------------------------------------------------------------------------------------------
192 //  Local Functions
193 //-------------------------------------------------------------------------------------------------
194 volatile  void *tmpFP = VDEC_EX_adp_Init;
utopia_proc_ioctl(struct file * filp,unsigned int cmd,void * arg)195 static long utopia_proc_ioctl(struct file *filp, unsigned int cmd, void* arg)
196 {
197    //UADPBypassIoctl(struct file *filp, unsigned int cmd, void* arg,UADP_STRUCT_POINTER_TABLE *pInTable, UADP_STRUCT_POINTER_TABLE *pOutTable);
198     UTOPIA_DDI_OPEN_ARG sOpenArg;
199     UTOPIA_DDI_IOCTL_ARG sIoctlArg;
200     MS_U32 u32Ret = UTOPIA_STATUS_FAIL;
201     MS_U32 ret = UTOPIA_STATUS_FAIL;
202     KDrvMPool_Info_t i;
203     UTOPIA_AUTH_IPCHECK_ARG sIPCheckArg;
204     UTOPIA_AUTH_HASHINFO_ARG sHashInfoArg;
205 
206     switch(cmd){
207     case UTOPIA_IOCTL_SetMODULE :
208 		copy_from_user(&sOpenArg,arg,sizeof(UTOPIA_DDI_OPEN_ARG));
209 
210 		switch(sOpenArg.u32ModuleID){
211 #if defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_64BIT) || defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_32BIT)
212 
213         #define PREFIX(MODULE) \
214 		case MODULE_##MODULE : \
215 				if (MODULE##_adp_Init != NULL) \
216 				{ \
217 					printk("utopia_proc_ioctl: setModule : %d  \n", MODULE_##MODULE); \
218                         u32Ret = (*(MODULE##IOCTLSetModule_adp_Init))(&(((UTOPIA2K_ADP*)(filp->private_data))->fpIoctl)); \
219 				}else  \
220 				{ \
221 				    printk("utopia_proc_ioctl: setModule error : %d  \n", MODULE_##MODULE); \
222 				    u32Ret = UTOPIA_STATUS_FAIL; \
223 				    break; \
224 				} \
225                 u32Ret = UtopiaOpen(sOpenArg.u32ModuleID,&(((UTOPIA2K_ADP*)(filp->private_data))->pInstant),sOpenArg.u32ModuleVersion,sOpenArg.pAttribute); \
226 		        break;
227         INCLUDED_MODULE
228         #undef PREFIX
229 
230 #else
231 
232         #define PREFIX(MODULE) \
233 		case MODULE_##MODULE : \
234 				if (MODULE##_adp_Init != NULL) \
235 				{ \
236 					printk("utopia_proc_ioctl: setModule : %d  \n", MODULE_##MODULE); \
237 					u32Ret |= MODULE##_adp_Init(&(((UTOPIA2K_ADP*)(filp->private_data))->fpIoctl)); \
238 				}else  \
239 				{ \
240 				    printk("utopia_proc_ioctl: setModule error : %d  \n", MODULE_##MODULE); \
241 				    u32Ret = UTOPIA_STATUS_FAIL; \
242 				    break; \
243 				} \
244                 u32Ret = UtopiaOpen(sOpenArg.u32ModuleID,&(((UTOPIA2K_ADP*)(filp->private_data))->pInstant),sOpenArg.u32ModuleVersion,sOpenArg.pAttribute); \
245 		        break;
246         INCLUDED_MODULE
247         #undef PREFIX
248 
249 #endif //CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_64BIT
250 		default:
251 		        printk("utopia_proc_ioctl: setModule error, no this module: %ld  \n",sOpenArg.u32ModuleID);
252 			    break;
253 			}
254 		break;
255 	case UTOPIA_IOCTL_IoctlMODULE:
256 		copy_from_user(&sIoctlArg,arg,sizeof(UTOPIA_DDI_IOCTL_ARG));
257 		u32Ret = ((UTOPIA2K_ADP*)(filp->private_data))->fpIoctl(((UTOPIA2K_ADP*)(filp->private_data))->pInstant,sIoctlArg.u32Cmd,sIoctlArg.pArg);
258         //u32Ret = ((UTOPIA2K_ADP*)(filp->private_data))->fpIoctl(((UTOPIA2K_ADP*)(filp->private_data))->pInstant,cmd,arg);
259         break;
260 
261 	case UTOPIA_IOCTL_CloseMODULE:
262 		//copy_from_user(&sIoctlArg,arg,sizeof(UTOPIA_DDI_IOCTL_ARG));
263 		u32Ret = UtopiaClose((((UTOPIA2K_ADP*)(filp->private_data))->pInstant));
264 		break;
265 
266 
267     case UTOPIA_IOCTL_MODULE_DYNAMIC_MAPPING:
268 
269         mutex_lock(&_Msos_Mapping_Mutex);
270 
271         if(copy_from_user(&i, (void __user *)arg, sizeof(i)))
272         {
273             u32Ret = UTOPIA_STATUS_FAIL;
274 			mutex_unlock(&_Msos_Mapping_Mutex);
275 			break;
276         }
277 
278 #if MPOOL_DIVIDE_32M_WORKAROUND_PATCH
279 		if(_MPOOL_Divide_Mapping(i.u8MiuSel,i.u32Addr,i.u32Size,!i.bcached))
280 		{
281 		    u32Ret = UTOPIA_STATUS_SUCCESS;
282 		}else
283 		{
284 		    u32Ret = UTOPIA_STATUS_FAIL;
285 		}
286 #else
287 		if(MsOS_MPool_Mapping_Dynamic(i.u8MiuSel,i.u32Addr,i.u32Size,!i.bcached))
288 		{
289 		    u32Ret = UTOPIA_STATUS_SUCCESS;
290 		}else
291 		{
292 		    u32Ret = UTOPIA_STATUS_FAIL;
293 		}
294 #endif
295 
296 
297         //u32Ret = MsOS_MPool_Mapping_Dynamic(i.u8MiuSel,i.u32Addr,i.u32Size,!i.bcached);
298         mutex_unlock(&_Msos_Mapping_Mutex);
299 
300         break;
301 
302     case UTOPIA_IOCTL_AUTH_SetIPCheck:
303         copy_from_user(&sIPCheckArg,arg,sizeof(UTOPIA_AUTH_IPCHECK_ARG));
304         if(gIpAuthVars==NULL)
305         {
306             gIpAuthVars=malloc(sizeof(UTOPIA_AUTH_IPCHECK_ARG));
307         }
308         memcpy(gIpAuthVars, &sIPCheckArg, sizeof(UTOPIA_AUTH_IPCHECK_ARG));
309         break;
310     case UTOPIA_IOCTL_AUTH_SetHashInfo:
311         copy_from_user(&sHashInfoArg,arg,sizeof(UTOPIA_AUTH_HASHINFO_ARG));
312         memcpy(gCusID, sHashInfoArg.u8CusID, sizeof(gCusID));
313         memcpy(gCusHash, sHashInfoArg.u8CusHash, sizeof(gCusHash));
314         break;
315 
316 	default:
317 		printk("utopia_proc_ioctl error :default \n");
318         //u32Ret = ((UTOPIA2K_ADP*)(filp->private_data))->fpIoctl(((UTOPIA2K_ADP*)(filp->private_data))->pInstant,cmd,arg);
319         break;
320 
321 	}
322 
323 	return u32Ret;
324 
325 }
326 
MDrv_AUTH_IPCheck(MS_U8 u8Bit)327 MS_U8 MDrv_AUTH_IPCheck(MS_U8 u8Bit)
328 {
329     MS_U8 rval=0;
330     MS_U8 i=0;
331 
332     if(gIpAuthVars==NULL)
333     {
334         printk("Hash key AUTH not set!\n");
335         return 0;
336     }
337     rval=gIpAuthVars->u8IpControl[31-u8Bit/8] & (1<<(u8Bit%8));
338     //printk("MDrv_AUTH_IPCheck, retval: %d\n", rval);
339     return rval;
340 }
341 
MDrv_AUTH_GetHashInfo(MS_U8 * hashinfo)342 void MDrv_AUTH_GetHashInfo (MS_U8 *hashinfo)
343 {
344     int i;
345     hashinfo[0] = gCusID[0];
346     hashinfo[1] = gCusID[1];
347 
348     for(i=0;i<16;i++)
349     {
350         hashinfo[i+2] = gCusHash[i];
351     }
352 }
353 
354 #if MPOOL_DIVIDE_32M_WORKAROUND_PATCH
_MPOOL_Divide_Mapping(MS_U8 u8MiuSel,MS_U32 u32Offset,MS_U32 u32MapSize,MS_BOOL bNonCache)355 static MS_BOOL _MPOOL_Divide_Mapping(MS_U8 u8MiuSel, MS_U32 u32Offset, MS_U32 u32MapSize, MS_BOOL bNonCache)
356 {
357     MS_U32 u32MapAddr, u32RemainSize;
358 
359     u32MapAddr = u32Offset;
360     u32RemainSize = u32MapSize;
361 
362     while(u32RemainSize > DIVIDE_SIZE)
363     {
364         if (MsOS_MPool_Mapping_Dynamic(u8MiuSel, u32MapAddr, DIVIDE_SIZE, bNonCache))
365         {
366             u32MapAddr += DIVIDE_SIZE;
367             u32RemainSize -= DIVIDE_SIZE;
368         }
369         else
370         {
371             return FALSE;
372         }
373     }
374 
375     return MsOS_MPool_Mapping_Dynamic(u8MiuSel, u32MapAddr, u32RemainSize, bNonCache);
376 }
377 #endif
378 
utopia_proc_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)379 static ssize_t utopia_proc_write(struct file *file, const char __user *buf,
380 		size_t count, loff_t *ppos)
381 {
382     return 0;
383 }
384 
utopia_proc_open(struct inode * inode,struct file * file)385 static int utopia_proc_open(struct inode *inode, struct file *file)
386 {
387 	UTOPIA2K_ADP *Tmp;
388 
389     Tmp = kzalloc(sizeof(UTOPIA2K_ADP), GFP_KERNEL);
390 	if (Tmp == NULL)
391 		return -ENOMEM;
392 
393 	memset(Tmp,0,sizeof(UTOPIA2K_ADP));
394 
395 	file->private_data = Tmp;
396 	return 0;
397 }
398 
utopia_proc_release(struct inode * inode,struct file * file)399 static int utopia_proc_release(struct inode *inode, struct file * file)
400 {
401 	 UTOPIA2K_ADP *mmapData = file->private_data ;
402 
403 	 //file->private_data->fpClose((UTOPIA2K_DDI*)file->private_data);
404 	 //UtopiaClose((((UTOPIA2K_ADP*)(file->private_data))->pInstant));
405 	 kfree(mmapData);
406 
407 	 // iounmap(dev->dmaBuf) ;
408 	 return 0;
409 }
410 
411 #ifdef CONFIG_UTOPIA_GARBAGE_COLLECTION
utopia_garbage_collection(pid_t pid)412 static void utopia_garbage_collection(pid_t pid)
413 {
414     // 1. Trace PID root to search the pid which need to be garbage_collection
415     MS_BOOL bFind = FALSE;
416     UTOPIA_PID_LIST *CurrNode;
417     int count;
418 
419     //if pid = tgid => process do_exit
420     if (pid != current->tgid)
421         return;
422 
423     //UTOPIA_PID_LIST could be modified by multi-process, so it need mutex to protect.
424     //But, CurrNode->instance_list would not be changed, because this process is killed.
425     //  so, CurrNode->instance_list does not need protect during garbage_collection.
426     mutex_lock(&_Utopia_Instance_Mutex);
427     CurrNode = g_Utopia_PID_root;
428 
429     while(CurrNode)
430     {
431         if (pid == CurrNode->pid)
432         {
433             bFind = TRUE;
434             break;
435         }
436         CurrNode = CurrNode->pNext;
437     }
438     mutex_unlock(&_Utopia_Instance_Mutex);
439 
440     if (!bFind) return; //No need to do garbage_collection.
441 
442     // 2. Do Garbage_Collection
443     for (count = 0; count < INSTANCE_MAX; count++)
444     {
445         void* pModule;
446         void* pResource;
447         MS_U32 u32ResourceStatus = UTOPIA_STATUS_SUCCESS;
448 
449         if (NULL == CurrNode->instance_list[count])
450             continue;
451 
452         // 3. Send ioctl cmd.
453         if (UTOPIA_STATUS_SIGNAL_OK != UtopiaIoctl(CurrNode->instance_list[count], CMD_USIGNAL_PROCESS_KILL, &pid))
454             //continue;
455         {
456             // 4. Check Resource.
457             //Get Module Pointer
458             UtopiaInstanceGetModule(CurrNode->instance_list[count], &pModule);
459             //Get Module Resource(s)
460             pResource = NULL;
461             while(UTOPIA_STATUS_SUCCESS == u32ResourceStatus)
462             {
463                 //Travel Each Resource of this Module.
464                 u32ResourceStatus = UtopiaResourceGetNext(pModule, &pResource);
465 
466                 //Check Resource pid.
467                 if (pResource && (UTOPIA_STATUS_SUCCESS == u32ResourceStatus))
468                 {
469                     if (pid == UtopiaResourceGetPid(pResource))
470                     {
471                         //Recycle resource.
472                         UtopiaResourceRelease(pResource);
473                     }
474                 }
475             }
476         }
477 
478         // 5. Close
479         UtopiaClose(CurrNode->instance_list[count]);
480     }
481 
482     return;
483 }
484 #endif
485 
486 //-------------------------------------------------------------------------------------------------
487 //  Local Functions MPool Info
488 //-------------------------------------------------------------------------------------------------
mpoolinfo_proc_read(struct file * file,char __user * buf,size_t size,loff_t * ppos)489 static ssize_t mpoolinfo_proc_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
490 {
491     printk("===== MPool Info =====\n");
492     MsOS_MPool_InfoMsg();
493     printk("======================\n");
494     return 0;
495 }
mpoolinfo_proc_open(struct inode * inode,struct file * file)496 static int mpoolinfo_proc_open(struct inode *inode, struct file *file)
497 {
498     return 0;
499 }
mpoolinfo_proc_release(struct inode * inode,struct file * file)500 static int mpoolinfo_proc_release(struct inode *inode, struct file * file)
501 {
502     return 0;
503 }
504 
505 
506 const struct file_operations proc_utopia_operations = {
507 	//.read       = utopia_read,
508 	.write      = utopia_proc_write,
509 	.open       = utopia_proc_open,
510 	.release    = utopia_proc_release,
511     .unlocked_ioctl  = (void*)utopia_proc_ioctl,
512 #if defined(CONFIG_COMPAT)
513 	.compat_ioctl = utopia_proc_ioctl_compat,
514 #endif
515 };
516 
517 const struct file_operations proc_mpoolinfo_operations = {
518     .read       = mpoolinfo_proc_read,
519     .open       = mpoolinfo_proc_open,
520     .release    = mpoolinfo_proc_release,
521 };
522 
523 extern char moduleNames[][40];
524 
525 #if CONFIG_MSTAR_UTOPIA2K_STR
serch_moduleID(char * sModuleName)526 static int serch_moduleID(char* sModuleName)
527 {
528     int u32cnt=0;
529 	int u32ret=0;
530 	for(u32cnt = 0;u32cnt<eMODULE_END;u32cnt++)
531     {
532         if (0== strcmp((const char*)sModuleName, (const char*)moduleNames[u32cnt]))
533 	    {
534 	        u32ret = u32cnt;
535 			break;
536 	    }
537 
538 	}
539 
540     return u32ret;
541 }
542 
543 extern int mdrv_utopia2k_str_module_selftest(void* pModuleTmp,char* sModuleName);
544 
STR_verify_proc_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)545 static ssize_t STR_verify_proc_write(struct file *file, const char __user *buf,
546 		size_t count, loff_t *ppos)
547 {
548     //printk("Jway...STR_verify_proc_write ..%z\n",count);
549     char sModuleName[40] = {0};
550 	int u32ModuleID = 0;
551 	void* pInstanceTemp = NULL;
552 	void* pModuleTemp = NULL;
553 
554 	if(count > 40)
555 	{
556 		printk("utopia_dev.c : str_verify input too long\n");
557 		return 0;
558 	}
559 	copy_from_user(sModuleName,buf,count);
560 
561 	u32ModuleID = serch_moduleID(sModuleName);
562 
563 	//printk("STR_verify_proc_write : name = %s ID = %d \n",sModuleName,u32ModuleID);
564 	if(u32ModuleID == 0)
565 	{
566 	   printk("utopia_dev.c : str_verify input module name error\n");
567 	   return 0;
568 	}
569 
570 	if(UtopiaOpen(u32ModuleID,&pInstanceTemp,NULL,NULL)!=  UTOPIA_STATUS_SUCCESS)
571 	{
572 	    printk("utopia_dev.c : UtopiaOpen fail , Module %s \n");
573 		return 0;
574 	}
575 
576     if(UtopiaInstanceGetModule(pInstanceTemp,&pModuleTemp)!=  UTOPIA_STATUS_SUCCESS)
577     {
578         printk("utopia_dev.c : UtopiaInstanceGetModule fail , Module %s \n");
579 		UtopiaClose(pInstanceTemp);
580 		return 0;
581     }
582 
583 	//printk("STR_verify_proc_write : UtopiaInstanceGetModule = %p \n",pModuleTemp);
584 
585 	mdrv_utopia2k_str_module_selftest(pModuleTemp,sModuleName);
586 	UtopiaClose(pInstanceTemp);
587     return count;
588 }
589 
STR_verify_proc_read(struct file * file,char __user * buf,size_t count,loff_t * ppos)590 ssize_t STR_verify_proc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
591 {
592     int u32cnt = 0;
593 
594     printk("\n\n=======You can type the following modules:========\n\n");
595 
596     for(u32cnt = 0; u32cnt < eMODULE_END; u32cnt++)
597     {
598         printk("%-20s", (const char*)moduleNames[u32cnt]);
599         if ((u32cnt % 5 == 4) || (u32cnt == eMODULE_END - 1))
600             printk("\n");
601     }
602     return 0;
603 }
604 
STR_verify_proc_open(struct inode * inode,struct file * file)605 static int STR_verify_proc_open(struct inode *inode, struct file *file)
606 {
607     return 0;
608 }
STR_verify_proc_release(struct inode * inode,struct file * file)609 static int STR_verify_proc_release(struct inode *inode, struct file * file)
610 {
611     return 0;
612 }
613 
614 
615 const struct file_operations proc_str_operations = {
616     .write      = STR_verify_proc_write,
617     .read       = STR_verify_proc_read,
618     .open       = STR_verify_proc_open,
619     .release    = STR_verify_proc_release,
620 };
621 
622 #endif
623 
624 #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
625 static MS_BOOL bAgentInit = FALSE;
626 struct mdb_fpioctl_list{
627     char iname[MDB_NODE_NAME_MAX];
628     FUtopiaMdbIoctl fpMdbIoctl;
629     MS_BOOL used;
630 };
631 static struct mdb_fpioctl_list _mdb_fpioctl_list[MDB_FPIOCTL_LIST_MAX];
632 
mdb_node_proc_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)633 static ssize_t mdb_node_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
634 {
635     char tmpbuf[MDB_CMDLINE_MAX];
636     MDBCMD_CMDLINE_PARAMETER paraCmdLine;
637     int i=0;
638     if(buf && !copy_from_user(tmpbuf, buf, count))
639     {
640         tmpbuf[count-1] = '\0';
641     }
642     for(i=0; i<MDB_FPIOCTL_LIST_MAX; i++)
643     {
644         if(TRUE==_mdb_fpioctl_list[i].used && 0==strncmp(_mdb_fpioctl_list[i].iname,(file->f_path.dentry->d_iname),strlen((file->f_path.dentry->d_iname))))
645         {
646             paraCmdLine.u64ReqHdl = file;
647             paraCmdLine.u32CmdSize = count-1;
648             memcpy(paraCmdLine.pcCmdLine, tmpbuf, MDB_CMDLINE_MAX);
649             _mdb_fpioctl_list[i].fpMdbIoctl(MDBCMD_CMDLINE,&paraCmdLine);
650             break;
651         }
652     }
653     return count;
654 }
655 
mdb_node_proc_read(struct file * file,char __user * buf,size_t size,loff_t * ppos)656 static ssize_t mdb_node_proc_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
657 {
658     MDBCMD_GETINFO_PARAMETER paraGetInfo;
659     int i=0;
660     for(i=0; i<MDB_FPIOCTL_LIST_MAX; i++)
661     {
662         if(TRUE==_mdb_fpioctl_list[i].used && 0==strncmp(_mdb_fpioctl_list[i].iname,(file->f_path.dentry->d_iname),strlen((file->f_path.dentry->d_iname))))
663         {
664             paraGetInfo.u64ReqHdl = file;
665             _mdb_fpioctl_list[i].fpMdbIoctl(MDBCMD_GETINFO,&paraGetInfo);
666             break;
667         }
668     }
669     return 0;
670 }
671 
672 struct file_operations proc_mdb_node_operations = {
673     .write      = mdb_node_proc_write,
674     .read       = mdb_node_proc_read,
675 };
676 
mdb_agent_proc_write(struct file * file,const char __user * buf,size_t count,loff_t * ppos)677 static ssize_t mdb_agent_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
678 {
679     return count;
680 }
681 
mdb_agent_proc_read(struct file * file,char __user * buf,size_t size,loff_t * ppos)682 static ssize_t mdb_agent_proc_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
683 {
684     return 0;
685 }
686 
687 const struct file_operations proc_mdb_agent_operations = {
688     .write      = mdb_agent_proc_write,
689     .read       = mdb_agent_proc_read,
690 };
691 
mdb_node_create_table(char sMdbNodeName[MDB_NODE_NAME_MAX],FUtopiaMdbIoctl fpMdbIoctl)692 void mdb_node_create_table(char sMdbNodeName[MDB_NODE_NAME_MAX], FUtopiaMdbIoctl fpMdbIoctl)
693 {
694     char sMdbNodeNameTmp[MDB_NODE_NAME_MAX*2];
695     int i=0;
696     sprintf(sMdbNodeNameTmp,"utopia_mdb/%s",sMdbNodeName);
697     mutex_lock(&_MdbFpioctlList_Mutex);
698     for(i=0; i<MDB_FPIOCTL_LIST_MAX; i++)
699     {
700         if(FALSE==_mdb_fpioctl_list[i].used)
701         {
702             memcpy(_mdb_fpioctl_list[i].iname,sMdbNodeName,strlen(sMdbNodeName));
703             _mdb_fpioctl_list[i].fpMdbIoctl = fpMdbIoctl;
704             _mdb_fpioctl_list[i].used = TRUE;
705             break;
706         }
707     }
708     mutex_unlock(&_MdbFpioctlList_Mutex);
709     return 0;
710 }
711 
mdb_node_create(void)712 void mdb_node_create(void)
713 {
714     char sMdbNodeNameTmp[MDB_NODE_NAME_MAX*2];
715     int i;
716 
717     for(i=0; i<MDB_FPIOCTL_LIST_MAX; i++)
718     {
719         if(TRUE==_mdb_fpioctl_list[i].used)
720         {
721             sprintf(sMdbNodeNameTmp,"utopia_mdb/%s",_mdb_fpioctl_list[i].iname);
722             proc_create(sMdbNodeNameTmp, S_IRUSR | S_IWUSR, NULL, &proc_mdb_node_operations);
723             printk("--------%s\n", _mdb_fpioctl_list[i].iname);
724         }
725     }
726     bAgentInit = TRUE;
727     return 0;
728 }
729 #endif
730 
init_procfs_msg(void)731 static int __init init_procfs_msg(void)
732 {
733     int i=0;
734     struct path path;
735     int error;
736 	proc_create("utopia", S_IRUSR | S_IWUSR, NULL, &proc_utopia_operations);
737 
738     //For utopia2k mpool info msg.
739     proc_mkdir("utopia2k", NULL);
740     proc_create("utopia2k/mpoolinfo", S_IRUSR | S_IWUSR, NULL, &proc_mpoolinfo_operations);
741 
742 	#if CONFIG_MSTAR_UTOPIA2K_STR
743 	proc_create("utopia2k/str_verify", S_IRUSR | S_IWUSR, NULL, &proc_str_operations);
744 	#endif
745     #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
746     //create /proc/utopia_mdb (directory) and /proc/utopia_mdb/agent (node)
747     error=kern_path("/proc/utopia_mdb",LOOKUP_FOLLOW, &path);
748     if(error)
749     {
750         proc_mkdir("utopia_mdb", NULL);
751     }
752     proc_create("utopia_mdb/agent", S_IRUSR | S_IWUSR, NULL, &proc_mdb_agent_operations);
753     //initial mdb_fpioctl_list
754     for(i=0; i<MDB_FPIOCTL_LIST_MAX; i++)
755     {
756         memset(_mdb_fpioctl_list[i].iname,0,sizeof(_mdb_fpioctl_list[i].iname));
757         _mdb_fpioctl_list[i].fpMdbIoctl = NULL;
758         _mdb_fpioctl_list[i].used = FALSE;
759     }
760     #endif
761 	return 0;
762 }
763 
764 
765 #define MAJOR_NUM          99
766 #define MODULE_NAME                "UTOPIA"
767 
768 void* pInstant = NULL;
769 void* pArg = NULL;
770 
771 
772 UADP_SPT_0NXT_DEF(MS_U8);
773 UADP_SPT_0NXT_DEF(MS_U16);
774 UADP_SPT_0NXT_DEF(MS_U32);
775 UADP_SPT_0NXT_DEF(MS_NULL);
776 
utopia_init(void)777 static int __init utopia_init(void)
778 {
779 
780 	init_procfs_msg();
781 
782     #if defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_64BIT) || defined(CONFIG_UTOPIA_FRAMEWORK_KERNEL_DRIVER_32BIT)
783     autoIoctlSetModule();
784 	#endif
785 
786 #if 0
787     if (register_chrdev(MAJOR_NUM, "utopia", &proc_utopia_operations) < 0)
788 	{
789       printk("<1>%s: can't get major %d\n", MODULE_NAME, MAJOR_NUM);
790       return (-EBUSY);
791     }
792     printk("<1>%s: started\n", MODULE_NAME);
793     // return 0;
794 #endif
795 	MsOS_MPool_Init();
796 	MsOS_Init();
797 	MDrv_SYS_Init();
798 	MDrv_SYS_DMD_VD_MBX_Init();
799 	//MDrv_MIU_Init();
800 #if 0   //test code.
801     _MPOOL_Divide_Mapping(0, 0x1F000000, (300<<20), TRUE);
802 #endif
803 
804         #ifdef CONFIG_MSTAR_UTOPIA2K_STR
805 		printk("utopia support STR\n");
806 	//mstar_set_utopia2k_cbf_pm(UtopiaSave_PM, UtopiaRestore_PM);
807         #endif
808 
809     g_Utopia_PID_root = NULL;
810 #ifdef CONFIG_UTOPIA_GARBAGE_COLLECTION
811     Utopia2K_resource_collection_Register(utopia_garbage_collection);
812 #endif
813 
814 	UADP_SPT_0NXT(MS_U8);
815 	UADP_SPT_0NXT(MS_U16);
816 	UADP_SPT_0NXT(MS_U32);
817 	UADP_SPT_0NXT(MS_NULL);
818 
819 	return 0;
820 }
821 
MApi_MBX_Enable(MS_BOOL bEnable)822 MS_BOOL  MApi_MBX_Enable(MS_BOOL bEnable)
823 {
824 	return 0;
825 }
826 
MApi_MBX_Init(MS_U32 eHKCPU,MS_U32 eHostRole,MS_U32 u32TimeoutMillSecs)827 MS_BOOL  MApi_MBX_Init(MS_U32 eHKCPU, MS_U32 eHostRole, MS_U32 u32TimeoutMillSecs)
828 {
829 	return 0;
830 }
831 
832 EXPORT_SYMBOL(MApi_MBX_Enable);
833 EXPORT_SYMBOL(MApi_MBX_Init);
834 
835 
836 EXPORT_SYMBOL(spt_MS_U8);
837 EXPORT_SYMBOL(spt_MS_U16);
838 EXPORT_SYMBOL(spt_MS_U32);
839 EXPORT_SYMBOL(spt_MS_NULL);
840 
841 EXPORT_SYMBOL(MDrv_AUTH_IPCheck);
842 EXPORT_SYMBOL(MDrv_AUTH_GetHashInfo);
843 
utopia_exit(void)844 static void utopia_exit(void) {
845    //unregister_chrdev(MAJOR_NUM, "utopia");
846    //printk("<1>%s: removed\n", MODULE_NAME);
847 }
848 
849 module_init(utopia_init);
850 module_exit(utopia_exit);
851 
852