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