debug.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 3 #include <commonlib/helpers.h> 4 #include <console/console.h> 5 #include <console/streams.h> 6 #include <cpu/x86/mtrr.h> 7 #include <fsp/debug.h> 8 #include <fsp/util.h> 9 #include <option.h> 10 11 enum fsp_call_phase { 12 BEFORE_FSP_CALL, 13 AFTER_FSP_CALL, 14 }; 15 16 static void fsp_gpio_config_check(enum fsp_call_phase phase, const char *call_str) 17 { 18 switch (phase) { 19 case BEFORE_FSP_CALL: 20 printk(BIOS_SPEW, "Snapshot all GPIOs before %s.\n", call_str); 21 gpio_snapshot(); 22 break; 23 case AFTER_FSP_CALL: 24 printk(BIOS_SPEW, "Verify GPIO snapshot after %s...", call_str); 25 printk(BIOS_SPEW, "%zd changes detected!\n", gpio_verify_snapshot()); 26 break; 27 default: 28 break; 29 } 30 } 31 32 enum fsp_log_level fsp_map_console_log_level(void) 33 { 34 enum fsp_log_level fsp_debug_level; 35 36 switch (get_log_level()) { 37 case BIOS_EMERG: 38 case BIOS_ALERT: 39 case BIOS_CRIT: 40 case BIOS_ERR: 41 fsp_debug_level = FSP_LOG_LEVEL_ERR; 42 break; 43 case BIOS_WARNING: 44 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN; 45 break; 46 case BIOS_NOTICE: 47 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO; 48 break; 49 case BIOS_INFO: 50 fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO_EVENT; 51 break; 52 case BIOS_DEBUG: 53 case BIOS_SPEW: 54 fsp_debug_level = FSP_LOG_LEVEL_VERBOSE; 55 break; 56 default: 57 fsp_debug_level = FSP_LOG_LEVEL_DISABLE; 58 break; 59 } 60 61 if (!CONFIG(DEBUG_RAM_SETUP)) 62 fsp_debug_level = MIN(fsp_debug_level, FSP_LOG_LEVEL_ERR_WARN_INFO); 63 64 return fsp_debug_level; 65 } 66 67 /*----------- 68 * MemoryInit 69 *----------- 70 */ 71 void fsp_debug_before_memory_init(fsp_memory_init_fn memory_init, 72 const FSPM_UPD *fspm_old_upd, 73 const FSPM_UPD *fspm_new_upd) 74 { 75 display_mtrrs(); 76 77 /* Display the UPD values */ 78 if (CONFIG(DISPLAY_UPD_DATA)) 79 fspm_display_upd_values(fspm_old_upd, fspm_new_upd); 80 81 /* Display the call entry point and parameters */ 82 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 83 return; 84 printk(BIOS_SPEW, "Calling FspMemoryInit: %p\n", memory_init); 85 printk(BIOS_SPEW, "\t%p: raminit_upd\n", fspm_new_upd); 86 printk(BIOS_SPEW, "\t%p: &hob_list_ptr\n", fsp_get_hob_list_ptr()); 87 } 88 89 void fsp_debug_after_memory_init(efi_return_status_t status) 90 { 91 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 92 fsp_printk(status, BIOS_SPEW, "FspMemoryInit"); 93 94 if (status != FSP_SUCCESS) 95 return; 96 97 /* Verify that the HOB list pointer was set */ 98 if (fsp_get_hob_list() == NULL) 99 die("ERROR - HOB list pointer was not returned!\n"); 100 101 /* Display and verify the HOBs */ 102 if (CONFIG(DISPLAY_HOBS)) 103 fsp_display_hobs(); 104 if (CONFIG(VERIFY_HOBS)) 105 fsp_verify_memory_init_hobs(); 106 107 display_mtrrs(); 108 } 109 110 /*----------- 111 * SiliconInit 112 *----------- 113 */ 114 void fsp_debug_before_silicon_init(fsp_silicon_init_fn silicon_init, 115 const FSPS_UPD *fsps_old_upd, 116 const FSPS_UPD *fsps_new_upd) 117 { 118 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) 119 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Silicon Init"); 120 121 display_mtrrs(); 122 123 /* Display the UPD values */ 124 if (CONFIG(DISPLAY_UPD_DATA)) 125 soc_display_fsps_upd_params(fsps_old_upd, fsps_new_upd); 126 127 /* Display the call to FSP SiliconInit */ 128 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 129 return; 130 printk(BIOS_SPEW, "Calling FspSiliconInit: %p\n", silicon_init); 131 printk(BIOS_SPEW, "\t%p: upd\n", fsps_new_upd); 132 } 133 134 void fsp_debug_after_silicon_init(efi_return_status_t status) 135 { 136 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) 137 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Silicon Init"); 138 139 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 140 fsp_printk(status, BIOS_SPEW, "FspSiliconInit"); 141 142 /* Display the HOBs */ 143 if (CONFIG(DISPLAY_HOBS)) 144 fsp_display_hobs(); 145 146 display_mtrrs(); 147 } 148 149 /*----------- 150 * FspNotify 151 *----------- 152 */ 153 void fsp_before_debug_notify(fsp_notify_fn notify, 154 const struct fsp_notify_params *notify_params) 155 { 156 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) 157 fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Notify"); 158 159 /* Display the call to FspNotify */ 160 if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 161 return; 162 printk(BIOS_SPEW, "0x%08x: notify_params->phase\n", 163 notify_params->phase); 164 printk(BIOS_SPEW, "Calling FspNotify: %p\n", notify); 165 printk(BIOS_SPEW, "\t%p: notify_params\n", notify_params); 166 } 167 168 void fsp_debug_after_notify(efi_return_status_t status) 169 { 170 if (CONFIG(CHECK_GPIO_CONFIG_CHANGES)) 171 fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Notify"); 172 173 if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS)) 174 fsp_printk(status, BIOS_SPEW, "FspNotify"); 175 176 /* Display the HOBs */ 177 if (CONFIG(DISPLAY_HOBS)) 178 fsp_display_hobs(); 179 180 display_mtrrs(); 181 } 182 183 enum fsp_log_level fsp_get_pcd_debug_log_level(void) 184 { 185 return get_uint_option("fsp_pcd_debug_level", fsp_map_console_log_level()); 186 } 187 188 enum fsp_log_level fsp_get_mrc_debug_log_level(void) 189 { 190 return get_uint_option("fsp_mrc_debug_level", fsp_map_console_log_level()); 191 }