Skip to content

Commit 4fe2ca2

Browse files
mmaka1mwasko
authored andcommitted
arch: fw: doc sof lib with zephyr and legacy configuration
Documentation of a unified SOF lib interface for the upper code and implementation of the interfaces with both Zephyr and legacy SOF parts. Signed-off-by: Marcin Maka <[email protected]>
1 parent 1a17d9c commit 4fe2ca2

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
component "app/mpp" as app
2+
3+
component lib <<sof_api>> {
4+
interface cpu
5+
interface dai
6+
interface dma
7+
interface pm_runtime
8+
9+
component dai_mng
10+
dai_mng -up- dai
11+
component dma_mng
12+
dma_mng -up- dma
13+
component pm_runtime_impl
14+
pm_runtime_impl -up- pm_runtime
15+
}
16+
17+
app .down.> dai : uses
18+
app .down.> dma : uses
19+
app .down.> pm_runtime : uses
20+
app .down.> cpu : uses
21+
22+
component "arch/xtensa/lib" as arch_xtensa {
23+
component arch_cpu
24+
}
25+
arch_cpu -up- cpu
26+
27+
component <i>vendor</i> {
28+
component platform {
29+
component dai_init
30+
dai_init .up.> dai_mng : initialize
31+
component dma_init
32+
dma_init .up.> dma_mng : initialize
33+
component platform_pm_runtime
34+
}
35+
component drivers
36+
drivers .up.> dma : uses
37+
}
38+
arch_cpu .down.> platform
39+
pm_runtime_impl .down.> platform_pm_runtime
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
component "app/mpp" as app
2+
3+
component lib <<sof_api>> {
4+
interface cpu
5+
interface dai
6+
interface dma
7+
interface pm_runtime
8+
9+
' component dai_mng
10+
' dai_mng -up- dai
11+
' component dma_mng
12+
' dma_mng -up- dma
13+
' component pm_runtime_impl
14+
' pm_runtime_impl -up- pm_runtime
15+
}
16+
17+
app .down.> dai : uses
18+
app .down.> dma : uses
19+
app .down.> pm_runtime : uses
20+
app .down.> cpu : uses
21+
22+
component "lib-zephyr" as lib_zephyr {
23+
component "cpu-flows" as cpu_flows
24+
cpu_flows -up- cpu
25+
}
26+
27+
component "zephyr" as zephyr {
28+
component "api" as zephyr_api
29+
}
30+
31+
cpu_flows .down.> zephyr_api : uses
32+
zephyr_api -up- dai
33+
zephyr_api -up- dma
34+
zephyr_api -up- pm_runtime
35+
36+
' component "arch/xtensa/lib" as arch_xtensa {
37+
' component arch_cpu
38+
' }
39+
' arch_cpu -up- cpu
40+
41+
' component <i>vendor</i> {
42+
' component platform {
43+
' component dai_init
44+
' dai_init .up.> dai_mng : initialize
45+
' component dma_init
46+
' dma_init .up.> dma_mng : initialize
47+
' component platform_pm_runtime
48+
' }
49+
' component drivers
50+
' drivers .up.> dma : uses
51+
' }
52+
' arch_cpu .down.> platform
53+
' pm_runtime_impl .down.> platform_pm_runtime

architectures/firmware/sof-zephyr/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ SOF with Zephyr Architecture
1010
app_layer/index
1111
mpp_layer/index
1212
rtos_layer/index
13+
zephyr_api_integration
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
.. _zephyr-api-integration:
2+
3+
Zephyr API Integration
4+
######################
5+
6+
Most of the interfaces between the application (audio) layer and the kernel are
7+
aggregated inside the part of the legacy SOF architecture called "lib". The
8+
interfaces are exposed by the *lib*, declared in header files in
9+
*src/include/sof/lib* directory. Implementation is located in the *src/lib*
10+
except for platform and architecture specific functions that are delegated to
11+
*platform* and *arch* parts respectively.
12+
13+
.. uml:: images/sof_lib.pu
14+
:caption: Legacy SOF Lib
15+
16+
Zephyr replaces *lib* and other architecture and platform specific code,
17+
everything below the *app* & *mpp* layers.
18+
19+
In order to unify the access to the lower parts from the *app* and *mpp*, the
20+
library header files provides now a definition of unified interface but some
21+
changes are introduced to the original set of APIs and/or the implementation.
22+
23+
Let's have a look at possible cases.
24+
25+
**Case #1: New Zephyr API replaces 1:1 legacy SOF lib API**
26+
27+
If there is a Zephyr version of a SOF legacy API which provides exactly the same
28+
functionality as the original function but has a different name, the Zephyr
29+
function name is used as a replacement in the SOF *app* and *mpp* code. It
30+
causes direct linking and call into the Zephyr code optimizing FW size and
31+
performance when SOF is built with Zephyr. Building with legacy SOF *lib*
32+
requires an implementation or just a simple adapter for the new Zephyr API. It
33+
may or may not slightly increase the size and decrease the performance of the
34+
legacy SOF.
35+
36+
.. code-block:: c
37+
38+
// src/include/sof/lib.cpu.h
39+
#ifdef __ZEPHYR__
40+
#include <zephyr/arch/cpu.h>
41+
#else
42+
// was: static inline int cpu_is_core_enabled(int id)
43+
static inline bool arch_cpu_active(int id)
44+
{
45+
arch_cpu_is_core_enabled(id);
46+
}
47+
#endif /* __ZEPHYR__ */
48+
49+
**Case #2: Legacy SOF lib API requires multi-step implementation for Zephyr
50+
configuration**
51+
52+
There may be a case when SOF legacy API is implemented by a single function
53+
provided by the *arch* or another package and there is no 1:1 API available in
54+
Zephyr to replace that. In this case, the API is implemented in the *lib-zephyr*
55+
part based on the native Zephyr APIs.
56+
57+
.. code-block:: c
58+
59+
// src/include/sof/lib/cpu.h
60+
#ifdef __ZEPHYR__
61+
void cpu_disable_core(int id);
62+
#else
63+
static inline void cpu_disable_core(int id)
64+
{
65+
arch_cpu_disable_core(id);
66+
}
67+
#endif /* __ZEPHYR__ */
68+
69+
// src/lib-zephyr/cpu.c
70+
void cpu_disable_core(int id)
71+
{
72+
// ... calls to Zephyr APIs
73+
}
74+
75+
**Case #3: Legacy SOF lib API is implemented completely inside the lib and does
76+
not have any replacement in Zephyr**
77+
78+
The agent code might be an example of the library functions that are common and
79+
must be compiled and linked together with either legacy SOF *lib* or
80+
*lib-zephyr*.
81+
82+
The dependencies between the SOF *lib*, *lib-zephyr*, and *zephyr* are
83+
illustrated in the below figure.
84+
85+
.. uml:: images/sof_lib_zephyr.pu
86+
:caption: SOF Lib + Zephyr

0 commit comments

Comments
 (0)