2 * Copyright (C) 2016 Freescale Semiconductor, Inc.
5 * Peng Fan <peng.fan@nxp.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
31 #include <kernel/generic_boot.h>
32 #include <kernel/thread.h>
34 #include <sm/optee_smc.h>
39 __weak uint32_t psci_version(void)
41 return PSCI_VERSION_0_2;
44 __weak int psci_cpu_suspend(uint32_t power_state __unused,
45 uintptr_t entry __unused,
46 uint32_t context_id __unused)
48 return PSCI_RET_NOT_SUPPORTED;
51 __weak int psci_cpu_off(void)
53 return PSCI_RET_NOT_SUPPORTED;
56 __weak int psci_cpu_on(uint32_t cpu_id __unused, uint32_t entry __unused,
57 uint32_t context_id __unused)
59 return PSCI_RET_NOT_SUPPORTED;
62 __weak int psci_affinity_info(uint32_t affinity __unused,
63 uint32_t lowest_affnity_level __unused)
65 return PSCI_RET_NOT_SUPPORTED;
68 __weak int psci_migrate(uint32_t cpu_id __unused)
70 return PSCI_RET_NOT_SUPPORTED;
73 __weak int psci_migrate_info_type(void)
75 return PSCI_RET_NOT_SUPPORTED;
78 __weak int psci_migrate_info_up_cpu(void)
80 return PSCI_RET_NOT_SUPPORTED;
83 __weak void psci_system_off(void)
87 __weak void psci_system_reset(void)
91 __weak int psci_features(uint32_t psci_fid __unused)
93 return PSCI_RET_NOT_SUPPORTED;
96 __weak int psci_node_hw_state(uint32_t cpu_id __unused,
97 uint32_t power_level __unused)
99 return PSCI_RET_NOT_SUPPORTED;
102 __weak int psci_stat_residency(uint32_t cpu_id __unused,
103 uint32_t power_state __unused)
105 return PSCI_RET_NOT_SUPPORTED;
108 __weak int psci_stat_count(uint32_t cpu_id __unused,
109 uint32_t power_state __unused)
111 return PSCI_RET_NOT_SUPPORTED;
114 void tee_psci_handler(struct thread_smc_args *args)
116 uint32_t smc_fid = args->a0;
117 uint32_t a1 = args->a1;
118 uint32_t a2 = args->a2;
119 uint32_t a3 = args->a3;
123 args->a0 = psci_version();
125 case PSCI_CPU_SUSPEND:
126 args->a0 = psci_cpu_suspend(a1, a2, a3);
129 args->a0 = psci_cpu_off();
132 args->a0 = psci_cpu_on(a1, a2, a3);
134 case PSCI_AFFINITY_INFO:
135 args->a0 = psci_affinity_info(a1, a2);
138 args->a0 = psci_migrate(a1);
140 case PSCI_MIGRATE_INFO_TYPE:
141 args->a0 = psci_migrate_info_type();
143 case PSCI_MIGRATE_INFO_UP_CPU:
144 args->a0 = psci_migrate_info_up_cpu();
146 case PSCI_SYSTEM_OFF:
151 case PSCI_SYSTEM_RESET:
156 case PSCI_PSCI_FEATURES:
157 args->a0 = psci_features(a1);
159 case PSCI_NODE_HW_STATE:
160 args->a0 = psci_node_hw_state(a1, a2);
163 args->a0 = OPTEE_SMC_RETURN_UNKNOWN_FUNCTION;