ACPI S3: Remove HIGH_MEMORY_SAVE where possible
Add implementation to use actual requirements of ramstage size for S3 resume backup in CBMEM. The backup covers complete pages of 4 KiB. Only the required amount of low memory is backed up when ACPI_TINY_LOWMEM_BACKUP is selected for the platform. Enable this option for AGESA and binaryPI, other platforms (without RELOCATABLE_RAMSTAGE) currently keep their romstage ramstack in low memory for s3 resume path. Change-Id: Ide7ce013f3727c2928cdb00fbcc7e7e84e859ff1 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/15255 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins) Tested-by: Raptor Engineering Automated Test Stand <noreply@raptorengineeringinc.com>
This commit is contained in:
parent
2c7ad8c8d3
commit
9d6f365643
13
src/Kconfig
13
src/Kconfig
|
@ -539,6 +539,19 @@ config HAVE_ACPI_RESUME
|
||||||
bool
|
bool
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config ACPI_TINY_LOWMEM_BACKUP
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
On S3 resume path, backup only the region of low memory ramstage
|
||||||
|
will occupy. Requires platform places romstage ramstack in CBMEM.
|
||||||
|
|
||||||
|
config ACPI_HUGE_LOWMEM_BACKUP
|
||||||
|
bool
|
||||||
|
default !ACPI_TINY_LOWMEM_BACKUP
|
||||||
|
help
|
||||||
|
On S3 resume path, backup low memory from RAMBASE..RAMTOP in CBMEM.
|
||||||
|
|
||||||
config RESUME_PATH_SAME_AS_BOOT
|
config RESUME_PATH_SAME_AS_BOOT
|
||||||
bool
|
bool
|
||||||
default y if ARCH_X86
|
default y if ARCH_X86
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
#include <cbmem.h>
|
#include <cbmem.h>
|
||||||
#include <cpu/cpu.h>
|
#include <cpu/cpu.h>
|
||||||
#include <timestamp.h>
|
#include <timestamp.h>
|
||||||
|
#include <program_loading.h>
|
||||||
#include <romstage_handoff.h>
|
#include <romstage_handoff.h>
|
||||||
#include <rules.h>
|
#include <rules.h>
|
||||||
|
#include <symbols.h>
|
||||||
|
|
||||||
#if ENV_RAMSTAGE
|
#if ENV_RAMSTAGE
|
||||||
|
|
||||||
|
@ -79,30 +81,125 @@ void acpi_fail_wakeup(void)
|
||||||
}
|
}
|
||||||
#endif /* ENV_RAMSTAGE */
|
#endif /* ENV_RAMSTAGE */
|
||||||
|
|
||||||
void acpi_prepare_for_resume(void)
|
struct resume_backup {
|
||||||
|
uint64_t cbmem;
|
||||||
|
uint64_t lowmem;
|
||||||
|
uint64_t size;
|
||||||
|
uint8_t valid;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BACKUP_PAGE_SZ 4096
|
||||||
|
|
||||||
|
static int backup_create_or_update(struct resume_backup *backup_mem,
|
||||||
|
uintptr_t base, size_t size)
|
||||||
{
|
{
|
||||||
if (!HIGH_MEMORY_SAVE)
|
uintptr_t top;
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_ACPI_HUGE_LOWMEM_BACKUP)) {
|
||||||
|
base = CONFIG_RAMBASE;
|
||||||
|
size = HIGH_MEMORY_SAVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Align backup region to complete pages. */
|
||||||
|
top = ALIGN_UP(base + size, BACKUP_PAGE_SZ);
|
||||||
|
base = ALIGN_DOWN(base, BACKUP_PAGE_SZ);
|
||||||
|
size = top - base;
|
||||||
|
|
||||||
|
/* Cannot extend existing region, should not happen. */
|
||||||
|
if (backup_mem && (backup_mem->size < size))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Allocate backup with room for header. */
|
||||||
|
if (!backup_mem) {
|
||||||
|
size_t header_sz = ALIGN_UP(sizeof(*backup_mem), BACKUP_PAGE_SZ);
|
||||||
|
backup_mem = cbmem_add(CBMEM_ID_RESUME, header_sz + size);
|
||||||
|
if (!backup_mem)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Container starts from boundary after header. */
|
||||||
|
backup_mem->cbmem = (uintptr_t)backup_mem + header_sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_mem->valid = 0;
|
||||||
|
backup_mem->lowmem = base;
|
||||||
|
backup_mem->size = size;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *acpi_backup_container(uintptr_t base, size_t size)
|
||||||
|
{
|
||||||
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
||||||
|
if (!backup_mem)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!IS_ALIGNED(base, BACKUP_PAGE_SZ) || !IS_ALIGNED(size, BACKUP_PAGE_SZ))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (backup_create_or_update(backup_mem, base, size) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
backup_mem->valid = 1;
|
||||||
|
return (void*)(uintptr_t)backup_mem->cbmem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void backup_ramstage_section(uintptr_t base, size_t size)
|
||||||
|
{
|
||||||
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
||||||
|
|
||||||
|
/* For first boot we exit here as CBMEM_ID_RESUME is only
|
||||||
|
* created late in ramstage with acpi_prepare_resume_backup().
|
||||||
|
*/
|
||||||
|
if (!backup_mem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Check that the backup is not done twice. */
|
||||||
|
if (backup_mem->valid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* When we are called from ramstage loader, update header with
|
||||||
|
* properties of the ramstage we will load.
|
||||||
|
*/
|
||||||
|
if (backup_create_or_update(backup_mem, base, size) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Back up the OS-controlled memory where ramstage will be loaded. */
|
/* Back up the OS-controlled memory where ramstage will be loaded. */
|
||||||
void *src = (void *)CONFIG_RAMBASE;
|
memcpy((void*)(uintptr_t)backup_mem->cbmem,
|
||||||
void *dest = cbmem_find(CBMEM_ID_RESUME);
|
(void*)(uintptr_t)backup_mem->lowmem, (size_t)backup_mem->size);
|
||||||
if (dest != NULL)
|
backup_mem->valid = 1;
|
||||||
memcpy(dest, src, HIGH_MEMORY_SAVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make backup of low-memory region, relying on the base and size
|
||||||
|
* of the ramstage that was loaded before entry to ACPI S3.
|
||||||
|
*
|
||||||
|
* DEPRECATED
|
||||||
|
*/
|
||||||
|
void acpi_prepare_for_resume(void)
|
||||||
|
{
|
||||||
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
||||||
|
if (!backup_mem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Back up the OS-controlled memory where ramstage will be loaded. */
|
||||||
|
memcpy((void*)(uintptr_t)backup_mem->cbmem,
|
||||||
|
(void*)(uintptr_t)backup_mem->lowmem, (size_t)backup_mem->size);
|
||||||
|
backup_mem->valid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Let's prepare the ACPI S3 Resume area now already, so we can rely on
|
||||||
|
* it being there during reboot time. If this fails, ACPI resume will
|
||||||
|
* be disabled. We assume that ramstage does not change while in suspend,
|
||||||
|
* so base and size of the currently running ramstage are used
|
||||||
|
* for allocation.
|
||||||
|
*/
|
||||||
void acpi_prepare_resume_backup(void)
|
void acpi_prepare_resume_backup(void)
|
||||||
{
|
{
|
||||||
if (!acpi_s3_resume_allowed())
|
if (!acpi_s3_resume_allowed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Let's prepare the ACPI S3 Resume area now already, so we can rely on
|
if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE))
|
||||||
* it being there during reboot time. We don't need the pointer, nor
|
return;
|
||||||
* the result right now. If it fails, ACPI resume will be disabled.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (HIGH_MEMORY_SAVE)
|
backup_create_or_update(NULL, (uintptr_t)_program, _program_size);
|
||||||
cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WAKEUP_BASE 0x600
|
#define WAKEUP_BASE 0x600
|
||||||
|
@ -115,17 +212,22 @@ extern unsigned int __wakeup_size;
|
||||||
|
|
||||||
static void acpi_jump_to_wakeup(void *vector)
|
static void acpi_jump_to_wakeup(void *vector)
|
||||||
{
|
{
|
||||||
uintptr_t acpi_backup_memory = 0;
|
uintptr_t source = 0, target = 0;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
if (!acpi_s3_resume_allowed()) {
|
if (!acpi_s3_resume_allowed()) {
|
||||||
printk(BIOS_WARNING, "ACPI: S3 resume not allowed.\n");
|
printk(BIOS_WARNING, "ACPI: S3 resume not allowed.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HIGH_MEMORY_SAVE) {
|
if (!IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
|
||||||
acpi_backup_memory = (uintptr_t)cbmem_find(CBMEM_ID_RESUME);
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
||||||
|
if (backup_mem && backup_mem->valid) {
|
||||||
if (!acpi_backup_memory) {
|
backup_mem->valid = 0;
|
||||||
|
target = backup_mem->lowmem;
|
||||||
|
source = backup_mem->cbmem;
|
||||||
|
size = backup_mem->size;
|
||||||
|
} else {
|
||||||
printk(BIOS_WARNING, "ACPI: Backup memory missing. "
|
printk(BIOS_WARNING, "ACPI: Backup memory missing. "
|
||||||
"No S3 resume.\n");
|
"No S3 resume.\n");
|
||||||
return;
|
return;
|
||||||
|
@ -137,8 +239,7 @@ static void acpi_jump_to_wakeup(void *vector)
|
||||||
|
|
||||||
timestamp_add_now(TS_ACPI_WAKE_JUMP);
|
timestamp_add_now(TS_ACPI_WAKE_JUMP);
|
||||||
|
|
||||||
acpi_do_wakeup((uintptr_t)vector, acpi_backup_memory, CONFIG_RAMBASE,
|
acpi_do_wakeup((uintptr_t)vector, source, target, size);
|
||||||
HIGH_MEMORY_SAVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((weak)) mainboard_suspend_resume(void)
|
void __attribute__((weak)) mainboard_suspend_resume(void)
|
||||||
|
|
|
@ -25,12 +25,7 @@
|
||||||
#ifndef __ASM_ACPI_H
|
#ifndef __ASM_ACPI_H
|
||||||
#define __ASM_ACPI_H
|
#define __ASM_ACPI_H
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && \
|
|
||||||
! IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)
|
|
||||||
#define HIGH_MEMORY_SAVE (CONFIG_RAMTOP - CONFIG_RAMBASE)
|
#define HIGH_MEMORY_SAVE (CONFIG_RAMTOP - CONFIG_RAMBASE)
|
||||||
#else
|
|
||||||
#define HIGH_MEMORY_SAVE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_ACPI_INTEL_HARDWARE_SLEEP_VALUES)
|
#if IS_ENABLED(CONFIG_ACPI_INTEL_HARDWARE_SLEEP_VALUES)
|
||||||
/*
|
/*
|
||||||
|
@ -688,6 +683,13 @@ static inline int acpi_s3_resume_allowed(void)
|
||||||
return IS_ENABLED(CONFIG_HAVE_ACPI_RESUME);
|
return IS_ENABLED(CONFIG_HAVE_ACPI_RESUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return address in reserved memory where to backup low memory
|
||||||
|
* while platform resumes from S3 suspend. Caller is responsible of
|
||||||
|
* making a complete copy of the region base..base+size, with
|
||||||
|
* parameteres base and size that meet page alignment requirement.
|
||||||
|
*/
|
||||||
|
void *acpi_backup_container(uintptr_t base, size_t size);
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
|
#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)
|
||||||
extern int acpi_slp_type;
|
extern int acpi_slp_type;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ config CPU_AMD_AGESA
|
||||||
select UDELAY_LAPIC
|
select UDELAY_LAPIC
|
||||||
select LAPIC_MONOTONIC_TIMER
|
select LAPIC_MONOTONIC_TIMER
|
||||||
select SPI_FLASH if HAVE_ACPI_RESUME
|
select SPI_FLASH if HAVE_ACPI_RESUME
|
||||||
|
select ACPI_TINY_LOWMEM_BACKUP
|
||||||
|
|
||||||
if CPU_AMD_AGESA
|
if CPU_AMD_AGESA
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ static void prepare_romstage_ramstack(int s3resume)
|
||||||
print_car_debug("Prepare CAR migration and stack regions...");
|
print_car_debug("Prepare CAR migration and stack regions...");
|
||||||
|
|
||||||
if (s3resume) {
|
if (s3resume) {
|
||||||
void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
|
void *resume_backup_memory = acpi_backup_container(CONFIG_RAMBASE, HIGH_MEMORY_SAVE);
|
||||||
if (resume_backup_memory)
|
if (resume_backup_memory)
|
||||||
memcpy_(resume_backup_memory + HIGH_MEMORY_SAVE - backup_top,
|
memcpy_(resume_backup_memory + HIGH_MEMORY_SAVE - backup_top,
|
||||||
(void *)(CONFIG_RAMTOP - backup_top), backup_top);
|
(void *)(CONFIG_RAMTOP - backup_top), backup_top);
|
||||||
|
@ -85,7 +85,7 @@ static void prepare_ramstage_region(int s3resume)
|
||||||
print_car_debug("Prepare ramstage memory region...");
|
print_car_debug("Prepare ramstage memory region...");
|
||||||
|
|
||||||
if (s3resume) {
|
if (s3resume) {
|
||||||
void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
|
void *resume_backup_memory = acpi_backup_container(CONFIG_RAMBASE, HIGH_MEMORY_SAVE);
|
||||||
if (resume_backup_memory)
|
if (resume_backup_memory)
|
||||||
memcpy_(resume_backup_memory, (void *) CONFIG_RAMBASE,
|
memcpy_(resume_backup_memory, (void *) CONFIG_RAMBASE,
|
||||||
HIGH_MEMORY_SAVE - backup_top);
|
HIGH_MEMORY_SAVE - backup_top);
|
||||||
|
|
|
@ -28,6 +28,7 @@ config CPU_AMD_PI
|
||||||
select UDELAY_LAPIC
|
select UDELAY_LAPIC
|
||||||
select LAPIC_MONOTONIC_TIMER
|
select LAPIC_MONOTONIC_TIMER
|
||||||
select SPI_FLASH if HAVE_ACPI_RESUME
|
select SPI_FLASH if HAVE_ACPI_RESUME
|
||||||
|
select ACPI_TINY_LOWMEM_BACKUP
|
||||||
|
|
||||||
if CPU_AMD_PI
|
if CPU_AMD_PI
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,9 @@ size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size);
|
||||||
size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
|
size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
|
||||||
size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
|
size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
|
||||||
|
|
||||||
|
/* Return the size and fill base of the memory pstage will occupy after loaded. */
|
||||||
|
size_t cbfs_prog_stage_section(struct prog *pstage, uintptr_t *base);
|
||||||
|
|
||||||
/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
|
/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
|
||||||
int cbfs_prog_stage_load(struct prog *prog);
|
int cbfs_prog_stage_load(struct prog *prog);
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,10 @@ uintptr_t romstage_ram_stack_base(size_t size, int src);
|
||||||
uintptr_t romstage_ram_stack_top(void);
|
uintptr_t romstage_ram_stack_top(void);
|
||||||
uintptr_t romstage_ram_stack_bottom(void);
|
uintptr_t romstage_ram_stack_bottom(void);
|
||||||
|
|
||||||
|
/* Backup OS memory to CBMEM_ID_RESUME on ACPI S3 resume path,
|
||||||
|
* if ramstage overwrites low memory. */
|
||||||
|
void backup_ramstage_section(uintptr_t base, size_t size);
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* PAYLOAD LOADING *
|
* PAYLOAD LOADING *
|
||||||
***********************/
|
***********************/
|
||||||
|
|
|
@ -187,6 +187,18 @@ size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size)
|
||||||
buf, buf_size, compression_algo);
|
buf, buf_size, compression_algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t cbfs_prog_stage_section(struct prog *pstage, uintptr_t *base)
|
||||||
|
{
|
||||||
|
struct cbfs_stage stage;
|
||||||
|
const struct region_device *fh = prog_rdev(pstage);
|
||||||
|
|
||||||
|
if (rdev_readat(fh, &stage, 0, sizeof(stage)) != sizeof(stage))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*base = (uintptr_t)stage.load;
|
||||||
|
return stage.memlen;
|
||||||
|
}
|
||||||
|
|
||||||
int cbfs_prog_stage_load(struct prog *pstage)
|
int cbfs_prog_stage_load(struct prog *pstage)
|
||||||
{
|
{
|
||||||
struct cbfs_stage stage;
|
struct cbfs_stage stage;
|
||||||
|
|
|
@ -110,6 +110,18 @@ static int load_relocatable_ramstage(struct prog *ramstage)
|
||||||
return rmodule_stage_load(&rmod_ram);
|
return rmodule_stage_load(&rmod_ram);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int load_nonrelocatable_ramstage(struct prog *ramstage)
|
||||||
|
{
|
||||||
|
if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
|
||||||
|
uintptr_t base = 0;
|
||||||
|
size_t size = cbfs_prog_stage_section(ramstage, &base);
|
||||||
|
if (size)
|
||||||
|
backup_ramstage_section(base, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cbfs_prog_stage_load(ramstage);
|
||||||
|
}
|
||||||
|
|
||||||
void run_ramstage(void)
|
void run_ramstage(void)
|
||||||
{
|
{
|
||||||
struct prog ramstage =
|
struct prog ramstage =
|
||||||
|
@ -135,7 +147,7 @@ void run_ramstage(void)
|
||||||
if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
|
if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
|
||||||
if (load_relocatable_ramstage(&ramstage))
|
if (load_relocatable_ramstage(&ramstage))
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (cbfs_prog_stage_load(&ramstage))
|
} else if (load_nonrelocatable_ramstage(&ramstage))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
stage_cache_add(STAGE_RAMSTAGE, &ramstage);
|
stage_cache_add(STAGE_RAMSTAGE, &ramstage);
|
||||||
|
|
Loading…
Reference in New Issue