From 8991eed7439cb565da505a2bf88e9ac87ad79c1c Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Thu, 23 Oct 2014 10:35:34 +0100 Subject: Rework the PSCI migrate APIs This patch reworks the PSCI MIGRATE, MIGRATE_INFO_TYPE and MIGRATE_INFO_UP_CPU support for Trusted Firmware. The implementation does the appropriate validation of parameters and invokes the appropriate hook exported by the SPD. The TSP is a MP Trusted OS. Hence the ability to actually migrate a Trusted OS has not been implemented. The corresponding function is not populated in the spd_pm_hooks structure for the TSPD. The `spd_pm_ops_t` has undergone changes with this patch. SPD PORTS MAY NEED TO BE UPDATED. Fixes ARM-software/tf-issues#249 Change-Id: Iabd87521bf7c530a5e4506b6d3bfd4f1bf87604f --- services/std_svc/psci/psci_main.c | 52 +++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'services/std_svc/psci/psci_main.c') diff --git a/services/std_svc/psci/psci_main.c b/services/std_svc/psci/psci_main.c index 91d16f46..af00551e 100644 --- a/services/std_svc/psci/psci_main.c +++ b/services/std_svc/psci/psci_main.c @@ -219,25 +219,57 @@ int psci_affinity_info(unsigned long target_affinity, return rc; } -/* Unimplemented */ -int psci_migrate(unsigned int target_cpu) +int psci_migrate(unsigned long target_cpu) { - return PSCI_E_NOT_SUPPORTED; + int rc; + unsigned long resident_cpu_mpidr; + + rc = psci_spd_migrate_info(&resident_cpu_mpidr); + if (rc != PSCI_TOS_UP_MIG_CAP) + return (rc == PSCI_TOS_NOT_UP_MIG_CAP) ? + PSCI_E_DENIED : PSCI_E_NOT_SUPPORTED; + + /* + * Migrate should only be invoked on the CPU where + * the Secure OS is resident. + */ + if (resident_cpu_mpidr != read_mpidr_el1()) + return PSCI_E_NOT_PRESENT; + + /* Check the validity of the specified target cpu */ + rc = psci_validate_mpidr(target_cpu, MPIDR_AFFLVL0); + if (rc != PSCI_E_SUCCESS) + return PSCI_E_INVALID_PARAMS; + + assert(psci_spd_pm && psci_spd_pm->svc_migrate); + + rc = psci_spd_pm->svc_migrate(read_mpidr_el1(), target_cpu); + assert(rc == PSCI_E_SUCCESS || rc == PSCI_E_INTERN_FAIL); + + return rc; } -/* Unimplemented */ -unsigned int psci_migrate_info_type(void) +int psci_migrate_info_type(void) { - return PSCI_TOS_NOT_PRESENT_MP; + unsigned long resident_cpu_mpidr; + + return psci_spd_migrate_info(&resident_cpu_mpidr); } -unsigned long psci_migrate_info_up_cpu(void) +long psci_migrate_info_up_cpu(void) { + unsigned long resident_cpu_mpidr; + int rc; + /* - * Return value of this currently unsupported call depends upon - * what psci_migrate_info_type() returns. + * Return value of this depends upon what + * psci_spd_migrate_info() returns. */ - return PSCI_E_SUCCESS; + rc = psci_spd_migrate_info(&resident_cpu_mpidr); + if (rc != PSCI_TOS_NOT_UP_MIG_CAP && rc != PSCI_TOS_UP_MIG_CAP) + return PSCI_E_INVALID_PARAMS; + + return resident_cpu_mpidr; } /******************************************************************************* -- cgit From 90e8258eec95bcad556426597489a34208232e39 Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Wed, 7 Jan 2015 11:10:22 +0000 Subject: Implement PSCI_FEATURES API This patch implements the PSCI_FEATURES function which is a mandatory API in the PSCI 1.0 specification. A capability variable is constructed during initialization by examining the plat_pm_ops and spd_pm_ops exported by the platform and the Secure Payload Dispatcher. This is used by the PSCI FEATURES function to determine which PSCI APIs are supported by the platform. Change-Id: I147ffc1bd5d90b469bd3cc4bbe0a20e95c247df7 --- services/std_svc/psci/psci_main.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'services/std_svc/psci/psci_main.c') diff --git a/services/std_svc/psci/psci_main.c b/services/std_svc/psci/psci_main.c index af00551e..0e10ac05 100644 --- a/services/std_svc/psci/psci_main.c +++ b/services/std_svc/psci/psci_main.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "psci_private.h" @@ -272,6 +273,39 @@ long psci_migrate_info_up_cpu(void) return resident_cpu_mpidr; } +int psci_features(unsigned int psci_fid) +{ + uint32_t local_caps = psci_caps; + + /* Check if it is a 64 bit function */ + if (((psci_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64) + local_caps &= PSCI_CAP_64BIT_MASK; + + /* Check for invalid fid */ + if (!(is_std_svc_call(psci_fid) && is_valid_fast_smc(psci_fid) + && is_psci_fid(psci_fid))) + return PSCI_E_NOT_SUPPORTED; + + + /* Check if the psci fid is supported or not */ + if (!(local_caps & define_psci_cap(psci_fid))) + return PSCI_E_NOT_SUPPORTED; + + /* Format the feature flags */ + if (psci_fid == PSCI_CPU_SUSPEND_AARCH32 || + psci_fid == PSCI_CPU_SUSPEND_AARCH64) { + /* + * The trusted firmware uses the original power state format + * and does not support OS Initiated Mode. + */ + return (FF_PSTATE_ORIG << FF_PSTATE_SHIFT) | + ((!FF_SUPPORTS_OS_INIT_MODE) << FF_MODE_SUPPORT_SHIFT); + } + + /* Return 0 for all other fid's */ + return PSCI_E_SUCCESS; +} + /******************************************************************************* * PSCI top level handler for servicing SMCs. ******************************************************************************/ @@ -327,6 +361,9 @@ uint64_t psci_smc_handler(uint32_t smc_fid, psci_system_reset(); /* We should never return from psci_system_reset() */ + case PSCI_FEATURES: + SMC_RET1(handle, psci_features(x1)); + default: break; } -- cgit From b234b2c4a06169aa965b77dd40c17be454a9f609 Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Thu, 15 Jan 2015 11:49:49 +0000 Subject: Verify capabilities before handling PSCI calls This patch implements conditional checks in psci_smc_handler() to verify that the psci function invoked by the caller is supported by the platform or SPD implementation. The level of support is saved in the 'psci_caps' variable. This check allows the PSCI implementation to return an error early. As a result of the above verification, the checks performed within the psci handlers for the pm hooks are now removed and replaced with assertions. Change-Id: I9b5b646a01d8566dc28c4d77dd3aa54e9bf3981a --- services/std_svc/psci/psci_main.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'services/std_svc/psci/psci_main.c') diff --git a/services/std_svc/psci/psci_main.c b/services/std_svc/psci/psci_main.c index 0e10ac05..d8a00097 100644 --- a/services/std_svc/psci/psci_main.c +++ b/services/std_svc/psci/psci_main.c @@ -321,6 +321,10 @@ uint64_t psci_smc_handler(uint32_t smc_fid, if (is_caller_secure(flags)) SMC_RET1(handle, SMC_UNK); + /* Check the fid against the capabilities */ + if (!(psci_caps & define_psci_cap(smc_fid))) + SMC_RET1(handle, SMC_UNK); + if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { /* 32-bit PSCI function, clear top parameter bits */ -- cgit