1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/arch/sh/kernel/sys_sh.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * This file contains various random system calls that
61da177e4SLinus Torvalds * have a non-standard calling sequence on the Linux/SuperH
71da177e4SLinus Torvalds * platform.
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * Taken from i386 version.
101da177e4SLinus Torvalds */
111da177e4SLinus Torvalds #include <linux/errno.h>
121da177e4SLinus Torvalds #include <linux/sched.h>
131da177e4SLinus Torvalds #include <linux/mm.h>
141da177e4SLinus Torvalds #include <linux/smp.h>
151da177e4SLinus Torvalds #include <linux/sem.h>
161da177e4SLinus Torvalds #include <linux/msg.h>
171da177e4SLinus Torvalds #include <linux/shm.h>
181da177e4SLinus Torvalds #include <linux/stat.h>
191da177e4SLinus Torvalds #include <linux/syscalls.h>
201da177e4SLinus Torvalds #include <linux/mman.h>
211da177e4SLinus Torvalds #include <linux/file.h>
221da177e4SLinus Torvalds #include <linux/utsname.h>
23f3c25758SPaul Mundt #include <linux/module.h>
24e06c4e57SPaul Mundt #include <linux/fs.h>
25cba4fbbfSAdrian Bunk #include <linux/ipc.h>
26fa43972fSPaul Mundt #include <asm/syscalls.h>
277c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
28fe74290dSArnd Bergmann #include <asm/unistd.h>
296d243dd3SStuart Menefy #include <asm/cacheflush.h>
306d243dd3SStuart Menefy #include <asm/cachectl.h>
311da177e4SLinus Torvalds
old_mmap(unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,int fd,unsigned long off)321da177e4SLinus Torvalds asmlinkage int old_mmap(unsigned long addr, unsigned long len,
331da177e4SLinus Torvalds unsigned long prot, unsigned long flags,
341da177e4SLinus Torvalds int fd, unsigned long off)
351da177e4SLinus Torvalds {
361da177e4SLinus Torvalds if (off & ~PAGE_MASK)
371da177e4SLinus Torvalds return -EINVAL;
38a90f590aSDominik Brodowski return ksys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
391da177e4SLinus Torvalds }
401da177e4SLinus Torvalds
sys_mmap2(unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long pgoff)411da177e4SLinus Torvalds asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
421da177e4SLinus Torvalds unsigned long prot, unsigned long flags,
431da177e4SLinus Torvalds unsigned long fd, unsigned long pgoff)
441da177e4SLinus Torvalds {
458c31813fSToshinobu Sugioka /*
468c31813fSToshinobu Sugioka * The shift for mmap2 is constant, regardless of PAGE_SIZE
478c31813fSToshinobu Sugioka * setting.
488c31813fSToshinobu Sugioka */
498c31813fSToshinobu Sugioka if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
508c31813fSToshinobu Sugioka return -EINVAL;
518c31813fSToshinobu Sugioka
528c31813fSToshinobu Sugioka pgoff >>= PAGE_SHIFT - 12;
538c31813fSToshinobu Sugioka
54a90f590aSDominik Brodowski return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
551da177e4SLinus Torvalds }
561da177e4SLinus Torvalds
576d243dd3SStuart Menefy /* sys_cacheflush -- flush (part of) the processor cache. */
sys_cacheflush(unsigned long addr,unsigned long len,int op)586d243dd3SStuart Menefy asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
596d243dd3SStuart Menefy {
606d243dd3SStuart Menefy struct vm_area_struct *vma;
616d243dd3SStuart Menefy
62788e6af3SGiuseppe Cavallaro if ((op <= 0) || (op > (CACHEFLUSH_D_PURGE|CACHEFLUSH_I)))
636d243dd3SStuart Menefy return -EINVAL;
646d243dd3SStuart Menefy
656d243dd3SStuart Menefy /*
666d243dd3SStuart Menefy * Verify that the specified address region actually belongs
676d243dd3SStuart Menefy * to this process.
686d243dd3SStuart Menefy */
696d243dd3SStuart Menefy if (addr + len < addr)
706d243dd3SStuart Menefy return -EFAULT;
716d243dd3SStuart Menefy
72*d8ed45c5SMichel Lespinasse mmap_read_lock(current->mm);
736d243dd3SStuart Menefy vma = find_vma (current->mm, addr);
746d243dd3SStuart Menefy if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) {
75*d8ed45c5SMichel Lespinasse mmap_read_unlock(current->mm);
766d243dd3SStuart Menefy return -EFAULT;
776d243dd3SStuart Menefy }
786d243dd3SStuart Menefy
796d243dd3SStuart Menefy switch (op & CACHEFLUSH_D_PURGE) {
806d243dd3SStuart Menefy case CACHEFLUSH_D_INVAL:
816d243dd3SStuart Menefy __flush_invalidate_region((void *)addr, len);
826d243dd3SStuart Menefy break;
836d243dd3SStuart Menefy case CACHEFLUSH_D_WB:
846d243dd3SStuart Menefy __flush_wback_region((void *)addr, len);
856d243dd3SStuart Menefy break;
866d243dd3SStuart Menefy case CACHEFLUSH_D_PURGE:
876d243dd3SStuart Menefy __flush_purge_region((void *)addr, len);
886d243dd3SStuart Menefy break;
896d243dd3SStuart Menefy }
906d243dd3SStuart Menefy
916d243dd3SStuart Menefy if (op & CACHEFLUSH_I)
92a6786fdaSGiuseppe CAVALLARO flush_icache_range(addr, addr+len);
936d243dd3SStuart Menefy
94*d8ed45c5SMichel Lespinasse mmap_read_unlock(current->mm);
956d243dd3SStuart Menefy return 0;
966d243dd3SStuart Menefy }
97