blob: cdace3190594ce34384ea57216b6f5edb87b1b62 [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;
13 uint8_t post_code_before;
14 uint8_t post_code_after;
15 enum timestamp_id timestamp_before;
16 enum timestamp_id timestamp_after;
17};
18
19static const struct fsp_notify_phase_data notify_data[] = {
20 {
21 .notify_phase = AFTER_PCI_ENUM,
22 .post_code_before = POST_FSP_NOTIFY_BEFORE_ENUMERATE,
23 .post_code_after = POST_FSP_NOTIFY_AFTER_ENUMERATE,
24 .timestamp_before = TS_FSP_BEFORE_ENUMERATE,
25 .timestamp_after = TS_FSP_AFTER_ENUMERATE,
26 },
27 {
28 .notify_phase = READY_TO_BOOT,
29 .post_code_before = POST_FSP_NOTIFY_BEFORE_FINALIZE,
30 .post_code_after = POST_FSP_NOTIFY_AFTER_FINALIZE,
31 .timestamp_before = TS_FSP_BEFORE_FINALIZE,
32 .timestamp_after = TS_FSP_AFTER_FINALIZE,
33 },
34 {
35 .notify_phase = END_OF_FIRMWARE,
36 .post_code_before = POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE,
37 .post_code_after = POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE,
38 .timestamp_before = TS_FSP_BEFORE_END_OF_FIRMWARE,
39 .timestamp_after = TS_FSP_AFTER_END_OF_FIRMWARE,
40 },
41};
42
43static const struct fsp_notify_phase_data *get_notify_phase_data(enum fsp_notify_phase phase)
44{
45 for (size_t i = 0; i < ARRAY_SIZE(notify_data); i++) {
46 if (notify_data[i].notify_phase == phase)
47 return &notify_data[i];
48 }
49 die("Unknown FSP notify phase %u\n", phase);
50}
Andrey Petrov9de55cc2016-02-25 14:19:07 -080051
Lee Leahy806fa242016-08-01 13:55:02 -070052static void fsp_notify(enum fsp_notify_phase phase)
Andrey Petrov9de55cc2016-02-25 14:19:07 -080053{
Angel Pons355d8442022-01-01 17:03:10 +010054 const struct fsp_notify_phase_data *data = get_notify_phase_data(phase);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080055 struct fsp_notify_params notify_params = { .phase = phase };
Angel Pons654930e2022-01-01 17:08:00 +010056 fsp_notify_fn fspnotify;
57 uint32_t ret;
Andrey Petrov9de55cc2016-02-25 14:19:07 -080058
Lee Leahy9671faa2016-07-24 18:18:52 -070059 if (!fsps_hdr.notify_phase_entry_offset)
60 die("Notify_phase_entry_offset is zero!\n");
Andrey Petrov9de55cc2016-02-25 14:19:07 -080061
Angel Pons654930e2022-01-01 17:08:00 +010062 fspnotify = (void *)(uintptr_t)(fsps_hdr.image_base +
Andrey Petrov9de55cc2016-02-25 14:19:07 -080063 fsps_hdr.notify_phase_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070064 fsp_before_debug_notify(fspnotify, &notify_params);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080065
Angel Pons355d8442022-01-01 17:03:10 +010066 timestamp_add_now(data->timestamp_before);
67 post_code(data->post_code_before);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070068
Patrick Rudolph31218a42020-11-30 15:50:06 +010069 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +010070 ret = protected_mode_call_1arg(fspnotify, (uintptr_t)&notify_params);
71 else
72 ret = fspnotify(&notify_params);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070073
Angel Pons355d8442022-01-01 17:03:10 +010074 timestamp_add_now(data->timestamp_after);
75 post_code(data->post_code_after);
76
Lee Leahy672df162016-07-24 18:21:13 -070077 fsp_debug_after_notify(ret);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070078
Lee Leahy9671faa2016-07-24 18:18:52 -070079 /* Handle any errors returned by FspNotify */
80 fsp_handle_reset(ret);
Angel Pons2b1f8d42022-01-01 17:20:00 +010081 if (ret != FSP_SUCCESS)
82 die("FspNotify returned with error 0x%08x!\n", ret);
Lee Leahy806fa242016-08-01 13:55:02 -070083
84 /* Allow the platform to run something after FspNotify */
85 platform_fsp_notify_status(phase);
86}
87
88static void fsp_notify_dummy(void *arg)
89{
Patrick Rudolph90fda022020-11-30 13:44:17 +010090 enum fsp_notify_phase phase = (uint32_t)(uintptr_t)arg;
Lee Leahy806fa242016-08-01 13:55:02 -070091
Nico Huberd67edca2018-11-13 19:28:07 +010092 display_mtrrs();
Lee Leahy806fa242016-08-01 13:55:02 -070093
94 fsp_notify(phase);
95 if (phase == READY_TO_BOOT)
96 fsp_notify(END_OF_FIRMWARE);
97}
98
Angel Pons654930e2022-01-01 17:08:00 +010099BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fsp_notify_dummy, (void *)AFTER_PCI_ENUM);
100BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, fsp_notify_dummy, (void *)READY_TO_BOOT);
101BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, fsp_notify_dummy, (void *)READY_TO_BOOT);
Lee Leahy806fa242016-08-01 13:55:02 -0700102
Angel Pons654930e2022-01-01 17:08:00 +0100103__weak void platform_fsp_notify_status(enum fsp_notify_phase phase)
Lee Leahy806fa242016-08-01 13:55:02 -0700104{
Andrey Petrov9de55cc2016-02-25 14:19:07 -0800105}