Angel Pons | 6bc1374 | 2020-04-05 15:46:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrey Petrov | 0f593c2 | 2016-06-17 15:30:13 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 3 | #include <cf9_reset.h> |
Andrey Petrov | 91ef21d | 2016-07-15 14:44:48 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 5 | #include <delay.h> |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 6 | #include <intelblocks/pmclib.h> |
| 7 | #include <soc/heci.h> |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 8 | #include <soc/intel/common/reset.h> |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 9 | #include <soc/pm.h> |
| 10 | #include <timer.h> |
| 11 | |
| 12 | #define CSE_WAIT_MAX_MS 1000 |
| 13 | |
| 14 | void do_global_reset(void) |
| 15 | { |
| 16 | pmc_global_reset_enable(1); |
| 17 | do_full_reset(); |
| 18 | } |
| 19 | |
| 20 | void 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 Barnes | d522f38 | 2022-09-12 06:31:47 -0600 | [diff] [blame] | 47 | printk(BIOS_SPEW, "CSE took %lld ms\n", stopwatch_duration_msecs(&sw)); |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 48 | } |