[POWERPC] Fix PCI IRQ fallback code to not map IRQ 0
[deliverable/linux.git] / arch / powerpc / kernel / syscalls.c
CommitLineData
1da177e4 1/*
30286ef6 2 * Implementation of various system calls for Linux/PowerPC
1da177e4 3 *
1da177e4
LT
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 *
6 * Derived from "arch/i386/kernel/sys_i386.c"
7 * Adapted from the i386 version by Gary Thomas
8 * Modified by Cort Dougan (cort@cs.nmt.edu)
9 * and Paul Mackerras (paulus@cs.anu.edu.au).
10 *
11 * This file contains various random system calls that
12 * have a non-standard calling sequence on the Linux/PPC
13 * platform.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 *
20 */
21
22#include <linux/errno.h>
23#include <linux/sched.h>
24#include <linux/syscalls.h>
25#include <linux/mm.h>
4e950f6f 26#include <linux/fs.h>
1da177e4 27#include <linux/smp.h>
1da177e4
LT
28#include <linux/sem.h>
29#include <linux/msg.h>
30#include <linux/shm.h>
31#include <linux/stat.h>
32#include <linux/mman.h>
33#include <linux/sys.h>
34#include <linux/ipc.h>
35#include <linux/utsname.h>
36#include <linux/file.h>
37#include <linux/init.h>
38#include <linux/personality.h>
39
40#include <asm/uaccess.h>
1da177e4 41#include <asm/semaphore.h>
a7f31841 42#include <asm/syscalls.h>
1da177e4
LT
43#include <asm/time.h>
44#include <asm/unistd.h>
45
1da177e4
LT
46/*
47 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
48 *
49 * This is really horribly ugly.
50 */
30286ef6
PM
51int sys_ipc(uint call, int first, unsigned long second, long third,
52 void __user *ptr, long fifth)
1da177e4
LT
53{
54 int version, ret;
55
56 version = call >> 16; /* hack for backward compatibility */
57 call &= 0xffff;
58
59 ret = -ENOSYS;
60 switch (call) {
61 case SEMOP:
62 ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
63 (unsigned)second, NULL);
64 break;
65 case SEMTIMEDOP:
66 ret = sys_semtimedop(first, (struct sembuf __user *)ptr,
67 (unsigned)second,
68 (const struct timespec __user *) fifth);
69 break;
70 case SEMGET:
71 ret = sys_semget (first, (int)second, third);
72 break;
73 case SEMCTL: {
74 union semun fourth;
75
76 ret = -EINVAL;
77 if (!ptr)
78 break;
79 if ((ret = get_user(fourth.__pad, (void __user * __user *)ptr)))
80 break;
81 ret = sys_semctl(first, (int)second, third, fourth);
82 break;
83 }
84 case MSGSND:
85 ret = sys_msgsnd(first, (struct msgbuf __user *)ptr,
30286ef6 86 (size_t)second, third);
1da177e4
LT
87 break;
88 case MSGRCV:
89 switch (version) {
90 case 0: {
91 struct ipc_kludge tmp;
92
93 ret = -EINVAL;
94 if (!ptr)
95 break;
96 if ((ret = copy_from_user(&tmp,
97 (struct ipc_kludge __user *) ptr,
98 sizeof (tmp)) ? -EFAULT : 0))
99 break;
100 ret = sys_msgrcv(first, tmp.msgp, (size_t) second,
101 tmp.msgtyp, third);
102 break;
103 }
104 default:
105 ret = sys_msgrcv (first, (struct msgbuf __user *) ptr,
106 (size_t)second, fifth, third);
107 break;
108 }
109 break;
110 case MSGGET:
30286ef6 111 ret = sys_msgget((key_t)first, (int)second);
1da177e4
LT
112 break;
113 case MSGCTL:
114 ret = sys_msgctl(first, (int)second,
115 (struct msqid_ds __user *)ptr);
116 break;
30286ef6
PM
117 case SHMAT: {
118 ulong raddr;
119 ret = do_shmat(first, (char __user *)ptr, (int)second, &raddr);
120 if (ret)
1da177e4 121 break;
30286ef6 122 ret = put_user(raddr, (ulong __user *) third);
1da177e4 123 break;
30286ef6
PM
124 }
125 case SHMDT:
126 ret = sys_shmdt((char __user *)ptr);
1da177e4
LT
127 break;
128 case SHMGET:
30286ef6 129 ret = sys_shmget(first, (size_t)second, third);
1da177e4
LT
130 break;
131 case SHMCTL:
132 ret = sys_shmctl(first, (int)second,
30286ef6 133 (struct shmid_ds __user *)ptr);
1da177e4
LT
134 break;
135 }
136
137 return ret;
138}
139
140/*
141 * sys_pipe() is the normal C calling standard for creating
142 * a pipe. It's not the way unix traditionally does this, though.
143 */
30286ef6 144int sys_pipe(int __user *fildes)
1da177e4
LT
145{
146 int fd[2];
147 int error;
30286ef6 148
1da177e4
LT
149 error = do_pipe(fd);
150 if (!error) {
151 if (copy_to_user(fildes, fd, 2*sizeof(int)))
152 error = -EFAULT;
153 }
1da177e4
LT
154 return error;
155}
156
30286ef6
PM
157static inline unsigned long do_mmap2(unsigned long addr, size_t len,
158 unsigned long prot, unsigned long flags,
159 unsigned long fd, unsigned long off, int shift)
1da177e4
LT
160{
161 struct file * file = NULL;
05d84681 162 unsigned long ret = -EINVAL;
1da177e4 163
30286ef6
PM
164 if (shift) {
165 if (off & ((1 << shift) - 1))
166 goto out;
167 off >>= shift;
168 }
169
170 ret = -EBADF;
1da177e4
LT
171 if (!(flags & MAP_ANONYMOUS)) {
172 if (!(file = fget(fd)))
173 goto out;
174 }
175
176 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
30286ef6 177
1da177e4 178 down_write(&current->mm->mmap_sem);
30286ef6 179 ret = do_mmap_pgoff(file, addr, len, prot, flags, off);
1da177e4
LT
180 up_write(&current->mm->mmap_sem);
181 if (file)
182 fput(file);
1da177e4
LT
183out:
184 return ret;
185}
186
30286ef6
PM
187unsigned long sys_mmap2(unsigned long addr, size_t len,
188 unsigned long prot, unsigned long flags,
189 unsigned long fd, unsigned long pgoff)
190{
191 return do_mmap2(addr, len, prot, flags, fd, pgoff, PAGE_SHIFT-12);
192}
193
194unsigned long sys_mmap(unsigned long addr, size_t len,
195 unsigned long prot, unsigned long flags,
196 unsigned long fd, off_t offset)
197{
198 return do_mmap2(addr, len, prot, flags, fd, offset, PAGE_SHIFT);
199}
200
201#ifdef CONFIG_PPC32
202/*
203 * Due to some executables calling the wrong select we sometimes
204 * get wrong args. This determines how the args are being passed
205 * (a single ptr to them all args passed) then calls
206 * sys_select() with the appropriate args. -- Cort
207 */
208int
209ppc_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, struct timeval __user *tvp)
210{
211 if ( (unsigned long)n >= 4096 )
212 {
213 unsigned long __user *buffer = (unsigned long __user *)n;
214 if (!access_ok(VERIFY_READ, buffer, 5*sizeof(unsigned long))
215 || __get_user(n, buffer)
216 || __get_user(inp, ((fd_set __user * __user *)(buffer+1)))
217 || __get_user(outp, ((fd_set __user * __user *)(buffer+2)))
218 || __get_user(exp, ((fd_set __user * __user *)(buffer+3)))
219 || __get_user(tvp, ((struct timeval __user * __user *)(buffer+4))))
220 return -EFAULT;
221 }
222 return sys_select(n, inp, outp, exp, tvp);
223}
224#endif
225
226#ifdef CONFIG_PPC64
ce10d979 227long ppc64_personality(unsigned long personality)
1da177e4 228{
ce10d979
PM
229 long ret;
230
231 if (personality(current->personality) == PER_LINUX32
232 && personality == PER_LINUX)
233 personality = PER_LINUX32;
234 ret = sys_personality(personality);
235 if (ret == PER_LINUX32)
236 ret = PER_LINUX;
237 return ret;
1da177e4 238}
30286ef6
PM
239#endif
240
241#ifdef CONFIG_PPC64
242#define OVERRIDE_MACHINE (personality(current->personality) == PER_LINUX32)
243#else
244#define OVERRIDE_MACHINE 0
245#endif
1da177e4 246
ebbd1bce 247static inline int override_machine(char __user *mach)
30286ef6
PM
248{
249 if (OVERRIDE_MACHINE) {
250 /* change ppc64 to ppc */
251 if (__put_user(0, mach+3) || __put_user(0, mach+4))
252 return -EFAULT;
253 }
254 return 0;
255}
256
257long ppc_newuname(struct new_utsname __user * name)
1da177e4 258{
ce10d979
PM
259 int err = 0;
260
1da177e4 261 down_read(&uts_sem);
e9ff3990 262 if (copy_to_user(name, utsname(), sizeof(*name)))
ce10d979 263 err = -EFAULT;
1da177e4 264 up_read(&uts_sem);
30286ef6
PM
265 if (!err)
266 err = override_machine(name->machine);
1da177e4
LT
267 return err;
268}
269
30286ef6
PM
270int sys_uname(struct old_utsname __user *name)
271{
272 int err = 0;
273
274 down_read(&uts_sem);
e9ff3990 275 if (copy_to_user(name, utsname(), sizeof(*name)))
30286ef6
PM
276 err = -EFAULT;
277 up_read(&uts_sem);
278 if (!err)
279 err = override_machine(name->machine);
280 return err;
281}
282
283int sys_olduname(struct oldold_utsname __user *name)
284{
285 int error;
286
287 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
288 return -EFAULT;
289
290 down_read(&uts_sem);
e9ff3990 291 error = __copy_to_user(&name->sysname, &utsname()->sysname,
30286ef6
PM
292 __OLD_UTS_LEN);
293 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
e9ff3990 294 error |= __copy_to_user(&name->nodename, &utsname()->nodename,
30286ef6
PM
295 __OLD_UTS_LEN);
296 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
e9ff3990 297 error |= __copy_to_user(&name->release, &utsname()->release,
30286ef6
PM
298 __OLD_UTS_LEN);
299 error |= __put_user(0, name->release + __OLD_UTS_LEN);
e9ff3990 300 error |= __copy_to_user(&name->version, &utsname()->version,
30286ef6
PM
301 __OLD_UTS_LEN);
302 error |= __put_user(0, name->version + __OLD_UTS_LEN);
e9ff3990 303 error |= __copy_to_user(&name->machine, &utsname()->machine,
30286ef6
PM
304 __OLD_UTS_LEN);
305 error |= override_machine(name->machine);
306 up_read(&uts_sem);
307
308 return error? -EFAULT: 0;
309}
310
77f543cb
PM
311long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
312 u32 len_high, u32 len_low)
313{
314 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
315 (u64)len_high << 32 | len_low, advice);
316}
317
1da177e4
LT
318void do_show_syscall(unsigned long r3, unsigned long r4, unsigned long r5,
319 unsigned long r6, unsigned long r7, unsigned long r8,
320 struct pt_regs *regs)
321{
322 printk("syscall %ld(%lx, %lx, %lx, %lx, %lx, %lx) regs=%p current=%p"
323 " cpu=%d\n", regs->gpr[0], r3, r4, r5, r6, r7, r8, regs,
324 current, smp_processor_id());
325}
326
327void do_show_syscall_exit(unsigned long r3)
328{
329 printk(" -> %lx, current=%p cpu=%d\n", r3, current, smp_processor_id());
330}
This page took 0.330319 seconds and 5 git commands to generate.