From 6340e5d4504a4910fa6d2ea613cef10f6e4d8428 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Tue, 11 Aug 2026 21:28:55 -0400 Subject: [PATCH] driver: add initial driver layer functions Signed-off-by: Michael Shaw --- drivers/ahci.c | 6 ++++-- drivers/pci/pci.c | 2 +- include/kernel/driver.h | 19 +++++++++++++++++++ kernel/driver.c | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/ahci.c b/drivers/ahci.c index f656a6a..2178c08 100644 --- a/drivers/ahci.c +++ b/drivers/ahci.c @@ -376,7 +376,7 @@ static void ahci_probe_ports(struct ahci_host *host) } } -static int ahci_init_device(struct pci_device *device, size_t ahci_dev_no) +static int ahci_init_device(struct pci_device *device) { struct ahci_host *host = kzalloc(sizeof(struct ahci_host), ALLOC_KERN); if (!host) @@ -395,6 +395,8 @@ void ahci_init() list_t dev_list; list_create(&dev_list); + driver_register("ahci", DRIVER_PCI, ahci_init_device, NULL, 1, 6); + krdy("AHCI ready\n"); } -DRIVER_ENTRY_PRIORITY(ahci_init, 3); +DRIVER_ENTRY_PRIORITY(ahci_init, 2); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b8ee97b..d2b1c48 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -152,4 +152,4 @@ void pci_init() krdy("PCI ready\n"); } -DRIVER_ENTRY_PRIORITY(pci_init, 2); +DRIVER_ENTRY_PRIORITY(pci_init, 4); diff --git a/include/kernel/driver.h b/include/kernel/driver.h index e2b9331..322af0a 100644 --- a/include/kernel/driver.h +++ b/include/kernel/driver.h @@ -2,7 +2,26 @@ #ifndef _DRIVER_H_ #define _DRIVER_H_ +#include +#include + #define DRIVER_ENTRY(fn) static void (*__initcall_##fn)(void) __attribute((used, section(".initcall"))) = fn #define DRIVER_ENTRY_PRIORITY(fn, pr) static void (*__initcall_##fn)(void) __attribute((used, section(".initcall." #pr))) = fn +#define DRIVER_PCI 1 + +typedef int (*pci_init_t)(struct pci_device *dev); + +struct driver { + char name[32]; + u64 type; + void *init_device; + void *deinit_device; + u64 major; + u64 minor; +}; + +int driver_register(const char *name, u64 type, void *init, void *deinit, u64 major, u64 minor); +struct driver *driver_find(const char *name); + #endif /* _DRIVER_H_ */ diff --git a/kernel/driver.c b/kernel/driver.c index 853b087..d5a8c07 100644 --- a/kernel/driver.c +++ b/kernel/driver.c @@ -1 +1,17 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include +#include + +int driver_register(const char *name, u64 type, void *init, void *deinit, u64 major, u64 minor) +{ + struct driver *driver = kzalloc(sizeof(struct driver), ALLOC_KERN); + strncpy(driver->name, name, sizeof(driver->name) - 1); + driver->type = type; + driver->init_device = init; + driver->deinit_device = deinit; + driver->major = major; + driver->minor = minor; + + return 0; +}