blob: 76a8c50d6a679d98077a56f2678dc37673ab0efa [file] [log] [blame]
Kevin O'Connor18e38b22008-12-10 20:40:13 -05001// Code for handling calls to "post" that are resume related.
2//
Kevin O'Connor14458432009-05-23 18:21:18 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor18e38b22008-12-10 20:40:13 -05004//
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"
Kevin O'Connor14458432009-05-23 18:21:18 -040043 "pushl $s3_resume\n"
Kevin O'Connorb24c5742009-01-17 21:52:52 -050044 "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:
Kevin O'Connor9967ab72008-12-18 21:57:33 -050051 case 0x0d ... 0xfd:
52 case 0xff:
Kevin O'Connor18e38b22008-12-10 20:40:13 -050053 // Normal post - now that status has been cleared a reset will
54 // run regular boot code..
55 reset_vector();
56 break;
57
58 case 0x05:
59 // flush keyboard (issue EOI) and jump via 40h:0067h
60 eoi_pic2();
61 // NO BREAK
62 case 0x0a:
Kevin O'Connor590e7152009-01-19 12:53:54 -050063#define BDA_JUMP_IP (((struct bios_data_area_s *)0)->jump_ip)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050064 // resume execution by jump via 40h:0067h
Kevin O'Connor18e38b22008-12-10 20:40:13 -050065 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050066 "movw %w1, %%ds\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050067 "ljmpw *%0\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050068 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050069 );
70 break;
71
72 case 0x0b:
73 // resume execution via IRET via 40h:0067h
74 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050075 "movw %w1, %%ds\n"
76 "lssw %0, %%sp\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050077 "iretw\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050078 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050079 );
80 break;
81
82 case 0x0c:
83 // resume execution via RETF via 40h:0067h
84 asm volatile(
Kevin O'Connor590e7152009-01-19 12:53:54 -050085 "movw %w1, %%ds\n"
86 "lssw %0, %%sp\n"
Kevin O'Connor18e38b22008-12-10 20:40:13 -050087 "lretw\n"
Kevin O'Connor590e7152009-01-19 12:53:54 -050088 : : "m"(BDA_JUMP_IP), "r"(SEG_BDA)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050089 );
90 break;
91 }
92
Kevin O'Connore07e18e2009-02-08 17:07:29 -050093 panic("Unimplemented shutdown status: %02x\n", status);
Kevin O'Connor18e38b22008-12-10 20:40:13 -050094}
Kevin O'Connor9967ab72008-12-18 21:57:33 -050095
Kevin O'Connor942d4952009-06-10 22:44:06 -040096#if MODE16==0
Kevin O'Connor9967ab72008-12-18 21:57:33 -050097void VISIBLE32
98s3_resume()
99{
Kevin O'Connorb24c5742009-01-17 21:52:52 -0500100 if (!CONFIG_S3_RESUME)
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500101 panic("S3 resume support not compiled in.\n");
Kevin O'Connorb24c5742009-01-17 21:52:52 -0500102
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'Connor942d4952009-06-10 22:44:06 -0400126#endif