Architecture
KDAL is a six-layer kernel framework plus a domain-specific language (DSL) toolchain that decouples device drivers from hardware specifics, enabling portable driver development across embedded platforms.
Layer Diagram
Section titled “Layer Diagram”The same diagram as KDAL’s README (key: Start here, Reading the
diagrams): green parts are built into kdal.ko, which CI loads and tests with its
KUnit suites; the user-space programs build, but CI does not run them
against the module.
Layer Responsibilities
Section titled “Layer Responsibilities”Layer 0 - Language Toolchain
Section titled “Layer 0 - Language Toolchain”compiler/, lang/
.kdhdevice headers - declarative register maps, signals, capabilities, power states.kdcdriver files - imperative event handlers (probe, read, write, signal, power)- Compiler pipeline - lexer → parser → AST → semantic analysis → C code generation
- Standard library - 7
.kdhfiles inlang/stdlib/(common, UART, I2C, SPI, GPIO, GPU, NPU) - Output - kernel C (
platform_driver,devm_*, OF match table) +Makefile.kbuild; the generated module does not build yet (open finding O7)
Layer 1 - Public Headers
Section titled “Layer 1 - Public Headers”include/kdal/
Stable API contracts that drivers and backends program against:
| Header | Purpose |
|---|---|
types.h |
Device classes, power states, event types, core structs, struct kdal_demand |
api/driver.h |
Conventional driver ops (probe/remove/read/write/ioctl) |
api/accel.h |
Accelerator ops (queue/buffer/submit) |
backend.h |
Backend ops (init/exit/enumerate/read/write/ioctl) |
ioctl.h |
Userspace ABI (ioctl magic 'K') |
core/kdal.h |
Lifecycle, registration, lookup, the resource demand |
Layer 2 - Core Runtime
Section titled “Layer 2 - Core Runtime”src/core/
| Module | Purpose |
|---|---|
module.c |
Kernel module entry/exit |
kdal.c |
Init cascade (chardev → debugfs → backends → drivers), attach and lookup |
chardev.c |
/dev/kdal misc device with per-fd state |
debugfs.c |
/sys/kernel/debug/kdal/ diagnostic files |
registry.c |
Thread-safe registration of backends/drivers/devices |
event.c |
Bounded circular event log (256 entries, mutex); wakes a wait queue nothing waits on yet |
power.c |
Power state transitions with event emission |
demand.c |
The resource demand as JSON (kdal_demand_format) |
Layer 3 - Backend Adapters
Section titled “Layer 3 - Backend Adapters”src/backends/
| Backend | Description |
|---|---|
qemu/ |
QEMU virt machine backend with software ring buffers (qemubackend.c), virtio I/O and accelerator, MMIO |
generic/ |
Platform device, Device Tree (kdal,device nodes), and SoC glue for real hardware |
Layer 4 - Device Drivers
Section titled “Layer 4 - Device Drivers”src/drivers/example/
Example drivers that find their backend through the registry
(kdal_find_backend):
| Driver | File | Description |
|---|---|---|
| UART | uartdriver.c |
Byte-stream I/O; a baud rate field, set to its default at probe |
| I2C | i2cdriver.c |
Bus speed (100 kHz default) and slave address |
| SPI | spidriver.c |
SPI emulation with a bus clock field |
| GPU | gpudriver.c |
Accelerator driver with queue/buffer semantics |
Layer 5 - Verification
Section titled “Layer 5 - Verification”tests/, tools/
- KUnit test suites for kernel-side validation
- Userspace integration tests and benchmarks
kdalityCLI for device management and driver compilation
Data Flow
Section titled “Data Flow”write(fd, "hello", 5) → kdal_cdev_write() [chardev.c] → file_ctx->selected->driver->ops->write() [uartdriver.c] → copy_from_user() into kernel buffer → backend->ops->write() [qemubackend.c] → qemu_ring_write() [ring buffer]
read(fd, buf, 5) → kdal_cdev_read() [chardev.c] → file_ctx->selected->driver->ops->read() [uartdriver.c] → backend->ops->read() [qemubackend.c] → qemu_ring_read() [ring buffer] → copy_to_user() back to userspaceInit Cascade
Section titled “Init Cascade”Module load triggers kdal_core_init() which brings up subsystems in order:
kdal_chardev_init()- registers/dev/kdalkdal_debugfs_init()- creates debugfs tree (non-fatal if unavailable)kdal_qemu_backend_init()- registers + inits QEMU backendkdal_soc_glue_init(),kdal_generic_platdev_init(),kdal_devicetree_scan()- the generic backend and the devices described in the device treekdal_uart_driver_init()- registers driver + device + attacheskdal_i2c_driver_init()- same patternkdal_spi_driver_init()- same patternkdal_gpu_driver_init()- same pattern
A failure unwinds the steps already done. Teardown in kdal_core_exit()
reverses this order and then resets the event log.
Design Decisions
Section titled “Design Decisions”| Decision | Rationale |
|---|---|
misc_register over raw char dev |
Simpler, automatic minor allocation |
Per-fd state via file->private_data |
Independent device selection per open |
| Ring buffer over DMA | No real hardware on QEMU first milestone |
| Mutex over spinlock in registry | Sleep-safe for module init path |
| Circular event log | Bounded memory, no allocation per event |
| Forward-declared driver inits | Avoids header coupling between drivers |