1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (c) 2010 Cavium Networks, Inc.
7  */
8 #ifndef _ASM_MIPS_JUMP_LABEL_H
9 #define _ASM_MIPS_JUMP_LABEL_H
10 
11 #ifndef __ASSEMBLY__
12 
13 #include <linux/types.h>
14 #include <asm/isa-rev.h>
15 
16 #define JUMP_LABEL_NOP_SIZE 4
17 
18 #ifdef CONFIG_64BIT
19 #define WORD_INSN ".dword"
20 #else
21 #define WORD_INSN ".word"
22 #endif
23 
24 #ifdef CONFIG_CPU_MICROMIPS
25 # define B_INSN "b32"
26 # define J_INSN "j32"
27 #elif MIPS_ISA_REV >= 6
28 # define B_INSN "bc"
29 # define J_INSN "bc"
30 #else
31 # define B_INSN "b"
32 # define J_INSN "j"
33 #endif
34 
arch_static_branch(struct static_key * key,bool branch)35 static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
36 {
37 	asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
38 		"2:\t.insn\n\t"
39 		".pushsection __jump_table,  \"aw\"\n\t"
40 		WORD_INSN " 1b, %l[l_yes], %0\n\t"
41 		".popsection\n\t"
42 		: :  "i" (&((char *)key)[branch]) : : l_yes);
43 
44 	return false;
45 l_yes:
46 	return true;
47 }
48 
arch_static_branch_jump(struct static_key * key,bool branch)49 static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
50 {
51 	asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
52 		".pushsection __jump_table,  \"aw\"\n\t"
53 		WORD_INSN " 1b, %l[l_yes], %0\n\t"
54 		".popsection\n\t"
55 		: :  "i" (&((char *)key)[branch]) : : l_yes);
56 
57 	return false;
58 l_yes:
59 	return true;
60 }
61 
62 #ifdef CONFIG_64BIT
63 typedef u64 jump_label_t;
64 #else
65 typedef u32 jump_label_t;
66 #endif
67 
68 struct jump_entry {
69 	jump_label_t code;
70 	jump_label_t target;
71 	jump_label_t key;
72 };
73 
74 #endif  /* __ASSEMBLY__ */
75 #endif /* _ASM_MIPS_JUMP_LABEL_H */
76