18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_MODULE_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_MODULE_H
48c2ecf20Sopenharmony_ci#ifdef __KERNEL__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/list.h>
78c2ecf20Sopenharmony_ci#include <asm/bug.h>
88c2ecf20Sopenharmony_ci#include <asm-generic/module.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __powerpc64__
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * Thanks to Paul M for explaining this.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * PPC can only do rel jumps += 32MB, and often the kernel and other
158c2ecf20Sopenharmony_ci * modules are further away than this.  So, we jump to a table of
168c2ecf20Sopenharmony_ci * trampolines attached to the module (the Procedure Linkage Table)
178c2ecf20Sopenharmony_ci * whenever that happens.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct ppc_plt_entry {
218c2ecf20Sopenharmony_ci	/* 16 byte jump instruction sequence (4 instructions) */
228c2ecf20Sopenharmony_ci	unsigned int jump[4];
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci#endif	/* __powerpc64__ */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct mod_arch_specific {
288c2ecf20Sopenharmony_ci#ifdef __powerpc64__
298c2ecf20Sopenharmony_ci	unsigned int stubs_section;	/* Index of stubs section in module */
308c2ecf20Sopenharmony_ci	unsigned int toc_section;	/* What section is the TOC? */
318c2ecf20Sopenharmony_ci	bool toc_fixed;			/* Have we fixed up .TOC.? */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* For module function descriptor dereference */
348c2ecf20Sopenharmony_ci	unsigned long start_opd;
358c2ecf20Sopenharmony_ci	unsigned long end_opd;
368c2ecf20Sopenharmony_ci#else /* powerpc64 */
378c2ecf20Sopenharmony_ci	/* Indices of PLT sections within module. */
388c2ecf20Sopenharmony_ci	unsigned int core_plt_section;
398c2ecf20Sopenharmony_ci	unsigned int init_plt_section;
408c2ecf20Sopenharmony_ci#endif /* powerpc64 */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#ifdef CONFIG_DYNAMIC_FTRACE
438c2ecf20Sopenharmony_ci	unsigned long tramp;
448c2ecf20Sopenharmony_ci#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
458c2ecf20Sopenharmony_ci	unsigned long tramp_regs;
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci#endif
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/* List of BUG addresses, source line numbers and filenames */
508c2ecf20Sopenharmony_ci	struct list_head bug_list;
518c2ecf20Sopenharmony_ci	struct bug_entry *bug_table;
528c2ecf20Sopenharmony_ci	unsigned int num_bugs;
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * Select ELF headers.
578c2ecf20Sopenharmony_ci * Make empty section for module_frob_arch_sections to expand.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#ifdef __powerpc64__
618c2ecf20Sopenharmony_ci#    ifdef MODULE
628c2ecf20Sopenharmony_ci	asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
638c2ecf20Sopenharmony_ci#    endif
648c2ecf20Sopenharmony_ci#else
658c2ecf20Sopenharmony_ci#    ifdef MODULE
668c2ecf20Sopenharmony_ci	asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
678c2ecf20Sopenharmony_ci	asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
688c2ecf20Sopenharmony_ci#    endif	/* MODULE */
698c2ecf20Sopenharmony_ci#endif
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#ifdef CONFIG_DYNAMIC_FTRACE
728c2ecf20Sopenharmony_ci#    ifdef MODULE
738c2ecf20Sopenharmony_ci	asm(".section .ftrace.tramp,\"ax\",@nobits; .align 3; .previous");
748c2ecf20Sopenharmony_ci#    endif	/* MODULE */
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ciint module_trampoline_target(struct module *mod, unsigned long trampoline,
778c2ecf20Sopenharmony_ci			     unsigned long *target);
788c2ecf20Sopenharmony_ciint module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs);
798c2ecf20Sopenharmony_ci#else
808c2ecf20Sopenharmony_cistatic inline int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	return 0;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci#endif
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
878c2ecf20Sopenharmony_ci#endif	/* _ASM_POWERPC_MODULE_H */
88