/
ms_msys.c
4084 lines (3470 loc) · 118 KB
/
ms_msys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ms_msys.c- Sigmastar
*
* Copyright (C) 2018 Sigmastar Technology Corp.
*
* Author: karl.xiao <karl.xiao@sigmastar.com.tw>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/*
* mdrv_system.c
*
* Created on: 2012/9/21
* Author: Administrator
*/
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/errno.h>
#include <linux/dma-mapping.h> /* for dma_alloc_coherent */
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/ctype.h>
#include <linux/swap.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
#include <linux/compaction.h>
#include <asm/cacheflush.h>
#include "ms_platform.h"
#include "registers.h"
#include "mdrv_msys_io_st.h"
#include "mdrv_msys_io.h"
#include "platform_msys.h"
#include "mdrv_verchk.h"
#include "mdrv_miu.h"
#include "mdrv_system.h"
#include "cam_os_wrapper.h"
#include "hal_bdma.h"
#include "hal_movedma.h"
#define MSYS_PERF_TEST 0
#if MSYS_PERF_TEST
#if 1
#define dmac_map_area __glue(_CACHE,_dma_map_area)
#define dmac_unmap_area __glue(_CACHE,_dma_unmap_area)
extern void dmac_map_area(const void *, size_t, int);
extern void dmac_unmap_area(const void *, size_t, int);
#else
#define dmac_map_area(a, b, c) {}
#define dmac_unmap_area(a, b, c) {}
#endif
#include <linux/time.h>
#define STR_IMI "IMI"
#define STR_MIU "MIU"
#define STR_CACHE "CACHE"
#define STR_CPUINFO "CPUINFO"
#define STR_ALL "ALL"
////////////////////////////////////////////
#define STR_CPUINFO_CA9 "ARMv7 CA9"
#define STR_CPUINFO_CA7 "ARMv7 CA7"
#define STR_CPUINFO_CA53 "ARMv8 CA53"
#define STR_CPUINFO_NULL "CPU_NULL"
#define IRQ_LIST 1000
#define CPU_PART_CA7 0xC07
#define CPU_PART_CA9 0xC09
#define CPU_PART_CA53 0xD03
#define CPU_PART_NULL 0x000
#define IMI_ADDR_INVALID 0xFFFFFFFF
#define IMI_SIZE_INVALID 0xFFFFFFFF
#endif // #if MSYS_PERF_TEST
#define BENCH_MEMORY_FUNC 0
#define MSYS_DEBUG 0
#define MINOR_SYS_NUM 128
#define MAJOR_SYS_NUM 233
#define MSYS_MIU_PROTECT 1
#if MSYS_DEBUG
#define MSYS_PRINT(fmt, args...) printk("[MSYS] " fmt, ## args)
#else
#define MSYS_PRINT(fmt, args...)
#endif
#define MSYS_ERROR(fmt, args...) printk(KERN_ERR"MSYS: " fmt, ## args)
#define MSYS_WARN(fmt, args...) printk(KERN_WARNING"MSYS: " fmt, ## args)
extern void Chip_Flush_Memory(void);
static int msys_open(struct inode *inode, struct file *filp);
static int msys_release(struct inode *inode, struct file *filp);
static long msys_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
typedef struct
{
MSYS_PROC_DEVICE proc_dev;
void *proc_addr;
struct proc_dir_entry* proc_entry;
struct list_head list;
} PROC_INFO_LIST;
static int msys_request_proc_attr(MSYS_PROC_ATTRIBUTE* proc_attr);
static int msys_release_proc_attr(MSYS_PROC_ATTRIBUTE* proc_attr);
static int msys_request_proc_dev(MSYS_PROC_DEVICE* proc_dev);
static int msys_release_proc_dev(MSYS_PROC_DEVICE* proc_dev);
#if BENCH_MEMORY_FUNC==1
static void msys_bench_memory(unsigned int);
#endif
static struct file_operations msys_fops = {
.owner = THIS_MODULE,
.open = msys_open,
.release = msys_release,
.unlocked_ioctl=msys_ioctl,
};
static struct miscdevice sys_dev = {
.minor = MINOR_SYS_NUM,
.name = "msys",
.fops = &msys_fops,
};
static unsigned char data_part_string[32]={0};
static unsigned char system_part_string[32]={0};
//static unsigned char mstar_property_path[32]="/data";
static u64 sys_dma_mask = 0xffffffffUL;
struct list_head kept_mem_head;
struct list_head fixed_mem_head;
static struct mutex dmem_mutex;
static unsigned char fixed_dmem_enabled=0;
static unsigned char dmem_realloc_enabled=0;
//static unsigned long dmem_lock_flags;
static unsigned int dmem_retry_interval=100; //(ms)
static unsigned int dmem_retry_count=16;
#if defined(CONFIG_MS_BDMA)
static CamOsTsem_t m_stBdmaDoneSem[HAL_BDMA_CH_NUM];
#endif
#if defined(CONFIG_MS_MOVE_DMA)
static CamOsTsem_t m_stMdmaDoneSem;
#endif
struct DMEM_INFO_LIST
{
struct list_head list;
MSYS_DMEM_INFO dmem_info;
};
//port from fs/proc/meminfo.c
unsigned int meminfo_free_in_K(void)
{
struct sysinfo i;
#if 0
unsigned long committed;
struct vmalloc_info vmi;
long cached;
long available;
unsigned long pagecache;
unsigned long wmark_low = 0;
unsigned long pages[NR_LRU_LISTS];
struct zone *zone;
int lru;
#endif
/*
* display in kilobytes.
*/
#define K(x) ((x) << (PAGE_SHIFT - 10))
si_meminfo(&i);
si_swapinfo(&i);
#if 0
committed = percpu_counter_read_positive(&vm_committed_as);
cached = global_page_state(NR_FILE_PAGES) -
total_swapcache_pages() - i.bufferram;
if (cached < 0)
cached = 0;
get_vmalloc_info(&vmi);
for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
pages[lru] = global_page_state(NR_LRU_BASE + lru);
for_each_zone(zone)
wmark_low += zone->watermark[WMARK_LOW];
/*
* Estimate the amount of memory available for userspace allocations,
* without causing swapping.
*
* Free memory cannot be taken below the low watermark, before the
* system starts swapping.
*/
available = i.freeram - wmark_low;
/*
* Not all the page cache can be freed, otherwise the system will
* start swapping. Assume at least half of the page cache, or the
* low watermark worth of cache, needs to stay.
*/
pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
pagecache -= min(pagecache / 2, wmark_low);
available += pagecache;
/*
* Part of the reclaimable slab consists of items that are in use,
* and cannot be freed. Cap this estimate at the low watermark.
*/
available += global_page_state(NR_SLAB_RECLAIMABLE) -
min(global_page_state(NR_SLAB_RECLAIMABLE) / 2, wmark_low);
if (available < 0)
available = 0;
#endif
return K(i.freeram);
}
EXPORT_SYMBOL(meminfo_free_in_K);
//static void *mm_mem_virt = NULL; /* virtual address of frame buffer 1 */
static int msys_open(struct inode *inode, struct file *filp)
{
// printk(KERN_WARNING"%s():\n", __FUNCTION__);
return 0;
}
static int msys_release(struct inode *inode, struct file *filp)
{
// MSYS_PRINT(KERN_WARNING"%s():\n", __FUNCTION__);
return 0;
}
int msys_fix_dmem(char* name)
{
int err=0;
struct list_head *ptr;
struct DMEM_INFO_LIST *entry,*match_entry;
match_entry=NULL;
mutex_lock(&dmem_mutex);
if(name!=NULL && name[0]!=0)
{
struct DMEM_INFO_LIST *new=NULL;
list_for_each(ptr, &fixed_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
if (0==strncmp(entry->dmem_info.name, name,strnlen(name,15)))
{
match_entry=entry;
goto BEACH;
}
}
new=(struct DMEM_INFO_LIST *)kmalloc(sizeof(struct DMEM_INFO_LIST),GFP_KERNEL);
if(new==NULL)
{
MSYS_ERROR("allocate memory for fixed_mem_list entry error\n" ) ;
err = -ENOMEM;
goto BEACH;
}
memset(new->dmem_info.name,0,16);
memcpy(new->dmem_info.name,name,strnlen(name,15));
//memcpy(&new->dmem_info,&mem_info,sizeof(MSYS_DMEM_INFO));
list_add(&new->list, &fixed_mem_head);
}
BEACH:
mutex_unlock(&dmem_mutex);
return err;
}
int msys_unfix_dmem(char* name)
{
//MSYS_DMEM_INFO mem_info;
struct list_head *ptr;
struct DMEM_INFO_LIST *entry,*match_entry;
match_entry=NULL;
mutex_lock(&dmem_mutex);
if(name!=NULL && name[0]!=0)
{
list_for_each(ptr, &fixed_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
if (0==strncmp(entry->dmem_info.name, name,strnlen(name,15)))
{
match_entry=entry;
break;
}
}
}
if(match_entry!=NULL)
{
list_del_init(&match_entry->list);
kfree(match_entry);
}
//BEACH:
mutex_unlock(&dmem_mutex);
return 0;
}
int msys_find_dmem_by_phys(unsigned long long phys,MSYS_DMEM_INFO *mem_info)
{
//MSYS_DMEM_INFO mem_info;
struct list_head *ptr;
struct DMEM_INFO_LIST *entry;
int res=-EINVAL;
mutex_lock(&dmem_mutex);
if(0!=phys)
{
list_for_each(ptr, &kept_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
if ((entry->dmem_info.phys<=phys) && phys<(entry->dmem_info.phys+entry->dmem_info.length))
{
memcpy(mem_info,&entry->dmem_info,sizeof(MSYS_DMEM_INFO));
res=0;
goto BEACH;
;
}
}
}
BEACH:
mutex_unlock(&dmem_mutex);
return res;
}
int msys_find_dmem_by_name(const char *name, MSYS_DMEM_INFO *mem_info)
{
struct list_head *ptr;
struct DMEM_INFO_LIST *entry, *match_entry=NULL;
int res=-EINVAL;
mutex_lock(&dmem_mutex);
if(name!=NULL && name[0]!=0)
{
list_for_each(ptr, &kept_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
res=strncmp(entry->dmem_info.name, name, 16);
if (0==res)
{
//MSYS_ERROR("%s: Find name\n", __func__);
match_entry=entry;
break;
}
}
}
else
{
MSYS_ERROR("%s: Invalid name\n", __func__);
}
if(match_entry!=NULL)
{
memcpy(mem_info, &match_entry->dmem_info, sizeof(MSYS_DMEM_INFO));
}
else
{
memset(mem_info->name,0,16);
}
mutex_unlock(&dmem_mutex);
return res;
}
int msys_release_dmem(MSYS_DMEM_INFO *mem_info)
{
//MSYS_DMEM_INFO mem_info;
struct list_head *ptr;
struct DMEM_INFO_LIST *entry,*match_entry;
int dmem_fixed=0;
mutex_lock(&dmem_mutex);
match_entry=NULL;
// MSYS_PRINT("\nFREEING DMEM [%s]\n\n",mem_info->name);
if(mem_info->name[0]!=0)
{
list_for_each(ptr, &kept_mem_head)
{
int res=0;
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
res=strncmp(entry->dmem_info.name, mem_info->name,strnlen(mem_info->name,15));
// MSYS_PRINT("DMEM0 [%s],%s %d\n",entry->dmem_info.name,match_entry->dmem_info.name,res);
if (0==res)
{
match_entry=entry;
break;
}
}
}
if(match_entry==NULL && (0!=mem_info->phys))
{
MSYS_ERROR("WARNING!! DMEM [%s]@0x%08X can not be found by name, try to find by phys address\n",mem_info->name, (unsigned int)mem_info->phys);
list_for_each(ptr, &kept_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
if (entry->dmem_info.phys==mem_info->phys)
{
match_entry=entry;
break;
}
}
}
if(match_entry==NULL)
{
MSYS_ERROR("DMEM [%s]@0x%08X not found, skipping release...\n",mem_info->name, (unsigned int)mem_info->phys);
goto BEACH;
}
if(fixed_dmem_enabled)
{
//check if entry is fixed
list_for_each(ptr, &fixed_mem_head)
{
int res=0;
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
res=strcmp(entry->dmem_info.name, match_entry->dmem_info.name);
if (0==res)
{
dmem_fixed=1;
MSYS_PRINT("DMEM [%s]@0x%08X is fixed, skipping release...\n",match_entry->dmem_info.name,(unsigned int)match_entry->dmem_info.phys);
goto BEACH;
}
}
}
dma_free_coherent(sys_dev.this_device, PAGE_ALIGN(match_entry->dmem_info.length),(void *)(uintptr_t)match_entry->dmem_info.kvirt,match_entry->dmem_info.phys);
MSYS_PRINT("DMEM [%s]@0x%08X successfully released\n",match_entry->dmem_info.name,(unsigned int)match_entry->dmem_info.phys);
list_del_init(&match_entry->list);
kfree(match_entry);
BEACH:
mutex_unlock(&dmem_mutex);
return 0;
}
int msys_request_dmem(MSYS_DMEM_INFO *mem_info)
{
dma_addr_t phys_addr;
int err=0;
int retry=0;
if(mem_info->name[0]==0||strlen(mem_info->name)>15)
{
MSYS_ERROR( "Invalid DMEM name!! Either garbage or empty name!!\n");
return -EINVAL;
}
/*if(mem_info->length<=0)
{
MSYS_ERROR( "Invalid DMEM length!! [%s]:0x%08X\n",mem_info->name,(unsigned int)mem_info->length);
return -EFAULT;
}*/
MSYS_ERROR("DMEM request: [%s]:0x%08X\n",mem_info->name,(unsigned int)mem_info->length);
mutex_lock(&dmem_mutex);
// if(mem_info->name[0]!=0)
{
struct list_head *ptr;
struct DMEM_INFO_LIST *entry;
list_for_each(ptr, &kept_mem_head)
{
entry = list_entry(ptr, struct DMEM_INFO_LIST, list);
if (0==strncmp(entry->dmem_info.name, mem_info->name,strnlen(mem_info->name,15)))
{
if(dmem_realloc_enabled && (entry->dmem_info.length != mem_info->length))
{
MSYS_ERROR("dmem realloc %s", entry->dmem_info.name);
dma_free_coherent(sys_dev.this_device, PAGE_ALIGN(entry->dmem_info.length),(void *)(uintptr_t)entry->dmem_info.kvirt,entry->dmem_info.phys);
MSYS_ERROR("DMEM [%s]@0x%08X successfully released\n",entry->dmem_info.name,(unsigned int)entry->dmem_info.phys);
list_del_init(&entry->list);
break;
}
else
{
memcpy(mem_info,&entry->dmem_info,sizeof(MSYS_DMEM_INFO));
MSYS_ERROR("DMEM kept entry found: name=%s, phys=0x%08X, length=0x%08X\n",mem_info->name,(unsigned int)mem_info->phys,(unsigned int)mem_info->length);
goto BEACH_ENTRY_FOUND;
}
}
}
//MSYS_PRINT(KERN_WARNING"can not found kept direct requested memory entry name=%s\n",mem_info.name);
}
// else
// {
// MSYS_PRINT(" !!ERROR!! Anonymous DMEM request is forbidden !!\n");
// return -EFAULT;
// }
while( !(mem_info->kvirt = (u64)(uintptr_t)dma_alloc_coherent(sys_dev.this_device, PAGE_ALIGN(mem_info->length), &phys_addr, GFP_KERNEL)) )
{
if(retry >= dmem_retry_count)
{
MSYS_ERROR( "unable to allocate direct memory\n");
err = -ENOMEM;
goto BEACH_ALLOCATE_FAILED;
}
MSYS_ERROR( "retry ALLOC_DMEM %d [%s]:0x%08X\n", retry, mem_info->name, (unsigned int)mem_info->length);
sysctl_compaction_handler(NULL, 1, NULL, NULL, NULL);
msleep(1000);
retry++;
}
mem_info->phys=(u64)phys_addr;
{
struct DMEM_INFO_LIST *new=(struct DMEM_INFO_LIST *)kmalloc(sizeof(struct DMEM_INFO_LIST),GFP_KERNEL);
if(new==NULL)
{
MSYS_ERROR("allocate memory for mem_list entry error\n" ) ;
err = -ENOMEM;
goto BEACH;
}
memset(new->dmem_info.name,0,16);
/*
new->dmem_info.kvirt=mem_info->kvirt;
new->dmem_info.phys=mem_info->phys;
new->dmem_info.length=mem_info->length;
if(mem_info->name!=NULL){
memcpy(new->dmem_info.name,mem_info->name,strnlen(mem_info->name,15));
}
*/
memcpy(&new->dmem_info,mem_info,sizeof(MSYS_DMEM_INFO));
list_add(&new->list, &kept_mem_head);
}
if(retry)
MSYS_ERROR("DMEM request: [%s]:0x%08X success, @0x%08X (retry=%d)\n",mem_info->name,(unsigned int)mem_info->length, (unsigned int)mem_info->phys, retry);
else
MSYS_ERROR("DMEM request: [%s]:0x%08X success, CPU phy:@0x%08X, virt:@0x%08X\n",mem_info->name,(unsigned int)mem_info->length, (unsigned int)mem_info->phys, (unsigned int)mem_info->kvirt);
BEACH:
if(err==-ENOMEM)
{
msys_release_dmem(mem_info);
}
BEACH_ALLOCATE_FAILED:
BEACH_ENTRY_FOUND:
if(err)
{
MSYS_ERROR("DMEM request: [%s]:0x%08X FAILED!! (retry=%d)\n",mem_info->name,(unsigned int)mem_info->length, retry);
}
#if 0
if(0==err){
memset((void *)((unsigned int)mem_info->kvirt),0,mem_info->length);
Chip_Flush_CacheAll();
MSYS_PRINT("DMEM CLEAR!!\n");
}
#endif
mutex_unlock(&dmem_mutex);
return err;
}
unsigned int get_PIU_tick_count(void)
{
return ( INREG16(0x1F006050) | (INREG16(0x1F006054)<<16) );
}
EXPORT_SYMBOL(get_PIU_tick_count);
int msys_user_to_physical(unsigned long addr,unsigned long *phys)
{
unsigned long paddr=0;
struct page *page;
down_read(¤t->mm->mmap_sem);
//if (get_user_pages(current, current->mm, addr, 1, 1, 0, &page, NULL) <= 0)//3.18
if (get_user_pages(addr, 1, FOLL_WRITE, &page, NULL) <= 0)
{
up_read(¤t->mm->mmap_sem);
printk(KERN_WARNING"ERR!!\n");
return -EINVAL;
}
up_read(¤t->mm->mmap_sem);
paddr= page_to_phys(page);
*phys=paddr;
// if(paddr>0x21E00000)
// {
// printk(KERN_WARNING"\nKXX:0x%08X,0x%08X\n",(unsigned int)addr,(unsigned int)paddr);
// }
return 0;
}
int msys_find_dmem_by_name_verchk(unsigned long arg)
{
MSYS_DMEM_INFO mem_info;
int err=0;
if(copy_from_user((void*)&mem_info, (void __user *)arg, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mem_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(mem_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mem_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mem_info.VerChk_Size), sizeof(MSYS_DMEM_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DMEM_INFO), (mem_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
if( (err=msys_find_dmem_by_name(mem_info.name, &mem_info)) )
{
//return -ENOENT;
}
if(copy_to_user((void __user *)arg, (void*)&mem_info, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
return 0;
}
int msys_request_dmem_verchk(unsigned long arg)
{
MSYS_DMEM_INFO mem_info;
int err=0;
if(copy_from_user((void*)&mem_info, (void __user *)arg, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mem_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(mem_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mem_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mem_info.VerChk_Size), sizeof(MSYS_DMEM_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DMEM_INFO), (mem_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
if( (err=msys_request_dmem(&mem_info)) )
{
MSYS_ERROR("request direct memory failed!!\n" );
return err;
}
if(copy_to_user((void __user *)arg, (void*)&mem_info, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
return 0;
}
int msys_release_dmem_verchk(unsigned long arg)
{
MSYS_DMEM_INFO mem_info;
if(copy_from_user((void*)&mem_info, (void __user *)arg, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mem_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(mem_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mem_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mem_info.VerChk_Size), sizeof(MSYS_DMEM_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DMEM_INFO), (mem_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
return msys_release_dmem(&mem_info);
}
int msys_flush_cache(unsigned long arg)
{
MSYS_DUMMY_INFO info;
if(copy_from_user((void*)&info, (void __user *)arg, sizeof(MSYS_DUMMY_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(info.VerChk_Size), sizeof(MSYS_DUMMY_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DUMMY_INFO), (info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
Chip_Flush_CacheAll();
return 0;
}
int msys_addr_translation_verchk(unsigned long arg, bool direction)
{
MSYS_ADDR_TRANSLATION_INFO addr_info;
if(copy_from_user((void*)&addr_info, (void __user *)arg, sizeof(addr_info)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(addr_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(addr_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
addr_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(addr_info.VerChk_Size), sizeof(MSYS_ADDR_TRANSLATION_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_ADDR_TRANSLATION_INFO), (addr_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
if(direction)
addr_info.addr=Chip_MIU_to_Phys(addr_info.addr);
else
addr_info.addr=Chip_Phys_to_MIU(addr_info.addr);
if(copy_to_user((void __user *)arg, (void*)&addr_info, sizeof(addr_info)))
{
return -EFAULT;
}
return 0;
}
int msys_get_riu_map_verchk(unsigned long arg)
{
MSYS_MMIO_INFO mmio_info;
if( copy_from_user((void*)&mmio_info, (void __user *)arg, sizeof(MSYS_MMIO_INFO)) )
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mmio_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&mmio_info, IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mmio_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mmio_info.VerChk_Size), sizeof(MSYS_MMIO_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_MMIO_INFO), (mmio_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
mmio_info.addr=Chip_Get_RIU_Phys();
mmio_info.size=Chip_Get_RIU_Size();
if( copy_to_user((void __user *)arg, (void*)&mmio_info, sizeof(MSYS_MMIO_INFO)) )
{
return -EFAULT;
}
return 0;
}
int msys_fix_dmem_verchk(unsigned long arg)
{
MSYS_DMEM_INFO mem_info;
int err=0;
if(copy_from_user((void*)&mem_info, (void __user *)arg, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mem_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(mem_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mem_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mem_info.VerChk_Size), sizeof(MSYS_DMEM_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DMEM_INFO), (mem_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;
}
if( (err=msys_fix_dmem(mem_info.name)) )
{
MSYS_ERROR("fix direct memory failed!! %s\n", mem_info.name);
return err;
}
return 0;
}
int msys_unfix_dmem_verchk(unsigned long arg)
{
MSYS_DMEM_INFO mem_info;
int err=0;
if(copy_from_user((void*)&mem_info, (void __user *)arg, sizeof(MSYS_DMEM_INFO)))
{
return -EFAULT;
}
if ( CHK_VERCHK_HEADER(&(mem_info.VerChk_Version)) )
{
if( CHK_VERCHK_VERSION_LESS(&(mem_info.VerChk_Version), IOCTL_MSYS_VERSION) )
{
VERCHK_ERR("\n\33[1;31m[%s] verchk version (%04x) < ioctl verision (%04x) !!!\33[0m\n", __FUNCTION__,
mem_info.VerChk_Version & VERCHK_VERSION_MASK, IOCTL_MSYS_VERSION);
return -EINVAL;
}
else
{
if( CHK_VERCHK_SIZE(&(mem_info.VerChk_Size), sizeof(MSYS_DMEM_INFO)) == 0 )
{
VERCHK_ERR("\n\33[1;31m[%s] struct size(%04x) != verchk size(%04x) !!!\33[0m\n", __FUNCTION__,
sizeof(MSYS_DMEM_INFO), (mem_info.VerChk_Size));
return -EINVAL;
}
}
}
else
{
VERCHK_ERR("\n\33[1;31m[%s] No verchk header !!!\33[0m\n", __FUNCTION__);
return -EFAULT;