0001
0002 #include <linux/memory.h>
0003 #include <linux/static_call.h>
0004
0005 #include <asm/code-patching.h>
0006
0007 void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
0008 {
0009 int err;
0010 bool is_ret0 = (func == __static_call_return0);
0011 unsigned long target = (unsigned long)(is_ret0 ? tramp + PPC_SCT_RET0 : func);
0012 bool is_short = is_offset_in_branch_range((long)target - (long)tramp);
0013
0014 if (!tramp)
0015 return;
0016
0017 mutex_lock(&text_mutex);
0018
0019 if (func && !is_short) {
0020 err = patch_instruction(tramp + PPC_SCT_DATA, ppc_inst(target));
0021 if (err)
0022 goto out;
0023 }
0024
0025 if (!func)
0026 err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
0027 else if (is_short)
0028 err = patch_branch(tramp, target, 0);
0029 else
0030 err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
0031 out:
0032 mutex_unlock(&text_mutex);
0033
0034 if (err)
0035 panic("%s: patching failed %pS at %pS\n", __func__, func, tramp);
0036 }
0037 EXPORT_SYMBOL_GPL(arch_static_call_transform);