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