xref: /openbmc/linux/arch/nios2/kernel/sys_nios2.c (revision e3d786a3)
1 /*
2  * Copyright (C) 2013 Altera Corporation
3  * Copyright (C) 2011-2012 Tobias Klauser <tklauser@distanz.ch>
4  * Copyright (C) 2004 Microtronix Datacom Ltd.
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file "COPYING" in the main directory of this archive
8  * for more details.
9  */
10 
11 #include <linux/export.h>
12 #include <linux/file.h>
13 #include <linux/fs.h>
14 #include <linux/slab.h>
15 #include <linux/syscalls.h>
16 
17 #include <asm/cacheflush.h>
18 #include <asm/traps.h>
19 
20 /* sys_cacheflush -- flush the processor cache. */
21 asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
22 				unsigned int op)
23 {
24 	struct vm_area_struct *vma;
25 
26 	if (len == 0)
27 		return 0;
28 
29 	/* We only support op 0 now, return error if op is non-zero.*/
30 	if (op)
31 		return -EINVAL;
32 
33 	/* Check for overflow */
34 	if (addr + len < addr)
35 		return -EFAULT;
36 
37 	/*
38 	 * Verify that the specified address region actually belongs
39 	 * to this process.
40 	 */
41 	vma = find_vma(current->mm, addr);
42 	if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
43 		return -EFAULT;
44 
45 	flush_cache_range(vma, addr, addr + len);
46 
47 	return 0;
48 }
49 
50 asmlinkage int sys_getpagesize(void)
51 {
52 	return PAGE_SIZE;
53 }
54