Merge branch 'acpica'
[linux-2.6-block.git] / arch / parisc / kernel / sys_parisc.c
CommitLineData
1da177e4
LT
1
2/*
3 * PARISC specific syscalls
4 *
5 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
6 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
7 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <asm/uaccess.h>
26#include <linux/file.h>
27#include <linux/fs.h>
28#include <linux/linkage.h>
29#include <linux/mm.h>
30#include <linux/mman.h>
31#include <linux/shm.h>
1da177e4 32#include <linux/syscalls.h>
75a49581
KM
33#include <linux/utsname.h>
34#include <linux/personality.h>
1da177e4 35
1da177e4
LT
36static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
37{
a0031197 38 struct vm_unmapped_area_info info;
1da177e4 39
a0031197
ML
40 info.flags = 0;
41 info.length = len;
42 info.low_limit = PAGE_ALIGN(addr);
43 info.high_limit = TASK_SIZE;
44 info.align_mask = 0;
45 info.align_offset = 0;
46 return vm_unmapped_area(&info);
1da177e4
LT
47}
48
1da177e4
LT
49/*
50 * We need to know the offset to use. Old scheme was to look for
51 * existing mapping and use the same offset. New scheme is to use the
52 * address of the kernel data structure as the seed for the offset.
53 * We'll see how that works...
54 *
55 * The mapping is cacheline aligned, so there's no information in the bottom
56 * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
57 * drop the bottom 8 bits and use bits 8-17.
58 */
59static int get_offset(struct address_space *mapping)
60{
a0031197 61 return (unsigned long) mapping >> 8;
1da177e4
LT
62}
63
64static unsigned long get_shared_area(struct address_space *mapping,
65 unsigned long addr, unsigned long len, unsigned long pgoff)
66{
a0031197 67 struct vm_unmapped_area_info info;
1da177e4 68
a0031197
ML
69 info.flags = 0;
70 info.length = len;
71 info.low_limit = PAGE_ALIGN(addr);
72 info.high_limit = TASK_SIZE;
73 info.align_mask = PAGE_MASK & (SHMLBA - 1);
74 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
75 return vm_unmapped_area(&info);
1da177e4
LT
76}
77
78unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
79 unsigned long len, unsigned long pgoff, unsigned long flags)
80{
81 if (len > TASK_SIZE)
82 return -ENOMEM;
5ca8b91d
JDA
83 if (flags & MAP_FIXED) {
84 if ((flags & MAP_SHARED) &&
85 (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
86 return -EINVAL;
869e5101 87 return addr;
5ca8b91d 88 }
1da177e4
LT
89 if (!addr)
90 addr = TASK_UNMAPPED_BASE;
91
92 if (filp) {
93 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
94 } else if(flags & MAP_SHARED) {
95 addr = get_shared_area(NULL, addr, len, pgoff);
96 } else {
97 addr = get_unshared_area(addr, len);
98 }
99 return addr;
100}
101
1da177e4
LT
102asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
103 unsigned long prot, unsigned long flags, unsigned long fd,
104 unsigned long pgoff)
105{
106 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
107 we have. */
f8b72560
AV
108 return sys_mmap_pgoff(addr, len, prot, flags, fd,
109 pgoff >> (PAGE_SHIFT - 12));
1da177e4
LT
110}
111
112asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
113 unsigned long prot, unsigned long flags, unsigned long fd,
114 unsigned long offset)
115{
116 if (!(offset & ~PAGE_MASK)) {
f8b72560
AV
117 return sys_mmap_pgoff(addr, len, prot, flags, fd,
118 offset >> PAGE_SHIFT);
1da177e4
LT
119 } else {
120 return -EINVAL;
121 }
122}
123
1da177e4
LT
124/* Fucking broken ABI */
125
126#ifdef CONFIG_64BIT
127asmlinkage long parisc_truncate64(const char __user * path,
128 unsigned int high, unsigned int low)
129{
130 return sys_truncate(path, (long)high << 32 | low);
131}
132
133asmlinkage long parisc_ftruncate64(unsigned int fd,
134 unsigned int high, unsigned int low)
135{
136 return sys_ftruncate(fd, (long)high << 32 | low);
137}
138
139/* stubs for the benefit of the syscall_table since truncate64 and truncate
140 * are identical on LP64 */
141asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
142{
143 return sys_truncate(path, length);
144}
145asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
146{
147 return sys_ftruncate(fd, length);
148}
149asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
150{
151 return sys_fcntl(fd, cmd, arg);
152}
153#else
154
155asmlinkage long parisc_truncate64(const char __user * path,
156 unsigned int high, unsigned int low)
157{
158 return sys_truncate64(path, (loff_t)high << 32 | low);
159}
160
161asmlinkage long parisc_ftruncate64(unsigned int fd,
162 unsigned int high, unsigned int low)
163{
164 return sys_ftruncate64(fd, (loff_t)high << 32 | low);
165}
166#endif
167
168asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
169 unsigned int high, unsigned int low)
170{
171 return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
172}
173
174asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
175 size_t count, unsigned int high, unsigned int low)
176{
177 return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
178}
179
180asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
181 size_t count)
182{
183 return sys_readahead(fd, (loff_t)high << 32 | low, count);
184}
185
186asmlinkage long parisc_fadvise64_64(int fd,
187 unsigned int high_off, unsigned int low_off,
188 unsigned int high_len, unsigned int low_len, int advice)
189{
190 return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
191 (loff_t)high_len << 32 | low_len, advice);
192}
193
6ca773cf
KM
194asmlinkage long parisc_sync_file_range(int fd,
195 u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
196 unsigned int flags)
197{
198 return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
199 (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
200}
201
4474a331
HD
202asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
203 u32 lenhi, u32 lenlo)
204{
205 return sys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
206 ((u64)lenhi << 32) | lenlo);
207}
208
1da177e4
LT
209asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
210{
211 return -ENOMEM;
212}
213
214asmlinkage int sys_free_hugepages(unsigned long addr)
215{
216 return -EINVAL;
217}
75a49581
KM
218
219long parisc_personality(unsigned long personality)
220{
221 long err;
222
223 if (personality(current->personality) == PER_LINUX32
5b24c421
JK
224 && personality(personality) == PER_LINUX)
225 personality = (personality & ~PER_MASK) | PER_LINUX32;
75a49581
KM
226
227 err = sys_personality(personality);
5b24c421
JK
228 if (personality(err) == PER_LINUX32)
229 err = (err & ~PER_MASK) | PER_LINUX;
75a49581
KM
230
231 return err;
232}