1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2ac5f89c7SMichael Ellerman #ifndef _ASM_POWERPC_JUMP_LABEL_H 3ac5f89c7SMichael Ellerman #define _ASM_POWERPC_JUMP_LABEL_H 4ac5f89c7SMichael Ellerman 5ac5f89c7SMichael Ellerman /* 6ac5f89c7SMichael Ellerman * Copyright 2010 Michael Ellerman, IBM Corp. 7ac5f89c7SMichael Ellerman */ 8ac5f89c7SMichael Ellerman 9cc1adb5fSAnton Blanchard #ifndef __ASSEMBLY__ 10ac5f89c7SMichael Ellerman #include <linux/types.h> 11ac5f89c7SMichael Ellerman 12ac5f89c7SMichael Ellerman #include <asm/feature-fixups.h> 13ec0c464cSChristophe Leroy #include <asm/asm-const.h> 14ac5f89c7SMichael Ellerman 15ac5f89c7SMichael Ellerman #define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG) 16ac5f89c7SMichael Ellerman #define JUMP_LABEL_NOP_SIZE 4 17ac5f89c7SMichael Ellerman 1811276d53SPeter Zijlstra static __always_inline bool arch_static_branch(struct static_key *key, bool branch) 19ac5f89c7SMichael Ellerman { 203f0116c3SIngo Molnar asm_volatile_goto("1:\n\t" 21e2985fd9SMichael Ellerman "nop # arch_static_branch\n\t" 22ac5f89c7SMichael Ellerman ".pushsection __jump_table, \"aw\"\n\t" 23ac5f89c7SMichael Ellerman JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" 24ac5f89c7SMichael Ellerman ".popsection \n\t" 2511276d53SPeter Zijlstra : : "i" (&((char *)key)[branch]) : : l_yes); 2611276d53SPeter Zijlstra 2711276d53SPeter Zijlstra return false; 2811276d53SPeter Zijlstra l_yes: 2911276d53SPeter Zijlstra return true; 3011276d53SPeter Zijlstra } 3111276d53SPeter Zijlstra 3211276d53SPeter Zijlstra static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) 3311276d53SPeter Zijlstra { 3411276d53SPeter Zijlstra asm_volatile_goto("1:\n\t" 35e2985fd9SMichael Ellerman "b %l[l_yes] # arch_static_branch_jump\n\t" 3611276d53SPeter Zijlstra ".pushsection __jump_table, \"aw\"\n\t" 3711276d53SPeter Zijlstra JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" 3811276d53SPeter Zijlstra ".popsection \n\t" 3911276d53SPeter Zijlstra : : "i" (&((char *)key)[branch]) : : l_yes); 4011276d53SPeter Zijlstra 41ac5f89c7SMichael Ellerman return false; 42ac5f89c7SMichael Ellerman l_yes: 43ac5f89c7SMichael Ellerman return true; 44ac5f89c7SMichael Ellerman } 45ac5f89c7SMichael Ellerman 46ac5f89c7SMichael Ellerman #ifdef CONFIG_PPC64 47ac5f89c7SMichael Ellerman typedef u64 jump_label_t; 48ac5f89c7SMichael Ellerman #else 49ac5f89c7SMichael Ellerman typedef u32 jump_label_t; 50ac5f89c7SMichael Ellerman #endif 51ac5f89c7SMichael Ellerman 52ac5f89c7SMichael Ellerman struct jump_entry { 53ac5f89c7SMichael Ellerman jump_label_t code; 54ac5f89c7SMichael Ellerman jump_label_t target; 55ac5f89c7SMichael Ellerman jump_label_t key; 56ac5f89c7SMichael Ellerman }; 57ac5f89c7SMichael Ellerman 58cc1adb5fSAnton Blanchard #else 59cc1adb5fSAnton Blanchard #define ARCH_STATIC_BRANCH(LABEL, KEY) \ 60cc1adb5fSAnton Blanchard 1098: nop; \ 61cc1adb5fSAnton Blanchard .pushsection __jump_table, "aw"; \ 62cc1adb5fSAnton Blanchard FTR_ENTRY_LONG 1098b, LABEL, KEY; \ 63cc1adb5fSAnton Blanchard .popsection 64cc1adb5fSAnton Blanchard #endif 65cc1adb5fSAnton Blanchard 66ac5f89c7SMichael Ellerman #endif /* _ASM_POWERPC_JUMP_LABEL_H */ 67