diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-07-27 21:58:45 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-07-27 21:58:45 +0200 |
commit | 154bc2aa3cb51104bdf213463da4fef9866c5a7b (patch) | |
tree | 8bb9449a8ad35a3c72a0d3de481a2c1c3c01d257 /include | |
parent | 8b0bf1ee077715ceb0535fbda799038ea62baef8 (diff) | |
parent | c55d8cbfc9447f32cb0d880e23c42d4ad185fae5 (diff) | |
download | barebox-154bc2aa3cb51104bdf213463da4fef9866c5a7b.tar.gz barebox-154bc2aa3cb51104bdf213463da4fef9866c5a7b.tar.xz |
Merge branch 'for-next/module'
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-generic/module.h | 49 | ||||
-rw-r--r-- | include/init.h | 26 | ||||
-rw-r--r-- | include/module.h | 78 |
3 files changed, 144 insertions, 9 deletions
diff --git a/include/asm-generic/module.h b/include/asm-generic/module.h new file mode 100644 index 0000000000..98e1541b72 --- /dev/null +++ b/include/asm-generic/module.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_GENERIC_MODULE_H +#define __ASM_GENERIC_MODULE_H + +/* + * Many architectures just need a simple module + * loader without arch specific data. + */ +#ifndef CONFIG_HAVE_MOD_ARCH_SPECIFIC +struct mod_arch_specific +{ +}; +#endif + +#ifdef CONFIG_64BIT +#define Elf_Shdr Elf64_Shdr +#define Elf_Phdr Elf64_Phdr +#define Elf_Sym Elf64_Sym +#define Elf_Dyn Elf64_Dyn +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Addr Elf64_Addr +#ifdef CONFIG_MODULES_USE_ELF_REL +#define Elf_Rel Elf64_Rel +#endif +#ifdef CONFIG_MODULES_USE_ELF_RELA +#define Elf_Rela Elf64_Rela +#endif +#define ELF_R_TYPE(X) ELF64_R_TYPE(X) +#define ELF_R_SYM(X) ELF64_R_SYM(X) + +#else /* CONFIG_64BIT */ + +#define Elf_Shdr Elf32_Shdr +#define Elf_Phdr Elf32_Phdr +#define Elf_Sym Elf32_Sym +#define Elf_Dyn Elf32_Dyn +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Addr Elf32_Addr +#ifdef CONFIG_MODULES_USE_ELF_REL +#define Elf_Rel Elf32_Rel +#endif +#ifdef CONFIG_MODULES_USE_ELF_RELA +#define Elf_Rela Elf32_Rela +#endif +#define ELF_R_TYPE(X) ELF32_R_TYPE(X) +#define ELF_R_SYM(X) ELF32_R_SYM(X) +#endif + +#endif /* __ASM_GENERIC_MODULE_H */ diff --git a/include/init.h b/include/init.h index d1cef14b07..2d61bc8963 100644 --- a/include/init.h +++ b/include/init.h @@ -18,6 +18,21 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); +/* section for code used very early when + * - we're not running from where we linked at + * - bss not cleared + * - static variables not initialized + * + * Mainly useful for booting from NAND Controllers + */ +#define __bare_init __section(.text_bare_init.text) + +#endif + +#ifndef MODULE + +#ifndef __ASSEMBLY__ + #define __define_initcall(level,fn,id) \ static initcall_t __initcall_##fn##id __attribute__((__used__)) \ __attribute__((__section__(".initcall." level))) = fn @@ -58,16 +73,9 @@ typedef void (*exitcall_t)(void); #define archshutdown_exitcall(fn) __define_exitcall("5",fn,5) #define postarchshutdown_exitcall(fn) __define_exitcall("6",fn,6) -/* section for code used very early when - * - we're not running from where we linked at - * - bss not cleared - * - static variables not initialized - * - * Mainly useful for booting from NAND Controllers - */ -#define __bare_init __section(.text_bare_init.text) +#endif /* __ASSEMBLY__ */ -#endif +#endif /* MODULE */ #endif /* _INIT_H */ diff --git a/include/module.h b/include/module.h index cea8c2e181..9099e5aeed 100644 --- a/include/module.h +++ b/include/module.h @@ -2,6 +2,7 @@ #ifndef __MODULE_H #define __MODULE_H +#include <init.h> #include <elf.h> #include <linux/compiler.h> #include <linux/export.h> @@ -13,6 +14,76 @@ #define MODULE_NAME_LEN (64 - sizeof(unsigned long)) +/* These are either module local, or the kernel's dummy ones. */ +extern int init_module(void); +extern void cleanup_module(void); + +#ifndef MODULE +/** + * module_init() - driver initialization entry point + * @x: function to be run at kernel boot time or module insertion + * + * module_init() will either be called during do_initcalls() (if + * builtin) or at module insertion time (if a module). There can only + * be one per module. + */ +#define module_init(x) device_initcall(x); + +/** + * module_exit() - driver exit entry point + * @x: function to be run when driver is removed + * + * module_exit() will wrap the driver clean-up code + * with cleanup_module() when used with rmmod when + * the driver is a module. If the driver is statically + * compiled into the kernel, module_exit() has no effect. + * There can only be one per module. + */ +#define module_exit(x) devshutdown_exitcall(x); + +#else /* MODULE */ + +/* + * In most cases loadable modules do not need custom + * initcall levels. There are still some valid cases where + * a driver may be needed early if built in, and does not + * matter when built as a loadable module. Like bus + * snooping debug drivers. + */ +#define core_initcall(fn) module_init(fn) +#define postcore_initcall(fn) module_init(fn) +#define console_initcall(fn) module_init(fn) +#define postconsole_initcall(fn) module_init(fn) +#define mem_initcall(fn) module_init(fn) +#define mmu_initcall(fn) module_init(fn) +#define postmmu_initcall(fn) module_init(fn) +#define coredevice_initcall(fn) module_init(fn) +#define fs_initcall(fn) module_init(fn) +#define device_initcall(fn) module_init(fn) +#define late_initcall(fn) module_init(fn) + +#define early_exitcall(fn) module_exit(fn) +#define predevshutdown_exitcall(fn) module_exit(fn) +#define devshutdown_exitcall(fn) module_exit(fn) +#define postdevshutdown_exitcall(fn) module_exit(fn) +#define prearchshutdown_exitcall(fn) module_exit(fn) +#define archshutdown_exitcall(fn) module_exit(fn) +#define postarchshutdown_exitcall(fn) module_exit(fn) + +/* Each module must use one module_init(). */ +#define module_init(initfn) \ + static inline initcall_t __maybe_unused __inittest(void) \ + { return initfn; } \ + int init_module(void) __attribute__((alias(#initfn))); + +/* This is only required if you want to be unloadable. */ +#define module_exit(exitfn) \ + static inline exitcall_t __maybe_unused __exittest(void) \ + { return exitfn; } \ + void cleanup_module(void) __attribute__((alias(#exitfn))); + +#endif + #ifdef CONFIG_MODULES #include <asm/module.h> @@ -51,6 +122,13 @@ int apply_relocate_add(Elf_Shdr *sechdrs, unsigned int symindex, unsigned int relsec, struct module *mod); + +/* Adjust arch-specific sections. Return 0 on success. */ +int module_frob_arch_sections(Elf_Ehdr *hdr, + Elf_Shdr *sechdrs, + char *secstrings, + struct module *mod); + #endif /* CONFIG_MODULES */ extern struct list_head module_list; |