xref: /linux/arch/powerpc/include/asm/jump_label.h (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_JUMP_LABEL_H
3 #define _ASM_POWERPC_JUMP_LABEL_H
4 
5 /*
6  * Copyright 2010 Michael Ellerman, IBM Corp.
7  */
8 
9 #ifndef __ASSEMBLER__
10 #include <linux/types.h>
11 
12 #include <asm/feature-fixups.h>
13 #include <asm/asm-const.h>
14 
15 #define JUMP_ENTRY_TYPE		stringify_in_c(FTR_ENTRY_LONG)
16 #define JUMP_LABEL_NOP_SIZE	4
17 
18 #define JUMP_TABLE_ENTRY(key, label)			\
19 	".pushsection __jump_table,  \"aw\"	\n\t"	\
20 	".long 1b - ., " label " - .		\n\t"	\
21 	JUMP_ENTRY_TYPE key " - .		\n\t"	\
22 	".popsection 				\n\t"
23 
24 #define ARCH_STATIC_BRANCH_ASM(key, label)		\
25 	"1:	nop				\n\t"	\
26 	JUMP_TABLE_ENTRY(key, label)
27 
28 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
29 {
30 	asm goto(
31 		 ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
32 		 : :  "i" (&((char *)key)[branch]) : : l_yes);
33 
34 	return false;
35 l_yes:
36 	return true;
37 }
38 
39 static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
40 {
41 	asm goto("1:\n\t"
42 		 "b %l[l_yes] # arch_static_branch_jump\n\t"
43 		 JUMP_TABLE_ENTRY("%c0", "%l[l_yes]")
44 		 : :  "i" (&((char *)key)[branch]) : : l_yes);
45 
46 	return false;
47 l_yes:
48 	return true;
49 }
50 
51 #else
52 #define ARCH_STATIC_BRANCH(LABEL, KEY)		\
53 1098:	nop;					\
54 	.pushsection __jump_table, "aw";	\
55 	.long 1098b - ., LABEL - .;		\
56 	FTR_ENTRY_LONG KEY - .;			\
57 	.popsection
58 #endif
59 
60 #endif /* _ASM_POWERPC_JUMP_LABEL_H */
61