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