Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_ARC_JUMP_LABEL_H
0003 #define _ASM_ARC_JUMP_LABEL_H
0004 
0005 #ifndef __ASSEMBLY__
0006 
0007 #include <linux/stringify.h>
0008 #include <linux/types.h>
0009 
0010 #define JUMP_LABEL_NOP_SIZE 4
0011 
0012 /*
0013  * NOTE about '.balign 4':
0014  *
0015  * To make atomic update of patched instruction available we need to guarantee
0016  * that this instruction doesn't cross L1 cache line boundary.
0017  *
0018  * As of today we simply align instruction which can be patched by 4 byte using
0019  * ".balign 4" directive. In that case patched instruction is aligned with one
0020  * 16-bit NOP_S if this is required.
0021  * However 'align by 4' directive is much stricter than it actually required.
0022  * It's enough that our 32-bit instruction don't cross L1 cache line boundary /
0023  * L1 I$ fetch block boundary which can be achieved by using
0024  * ".bundle_align_mode" assembler directive. That will save us from adding
0025  * useless NOP_S padding in most of the cases.
0026  *
0027  * TODO: switch to ".bundle_align_mode" directive using whin it will be
0028  * supported by ARC toolchain.
0029  */
0030 
0031 static __always_inline bool arch_static_branch(struct static_key *key,
0032                            bool branch)
0033 {
0034     asm_volatile_goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)"   \n"
0035          "1:                            \n"
0036          "nop                           \n"
0037          ".pushsection __jump_table, \"aw\"         \n"
0038          ".word 1b, %l[l_yes], %c0              \n"
0039          ".popsection                       \n"
0040          : : "i" (&((char *)key)[branch]) : : l_yes);
0041 
0042     return false;
0043 l_yes:
0044     return true;
0045 }
0046 
0047 static __always_inline bool arch_static_branch_jump(struct static_key *key,
0048                             bool branch)
0049 {
0050     asm_volatile_goto(".balign "__stringify(JUMP_LABEL_NOP_SIZE)"   \n"
0051          "1:                            \n"
0052          "b %l[l_yes]                       \n"
0053          ".pushsection __jump_table, \"aw\"         \n"
0054          ".word 1b, %l[l_yes], %c0              \n"
0055          ".popsection                       \n"
0056          : : "i" (&((char *)key)[branch]) : : l_yes);
0057 
0058     return false;
0059 l_yes:
0060     return true;
0061 }
0062 
0063 typedef u32 jump_label_t;
0064 
0065 struct jump_entry {
0066     jump_label_t code;
0067     jump_label_t target;
0068     jump_label_t key;
0069 };
0070 
0071 #endif  /* __ASSEMBLY__ */
0072 #endif