Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 2 | |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 3 | #include <bootstate.h> |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 4 | #include <console/console.h> |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 5 | #include <cpu/x86/mtrr.h> |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 6 | #include <fsp/util.h> |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 7 | #include <mode_switch.h> |
Angel Pons | 654930e | 2022-01-01 17:08:00 +0100 | [diff] [blame^] | 8 | #include <timestamp.h> |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 9 | |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 10 | static void fsp_notify(enum fsp_notify_phase phase) |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 11 | { |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 12 | struct fsp_notify_params notify_params = { .phase = phase }; |
Angel Pons | 654930e | 2022-01-01 17:08:00 +0100 | [diff] [blame^] | 13 | fsp_notify_fn fspnotify; |
| 14 | uint32_t ret; |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 15 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 16 | if (!fsps_hdr.notify_phase_entry_offset) |
| 17 | die("Notify_phase_entry_offset is zero!\n"); |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 18 | |
Angel Pons | 654930e | 2022-01-01 17:08:00 +0100 | [diff] [blame^] | 19 | fspnotify = (void *)(uintptr_t)(fsps_hdr.image_base + |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 20 | fsps_hdr.notify_phase_entry_offset); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 21 | fsp_before_debug_notify(fspnotify, ¬ify_params); |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 22 | |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 23 | if (phase == AFTER_PCI_ENUM) { |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 24 | timestamp_add_now(TS_FSP_BEFORE_ENUMERATE); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 25 | post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE); |
| 26 | } else if (phase == READY_TO_BOOT) { |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 27 | timestamp_add_now(TS_FSP_BEFORE_FINALIZE); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 28 | post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE); |
Aaron Durbin | 96b3c6f | 2016-11-10 21:09:25 -0600 | [diff] [blame] | 29 | } else if (phase == END_OF_FIRMWARE) { |
| 30 | timestamp_add_now(TS_FSP_BEFORE_END_OF_FIRMWARE); |
| 31 | post_code(POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 32 | } |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 33 | |
Patrick Rudolph | 31218a4 | 2020-11-30 15:50:06 +0100 | [diff] [blame] | 34 | if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32)) |
Patrick Rudolph | 40beb36 | 2020-12-01 10:08:38 +0100 | [diff] [blame] | 35 | ret = protected_mode_call_1arg(fspnotify, (uintptr_t)¬ify_params); |
| 36 | else |
| 37 | ret = fspnotify(¬ify_params); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 38 | |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 39 | if (phase == AFTER_PCI_ENUM) { |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 40 | timestamp_add_now(TS_FSP_AFTER_ENUMERATE); |
Subrata Banik | 86b1b68 | 2021-05-04 23:43:34 +0530 | [diff] [blame] | 41 | post_code(POST_FSP_NOTIFY_AFTER_ENUMERATE); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 42 | } else if (phase == READY_TO_BOOT) { |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 43 | timestamp_add_now(TS_FSP_AFTER_FINALIZE); |
Subrata Banik | 86b1b68 | 2021-05-04 23:43:34 +0530 | [diff] [blame] | 44 | post_code(POST_FSP_NOTIFY_AFTER_FINALIZE); |
Aaron Durbin | 96b3c6f | 2016-11-10 21:09:25 -0600 | [diff] [blame] | 45 | } else if (phase == END_OF_FIRMWARE) { |
| 46 | timestamp_add_now(TS_FSP_AFTER_END_OF_FIRMWARE); |
| 47 | post_code(POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 48 | } |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 49 | fsp_debug_after_notify(ret); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 50 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 51 | /* Handle any errors returned by FspNotify */ |
| 52 | fsp_handle_reset(ret); |
Angel Pons | 2b1f8d4 | 2022-01-01 17:20:00 +0100 | [diff] [blame] | 53 | if (ret != FSP_SUCCESS) |
| 54 | die("FspNotify returned with error 0x%08x!\n", ret); |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 55 | |
| 56 | /* Allow the platform to run something after FspNotify */ |
| 57 | platform_fsp_notify_status(phase); |
| 58 | } |
| 59 | |
| 60 | static void fsp_notify_dummy(void *arg) |
| 61 | { |
Patrick Rudolph | 90fda02 | 2020-11-30 13:44:17 +0100 | [diff] [blame] | 62 | enum fsp_notify_phase phase = (uint32_t)(uintptr_t)arg; |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 63 | |
Nico Huber | d67edca | 2018-11-13 19:28:07 +0100 | [diff] [blame] | 64 | display_mtrrs(); |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 65 | |
| 66 | fsp_notify(phase); |
| 67 | if (phase == READY_TO_BOOT) |
| 68 | fsp_notify(END_OF_FIRMWARE); |
| 69 | } |
| 70 | |
Angel Pons | 654930e | 2022-01-01 17:08:00 +0100 | [diff] [blame^] | 71 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fsp_notify_dummy, (void *)AFTER_PCI_ENUM); |
| 72 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, fsp_notify_dummy, (void *)READY_TO_BOOT); |
| 73 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, fsp_notify_dummy, (void *)READY_TO_BOOT); |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 74 | |
Angel Pons | 654930e | 2022-01-01 17:08:00 +0100 | [diff] [blame^] | 75 | __weak void platform_fsp_notify_status(enum fsp_notify_phase phase) |
Lee Leahy | 806fa24 | 2016-08-01 13:55:02 -0700 | [diff] [blame] | 76 | { |
Andrey Petrov | 9de55cc | 2016-02-25 14:19:07 -0800 | [diff] [blame] | 77 | } |