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/errno.h>
10 #include <linux/sched.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.h>
14 #include <linux/sem.h>
15 #include <linux/msg.h>
16 #include <linux/shm.h>
17 #include <linux/stat.h>
18 #include <linux/syscalls.h>
19 #include <linux/mman.h>
20 #include <linux/file.h>
21 #include <linux/utsname.h>
23 #include <asm/setup.h>
24 #include <asm/uaccess.h>
25 #include <asm/cachectl.h>
26 #include <asm/traps.h>
31 * sys_pipe() is the normal C calling standard for creating
32 * a pipe. It's not the way unix traditionally does this, though.
34 asmlinkage int sys_pipe(unsigned long * fildes)
41 if (copy_to_user(fildes, fd, 2*sizeof(int)))
47 /* common code for old and new mmaps */
48 static inline long do_mmap2(
49 unsigned long addr, unsigned long len,
50 unsigned long prot, unsigned long flags,
51 unsigned long fd, unsigned long pgoff)
54 struct file * file = NULL;
56 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
57 if (!(flags & MAP_ANONYMOUS)) {
63 down_write(¤t->mm->mmap_sem);
64 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
65 up_write(¤t->mm->mmap_sem);
73 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
74 unsigned long prot, unsigned long flags,
75 unsigned long fd, unsigned long pgoff)
77 return do_mmap2(addr, len, prot, flags, fd, pgoff);
81 * Perform the select(nd, in, out, ex, tv) and mmap() system
82 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
83 * handle more than 4 system call parameters, so these system calls
84 * used a memory block for parameter passing..
87 struct mmap_arg_struct {
96 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
98 struct mmap_arg_struct a;
101 if (copy_from_user(&a, arg, sizeof(a)))
105 if (a.offset & ~PAGE_MASK)
108 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
110 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
116 struct mmap_arg_struct64 {
121 __u64 offset; /* 64 bits */
125 asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
128 struct file * file = NULL;
129 struct mmap_arg_struct64 a;
132 if (copy_from_user(&a, arg, sizeof(a)))
135 if ((long)a.offset & ~PAGE_MASK)
138 pgoff = a.offset >> PAGE_SHIFT;
139 if ((a.offset >> PAGE_SHIFT) != pgoff)
142 if (!(a.flags & MAP_ANONYMOUS)) {
148 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
150 down_write(¤t->mm->mmap_sem);
151 error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
152 up_write(¤t->mm->mmap_sem);
160 struct sel_arg_struct {
162 fd_set *inp, *outp, *exp;
166 asmlinkage int old_select(struct sel_arg_struct *arg)
168 struct sel_arg_struct a;
170 if (copy_from_user(&a, arg, sizeof(a)))
172 /* sys_select() does the appropriate kernel locking */
173 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
177 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
179 * This is really horribly ugly.
181 asmlinkage int sys_ipc (uint call, int first, int second,
182 int third, void *ptr, long fifth)
186 version = call >> 16; /* hack for backward compatibility */
192 return sys_semop (first, (struct sembuf *)ptr, second);
194 return sys_semget (first, second, third);
199 if (get_user(fourth.__pad, (void **) ptr))
201 return sys_semctl (first, second, third, fourth);
209 return sys_msgsnd (first, (struct msgbuf *) ptr,
214 struct ipc_kludge tmp;
217 if (copy_from_user (&tmp,
218 (struct ipc_kludge *)ptr,
221 return sys_msgrcv (first, tmp.msgp, second,
225 return sys_msgrcv (first,
226 (struct msgbuf *) ptr,
227 second, fifth, third);
230 return sys_msgget ((key_t) first, second);
232 return sys_msgctl (first, second,
233 (struct msqid_ds *) ptr);
243 ret = do_shmat (first, (char *) ptr,
247 return put_user (raddr, (ulong *) third);
251 return sys_shmdt ((char *)ptr);
253 return sys_shmget (first, second, third);
255 return sys_shmctl (first, second,
256 (struct shmid_ds *) ptr);
264 /* Convert virtual (user) address VADDR to physical address PADDR */
265 #define virt_to_phys_040(vaddr) \
267 unsigned long _mmusr, _paddr; \
269 __asm__ __volatile__ (".chip 68040\n\t" \
271 "movec %%mmusr,%0\n\t" \
275 _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0; \
280 cache_flush_040 (unsigned long addr, int scope, int cache, unsigned long len)
282 unsigned long paddr, i;
286 case FLUSH_SCOPE_ALL:
289 case FLUSH_CACHE_DATA:
290 /* This nop is needed for some broken versions of the 68040. */
291 __asm__ __volatile__ ("nop\n\t"
296 case FLUSH_CACHE_INSN:
297 __asm__ __volatile__ ("nop\n\t"
303 case FLUSH_CACHE_BOTH:
304 __asm__ __volatile__ ("nop\n\t"
312 case FLUSH_SCOPE_LINE:
313 /* Find the physical address of the first mapped page in the
315 if ((paddr = virt_to_phys_040(addr))) {
316 paddr += addr & ~(PAGE_MASK | 15);
317 len = (len + (addr & 15) + 15) >> 4;
319 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
328 if ((paddr = virt_to_phys_040(addr)))
335 len = (len + 15) >> 4;
337 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
342 case FLUSH_CACHE_DATA:
343 __asm__ __volatile__ ("nop\n\t"
345 "cpushl %%dc,(%0)\n\t"
349 case FLUSH_CACHE_INSN:
350 __asm__ __volatile__ ("nop\n\t"
352 "cpushl %%ic,(%0)\n\t"
357 case FLUSH_CACHE_BOTH:
358 __asm__ __volatile__ ("nop\n\t"
360 "cpushl %%bc,(%0)\n\t"
368 * No need to page align here since it is done by
369 * virt_to_phys_040().
373 /* Recompute physical address when crossing a page
377 if ((paddr = virt_to_phys_040(addr)))
391 case FLUSH_SCOPE_PAGE:
392 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
393 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
395 if (!(paddr = virt_to_phys_040(addr)))
399 case FLUSH_CACHE_DATA:
400 __asm__ __volatile__ ("nop\n\t"
402 "cpushp %%dc,(%0)\n\t"
406 case FLUSH_CACHE_INSN:
407 __asm__ __volatile__ ("nop\n\t"
409 "cpushp %%ic,(%0)\n\t"
414 case FLUSH_CACHE_BOTH:
415 __asm__ __volatile__ ("nop\n\t"
417 "cpushp %%bc,(%0)\n\t"
428 #define virt_to_phys_060(vaddr) \
430 unsigned long paddr; \
431 __asm__ __volatile__ (".chip 68060\n\t" \
440 cache_flush_060 (unsigned long addr, int scope, int cache, unsigned long len)
442 unsigned long paddr, i;
446 * cpush %dc : flush DC, remains valid (with our %cacr setup)
447 * cpush %ic : invalidate IC
448 * cpush %bc : flush DC + invalidate IC
452 case FLUSH_SCOPE_ALL:
455 case FLUSH_CACHE_DATA:
456 __asm__ __volatile__ (".chip 68060\n\t"
460 case FLUSH_CACHE_INSN:
461 __asm__ __volatile__ (".chip 68060\n\t"
466 case FLUSH_CACHE_BOTH:
467 __asm__ __volatile__ (".chip 68060\n\t"
474 case FLUSH_SCOPE_LINE:
475 /* Find the physical address of the first mapped page in the
479 if (!(paddr = virt_to_phys_060(addr))) {
480 unsigned long tmp = PAGE_SIZE - (addr & ~PAGE_MASK);
489 if ((paddr = virt_to_phys_060(addr)))
497 len = (len + 15) >> 4;
498 i = (PAGE_SIZE - (paddr & ~PAGE_MASK)) >> 4;
503 case FLUSH_CACHE_DATA:
504 __asm__ __volatile__ (".chip 68060\n\t"
505 "cpushl %%dc,(%0)\n\t"
509 case FLUSH_CACHE_INSN:
510 __asm__ __volatile__ (".chip 68060\n\t"
511 "cpushl %%ic,(%0)\n\t"
516 case FLUSH_CACHE_BOTH:
517 __asm__ __volatile__ (".chip 68060\n\t"
518 "cpushl %%bc,(%0)\n\t"
527 * We just want to jump to the first cache line
534 /* Recompute physical address when crossing a page
538 if ((paddr = virt_to_phys_060(addr)))
552 case FLUSH_SCOPE_PAGE:
553 len += (addr & ~PAGE_MASK) + (PAGE_SIZE - 1);
554 addr &= PAGE_MASK; /* Workaround for bug in some
555 revisions of the 68060 */
556 for (len >>= PAGE_SHIFT; len--; addr += PAGE_SIZE)
558 if (!(paddr = virt_to_phys_060(addr)))
562 case FLUSH_CACHE_DATA:
563 __asm__ __volatile__ (".chip 68060\n\t"
564 "cpushp %%dc,(%0)\n\t"
568 case FLUSH_CACHE_INSN:
569 __asm__ __volatile__ (".chip 68060\n\t"
570 "cpushp %%ic,(%0)\n\t"
575 case FLUSH_CACHE_BOTH:
576 __asm__ __volatile__ (".chip 68060\n\t"
577 "cpushp %%bc,(%0)\n\t"
588 /* sys_cacheflush -- flush (part of) the processor cache. */
590 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
592 struct vm_area_struct *vma;
596 if (scope < FLUSH_SCOPE_LINE || scope > FLUSH_SCOPE_ALL ||
597 cache & ~FLUSH_CACHE_BOTH)
600 if (scope == FLUSH_SCOPE_ALL) {
601 /* Only the superuser may explicitly flush the whole cache. */
603 if (!capable(CAP_SYS_ADMIN))
607 * Verify that the specified address region actually belongs
610 vma = find_vma (current->mm, addr);
612 /* Check for overflow. */
613 if (addr + len < addr)
615 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
619 if (CPU_IS_020_OR_030) {
620 if (scope == FLUSH_SCOPE_LINE && len < 256) {
622 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
623 if (cache & FLUSH_CACHE_INSN)
625 if (cache & FLUSH_CACHE_DATA)
629 __asm__ __volatile__ ("movec %1, %%caar\n\t"
632 : "r" (cacr), "r" (addr));
636 /* Flush the whole cache, even if page granularity requested. */
638 __asm__ ("movec %%cacr, %0" : "=r" (cacr));
639 if (cache & FLUSH_CACHE_INSN)
641 if (cache & FLUSH_CACHE_DATA)
643 __asm__ __volatile__ ("movec %0, %%cacr" : : "r" (cacr));
649 * 040 or 060: don't blindly trust 'scope', someone could
650 * try to flush a few megs of memory.
653 if (len>=3*PAGE_SIZE && scope<FLUSH_SCOPE_PAGE)
654 scope=FLUSH_SCOPE_PAGE;
655 if (len>=10*PAGE_SIZE && scope<FLUSH_SCOPE_ALL)
656 scope=FLUSH_SCOPE_ALL;
658 ret = cache_flush_040 (addr, scope, cache, len);
659 } else if (CPU_IS_060) {
660 ret = cache_flush_060 (addr, scope, cache, len);
668 asmlinkage int sys_getpagesize(void)