Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 4 | #include <cbmem.h> |
Elyes Haouas | 45d3205 | 2022-10-07 10:07:12 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 6 | #include <cpu/x86/smm.h> |
Elyes Haouas | 45d3205 | 2022-10-07 10:07:12 +0200 | [diff] [blame] | 7 | #include <string.h> |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 8 | |
| 9 | void *backup_default_smm_area(void) |
| 10 | { |
| 11 | void *save_area; |
| 12 | const void *default_smm = (void *)SMM_DEFAULT_BASE; |
| 13 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 14 | if (!CONFIG(HAVE_ACPI_RESUME)) |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 15 | return NULL; |
| 16 | |
| 17 | /* |
| 18 | * The buffer needs to be preallocated regardless. In the non-resume |
| 19 | * path it will be allocated for handling resume. Note that cbmem_add() |
| 20 | * does a find before the addition. |
| 21 | */ |
| 22 | save_area = cbmem_add(CBMEM_ID_SMM_SAVE_SPACE, SMM_DEFAULT_SIZE); |
| 23 | |
| 24 | if (save_area == NULL) { |
| 25 | printk(BIOS_DEBUG, "SMM save area not added.\n"); |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | /* Only back up the area on S3 resume. */ |
Kyösti Mälkki | c3c4a38 | 2014-06-20 05:21:30 +0300 | [diff] [blame] | 30 | if (acpi_is_wakeup_s3()) { |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 31 | memcpy(save_area, default_smm, SMM_DEFAULT_SIZE); |
| 32 | return save_area; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * Not the S3 resume path. No need to restore memory contents after |
| 37 | * SMM relocation. |
| 38 | */ |
| 39 | return NULL; |
| 40 | } |
| 41 | |
| 42 | void restore_default_smm_area(void *smm_save_area) |
| 43 | { |
| 44 | void *default_smm = (void *)SMM_DEFAULT_BASE; |
| 45 | |
| 46 | if (smm_save_area == NULL) |
| 47 | return; |
| 48 | |
| 49 | memcpy(default_smm, smm_save_area, SMM_DEFAULT_SIZE); |
| 50 | } |