Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6
[pandora-kernel.git] / arch / tile / kernel / sys.c
1 /*
2  * Copyright 2010 Tilera Corporation. All Rights Reserved.
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful, but
9  *   WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11  *   NON INFRINGEMENT.  See the GNU General Public License for
12  *   more details.
13  *
14  * This file contains various random system calls that
15  * have a non-standard calling sequence on the Linux/TILE
16  * platform.
17  */
18
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/mm.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
24 #include <linux/syscalls.h>
25 #include <linux/mman.h>
26 #include <linux/file.h>
27 #include <linux/mempolicy.h>
28 #include <linux/binfmts.h>
29 #include <linux/fs.h>
30 #include <linux/compat.h>
31 #include <linux/uaccess.h>
32 #include <linux/signal.h>
33 #include <asm/syscalls.h>
34 #include <asm/pgtable.h>
35 #include <asm/homecache.h>
36 #include <arch/chip.h>
37
38 SYSCALL_DEFINE0(flush_cache)
39 {
40         homecache_evict(cpumask_of(smp_processor_id()));
41         return 0;
42 }
43
44 /*
45  * Syscalls that pass 64-bit values on 32-bit systems normally
46  * pass them as (low,high) word packed into the immediately adjacent
47  * registers.  If the low word naturally falls on an even register,
48  * our ABI makes it work correctly; if not, we adjust it here.
49  * Handling it here means we don't have to fix uclibc AND glibc AND
50  * any other standard libcs we want to support.
51  */
52
53 #if !defined(__tilegx__) || defined(CONFIG_COMPAT)
54
55 ssize_t sys32_readahead(int fd, u32 offset_lo, u32 offset_hi, u32 count)
56 {
57         return sys_readahead(fd, ((loff_t)offset_hi << 32) | offset_lo, count);
58 }
59
60 long sys32_fadvise64(int fd, u32 offset_lo, u32 offset_hi,
61                      u32 len, int advice)
62 {
63         return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo,
64                                 len, advice);
65 }
66
67 int sys32_fadvise64_64(int fd, u32 offset_lo, u32 offset_hi,
68                        u32 len_lo, u32 len_hi, int advice)
69 {
70         return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo,
71                                 ((loff_t)len_hi << 32) | len_lo, advice);
72 }
73
74 #endif /* 32-bit syscall wrappers */
75
76 /* Note: used by the compat code even in 64-bit Linux. */
77 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
78                 unsigned long, prot, unsigned long, flags,
79                 unsigned long, fd, unsigned long, off_4k)
80 {
81 #define PAGE_ADJUST (PAGE_SHIFT - 12)
82         if (off_4k & ((1 << PAGE_ADJUST) - 1))
83                 return -EINVAL;
84         return sys_mmap_pgoff(addr, len, prot, flags, fd,
85                               off_4k >> PAGE_ADJUST);
86 }
87
88 #ifdef __tilegx__
89 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
90                 unsigned long, prot, unsigned long, flags,
91                 unsigned long, fd, off_t, offset)
92 {
93         if (offset & ((1 << PAGE_SHIFT) - 1))
94                 return -EINVAL;
95         return sys_mmap_pgoff(addr, len, prot, flags, fd,
96                               offset >> PAGE_SHIFT);
97 }
98 #endif
99
100
101 /* Provide the actual syscall number to call mapping. */
102 #undef __SYSCALL
103 #define __SYSCALL(nr, call) [nr] = (call),
104
105 #ifndef __tilegx__
106 /* See comments at the top of the file. */
107 #define sys_fadvise64 sys32_fadvise64
108 #define sys_fadvise64_64 sys32_fadvise64_64
109 #define sys_readahead sys32_readahead
110 #define sys_sync_file_range sys_sync_file_range2
111 #endif
112
113 /* Call the trampolines to manage pt_regs where necessary. */
114 #define sys_execve _sys_execve
115 #define sys_sigaltstack _sys_sigaltstack
116 #define sys_rt_sigreturn _sys_rt_sigreturn
117 #define sys_clone _sys_clone
118 #ifndef __tilegx__
119 #define sys_cmpxchg_badaddr _sys_cmpxchg_badaddr
120 #endif
121
122 /*
123  * Note that we can't include <linux/unistd.h> here since the header
124  * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
125  */
126 void *sys_call_table[__NR_syscalls] = {
127         [0 ... __NR_syscalls-1] = sys_ni_syscall,
128 #include <asm/unistd.h>
129 };