Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 ARM Ltd. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/linkage.h> |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 18 | |
| 19 | #include <asm/alternative.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 20 | #include <asm/assembler.h> |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 21 | #include <asm/cache.h> |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 22 | #include <asm/cpufeature.h> |
| 23 | #include <asm/sysreg.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Copy to user space from a kernel buffer (alignment handled by the hardware) |
| 27 | * |
| 28 | * Parameters: |
| 29 | * x0 - to |
| 30 | * x1 - from |
| 31 | * x2 - n |
| 32 | * Returns: |
| 33 | * x0 - bytes not copied |
| 34 | */ |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 35 | .macro ldrb1 ptr, regB, val |
| 36 | ldrb \ptr, [\regB], \val |
| 37 | .endm |
| 38 | |
| 39 | .macro strb1 ptr, regB, val |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 40 | uao_user_alternative 9998f, strb, sttrb, \ptr, \regB, \val |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 41 | .endm |
| 42 | |
| 43 | .macro ldrh1 ptr, regB, val |
| 44 | ldrh \ptr, [\regB], \val |
| 45 | .endm |
| 46 | |
| 47 | .macro strh1 ptr, regB, val |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 48 | uao_user_alternative 9998f, strh, sttrh, \ptr, \regB, \val |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 49 | .endm |
| 50 | |
| 51 | .macro ldr1 ptr, regB, val |
| 52 | ldr \ptr, [\regB], \val |
| 53 | .endm |
| 54 | |
| 55 | .macro str1 ptr, regB, val |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 56 | uao_user_alternative 9998f, str, sttr, \ptr, \regB, \val |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 57 | .endm |
| 58 | |
| 59 | .macro ldp1 ptr, regB, regC, val |
| 60 | ldp \ptr, \regB, [\regC], \val |
| 61 | .endm |
| 62 | |
| 63 | .macro stp1 ptr, regB, regC, val |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 64 | uao_stp 9998f, \ptr, \regB, \regC, \val |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 65 | .endm |
| 66 | |
| 67 | end .req x5 |
Yang Shi | bffe1ba | 2016-06-08 14:40:56 -0700 | [diff] [blame] | 68 | ENTRY(__arch_copy_to_user) |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 69 | ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(0)), ARM64_ALT_PAN_NOT_UAO, \ |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 70 | CONFIG_ARM64_PAN) |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 71 | add end, x0, x2 |
| 72 | #include "copy_template.S" |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 73 | ALTERNATIVE("nop", __stringify(SET_PSTATE_PAN(1)), ARM64_ALT_PAN_NOT_UAO, \ |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 74 | CONFIG_ARM64_PAN) |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 75 | mov x0, #0 |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 76 | ret |
Yang Shi | bffe1ba | 2016-06-08 14:40:56 -0700 | [diff] [blame] | 77 | ENDPROC(__arch_copy_to_user) |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 78 | |
| 79 | .section .fixup,"ax" |
| 80 | .align 2 |
Feng Kan | 4042688 | 2015-09-23 11:55:39 -0700 | [diff] [blame] | 81 | 9998: sub x0, end, dst // bytes not copied |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 82 | ret |
| 83 | .previous |