blob: 36b538ffc65631d61c11fe2ce2fe607813a73e5e [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
Lee Leahy806fa242016-08-01 13:55:02 -07003#include <bootstate.h>
Andrey Petrov9de55cc2016-02-25 14:19:07 -08004#include <console/console.h>
Nico Huberd67edca2018-11-13 19:28:07 +01005#include <cpu/x86/mtrr.h>
Andrey Petrov9de55cc2016-02-25 14:19:07 -08006#include <fsp/util.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +01007#include <mode_switch.h>
Angel Pons654930e2022-01-01 17:08:00 +01008#include <timestamp.h>
Angel Pons355d8442022-01-01 17:03:10 +01009#include <types.h>
10
11struct fsp_notify_phase_data {
12 enum fsp_notify_phase notify_phase;
Subrata Banike8feab02021-12-27 10:25:55 +000013 bool skip;
Angel Pons355d8442022-01-01 17:03:10 +010014 uint8_t post_code_before;
15 uint8_t post_code_after;
16 enum timestamp_id timestamp_before;
17 enum timestamp_id timestamp_after;
18};
19
20static const struct fsp_notify_phase_data notify_data[] = {
21 {
22 .notify_phase = AFTER_PCI_ENUM,
Subrata Banike8feab02021-12-27 10:25:55 +000023 .skip = CONFIG(SKIP_FSP_NOTIFY_PHASE_AFTER_PCI_ENUM),
Angel Pons355d8442022-01-01 17:03:10 +010024 .post_code_before = POST_FSP_NOTIFY_BEFORE_ENUMERATE,
25 .post_code_after = POST_FSP_NOTIFY_AFTER_ENUMERATE,
26 .timestamp_before = TS_FSP_BEFORE_ENUMERATE,
27 .timestamp_after = TS_FSP_AFTER_ENUMERATE,
28 },
29 {
30 .notify_phase = READY_TO_BOOT,
Subrata Banike8feab02021-12-27 10:25:55 +000031 .skip = CONFIG(SKIP_FSP_NOTIFY_PHASE_READY_TO_BOOT),
Angel Pons355d8442022-01-01 17:03:10 +010032 .post_code_before = POST_FSP_NOTIFY_BEFORE_FINALIZE,
33 .post_code_after = POST_FSP_NOTIFY_AFTER_FINALIZE,
34 .timestamp_before = TS_FSP_BEFORE_FINALIZE,
35 .timestamp_after = TS_FSP_AFTER_FINALIZE,
36 },
37 {
38 .notify_phase = END_OF_FIRMWARE,
Subrata Banike8feab02021-12-27 10:25:55 +000039 .skip = CONFIG(SKIP_FSP_NOTIFY_PHASE_END_OF_FIRMWARE),
Angel Pons355d8442022-01-01 17:03:10 +010040 .post_code_before = POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE,
41 .post_code_after = POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE,
42 .timestamp_before = TS_FSP_BEFORE_END_OF_FIRMWARE,
43 .timestamp_after = TS_FSP_AFTER_END_OF_FIRMWARE,
44 },
45};
46
47static const struct fsp_notify_phase_data *get_notify_phase_data(enum fsp_notify_phase phase)
48{
49 for (size_t i = 0; i < ARRAY_SIZE(notify_data); i++) {
50 if (notify_data[i].notify_phase == phase)
51 return &notify_data[i];
52 }
53 die("Unknown FSP notify phase %u\n", phase);
54}
Andrey Petrov9de55cc2016-02-25 14:19:07 -080055
Lee Leahy806fa242016-08-01 13:55:02 -070056static void fsp_notify(enum fsp_notify_phase phase)
Andrey Petrov9de55cc2016-02-25 14:19:07 -080057{
Angel Pons355d8442022-01-01 17:03:10 +010058 const struct fsp_notify_phase_data *data = get_notify_phase_data(phase);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080059 struct fsp_notify_params notify_params = { .phase = phase };
Angel Pons654930e2022-01-01 17:08:00 +010060 fsp_notify_fn fspnotify;
61 uint32_t ret;
Andrey Petrov9de55cc2016-02-25 14:19:07 -080062
Subrata Banike8feab02021-12-27 10:25:55 +000063 if (data->skip) {
64 printk(BIOS_INFO, "coreboot skipped calling FSP notify phase: %08x.\n", phase);
65 return;
66 }
67
Lee Leahy9671faa2016-07-24 18:18:52 -070068 if (!fsps_hdr.notify_phase_entry_offset)
69 die("Notify_phase_entry_offset is zero!\n");
Andrey Petrov9de55cc2016-02-25 14:19:07 -080070
Angel Pons654930e2022-01-01 17:08:00 +010071 fspnotify = (void *)(uintptr_t)(fsps_hdr.image_base +
Andrey Petrov9de55cc2016-02-25 14:19:07 -080072 fsps_hdr.notify_phase_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070073 fsp_before_debug_notify(fspnotify, &notify_params);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080074
Angel Pons355d8442022-01-01 17:03:10 +010075 timestamp_add_now(data->timestamp_before);
76 post_code(data->post_code_before);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070077
Patrick Rudolph31218a42020-11-30 15:50:06 +010078 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +010079 ret = protected_mode_call_1arg(fspnotify, (uintptr_t)&notify_params);
80 else
81 ret = fspnotify(&notify_params);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070082
Angel Pons355d8442022-01-01 17:03:10 +010083 timestamp_add_now(data->timestamp_after);
84 post_code(data->post_code_after);
85
Lee Leahy672df162016-07-24 18:21:13 -070086 fsp_debug_after_notify(ret);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070087
Lee Leahy9671faa2016-07-24 18:18:52 -070088 /* Handle any errors returned by FspNotify */
89 fsp_handle_reset(ret);
Angel Pons2b1f8d42022-01-01 17:20:00 +010090 if (ret != FSP_SUCCESS)
91 die("FspNotify returned with error 0x%08x!\n", ret);
Lee Leahy806fa242016-08-01 13:55:02 -070092
93 /* Allow the platform to run something after FspNotify */
94 platform_fsp_notify_status(phase);
95}
96
97static void fsp_notify_dummy(void *arg)
98{
Patrick Rudolph90fda022020-11-30 13:44:17 +010099 enum fsp_notify_phase phase = (uint32_t)(uintptr_t)arg;
Lee Leahy806fa242016-08-01 13:55:02 -0700100
Nico Huberd67edca2018-11-13 19:28:07 +0100101 display_mtrrs();
Lee Leahy806fa242016-08-01 13:55:02 -0700102
103 fsp_notify(phase);
104 if (phase == READY_TO_BOOT)
105 fsp_notify(END_OF_FIRMWARE);
106}
107
Angel Pons654930e2022-01-01 17:08:00 +0100108BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fsp_notify_dummy, (void *)AFTER_PCI_ENUM);
109BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, fsp_notify_dummy, (void *)READY_TO_BOOT);
110BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, fsp_notify_dummy, (void *)READY_TO_BOOT);
Lee Leahy806fa242016-08-01 13:55:02 -0700111
Angel Pons654930e2022-01-01 17:08:00 +0100112__weak void platform_fsp_notify_status(enum fsp_notify_phase phase)
Lee Leahy806fa242016-08-01 13:55:02 -0700113{
Andrey Petrov9de55cc2016-02-25 14:19:07 -0800114}