Module Name:    src
Committed By:   martin
Date:           Fri May  4 16:07:59 UTC 2018

Modified Files:
        src/sys/arch/x86/acpi [netbsd-8]: acpi_wakeup.c

Log Message:
Pull up following revision(s) (requested by maya in ticket #784):
        sys/arch/x86/acpi/acpi_wakeup.c: revision 1.46
Save and restore xcr0 when doing ACPI sleeps. Should fix PR/49174.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.45.8.1 src/sys/arch/x86/acpi/acpi_wakeup.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/acpi/acpi_wakeup.c
diff -u src/sys/arch/x86/acpi/acpi_wakeup.c:1.45 src/sys/arch/x86/acpi/acpi_wakeup.c:1.45.8.1
--- src/sys/arch/x86/acpi/acpi_wakeup.c:1.45	Thu Oct 20 16:05:04 2016
+++ src/sys/arch/x86/acpi/acpi_wakeup.c	Fri May  4 16:07:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakeup.c,v 1.45 2016/10/20 16:05:04 maxv Exp $	*/
+/*	$NetBSD: acpi_wakeup.c,v 1.45.8.1 2018/05/04 16:07:59 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2011 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.45 2016/10/20 16:05:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakeup.c,v 1.45.8.1 2018/05/04 16:07:59 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -250,6 +250,7 @@ acpi_md_sleep_enter(int state)
 void
 acpi_cpu_sleep(struct cpu_info *ci)
 {
+	uint64_t xcr0 = 0;
 	int s;
 
 	KASSERT(!CPU_IS_PRIMARY(ci));
@@ -259,12 +260,21 @@ acpi_cpu_sleep(struct cpu_info *ci)
 	fpusave_cpu(true);
 	x86_disable_intr();
 
+	/*
+	 * XXX also need to save the PMCs, the dbregs, and probably a few
+	 * MSRs too.
+	 */
+	if (rcr4() & CR4_OSXSAVE)
+		xcr0 = rdxcr(0);
+
 	if (acpi_md_sleep_prepare(-1))
 		goto out;
 
 	/* Execute Wakeup */
 	cpu_init_msrs(ci, false);
 	fpuinit(ci);
+	if (rcr4() & CR4_OSXSAVE)
+		wrxcr(0, xcr0);
 
 #if NLAPIC > 0
 	lapic_enable();
@@ -285,6 +295,7 @@ out:
 int
 acpi_md_sleep(int state)
 {
+	uint64_t xcr0 = 0;
 	int s, ret = 0;
 #ifdef MULTIPROCESSOR
 	struct cpu_info *ci;
@@ -315,12 +326,21 @@ acpi_md_sleep(int state)
 	}
 #endif
 
+	/*
+	 * XXX also need to save the PMCs, the dbregs, and probably a few
+	 * MSRs too.
+	 */
+	if (rcr4() & CR4_OSXSAVE)
+		xcr0 = rdxcr(0);
+
 	if (acpi_md_sleep_prepare(state))
 		goto out;
 
 	/* Execute Wakeup */
 	cpu_init_msrs(&cpu_info_primary, false);
 	fpuinit(&cpu_info_primary);
+	if (rcr4() & CR4_OSXSAVE)
+		wrxcr(0, xcr0);
 	i8259_reinit();
 #if NLAPIC > 0
 	lapic_enable();

Reply via email to