From e236bf0750d8ecd19d1d560e0068d1948f718f49 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Thu, 13 Feb 2014 10:26:18 -0600 Subject: [PATCH] BACKPORT: x86: provide infrastructure to backup default SMM region Certain CPUs require the default SMM region to be backed up on resume after a suspend. The reason is that in order to relocate the SMM region the default SMM region has to be used. As coreboot is unaware of how that memory is used it needs to be backed up. Therefore provide a common method for doing this. BUG=chrome-os-partner:26563 BRANCH=baytrail TEST=Confirmed SMM backup region in cbmem. Suspend and Resumed. Change-Id: I65fe1317dc0b2203cb29118564fdba995770ffea Signed-off-by: Aaron Durbin Reviewed-on: https://chromium-review.googlesource.com/188716 Reviewed-by: Marc Jones --- src/cpu/x86/Kconfig | 6 +++ src/cpu/x86/smm/Makefile.inc | 2 + src/cpu/x86/smm/backup_default_smm.c | 68 ++++++++++++++++++++++++++++ src/include/cbmem.h | 1 + src/include/cpu/x86/smm.h | 4 ++ src/lib/cbmem_info.c | 1 + 6 files changed, 82 insertions(+) create mode 100644 src/cpu/x86/smm/backup_default_smm.c diff --git a/src/cpu/x86/Kconfig b/src/cpu/x86/Kconfig index 21282c321a..98238d8f06 100644 --- a/src/cpu/x86/Kconfig +++ b/src/cpu/x86/Kconfig @@ -122,3 +122,9 @@ config PARALLEL_MP This option uses common MP infrastructure for bringing up APs in parallel. It additionally provides a more flexible mechanism for sequencing the steps of bringing up the APs. + +config BACKUP_DEFAULT_SMM_REGION + def_bool n + help + The cpu support will select this option if the default SMM region + needs to be backed up for suspend/resume purposes. diff --git a/src/cpu/x86/smm/Makefile.inc b/src/cpu/x86/smm/Makefile.inc index b595a36924..8dcd130117 100644 --- a/src/cpu/x86/smm/Makefile.inc +++ b/src/cpu/x86/smm/Makefile.inc @@ -17,6 +17,8 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## +ramstage-$(CONFIG_BACKUP_DEFAULT_SMM_REGION) += backup_default_smm.c + ifeq ($(CONFIG_SMM_MODULES),y) smmstub-y += smm_stub.S smmstub-y += smm_module_header.c diff --git a/src/cpu/x86/smm/backup_default_smm.c b/src/cpu/x86/smm/backup_default_smm.c new file mode 100644 index 0000000000..ef1d3a9e41 --- /dev/null +++ b/src/cpu/x86/smm/backup_default_smm.c @@ -0,0 +1,68 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2014 Google Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of + * the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include + +void *backup_default_smm_area(void) +{ + void *save_area; + const void *default_smm = (void *)SMM_DEFAULT_BASE; + + if (!IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) + return NULL; + + /* + * The buffer needs to be preallocated regardless. In the non-resume + * path it will be allocated for handling resume. Note that cbmem_add() + * does a find before the addition. + */ + save_area = cbmem_add(CBMEM_ID_SMM_SAVE_SPACE, SMM_DEFAULT_SIZE); + + if (save_area == NULL) { + printk(BIOS_DEBUG, "SMM save area not added.\n"); + return NULL; + } + + /* Only back up the area on S3 resume. */ + if (acpi_slp_type == 3) { + memcpy(save_area, default_smm, SMM_DEFAULT_SIZE); + return save_area; + } + + /* + * Not the S3 resume path. No need to restore memory contents after + * SMM relocation. + */ + return NULL; +} + +void restore_default_smm_area(void *smm_save_area) +{ + void *default_smm = (void *)SMM_DEFAULT_BASE; + + if (smm_save_area == NULL) + return; + + memcpy(default_smm, smm_save_area, SMM_DEFAULT_SIZE); +} diff --git a/src/include/cbmem.h b/src/include/cbmem.h index 62e74bc44d..70d2f5f620 100644 --- a/src/include/cbmem.h +++ b/src/include/cbmem.h @@ -74,6 +74,7 @@ #define CBMEM_ID_REFCODE_CACHE 0x4efc0de5 #define CBMEM_ID_POWER_STATE 0x50535454 #define CBMEM_ID_RAM_OOPS 0x05430095 +#define CBMEM_ID_SMM_SAVE_SPACE 0x07e9acee #define CBMEM_ID_NONE 0x00000000 #ifndef __ASSEMBLER__ diff --git a/src/include/cpu/x86/smm.h b/src/include/cpu/x86/smm.h index e268b2e7f8..d938aa4f65 100644 --- a/src/include/cpu/x86/smm.h +++ b/src/include/cpu/x86/smm.h @@ -571,4 +571,8 @@ int smm_load_module(void *smram, int size, struct smm_loader_params *params); #endif /* __SMM__ */ #endif /* CONFIG_SMM_MODULES */ +/* Backup and restore default SMM region. */ +void *backup_default_smm_area(void); +void restore_default_smm_area(void *smm_save_area); + #endif diff --git a/src/lib/cbmem_info.c b/src/lib/cbmem_info.c index d6d3b69273..ca4c44cd7f 100644 --- a/src/lib/cbmem_info.c +++ b/src/lib/cbmem_info.c @@ -48,6 +48,7 @@ static struct cbmem_id_to_name { { CBMEM_ID_VBOOT_HANDOFF, "VBOOT " }, { CBMEM_ID_CAR_GLOBALS, "CAR GLOBALS" }, { CBMEM_ID_REFCODE, "REFCODE " }, + { CBMEM_ID_SMM_SAVE_SPACE, "SMM BACKUP " }, { CBMEM_ID_REFCODE_CACHE, "REFCODE $ " }, { CBMEM_ID_POWER_STATE, "POWER STATE" }, { CBMEM_ID_RAM_OOPS, "RAMOOPS " },