Commit 3a34cae01160d207d50db267585b963cf0a0018d
1 parent
e76bf38f18
Exists in
smarc_8mq_lf_v2020.04
and in
20 other branches
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 Inline Diff
arch/x86/cpu/cpu.c
| 1 | /* | 1 | /* |
| 2 | * (C) Copyright 2008-2011 | 2 | * (C) Copyright 2008-2011 |
| 3 | * Graeme Russ, <graeme.russ@gmail.com> | 3 | * Graeme Russ, <graeme.russ@gmail.com> |
| 4 | * | 4 | * |
| 5 | * (C) Copyright 2002 | 5 | * (C) Copyright 2002 |
| 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> | 6 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
| 7 | * | 7 | * |
| 8 | * (C) Copyright 2002 | 8 | * (C) Copyright 2002 |
| 9 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | 9 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 10 | * Marius Groeger <mgroeger@sysgo.de> | 10 | * Marius Groeger <mgroeger@sysgo.de> |
| 11 | * | 11 | * |
| 12 | * (C) Copyright 2002 | 12 | * (C) Copyright 2002 |
| 13 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | 13 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 14 | * Alex Zuepke <azu@sysgo.de> | 14 | * Alex Zuepke <azu@sysgo.de> |
| 15 | * | 15 | * |
| 16 | * Part of this file is adapted from coreboot | 16 | * Part of this file is adapted from coreboot |
| 17 | * src/arch/x86/lib/cpu.c | 17 | * src/arch/x86/lib/cpu.c |
| 18 | * | 18 | * |
| 19 | * SPDX-License-Identifier: GPL-2.0+ | 19 | * SPDX-License-Identifier: GPL-2.0+ |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <common.h> | 22 | #include <common.h> |
| 23 | #include <command.h> | 23 | #include <command.h> |
| 24 | #include <dm.h> | 24 | #include <dm.h> |
| 25 | #include <errno.h> | 25 | #include <errno.h> |
| 26 | #include <malloc.h> | 26 | #include <malloc.h> |
| 27 | #include <syscon.h> | 27 | #include <syscon.h> |
| 28 | #include <asm/acpi_s3.h> | 28 | #include <asm/acpi_s3.h> |
| 29 | #include <asm/acpi_table.h> | ||
| 29 | #include <asm/control_regs.h> | 30 | #include <asm/control_regs.h> |
| 30 | #include <asm/coreboot_tables.h> | 31 | #include <asm/coreboot_tables.h> |
| 31 | #include <asm/cpu.h> | 32 | #include <asm/cpu.h> |
| 32 | #include <asm/lapic.h> | 33 | #include <asm/lapic.h> |
| 33 | #include <asm/microcode.h> | 34 | #include <asm/microcode.h> |
| 34 | #include <asm/mp.h> | 35 | #include <asm/mp.h> |
| 35 | #include <asm/mrccache.h> | 36 | #include <asm/mrccache.h> |
| 36 | #include <asm/msr.h> | 37 | #include <asm/msr.h> |
| 37 | #include <asm/mtrr.h> | 38 | #include <asm/mtrr.h> |
| 38 | #include <asm/post.h> | 39 | #include <asm/post.h> |
| 39 | #include <asm/processor.h> | 40 | #include <asm/processor.h> |
| 40 | #include <asm/processor-flags.h> | 41 | #include <asm/processor-flags.h> |
| 41 | #include <asm/interrupt.h> | 42 | #include <asm/interrupt.h> |
| 42 | #include <asm/tables.h> | 43 | #include <asm/tables.h> |
| 43 | #include <linux/compiler.h> | 44 | #include <linux/compiler.h> |
| 44 | 45 | ||
| 45 | DECLARE_GLOBAL_DATA_PTR; | 46 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | 47 | ||
| 47 | static const char *const x86_vendor_name[] = { | 48 | static const char *const x86_vendor_name[] = { |
| 48 | [X86_VENDOR_INTEL] = "Intel", | 49 | [X86_VENDOR_INTEL] = "Intel", |
| 49 | [X86_VENDOR_CYRIX] = "Cyrix", | 50 | [X86_VENDOR_CYRIX] = "Cyrix", |
| 50 | [X86_VENDOR_AMD] = "AMD", | 51 | [X86_VENDOR_AMD] = "AMD", |
| 51 | [X86_VENDOR_UMC] = "UMC", | 52 | [X86_VENDOR_UMC] = "UMC", |
| 52 | [X86_VENDOR_NEXGEN] = "NexGen", | 53 | [X86_VENDOR_NEXGEN] = "NexGen", |
| 53 | [X86_VENDOR_CENTAUR] = "Centaur", | 54 | [X86_VENDOR_CENTAUR] = "Centaur", |
| 54 | [X86_VENDOR_RISE] = "Rise", | 55 | [X86_VENDOR_RISE] = "Rise", |
| 55 | [X86_VENDOR_TRANSMETA] = "Transmeta", | 56 | [X86_VENDOR_TRANSMETA] = "Transmeta", |
| 56 | [X86_VENDOR_NSC] = "NSC", | 57 | [X86_VENDOR_NSC] = "NSC", |
| 57 | [X86_VENDOR_SIS] = "SiS", | 58 | [X86_VENDOR_SIS] = "SiS", |
| 58 | }; | 59 | }; |
| 59 | 60 | ||
| 60 | int __weak x86_cleanup_before_linux(void) | 61 | int __weak x86_cleanup_before_linux(void) |
| 61 | { | 62 | { |
| 62 | #ifdef CONFIG_BOOTSTAGE_STASH | 63 | #ifdef CONFIG_BOOTSTAGE_STASH |
| 63 | bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR, | 64 | bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR, |
| 64 | CONFIG_BOOTSTAGE_STASH_SIZE); | 65 | CONFIG_BOOTSTAGE_STASH_SIZE); |
| 65 | #endif | 66 | #endif |
| 66 | 67 | ||
| 67 | return 0; | 68 | return 0; |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | int x86_init_cache(void) | 71 | int x86_init_cache(void) |
| 71 | { | 72 | { |
| 72 | enable_caches(); | 73 | enable_caches(); |
| 73 | 74 | ||
| 74 | return 0; | 75 | return 0; |
| 75 | } | 76 | } |
| 76 | int init_cache(void) __attribute__((weak, alias("x86_init_cache"))); | 77 | int init_cache(void) __attribute__((weak, alias("x86_init_cache"))); |
| 77 | 78 | ||
| 78 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | 79 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 79 | { | 80 | { |
| 80 | printf("resetting ...\n"); | 81 | printf("resetting ...\n"); |
| 81 | 82 | ||
| 82 | /* wait 50 ms */ | 83 | /* wait 50 ms */ |
| 83 | udelay(50000); | 84 | udelay(50000); |
| 84 | disable_interrupts(); | 85 | disable_interrupts(); |
| 85 | reset_cpu(0); | 86 | reset_cpu(0); |
| 86 | 87 | ||
| 87 | /*NOTREACHED*/ | 88 | /*NOTREACHED*/ |
| 88 | return 0; | 89 | return 0; |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | void flush_cache(unsigned long dummy1, unsigned long dummy2) | 92 | void flush_cache(unsigned long dummy1, unsigned long dummy2) |
| 92 | { | 93 | { |
| 93 | asm("wbinvd\n"); | 94 | asm("wbinvd\n"); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | __weak void reset_cpu(ulong addr) | 97 | __weak void reset_cpu(ulong addr) |
| 97 | { | 98 | { |
| 98 | /* Do a hard reset through the chipset's reset control register */ | 99 | /* Do a hard reset through the chipset's reset control register */ |
| 99 | outb(SYS_RST | RST_CPU, IO_PORT_RESET); | 100 | outb(SYS_RST | RST_CPU, IO_PORT_RESET); |
| 100 | for (;;) | 101 | for (;;) |
| 101 | cpu_hlt(); | 102 | cpu_hlt(); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | void x86_full_reset(void) | 105 | void x86_full_reset(void) |
| 105 | { | 106 | { |
| 106 | outb(FULL_RST | SYS_RST | RST_CPU, IO_PORT_RESET); | 107 | outb(FULL_RST | SYS_RST | RST_CPU, IO_PORT_RESET); |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 109 | /* Define these functions to allow ehch-hcd to function */ | 110 | /* Define these functions to allow ehch-hcd to function */ |
| 110 | void flush_dcache_range(unsigned long start, unsigned long stop) | 111 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 111 | { | 112 | { |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | void invalidate_dcache_range(unsigned long start, unsigned long stop) | 115 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 115 | { | 116 | { |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | void dcache_enable(void) | 119 | void dcache_enable(void) |
| 119 | { | 120 | { |
| 120 | enable_caches(); | 121 | enable_caches(); |
| 121 | } | 122 | } |
| 122 | 123 | ||
| 123 | void dcache_disable(void) | 124 | void dcache_disable(void) |
| 124 | { | 125 | { |
| 125 | disable_caches(); | 126 | disable_caches(); |
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | void icache_enable(void) | 129 | void icache_enable(void) |
| 129 | { | 130 | { |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | void icache_disable(void) | 133 | void icache_disable(void) |
| 133 | { | 134 | { |
| 134 | } | 135 | } |
| 135 | 136 | ||
| 136 | int icache_status(void) | 137 | int icache_status(void) |
| 137 | { | 138 | { |
| 138 | return 1; | 139 | return 1; |
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | const char *cpu_vendor_name(int vendor) | 142 | const char *cpu_vendor_name(int vendor) |
| 142 | { | 143 | { |
| 143 | const char *name; | 144 | const char *name; |
| 144 | name = "<invalid cpu vendor>"; | 145 | name = "<invalid cpu vendor>"; |
| 145 | if ((vendor < (ARRAY_SIZE(x86_vendor_name))) && | 146 | if ((vendor < (ARRAY_SIZE(x86_vendor_name))) && |
| 146 | (x86_vendor_name[vendor] != 0)) | 147 | (x86_vendor_name[vendor] != 0)) |
| 147 | name = x86_vendor_name[vendor]; | 148 | name = x86_vendor_name[vendor]; |
| 148 | 149 | ||
| 149 | return name; | 150 | return name; |
| 150 | } | 151 | } |
| 151 | 152 | ||
| 152 | char *cpu_get_name(char *name) | 153 | char *cpu_get_name(char *name) |
| 153 | { | 154 | { |
| 154 | unsigned int *name_as_ints = (unsigned int *)name; | 155 | unsigned int *name_as_ints = (unsigned int *)name; |
| 155 | struct cpuid_result regs; | 156 | struct cpuid_result regs; |
| 156 | char *ptr; | 157 | char *ptr; |
| 157 | int i; | 158 | int i; |
| 158 | 159 | ||
| 159 | /* This bit adds up to 48 bytes */ | 160 | /* This bit adds up to 48 bytes */ |
| 160 | for (i = 0; i < 3; i++) { | 161 | for (i = 0; i < 3; i++) { |
| 161 | regs = cpuid(0x80000002 + i); | 162 | regs = cpuid(0x80000002 + i); |
| 162 | name_as_ints[i * 4 + 0] = regs.eax; | 163 | name_as_ints[i * 4 + 0] = regs.eax; |
| 163 | name_as_ints[i * 4 + 1] = regs.ebx; | 164 | name_as_ints[i * 4 + 1] = regs.ebx; |
| 164 | name_as_ints[i * 4 + 2] = regs.ecx; | 165 | name_as_ints[i * 4 + 2] = regs.ecx; |
| 165 | name_as_ints[i * 4 + 3] = regs.edx; | 166 | name_as_ints[i * 4 + 3] = regs.edx; |
| 166 | } | 167 | } |
| 167 | name[CPU_MAX_NAME_LEN - 1] = '\0'; | 168 | name[CPU_MAX_NAME_LEN - 1] = '\0'; |
| 168 | 169 | ||
| 169 | /* Skip leading spaces. */ | 170 | /* Skip leading spaces. */ |
| 170 | ptr = name; | 171 | ptr = name; |
| 171 | while (*ptr == ' ') | 172 | while (*ptr == ' ') |
| 172 | ptr++; | 173 | ptr++; |
| 173 | 174 | ||
| 174 | return ptr; | 175 | return ptr; |
| 175 | } | 176 | } |
| 176 | 177 | ||
| 177 | int default_print_cpuinfo(void) | 178 | int default_print_cpuinfo(void) |
| 178 | { | 179 | { |
| 179 | printf("CPU: %s, vendor %s, device %xh\n", | 180 | printf("CPU: %s, vendor %s, device %xh\n", |
| 180 | cpu_has_64bit() ? "x86_64" : "x86", | 181 | cpu_has_64bit() ? "x86_64" : "x86", |
| 181 | cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device); | 182 | cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device); |
| 182 | 183 | ||
| 183 | #ifdef CONFIG_HAVE_ACPI_RESUME | 184 | #ifdef CONFIG_HAVE_ACPI_RESUME |
| 184 | debug("ACPI previous sleep state: %s\n", | 185 | debug("ACPI previous sleep state: %s\n", |
| 185 | acpi_ss_string(gd->arch.prev_sleep_state)); | 186 | acpi_ss_string(gd->arch.prev_sleep_state)); |
| 186 | #endif | 187 | #endif |
| 187 | 188 | ||
| 188 | return 0; | 189 | return 0; |
| 189 | } | 190 | } |
| 190 | 191 | ||
| 191 | void show_boot_progress(int val) | 192 | void show_boot_progress(int val) |
| 192 | { | 193 | { |
| 193 | outb(val, POST_PORT); | 194 | outb(val, POST_PORT); |
| 194 | } | 195 | } |
| 195 | 196 | ||
| 196 | #ifndef CONFIG_SYS_COREBOOT | 197 | #ifndef CONFIG_SYS_COREBOOT |
| 197 | /* | 198 | /* |
| 198 | * Implement a weak default function for boards that optionally | 199 | * Implement a weak default function for boards that optionally |
| 199 | * need to clean up the system before jumping to the kernel. | 200 | * need to clean up the system before jumping to the kernel. |
| 200 | */ | 201 | */ |
| 201 | __weak void board_final_cleanup(void) | 202 | __weak void board_final_cleanup(void) |
| 202 | { | 203 | { |
| 203 | } | 204 | } |
| 204 | 205 | ||
| 205 | int last_stage_init(void) | 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 | write_tables(); | 215 | write_tables(); |
| 208 | 216 | ||
| 209 | board_final_cleanup(); | 217 | board_final_cleanup(); |
| 210 | 218 | ||
| 211 | return 0; | 219 | return 0; |
| 212 | } | 220 | } |
| 213 | #endif | 221 | #endif |
| 214 | 222 | ||
| 215 | static int x86_init_cpus(void) | 223 | static int x86_init_cpus(void) |
| 216 | { | 224 | { |
| 217 | #ifdef CONFIG_SMP | 225 | #ifdef CONFIG_SMP |
| 218 | debug("Init additional CPUs\n"); | 226 | debug("Init additional CPUs\n"); |
| 219 | x86_mp_init(); | 227 | x86_mp_init(); |
| 220 | #else | 228 | #else |
| 221 | struct udevice *dev; | 229 | struct udevice *dev; |
| 222 | 230 | ||
| 223 | /* | 231 | /* |
| 224 | * This causes the cpu-x86 driver to be probed. | 232 | * This causes the cpu-x86 driver to be probed. |
| 225 | * We don't check return value here as we want to allow boards | 233 | * We don't check return value here as we want to allow boards |
| 226 | * which have not been converted to use cpu uclass driver to boot. | 234 | * which have not been converted to use cpu uclass driver to boot. |
| 227 | */ | 235 | */ |
| 228 | uclass_first_device(UCLASS_CPU, &dev); | 236 | uclass_first_device(UCLASS_CPU, &dev); |
| 229 | #endif | 237 | #endif |
| 230 | 238 | ||
| 231 | return 0; | 239 | return 0; |
| 232 | } | 240 | } |
| 233 | 241 | ||
| 234 | int cpu_init_r(void) | 242 | int cpu_init_r(void) |
| 235 | { | 243 | { |
| 236 | struct udevice *dev; | 244 | struct udevice *dev; |
| 237 | int ret; | 245 | int ret; |
| 238 | 246 | ||
| 239 | if (!ll_boot_init()) | 247 | if (!ll_boot_init()) |
| 240 | return 0; | 248 | return 0; |
| 241 | 249 | ||
| 242 | ret = x86_init_cpus(); | 250 | ret = x86_init_cpus(); |
| 243 | if (ret) | 251 | if (ret) |
| 244 | return ret; | 252 | return ret; |
| 245 | 253 | ||
| 246 | /* | 254 | /* |
| 247 | * Set up the northbridge, PCH and LPC if available. Note that these | 255 | * Set up the northbridge, PCH and LPC if available. Note that these |
| 248 | * may have had some limited pre-relocation init if they were probed | 256 | * may have had some limited pre-relocation init if they were probed |
| 249 | * before relocation, but this is post relocation. | 257 | * before relocation, but this is post relocation. |
| 250 | */ | 258 | */ |
| 251 | uclass_first_device(UCLASS_NORTHBRIDGE, &dev); | 259 | uclass_first_device(UCLASS_NORTHBRIDGE, &dev); |
| 252 | uclass_first_device(UCLASS_PCH, &dev); | 260 | uclass_first_device(UCLASS_PCH, &dev); |
| 253 | uclass_first_device(UCLASS_LPC, &dev); | 261 | uclass_first_device(UCLASS_LPC, &dev); |
| 254 | 262 | ||
| 255 | /* Set up pin control if available */ | 263 | /* Set up pin control if available */ |
| 256 | ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev); | 264 | ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev); |
| 257 | debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret); | 265 | debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret); |
| 258 | 266 | ||
| 259 | return 0; | 267 | return 0; |
| 260 | } | 268 | } |
| 261 | 269 | ||
| 262 | #ifndef CONFIG_EFI_STUB | 270 | #ifndef CONFIG_EFI_STUB |
| 263 | int reserve_arch(void) | 271 | int reserve_arch(void) |
| 264 | { | 272 | { |
| 265 | #ifdef CONFIG_ENABLE_MRC_CACHE | 273 | #ifdef CONFIG_ENABLE_MRC_CACHE |
| 266 | mrccache_reserve(); | 274 | mrccache_reserve(); |
| 267 | #endif | 275 | #endif |
| 268 | 276 | ||
| 269 | #ifdef CONFIG_SEABIOS | 277 | #ifdef CONFIG_SEABIOS |
| 270 | high_table_reserve(); | 278 | high_table_reserve(); |
| 271 | #endif | 279 | #endif |
| 272 | 280 | ||
| 273 | return 0; | 281 | return 0; |
| 274 | } | 282 | } |
| 275 | #endif | 283 | #endif |
| 276 | 284 |
arch/x86/include/asm/acpi_s3.h
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> | 2 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #ifndef __ASM_ACPI_S3_H__ | 7 | #ifndef __ASM_ACPI_S3_H__ |
| 8 | #define __ASM_ACPI_S3_H__ | 8 | #define __ASM_ACPI_S3_H__ |
| 9 | 9 | ||
| 10 | #define WAKEUP_BASE 0x600 | 10 | #define WAKEUP_BASE 0x600 |
| 11 | 11 | ||
| 12 | /* PM1_STATUS register */ | 12 | /* PM1_STATUS register */ |
| 13 | #define WAK_STS (1 << 15) | 13 | #define WAK_STS (1 << 15) |
| 14 | #define PCIEXPWAK_STS (1 << 14) | 14 | #define PCIEXPWAK_STS (1 << 14) |
| 15 | #define RTC_STS (1 << 10) | 15 | #define RTC_STS (1 << 10) |
| 16 | #define SLPBTN_STS (1 << 9) | 16 | #define SLPBTN_STS (1 << 9) |
| 17 | #define PWRBTN_STS (1 << 8) | 17 | #define PWRBTN_STS (1 << 8) |
| 18 | #define GBL_STS (1 << 5) | 18 | #define GBL_STS (1 << 5) |
| 19 | #define BM_STS (1 << 4) | 19 | #define BM_STS (1 << 4) |
| 20 | #define TMR_STS (1 << 0) | 20 | #define TMR_STS (1 << 0) |
| 21 | 21 | ||
| 22 | /* PM1_CNT register */ | 22 | /* PM1_CNT register */ |
| 23 | #define SLP_EN (1 << 13) | 23 | #define SLP_EN (1 << 13) |
| 24 | #define SLP_TYP_SHIFT 10 | 24 | #define SLP_TYP_SHIFT 10 |
| 25 | #define SLP_TYP (7 << SLP_TYP_SHIFT) | 25 | #define SLP_TYP (7 << SLP_TYP_SHIFT) |
| 26 | #define SLP_TYP_S0 0 | 26 | #define SLP_TYP_S0 0 |
| 27 | #define SLP_TYP_S1 1 | 27 | #define SLP_TYP_S1 1 |
| 28 | #define SLP_TYP_S3 5 | 28 | #define SLP_TYP_S3 5 |
| 29 | #define SLP_TYP_S4 6 | 29 | #define SLP_TYP_S4 6 |
| 30 | #define SLP_TYP_S5 7 | 30 | #define SLP_TYP_S5 7 |
| 31 | 31 | ||
| 32 | #ifndef __ASSEMBLY__ | 32 | #ifndef __ASSEMBLY__ |
| 33 | 33 | ||
| 34 | extern char __wakeup[]; | 34 | extern char __wakeup[]; |
| 35 | extern int __wakeup_size; | 35 | extern int __wakeup_size; |
| 36 | 36 | ||
| 37 | enum acpi_sleep_state { | 37 | enum acpi_sleep_state { |
| 38 | ACPI_S0, | 38 | ACPI_S0, |
| 39 | ACPI_S1, | 39 | ACPI_S1, |
| 40 | ACPI_S2, | 40 | ACPI_S2, |
| 41 | ACPI_S3, | 41 | ACPI_S3, |
| 42 | ACPI_S4, | 42 | ACPI_S4, |
| 43 | ACPI_S5, | 43 | ACPI_S5, |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * acpi_ss_string() - get ACPI-defined sleep state string | 47 | * acpi_ss_string() - get ACPI-defined sleep state string |
| 48 | * | 48 | * |
| 49 | * @pm1_cnt: ACPI-defined sleep state | 49 | * @pm1_cnt: ACPI-defined sleep state |
| 50 | * @return: a pointer to the sleep state string. | 50 | * @return: a pointer to the sleep state string. |
| 51 | */ | 51 | */ |
| 52 | static inline char *acpi_ss_string(enum acpi_sleep_state state) | 52 | static inline char *acpi_ss_string(enum acpi_sleep_state state) |
| 53 | { | 53 | { |
| 54 | char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"}; | 54 | char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"}; |
| 55 | 55 | ||
| 56 | return ss_string[state]; | 56 | return ss_string[state]; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /** | 59 | /** |
| 60 | * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register | 60 | * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register |
| 61 | * | 61 | * |
| 62 | * @pm1_cnt: PM1_CNT register value | 62 | * @pm1_cnt: PM1_CNT register value |
| 63 | * @return: ACPI-defined sleep state if given valid PM1_CNT register value, | 63 | * @return: ACPI-defined sleep state if given valid PM1_CNT register value, |
| 64 | * -EINVAL otherwise. | 64 | * -EINVAL otherwise. |
| 65 | */ | 65 | */ |
| 66 | static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt) | 66 | static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt) |
| 67 | { | 67 | { |
| 68 | switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) { | 68 | switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) { |
| 69 | case SLP_TYP_S0: | 69 | case SLP_TYP_S0: |
| 70 | return ACPI_S0; | 70 | return ACPI_S0; |
| 71 | case SLP_TYP_S1: | 71 | case SLP_TYP_S1: |
| 72 | return ACPI_S1; | 72 | return ACPI_S1; |
| 73 | case SLP_TYP_S3: | 73 | case SLP_TYP_S3: |
| 74 | return ACPI_S3; | 74 | return ACPI_S3; |
| 75 | case SLP_TYP_S4: | 75 | case SLP_TYP_S4: |
| 76 | return ACPI_S4; | 76 | return ACPI_S4; |
| 77 | case SLP_TYP_S5: | 77 | case SLP_TYP_S5: |
| 78 | return ACPI_S5; | 78 | return ACPI_S5; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | return -EINVAL; | 81 | return -EINVAL; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | /** | 84 | /** |
| 85 | * chipset_prev_sleep_state() - Get chipset previous sleep state | 85 | * chipset_prev_sleep_state() - Get chipset previous sleep state |
| 86 | * | 86 | * |
| 87 | * This returns chipset previous sleep state from ACPI registers. | 87 | * This returns chipset previous sleep state from ACPI registers. |
| 88 | * Platform codes must supply this routine in order to support ACPI S3. | 88 | * Platform codes must supply this routine in order to support ACPI S3. |
| 89 | * | 89 | * |
| 90 | * @return ACPI_S0/S1/S2/S3/S4/S5. | 90 | * @return ACPI_S0/S1/S2/S3/S4/S5. |
| 91 | */ | 91 | */ |
| 92 | enum acpi_sleep_state chipset_prev_sleep_state(void); | 92 | enum acpi_sleep_state chipset_prev_sleep_state(void); |
| 93 | 93 | ||
| 94 | /** | 94 | /** |
| 95 | * chipset_clear_sleep_state() - Clear chipset sleep state | 95 | * chipset_clear_sleep_state() - Clear chipset sleep state |
| 96 | * | 96 | * |
| 97 | * This clears chipset sleep state in ACPI registers. | 97 | * This clears chipset sleep state in ACPI registers. |
| 98 | * Platform codes must supply this routine in order to support ACPI S3. | 98 | * Platform codes must supply this routine in order to support ACPI S3. |
| 99 | */ | 99 | */ |
| 100 | void chipset_clear_sleep_state(void); | 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 | #endif /* __ASSEMBLY__ */ | 112 | #endif /* __ASSEMBLY__ */ |
| 103 | 113 | ||
| 104 | #endif /* __ASM_ACPI_S3_H__ */ | 114 | #endif /* __ASM_ACPI_S3_H__ */ |
| 105 | 115 |
arch/x86/lib/Makefile
| 1 | # | 1 | # |
| 2 | # (C) Copyright 2002-2006 | 2 | # (C) Copyright 2002-2006 |
| 3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. | 3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | # | 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0+ | 5 | # SPDX-License-Identifier: GPL-2.0+ |
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | ifndef CONFIG_X86_64 | 8 | ifndef CONFIG_X86_64 |
| 9 | obj-y += bios.o | 9 | obj-y += bios.o |
| 10 | obj-y += bios_asm.o | 10 | obj-y += bios_asm.o |
| 11 | obj-y += bios_interrupts.o | 11 | obj-y += bios_interrupts.o |
| 12 | endif | 12 | endif |
| 13 | ifndef CONFIG_SPL_BUILD | 13 | ifndef CONFIG_SPL_BUILD |
| 14 | obj-$(CONFIG_CMD_BOOTM) += bootm.o | 14 | obj-$(CONFIG_CMD_BOOTM) += bootm.o |
| 15 | endif | 15 | endif |
| 16 | obj-y += cmd_boot.o | 16 | obj-y += cmd_boot.o |
| 17 | obj-$(CONFIG_SEABIOS) += coreboot_table.o | 17 | obj-$(CONFIG_SEABIOS) += coreboot_table.o |
| 18 | obj-$(CONFIG_EFI) += efi/ | 18 | obj-$(CONFIG_EFI) += efi/ |
| 19 | obj-y += e820.o | 19 | obj-y += e820.o |
| 20 | obj-y += gcc.o | 20 | obj-y += gcc.o |
| 21 | obj-y += init_helpers.o | 21 | obj-y += init_helpers.o |
| 22 | obj-y += interrupts.o | 22 | obj-y += interrupts.o |
| 23 | obj-y += lpc-uclass.o | 23 | obj-y += lpc-uclass.o |
| 24 | obj-y += mpspec.o | 24 | obj-y += mpspec.o |
| 25 | obj-$(CONFIG_ENABLE_MRC_CACHE) += mrccache.o | 25 | obj-$(CONFIG_ENABLE_MRC_CACHE) += mrccache.o |
| 26 | obj-y += cmd_mtrr.o | 26 | obj-y += cmd_mtrr.o |
| 27 | obj-y += northbridge-uclass.o | 27 | obj-y += northbridge-uclass.o |
| 28 | obj-$(CONFIG_I8259_PIC) += i8259.o | 28 | obj-$(CONFIG_I8259_PIC) += i8259.o |
| 29 | obj-$(CONFIG_I8254_TIMER) += i8254.o | 29 | obj-$(CONFIG_I8254_TIMER) += i8254.o |
| 30 | obj-y += pinctrl_ich6.o | 30 | obj-y += pinctrl_ich6.o |
| 31 | obj-y += pirq_routing.o | 31 | obj-y += pirq_routing.o |
| 32 | obj-y += relocate.o | 32 | obj-y += relocate.o |
| 33 | obj-y += physmem.o | 33 | obj-y += physmem.o |
| 34 | obj-$(CONFIG_INTEL_MID) += pmu.o | 34 | obj-$(CONFIG_INTEL_MID) += pmu.o |
| 35 | obj-$(CONFIG_X86_RAMTEST) += ramtest.o | 35 | obj-$(CONFIG_X86_RAMTEST) += ramtest.o |
| 36 | obj-$(CONFIG_INTEL_MID) += scu.o | 36 | obj-$(CONFIG_INTEL_MID) += scu.o |
| 37 | obj-y += sections.o | 37 | obj-y += sections.o |
| 38 | obj-y += sfi.o | 38 | obj-y += sfi.o |
| 39 | obj-y += string.o | 39 | obj-y += string.o |
| 40 | obj-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.o | ||
| 40 | ifndef CONFIG_QEMU | 41 | ifndef CONFIG_QEMU |
| 41 | obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o | 42 | obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o |
| 42 | endif | 43 | endif |
| 43 | obj-y += tables.o | 44 | obj-y += tables.o |
| 44 | ifndef CONFIG_SPL_BUILD | 45 | ifndef CONFIG_SPL_BUILD |
| 45 | obj-$(CONFIG_CMD_ZBOOT) += zimage.o | 46 | obj-$(CONFIG_CMD_ZBOOT) += zimage.o |
| 46 | endif | 47 | endif |
| 47 | obj-$(CONFIG_HAVE_FSP) += fsp/ | 48 | obj-$(CONFIG_HAVE_FSP) += fsp/ |
| 48 | obj-$(CONFIG_SPL_BUILD) += spl.o | 49 | obj-$(CONFIG_SPL_BUILD) += spl.o |
| 49 | 50 | ||
| 50 | extra-$(CONFIG_USE_PRIVATE_LIBGCC) += lib.a | 51 | extra-$(CONFIG_USE_PRIVATE_LIBGCC) += lib.a |
| 51 | 52 | ||
| 52 | NORMAL_LIBGCC = $(shell $(CC) $(PLATFORM_CPPFLAGS) -print-libgcc-file-name) | 53 | NORMAL_LIBGCC = $(shell $(CC) $(PLATFORM_CPPFLAGS) -print-libgcc-file-name) |
| 53 | OBJCOPYFLAGS := --prefix-symbols=__normal_ | 54 | OBJCOPYFLAGS := --prefix-symbols=__normal_ |
| 54 | $(obj)/lib.a: $(NORMAL_LIBGCC) FORCE | 55 | $(obj)/lib.a: $(NORMAL_LIBGCC) FORCE |
| 55 | $(call if_changed,objcopy) | 56 | $(call if_changed,objcopy) |
| 56 | 57 | ||
| 57 | ifeq ($(CONFIG_$(SPL_)X86_64),) | 58 | ifeq ($(CONFIG_$(SPL_)X86_64),) |
| 58 | obj-$(CONFIG_EFI_APP) += crt0_ia32_efi.o reloc_ia32_efi.o | 59 | obj-$(CONFIG_EFI_APP) += crt0_ia32_efi.o reloc_ia32_efi.o |
| 59 | endif | 60 | endif |
| 60 | 61 | ||
| 61 | ifneq ($(CONFIG_EFI_STUB),) | 62 | ifneq ($(CONFIG_EFI_STUB),) |
| 62 | 63 | ||
| 63 | CFLAGS_REMOVE_reloc_ia32_efi.o += -mregparm=3 | 64 | CFLAGS_REMOVE_reloc_ia32_efi.o += -mregparm=3 |
| 64 | CFLAGS_reloc_ia32_efi.o += -fpic -fshort-wchar | 65 | CFLAGS_reloc_ia32_efi.o += -fpic -fshort-wchar |
| 65 | 66 | ||
| 66 | # When building for 64-bit we must remove the i386-specific flags | 67 | # When building for 64-bit we must remove the i386-specific flags |
| 67 | CFLAGS_REMOVE_reloc_x86_64_efi.o += -mregparm=3 -march=i386 -m32 | 68 | CFLAGS_REMOVE_reloc_x86_64_efi.o += -mregparm=3 -march=i386 -m32 |
| 68 | CFLAGS_reloc_x86_64_efi.o += -fpic -fshort-wchar | 69 | CFLAGS_reloc_x86_64_efi.o += -fpic -fshort-wchar |
| 69 | 70 | ||
| 70 | AFLAGS_REMOVE_crt0_x86_64_efi.o += -mregparm=3 -march=i386 -m32 | 71 | AFLAGS_REMOVE_crt0_x86_64_efi.o += -mregparm=3 -march=i386 -m32 |
| 71 | AFLAGS_crt0_x86_64_efi.o += -fpic -fshort-wchar | 72 | AFLAGS_crt0_x86_64_efi.o += -fpic -fshort-wchar |
| 72 | 73 | ||
| 73 | extra-$(CONFIG_EFI_STUB_32BIT) += crt0_ia32_efi.o reloc_ia32_efi.o | 74 | extra-$(CONFIG_EFI_STUB_32BIT) += crt0_ia32_efi.o reloc_ia32_efi.o |
| 74 | extra-$(CONFIG_EFI_STUB_64BIT) += crt0_x86_64_efi.o reloc_x86_64_efi.o | 75 | extra-$(CONFIG_EFI_STUB_64BIT) += crt0_x86_64_efi.o reloc_x86_64_efi.o |
| 75 | 76 | ||
| 76 | endif | 77 | endif |
| 77 | 78 | ||
| 78 | ifneq ($(CONFIG_EFI_STUB)$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),) | 79 | ifneq ($(CONFIG_EFI_STUB)$(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),) |
| 79 | ifeq ($(CONFIG_$(SPL_)X86_64),) | 80 | ifeq ($(CONFIG_$(SPL_)X86_64),) |
| 80 | extra-y += $(EFI_CRT0) $(EFI_RELOC) | 81 | extra-y += $(EFI_CRT0) $(EFI_RELOC) |
| 81 | endif | 82 | endif |
| 82 | endif | 83 | endif |
| 83 | 84 |
arch/x86/lib/acpi_s3.c
| File was created | 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 | } | ||
| 27 |