xref: /linux/arch/arm64/include/asm/jump_label.h (revision f5c31bcf604db54470868f3118a60dc4a9ba8813)
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 JUMP_LABEL_NOP_SIZE		AARCH64_INSN_SIZE
17 
18 static __always_inline bool arch_static_branch(struct static_key * const key,
19 					       const bool branch)
20 {
21 	asm goto(
22 		"1:	nop					\n\t"
23 		 "	.pushsection	__jump_table, \"aw\"	\n\t"
24 		 "	.align		3			\n\t"
25 		 "	.long		1b - ., %l[l_yes] - .	\n\t"
26 		 "	.quad		%c0 - .			\n\t"
27 		 "	.popsection				\n\t"
28 		 :  :  "i"(&((char *)key)[branch]) :  : l_yes);
29 
30 	return false;
31 l_yes:
32 	return true;
33 }
34 
35 static __always_inline bool arch_static_branch_jump(struct static_key * const key,
36 						    const bool branch)
37 {
38 	asm goto(
39 		"1:	b		%l[l_yes]		\n\t"
40 		 "	.pushsection	__jump_table, \"aw\"	\n\t"
41 		 "	.align		3			\n\t"
42 		 "	.long		1b - ., %l[l_yes] - .	\n\t"
43 		 "	.quad		%c0 - .			\n\t"
44 		 "	.popsection				\n\t"
45 		 :  :  "i"(&((char *)key)[branch]) :  : l_yes);
46 
47 	return false;
48 l_yes:
49 	return true;
50 }
51 
52 #endif  /* __ASSEMBLY__ */
53 #endif	/* __ASM_JUMP_LABEL_H */
54