|
| 1 | +# ALSA Topology v2 (`tools/topology/topology2`) |
| 2 | + |
| 3 | +This directory contains the ALSA Topology 2.0 source files for Sound Open Firmware. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Topology 2.0 (Topology v2) is a modernization of the ALSA topology infrastructure. It aims to solve the verbosity and complexity issues of Topology v1 without relying as heavily on external macro processors like `m4`. |
| 8 | + |
| 9 | +Topology v2 introduces an object-oriented pre-processing layer directly into the newer `alsatplg` compiler (invoked via the `-p` flag). This allows the configuration files to define classes, objects, and attributes natively within the ALSA configuration syntax. |
| 10 | + |
| 11 | +## Key Advantages |
| 12 | + |
| 13 | +- **Object-Oriented Syntax**: Topology v2 allows for the definition of classes (`Class.Widget`, `Class.Pipeline`) and object instantiation, making the topology files much easier to read, maintain, and extend. |
| 14 | +- **Reduced Pre-Processing**: By handling templating and instantiation inside the `alsatplg` tool itself, the build process is cleaner and errors are easier to trace back to the source files, as opposed to deciphering expanded `m4` output. |
| 15 | +- **Dynamic Variables**: Attributes can be parameterized and passed down to nested objects, allowing for highly flexible definitions of audio pipelines. |
| 16 | + |
| 17 | +## Structure and Component Assembly |
| 18 | + |
| 19 | +Topology v2 shifts the source code layout from macro definitions to class definitions, leveraging the structured nature of the newer compiler. |
| 20 | + |
| 21 | +The directory is built around these core parts: |
| 22 | + |
| 23 | +- **`include/`**: Contains the base ALSA topology class definitions. |
| 24 | + - `components/`: Base classes for individual processing nodes (e.g., PGA, Mixer, SRC). |
| 25 | + - `pipelines/`: Reusable pipeline class definitions that instantiate and connect several base components. |
| 26 | + - `dais/`: Definitions for Digital Audio Interfaces (hardware endpoints). |
| 27 | + - `controls/`: Definitions for volume, enum, and byte controls. |
| 28 | +- **`platform/`**: Hardware-specific configurations and overrides (e.g., Intel-specific IPC attributes). |
| 29 | +- **Top-Level `.conf` files**: The board-specific configurations (e.g., `cavs-rt5682.conf`). These behave like standard ALSA `.conf` files but utilize the `@include` directive to import classes and instantiate them dynamically. |
| 30 | + |
| 31 | +```mermaid |
| 32 | +graph TD |
| 33 | + subgraph "Class Definitions (include/)" |
| 34 | + C_Comp[Class: components/pga.conf] |
| 35 | + C_Pipe[Class: pipelines/volume-playback.conf] |
| 36 | + C_DAI[Class: dais/ssp.conf] |
| 37 | + end |
| 38 | +
|
| 39 | + subgraph "Pipeline Object" |
| 40 | + C_Pipe -.->|Instantiates| C_Comp |
| 41 | + end |
| 42 | +
|
| 43 | + subgraph "Top-Level Topology (board.conf)" |
| 44 | + Board[cavs-board.conf] |
| 45 | + Board -->|"@include"| C_Pipe |
| 46 | + Board -->|"@include"| C_DAI |
| 47 | +
|
| 48 | + Obj_Pipe[Object.Pipeline.volume-playback.1] |
| 49 | + Obj_DAI[Object.Dai.SSP.1] |
| 50 | +
|
| 51 | + Board -.->|Instantiates| Obj_Pipe |
| 52 | + Board -.->|Instantiates| Obj_DAI |
| 53 | +
|
| 54 | + Routes[Object.Base.route] |
| 55 | + Board -.->|Connects Objects| Routes |
| 56 | + end |
| 57 | +``` |
| 58 | + |
| 59 | +## Architecture and Build Flow |
| 60 | + |
| 61 | +Unlike v1, Topology 2 processes objects and classes within the `alsatplg` compiler itself. |
| 62 | + |
| 63 | +### Diagram |
| 64 | + |
| 65 | +```mermaid |
| 66 | +flowchart TD |
| 67 | + conf_classes(["Class Definitions (.conf)"]) -.-> conf_objs(["Object Instantiations (.conf)"]) |
| 68 | +
|
| 69 | + conf_objs -->|"alsatplg -p (Pre-processor Engine)"| tplg["ALSA .tplg Binary"] |
| 70 | +
|
| 71 | + subgraph alsatplg_internal [alsatplg Internal Processing] |
| 72 | + direction TB |
| 73 | + parse["Parse Classes & Objects"] --> resolve["Resolve Attributes"] |
| 74 | + resolve --> validate["Validate Topologies"] |
| 75 | + end |
| 76 | +
|
| 77 | + conf_objs -.-> alsatplg_internal |
| 78 | + alsatplg_internal -.-> tplg |
| 79 | +``` |
| 80 | + |
| 81 | +When building a v2 topology, the `CMakeLists.txt` in `tools/topology/` provides the `add_alsatplg2_command` macro. This macro specifically passes the `-p` flag to `alsatplg`, instructing it to use the new pre-processor engine to resolve the classes and objects defined in the `.conf` files before compiling them into the `.tplg` binary. |
| 82 | + |
| 83 | +### Build Instructions |
| 84 | + |
| 85 | +Topologies are built automatically as part of the standard SOF CMake build process. To explicitly build Topology 2 configurations: |
| 86 | + |
| 87 | +```bash |
| 88 | +# From your build directory: |
| 89 | +make topologies2 |
| 90 | +# OR |
| 91 | +cmake --build . --target topologies2 |
| 92 | +``` |
0 commit comments