Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <bootstate.h> |
| 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
| 7 | #include <fsp/util.h> |
| 8 | #include <mrc_cache.h> |
| 9 | |
| 10 | static void save_mrc_data(void *unused) |
| 11 | { |
| 12 | size_t mrc_data_size; |
| 13 | const void *mrc_data; |
Subrata Banik | f31ab7a | 2023-06-19 12:07:29 +0000 | [diff] [blame^] | 14 | uint32_t cbmem_id = CONFIG(MRC_CACHE_USING_MRC_VERSION) ? CBMEM_ID_MRC_VERSION : |
| 15 | CBMEM_ID_FSPM_VERSION; |
Subrata Banik | 79274e01 | 2023-06-19 11:32:19 +0000 | [diff] [blame] | 16 | uint32_t *version; |
Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 17 | |
| 18 | if (acpi_is_wakeup_s3()) |
| 19 | return; |
| 20 | |
Subrata Banik | f31ab7a | 2023-06-19 12:07:29 +0000 | [diff] [blame^] | 21 | version = cbmem_find(cbmem_id); |
Subrata Banik | 79274e01 | 2023-06-19 11:32:19 +0000 | [diff] [blame] | 22 | if (!version) { |
Subrata Banik | f31ab7a | 2023-06-19 12:07:29 +0000 | [diff] [blame^] | 23 | printk(BIOS_ERR, "Failed to read %s version from cbmem.\n", |
| 24 | CONFIG(MRC_CACHE_USING_MRC_VERSION) ? "MRC" : "FSP-M"); |
Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 25 | return; |
| 26 | } |
| 27 | |
| 28 | mrc_data = fsp_find_nv_storage_data(&mrc_data_size); |
| 29 | if (!mrc_data) { |
| 30 | printk(BIOS_ERR, "FSP_NON_VOLATILE_STORAGE_HOB missing!\n"); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * Save MRC data to SPI flash. By always saving the data this forces |
| 36 | * a retrain after a trip through ChromeOS recovery path. The |
| 37 | * code which saves the data to flash doesn't write if the latest |
| 38 | * training data matches this one. |
| 39 | */ |
Subrata Banik | 79274e01 | 2023-06-19 11:32:19 +0000 | [diff] [blame] | 40 | if (mrc_cache_stash_data(MRC_TRAINING_DATA, *version, mrc_data, |
Reka Norman | 7b5a931 | 2022-09-13 14:06:52 +1000 | [diff] [blame] | 41 | mrc_data_size) < 0) |
| 42 | printk(BIOS_ERR, "Failed to stash MRC data\n"); |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Should be done before ramstage_cse_fw_sync() to avoid traning memory twice on |
| 47 | * a cold boot after a full firmware update. |
| 48 | */ |
David Hendricks | 69b8194 | 2023-01-29 17:56:23 -0800 | [diff] [blame] | 49 | #if CONFIG(SAVE_MRC_AFTER_FSPS) |
Johnny Lin | 55bc2d3 | 2022-06-13 14:05:43 +0800 | [diff] [blame] | 50 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT_CHIPS, BS_ON_EXIT, save_mrc_data, NULL); |
David Hendricks | 69b8194 | 2023-01-29 17:56:23 -0800 | [diff] [blame] | 51 | #else |
| 52 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, save_mrc_data, NULL); |
Johnny Lin | 55bc2d3 | 2022-06-13 14:05:43 +0800 | [diff] [blame] | 53 | #endif |