summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-05-02 23:36:26 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-05-02 23:36:26 +0800
commit943bed289d145c1ff09bdd888f8060f2cfb433e8 (patch)
tree2b4dcb8d296d0a18cb06281875657fca2b861a7d
parent70b0c0f6032abfd820ccee22c23bc66d171bee34 (diff)
downloadlume-943bed289d145c1ff09bdd888f8060f2cfb433e8.tar.gz
lume-943bed289d145c1ff09bdd888f8060f2cfb433e8.tar.xz
feat: add driver registration subsystem with probe functionality
-rw-r--r--na/drivers/driver.cc27
-rw-r--r--na/include/lume/driver.h33
2 files changed, 60 insertions, 0 deletions
diff --git a/na/drivers/driver.cc b/na/drivers/driver.cc
new file mode 100644
index 0000000..5810645
--- /dev/null
+++ b/na/drivers/driver.cc
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+#include <lume/driver.h>
+#include <lume/fdt.h>
+#include <lume/kprintf.h>
+
+extern "C" {
+ extern DriverEntry __drivers_start[];
+ extern DriverEntry __drivers_end[];
+}
+
+void driver_probe_all() {
+ DeviceNode* root = fdt_get_node_by_path("/");
+ if (!root) {
+ kprintf("[driver] WARN: No FDT root found\n");
+ return;
+ }
+
+ for (DriverEntry* drv = __drivers_start; drv < __drivers_end; ++drv) {
+ DeviceNode* node = fdt_find_compatible(drv->compatible);
+ if (node) {
+ kprintf("[driver] Probing %s\n", drv->compatible);
+ drv->probe(node);
+ }
+ }
+}
diff --git a/na/include/lume/driver.h b/na/include/lume/driver.h
new file mode 100644
index 0000000..c9d5669
--- /dev/null
+++ b/na/include/lume/driver.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+#pragma once
+
+/*
+ * Driver Registration Subsystem
+ *
+ * Provides a linker-set based registration mechanism for hardware drivers.
+ * Drivers define a probe function and register it with the REGISTER_DRIVER macro.
+ * During boot, driver_probe_all() scans the Device Tree (FDT) and invokes the
+ * probe function for any matching compatible strings.
+ *
+ * This decouples the MI kernel initialization from MD driver specifics.
+ */
+
+#include <lume/types.h>
+
+class DeviceNode;
+
+using DriverProbeFunc = void (*)(DeviceNode* node);
+
+struct DriverEntry {
+ const char* compatible;
+ DriverProbeFunc probe;
+};
+
+#define REGISTER_DRIVER(compat_str, probe_fn) \
+ static const DriverEntry __driver_##probe_fn \
+ __attribute__((used, section(".drivers"))) = { compat_str, probe_fn }
+
+/* MI initialization function called from kernel_main() */
+void driver_probe_all();