From 943bed289d145c1ff09bdd888f8060f2cfb433e8 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 2 May 2026 23:36:26 +0800 Subject: feat: add driver registration subsystem with probe functionality --- na/include/lume/driver.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 na/include/lume/driver.h (limited to 'na/include') 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 + +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(); -- cgit v1.2.3