My Kernel v0.1.0

Kernel Device/Driver API. More...

Collaboration diagram for Devices:

Modules

 ACPI
 
 Drivers
 Driver API.
 
 Network Device
 
 PCI
 

Data Structures

struct  device
 Represents a device inside the kernel. More...
 

Macros

#define generate_device_rw_functions(_pfx, _dev_type, _reg_field, _off_type)
 Generate generic functions used to read/write a device's regsiters. More...
 

Functions

error_t device_register (device_t *)
 Register a new device. More...
 
struct devicedevice_find (const char *name)
 Find a registered device by name.
 
struct filedevice_open (device_t *)
 Open a device for interacting with it.
 
static void device_set_name (struct device *dev, const char *name)
 Set the name of the device.
 
static const char * device_name (struct device *dev)
 

Detailed Description

Devices

Philsophy

This device driver API is heavily inspired by Linux's one, as it is the only one I'm familiar with currently, and I like it.

Hardware interactions are split into two 3 parts:

Every interaction with a hardware component is done by interacting with its corresponding device.

Design

Devices come in many shapes (timers, buses, etc ...), and as such, the sets of functions used to communicate with a given hardware varies a lot. The different function groups (vtables) should be located inside the device struct (whichever one, depending on the type of hardware), and should stay hidden the driver.

The driver's only responsibility is to create, initialize and register the appropriate device device for its hardware. Once the device has been registered, it can be used to communicate with the underlying hardware.

Usage

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 in the list of curenlty loaded drivers. If a matching one has been found, it is requested to create the appropriate device.

See also
Drivers

Macro Definition Documentation

◆ generate_device_rw_functions

#define generate_device_rw_functions (   _pfx,
  _dev_type,
  _reg_field,
  _off_type 
)
Value:
__device_read(u8, b, _pfx, _dev_type, _reg_field, _off_type) \
__device_write(u8, b, _pfx, _dev_type, _reg_field, _off_type) \
__device_read(u16, w, _pfx, _dev_type, _reg_field, _off_type) \
__device_write(u16, w, _pfx, _dev_type, _reg_field, _off_type) \
__device_read(u32, l, _pfx, _dev_type, _reg_field, \
_off_type) \
__device_write(u32, l, _pfx, _dev_type, _reg_field, \
_off_type)

The functions are named: prefix_[read,write][b,w,l]

Parameters
_pfxThe device's functions' prefix
_dev_typeThe device's type
_reg_fieldThe name of the fields pointing to the device's registers
_off_typeThe type used for the offset variable

@info _off_type must be indirectly castable into an integer

Function Documentation

◆ device_name()

static const char * device_name ( struct device dev)
inlinestatic
Returns
The name of the device

◆ device_register()

error_t device_register ( device_t dev)

The device must have been allocated and initialized first by its corresponding driver.