]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Library/ResetSystemLib/ResetSystemLib.c
Vlv2TbltDevicePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / ResetSystemLib / ResetSystemLib.c
CommitLineData
3cbfba02
DW
1/** @file\r
2\r
cdd1ae1f 3 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
9dc8036d
MK
4 SPDX-License-Identifier: BSD-2-Clause-Patent\r
5\r
3cbfba02
DW
6 \r\r
7\r
8\r
9Module Name:\r
10\r
11 IdeBus.h\r
12\r
13Abstract:\r
14\r
15 System reset Library Services. This library class provides a set of\r
16 methods to reset whole system with manipulate ICH.\r
17\r
18**/\r
19\r
20\r
21#include <Base.h>\r
22\r
23\r
24#include <Library/ResetSystemLib.h>\r
25#include <Library/BaseLib.h>\r
26#include <Library/IoLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/PciLib.h>\r
29\r
30#include "PchRegs.h"\r
31#include "Rsci.h"\r
32#include "Platform.h"\r
33\r
34#define RESET_GENERATOR_PORT R_PCH_RST_CNT\r
35\r
36VOID\r
37EFIAPI\r
38PlatformResetHook (\r
39 UINT8 ResetType\r
40 )\r
41{\r
42 //\r
43 // Platform need to save OS reset request/types for next Android boot\r
44 //\r
45 IoWrite8 (0x72, CMOS_RESET_TYPE_BY_OS);\r
46 IoWrite8 (0x73, ResetType);\r
47}\r
48\r
49/**\r
50 Calling this function causes a system-wide reset. This sets\r
51 all circuitry within the system to its initial state. This type of reset\r
52 is asynchronous to system operation and operates without regard to\r
53 cycle boundaries.\r
54\r
55 System reset should not return, if it returns, it means the system does\r
56 not support cold reset.\r
57**/\r
58VOID\r
59EFIAPI\r
60ResetCold (\r
61 VOID\r
62 )\r
63{\r
64 PlatformResetHook(COLD_RESET);\r
65 IoWrite8 (RESET_GENERATOR_PORT, 0x2);\r
66 IoWrite8 (RESET_GENERATOR_PORT, 0x6);\r
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
76VOID\r
77EFIAPI\r
78ResetWarm (\r
79 VOID\r
80 )\r
81{\r
82 PlatformResetHook(WARM_RESET);\r
83 IoWrite8 (RESET_GENERATOR_PORT, 0x0);\r
84 IoWrite8 (RESET_GENERATOR_PORT, 0x4);\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
94VOID\r
95EFIAPI\r
96ResetShutdown (\r
97 VOID\r
98 )\r
99{\r
100 UINT16 PchPmioBase;\r
101 UINT16 Data16;\r
102 UINT32 Data32;\r
103\r
104 PchPmioBase = (UINT16) (PciRead16 (PCI_LIB_ADDRESS(0, PCI_DEVICE_NUMBER_PCH_LPC, 0, R_PCH_LPC_ACPI_BASE)) & ~BIT0);\r
105\r
106 //\r
107 // Then, GPE0_EN should be disabled to avoid any GPI waking up the system from S5\r
108 //\r
109 Data16 = 0;\r
110 IoWrite16 (\r
111 (UINTN)(PchPmioBase + R_PCH_ACPI_GPE0a_EN),\r
112 (UINT16)Data16\r
113 );\r
114\r
115 //\r
116 // Clear Sleep SMI Status\r
117 //\r
118 IoWrite16 (PchPmioBase + R_PCH_SMI_STS,\r
119 (UINT16)(IoRead16 (PchPmioBase + R_PCH_SMI_STS) | B_PCH_SMI_STS_ON_SLP_EN));\r
120 //\r
121 // Clear Sleep Type Enable\r
122 //\r
123 IoWrite16 (PchPmioBase + R_PCH_SMI_EN,\r
124 (UINT16)(IoRead16 (PchPmioBase + R_PCH_SMI_EN) & (~B_PCH_SMI_EN_ON_SLP_EN)));\r
125 //\r
126 // Clear Power Button Status\r
127 //\r
128 IoWrite16(PchPmioBase + R_PCH_ACPI_PM1_STS, B_PCH_ACPI_PM1_STS_PWRBTN);\r
129\r
130 //\r
131 // Secondly, Power Button Status bit must be cleared\r
132 //\r
133 // Write a "1" to bit[8] of power button status register at\r
134 // (ABASE + PM1_STS) to clear this bit\r
135 // Clear it through SMI Status register\r
136 //\r
137 Data16 = B_PCH_SMI_STS_PM1_STS_REG;\r
138 IoWrite16 ((UINTN) (PchPmioBase + R_PCH_SMI_STS), Data16);\r
139\r
140 //\r
141 // Finally, transform system into S5 sleep state\r
142 //\r
143 Data32 = IoRead32 ((UINTN) (PchPmioBase + R_PCH_ACPI_PM1_CNT));\r
144\r
145 Data32 = (UINT32) ((Data32 &~(B_PCH_ACPI_PM1_CNT_SLP_TYP + B_PCH_ACPI_PM1_CNT_SLP_EN)) | V_PCH_ACPI_PM1_CNT_S5);\r
146\r
147 IoWrite32 ((UINTN) (PchPmioBase + R_PCH_ACPI_PM1_CNT), Data32);\r
148\r
149 Data32 = Data32 | B_PCH_ACPI_PM1_CNT_SLP_EN;\r
150\r
151 IoWrite32 ((UINTN) (PchPmioBase + R_PCH_ACPI_PM1_CNT), Data32);\r
152\r
153 return;\r
154}\r
155\r
156/**\r
157 Calling this function causes the system to enter a power state for capsule\r
158 update.\r
159\r
160 Reset update should not return, if it returns, it means the system does\r
161 not support capsule update.\r
162\r
163**/\r
164VOID\r
165EFIAPI\r
166EnterS3WithImmediateWake (\r
167 VOID\r
168 )\r
169{\r
170 ASSERT (FALSE);\r
171}\r
172\r
cdd1ae1f
RN
173/**\r
174 This function causes a systemwide reset. The exact type of the reset is\r
175 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
176 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
177 the platform must pick a supported reset type to perform.The platform may\r
178 optionally log the parameters from any non-normal reset that occurs.\r
179\r
180 @param[in] DataSize The size, in bytes, of ResetData.\r
181 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
182 followed by the EFI_GUID.\r
183**/\r
184VOID\r
185EFIAPI\r
186ResetPlatformSpecific (\r
187 IN UINTN DataSize,\r
188 IN VOID *ResetData\r
189 )\r
190{\r
191 ResetCold ();\r
192}\r