blob: 2023aede746888e050be270c4f68f451aed8d68f [file] [log] [blame]
Aaron Durbinb4b9eb32014-02-13 10:26:18 -06001/*
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 Durbinb4b9eb32014-02-13 10:26:18 -060015 */
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
23void *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älkkic3c4a382014-06-20 05:21:30 +030044 if (acpi_is_wakeup_s3()) {
Aaron Durbinb4b9eb32014-02-13 10:26:18 -060045 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
56void 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}