summaryrefslogtreecommitdiff
path: root/target/linux/brcm2708/patches-4.4/0037-vc_mem-Add-vc_mem-driver.patch
blob: 5559db506d314ed9512aad777ff46d1452b10bc5 (plain)
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
From f5cce853dbe19f479d61c2d91a009edbea5735fc Mon Sep 17 00:00:00 2001
From: popcornmix <popcornmix@gmail.com>
Date: Wed, 17 Jun 2015 16:07:06 +0100
Subject: [PATCH 037/381] vc_mem: Add vc_mem driver
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: popcornmix <popcornmix@gmail.com>

BCM270x: Move vc_mem

Make the vc_mem module available for ARCH_BCM2835 by moving it.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 arch/arm/mach-bcm2709/include/mach/vc_mem.h |  35 ---
 arch/arm/mach-bcm2709/vc_mem.c              | 431 ----------------------------
 drivers/char/broadcom/Kconfig               |  12 +-
 drivers/char/broadcom/Makefile              |   1 +
 drivers/char/broadcom/vc_mem.c              | 422 +++++++++++++++++++++++++++
 include/linux/broadcom/vc_mem.h             |  35 +++
 6 files changed, 469 insertions(+), 467 deletions(-)
 delete mode 100644 arch/arm/mach-bcm2709/include/mach/vc_mem.h
 delete mode 100644 arch/arm/mach-bcm2709/vc_mem.c
 create mode 100644 drivers/char/broadcom/vc_mem.c
 create mode 100644 include/linux/broadcom/vc_mem.h

--- a/arch/arm/mach-bcm2709/include/mach/vc_mem.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*****************************************************************************
-* Copyright 2010 - 2011 Broadcom Corporation.  All rights reserved.
-*
-* Unless you and Broadcom execute a separate written software license
-* agreement governing use of this software, this software is licensed to you
-* under the terms of the GNU General Public License version 2, available at
-* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
-*
-* Notwithstanding the above, under no circumstances may you combine this
-* software in any way with any other Broadcom software provided under a
-* license other than the GPL, without Broadcom's express prior written
-* consent.
-*****************************************************************************/
-
-#if !defined( VC_MEM_H )
-#define VC_MEM_H
-
-#include <linux/ioctl.h>
-
-#define VC_MEM_IOC_MAGIC  'v'
-
-#define VC_MEM_IOC_MEM_PHYS_ADDR    _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
-#define VC_MEM_IOC_MEM_SIZE         _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
-#define VC_MEM_IOC_MEM_BASE         _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
-#define VC_MEM_IOC_MEM_LOAD         _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
-
-#if defined( __KERNEL__ )
-#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
-
-extern unsigned long mm_vc_mem_phys_addr;
-extern unsigned int  mm_vc_mem_size;
-extern int vc_mem_get_current_size( void );
-#endif
-
-#endif  /* VC_MEM_H */
--- a/arch/arm/mach-bcm2709/vc_mem.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/*****************************************************************************
-* Copyright 2010 - 2011 Broadcom Corporation.  All rights reserved.
-*
-* Unless you and Broadcom execute a separate written software license
-* agreement governing use of this software, this software is licensed to you
-* under the terms of the GNU General Public License version 2, available at
-* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
-*
-* Notwithstanding the above, under no circumstances may you combine this
-* software in any way with any other Broadcom software provided under a
-* license other than the GPL, without Broadcom's express prior written
-* consent.
-*****************************************************************************/
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/device.h>
-#include <linux/cdev.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/debugfs.h>
-#include <asm/uaccess.h>
-#include <linux/dma-mapping.h>
-#include <linux/platform_data/mailbox-bcm2708.h>
-
-#ifdef CONFIG_ARCH_KONA
-#include <chal/chal_ipc.h>
-#elif defined(CONFIG_ARCH_BCM2708) || defined(CONFIG_ARCH_BCM2709)
-#else
-#include <csp/chal_ipc.h>
-#endif
-
-#include "mach/vc_mem.h"
-
-#define DRIVER_NAME  "vc-mem"
-
-// Device (/dev) related variables
-static dev_t vc_mem_devnum = 0;
-static struct class *vc_mem_class = NULL;
-static struct cdev vc_mem_cdev;
-static int vc_mem_inited = 0;
-
-#ifdef CONFIG_DEBUG_FS
-static struct dentry *vc_mem_debugfs_entry;
-#endif
-
-/*
- * Videocore memory addresses and size
- *
- * Drivers that wish to know the videocore memory addresses and sizes should
- * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
- * headers. This allows the other drivers to not be tied down to a a certain
- * address/size at compile time.
- *
- * In the future, the goal is to have the videocore memory virtual address and
- * size be calculated at boot time rather than at compile time. The decision of
- * where the videocore memory resides and its size would be in the hands of the
- * bootloader (and/or kernel). When that happens, the values of these variables
- * would be calculated and assigned in the init function.
- */
-// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
-unsigned long mm_vc_mem_phys_addr = 0x00000000;
-unsigned int mm_vc_mem_size = 0;
-unsigned int mm_vc_mem_base = 0;
-
-EXPORT_SYMBOL(mm_vc_mem_phys_addr);
-EXPORT_SYMBOL(mm_vc_mem_size);
-EXPORT_SYMBOL(mm_vc_mem_base);
-
-static uint phys_addr = 0;
-static uint mem_size = 0;
-static uint mem_base = 0;
-
-
-/****************************************************************************
-*
-*   vc_mem_open
-*
-***************************************************************************/
-
-static int
-vc_mem_open(struct inode *inode, struct file *file)
-{
-	(void) inode;
-	(void) file;
-
-	pr_debug("%s: called file = 0x%p\n", __func__, file);
-
-	return 0;
-}
-
-/****************************************************************************
-*
-*   vc_mem_release
-*
-***************************************************************************/
-
-static int
-vc_mem_release(struct inode *inode, struct file *file)
-{
-	(void) inode;
-	(void) file;
-
-	pr_debug("%s: called file = 0x%p\n", __func__, file);
-
-	return 0;
-}
-
-/****************************************************************************
-*
-*   vc_mem_get_size
-*
-***************************************************************************/
-
-static void
-vc_mem_get_size(void)
-{
-}
-
-/****************************************************************************
-*
-*   vc_mem_get_base
-*
-***************************************************************************/
-
-static void
-vc_mem_get_base(void)
-{
-}
-
-/****************************************************************************
-*
-*   vc_mem_get_current_size
-*
-***************************************************************************/
-
-int
-vc_mem_get_current_size(void)
-{
-	return mm_vc_mem_size;
-}
-
-EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
-
-/****************************************************************************
-*
-*   vc_mem_ioctl
-*
-***************************************************************************/
-
-static long
-vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-{
-	int rc = 0;
-
-	(void) cmd;
-	(void) arg;
-
-	pr_debug("%s: called file = 0x%p\n", __func__, file);
-
-	switch (cmd) {
-	case VC_MEM_IOC_MEM_PHYS_ADDR:
-		{
-			pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
-				__func__, (void *) mm_vc_mem_phys_addr);
-
-			if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
-					 sizeof (mm_vc_mem_phys_addr)) != 0) {
-				rc = -EFAULT;
-			}
-			break;
-		}
-	case VC_MEM_IOC_MEM_SIZE:
-		{
-			// Get the videocore memory size first
-			vc_mem_get_size();
-
-			pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
-				mm_vc_mem_size);
-
-			if (copy_to_user((void *) arg, &mm_vc_mem_size,
-					 sizeof (mm_vc_mem_size)) != 0) {
-				rc = -EFAULT;
-			}
-			break;
-		}
-	case VC_MEM_IOC_MEM_BASE:
-		{
-			// Get the videocore memory base
-			vc_mem_get_base();
-
-			pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
-				mm_vc_mem_base);
-
-			if (copy_to_user((void *) arg, &mm_vc_mem_base,
-					 sizeof (mm_vc_mem_base)) != 0) {
-				rc = -EFAULT;
-			}
-			break;
-		}
-	case VC_MEM_IOC_MEM_LOAD:
-		{
-			// Get the videocore memory base
-			vc_mem_get_base();
-
-			pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
-				mm_vc_mem_base);
-
-			if (copy_to_user((void *) arg, &mm_vc_mem_base,
-					 sizeof (mm_vc_mem_base)) != 0) {
-				rc = -EFAULT;
-			}
-			break;
-		}
-	default:
-		{
-			return -ENOTTY;
-		}
-	}
-	pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
-
-	return rc;
-}
-
-/****************************************************************************
-*
-*   vc_mem_mmap
-*
-***************************************************************************/
-
-static int
-vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
-{
-	int rc = 0;
-	unsigned long length = vma->vm_end - vma->vm_start;
-	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
-
-	pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
-		__func__, (long) vma->vm_start, (long) vma->vm_end,
-		(long) vma->vm_pgoff);
-
-	if (offset + length > mm_vc_mem_size) {
-		pr_err("%s: length %ld is too big\n", __func__, length);
-		return -EINVAL;
-	}
-	// Do not cache the memory map
-	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-
-	rc = remap_pfn_range(vma, vma->vm_start,
-			     (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
-			     vma->vm_pgoff, length, vma->vm_page_prot);
-	if (rc != 0) {
-		pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
-	}
-
-	return rc;
-}
-
-/****************************************************************************
-*
-*   File Operations for the driver.
-*
-***************************************************************************/
-
-static const struct file_operations vc_mem_fops = {
-	.owner = THIS_MODULE,
-	.open = vc_mem_open,
-	.release = vc_mem_release,
-	.unlocked_ioctl = vc_mem_ioctl,
-	.mmap = vc_mem_mmap,
-};
-
-#ifdef CONFIG_DEBUG_FS
-static void vc_mem_debugfs_deinit(void)
-{
-	debugfs_remove_recursive(vc_mem_debugfs_entry);
-	vc_mem_debugfs_entry = NULL;
-}
-
-
-static int vc_mem_debugfs_init(
-	struct device *dev)
-{
-	vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
-	if (!vc_mem_debugfs_entry) {
-		dev_warn(dev, "could not create debugfs entry\n");
-		return -EFAULT;
-	}
-
-	if (!debugfs_create_x32("vc_mem_phys_addr",
-				0444,
-				vc_mem_debugfs_entry,
-				(u32 *)&mm_vc_mem_phys_addr)) {
-		dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
-			__func__);
-		goto fail;
-	}
-
-	if (!debugfs_create_x32("vc_mem_size",
-				0444,
-				vc_mem_debugfs_entry,
-				(u32 *)&mm_vc_mem_size)) {
-		dev_warn(dev, "%s:could not create vc_mem_size entry\n",
-			__func__);
-		goto fail;
-	}
-
-	if (!debugfs_create_x32("vc_mem_base",
-				0444,
-				vc_mem_debugfs_entry,
-				(u32 *)&mm_vc_mem_base)) {
-		dev_warn(dev, "%s:could not create vc_mem_base entry\n",
-			 __func__);
-		goto fail;
-	}
-
-	return 0;
-
-fail:
-	vc_mem_debugfs_deinit();
-	return -EFAULT;
-}
-
-#endif /* CONFIG_DEBUG_FS */
-
-
-/****************************************************************************
-*
-*   vc_mem_init
-*
-***************************************************************************/
-
-static int __init
-vc_mem_init(void)
-{
-	int rc = -EFAULT;
-	struct device *dev;
-
-	pr_debug("%s: called\n", __func__);
-
-	mm_vc_mem_phys_addr = phys_addr;
-	mm_vc_mem_size = mem_size;
-	mm_vc_mem_base = mem_base;
-
-	vc_mem_get_size();
-
-	pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
-		mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
-
-	if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
-		pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
-		       __func__, rc);
-		goto out_err;
-	}
-
-	cdev_init(&vc_mem_cdev, &vc_mem_fops);
-	if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
-		pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
-		goto out_unregister;
-	}
-
-	vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
-	if (IS_ERR(vc_mem_class)) {
-		rc = PTR_ERR(vc_mem_class);
-		pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
-		goto out_cdev_del;
-	}
-
-	dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
-			    DRIVER_NAME);
-	if (IS_ERR(dev)) {
-		rc = PTR_ERR(dev);
-		pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
-		goto out_class_destroy;
-	}
-
-#ifdef CONFIG_DEBUG_FS
-	/* don't fail if the debug entries cannot be created */
-	vc_mem_debugfs_init(dev);
-#endif
-
-	vc_mem_inited = 1;
-	return 0;
-
-	device_destroy(vc_mem_class, vc_mem_devnum);
-
-      out_class_destroy:
-	class_destroy(vc_mem_class);
-	vc_mem_class = NULL;
-
-      out_cdev_del:
-	cdev_del(&vc_mem_cdev);
-
-      out_unregister:
-	unregister_chrdev_region(vc_mem_devnum, 1);
-
-      out_err:
-	return -1;
-}
-
-/****************************************************************************
-*
-*   vc_mem_exit
-*
-***************************************************************************/
-
-static void __exit
-vc_mem_exit(void)
-{
-	pr_debug("%s: called\n", __func__);
-
-	if (vc_mem_inited) {
-#if CONFIG_DEBUG_FS
-		vc_mem_debugfs_deinit();
-#endif
-		device_destroy(vc_mem_class, vc_mem_devnum);
-		class_destroy(vc_mem_class);
-		cdev_del(&vc_mem_cdev);
-		unregister_chrdev_region(vc_mem_devnum, 1);
-	}
-}
-
-module_init(vc_mem_init);
-module_exit(vc_mem_exit);
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Broadcom Corporation");
-
-module_param(phys_addr, uint, 0644);
-module_param(mem_size, uint, 0644);
-module_param(mem_base, uint, 0644);
--- a/drivers/char/broadcom/Kconfig
+++ b/drivers/char/broadcom/Kconfig
@@ -7,9 +7,19 @@ menuconfig BRCM_CHAR_DRIVERS
 	help
 	  Broadcom's char drivers
 
+if BRCM_CHAR_DRIVERS
+
 config BCM_VC_CMA
 	bool "Videocore CMA"
-	depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
+	depends on CMA && BCM2708_VCHIQ
 	default n
         help
           Helper for videocore CMA access.
+
+config BCM2708_VCMEM
+	bool "Videocore Memory"
+        default y
+        help
+          Helper for videocore memory access and total size allocation.
+
+endif
--- a/drivers/char/broadcom/Makefile
+++ b/drivers/char/broadcom/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_BCM_VC_CMA)	+= vc_cma/
+obj-$(CONFIG_BCM2708_VCMEM)	+= vc_mem.o
--- /dev/null
+++ b/drivers/char/broadcom/vc_mem.c
@@ -0,0 +1,422 @@
+/*****************************************************************************
+* Copyright 2010 - 2011 Broadcom Corporation.  All rights reserved.
+*
+* Unless you and Broadcom execute a separate written software license
+* agreement governing use of this software, this software is licensed to you
+* under the terms of the GNU General Public License version 2, available at
+* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
+*
+* Notwithstanding the above, under no circumstances may you combine this
+* software in any way with any other Broadcom software provided under a
+* license other than the GPL, without Broadcom's express prior written
+* consent.
+*****************************************************************************/
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/debugfs.h>
+#include <asm/uaccess.h>
+#include <linux/dma-mapping.h>
+#include <linux/broadcom/vc_mem.h>
+
+#define DRIVER_NAME  "vc-mem"
+
+// Device (/dev) related variables
+static dev_t vc_mem_devnum = 0;
+static struct class *vc_mem_class = NULL;
+static struct cdev vc_mem_cdev;
+static int vc_mem_inited = 0;
+
+#ifdef CONFIG_DEBUG_FS
+static struct dentry *vc_mem_debugfs_entry;
+#endif
+
+/*
+ * Videocore memory addresses and size
+ *
+ * Drivers that wish to know the videocore memory addresses and sizes should
+ * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
+ * headers. This allows the other drivers to not be tied down to a a certain
+ * address/size at compile time.
+ *
+ * In the future, the goal is to have the videocore memory virtual address and
+ * size be calculated at boot time rather than at compile time. The decision of
+ * where the videocore memory resides and its size would be in the hands of the
+ * bootloader (and/or kernel). When that happens, the values of these variables
+ * would be calculated and assigned in the init function.
+ */
+// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
+unsigned long mm_vc_mem_phys_addr = 0x00000000;
+unsigned int mm_vc_mem_size = 0;
+unsigned int mm_vc_mem_base = 0;
+
+EXPORT_SYMBOL(mm_vc_mem_phys_addr);
+EXPORT_SYMBOL(mm_vc_mem_size);
+EXPORT_SYMBOL(mm_vc_mem_base);
+
+static uint phys_addr = 0;
+static uint mem_size = 0;
+static uint mem_base = 0;
+
+
+/****************************************************************************
+*
+*   vc_mem_open
+*
+***************************************************************************/
+
+static int
+vc_mem_open(struct inode *inode, struct file *file)
+{
+	(void) inode;
+	(void) file;
+
+	pr_debug("%s: called file = 0x%p\n", __func__, file);
+
+	return 0;
+}
+
+/****************************************************************************
+*
+*   vc_mem_release
+*
+***************************************************************************/
+
+static int
+vc_mem_release(struct inode *inode, struct file *file)
+{
+	(void) inode;
+	(void) file;
+
+	pr_debug("%s: called file = 0x%p\n", __func__, file);
+
+	return 0;
+}
+
+/****************************************************************************
+*
+*   vc_mem_get_size
+*
+***************************************************************************/
+
+static void
+vc_mem_get_size(void)
+{
+}
+
+/****************************************************************************
+*
+*   vc_mem_get_base
+*
+***************************************************************************/
+
+static void
+vc_mem_get_base(void)
+{
+}
+
+/****************************************************************************
+*
+*   vc_mem_get_current_size
+*
+***************************************************************************/
+
+int
+vc_mem_get_current_size(void)
+{
+	return mm_vc_mem_size;
+}
+
+EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
+
+/****************************************************************************
+*
+*   vc_mem_ioctl
+*
+***************************************************************************/
+
+static long
+vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	int rc = 0;
+
+	(void) cmd;
+	(void) arg;
+
+	pr_debug("%s: called file = 0x%p\n", __func__, file);
+
+	switch (cmd) {
+	case VC_MEM_IOC_MEM_PHYS_ADDR:
+		{
+			pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
+				__func__, (void *) mm_vc_mem_phys_addr);
+
+			if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
+					 sizeof (mm_vc_mem_phys_addr)) != 0) {
+				rc = -EFAULT;
+			}
+			break;
+		}
+	case VC_MEM_IOC_MEM_SIZE:
+		{
+			// Get the videocore memory size first
+			vc_mem_get_size();
+
+			pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
+				mm_vc_mem_size);
+
+			if (copy_to_user((void *) arg, &mm_vc_mem_size,
+					 sizeof (mm_vc_mem_size)) != 0) {
+				rc = -EFAULT;
+			}
+			break;
+		}
+	case VC_MEM_IOC_MEM_BASE:
+		{
+			// Get the videocore memory base
+			vc_mem_get_base();
+
+			pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
+				mm_vc_mem_base);
+
+			if (copy_to_user((void *) arg, &mm_vc_mem_base,
+					 sizeof (mm_vc_mem_base)) != 0) {
+				rc = -EFAULT;
+			}
+			break;
+		}
+	case VC_MEM_IOC_MEM_LOAD:
+		{
+			// Get the videocore memory base
+			vc_mem_get_base();
+
+			pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
+				mm_vc_mem_base);
+
+			if (copy_to_user((void *) arg, &mm_vc_mem_base,
+					 sizeof (mm_vc_mem_base)) != 0) {
+				rc = -EFAULT;
+			}
+			break;
+		}
+	default:
+		{
+			return -ENOTTY;
+		}
+	}
+	pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
+
+	return rc;
+}
+
+/****************************************************************************
+*
+*   vc_mem_mmap
+*
+***************************************************************************/
+
+static int
+vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+	int rc = 0;
+	unsigned long length = vma->vm_end - vma->vm_start;
+	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+
+	pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
+		__func__, (long) vma->vm_start, (long) vma->vm_end,
+		(long) vma->vm_pgoff);
+
+	if (offset + length > mm_vc_mem_size) {
+		pr_err("%s: length %ld is too big\n", __func__, length);
+		return -EINVAL;
+	}
+	// Do not cache the memory map
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	rc = remap_pfn_range(vma, vma->vm_start,
+			     (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
+			     vma->vm_pgoff, length, vma->vm_page_prot);
+	if (rc != 0) {
+		pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
+	}
+
+	return rc;
+}
+
+/****************************************************************************
+*
+*   File Operations for the driver.
+*
+***************************************************************************/
+
+static const struct file_operations vc_mem_fops = {
+	.owner = THIS_MODULE,
+	.open = vc_mem_open,
+	.release = vc_mem_release,
+	.unlocked_ioctl = vc_mem_ioctl,
+	.mmap = vc_mem_mmap,
+};
+
+#ifdef CONFIG_DEBUG_FS
+static void vc_mem_debugfs_deinit(void)
+{
+	debugfs_remove_recursive(vc_mem_debugfs_entry);
+	vc_mem_debugfs_entry = NULL;
+}
+
+
+static int vc_mem_debugfs_init(
+	struct device *dev)
+{
+	vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
+	if (!vc_mem_debugfs_entry) {
+		dev_warn(dev, "could not create debugfs entry\n");
+		return -EFAULT;
+	}
+
+	if (!debugfs_create_x32("vc_mem_phys_addr",
+				0444,
+				vc_mem_debugfs_entry,
+				(u32 *)&mm_vc_mem_phys_addr)) {
+		dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
+			__func__);
+		goto fail;
+	}
+
+	if (!debugfs_create_x32("vc_mem_size",
+				0444,
+				vc_mem_debugfs_entry,
+				(u32 *)&mm_vc_mem_size)) {
+		dev_warn(dev, "%s:could not create vc_mem_size entry\n",
+			__func__);
+		goto fail;
+	}
+
+	if (!debugfs_create_x32("vc_mem_base",
+				0444,
+				vc_mem_debugfs_entry,
+				(u32 *)&mm_vc_mem_base)) {
+		dev_warn(dev, "%s:could not create vc_mem_base entry\n",
+			 __func__);
+		goto fail;
+	}
+
+	return 0;
+
+fail:
+	vc_mem_debugfs_deinit();
+	return -EFAULT;
+}
+
+#endif /* CONFIG_DEBUG_FS */
+
+
+/****************************************************************************
+*
+*   vc_mem_init
+*
+***************************************************************************/
+
+static int __init
+vc_mem_init(void)
+{
+	int rc = -EFAULT;
+	struct device *dev;
+
+	pr_debug("%s: called\n", __func__);
+
+	mm_vc_mem_phys_addr = phys_addr;
+	mm_vc_mem_size = mem_size;
+	mm_vc_mem_base = mem_base;
+
+	vc_mem_get_size();
+
+	pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
+		mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
+
+	if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
+		pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
+		       __func__, rc);
+		goto out_err;
+	}
+
+	cdev_init(&vc_mem_cdev, &vc_mem_fops);
+	if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
+		pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
+		goto out_unregister;
+	}
+
+	vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
+	if (IS_ERR(vc_mem_class)) {
+		rc = PTR_ERR(vc_mem_class);
+		pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
+		goto out_cdev_del;
+	}
+
+	dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
+			    DRIVER_NAME);
+	if (IS_ERR(dev)) {
+		rc = PTR_ERR(dev);
+		pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
+		goto out_class_destroy;
+	}
+
+#ifdef CONFIG_DEBUG_FS
+	/* don't fail if the debug entries cannot be created */
+	vc_mem_debugfs_init(dev);
+#endif
+
+	vc_mem_inited = 1;
+	return 0;
+
+	device_destroy(vc_mem_class, vc_mem_devnum);
+
+      out_class_destroy:
+	class_destroy(vc_mem_class);
+	vc_mem_class = NULL;
+
+      out_cdev_del:
+	cdev_del(&vc_mem_cdev);
+
+      out_unregister:
+	unregister_chrdev_region(vc_mem_devnum, 1);
+
+      out_err:
+	return -1;
+}
+
+/****************************************************************************
+*
+*   vc_mem_exit
+*
+***************************************************************************/
+
+static void __exit
+vc_mem_exit(void)
+{
+	pr_debug("%s: called\n", __func__);
+
+	if (vc_mem_inited) {
+#if CONFIG_DEBUG_FS
+		vc_mem_debugfs_deinit();
+#endif
+		device_destroy(vc_mem_class, vc_mem_devnum);
+		class_destroy(vc_mem_class);
+		cdev_del(&vc_mem_cdev);
+		unregister_chrdev_region(vc_mem_devnum, 1);
+	}
+}
+
+module_init(vc_mem_init);
+module_exit(vc_mem_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Broadcom Corporation");
+
+module_param(phys_addr, uint, 0644);
+module_param(mem_size, uint, 0644);
+module_param(mem_base, uint, 0644);
--- /dev/null
+++ b/include/linux/broadcom/vc_mem.h
@@ -0,0 +1,35 @@
+/*****************************************************************************
+* Copyright 2010 - 2011 Broadcom Corporation.  All rights reserved.
+*
+* Unless you and Broadcom execute a separate written software license
+* agreement governing use of this software, this software is licensed to you
+* under the terms of the GNU General Public License version 2, available at
+* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
+*
+* Notwithstanding the above, under no circumstances may you combine this
+* software in any way with any other Broadcom software provided under a
+* license other than the GPL, without Broadcom's express prior written
+* consent.
+*****************************************************************************/
+
+#ifndef _VC_MEM_H
+#define _VC_MEM_H
+
+#include <linux/ioctl.h>
+
+#define VC_MEM_IOC_MAGIC  'v'
+
+#define VC_MEM_IOC_MEM_PHYS_ADDR    _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
+#define VC_MEM_IOC_MEM_SIZE         _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
+#define VC_MEM_IOC_MEM_BASE         _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
+#define VC_MEM_IOC_MEM_LOAD         _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
+
+#if defined( __KERNEL__ )
+#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
+
+extern unsigned long mm_vc_mem_phys_addr;
+extern unsigned int  mm_vc_mem_size;
+extern int vc_mem_get_current_size( void );
+#endif
+
+#endif  /* _VC_MEM_H */