Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 25 | struct mm_struct *mm = current->mm; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 26 | |
| 27 | if (len == 0) |
| 28 | return 0; |
| 29 | |
| 30 | /* We only support op 0 now, return error if op is non-zero.*/ |
| 31 | if (op) |
| 32 | return -EINVAL; |
| 33 | |
| 34 | /* Check for overflow */ |
| 35 | if (addr + len < addr) |
| 36 | return -EFAULT; |
| 37 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 38 | if (mmap_read_lock_killable(mm)) |
| 39 | return -EINTR; |
| 40 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 41 | /* |
| 42 | * Verify that the specified address region actually belongs |
| 43 | * to this process. |
| 44 | */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 45 | vma = find_vma(mm, addr); |
| 46 | if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) { |
| 47 | mmap_read_unlock(mm); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 48 | return -EFAULT; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 49 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 50 | |
| 51 | flush_cache_range(vma, addr, addr + len); |
| 52 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 53 | mmap_read_unlock(mm); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | asmlinkage int sys_getpagesize(void) |
| 58 | { |
| 59 | return PAGE_SIZE; |
| 60 | } |