jump_label: make initial NOP patching the special case
[linux-2.6-block.git] / arch / mips / include / asm / jump_label.h
CommitLineData
94bb0c1a
DD
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
7e6b9db2
AB
11#define arch_jump_label_transform_static arch_jump_label_transform
12
55dd0df7 13#ifndef __ASSEMBLY__
94bb0c1a 14
55dd0df7 15#include <linux/types.h>
9b6584e3 16#include <asm/isa-rev.h>
94bb0c1a
DD
17
18#define JUMP_LABEL_NOP_SIZE 4
19
20#ifdef CONFIG_64BIT
21#define WORD_INSN ".dword"
22#else
23#define WORD_INSN ".word"
24#endif
25
935c2dbe 26#ifdef CONFIG_CPU_MICROMIPS
9b6584e3
PB
27# define B_INSN "b32"
28# define J_INSN "j32"
29#elif MIPS_ISA_REV >= 6
30# define B_INSN "bc"
31# define J_INSN "bc"
935c2dbe 32#else
9b6584e3
PB
33# define B_INSN "b"
34# define J_INSN "j"
935c2dbe
MR
35#endif
36
11276d53 37static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
d430d3d7 38{
47c25036 39 asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
c838b580 40 "2:\t.insn\n\t"
d430d3d7
JB
41 ".pushsection __jump_table, \"aw\"\n\t"
42 WORD_INSN " 1b, %l[l_yes], %0\n\t"
43 ".popsection\n\t"
11276d53
PZ
44 : : "i" (&((char *)key)[branch]) : : l_yes);
45
46 return false;
47l_yes:
48 return true;
49}
50
51static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
52{
9b6584e3 53 asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
11276d53
PZ
54 ".pushsection __jump_table, \"aw\"\n\t"
55 WORD_INSN " 1b, %l[l_yes], %0\n\t"
56 ".popsection\n\t"
57 : : "i" (&((char *)key)[branch]) : : l_yes);
58
d430d3d7
JB
59 return false;
60l_yes:
61 return true;
62}
94bb0c1a 63
94bb0c1a
DD
64#ifdef CONFIG_64BIT
65typedef u64 jump_label_t;
66#else
67typedef u32 jump_label_t;
68#endif
69
70struct jump_entry {
71 jump_label_t code;
72 jump_label_t target;
73 jump_label_t key;
74};
75
55dd0df7 76#endif /* __ASSEMBLY__ */
94bb0c1a 77#endif /* _ASM_MIPS_JUMP_LABEL_H */