Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 1 | /* |
| 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 Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 17 | #include <stage_cache.h> |
| 18 | #include <mrc_cache.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame^] | 19 | #include <reset.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 20 | #include <console/console.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame^] | 21 | #include <soc/southbridge.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 22 | #include <amdblocks/s3_resume.h> |
| 23 | |
| 24 | /* Training data versioning is not supported or tracked. */ |
| 25 | #define DEFAULT_MRC_VERSION 0 |
| 26 | |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame^] | 27 | static 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 Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 34 | void get_s3nv_info(void **base, size_t *size) |
| 35 | { |
| 36 | struct region_device rdev; |
| 37 | |
Richard Spiegel | 405f729 | 2018-02-14 10:18:17 -0700 | [diff] [blame] | 38 | if (mrc_cache_get_current(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame^] | 39 | &rdev)) |
| 40 | reboot_from_resume("mrc_cache_get_current error, rebooting.\n"); |
| 41 | |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 42 | *base = rdev_mmap_full(&rdev); |
| 43 | *size = region_device_sz(&rdev); |
| 44 | if (!*base || !*size) |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame^] | 45 | 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 Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void 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 | |
| 69 | int 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 | } |