blob: e4456e450f946d5c9c55b52d78aeee60d3a2a0e2 [file] [log] [blame]
David Daney94bb0c12010-12-28 13:26:23 -08001/*
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
Anton Blanchard55dd0df2015-04-09 13:51:30 +100011#ifndef __ASSEMBLY__
David Daney94bb0c12010-12-28 13:26:23 -080012
Anton Blanchard55dd0df2015-04-09 13:51:30 +100013#include <linux/types.h>
David Daney94bb0c12010-12-28 13:26:23 -080014
15#define JUMP_LABEL_NOP_SIZE 4
16
17#ifdef CONFIG_64BIT
18#define WORD_INSN ".dword"
19#else
20#define WORD_INSN ".word"
21#endif
22
Maciej W. Rozycki935c2db2014-11-17 16:10:32 +000023#ifdef CONFIG_CPU_MICROMIPS
Archer Yanb84089b2019-03-08 03:29:19 +000024#define B_INSN "b32"
Maciej W. Rozycki935c2db2014-11-17 16:10:32 +000025#else
Archer Yanb84089b2019-03-08 03:29:19 +000026#define B_INSN "b"
Maciej W. Rozycki935c2db2014-11-17 16:10:32 +000027#endif
28
Peter Zijlstra11276d52015-07-24 15:09:55 +020029static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
Jason Barond430d3d2011-03-16 17:29:47 -040030{
Archer Yanb84089b2019-03-08 03:29:19 +000031 asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
32 "2:\tnop\n\t"
Jason Barond430d3d2011-03-16 17:29:47 -040033 ".pushsection __jump_table, \"aw\"\n\t"
34 WORD_INSN " 1b, %l[l_yes], %0\n\t"
35 ".popsection\n\t"
Peter Zijlstra11276d52015-07-24 15:09:55 +020036 : : "i" (&((char *)key)[branch]) : : l_yes);
37
38 return false;
39l_yes:
40 return true;
41}
42
43static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
44{
45 asm_volatile_goto("1:\tj %l[l_yes]\n\t"
46 "nop\n\t"
47 ".pushsection __jump_table, \"aw\"\n\t"
48 WORD_INSN " 1b, %l[l_yes], %0\n\t"
49 ".popsection\n\t"
50 : : "i" (&((char *)key)[branch]) : : l_yes);
51
Jason Barond430d3d2011-03-16 17:29:47 -040052 return false;
53l_yes:
54 return true;
55}
David Daney94bb0c12010-12-28 13:26:23 -080056
David Daney94bb0c12010-12-28 13:26:23 -080057#ifdef CONFIG_64BIT
58typedef u64 jump_label_t;
59#else
60typedef u32 jump_label_t;
61#endif
62
63struct jump_entry {
64 jump_label_t code;
65 jump_label_t target;
66 jump_label_t key;
67};
68
Anton Blanchard55dd0df2015-04-09 13:51:30 +100069#endif /* __ASSEMBLY__ */
David Daney94bb0c12010-12-28 13:26:23 -080070#endif /* _ASM_MIPS_JUMP_LABEL_H */