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