tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / linux / mali_kernel_linux.c
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 /**
12  * @file mali_kernel_linux.c
13  * Implementation of the Linux device driver entrypoints
14  */
15 #include <linux/module.h>   /* kernel module definitions */
16 #include <linux/fs.h>       /* file system operations */
17 #include <linux/cdev.h>     /* character device definitions */
18 #include <linux/mm.h>       /* memory manager definitions */
19 #include <linux/mali/mali_utgard_ioctl.h>
20 #include <linux/of.h>
21 #include <linux/version.h>
22 #include <linux/device.h>
23 #include "mali_kernel_license.h"
24 #include <linux/platform_device.h>
25 #if MALI_LICENSE_IS_GPL
26 #include <linux/miscdevice.h>
27 #endif
28 #include <linux/mali/mali_utgard.h>
29 #include "mali_kernel_common.h"
30 #include "mali_session.h"
31 #include "mali_kernel_core.h"
32 #include "mali_osk.h"
33 #include "mali_kernel_linux.h"
34 #include "mali_ukk.h"
35 #include "mali_ukk_wrappers.h"
36 #include "mali_kernel_sysfs.h"
37 #include "mali_pm.h"
38 #include "mali_kernel_license.h"
39 #include "mali_dma_buf.h"
40 #if defined(CONFIG_MALI400_INTERNAL_PROFILING)
41 #include "mali_profiling_internal.h"
42 #endif
43 /* MALI_SEC */
44 #include "../platform/exynos4/exynos4.h"
45
46 /* Streamline support for the Mali driver */
47 #if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_MALI400_PROFILING)
48 /* Ask Linux to create the tracepoints */
49 #define CREATE_TRACE_POINTS
50 #include "mali_linux_trace.h"
51 #endif /* CONFIG_TRACEPOINTS */
52
53 /* from the __malidrv_build_info.c file that is generated during build */
54 extern const char *__malidrv_build_info(void);
55
56 /* Module parameter to control log level */
57 int mali_debug_level = 2;
58 module_param(mali_debug_level, int, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH); /* rw-rw-r-- */
59 MODULE_PARM_DESC(mali_debug_level, "Higher number, more dmesg output");
60
61 module_param(mali_max_job_runtime, int, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH);
62 MODULE_PARM_DESC(mali_max_job_runtime, "Maximum allowed job runtime in msecs.\nJobs will be killed after this no matter what");
63
64 extern int mali_l2_max_reads;
65 module_param(mali_l2_max_reads, int, S_IRUSR | S_IRGRP | S_IROTH);
66 MODULE_PARM_DESC(mali_l2_max_reads, "Maximum reads for Mali L2 cache");
67
68 extern int mali_dedicated_mem_start;
69 module_param(mali_dedicated_mem_start, int, S_IRUSR | S_IRGRP | S_IROTH);
70 MODULE_PARM_DESC(mali_dedicated_mem_start, "Physical start address of dedicated Mali GPU memory.");
71
72 extern int mali_dedicated_mem_size;
73 module_param(mali_dedicated_mem_size, int, S_IRUSR | S_IRGRP | S_IROTH);
74 MODULE_PARM_DESC(mali_dedicated_mem_size, "Size of dedicated Mali GPU memory.");
75
76 extern int mali_shared_mem_size;
77 module_param(mali_shared_mem_size, int, S_IRUSR | S_IRGRP | S_IROTH);
78 MODULE_PARM_DESC(mali_shared_mem_size, "Size of shared Mali GPU memory.");
79
80 #if defined(CONFIG_MALI400_PROFILING)
81 extern int mali_boot_profiling;
82 module_param(mali_boot_profiling, int, S_IRUSR | S_IRGRP | S_IROTH);
83 MODULE_PARM_DESC(mali_boot_profiling, "Start profiling as a part of Mali driver initialization");
84 #endif
85
86 extern int mali_max_pp_cores_group_1;
87 module_param(mali_max_pp_cores_group_1, int, S_IRUSR | S_IRGRP | S_IROTH);
88 MODULE_PARM_DESC(mali_max_pp_cores_group_1, "Limit the number of PP cores to use from first PP group.");
89
90 extern int mali_max_pp_cores_group_2;
91 module_param(mali_max_pp_cores_group_2, int, S_IRUSR | S_IRGRP | S_IROTH);
92 MODULE_PARM_DESC(mali_max_pp_cores_group_2, "Limit the number of PP cores to use from second PP group (Mali-450 only).");
93
94 /* Export symbols from common code: mali_user_settings.c */
95 #include "mali_user_settings_db.h"
96 EXPORT_SYMBOL(mali_set_user_setting);
97 EXPORT_SYMBOL(mali_get_user_setting);
98 #if CONFIG_MALI_DVFS
99 #if 0
100 extern int mali_gpu_clk;
101 module_param(mali_gpu_clk, int, S_IRUSR | S_IRGRP | S_IROTH); /* r--r--r-- */
102 MODULE_PARM_DESC(mali_gpu_clk, "Mali Current Clock");
103
104 extern int mali_gpu_vol;
105 module_param(mali_gpu_vol, int, S_IRUSR | S_IRGRP | S_IROTH); /* r--r--r-- */
106 MODULE_PARM_DESC(mali_gpu_vol, "Mali Current Voltage");
107
108 extern int gpu_power_state;
109 module_param(gpu_power_state, int, S_IRUSR | S_IRGRP | S_IROTH); /* r--r--r-- */
110 MODULE_PARM_DESC(gpu_power_state, "Mali Power State");
111 #endif
112 #endif
113
114 static char mali_dev_name[] = "mali"; /* should be const, but the functions we call requires non-cost */
115
116 /* This driver only supports one Mali device, and this variable stores this single platform device */
117 struct platform_device *mali_platform_device = NULL;
118
119 /* This driver only supports one Mali device, and this variable stores the exposed misc device (/dev/mali) */
120 static struct miscdevice mali_miscdevice = { 0, };
121
122 static int mali_miscdevice_register(struct platform_device *pdev);
123 static void mali_miscdevice_unregister(void);
124
125 static int mali_open(struct inode *inode, struct file *filp);
126 static int mali_release(struct inode *inode, struct file *filp);
127 #ifdef HAVE_UNLOCKED_IOCTL
128 static long mali_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
129 #else
130 static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
131 #endif
132 static int mali_mmap(struct file * filp, struct vm_area_struct * vma);
133
134 static int mali_probe(struct platform_device *pdev);
135 static int mali_remove(struct platform_device *pdev);
136
137 static int mali_driver_suspend_scheduler(struct device *dev);
138 static int mali_driver_resume_scheduler(struct device *dev);
139
140 #ifdef CONFIG_PM_RUNTIME
141 static int mali_driver_runtime_suspend(struct device *dev);
142 static int mali_driver_runtime_resume(struct device *dev);
143 static int mali_driver_runtime_idle(struct device *dev);
144 #endif
145
146 #if defined(MALI_FAKE_PLATFORM_DEVICE)
147 extern int mali_platform_device_register(void);
148 extern int mali_platform_device_unregister(void);
149 #endif
150
151 /* Linux power management operations provided by the Mali device driver */
152 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
153 struct pm_ext_ops mali_dev_ext_pm_ops =
154 {
155         .base =
156         {
157                 .suspend = mali_driver_suspend_scheduler,
158                 .resume = mali_driver_resume_scheduler,
159                 .freeze = mali_driver_suspend_scheduler,
160                 .thaw =   mali_driver_resume_scheduler,
161         },
162 };
163 #else
164 static const struct dev_pm_ops mali_dev_pm_ops =
165 {
166 #ifdef CONFIG_PM_RUNTIME
167         .runtime_suspend = mali_driver_runtime_suspend,
168         .runtime_resume = mali_driver_runtime_resume,
169         .runtime_idle = mali_driver_runtime_idle,
170 #endif
171         .suspend = mali_driver_suspend_scheduler,
172         .resume = mali_driver_resume_scheduler,
173         .freeze = mali_driver_suspend_scheduler,
174         .thaw = mali_driver_resume_scheduler,
175 };
176 #endif
177
178 /* The Mali device driver struct */
179 static struct platform_driver mali_platform_driver =
180 {
181         .probe  = mali_probe,
182         .remove = mali_remove,
183 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
184         .pm = &mali_dev_ext_pm_ops,
185 #endif
186         .driver =
187         {
188                 .name   = "mali_dev", /* MALI_SEC MALI_GPU_NAME_UTGARD, */
189                 .owner  = THIS_MODULE,
190                 .bus = &platform_bus_type,
191 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
192                 .pm = &mali_dev_pm_ops,
193 #endif
194                 .of_match_table = of_match_ptr(mali_of_matches),
195         },
196 };
197
198 /* Linux misc device operations (/dev/mali) */
199 struct file_operations mali_fops =
200 {
201         .owner = THIS_MODULE,
202         .open = mali_open,
203         .release = mali_release,
204 #ifdef HAVE_UNLOCKED_IOCTL
205         .unlocked_ioctl = mali_ioctl,
206 #else
207         .ioctl = mali_ioctl,
208 #endif
209         .mmap = mali_mmap
210 };
211
212
213
214
215
216
217 int mali_module_init(void)
218 {
219         int err = 0;
220
221         MALI_DEBUG_PRINT(2, ("Inserting Mali v%d device driver. \n",_MALI_API_VERSION));
222         MALI_DEBUG_PRINT(2, ("Compiled: %s, time: %s.\n", __DATE__, __TIME__));
223         MALI_DEBUG_PRINT(2, ("Driver revision: %s\n", SVN_REV_STRING));
224
225         /* Initialize module wide settings */
226         mali_osk_low_level_mem_init();
227
228 #if defined(MALI_FAKE_PLATFORM_DEVICE)
229         MALI_DEBUG_PRINT(2, ("mali_module_init() registering device\n"));
230         err = mali_platform_device_register();
231         if (0 != err)
232         {
233                 return err;
234         }
235 #endif
236
237         MALI_DEBUG_PRINT(2, ("mali_module_init() registering driver\n"));
238
239         err = platform_driver_register(&mali_platform_driver);
240
241         if (0 != err)
242         {
243                 MALI_DEBUG_PRINT(2, ("mali_module_init() Failed to register driver (%d)\n", err));
244 #if defined(MALI_FAKE_PLATFORM_DEVICE)
245                 mali_platform_device_unregister();
246 #endif
247                 mali_platform_device = NULL;
248                 return err;
249         }
250
251 #if defined(CONFIG_MALI400_INTERNAL_PROFILING)
252         err = _mali_internal_profiling_init(mali_boot_profiling ? MALI_TRUE : MALI_FALSE);
253         if (0 != err)
254         {
255                 /* No biggie if we wheren't able to initialize the profiling */
256                 MALI_PRINT_ERROR(("Failed to initialize profiling, feature will be unavailable\n"));
257         }
258 #endif
259
260         MALI_PRINT(("Mali device driver loaded\n"));
261
262         return 0; /* Success */
263 }
264
265 void mali_module_exit(void)
266 {
267         MALI_DEBUG_PRINT(2, ("Unloading Mali v%d device driver.\n",_MALI_API_VERSION));
268
269         MALI_DEBUG_PRINT(2, ("mali_module_exit() unregistering driver\n"));
270
271 #if defined(CONFIG_MALI400_INTERNAL_PROFILING)
272         _mali_internal_profiling_term();
273 #endif
274
275         platform_driver_unregister(&mali_platform_driver);
276
277 #if defined(MALI_FAKE_PLATFORM_DEVICE)
278         MALI_DEBUG_PRINT(2, ("mali_module_exit() unregistering device\n"));
279         mali_platform_device_unregister();
280 #endif
281
282         mali_osk_low_level_mem_term();
283
284         MALI_PRINT(("Mali device driver unloaded\n"));
285 }
286
287 static int mali_probe(struct platform_device *pdev)
288 {
289         int err;
290
291         MALI_DEBUG_PRINT(2, ("mali_probe(): Called for platform device %s\n", pdev->name));
292
293         if (NULL != mali_platform_device)
294         {
295                 /* Already connected to a device, return error */
296                 MALI_PRINT_ERROR(("mali_probe(): The Mali driver is already connected with a Mali device."));
297                 return -EEXIST;
298         }
299
300         mali_platform_device = pdev;
301
302         if (mali_platform_init() != _MALI_OSK_ERR_OK)
303         {
304                 /* Platform-specific initialization failed, return error */
305                 MALI_PRINT_ERROR(("mali_probe(): mali_platform_init() failed."));
306                 return -EFAULT;
307         }
308
309         if (_MALI_OSK_ERR_OK == _mali_osk_wq_init())
310         {
311                 /* Initialize the Mali GPU HW specified by pdev */
312                 if (_MALI_OSK_ERR_OK == mali_initialize_subsystems())
313                 {
314                         /* Register a misc device (so we are accessible from user space) */
315                         err = mali_miscdevice_register(pdev);
316                         if (0 == err)
317                         {
318                                 /* Setup sysfs entries */
319                                 err = mali_sysfs_register(mali_dev_name);
320                                 if (0 == err)
321                                 {
322                                         MALI_DEBUG_PRINT(2, ("mali_probe(): Successfully initialized driver for platform device %s\n", pdev->name));
323                                         return 0;
324                                 }
325                                 else
326                                 {
327                                         MALI_PRINT_ERROR(("mali_probe(): failed to register sysfs entries"));
328                                 }
329                                 mali_miscdevice_unregister();
330                         }
331                         else
332                         {
333                                 MALI_PRINT_ERROR(("mali_probe(): failed to register Mali misc device."));
334                         }
335                         mali_terminate_subsystems();
336                 }
337                 else
338                 {
339                         MALI_PRINT_ERROR(("mali_probe(): Failed to initialize Mali device driver."));
340                 }
341                 _mali_osk_wq_term();
342         }
343
344         mali_platform_device = NULL;
345         return -EFAULT;
346 }
347
348 static int mali_remove(struct platform_device *pdev)
349 {
350         MALI_DEBUG_PRINT(2, ("mali_remove() called for platform device %s\n", pdev->name));
351         mali_sysfs_unregister();
352         mali_miscdevice_unregister();
353         mali_terminate_subsystems();
354         _mali_osk_wq_term();
355         mali_platform_deinit();
356         mali_platform_device = NULL;
357         return 0;
358 }
359
360 static int mali_miscdevice_register(struct platform_device *pdev)
361 {
362         int err;
363
364         mali_miscdevice.minor = MISC_DYNAMIC_MINOR;
365         mali_miscdevice.name = mali_dev_name;
366         mali_miscdevice.fops = &mali_fops;
367         mali_miscdevice.parent = get_device(&pdev->dev);
368
369         err = misc_register(&mali_miscdevice);
370         if (0 != err)
371         {
372                 MALI_PRINT_ERROR(("Failed to register misc device, misc_register() returned %d\n", err));
373         }
374
375         return err;
376 }
377
378 static void mali_miscdevice_unregister(void)
379 {
380         misc_deregister(&mali_miscdevice);
381 }
382
383 static int mali_driver_suspend_scheduler(struct device *dev)
384 {
385         mali_pm_os_suspend();
386         /* MALI_SEC */
387         mali_platform_power_mode_change(MALI_POWER_MODE_DEEP_SLEEP);
388         return 0;
389 }
390
391 static int mali_driver_resume_scheduler(struct device *dev)
392 {
393         /* MALI_SEC */
394         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
395         mali_pm_os_resume();
396         return 0;
397 }
398
399 #ifdef CONFIG_PM_RUNTIME
400 static int mali_driver_runtime_suspend(struct device *dev)
401 {
402         mali_pm_runtime_suspend();
403         /* MALI_SEC */
404         mali_platform_power_mode_change(MALI_POWER_MODE_LIGHT_SLEEP);
405         return 0;
406 }
407
408 static int mali_driver_runtime_resume(struct device *dev)
409 {
410         /* MALI_SEC */
411         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
412         mali_pm_runtime_resume();
413         return 0;
414 }
415
416 static int mali_driver_runtime_idle(struct device *dev)
417 {
418         /* Nothing to do */
419         return 0;
420 }
421 #endif
422
423 /** @note munmap handler is done by vma close handler */
424 static int mali_mmap(struct file * filp, struct vm_area_struct * vma)
425 {
426         struct mali_session_data * session_data;
427         _mali_uk_mem_mmap_s args = {0, };
428
429     session_data = (struct mali_session_data *)filp->private_data;
430         if (NULL == session_data)
431         {
432                 MALI_PRINT_ERROR(("mmap called without any session data available\n"));
433                 return -EFAULT;
434         }
435
436         MALI_DEBUG_PRINT(4, ("MMap() handler: start=0x%08X, phys=0x%08X, size=0x%08X vma->flags 0x%08x\n", (unsigned int)vma->vm_start, (unsigned int)(vma->vm_pgoff << PAGE_SHIFT), (unsigned int)(vma->vm_end - vma->vm_start), vma->vm_flags));
437
438         /* Re-pack the arguments that mmap() packed for us */
439         args.ctx = session_data;
440         args.phys_addr = vma->vm_pgoff << PAGE_SHIFT;
441         args.size = vma->vm_end - vma->vm_start;
442         args.ukk_private = vma;
443
444         if ( VM_SHARED== (VM_SHARED  & vma->vm_flags))
445         {
446                 args.cache_settings = MALI_CACHE_STANDARD ;
447                 MALI_DEBUG_PRINT(3,("Allocate - Standard - Size: %d kb\n", args.size/1024));
448         }
449         else
450         {
451                 args.cache_settings = MALI_CACHE_GP_READ_ALLOCATE;
452                 MALI_DEBUG_PRINT(3,("Allocate - GP Cached - Size: %d kb\n", args.size/1024));
453         }
454         /* Setting it equal to VM_SHARED and not Private, which would have made the later io_remap fail for MALI_CACHE_GP_READ_ALLOCATE */
455         vma->vm_flags = 0x000000fb;
456
457         /* Call the common mmap handler */
458         MALI_CHECK(_MALI_OSK_ERR_OK ==_mali_ukk_mem_mmap( &args ), -EFAULT);
459
460     return 0;
461 }
462
463 static int mali_open(struct inode *inode, struct file *filp)
464 {
465         struct mali_session_data * session_data;
466     _mali_osk_errcode_t err;
467
468         /* input validation */
469         if (mali_miscdevice.minor != iminor(inode))
470         {
471                 MALI_PRINT_ERROR(("mali_open() Minor does not match\n"));
472                 return -ENODEV;
473         }
474
475         /* allocated struct to track this session */
476     err = _mali_ukk_open((void **)&session_data);
477     if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
478
479         /* initialize file pointer */
480         filp->f_pos = 0;
481
482         /* link in our session data */
483         filp->private_data = (void*)session_data;
484
485         return 0;
486 }
487
488 static int mali_release(struct inode *inode, struct file *filp)
489 {
490     _mali_osk_errcode_t err;
491
492         /* input validation */
493         if (mali_miscdevice.minor != iminor(inode))
494         {
495                 MALI_PRINT_ERROR(("mali_release() Minor does not match\n"));
496                 return -ENODEV;
497         }
498
499     err = _mali_ukk_close((void **)&filp->private_data);
500     if (_MALI_OSK_ERR_OK != err) return map_errcode(err);
501
502         return 0;
503 }
504
505 int map_errcode( _mali_osk_errcode_t err )
506 {
507     switch(err)
508     {
509         case _MALI_OSK_ERR_OK : return 0;
510         case _MALI_OSK_ERR_FAULT: return -EFAULT;
511         case _MALI_OSK_ERR_INVALID_FUNC: return -ENOTTY;
512         case _MALI_OSK_ERR_INVALID_ARGS: return -EINVAL;
513         case _MALI_OSK_ERR_NOMEM: return -ENOMEM;
514         case _MALI_OSK_ERR_TIMEOUT: return -ETIMEDOUT;
515         case _MALI_OSK_ERR_RESTARTSYSCALL: return -ERESTARTSYS;
516         case _MALI_OSK_ERR_ITEM_NOT_FOUND: return -ENOENT;
517         default: return -EFAULT;
518     }
519 }
520
521 #ifdef HAVE_UNLOCKED_IOCTL
522 static long mali_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
523 #else
524 static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
525 #endif
526 {
527         int err;
528         struct mali_session_data *session_data;
529
530 #ifndef HAVE_UNLOCKED_IOCTL
531         /* inode not used */
532         (void)inode;
533 #endif
534
535         MALI_DEBUG_PRINT(7, ("Ioctl received 0x%08X 0x%08lX\n", cmd, arg));
536
537         session_data = (struct mali_session_data *)filp->private_data;
538         if (NULL == session_data)
539         {
540                 MALI_DEBUG_PRINT(7, ("filp->private_data was NULL\n"));
541                 return -ENOTTY;
542         }
543
544         if (NULL == (void *)arg)
545         {
546                 MALI_DEBUG_PRINT(7, ("arg was NULL\n"));
547                 return -ENOTTY;
548         }
549
550         switch(cmd)
551         {
552                 case MALI_IOC_WAIT_FOR_NOTIFICATION:
553                         err = wait_for_notification_wrapper(session_data, (_mali_uk_wait_for_notification_s __user *)arg);
554                         break;
555
556                 case MALI_IOC_GET_API_VERSION:
557                         err = get_api_version_wrapper(session_data, (_mali_uk_get_api_version_s __user *)arg);
558                         break;
559
560                 case MALI_IOC_POST_NOTIFICATION:
561                         err = post_notification_wrapper(session_data, (_mali_uk_post_notification_s __user *)arg);
562                         break;
563
564                 case MALI_IOC_GET_USER_SETTINGS:
565                         err = get_user_settings_wrapper(session_data, (_mali_uk_get_user_settings_s __user *)arg);
566                         break;
567
568 #if defined(CONFIG_MALI400_PROFILING)
569                 case MALI_IOC_PROFILING_START:
570                         err = profiling_start_wrapper(session_data, (_mali_uk_profiling_start_s __user *)arg);
571                         break;
572
573                 case MALI_IOC_PROFILING_ADD_EVENT:
574                         err = profiling_add_event_wrapper(session_data, (_mali_uk_profiling_add_event_s __user *)arg);
575                         break;
576
577                 case MALI_IOC_PROFILING_STOP:
578                         err = profiling_stop_wrapper(session_data, (_mali_uk_profiling_stop_s __user *)arg);
579                         break;
580
581                 case MALI_IOC_PROFILING_GET_EVENT:
582                         err = profiling_get_event_wrapper(session_data, (_mali_uk_profiling_get_event_s __user *)arg);
583                         break;
584
585                 case MALI_IOC_PROFILING_CLEAR:
586                         err = profiling_clear_wrapper(session_data, (_mali_uk_profiling_clear_s __user *)arg);
587                         break;
588
589                 case MALI_IOC_PROFILING_GET_CONFIG:
590                         /* Deprecated: still compatible with get_user_settings */
591                         err = get_user_settings_wrapper(session_data, (_mali_uk_get_user_settings_s __user *)arg);
592                         break;
593
594                 case MALI_IOC_PROFILING_REPORT_SW_COUNTERS:
595                         err = profiling_report_sw_counters_wrapper(session_data, (_mali_uk_sw_counters_report_s __user *)arg);
596                         break;
597
598 #else
599
600                 case MALI_IOC_PROFILING_START:              /* FALL-THROUGH */
601                 case MALI_IOC_PROFILING_ADD_EVENT:          /* FALL-THROUGH */
602                 case MALI_IOC_PROFILING_STOP:               /* FALL-THROUGH */
603                 case MALI_IOC_PROFILING_GET_EVENT:          /* FALL-THROUGH */
604                 case MALI_IOC_PROFILING_CLEAR:              /* FALL-THROUGH */
605                 case MALI_IOC_PROFILING_GET_CONFIG:         /* FALL-THROUGH */
606                 case MALI_IOC_PROFILING_REPORT_SW_COUNTERS: /* FALL-THROUGH */
607                         MALI_DEBUG_PRINT(2, ("Profiling not supported\n"));
608                         err = -ENOTTY;
609                         break;
610
611 #endif
612
613                 case MALI_IOC_MEM_INIT:
614                         err = mem_init_wrapper(session_data, (_mali_uk_init_mem_s __user *)arg);
615                         break;
616
617                 case MALI_IOC_MEM_TERM:
618                         err = mem_term_wrapper(session_data, (_mali_uk_term_mem_s __user *)arg);
619                         break;
620
621                 case MALI_IOC_MEM_MAP_EXT:
622                         err = mem_map_ext_wrapper(session_data, (_mali_uk_map_external_mem_s __user *)arg);
623                         break;
624
625                 case MALI_IOC_MEM_UNMAP_EXT:
626                         err = mem_unmap_ext_wrapper(session_data, (_mali_uk_unmap_external_mem_s __user *)arg);
627                         break;
628
629                 case MALI_IOC_MEM_QUERY_MMU_PAGE_TABLE_DUMP_SIZE:
630                         err = mem_query_mmu_page_table_dump_size_wrapper(session_data, (_mali_uk_query_mmu_page_table_dump_size_s __user *)arg);
631                         break;
632
633                 case MALI_IOC_MEM_DUMP_MMU_PAGE_TABLE:
634                         err = mem_dump_mmu_page_table_wrapper(session_data, (_mali_uk_dump_mmu_page_table_s __user *)arg);
635                         break;
636
637 #if defined(CONFIG_MALI400_UMP)
638
639                 case MALI_IOC_MEM_ATTACH_UMP:
640                         err = mem_attach_ump_wrapper(session_data, (_mali_uk_attach_ump_mem_s __user *)arg);
641                         break;
642
643                 case MALI_IOC_MEM_RELEASE_UMP:
644                         err = mem_release_ump_wrapper(session_data, (_mali_uk_release_ump_mem_s __user *)arg);
645                         break;
646
647 #else
648
649                 case MALI_IOC_MEM_ATTACH_UMP:
650                 case MALI_IOC_MEM_RELEASE_UMP: /* FALL-THROUGH */
651                         MALI_DEBUG_PRINT(2, ("UMP not supported\n"));
652                         err = -ENOTTY;
653                         break;
654 #endif
655
656 #ifdef CONFIG_DMA_SHARED_BUFFER
657                 case MALI_IOC_MEM_ATTACH_DMA_BUF:
658                         err = mali_attach_dma_buf(session_data, (_mali_uk_attach_dma_buf_s __user *)arg);
659                         break;
660
661                 case MALI_IOC_MEM_RELEASE_DMA_BUF:
662                         err = mali_release_dma_buf(session_data, (_mali_uk_release_dma_buf_s __user *)arg);
663                         break;
664
665                 case MALI_IOC_MEM_DMA_BUF_GET_SIZE:
666                         err = mali_dma_buf_get_size(session_data, (_mali_uk_dma_buf_get_size_s __user *)arg);
667                         break;
668 #else
669
670                 case MALI_IOC_MEM_ATTACH_DMA_BUF:   /* FALL-THROUGH */
671                 case MALI_IOC_MEM_RELEASE_DMA_BUF:  /* FALL-THROUGH */
672                 case MALI_IOC_MEM_DMA_BUF_GET_SIZE: /* FALL-THROUGH */
673                         MALI_DEBUG_PRINT(2, ("DMA-BUF not supported\n"));
674                         err = -ENOTTY;
675                         break;
676 #endif
677
678                 case MALI_IOC_PP_START_JOB:
679                         err = pp_start_job_wrapper(session_data, (_mali_uk_pp_start_job_s __user *)arg);
680                         break;
681
682                 case MALI_IOC_PP_NUMBER_OF_CORES_GET:
683                         err = pp_get_number_of_cores_wrapper(session_data, (_mali_uk_get_pp_number_of_cores_s __user *)arg);
684                         break;
685
686                 case MALI_IOC_PP_CORE_VERSION_GET:
687                         err = pp_get_core_version_wrapper(session_data, (_mali_uk_get_pp_core_version_s __user *)arg);
688                         break;
689
690                 case MALI_IOC_PP_DISABLE_WB:
691                         err = pp_disable_wb_wrapper(session_data, (_mali_uk_pp_disable_wb_s __user *)arg);
692                         break;
693
694                 case MALI_IOC_GP2_START_JOB:
695                         err = gp_start_job_wrapper(session_data, (_mali_uk_gp_start_job_s __user *)arg);
696                         break;
697
698                 case MALI_IOC_GP2_NUMBER_OF_CORES_GET:
699                         err = gp_get_number_of_cores_wrapper(session_data, (_mali_uk_get_gp_number_of_cores_s __user *)arg);
700                         break;
701
702                 case MALI_IOC_GP2_CORE_VERSION_GET:
703                         err = gp_get_core_version_wrapper(session_data, (_mali_uk_get_gp_core_version_s __user *)arg);
704                         break;
705
706                 case MALI_IOC_GP2_SUSPEND_RESPONSE:
707                         err = gp_suspend_response_wrapper(session_data, (_mali_uk_gp_suspend_response_s __user *)arg);
708                         break;
709
710                 case MALI_IOC_VSYNC_EVENT_REPORT:
711                         err = vsync_event_report_wrapper(session_data, (_mali_uk_vsync_event_report_s __user *)arg);
712                         break;
713
714                 case MALI_IOC_STREAM_CREATE:
715 #if defined(CONFIG_SYNC)
716 /* MALI_SEC */
717 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
718                         err = stream_create_wrapper(session_data, (_mali_uk_stream_create_s __user *)arg);
719 #else
720                         err = -ENOTTY;
721 #endif
722                         break;
723 #endif
724                 case MALI_IOC_FENCE_VALIDATE:
725 #if defined(CONFIG_SYNC)
726 /* MALI_SEC */
727 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
728                         err = sync_fence_validate_wrapper(session_data, (_mali_uk_fence_validate_s __user *)arg);
729 #else
730                         MALI_DEBUG_PRINT(2, ("Sync objects not supported\n"));
731                         err = -ENOTTY;
732 #endif
733                         break;
734 #else
735                         MALI_DEBUG_PRINT(2, ("Sync objects not supported\n"));
736                         err = -ENOTTY;
737                         break;
738 #endif
739
740                 case MALI_IOC_MEM_GET_BIG_BLOCK: /* Fallthrough */
741                 case MALI_IOC_MEM_FREE_BIG_BLOCK:
742                         MALI_PRINT_ERROR(("Non-MMU mode is no longer supported.\n"));
743                         err = -ENOTTY;
744                         break;
745
746                 default:
747                         MALI_DEBUG_PRINT(2, ("No handler for ioctl 0x%08X 0x%08lX\n", cmd, arg));
748                         err = -ENOTTY;
749         };
750
751         return err;
752 }
753
754
755 module_init(mali_module_init);
756 module_exit(mali_module_exit);
757
758 MODULE_LICENSE(MALI_KERNEL_LINUX_LICENSE);
759 MODULE_AUTHOR("ARM Ltd.");
760 MODULE_VERSION(SVN_REV_STRING);