Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband
[linux-2.6] / arch / m32r / kernel / sys_m32r.c
1 /*
2  * linux/arch/m32r/kernel/sys_m32r.c
3  *
4  * This file contains various random system calls that
5  * have a non-standard calling sequence on the Linux/M32R platform.
6  *
7  * Taken from i386 version.
8  */
9
10 #include <linux/errno.h>
11 #include <linux/sched.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/syscalls.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/utsname.h>
23
24 #include <asm/uaccess.h>
25 #include <asm/cachectl.h>
26 #include <asm/cacheflush.h>
27 #include <asm/ipc.h>
28
29 /*
30  * sys_tas() - test-and-set
31  */
32 asmlinkage int sys_tas(int *addr)
33 {
34         int oldval;
35
36         if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
37                 return -EFAULT;
38
39         /* atomic operation:
40          *   oldval = *addr; *addr = 1;
41          */
42         __asm__ __volatile__ (
43                 DCACHE_CLEAR("%0", "r4", "%1")
44                 "       .fillinsn\n"
45                 "1:\n"
46                 "       lock    %0, @%1     ->  unlock  %2, @%1\n"
47                 "2:\n"
48                 /* NOTE:
49                  *   The m32r processor can accept interrupts only
50                  *   at the 32-bit instruction boundary.
51                  *   So, in the above code, the "unlock" instruction
52                  *   can be executed continuously after the "lock"
53                  *   instruction execution without any interruptions.
54                  */
55                 ".section .fixup,\"ax\"\n"
56                 "       .balign 4\n"
57                 "3:     ldi     %0, #%3\n"
58                 "       seth    r14, #high(2b)\n"
59                 "       or3     r14, r14, #low(2b)\n"
60                 "       jmp     r14\n"
61                 ".previous\n"
62                 ".section __ex_table,\"a\"\n"
63                 "       .balign 4\n"
64                 "       .long 1b,3b\n"
65                 ".previous\n"
66                 : "=&r" (oldval)
67                 : "r" (addr), "r" (1), "i"(-EFAULT)
68                 : "r14", "memory"
69 #ifdef CONFIG_CHIP_M32700_TS1
70                   , "r4"
71 #endif /* CONFIG_CHIP_M32700_TS1 */
72         );
73
74         return oldval;
75 }
76
77 /*
78  * sys_pipe() is the normal C calling standard for creating
79  * a pipe. It's not the way Unix traditionally does this, though.
80  */
81 asmlinkage int
82 sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,
83         unsigned long r3, unsigned long r4, unsigned long r5,
84         unsigned long r6, struct pt_regs regs)
85 {
86         int fd[2];
87         int error;
88
89         error = do_pipe(fd);
90         if (!error) {
91                 if (copy_to_user((void *)r0, (void *)fd, 2*sizeof(int)))
92                         error = -EFAULT;
93         }
94         return error;
95 }
96
97 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
98         unsigned long prot, unsigned long flags,
99         unsigned long fd, unsigned long pgoff)
100 {
101         int error = -EBADF;
102         struct file *file = NULL;
103
104         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
105         if (!(flags & MAP_ANONYMOUS)) {
106                 file = fget(fd);
107                 if (!file)
108                         goto out;
109         }
110
111         down_write(&current->mm->mmap_sem);
112         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
113         up_write(&current->mm->mmap_sem);
114
115         if (file)
116                 fput(file);
117 out:
118         return error;
119 }
120
121 /*
122  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
123  *
124  * This is really horribly ugly.
125  */
126 asmlinkage int sys_ipc(uint call, int first, int second,
127                        int third, void __user *ptr, long fifth)
128 {
129         int version, ret;
130
131         version = call >> 16; /* hack for backward compatibility */
132         call &= 0xffff;
133
134         switch (call) {
135         case SEMOP:
136                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
137                                       second, NULL);
138         case SEMTIMEDOP:
139                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
140                                       second, (const struct timespec __user *)fifth);
141         case SEMGET:
142                 return sys_semget (first, second, third);
143         case SEMCTL: {
144                 union semun fourth;
145                 if (!ptr)
146                         return -EINVAL;
147                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
148                         return -EFAULT;
149                 return sys_semctl (first, second, third, fourth);
150                 }
151
152         case MSGSND:
153                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
154                                    second, third);
155         case MSGRCV:
156                 switch (version) {
157                 case 0: {
158                         struct ipc_kludge tmp;
159                         if (!ptr)
160                                 return -EINVAL;
161
162                         if (copy_from_user(&tmp,
163                                            (struct ipc_kludge __user *) ptr,
164                                            sizeof (tmp)))
165                                 return -EFAULT;
166                         return sys_msgrcv (first, tmp.msgp, second,
167                                            tmp.msgtyp, third);
168                         }
169                 default:
170                         return sys_msgrcv (first,
171                                            (struct msgbuf __user *) ptr,
172                                            second, fifth, third);
173                 }
174         case MSGGET:
175                 return sys_msgget ((key_t) first, second);
176         case MSGCTL:
177                 return sys_msgctl (first, second,
178                                    (struct msqid_ds __user *) ptr);
179         case SHMAT: {
180                 ulong raddr;
181
182                 if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
183                                       sizeof(ulong)))
184                         return -EFAULT;
185                 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
186                 if (ret)
187                         return ret;
188                 return put_user (raddr, (ulong __user *) third);
189                 }
190         case SHMDT:
191                 return sys_shmdt ((char __user *)ptr);
192         case SHMGET:
193                 return sys_shmget (first, second, third);
194         case SHMCTL:
195                 return sys_shmctl (first, second,
196                                    (struct shmid_ds __user *) ptr);
197         default:
198                 return -ENOSYS;
199         }
200 }
201
202 asmlinkage int sys_uname(struct old_utsname * name)
203 {
204         int err;
205         if (!name)
206                 return -EFAULT;
207         down_read(&uts_sem);
208         err=copy_to_user(name, &system_utsname, sizeof (*name));
209         up_read(&uts_sem);
210         return err?-EFAULT:0;
211 }
212
213 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
214 {
215         /* This should flush more selectivly ...  */
216         _flush_cache_all();
217         return 0;
218 }
219
220 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
221 {
222         /* Not implemented yet. */
223         return -ENOSYS;
224 }
225