diff --git a/src/lib/pm_runtime.c b/src/lib/pm_runtime.c deleted file mode 100644 index 9d4f2492c8dd..000000000000 --- a/src/lib/pm_runtime.c +++ /dev/null @@ -1,195 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2018 Intel Corporation. All rights reserved. -// -// Author: Tomasz Lauda - -/** - * \file - * \brief Runtime power management implementation - * \author Tomasz Lauda - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -LOG_MODULE_REGISTER(pm_runtime, CONFIG_SOF_LOG_LEVEL); - -SOF_DEFINE_REG_UUID(pm_runtime); - -DECLARE_TR_CTX(pm_tr, SOF_UUID(pm_runtime_uuid), LOG_LEVEL_INFO); - -void pm_runtime_init(struct sof *sof) -{ - sof->prd = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*sof->prd)); - if (!sof->prd) { - tr_err(&pm_tr, "pm_runtime_init(): allocation failed"); - return; - } - k_spinlock_init(&sof->prd->lock); - - platform_pm_runtime_init(sof->prd); -} - -/* Warning: the terms in this API (enable, active,... ) apply sometimes - * to power _management_ and other times to _power_ which can be - * confusing. They are however consistent with - * https://www.kernel.org/doc/Documentation/power/runtime_pm.txt and the - * long tradition of double and triple negations in power management. - */ - -/** Increase the usage counter of some PM context. In general this - * blocks low power state but there are exception(s), for instance the - * context for the PM_RUNTIME_HOST_DMA_L1 is reversed: usage blocks high - * power state. - * - * Warning: some (all?) platforms don't really implement any counter, in - * other words the "counter" is silently maxed at 1. - */ -void pm_runtime_get(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_get() context %d index %d", context, index); - - switch (context) { - default: - platform_pm_runtime_get(context, index, RPM_ASYNC); - break; - } -} - -void pm_runtime_get_sync(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_get_sync() context %d index %d", context, - index); - - switch (context) { - default: - platform_pm_runtime_get(context, index, 0); - break; - } -} - -/** Decreases the usage counter of some PM context, see pm_runtime_get() - */ -void pm_runtime_put(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_put() context %d index %d", context, index); - - switch (context) { - default: - platform_pm_runtime_put(context, index, RPM_ASYNC); - break; - } -} - -void pm_runtime_put_sync(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_put_sync() context %d index %d", context, - index); - - switch (context) { - default: - platform_pm_runtime_put(context, index, 0); - break; - } -} - -/** Enables power _management_. The management, not the power. */ -void pm_runtime_enable(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_enable() context %d index %d", context, - index); - - switch (context) { - default: - platform_pm_runtime_enable(context, index); - break; - } -} - -/** Disables power _management_. The management, not the power. */ -void pm_runtime_disable(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_disable() context %d index %d", context, - index); - - switch (context) { - default: - platform_pm_runtime_disable(context, index); - break; - } -} - -/** Is the _power_ active. The power, not its management. */ -bool pm_runtime_is_active(enum pm_runtime_context context, uint32_t index) -{ - tr_dbg(&pm_tr, "pm_runtime_is_active() context %d index %d", context, - index); -#if defined(CONFIG_PM) - return pm_policy_state_lock_is_active(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES); -#else - switch (context) { - default: - return platform_pm_runtime_is_active(context, index); - } -#endif -} - -#if CONFIG_DSP_RESIDENCY_COUNTERS -void init_dsp_r_state(enum dsp_r_state r_state) -{ - struct pm_runtime_data *prd = pm_runtime_data_get(); - struct r_counters_data *r_counters; - - r_counters = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*r_counters)); - if (!r_counters) { - tr_err(&pm_tr, "init_dsp_r_state(): allocation failed"); - return; - } - prd->r_counters = r_counters; - - r_counters->ts = sof_cycle_get_64(); - r_counters->cur_r_state = r_state; -} - -void report_dsp_r_state(enum dsp_r_state r_state) -{ - struct r_counters_data *r_counters = pm_runtime_data_get()->r_counters; - uint64_t ts, delta; - - /* It is possible to call report_dsp_r_state in early platform init from - * pm_runtime_disable so a safe check for r_counters is required - */ - if (!r_counters || r_counters->cur_r_state == r_state) - return; - - ts = sof_cycle_get_64(); - delta = ts - r_counters->ts; - - delta += mailbox_sw_reg_read64(SRAM_REG_R_STATE_TRACE_BASE + - r_counters->cur_r_state * - sizeof(uint64_t)); - - mailbox_sw_reg_write64(SRAM_REG_R_STATE_TRACE_BASE + r_counters->cur_r_state - * sizeof(uint64_t), delta); - - r_counters->cur_r_state = r_state; - r_counters->ts = ts; -} - -enum dsp_r_state get_dsp_r_state(void) -{ - struct r_counters_data *r_counters = pm_runtime_data_get()->r_counters; - - return r_counters ? r_counters->cur_r_state : 0; -} -#endif diff --git a/src/lib/wait.c b/src/lib/wait.c deleted file mode 100644 index 14c21d621209..000000000000 --- a/src/lib/wait.c +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2016 Intel Corporation. All rights reserved. -// -// Author: Liam Girdwood - -/* - * Simple wait for event completion and signaling with timeouts. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -LOG_MODULE_REGISTER(wait, CONFIG_SOF_LOG_LEVEL); - -SOF_DEFINE_REG_UUID(wait); - -DECLARE_TR_CTX(wait_tr, SOF_UUID(wait_uuid), LOG_LEVEL_INFO); - -#define DEFAULT_TRY_TIMES 8 - -int poll_for_register_delay(uint32_t reg, uint32_t mask, - uint32_t val, uint64_t us) -{ - uint64_t tick = k_us_to_cyc_ceil64(us); - uint32_t tries = DEFAULT_TRY_TIMES; - uint64_t delta = tick / tries; - - if (!delta) { - /* - * If we want to wait for less than DEFAULT_TRY_TIMES ticks then - * delta has to be set to 1 and number of tries to that of number - * of ticks. - */ - delta = 1; - tries = tick; - } - - while ((io_reg_read(reg) & mask) != val) { - if (!tries--) { - tr_err(&wait_tr, "poll timeout reg %u mask %u val %u us %u", - reg, mask, val, (uint32_t)us); - return -EIO; - } - wait_delay(delta); - } - return 0; -} - -void wait_delay(uint64_t number_of_clks) -{ - uint64_t timeout = sof_cycle_get_64() + number_of_clks; - - while (sof_cycle_get_64() < timeout) - idelay(PLATFORM_DEFAULT_DELAY); -} - -void wait_delay_ms(uint64_t ms) -{ - wait_delay(k_ms_to_cyc_ceil64(ms)); -} - -void wait_delay_us(uint64_t us) -{ - wait_delay(k_us_to_cyc_ceil64(us)); -}