blob: 8c6a350df751a97779cfe7030054b416203f9d9a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/sh/kernel/sys_sh.c
3 *
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/SuperH
6 * platform.
7 *
8 * Taken from i386 version.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/errno.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#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>
Paul Mundtf3c25752006-09-27 18:36:17 +090022#include <linux/module.h>
Paul Mundte06c4e52007-07-31 13:01:43 +090023#include <linux/fs.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070024#include <linux/ipc.h>
Paul Mundtfa439722008-09-04 18:53:58 +090025#include <asm/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/uaccess.h>
Arnd Bergmannfe742902006-10-02 02:18:34 -070027#include <asm/unistd.h>
Stuart Menefy6d243dd2009-08-24 18:16:56 +090028#include <asm/cacheflush.h>
29#include <asm/cachectl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031asmlinkage int old_mmap(unsigned long addr, unsigned long len,
32 unsigned long prot, unsigned long flags,
33 int fd, unsigned long off)
34{
35 if (off & ~PAGE_MASK)
36 return -EINVAL;
Al Virof8b72562009-11-30 17:37:04 -050037 return sys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
41 unsigned long prot, unsigned long flags,
42 unsigned long fd, unsigned long pgoff)
43{
Toshinobu Sugioka8c318132009-04-21 07:34:53 +090044 /*
45 * The shift for mmap2 is constant, regardless of PAGE_SIZE
46 * setting.
47 */
48 if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
49 return -EINVAL;
50
51 pgoff >>= PAGE_SHIFT - 12;
52
Al Virof8b72562009-11-30 17:37:04 -050053 return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Stuart Menefy6d243dd2009-08-24 18:16:56 +090056/* sys_cacheflush -- flush (part of) the processor cache. */
57asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
58{
59 struct vm_area_struct *vma;
60
Giuseppe Cavallaro788e6af2009-08-24 18:59:09 +090061 if ((op <= 0) || (op > (CACHEFLUSH_D_PURGE|CACHEFLUSH_I)))
Stuart Menefy6d243dd2009-08-24 18:16:56 +090062 return -EINVAL;
63
64 /*
65 * Verify that the specified address region actually belongs
66 * to this process.
67 */
68 if (addr + len < addr)
69 return -EFAULT;
70
71 down_read(&current->mm->mmap_sem);
72 vma = find_vma (current->mm, addr);
73 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) {
74 up_read(&current->mm->mmap_sem);
75 return -EFAULT;
76 }
77
78 switch (op & CACHEFLUSH_D_PURGE) {
79 case CACHEFLUSH_D_INVAL:
80 __flush_invalidate_region((void *)addr, len);
81 break;
82 case CACHEFLUSH_D_WB:
83 __flush_wback_region((void *)addr, len);
84 break;
85 case CACHEFLUSH_D_PURGE:
86 __flush_purge_region((void *)addr, len);
87 break;
88 }
89
90 if (op & CACHEFLUSH_I)
Giuseppe CAVALLAROa6786fd2010-11-17 06:51:08 +000091 flush_icache_range(addr, addr+len);
Stuart Menefy6d243dd2009-08-24 18:16:56 +090092
93 up_read(&current->mm->mmap_sem);
94 return 0;
95}