Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * 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. |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <string.h> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <console/console.h> |
| 20 | #include <cbmem.h> |
| 21 | #include <cpu/x86/smm.h> |
| 22 | |
| 23 | void *backup_default_smm_area(void) |
| 24 | { |
| 25 | void *save_area; |
| 26 | const void *default_smm = (void *)SMM_DEFAULT_BASE; |
| 27 | |
| 28 | if (!IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) |
| 29 | return NULL; |
| 30 | |
| 31 | /* |
| 32 | * The buffer needs to be preallocated regardless. In the non-resume |
| 33 | * path it will be allocated for handling resume. Note that cbmem_add() |
| 34 | * does a find before the addition. |
| 35 | */ |
| 36 | save_area = cbmem_add(CBMEM_ID_SMM_SAVE_SPACE, SMM_DEFAULT_SIZE); |
| 37 | |
| 38 | if (save_area == NULL) { |
| 39 | printk(BIOS_DEBUG, "SMM save area not added.\n"); |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | /* Only back up the area on S3 resume. */ |
Kyösti Mälkki | c3c4a38 | 2014-06-20 05:21:30 +0300 | [diff] [blame] | 44 | if (acpi_is_wakeup_s3()) { |
Aaron Durbin | b4b9eb3 | 2014-02-13 10:26:18 -0600 | [diff] [blame] | 45 | memcpy(save_area, default_smm, SMM_DEFAULT_SIZE); |
| 46 | return save_area; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Not the S3 resume path. No need to restore memory contents after |
| 51 | * SMM relocation. |
| 52 | */ |
| 53 | return NULL; |
| 54 | } |
| 55 | |
| 56 | void restore_default_smm_area(void *smm_save_area) |
| 57 | { |
| 58 | void *default_smm = (void *)SMM_DEFAULT_BASE; |
| 59 | |
| 60 | if (smm_save_area == NULL) |
| 61 | return; |
| 62 | |
| 63 | memcpy(default_smm, smm_save_area, SMM_DEFAULT_SIZE); |
| 64 | } |