1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2013 Huawei Ltd.
4  * Author: Jiang Liu <liuj97@gmail.com>
5  *
6  * Based on arch/arm/include/asm/jump_label.h
7  */
8 #ifndef __ASM_JUMP_LABEL_H
9 #define __ASM_JUMP_LABEL_H
10 
11 #ifndef __ASSEMBLY__
12 
13 #include <linux/types.h>
14 #include <asm/insn.h>
15 
16 #define HAVE_JUMP_LABEL_BATCH
17 #define JUMP_LABEL_NOP_SIZE		AARCH64_INSN_SIZE
18 
19 static __always_inline bool arch_static_branch(struct static_key * const key,
20 					       const bool branch)
21 {
22 	asm goto(
23 		"1:	nop					\n\t"
24 		 "	.pushsection	__jump_table, \"aw\"	\n\t"
25 		 "	.align		3			\n\t"
26 		 "	.long		1b - ., %l[l_yes] - .	\n\t"
27 		 "	.quad		%c0 - .			\n\t"
28 		 "	.popsection				\n\t"
29 		 :  :  "i"(&((char *)key)[branch]) :  : l_yes);
30 
31 	return false;
32 l_yes:
33 	return true;
34 }
35 
36 static __always_inline bool arch_static_branch_jump(struct static_key * const key,
37 						    const bool branch)
38 {
39 	asm goto(
40 		"1:	b		%l[l_yes]		\n\t"
41 		 "	.pushsection	__jump_table, \"aw\"	\n\t"
42 		 "	.align		3			\n\t"
43 		 "	.long		1b - ., %l[l_yes] - .	\n\t"
44 		 "	.quad		%c0 - .			\n\t"
45 		 "	.popsection				\n\t"
46 		 :  :  "i"(&((char *)key)[branch]) :  : l_yes);
47 
48 	return false;
49 l_yes:
50 	return true;
51 }
52 
53 #endif  /* __ASSEMBLY__ */
54 #endif	/* __ASM_JUMP_LABEL_H */
55