xref: /openbmc/linux/arch/riscv/include/asm/jump_label.h (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
1ebc00ddeSEmil Renner Berthing /* SPDX-License-Identifier: GPL-2.0-only */
2ebc00ddeSEmil Renner Berthing /*
3ebc00ddeSEmil Renner Berthing  * Copyright (C) 2020 Emil Renner Berthing
4ebc00ddeSEmil Renner Berthing  *
5ebc00ddeSEmil Renner Berthing  * Based on arch/arm64/include/asm/jump_label.h
6ebc00ddeSEmil Renner Berthing  */
7ebc00ddeSEmil Renner Berthing #ifndef __ASM_JUMP_LABEL_H
8ebc00ddeSEmil Renner Berthing #define __ASM_JUMP_LABEL_H
9ebc00ddeSEmil Renner Berthing 
10ebc00ddeSEmil Renner Berthing #ifndef __ASSEMBLY__
11ebc00ddeSEmil Renner Berthing 
12ebc00ddeSEmil Renner Berthing #include <linux/types.h>
13ebc00ddeSEmil Renner Berthing #include <asm/asm.h>
14ebc00ddeSEmil Renner Berthing 
15ebc00ddeSEmil Renner Berthing #define JUMP_LABEL_NOP_SIZE 4
16ebc00ddeSEmil Renner Berthing 
arch_static_branch(struct static_key * const key,const bool branch)1789fd4a1dSJisheng Zhang static __always_inline bool arch_static_branch(struct static_key * const key,
1889fd4a1dSJisheng Zhang 					       const bool branch)
19ebc00ddeSEmil Renner Berthing {
20*aaff74d8SLinus Torvalds 	asm goto(
219ddfc3cdSAndy Chiu 		"	.align		2			\n\t"
22ebc00ddeSEmil Renner Berthing 		"	.option push				\n\t"
23ebc00ddeSEmil Renner Berthing 		"	.option norelax				\n\t"
24ebc00ddeSEmil Renner Berthing 		"	.option norvc				\n\t"
25ebc00ddeSEmil Renner Berthing 		"1:	nop					\n\t"
26ebc00ddeSEmil Renner Berthing 		"	.option pop				\n\t"
27ebc00ddeSEmil Renner Berthing 		"	.pushsection	__jump_table, \"aw\"	\n\t"
28ebc00ddeSEmil Renner Berthing 		"	.align		" RISCV_LGPTR "		\n\t"
29ebc00ddeSEmil Renner Berthing 		"	.long		1b - ., %l[label] - .	\n\t"
30ebc00ddeSEmil Renner Berthing 		"	" RISCV_PTR "	%0 - .			\n\t"
31ebc00ddeSEmil Renner Berthing 		"	.popsection				\n\t"
32ebc00ddeSEmil Renner Berthing 		:  :  "i"(&((char *)key)[branch]) :  : label);
33ebc00ddeSEmil Renner Berthing 
34ebc00ddeSEmil Renner Berthing 	return false;
35ebc00ddeSEmil Renner Berthing label:
36ebc00ddeSEmil Renner Berthing 	return true;
37ebc00ddeSEmil Renner Berthing }
38ebc00ddeSEmil Renner Berthing 
arch_static_branch_jump(struct static_key * const key,const bool branch)3989fd4a1dSJisheng Zhang static __always_inline bool arch_static_branch_jump(struct static_key * const key,
4089fd4a1dSJisheng Zhang 						    const bool branch)
41ebc00ddeSEmil Renner Berthing {
42*aaff74d8SLinus Torvalds 	asm goto(
439ddfc3cdSAndy Chiu 		"	.align		2			\n\t"
44ebc00ddeSEmil Renner Berthing 		"	.option push				\n\t"
45ebc00ddeSEmil Renner Berthing 		"	.option norelax				\n\t"
46ebc00ddeSEmil Renner Berthing 		"	.option norvc				\n\t"
47ebc00ddeSEmil Renner Berthing 		"1:	jal		zero, %l[label]		\n\t"
48ebc00ddeSEmil Renner Berthing 		"	.option pop				\n\t"
49ebc00ddeSEmil Renner Berthing 		"	.pushsection	__jump_table, \"aw\"	\n\t"
50ebc00ddeSEmil Renner Berthing 		"	.align		" RISCV_LGPTR "		\n\t"
51ebc00ddeSEmil Renner Berthing 		"	.long		1b - ., %l[label] - .	\n\t"
52ebc00ddeSEmil Renner Berthing 		"	" RISCV_PTR "	%0 - .			\n\t"
53ebc00ddeSEmil Renner Berthing 		"	.popsection				\n\t"
54ebc00ddeSEmil Renner Berthing 		:  :  "i"(&((char *)key)[branch]) :  : label);
55ebc00ddeSEmil Renner Berthing 
56ebc00ddeSEmil Renner Berthing 	return false;
57ebc00ddeSEmil Renner Berthing label:
58ebc00ddeSEmil Renner Berthing 	return true;
59ebc00ddeSEmil Renner Berthing }
60ebc00ddeSEmil Renner Berthing 
61ebc00ddeSEmil Renner Berthing #endif  /* __ASSEMBLY__ */
62ebc00ddeSEmil Renner Berthing #endif	/* __ASM_JUMP_LABEL_H */
63