blob: 25b5bdef6cd27c9b22cd8ce941e5b2a290fffb83 [file] [log] [blame]
Angel Pons6bc13742020-04-05 15:46:38 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Andrey Petrov0f593c22016-06-17 15:30:13 -07002
Furquan Shaikhb13bd1e2020-09-21 22:44:27 +00003#include <cf9_reset.h>
Andrey Petrov91ef21d2016-07-15 14:44:48 -07004#include <console/console.h>
Furquan Shaikhb13bd1e2020-09-21 22:44:27 +00005#include <delay.h>
Furquan Shaikhb13bd1e2020-09-21 22:44:27 +00006#include <intelblocks/pmclib.h>
7#include <soc/heci.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02008#include <soc/intel/common/reset.h>
Furquan Shaikhb13bd1e2020-09-21 22:44:27 +00009#include <soc/pm.h>
10#include <timer.h>
11
12#define CSE_WAIT_MAX_MS 1000
13
14void do_global_reset(void)
15{
16 pmc_global_reset_enable(1);
17 do_full_reset();
18}
19
20void cf9_reset_prepare(void)
21{
22 struct stopwatch sw;
23
24 /*
25 * If CSE state is something else than 'normal', it is probably in some
26 * recovery state. In this case there is no point in waiting for it to
27 * get ready so we cross fingers and reset.
28 */
29 if (!heci_cse_normal()) {
30 printk(BIOS_DEBUG, "CSE is not in normal state, resetting\n");
31 return;
32 }
33
34 /* Reset if CSE is ready */
35 if (heci_cse_done())
36 return;
37
38 printk(BIOS_SPEW, "CSE is not yet ready, waiting\n");
39 stopwatch_init_msecs_expire(&sw, CSE_WAIT_MAX_MS);
40 while (!heci_cse_done()) {
41 if (stopwatch_expired(&sw)) {
42 printk(BIOS_SPEW, "CSE timed out. Resetting\n");
43 return;
44 }
45 mdelay(1);
46 }
Rob Barnesd522f382022-09-12 06:31:47 -060047 printk(BIOS_SPEW, "CSE took %lld ms\n", stopwatch_duration_msecs(&sw));
Furquan Shaikhb13bd1e2020-09-21 22:44:27 +000048}