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