2 * linux/arch/m68k/kernel/sys_m68k.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/m68k
9 #include <linux/capability.h>
10 #include <linux/errno.h>
11 #include <linux/sched.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>
24 #include <asm/setup.h>
25 #include <asm/uaccess.h>
26 #include <asm/cachectl.h>
27 #include <asm/traps.h>
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way unix traditionally does this, though.
35 asmlinkage int sys_pipe(unsigned long * fildes)
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
48 /* common code for old and new mmaps */
49 static inline long do_mmap2(
50 unsigned long addr, unsigned long len,
51 unsigned long prot, unsigned long flags,
52 unsigned long fd, unsigned long pgoff)
55 struct file * file = NULL;
57 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
58 if (!(flags & MAP_ANONYMOUS)) {
64 down_write(¤t->mm->mmap_sem);
65 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
66 up_write(¤t->mm->mmap_sem);
74 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
75 unsigned long prot, unsigned long flags,
76 unsigned long fd, unsigned long pgoff)
78 return do_mmap2(addr, len, prot, flags, fd, pgoff);
82 * Perform the select(nd, in, out, ex, tv) and mmap() system
83 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
84 * handle more than 4 system call parameters, so these system calls
85 * used a memory block for parameter passing..
88 struct mmap_arg_struct {
97 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
99 struct mmap_arg_struct a;
102 if (copy_from_user(&a, arg, sizeof(a)))
106 if (a.offset & ~PAGE_MASK)
109 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
111 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
117 struct mmap_arg_struct64 {
122 __u64 offset; /* 64 bits */
126 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
129 struct file * file = NULL;
130 struct mmap_arg_struct64 a;
133 if (copy_from_user(&a, arg, sizeof(a)))
136 if ((long)a.offset & ~PAGE_MASK)
139 pgoff = a.offset >> PAGE_SHIFT;
140 if ((a.offset >> PAGE_SHIFT) != pgoff)
143 if (!(a.flags & MAP_ANONYMOUS)) {
149 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
151 down_write(¤t->mm->mmap_sem);
152 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
153 up_write(¤t->mm->mmap_sem);
161 struct sel_arg_struct {
163 fd_set *inp, *outp, *exp;
167 asmlinkage int old_select(struct sel_arg_struct *arg)
169 struct sel_arg_struct a;
171 if (copy_from_user(&a, arg, sizeof(a)))
173 /* sys_select() does the appropriate kernel locking */
174 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
178 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
180 * This is really horribly ugly.
182 asmlinkage int sys_ipc (uint call, int first, int second,
183 int third, void *ptr, long fifth)
187 version = call >> 16; /* hack for backward compatibility */
193 return sys_semop (first, (struct sembuf *)ptr, second);
195 return sys_semget (first, second, third);
200 if (get_user(fourth.__pad, (void **) ptr))
202 return sys_semctl (first, second, third, fourth);
210 return sys_msgsnd (first, (struct msgbuf *) ptr,
215 struct ipc_kludge tmp;
218 if (copy_from_user (&tmp,
219 (struct ipc_kludge *)ptr,
222 return sys_msgrcv (first, tmp.msgp, second,
226 return sys_msgrcv (first,
227 (struct msgbuf *) ptr,
228 second, fifth, third);
231 return sys_msgget ((key_t) first, second);
233 return sys_msgctl (first, second,
234 (struct msqid_ds *) ptr);
244 ret = do_shmat (first, (char *) ptr,
248 return put_user (raddr, (ulong *) third);
252 return sys_shmdt ((char *)ptr);
254 return sys_shmget (first, second, third);
256 return sys_shmctl (first, second,
257 (struct shmid_ds *) ptr);
265 /* Convert virtual (user) address VADDR to physical address PADDR */
266 #define virt_to_phys_040(vaddr) \
268 unsigned long _mmusr, _paddr; \
270 __asm__ __volatile__ (".chip 68040\n\t" \
272 "movec %%mmusr,%0\n\t" \
276 _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0; \
281 cache_flush_040 (unsigned long addr, int scope, int cache, unsigned long len)
283 unsigned long paddr, i;
287 case FLUSH_SCOPE_ALL:
290 case FLUSH_CACHE_DATA:
291 /* This nop is needed for some broken versions of the 68040. */
292 __asm__ __volatile__ ("nop\n\t"
297 case FLUSH_CACHE_INSN:
298 __asm__ __volatile__ ("nop\n\t"
304 case FLUSH_CACHE_BOTH:
305 __asm__ __volatile__ ("nop\n\t"
313 case FLUSH_SCOPE_LINE:
314 /* Find the physical address of the first mapped page in the
316 if ((paddr = virt_to_phys_040(addr))) {
317 paddr += addr & ~(PAGE_MASK | 15);
318 len = (len + (addr & 15) + 15) >> 4;
320 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
329 if ((paddr = virt_to_phys_040(addr)))
336 len = (len + 15) >> 4;
338 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
343 case FLUSH_CACHE_DATA:
344 __asm__ __volatile__ ("nop\n\t"
346 "cpushl %%dc,(%0)\n\t"
350 case FLUSH_CACHE_INSN:
351 __asm__ __volatile__ ("nop\n\t"
353 "cpushl %%ic,(%0)\n\t"
358 case FLUSH_CACHE_BOTH:
359 __asm__ __volatile__ ("nop\n\t"
361 "cpushl %%bc,(%0)\n\t"
369 * No need to page align here since it is done by
370 * virt_to_phys_040().
374 /* Recompute physical address when crossing a page
378 if ((paddr = virt_to_phys_040(addr)))
392 case FLUSH_SCOPE_PAGE:
393 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
394 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
396 if (!(paddr = virt_to_phys_040(addr)))
400 case FLUSH_CACHE_DATA:
401 __asm__ __volatile__ ("nop\n\t"
403 "cpushp %%dc,(%0)\n\t"
407 case FLUSH_CACHE_INSN:
408 __asm__ __volatile__ ("nop\n\t"
410 "cpushp %%ic,(%0)\n\t"
415 case FLUSH_CACHE_BOTH:
416 __asm__ __volatile__ ("nop\n\t"
418 "cpushp %%bc,(%0)\n\t"
429 #define virt_to_phys_060(vaddr) \
431 unsigned long paddr; \
432 __asm__ __volatile__ (".chip 68060\n\t" \
441 cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
443 unsigned long paddr, i;
447 * cpush %dc : flush DC, remains valid (with our %cacr setup)
448 * cpush %ic : invalidate IC
449 * cpush %bc : flush DC + invalidate IC
453 case FLUSH_SCOPE_ALL:
456 case FLUSH_CACHE_DATA:
457 __asm__ __volatile__ (".chip 68060\n\t"
461 case FLUSH_CACHE_INSN:
462 __asm__ __volatile__ (".chip 68060\n\t"
467 case FLUSH_CACHE_BOTH:
468 __asm__ __volatile__ (".chip 68060\n\t"
475 case FLUSH_SCOPE_LINE:
476 /* Find the physical address of the first mapped page in the
480 if (!(paddr = virt_to_phys_060(addr))) {
481 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
490 if ((paddr = virt_to_phys_060(addr)))
498 len = (len + 15) >> 4;
499 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
504 case FLUSH_CACHE_DATA:
505 __asm__ __volatile__ (".chip 68060\n\t"
506 "cpushl %%dc,(%0)\n\t"
510 case FLUSH_CACHE_INSN:
511 __asm__ __volatile__ (".chip 68060\n\t"
512 "cpushl %%ic,(%0)\n\t"
517 case FLUSH_CACHE_BOTH:
518 __asm__ __volatile__ (".chip 68060\n\t"
519 "cpushl %%bc,(%0)\n\t"
528 * We just want to jump to the first cache line
535 /* Recompute physical address when crossing a page
539 if ((paddr = virt_to_phys_060(addr)))
553 case FLUSH_SCOPE_PAGE:
554 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
555 addr &= PAGE_MASK; /* Workaround for bug in some
556 revisions of the 68060 */
557 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
559 if (!(paddr = virt_to_phys_060(addr)))
563 case FLUSH_CACHE_DATA:
564 __asm__ __volatile__ (".chip 68060\n\t"
565 "cpushp %%dc,(%0)\n\t"
569 case FLUSH_CACHE_INSN:
570 __asm__ __volatile__ (".chip 68060\n\t"
571 "cpushp %%ic,(%0)\n\t"
576 case FLUSH_CACHE_BOTH:
577 __asm__ __volatile__ (".chip 68060\n\t"
578 "cpushp %%bc,(%0)\n\t"
589 /* sys_cacheflush -- flush (part of) the processor cache. */
591 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
593 struct vm_area_struct *vma;
597 if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
598 cache & ~FLUSH_CACHE_BOTH)
601 if (scope == FLUSH_SCOPE_ALL) {
602 /* Only the superuser may explicitly flush the whole cache. */
604 if (!capable(CAP_SYS_ADMIN))
608 * Verify that the specified address region actually belongs
611 vma = find_vma (current->mm, addr);
613 /* Check for overflow. */
614 if (addr + len < addr)
616 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
620 if (CPU_IS_020_OR_030) {
621 if (scope == FLUSH_SCOPE_LINE && len < 256) {
623 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
624 if (cache & FLUSH_CACHE_INSN)
626 if (cache & FLUSH_CACHE_DATA)
630 __asm__ __volatile__ ("movec %1, %%caar\n\t"
633 : "r" (cacr), "r" (addr));
637 /* Flush the whole cache, even if page granularity requested. */
639 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
640 if (cache & FLUSH_CACHE_INSN)
642 if (cache & FLUSH_CACHE_DATA)
644 __asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
650 * 040 or 060: don't blindly trust 'scope', someone could
651 * try to flush a few megs of memory.
654 if (len>=3*PAGE_SIZE && scope<FLUSH_SCOPE_PAGE)
655 scope=FLUSH_SCOPE_PAGE;
656 if (len>=10*PAGE_SIZE && scope<FLUSH_SCOPE_ALL)
657 scope=FLUSH_SCOPE_ALL;
659 ret = cache_flush_040 (addr, scope, cache, len);
660 } else if (CPU_IS_060) {
661 ret = cache_flush_060 (addr, scope, cache, len);
669 asmlinkage int sys_getpagesize(void)