diff mbox series

[RFC,3/6] rust: module: Allow modules to specify initcall section

Message ID 20240815082916.1210110-4-pierre.gondois@arm.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series rust: cpufreq: Add cppc_cpufreq driver implementation | expand

Commit Message

Pierre Gondois Aug. 15, 2024, 8:29 a.m. UTC
To give more flexibility to modules regarding their initialization,
add an `initcall` field allowing to specify the initicall section
their initialization function belongs to.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 rust/macros/module.rs | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index be03b2cf77a1..8724738f2a52 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -97,14 +97,22 @@  struct ModuleInfo {
     author: Option<String>,
     description: Option<String>,
     alias: Option<Vec<String>>,
+    initcall: Option<String>,
 }
 
 impl ModuleInfo {
     fn parse(it: &mut token_stream::IntoIter) -> Self {
         let mut info = ModuleInfo::default();
 
-        const EXPECTED_KEYS: &[&str] =
-            &["type", "name", "author", "description", "license", "alias"];
+        const EXPECTED_KEYS: &[&str] = &[
+            "type",
+            "name",
+            "author",
+            "description",
+            "license",
+            "alias",
+            "initcall",
+        ];
         const REQUIRED_KEYS: &[&str] = &["type", "name", "license"];
         let mut seen_keys = Vec::new();
 
@@ -131,6 +139,7 @@  fn parse(it: &mut token_stream::IntoIter) -> Self {
                 "description" => info.description = Some(expect_string(it)),
                 "license" => info.license = expect_string_ascii(it),
                 "alias" => info.alias = Some(expect_string_array(it)),
+                "initcall" => info.initcall = Some(expect_string(it)),
                 _ => panic!(
                     "Unknown key \"{}\". Valid keys are: {:?}.",
                     key, EXPECTED_KEYS
@@ -187,6 +196,12 @@  pub(crate) fn module(ts: TokenStream) -> TokenStream {
         }
     }
 
+    let initcall_section = if let Some(section) = info.initcall {
+        section
+    } else {
+        String::from(".initcall6.init")
+    };
+
     // Built-in modules also export the `file` modinfo string.
     let file =
         std::env::var("RUST_MODFILE").expect("Unable to fetch RUST_MODFILE environmental variable");
@@ -335,7 +350,7 @@  unsafe fn __exit() {{
         type_ = info.type_,
         name = info.name,
         modinfo = modinfo.buffer,
-        initcall_section = ".initcall6.init"
+        initcall_section = initcall_section,
     )
     .parse()
     .expect("Error parsing formatted string into token stream.")