blob: 4883fa5597f9e710d96b42980689e8bd7637e5bb [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
17#include <cbmem.h>
18#include <stage_cache.h>
19#include <mrc_cache.h>
20#include <console/console.h>
21#include <amdblocks/s3_resume.h>
22
23/* Training data versioning is not supported or tracked. */
24#define DEFAULT_MRC_VERSION 0
25
26void get_s3nv_info(void **base, size_t *size)
27{
28 struct region_device rdev;
29
30 mrc_cache_get_current(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, &rdev);
31 *base = rdev_mmap_full(&rdev);
32 *size = region_device_sz(&rdev);
33 if (!*base || !*size)
34 printk(BIOS_ERR, "Error: S3 NV data not found\n");
35 else
36 printk(BIOS_SPEW, "S3 NV data @0x%p 0x%0zx total bytes\n",
37 *base, *size);
38}
39
40void get_s3vol_info(void **base, size_t *size)
41{
42 stage_cache_get_raw(STAGE_S3_DATA, base, size);
43 if (!*base || !*size)
44 printk(BIOS_ERR, "Error: S3 volatile data not found\n");
45 else
46 printk(BIOS_SPEW, "S3 volatile data @0x%p 0x%0zx total bytes\n",
47 *base, *size);
48}
49
50int save_s3_info(void *nv_base, size_t nv_size, void *vol_base, size_t vol_size)
51{
52 if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION,
53 nv_base, nv_size) < 0) {
54 printk(BIOS_ERR, "Failed to stash MRC data\n");
55 return -1;
56 }
57
58 stage_cache_add_raw(STAGE_S3_DATA, vol_base, vol_size);
59 return 0;
60}