]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - arch/sparc64/kernel/sys_sparc.c
Linux-2.6.12-rc2
[sojka/nv-tegra/linux-3.10.git] / arch / sparc64 / kernel / sys_sparc.c
1 /* $Id: sys_sparc.c,v 1.57 2002/02/09 19:49:30 davem Exp $
2  * linux/arch/sparc64/kernel/sys_sparc.c
3  *
4  * This file contains various random system calls that
5  * have a non-standard calling sequence on the Linux/sparc
6  * platform.
7  */
8
9 #include <linux/config.h>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/sched.h>
13 #include <linux/fs.h>
14 #include <linux/file.h>
15 #include <linux/mm.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/utsname.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/slab.h>
25 #include <linux/syscalls.h>
26 #include <linux/ipc.h>
27 #include <linux/personality.h>
28
29 #include <asm/uaccess.h>
30 #include <asm/ipc.h>
31 #include <asm/utrap.h>
32 #include <asm/perfctr.h>
33
34 /* #define DEBUG_UNIMP_SYSCALL */
35
36 /* XXX Make this per-binary type, this way we can detect the type of
37  * XXX a binary.  Every Sparc executable calls this very early on.
38  */
39 asmlinkage unsigned long sys_getpagesize(void)
40 {
41         return PAGE_SIZE;
42 }
43
44 #define COLOUR_ALIGN(addr,pgoff)                \
45         ((((addr)+SHMLBA-1)&~(SHMLBA-1)) +      \
46          (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
47
48 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
49 {
50         struct mm_struct *mm = current->mm;
51         struct vm_area_struct * vma;
52         unsigned long task_size = TASK_SIZE;
53         unsigned long start_addr;
54         int do_color_align;
55
56         if (flags & MAP_FIXED) {
57                 /* We do not accept a shared mapping if it would violate
58                  * cache aliasing constraints.
59                  */
60                 if ((flags & MAP_SHARED) &&
61                     ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
62                         return -EINVAL;
63                 return addr;
64         }
65
66         if (test_thread_flag(TIF_32BIT))
67                 task_size = 0xf0000000UL;
68         if (len > task_size || len > -PAGE_OFFSET)
69                 return -ENOMEM;
70
71         do_color_align = 0;
72         if (filp || (flags & MAP_SHARED))
73                 do_color_align = 1;
74
75         if (addr) {
76                 if (do_color_align)
77                         addr = COLOUR_ALIGN(addr, pgoff);
78                 else
79                         addr = PAGE_ALIGN(addr);
80
81                 vma = find_vma(mm, addr);
82                 if (task_size - len >= addr &&
83                     (!vma || addr + len <= vma->vm_start))
84                         return addr;
85         }
86
87         start_addr = addr = mm->free_area_cache;
88
89         task_size -= len;
90
91 full_search:
92         if (do_color_align)
93                 addr = COLOUR_ALIGN(addr, pgoff);
94         else
95                 addr = PAGE_ALIGN(addr);
96
97         for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
98                 /* At this point:  (!vma || addr < vma->vm_end). */
99                 if (addr < PAGE_OFFSET && -PAGE_OFFSET - len < addr) {
100                         addr = PAGE_OFFSET;
101                         vma = find_vma(mm, PAGE_OFFSET);
102                 }
103                 if (task_size < addr) {
104                         if (start_addr != TASK_UNMAPPED_BASE) {
105                                 start_addr = addr = TASK_UNMAPPED_BASE;
106                                 goto full_search;
107                         }
108                         return -ENOMEM;
109                 }
110                 if (!vma || addr + len <= vma->vm_start) {
111                         /*
112                          * Remember the place where we stopped the search:
113                          */
114                         mm->free_area_cache = addr + len;
115                         return addr;
116                 }
117                 addr = vma->vm_end;
118                 if (do_color_align)
119                         addr = COLOUR_ALIGN(addr, pgoff);
120         }
121 }
122
123 /* Try to align mapping such that we align it as much as possible. */
124 unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
125 {
126         unsigned long align_goal, addr = -ENOMEM;
127
128         if (flags & MAP_FIXED) {
129                 /* Ok, don't mess with it. */
130                 return get_unmapped_area(NULL, addr, len, pgoff, flags);
131         }
132         flags &= ~MAP_SHARED;
133
134         align_goal = PAGE_SIZE;
135         if (len >= (4UL * 1024 * 1024))
136                 align_goal = (4UL * 1024 * 1024);
137         else if (len >= (512UL * 1024))
138                 align_goal = (512UL * 1024);
139         else if (len >= (64UL * 1024))
140                 align_goal = (64UL * 1024);
141
142         do {
143                 addr = get_unmapped_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags);
144                 if (!(addr & ~PAGE_MASK)) {
145                         addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
146                         break;
147                 }
148
149                 if (align_goal == (4UL * 1024 * 1024))
150                         align_goal = (512UL * 1024);
151                 else if (align_goal == (512UL * 1024))
152                         align_goal = (64UL * 1024);
153                 else
154                         align_goal = PAGE_SIZE;
155         } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
156
157         /* Mapping is smaller than 64K or larger areas could not
158          * be obtained.
159          */
160         if (addr & ~PAGE_MASK)
161                 addr = get_unmapped_area(NULL, orig_addr, len, pgoff, flags);
162
163         return addr;
164 }
165
166 asmlinkage unsigned long sparc_brk(unsigned long brk)
167 {
168         /* People could try to be nasty and use ta 0x6d in 32bit programs */
169         if (test_thread_flag(TIF_32BIT) &&
170             brk >= 0xf0000000UL)
171                 return current->mm->brk;
172
173         if ((current->mm->brk & PAGE_OFFSET) != (brk & PAGE_OFFSET))
174                 return current->mm->brk;
175         return sys_brk(brk);
176 }
177                                                                 
178 /*
179  * sys_pipe() is the normal C calling standard for creating
180  * a pipe. It's not the way unix traditionally does this, though.
181  */
182 asmlinkage long sparc_pipe(struct pt_regs *regs)
183 {
184         int fd[2];
185         int error;
186
187         error = do_pipe(fd);
188         if (error)
189                 goto out;
190         regs->u_regs[UREG_I1] = fd[1];
191         error = fd[0];
192 out:
193         return error;
194 }
195
196 /*
197  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
198  *
199  * This is really horribly ugly.
200  */
201
202 asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
203                         unsigned long third, void __user *ptr, long fifth)
204 {
205         int err;
206
207         /* No need for backward compatibility. We can start fresh... */
208         if (call <= SEMCTL) {
209                 switch (call) {
210                 case SEMOP:
211                         err = sys_semtimedop(first, ptr,
212                                              (unsigned)second, NULL);
213                         goto out;
214                 case SEMTIMEDOP:
215                         err = sys_semtimedop(first, ptr, (unsigned)second,
216                                 (const struct timespec __user *) fifth);
217                         goto out;
218                 case SEMGET:
219                         err = sys_semget(first, (int)second, (int)third);
220                         goto out;
221                 case SEMCTL: {
222                         union semun fourth;
223                         err = -EINVAL;
224                         if (!ptr)
225                                 goto out;
226                         err = -EFAULT;
227                         if (get_user(fourth.__pad,
228                                      (void __user * __user *) ptr))
229                                 goto out;
230                         err = sys_semctl(first, (int)second | IPC_64,
231                                          (int)third, fourth);
232                         goto out;
233                 }
234                 default:
235                         err = -ENOSYS;
236                         goto out;
237                 };
238         }
239         if (call <= MSGCTL) {
240                 switch (call) {
241                 case MSGSND:
242                         err = sys_msgsnd(first, ptr, (size_t)second,
243                                          (int)third);
244                         goto out;
245                 case MSGRCV:
246                         err = sys_msgrcv(first, ptr, (size_t)second, fifth,
247                                          (int)third);
248                         goto out;
249                 case MSGGET:
250                         err = sys_msgget((key_t)first, (int)second);
251                         goto out;
252                 case MSGCTL:
253                         err = sys_msgctl(first, (int)second | IPC_64, ptr);
254                         goto out;
255                 default:
256                         err = -ENOSYS;
257                         goto out;
258                 };
259         }
260         if (call <= SHMCTL) {
261                 switch (call) {
262                 case SHMAT: {
263                         ulong raddr;
264                         err = do_shmat(first, ptr, (int)second, &raddr);
265                         if (!err) {
266                                 if (put_user(raddr,
267                                              (ulong __user *) third))
268                                         err = -EFAULT;
269                         }
270                         goto out;
271                 }
272                 case SHMDT:
273                         err = sys_shmdt(ptr);
274                         goto out;
275                 case SHMGET:
276                         err = sys_shmget(first, (size_t)second, (int)third);
277                         goto out;
278                 case SHMCTL:
279                         err = sys_shmctl(first, (int)second | IPC_64, ptr);
280                         goto out;
281                 default:
282                         err = -ENOSYS;
283                         goto out;
284                 };
285         } else {
286                 err = -ENOSYS;
287         }
288 out:
289         return err;
290 }
291
292 asmlinkage long sparc64_newuname(struct new_utsname __user *name)
293 {
294         int ret = sys_newuname(name);
295         
296         if (current->personality == PER_LINUX32 && !ret) {
297                 ret = (copy_to_user(name->machine, "sparc\0\0", 8)
298                        ? -EFAULT : 0);
299         }
300         return ret;
301 }
302
303 asmlinkage long sparc64_personality(unsigned long personality)
304 {
305         int ret;
306
307         if (current->personality == PER_LINUX32 &&
308             personality == PER_LINUX)
309                 personality = PER_LINUX32;
310         ret = sys_personality(personality);
311         if (ret == PER_LINUX32)
312                 ret = PER_LINUX;
313
314         return ret;
315 }
316
317 /* Linux version of mmap */
318 asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
319         unsigned long prot, unsigned long flags, unsigned long fd,
320         unsigned long off)
321 {
322         struct file * file = NULL;
323         unsigned long retval = -EBADF;
324
325         if (!(flags & MAP_ANONYMOUS)) {
326                 file = fget(fd);
327                 if (!file)
328                         goto out;
329         }
330         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
331         len = PAGE_ALIGN(len);
332         retval = -EINVAL;
333
334         if (test_thread_flag(TIF_32BIT)) {
335                 if (len > 0xf0000000UL ||
336                     ((flags & MAP_FIXED) && addr > 0xf0000000UL - len))
337                         goto out_putf;
338         } else {
339                 if (len > -PAGE_OFFSET ||
340                     ((flags & MAP_FIXED) &&
341                      addr < PAGE_OFFSET && addr + len > -PAGE_OFFSET))
342                         goto out_putf;
343         }
344
345         down_write(&current->mm->mmap_sem);
346         retval = do_mmap(file, addr, len, prot, flags, off);
347         up_write(&current->mm->mmap_sem);
348
349 out_putf:
350         if (file)
351                 fput(file);
352 out:
353         return retval;
354 }
355
356 asmlinkage long sys64_munmap(unsigned long addr, size_t len)
357 {
358         long ret;
359
360         if (len > -PAGE_OFFSET ||
361             (addr < PAGE_OFFSET && addr + len > -PAGE_OFFSET))
362                 return -EINVAL;
363         down_write(&current->mm->mmap_sem);
364         ret = do_munmap(current->mm, addr, len);
365         up_write(&current->mm->mmap_sem);
366         return ret;
367 }
368
369 extern unsigned long do_mremap(unsigned long addr,
370         unsigned long old_len, unsigned long new_len,
371         unsigned long flags, unsigned long new_addr);
372                 
373 asmlinkage unsigned long sys64_mremap(unsigned long addr,
374         unsigned long old_len, unsigned long new_len,
375         unsigned long flags, unsigned long new_addr)
376 {
377         struct vm_area_struct *vma;
378         unsigned long ret = -EINVAL;
379         if (test_thread_flag(TIF_32BIT))
380                 goto out;
381         if (old_len > -PAGE_OFFSET || new_len > -PAGE_OFFSET)
382                 goto out;
383         if (addr < PAGE_OFFSET && addr + old_len > -PAGE_OFFSET)
384                 goto out;
385         down_write(&current->mm->mmap_sem);
386         if (flags & MREMAP_FIXED) {
387                 if (new_addr < PAGE_OFFSET &&
388                     new_addr + new_len > -PAGE_OFFSET)
389                         goto out_sem;
390         } else if (addr < PAGE_OFFSET && addr + new_len > -PAGE_OFFSET) {
391                 unsigned long map_flags = 0;
392                 struct file *file = NULL;
393
394                 ret = -ENOMEM;
395                 if (!(flags & MREMAP_MAYMOVE))
396                         goto out_sem;
397
398                 vma = find_vma(current->mm, addr);
399                 if (vma) {
400                         if (vma->vm_flags & VM_SHARED)
401                                 map_flags |= MAP_SHARED;
402                         file = vma->vm_file;
403                 }
404
405                 /* MREMAP_FIXED checked above. */
406                 new_addr = get_unmapped_area(file, addr, new_len,
407                                     vma ? vma->vm_pgoff : 0,
408                                     map_flags);
409                 ret = new_addr;
410                 if (new_addr & ~PAGE_MASK)
411                         goto out_sem;
412                 flags |= MREMAP_FIXED;
413         }
414         ret = do_mremap(addr, old_len, new_len, flags, new_addr);
415 out_sem:
416         up_write(&current->mm->mmap_sem);
417 out:
418         return ret;       
419 }
420
421 /* we come to here via sys_nis_syscall so it can setup the regs argument */
422 asmlinkage unsigned long c_sys_nis_syscall(struct pt_regs *regs)
423 {
424         static int count;
425         
426         /* Don't make the system unusable, if someone goes stuck */
427         if (count++ > 5)
428                 return -ENOSYS;
429
430         printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
431 #ifdef DEBUG_UNIMP_SYSCALL      
432         show_regs (regs);
433 #endif
434
435         return -ENOSYS;
436 }
437
438 /* #define DEBUG_SPARC_BREAKPOINT */
439
440 asmlinkage void sparc_breakpoint(struct pt_regs *regs)
441 {
442         siginfo_t info;
443
444         if (test_thread_flag(TIF_32BIT)) {
445                 regs->tpc &= 0xffffffff;
446                 regs->tnpc &= 0xffffffff;
447         }
448 #ifdef DEBUG_SPARC_BREAKPOINT
449         printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
450 #endif
451         info.si_signo = SIGTRAP;
452         info.si_errno = 0;
453         info.si_code = TRAP_BRKPT;
454         info.si_addr = (void __user *)regs->tpc;
455         info.si_trapno = 0;
456         force_sig_info(SIGTRAP, &info, current);
457 #ifdef DEBUG_SPARC_BREAKPOINT
458         printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
459 #endif
460 }
461
462 extern void check_pending(int signum);
463
464 asmlinkage long sys_getdomainname(char __user *name, int len)
465 {
466         int nlen;
467         int err = -EFAULT;
468
469         down_read(&uts_sem);
470         
471         nlen = strlen(system_utsname.domainname) + 1;
472
473         if (nlen < len)
474                 len = nlen;
475         if (len > __NEW_UTS_LEN)
476                 goto done;
477         if (copy_to_user(name, system_utsname.domainname, len))
478                 goto done;
479         err = 0;
480 done:
481         up_read(&uts_sem);
482         return err;
483 }
484
485 asmlinkage long solaris_syscall(struct pt_regs *regs)
486 {
487         static int count;
488
489         regs->tpc = regs->tnpc;
490         regs->tnpc += 4;
491         if (test_thread_flag(TIF_32BIT)) {
492                 regs->tpc &= 0xffffffff;
493                 regs->tnpc &= 0xffffffff;
494         }
495         if (++count <= 5) {
496                 printk ("For Solaris binary emulation you need solaris module loaded\n");
497                 show_regs (regs);
498         }
499         send_sig(SIGSEGV, current, 1);
500
501         return -ENOSYS;
502 }
503
504 #ifndef CONFIG_SUNOS_EMUL
505 asmlinkage long sunos_syscall(struct pt_regs *regs)
506 {
507         static int count;
508
509         regs->tpc = regs->tnpc;
510         regs->tnpc += 4;
511         if (test_thread_flag(TIF_32BIT)) {
512                 regs->tpc &= 0xffffffff;
513                 regs->tnpc &= 0xffffffff;
514         }
515         if (++count <= 20)
516                 printk ("SunOS binary emulation not compiled in\n");
517         force_sig(SIGSEGV, current);
518
519         return -ENOSYS;
520 }
521 #endif
522
523 asmlinkage long sys_utrap_install(utrap_entry_t type,
524                                   utrap_handler_t new_p,
525                                   utrap_handler_t new_d,
526                                   utrap_handler_t __user *old_p,
527                                   utrap_handler_t __user *old_d)
528 {
529         if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
530                 return -EINVAL;
531         if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
532                 if (old_p) {
533                         if (!current_thread_info()->utraps) {
534                                 if (put_user(NULL, old_p))
535                                         return -EFAULT;
536                         } else {
537                                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
538                                         return -EFAULT;
539                         }
540                 }
541                 if (old_d) {
542                         if (put_user(NULL, old_d))
543                                 return -EFAULT;
544                 }
545                 return 0;
546         }
547         if (!current_thread_info()->utraps) {
548                 current_thread_info()->utraps =
549                         kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), GFP_KERNEL);
550                 if (!current_thread_info()->utraps)
551                         return -ENOMEM;
552                 current_thread_info()->utraps[0] = 1;
553                 memset(current_thread_info()->utraps+1, 0,
554                        UT_TRAP_INSTRUCTION_31*sizeof(long));
555         } else {
556                 if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
557                     current_thread_info()->utraps[0] > 1) {
558                         long *p = current_thread_info()->utraps;
559
560                         current_thread_info()->utraps =
561                                 kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
562                                         GFP_KERNEL);
563                         if (!current_thread_info()->utraps) {
564                                 current_thread_info()->utraps = p;
565                                 return -ENOMEM;
566                         }
567                         p[0]--;
568                         current_thread_info()->utraps[0] = 1;
569                         memcpy(current_thread_info()->utraps+1, p+1,
570                                UT_TRAP_INSTRUCTION_31*sizeof(long));
571                 }
572         }
573         if (old_p) {
574                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
575                         return -EFAULT;
576         }
577         if (old_d) {
578                 if (put_user(NULL, old_d))
579                         return -EFAULT;
580         }
581         current_thread_info()->utraps[type] = (long)new_p;
582
583         return 0;
584 }
585
586 long sparc_memory_ordering(unsigned long model, struct pt_regs *regs)
587 {
588         if (model >= 3)
589                 return -EINVAL;
590         regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
591         return 0;
592 }
593
594 asmlinkage long sys_rt_sigaction(int sig,
595                                  const struct sigaction __user *act,
596                                  struct sigaction __user *oact,
597                                  void __user *restorer,
598                                  size_t sigsetsize)
599 {
600         struct k_sigaction new_ka, old_ka;
601         int ret;
602
603         /* XXX: Don't preclude handling different sized sigset_t's.  */
604         if (sigsetsize != sizeof(sigset_t))
605                 return -EINVAL;
606
607         if (act) {
608                 new_ka.ka_restorer = restorer;
609                 if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
610                         return -EFAULT;
611         }
612
613         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
614
615         if (!ret && oact) {
616                 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
617                         return -EFAULT;
618         }
619
620         return ret;
621 }
622
623 /* Invoked by rtrap code to update performance counters in
624  * user space.
625  */
626 asmlinkage void update_perfctrs(void)
627 {
628         unsigned long pic, tmp;
629
630         read_pic(pic);
631         tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
632         __put_user(tmp, current_thread_info()->user_cntd0);
633         tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
634         __put_user(tmp, current_thread_info()->user_cntd1);
635         reset_pic();
636 }
637
638 asmlinkage long sys_perfctr(int opcode, unsigned long arg0, unsigned long arg1, unsigned long arg2)
639 {
640         int err = 0;
641
642         switch(opcode) {
643         case PERFCTR_ON:
644                 current_thread_info()->pcr_reg = arg2;
645                 current_thread_info()->user_cntd0 = (u64 __user *) arg0;
646                 current_thread_info()->user_cntd1 = (u64 __user *) arg1;
647                 current_thread_info()->kernel_cntd0 =
648                         current_thread_info()->kernel_cntd1 = 0;
649                 write_pcr(arg2);
650                 reset_pic();
651                 set_thread_flag(TIF_PERFCTR);
652                 break;
653
654         case PERFCTR_OFF:
655                 err = -EINVAL;
656                 if (test_thread_flag(TIF_PERFCTR)) {
657                         current_thread_info()->user_cntd0 =
658                                 current_thread_info()->user_cntd1 = NULL;
659                         current_thread_info()->pcr_reg = 0;
660                         write_pcr(0);
661                         clear_thread_flag(TIF_PERFCTR);
662                         err = 0;
663                 }
664                 break;
665
666         case PERFCTR_READ: {
667                 unsigned long pic, tmp;
668
669                 if (!test_thread_flag(TIF_PERFCTR)) {
670                         err = -EINVAL;
671                         break;
672                 }
673                 read_pic(pic);
674                 tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
675                 err |= __put_user(tmp, current_thread_info()->user_cntd0);
676                 tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
677                 err |= __put_user(tmp, current_thread_info()->user_cntd1);
678                 reset_pic();
679                 break;
680         }
681
682         case PERFCTR_CLRPIC:
683                 if (!test_thread_flag(TIF_PERFCTR)) {
684                         err = -EINVAL;
685                         break;
686                 }
687                 current_thread_info()->kernel_cntd0 =
688                         current_thread_info()->kernel_cntd1 = 0;
689                 reset_pic();
690                 break;
691
692         case PERFCTR_SETPCR: {
693                 u64 __user *user_pcr = (u64 __user *)arg0;
694
695                 if (!test_thread_flag(TIF_PERFCTR)) {
696                         err = -EINVAL;
697                         break;
698                 }
699                 err |= __get_user(current_thread_info()->pcr_reg, user_pcr);
700                 write_pcr(current_thread_info()->pcr_reg);
701                 current_thread_info()->kernel_cntd0 =
702                         current_thread_info()->kernel_cntd1 = 0;
703                 reset_pic();
704                 break;
705         }
706
707         case PERFCTR_GETPCR: {
708                 u64 __user *user_pcr = (u64 __user *)arg0;
709
710                 if (!test_thread_flag(TIF_PERFCTR)) {
711                         err = -EINVAL;
712                         break;
713                 }
714                 err |= __put_user(current_thread_info()->pcr_reg, user_pcr);
715                 break;
716         }
717
718         default:
719                 err = -EINVAL;
720                 break;
721         };
722         return err;
723 }