1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_MODULE_H
3 #define _ASM_POWERPC_MODULE_H
4 #ifdef __KERNEL__
5
6 #include <linux/list.h>
7 #include <asm/bug.h>
8 #include <asm-generic/module.h>
9
10 #ifndef __powerpc64__
11 /*
12 * Thanks to Paul M for explaining this.
13 *
14 * PPC can only do rel jumps += 32MB, and often the kernel and other
15 * modules are further away than this. So, we jump to a table of
16 * trampolines attached to the module (the Procedure Linkage Table)
17 * whenever that happens.
18 */
19
20 struct ppc_plt_entry {
21 /* 16 byte jump instruction sequence (4 instructions) */
22 unsigned int jump[4];
23 };
24 #endif /* __powerpc64__ */
25
26
27 struct mod_arch_specific {
28 #ifdef __powerpc64__
29 unsigned int stubs_section; /* Index of stubs section in module */
30 unsigned int stub_count; /* Number of stubs used */
31 #ifdef CONFIG_PPC_KERNEL_PCREL
32 unsigned int got_section; /* What section is the GOT? */
33 unsigned int pcpu_section; /* .data..percpu section */
34 #else
35 unsigned int toc_section; /* What section is the TOC? */
36 bool toc_fixed; /* Have we fixed up .TOC.? */
37 #endif
38
39 #ifdef CONFIG_PPC64_ELF_ABI_V1
40 /* For module function descriptor dereference */
41 unsigned long start_opd;
42 unsigned long end_opd;
43 #endif
44 #else /* powerpc64 */
45 /* Indices of PLT sections within module. */
46 unsigned int core_plt_section;
47 unsigned int init_plt_section;
48 #endif /* powerpc64 */
49
50 #ifdef CONFIG_DYNAMIC_FTRACE
51 unsigned long tramp;
52 unsigned long tramp_regs;
53 #ifdef CONFIG_PPC_FTRACE_OUT_OF_LINE
54 struct ftrace_ool_stub *ool_stubs;
55 unsigned int ool_stub_count;
56 unsigned int ool_stub_index;
57 #endif
58 #endif
59 };
60
61 /*
62 * Select ELF headers.
63 * Make empty sections for module_frob_arch_sections to expand.
64 */
65
66 #ifdef __powerpc64__
67 # ifdef MODULE
68 asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
69 # ifdef CONFIG_PPC_KERNEL_PCREL
70 asm(".section .mygot,\"a\",@nobits; .align 3; .previous");
71 # endif
72 # endif
73 #else
74 # ifdef MODULE
75 asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
76 asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
77 # endif /* MODULE */
78 #endif
79
80 #ifdef CONFIG_DYNAMIC_FTRACE
81 int module_trampoline_target(struct module *mod, unsigned long trampoline,
82 unsigned long *target);
83 int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs);
84 #else
module_finalize_ftrace(struct module * mod,const Elf_Shdr * sechdrs)85 static inline int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs)
86 {
87 return 0;
88 }
89 #endif
90
91 #endif /* __KERNEL__ */
92 #endif /* _ASM_POWERPC_MODULE_H */
93