Greentime Hu | 1932fbe | 2017-10-25 10:37:49 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // Copyright (C) 2005-2017 Andes Technology Corporation |
| 3 | |
| 4 | #include <linux/syscalls.h> |
| 5 | #include <linux/uaccess.h> |
| 6 | |
| 7 | #include <asm/cachectl.h> |
| 8 | #include <asm/proc-fns.h> |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 9 | #include <asm/fpu.h> |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 10 | #include <asm/fp_udfiex_crtl.h> |
Greentime Hu | 1932fbe | 2017-10-25 10:37:49 +0800 | [diff] [blame] | 11 | |
| 12 | SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, |
| 13 | unsigned long, prot, unsigned long, flags, |
| 14 | unsigned long, fd, unsigned long, pgoff) |
| 15 | { |
| 16 | if (pgoff & (~PAGE_MASK >> 12)) |
| 17 | return -EINVAL; |
| 18 | |
| 19 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
| 20 | pgoff >> (PAGE_SHIFT - 12)); |
| 21 | } |
| 22 | |
| 23 | SYSCALL_DEFINE4(fadvise64_64_wrapper,int, fd, int, advice, loff_t, offset, |
| 24 | loff_t, len) |
| 25 | { |
| 26 | return sys_fadvise64_64(fd, offset, len, advice); |
| 27 | } |
| 28 | |
| 29 | SYSCALL_DEFINE3(cacheflush, unsigned int, start, unsigned int, end, int, cache) |
| 30 | { |
| 31 | struct vm_area_struct *vma; |
| 32 | bool flushi = true, wbd = true; |
| 33 | |
| 34 | vma = find_vma(current->mm, start); |
| 35 | if (!vma) |
| 36 | return -EFAULT; |
| 37 | switch (cache) { |
| 38 | case ICACHE: |
| 39 | wbd = false; |
| 40 | break; |
| 41 | case DCACHE: |
| 42 | flushi = false; |
| 43 | break; |
| 44 | case BCACHE: |
| 45 | break; |
| 46 | default: |
| 47 | return -EINVAL; |
| 48 | } |
| 49 | cpu_cache_wbinval_range_check(vma, start, end, flushi, wbd); |
| 50 | |
| 51 | return 0; |
| 52 | } |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 53 | |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 54 | SYSCALL_DEFINE2(fp_udfiex_crtl, unsigned int, cmd, unsigned int, act) |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 55 | { |
| 56 | #if IS_ENABLED(CONFIG_SUPPORT_DENORMAL_ARITHMETIC) |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 57 | int old_udf_iex; |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 58 | |
| 59 | if (!used_math()) { |
| 60 | load_fpu(&init_fpuregs); |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 61 | current->thread.fpu.UDF_IEX_trap = init_fpuregs.UDF_IEX_trap; |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 62 | set_used_math(); |
| 63 | } |
| 64 | |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 65 | old_udf_iex = current->thread.fpu.UDF_IEX_trap; |
| 66 | act &= (FPCSR_mskUDFE | FPCSR_mskIEXE); |
| 67 | |
| 68 | switch (cmd) { |
| 69 | case DISABLE_UDF_IEX_TRAP: |
| 70 | current->thread.fpu.UDF_IEX_trap &= ~act; |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 71 | break; |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 72 | case ENABLE_UDF_IEX_TRAP: |
| 73 | current->thread.fpu.UDF_IEX_trap |= act; |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 74 | break; |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 75 | case GET_UDF_IEX_TRAP: |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 76 | break; |
| 77 | default: |
| 78 | return -EINVAL; |
| 79 | } |
Vincent Chen | ed32949 | 2019-05-20 09:21:12 +0800 | [diff] [blame] | 80 | return old_udf_iex; |
Vincent Chen | 44e92e0 | 2018-11-22 11:14:36 +0800 | [diff] [blame] | 81 | #else |
| 82 | return -ENOTSUPP; |
| 83 | #endif |
| 84 | } |