mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: David Dgien <dgienda125@gmail.com>
To: barebox@lists.infradead.org
Cc: David Dgien <dgienda125@gmail.com>
Subject: [RFC PATCH 2/8] module: Add init macros to module.h
Date: Tue, 16 Jun 2020 23:43:58 -0400	[thread overview]
Message-ID: <20200617034404.5904-3-dgienda125@gmail.com> (raw)
In-Reply-To: <20200617034404.5904-1-dgienda125@gmail.com>

Port module initialization macros and initcall redefinition macros from
Linux

Signed-off-by: David Dgien <dgienda125@gmail.com>
---
 include/module.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/include/module.h b/include/module.h
index cea8c2e18..37c48f065 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,96 @@
 
 #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.
+ */
+#undef core_initcall
+#undef postcore_initcall
+#undef console_initcall
+#undef postconsole_initcall
+#undef mem_initcall
+#undef mmu_initcall
+#undef postmmu_initcall
+#undef coredevice_initcall
+#undef fs_initcall
+#undef device_initcall
+#undef late_initcall
+
+#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)
+
+#undef early_exitcall
+#undef predevshutdown_exitcall
+#undef devshutdown_exitcall
+#undef postdevshutdown_exitcall
+#undef prearchshutdown_exitcall
+#undef archshutdown_exitcall
+#undef postarchshutdown_exitcall
+
+#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>
 
-- 
2.27.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-06-17  3:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17  3:43 [RFC PATCH 0/8] Module and ARM Module updates and fixes David Dgien
2020-06-17  3:43 ` [RFC PATCH 1/8] Makefile: Initialize and export KBUILD variables David Dgien
2020-06-17  3:43 ` David Dgien [this message]
2020-06-17  3:43 ` [RFC PATCH 3/8] module: Fix adding module to list after layout David Dgien
2020-06-17  3:44 ` [RFC PATCH 4/8] module: Fix module command registration David Dgien
2020-06-17  3:44 ` [RFC PATCH 5/8] module: Implement HAVE_MOD_ARCH_SPECIFIC David Dgien
2020-06-17  3:44 ` [RFC PATCH 6/8] arm: makefile: Fix compiler flag variable David Dgien
2020-06-17  3:44 ` [RFC PATCH 7/8] arm: elf: Add THM relocation types David Dgien
2020-06-17  3:44 ` [RFC PATCH 8/8] arm: module: Allow modules outside of bl range David Dgien
2020-06-17 13:52   ` Sascha Hauer
2020-06-17 13:45 ` [RFC PATCH 0/8] Module and ARM Module updates and fixes Sascha Hauer
2020-06-18  1:54   ` David Dgien
2020-06-18 13:10     ` Sascha Hauer
2020-06-22 17:52       ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200617034404.5904-3-dgienda125@gmail.com \
    --to=dgienda125@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox