From: Tulio A M Mendes Date: Fri, 13 Feb 2026 20:01:37 +0000 (-0300) Subject: feat: migrate PCI and E1000 to HAL driver registry X-Git-Url: https://projects.tadryanom.me/docs/static/gitweb.js?a=commitdiff_plain;h=5c4e1226014c4bcf227544576af143a76a8ff597;p=AdrOS.git feat: migrate PCI and E1000 to HAL driver registry - 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 --- diff --git a/include/e1000.h b/include/e1000.h index 16492ce..b34293c 100644 --- a/include/e1000.h +++ b/include/e1000.h @@ -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 diff --git a/include/pci.h b/include/pci.h index bc0f79e..65d3583 100644 --- a/include/pci.h +++ b/include/pci.h @@ -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 diff --git a/src/drivers/e1000.c b/src/drivers/e1000.c index 3423917..2665771 100644 --- a/src/drivers/e1000.c +++ b/src/drivers/e1000.c @@ -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); +} diff --git a/src/hal/x86/pci.c b/src/hal/x86/pci.c index 08b86a7..f3a8514 100644 --- a/src/hal/x86/pci.c +++ b/src/hal/x86/pci.c @@ -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); +} diff --git a/src/kernel/init.c b/src/kernel/init.c index eb410aa..d86ab48 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -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();