godspeed/driver/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2//! `gs::driver` - the device-neutral mechanisms a driver is built from.
3//!
4//! # What belongs here, and what never does
5//!
6//! A driver describes a device. This module holds what is left when the device is taken away: the
7//! mechanisms every driver needs and no driver should have to reinvent. The question that decides
8//! membership is the one `docs/driver-library.md` opens with - **does this part describe the device,
9//! or a reusable Godspeed mechanism?** A register sequence, a command set, a firmware's quirks and a
10//! chip's recovery dance describe the device and stay in its driver. How long to wait for a register,
11//! how to say the wait gave up, how long to hold still when no register can say, and how to wait for an
12//! interrupt without losing a request, describe neither - so they are here (`wait`, `delay`, `irq`). So are
13//! the two grants a driver names: its register window (`registers`) and its DMA arena, laid out by name
14//! (`arena`). And so are the calls a driver made to the SDK for what its grants carry with them: the input
15//! it hands the console (`input`), its device's power (`power`), and what the kernel knows about the device
16//! that the driver cannot read for itself (`device`) - each the SDK's own call, so that a driver is written
17//! on this module and nothing beside it (step 5). And a device that has no registers of its own, because it is
18//! on a bus whose host owns them - a USB device - is reached through that host (`bus`), as a bus and never as a
19//! class: it moves transfers and knows nothing of what the device is.
20//!
21//! **There are no device CLASSES here, and there will not be.** No driver::wifi, driver::audio or
22//! driver::usb: a class API is a guess about what every device of that kind will need, made before
23//! most of them exist. A family of devices that genuinely shares a protocol gets a domain library of
24//! its own outside the standard library (`sdk/wifi` is the first), built on this module.
25//!
26//! # How a mechanism gets in
27//!
28//! By being REPEATED, not by being imagined. Each module here was found written out by hand in more
29//! than one driver, differently each time, and then moved here and the drivers converted to it. `irq`
30//! was built from `xhci`, `ehci` and `dwc2`, tested by the two audio drivers, and since 2026-10-22 is
31//! the wait of all five. (`input`, `power` and `device` are the exception, recorded in step 5: each is
32//! one SDK call a driver must name, wrapped, not a mechanism found written out.) A
33//! second, independent kind of driver using it naturally is the test of whether it is general; one
34//! that has to be bent to fit it means the abstraction is shaped like the driver it came from.
35//!
36//! # Unsafe
37//!
38//! None, as everywhere in this crate (`#![deny(unsafe_code)]`). A driver that seems to need `unsafe`
39//! is asking a question - **which safe mechanism is missing from here?** - and the answer belongs in
40//! this module or the SDK's audited layer (CLAUDE.md 18.1), never in the driver.
41//!
42//! # What it does not change
43//!
44//! The kernel. Nothing here is a new kernel responsibility or a new syscall; these are the mechanisms
45//! the kernel already offers, put in the one shape a driver should reach for.
46
47pub mod arena;
48// A device reached through its bus's host, not registers of its own: a USB device's transfers (2026-10-23).
49#[cfg(not(test))]
50pub mod bus;
51pub mod delay;
52pub mod device;
53pub mod input;
54pub mod irq;
55pub mod power;
56pub mod registers;
57pub mod wait;
58
59// The two grants a driver names and relies on (step 3, 2026-10-19): its device's registers and its DMA
60// arena, taken at the top of a driver, so they are here rather than a module down.
61#[cfg(not(test))]
62pub use arena::{arena, Arena, Layout, Part};
63#[cfg(not(test))]
64pub use registers::{registers, Registers};