blob: 67c2b7398b2a8ef9286179df729b47ca0dfc1dae [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch_helpers.h>
32#include <assert.h>
33#include <errno.h>
34#include <psci.h>
35
36
37/*******************************************************************************
38 * ARM standard platform utility function which is used to determine if any
39 * platform actions should be performed for the specified affinity instance
40 * given its state. Nothing needs to be done if the 'state' is not off or if
41 * this is not the highest affinity level which will enter the 'state'.
42 ******************************************************************************/
43int32_t arm_do_affinst_actions(unsigned int afflvl, unsigned int state)
44{
45 unsigned int max_phys_off_afflvl;
46
47 assert(afflvl <= MPIDR_AFFLVL1);
48
49 if (state != PSCI_STATE_OFF)
50 return -EAGAIN;
51
52 /*
53 * Find the highest affinity level which will be suspended and postpone
54 * all the platform specific actions until that level is hit.
55 */
56 max_phys_off_afflvl = psci_get_max_phys_off_afflvl();
57 assert(max_phys_off_afflvl != PSCI_INVALID_DATA);
58 if (afflvl != max_phys_off_afflvl)
59 return -EAGAIN;
60
61 return 0;
62}
63
64/*******************************************************************************
65 * ARM standard platform handler called to check the validity of the power state
66 * parameter.
67 ******************************************************************************/
68int arm_validate_power_state(unsigned int power_state)
69{
70 /* Sanity check the requested state */
71 if (psci_get_pstate_type(power_state) == PSTATE_TYPE_STANDBY) {
72 /*
73 * It's possible to enter standby only on affinity level 0
74 * (i.e. a CPU on ARM standard platforms).
75 * Ignore any other affinity level.
76 */
77 if (psci_get_pstate_afflvl(power_state) != MPIDR_AFFLVL0)
78 return PSCI_E_INVALID_PARAMS;
79 }
80
81 /*
82 * We expect the 'state id' to be zero.
83 */
84 if (psci_get_pstate_id(power_state))
85 return PSCI_E_INVALID_PARAMS;
86
87 return PSCI_E_SUCCESS;
88}