1419b0af8Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
2419b0af8Sopenharmony_ci/*
3419b0af8Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
4419b0af8Sopenharmony_ci *
5419b0af8Sopenharmony_ci * Pointer authentication keys initialisation.
6419b0af8Sopenharmony_ci */
7419b0af8Sopenharmony_ci
8419b0af8Sopenharmony_ci#ifndef __ASM_POINTER_AUTH_KEY_H
9419b0af8Sopenharmony_ci#define __ASM_POINTER_AUTH_KEY_H
10419b0af8Sopenharmony_ci
11419b0af8Sopenharmony_ci#include <asm/alternative.h>
12419b0af8Sopenharmony_ci#include <asm/asm-offsets.h>
13419b0af8Sopenharmony_ci#include <asm/cpucaps.h>
14419b0af8Sopenharmony_ci#include <asm/sysreg.h>
15419b0af8Sopenharmony_ci
16419b0af8Sopenharmony_ci	.macro __ptrauth_address_keys_install_kernel tmp1, tmp2, tmp3
17419b0af8Sopenharmony_ci	ldp	\tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APIB]
18419b0af8Sopenharmony_ci	msr_s	SYS_APIBKEYLO_EL1, \tmp2
19419b0af8Sopenharmony_ci	msr_s	SYS_APIBKEYHI_EL1, \tmp3
20419b0af8Sopenharmony_ci
21419b0af8Sopenharmony_ci	adr_l	\tmp1, kernel_common_keys
22419b0af8Sopenharmony_ci	ldp	\tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APIA]
23419b0af8Sopenharmony_ci	msr_s	SYS_APIAKEYLO_EL1, \tmp2
24419b0af8Sopenharmony_ci	msr_s	SYS_APIAKEYHI_EL1, \tmp3
25419b0af8Sopenharmony_ci
26419b0af8Sopenharmony_ci	ldp	\tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APDA]
27419b0af8Sopenharmony_ci	msr_s	SYS_APDAKEYLO_EL1, \tmp2
28419b0af8Sopenharmony_ci	msr_s	SYS_APDAKEYHI_EL1, \tmp3
29419b0af8Sopenharmony_ci
30419b0af8Sopenharmony_ci	ldp	\tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APDB]
31419b0af8Sopenharmony_ci	msr_s	SYS_APDBKEYLO_EL1, \tmp2
32419b0af8Sopenharmony_ci	msr_s	SYS_APDBKEYHI_EL1, \tmp3
33419b0af8Sopenharmony_ci	.endm
34419b0af8Sopenharmony_ci
35419b0af8Sopenharmony_ci	.macro __ptrauth_generic_key_install_kernel tmp1, tmp2, tmp3
36419b0af8Sopenharmony_ci	ldp	\tmp2, \tmp3, [\tmp1, #PTRAUTH_KERNEL_KEY_APGA]
37419b0af8Sopenharmony_ci	msr_s	SYS_APGAKEYLO_EL1, \tmp2
38419b0af8Sopenharmony_ci	msr_s	SYS_APGAKEYHI_EL1, \tmp3
39419b0af8Sopenharmony_ci	.endm
40419b0af8Sopenharmony_ci
41419b0af8Sopenharmony_ci	.macro ptrauth_keys_install_kernel_all tsk, tmp1, tmp2, tmp3
42419b0af8Sopenharmony_ci	mov	\tmp1, #THREAD_KEYS_KERNEL
43419b0af8Sopenharmony_ci	add	\tmp1, \tsk, \tmp1
44419b0af8Sopenharmony_ci
45419b0af8Sopenharmony_cialternative_if_not ARM64_HAS_ADDRESS_AUTH
46419b0af8Sopenharmony_ci	b	.Lno_addr_auth\@
47419b0af8Sopenharmony_cialternative_else_nop_endif
48419b0af8Sopenharmony_ci	__ptrauth_address_keys_install_kernel \tmp1, \tmp2, \tmp3
49419b0af8Sopenharmony_ci
50419b0af8Sopenharmony_ci.Lno_addr_auth\@:
51419b0af8Sopenharmony_cialternative_if ARM64_HAS_GENERIC_AUTH
52419b0af8Sopenharmony_ci	__ptrauth_generic_key_install_kernel \tmp1, \tmp2, \tmp3
53419b0af8Sopenharmony_cialternative_else_nop_endif
54419b0af8Sopenharmony_ci	isb
55419b0af8Sopenharmony_ci	.endm
56419b0af8Sopenharmony_ci
57419b0af8Sopenharmony_ci	.macro __ptrauth_keys_install_kernel_all tsk, tmp1, tmp2, tmp3
58419b0af8Sopenharmony_ci	mov	\tmp1, #THREAD_KEYS_KERNEL
59419b0af8Sopenharmony_ci	add	\tmp1, \tsk, \tmp1
60419b0af8Sopenharmony_ci	__ptrauth_address_keys_install_kernel \tmp1, \tmp2, \tmp3
61419b0af8Sopenharmony_ci	__ptrauth_generic_key_install_kernel \tmp1, \tmp2, \tmp3
62419b0af8Sopenharmony_ci	.endm
63419b0af8Sopenharmony_ci
64419b0af8Sopenharmony_ci#endif
65