xref: /linux/arch/loongarch/include/asm/jump_label.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1f02644e3SYouling Tang /* SPDX-License-Identifier: GPL-2.0-only */
2f02644e3SYouling Tang /*
3f02644e3SYouling Tang  * Copyright (C) 2023 Loongson Technology Corporation Limited
4f02644e3SYouling Tang  *
5f02644e3SYouling Tang  * Based on arch/arm64/include/asm/jump_label.h
6f02644e3SYouling Tang  */
7f02644e3SYouling Tang #ifndef __ASM_JUMP_LABEL_H
8f02644e3SYouling Tang #define __ASM_JUMP_LABEL_H
9f02644e3SYouling Tang 
10f02644e3SYouling Tang #ifndef __ASSEMBLY__
11f02644e3SYouling Tang 
12f02644e3SYouling Tang #include <linux/types.h>
13f02644e3SYouling Tang 
14f02644e3SYouling Tang #define JUMP_LABEL_NOP_SIZE	4
15f02644e3SYouling Tang 
16f02644e3SYouling Tang #define JUMP_TABLE_ENTRY				\
17f02644e3SYouling Tang 	 ".pushsection	__jump_table, \"aw\"	\n\t"	\
18f02644e3SYouling Tang 	 ".align	3			\n\t"	\
19f02644e3SYouling Tang 	 ".long		1b - ., %l[l_yes] - .	\n\t"	\
20f02644e3SYouling Tang 	 ".quad		%0 - .			\n\t"	\
21f02644e3SYouling Tang 	 ".popsection				\n\t"
22f02644e3SYouling Tang 
arch_static_branch(struct static_key * const key,const bool branch)23f02644e3SYouling Tang static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
24f02644e3SYouling Tang {
25*4356e9f8SLinus Torvalds 	asm goto(
26f02644e3SYouling Tang 		"1:	nop			\n\t"
27f02644e3SYouling Tang 		JUMP_TABLE_ENTRY
28f02644e3SYouling Tang 		:  :  "i"(&((char *)key)[branch]) :  : l_yes);
29f02644e3SYouling Tang 
30f02644e3SYouling Tang 	return false;
31f02644e3SYouling Tang 
32f02644e3SYouling Tang l_yes:
33f02644e3SYouling Tang 	return true;
34f02644e3SYouling Tang }
35f02644e3SYouling Tang 
arch_static_branch_jump(struct static_key * const key,const bool branch)36f02644e3SYouling Tang static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
37f02644e3SYouling Tang {
38*4356e9f8SLinus Torvalds 	asm goto(
39f02644e3SYouling Tang 		"1:	b	%l[l_yes]	\n\t"
40f02644e3SYouling Tang 		JUMP_TABLE_ENTRY
41f02644e3SYouling Tang 		:  :  "i"(&((char *)key)[branch]) :  : l_yes);
42f02644e3SYouling Tang 
43f02644e3SYouling Tang 	return false;
44f02644e3SYouling Tang 
45f02644e3SYouling Tang l_yes:
46f02644e3SYouling Tang 	return true;
47f02644e3SYouling Tang }
48f02644e3SYouling Tang 
49f02644e3SYouling Tang #endif  /* __ASSEMBLY__ */
50f02644e3SYouling Tang #endif	/* __ASM_JUMP_LABEL_H */
51