xref: /rk3399_ARM-atf/lib/psci/psci_main.c (revision 8fd307ffd602b760634a2be6e2e67033e8c056bd)
1532ed618SSoby Mathew /*
204c1db1eSdp-arm  * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5532ed618SSoby Mathew  */
6532ed618SSoby Mathew 
7532ed618SSoby Mathew #include <arch.h>
8532ed618SSoby Mathew #include <arch_helpers.h>
9532ed618SSoby Mathew #include <assert.h>
10532ed618SSoby Mathew #include <debug.h>
11532ed618SSoby Mathew #include <platform.h>
12872be88aSdp-arm #include <pmf.h>
13872be88aSdp-arm #include <runtime_instr.h>
14cf0b1492SSoby Mathew #include <smcc.h>
15532ed618SSoby Mathew #include <string.h>
16532ed618SSoby Mathew #include "psci_private.h"
17532ed618SSoby Mathew 
18532ed618SSoby Mathew /*******************************************************************************
19532ed618SSoby Mathew  * PSCI frontend api for servicing SMCs. Described in the PSCI spec.
20532ed618SSoby Mathew  ******************************************************************************/
21532ed618SSoby Mathew int psci_cpu_on(u_register_t target_cpu,
22532ed618SSoby Mathew 		uintptr_t entrypoint,
23532ed618SSoby Mathew 		u_register_t context_id)
24532ed618SSoby Mathew 
25532ed618SSoby Mathew {
26532ed618SSoby Mathew 	int rc;
27532ed618SSoby Mathew 	entry_point_info_t ep;
28532ed618SSoby Mathew 
29532ed618SSoby Mathew 	/* Determine if the cpu exists of not */
30532ed618SSoby Mathew 	rc = psci_validate_mpidr(target_cpu);
31532ed618SSoby Mathew 	if (rc != PSCI_E_SUCCESS)
32532ed618SSoby Mathew 		return PSCI_E_INVALID_PARAMS;
33532ed618SSoby Mathew 
34532ed618SSoby Mathew 	/* Validate the entry point and get the entry_point_info */
35532ed618SSoby Mathew 	rc = psci_validate_entry_point(&ep, entrypoint, context_id);
36532ed618SSoby Mathew 	if (rc != PSCI_E_SUCCESS)
37532ed618SSoby Mathew 		return rc;
38532ed618SSoby Mathew 
39532ed618SSoby Mathew 	/*
40532ed618SSoby Mathew 	 * To turn this cpu on, specify which power
41532ed618SSoby Mathew 	 * levels need to be turned on
42532ed618SSoby Mathew 	 */
43532ed618SSoby Mathew 	return psci_cpu_on_start(target_cpu, &ep);
44532ed618SSoby Mathew }
45532ed618SSoby Mathew 
46532ed618SSoby Mathew unsigned int psci_version(void)
47532ed618SSoby Mathew {
48532ed618SSoby Mathew 	return PSCI_MAJOR_VER | PSCI_MINOR_VER;
49532ed618SSoby Mathew }
50532ed618SSoby Mathew 
51532ed618SSoby Mathew int psci_cpu_suspend(unsigned int power_state,
52532ed618SSoby Mathew 		     uintptr_t entrypoint,
53532ed618SSoby Mathew 		     u_register_t context_id)
54532ed618SSoby Mathew {
55532ed618SSoby Mathew 	int rc;
56532ed618SSoby Mathew 	unsigned int target_pwrlvl, is_power_down_state;
57532ed618SSoby Mathew 	entry_point_info_t ep;
58532ed618SSoby Mathew 	psci_power_state_t state_info = { {PSCI_LOCAL_STATE_RUN} };
59532ed618SSoby Mathew 	plat_local_state_t cpu_pd_state;
60532ed618SSoby Mathew 
61532ed618SSoby Mathew 	/* Validate the power_state parameter */
62532ed618SSoby Mathew 	rc = psci_validate_power_state(power_state, &state_info);
63532ed618SSoby Mathew 	if (rc != PSCI_E_SUCCESS) {
64532ed618SSoby Mathew 		assert(rc == PSCI_E_INVALID_PARAMS);
65532ed618SSoby Mathew 		return rc;
66532ed618SSoby Mathew 	}
67532ed618SSoby Mathew 
68532ed618SSoby Mathew 	/*
69532ed618SSoby Mathew 	 * Get the value of the state type bit from the power state parameter.
70532ed618SSoby Mathew 	 */
71532ed618SSoby Mathew 	is_power_down_state = psci_get_pstate_type(power_state);
72532ed618SSoby Mathew 
73532ed618SSoby Mathew 	/* Sanity check the requested suspend levels */
74532ed618SSoby Mathew 	assert(psci_validate_suspend_req(&state_info, is_power_down_state)
75532ed618SSoby Mathew 			== PSCI_E_SUCCESS);
76532ed618SSoby Mathew 
77532ed618SSoby Mathew 	target_pwrlvl = psci_find_target_suspend_lvl(&state_info);
78a1c3faa6SSandrine Bailleux 	if (target_pwrlvl == PSCI_INVALID_PWR_LVL) {
79a1c3faa6SSandrine Bailleux 		ERROR("Invalid target power level for suspend operation\n");
80a1c3faa6SSandrine Bailleux 		panic();
81a1c3faa6SSandrine Bailleux 	}
82532ed618SSoby Mathew 
83532ed618SSoby Mathew 	/* Fast path for CPU standby.*/
84532ed618SSoby Mathew 	if (is_cpu_standby_req(is_power_down_state, target_pwrlvl)) {
85532ed618SSoby Mathew 		if  (!psci_plat_pm_ops->cpu_standby)
86532ed618SSoby Mathew 			return PSCI_E_INVALID_PARAMS;
87532ed618SSoby Mathew 
88532ed618SSoby Mathew 		/*
89532ed618SSoby Mathew 		 * Set the state of the CPU power domain to the platform
90532ed618SSoby Mathew 		 * specific retention state and enter the standby state.
91532ed618SSoby Mathew 		 */
92532ed618SSoby Mathew 		cpu_pd_state = state_info.pwr_domain_state[PSCI_CPU_PWR_LVL];
93532ed618SSoby Mathew 		psci_set_cpu_local_state(cpu_pd_state);
94532ed618SSoby Mathew 
95532ed618SSoby Mathew #if ENABLE_PSCI_STAT
9604c1db1eSdp-arm 		plat_psci_stat_accounting_start(&state_info);
97532ed618SSoby Mathew #endif
98532ed618SSoby Mathew 
99872be88aSdp-arm #if ENABLE_RUNTIME_INSTRUMENTATION
100872be88aSdp-arm 		PMF_CAPTURE_TIMESTAMP(rt_instr_svc,
101872be88aSdp-arm 		    RT_INSTR_ENTER_HW_LOW_PWR,
102872be88aSdp-arm 		    PMF_NO_CACHE_MAINT);
103872be88aSdp-arm #endif
104872be88aSdp-arm 
105532ed618SSoby Mathew 		psci_plat_pm_ops->cpu_standby(cpu_pd_state);
106532ed618SSoby Mathew 
107532ed618SSoby Mathew 		/* Upon exit from standby, set the state back to RUN. */
108532ed618SSoby Mathew 		psci_set_cpu_local_state(PSCI_LOCAL_STATE_RUN);
109532ed618SSoby Mathew 
110872be88aSdp-arm #if ENABLE_RUNTIME_INSTRUMENTATION
111872be88aSdp-arm 		PMF_CAPTURE_TIMESTAMP(rt_instr_svc,
112872be88aSdp-arm 		    RT_INSTR_EXIT_HW_LOW_PWR,
113872be88aSdp-arm 		    PMF_NO_CACHE_MAINT);
114872be88aSdp-arm #endif
115872be88aSdp-arm 
116532ed618SSoby Mathew #if ENABLE_PSCI_STAT
11704c1db1eSdp-arm 		plat_psci_stat_accounting_stop(&state_info);
118532ed618SSoby Mathew 
119532ed618SSoby Mathew 		/* Update PSCI stats */
12004c1db1eSdp-arm 		psci_stats_update_pwr_up(PSCI_CPU_PWR_LVL, &state_info);
121532ed618SSoby Mathew #endif
122532ed618SSoby Mathew 
123532ed618SSoby Mathew 		return PSCI_E_SUCCESS;
124532ed618SSoby Mathew 	}
125532ed618SSoby Mathew 
126532ed618SSoby Mathew 	/*
127532ed618SSoby Mathew 	 * If a power down state has been requested, we need to verify entry
128532ed618SSoby Mathew 	 * point and program entry information.
129532ed618SSoby Mathew 	 */
130532ed618SSoby Mathew 	if (is_power_down_state) {
131532ed618SSoby Mathew 		rc = psci_validate_entry_point(&ep, entrypoint, context_id);
132532ed618SSoby Mathew 		if (rc != PSCI_E_SUCCESS)
133532ed618SSoby Mathew 			return rc;
134532ed618SSoby Mathew 	}
135532ed618SSoby Mathew 
136532ed618SSoby Mathew 	/*
137532ed618SSoby Mathew 	 * Do what is needed to enter the power down state. Upon success,
138532ed618SSoby Mathew 	 * enter the final wfi which will power down this CPU. This function
139532ed618SSoby Mathew 	 * might return if the power down was abandoned for any reason, e.g.
140532ed618SSoby Mathew 	 * arrival of an interrupt
141532ed618SSoby Mathew 	 */
142532ed618SSoby Mathew 	psci_cpu_suspend_start(&ep,
143532ed618SSoby Mathew 			    target_pwrlvl,
144532ed618SSoby Mathew 			    &state_info,
145532ed618SSoby Mathew 			    is_power_down_state);
146532ed618SSoby Mathew 
147532ed618SSoby Mathew 	return PSCI_E_SUCCESS;
148532ed618SSoby Mathew }
149532ed618SSoby Mathew 
150532ed618SSoby Mathew 
151532ed618SSoby Mathew int psci_system_suspend(uintptr_t entrypoint, u_register_t context_id)
152532ed618SSoby Mathew {
153532ed618SSoby Mathew 	int rc;
154532ed618SSoby Mathew 	psci_power_state_t state_info;
155532ed618SSoby Mathew 	entry_point_info_t ep;
156532ed618SSoby Mathew 
157532ed618SSoby Mathew 	/* Check if the current CPU is the last ON CPU in the system */
158532ed618SSoby Mathew 	if (!psci_is_last_on_cpu())
159532ed618SSoby Mathew 		return PSCI_E_DENIED;
160532ed618SSoby Mathew 
161532ed618SSoby Mathew 	/* Validate the entry point and get the entry_point_info */
162532ed618SSoby Mathew 	rc = psci_validate_entry_point(&ep, entrypoint, context_id);
163532ed618SSoby Mathew 	if (rc != PSCI_E_SUCCESS)
164532ed618SSoby Mathew 		return rc;
165532ed618SSoby Mathew 
166532ed618SSoby Mathew 	/* Query the psci_power_state for system suspend */
167532ed618SSoby Mathew 	psci_query_sys_suspend_pwrstate(&state_info);
168532ed618SSoby Mathew 
169532ed618SSoby Mathew 	/* Ensure that the psci_power_state makes sense */
170532ed618SSoby Mathew 	assert(psci_find_target_suspend_lvl(&state_info) == PLAT_MAX_PWR_LVL);
171532ed618SSoby Mathew 	assert(psci_validate_suspend_req(&state_info, PSTATE_TYPE_POWERDOWN)
172532ed618SSoby Mathew 						== PSCI_E_SUCCESS);
173532ed618SSoby Mathew 	assert(is_local_state_off(state_info.pwr_domain_state[PLAT_MAX_PWR_LVL]));
174532ed618SSoby Mathew 
175532ed618SSoby Mathew 	/*
176532ed618SSoby Mathew 	 * Do what is needed to enter the system suspend state. This function
177532ed618SSoby Mathew 	 * might return if the power down was abandoned for any reason, e.g.
178532ed618SSoby Mathew 	 * arrival of an interrupt
179532ed618SSoby Mathew 	 */
180532ed618SSoby Mathew 	psci_cpu_suspend_start(&ep,
181532ed618SSoby Mathew 			    PLAT_MAX_PWR_LVL,
182532ed618SSoby Mathew 			    &state_info,
183532ed618SSoby Mathew 			    PSTATE_TYPE_POWERDOWN);
184532ed618SSoby Mathew 
185532ed618SSoby Mathew 	return PSCI_E_SUCCESS;
186532ed618SSoby Mathew }
187532ed618SSoby Mathew 
188532ed618SSoby Mathew int psci_cpu_off(void)
189532ed618SSoby Mathew {
190532ed618SSoby Mathew 	int rc;
191532ed618SSoby Mathew 	unsigned int target_pwrlvl = PLAT_MAX_PWR_LVL;
192532ed618SSoby Mathew 
193532ed618SSoby Mathew 	/*
194532ed618SSoby Mathew 	 * Do what is needed to power off this CPU and possible higher power
195532ed618SSoby Mathew 	 * levels if it able to do so. Upon success, enter the final wfi
196532ed618SSoby Mathew 	 * which will power down this CPU.
197532ed618SSoby Mathew 	 */
198532ed618SSoby Mathew 	rc = psci_do_cpu_off(target_pwrlvl);
199532ed618SSoby Mathew 
200532ed618SSoby Mathew 	/*
201532ed618SSoby Mathew 	 * The only error cpu_off can return is E_DENIED. So check if that's
202532ed618SSoby Mathew 	 * indeed the case.
203532ed618SSoby Mathew 	 */
204532ed618SSoby Mathew 	assert(rc == PSCI_E_DENIED);
205532ed618SSoby Mathew 
206532ed618SSoby Mathew 	return rc;
207532ed618SSoby Mathew }
208532ed618SSoby Mathew 
209532ed618SSoby Mathew int psci_affinity_info(u_register_t target_affinity,
210532ed618SSoby Mathew 		       unsigned int lowest_affinity_level)
211532ed618SSoby Mathew {
2126311f63dSVarun Wadekar 	int target_idx;
213532ed618SSoby Mathew 
214532ed618SSoby Mathew 	/* We dont support level higher than PSCI_CPU_PWR_LVL */
215532ed618SSoby Mathew 	if (lowest_affinity_level > PSCI_CPU_PWR_LVL)
216532ed618SSoby Mathew 		return PSCI_E_INVALID_PARAMS;
217532ed618SSoby Mathew 
218532ed618SSoby Mathew 	/* Calculate the cpu index of the target */
219532ed618SSoby Mathew 	target_idx = plat_core_pos_by_mpidr(target_affinity);
220532ed618SSoby Mathew 	if (target_idx == -1)
221532ed618SSoby Mathew 		return PSCI_E_INVALID_PARAMS;
222532ed618SSoby Mathew 
223*8fd307ffSRoberto Vargas 	/*
224*8fd307ffSRoberto Vargas 	 * Generic management:
225*8fd307ffSRoberto Vargas 	 * Perform cache maintanence ahead of reading the target CPU state to
226*8fd307ffSRoberto Vargas 	 * ensure that the data is not stale.
227*8fd307ffSRoberto Vargas 	 * There is a theoretical edge case where the cache may contain stale
228*8fd307ffSRoberto Vargas 	 * data for the target CPU data - this can occur under the following
229*8fd307ffSRoberto Vargas 	 * conditions:
230*8fd307ffSRoberto Vargas 	 * - the target CPU is in another cluster from the current
231*8fd307ffSRoberto Vargas 	 * - the target CPU was the last CPU to shutdown on its cluster
232*8fd307ffSRoberto Vargas 	 * - the cluster was removed from coherency as part of the CPU shutdown
233*8fd307ffSRoberto Vargas 	 *
234*8fd307ffSRoberto Vargas 	 * In this case the cache maintenace that was performed as part of the
235*8fd307ffSRoberto Vargas 	 * target CPUs shutdown was not seen by the current CPU's cluster. And
236*8fd307ffSRoberto Vargas 	 * so the cache may contain stale data for the target CPU.
237*8fd307ffSRoberto Vargas 	 */
238*8fd307ffSRoberto Vargas 	flush_cpu_data_by_index(target_idx, psci_svc_cpu_data.aff_info_state);
239*8fd307ffSRoberto Vargas 
240532ed618SSoby Mathew 	return psci_get_aff_info_state_by_idx(target_idx);
241532ed618SSoby Mathew }
242532ed618SSoby Mathew 
243532ed618SSoby Mathew int psci_migrate(u_register_t target_cpu)
244532ed618SSoby Mathew {
245532ed618SSoby Mathew 	int rc;
246532ed618SSoby Mathew 	u_register_t resident_cpu_mpidr;
247532ed618SSoby Mathew 
248532ed618SSoby Mathew 	rc = psci_spd_migrate_info(&resident_cpu_mpidr);
249532ed618SSoby Mathew 	if (rc != PSCI_TOS_UP_MIG_CAP)
250532ed618SSoby Mathew 		return (rc == PSCI_TOS_NOT_UP_MIG_CAP) ?
251532ed618SSoby Mathew 			  PSCI_E_DENIED : PSCI_E_NOT_SUPPORTED;
252532ed618SSoby Mathew 
253532ed618SSoby Mathew 	/*
254532ed618SSoby Mathew 	 * Migrate should only be invoked on the CPU where
255532ed618SSoby Mathew 	 * the Secure OS is resident.
256532ed618SSoby Mathew 	 */
257532ed618SSoby Mathew 	if (resident_cpu_mpidr != read_mpidr_el1())
258532ed618SSoby Mathew 		return PSCI_E_NOT_PRESENT;
259532ed618SSoby Mathew 
260532ed618SSoby Mathew 	/* Check the validity of the specified target cpu */
261532ed618SSoby Mathew 	rc = psci_validate_mpidr(target_cpu);
262532ed618SSoby Mathew 	if (rc != PSCI_E_SUCCESS)
263532ed618SSoby Mathew 		return PSCI_E_INVALID_PARAMS;
264532ed618SSoby Mathew 
265532ed618SSoby Mathew 	assert(psci_spd_pm && psci_spd_pm->svc_migrate);
266532ed618SSoby Mathew 
267532ed618SSoby Mathew 	rc = psci_spd_pm->svc_migrate(read_mpidr_el1(), target_cpu);
268532ed618SSoby Mathew 	assert(rc == PSCI_E_SUCCESS || rc == PSCI_E_INTERN_FAIL);
269532ed618SSoby Mathew 
270532ed618SSoby Mathew 	return rc;
271532ed618SSoby Mathew }
272532ed618SSoby Mathew 
273532ed618SSoby Mathew int psci_migrate_info_type(void)
274532ed618SSoby Mathew {
275532ed618SSoby Mathew 	u_register_t resident_cpu_mpidr;
276532ed618SSoby Mathew 
277532ed618SSoby Mathew 	return psci_spd_migrate_info(&resident_cpu_mpidr);
278532ed618SSoby Mathew }
279532ed618SSoby Mathew 
280532ed618SSoby Mathew long psci_migrate_info_up_cpu(void)
281532ed618SSoby Mathew {
282532ed618SSoby Mathew 	u_register_t resident_cpu_mpidr;
283532ed618SSoby Mathew 	int rc;
284532ed618SSoby Mathew 
285532ed618SSoby Mathew 	/*
286532ed618SSoby Mathew 	 * Return value of this depends upon what
287532ed618SSoby Mathew 	 * psci_spd_migrate_info() returns.
288532ed618SSoby Mathew 	 */
289532ed618SSoby Mathew 	rc = psci_spd_migrate_info(&resident_cpu_mpidr);
290532ed618SSoby Mathew 	if (rc != PSCI_TOS_NOT_UP_MIG_CAP && rc != PSCI_TOS_UP_MIG_CAP)
291532ed618SSoby Mathew 		return PSCI_E_INVALID_PARAMS;
292532ed618SSoby Mathew 
293532ed618SSoby Mathew 	return resident_cpu_mpidr;
294532ed618SSoby Mathew }
295532ed618SSoby Mathew 
29628d3d614SJeenu Viswambharan int psci_node_hw_state(u_register_t target_cpu,
29728d3d614SJeenu Viswambharan 		       unsigned int power_level)
29828d3d614SJeenu Viswambharan {
29928d3d614SJeenu Viswambharan 	int rc;
30028d3d614SJeenu Viswambharan 
30128d3d614SJeenu Viswambharan 	/* Validate target_cpu */
30228d3d614SJeenu Viswambharan 	rc = psci_validate_mpidr(target_cpu);
30328d3d614SJeenu Viswambharan 	if (rc != PSCI_E_SUCCESS)
30428d3d614SJeenu Viswambharan 		return PSCI_E_INVALID_PARAMS;
30528d3d614SJeenu Viswambharan 
30628d3d614SJeenu Viswambharan 	/* Validate power_level against PLAT_MAX_PWR_LVL */
30728d3d614SJeenu Viswambharan 	if (power_level > PLAT_MAX_PWR_LVL)
30828d3d614SJeenu Viswambharan 		return PSCI_E_INVALID_PARAMS;
30928d3d614SJeenu Viswambharan 
31028d3d614SJeenu Viswambharan 	/*
31128d3d614SJeenu Viswambharan 	 * Dispatch this call to platform to query power controller, and pass on
31228d3d614SJeenu Viswambharan 	 * to the caller what it returns
31328d3d614SJeenu Viswambharan 	 */
31428d3d614SJeenu Viswambharan 	assert(psci_plat_pm_ops->get_node_hw_state);
31528d3d614SJeenu Viswambharan 	rc = psci_plat_pm_ops->get_node_hw_state(target_cpu, power_level);
31628d3d614SJeenu Viswambharan 	assert((rc >= HW_ON && rc <= HW_STANDBY) || rc == PSCI_E_NOT_SUPPORTED
31728d3d614SJeenu Viswambharan 			|| rc == PSCI_E_INVALID_PARAMS);
31828d3d614SJeenu Viswambharan 	return rc;
31928d3d614SJeenu Viswambharan }
32028d3d614SJeenu Viswambharan 
321532ed618SSoby Mathew int psci_features(unsigned int psci_fid)
322532ed618SSoby Mathew {
323532ed618SSoby Mathew 	unsigned int local_caps = psci_caps;
324532ed618SSoby Mathew 
325532ed618SSoby Mathew 	/* Check if it is a 64 bit function */
326532ed618SSoby Mathew 	if (((psci_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64)
327532ed618SSoby Mathew 		local_caps &= PSCI_CAP_64BIT_MASK;
328532ed618SSoby Mathew 
329532ed618SSoby Mathew 	/* Check for invalid fid */
330532ed618SSoby Mathew 	if (!(is_std_svc_call(psci_fid) && is_valid_fast_smc(psci_fid)
331532ed618SSoby Mathew 			&& is_psci_fid(psci_fid)))
332532ed618SSoby Mathew 		return PSCI_E_NOT_SUPPORTED;
333532ed618SSoby Mathew 
334532ed618SSoby Mathew 
335532ed618SSoby Mathew 	/* Check if the psci fid is supported or not */
336532ed618SSoby Mathew 	if (!(local_caps & define_psci_cap(psci_fid)))
337532ed618SSoby Mathew 		return PSCI_E_NOT_SUPPORTED;
338532ed618SSoby Mathew 
339532ed618SSoby Mathew 	/* Format the feature flags */
340532ed618SSoby Mathew 	if (psci_fid == PSCI_CPU_SUSPEND_AARCH32 ||
341532ed618SSoby Mathew 			psci_fid == PSCI_CPU_SUSPEND_AARCH64) {
342532ed618SSoby Mathew 		/*
343532ed618SSoby Mathew 		 * The trusted firmware does not support OS Initiated Mode.
344532ed618SSoby Mathew 		 */
345532ed618SSoby Mathew 		return (FF_PSTATE << FF_PSTATE_SHIFT) |
346532ed618SSoby Mathew 			((!FF_SUPPORTS_OS_INIT_MODE) << FF_MODE_SUPPORT_SHIFT);
347532ed618SSoby Mathew 	}
348532ed618SSoby Mathew 
349532ed618SSoby Mathew 	/* Return 0 for all other fid's */
350532ed618SSoby Mathew 	return PSCI_E_SUCCESS;
351532ed618SSoby Mathew }
352532ed618SSoby Mathew 
353532ed618SSoby Mathew /*******************************************************************************
354532ed618SSoby Mathew  * PSCI top level handler for servicing SMCs.
355532ed618SSoby Mathew  ******************************************************************************/
356cf0b1492SSoby Mathew u_register_t psci_smc_handler(uint32_t smc_fid,
357532ed618SSoby Mathew 			  u_register_t x1,
358532ed618SSoby Mathew 			  u_register_t x2,
359532ed618SSoby Mathew 			  u_register_t x3,
360532ed618SSoby Mathew 			  u_register_t x4,
361532ed618SSoby Mathew 			  void *cookie,
362532ed618SSoby Mathew 			  void *handle,
363532ed618SSoby Mathew 			  u_register_t flags)
364532ed618SSoby Mathew {
365532ed618SSoby Mathew 	if (is_caller_secure(flags))
366cf0b1492SSoby Mathew 		return SMC_UNK;
367532ed618SSoby Mathew 
368532ed618SSoby Mathew 	/* Check the fid against the capabilities */
369532ed618SSoby Mathew 	if (!(psci_caps & define_psci_cap(smc_fid)))
370cf0b1492SSoby Mathew 		return SMC_UNK;
371532ed618SSoby Mathew 
372532ed618SSoby Mathew 	if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
373532ed618SSoby Mathew 		/* 32-bit PSCI function, clear top parameter bits */
374532ed618SSoby Mathew 
375532ed618SSoby Mathew 		x1 = (uint32_t)x1;
376532ed618SSoby Mathew 		x2 = (uint32_t)x2;
377532ed618SSoby Mathew 		x3 = (uint32_t)x3;
378532ed618SSoby Mathew 
379532ed618SSoby Mathew 		switch (smc_fid) {
380532ed618SSoby Mathew 		case PSCI_VERSION:
381cf0b1492SSoby Mathew 			return psci_version();
382532ed618SSoby Mathew 
383532ed618SSoby Mathew 		case PSCI_CPU_OFF:
384cf0b1492SSoby Mathew 			return psci_cpu_off();
385532ed618SSoby Mathew 
386532ed618SSoby Mathew 		case PSCI_CPU_SUSPEND_AARCH32:
387cf0b1492SSoby Mathew 			return psci_cpu_suspend(x1, x2, x3);
388532ed618SSoby Mathew 
389532ed618SSoby Mathew 		case PSCI_CPU_ON_AARCH32:
390cf0b1492SSoby Mathew 			return psci_cpu_on(x1, x2, x3);
391532ed618SSoby Mathew 
392532ed618SSoby Mathew 		case PSCI_AFFINITY_INFO_AARCH32:
393cf0b1492SSoby Mathew 			return psci_affinity_info(x1, x2);
394532ed618SSoby Mathew 
395532ed618SSoby Mathew 		case PSCI_MIG_AARCH32:
396cf0b1492SSoby Mathew 			return psci_migrate(x1);
397532ed618SSoby Mathew 
398532ed618SSoby Mathew 		case PSCI_MIG_INFO_TYPE:
399cf0b1492SSoby Mathew 			return psci_migrate_info_type();
400532ed618SSoby Mathew 
401532ed618SSoby Mathew 		case PSCI_MIG_INFO_UP_CPU_AARCH32:
402cf0b1492SSoby Mathew 			return psci_migrate_info_up_cpu();
403532ed618SSoby Mathew 
40428d3d614SJeenu Viswambharan 		case PSCI_NODE_HW_STATE_AARCH32:
40528d3d614SJeenu Viswambharan 			return psci_node_hw_state(x1, x2);
40628d3d614SJeenu Viswambharan 
407532ed618SSoby Mathew 		case PSCI_SYSTEM_SUSPEND_AARCH32:
408cf0b1492SSoby Mathew 			return psci_system_suspend(x1, x2);
409532ed618SSoby Mathew 
410532ed618SSoby Mathew 		case PSCI_SYSTEM_OFF:
411532ed618SSoby Mathew 			psci_system_off();
412532ed618SSoby Mathew 			/* We should never return from psci_system_off() */
413532ed618SSoby Mathew 
414532ed618SSoby Mathew 		case PSCI_SYSTEM_RESET:
415532ed618SSoby Mathew 			psci_system_reset();
416532ed618SSoby Mathew 			/* We should never return from psci_system_reset() */
417532ed618SSoby Mathew 
418532ed618SSoby Mathew 		case PSCI_FEATURES:
419cf0b1492SSoby Mathew 			return psci_features(x1);
420532ed618SSoby Mathew 
421532ed618SSoby Mathew #if ENABLE_PSCI_STAT
422532ed618SSoby Mathew 		case PSCI_STAT_RESIDENCY_AARCH32:
423cf0b1492SSoby Mathew 			return psci_stat_residency(x1, x2);
424532ed618SSoby Mathew 
425532ed618SSoby Mathew 		case PSCI_STAT_COUNT_AARCH32:
426cf0b1492SSoby Mathew 			return psci_stat_count(x1, x2);
427532ed618SSoby Mathew #endif
428d4c596beSRoberto Vargas 		case PSCI_MEM_PROTECT:
429d4c596beSRoberto Vargas 			return psci_mem_protect(x1);
430d4c596beSRoberto Vargas 
431d4c596beSRoberto Vargas 		case PSCI_MEM_CHK_RANGE_AARCH32:
432d4c596beSRoberto Vargas 			return psci_mem_chk_range(x1, x2);
433532ed618SSoby Mathew 
43436a8f8fdSRoberto Vargas 		case PSCI_SYSTEM_RESET2_AARCH32:
43536a8f8fdSRoberto Vargas 			/* We should never return from psci_system_reset2() */
43636a8f8fdSRoberto Vargas 			return psci_system_reset2(x1, x2);
43736a8f8fdSRoberto Vargas 
438532ed618SSoby Mathew 		default:
439532ed618SSoby Mathew 			break;
440532ed618SSoby Mathew 		}
441532ed618SSoby Mathew 	} else {
442532ed618SSoby Mathew 		/* 64-bit PSCI function */
443532ed618SSoby Mathew 
444532ed618SSoby Mathew 		switch (smc_fid) {
445532ed618SSoby Mathew 		case PSCI_CPU_SUSPEND_AARCH64:
446cf0b1492SSoby Mathew 			return psci_cpu_suspend(x1, x2, x3);
447532ed618SSoby Mathew 
448532ed618SSoby Mathew 		case PSCI_CPU_ON_AARCH64:
449cf0b1492SSoby Mathew 			return psci_cpu_on(x1, x2, x3);
450532ed618SSoby Mathew 
451532ed618SSoby Mathew 		case PSCI_AFFINITY_INFO_AARCH64:
452cf0b1492SSoby Mathew 			return psci_affinity_info(x1, x2);
453532ed618SSoby Mathew 
454532ed618SSoby Mathew 		case PSCI_MIG_AARCH64:
455cf0b1492SSoby Mathew 			return psci_migrate(x1);
456532ed618SSoby Mathew 
457532ed618SSoby Mathew 		case PSCI_MIG_INFO_UP_CPU_AARCH64:
458cf0b1492SSoby Mathew 			return psci_migrate_info_up_cpu();
459532ed618SSoby Mathew 
46028d3d614SJeenu Viswambharan 		case PSCI_NODE_HW_STATE_AARCH64:
46128d3d614SJeenu Viswambharan 			return psci_node_hw_state(x1, x2);
46228d3d614SJeenu Viswambharan 
463532ed618SSoby Mathew 		case PSCI_SYSTEM_SUSPEND_AARCH64:
464cf0b1492SSoby Mathew 			return psci_system_suspend(x1, x2);
465532ed618SSoby Mathew 
466532ed618SSoby Mathew #if ENABLE_PSCI_STAT
467532ed618SSoby Mathew 		case PSCI_STAT_RESIDENCY_AARCH64:
468cf0b1492SSoby Mathew 			return psci_stat_residency(x1, x2);
469532ed618SSoby Mathew 
470532ed618SSoby Mathew 		case PSCI_STAT_COUNT_AARCH64:
471cf0b1492SSoby Mathew 			return psci_stat_count(x1, x2);
472532ed618SSoby Mathew #endif
473532ed618SSoby Mathew 
474d4c596beSRoberto Vargas 		case PSCI_MEM_CHK_RANGE_AARCH64:
475d4c596beSRoberto Vargas 			return psci_mem_chk_range(x1, x2);
476d4c596beSRoberto Vargas 
47736a8f8fdSRoberto Vargas 		case PSCI_SYSTEM_RESET2_AARCH64:
47836a8f8fdSRoberto Vargas 			/* We should never return from psci_system_reset2() */
47936a8f8fdSRoberto Vargas 			return psci_system_reset2(x1, x2);
480d4c596beSRoberto Vargas 
481532ed618SSoby Mathew 		default:
482532ed618SSoby Mathew 			break;
483532ed618SSoby Mathew 		}
484532ed618SSoby Mathew 	}
485532ed618SSoby Mathew 
486532ed618SSoby Mathew 	WARN("Unimplemented PSCI Call: 0x%x \n", smc_fid);
487cf0b1492SSoby Mathew 	return SMC_UNK;
488532ed618SSoby Mathew }
489