18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2001-2003 Pavel Machek <pavel@suse.cz>
48c2ecf20Sopenharmony_ci * Based on code
58c2ecf20Sopenharmony_ci * Copyright 2001 Patrick Mochel <mochel@osdl.org>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef _ASM_X86_SUSPEND_64_H
88c2ecf20Sopenharmony_ci#define _ASM_X86_SUSPEND_64_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <asm/desc.h>
118c2ecf20Sopenharmony_ci#include <asm/fpu/api.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * Image of the saved processor state, used by the low level ACPI suspend to
158c2ecf20Sopenharmony_ci * RAM code and by the low level hibernation code.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * If you modify it, check how it is used in arch/x86/kernel/acpi/wakeup_64.S
188c2ecf20Sopenharmony_ci * and make sure that __save/__restore_processor_state(), defined in
198c2ecf20Sopenharmony_ci * arch/x86/power/cpu.c, still work as required.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Because the structure is packed, make sure to avoid unaligned members. For
228c2ecf20Sopenharmony_ci * optimisation purposes but also because tools like kmemleak only search for
238c2ecf20Sopenharmony_ci * pointers that are aligned.
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_cistruct saved_context {
268c2ecf20Sopenharmony_ci	struct pt_regs regs;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	/*
298c2ecf20Sopenharmony_ci	 * User CS and SS are saved in current_pt_regs().  The rest of the
308c2ecf20Sopenharmony_ci	 * segment selectors need to be saved and restored here.
318c2ecf20Sopenharmony_ci	 */
328c2ecf20Sopenharmony_ci	u16 ds, es, fs, gs;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	/*
358c2ecf20Sopenharmony_ci	 * Usermode FSBASE and GSBASE may not match the fs and gs selectors,
368c2ecf20Sopenharmony_ci	 * so we save them separately.  We save the kernelmode GSBASE to
378c2ecf20Sopenharmony_ci	 * restore percpu access after resume.
388c2ecf20Sopenharmony_ci	 */
398c2ecf20Sopenharmony_ci	unsigned long kernelmode_gs_base, usermode_gs_base, fs_base;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	unsigned long cr0, cr2, cr3, cr4;
428c2ecf20Sopenharmony_ci	u64 misc_enable;
438c2ecf20Sopenharmony_ci	struct saved_msrs saved_msrs;
448c2ecf20Sopenharmony_ci	unsigned long efer;
458c2ecf20Sopenharmony_ci	u16 gdt_pad; /* Unused */
468c2ecf20Sopenharmony_ci	struct desc_ptr gdt_desc;
478c2ecf20Sopenharmony_ci	u16 idt_pad;
488c2ecf20Sopenharmony_ci	struct desc_ptr idt;
498c2ecf20Sopenharmony_ci	u16 ldt;
508c2ecf20Sopenharmony_ci	u16 tss;
518c2ecf20Sopenharmony_ci	unsigned long tr;
528c2ecf20Sopenharmony_ci	unsigned long safety;
538c2ecf20Sopenharmony_ci	unsigned long return_address;
548c2ecf20Sopenharmony_ci	bool misc_enable_saved;
558c2ecf20Sopenharmony_ci} __attribute__((packed));
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define loaddebug(thread,register) \
588c2ecf20Sopenharmony_ci	set_debugreg((thread)->debugreg##register, register)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* routines for saving/restoring kernel state */
618c2ecf20Sopenharmony_ciextern char core_restore_code[];
628c2ecf20Sopenharmony_ciextern char restore_registers[];
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#endif /* _ASM_X86_SUSPEND_64_H */
65