Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel: Introduce a new model for writing devicetree drivers #25192

Merged
merged 5 commits into from
Nov 2, 2024

Conversation

spholz
Copy link
Member

@spholz spholz commented Oct 29, 2024

This PR should make writing devicetree drivers a lot simpler and keep code duplication minimal.

This PR does not depend on #25103. But we will need that PR to actually get the physical addresses from the 'reg' properties.

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 29, 2024
@spholz spholz force-pushed the aarch64-devicetree-drivers branch from 1dca154 to bd5c7d9 Compare October 29, 2024 20:13
Copy link
Contributor

@Hendiadyoin1 Hendiadyoin1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
(am biased though)

Copy link
Contributor

@nico nico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Userland/Libraries/LibDeviceTree/DeviceTree.cpp Outdated Show resolved Hide resolved
Kernel/Bus/USB/USBDevice.cpp Show resolved Hide resolved
Kernel/Arch/init.cpp Show resolved Hide resolved
@spholz spholz force-pushed the aarch64-devicetree-drivers branch from bd5c7d9 to 7cfa4a1 Compare November 2, 2024 14:47
This will be needed in the next commit, which moves the driver init
functions calling code earlier into the boot process.
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.
@spholz spholz force-pushed the aarch64-devicetree-drivers branch from 7cfa4a1 to c1460d3 Compare November 2, 2024 15:04
This driver doesn't actually get any info (like the physical address)
from the devicetree node for now.
This driver doesn't actually get any info (like the physical address)
from the devicetree node for now.
@spholz spholz force-pushed the aarch64-devicetree-drivers branch from c1460d3 to 87adc01 Compare November 2, 2024 17:06
@nico nico merged commit d6a3500 into SerenityOS:master Nov 2, 2024
12 of 13 checks passed
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Nov 2, 2024
@spholz spholz deleted the aarch64-devicetree-drivers branch November 2, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants