blob: b1aa8997695a0a9ce0f099632feec9c91637c5b7 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleyab2d31e2013-12-02 19:25:12 +00002 * Copyright (c) 2013, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
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 <stdio.h>
32#include <string.h>
33#include <assert.h>
34#include <arch_helpers.h>
35#include <console.h>
36#include <platform.h>
37#include <psci_private.h>
38
39/*******************************************************************************
40 * PSCI frontend api for servicing SMCs. Described in the PSCI spec.
41 ******************************************************************************/
42int psci_cpu_on(unsigned long target_cpu,
43 unsigned long entrypoint,
44 unsigned long context_id)
45
46{
47 int rc;
48 unsigned int start_afflvl, target_afflvl;
49
50 /* Determine if the cpu exists of not */
51 rc = psci_validate_mpidr(target_cpu, MPIDR_AFFLVL0);
52 if (rc != PSCI_E_SUCCESS) {
53 goto exit;
54 }
55
56 start_afflvl = get_max_afflvl();
57 target_afflvl = MPIDR_AFFLVL0;
58 rc = psci_afflvl_on(target_cpu,
59 entrypoint,
60 context_id,
61 start_afflvl,
62 target_afflvl);
63
64exit:
65 return rc;
66}
67
68unsigned int psci_version(void)
69{
70 return PSCI_MAJOR_VER | PSCI_MINOR_VER;
71}
72
73int psci_cpu_suspend(unsigned int power_state,
74 unsigned long entrypoint,
75 unsigned long context_id)
76{
77 int rc;
78 unsigned long mpidr;
79 unsigned int tgt_afflvl, pstate_type;
80
81 /* TODO: Standby states are not supported at the moment */
82 pstate_type = psci_get_pstate_type(power_state);
83 if (pstate_type == 0) {
84 rc = PSCI_E_INVALID_PARAMS;
85 goto exit;
86 }
87
88 /* Sanity check the requested state */
89 tgt_afflvl = psci_get_pstate_afflvl(power_state);
90 if (tgt_afflvl > MPIDR_MAX_AFFLVL) {
91 rc = PSCI_E_INVALID_PARAMS;
92 goto exit;
93 }
94
95 mpidr = read_mpidr();
96 rc = psci_afflvl_suspend(mpidr,
97 entrypoint,
98 context_id,
99 power_state,
100 tgt_afflvl,
101 MPIDR_AFFLVL0);
102
103exit:
104 if (rc != PSCI_E_SUCCESS)
105 assert(rc == PSCI_E_INVALID_PARAMS);
106 return rc;
107}
108
109int psci_cpu_off(void)
110{
111 int rc;
112 unsigned long mpidr;
113 int target_afflvl = get_max_afflvl();
114
115 mpidr = read_mpidr();
116
117 /*
118 * Traverse from the highest to the lowest affinity level. When the
119 * lowest affinity level is hit, all the locks are acquired. State
120 * management is done immediately followed by cpu, cluster ...
121 * ..target_afflvl specific actions as this function unwinds back.
122 */
123 rc = psci_afflvl_off(mpidr, target_afflvl, MPIDR_AFFLVL0);
124
125 if (rc != PSCI_E_SUCCESS) {
126 assert(rc == PSCI_E_DENIED);
127 }
128
129 return rc;
130}
131
132int psci_affinity_info(unsigned long target_affinity,
133 unsigned int lowest_affinity_level)
134{
135 int rc = PSCI_E_INVALID_PARAMS;
136 unsigned int aff_state;
137 aff_map_node *node;
138
139 if (lowest_affinity_level > get_max_afflvl()) {
140 goto exit;
141 }
142
143 node = psci_get_aff_map_node(target_affinity, lowest_affinity_level);
144 if (node && (node->state & PSCI_AFF_PRESENT)) {
145 aff_state = psci_get_state(node->state);
146
147 /* A suspended cpu is available & on for the OS */
148 if (aff_state == PSCI_STATE_SUSPEND) {
149 aff_state = PSCI_STATE_ON;
150 }
151
152 rc = aff_state;
153 }
154exit:
155 return rc;
156}
157
158/* Unimplemented */
159int psci_migrate(unsigned int target_cpu)
160{
161 return PSCI_E_NOT_SUPPORTED;
162}
163
164/* Unimplemented */
165unsigned int psci_migrate_info_type(void)
166{
167 return PSCI_TOS_NOT_PRESENT;
168}
169
170unsigned long psci_migrate_info_up_cpu(void)
171{
172 /*
173 * Return value of this currently unsupported call depends upon
174 * what psci_migrate_info_type() returns.
175 */
176 return PSCI_E_SUCCESS;
177}
178
179/* Unimplemented */
180void psci_system_off(void)
181{
182 assert(0);
183}
184
185/* Unimplemented */
186void psci_system_reset(void)
187{
188 assert(0);
189}
190