drivers: pm_cpu_ops: Add support for multiple PSCI versions
Each PSCI interface versions have different DT compatible strings like arm,psci-0.2, arm,psci-1.1 and so on. However, the same driver can be used for all the versions by adding #define DT_COMPAT for required version and #undef DT_COMPAT for default version. Add support for PSCI cold reset, warm reset and cpu-on function IDs. Signed-off-by: Girisha Dengi <girisha.dengi@intel.com> Signed-off-by: Navinkumar Balabakthan <navinkumar.balabakthan@intel.com>
This commit is contained in:
parent
f0ac2347da
commit
62dbe72cb7
9 changed files with 292 additions and 57 deletions
|
@ -1,6 +1,8 @@
|
|||
/*
|
||||
* Copyright 2020 Carlo Caione <ccaione@baylibre.com>
|
||||
*
|
||||
* Copyright (c) 2023, Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
@ -19,7 +21,8 @@ LOG_MODULE_REGISTER(psci);
|
|||
#include <zephyr/drivers/pm_cpu_ops.h>
|
||||
#include "pm_cpu_ops_psci.h"
|
||||
|
||||
static struct psci psci_data;
|
||||
/* PSCI data object. */
|
||||
static struct psci_data_t psci_data;
|
||||
|
||||
static int psci_to_dev_err(int ret)
|
||||
{
|
||||
|
@ -80,6 +83,43 @@ int pm_system_off(void)
|
|||
return psci_to_dev_err(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks whether the given ID is supported or not, using
|
||||
* PSCI_FEATURES command.PSCI_FEATURES is supported from version 1.0 onwards.
|
||||
*/
|
||||
static int psci_features_check(unsigned long function_id)
|
||||
{
|
||||
/* PSCI_FEATURES function ID is supported from PSCI 1.0 onwards. */
|
||||
if (!(PSCI_VERSION_MAJOR(psci_data.ver) >= 1)) {
|
||||
LOG_ERR("Function ID %lu not supported", function_id);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return psci_data.invoke_psci_fn(PSCI_FN_NATIVE(1_0, PSCI_FEATURES), function_id, 0, 0);
|
||||
}
|
||||
|
||||
int pm_system_reset(unsigned char reset_type)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (psci_data.conduit == SMCCC_CONDUIT_NONE) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((reset_type == SYS_WARM_RESET) &&
|
||||
(!psci_features_check(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2)))) {
|
||||
ret = psci_data.invoke_psci_fn(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2), 0, 0, 0);
|
||||
} else if (reset_type == SYS_COLD_RESET) {
|
||||
ret = psci_data.invoke_psci_fn(PSCI_FN_NATIVE(0_2, SYSTEM_RESET), 0, 0, 0);
|
||||
} else {
|
||||
LOG_ERR("Invalid system reset type issued");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return psci_to_dev_err(ret);
|
||||
|
||||
}
|
||||
|
||||
static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
|
||||
unsigned long arg0,
|
||||
unsigned long arg1,
|
||||
|
@ -107,16 +147,14 @@ static uint32_t psci_get_version(void)
|
|||
return psci_data.invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
|
||||
}
|
||||
|
||||
static int set_conduit_method(void)
|
||||
static int set_conduit_method(const struct device *dev)
|
||||
{
|
||||
const char *method;
|
||||
const struct psci_config_t *dev_config = (const struct psci_config_t *)dev->config;
|
||||
|
||||
method = DT_PROP(DT_INST(0, DT_DRV_COMPAT), method);
|
||||
|
||||
if (!strcmp("hvc", method)) {
|
||||
if (!strcmp("hvc", dev_config->method)) {
|
||||
psci_data.conduit = SMCCC_CONDUIT_HVC;
|
||||
psci_data.invoke_psci_fn = __invoke_psci_fn_hvc;
|
||||
} else if (!strcmp("smc", method)) {
|
||||
} else if (!strcmp("smc", dev_config->method)) {
|
||||
psci_data.conduit = SMCCC_CONDUIT_SMC;
|
||||
psci_data.invoke_psci_fn = __invoke_psci_fn_smc;
|
||||
} else {
|
||||
|
@ -154,13 +192,38 @@ static int psci_init(const struct device *dev)
|
|||
{
|
||||
psci_data.conduit = SMCCC_CONDUIT_NONE;
|
||||
|
||||
if (set_conduit_method()) {
|
||||
if (set_conduit_method(dev)) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return psci_detect();
|
||||
}
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, psci_init, NULL,
|
||||
&psci_data, NULL, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
NULL);
|
||||
/**
|
||||
* Each PSCI interface versions have different DT compatible strings like arm,psci-0.2,
|
||||
* arm,psci-1.1 and so on. However, the same driver can be used for all the versions with
|
||||
* the below mentioned DT method where we need to #undef the default version arm,psci-0.2
|
||||
* and #define the required version like arm,psci-1.0 or arm,psci-1.1.
|
||||
*/
|
||||
#define PSCI_DEFINE(inst, ver) \
|
||||
static const struct psci_config_t psci_config_##inst##ver = { \
|
||||
.method = DT_PROP(DT_DRV_INST(inst), method) \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(inst, \
|
||||
&psci_init, \
|
||||
NULL, \
|
||||
&psci_data, \
|
||||
&psci_config_##inst##ver, \
|
||||
PRE_KERNEL_1, \
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||
NULL);
|
||||
|
||||
#define PSCI_0_2_INIT(n) PSCI_DEFINE(n, PSCI_0_2)
|
||||
#undef DT_DRV_COMPAT
|
||||
#define DT_DRV_COMPAT arm_psci_0_2
|
||||
DT_INST_FOREACH_STATUS_OKAY(PSCI_0_2_INIT)
|
||||
|
||||
#define PSCI_1_1_INIT(n) PSCI_DEFINE(n, PSCI_1_1)
|
||||
#undef DT_DRV_COMPAT
|
||||
#define DT_DRV_COMPAT arm_psci_1_1
|
||||
DT_INST_FOREACH_STATUS_OKAY(PSCI_1_1_INIT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue