summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoby Mathew <soby.mathew@arm.com>2015-04-16 14:49:09 +0100
committerSoby Mathew <soby.mathew@arm.com>2015-04-16 16:48:56 +0100
commitfed2a99bafb4d9eb27521b488249015487546878 (patch)
treef4bb0e7dd14f6502b97937492b96751c13488e3b
parent5e4ec4bdb45a7172d02114c308cb1f32917c61ae (diff)
downloadarm-trusted-firmware-rfc/psci-comp-pwr-states.tar.gz
PSCI: Demonstrate support for composite power statesrfc/psci-comp-pwr-states
This patch adds support to the Juno and FVP ports for composite power states with both the original and extended state-id power-state formats. Both the platform ports use the recommended state-id encoding as specified in Section 6.5 of the PSCI specification (ARM DEN 0022C). The platform build flag RECOM_STATE_ID_ENC is used to include this support. By default, to maintain backwards compatibility, the original power state parameter format is used and the state-id field is expected to be zero. Change-Id: Ie721b961957eaecaca5bf417a30952fe0627ef10
-rw-r--r--plat/fvp/fvp_pm.c65
-rw-r--r--plat/fvp/fvp_private.h23
-rw-r--r--plat/fvp/platform.mk17
-rw-r--r--plat/juno/juno_private.h23
-rw-r--r--plat/juno/plat_pm.c61
-rw-r--r--plat/juno/platform.mk17
6 files changed, 205 insertions, 1 deletions
diff --git a/plat/fvp/fvp_pm.c b/plat/fvp/fvp_pm.c
index 6545998f4..690c7382b 100644
--- a/plat/fvp/fvp_pm.c
+++ b/plat/fvp/fvp_pm.c
@@ -44,6 +44,25 @@
#include "fvp_def.h"
#include "fvp_private.h"
+#if RECOM_STATE_ID_ENC
+/*
+ * The table storing the valid idle power states. Ensure that the
+ * array entries are populated in ascending order of state-id to
+ * enable us to use binary search during power state validation.
+ */
+const uint32_t fvp_idle_states[] = {
+ /* State-id - 0x01 */
+ fvp_make_pwr_state(FVP_PM_RUN, FVP_PM_RET,
+ FVP_PWR_LVL0, PSTATE_TYPE_STANDBY),
+ /* State-id - 0x02 */
+ fvp_make_pwr_state(FVP_PM_RUN, FVP_PM_OFF,
+ FVP_PWR_LVL0, PSTATE_TYPE_POWERDOWN),
+ /* State-id - 0x22 */
+ fvp_make_pwr_state(FVP_PM_OFF, FVP_PM_OFF,
+ FVP_PWR_LVL1, PSTATE_TYPE_POWERDOWN),
+};
+#endif /* __RECOM_STATE_ID_ENC__ */
+
/*******************************************************************************
* Private FVP function to program the mailbox for a cpu before it is released
* from reset.
@@ -274,10 +293,12 @@ static void __dead2 fvp_system_reset(void)
panic();
}
+#if !RECOM_STATE_ID_ENC
/*******************************************************************************
* FVP handler called to check the validity of the power state parameter.
******************************************************************************/
-int fvp_validate_power_state(unsigned int power_state, psci_power_state_t *req_state)
+int fvp_validate_power_state(unsigned int power_state,
+ psci_power_state_t *req_state)
{
int pstate = psci_get_pstate_type(power_state);
int pwr_lvl = psci_get_pstate_pwrlvl(power_state);
@@ -312,6 +333,48 @@ int fvp_validate_power_state(unsigned int power_state, psci_power_state_t *req_s
return PSCI_E_SUCCESS;
}
+#else
+/*******************************************************************************
+ * FVP handler called to check the validity of the power state parameter. The
+ * power state parameter has to be a composite power state.
+ ******************************************************************************/
+int fvp_validate_power_state(unsigned int power_state,
+ psci_power_state_t *req_state)
+{
+ unsigned int state_id;
+ int i, idle_states_num = sizeof(fvp_idle_states)/
+ sizeof(fvp_idle_states[0]);
+
+ assert(req_state);
+
+ /*
+ * Currently we are using a linear search for finding the matching
+ * entry in the idle power state array. This can be made a binary
+ * search if the number of entries justify the additional complexity.
+ */
+ for (i = 0; i < idle_states_num; i++) {
+ if (power_state == fvp_idle_states[i])
+ break;
+ }
+
+ /* Return error if entry not found in the idle state array */
+ if (i == idle_states_num)
+ return PSCI_E_INVALID_PARAMS;
+
+ i = 0;
+ state_id = psci_get_pstate_id(power_state);
+
+ /* Parse the State ID and populate the state info parameter */
+ while (state_id) {
+ req_state->pwr_domain_state[i++] = state_id &
+ FVP_LOCAL_PSTATE_MASK;
+ state_id >>= FVP_LOCAL_PSTATE_WIDTH;
+ }
+
+ return PSCI_E_SUCCESS;
+}
+#endif /* __RECOM_STATE_ID_ENC__ */
+
/*******************************************************************************
* Export the platform handlers to enable psci to invoke them
******************************************************************************/
diff --git a/plat/fvp/fvp_private.h b/plat/fvp/fvp_private.h
index d0cff21cf..b3f54738c 100644
--- a/plat/fvp/fvp_private.h
+++ b/plat/fvp/fvp_private.h
@@ -112,6 +112,29 @@ CASSERT(PLAT_PCPU_DATA_SIZE == sizeof(fvp_cpu_data_t), \
#endif /* __USE_COHERENT_MEM__ */
+#if RECOM_STATE_ID_ENC
+/*
+ * Macros used to parse state information from State-ID if it is using the
+ * recommended encoding for State-ID.
+ */
+#define FVP_LOCAL_PSTATE_MASK 0xF
+#define FVP_LOCAL_PSTATE_WIDTH 4
+
+/* Macro to construct the power state */
+#if PSCI_EXTENDED_STATE_ID
+#define fvp_make_pwr_state(lvl1_state, lvl0_state, pwr_lvl, type) \
+ (((lvl1_state << FVP_LOCAL_PSTATE_WIDTH | lvl0_state) \
+ << PSTATE_ID_SHIFT) | \
+ (type << PSTATE_TYPE_SHIFT))
+#else
+#define fvp_make_pwr_state(lvl1_state, lvl0_state, pwr_lvl, type) \
+ (((lvl1_state << FVP_LOCAL_PSTATE_WIDTH | lvl0_state) \
+ << PSTATE_ID_SHIFT) | \
+ (pwr_lvl << PSTATE_PWR_LVL_SHIFT) | \
+ (type << PSTATE_TYPE_SHIFT))
+#endif /* __PSCI_EXTENDED_STATE_ID__ */
+#endif /* __RECOM_STATE_ID_ENC__ */
+
/*******************************************************************************
* Function and variable prototypes
******************************************************************************/
diff --git a/plat/fvp/platform.mk b/plat/fvp/platform.mk
index 7cf571e45..19d45ac88 100644
--- a/plat/fvp/platform.mk
+++ b/plat/fvp/platform.mk
@@ -44,6 +44,23 @@ endif
# Process flags
$(eval $(call add_define,FVP_TSP_RAM_LOCATION_ID))
+# On FVP, for the original power-state parameter, the State-ID can be encoded according
+# to the recommended encoding or zero. This flag determines which State-ID encoding
+# to be parsed.
+RECOM_STATE_ID_ENC := 0
+
+# If the PSCI_EXTENDED_STATE_ID is set, then the recommended state ID need to be used.
+# Else throw a build error.
+ifeq (${PSCI_EXTENDED_STATE_ID}, 1)
+ ifeq (${RECOM_STATE_ID_ENC}, 0)
+ $(error "Incompatible STATE_ID build option specified")
+ endif
+endif
+
+# Process RECOM_STATE_ID_ENC flag
+$(eval $(call assert_boolean,RECOM_STATE_ID_ENC))
+$(eval $(call add_define,RECOM_STATE_ID_ENC))
+
PLAT_INCLUDES := -Iplat/fvp/include/
PLAT_BL_COMMON_SOURCES := drivers/arm/pl011/pl011_console.S \
diff --git a/plat/juno/juno_private.h b/plat/juno/juno_private.h
index 31232493c..a5e42944f 100644
--- a/plat/juno/juno_private.h
+++ b/plat/juno/juno_private.h
@@ -123,6 +123,29 @@ CASSERT(PLAT_PCPU_DATA_SIZE == sizeof(juno_cpu_data_t), \
#endif /* __IMAGE_BL31__ */
+#if RECOM_STATE_ID_ENC
+/*
+ * Macros used to parse state information from State-ID if it is using the
+ * recommended encoding for State-ID.
+ */
+#define JUNO_LOCAL_PSTATE_MASK 0xF
+#define JUNO_LOCAL_PSTATE_WIDTH 4
+
+/* Macro to construct the power state */
+#if PSCI_EXTENDED_STATE_ID
+#define juno_make_pwr_state(lvl1_state, lvl0_state, pwr_lvl, type) \
+ (((lvl1_state << JUNO_LOCAL_PSTATE_WIDTH | lvl0_state) \
+ << PSTATE_ID_SHIFT) | \
+ (type << PSTATE_TYPE_SHIFT))
+#else
+#define juno_make_pwr_state(lvl1_state, lvl0_state, pwr_lvl, type) \
+ (((lvl1_state << JUNO_LOCAL_PSTATE_WIDTH | lvl0_state) \
+ << PSTATE_ID_SHIFT) | \
+ (pwr_lvl << PSTATE_PWR_LVL_SHIFT) | \
+ (type << PSTATE_TYPE_SHIFT))
+#endif /* __PSCI_EXTENDED_STATE_ID__ */
+#endif /* __RECOM_STATE_ID_ENC__ */
+
/*******************************************************************************
* Function and variable prototypes
******************************************************************************/
diff --git a/plat/juno/plat_pm.c b/plat/juno/plat_pm.c
index c19d99c76..1a9928808 100644
--- a/plat/juno/plat_pm.c
+++ b/plat/juno/plat_pm.c
@@ -41,6 +41,25 @@
#include "juno_private.h"
#include "scpi.h"
+#if RECOM_STATE_ID_ENC
+/*
+ * The table storing the valid idle power states. Ensure that the
+ * array entries are populated in ascending order of state-id to
+ * enable us to use binary search during power state validation.
+ */
+const uint32_t juno_idle_states[] = {
+ /* State-id - 0x01 */
+ juno_make_pwr_state(JUNO_PM_RUN, JUNO_PM_RET,
+ JUNO_PWR_LVL0, PSTATE_TYPE_STANDBY),
+ /* State-id - 0x02 */
+ juno_make_pwr_state(JUNO_PM_RUN, JUNO_PM_OFF,
+ JUNO_PWR_LVL0, PSTATE_TYPE_POWERDOWN),
+ /* State-id - 0x22 */
+ juno_make_pwr_state(JUNO_PM_OFF, JUNO_PM_OFF,
+ JUNO_PWR_LVL1, PSTATE_TYPE_POWERDOWN),
+};
+#endif /* __RECOM_STATE_ID_ENC__ */
+
/*******************************************************************************
* Private Juno function to program the mailbox for a cpu before it is released
* from reset.
@@ -56,6 +75,7 @@ static void juno_program_mailbox(uint64_t mpidr, uint64_t address)
flush_dcache_range(mbox, sizeof(mbox));
}
+#if !RECOM_STATE_ID_ENC
/*******************************************************************************
* Juno handler called to check the validity of the power state parameter.
******************************************************************************/
@@ -94,7 +114,48 @@ int32_t juno_validate_power_state(unsigned int power_state,
return PSCI_E_SUCCESS;
}
+#else
+/*******************************************************************************
+ * JUNO handler called to check the validity of the power state parameter. The
+ * power state parameter must encode composite power state.
+ ******************************************************************************/
+int juno_validate_power_state(unsigned int power_state,
+ psci_power_state_t *req_state)
+{
+ unsigned int state_id;
+ int i, idle_states_num = sizeof(juno_idle_states)/
+ sizeof(juno_idle_states[0]);
+
+ assert(req_state);
+
+ /*
+ * Currently we are using a linear search for finding the matching
+ * entry in the idle power state array. This can be made a binary
+ * search if the number of entries justify the additional complexity.
+ */
+ for (i = 0; i < idle_states_num; i++) {
+ if (power_state == juno_idle_states[i])
+ break;
+ }
+
+ /* Return error if entry not found in the idle state array */
+ if (i == idle_states_num)
+ return PSCI_E_INVALID_PARAMS;
+
+ i = 0;
+ state_id = psci_get_pstate_id(power_state);
+
+ /* Parse the State ID and populate the state info parameter */
+ while (state_id) {
+ req_state->pwr_domain_state[i++] = state_id &
+ JUNO_LOCAL_PSTATE_MASK;
+ state_id >>= JUNO_LOCAL_PSTATE_WIDTH;
+ }
+
+ return PSCI_E_SUCCESS;
+}
+#endif
/*******************************************************************************
* Juno handler called when a power domain is about to be turned on. The
diff --git a/plat/juno/platform.mk b/plat/juno/platform.mk
index 687781417..055309e88 100644
--- a/plat/juno/platform.mk
+++ b/plat/juno/platform.mk
@@ -44,6 +44,23 @@ endif
# Process flags
$(eval $(call add_define,PLAT_TSP_LOCATION_ID))
+# On Juno, for the original power-state parameter, the State-ID can be encoded according
+# to the recommended encoding or zero. This flag determines which State-ID encoding
+# to be parsed.
+RECOM_STATE_ID_ENC := 0
+
+# If the PSCI_EXTENDED_STATE_ID is set, then the recommended state ID need to be used.
+# Else throw a build error.
+ifeq (${PSCI_EXTENDED_STATE_ID}, 1)
+ ifeq (${RECOM_STATE_ID_ENC}, 0)
+ $(error "Incompatible STATE_ID build option specified")
+ endif
+endif
+
+# Process RECOM_STATE_ID_ENC flag
+$(eval $(call assert_boolean,RECOM_STATE_ID_ENC))
+$(eval $(call add_define,RECOM_STATE_ID_ENC))
+
PLAT_INCLUDES := -Iplat/juno/include/