blob: 4cd309e7e73813dcb132ba8f26a034e876bdf3cd [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Lee Leahy672df162016-07-24 18:21:13 -07002
Subrata Banik69107c12021-12-29 18:24:07 +00003#include <commonlib/helpers.h>
Lee Leahy672df162016-07-24 18:21:13 -07004#include <console/console.h>
Lee Leahy00a38a42016-08-09 09:04:45 -07005#include <console/streams.h>
Nico Huberd67edca2018-11-13 19:28:07 +01006#include <cpu/x86/mtrr.h>
Subrata Banik69107c12021-12-29 18:24:07 +00007#include <fsp/debug.h>
Lee Leahy672df162016-07-24 18:21:13 -07008#include <fsp/util.h>
9
Furquan Shaikhe07532f2021-04-10 14:26:15 -070010enum fsp_call_phase {
11 BEFORE_FSP_CALL,
12 AFTER_FSP_CALL,
13};
14
15static void fsp_gpio_config_check(enum fsp_call_phase phase, const char *call_str)
16{
17 switch (phase) {
18 case BEFORE_FSP_CALL:
19 printk(BIOS_SPEW, "Snapshot all GPIOs before %s.\n", call_str);
20 gpio_snapshot();
21 break;
22 case AFTER_FSP_CALL:
23 printk(BIOS_SPEW, "Verify GPIO snapshot after %s...", call_str);
24 printk(BIOS_SPEW, "%zd changes detected!\n", gpio_verify_snapshot());
25 break;
26 default:
27 break;
28 }
29}
30
Subrata Banik69107c12021-12-29 18:24:07 +000031enum fsp_log_level fsp_map_console_log_level(void)
32{
33 enum fsp_log_level fsp_debug_level;
34
35 switch (get_log_level()) {
36 case BIOS_EMERG:
37 case BIOS_ALERT:
38 case BIOS_CRIT:
39 case BIOS_ERR:
40 fsp_debug_level = FSP_LOG_LEVEL_ERR;
41 break;
42 case BIOS_WARNING:
43 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN;
44 break;
45 case BIOS_NOTICE:
46 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO;
47 break;
48 case BIOS_INFO:
49 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO_EVENT;
50 break;
51 case BIOS_DEBUG:
52 case BIOS_SPEW:
53 fsp_debug_level = FSP_LOG_LEVEL_VERBOSE;
54 break;
55 default:
56 fsp_debug_level = FSP_LOG_LEVEL_DISABLE;
57 break;
58 }
59
60 if (!CONFIG(DEBUG_RAM_SETUP))
Kane Chen5e8dd5d2022-02-15 09:29:22 +080061 fsp_debug_level = MIN(fsp_debug_level, FSP_LOG_LEVEL_ERR_WARN_INFO);
Subrata Banik69107c12021-12-29 18:24:07 +000062
63 return fsp_debug_level;
64}
65
Lee Leahy672df162016-07-24 18:21:13 -070066/*-----------
67 * MemoryInit
68 *-----------
69 */
70void fsp_debug_before_memory_init(fsp_memory_init_fn memory_init,
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070071 const FSPM_UPD *fspm_old_upd,
72 const FSPM_UPD *fspm_new_upd)
Lee Leahy672df162016-07-24 18:21:13 -070073{
Nico Huberd67edca2018-11-13 19:28:07 +010074 display_mtrrs();
Lee Leahy0a38b222016-07-24 08:26:06 -070075
Lee Leahye6f2f742016-07-21 09:48:49 -070076 /* Display the UPD values */
Julius Wernercd49cce2019-03-05 16:53:33 -080077 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahye6f2f742016-07-21 09:48:49 -070078 fspm_display_upd_values(fspm_old_upd, fspm_new_upd);
79
Elyes HAOUAS18958382018-08-07 12:23:16 +020080 /* Display the call entry point and parameters */
Julius Wernercd49cce2019-03-05 16:53:33 -080081 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -070082 return;
Julius Werner540a9802019-12-09 13:03:29 -080083 printk(BIOS_SPEW, "Calling FspMemoryInit: %p\n", memory_init);
84 printk(BIOS_SPEW, "\t%p: raminit_upd\n", fspm_new_upd);
85 printk(BIOS_SPEW, "\t%p: &hob_list_ptr\n", fsp_get_hob_list_ptr());
Lee Leahy672df162016-07-24 18:21:13 -070086}
87
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070088void fsp_debug_after_memory_init(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -070089{
Julius Wernercd49cce2019-03-05 16:53:33 -080090 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahyb20d4ba2016-07-31 16:49:28 -070091 printk(BIOS_SPEW, "FspMemoryInit returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -070092
Lee Leahy6359a752016-08-11 17:40:01 -070093 if (status != FSP_SUCCESS)
94 return;
95
Lee Leahy52d0c682016-08-01 15:47:42 -070096 /* Verify that the HOB list pointer was set */
97 if (fsp_get_hob_list() == NULL)
98 die("ERROR - HOB list pointer was not returned!\n");
99
100 /* Display and verify the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800101 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700102 fsp_display_hobs();
Julius Wernercd49cce2019-03-05 16:53:33 -0800103 if (CONFIG(VERIFY_HOBS))
Lee Leahy52d0c682016-08-01 15:47:42 -0700104 fsp_verify_memory_init_hobs();
Lee Leahyac3b0a62016-07-27 07:40:25 -0700105
Nico Huberd67edca2018-11-13 19:28:07 +0100106 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700107}
108
109/*-----------
110 * SiliconInit
111 *-----------
112 */
113void fsp_debug_before_silicon_init(fsp_silicon_init_fn silicon_init,
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700114 const FSPS_UPD *fsps_old_upd,
115 const FSPS_UPD *fsps_new_upd)
Lee Leahy672df162016-07-24 18:21:13 -0700116{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700117 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
118 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Silicon Init");
119
Nico Huberd67edca2018-11-13 19:28:07 +0100120 display_mtrrs();
Lee Leahy0a38b222016-07-24 08:26:06 -0700121
Lee Leahye6f2f742016-07-21 09:48:49 -0700122 /* Display the UPD values */
Julius Wernercd49cce2019-03-05 16:53:33 -0800123 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahye6f2f742016-07-21 09:48:49 -0700124 soc_display_fsps_upd_params(fsps_old_upd, fsps_new_upd);
125
Lee Leahy672df162016-07-24 18:21:13 -0700126 /* Display the call to FSP SiliconInit */
Julius Wernercd49cce2019-03-05 16:53:33 -0800127 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700128 return;
Julius Werner540a9802019-12-09 13:03:29 -0800129 printk(BIOS_SPEW, "Calling FspSiliconInit: %p\n", silicon_init);
130 printk(BIOS_SPEW, "\t%p: upd\n", fsps_new_upd);
Lee Leahy672df162016-07-24 18:21:13 -0700131}
132
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700133void fsp_debug_after_silicon_init(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -0700134{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700135 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
136 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Silicon Init");
137
Julius Wernercd49cce2019-03-05 16:53:33 -0800138 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700139 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -0700140
Lee Leahyac3b0a62016-07-27 07:40:25 -0700141 /* Display the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800142 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700143 fsp_display_hobs();
144
Nico Huberd67edca2018-11-13 19:28:07 +0100145 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700146}
147
148/*-----------
149 * FspNotify
150 *-----------
151 */
152void fsp_before_debug_notify(fsp_notify_fn notify,
153 const struct fsp_notify_params *notify_params)
154{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700155 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
156 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Notify");
157
Lee Leahy0a38b222016-07-24 08:26:06 -0700158 /* Display the call to FspNotify */
Julius Wernercd49cce2019-03-05 16:53:33 -0800159 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700160 return;
161 printk(BIOS_SPEW, "0x%08x: notify_params->phase\n",
162 notify_params->phase);
Julius Werner540a9802019-12-09 13:03:29 -0800163 printk(BIOS_SPEW, "Calling FspNotify: %p\n", notify);
164 printk(BIOS_SPEW, "\t%p: notify_params\n", notify_params);
Lee Leahy672df162016-07-24 18:21:13 -0700165}
166
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700167void fsp_debug_after_notify(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -0700168{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700169 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
170 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Notify");
171
Julius Wernercd49cce2019-03-05 16:53:33 -0800172 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700173 printk(BIOS_SPEW, "FspNotify returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -0700174
Lee Leahyac3b0a62016-07-27 07:40:25 -0700175 /* Display the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800176 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700177 fsp_display_hobs();
178
Nico Huberd67edca2018-11-13 19:28:07 +0100179 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700180}