blob: 22bbf539d32a91f6dd4eeb9bda67d606acd642ee [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrov9de55cc2016-02-25 14:19:07 -08002
Arthur Heymansfdf6d122022-05-17 13:07:30 +02003#include <arch/null_breakpoint.h>
Lee Leahy806fa242016-08-01 13:55:02 -07004#include <bootstate.h>
Andrey Petrov9de55cc2016-02-25 14:19:07 -08005#include <console/console.h>
Nico Huberd67edca2018-11-13 19:28:07 +01006#include <cpu/x86/mtrr.h>
Andrey Petrov9de55cc2016-02-25 14:19:07 -08007#include <fsp/util.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +01008#include <mode_switch.h>
Angel Pons654930e2022-01-01 17:08:00 +01009#include <timestamp.h>
Angel Pons355d8442022-01-01 17:03:10 +010010#include <types.h>
11
12struct fsp_notify_phase_data {
13 enum fsp_notify_phase notify_phase;
Subrata Banike8feab02021-12-27 10:25:55 +000014 bool skip;
Angel Pons355d8442022-01-01 17:03:10 +010015 uint8_t post_code_before;
16 uint8_t post_code_after;
17 enum timestamp_id timestamp_before;
18 enum timestamp_id timestamp_after;
19};
20
21static const struct fsp_notify_phase_data notify_data[] = {
22 {
23 .notify_phase = AFTER_PCI_ENUM,
Subrata Banik34f26b22022-02-10 12:38:02 +053024 .skip = !CONFIG(USE_FSP_NOTIFY_PHASE_POST_PCI_ENUM),
lilacious40cb3fe2023-06-21 23:24:14 +020025 .post_code_before = POSTCODE_FSP_NOTIFY_BEFORE_ENUMERATE,
26 .post_code_after = POSTCODE_FSP_NOTIFY_AFTER_ENUMERATE,
Jakub Czapigaad6157e2022-02-15 11:50:31 +010027 .timestamp_before = TS_FSP_ENUMERATE_START,
28 .timestamp_after = TS_FSP_ENUMERATE_END,
Angel Pons355d8442022-01-01 17:03:10 +010029 },
30 {
31 .notify_phase = READY_TO_BOOT,
Subrata Banik34f26b22022-02-10 12:38:02 +053032 .skip = !CONFIG(USE_FSP_NOTIFY_PHASE_READY_TO_BOOT),
lilacious40cb3fe2023-06-21 23:24:14 +020033 .post_code_before = POSTCODE_FSP_NOTIFY_BEFORE_FINALIZE,
34 .post_code_after = POSTCODE_FSP_NOTIFY_AFTER_FINALIZE,
Jakub Czapigaad6157e2022-02-15 11:50:31 +010035 .timestamp_before = TS_FSP_FINALIZE_START,
36 .timestamp_after = TS_FSP_FINALIZE_END,
Angel Pons355d8442022-01-01 17:03:10 +010037 },
38 {
39 .notify_phase = END_OF_FIRMWARE,
Subrata Banik34f26b22022-02-10 12:38:02 +053040 .skip = !CONFIG(USE_FSP_NOTIFY_PHASE_END_OF_FIRMWARE),
lilacious40cb3fe2023-06-21 23:24:14 +020041 .post_code_before = POSTCODE_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE,
42 .post_code_after = POSTCODE_FSP_NOTIFY_AFTER_END_OF_FIRMWARE,
Jakub Czapigaad6157e2022-02-15 11:50:31 +010043 .timestamp_before = TS_FSP_END_OF_FIRMWARE_START,
44 .timestamp_after = TS_FSP_END_OF_FIRMWARE_END,
Angel Pons355d8442022-01-01 17:03:10 +010045 },
46};
47
48static const struct fsp_notify_phase_data *get_notify_phase_data(enum fsp_notify_phase phase)
49{
50 for (size_t i = 0; i < ARRAY_SIZE(notify_data); i++) {
51 if (notify_data[i].notify_phase == phase)
52 return &notify_data[i];
53 }
54 die("Unknown FSP notify phase %u\n", phase);
55}
Andrey Petrov9de55cc2016-02-25 14:19:07 -080056
Lee Leahy806fa242016-08-01 13:55:02 -070057static void fsp_notify(enum fsp_notify_phase phase)
Andrey Petrov9de55cc2016-02-25 14:19:07 -080058{
Angel Pons355d8442022-01-01 17:03:10 +010059 const struct fsp_notify_phase_data *data = get_notify_phase_data(phase);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080060 struct fsp_notify_params notify_params = { .phase = phase };
Angel Pons654930e2022-01-01 17:08:00 +010061 fsp_notify_fn fspnotify;
62 uint32_t ret;
Andrey Petrov9de55cc2016-02-25 14:19:07 -080063
Subrata Banike8feab02021-12-27 10:25:55 +000064 if (data->skip) {
65 printk(BIOS_INFO, "coreboot skipped calling FSP notify phase: %08x.\n", phase);
66 return;
67 }
68
Lee Leahy9671faa2016-07-24 18:18:52 -070069 if (!fsps_hdr.notify_phase_entry_offset)
70 die("Notify_phase_entry_offset is zero!\n");
Andrey Petrov9de55cc2016-02-25 14:19:07 -080071
Angel Pons654930e2022-01-01 17:08:00 +010072 fspnotify = (void *)(uintptr_t)(fsps_hdr.image_base +
Andrey Petrov9de55cc2016-02-25 14:19:07 -080073 fsps_hdr.notify_phase_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070074 fsp_before_debug_notify(fspnotify, &notify_params);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080075
Angel Pons355d8442022-01-01 17:03:10 +010076 timestamp_add_now(data->timestamp_before);
77 post_code(data->post_code_before);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070078
Arthur Heymansfdf6d122022-05-17 13:07:30 +020079 /* FSP disables the interrupt handler so remove debug exceptions temporarily */
80 null_breakpoint_disable();
Patrick Rudolph31218a42020-11-30 15:50:06 +010081 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +010082 ret = protected_mode_call_1arg(fspnotify, (uintptr_t)&notify_params);
83 else
84 ret = fspnotify(&notify_params);
Arthur Heymansfdf6d122022-05-17 13:07:30 +020085 null_breakpoint_init();
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070086
Angel Pons355d8442022-01-01 17:03:10 +010087 timestamp_add_now(data->timestamp_after);
88 post_code(data->post_code_after);
89
Lee Leahy672df162016-07-24 18:21:13 -070090 fsp_debug_after_notify(ret);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070091
Lee Leahy9671faa2016-07-24 18:18:52 -070092 /* Handle any errors returned by FspNotify */
93 fsp_handle_reset(ret);
Angel Pons2b1f8d42022-01-01 17:20:00 +010094 if (ret != FSP_SUCCESS)
95 die("FspNotify returned with error 0x%08x!\n", ret);
Lee Leahy806fa242016-08-01 13:55:02 -070096
97 /* Allow the platform to run something after FspNotify */
98 platform_fsp_notify_status(phase);
99}
100
101static void fsp_notify_dummy(void *arg)
102{
Patrick Rudolph90fda022020-11-30 13:44:17 +0100103 enum fsp_notify_phase phase = (uint32_t)(uintptr_t)arg;
Lee Leahy806fa242016-08-01 13:55:02 -0700104
Nico Huberd67edca2018-11-13 19:28:07 +0100105 display_mtrrs();
Lee Leahy806fa242016-08-01 13:55:02 -0700106
107 fsp_notify(phase);
108 if (phase == READY_TO_BOOT)
109 fsp_notify(END_OF_FIRMWARE);
110}
111
Angel Pons654930e2022-01-01 17:08:00 +0100112BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fsp_notify_dummy, (void *)AFTER_PCI_ENUM);
113BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, fsp_notify_dummy, (void *)READY_TO_BOOT);
114BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, fsp_notify_dummy, (void *)READY_TO_BOOT);
Lee Leahy806fa242016-08-01 13:55:02 -0700115
Angel Pons654930e2022-01-01 17:08:00 +0100116__weak void platform_fsp_notify_status(enum fsp_notify_phase phase)
Lee Leahy806fa242016-08-01 13:55:02 -0700117{
Andrey Petrov9de55cc2016-02-25 14:19:07 -0800118}