Skip to content

Device Headers (.kdh)

A .kdh file describes a hardware device declaratively. It contains no executable logic - only structural declarations, which kdality lint uses to check a driver’s register accesses and kdality dt-gen turns into a Device Tree overlay. The frozen compiler reads the header a driver imports but checks ro/wo only for registers declared in the file it compiles, so for a driver the check is kdality lint’s (W003, W004).

kdal_version: "0.1";
import "kdal/stdlib/common.kdh";
device class <Name> {
compatible "<vendor>,<device>";
class <device_class>;
registers { … }
register_map { … }
signals { … }
capabilities { … }
power { … }
config { … }
}

This one uses the short forms (register_map, bare signal names, power_states), which the parser accepts with default settings:

// led.kdh - a simple GPIO-controlled LED
device class Led {
class gpio;
compatible "example,led-gpio";
register_map {
CTRL 0x00 rw;
STATE 0x04 ro;
}
signals {
toggle;
}
capabilities {
dimmable false;
}
power_states {
off;
on;
}
}

Each register declaration binds a name to a hardware register with type, offset, access mode, and optional default value:

registers {
STATUS : u8 @ 0x00 rw = 0x00;
DATA : u32 @ 0x04 rw;
CONTROL : bitfield @ 0x08 rw {
enable : 0 = false;
irq_mask : 1 = true;
baud_sel : 4..6 = 0;
};
}
  • @ 0xNN - MMIO offset (optional; platform drivers may ignore it)
  • Access qualifiers:
Qualifier Meaning Checked
ro Read-only kdality lint warns on a write (W003)
wo Write-only kdality lint warns on a read (W004)
rw Read-write -
rc Clear-on-read - (accepted; reading is meant to clear the register)

The generated C reads and writes through the runtime’s kdal_reg_read and kdal_reg_write, which do not exist yet (open finding O7).

  • = value - reset/default value
  • bitfield - nested bit fields with named bits or bit ranges (4..6)

Signals map to IRQs or GPIO lines. For an on signal handler the compiler generates an irqreturn_t function; nothing in the generated module requests the IRQ yet:

signals {
rx_ready : in edge(rising);
tx_empty : in edge(rising);
error : in level(high);
power_ack : in completion;
done : in timeout(100);
}
Direction Meaning
in Input signal (device → driver)
out Output signal (driver → device)
inout Bidirectional
Trigger Meaning
edge(rising) Rising edge triggered
edge(falling) Falling edge triggered
edge(any) Any edge
level(high) High level triggered
level(low) Low level triggered
completion Completion event
timeout(ms) Timer expiry

Key-value pairs, or bare names, describing hardware features. The frozen code generator emits nothing for them:

capabilities {
fifo_depth = 16;
dma_capable;
error_correction;
}

Supported power states and transition rules:

power {
on : allowed;
off : allowed;
suspend : forbidden;
default : on;
}

Typed parameters with optional default values and range constraints:

config {
baud_rate : u32 = 115200 in 1200..4000000;
data_bits : u8 = 8 in 5..9;
parity : u8 = 0 in 0..2;
}

Config fields may be overridden in the .kdc driver’s config bind block.

Element Purpose
device class Names the device (used in .kdc and generated code)
class The device class (uart, i2c, spi, gpio, gpu, npu); parsed, not yet used by the code generator
compatible Device Tree compatible string for OF matching
registers / register_map Named registers with offset and access mode
signals Software/hardware events the driver reacts to
capabilities Key-value pairs describing hardware features
power Supported power states
config Typed, range-constrained parameters