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