My Kernel v0.1.0

Driver API. More...

Collaboration diagram for Drivers:

Data Structures

struct  device_driver
 The basic device driver structure. More...
 

Macros

#define DECLARE_DRIVER(_name, _driver, _driver_register)
 Declare a new driver. More...
 

Functions

void driver_register (driver_t *driver)
 Register a new driver. More...
 
void driver_load_drivers (void)
 Load all builtin drivers. More...
 
driver_tdriver_find_match (device_t *)
 Retreive the driver that matches the given arguments. More...
 

Detailed Description

Drivers

This file describes the driver part of the Device/Driver API.

Creating a driver

When creating a new driver, you MUST declare it using DECLARE_DRIVER. All drivers declared using this macro are automatically loaded when starting up the kernel.

The kernel automatically detects and keeps track of all the connected hardware devices. When a new device is detected, its corresponding driver is looked for inside this list of loaded drivers. If a match is found, the matching driver's probe function is called to create the correct type of device, and register it.

Driver types

Drivers for devices on a same bus generally share some similarities, at least in the way the are interacted with. The driver struct should be embedded inside a more specific 'per-bus' struct and interacted with through the bus's API.

See also
Devices

Macro Definition Documentation

◆ DECLARE_DRIVER

#define DECLARE_DRIVER (   _name,
  _driver,
  _driver_register 
)
Value:
static void init_driver_##_name(void) \
{ \
_driver_register(_driver); \
} \
\
SECTION(".data.driver.init") \
MAYBE_UNUSED \
static driver_init_t __##_name##_driver_init = init_driver_##_name;

Drivers declared using this macro are automatically loaded at startup, and are automatically associated with their corresponding devices.

Parameters
_nameThe name of the driver
_driverThe driver's definition (device_driver)
_driver_registerThe per-bus API register function

Function Documentation

◆ driver_find_match()

driver_t * driver_find_match ( device_t dev)
Returns
A pointer to the driver, or one containing an eventual error code.

◆ driver_load_drivers()

void driver_load_drivers ( void  )

Builtin drivers are ones declared using DECLARE_DRIVER

◆ driver_register()

void driver_register ( driver_t driver)

This function adds the driver to the list of enumeratable drivers. It should always be called inside a per-bus API's register function as this step is bus-independent (and required).

After a driver has been registerd, any newly detected device that it matches will automatically be bound to it using the probe function.

@info This function is generally called automatically during startup on the declared drivers, and should not need to be called manually elsewhere.