Commit 3a34cae01160d207d50db267585b963cf0a0018d

Authored by Bin Meng
1 parent e76bf38f18

x86: acpi: Resume OS if resume vector is found

In an S3 resume path, U-Boot does everything like a cold boot except
in the last_stage_init() it jumps to the OS resume vector.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Stefan Roese <sr@denx.de>

Showing 4 changed files with 45 additions and 0 deletions Side-by-side Diff

... ... @@ -26,6 +26,7 @@
26 26 #include <malloc.h>
27 27 #include <syscon.h>
28 28 #include <asm/acpi_s3.h>
  29 +#include <asm/acpi_table.h>
29 30 #include <asm/control_regs.h>
30 31 #include <asm/coreboot_tables.h>
31 32 #include <asm/cpu.h>
... ... @@ -204,6 +205,13 @@
204 205  
205 206 int last_stage_init(void)
206 207 {
  208 +#if CONFIG_HAVE_ACPI_RESUME
  209 + void *wake_vector = acpi_find_wakeup_vector();
  210 +
  211 + if (wake_vector != NULL && gd->arch.prev_sleep_state == ACPI_S3)
  212 + acpi_resume(wake_vector);
  213 +#endif
  214 +
207 215 write_tables();
208 216  
209 217 board_final_cleanup();
arch/x86/include/asm/acpi_s3.h
... ... @@ -99,6 +99,16 @@
99 99 */
100 100 void chipset_clear_sleep_state(void);
101 101  
  102 +/**
  103 + * acpi_resume() - Do ACPI S3 resume
  104 + *
  105 + * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector.
  106 + *
  107 + * @wake_vec: OS wake up vector
  108 + * @return: Never returns
  109 + */
  110 +void acpi_resume(void *wake_vec);
  111 +
102 112 #endif /* __ASSEMBLY__ */
103 113  
104 114 #endif /* __ASM_ACPI_S3_H__ */
arch/x86/lib/Makefile
... ... @@ -37,6 +37,7 @@
37 37 obj-y += sections.o
38 38 obj-y += sfi.o
39 39 obj-y += string.o
  40 +obj-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.o
40 41 ifndef CONFIG_QEMU
41 42 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
42 43 endif
arch/x86/lib/acpi_s3.c
  1 +/*
  2 + * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <asm/acpi_s3.h>
  9 +#include <asm/post.h>
  10 +
  11 +static void asmlinkage (*acpi_do_wakeup)(void *vector) = (void *)WAKEUP_BASE;
  12 +
  13 +static void acpi_jump_to_wakeup(void *vector)
  14 +{
  15 + /* Copy wakeup trampoline in place */
  16 + memcpy((void *)WAKEUP_BASE, __wakeup, __wakeup_size);
  17 +
  18 + printf("Jumping to OS waking vector %p\n", vector);
  19 + acpi_do_wakeup(vector);
  20 +}
  21 +
  22 +void acpi_resume(void *wake_vec)
  23 +{
  24 + post_code(POST_OS_RESUME);
  25 + acpi_jump_to_wakeup(wake_vec);
  26 +}