1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2013 Huawei Ltd. 4 * Author: Jiang Liu <liuj97@gmail.com> 5 * 6 * Based on arch/arm/include/asm/jump_label.h 7 */ 8 #ifndef __ASM_JUMP_LABEL_H 9 #define __ASM_JUMP_LABEL_H 10 11 #ifndef __ASSEMBLY__ 12 13 #include <linux/types.h> 14 #include <asm/insn.h> 15 16 #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE 17 18 #define JUMP_TABLE_ENTRY(key, label) \ 19 ".pushsection __jump_table, \"aw\"\n\t" \ 20 ".align 3\n\t" \ 21 ".long 1b - ., %l["#label"] - .\n\t" \ 22 ".quad %c0 - .\n\t" \ 23 ".popsection\n\t" \ 24 : : "i"(key) : : label 25 26 static __always_inline bool arch_static_branch(struct static_key * const key, 27 const bool branch) 28 { 29 char *k = &((char *)key)[branch]; 30 31 asm goto( 32 "1: nop \n\t" 33 JUMP_TABLE_ENTRY(k, l_yes) 34 ); 35 36 return false; 37 l_yes: 38 return true; 39 } 40 41 static __always_inline bool arch_static_branch_jump(struct static_key * const key, 42 const bool branch) 43 { 44 char *k = &((char *)key)[branch]; 45 asm goto( 46 "1: b %l[l_yes] \n\t" 47 JUMP_TABLE_ENTRY(k, l_yes) 48 ); 49 return false; 50 l_yes: 51 return true; 52 } 53 54 #endif /* __ASSEMBLY__ */ 55 #endif /* __ASM_JUMP_LABEL_H */ 56