1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/static_call.h> 3 #include <linux/memory.h> 4 #include <asm/text-patching.h> 5 #include <asm/insn.h> 6 7 void arch_static_call_transform(void *site, void *tramp, void *func, bool tail) 8 { 9 u64 literal; 10 int ret; 11 12 if (!func) 13 func = __static_call_return0; 14 15 /* decode the instructions to discover the literal address */ 16 literal = ALIGN_DOWN((u64)tramp + 4, SZ_4K) + 17 aarch64_insn_adrp_get_offset(le32_to_cpup(tramp + 4)) + 18 8 * aarch64_insn_decode_immediate(AARCH64_INSN_IMM_12, 19 le32_to_cpup(tramp + 8)); 20 21 ret = aarch64_insn_write_literal_u64((void *)literal, (u64)func); 22 WARN_ON_ONCE(ret); 23 } 24 EXPORT_SYMBOL_GPL(arch_static_call_transform); 25