blob: 20d1ae6229d3f75bc633f3737e0b8d9a804bd84b [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>
9#include <debug.h>
10#include <k3_gicv3.h>
11#include <psci.h>
Andrew F. Davis60541b12018-05-24 11:15:42 -050012#include <platform.h>
Benjamin Faira42b61b2016-10-14 01:13:46 +000013#include <stdbool.h>
14
Andrew F. Davis60541b12018-05-24 11:15:42 -050015#include <ti_sci.h>
16
Benjamin Faira42b61b2016-10-14 01:13:46 +000017#define STUB() ERROR("stub %s called\n", __func__)
18
19uintptr_t k3_sec_entrypoint;
20
21static void k3_cpu_standby(plat_local_state_t cpu_state)
22{
Andrew F. Davisae40e692018-06-25 12:36:25 -050023 unsigned int scr;
24
25 scr = read_scr_el3();
26 /* Enable the Non secure interrupt to wake the CPU */
27 write_scr_el3(scr | SCR_IRQ_BIT | SCR_FIQ_BIT);
28 isb();
29 /* dsb is good practice before using wfi to enter low power states */
Benjamin Faira42b61b2016-10-14 01:13:46 +000030 dsb();
Andrew F. Davisae40e692018-06-25 12:36:25 -050031 /* Enter standby state */
Benjamin Faira42b61b2016-10-14 01:13:46 +000032 wfi();
Andrew F. Davisae40e692018-06-25 12:36:25 -050033 /* Restore SCR */
34 write_scr_el3(scr);
Benjamin Faira42b61b2016-10-14 01:13:46 +000035}
36
37static int k3_pwr_domain_on(u_register_t mpidr)
38{
Andrew F. Davis60541b12018-05-24 11:15:42 -050039 int core_id, proc, device, ret;
40
41 core_id = plat_core_pos_by_mpidr(mpidr);
42 if (core_id < 0) {
43 ERROR("Could not get target core id: %d\n", core_id);
44 return PSCI_E_INTERN_FAIL;
45 }
46
47 proc = PLAT_PROC_START_ID + core_id;
48 device = PLAT_PROC_DEVICE_START_ID + core_id;
49
50 ret = ti_sci_proc_request(proc);
51 if (ret) {
52 ERROR("Request for processor failed: %d\n", ret);
53 return PSCI_E_INTERN_FAIL;
54 }
55
56 ret = ti_sci_proc_set_boot_cfg(proc, k3_sec_entrypoint, 0, 0);
57 if (ret) {
58 ERROR("Request to set core boot address failed: %d\n", ret);
59 return PSCI_E_INTERN_FAIL;
60 }
61
62 ret = ti_sci_device_get(device);
63 if (ret) {
64 ERROR("Request to start core failed: %d\n", ret);
65 return PSCI_E_INTERN_FAIL;
66 }
Benjamin Faira42b61b2016-10-14 01:13:46 +000067
Andrew F. Davis60541b12018-05-24 11:15:42 -050068 ret = ti_sci_proc_release(proc);
69 if (ret) {
70 /* this is not fatal */
71 WARN("Could not release processor control: %d\n", ret);
72 }
Benjamin Faira42b61b2016-10-14 01:13:46 +000073
74 return PSCI_E_SUCCESS;
75}
76
77void k3_pwr_domain_off(const psci_power_state_t *target_state)
78{
79 /* Prevent interrupts from spuriously waking up this cpu */
80 k3_gic_cpuif_disable();
81
82 /* TODO: Indicate to System firmware about powering down */
83}
84
85void k3_pwr_domain_on_finish(const psci_power_state_t *target_state)
86{
87 /* TODO: Indicate to System firmware about completion */
88
89 k3_gic_pcpu_init();
90 k3_gic_cpuif_enable();
91}
92
93static void __dead2 k3_system_reset(void)
94{
95 /* TODO: Indicate to System firmware about system reset */
96 STUB();
97
98 while (true)
99 wfi();
100}
101
102static int k3_validate_power_state(unsigned int power_state,
103 psci_power_state_t *req_state)
104{
105 /* TODO: perform the proper validation */
106
107 return PSCI_E_SUCCESS;
108}
109
110static int k3_validate_ns_entrypoint(uintptr_t entrypoint)
111{
112 /* TODO: perform the proper validation */
113
114 return PSCI_E_SUCCESS;
115}
116
117static const plat_psci_ops_t k3_plat_psci_ops = {
118 .cpu_standby = k3_cpu_standby,
119 .pwr_domain_on = k3_pwr_domain_on,
120 .pwr_domain_off = k3_pwr_domain_off,
121 .pwr_domain_on_finish = k3_pwr_domain_on_finish,
122 .system_reset = k3_system_reset,
123 .validate_power_state = k3_validate_power_state,
124 .validate_ns_entrypoint = k3_validate_ns_entrypoint
125};
126
127int plat_setup_psci_ops(uintptr_t sec_entrypoint,
128 const plat_psci_ops_t **psci_ops)
129{
130 k3_sec_entrypoint = sec_entrypoint;
131
132 *psci_ops = &k3_plat_psci_ops;
133
134 return 0;
135}