Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 4 | #include <stage_cache.h> |
| 5 | #include <mrc_cache.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 6 | #include <reset.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 7 | #include <console/console.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 8 | #include <soc/southbridge.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 9 | #include <amdblocks/s3_resume.h> |
Marshall Dawson | 4ee83b2 | 2019-05-03 11:44:22 -0600 | [diff] [blame] | 10 | #include <amdblocks/acpi.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 11 | |
| 12 | /* Training data versioning is not supported or tracked. */ |
| 13 | #define DEFAULT_MRC_VERSION 0 |
| 14 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 15 | static void __noreturn reboot_from_resume(const char *message) |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 16 | { |
| 17 | printk(BIOS_ERR, "%s", message); |
| 18 | set_pm1cnt_s5(); |
| 19 | board_reset(); |
| 20 | } |
| 21 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 22 | AGESA_STATUS OemInitResume(S3_DATA_BLOCK *dataBlock) |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 23 | { |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 24 | void *base; |
| 25 | size_t size; |
| 26 | int i; |
| 27 | uint32_t erased = 0xffffffff; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 28 | |
Shelley Chen | ad9cd68 | 2020-07-23 16:10:52 -0700 | [diff] [blame] | 29 | base = mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, |
| 30 | DEFAULT_MRC_VERSION, |
| 31 | &size); |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 32 | if (!base || !size) |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 33 | reboot_from_resume("Error: S3 NV data not found, rebooting.\n"); |
| 34 | |
| 35 | /* Read 16 bytes to infer if the NV has been erased from flash. */ |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 36 | for (i = 0; i < 4; i++) |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 37 | erased &= read32((uint32_t *)base + i); |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 38 | if (erased == 0xffffffff) |
| 39 | reboot_from_resume("Error: S3 NV data invalid, rebooting.\n"); |
| 40 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 41 | dataBlock->NvStorage = base; |
| 42 | dataBlock->NvStorageSize = size; |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 43 | printk(BIOS_SPEW, "S3 NV data @%p, 0x%0zx bytes\n", |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 44 | dataBlock->NvStorage, (size_t)dataBlock->NvStorageSize); |
| 45 | |
| 46 | return AGESA_SUCCESS; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 49 | AGESA_STATUS OemS3LateRestore(S3_DATA_BLOCK *dataBlock) |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 50 | { |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 51 | void *base = NULL; |
| 52 | size_t size = 0; |
| 53 | |
| 54 | stage_cache_get_raw(STAGE_S3_DATA, &base, &size); |
| 55 | if (!base || !size) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame^] | 56 | printk(BIOS_ERR, "S3 volatile data not found\n"); |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 57 | return AGESA_FATAL; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 60 | dataBlock->VolatileStorage = base; |
| 61 | dataBlock->VolatileStorageSize = size; |
Julius Werner | 540a980 | 2019-12-09 13:03:29 -0800 | [diff] [blame] | 62 | printk(BIOS_SPEW, "S3 volatile data @%p, 0x%0zx bytes\n", |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame] | 63 | dataBlock->VolatileStorage, (size_t)dataBlock->VolatileStorageSize); |
| 64 | |
| 65 | return AGESA_SUCCESS; |
| 66 | } |
| 67 | |
| 68 | AGESA_STATUS OemS3Save(S3_DATA_BLOCK *dataBlock) |
| 69 | { |
| 70 | if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
| 71 | dataBlock->NvStorage, dataBlock->NvStorageSize) < 0) { |
| 72 | printk(BIOS_ERR, "Failed to stash MRC data\n"); |
| 73 | return AGESA_CRITICAL; |
| 74 | } |
| 75 | |
| 76 | stage_cache_add_raw(STAGE_S3_DATA, dataBlock->VolatileStorage, |
| 77 | dataBlock->VolatileStorageSize); |
| 78 | |
| 79 | return AGESA_SUCCESS; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 80 | } |