|
My Kernel v0.1.0
|
Kernel Device/Driver API. More...

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 device * | device_find (const char *name) |
| Find a registered device by name. | |
| struct file * | device_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) |
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.
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.
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.
| #define generate_device_rw_functions | ( | _pfx, | |
| _dev_type, | |||
| _reg_field, | |||
| _off_type | |||
| ) |
The functions are named: prefix_[read,write][b,w,l]
| _pfx | The device's functions' prefix |
| _dev_type | The device's type |
| _reg_field | The name of the fields pointing to the device's registers |
| _off_type | The type used for the offset variable |
@info _off_type must be indirectly castable into an integer
|
inlinestatic |
| error_t device_register | ( | device_t * | dev | ) |
The device must have been allocated and initialized first by its corresponding driver.