Alexei Fedorov | 719714f | 2019-10-03 10:57:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | |
| 10 | .global pauth_init_enable |
Alexei Fedorov | 52fd733 | 2020-01-08 14:02:18 +0000 | [diff] [blame] | 11 | .global pauth_disable |
Alexei Fedorov | 719714f | 2019-10-03 10:57:53 +0100 | [diff] [blame] | 12 | |
| 13 | /* ----------------------------------------------------------- |
| 14 | * Program APIAKey_EL1 key and enable Pointer Authentication |
| 15 | * of instruction addresses in the current translation regime |
| 16 | * for the calling CPU. |
| 17 | * ----------------------------------------------------------- |
| 18 | */ |
| 19 | func pauth_init_enable |
| 20 | stp x29, x30, [sp, #-16]! |
| 21 | |
| 22 | /* Initialize platform key */ |
| 23 | bl init_apkey |
| 24 | |
| 25 | /* |
| 26 | * Program instruction key A used by |
| 27 | * the Trusted Firmware Test Framework |
| 28 | */ |
| 29 | msr APIAKeyLo_EL1, x0 |
| 30 | msr APIAKeyHi_EL1, x1 |
| 31 | |
| 32 | /* Detect Current Exception level */ |
| 33 | mrs x0, CurrentEL |
| 34 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 35 | b.eq enable_el1 |
| 36 | |
| 37 | /* Enable EL2 pointer authentication */ |
| 38 | mrs x0, sctlr_el2 |
| 39 | orr x0, x0, #SCTLR_EnIA_BIT |
| 40 | msr sctlr_el2, x0 |
| 41 | b enable_exit |
| 42 | |
| 43 | /* Enable EL1 pointer authentication */ |
| 44 | enable_el1: |
| 45 | mrs x0, sctlr_el1 |
| 46 | orr x0, x0, #SCTLR_EnIA_BIT |
| 47 | msr sctlr_el1, x0 |
| 48 | |
| 49 | enable_exit: |
| 50 | isb |
| 51 | |
| 52 | ldp x29, x30, [sp], #16 |
| 53 | ret |
| 54 | endfunc pauth_init_enable |
Alexei Fedorov | 52fd733 | 2020-01-08 14:02:18 +0000 | [diff] [blame] | 55 | |
| 56 | /* ----------------------------------------------------------- |
| 57 | * Disable pointer authentication in EL1/EL2 |
| 58 | * ----------------------------------------------------------- |
| 59 | */ |
| 60 | func pauth_disable |
| 61 | /* Detect Current Exception level */ |
| 62 | mrs x0, CurrentEL |
| 63 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 64 | b.eq disable_el1 |
| 65 | |
| 66 | /* Disable EL2 pointer authentication */ |
| 67 | mrs x0, sctlr_el2 |
| 68 | bic x0, x0, #SCTLR_EnIA_BIT |
| 69 | msr sctlr_el2, x0 |
| 70 | isb |
| 71 | ret |
| 72 | |
| 73 | /* Disable EL1 pointer authentication */ |
| 74 | disable_el1: |
| 75 | mrs x0, sctlr_el1 |
| 76 | bic x0, x0, #SCTLR_EnIA_BIT |
| 77 | msr sctlr_el1, x0 |
| 78 | isb |
| 79 | ret |
| 80 | endfunc pauth_disable |