Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .agent/rules/topology2_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
trigger: glob
glob: tools/topology/topology2/**
---

# Topology2 Design Rule

When working in tools/topology/topology2, follow the canonical guidance in
.github/instructions/topology2-design.instructions.md.

Apply those instructions for topology structure, ID assignment, routing,
platform overrides, and topology target registration.
86 changes: 86 additions & 0 deletions .github/instructions/topology2-design.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
description: "Agent instructions for designing and updating ALSA topology v2 files in SOF"
applyTo: 'tools/topology/topology2/**'
---

# Topology2 Design Instructions

Use this guidance when creating or modifying files under tools/topology/topology2.
These rules align with the topology2 README and capture expected design patterns for
class-based ALSA topology v2 authoring.

## Scope

* Applies to topology2 .conf definitions, platform overrides, pipeline and DAI class files, and topology2 CMake target lists
* Focuses on design consistency, ID safety, and maintainable reuse of existing class and object templates

## Core Model

* Use topology2 object model primitives consistently: Class.*, Object.*, Define, and IncludeByKey
* Prefer reusable classes in include/ over one-off duplicated object blocks
* Keep object instantiation explicit and readable so generated pipelines are traceable

## Top Level Topology Layout

For new top-level board .conf files, keep this order:

1. Search directories
2. Required class includes
3. Define block with defaults
4. IncludeByKey.PLATFORM overrides
5. Feature-gated IncludeByKey blocks
6. DAI, pipeline, and PCM objects
7. Route definitions

## Reuse Before New Base Files

* Prefer extending an existing base input .conf with variable overrides from CMake targets
* Add a new base .conf only when existing topologies cannot represent the use case cleanly
* When adding a new target, use the tuple format exactly:

```text
"input-conf;output-name;variable1=value1,variable2=value2"
Comment on lines +39 to +42
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented CMake tuple format uses raw semicolons, but the topology2 CMake target lists escape semicolons inside quoted strings (e.g., "cavs-sdw\;...\;PLATFORM=..." as in tools/topology/topology2/README.md:204 and production/tplg-targets-ace1.cmake:6). As written, “use the tuple format exactly” may cause copy/paste errors in CMake. Please update this section to either show the escaped form used in CMake (\;) or explicitly call out that semicolons must be escaped in CMake strings.

Suggested change
* When adding a new target, use the tuple format exactly:
```text
"input-conf;output-name;variable1=value1,variable2=value2"
* When adding a new target, use this tuple structure. In CMake quoted strings, escape each semicolon as `\;`.
```text
Logical tuple format:
"input-conf;output-name;variable1=value1,variable2=value2"
CMake string form:
"input-conf\;output-name\;variable1=value1,variable2=value2"

Copilot uses AI. Check for mistakes.
```

## ID Conventions and Safety

* Keep PCM IDs unique within a single topology
* Keep pipeline indexes unique within a single topology
* Pair FE and BE pipelines as N and N+1 where applicable
* For SoundWire pipelines, follow index equals PCM ID times 10 unless a documented topology-specific exception exists
* For HDMI pipelines, keep stride-10 layout with host at N0 and DAI at N1
* When combining features such as SDW, PCH DMIC, HDMI, deep buffer, or compress, verify there are no ID collisions after overrides

## Routing Rules

* Connect FE mixin outputs to BE mixout inputs using Object.Base.route
* Keep route naming and widget references aligned with topology naming patterns
* Validate that each route endpoint maps to a declared widget in the same compiled topology

## Widget Naming

* Follow naming pattern type.pipeline-index.instance
* Keep naming stable and descriptive for easier graph inspection and debug

## Platform Overrides

* Use IncludeByKey.PLATFORM for platform-specific Define overrides
* Restrict platform-specific tuning to platform/intel/*.conf instead of duplicating board-level logic
* Ensure supported platform keys remain consistent with project usage: tgl, mtl, lnl, ptl
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list of “supported platform keys” is incomplete compared to current topology2 usage. Existing top-level configs use additional keys like adl and nvl (e.g., tools/topology/topology2/cavs-nocodec.conf:105-112 and cavs-sdw.conf:129-134). Please update the guidance to include the full set of in-tree keys (or reference the authoritative list) so new changes don’t incorrectly reject/avoid valid platform values.

Suggested change
* Ensure supported platform keys remain consistent with project usage: tgl, mtl, lnl, ptl
* Ensure platform keys remain consistent with the authoritative in-tree overrides under tools/topology/topology2/platform/intel/*.conf; current examples include tgl, adl, mtl, lnl, ptl, and nvl

Copilot uses AI. Check for mistakes.

## CMake Target Placement

Register targets in the correct file for platform generation:

* Tiger Lake and Alder Lake: production/tplg-targets-cavs25.cmake
* Meteor Lake: production/tplg-targets-ace1.cmake
* Lunar Lake: production/tplg-targets-ace2.cmake
* Panther Lake: production/tplg-targets-ace3.cmake
* HDA generic: production/tplg-targets-hda-generic.cmake
* Development and test topologies: development/tplg-targets.cmake

Comment on lines +78 to +81
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target-placement mapping omits existing production target lists such as production/tplg-targets-ace4.cmake (used for sof-nvl-* targets) and others like tplg-targets-imx8.cmake / tplg-targets-sdca-generic.cmake. Since this file is intended as canonical guidance, please extend the table (or point to a single source of truth) so contributors register targets in the correct CMake file.

Suggested change
* Panther Lake: production/tplg-targets-ace3.cmake
* HDA generic: production/tplg-targets-hda-generic.cmake
* Development and test topologies: development/tplg-targets.cmake
* Panther Lake: production/tplg-targets-ace3.cmake
* Nova Lake / `sof-nvl-*`: production/tplg-targets-ace4.cmake
* i.MX8 platforms: production/tplg-targets-imx8.cmake
* SDCA generic topologies: production/tplg-targets-sdca-generic.cmake
* HDA generic: production/tplg-targets-hda-generic.cmake
* Development and test topologies: development/tplg-targets.cmake
If a target family is not listed above, use the existing `tplg-targets-*.cmake`
file that already contains similar topologies as the source of truth, and keep new
targets grouped with the same platform or product family in either `production/` or
`development/`.

Copilot uses AI. Check for mistakes.
## Validation Expectations

* Keep topology2 buildable through the topologies2 target
* Preserve compatibility with alsatplg pre-processing mode used by the build system
* Ensure topology edits remain synchronized with nearby architecture or README documentation when design behavior changes
Loading