blob: 20e2e3ddeada1f6d27bbfeb63702a25cde64efa8 [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
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050016init_dma(void)
Kevin O'Connor18e38b22008-12-10 20:40:13 -050017{
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'Connorf3fe3aa2010-12-05 12:38:33 -050043 "movl $_cfunc32flat_s3_resume, %%edx\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'Connor9f985422009-09-09 11:34:39 -040063#define BDA_JUMP (((struct bios_data_area_s *)0)->jump)
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'Connor9f985422009-09-09 11:34:39 -040068 : : "m"(BDA_JUMP), "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'Connor9f985422009-09-09 11:34:39 -040078 : : "m"(BDA_JUMP), "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'Connor9f985422009-09-09 11:34:39 -040088 : : "m"(BDA_JUMP), "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'Connor52a300f2009-12-26 23:32:57 -050096void VISIBLE32FLAT
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050097s3_resume(void)
Kevin O'Connor9967ab72008-12-18 21:57:33 -050098{
Kevin O'Connord705e5a2010-03-20 20:21:13 -040099 ASSERT32FLAT();
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
Kevin O'Connord282af72009-07-04 04:10:32 -0400107 s3_resume_vga_init();
108
Kevin O'Connor9967ab72008-12-18 21:57:33 -0500109 make_bios_readonly();
110
111 u32 s3_resume_vector = find_resume_vector();
112
113 // Invoke the resume vector.
114 struct bregs br;
115 memset(&br, 0, sizeof(br));
116 if (s3_resume_vector) {
117 dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
Kevin O'Connor9f985422009-09-09 11:34:39 -0400118 br.code = FLATPTR_TO_SEGOFF((void*)s3_resume_vector);
Kevin O'Connor9967ab72008-12-18 21:57:33 -0500119 } else {
120 dprintf(1, "No resume vector set!\n");
121 // Jump to the post vector to restart with a normal boot.
Kevin O'Connor9f985422009-09-09 11:34:39 -0400122 br.code = SEGOFF(SEG_BIOS, (u32)reset_vector - BUILD_BIOS_ADDR);
Kevin O'Connor9967ab72008-12-18 21:57:33 -0500123 }
124 call16big(&br);
125}