1- /*****************************************************************************
2- * Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
3- *
4- * Unless you and Broadcom execute a separate written software license
5- * agreement governing use of this software, this software is licensed to you
6- * under the terms of the GNU General Public License version 2, available at
7- * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8- *
9- * Notwithstanding the above, under no circumstances may you combine this
10- * software in any way with any other Broadcom software provided under a
11- * license other than the GPL, without Broadcom's express prior written
12- * consent.
13- **************************************************************************** */
1+ /*
2+ * Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
3+ *
4+ * Unless you and Broadcom execute a separate written software license
5+ * agreement governing use of this software, this software is licensed to you
6+ * under the terms of the GNU General Public License version 2, available at
7+ * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8+ *
9+ * Notwithstanding the above, under no circumstances may you combine this
10+ * software in any way with any other Broadcom software provided under a
11+ * license other than the GPL, without Broadcom's express prior written
12+ * consent.
13+ */
1414
1515#include <linux/kernel.h>
1616#include <linux/module.h>
2626
2727#define DRIVER_NAME "vc-mem"
2828
29- // Device (/dev) related variables
30- static dev_t vc_mem_devnum = 0 ;
31- static struct class * vc_mem_class = NULL ;
29+ /* Device (/dev) related variables */
30+ static dev_t vc_mem_devnum ;
31+ static struct class * vc_mem_class ;
3232static struct cdev vc_mem_cdev ;
33- static int vc_mem_inited = 0 ;
33+ static int vc_mem_inited ;
3434
3535#ifdef CONFIG_DEBUG_FS
3636static struct dentry * vc_mem_debugfs_entry ;
@@ -50,96 +50,55 @@ static struct dentry *vc_mem_debugfs_entry;
5050 * bootloader (and/or kernel). When that happens, the values of these variables
5151 * would be calculated and assigned in the init function.
5252 */
53- // in the 2835 VC in mapped above ARM, but ARM has full access to VC space
54- unsigned long mm_vc_mem_phys_addr = 0x00000000 ;
55- unsigned int mm_vc_mem_size = 0 ;
56- unsigned int mm_vc_mem_base = 0 ;
57-
53+ /* In the 2835 VC in mapped above ARM, but ARM has full access to VC space */
54+ unsigned long mm_vc_mem_phys_addr ;
5855EXPORT_SYMBOL (mm_vc_mem_phys_addr );
56+ unsigned int mm_vc_mem_size ;
5957EXPORT_SYMBOL (mm_vc_mem_size );
58+ unsigned int mm_vc_mem_base ;
6059EXPORT_SYMBOL (mm_vc_mem_base );
6160
62- static uint phys_addr = 0 ;
63- static uint mem_size = 0 ;
64- static uint mem_base = 0 ;
65-
66-
67- /****************************************************************************
68- *
69- * vc_mem_open
70- *
71- ***************************************************************************/
61+ static uint phys_addr ;
62+ static uint mem_size ;
63+ static uint mem_base ;
7264
7365static int
7466vc_mem_open (struct inode * inode , struct file * file )
7567{
76- (void ) inode ;
77- (void ) file ;
68+ (void )inode ;
7869
7970 pr_debug ("%s: called file = 0x%p\n" , __func__ , file );
8071
8172 return 0 ;
8273}
8374
84- /****************************************************************************
85- *
86- * vc_mem_release
87- *
88- ***************************************************************************/
89-
9075static int
9176vc_mem_release (struct inode * inode , struct file * file )
9277{
93- (void ) inode ;
94- (void ) file ;
78+ (void )inode ;
9579
9680 pr_debug ("%s: called file = 0x%p\n" , __func__ , file );
9781
9882 return 0 ;
9983}
10084
101- /****************************************************************************
102- *
103- * vc_mem_get_size
104- *
105- ***************************************************************************/
106-
10785static void
10886vc_mem_get_size (void )
10987{
11088}
11189
112- /****************************************************************************
113- *
114- * vc_mem_get_base
115- *
116- ***************************************************************************/
117-
11890static void
11991vc_mem_get_base (void )
12092{
12193}
12294
123- /****************************************************************************
124- *
125- * vc_mem_get_current_size
126- *
127- ***************************************************************************/
128-
12995int
13096vc_mem_get_current_size (void )
13197{
13298 return mm_vc_mem_size ;
13399}
134-
135100EXPORT_SYMBOL_GPL (vc_mem_get_current_size );
136101
137- /****************************************************************************
138- *
139- * vc_mem_ioctl
140- *
141- ***************************************************************************/
142-
143102static long
144103vc_mem_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
145104{
@@ -154,52 +113,52 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
154113 case VC_MEM_IOC_MEM_PHYS_ADDR :
155114 {
156115 pr_debug ("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n" ,
157- __func__ , (void * ) mm_vc_mem_phys_addr );
116+ __func__ , (void * )mm_vc_mem_phys_addr );
158117
159- if (copy_to_user ((void * ) arg , & mm_vc_mem_phys_addr ,
160- sizeof (mm_vc_mem_phys_addr )) != 0 ) {
118+ if (copy_to_user ((void * )arg , & mm_vc_mem_phys_addr ,
119+ sizeof (mm_vc_mem_phys_addr ))) {
161120 rc = - EFAULT ;
162121 }
163122 break ;
164123 }
165124 case VC_MEM_IOC_MEM_SIZE :
166125 {
167- // Get the videocore memory size first
126+ /* Get the videocore memory size first */
168127 vc_mem_get_size ();
169128
170129 pr_debug ("%s: VC_MEM_IOC_MEM_SIZE=%x\n" , __func__ ,
171- mm_vc_mem_size );
130+ mm_vc_mem_size );
172131
173- if (copy_to_user ((void * ) arg , & mm_vc_mem_size ,
174- sizeof (mm_vc_mem_size )) != 0 ) {
132+ if (copy_to_user ((void * )arg , & mm_vc_mem_size ,
133+ sizeof (mm_vc_mem_size ))) {
175134 rc = - EFAULT ;
176135 }
177136 break ;
178137 }
179138 case VC_MEM_IOC_MEM_BASE :
180139 {
181- // Get the videocore memory base
140+ /* Get the videocore memory base */
182141 vc_mem_get_base ();
183142
184143 pr_debug ("%s: VC_MEM_IOC_MEM_BASE=%x\n" , __func__ ,
185- mm_vc_mem_base );
144+ mm_vc_mem_base );
186145
187- if (copy_to_user ((void * ) arg , & mm_vc_mem_base ,
188- sizeof (mm_vc_mem_base )) != 0 ) {
146+ if (copy_to_user ((void * )arg , & mm_vc_mem_base ,
147+ sizeof (mm_vc_mem_base ))) {
189148 rc = - EFAULT ;
190149 }
191150 break ;
192151 }
193152 case VC_MEM_IOC_MEM_LOAD :
194153 {
195- // Get the videocore memory base
154+ /* Get the videocore memory base */
196155 vc_mem_get_base ();
197156
198157 pr_debug ("%s: VC_MEM_IOC_MEM_LOAD=%x\n" , __func__ ,
199158 mm_vc_mem_base );
200159
201- if (copy_to_user ((void * ) arg , & mm_vc_mem_base ,
202- sizeof (mm_vc_mem_base )) != 0 ) {
160+ if (copy_to_user ((void * )arg , & mm_vc_mem_base ,
161+ sizeof (mm_vc_mem_base ))) {
203162 rc = - EFAULT ;
204163 }
205164 break ;
@@ -243,12 +202,6 @@ vc_mem_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
243202}
244203#endif
245204
246- /****************************************************************************
247- *
248- * vc_mem_mmap
249- *
250- ***************************************************************************/
251-
252205static int
253206vc_mem_mmap (struct file * filp , struct vm_area_struct * vma )
254207{
@@ -257,32 +210,26 @@ vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
257210 unsigned long offset = vma -> vm_pgoff << PAGE_SHIFT ;
258211
259212 pr_debug ("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n" ,
260- __func__ , (long ) vma -> vm_start , (long ) vma -> vm_end ,
261- (long ) vma -> vm_pgoff );
213+ __func__ , (long )vma -> vm_start , (long )vma -> vm_end ,
214+ (long )vma -> vm_pgoff );
262215
263216 if (offset + length > mm_vc_mem_size ) {
264217 pr_err ("%s: length %ld is too big\n" , __func__ , length );
265218 return - EINVAL ;
266219 }
267- // Do not cache the memory map
220+ /* Do not cache the memory map */
268221 vma -> vm_page_prot = pgprot_noncached (vma -> vm_page_prot );
269222
270223 rc = remap_pfn_range (vma , vma -> vm_start ,
271224 (mm_vc_mem_phys_addr >> PAGE_SHIFT ) +
272225 vma -> vm_pgoff , length , vma -> vm_page_prot );
273- if (rc != 0 ) {
226+ if (rc )
274227 pr_err ("%s: remap_pfn_range failed (rc=%d)\n" , __func__ , rc );
275- }
276228
277229 return rc ;
278230}
279231
280- /****************************************************************************
281- *
282- * File Operations for the driver.
283- *
284- ***************************************************************************/
285-
232+ /* File Operations for the driver. */
286233static const struct file_operations vc_mem_fops = {
287234 .owner = THIS_MODULE ,
288235 .open = vc_mem_open ,
@@ -316,7 +263,7 @@ static int vc_mem_debugfs_init(
316263 vc_mem_debugfs_entry ,
317264 (u32 * )& mm_vc_mem_phys_addr )) {
318265 dev_warn (dev , "%s:could not create vc_mem_phys entry\n" ,
319- __func__ );
266+ __func__ );
320267 goto fail ;
321268 }
322269
@@ -325,7 +272,7 @@ static int vc_mem_debugfs_init(
325272 vc_mem_debugfs_entry ,
326273 (u32 * )& mm_vc_mem_size )) {
327274 dev_warn (dev , "%s:could not create vc_mem_size entry\n" ,
328- __func__ );
275+ __func__ );
329276 goto fail ;
330277 }
331278
@@ -347,12 +294,7 @@ static int vc_mem_debugfs_init(
347294
348295#endif /* CONFIG_DEBUG_FS */
349296
350-
351- /****************************************************************************
352- *
353- * vc_mem_init
354- *
355- ***************************************************************************/
297+ /* Module load/unload functions */
356298
357299static int __init
358300vc_mem_init (void )
@@ -369,16 +311,19 @@ vc_mem_init(void)
369311 vc_mem_get_size ();
370312
371313 pr_info ("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n" ,
372- mm_vc_mem_phys_addr , mm_vc_mem_base , mm_vc_mem_size , mm_vc_mem_size / (1024 * 1024 ));
314+ mm_vc_mem_phys_addr , mm_vc_mem_base , mm_vc_mem_size ,
315+ mm_vc_mem_size / (1024 * 1024 ));
373316
374- if ((rc = alloc_chrdev_region (& vc_mem_devnum , 0 , 1 , DRIVER_NAME )) < 0 ) {
317+ rc = alloc_chrdev_region (& vc_mem_devnum , 0 , 1 , DRIVER_NAME );
318+ if (rc < 0 ) {
375319 pr_err ("%s: alloc_chrdev_region failed (rc=%d)\n" ,
376320 __func__ , rc );
377321 goto out_err ;
378322 }
379323
380324 cdev_init (& vc_mem_cdev , & vc_mem_fops );
381- if ((rc = cdev_add (& vc_mem_cdev , vc_mem_devnum , 1 )) != 0 ) {
325+ rc = cdev_add (& vc_mem_cdev , vc_mem_devnum , 1 );
326+ if (rc ) {
382327 pr_err ("%s: cdev_add failed (rc=%d)\n" , __func__ , rc );
383328 goto out_unregister ;
384329 }
@@ -408,26 +353,20 @@ vc_mem_init(void)
408353
409354 device_destroy (vc_mem_class , vc_mem_devnum );
410355
411- out_class_destroy :
356+ out_class_destroy :
412357 class_destroy (vc_mem_class );
413358 vc_mem_class = NULL ;
414359
415- out_cdev_del :
360+ out_cdev_del :
416361 cdev_del (& vc_mem_cdev );
417362
418- out_unregister :
363+ out_unregister :
419364 unregister_chrdev_region (vc_mem_devnum , 1 );
420365
421- out_err :
366+ out_err :
422367 return -1 ;
423368}
424369
425- /****************************************************************************
426- *
427- * vc_mem_exit
428- *
429- ***************************************************************************/
430-
431370static void __exit
432371vc_mem_exit (void )
433372{
0 commit comments