Q&A-17Walk me through how a peripheral gets enumerated and bound to a driver (device tree, ACPI, or PCI config space) and what happens when probe needs a clock or regulator that isn't ready yet?
Answer
Three paths carry a device from firmware to a driver, and they differ in who owns the description.
PCI is self-describing. The kernel walks bus 0–255, device 0–31, function 0–7, reading vendor/device ID from config space: ECAM/MMCONFIG on modern systems, the 0xCF8/0xCFC pair on legacy x86. A vendor read of 0xFFFF means no device. BARs are sized by writing all-ones and reading back the mask. Matching is by pci_device_id: PCI_DEVICE(v, d) or PCI_DEVICE_CLASS(class, mask). By the time probe runs, resources are already assigned.
Device tree and ACPI describe non-discoverable devices. DT is compiled into the image (or an overlay) and matched via of_device_id.compatible against the node's compatible string. ACPI matches acpi_device_id against _HID/_CID, with _CRS carrying memory, IRQ and GPIO resources; PRP0001 lets an ACPI system describe a DT-compatible device. Zephyr has no runtime DT at all: the .dts is compiled to devicetree_generated.h at build time, and DEVICE_DT_INST_DEFINE with DT_INST_FOREACH_STATUS_OKAY instantiates one struct device per enabled node.
| path | who describes it | match key | resource source |
|---|---|---|---|
| PCI | the device itself | vendor/device or class ID | config space BARs, assigned by kernel |
| DT | firmware blob, build-time in Zephyr | compatible | node properties, phandles |
| ACPI | firmware namespace | _HID/_CID | _CRS |
That difference decides how you handle a missing clock or regulator. Linux returns -EPROBE_DEFER from probe; the driver core puts the device on the deferred probe pending list and retries it after every successful probe and at late_initcall. fw_devlink (default on since 5.13) reads the firmware graph (clock, regulator and GPIO phandles) and orders probes so suppliers go first, which removes most deferrals before they happen. deferred_probe_timeout is 0 by default, so a device can sit on that list forever.
c static int foo_probe(struct platform_device *pdev) { struct clk clk = devm_clk_get(&pdev->dev, "core"); if (IS_ERR(clk)) return dev_err_probe(&pdev->dev, PTR_ERR(clk), "core clock\n"); / dev_err_probe() returns the code and stays quiet for -EPROBE_DEFER */ ... }
Zephyr has no retry loop. Ordering is init level (PRE_KERNEL_1/2, POST_KERNEL, APPLICATION) plus init priority, and a consumer that needs a later device gates on device_is_ready() and returns -ENODEV if it is not up:
c static int foo_init(const struct device *dev) { const struct foo_config cfg = dev->config; if (!device_is_ready(cfg->clk_dev)) return -ENODEV; / permanent: Zephyr will not call this again */ ... }
Trace of a deferral: foo_probe → devm_clk_get("core") → -EPROBE_DEFER → device queued on deferred_probe_pending_list → clk driver probes → driver_deferred_probe_trigger() → foo_probe runs again → succeeds.
Failure modes worth naming. A deferral that never resolves is silent: the device simply never appears, no error in dmesg. Check /sys/kernel/debug/devices_deferred and the supplier's module load state. Returning -EPROBE_DEFER after irreversible side effects (registering an IRQ, enabling a regulator, allocating a non-devm_ buffer) means the second probe double-registers or leaks; acquire everything first or use devm_. Probe is not once-only: sysfs unbind/rebind calls it again, so it must be idempotent. And in Zephyr, -ENODEV from init is final: a driver whose dependency sits later in the same init level never comes up, and the only fix is level/priority or polling device_is_ready() in the consumer.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.