Skip to content

Commit

Permalink
zephyr: decouple from platform pm_runtime.h interface
Browse files Browse the repository at this point in the history
SOF defines a pm_runtime.h interface that consists of a RTOS
layer and a platform specific layer.

So far, the interface has been used in driver code and a very
small set of audio modules (e.g. key phrase buffer in kpb.c).
The platform layer has only been implemented on Intel platforms.
A no-op implementation is used for other platforms.

As all Intel platforms have moved to Zephyr, this now allows to
simplify the code a lot for SOF Zephyr builds and drop all
dependencies to the pm_runtime.h platform layer. With Zephyr,
the drivers are defined on Zephyr side and the device runtime
management can be handled with Zephyr device interfaces.

This patch removes any use of the platform layer and also drops
the generic lib/pm_runtime.c from Zephyr builds. A thin
sof/lib/pm_runtime.h for Zephyr is added to handle the few
uses of pm_runtime interface in SOF codebase (e.g. init and kbp).

The changes simplify the codebase and reduce the amount of
boilerplate code needed to add new hardware targets to SOF, when
Zephyr is used as the RTOS.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
  • Loading branch information
kv2019i committed Sep 19, 2024
1 parent 9dd8e54 commit c74889e
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 21 deletions.
4 changes: 1 addition & 3 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ if (CONFIG_SOC_SERIES_INTEL_CAVS_V25)
zephyr_library_sources(
${SOF_PLATFORM_PATH}/intel/cavs/platform.c
${SOF_PLATFORM_PATH}/tigerlake/lib/clk.c
lib/pm_runtime.c
lib/clk.c
lib/dma.c
)
Expand All @@ -251,7 +250,6 @@ if (CONFIG_SOC_SERIES_INTEL_ADSP_ACE)
# Platform sources
zephyr_library_sources(
${SOF_PLATFORM_PATH}/intel/ace/platform.c
lib/pm_runtime.c
lib/clk.c
lib/dma.c
)
Expand Down Expand Up @@ -428,7 +426,6 @@ zephyr_library_sources(
# SOF library - parts to transition to Zephyr over time
${SOF_LIB_PATH}/clk.c
${SOF_LIB_PATH}/notifier.c
${SOF_LIB_PATH}/pm_runtime.c
${SOF_LIB_PATH}/cpu-clk-manager.c
${SOF_LIB_PATH}/dma.c
${SOF_LIB_PATH}/dai.c
Expand Down Expand Up @@ -461,6 +458,7 @@ zephyr_library_sources(
schedule.c
lib/alloc.c
lib/cpu.c
lib/pm_runtime.c

# Common library functions - Will be moved to Zephyr over time
lib.c
Expand Down
131 changes: 131 additions & 0 deletions zephyr/include/sof/lib/pm_runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2024 Intel Corporation.
*/

#ifndef __SOF_LIB_PM_RUNTIME_H__
#define __SOF_LIB_PM_RUNTIME_H__

#include <rtos/sof.h>
#include <stdint.h>

/** \addtogroup pm_runtime PM Runtime
* SOF PM runtime specification mapping for Zephyr builds.
*
* This interface is considered deprecated and native Zephyr
* interfaces should be used instead.
* @{
*/

/** \brief Runtime power management context */
enum pm_runtime_context {
PM_RUNTIME_DSP /**< DSP */
};

/**
* \brief Initializes runtime power management.
*/
static inline void pm_runtime_init(struct sof *sof)
{
}

/**
* \brief Retrieves power management resource (async).
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
void pm_runtime_get(enum pm_runtime_context context, uint32_t index);

/**
* \brief Retrieves power management resource.
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
static inline void pm_runtime_get_sync(enum pm_runtime_context context, uint32_t index)
{
}


/**
* \brief Releases power management resource (async).
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
void pm_runtime_put(enum pm_runtime_context context, uint32_t index);

/**
* \brief Releases power management resource.
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
static inline void pm_runtime_put_sync(enum pm_runtime_context context, uint32_t index)
{
}

/**
* \brief Enables power management operations for the resource.
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
void pm_runtime_enable(enum pm_runtime_context context, uint32_t index);

/**
* \brief Disables power management operations for the resource.
*
* \param[in] context Type of power management context.
* \param[in] index Index of the device.
*/
void pm_runtime_disable(enum pm_runtime_context context, uint32_t index);

/**
* \brief Reports state of the power managed resource.
*
* @param context Type of power management context.
* @param index Index of the resource.
*
* @return true if the resource is active or pm disabled, false otherwise.
*/
bool pm_runtime_is_active(enum pm_runtime_context context, uint32_t index);

static inline void platform_pm_runtime_prepare_d0ix_en(uint32_t index)
{
}

#if CONFIG_DSP_RESIDENCY_COUNTERS

/**
* \brief Initializes DSP residency counters.
*
* \param[in] context Type of power management context.
*/
static inline void init_dsp_r_state(enum dsp_r_state)
{
}

/**
* \brief Reports DSP residency state.
*
* \param[in] new state
*/
static inline void report_dsp_r_state(enum dsp_r_state)
{
}

/**
* \brief Retrieves current DSP residency state.
*
* @return active DSP residency state
*/
static inline enum dsp_r_state get_dsp_r_state(void)
{
}
#endif

/** @}*/

#endif /* __SOF_LIB_PM_RUNTIME_H__ */
36 changes: 18 additions & 18 deletions zephyr/lib/pm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
}
#endif /* CONFIG_PM_POLICY_CUSTOM */

void platform_pm_runtime_enable(uint32_t context, uint32_t index)
void pm_runtime_enable(enum pm_runtime_context context, uint32_t index)
{
switch (context) {
case PM_RUNTIME_DSP:
Expand All @@ -77,7 +77,8 @@ void platform_pm_runtime_enable(uint32_t context, uint32_t index)
}
}

void platform_pm_runtime_disable(uint32_t context, uint32_t index)
/** Disables power _management_. The management, not the power. */
void pm_runtime_disable(enum pm_runtime_context context, uint32_t index)
{
switch (context) {
case PM_RUNTIME_DSP:
Expand All @@ -89,19 +90,18 @@ void platform_pm_runtime_disable(uint32_t context, uint32_t index)
}
}

void platform_pm_runtime_init(struct pm_runtime_data *prd)
{ }

void platform_pm_runtime_get(enum pm_runtime_context context, uint32_t index,
uint32_t flags)
{ }

void platform_pm_runtime_put(enum pm_runtime_context context, uint32_t index,
uint32_t flags)
{ }

void platform_pm_runtime_prepare_d0ix_en(uint32_t index)
{ }

void platform_pm_runtime_power_off(void)
{ }
/** Is the _power_ active. The power, not its management. */
bool pm_runtime_is_active(enum pm_runtime_context context, uint32_t index)
{
switch (context) {
case PM_RUNTIME_DSP:
#if defined(CONFIG_PM)
return pm_policy_state_lock_is_active(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES);
#else
return true;
#endif
default:
break;
}
return false;
}

0 comments on commit c74889e

Please sign in to comment.