]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
b3abda80e75a152bc76afa1f112e577345fc1d17
[mirror_edk2.git] / OvmfPkg / Library / ResetSystemLib / ResetSystemLib.c
1 /** @file
2 Reset System Library functions for OVMF
3
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/IoLib.h>
14 #include <Library/PciLib.h>
15 #include <Library/TimerLib.h>
16 #include <OvmfPlatforms.h>
17
18 VOID
19 AcpiPmControl (
20 UINTN SuspendType
21 )
22 {
23 UINT16 AcpiPmBaseAddress;
24 UINT16 HostBridgeDevId;
25
26 ASSERT (SuspendType < 6);
27
28 AcpiPmBaseAddress = 0;
29 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
30 switch (HostBridgeDevId) {
31 case INTEL_82441_DEVICE_ID:
32 AcpiPmBaseAddress = PIIX4_PMBA_VALUE;
33 break;
34 case INTEL_Q35_MCH_DEVICE_ID:
35 AcpiPmBaseAddress = ICH9_PMBASE_VALUE;
36 break;
37 default:
38 ASSERT (FALSE);
39 CpuDeadLoop ();
40 }
41
42 IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, (UINT16) SuspendType);
43 IoOr16 (AcpiPmBaseAddress + 4, BIT13);
44 CpuDeadLoop ();
45 }
46
47 /**
48 Calling this function causes a system-wide reset. This sets
49 all circuitry within the system to its initial state. This type of reset
50 is asynchronous to system operation and operates without regard to
51 cycle boundaries.
52
53 System reset should not return, if it returns, it means the system does
54 not support cold reset.
55 **/
56 VOID
57 EFIAPI
58 ResetCold (
59 VOID
60 )
61 {
62 IoWrite8 (0xCF9, BIT2 | BIT1); // 1st choice: PIIX3 RCR, RCPU|SRST
63 MicroSecondDelay (50);
64
65 IoWrite8 (0x64, 0xfe); // 2nd choice: keyboard controller
66 CpuDeadLoop ();
67 }
68
69 /**
70 Calling this function causes a system-wide initialization. The processors
71 are set to their initial state, and pending cycles are not corrupted.
72
73 System reset should not return, if it returns, it means the system does
74 not support warm reset.
75 **/
76 VOID
77 EFIAPI
78 ResetWarm (
79 VOID
80 )
81 {
82 IoWrite8 (0x64, 0xfe);
83 CpuDeadLoop ();
84 }
85
86 /**
87 Calling this function causes the system to enter a power state equivalent
88 to the ACPI G2/S5 or G3 states.
89
90 System shutdown should not return, if it returns, it means the system does
91 not support shut down reset.
92 **/
93 VOID
94 EFIAPI
95 ResetShutdown (
96 VOID
97 )
98 {
99 AcpiPmControl (0);
100 ASSERT (FALSE);
101 }
102
103
104 /**
105 This function causes a systemwide reset. The exact type of the reset is
106 defined by the EFI_GUID that follows the Null-terminated Unicode string
107 passed into ResetData. If the platform does not recognize the EFI_GUID in
108 ResetData the platform must pick a supported reset type to perform.The
109 platform may optionally log the parameters from any non-normal reset that
110 occurs.
111
112 @param[in] DataSize The size, in bytes, of ResetData.
113 @param[in] ResetData The data buffer starts with a Null-terminated string,
114 followed by the EFI_GUID.
115 **/
116 VOID
117 EFIAPI
118 ResetPlatformSpecific (
119 IN UINTN DataSize,
120 IN VOID *ResetData
121 )
122 {
123 ResetCold ();
124 }
125
126 /**
127 The ResetSystem function resets the entire platform.
128
129 @param[in] ResetType The type of reset to perform.
130 @param[in] ResetStatus The status code for the reset.
131 @param[in] DataSize The size, in bytes, of ResetData.
132 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
133 EfiResetShutdown the data buffer starts with a
134 Null-terminated string, optionally followed by
135 additional binary data. The string is a description
136 that the caller may use to further indicate the
137 reason for the system reset.
138 **/
139 VOID
140 EFIAPI
141 ResetSystem (
142 IN EFI_RESET_TYPE ResetType,
143 IN EFI_STATUS ResetStatus,
144 IN UINTN DataSize,
145 IN VOID *ResetData OPTIONAL
146 )
147 {
148 switch (ResetType) {
149 case EfiResetWarm:
150 ResetWarm ();
151 break;
152
153 case EfiResetCold:
154 ResetCold ();
155 break;
156
157 case EfiResetShutdown:
158 ResetShutdown ();
159 return;
160
161 case EfiResetPlatformSpecific:
162 ResetPlatformSpecific (DataSize, ResetData);
163 return;
164
165 default:
166 return;
167 }
168 }