1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
4 #include <stage_cache.h>
7 #include <console/console.h>
8 #include <soc/southbridge.h>
9 #include <amdblocks/s3_resume.h>
10 #include <amdblocks/acpi.h>
12 /* Training data versioning is not supported or tracked. */
13 #define DEFAULT_MRC_VERSION 0
15 static void __noreturn
reboot_from_resume(const char *message
)
17 printk(BIOS_ERR
, "%s", message
);
22 AGESA_STATUS
OemInitResume(S3_DATA_BLOCK
*dataBlock
)
27 uint32_t erased
= 0xffffffff;
29 base
= mrc_cache_current_mmap_leak(MRC_TRAINING_DATA
,
33 reboot_from_resume("Error: S3 NV data not found, rebooting.\n");
35 /* Read 16 bytes to infer if the NV has been erased from flash. */
36 for (i
= 0; i
< 4; i
++)
37 erased
&= read32((uint32_t *)base
+ i
);
38 if (erased
== 0xffffffff)
39 reboot_from_resume("Error: S3 NV data invalid, rebooting.\n");
41 dataBlock
->NvStorage
= base
;
42 dataBlock
->NvStorageSize
= size
;
43 printk(BIOS_SPEW
, "S3 NV data @%p, 0x%0zx bytes\n",
44 dataBlock
->NvStorage
, (size_t)dataBlock
->NvStorageSize
);
49 AGESA_STATUS
OemS3LateRestore(S3_DATA_BLOCK
*dataBlock
)
54 stage_cache_get_raw(STAGE_S3_DATA
, &base
, &size
);
56 printk(BIOS_ERR
, "S3 volatile data not found\n");
60 dataBlock
->VolatileStorage
= base
;
61 dataBlock
->VolatileStorageSize
= size
;
62 printk(BIOS_SPEW
, "S3 volatile data @%p, 0x%0zx bytes\n",
63 dataBlock
->VolatileStorage
, (size_t)dataBlock
->VolatileStorageSize
);
68 AGESA_STATUS
OemS3Save(S3_DATA_BLOCK
*dataBlock
)
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
;
76 stage_cache_add_raw(STAGE_S3_DATA
, dataBlock
->VolatileStorage
,
77 dataBlock
->VolatileStorageSize
);