blob: 787cc82fda535a561fa1a056858039374936489a [file] [log] [blame]
Benjamin Faira42b61b2016-10-14 01:13:46 +00001/*
2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
Andrew F. Davis7c461d72018-10-12 15:37:04 -05009#include <cpu_data.h>
Benjamin Faira42b61b2016-10-14 01:13:46 +000010#include <debug.h>
11#include <k3_gicv3.h>
12#include <psci.h>
Andrew F. Davis7c461d72018-10-12 15:37:04 -050013/* Need to flush psci internal locks before shutdown or their values are lost */
14#include <../../lib/psci/psci_private.h>
Andrew F. Davis60541b12018-05-24 11:15:42 -050015#include <platform.h>
Benjamin Faira42b61b2016-10-14 01:13:46 +000016#include <stdbool.h>
17
Andrew F. Davis60541b12018-05-24 11:15:42 -050018#include <ti_sci.h>
19
Benjamin Faira42b61b2016-10-14 01:13:46 +000020#define STUB() ERROR("stub %s called\n", __func__)
21
22uintptr_t k3_sec_entrypoint;
23
24static void k3_cpu_standby(plat_local_state_t cpu_state)
25{
Andrew F. Davisae40e692018-06-25 12:36:25 -050026 unsigned int scr;
27
28 scr = read_scr_el3();
29 /* Enable the Non secure interrupt to wake the CPU */
30 write_scr_el3(scr | SCR_IRQ_BIT | SCR_FIQ_BIT);
31 isb();
32 /* dsb is good practice before using wfi to enter low power states */
Benjamin Faira42b61b2016-10-14 01:13:46 +000033 dsb();
Andrew F. Davisae40e692018-06-25 12:36:25 -050034 /* Enter standby state */
Benjamin Faira42b61b2016-10-14 01:13:46 +000035 wfi();
Andrew F. Davisae40e692018-06-25 12:36:25 -050036 /* Restore SCR */
37 write_scr_el3(scr);
Benjamin Faira42b61b2016-10-14 01:13:46 +000038}
39
40static int k3_pwr_domain_on(u_register_t mpidr)
41{
Andrew F. Davis60541b12018-05-24 11:15:42 -050042 int core_id, proc, device, ret;
43
44 core_id = plat_core_pos_by_mpidr(mpidr);
45 if (core_id < 0) {
46 ERROR("Could not get target core id: %d\n", core_id);
47 return PSCI_E_INTERN_FAIL;
48 }
49
50 proc = PLAT_PROC_START_ID + core_id;
51 device = PLAT_PROC_DEVICE_START_ID + core_id;
52
53 ret = ti_sci_proc_request(proc);
54 if (ret) {
55 ERROR("Request for processor failed: %d\n", ret);
56 return PSCI_E_INTERN_FAIL;
57 }
58
59 ret = ti_sci_proc_set_boot_cfg(proc, k3_sec_entrypoint, 0, 0);
60 if (ret) {
61 ERROR("Request to set core boot address failed: %d\n", ret);
62 return PSCI_E_INTERN_FAIL;
63 }
64
65 ret = ti_sci_device_get(device);
66 if (ret) {
67 ERROR("Request to start core failed: %d\n", ret);
68 return PSCI_E_INTERN_FAIL;
69 }
Benjamin Faira42b61b2016-10-14 01:13:46 +000070
Andrew F. Davis60541b12018-05-24 11:15:42 -050071 ret = ti_sci_proc_release(proc);
72 if (ret) {
73 /* this is not fatal */
74 WARN("Could not release processor control: %d\n", ret);
75 }
Benjamin Faira42b61b2016-10-14 01:13:46 +000076
77 return PSCI_E_SUCCESS;
78}
79
80void k3_pwr_domain_off(const psci_power_state_t *target_state)
81{
Andrew F. Davis7804b272018-08-09 10:01:53 -050082 int core_id, device, ret;
83
Benjamin Faira42b61b2016-10-14 01:13:46 +000084 /* Prevent interrupts from spuriously waking up this cpu */
85 k3_gic_cpuif_disable();
86
Andrew F. Davis7804b272018-08-09 10:01:53 -050087 core_id = plat_my_core_pos();
88 device = PLAT_PROC_DEVICE_START_ID + core_id;
89
90 ret = ti_sci_device_put(device);
91 if (ret) {
92 ERROR("Request to stop core failed: %d\n", ret);
93 return;
94 }
Benjamin Faira42b61b2016-10-14 01:13:46 +000095}
96
97void k3_pwr_domain_on_finish(const psci_power_state_t *target_state)
98{
99 /* TODO: Indicate to System firmware about completion */
100
101 k3_gic_pcpu_init();
102 k3_gic_cpuif_enable();
103}
104
Andrew F. Davis7c461d72018-10-12 15:37:04 -0500105static void __dead2 k3_pwr_domain_pwr_down_wfi(const psci_power_state_t
106 *target_state)
107{
108 flush_cpu_data(psci_svc_cpu_data);
109 flush_dcache_range((uintptr_t) psci_locks, sizeof(psci_locks));
110 psci_power_down_wfi();
111}
112
Benjamin Faira42b61b2016-10-14 01:13:46 +0000113static void __dead2 k3_system_reset(void)
114{
Andrew F. Davis6a60d022018-05-24 11:15:42 -0500115 /* Send the system reset request to system firmware */
116 ti_sci_core_reboot();
Benjamin Faira42b61b2016-10-14 01:13:46 +0000117
118 while (true)
119 wfi();
120}
121
122static int k3_validate_power_state(unsigned int power_state,
123 psci_power_state_t *req_state)
124{
125 /* TODO: perform the proper validation */
126
127 return PSCI_E_SUCCESS;
128}
129
130static int k3_validate_ns_entrypoint(uintptr_t entrypoint)
131{
132 /* TODO: perform the proper validation */
133
134 return PSCI_E_SUCCESS;
135}
136
137static const plat_psci_ops_t k3_plat_psci_ops = {
138 .cpu_standby = k3_cpu_standby,
139 .pwr_domain_on = k3_pwr_domain_on,
140 .pwr_domain_off = k3_pwr_domain_off,
141 .pwr_domain_on_finish = k3_pwr_domain_on_finish,
Andrew F. Davis7c461d72018-10-12 15:37:04 -0500142 .pwr_domain_pwr_down_wfi = k3_pwr_domain_pwr_down_wfi,
Benjamin Faira42b61b2016-10-14 01:13:46 +0000143 .system_reset = k3_system_reset,
144 .validate_power_state = k3_validate_power_state,
145 .validate_ns_entrypoint = k3_validate_ns_entrypoint
146};
147
148int plat_setup_psci_ops(uintptr_t sec_entrypoint,
149 const plat_psci_ops_t **psci_ops)
150{
151 k3_sec_entrypoint = sec_entrypoint;
152
153 *psci_ops = &k3_plat_psci_ops;
154
155 return 0;
156}