blob: f7def4a117e3d34efb93c82b1b3fd362df8fdaf8 [file] [log] [blame]
Anson Huangbaa76502018-06-11 12:54:05 +08001/*
2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <cci.h>
10#include <debug.h>
11#include <gicv3.h>
12#include <mmio.h>
13#include <plat_imx8.h>
14#include <psci.h>
15#include <sci/sci.h>
16#include <stdbool.h>
17
18const static int ap_core_index[PLATFORM_CORE_COUNT] = {
19 SC_R_A53_0, SC_R_A53_1, SC_R_A53_2,
20 SC_R_A53_3, SC_R_A72_0, SC_R_A72_1,
21};
22
23/* need to enable USE_COHERENT_MEM to avoid coherence issue */
24#if USE_COHERENT_MEM
25static unsigned int a53_cpu_on_number __section("tzfw_coherent_mem");
26static unsigned int a72_cpu_on_number __section("tzfw_coherent_mem");
27#endif
28
29int imx_pwr_domain_on(u_register_t mpidr)
30{
31 int ret = PSCI_E_SUCCESS;
32 unsigned int cluster_id, cpu_id;
33
34 cluster_id = MPIDR_AFFLVL1_VAL(mpidr);
35 cpu_id = MPIDR_AFFLVL0_VAL(mpidr);
36
37 tf_printf("imx_pwr_domain_on cluster_id %d, cpu_id %d\n", cluster_id, cpu_id);
38
39 if (cluster_id == 0) {
40 if (a53_cpu_on_number == 0)
41 sc_pm_set_resource_power_mode(ipc_handle, SC_R_A53, SC_PM_PW_MODE_ON);
42
43 if (sc_pm_set_resource_power_mode(ipc_handle, ap_core_index[cpu_id],
44 SC_PM_PW_MODE_ON) != SC_ERR_NONE) {
45 ERROR("cluster0 core %d power on failed!\n", cpu_id);
46 ret = PSCI_E_INTERN_FAIL;
47 }
48
49 if (sc_pm_cpu_start(ipc_handle, ap_core_index[cpu_id],
50 true, BL31_BASE) != SC_ERR_NONE) {
51 ERROR("boot cluster0 core %d failed!\n", cpu_id);
52 ret = PSCI_E_INTERN_FAIL;
53 }
54 } else {
55 if (a72_cpu_on_number == 0)
56 sc_pm_set_resource_power_mode(ipc_handle, SC_R_A72, SC_PM_PW_MODE_ON);
57
58 if (sc_pm_set_resource_power_mode(ipc_handle, ap_core_index[cpu_id + 4],
59 SC_PM_PW_MODE_ON) != SC_ERR_NONE) {
60 ERROR(" cluster1 core %d power on failed!\n", cpu_id);
61 ret = PSCI_E_INTERN_FAIL;
62 }
63
64 if (sc_pm_cpu_start(ipc_handle, ap_core_index[cpu_id + 4],
65 true, BL31_BASE) != SC_ERR_NONE) {
66 ERROR("boot cluster1 core %d failed!\n", cpu_id);
67 ret = PSCI_E_INTERN_FAIL;
68 }
69 }
70
71 return ret;
72}
73
74void imx_pwr_domain_on_finish(const psci_power_state_t *target_state)
75{
76 uint64_t mpidr = read_mpidr_el1();
77 unsigned int cluster_id = MPIDR_AFFLVL1_VAL(mpidr);
78
79 if (cluster_id == 0 && a53_cpu_on_number++ == 0)
80 cci_enable_snoop_dvm_reqs(0);
81 if (cluster_id == 1 && a72_cpu_on_number++ == 0)
82 cci_enable_snoop_dvm_reqs(1);
83
84 plat_gic_pcpu_init();
85 plat_gic_cpuif_enable();
86}
87
Anson Huang0f53bca2018-07-12 14:30:52 +080088void imx_pwr_domain_off(const psci_power_state_t *target_state)
89{
90 u_register_t mpidr = read_mpidr_el1();
91 unsigned int cluster_id = MPIDR_AFFLVL1_VAL(mpidr);
92 unsigned int cpu_id = MPIDR_AFFLVL0_VAL(mpidr);
93
94 plat_gic_cpuif_disable();
95 if (cluster_id == 0) {
96 sc_pm_req_cpu_low_power_mode(ipc_handle, ap_core_index[cpu_id],
97 SC_PM_PW_MODE_OFF, SC_PM_WAKE_SRC_NONE);
98 if (--a53_cpu_on_number == 0)
99 cci_disable_snoop_dvm_reqs(0);
100 } else {
101 sc_pm_req_cpu_low_power_mode(ipc_handle,
102 ap_core_index[cpu_id + 4],
103 SC_PM_PW_MODE_OFF,
104 SC_PM_WAKE_SRC_NONE);
105 if (--a72_cpu_on_number == 0)
106 cci_disable_snoop_dvm_reqs(1);
107 }
108 tf_printf("turn off cluster:%d core:%d\n", cluster_id, cpu_id);
109}
110
Anson Huangbaa76502018-06-11 12:54:05 +0800111int imx_validate_ns_entrypoint(uintptr_t ns_entrypoint)
112{
113 return PSCI_E_SUCCESS;
114}
115
116static const plat_psci_ops_t imx_plat_psci_ops = {
117 .pwr_domain_on = imx_pwr_domain_on,
118 .pwr_domain_on_finish = imx_pwr_domain_on_finish,
Anson Huang0f53bca2018-07-12 14:30:52 +0800119 .pwr_domain_off = imx_pwr_domain_off,
Anson Huangbaa76502018-06-11 12:54:05 +0800120 .validate_ns_entrypoint = imx_validate_ns_entrypoint,
Anson Huangdb81c592018-07-12 14:26:07 +0800121 .system_off = imx_system_off,
Anson Huangd31ffcf2018-07-12 14:27:36 +0800122 .system_reset = imx_system_reset,
Anson Huangbaa76502018-06-11 12:54:05 +0800123};
124
125int plat_setup_psci_ops(uintptr_t sec_entrypoint,
126 const plat_psci_ops_t **psci_ops)
127{
128 uint64_t mpidr = read_mpidr_el1();
129 unsigned int cluster_id = MPIDR_AFFLVL1_VAL(mpidr);
130
131 imx_mailbox_init(sec_entrypoint);
132 *psci_ops = &imx_plat_psci_ops;
133
134 if (cluster_id == 0)
135 a53_cpu_on_number++;
136 else
137 a72_cpu_on_number++;
138
139 return 0;
140}