From 355d8444a8ffb70a4a09aaad0e4b3ab15ffedc56 Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Sat, 1 Jan 2022 17:03:10 +0100 Subject: [PATCH] drivers/intel/fsp2_0/notify.c: Group per-phase data Group all data specific to each notify phase in a struct to avoid redundant code. Change-Id: Ib4ab3d87edfcd5426ce35c168cbb780ade87290e Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/coreboot/+/60639 Tested-by: build bot (Jenkins) Reviewed-by: Felix Singer Reviewed-by: Tim Wawrzynczak Reviewed-by: Subrata Banik --- src/drivers/intel/fsp2_0/notify.c | 68 ++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/drivers/intel/fsp2_0/notify.c b/src/drivers/intel/fsp2_0/notify.c index b3563c0dbc..cdace31905 100644 --- a/src/drivers/intel/fsp2_0/notify.c +++ b/src/drivers/intel/fsp2_0/notify.c @@ -6,9 +6,52 @@ #include #include #include +#include + +struct fsp_notify_phase_data { + enum fsp_notify_phase notify_phase; + uint8_t post_code_before; + uint8_t post_code_after; + enum timestamp_id timestamp_before; + enum timestamp_id timestamp_after; +}; + +static const struct fsp_notify_phase_data notify_data[] = { + { + .notify_phase = AFTER_PCI_ENUM, + .post_code_before = POST_FSP_NOTIFY_BEFORE_ENUMERATE, + .post_code_after = POST_FSP_NOTIFY_AFTER_ENUMERATE, + .timestamp_before = TS_FSP_BEFORE_ENUMERATE, + .timestamp_after = TS_FSP_AFTER_ENUMERATE, + }, + { + .notify_phase = READY_TO_BOOT, + .post_code_before = POST_FSP_NOTIFY_BEFORE_FINALIZE, + .post_code_after = POST_FSP_NOTIFY_AFTER_FINALIZE, + .timestamp_before = TS_FSP_BEFORE_FINALIZE, + .timestamp_after = TS_FSP_AFTER_FINALIZE, + }, + { + .notify_phase = END_OF_FIRMWARE, + .post_code_before = POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE, + .post_code_after = POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE, + .timestamp_before = TS_FSP_BEFORE_END_OF_FIRMWARE, + .timestamp_after = TS_FSP_AFTER_END_OF_FIRMWARE, + }, +}; + +static const struct fsp_notify_phase_data *get_notify_phase_data(enum fsp_notify_phase phase) +{ + for (size_t i = 0; i < ARRAY_SIZE(notify_data); i++) { + if (notify_data[i].notify_phase == phase) + return ¬ify_data[i]; + } + die("Unknown FSP notify phase %u\n", phase); +} static void fsp_notify(enum fsp_notify_phase phase) { + const struct fsp_notify_phase_data *data = get_notify_phase_data(phase); struct fsp_notify_params notify_params = { .phase = phase }; fsp_notify_fn fspnotify; uint32_t ret; @@ -20,32 +63,17 @@ static void fsp_notify(enum fsp_notify_phase phase) fsps_hdr.notify_phase_entry_offset); fsp_before_debug_notify(fspnotify, ¬ify_params); - if (phase == AFTER_PCI_ENUM) { - timestamp_add_now(TS_FSP_BEFORE_ENUMERATE); - post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE); - } else if (phase == READY_TO_BOOT) { - timestamp_add_now(TS_FSP_BEFORE_FINALIZE); - post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE); - } else if (phase == END_OF_FIRMWARE) { - timestamp_add_now(TS_FSP_BEFORE_END_OF_FIRMWARE); - post_code(POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE); - } + timestamp_add_now(data->timestamp_before); + post_code(data->post_code_before); if (ENV_X86_64 && CONFIG(PLATFORM_USES_FSP2_X86_32)) ret = protected_mode_call_1arg(fspnotify, (uintptr_t)¬ify_params); else ret = fspnotify(¬ify_params); - if (phase == AFTER_PCI_ENUM) { - timestamp_add_now(TS_FSP_AFTER_ENUMERATE); - post_code(POST_FSP_NOTIFY_AFTER_ENUMERATE); - } else if (phase == READY_TO_BOOT) { - timestamp_add_now(TS_FSP_AFTER_FINALIZE); - post_code(POST_FSP_NOTIFY_AFTER_FINALIZE); - } else if (phase == END_OF_FIRMWARE) { - timestamp_add_now(TS_FSP_AFTER_END_OF_FIRMWARE); - post_code(POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE); - } + timestamp_add_now(data->timestamp_after); + post_code(data->post_code_after); + fsp_debug_after_notify(ret); /* Handle any errors returned by FspNotify */