xref: /openbmc/linux/arch/powerpc/include/asm/module.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_MODULE_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_MODULE_H
4b8b572e1SStephen Rothwell #ifdef __KERNEL__
5b8b572e1SStephen Rothwell 
6b8b572e1SStephen Rothwell #include <linux/list.h>
7b8b572e1SStephen Rothwell #include <asm/bug.h>
8786d35d4SDavid Howells #include <asm-generic/module.h>
9b8b572e1SStephen Rothwell 
10b8b572e1SStephen Rothwell #ifndef __powerpc64__
11b8b572e1SStephen Rothwell /*
12b8b572e1SStephen Rothwell  * Thanks to Paul M for explaining this.
13b8b572e1SStephen Rothwell  *
14b8b572e1SStephen Rothwell  * PPC can only do rel jumps += 32MB, and often the kernel and other
15446957baSAdam Buchbinder  * modules are further away than this.  So, we jump to a table of
16b8b572e1SStephen Rothwell  * trampolines attached to the module (the Procedure Linkage Table)
17b8b572e1SStephen Rothwell  * whenever that happens.
18b8b572e1SStephen Rothwell  */
19b8b572e1SStephen Rothwell 
20b8b572e1SStephen Rothwell struct ppc_plt_entry {
21b8b572e1SStephen Rothwell 	/* 16 byte jump instruction sequence (4 instructions) */
22b8b572e1SStephen Rothwell 	unsigned int jump[4];
23b8b572e1SStephen Rothwell };
24b8b572e1SStephen Rothwell #endif	/* __powerpc64__ */
25b8b572e1SStephen Rothwell 
26b8b572e1SStephen Rothwell 
27b8b572e1SStephen Rothwell struct mod_arch_specific {
28b8b572e1SStephen Rothwell #ifdef __powerpc64__
29b8b572e1SStephen Rothwell 	unsigned int stubs_section;	/* Index of stubs section in module */
30*77e69ee7SNicholas Piggin #ifdef CONFIG_PPC_KERNEL_PCREL
31*77e69ee7SNicholas Piggin 	unsigned int got_section;	/* What section is the GOT? */
32*77e69ee7SNicholas Piggin 	unsigned int pcpu_section;	/* .data..percpu section */
33*77e69ee7SNicholas Piggin #else
34b8b572e1SStephen Rothwell 	unsigned int toc_section;	/* What section is the TOC? */
354edebbeaSRusty Russell 	bool toc_fixed;			/* Have we fixed up .TOC.? */
36*77e69ee7SNicholas Piggin #endif
37f48cb8b4SSteven Rostedt 
385633e85bSSergey Senozhatsky 	/* For module function descriptor dereference */
395633e85bSSergey Senozhatsky 	unsigned long start_opd;
405633e85bSSergey Senozhatsky 	unsigned long end_opd;
417cc45e64SSteven Rostedt #else /* powerpc64 */
42b8b572e1SStephen Rothwell 	/* Indices of PLT sections within module. */
43b8b572e1SStephen Rothwell 	unsigned int core_plt_section;
44b8b572e1SStephen Rothwell 	unsigned int init_plt_section;
458ce621e1SJosh Poimboeuf #endif /* powerpc64 */
468ce621e1SJosh Poimboeuf 
477cc45e64SSteven Rostedt #ifdef CONFIG_DYNAMIC_FTRACE
487cc45e64SSteven Rostedt 	unsigned long tramp;
498ce621e1SJosh Poimboeuf 	unsigned long tramp_regs;
50b8b572e1SStephen Rothwell #endif
51b8b572e1SStephen Rothwell 
52b8b572e1SStephen Rothwell 	/* List of BUG addresses, source line numbers and filenames */
53b8b572e1SStephen Rothwell 	struct list_head bug_list;
54b8b572e1SStephen Rothwell 	struct bug_entry *bug_table;
55b8b572e1SStephen Rothwell 	unsigned int num_bugs;
56b8b572e1SStephen Rothwell };
57b8b572e1SStephen Rothwell 
58b8b572e1SStephen Rothwell /*
59b8b572e1SStephen Rothwell  * Select ELF headers.
60*77e69ee7SNicholas Piggin  * Make empty sections for module_frob_arch_sections to expand.
61b8b572e1SStephen Rothwell  */
62b8b572e1SStephen Rothwell 
63b8b572e1SStephen Rothwell #ifdef __powerpc64__
64b8b572e1SStephen Rothwell #    ifdef MODULE
65b8b572e1SStephen Rothwell 	asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
66*77e69ee7SNicholas Piggin #        ifdef CONFIG_PPC_KERNEL_PCREL
67*77e69ee7SNicholas Piggin 	    asm(".section .mygot,\"a\",@nobits; .align 3; .previous");
68*77e69ee7SNicholas Piggin #        endif
69b8b572e1SStephen Rothwell #    endif
70b8b572e1SStephen Rothwell #else
71b8b572e1SStephen Rothwell #    ifdef MODULE
72b8b572e1SStephen Rothwell 	asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
73b8b572e1SStephen Rothwell 	asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
74b8b572e1SStephen Rothwell #    endif	/* MODULE */
75b8b572e1SStephen Rothwell #endif
76b8b572e1SStephen Rothwell 
77f48cb8b4SSteven Rostedt #ifdef CONFIG_DYNAMIC_FTRACE
78f17c4e01SMichael Ellerman int module_trampoline_target(struct module *mod, unsigned long trampoline,
79dd9fa162SAnton Blanchard 			     unsigned long *target);
80136cd345SMichael Ellerman int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs);
81136cd345SMichael Ellerman #else
module_finalize_ftrace(struct module * mod,const Elf_Shdr * sechdrs)82136cd345SMichael Ellerman static inline int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs)
83136cd345SMichael Ellerman {
84136cd345SMichael Ellerman 	return 0;
85136cd345SMichael Ellerman }
86136cd345SMichael Ellerman #endif
87136cd345SMichael Ellerman 
88b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
89b8b572e1SStephen Rothwell #endif	/* _ASM_POWERPC_MODULE_H */
90