1ac5f89c7SMichael Ellerman #ifndef _ASM_POWERPC_JUMP_LABEL_H 2ac5f89c7SMichael Ellerman #define _ASM_POWERPC_JUMP_LABEL_H 3ac5f89c7SMichael Ellerman 4ac5f89c7SMichael Ellerman /* 5ac5f89c7SMichael Ellerman * Copyright 2010 Michael Ellerman, IBM Corp. 6ac5f89c7SMichael Ellerman * 7ac5f89c7SMichael Ellerman * This program is free software; you can redistribute it and/or 8ac5f89c7SMichael Ellerman * modify it under the terms of the GNU General Public License 9ac5f89c7SMichael Ellerman * as published by the Free Software Foundation; either version 10ac5f89c7SMichael Ellerman * 2 of the License, or (at your option) any later version. 11ac5f89c7SMichael Ellerman */ 12ac5f89c7SMichael Ellerman 13cc1adb5fSAnton Blanchard #ifndef __ASSEMBLY__ 14ac5f89c7SMichael Ellerman #include <linux/types.h> 15ac5f89c7SMichael Ellerman 16ac5f89c7SMichael Ellerman #include <asm/feature-fixups.h> 17ac5f89c7SMichael Ellerman 18ac5f89c7SMichael Ellerman #define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG) 19ac5f89c7SMichael Ellerman #define JUMP_LABEL_NOP_SIZE 4 20ac5f89c7SMichael Ellerman 21*11276d53SPeter Zijlstra static __always_inline bool arch_static_branch(struct static_key *key, bool branch) 22ac5f89c7SMichael Ellerman { 233f0116c3SIngo Molnar asm_volatile_goto("1:\n\t" 24ac5f89c7SMichael Ellerman "nop\n\t" 25ac5f89c7SMichael Ellerman ".pushsection __jump_table, \"aw\"\n\t" 26ac5f89c7SMichael Ellerman JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" 27ac5f89c7SMichael Ellerman ".popsection \n\t" 28*11276d53SPeter Zijlstra : : "i" (&((char *)key)[branch]) : : l_yes); 29*11276d53SPeter Zijlstra 30*11276d53SPeter Zijlstra return false; 31*11276d53SPeter Zijlstra l_yes: 32*11276d53SPeter Zijlstra return true; 33*11276d53SPeter Zijlstra } 34*11276d53SPeter Zijlstra 35*11276d53SPeter Zijlstra static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) 36*11276d53SPeter Zijlstra { 37*11276d53SPeter Zijlstra asm_volatile_goto("1:\n\t" 38*11276d53SPeter Zijlstra "b %l[l_yes]\n\t" 39*11276d53SPeter Zijlstra ".pushsection __jump_table, \"aw\"\n\t" 40*11276d53SPeter Zijlstra JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" 41*11276d53SPeter Zijlstra ".popsection \n\t" 42*11276d53SPeter Zijlstra : : "i" (&((char *)key)[branch]) : : l_yes); 43*11276d53SPeter Zijlstra 44ac5f89c7SMichael Ellerman return false; 45ac5f89c7SMichael Ellerman l_yes: 46ac5f89c7SMichael Ellerman return true; 47ac5f89c7SMichael Ellerman } 48ac5f89c7SMichael Ellerman 49ac5f89c7SMichael Ellerman #ifdef CONFIG_PPC64 50ac5f89c7SMichael Ellerman typedef u64 jump_label_t; 51ac5f89c7SMichael Ellerman #else 52ac5f89c7SMichael Ellerman typedef u32 jump_label_t; 53ac5f89c7SMichael Ellerman #endif 54ac5f89c7SMichael Ellerman 55ac5f89c7SMichael Ellerman struct jump_entry { 56ac5f89c7SMichael Ellerman jump_label_t code; 57ac5f89c7SMichael Ellerman jump_label_t target; 58ac5f89c7SMichael Ellerman jump_label_t key; 59ac5f89c7SMichael Ellerman }; 60ac5f89c7SMichael Ellerman 61cc1adb5fSAnton Blanchard #else 62cc1adb5fSAnton Blanchard #define ARCH_STATIC_BRANCH(LABEL, KEY) \ 63cc1adb5fSAnton Blanchard 1098: nop; \ 64cc1adb5fSAnton Blanchard .pushsection __jump_table, "aw"; \ 65cc1adb5fSAnton Blanchard FTR_ENTRY_LONG 1098b, LABEL, KEY; \ 66cc1adb5fSAnton Blanchard .popsection 67cc1adb5fSAnton Blanchard #endif 68cc1adb5fSAnton Blanchard 69ac5f89c7SMichael Ellerman #endif /* _ASM_POWERPC_JUMP_LABEL_H */ 70