mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-11 17:37:00 +02:00
Devicetree drivers are created by using the `DEVICETREE_DRIVER` macro. That macro creates a new class deriving from `DeviceTree::Driver` and inserts it into the driver init section. The driver code then has to implement the `probe` member function, which will be called if `DeviceTree::Management` finds a node with a compatible property entry that was in the array passed as the second argument to the `DEVICETREE_DRIVER` macro. The `probe` function then will check if it supports the given node and if so, registers a `DeviceTree::DeviceRecipe` at the appropriate subsystem, which will then create a device from that recipe once it is initialized. The driver can store the necessary info it got from the devicetree, such as the physical address and interrupt numbers, in the capture list of the callback lambda stored in `DeviceRecipe::create_device`. The `DeviceTree::DeviceRecipe`s are necessary, as the `probe` functions might not be able to create an instance of the actual device class, since doing so can depend on some subsystems being initialized first.