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