Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 2 | |
Subrata Banik | 69107c1 | 2021-12-29 18:24:07 +0000 | [diff] [blame] | 3 | #include <commonlib/helpers.h> |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
Lee Leahy | 00a38a4 | 2016-08-09 09:04:45 -0700 | [diff] [blame] | 5 | #include <console/streams.h> |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 6 | #include <cpu/x86/mtrr.h> |
Subrata Banik | 69107c1 | 2021-12-29 18:24:07 +0000 | [diff] [blame] | 7 | #include <fsp/debug.h> |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 8 | #include <fsp/util.h> |
| 9 | |
Lee Leahy | 00a38a4 | 2016-08-09 09:04:45 -0700 | [diff] [blame] | 10 | asmlinkage 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 Shaikh | e07532f | 2021-04-10 14:26:15 -0700 | [diff] [blame] | 16 | enum fsp_call_phase { |
| 17 | BEFORE_FSP_CALL, |
| 18 | AFTER_FSP_CALL, |
| 19 | }; |
| 20 | |
| 21 | static 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 Banik | 69107c1 | 2021-12-29 18:24:07 +0000 | [diff] [blame] | 37 | enum 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 Chen | 5e8dd5d | 2022-02-15 09:29:22 +0800 | [diff] [blame] | 67 | fsp_debug_level = MIN(fsp_debug_level, FSP_LOG_LEVEL_ERR_WARN_INFO); |
Subrata Banik | 69107c1 | 2021-12-29 18:24:07 +0000 | [diff] [blame] | 68 | |
| 69 | return fsp_debug_level; |
| 70 | } |
| 71 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 72 | /*----------- |
| 73 | * MemoryInit |
| 74 | *----------- |
| 75 | */ |
| 76 | void fsp_debug_before_memory_init(fsp_memory_init_fn memory_init, |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 77 | const FSPM_UPD *fspm_old_upd, |
| 78 | const FSPM_UPD *fspm_new_upd) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 79 | { |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 80 | display_mtrrs(); |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 81 | |
Lee Leahy | e6f2f74 | 2016-07-21 09:48:49 -0700 | [diff] [blame] | 82 | /* Display the UPD values */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 83 | if (CONFIG(DISPLAY_UPD_DATA)) |
Lee Leahy | e6f2f74 | 2016-07-21 09:48:49 -0700 | [diff] [blame] | 84 | fspm_display_upd_values(fspm_old_upd, fspm_new_upd); |
| 85 | |
Elyes HAOUAS | 1895838 | 2018-08-07 12:23:16 +0200 | [diff] [blame] | 86 | /* Display the call entry point and parameters */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 87 | if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 88 | return; |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 89 | 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 Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 94 | void fsp_debug_after_memory_init(uint32_t status) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 95 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 96 | if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 97 | printk(BIOS_SPEW, "FspMemoryInit returned 0x%08x\n", status); |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 98 | |
Lee Leahy | 6359a75 | 2016-08-11 17:40:01 -0700 | [diff] [blame] | 99 | if (status != FSP_SUCCESS) |
| 100 | return; |
| 101 | |
Lee Leahy | 52d0c68 | 2016-08-01 15:47:42 -0700 | [diff] [blame] | 102 | /* 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 107 | if (CONFIG(DISPLAY_HOBS)) |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 108 | fsp_display_hobs(); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 109 | if (CONFIG(VERIFY_HOBS)) |
Lee Leahy | 52d0c68 | 2016-08-01 15:47:42 -0700 | [diff] [blame] | 110 | fsp_verify_memory_init_hobs(); |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 111 | |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 112 | display_mtrrs(); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /*----------- |
| 116 | * SiliconInit |
| 117 | *----------- |
| 118 | */ |
| 119 | void fsp_debug_before_silicon_init(fsp_silicon_init_fn silicon_init, |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 120 | const FSPS_UPD *fsps_old_upd, |
| 121 | const FSPS_UPD *fsps_new_upd) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 122 | { |
Furquan Shaikh | e07532f | 2021-04-10 14:26:15 -0700 | [diff] [blame] | 123 | if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) |
| 124 | fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Silicon Init"); |
| 125 | |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 126 | display_mtrrs(); |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 127 | |
Lee Leahy | e6f2f74 | 2016-07-21 09:48:49 -0700 | [diff] [blame] | 128 | /* Display the UPD values */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 129 | if (CONFIG(DISPLAY_UPD_DATA)) |
Lee Leahy | e6f2f74 | 2016-07-21 09:48:49 -0700 | [diff] [blame] | 130 | soc_display_fsps_upd_params(fsps_old_upd, fsps_new_upd); |
| 131 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 132 | /* Display the call to FSP SiliconInit */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 133 | if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 134 | return; |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 135 | printk(BIOS_SPEW, "Calling FspSiliconInit: %p\n", silicon_init); |
| 136 | printk(BIOS_SPEW, "\t%p: upd\n", fsps_new_upd); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 139 | void fsp_debug_after_silicon_init(uint32_t status) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 140 | { |
Furquan Shaikh | e07532f | 2021-04-10 14:26:15 -0700 | [diff] [blame] | 141 | if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) |
| 142 | fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Silicon Init"); |
| 143 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 144 | if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 145 | printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status); |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 146 | |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 147 | /* Display the HOBs */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 148 | if (CONFIG(DISPLAY_HOBS)) |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 149 | fsp_display_hobs(); |
| 150 | |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 151 | display_mtrrs(); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /*----------- |
| 155 | * FspNotify |
| 156 | *----------- |
| 157 | */ |
| 158 | void fsp_before_debug_notify(fsp_notify_fn notify, |
| 159 | const struct fsp_notify_params *notify_params) |
| 160 | { |
Furquan Shaikh | e07532f | 2021-04-10 14:26:15 -0700 | [diff] [blame] | 161 | if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) |
| 162 | fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Notify"); |
| 163 | |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 164 | /* Display the call to FspNotify */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 165 | if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 166 | return; |
| 167 | printk(BIOS_SPEW, "0x%08x: notify_params->phase\n", |
| 168 | notify_params->phase); |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 169 | printk(BIOS_SPEW, "Calling FspNotify: %p\n", notify); |
| 170 | printk(BIOS_SPEW, "\t%p: notify_params\n", notify_params); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 173 | void fsp_debug_after_notify(uint32_t status) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 174 | { |
Furquan Shaikh | e07532f | 2021-04-10 14:26:15 -0700 | [diff] [blame] | 175 | if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) |
| 176 | fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Notify"); |
| 177 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 178 | if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 179 | printk(BIOS_SPEW, "FspNotify returned 0x%08x\n", status); |
Lee Leahy | 0a38b22 | 2016-07-24 08:26:06 -0700 | [diff] [blame] | 180 | |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 181 | /* Display the HOBs */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 182 | if (CONFIG(DISPLAY_HOBS)) |
Lee Leahy | ac3b0a6 | 2016-07-27 07:40:25 -0700 | [diff] [blame] | 183 | fsp_display_hobs(); |
| 184 | |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 185 | display_mtrrs(); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 186 | } |