blob: 1f0e2e05b0563f0f1499d68e9beefb5202b09172 [file] [log] [blame]
Alexei Fedorovf41355c2019-09-13 14:11:59 +01001/*
Boyan Karatotev7a5246e2025-03-26 15:54:55 +00002 * Copyright (c) 2019-2025, Arm Limited. All rights reserved.
Alexei Fedorovf41355c2019-09-13 14:11:59 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <lib/el3_runtime/cpu_data.h>
10
11 .global pauth_init_enable_el1
12 .global pauth_disable_el1
13 .global pauth_init_enable_el3
14 .global pauth_disable_el3
15 .globl pauth_load_bl31_apiakey
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010016 .globl pauth_load_bl1_apiakey_enable
Alexei Fedorovf41355c2019-09-13 14:11:59 +010017
18/* -------------------------------------------------------------
19 * Program APIAKey_EL1 and enable pointer authentication in EL1
20 * -------------------------------------------------------------
21 */
22func pauth_init_enable_el1
23 stp x29, x30, [sp, #-16]!
24
25 /* Initialize platform key */
26 bl plat_init_apkey
27
28 /* Program instruction key A used by the Trusted Firmware */
29 msr APIAKeyLo_EL1, x0
30 msr APIAKeyHi_EL1, x1
31
32 /* Enable pointer authentication */
33 mrs x0, sctlr_el1
34 orr x0, x0, #SCTLR_EnIA_BIT
Alexei Fedorovf41355c2019-09-13 14:11:59 +010035 msr sctlr_el1, x0
36 isb
37
38 ldp x29, x30, [sp], #16
39 ret
40endfunc pauth_init_enable_el1
41
42/* -------------------------------------------------------------
Boyan Karatoteve7792e82023-03-06 14:45:15 +000043 * Disable pointer authentication in EL1
Alexei Fedorovf41355c2019-09-13 14:11:59 +010044 * -------------------------------------------------------------
45 */
46func pauth_disable_el1
47 mrs x0, sctlr_el1
48 bic x0, x0, #SCTLR_EnIA_BIT
49 msr sctlr_el1, x0
50 isb
51 ret
52endfunc pauth_disable_el1
53
54/* -------------------------------------------------------------
55 * Program APIAKey_EL1 and enable pointer authentication in EL3
56 * -------------------------------------------------------------
57 */
58func pauth_init_enable_el3
59 stp x29, x30, [sp, #-16]!
60
61 /* Initialize platform key */
62 bl plat_init_apkey
63
64 /* Program instruction key A used by the Trusted Firmware */
65 msr APIAKeyLo_EL1, x0
66 msr APIAKeyHi_EL1, x1
67
68 /* Enable pointer authentication */
69 mrs x0, sctlr_el3
70 orr x0, x0, #SCTLR_EnIA_BIT
Alexei Fedorovf41355c2019-09-13 14:11:59 +010071 msr sctlr_el3, x0
72 isb
73
74 ldp x29, x30, [sp], #16
75 ret
76endfunc pauth_init_enable_el3
77
78/* -------------------------------------------------------------
79 * Disable pointer authentication in EL3
80 * -------------------------------------------------------------
81 */
82func pauth_disable_el3
83 mrs x0, sctlr_el3
84 bic x0, x0, #SCTLR_EnIA_BIT
85 msr sctlr_el3, x0
86 isb
87 ret
88endfunc pauth_disable_el3
89
90/* -------------------------------------------------------------
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010091 * The following functions strictly follow the AArch64 PCS
Alexei Fedorovf41355c2019-09-13 14:11:59 +010092 * to use x9-x17 (temporary caller-saved registers) to load
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +010093 * the APIAKey_EL1 and enable pointer authentication.
Alexei Fedorovf41355c2019-09-13 14:11:59 +010094 * -------------------------------------------------------------
95 */
96func pauth_load_bl31_apiakey
97 /* tpidr_el3 contains the address of cpu_data structure */
98 mrs x9, tpidr_el3
99
100 /* Load apiakey from cpu_data */
101 ldp x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]
102
103 /* Program instruction key A */
104 msr APIAKeyLo_EL1, x10
105 msr APIAKeyHi_EL1, x11
106 isb
107 ret
108endfunc pauth_load_bl31_apiakey
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +0100109
110func pauth_load_bl1_apiakey_enable
111 /* Load instruction key A used by the Trusted Firmware */
112 adrp x9, bl1_apiakey
113 add x9, x9, :lo12:bl1_apiakey
114 ldp x10, x11, [x9]
115
116 /* Program instruction key A */
117 msr APIAKeyLo_EL1, x10
118 msr APIAKeyHi_EL1, x11
119
120 /* Enable pointer authentication */
121 mrs x9, sctlr_el3
122 orr x9, x9, #SCTLR_EnIA_BIT
Alexei Fedorov3dd9f2b2019-10-01 13:58:23 +0100123 msr sctlr_el3, x9
124 isb
125 ret
126endfunc pauth_load_bl1_apiakey_enable