/** * @file driver.h * @brief Kernel driver architecture. * * Provides a simple framework for registering and initializing kernel drivers. * Each driver provides a probe function that returns whether it should load, * and an init function that performs the actual initialization. * * Drivers are registered at compile time using the REGISTER_DRIVER macro, * which places driver descriptors in a special linker section. The kernel * iterates over all registered drivers during boot. */ #ifndef DRIVER_H #define DRIVER_H #include /** Driver probe result codes. */ typedef enum { DRIVER_PROBE_OK = 0, /**< Driver should be loaded. */ DRIVER_PROBE_NOT_FOUND = 1, /**< Hardware not found, skip this driver. */ DRIVER_PROBE_ERROR = 2 /**< Error during probing. */ } driver_probe_result_t; /** * Driver descriptor structure. * * Each driver provides a name, a probe function (to test if hardware is * present), and an init function (to set up the driver). */ typedef struct driver { const char *name; /**< Human-readable driver name. */ driver_probe_result_t (*probe)(void); /**< Probe function. Returns DRIVER_PROBE_OK if driver should load. */ int (*init)(void); /**< Init function. Returns 0 on success, non-zero on failure. */ } driver_t; /** * Register a driver. * * Places the driver descriptor in the .drivers linker section so it * is automatically discovered during boot. */ #define REGISTER_DRIVER(drv) \ static const driver_t * __attribute__((used, section(".drivers"))) \ _driver_##drv = &(drv) /** * Initialize all registered drivers. * * Iterates over the .drivers section, probes each driver, and initializes * those that respond positively to probing. */ void init_drivers(void); #endif /* DRIVER_H */