From 6869ba3c1ba37d74619482589dda4c73d6721521 Mon Sep 17 00:00:00 2001 From: jkim Date: Mon, 23 Mar 2009 22:35:30 +0000 Subject: - Clean up suspend/resume code for amd64. - Call acpi_resync_clock() to reset system time before hardclock is ready to tick. Note we assume the current timecounter hardware and RTC are already available for read operation. Tested by: mav --- sys/amd64/acpica/acpi_machdep.c | 7 ++++--- sys/amd64/acpica/acpi_wakecode.S | 38 +++++++++++++++++++------------------- sys/amd64/acpica/acpi_wakeup.c | 13 +++++-------- sys/amd64/acpica/genwakecode.sh | 2 +- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/sys/amd64/acpica/acpi_machdep.c b/sys/amd64/acpica/acpi_machdep.c index 8b4840e..c69f14a 100644 --- a/sys/amd64/acpica/acpi_machdep.c +++ b/sys/amd64/acpica/acpi_machdep.c @@ -40,11 +40,12 @@ __FBSDID("$FreeBSD$"); SYSCTL_DECL(_debug_acpi); -uint32_t acpi_resume_beep; +int acpi_resume_beep; TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep); -SYSCTL_UINT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep, +SYSCTL_INT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep, 0, "Beep the PC speaker when resuming"); -uint32_t acpi_reset_video; + +int acpi_reset_video; TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video); static int intr_model = ACPI_INTR_PIC; diff --git a/sys/amd64/acpica/acpi_wakecode.S b/sys/amd64/acpica/acpi_wakecode.S index 111486e..4165ec6 100644 --- a/sys/amd64/acpica/acpi_wakecode.S +++ b/sys/amd64/acpica/acpi_wakecode.S @@ -2,7 +2,7 @@ * Copyright (c) 2001 Takanori Watanabe * Copyright (c) 2001 Mitsuru IWASAKI * Copyright (c) 2003 Peter Wemm - * Copyright (c) 2008 Jung-uk Kim + * Copyright (c) 2008-2009 Jung-uk Kim * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,12 +66,14 @@ wakeup_start: mov %ax, %ds /* are offsets rather than selectors */ mov %ax, %ss movw $PAGE_SIZE - 8, %sp - pushw $0 + xorw %ax, %ax + pushw %ax popfw /* To debug resume hangs, beep the speaker if the user requested. */ - cmpw $0, resume_beep - wakeup_start - je 1f + testb $~0, resume_beep - wakeup_start + jz 1f + movb $0, resume_beep - wakeup_start movb $0xc0, %al outb %al, $0x42 movb $0x04, %al @@ -79,22 +81,16 @@ wakeup_start: inb $0x61, %al orb $0x3, %al outb %al, $0x61 - movw $0, resume_beep - wakeup_start 1: /* Re-initialize video BIOS if the reset_video tunable is set. */ - cmpw $0, reset_video - wakeup_start - je 1f + testb $~0, reset_video - wakeup_start + jz 1f + movb $0, reset_video - wakeup_start lcall $0xc000, $3 - movw $0, reset_video - wakeup_start - /* - * Set up segment registers for real mode again in case the - * previous BIOS call clobbers them. - */ - mov %cs, %ax - mov %ax, %ds - mov %ax, %ss + /* Re-start in case the previous BIOS call clobbers them. */ + jmp wakeup_start 1: /* @@ -204,6 +200,7 @@ wakeup_sw64: * space. Remember that jmp is relative and that we've been relocated, * so use an indirect jump. */ + ALIGN_TEXT .code64 wakeup_64: mov $bootdata64 - bootgdt, %eax @@ -215,6 +212,13 @@ wakeup_64: movq wakeup_retaddr - wakeup_start(%rbx), %rax jmp *%rax + .data + +resume_beep: + .byte 0 +reset_video: + .byte 0 + ALIGN_DATA bootgdt: .long 0x00000000 @@ -245,10 +249,6 @@ bootgdtdesc: .long bootgdt - wakeup_start /* Offset plus %ds << 4 */ ALIGN_DATA -resume_beep: - .long 0 -reset_video: - .long 0 wakeup_retaddr: .quad 0 wakeup_kpml4: diff --git a/sys/amd64/acpica/acpi_wakeup.c b/sys/amd64/acpica/acpi_wakeup.c index 5e3d5b1..02432f0 100644 --- a/sys/amd64/acpica/acpi_wakeup.c +++ b/sys/amd64/acpica/acpi_wakeup.c @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -67,8 +66,8 @@ CTASSERT(sizeof(wakecode) < PAGE_SIZE - 1024); #error this file needs sys/cdefs.h as a prerequisite #endif -extern uint32_t acpi_resume_beep; -extern uint32_t acpi_reset_video; +extern int acpi_resume_beep; +extern int acpi_reset_video; #ifdef SMP extern struct xpcb *stopxpcbs; @@ -280,8 +279,8 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state) } #endif - WAKECODE_FIXUP(resume_beep, uint32_t, acpi_resume_beep); - WAKECODE_FIXUP(reset_video, uint32_t, acpi_reset_video); + WAKECODE_FIXUP(resume_beep, uint8_t, (acpi_resume_beep != 0)); + WAKECODE_FIXUP(reset_video, uint8_t, (acpi_reset_video != 0)); WAKECODE_FIXUP(wakeup_xpcb, struct xpcb *, &stopxpcbs[0]); WAKECODE_FIXUP(wakeup_gdt, uint16_t, @@ -309,13 +308,11 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state) ia32_pause(); } else { fpusetregs(curthread, stopfpu); - - WAKECODE_FIXUP(resume_beep, uint32_t, 0); - WAKECODE_FIXUP(reset_video, uint32_t, 0); #ifdef SMP if (wakeup_cpus != 0) acpi_wakeup_cpus(sc, wakeup_cpus); #endif + acpi_resync_clock(sc); ret = 0; } diff --git a/sys/amd64/acpica/genwakecode.sh b/sys/amd64/acpica/genwakecode.sh index b485386..c9d0077 100755 --- a/sys/amd64/acpica/genwakecode.sh +++ b/sys/amd64/acpica/genwakecode.sh @@ -1,6 +1,6 @@ #!/bin/sh # $FreeBSD$ # -file2c 'static char wakecode[] = {' '};'