From 3538376f2826ed4861d45f92e542cfa0b4a660d9 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Fri, 13 Feb 2026 17:01:37 -0300 Subject: [PATCH] feat: migrate PCI and E1000 to HAL driver registry MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - 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 | 2 ++ include/pci.h | 2 ++ src/drivers/e1000.c | 17 +++++++++++++++++ src/hal/x86/pci.c | 15 +++++++++++++++ src/kernel/init.c | 8 ++++++-- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/e1000.h b/include/e1000.h index 31ee8797..f60bd9f6 100644 --- a/include/e1000.h +++ b/include/e1000.h @@ -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 diff --git a/include/pci.h b/include/pci.h index e3aba060..90b874aa 100644 --- a/include/pci.h +++ b/include/pci.h @@ -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 diff --git a/src/drivers/e1000.c b/src/drivers/e1000.c index b1a09950..2e9f6768 100644 --- a/src/drivers/e1000.c +++ b/src/drivers/e1000.c @@ -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); +} diff --git a/src/hal/x86/pci.c b/src/hal/x86/pci.c index 55a16c36..d6d15dcf 100644 --- a/src/hal/x86/pci.c +++ b/src/hal/x86/pci.c @@ -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); +} diff --git a/src/kernel/init.c b/src/kernel/init.c index c5a67de7..5f835ff4 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -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(); -- 2.43.0