coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
backup_default_smm.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <string.h>
4 #include <acpi/acpi.h>
5 #include <console/console.h>
6 #include <cbmem.h>
7 #include <cpu/x86/smm.h>
8 
10 {
11  void *save_area;
12  const void *default_smm = (void *)SMM_DEFAULT_BASE;
13 
14  if (!CONFIG(HAVE_ACPI_RESUME))
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  */
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. */
30  if (acpi_is_wakeup_s3()) {
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 }
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
void restore_default_smm_area(void *smm_save_area)
void * backup_default_smm_area(void)
void * cbmem_add(u32 id, u64 size)
Definition: imd_cbmem.c:144
#define CBMEM_ID_SMM_SAVE_SPACE
Definition: cbmem_id.h:55
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
#define SMM_DEFAULT_SIZE
Definition: smm.h:11
#define SMM_DEFAULT_BASE
Definition: smm.h:10
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define NULL
Definition: stddef.h:19