Removed multiple buffer functionality
[kernel/swap-modules.git] / driver / device_driver.c
1 ////////////////////////////////////////////////////////////////////////////////////
2 //
3 //      FILE:           device_driver.c
4 //
5 //      DESCRIPTION:
6 //      This file is C source for SWAP driver.
7 //
8 //      SEE ALSO:       device_driver.h
9 //      AUTHOR:         L.Komkov, S.Dianov, S.Grekhov, A.Gerenkov
10 //      COMPANY NAME:   Samsung Research Center in Moscow
11 //      DEPT NAME:      Advanced Software Group 
12 //      CREATED:        2008.02.15
13 //      VERSION:        1.0
14 //      REVISION DATE:  2008.12.03
15 //
16 ////////////////////////////////////////////////////////////////////////////////////
17
18 #include "module.h"
19 #include "device_driver.h"      // device driver
20 #include "handlers_core.h"
21 #include <linux/notifier.h>
22
23 #ifdef OVERHEAD_DEBUG
24 extern unsigned long swap_sum_time;
25 extern unsigned long swap_sum_hit;
26 #endif
27
28 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
29 static BLOCKING_NOTIFIER_HEAD(swap_notifier_list);
30 #endif
31 pid_t gl_nNotifyTgid;
32 EXPORT_SYMBOL_GPL(gl_nNotifyTgid);
33
34 DECLARE_WAIT_QUEUE_HEAD (notification_waiters_queue);
35 volatile unsigned notification_count;
36
37 static int device_mmap (struct file *filp, struct vm_area_struct *vma);
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
39 static int device_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
40 #else
41 static long device_ioctl (struct file *file, unsigned int cmd, unsigned long arg);
42 #endif
43 static int device_open(struct inode *, struct file *);
44 static int device_release(struct inode *, struct file *);
45 static ssize_t device_read(struct file *, char *, size_t, loff_t *);
46 static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
47
48 static int gl_nDeviceOpened = 0;
49 static struct file_operations device_fops = {
50         .owner = THIS_MODULE,
51         .mmap = device_mmap,
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
53         .ioctl = device_ioctl,
54 #else
55         .unlocked_ioctl = device_ioctl,
56 #endif
57         .read = device_read,
58         .write = device_write,
59         .open = device_open,
60         .release = device_release
61 };
62
63 typedef void (* dbi_module_callback)();
64
65 int device_init (void)
66 {
67         int nReserved = 0;
68         int nRetVal = register_chrdev(device_major, device_name, &device_fops);
69         if (nRetVal < 0) {
70                 EPRINTF("Cannot register character device! [%s, %d]", device_name, device_major);
71                 nReserved = register_chrdev(0, device_name, &device_fops);
72                 if(nReserved >= 0)
73                 {
74                         unregister_chrdev(nReserved, device_name);
75                         EPRINTF("Please, create a new device node with major number [%d],\n\tand pass it as module parameter!", nReserved);
76                 }
77                 return -1;
78         } else if(nRetVal > 0) {
79                 EPRINTF("Cannot register this device major number! [%d]\n\tTrying a new one. [%d]", device_major, nRetVal);
80                 device_major = nRetVal;
81         }
82         return 0;
83 }
84
85 void device_down (void)
86 {
87         unregister_chrdev(device_major, device_name);
88 }
89
90 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
91 void swap_register_notify (struct notifier_block *nb)
92 {
93         blocking_notifier_chain_register(&swap_notifier_list, nb);
94 }
95 EXPORT_SYMBOL_GPL(swap_register_notify);
96
97 void swap_unregister_notify (struct notifier_block *nb)
98 {
99         blocking_notifier_chain_unregister(&swap_notifier_list, nb);
100 }
101 EXPORT_SYMBOL_GPL(swap_unregister_notify);
102 #endif
103
104 void notify_user (event_id_t event_id)
105 {
106         ec_info.events_counters[event_id] += 1;
107
108         if (EVENT_EC_PROBE_RECORD == event_id)
109         {
110                 // EC_PROBE_RECORD events happen to often. To reduce overhead user
111                 // space will be notified only once per each EVENTS_AGGREGATION_USEC
112                 static uint64_t timestamp_usec = 0;
113
114                 uint64_t current_usec;
115                 uint64_t delta_usec;
116
117                 struct timeval tv;
118
119                 do_gettimeofday (&tv);
120                 current_usec = 1000000ULL * (unsigned) tv.tv_sec + (unsigned) tv.tv_usec;
121
122                 if (current_usec < timestamp_usec)
123                 {
124                         // Note: time from do_gettimeofday() may go backward
125                         EPRINTF ("current_usec=%llu timestamp_usec=%llu", current_usec, timestamp_usec);
126                 }
127                 else
128                 {
129                         delta_usec = current_usec - timestamp_usec;
130                         if (EVENTS_AGGREGATION_USEC > delta_usec)
131                         {
132                                 // wait the time left
133 #if defined(__DEBUG)
134                                 unsigned UNUSED left_usec = EVENTS_AGGREGATION_USEC - delta_usec;
135 #endif /* defined(__DEBUG) */
136                                 return; // supress notification
137                         }
138                 }
139                 timestamp_usec = current_usec;  // remember new time for the future use
140         } else if (EVENT_EC_START_CONDITION_SEEN == event_id) {
141                 return;         // supress notification
142         } else if (EVENT_EC_STOP_CONDITION_SEEN == event_id) {
143                 return;         // supress notification
144         }
145
146         ++notification_count;
147         wake_up_interruptible (&notification_waiters_queue);
148 }
149
150 static int device_mmap (struct file *filp UNUSED, struct vm_area_struct *vma)
151 {
152         if(!p_buffer) {
153                 EPRINTF("Null pointer to buffer!");
154                 return -1;
155         }
156         return remap_vmalloc_range (vma, p_buffer, 0);
157 }
158
159 static int device_open(struct inode *inode, struct file *file)
160 {
161         /*if (gl_nDeviceOpened)
162                 return -EBUSY;*/
163         gl_nDeviceOpened++;
164         // TODO
165         try_module_get(THIS_MODULE);
166         return 0;
167 }
168  
169 static int device_release(struct inode *inode, struct file *file)
170 {
171         gl_nDeviceOpened--;
172         module_put(THIS_MODULE);
173         return 0;
174 }
175  
176 static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t * offset)
177 {
178         EPRINTF("Operation <<read>> not supported!");
179         return -1;
180 }
181  
182 static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
183 {
184         EPRINTF("Operation <<write>> not supported!");
185         return -1;
186 }
187
188 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
189 static int device_ioctl (struct inode *inode UNUSED, struct file *file UNUSED, unsigned int cmd, unsigned long arg)
190 #else
191 static long device_ioctl (struct file *file UNUSED, unsigned int cmd, unsigned long arg)
192 #endif
193 {
194         unsigned long spinlock_flags = 0L;
195         int result = -1;
196 //      DPRINTF("Command=%d", cmd);
197         switch (cmd)
198         {
199         case EC_IOCTL_SET_EC_MODE:
200                 {
201                         ioctl_general_t param;
202                         unsigned long nIgnoredBytes = 0;
203                         memset(&param, '0', sizeof(ioctl_general_t));
204                         nIgnoredBytes = copy_from_user (&param, (void*)arg, sizeof(ioctl_general_t));
205                         if (nIgnoredBytes > 0) {
206                                 result = -1;
207                                 break;
208                         }
209                         if(SetECMode(param.m_unsignedLong) == -1) {
210                                 result = -1;
211                                 break;
212                         }
213                         result = 0;
214                         DPRINTF("Set EC Mode = %lu", param.m_unsignedLong);
215                         break;
216                 }
217         case EC_IOCTL_GET_EC_MODE:
218                 {
219                         ioctl_general_t param;
220                         unsigned long nIgnoredBytes = 0;
221                         memset(&param, '0', sizeof(ioctl_general_t));
222                         param.m_unsignedLong = GetECMode();
223                         nIgnoredBytes = copy_to_user ((void*)arg, &param, sizeof (ioctl_general_t));
224                         if (nIgnoredBytes > 0) {
225                                 result = -1;
226                                 break;
227                         }
228                         result = 0;
229 //                      DPRINTF("Get EC Mode = %lu", param.m_unsignedLong);  // Frequent call
230                         break;
231                 }
232         case EC_IOCTL_SET_BUFFER_SIZE:
233                 {
234                         ioctl_general_t param;
235                         unsigned long nIgnoredBytes = 0;
236                         memset(&param, '0', sizeof(ioctl_general_t));
237                         nIgnoredBytes = copy_from_user (&param, (void*)arg, sizeof(ioctl_general_t));
238                         if (nIgnoredBytes > 0) {
239                                 result = -1;
240                                 break;
241                         }
242                         if (SetBufferSize(param.m_unsignedLong) == -1) {
243                                 result = -1;
244                                 break;
245                         }
246                         result = 0;
247                         DPRINTF("Set Buffer Size = %lu", param.m_unsignedLong);
248                         break;
249                 }
250         case EC_IOCTL_GET_BUFFER_SIZE:
251                 {
252                         ioctl_general_t param;
253                         unsigned long nIgnoredBytes = 0;
254                         memset(&param, '0', sizeof(ioctl_general_t));
255                         param.m_unsignedLong = GetBufferSize();
256                         nIgnoredBytes = copy_to_user ((void*)arg, &param, sizeof (ioctl_general_t));
257                         if (nIgnoredBytes > 0) {
258                                 result = -1;
259                                 break;
260                         }
261                         result = 0;
262                         DPRINTF("Get Buffer Size = %lu", param.m_unsignedLong);
263                         break;
264                 }
265         case EC_IOCTL_RESET_BUFFER:
266                 {
267                         if (ResetBuffer() == -1) {
268                                 result = -1;
269                                 break;
270                         }
271                         result = 0;
272                         DPRINTF("Reset Buffer");
273                         break;
274                 }
275         case EC_IOCTL_GET_EC_INFO:
276                 {
277                         if (copy_ec_info_to_user_space ((ec_info_t *) arg) != 0) {
278                                 result = -1;
279                                 break;
280                         }
281                         result = 0;
282 //                      DPRINTF("Get Buffer Status"); // Frequent call
283                         break;
284                 }
285         case EC_IOCTL_CONSUME_BUFFER:
286                 {
287                         static ec_info_t ec_info_copy;
288                         int nIgnoredBytes = 0;
289
290                         nIgnoredBytes = copy_from_user (&ec_info_copy, (ec_info_t *) arg, sizeof (ec_info_t));
291                         if(nIgnoredBytes > 0)
292                         {
293                                 EPRINTF ("copy_from_user(%08X,%08X)=%d", (unsigned) arg, (unsigned) &ec_info_copy, nIgnoredBytes);
294                                 result = -1;
295                                 break;
296                         }
297
298                         spin_lock_irqsave (&ec_spinlock, spinlock_flags);
299
300                         // Original buffer
301                         if(ec_info.after_last > ec_info.first) {
302                                 ec_info.buffer_effect = ec_info.buffer_size;
303                         }
304                         if (ec_info.after_last == ec_info.buffer_effect) {
305                                  ec_info.first = 0;
306                         } else {
307                                  ec_info.first = ec_info_copy.after_last;
308                         }
309                         ec_info.trace_size = ec_info.trace_size - ec_info_copy.trace_size;
310
311                         spin_unlock_irqrestore (&ec_spinlock, spinlock_flags);
312                         result = 0;
313 //                      DPRINTF("Consume Buffer"); // Frequent call
314                         break;
315                 }
316         case EC_IOCTL_ADD_PROBE:
317                 {
318                         unsigned long addr = arg;
319                         result = add_probe(addr);
320
321                         break;
322                 }
323         //@AGv: remove_probe expects probe address instead of name
324         /*case EC_IOCTL_REMOVE_PROBE:
325                 {
326                         char *probe_name = (char *) arg;
327                         result = remove_probe (probe_name);
328
329                         break;
330                 }*/
331         case EC_IOCTL_SET_APPDEPS:
332         {
333                 size_t size;
334                 result = copy_from_user(&size, (void *)arg, sizeof(size_t));
335                 if (result) {
336                         EPRINTF("Cannot copy deps size!");
337                         result = -1;
338                         break;
339                 }
340                 DPRINTF("Deps size has been copied (%d)", size);
341
342                 if (size == 0) {
343                         DPRINTF("Deps are size of 0");
344                         break;
345                 }
346
347                 deps = vmalloc(size);
348                 if (deps == NULL) {
349                         EPRINTF("Cannot alloc mem for deps!");
350                         result = -1;
351                         break;
352                 }
353                 DPRINTF("Mem for deps has been allocated");
354
355                 result = copy_from_user(deps, (void *)arg, size);
356                 if (result) {
357                         EPRINTF("Cannot copy deps!");
358                         result = -1;
359                         break;
360                 }
361                 DPRINTF("Deps has been copied successfully");
362
363                 break;
364         }
365         case EC_IOCTL_SET_PID:
366         {
367                 unsigned int _pid;
368
369                 result = copy_from_user(&_pid, (void *)arg, sizeof(unsigned int));
370                 if (result) {
371                         EPRINTF("Cannot copy pid!");
372                         result = -1;
373                         break;
374                 }
375
376                 inst_pid = _pid;
377
378                 DPRINTF("EC_IOCTL_SET_PID pid:%d", inst_pid);
379
380                 break;
381         }
382         case EC_IOCTL_SET_PROFILEBUNDLE:
383         {
384                 size_t size;
385
386                 result = copy_from_user(&size, (void *)arg, sizeof(size_t));
387                 if (result) {
388                         EPRINTF("Cannot copy bundle size!");
389                         result = -1;
390                         break;
391                 }
392                 DPRINTF("Bundle size has been copied");
393
394                 bundle = vmalloc(size);
395                 if (bundle == NULL) {
396                         EPRINTF("Cannot alloc mem for bundle!");
397                         result = -1;
398                         break;
399                 }
400                 DPRINTF("Mem for bundle has been alloced");
401
402                 result = copy_from_user(bundle, (void *)arg, size);
403                 if (result) {
404                         EPRINTF("Cannot copy bundle!");
405                         result = -1;
406                         break;
407                 }
408                 DPRINTF("Bundle has been copied successfully");
409
410                 if (link_bundle() == -1) {
411                         EPRINTF("Cannot link profile bundle!");
412                         result = -1;
413                         break;
414                 }
415
416                 break;
417         }
418         case EC_IOCTL_RESET_PROBES:
419                 {
420                         result = reset_probes();
421
422                         break;
423                 }
424         case EC_IOCTL_UPDATE_CONDS:
425                 {
426                         int args_cnt, i;
427                         struct cond *c, *c_tmp, *p_cond;
428                         unsigned char *p_data;
429                         int err;
430                         result = 0;
431                         err = copy_from_user(&args_cnt, (void *)arg, sizeof(int));
432                         if (err) {
433                                 result = -1;
434                                 break;
435                         }
436                         /* first, delete all the conds */
437                         list_for_each_entry_safe(c, c_tmp, &cond_list.list, list) {
438                                 list_del(&c->list);
439                                 kfree(c);
440                         }
441                         /* second, add new conds */
442                         p_data = (unsigned char *)(arg + sizeof(int));
443                         for (i = 0; i < args_cnt; i++) {
444                                 p_cond = kmalloc(sizeof(struct cond), GFP_KERNEL);
445                                 if (!p_cond) {
446                                         DPRINTF("Cannot alloc cond!");
447                                         result = -1;
448                                         break;
449                                 }
450                                 err = copy_from_user(&p_cond->tmpl, p_data, sizeof(struct event_tmpl));
451                                 if (err) {
452                                         DPRINTF("Cannot copy cond from user!");
453                                         result = -1;
454                                         break;
455                                 }
456                                 p_cond->applied = 0;
457                                 list_add(&(p_cond->list), &(cond_list.list));
458                                 p_data += sizeof(struct event_tmpl);
459                         }
460                         break;
461                 }
462         case EC_IOCTL_ATTACH:
463                 {
464                         unsigned long dbi_flags;
465                         struct dbi_modules_handlers *local_mh;
466                         struct dbi_modules_handlers_info *local_mhi;
467                         int j;
468                         dbi_module_callback dmc_start;
469
470                         // call "start"-callback for all modules according module priority
471                         local_mh = get_dbi_modules_handlers();
472                         spin_lock_irqsave(&local_mh->lock, dbi_flags);
473                         for (j = 0; j <= MAX_PRIORITY; j++) {
474                                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
475                                         if (local_mhi->dbi_module_priority_start == j) {
476                                                 if (local_mhi->dbi_module_callback_start != NULL) {
477                                                         printk("Started module callback (start) %s\n", local_mhi->dbi_module->name);
478                                                         dmc_start = (dbi_module_callback )local_mhi->dbi_module_callback_start;
479                                                         dmc_start();
480                                                 }
481                                         }
482                                 }
483                         }
484                         spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
485
486                         result = ec_user_attach ();
487 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
488                         DPRINTF("EC_IOCTL_ATTACH calling notification chain");
489                         blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_ATTACH, (void*)NULL);
490 #endif
491                         DPRINTF("Attach Probes");
492                         break;
493                 }
494         case EC_IOCTL_ACTIVATE:
495                 result = ec_user_activate ();
496                 DPRINTF("Activate Probes");
497                 break;
498         case EC_IOCTL_STOP_AND_DETACH:
499         {
500                 unsigned long nIgnoredBytes = 0;
501                 unsigned long dbi_flags;
502                 struct dbi_modules_handlers *local_mh;
503                 struct dbi_modules_handlers_info *local_mhi;
504                 unsigned int local_module_refcount = 0;
505                 int j;
506                 dbi_module_callback dmc_stop;
507
508 #ifdef OVERHEAD_DEBUG
509                 printk("\nswap_sum_time = %ld in kprobe_handler()\n", swap_sum_time);
510                 printk("swap_sum_hit = %ld in kprobe_handler()\n", swap_sum_hit);
511                 swap_sum_time = 0;
512                 swap_sum_hit = 0;
513 #endif
514                 local_mh = get_dbi_modules_handlers();
515                 if(ec_user_stop() != 0) {
516                         result = -1;
517                         goto sad_cleanup;
518                 }
519                 nIgnoredBytes = copy_ec_info_to_user_space ((ec_info_t*)arg);
520                 if(nIgnoredBytes > 0) {
521                         result = -1;
522                         goto sad_cleanup;
523                 }
524                 vfree(bundle);
525                 result = 0;
526                 DPRINTF("Stop and Detach Probes");
527 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
528                 DPRINTF("EC_IOCTL_STOP_AND_DETACH calling notification chain");
529                 blocking_notifier_call_chain(&swap_notifier_list, EC_IOCTL_STOP_AND_DETACH, (void*)&gl_nNotifyTgid);
530 #endif
531                 // call "stop"-callback for all modules according module priority
532                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
533                 for (j = 0; j <= MAX_PRIORITY; j++) {
534                         list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
535                                 if (local_mhi->dbi_module_priority_stop == j) {
536                                         if (local_mhi->dbi_module_callback_stop != NULL) {
537                                                 printk("Started module callback (stop) %s\n", local_mhi->dbi_module->name);
538                                                 dmc_stop = (dbi_module_callback )local_mhi->dbi_module_callback_stop;
539                                                 dmc_stop();
540                                         }
541                                 }
542                         }
543                 }
544                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
545 sad_cleanup:
546                 spin_lock_irqsave(&local_mh->lock, dbi_flags);
547                 list_for_each_entry_rcu(local_mhi, &local_mh->modules_handlers, dbi_list_head) {
548                         local_module_refcount = module_refcount(local_mhi->dbi_module);
549                         if (local_module_refcount == 1) {
550                                 module_put(local_mhi->dbi_module);
551                         }
552                         else if (local_module_refcount > 1) {
553                                 printk("local_module_refcount too much - force set refcount to zero\n");
554                                 while (local_module_refcount--)
555                                         module_put(local_mhi->dbi_module);
556                         }
557                 }
558                 spin_unlock_irqrestore(&local_mh->lock, dbi_flags);
559                 break;
560         }
561         case EC_IOCTL_WAIT_NOTIFICATION:
562                 {
563                         static ec_info_t ec_info_copy;
564
565                         ioctl_wait_notification_t ioctl_args;
566
567                         result = copy_from_user (&ioctl_args, (void *) arg, sizeof (ioctl_args));
568                         if (result)
569                         {
570                                 result = -1;
571                                 break;
572                         }
573
574                         result = wait_event_interruptible (notification_waiters_queue, ioctl_args.notification_count != notification_count);
575                         if (result)
576                         {
577                                 result = -EINTR;        // woken by signal (ERESTARTSYS 512)
578                                 break;
579                         }
580
581                         ioctl_args.notification_count = notification_count;
582
583                         result = copy_to_user ((void *) arg, &ioctl_args, sizeof (ioctl_args));
584                         if (result)
585                         {
586                                 result = -1;
587                                 break;
588                         }
589
590                         // FIXME: synchronization is necessary here (ec_info must be locked).
591                         // ENTER_CRITICAL_SECTION
592                         memcpy (&ec_info_copy, &ec_info, sizeof (ec_info_copy));
593                         // LEAVE_CRITICAL_SECTION
594
595                         result = copy_to_user ((void *) ioctl_args.p_ec_info, &ec_info_copy, sizeof (ec_info_t));
596                         if (result)
597                         {
598                                 EPRINTF ("copy_to_user(%08X,%08X)=%d", (unsigned) ioctl_args.p_ec_info, (unsigned) &ec_info_copy, result);
599                                 result = -1;
600                                 break;
601                         }
602                         DPRINTF("Wake up");
603                         break;
604                 }
605         case EC_IOCTL_US_EVENT:
606                 {
607                         ioctl_us_event_t ioctl_args;
608                         result = copy_from_user (&ioctl_args, (void *) arg, sizeof (ioctl_args));
609                         if (result)
610                         {
611                                 result = -1;
612                                 EPRINTF ("copy_from_user() failure");
613                         }
614                         else
615                         {
616                                 if(ioctl_args.len == 0){
617                                         result = -EINVAL;
618                                         EPRINTF ("invalid event length!");                                      
619                                 }
620                                 else {
621                                         char *buf = kmalloc(ioctl_args.len, GFP_KERNEL);
622                                         if(!buf){
623                                                 result = -ENOMEM;
624                                                 EPRINTF ("failed to alloc mem for event!");                                     
625                                         }
626                                         else {
627                                                 result = copy_from_user (buf, (void *) ioctl_args.data, ioctl_args.len);
628                                                 if (result){
629                                                         result = -1;
630                                                         EPRINTF ("failed to copy event from user space!");
631                                                 }
632                                                 else
633                                                         result = put_us_event(buf, ioctl_args.len);
634                                                 kfree(buf);
635                                         }
636                                 }
637                         }
638 //                      DPRINTF("User Space Event"); // Frequent call
639                         break;
640                 }
641                 
642         case EC_IOCTL_SET_EVENT_MASK:
643                 {
644                         int mask;
645                         result = copy_from_user (&mask, (void *) arg, sizeof (mask));
646                         if (result)
647                         {
648                                 result = -EFAULT;
649                                 break;
650                         }
651
652                         result = set_event_mask (mask);
653                         if (result)
654                         {
655                                 break;
656                         }
657                         DPRINTF("Set Event Mask = %d", mask);
658                         break;
659                 }
660
661         case EC_IOCTL_GET_EVENT_MASK:
662                 {
663                         int mask = 0;
664                         result = get_event_mask(&mask);
665                         if (result)
666                         {
667                                 result = -EFAULT;
668                         }
669                         result = copy_to_user ((void *) arg, &mask, sizeof (mask));
670                         if (result)
671                         {
672                                 result = -EFAULT;
673                         }
674                         DPRINTF("Get Event Mask = %d", mask);
675                         break;
676                 }
677
678         case EC_IOCTL_SET_PREDEF_UPROBES:
679                 {
680                         ioctl_predef_uprobes_info_t data;
681                         result = copy_from_user (&data, (void *) arg, sizeof (data));
682                         if (result)
683                         {
684                                 result = -EFAULT;
685                                 break;
686                         }
687
688                         result = set_predef_uprobes (&data);
689                         if (result)
690                         {
691                                 break;
692                         }
693                         DPRINTF("Set Predefined User Space Probes");
694                         break;
695                 }
696                 
697         case EC_IOCTL_GET_PREDEF_UPROBES:
698                 {
699                         result = get_predef_uprobes((ioctl_predef_uprobes_info_t *)arg);
700                         if (result)
701                         {
702                                 result = -EFAULT;
703                         }
704                         DPRINTF("Get Predefined User Space Probes");
705                         break;
706                 }
707                 
708         case EC_IOCTL_GET_PREDEF_UPROBES_SIZE:
709                 {
710                         int size = 0;
711                         result = get_predef_uprobes_size(&size);
712                         if (result)
713                         {
714                                 result = -EFAULT;
715                         }
716                         result = copy_to_user ((void *) arg, &size, sizeof (size));
717                         if (result)
718                         {
719                                 result = -EFAULT;
720                         }
721                         DPRINTF("Get Size of Predefined User Space Probes");
722                         break;
723                 }
724         
725         default:
726                 EPRINTF ("Unknown driver command = %u", cmd);
727                 result = -EINVAL;
728                 break;
729         }
730
731         return result;
732 }