2020-03-04 15:10:45 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-06-18 08:19:18 +02:00
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <string.h>
|
2020-05-02 19:24:23 +02:00
|
|
|
#include <acpi/acpi.h>
|
2018-10-27 09:41:02 +02:00
|
|
|
#include <arch/cpu.h>
|
2019-06-21 07:06:50 +02:00
|
|
|
#include <commonlib/helpers.h>
|
2020-06-16 11:45:11 +02:00
|
|
|
#include <cpu/x86/smm.h>
|
2016-12-11 12:31:17 +01:00
|
|
|
#include <fallback.h>
|
2016-06-18 08:19:18 +02:00
|
|
|
#include <timestamp.h>
|
|
|
|
#include <romstage_handoff.h>
|
|
|
|
|
2017-09-21 15:47:33 +02:00
|
|
|
#if ENV_RAMSTAGE || ENV_POSTCAR
|
2016-06-20 19:40:32 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
static void acpi_handoff_wakeup(void)
|
|
|
|
{
|
2017-09-04 18:22:26 +02:00
|
|
|
if (acpi_slp_type < 0) {
|
|
|
|
if (romstage_handoff_is_resume()) {
|
2019-01-10 15:03:35 +01:00
|
|
|
printk(BIOS_DEBUG, "S3 Resume\n");
|
2017-09-04 18:22:26 +02:00
|
|
|
acpi_slp_type = ACPI_S3;
|
|
|
|
} else {
|
2019-01-10 15:03:35 +01:00
|
|
|
printk(BIOS_DEBUG, "Normal boot\n");
|
2017-09-04 18:22:26 +02:00
|
|
|
acpi_slp_type = ACPI_S0;
|
|
|
|
}
|
|
|
|
}
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-06-20 19:40:32 +02:00
|
|
|
#endif /* ENV_RAMSTAGE */
|
|
|
|
|
2016-06-18 08:19:18 +02:00
|
|
|
#define WAKEUP_BASE 0x600
|
|
|
|
|
2018-06-03 22:04:28 +02:00
|
|
|
asmlinkage void (*acpi_do_wakeup)(uintptr_t vector) = (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)
|
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
|
2018-06-03 22:04:28 +02:00
|
|
|
acpi_do_wakeup((uintptr_t)vector);
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
void __weak mainboard_suspend_resume(void)
|
2016-06-18 08:19:18 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-18 07:28:12 +02:00
|
|
|
void __noreturn acpi_resume(void *wake_vec)
|
2016-06-18 08:19:18 +02:00
|
|
|
{
|
2020-06-17 09:34:26 +02:00
|
|
|
/* Restore GNVS pointer in SMM if found. */
|
|
|
|
apm_control(APM_CNT_GNVS_UPDATE);
|
2016-06-18 08:19:18 +02:00
|
|
|
|
|
|
|
/* Call mainboard resume handler first, if defined. */
|
|
|
|
mainboard_suspend_resume();
|
|
|
|
|
|
|
|
post_code(POST_OS_RESUME);
|
|
|
|
acpi_jump_to_wakeup(wake_vec);
|
2020-06-18 07:28:12 +02:00
|
|
|
|
|
|
|
die("Failed the jump to wakeup vector\n");
|
2016-06-18 08:19:18 +02:00
|
|
|
}
|