2016-06-18 08:19:18 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2009 coresystems GmbH
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <arch/acpi.h>
|
|
|
|
#include <cbmem.h>
|
|
|
|
#include <cpu/cpu.h>
|
2016-12-11 12:31:17 +01:00
|
|
|
#include <fallback.h>
|
2016-06-18 08:19:18 +02:00
|
|
|
#include <timestamp.h>
|
2016-06-28 06:38:46 +02:00
|
|
|
#include <program_loading.h>
|
2016-06-18 08:19:18 +02:00
|
|
|
#include <romstage_handoff.h>
|
|
|
|
#include <rules.h>
|
2016-06-28 06:38:46 +02:00
|
|
|
#include <symbols.h>
|
2016-06-18 08:19:18 +02:00
|
|
|
|
2016-06-20 19:40:32 +02:00
|
|
|
#if ENV_RAMSTAGE
|
|
|
|
|
2016-06-18 08:19:18 +02:00
|
|
|
/* This is filled with acpi_is_wakeup() call early in ramstage. */
|
2015-05-29 05:17:23 +02:00
|
|
|
static int acpi_slp_type = -1;
|
2016-06-18 08:19:18 +02:00
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_EARLY_CBMEM_INIT)
|
|
|
|
int acpi_get_sleep_type(void)
|
|
|
|
{
|
2016-11-30 04:22:42 +01:00
|
|
|
if (romstage_handoff_is_resume()) {
|
2016-06-18 08:19:18 +02:00
|
|
|
printk(BIOS_DEBUG, "S3 Resume.\n");
|
2016-07-13 19:08:33 +02:00
|
|
|
return ACPI_S3;
|
2016-06-18 08:19:18 +02:00
|
|
|
} else {
|
|
|
|
printk(BIOS_DEBUG, "Normal boot.\n");
|
2016-07-13 19:08:33 +02:00
|
|
|
return ACPI_S0;
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void acpi_handoff_wakeup(void)
|
|
|
|
{
|
|
|
|
if (acpi_slp_type < 0)
|
|
|
|
acpi_slp_type = acpi_get_sleep_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
int acpi_is_wakeup(void)
|
|
|
|
{
|
|
|
|
acpi_handoff_wakeup();
|
|
|
|
/* Both resume from S2 and resume from S3 restart at CPU reset */
|
2016-07-13 19:08:33 +02:00
|
|
|
return (acpi_slp_type == ACPI_S3 || acpi_slp_type == ACPI_S2);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int acpi_is_wakeup_s3(void)
|
|
|
|
{
|
|
|
|
acpi_handoff_wakeup();
|
2016-07-13 19:08:33 +02:00
|
|
|
return (acpi_slp_type == ACPI_S3);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int acpi_is_wakeup_s4(void)
|
|
|
|
{
|
|
|
|
acpi_handoff_wakeup();
|
2016-07-13 19:08:33 +02:00
|
|
|
return (acpi_slp_type == ACPI_S4);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void acpi_fail_wakeup(void)
|
|
|
|
{
|
2016-07-13 19:08:33 +02:00
|
|
|
if (acpi_slp_type == ACPI_S3 || acpi_slp_type == ACPI_S2)
|
|
|
|
acpi_slp_type = ACPI_S0;
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
2016-06-20 19:40:32 +02:00
|
|
|
#endif /* ENV_RAMSTAGE */
|
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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) {
|
2017-03-16 23:18:22 +01:00
|
|
|
size_t header_sz = ALIGN_UP(sizeof(*backup_mem),
|
|
|
|
BACKUP_PAGE_SZ);
|
2016-06-28 06:38:46 +02:00
|
|
|
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;
|
|
|
|
|
2017-03-16 23:18:22 +01:00
|
|
|
if (!IS_ALIGNED(base, BACKUP_PAGE_SZ) || !IS_ALIGNED(size,
|
|
|
|
BACKUP_PAGE_SZ))
|
2016-06-28 06:38:46 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (backup_create_or_update(backup_mem, base, size) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
backup_mem->valid = 1;
|
2017-03-16 21:41:11 +01:00
|
|
|
return (void *)(uintptr_t)backup_mem->cbmem;
|
2016-06-28 06:38:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Back up the OS-controlled memory where ramstage will be loaded. */
|
2017-03-16 21:41:11 +01:00
|
|
|
memcpy((void *)(uintptr_t)backup_mem->cbmem,
|
2017-03-16 23:18:22 +01:00
|
|
|
(void *)(uintptr_t)backup_mem->lowmem,
|
|
|
|
(size_t)backup_mem->size);
|
2016-06-28 06:38:46 +02:00
|
|
|
backup_mem->valid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make backup of low-memory region, relying on the base and size
|
|
|
|
* of the ramstage that was loaded before entry to ACPI S3.
|
|
|
|
*
|
|
|
|
* DEPRECATED
|
|
|
|
*/
|
2016-06-20 19:40:32 +02:00
|
|
|
void acpi_prepare_for_resume(void)
|
|
|
|
{
|
2016-06-28 06:38:46 +02:00
|
|
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
|
|
|
if (!backup_mem)
|
2016-06-20 19:40:32 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Back up the OS-controlled memory where ramstage will be loaded. */
|
2017-03-16 21:41:11 +01:00
|
|
|
memcpy((void *)(uintptr_t)backup_mem->cbmem,
|
2017-03-16 23:18:22 +01:00
|
|
|
(void *)(uintptr_t)backup_mem->lowmem,
|
|
|
|
(size_t)backup_mem->size);
|
2016-06-28 06:38:46 +02:00
|
|
|
backup_mem->valid = 1;
|
2016-06-20 19:40:32 +02:00
|
|
|
}
|
2016-06-18 08:19:18 +02:00
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
/* 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.
|
|
|
|
*/
|
2016-06-18 08:19:18 +02:00
|
|
|
void acpi_prepare_resume_backup(void)
|
|
|
|
{
|
|
|
|
if (!acpi_s3_resume_allowed())
|
|
|
|
return;
|
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE))
|
|
|
|
return;
|
2016-06-18 08:19:18 +02:00
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
backup_create_or_update(NULL, (uintptr_t)_program, _program_size);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define WAKEUP_BASE 0x600
|
|
|
|
|
|
|
|
void (*acpi_do_wakeup)(uintptr_t vector, u32 backup_source, u32 backup_target,
|
2017-03-16 21:41:11 +01:00
|
|
|
u32 backup_size) asmlinkage = (void *)WAKEUP_BASE;
|
2016-06-18 08:19:18 +02:00
|
|
|
|
|
|
|
extern unsigned char __wakeup;
|
|
|
|
extern unsigned int __wakeup_size;
|
|
|
|
|
|
|
|
static void acpi_jump_to_wakeup(void *vector)
|
|
|
|
{
|
2016-06-28 06:38:46 +02:00
|
|
|
uintptr_t source = 0, target = 0;
|
|
|
|
size_t size = 0;
|
2016-06-18 08:19:18 +02:00
|
|
|
|
2016-06-20 23:03:01 +02:00
|
|
|
if (!acpi_s3_resume_allowed()) {
|
|
|
|
printk(BIOS_WARNING, "ACPI: S3 resume not allowed.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
if (!IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
|
|
|
|
struct resume_backup *backup_mem = cbmem_find(CBMEM_ID_RESUME);
|
|
|
|
if (backup_mem && backup_mem->valid) {
|
|
|
|
backup_mem->valid = 0;
|
|
|
|
target = backup_mem->lowmem;
|
|
|
|
source = backup_mem->cbmem;
|
|
|
|
size = backup_mem->size;
|
|
|
|
} else {
|
2016-06-18 08:19:18 +02:00
|
|
|
printk(BIOS_WARNING, "ACPI: Backup memory missing. "
|
|
|
|
"No S3 resume.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy wakeup trampoline in place. */
|
|
|
|
memcpy((void *)WAKEUP_BASE, &__wakeup, __wakeup_size);
|
|
|
|
|
2016-12-11 12:31:17 +01:00
|
|
|
set_boot_successful();
|
|
|
|
|
2016-06-18 08:19:18 +02:00
|
|
|
timestamp_add_now(TS_ACPI_WAKE_JUMP);
|
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
acpi_do_wakeup((uintptr_t)vector, source, target, size);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((weak)) mainboard_suspend_resume(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void acpi_resume(void *wake_vec)
|
|
|
|
{
|
|
|
|
#if CONFIG_HAVE_SMI_HANDLER
|
|
|
|
u32 *gnvs_address = cbmem_find(CBMEM_ID_ACPI_GNVS_PTR);
|
|
|
|
|
|
|
|
/* Restore GNVS pointer in SMM if found */
|
|
|
|
if (gnvs_address && *gnvs_address) {
|
|
|
|
printk(BIOS_DEBUG, "Restore GNVS pointer to 0x%08x\n",
|
|
|
|
*gnvs_address);
|
|
|
|
smm_setup_structures((void *)*gnvs_address, NULL, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Call mainboard resume handler first, if defined. */
|
|
|
|
mainboard_suspend_resume();
|
|
|
|
|
|
|
|
post_code(POST_OS_RESUME);
|
|
|
|
acpi_jump_to_wakeup(wake_vec);
|
|
|
|
}
|