Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 2 | |
Arthur Heymans | 78ab06a | 2021-05-29 06:58:38 +0200 | [diff] [blame] | 3 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 4 | #include <console/console.h> |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 5 | #include <stdint.h> |
| 6 | #include <string.h> |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 7 | #include <timestamp.h> |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 8 | |
Kyösti Mälkki | acc599b | 2016-11-24 14:31:07 +0200 | [diff] [blame] | 9 | #include <northbridge/amd/agesa/state_machine.h> |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 10 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 11 | #include <amdlib.h> |
Kyösti Mälkki | d1d4f93 | 2017-09-24 08:21:00 +0300 | [diff] [blame] | 12 | #include <debug_util.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 13 | #include <AGESA.h> |
| 14 | #include <AMD.h> |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 15 | |
Kyösti Mälkki | acc599b | 2016-11-24 14:31:07 +0200 | [diff] [blame] | 16 | static const char undefined[] = "undefined"; |
| 17 | |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 18 | struct agesa_mapping |
| 19 | { |
| 20 | AGESA_STRUCT_NAME func; |
| 21 | const char *name; |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 22 | uint32_t entry_id; |
| 23 | uint32_t exit_id; |
Kyösti Mälkki | acc599b | 2016-11-24 14:31:07 +0200 | [diff] [blame] | 24 | }; |
| 25 | |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 26 | static const struct agesa_mapping entrypoint[] = { |
| 27 | { |
| 28 | .func = AMD_INIT_RESET, |
| 29 | .name = "AmdInitReset", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 30 | .entry_id = TS_AGESA_INIT_RESET_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 31 | .exit_id = TS_AGESA_INIT_RESET_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 32 | }, |
| 33 | { |
| 34 | .func = AMD_INIT_EARLY, |
| 35 | .name = "AmdInitEarly", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 36 | .entry_id = TS_AGESA_INIT_EARLY_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 37 | .exit_id = TS_AGESA_INIT_EARLY_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 38 | }, |
| 39 | { |
| 40 | .func = AMD_INIT_POST, |
| 41 | .name = "AmdInitPost", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 42 | .entry_id = TS_AGESA_INIT_POST_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 43 | .exit_id = TS_AGESA_INIT_POST_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 44 | }, |
| 45 | { |
| 46 | .func = AMD_INIT_RESUME, |
| 47 | .name = "AmdInitResume", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 48 | .entry_id = TS_AGESA_INIT_RESUME_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 49 | .exit_id = TS_AGESA_INIT_RESUME_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 50 | }, |
| 51 | { |
| 52 | .func = AMD_INIT_ENV, |
| 53 | .name = "AmdInitEnv", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 54 | .entry_id = TS_AGESA_INIT_ENV_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 55 | .exit_id = TS_AGESA_INIT_ENV_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 56 | }, |
| 57 | { |
| 58 | .func = AMD_INIT_MID, |
| 59 | .name = "AmdInitMid", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 60 | .entry_id = TS_AGESA_INIT_MID_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 61 | .exit_id = TS_AGESA_INIT_MID_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 62 | }, |
| 63 | { |
| 64 | .func = AMD_INIT_LATE, |
| 65 | .name = "AmdInitLate", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 66 | .entry_id = TS_AGESA_INIT_LATE_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 67 | .exit_id = TS_AGESA_INIT_LATE_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 68 | }, |
| 69 | { |
| 70 | .func = AMD_S3LATE_RESTORE, |
| 71 | .name = "AmdS3LateRestore", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 72 | .entry_id = TS_AGESA_S3_LATE_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 73 | .exit_id = TS_AGESA_S3_LATE_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 74 | }, |
| 75 | #if !defined(AMD_S3_SAVE_REMOVED) |
| 76 | { |
| 77 | .func = AMD_S3_SAVE, |
| 78 | .name = "AmdS3Save", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 79 | .entry_id = TS_AGESA_INIT_RTB_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 80 | .exit_id = TS_AGESA_INIT_RTB_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 81 | }, |
Kyösti Mälkki | 903ce25 | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 82 | #endif |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 83 | { |
| 84 | .func = AMD_S3FINAL_RESTORE, |
| 85 | .name = "AmdS3FinalRestore", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 86 | .entry_id = TS_AGESA_S3_FINAL_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 87 | .exit_id = TS_AGESA_S3_FINAL_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 88 | }, |
| 89 | { |
| 90 | .func = AMD_INIT_RTB, |
| 91 | .name = "AmdInitRtb", |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 92 | .entry_id = TS_AGESA_INIT_RTB_START, |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 93 | .exit_id = TS_AGESA_INIT_RTB_END, |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 94 | }, |
| 95 | }; |
Kyösti Mälkki | acc599b | 2016-11-24 14:31:07 +0200 | [diff] [blame] | 96 | |
Kyösti Mälkki | d1d4f93 | 2017-09-24 08:21:00 +0300 | [diff] [blame] | 97 | void agesa_state_on_entry(struct agesa_state *task, AGESA_STRUCT_NAME func) |
| 98 | { |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 99 | int i; |
| 100 | |
Arthur Heymans | 78ab06a | 2021-05-29 06:58:38 +0200 | [diff] [blame] | 101 | task->apic_id = (u8)initial_lapicid(); |
Kyösti Mälkki | d1d4f93 | 2017-09-24 08:21:00 +0300 | [diff] [blame] | 102 | task->func = func; |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 103 | task->function_name = undefined; |
| 104 | |
| 105 | for (i = 0; i < ARRAY_SIZE(entrypoint); i++) { |
| 106 | if (task->func == entrypoint[i].func) { |
| 107 | task->function_name = entrypoint[i].name; |
Kyösti Mälkki | 43f6d9d | 2019-03-14 14:59:31 +0200 | [diff] [blame] | 108 | task->ts_entry_id = entrypoint[i].entry_id; |
| 109 | task->ts_exit_id = entrypoint[i].exit_id; |
Kyösti Mälkki | e20d609 | 2018-06-10 08:20:56 +0300 | [diff] [blame] | 110 | break; |
| 111 | } |
| 112 | } |
Kyösti Mälkki | d1d4f93 | 2017-09-24 08:21:00 +0300 | [diff] [blame] | 113 | |
| 114 | printk(BIOS_DEBUG, "\nAPIC %02d: ** Enter %s [%08x]\n", |
| 115 | task->apic_id, task->function_name, task->func); |
| 116 | } |
| 117 | |
| 118 | void agesa_state_on_exit(struct agesa_state *task, |
| 119 | AMD_CONFIG_PARAMS *StdHeader) |
| 120 | { |
| 121 | printk(BIOS_DEBUG, "APIC %02d: Heap in %s (%d) at 0x%08x\n", |
| 122 | task->apic_id, heap_status_name(StdHeader->HeapStatus), |
| 123 | StdHeader->HeapStatus, (u32)StdHeader->HeapBasePtr); |
| 124 | |
| 125 | printk(BIOS_DEBUG, "APIC %02d: ** Exit %s [%08x]\n", |
| 126 | task->apic_id, task->function_name, task->func); |
| 127 | } |
| 128 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 129 | /* |
| 130 | * Possible AGESA_STATUS values: |
| 131 | * |
| 132 | * 0x0 = AGESA_SUCCESS |
| 133 | * 0x1 = AGESA_UNSUPPORTED |
| 134 | * 0x2 = AGESA_BOUNDS_CHK |
| 135 | * 0x3 = AGESA_ALERT |
| 136 | * 0x4 = AGESA_WARNING |
| 137 | * 0x5 = AGESA_ERROR |
| 138 | * 0x6 = AGESA_CRITICAL |
| 139 | * 0x7 = AGESA_FATAL |
| 140 | */ |
Elyes HAOUAS | 448d9fb | 2018-05-22 12:51:27 +0200 | [diff] [blame] | 141 | static const char *decodeAGESA_STATUS(AGESA_STATUS sret) |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 142 | { |
Elyes HAOUAS | 448d9fb | 2018-05-22 12:51:27 +0200 | [diff] [blame] | 143 | const char *statusStrings[] = { "AGESA_SUCCESS", "AGESA_UNSUPPORTED", |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 144 | "AGESA_BOUNDS_CHK", "AGESA_ALERT", |
| 145 | "AGESA_WARNING", "AGESA_ERROR", |
| 146 | "AGESA_CRITICAL", "AGESA_FATAL" |
| 147 | }; |
| 148 | if (sret > 7) return "unknown"; /* Non-AGESA error code */ |
| 149 | return statusStrings[sret]; |
| 150 | } |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 151 | |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 152 | static void show_event(EVENT_PARAMS *Event) |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 153 | { |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 154 | printk(BIOS_DEBUG, "\nEventLog: EventClass = %x, EventInfo = %x.\n", |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 155 | (unsigned int)Event->EventClass, |
| 156 | (unsigned int)Event->EventInfo); |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 157 | printk(BIOS_DEBUG, " Param1 = %x, Param2 = %x.\n", |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 158 | (unsigned int)Event->DataParam1, |
| 159 | (unsigned int)Event->DataParam2); |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 160 | printk(BIOS_DEBUG, " Param3 = %x, Param4 = %x.\n", |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 161 | (unsigned int)Event->DataParam3, |
| 162 | (unsigned int)Event->DataParam4); |
| 163 | } |
| 164 | |
| 165 | #define MAX_LOG_ENTRIES 100 |
| 166 | |
| 167 | static void amd_flush_eventlog(EVENT_PARAMS *Event) |
| 168 | { |
| 169 | int i = 0; |
| 170 | |
| 171 | do { |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 172 | AGESA_STATUS status; |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 173 | status = module_dispatch(AMD_READ_EVENT_LOG, &Event->StdHeader); |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 174 | if (status != AGESA_SUCCESS) |
| 175 | return; |
| 176 | if (Event->EventClass == 0) |
| 177 | return; |
| 178 | show_event(Event); |
| 179 | } while (++i < MAX_LOG_ENTRIES); |
| 180 | } |
| 181 | |
| 182 | void agesawrapper_trace(AGESA_STATUS ret, AMD_CONFIG_PARAMS *StdHeader, |
| 183 | const char *func) |
| 184 | { |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 185 | EVENT_PARAMS AmdEventParams; |
| 186 | |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 187 | printk(BIOS_DEBUG, "%s() returned %s\n", func, decodeAGESA_STATUS(ret)); |
| 188 | if (ret == AGESA_SUCCESS) |
| 189 | return; |
| 190 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 191 | memset(&AmdEventParams, 0, sizeof(EVENT_PARAMS)); |
Kyösti Mälkki | 46f04cb | 2017-09-06 15:42:23 +0300 | [diff] [blame] | 192 | memcpy(&AmdEventParams.StdHeader, StdHeader, sizeof(*StdHeader)); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 193 | |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 194 | amd_flush_eventlog(&AmdEventParams); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 195 | } |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 196 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 197 | AGESA_STATUS agesawrapper_amdreadeventlog(UINT8 HeapStatus) |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 198 | { |
Kyösti Mälkki | 0a7cab8 | 2017-07-29 08:11:52 +0300 | [diff] [blame] | 199 | EVENT_PARAMS AmdEventParams; |
| 200 | |
| 201 | memset(&AmdEventParams, 0, sizeof(EVENT_PARAMS)); |
| 202 | |
| 203 | AmdEventParams.StdHeader.AltImageBasePtr = 0; |
| 204 | AmdEventParams.StdHeader.CalloutPtr = &GetBiosCallout; |
| 205 | AmdEventParams.StdHeader.Func = 0; |
| 206 | AmdEventParams.StdHeader.ImageBasePtr = 0; |
| 207 | AmdEventParams.StdHeader.HeapStatus = HeapStatus; |
| 208 | |
| 209 | amd_flush_eventlog(&AmdEventParams); |
| 210 | |
| 211 | return AGESA_SUCCESS; |
Kyösti Mälkki | e68f4ff | 2014-10-22 15:53:34 +0300 | [diff] [blame] | 212 | } |