| 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 |
|
| 6 |
void arch_static_call_transform(void *site, void *tramp, void *func, bool tail) |
| 7 |
{ |
| 8 |
u64 literal; |
| 9 |
int ret; |
| 10 |
|
| 11 |
if (!func) |
| 12 |
func = __static_call_return0; |
| 13 |
|
| 14 |
/* decode the instructions to discover the literal address */ |
| 15 |
literal = ALIGN_DOWN((u64)tramp + 4, SZ_4K) + |
| 16 |
aarch64_insn_adrp_get_offset(le32_to_cpup(tramp + 4)) + |
| 17 |
8 * aarch64_insn_decode_immediate(AARCH64_INSN_IMM_12, |
| 18 |
le32_to_cpup(tramp + 8)); |
| 19 |
|
| 20 |
ret = aarch64_insn_write_literal_u64((void *)literal, (u64)func); |
| 21 |
WARN_ON_ONCE(ret); |
| 22 |
} |
| 23 |
EXPORT_SYMBOL_GPL(arch_static_call_transform); |