1*f02644e3SYouling Tang /* SPDX-License-Identifier: GPL-2.0-only */ 2*f02644e3SYouling Tang /* 3*f02644e3SYouling Tang * Copyright (C) 2023 Loongson Technology Corporation Limited 4*f02644e3SYouling Tang * 5*f02644e3SYouling Tang * Based on arch/arm64/include/asm/jump_label.h 6*f02644e3SYouling Tang */ 7*f02644e3SYouling Tang #ifndef __ASM_JUMP_LABEL_H 8*f02644e3SYouling Tang #define __ASM_JUMP_LABEL_H 9*f02644e3SYouling Tang 10*f02644e3SYouling Tang #ifndef __ASSEMBLY__ 11*f02644e3SYouling Tang 12*f02644e3SYouling Tang #include <linux/types.h> 13*f02644e3SYouling Tang 14*f02644e3SYouling Tang #define JUMP_LABEL_NOP_SIZE 4 15*f02644e3SYouling Tang 16*f02644e3SYouling Tang #define JUMP_TABLE_ENTRY \ 17*f02644e3SYouling Tang ".pushsection __jump_table, \"aw\" \n\t" \ 18*f02644e3SYouling Tang ".align 3 \n\t" \ 19*f02644e3SYouling Tang ".long 1b - ., %l[l_yes] - . \n\t" \ 20*f02644e3SYouling Tang ".quad %0 - . \n\t" \ 21*f02644e3SYouling Tang ".popsection \n\t" 22*f02644e3SYouling Tang 23*f02644e3SYouling Tang static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) 24*f02644e3SYouling Tang { 25*f02644e3SYouling Tang asm_volatile_goto( 26*f02644e3SYouling Tang "1: nop \n\t" 27*f02644e3SYouling Tang JUMP_TABLE_ENTRY 28*f02644e3SYouling Tang : : "i"(&((char *)key)[branch]) : : l_yes); 29*f02644e3SYouling Tang 30*f02644e3SYouling Tang return false; 31*f02644e3SYouling Tang 32*f02644e3SYouling Tang l_yes: 33*f02644e3SYouling Tang return true; 34*f02644e3SYouling Tang } 35*f02644e3SYouling Tang 36*f02644e3SYouling Tang static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) 37*f02644e3SYouling Tang { 38*f02644e3SYouling Tang asm_volatile_goto( 39*f02644e3SYouling Tang "1: b %l[l_yes] \n\t" 40*f02644e3SYouling Tang JUMP_TABLE_ENTRY 41*f02644e3SYouling Tang : : "i"(&((char *)key)[branch]) : : l_yes); 42*f02644e3SYouling Tang 43*f02644e3SYouling Tang return false; 44*f02644e3SYouling Tang 45*f02644e3SYouling Tang l_yes: 46*f02644e3SYouling Tang return true; 47*f02644e3SYouling Tang } 48*f02644e3SYouling Tang 49*f02644e3SYouling Tang #endif /* __ASSEMBLY__ */ 50*f02644e3SYouling Tang #endif /* __ASM_JUMP_LABEL_H */ 51