blob: 74aa79c39816613ac05e2744aff9d14583ccf1f2 [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
Marshall Dawsonf56249b2019-01-30 11:56:52 -070029static void reboot_from_resume(const char *message) /* Does not return */
30{
31 printk(BIOS_ERR, "%s", message);
32 set_pm1cnt_s5();
33 board_reset();
34}
35
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070036void get_s3nv_info(void **base, size_t *size)
37{
38 struct region_device rdev;
39
Richard Spiegel405f7292018-02-14 10:18:17 -070040 if (mrc_cache_get_current(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION,
Marshall Dawsonf56249b2019-01-30 11:56:52 -070041 &rdev))
42 reboot_from_resume("mrc_cache_get_current error, rebooting.\n");
43
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070044 *base = rdev_mmap_full(&rdev);
45 *size = region_device_sz(&rdev);
46 if (!*base || !*size)
Marshall Dawsonf56249b2019-01-30 11:56:52 -070047 reboot_from_resume("Error: S3 NV data not found, rebooting.\n");
48
49 /* Read 16 bytes to infer if the NV has been erased from flash. */
50 int i;
51 uint32_t erased = 0xffffffff;
52 for (i = 0; i < 4; i++)
53 erased &= read32((uint32_t *)*base + i);
54
55 if (erased == 0xffffffff)
56 reboot_from_resume("Error: S3 NV data invalid, rebooting.\n");
57
58 printk(BIOS_SPEW, "S3 NV data @0x%p, 0x%0zx bytes\n", *base, *size);
Marshall Dawson52f5cdc2018-01-30 15:28:14 -070059}
60
61void get_s3vol_info(void **base, size_t *size)
62{
63 stage_cache_get_raw(STAGE_S3_DATA, base, size);
64 if (!*base || !*size)
65 printk(BIOS_ERR, "Error: S3 volatile data not found\n");
66 else
67 printk(BIOS_SPEW, "S3 volatile data @0x%p 0x%0zx total bytes\n",
68 *base, *size);
69}
70
71int save_s3_info(void *nv_base, size_t nv_size, void *vol_base, size_t vol_size)
72{
73 if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION,
74 nv_base, nv_size) < 0) {
75 printk(BIOS_ERR, "Failed to stash MRC data\n");
76 return -1;
77 }
78
79 stage_cache_add_raw(STAGE_S3_DATA, vol_base, vol_size);
80 return 0;
81}