My Kernel v0.1.0
driver.h
1
35#pragma once
36
37#include <kernel/device.h>
38#include <kernel/error.h>
39
40#include <libalgo/linked_list.h>
41#include <utils/compiler.h>
42
77typedef struct device_driver {
78
79 node_t this;
80 const char *name;
81
87 error_t (*probe)(device_t *);
91 bool (*match)(const driver_t *, const device_t *);
93
94} driver_t;
95
108void driver_register(driver_t *driver);
109
110error_t driver_probe(driver_t *driver, device_t *device);
111
112typedef void (*driver_init_t)(void);
113
123#define DECLARE_DRIVER(_name, _driver, _driver_register) \
124 static void init_driver_##_name(void) \
125 { \
126 _driver_register(_driver); \
127 } \
128 \
129 SECTION(".data.driver.init") \
130 MAYBE_UNUSED \
131 static driver_init_t __##_name##_driver_init = init_driver_##_name;
132
136void driver_load_drivers(void);
137
142
void driver_register(driver_t *driver)
Register a new driver.
Definition: driver.c:45
void driver_load_drivers(void)
Load all builtin drivers.
Definition: driver.c:34
driver_t * driver_find_match(device_t *)
Retreive the driver that matches the given arguments.
Definition: driver.c:68
Vector table of the common operations used to control drivers.
Definition: driver.h:85
error_t(* probe)(device_t *)
Bind the driver to a device.
Definition: driver.h:87
bool(* match)(const driver_t *, const device_t *)
Check if the driver should be used for this device This function should be the same for each driver o...
Definition: driver.h:91
The basic device driver structure.
Definition: driver.h:77
struct device_driver::driver_operations operations
Vector table of driver control operations.
const char * name
The name of the driver.
Definition: driver.h:80
Represents a device inside the kernel.
Definition: device.h:78
Intrusive doubly-linked list node.
Definition: linked_list.h:27