blob: cbccc6eacf50f46fb96577c27ceab245871df15d [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>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -07007#include <timestamp.h>
Patrick Rudolph40beb362020-12-01 10:08:38 +01008#include <mode_switch.h>
Andrey Petrov9de55cc2016-02-25 14:19:07 -08009
Lee Leahy806fa242016-08-01 13:55:02 -070010static void fsp_notify(enum fsp_notify_phase phase)
Andrey Petrov9de55cc2016-02-25 14:19:07 -080011{
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070012 uint32_t ret;
Andrey Petrov9de55cc2016-02-25 14:19:07 -080013 fsp_notify_fn fspnotify;
14 struct fsp_notify_params notify_params = { .phase = phase };
15
Lee Leahy9671faa2016-07-24 18:18:52 -070016 if (!fsps_hdr.notify_phase_entry_offset)
17 die("Notify_phase_entry_offset is zero!\n");
Andrey Petrov9de55cc2016-02-25 14:19:07 -080018
Patrick Rudolph31218a42020-11-30 15:50:06 +010019 fspnotify = (void *) (uintptr_t)(fsps_hdr.image_base +
Andrey Petrov9de55cc2016-02-25 14:19:07 -080020 fsps_hdr.notify_phase_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070021 fsp_before_debug_notify(fspnotify, &notify_params);
Andrey Petrov9de55cc2016-02-25 14:19:07 -080022
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070023 if (phase == AFTER_PCI_ENUM) {
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070024 timestamp_add_now(TS_FSP_BEFORE_ENUMERATE);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070025 post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE);
26 } else if (phase == READY_TO_BOOT) {
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070027 timestamp_add_now(TS_FSP_BEFORE_FINALIZE);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070028 post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE);
Aaron Durbin96b3c6f2016-11-10 21:09:25 -060029 } 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 Gagniucc4ea8f72016-05-23 12:16:58 -070032 }
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070033
Patrick Rudolph31218a42020-11-30 15:50:06 +010034 if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32))
Patrick Rudolph40beb362020-12-01 10:08:38 +010035 ret = protected_mode_call_1arg(fspnotify, (uintptr_t)&notify_params);
36 else
37 ret = fspnotify(&notify_params);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070038
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070039 if (phase == AFTER_PCI_ENUM) {
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070040 timestamp_add_now(TS_FSP_AFTER_ENUMERATE);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070041 post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE);
42 } else if (phase == READY_TO_BOOT) {
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070043 timestamp_add_now(TS_FSP_AFTER_FINALIZE);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070044 post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE);
Aaron Durbin96b3c6f2016-11-10 21:09:25 -060045 } 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 Gagniucc4ea8f72016-05-23 12:16:58 -070048 }
Lee Leahy672df162016-07-24 18:21:13 -070049 fsp_debug_after_notify(ret);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070050
Lee Leahy9671faa2016-07-24 18:18:52 -070051 /* Handle any errors returned by FspNotify */
52 fsp_handle_reset(ret);
53 if (ret != FSP_SUCCESS) {
54 printk(BIOS_SPEW, "FspNotify returned 0x%08x\n", ret);
55 die("FspNotify returned an error!\n");
56 }
Lee Leahy806fa242016-08-01 13:55:02 -070057
58 /* Allow the platform to run something after FspNotify */
59 platform_fsp_notify_status(phase);
60}
61
62static void fsp_notify_dummy(void *arg)
63{
Patrick Rudolph90fda022020-11-30 13:44:17 +010064 enum fsp_notify_phase phase = (uint32_t)(uintptr_t)arg;
Lee Leahy806fa242016-08-01 13:55:02 -070065
Nico Huberd67edca2018-11-13 19:28:07 +010066 display_mtrrs();
Lee Leahy806fa242016-08-01 13:55:02 -070067
68 fsp_notify(phase);
69 if (phase == READY_TO_BOOT)
70 fsp_notify(END_OF_FIRMWARE);
71}
72
Subrata Banik3f3025d2017-08-18 15:05:05 +053073BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fsp_notify_dummy,
Lee Leahy806fa242016-08-01 13:55:02 -070074 (void *) AFTER_PCI_ENUM);
75BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, fsp_notify_dummy,
76 (void *) READY_TO_BOOT);
77BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, fsp_notify_dummy,
78 (void *) READY_TO_BOOT);
79
Aaron Durbin64031672018-04-21 14:45:32 -060080__weak void platform_fsp_notify_status(
Lee Leahy806fa242016-08-01 13:55:02 -070081 enum fsp_notify_phase phase)
82{
Andrey Petrov9de55cc2016-02-25 14:19:07 -080083}