blob: 598036acf29f4c6f57a56e593674e240d831d27b [file] [log] [blame]
Marshall Dawson52f5cdc2018-01-30 15:28:14 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012-2017 Advanced Micro Devices, Inc.
5 * Copyright (C) 2014 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
Kyösti Mälkki13f66502019-03-03 08:01:05 +020017#include <device/mmio.h>
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070018#include <stage_cache.h>
19#include <mrc_cache.h>
Marshall Dawsonf56249b2019-01-30 11:56:52 -070020#include <reset.h>
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070021#include <console/console.h>
Marshall Dawsonf56249b2019-01-30 11:56:52 -070022#include <soc/southbridge.h>
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070023#include <amdblocks/s3_resume.h>
Marshall Dawson4ee83b22019-05-03 11:44:22 -060024#include <amdblocks/acpi.h>
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070025
26/* Training data versioning is not supported or tracked. */
27#define DEFAULT_MRC_VERSION 0
28
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030029static void __noreturn reboot_from_resume(const char *message)
Marshall Dawsonf56249b2019-01-30 11:56:52 -070030{
31 printk(BIOS_ERR, "%s", message);
32 set_pm1cnt_s5();
33 board_reset();
34}
35
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030036AGESA_STATUS OemInitResume(S3_DATA_BLOCK *dataBlock)
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070037{
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030038 void *base;
39 size_t size;
40 int i;
41 uint32_t erased = 0xffffffff;
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070042 struct region_device rdev;
43
Richard Spiegel405f7292018-02-14 10:18:17 -070044 if (mrc_cache_get_current(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION,
Marshall Dawsonf56249b2019-01-30 11:56:52 -070045 &rdev))
46 reboot_from_resume("mrc_cache_get_current error, rebooting.\n");
47
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030048 base = rdev_mmap_full(&rdev);
49 size = region_device_sz(&rdev);
50 if (!base || !size)
Marshall Dawsonf56249b2019-01-30 11:56:52 -070051 reboot_from_resume("Error: S3 NV data not found, rebooting.\n");
52
53 /* Read 16 bytes to infer if the NV has been erased from flash. */
Marshall Dawsonf56249b2019-01-30 11:56:52 -070054 for (i = 0; i < 4; i++)
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030055 erased &= read32((uint32_t *)base + i);
Marshall Dawsonf56249b2019-01-30 11:56:52 -070056 if (erased == 0xffffffff)
57 reboot_from_resume("Error: S3 NV data invalid, rebooting.\n");
58
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030059 dataBlock->NvStorage = base;
60 dataBlock->NvStorageSize = size;
61 printk(BIOS_SPEW, "S3 NV data @0x%p, 0x%0zx bytes\n",
62 dataBlock->NvStorage, (size_t)dataBlock->NvStorageSize);
63
64 return AGESA_SUCCESS;
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070065}
66
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030067AGESA_STATUS OemS3LateRestore(S3_DATA_BLOCK *dataBlock)
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070068{
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030069 void *base = NULL;
70 size_t size = 0;
71
72 stage_cache_get_raw(STAGE_S3_DATA, &base, &size);
73 if (!base || !size) {
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070074 printk(BIOS_ERR, "Error: S3 volatile data not found\n");
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030075 return AGESA_FATAL;
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070076 }
77
Kyösti Mälkki66cabe72018-07-01 03:48:39 +030078 dataBlock->VolatileStorage = base;
79 dataBlock->VolatileStorageSize = size;
80 printk(BIOS_SPEW, "S3 volatile data @0x%p, 0x%0zx bytes\n",
81 dataBlock->VolatileStorage, (size_t)dataBlock->VolatileStorageSize);
82
83 return AGESA_SUCCESS;
84}
85
86AGESA_STATUS OemS3Save(S3_DATA_BLOCK *dataBlock)
87{
88 if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION,
89 dataBlock->NvStorage, dataBlock->NvStorageSize) < 0) {
90 printk(BIOS_ERR, "Failed to stash MRC data\n");
91 return AGESA_CRITICAL;
92 }
93
94 stage_cache_add_raw(STAGE_S3_DATA, dataBlock->VolatileStorage,
95 dataBlock->VolatileStorageSize);
96
97 return AGESA_SUCCESS;
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070098}