blob: e421c52ea3a52883ff282f442657b0f81851f0a2 [file] [view]
# Driver Manifest Language (DML) reference
This document provides a comprehensive reference for the **Driver Manifest Language (DML)** in
Fuchsia's [Driver Framework v2 (DFv2)][dfv2].
---
## 1. Overview
In Driver Framework v2 (DFv2), drivers are components executed by the driver runner.
Historically, authoring a DFv2 driver required maintaining multiple disconnected configuration files:
* A **Component Manifest (`.cml`)**: Declaring capabilities, used services, runner configuration, and binary locations.
* A **Bind Rules File (`.bind`)**: Declaring driver matching rules, hardware identifiers, and composite parent specifications.
* **Board Configurations (`.fidl`)**: Board drivers required board topology manifests, capability route mappings, and static metadata payloads.
* **Metadata Deserialization Boilerplate**: Manual deserialization of structured FIDL dictionaries or raw metadata bytes.
Maintaining these files separately introduced duplication: service names, parent node names, and
hardware protocol requirements were repeated across both `.cml` and `.bind` files, creating a risk
of drift and configuration bugs.
**DML (Driver Manifest Language)** solves this by providing a single, unified declarative JSON5 manifest
(`.dml`). The DML compiler (`dmlc`) processes `.dml` files and automatically produces:
1. **Component Manifests (`.cml`)**: Cleaned and validated component manifests ready for compilation with `cmc`.
2. **Bind Rules (`.bind`)**: Bind program source code compiled with `bindc` into driver bytecode (`.bindbc`).
3. **FIDL Board Configurations**: Board topology binaries (`BoardConfig`) for platform bus drivers.
4. **C++ and Rust Metadata Parsers**: Type-safe parser libraries automatically generated from embedded JSON Schemas.
The official schema for DML manifests is checked in at
[`//src/devices/tools/dmlc/dml.schema.json`](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/devices/tools/dmlc/dml.schema.json).
---
## 2. Driver manifest vs board manifest
DML supports two categories of manifests:
| Feature | Driver Manifest (`compile-driver`) | Board Manifest (`compile-board`) |
| :--- | :--- | :--- |
| **Target** | Standalone or composite leaf/intermediate device drivers | System board drivers (e.g. Vim3, QEMU, Astro) |
| **Outputs** | `.cml`, `.bind`, optional C++/Rust metadata parsers | `.cml`, `.bind`, `.fidl` board configuration |
| **Top-Level Sections** | `name`, `include_inspect`, `constants`, `program`, `use`, `capabilities`, `expose`, `include`, `config` | `name`, `constants`, `program`, `children`, `offer`, `metadata_mappings`, `use`, `include`, `capabilities`, `expose` |
| **Binding Style** | Non-composite (`program.bind`) or composite (`use[].bind`) | Platform bus device binding (`program.bind`) |
| **Hardware Nodes** | Consumes parent nodes | Declares child nodes and capability routes (`offer`) |
---
## 3. Syntax reference
### 3.1 Top-level properties
```json5
{
// Name of the driver or board component (required).
name: "sample_driver",
// Optional composite name override. Defaults to 'name' with '-' replaced by '_'.
composite_name: "custom_composite_name",
// Shards and manifests to include.
include: [
"//sdk/lib/driver/compat/compat.shard.cml",
"subsystem.shard.dml"
],
// Driver manifest only: include 'inspect/client.shard.cml' in the generated
// CML (default: true). 'syslog/client.shard.cml' is always included.
include_inspect: true,
// Optional named compile-time constants (flat or nested namespaces).
constants: { ... },
// Execution parameters and standalone bind rules.
program: { ... },
// Capabilities consumed, and parent node definitions for composite drivers.
use: [ ... ],
// Capabilities provided by this driver, including metadata schemas.
capabilities: [ ... ],
// Capabilities exposed to the framework or parent component.
expose: [ ... ],
// Optional structured component configuration schema.
config: { ... },
// Board manifest only: child device node definitions.
children: [ ... ],
// Board manifest only: capability offers and constraint routing.
offer: [ ... ],
// Board manifest only: rules for aggregating metadata across children.
metadata_mappings: [ ... ]
}
```
---
### 3.2 The program section
The `program` section defines driver execution parameters and bind rules for standalone (non-composite) drivers.
| Property | Type | Description |
| :--- | :--- | :--- |
| `runner` | string | Component runner name. Defaults to `"driver"`. |
| `binary` | string | Path to driver shared library (e.g. `"driver/sample.so"`). Defaults to `"driver/<name>.so"`. |
| `compat` | string | Path to DFv1 compatibility driver shared library (e.g. `"driver/sample_compat.so"`). Automatically includes `//sdk/lib/driver/compat/compat.shard.cml` in the generated CML unless already listed in `include`. |
| `colocate` | string or boolean | Whether to colocate the driver in its parent driver host (`"true"` or `true`). |
| `default_dispatcher_opts` | array of string | Options for the driver's default dispatcher (e.g. `["allow_sync_calls"]`). |
| `bind` / `requirements` | object or `false` | Structured bind block for standalone drivers (see [Hardware bus blocks](#4-hardware-bus-blocks)), or `false` (driver manifests only) for a driver without bind rules. Note: string bind paths are not allowed in DML. |
| `driver_name` | string | Driver name override (primarily used in board manifests). |
#### Example: Standalone driver program block
```json5
program: {
binary: "driver/usb_mass_storage.so",
colocate: "true",
default_dispatcher_opts: [ "allow_sync_calls" ],
bind: {
protocol: "fuchsia.usb.BIND_PROTOCOL.INTERFACE",
usb: {
class: "fuchsia.usb.CLASS.MASS_STORAGE",
subclass: "fuchsia.usb.massstorage.SUBCLASS.SCSI",
protocol: "fuchsia.usb.massstorage.PROTOCOL.BULK_ONLY"
}
}
}
```
#### Example: Bind-less driver (`program.bind: false`)
For drivers that do not ship bind rules (for example, drivers bound only manually or test drivers), set `bind: false` (or `requirements: false`). `dmlc` omits `program.bind` from the generated CML and refuses to write a `.bind` output; pair it with `disable_autobind = true` on the GN `fuchsia_driver_dml` target. `bind: false` cannot be combined with composite parent bind rules.
```json5
program: {
binary: "driver/manual_driver.so",
bind: false,
}
```
---
### 3.3 The use section
The `use` section serves a dual purpose:
1. **Component Capability Routing**: Passing standard CML capabilities (`service`, `protocol`, `directory`).
2. **Composite Parent Node Specification**: Defining the parent nodes that a composite driver binds to.
| Property | Type | Description |
| :--- | :--- | :--- |
| `service` | string | FIDL service name (e.g. `"fuchsia.hardware.gpio.Service"`). Emits `fuchsia.Service == "<service>";` in parent bind rules. |
| `protocol` | string | FIDL protocol name. |
| `banjo` | string | Banjo protocol identifier (e.g. `"fuchsia.acpi.BIND_PROTOCOL.DEVICE"`). Emits `fuchsia.BIND_PROTOCOL == <banjo>;` in bind rules and is excluded from CML. |
| `name` / `instance_name` | string | Name of the parent node in the composite device specification. |
| `primary` | boolean | Set to `true` on exactly one `use` entry to designate it as the primary parent node. |
| `availability` | string | `"required"` (default) or `"optional"`. Generates `optional parent "<name>"` in bind rules. |
| `transport` | string | Service transport: `"Zircon"`, `"Driver"`, or `"Banjo"`. |
| `generate_bind_rule` | boolean | Defaults to `true`. If set to `false`, the capability is consumed via CML without generating a composite parent bind node. |
| `bind` / `requirements` | object | Inline bind rules for this parent node (see [Hardware bus blocks](#4-hardware-bus-blocks)). |
#### Special handling for initialization steps
Services representing platform init steps (such as `fuchsia.gpio.Init` and `fuchsia.pwm.Init`) are automatically detected:
* They generate the standard service bind rule (e.g. `fuchsia.Service == "fuchsia.gpio.Init";`).
* They are automatically filtered out of runtime CML `use` entries because init steps are transient bind milestones rather than connectable runtime FIDL services.
---
### 3.4 The capabilities and expose sections
#### Capabilities
Declares capabilities provided by the driver. In addition to standard CML capability types, DML supports **schema-driven metadata definitions**:
```json5
capabilities: [
{
service: "fuchsia.hardware.buttons.Service"
},
{
metadata: {
id: "fuchsia.hardware.buttons.Metadata",
schema: {
title: "ButtonsMetadata",
type: "object",
definitions: {
ButtonItem: {
type: "object",
properties: {
type: { type: "integer", fuchsia_type: "uint8" },
gpio: { type: "integer", fuchsia_type: "uint32" }
},
required: [ "type", "gpio" ]
}
},
properties: {
buttons: {
type: "array",
items: {
"$ref": "#/definitions/ButtonItem"
}
}
},
required: [ "buttons" ]
}
}
}
]
```
When `dmlc compile-driver` is executed with `--h-output`, `--cc-output`, or `--rs-output`, it generates complete C++ and Rust parser code that parses and validates incoming metadata against the schema.
#### Expose
Standard DFv2 capability exposure:
```json5
expose: [
{
service: "fuchsia.hardware.buttons.Service",
from: "self"
}
]
```
---
### 3.5 Board manifest top-level sections
Board manifests (compiled with `dmlc compile-board`) configure the platform bus and topology:
#### children
Declares devices published to the platform bus:
```json5
children: [
{
name: "adc-buttons",
url: "fuchsia-pkg://fuchsia.com/adc-buttons#meta/adc-buttons.cm",
compatible: "fuchsia,adc-buttons",
metadata: [
{
id: "fuchsia.hardware.adc.Metadata",
data: [ 1, 0, 0, 0 ]
}
]
}
]
```
#### offer
Routes capabilities between parent controllers and child drivers with hardware constraints:
```json5
offer: [
{
service: "fuchsia.hardware.gpio.Service",
name: "power",
from: "#gpio-controller-ff634400",
to: "#gpio-buttons",
constraints: {
pin: 92,
name: "power"
}
}
]
```
##### Userspace interrupt controllers
When a platform device consumes an interrupt managed by a userspace interrupt controller driver (rather than the kernel interrupt controller directly), two `offer` entries are required:
1. Route `fuchsia.hardware.interrupt.ControllerRegistryService` from `"parent"` to the interrupt controller node (`name: "pdev"`). `dmlc` automatically allocates a unique platform bus `interrupt_controller_id` for that controller node.
2. Reference the controller node in the consumer's `fuchsia.hardware.platform.device.Service` `interrupts` constraint via `controller: "#<controller-node>"`.
```json5
offer: [
{
name: "pdev",
service: "fuchsia.hardware.interrupt.ControllerRegistryService",
from: "parent",
to: "#gpio-controller-ff634400",
},
{
name: "pdev",
service: "fuchsia.hardware.platform.device.Service",
from: "parent",
to: "#touchscreen",
constraints: {
interrupts: [
{
name: "touch-irq",
number: 14,
mode: "EdgeLow",
controller: "#gpio-controller-ff634400",
},
],
},
},
]
```
#### metadata_mappings
Aggregates child device constraints into unified FIDL metadata:
```json5
metadata_mappings: [
{
metadata_id: "fuchsia.hardware.pinimpl.Metadata",
aggregations: [
{
service: "fuchsia.hardware.gpio.Service",
field: "pins"
},
{
service: "fuchsia.hardware.pin.PinStatesService",
field: "device_pin_states",
use_node_name: true
}
]
}
]
```
---
### 3.6 Named constants
DML supports compile-time named constants so hardware IDs, clock IDs, pin numbers, and shared bind values can be named once instead of repeated as raw literals.
#### Inline constants and namespaces
Define constants in a top-level `constants` object containing integer (including JSON5 hex literals such as `0x1000b`), string, or boolean values. Constants may be grouped into arbitrarily nested namespace objects, which are flattened with `.` separators:
```json5
{
name: "sample_pci_driver",
constants: {
LOCAL_DID: 0x1234,
pci: {
VID: {
INTEL: 0x8086,
},
},
},
program: {
bind: {
pci: {
vid: "pci.VID.INTEL",
did: "LOCAL_DID",
},
},
},
}
```
#### Referencing and scoped resolution
* **Unprefixed lookup (`"name"` / `"ns.name"`)**: Reference constants directly by their flattened name (such as `"g12b_clk.AUDIO"`, `"pci.VID.INTEL"`, or `"AX88179_PID"`). Matching string values are replaced in place with the constant's typed value (integer, string, or boolean) before the manifest is parsed.
* **Single-pass resolution**: Resolution runs in a single pass, so a string constant whose value matches another constant name is never re-resolved.
* **Scoped to data and bind fields**: Constant resolution applies only to data and bind sections (`program.bind` / `program.requirements`, `use[].bind` / `use[].requirements` / `use[].constraints`, and in board manifests `offer[]` / `offers[]` constraints, properties, metadata payloads, and driver-config payload fields, `children[]` non-structural fields such as `compatible`/`driver_host`/`id`/`metadata[].data`, and `iommus[]` non-`name` fields). Structural identifiers (including top-level `name`, `composite_name`, `include`, `constants`, `program.binary`, `use[].name`, `use[].service`, `children[].name`/`url`/`metadata[].id`, `offer[].name`/`from`/`to`/`service`/`driver_config`/`metadata.id`, `primary.node`, and JSON `schema` blocks) are never rewritten.
* **Namespace typo detection**: If an unresolved dotted string matches a known constant namespace (such as `"pci.VID"`) or falls inside a known constant namespace (such as `"pci.VID.GOOGEL"` or `"pci.TYPO.GOOGLE"`), `dmlc` fails with a compile error. Plain non-constant strings (including bare strings matching a top-level namespace name like `"pci"`, or standard `fuchsia.*` protocol and service identifiers) pass through untouched.
#### Board shard merging
When compiling a board manifest (`dmlc compile-board`), `dmlc` collects `constants` blocks from the root manifest and all transitively `include`d `.dml` shards in a first pass before resolving any references. As a result, a shard may reference constants defined in another shard regardless of `include` order.
#### Shared constant files (`include`)
To share constants across multiple manifests, place them in a standalone `.constants.dml` file containing only `constants` (and optionally nested `.dml` `include` entries) and reference it explicitly in the manifest's `include` array:
```json5
// sdk/lib/driver/dml/pci.constants.dml
{
constants: {
pci: {
VID: {
INTEL: 0x8086,
},
},
},
}
```
```json5
// meta/my_pci_driver.dml
{
name: "my_pci_driver",
include: [
"driver/dml/pci.constants.dml",
"driver_component/driver.shard.cml",
],
program: {
bind: {
pci: {
vid: "pci.VID.INTEL",
},
},
},
}
```
`dmlc` resolves `include` paths using the same conventions as `cmc` (`--includeroot` and repeatable `--includepath`, defaulting in GN and Bazel to `//` and `//sdk/lib`):
* Paths starting with `//` (such as `"//sdk/lib/driver/dml/pci.constants.dml"`) resolve relative to `--includeroot`.
* Other paths first check relative to the including file's directory (e.g., `"g12b-clk.constants.dml"`), then search each `--includepath` directory (e.g., `"driver/dml/pci.constants.dml"`).
* In driver manifests (`compile-driver`), `.dml` entries in `include` are loaded as constant shards and stripped from the generated `.cml`, while `.cml` shards are forwarded to the generated `.cml` unchanged.
* In GN (`fuchsia_driver_dml` and `fuchsia_board_dml`), `dmlc` emits a Ninja depfile via `--depfile`, so included `.dml` files are tracked automatically with no build-file boilerplate.
* In Bazel (`dml_outputs` and `board_dml_outputs`), list included `.dml` files alongside `.cml` shards in `includes = [...]` so Bazel makes them available in the action sandbox (for `dml_cc_library`, pass them in `dml_includes = [...]`).
#### Generating C++ and Rust libraries
Standalone `.constants.dml` files can also be compiled into C++ headers and Rust crates so driver and board source code shares the exact same definitions as DML manifests without duplicating constants.
In GN (`//build/drivers/dml.gni`), declare a `dml_constants_library`:
```gn
import("//build/drivers/dml.gni")
dml_constants_library("pci") {
source = "pci.constants.dml"
}
```
In Bazel (`//build/bazel/rules/drivers:dml_constants_library.bzl`), declare the equivalent macro (passing any transitively included `.dml` files or `dml_constants_library` targets via `includes`):
```starlark
load("//build/bazel/rules/drivers:dml_constants_library.bzl", "dml_constants_library")
dml_constants_library(
name = "pci",
src = "pci.constants.dml",
includes = [],
)
```
Both GN and Bazel expand to:
* `:pci`: Primary target exposing the `.constants.dml` source (in Bazel, also provides transitive `.dml` inputs so downstream `dml_outputs`, `board_dml_outputs`, and `dml_constants_library` targets can list `:pci` in `includes`).
* `:pci_cpp`: C++ library (`source_set` in GN, `fx_cc_library` in Bazel) providing `#include <dml/pci.h>` (overridable with `header_path`) with `inline constexpr` declarations inside `namespace dml` (overridable with `namespace`, or `""` for no outer wrapper) and nested namespaces mirroring the DML constant hierarchy.
* `:pci_rust`: Rust `rustc_library` crate (omitted in GN Zircon toolchains) named `dml_pci` (overridable with `crate_name`) with `pub const` declarations inside nested `pub mod` modules.
Generated leaf constants map DML scalar values to C++ and Rust types as follows:
| DML value range / type | C++ type | Rust type |
| :--- | :--- | :--- |
| Non-negative integer `0 ..= u32::MAX` | `uint32_t` | `u32` |
| Non-negative integer `> u32::MAX` (`<= u64::MAX`) | `uint64_t` | `u64` |
| Negative integer `i32::MIN ..= -1` | `int32_t` | `i32` |
| Negative integer `i64::MIN ..< i32::MIN` | `int64_t` | `i64` |
| Boolean | `bool` | `bool` |
| String | `::std::string_view` | `&str` |
Under the hood, `dml_constants_library` invokes `dmlc generate-constants` (at least one of `--h-output` or `--rs-output` is required):
```sh
dmlc generate-constants <input.constants.dml> \
[--h-output <out.h> [--header-path <dml/foo.h>] [--namespace <dml>] [--include-guard <GUARD>]] \
[--rs-output <out.rs>] \
[--includeroot <root>] [--includepath <dir>] [--depfile <out.d>]
```
Transitively included `.dml` constant shards are merged into the generated outputs and recorded in `--depfile`.
#### Validation and error rules
* Key segments must start with an ASCII letter or `_` and contain only ASCII alphanumeric characters or `_` (dots, hyphens, spaces, and leading digits are rejected).
* When generating C++ or Rust code (`generate-constants`), key segments (and C++ `--namespace` segments) must not be `"_"` or reserved keywords in the target language (C++20/23 keywords and alternative operator tokens for `--h-output`; Rust edition 2024 strict and reserved keywords for `--rs-output`).
* Nested namespace objects cannot be empty (`{}` is an error).
* Only integer, string, and boolean leaf values are allowed; floating-point numbers, `null`, and arrays are rejected.
* Duplicate definitions of the same key with the exact same value are idempotent (safe across diamond includes); conflicting values for the same key, or redefining a namespace as a scalar (or vice versa), are compile errors.
* Referencing a qualified constant namespace as a value (e.g., `"pci.VID"`) or an undefined constant inside a known constant namespace (e.g., `"pci.VID.MISSING"`) is a compile error.
* Included driver constant shards (`.dml`) accept only `constants` and `.dml` `include` entries and reject unknown top-level fields, non-`.dml` includes, and circular includes.
---
## 4. Hardware bus blocks {:#4-hardware-bus-blocks}
DML provides structured blocks for major hardware interconnects and discovery protocols.
### 4.1 Platform bus & devicetree
Platform devices match on Devicetree/platform `compatible` strings (`compat`) or Instance ID (`instance_id`):
```json5
bind: {
compat: "fuchsia,gpio-buttons",
instance_id: 0
}
```
Generated bind rules:
```bind
fuchsia.BIND_PLATFORM_DEV_INSTANCE_ID == 0;
fuchsia.COMPATIBLE == "fuchsia,gpio-buttons";
```
### 4.2 PCI bus
PCI devices match on PCI vendor, device, class, subclass, interface, or topology:
Note: Legacy flat PCI fields (`pci_class`, `pci_subclass`, `pci_interface`) are rejected by `dmlc`. Always use the structured `pci: { ... }` block.
```json5
bind: {
service: "fuchsia.hardware.pci.Service",
pci: {
vid: "fuchsia.pci.BIND_PCI_VID.INTEL",
did: "0x1234",
class: "fuchsia.pci.BIND_PCI_CLASS.GENERIC_SYSTEM_PERIPHERAL",
subclass: "0x05",
interface: "0x01",
topo: "0x05"
}
}
```
Generated bind rules:
```bind
fuchsia.Service == "fuchsia.hardware.pci.Service";
fuchsia.BIND_PCI_VID == fuchsia.pci.BIND_PCI_VID.INTEL;
fuchsia.BIND_PCI_DID == 0x1234;
fuchsia.BIND_PCI_CLASS == fuchsia.pci.BIND_PCI_CLASS.GENERIC_SYSTEM_PERIPHERAL;
fuchsia.BIND_PCI_SUBCLASS == 0x05;
fuchsia.BIND_PCI_INTERFACE == 0x01;
fuchsia.BIND_PCI_TOPO == 0x05;
```
### 4.3 USB bus
USB interfaces and devices match on USB vendor, product, class, subclass, and protocol:
```json5
bind: {
usb: {
vid: "fuchsia.usb.VID.GOOGLE",
pid: "0x1234",
class: "fuchsia.usb.CLASS.MASS_STORAGE",
subclass: "0x02",
protocol: 0,
bind_protocol: "fuchsia.usb.BIND_PROTOCOL.INTERFACE"
}
}
```
Generated bind rules:
```bind
fuchsia.BIND_PROTOCOL == fuchsia.usb.BIND_PROTOCOL.INTERFACE;
fuchsia.usb.VID == fuchsia.usb.VID.GOOGLE;
fuchsia.usb.PID == 0x1234;
fuchsia.usb.CLASS == fuchsia.usb.CLASS.MASS_STORAGE;
fuchsia.usb.SUBCLASS == 0x02;
fuchsia.usb.PROTOCOL == 0;
```
### 4.4 ACPI bus
ACPI devices match on Hardware ID (`hid`), Compatible ID (`first_cid`), or ACPI Bus Type:
```json5
bind: {
acpi: {
hid: "PNP0C0A",
first_cid: "PNP0C0B",
bus_type: "fuchsia.acpi.BUS_TYPE.PCI"
}
}
```
Generated bind rules:
```bind
fuchsia.acpi.HID == "PNP0C0A";
fuchsia.acpi.FIRST_CID == "PNP0C0B";
fuchsia.acpi.BUS_TYPE == fuchsia.acpi.BUS_TYPE.PCI;
```
### 4.5 SDIO bus
SDIO devices match on Vendor ID (`vid`), Product/Device ID (`pid`), and Function (`function`):
```json5
bind: {
sdio: {
vid: "fuchsia.broadcom.platform.sdio.BIND_SDIO_VID.BROADCOM",
pid: "fuchsia.broadcom.platform.sdio.BIND_SDIO_PID.BCM43458",
function: 1
}
}
```
Generated bind rules:
```bind
fuchsia.BIND_SDIO_VID == fuchsia.broadcom.platform.sdio.BIND_SDIO_VID.BROADCOM;
fuchsia.BIND_SDIO_PID == fuchsia.broadcom.platform.sdio.BIND_SDIO_PID.BCM43458;
fuchsia.BIND_SDIO_FUNCTION == 1;
```
### 4.6 Device ID and NAND class shorthands
Additional high-frequency bind properties have first-class shorthands:
* `id`: Emits `fuchsia.ID` (e.g. `id: 1`).
* `nand`: Emits `fuchsia.nand.CLASS` (e.g. `nand: "fuchsia.nand.CLASS.PARTMAP"`).
```json5
bind: {
id: 1,
nand: "fuchsia.nand.CLASS.PARTMAP"
}
```
Generated bind rules:
```bind
fuchsia.ID == 1;
fuchsia.nand.CLASS == fuchsia.nand.CLASS.PARTMAP;
```
---
## 5. Composite binding rules & parent matching
Composite drivers require binding to multiple parent devices (e.g. a platform device, plus GPIO pins, plus I2C buses).
### 5.1 Primary parent node
Designate the primary parent with `primary: true` in its `use` entry:
```json5
use: [
{
service: "fuchsia.hardware.platform.device.Service",
name: "pdev",
primary: true,
bind: {
compat: "sample,buttons"
}
},
{
service: "fuchsia.hardware.gpio.Service",
name: "mic-mute",
availability: "optional"
}
]
```
Generated bind rules:
```bind
composite sample_composite;
using fuchsia;
primary parent "pdev" {
fuchsia.COMPATIBLE == "sample,buttons";
}
optional parent "mic-mute" {
fuchsia.Service == "fuchsia.hardware.gpio.Service";
}
```
Note: If a driver is a composite driver, specifying bind rules under `program.bind` is forbidden. Place all bind rules in the corresponding `use` entries instead.
### 5.2 Parent node matching (match_name: true)
When a driver connects to multiple parents of the same service type (e.g. multiple GPIO pins or ADCs), specify `match_name: true` inside the parent's `bind` block. `dmlc` will automatically emit a rule matching the parent's topological node name (`fuchsia.NAME`):
```json5
use: [
{
service: "fuchsia.hardware.gpio.Service",
name: "volume-up",
bind: {
match_name: true
}
}
]
```
Generated bind rules:
```bind
parent "volume-up" {
fuchsia.Service == "fuchsia.hardware.gpio.Service";
fuchsia.NAME == "volume-up";
}
```
### 5.3 Parent grouping
If multiple `use` entries reference the same parent `name` (for example, one for a Banjo interface and another for a FIDL service or init step), `dmlc` automatically groups them into a single parent specification:
```json5
use: [
{
service: "fuchsia.gpio.Init",
name: "gpio-init"
},
{
service: "fuchsia.hardware.gpio.Service",
name: "gpio-init",
availability: "optional"
}
]
```
Generated bind rules:
```bind
parent "gpio-init" {
fuchsia.Service == "fuchsia.gpio.Init";
fuchsia.Service == "fuchsia.hardware.gpio.Service";
}
```
---
## 6. Conditional branching and array acceptance
### 6.1 Array acceptance (accept)
To match against any one of multiple acceptable values, pass an array instead of a single scalar. `dmlc` will generate an `accept <property> { ... }` block in bind rules.
```json5
bind: {
pci: {
vid: "fuchsia.pci.BIND_PCI_VID.INTEL",
did: [ "0x1234", "0x5678" ]
}
}
```
Generated bind rules:
```bind
fuchsia.BIND_PCI_VID == fuchsia.pci.BIND_PCI_VID.INTEL;
accept fuchsia.BIND_PCI_DID {
0x1234,
0x5678,
}
```
Works for `protocol`, `compat`, `instance_id`, `node_name`, `id`, `nand`, PCI properties, USB properties, ACPI properties, SDIO properties, and custom `rules`.
### 6.2 Conditional branching (one_of)
When matching logic requires branching across different buses or device generations, use `one_of`. `dmlc` inspects each branch's trigger conditions and compiles them into `if ... else if ... else ...` statements.
```json5
bind: {
one_of: [
{
pci: {
vid: "fuchsia.pci.BIND_PCI_VID.INTEL",
did: "0x1234"
}
},
{
pci: {
class: "0x02",
subclass: "0x00"
}
}
]
}
```
Generated bind rules:
```bind
if fuchsia.BIND_PCI_VID == fuchsia.pci.BIND_PCI_VID.INTEL {
fuchsia.BIND_PCI_DID == 0x1234;
} else if fuchsia.BIND_PCI_CLASS == 0x02 {
fuchsia.BIND_PCI_SUBCLASS == 0x00;
} else {
false;
}
```
Supported trigger properties in `one_of` include:
* `node_name` (`fuchsia.NAME`)
* `acpi.hid` and `acpi.bus_type`
* `compat` (`fuchsia.COMPATIBLE`)
* `protocol` / `banjo` (`fuchsia.BIND_PROTOCOL`)
* `service` (`fuchsia.Service`)
* `instance_id` (`fuchsia.BIND_PLATFORM_DEV_INSTANCE_ID`)
* `pci.vid`, `pci.did`, `pci.class`
* `usb.vid`, `usb.pid`, `usb.class`
* `sdio.vid`, `sdio.pid`, `sdio.function`
* `id` (`fuchsia.ID`) and `nand` (`fuchsia.nand.CLASS`)
* Custom `rules` keys without a first-class shorthand (e.g. `fuchsia.BIND_AUTOBIND`)
An alternative inside `one_of` may itself contain a nested `one_of` to emit a nested conditional inside that branch:
```json5
bind: {
one_of: [
{
service: "fuchsia.hardware.pci.Service",
one_of: [
{ pci: { vid: "0x10de", did: "0x01" } },
{ pci: { vid: "0x8086", did: "0x02" } }
]
},
{
compat: "fuchsia,fallback"
}
]
}
```
Generated bind rules:
```bind
if fuchsia.Service == "fuchsia.hardware.pci.Service" {
if fuchsia.BIND_PCI_VID == 0x10de {
fuchsia.BIND_PCI_DID == 0x01;
} else if fuchsia.BIND_PCI_VID == 0x8086 {
fuchsia.BIND_PCI_DID == 0x02;
} else {
false;
}
} else if fuchsia.COMPATIBLE == "fuchsia,fallback" {
true;
} else {
false;
}
```
### 6.3 Inequality constraints and custom rules
To require that a property does *not* equal one or more values, specify `{ neq: <value> }` or `{ neq: [ <value1>, <value2>, ... ] }` on any first-class bind field (`protocol`, `instance_id`, `compat`, `node_name`, `pci.*`, `usb.*`, `acpi.*`, `sdio.*`, `id`, `nand`) or in `rules`. A non-empty list emits one `!=` constraint per value.
Note: `rules` is strictly for bind properties that do not have a first-class shorthand. `dmlc` rejects any key in `rules` that has a dedicated shorthand field (for example, `fuchsia.BIND_PCI_VID` must use `pci: { vid: ... }` and `fuchsia.NAME` must use `node_name` or `match_name`).
```json5
bind: {
protocol: { neq: "fuchsia.usb.BIND_PROTOCOL.INTERFACE" },
compat: { neq: [ "acme,legacy-a", "acme,legacy-b" ] },
rules: {
"fuchsia.BIND_COMPOSITE": { neq: 1 }
}
}
```
Generated bind rules:
```bind
fuchsia.BIND_PROTOCOL != fuchsia.usb.BIND_PROTOCOL.INTERFACE;
fuchsia.COMPATIBLE != "acme,legacy-a";
fuchsia.COMPATIBLE != "acme,legacy-b";
fuchsia.BIND_COMPOSITE != 1;
```
---
## 7. Real-world before / after examples
### Example 1: Standalone USB mass storage driver
#### Before: Separate files
`meta/usb_mass_storage.cml`:
```json5
{
include: [
"inspect/client.shard.cml",
"syslog/client.shard.cml",
],
program: {
runner: "driver",
binary: "driver/usb_mass_storage.so",
bind: "meta/bind/usb_mass_storage.bindbc",
colocate: "true",
default_dispatcher_opts: [ "allow_sync_calls" ],
},
capabilities: [
{ service: "fuchsia.hardware.block.volume.Service" }
],
expose: [
{
service: "fuchsia.hardware.block.volume.Service",
from: "self"
}
]
}
```
`meta/usb_mass_storage.bind`:
```bind
using fuchsia.usb;
using fuchsia.usb.massstorage;
fuchsia.BIND_PROTOCOL == fuchsia.usb.BIND_PROTOCOL.INTERFACE;
fuchsia.usb.CLASS == fuchsia.usb.CLASS.MASS_STORAGE;
fuchsia.usb.SUBCLASS == fuchsia.usb.massstorage.SUBCLASS.SCSI;
fuchsia.usb.PROTOCOL == fuchsia.usb.massstorage.PROTOCOL.BULK_ONLY;
```
#### After: Unified meta/usb_mass_storage.dml
```json5
{
name: "usb-mass-storage",
program: {
colocate: "true",
default_dispatcher_opts: [ "allow_sync_calls" ],
bind: {
protocol: "fuchsia.usb.BIND_PROTOCOL.INTERFACE",
usb: {
class: "fuchsia.usb.CLASS.MASS_STORAGE",
subclass: "fuchsia.usb.massstorage.SUBCLASS.SCSI",
protocol: "fuchsia.usb.massstorage.PROTOCOL.BULK_ONLY"
}
}
},
capabilities: [
{ service: "fuchsia.hardware.block.volume.Service" }
],
expose: [
{
service: "fuchsia.hardware.block.volume.Service",
from: "self"
}
]
}
```
---
### Example 2: Composite buttons driver
#### Before: Separate files
`meta/buttons.cml`:
```json5
{
include: [
"inspect/client.shard.cml",
"syslog/client.shard.cml",
],
program: {
runner: "driver",
binary: "driver/buttons.so",
bind: "meta/bind/buttons.bindbc",
},
use: [
{ service: "fuchsia.hardware.platform.device.Service" },
{ service: "fuchsia.hardware.gpio.Service" },
],
capabilities: [
{ service: "fuchsia.input.report.Service" }
],
expose: [
{
service: "fuchsia.input.report.Service",
from: "self"
}
]
}
```
`meta/buttons.bind`:
```bind
composite buttons;
using fuchsia;
primary parent "pdev" {
fuchsia.COMPATIBLE == "fuchsia,gpio-buttons";
}
optional parent "gpio-init" {
fuchsia.Service == "fuchsia.gpio.Init";
}
optional parent "volume-up" {
fuchsia.Service == "fuchsia.hardware.gpio.Service";
fuchsia.NAME == "volume-up";
}
```
#### After: Unified meta/buttons.dml
```json5
{
name: "buttons",
use: [
{
service: "fuchsia.hardware.platform.device.Service",
name: "pdev",
primary: true,
bind: {
compat: "fuchsia,gpio-buttons"
}
},
{
service: "fuchsia.gpio.Init",
name: "gpio-init",
availability: "optional"
},
{
service: "fuchsia.hardware.gpio.Service",
name: "volume-up",
availability: "optional",
bind: {
match_name: true
}
}
],
capabilities: [
{ service: "fuchsia.input.report.Service" }
],
expose: [
{
service: "fuchsia.input.report.Service",
from: "self"
}
]
}
```
Notice that:
* `pdev` is explicitly the primary parent.
* `fuchsia.gpio.Init` generates a `fuchsia.Service == "fuchsia.gpio.Init";` bind rule and is automatically filtered out of the generated CML.
* `volume-up` with `match_name: true` automatically matches `fuchsia.NAME == "volume-up"`.
---
[dfv2]: /docs/development/drivers/dfv2-overview.md