1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/memory.h>
3 #include <linux/static_call.h>
5 #include <asm/code-patching.h>
7 void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
10 bool is_ret0 = (func == __static_call_return0);
11 unsigned long target = (unsigned long)(is_ret0 ? tramp + PPC_SCT_RET0 : func);
12 bool is_short = is_offset_in_branch_range((long)target - (long)tramp);
17 mutex_lock(&text_mutex);
19 if (func && !is_short) {
20 err = patch_instruction(tramp + PPC_SCT_DATA, ppc_inst(target));
26 err = patch_instruction(tramp, ppc_inst(PPC_RAW_BLR()));
28 err = patch_branch(tramp, target, 0);
30 err = patch_instruction(tramp, ppc_inst(PPC_RAW_NOP()));
32 mutex_unlock(&text_mutex);
35 panic("%s: patching failed %pS at %pS\n", __func__, func, tramp);
37 EXPORT_SYMBOL_GPL(arch_static_call_transform);