blob: aab52edc1162f7f066caa9ab2739a73a82d58ad1 [file] [log] [blame]
Kevin O'Connor18e38b22008-12-10 20:40:13 -05001// Code for handling calls to "post" that are resume related.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connor18e38b22008-12-10 20:40:13 -05006
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
Kevin O'Connor9967ab72008-12-18 21:57:33 -050011#include "bregs.h" // struct bregs
12#include "acpi.h" // find_resume_vector
Kevin O'Connor18e38b22008-12-10 20:40:13 -050013
14// Reset DMA controller
15void
16init_dma()
17{
18 // first reset the DMA controllers
19 outb(0, PORT_DMA1_MASTER_CLEAR);
20 outb(0, PORT_DMA2_MASTER_CLEAR);
21
22 // then initialize the DMA controllers
23 outb(0xc0, PORT_DMA2_MODE_REG);
24 outb(0x00, PORT_DMA2_MASK_REG);
25}
26
27// Handler for post calls that look like a resume.
28void VISIBLE16
29handle_resume(u8 status)
30{
31 init_dma();
32
33 debug_serial_setup();
34 dprintf(1, "In resume (status=%d)\n", status);
35
36 switch (status) {
Kevin O'Connor9967ab72008-12-18 21:57:33 -050037 case 0xfe:
Kevin O'Connorb24c5742009-01-17 21:52:52 -050038 if (CONFIG_S3_RESUME) {
39 // S3 resume request. Jump to 32bit mode to handle the resume.
40 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050041 "movw %w1, %%ss\n"
Kevin O'Connorb24c5742009-01-17 21:52:52 -050042 "movl %0, %%esp\n"
43 "pushl $_code32_s3_resume\n"
44 "jmp transition32\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050045 : : "i"(BUILD_S3RESUME_STACK_ADDR), "r"(0)
Kevin O'Connorb24c5742009-01-17 21:52:52 -050046 );
47 break;
48 }
49 // NO BREAK
Kevin O'Connor18e38b22008-12-10 20:40:13 -050050 case 0x00:
51 case 0x09:
Kevin O'Connor9967ab72008-12-18 21:57:33 -050052 case 0x0d ... 0xfd:
53 case 0xff:
Kevin O'Connor18e38b22008-12-10 20:40:13 -050054 // Normal post - now that status has been cleared a reset will
55 // run regular boot code..
56 reset_vector();
57 break;
58
59 case 0x05:
60 // flush keyboard (issue EOI) and jump via 40h:0067h
61 eoi_pic2();
62 // NO BREAK
63 case 0x0a:
Kevin O'Connor590e7152009-01-19 12:53:54 -050064#define BDA_JUMP_IP (((struct bios_data_area_s *)0)->jump_ip)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050065 // resume execution by jump via 40h:0067h
Kevin O'Connor18e38b22008-12-10 20:40:13 -050066 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050067 "movw %w1, %%ds\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050068 "ljmpw *%0\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050069 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050070 );
71 break;
72
73 case 0x0b:
74 // resume execution via IRET via 40h:0067h
75 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050076 "movw %w1, %%ds\n"
77 "lssw %0, %%sp\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050078 "iretw\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050079 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050080 );
81 break;
82
83 case 0x0c:
84 // resume execution via RETF via 40h:0067h
85 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050086 "movw %w1, %%ds\n"
87 "lssw %0, %%sp\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050088 "lretw\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050089 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050090 );
91 break;
92 }
93
94 BX_PANIC("Unimplemented shutdown status: %02x\n", status);
95}
Kevin O'Connor9967ab72008-12-18 21:57:33 -050096
97void VISIBLE32
98s3_resume()
99{
Kevin O'Connorb24c5742009-01-17 21:52:52 -0500100 if (!CONFIG_S3_RESUME)
101 BX_PANIC("S3 resume support not compiled in.\n");
102
Kevin O'Connor9967ab72008-12-18 21:57:33 -0500103 dprintf(1, "In 32bit resume\n");
104
105 smm_init();
106
107 make_bios_readonly();
108
109 u32 s3_resume_vector = find_resume_vector();
110
111 // Invoke the resume vector.
112 struct bregs br;
113 memset(&br, 0, sizeof(br));
114 if (s3_resume_vector) {
115 dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500116 br.ip = FLATPTR_TO_OFFSET(s3_resume_vector);
117 br.cs = FLATPTR_TO_SEG(s3_resume_vector);
Kevin O'Connor9967ab72008-12-18 21:57:33 -0500118 } else {
119 dprintf(1, "No resume vector set!\n");
120 // Jump to the post vector to restart with a normal boot.
121 br.ip = (u32)reset_vector - BUILD_BIOS_ADDR;
122 br.cs = SEG_BIOS;
123 }
124 call16big(&br);
125}
Kevin O'Connorcc6a3772008-12-19 16:48:20 -0500126
127// Ughh - some older gcc compilers have a bug which causes VISIBLE32
128// functions to not be exported as global variables.
129asm(".global s3_resume");