1 // Code for handling calls to "post" that are resume related.
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "bregs.h" // struct bregs
8 #include "config.h" // CONFIG_*
9 #include "farptr.h" // FLATPTR_TO_SEGOFF
10 #include "hw/pci.h" // pci_reboot
11 #include "hw/pic.h" // pic_eoi2
12 #include "hw/ps2port.h" // i8042_reboot
13 #include "hw/rtc.h" // rtc_read
14 #include "output.h" // dprintf
15 #include "stacks.h" // farcall16big
16 #include "std/bda.h" // struct bios_data_area_s
17 #include "string.h" // memset
18 #include "util.h" // dma_setup
19 #include "tcgbios.h" // tpm_s3_resume
21 // Handler for post calls that look like a resume.
26 int status = rtc_read(CMOS_RESET_CODE);
27 rtc_write(CMOS_RESET_CODE, 0);
28 dprintf(1, "In resume (status=%d)\n", status);
35 panic("Unimplemented shutdown status: %02x\n", status);
38 // flush keyboard (issue EOI) and jump via 40h:0067h
42 #define BDA_JUMP (((struct bios_data_area_s *)0)->jump)
43 // resume execution by jump via 40h:0067h
47 : : "m"(BDA_JUMP), "r"(SEG_BDA)
52 // resume execution via IRET via 40h:0067h
57 : : "m"(BDA_JUMP), "r"(SEG_BDA)
62 // resume execution via RETF via 40h:0067h
67 : : "m"(BDA_JUMP), "r"(SEG_BDA)
75 // Not a 16bit resume - do remaining checks in 32bit mode
79 "movl $_cfunc32flat_handle_resume32, %%edx\n"
81 : : "i"(BUILD_S3RESUME_STACK_ADDR), "r"(0), "a"(status)
85 // Handle an S3 resume event
89 if (!CONFIG_S3_RESUME)
92 u32 s3_resume_vector = find_resume_vector();
93 if (!s3_resume_vector) {
94 dprintf(1, "No resume vector set!\n");
103 /* resume TPM before we may measure option roms */
107 make_bios_readonly();
109 // Invoke the resume vector.
111 memset(&br, 0, sizeof(br));
112 dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
113 br.code = FLATPTR_TO_SEGOFF((void*)s3_resume_vector);
117 u8 HaveAttemptedReboot VARLOW;
119 // Attempt to invoke a hard-reboot.
123 if (HaveAttemptedReboot) {
124 // Hard reboot has failed - try to shutdown machine.
125 dprintf(1, "Unable to hard-reboot machine - attempting shutdown.\n");
128 HaveAttemptedReboot = 1;
130 dprintf(1, "Attempting a hard reboot\n");
132 // Setup for reset on qemu.
135 // Reboot using ACPI RESET_REG
138 // Try keyboard controller reboot.
141 // Try PCI 0xcf9 reboot
145 asm volatile("int3");
147 panic("Could not reboot");
151 handle_resume32(int status)
154 dprintf(1, "In 32bit resume\n");
159 // Must be a soft reboot - invoke a hard reboot.