blob: 8c0d67daeb38e8992b1672a1f1b2907c50d1027e [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
Lee Leahy00a38a42016-08-09 09:04:45 -070010asmlinkage size_t fsp_write_line(uint8_t *buffer, size_t number_of_bytes)
11{
12 console_write_line(buffer, number_of_bytes);
13 return number_of_bytes;
14}
15
Furquan Shaikhe07532f2021-04-10 14:26:15 -070016enum fsp_call_phase {
17 BEFORE_FSP_CALL,
18 AFTER_FSP_CALL,
19};
20
21static void fsp_gpio_config_check(enum fsp_call_phase phase, const char *call_str)
22{
23 switch (phase) {
24 case BEFORE_FSP_CALL:
25 printk(BIOS_SPEW, "Snapshot all GPIOs before %s.\n", call_str);
26 gpio_snapshot();
27 break;
28 case AFTER_FSP_CALL:
29 printk(BIOS_SPEW, "Verify GPIO snapshot after %s...", call_str);
30 printk(BIOS_SPEW, "%zd changes detected!\n", gpio_verify_snapshot());
31 break;
32 default:
33 break;
34 }
35}
36
Subrata Banik69107c12021-12-29 18:24:07 +000037enum fsp_log_level fsp_map_console_log_level(void)
38{
39 enum fsp_log_level fsp_debug_level;
40
41 switch (get_log_level()) {
42 case BIOS_EMERG:
43 case BIOS_ALERT:
44 case BIOS_CRIT:
45 case BIOS_ERR:
46 fsp_debug_level = FSP_LOG_LEVEL_ERR;
47 break;
48 case BIOS_WARNING:
49 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN;
50 break;
51 case BIOS_NOTICE:
52 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO;
53 break;
54 case BIOS_INFO:
55 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO_EVENT;
56 break;
57 case BIOS_DEBUG:
58 case BIOS_SPEW:
59 fsp_debug_level = FSP_LOG_LEVEL_VERBOSE;
60 break;
61 default:
62 fsp_debug_level = FSP_LOG_LEVEL_DISABLE;
63 break;
64 }
65
66 if (!CONFIG(DEBUG_RAM_SETUP))
Kane Chen5e8dd5d2022-02-15 09:29:22 +080067 fsp_debug_level = MIN(fsp_debug_level, FSP_LOG_LEVEL_ERR_WARN_INFO);
Subrata Banik69107c12021-12-29 18:24:07 +000068
69 return fsp_debug_level;
70}
71
Lee Leahy672df162016-07-24 18:21:13 -070072/*-----------
73 * MemoryInit
74 *-----------
75 */
76void fsp_debug_before_memory_init(fsp_memory_init_fn memory_init,
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070077 const FSPM_UPD *fspm_old_upd,
78 const FSPM_UPD *fspm_new_upd)
Lee Leahy672df162016-07-24 18:21:13 -070079{
Nico Huberd67edca2018-11-13 19:28:07 +010080 display_mtrrs();
Lee Leahy0a38b222016-07-24 08:26:06 -070081
Lee Leahye6f2f742016-07-21 09:48:49 -070082 /* Display the UPD values */
Julius Wernercd49cce2019-03-05 16:53:33 -080083 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahye6f2f742016-07-21 09:48:49 -070084 fspm_display_upd_values(fspm_old_upd, fspm_new_upd);
85
Elyes HAOUAS18958382018-08-07 12:23:16 +020086 /* Display the call entry point and parameters */
Julius Wernercd49cce2019-03-05 16:53:33 -080087 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -070088 return;
Julius Werner540a9802019-12-09 13:03:29 -080089 printk(BIOS_SPEW, "Calling FspMemoryInit: %p\n", memory_init);
90 printk(BIOS_SPEW, "\t%p: raminit_upd\n", fspm_new_upd);
91 printk(BIOS_SPEW, "\t%p: &hob_list_ptr\n", fsp_get_hob_list_ptr());
Lee Leahy672df162016-07-24 18:21:13 -070092}
93
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070094void fsp_debug_after_memory_init(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -070095{
Julius Wernercd49cce2019-03-05 16:53:33 -080096 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahyb20d4ba2016-07-31 16:49:28 -070097 printk(BIOS_SPEW, "FspMemoryInit returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -070098
Lee Leahy6359a752016-08-11 17:40:01 -070099 if (status != FSP_SUCCESS)
100 return;
101
Lee Leahy52d0c682016-08-01 15:47:42 -0700102 /* Verify that the HOB list pointer was set */
103 if (fsp_get_hob_list() == NULL)
104 die("ERROR - HOB list pointer was not returned!\n");
105
106 /* Display and verify the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800107 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700108 fsp_display_hobs();
Julius Wernercd49cce2019-03-05 16:53:33 -0800109 if (CONFIG(VERIFY_HOBS))
Lee Leahy52d0c682016-08-01 15:47:42 -0700110 fsp_verify_memory_init_hobs();
Lee Leahyac3b0a62016-07-27 07:40:25 -0700111
Nico Huberd67edca2018-11-13 19:28:07 +0100112 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700113}
114
115/*-----------
116 * SiliconInit
117 *-----------
118 */
119void fsp_debug_before_silicon_init(fsp_silicon_init_fn silicon_init,
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700120 const FSPS_UPD *fsps_old_upd,
121 const FSPS_UPD *fsps_new_upd)
Lee Leahy672df162016-07-24 18:21:13 -0700122{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700123 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
124 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Silicon Init");
125
Nico Huberd67edca2018-11-13 19:28:07 +0100126 display_mtrrs();
Lee Leahy0a38b222016-07-24 08:26:06 -0700127
Lee Leahye6f2f742016-07-21 09:48:49 -0700128 /* Display the UPD values */
Julius Wernercd49cce2019-03-05 16:53:33 -0800129 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahye6f2f742016-07-21 09:48:49 -0700130 soc_display_fsps_upd_params(fsps_old_upd, fsps_new_upd);
131
Lee Leahy672df162016-07-24 18:21:13 -0700132 /* Display the call to FSP SiliconInit */
Julius Wernercd49cce2019-03-05 16:53:33 -0800133 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700134 return;
Julius Werner540a9802019-12-09 13:03:29 -0800135 printk(BIOS_SPEW, "Calling FspSiliconInit: %p\n", silicon_init);
136 printk(BIOS_SPEW, "\t%p: upd\n", fsps_new_upd);
Lee Leahy672df162016-07-24 18:21:13 -0700137}
138
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700139void fsp_debug_after_silicon_init(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -0700140{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700141 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
142 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Silicon Init");
143
Julius Wernercd49cce2019-03-05 16:53:33 -0800144 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700145 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -0700146
Lee Leahyac3b0a62016-07-27 07:40:25 -0700147 /* Display the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800148 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700149 fsp_display_hobs();
150
Nico Huberd67edca2018-11-13 19:28:07 +0100151 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700152}
153
154/*-----------
155 * FspNotify
156 *-----------
157 */
158void fsp_before_debug_notify(fsp_notify_fn notify,
159 const struct fsp_notify_params *notify_params)
160{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700161 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
162 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Notify");
163
Lee Leahy0a38b222016-07-24 08:26:06 -0700164 /* Display the call to FspNotify */
Julius Wernercd49cce2019-03-05 16:53:33 -0800165 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700166 return;
167 printk(BIOS_SPEW, "0x%08x: notify_params->phase\n",
168 notify_params->phase);
Julius Werner540a9802019-12-09 13:03:29 -0800169 printk(BIOS_SPEW, "Calling FspNotify: %p\n", notify);
170 printk(BIOS_SPEW, "\t%p: notify_params\n", notify_params);
Lee Leahy672df162016-07-24 18:21:13 -0700171}
172
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700173void fsp_debug_after_notify(uint32_t status)
Lee Leahy672df162016-07-24 18:21:13 -0700174{
Furquan Shaikhe07532f2021-04-10 14:26:15 -0700175 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
176 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Notify");
177
Julius Wernercd49cce2019-03-05 16:53:33 -0800178 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
Lee Leahy672df162016-07-24 18:21:13 -0700179 printk(BIOS_SPEW, "FspNotify returned 0x%08x\n", status);
Lee Leahy0a38b222016-07-24 08:26:06 -0700180
Lee Leahyac3b0a62016-07-27 07:40:25 -0700181 /* Display the HOBs */
Julius Wernercd49cce2019-03-05 16:53:33 -0800182 if (CONFIG(DISPLAY_HOBS))
Lee Leahyac3b0a62016-07-27 07:40:25 -0700183 fsp_display_hobs();
184
Nico Huberd67edca2018-11-13 19:28:07 +0100185 display_mtrrs();
Lee Leahy672df162016-07-24 18:21:13 -0700186}