Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 90a54b0 | 2015-05-24 09:06:03 +0300 | [diff] [blame] | 2 | |
Kyösti Mälkki | 90a54b0 | 2015-05-24 09:06:03 +0300 | [diff] [blame] | 3 | #include <string.h> |
Kyösti Mälkki | f728408 | 2015-05-26 10:12:45 +0300 | [diff] [blame] | 4 | #include <cbmem.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 5 | #include <console/console.h> |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 6 | #include <mrc_cache.h> |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 7 | #include <northbridge/amd/agesa/state_machine.h> |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 8 | #include <AGESA.h> |
Kyösti Mälkki | da74041 | 2017-03-05 18:57:03 +0200 | [diff] [blame] | 9 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 10 | |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 11 | /* Training data versioning is not supported or tracked. */ |
| 12 | #define DEFAULT_MRC_VERSION 0 |
Kyösti Mälkki | 90a54b0 | 2015-05-24 09:06:03 +0300 | [diff] [blame] | 13 | |
Kyösti Mälkki | fa420b4 | 2017-03-26 11:35:23 +0300 | [diff] [blame] | 14 | AGESA_STATUS OemInitResume(AMD_S3_PARAMS *dataBlock) |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 15 | { |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 16 | void *nv_storage = NULL; |
| 17 | size_t nv_storage_size = 0; |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 18 | |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 19 | nv_storage = mrc_cache_current_mmap_leak(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
| 20 | &nv_storage_size); |
Kyösti Mälkki | 424c639 | 2017-03-29 15:53:54 +0300 | [diff] [blame] | 21 | |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 22 | if (nv_storage == NULL || nv_storage_size == 0) { |
| 23 | printk(BIOS_ERR, "%s: No valid MRC cache!\n", __func__); |
| 24 | return AGESA_CRITICAL; |
| 25 | } |
Kyösti Mälkki | 424c639 | 2017-03-29 15:53:54 +0300 | [diff] [blame] | 26 | |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 27 | dataBlock->NvStorage = nv_storage; |
| 28 | dataBlock->NvStorageSize = nv_storage_size; |
| 29 | |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 30 | return AGESA_SUCCESS; |
| 31 | } |
| 32 | |
Kyösti Mälkki | fa420b4 | 2017-03-26 11:35:23 +0300 | [diff] [blame] | 33 | AGESA_STATUS OemS3LateRestore(AMD_S3_PARAMS *dataBlock) |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 34 | { |
Kyösti Mälkki | 424c639 | 2017-03-29 15:53:54 +0300 | [diff] [blame] | 35 | char *heap = cbmem_find(CBMEM_ID_RESUME_SCRATCH); |
| 36 | if (heap == NULL) |
| 37 | return AGESA_FATAL; |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 38 | |
Kyösti Mälkki | 424c639 | 2017-03-29 15:53:54 +0300 | [diff] [blame] | 39 | printk(BIOS_DEBUG, "Using resume HEAP at %08x\n", |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 40 | (unsigned int)(uintptr_t)heap); |
Kyösti Mälkki | b1fcbf3 | 2015-05-26 11:25:13 +0300 | [diff] [blame] | 41 | |
Kyösti Mälkki | 424c639 | 2017-03-29 15:53:54 +0300 | [diff] [blame] | 42 | /* Return allocated CBMEM size, we do not keep track of |
| 43 | * how much was actually used. |
| 44 | */ |
| 45 | dataBlock->VolatileStorageSize = HIGH_MEMORY_SCRATCH; |
| 46 | dataBlock->VolatileStorage = heap; |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 47 | return AGESA_SUCCESS; |
| 48 | } |
| 49 | |
Kyösti Mälkki | fa420b4 | 2017-03-26 11:35:23 +0300 | [diff] [blame] | 50 | AGESA_STATUS OemS3Save(AMD_S3_PARAMS *dataBlock) |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 51 | { |
Arthur Heymans | b97a303 | 2020-08-07 22:30:04 +0200 | [diff] [blame] | 52 | if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
| 53 | dataBlock->NvStorage, dataBlock->NvStorageSize) < 0) { |
| 54 | printk(BIOS_ERR, "%s: Failed to stash MRC data\n", __func__); |
| 55 | return AGESA_CRITICAL; |
| 56 | } |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 57 | |
| 58 | /* To be consumed in AmdS3LateRestore. */ |
Kyösti Mälkki | c74b53f | 2015-05-26 15:38:58 +0300 | [diff] [blame] | 59 | char *heap = cbmem_add(CBMEM_ID_RESUME_SCRATCH, HIGH_MEMORY_SCRATCH); |
| 60 | if (heap) { |
| 61 | memset(heap, 0, HIGH_MEMORY_SCRATCH); |
| 62 | memcpy(heap, dataBlock->VolatileStorage, dataBlock->VolatileStorageSize); |
| 63 | } |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 64 | |
| 65 | /* Collect MTRR setup. */ |
Arthur Heymans | 750d57f | 2020-08-07 22:12:09 +0200 | [diff] [blame] | 66 | backup_mtrr(); |
Kyösti Mälkki | 300cace | 2014-12-16 19:50:47 +0200 | [diff] [blame] | 67 | |
| 68 | return AGESA_SUCCESS; |
| 69 | } |