]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: migrate PCI and E1000 to HAL driver registry
authorTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 20:01:37 +0000 (17:01 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 20:01:37 +0000 (17:01 -0300)
- PCI: hal_driver 'x86-pci' (BUS, priority 10) — self-registers via pci_driver_register()
- E1000: hal_driver 'e1000' (NET, priority 20) — probe checks PCI for Intel 82540EM
- init.c: replace explicit pci_init()/e1000_init() with driver registration + hal_drivers_init_all()
- Drivers init in priority order: PCI bus first, then E1000 probes and inits
- Pattern ready for additional drivers to self-register

20/20 smoke, cppcheck clean

include/e1000.h
include/pci.h
src/drivers/e1000.c
src/hal/x86/pci.c
src/kernel/init.c

index 16492ce074d174ad3ae25781754df0f7ce030f66..b34293c8f66103267e3e3937f81aec064c82477b 100644 (file)
@@ -125,4 +125,6 @@ void e1000_get_mac(uint8_t mac[6]);
 /* Check if the NIC is initialized and link is up. */
 int e1000_link_up(void);
 
+void e1000_driver_register(void);
+
 #endif
index bc0f79eb1f5939edb0c0b0cea8e3fd23202de643..65d358312cbfd73c3cf42fad6cd96b416f9c1fb1 100644 (file)
@@ -28,4 +28,6 @@ const struct pci_device* pci_get_device(int index);
 const struct pci_device* pci_find_device(uint16_t vendor, uint16_t device);
 const struct pci_device* pci_find_class(uint8_t class_code, uint8_t subclass);
 
+void pci_driver_register(void);
+
 #endif
index 3423917e60b8e1cd805f90d729c03bf80f0fd47a..2665771f7e61126b5c481b83cc687d75053daa1a 100644 (file)
@@ -1,4 +1,5 @@
 #include "e1000.h"
+#include "hal/driver.h"
 #include "kernel_va_map.h"
 #include "pci.h"
 #include "vmm.h"
@@ -359,3 +360,19 @@ int e1000_link_up(void) {
     if (!e1000_ready) return 0;
     return (e1000_read(E1000_STATUS) & (1U << 1)) ? 1 : 0;
 }
+
+/* HAL driver registration */
+static int e1000_drv_probe(void) {
+    return pci_find_device(0x8086, 0x100E) ? 0 : -1;
+}
+
+static const struct hal_driver e1000_hal_driver = {
+    .name     = "e1000",
+    .type     = HAL_DRV_NET,
+    .priority = 20,
+    .ops      = { .probe = e1000_drv_probe, .init = e1000_init, .shutdown = NULL }
+};
+
+void e1000_driver_register(void) {
+    hal_driver_register(&e1000_hal_driver);
+}
index 08b86a79cdfdbcd37122b5943264075497b495b8..f3a851443c4a148ca714f91935118ec15b4ad719 100644 (file)
@@ -1,4 +1,5 @@
 #include "pci.h"
+#include "hal/driver.h"
 #include "console.h"
 #include "utils.h"
 #include "io.h"
@@ -133,3 +134,17 @@ const struct pci_device* pci_find_class(uint8_t class_code, uint8_t subclass) {
     }
     return 0;
 }
+
+/* HAL driver registration */
+static int pci_drv_init(void) { pci_init(); return 0; }
+
+static const struct hal_driver pci_hal_driver = {
+    .name     = "x86-pci",
+    .type     = HAL_DRV_BUS,
+    .priority = 10,
+    .ops      = { .probe = NULL, .init = pci_drv_init, .shutdown = NULL }
+};
+
+void pci_driver_register(void) {
+    hal_driver_register(&pci_hal_driver);
+}
index eb410aab59ad560aa072cb5c5885a2937e1a3694..d86ab4849efe77662e576810cebce27e534592da 100644 (file)
@@ -1,6 +1,7 @@
 #include "kernel/init.h"
 
 #include "arch/arch_platform.h"
+#include "hal/driver.h"
 
 #include "fs.h"
 #include "initrd.h"
@@ -192,8 +193,11 @@ int init_start(const struct boot_info* bi) {
         (void)vfs_mount("/tmp", tmp);
     }
 
-    pci_init();
-    e1000_init();
+    /* Register hardware drivers with HAL and init in priority order */
+    pci_driver_register();      /* priority 10: bus */
+    e1000_driver_register();    /* priority 20: NIC (probes PCI) */
+    hal_drivers_init_all();
+
     net_init();
     net_ping_test();
     ksocket_init();