1 /** @file
2   Reset System Library functions for OVMF
3 
4   Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include <Base.h>
16 
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/TimerLib.h>
22 
23 VOID
AcpiPmControl(UINTN SuspendType)24 AcpiPmControl (
25   UINTN SuspendType
26   )
27 {
28   ASSERT (SuspendType < 6);
29 
30   IoBitFieldWrite16  (PcdGet16 (PcdAcpiPmBaseAddress) + 4, 10, 13, (UINT16) SuspendType);
31   IoOr16 (PcdGet16 (PcdAcpiPmBaseAddress) + 4, BIT13);
32   CpuDeadLoop ();
33 }
34 
35 /**
36   Calling this function causes a system-wide reset. This sets
37   all circuitry within the system to its initial state. This type of reset
38   is asynchronous to system operation and operates without regard to
39   cycle boundaries.
40 
41   System reset should not return, if it returns, it means the system does
42   not support cold reset.
43 **/
44 VOID
45 EFIAPI
ResetCold(VOID)46 ResetCold (
47   VOID
48   )
49 {
50   IoWrite8 (0xCF9, BIT2 | BIT1); // 1st choice: PIIX3 RCR, RCPU|SRST
51   MicroSecondDelay (50);
52 
53   IoWrite8 (0x64, 0xfe);         // 2nd choice: keyboard controller
54   CpuDeadLoop ();
55 }
56 
57 /**
58   Calling this function causes a system-wide initialization. The processors
59   are set to their initial state, and pending cycles are not corrupted.
60 
61   System reset should not return, if it returns, it means the system does
62   not support warm reset.
63 **/
64 VOID
65 EFIAPI
ResetWarm(VOID)66 ResetWarm (
67   VOID
68   )
69 {
70   IoWrite8 (0x64, 0xfe);
71   CpuDeadLoop ();
72 }
73 
74 /**
75   Calling this function causes the system to enter a power state equivalent
76   to the ACPI G2/S5 or G3 states.
77 
78   System shutdown should not return, if it returns, it means the system does
79   not support shut down reset.
80 **/
81 VOID
82 EFIAPI
ResetShutdown(VOID)83 ResetShutdown (
84   VOID
85   )
86 {
87   AcpiPmControl (0);
88   ASSERT (FALSE);
89 }
90 
91 
92 /**
93   Calling this function causes the system to enter a power state for capsule
94   update.
95 
96   Reset update should not return, if it returns, it means the system does
97   not support capsule update.
98 
99 **/
100 VOID
101 EFIAPI
EnterS3WithImmediateWake(VOID)102 EnterS3WithImmediateWake (
103   VOID
104   )
105 {
106   AcpiPmControl (1);
107   ASSERT (FALSE);
108 }
109