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 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 17 | #include <device/mmio.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 18 | #include <stage_cache.h> |
| 19 | #include <mrc_cache.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 20 | #include <reset.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 21 | #include <console/console.h> |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 22 | #include <soc/southbridge.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 23 | #include <amdblocks/s3_resume.h> |
Marshall Dawson | 4ee83b2 | 2019-05-03 11:44:22 -0600 | [diff] [blame] | 24 | #include <amdblocks/acpi.h> |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 25 | |
| 26 | /* Training data versioning is not supported or tracked. */ |
| 27 | #define DEFAULT_MRC_VERSION 0 |
| 28 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 29 | static void __noreturn reboot_from_resume(const char *message) |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 30 | { |
| 31 | printk(BIOS_ERR, "%s", message); |
| 32 | set_pm1cnt_s5(); |
| 33 | board_reset(); |
| 34 | } |
| 35 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 36 | AGESA_STATUS OemInitResume(S3_DATA_BLOCK *dataBlock) |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 37 | { |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 38 | void *base; |
| 39 | size_t size; |
| 40 | int i; |
| 41 | uint32_t erased = 0xffffffff; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 42 | struct region_device rdev; |
| 43 | |
Richard Spiegel | 405f729 | 2018-02-14 10:18:17 -0700 | [diff] [blame] | 44 | if (mrc_cache_get_current(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 45 | &rdev)) |
| 46 | reboot_from_resume("mrc_cache_get_current error, rebooting.\n"); |
| 47 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 48 | base = rdev_mmap_full(&rdev); |
| 49 | size = region_device_sz(&rdev); |
| 50 | if (!base || !size) |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 51 | reboot_from_resume("Error: S3 NV data not found, rebooting.\n"); |
| 52 | |
| 53 | /* Read 16 bytes to infer if the NV has been erased from flash. */ |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 54 | for (i = 0; i < 4; i++) |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 55 | erased &= read32((uint32_t *)base + i); |
Marshall Dawson | f56249b | 2019-01-30 11:56:52 -0700 | [diff] [blame] | 56 | if (erased == 0xffffffff) |
| 57 | reboot_from_resume("Error: S3 NV data invalid, rebooting.\n"); |
| 58 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 59 | dataBlock->NvStorage = base; |
| 60 | dataBlock->NvStorageSize = size; |
| 61 | printk(BIOS_SPEW, "S3 NV data @0x%p, 0x%0zx bytes\n", |
| 62 | dataBlock->NvStorage, (size_t)dataBlock->NvStorageSize); |
| 63 | |
| 64 | return AGESA_SUCCESS; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 67 | AGESA_STATUS OemS3LateRestore(S3_DATA_BLOCK *dataBlock) |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 68 | { |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 69 | void *base = NULL; |
| 70 | size_t size = 0; |
| 71 | |
| 72 | stage_cache_get_raw(STAGE_S3_DATA, &base, &size); |
| 73 | if (!base || !size) { |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 74 | printk(BIOS_ERR, "Error: S3 volatile data not found\n"); |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 75 | return AGESA_FATAL; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Kyösti Mälkki | 66cabe7 | 2018-07-01 03:48:39 +0300 | [diff] [blame^] | 78 | dataBlock->VolatileStorage = base; |
| 79 | dataBlock->VolatileStorageSize = size; |
| 80 | printk(BIOS_SPEW, "S3 volatile data @0x%p, 0x%0zx bytes\n", |
| 81 | dataBlock->VolatileStorage, (size_t)dataBlock->VolatileStorageSize); |
| 82 | |
| 83 | return AGESA_SUCCESS; |
| 84 | } |
| 85 | |
| 86 | AGESA_STATUS OemS3Save(S3_DATA_BLOCK *dataBlock) |
| 87 | { |
| 88 | if (mrc_cache_stash_data(MRC_TRAINING_DATA, DEFAULT_MRC_VERSION, |
| 89 | dataBlock->NvStorage, dataBlock->NvStorageSize) < 0) { |
| 90 | printk(BIOS_ERR, "Failed to stash MRC data\n"); |
| 91 | return AGESA_CRITICAL; |
| 92 | } |
| 93 | |
| 94 | stage_cache_add_raw(STAGE_S3_DATA, dataBlock->VolatileStorage, |
| 95 | dataBlock->VolatileStorageSize); |
| 96 | |
| 97 | return AGESA_SUCCESS; |
Marshall Dawson | 52f5cdc | 2018-01-30 15:28:14 -0700 | [diff] [blame] | 98 | } |