]> 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 31ee879767c54778e0eb1a8a7daaf42650262907..f60bd9f6bdd22845b2ad77b9e4ebf7bafbb44f9a 100644 (file)
@@ -134,4 +134,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 e3aba0602dd332eace6a5a5c5a141e7eba97c276..90b874aa55931c3c124862024379bcce936cdc4d 100644 (file)
@@ -37,4 +37,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 b1a09950cc2a25cfc20cafcde0e62d6227704048..2e9f6768cb0cbf478807beaf452359116bc3bfab 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "e1000.h"
+#include "hal/driver.h"
 #include "kernel_va_map.h"
 #include "pci.h"
 #include "vmm.h"
@@ -368,3 +369,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 55a16c36bd1b9f6ae06f2ce98fc2b9d966c53da9..d6d15dcfd632650f6bb000a3ab3b8c24881b8e3d 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "pci.h"
+#include "hal/driver.h"
 #include "console.h"
 #include "utils.h"
 #include "io.h"
@@ -142,3 +143,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 c5a67de7d9b975f1e1e06922260c9690214ec064..5f835ff4afd33ae3a8e9d0c461e45e27baf7e80b 100644 (file)
@@ -10,6 +10,7 @@
 #include "kernel/init.h"
 
 #include "arch/arch_platform.h"
+#include "hal/driver.h"
 
 #include "fs.h"
 #include "initrd.h"
@@ -201,8 +202,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();