xref: /openbmc/linux/arch/powerpc/include/asm/jump_label.h (revision ec0c464cdbf38bf6ddabec8bfa595bd421cab203)
1ac5f89c7SMichael Ellerman #ifndef _ASM_POWERPC_JUMP_LABEL_H
2ac5f89c7SMichael Ellerman #define _ASM_POWERPC_JUMP_LABEL_H
3ac5f89c7SMichael Ellerman 
4ac5f89c7SMichael Ellerman /*
5ac5f89c7SMichael Ellerman  * Copyright 2010 Michael Ellerman, IBM Corp.
6ac5f89c7SMichael Ellerman  *
7ac5f89c7SMichael Ellerman  * This program is free software; you can redistribute it and/or
8ac5f89c7SMichael Ellerman  * modify it under the terms of the GNU General Public License
9ac5f89c7SMichael Ellerman  * as published by the Free Software Foundation; either version
10ac5f89c7SMichael Ellerman  * 2 of the License, or (at your option) any later version.
11ac5f89c7SMichael Ellerman  */
12ac5f89c7SMichael Ellerman 
13cc1adb5fSAnton Blanchard #ifndef __ASSEMBLY__
14ac5f89c7SMichael Ellerman #include <linux/types.h>
15ac5f89c7SMichael Ellerman 
16ac5f89c7SMichael Ellerman #include <asm/feature-fixups.h>
17*ec0c464cSChristophe Leroy #include <asm/asm-const.h>
18ac5f89c7SMichael Ellerman 
19ac5f89c7SMichael Ellerman #define JUMP_ENTRY_TYPE		stringify_in_c(FTR_ENTRY_LONG)
20ac5f89c7SMichael Ellerman #define JUMP_LABEL_NOP_SIZE	4
21ac5f89c7SMichael Ellerman 
2211276d53SPeter Zijlstra static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
23ac5f89c7SMichael Ellerman {
243f0116c3SIngo Molnar 	asm_volatile_goto("1:\n\t"
25e2985fd9SMichael Ellerman 		 "nop # arch_static_branch\n\t"
26ac5f89c7SMichael Ellerman 		 ".pushsection __jump_table,  \"aw\"\n\t"
27ac5f89c7SMichael Ellerman 		 JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
28ac5f89c7SMichael Ellerman 		 ".popsection \n\t"
2911276d53SPeter Zijlstra 		 : :  "i" (&((char *)key)[branch]) : : l_yes);
3011276d53SPeter Zijlstra 
3111276d53SPeter Zijlstra 	return false;
3211276d53SPeter Zijlstra l_yes:
3311276d53SPeter Zijlstra 	return true;
3411276d53SPeter Zijlstra }
3511276d53SPeter Zijlstra 
3611276d53SPeter Zijlstra static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
3711276d53SPeter Zijlstra {
3811276d53SPeter Zijlstra 	asm_volatile_goto("1:\n\t"
39e2985fd9SMichael Ellerman 		 "b %l[l_yes] # arch_static_branch_jump\n\t"
4011276d53SPeter Zijlstra 		 ".pushsection __jump_table,  \"aw\"\n\t"
4111276d53SPeter Zijlstra 		 JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
4211276d53SPeter Zijlstra 		 ".popsection \n\t"
4311276d53SPeter Zijlstra 		 : :  "i" (&((char *)key)[branch]) : : l_yes);
4411276d53SPeter Zijlstra 
45ac5f89c7SMichael Ellerman 	return false;
46ac5f89c7SMichael Ellerman l_yes:
47ac5f89c7SMichael Ellerman 	return true;
48ac5f89c7SMichael Ellerman }
49ac5f89c7SMichael Ellerman 
50ac5f89c7SMichael Ellerman #ifdef CONFIG_PPC64
51ac5f89c7SMichael Ellerman typedef u64 jump_label_t;
52ac5f89c7SMichael Ellerman #else
53ac5f89c7SMichael Ellerman typedef u32 jump_label_t;
54ac5f89c7SMichael Ellerman #endif
55ac5f89c7SMichael Ellerman 
56ac5f89c7SMichael Ellerman struct jump_entry {
57ac5f89c7SMichael Ellerman 	jump_label_t code;
58ac5f89c7SMichael Ellerman 	jump_label_t target;
59ac5f89c7SMichael Ellerman 	jump_label_t key;
60ac5f89c7SMichael Ellerman };
61ac5f89c7SMichael Ellerman 
62cc1adb5fSAnton Blanchard #else
63cc1adb5fSAnton Blanchard #define ARCH_STATIC_BRANCH(LABEL, KEY)		\
64cc1adb5fSAnton Blanchard 1098:	nop;					\
65cc1adb5fSAnton Blanchard 	.pushsection __jump_table, "aw";	\
66cc1adb5fSAnton Blanchard 	FTR_ENTRY_LONG 1098b, LABEL, KEY;	\
67cc1adb5fSAnton Blanchard 	.popsection
68cc1adb5fSAnton Blanchard #endif
69cc1adb5fSAnton Blanchard 
70ac5f89c7SMichael Ellerman #endif /* _ASM_POWERPC_JUMP_LABEL_H */
71