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 "util.h" // dprintf
8 #include "ioport.h" // outb
9 #include "pic.h" // eoi_pic2
10 #include "biosvar.h" // struct bios_data_area_s
11 #include "bregs.h" // struct bregs
12 #include "acpi.h" // find_resume_vector
13 #include "ps2port.h" // i8042_reboot
14 #include "pci.h" // pci_reboot
15 #include "cmos.h" // inb_cmos
17 // Indicator if POST phase has been run.
18 int HaveRunPost VAR16VISIBLE;
20 // Reset DMA controller
24 // first reset the DMA controllers
25 outb(0, PORT_DMA1_MASTER_CLEAR);
26 outb(0, PORT_DMA2_MASTER_CLEAR);
28 // then initialize the DMA controllers
29 outb(0xc0, PORT_DMA2_MODE_REG);
30 outb(0x00, PORT_DMA2_MASK_REG);
33 // Handler for post calls that look like a resume.
38 int status = inb_cmos(CMOS_RESET_CODE);
39 outb_cmos(0, CMOS_RESET_CODE);
40 dprintf(1, "In resume (status=%d)\n", status);
47 panic("Unimplemented shutdown status: %02x\n", status);
50 // flush keyboard (issue EOI) and jump via 40h:0067h
54 #define BDA_JUMP (((struct bios_data_area_s *)0)->jump)
55 // resume execution by jump via 40h:0067h
59 : : "m"(BDA_JUMP), "r"(SEG_BDA)
64 // resume execution via IRET via 40h:0067h
69 : : "m"(BDA_JUMP), "r"(SEG_BDA)
74 // resume execution via RETF via 40h:0067h
79 : : "m"(BDA_JUMP), "r"(SEG_BDA)
87 // Not a 16bit resume - do remaining checks in 32bit mode
91 "movl $_cfunc32flat_handle_resume32, %%edx\n"
93 : : "i"(BUILD_S3RESUME_STACK_ADDR), "r"(0), "a"(status)
97 // Handle an S3 resume event
101 if (!CONFIG_S3_RESUME)
104 u32 s3_resume_vector = find_resume_vector();
105 if (!s3_resume_vector) {
106 dprintf(1, "No resume vector set!\n");
112 s3_resume_vga_init();
114 make_bios_readonly();
116 // Invoke the resume vector.
118 memset(&br, 0, sizeof(br));
119 dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
120 br.code = FLATPTR_TO_SEGOFF((void*)s3_resume_vector);
124 // Attempt to invoke a hard-reboot.
128 dprintf(1, "Attempting a hard reboot\n");
130 // Setup for reset on qemu.
131 if (! CONFIG_COREBOOT) {
137 // Try keyboard controller reboot.
140 // Try PCI 0xcf9 reboot
144 asm volatile("int3");
146 panic("Could not reboot");
150 handle_resume32(int status)
153 dprintf(1, "In 32bit resume\n");
158 // Must be a soft reboot - invoke a hard reboot.