David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 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 | |
Anton Blanchard | 55dd0df | 2015-04-09 13:51:30 +1000 | [diff] [blame] | 11 | #ifndef __ASSEMBLY__ |
David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 12 | |
Anton Blanchard | 55dd0df | 2015-04-09 13:51:30 +1000 | [diff] [blame] | 13 | #include <linux/types.h> |
David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 14 | |
| 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. Rozycki | 935c2db | 2014-11-17 16:10:32 +0000 | [diff] [blame] | 23 | #ifdef CONFIG_CPU_MICROMIPS |
| 24 | #define NOP_INSN "nop32" |
| 25 | #else |
| 26 | #define NOP_INSN "nop" |
| 27 | #endif |
| 28 | |
Peter Zijlstra | 11276d5 | 2015-07-24 15:09:55 +0200 | [diff] [blame] | 29 | static __always_inline bool arch_static_branch(struct static_key *key, bool branch) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 30 | { |
Maciej W. Rozycki | 935c2db | 2014-11-17 16:10:32 +0000 | [diff] [blame] | 31 | asm_volatile_goto("1:\t" NOP_INSN "\n\t" |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 32 | "nop\n\t" |
| 33 | ".pushsection __jump_table, \"aw\"\n\t" |
| 34 | WORD_INSN " 1b, %l[l_yes], %0\n\t" |
| 35 | ".popsection\n\t" |
Peter Zijlstra | 11276d5 | 2015-07-24 15:09:55 +0200 | [diff] [blame] | 36 | : : "i" (&((char *)key)[branch]) : : l_yes); |
| 37 | |
| 38 | return false; |
| 39 | l_yes: |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | static __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 Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 52 | return false; |
| 53 | l_yes: |
| 54 | return true; |
| 55 | } |
David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 56 | |
David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 57 | #ifdef CONFIG_64BIT |
| 58 | typedef u64 jump_label_t; |
| 59 | #else |
| 60 | typedef u32 jump_label_t; |
| 61 | #endif |
| 62 | |
| 63 | struct jump_entry { |
| 64 | jump_label_t code; |
| 65 | jump_label_t target; |
| 66 | jump_label_t key; |
| 67 | }; |
| 68 | |
Anton Blanchard | 55dd0df | 2015-04-09 13:51:30 +1000 | [diff] [blame] | 69 | #endif /* __ASSEMBLY__ */ |
David Daney | 94bb0c1 | 2010-12-28 13:26:23 -0800 | [diff] [blame] | 70 | #endif /* _ASM_MIPS_JUMP_LABEL_H */ |