]> git.proxmox.com Git - mirror_edk2.git/blame - UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.c
UefiPayloadPkg: Enhance UEFI payload for coreboot and Slim Bootloader
[mirror_edk2.git] / UefiPayloadPkg / Library / ResetSystemLib / ResetSystemLib.c
CommitLineData
04af8bf2
DG
1/** @file\r
2 Reset System Library functions for bootloader\r
3\r
4 Copyright (c) 2014 - 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 <PiDxe.h>\r
10#include <Library/BaseLib.h>\r
11#include <Library/DebugLib.h>\r
12#include <Library/IoLib.h>\r
13#include <Library/HobLib.h>\r
14#include <Library/BaseMemoryLib.h>\r
15#include <Guid/AcpiBoardInfoGuid.h>\r
16\r
17ACPI_BOARD_INFO mAcpiBoardInfo;\r
18\r
19/**\r
20 The constructor function to initialize mAcpiBoardInfo.\r
21\r
22 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
23\r
24**/\r
25RETURN_STATUS\r
26EFIAPI\r
27ResetSystemLibConstructor (\r
28 VOID\r
29 )\r
30{\r
31 EFI_HOB_GUID_TYPE *GuidHob;\r
32 ACPI_BOARD_INFO *AcpiBoardInfoPtr;\r
33\r
34 //\r
35 // Find the acpi board information guid hob\r
36 //\r
37 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);\r
38 ASSERT (GuidHob != NULL);\r
39\r
40 AcpiBoardInfoPtr = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);\r
41 CopyMem (&mAcpiBoardInfo, AcpiBoardInfoPtr, sizeof (ACPI_BOARD_INFO));\r
42\r
43 return EFI_SUCCESS;\r
44}\r
45\r
46\r
47VOID\r
48AcpiPmControl (\r
49 UINTN SuspendType\r
50 )\r
51{\r
52 UINTN PmCtrlReg;\r
53\r
54 ASSERT (SuspendType <= 7);\r
55\r
56 PmCtrlReg = (UINTN)mAcpiBoardInfo.PmCtrlRegBase;\r
57 IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (SuspendType << 10));\r
58 IoOr16 (PmCtrlReg, BIT13);\r
59 CpuDeadLoop ();\r
60}\r
61\r
62/**\r
63 Calling this function causes a system-wide reset. This sets\r
64 all circuitry within the system to its initial state. This type of reset\r
65 is asynchronous to system operation and operates without regard to\r
66 cycle boundaries.\r
67\r
68 System reset should not return, if it returns, it means the system does\r
69 not support cold reset.\r
70**/\r
71VOID\r
72EFIAPI\r
73ResetCold (\r
74 VOID\r
75 )\r
76{\r
77 IoWrite8 ((UINTN)mAcpiBoardInfo.ResetRegAddress, mAcpiBoardInfo.ResetValue);\r
78 CpuDeadLoop ();\r
79}\r
80\r
81/**\r
82 Calling this function causes a system-wide initialization. The processors\r
83 are set to their initial state, and pending cycles are not corrupted.\r
84\r
85 System reset should not return, if it returns, it means the system does\r
86 not support warm reset.\r
87**/\r
88VOID\r
89EFIAPI\r
90ResetWarm (\r
91 VOID\r
92 )\r
93{\r
94 IoWrite8 ((UINTN)mAcpiBoardInfo.ResetRegAddress, mAcpiBoardInfo.ResetValue);\r
95 CpuDeadLoop ();\r
96}\r
97\r
98/**\r
99 Calling this function causes the system to enter a power state equivalent\r
100 to the ACPI G2/S5 or G3 states.\r
101\r
102 System shutdown should not return, if it returns, it means the system does\r
103 not support shut down reset.\r
104**/\r
105VOID\r
106EFIAPI\r
107ResetShutdown (\r
108 VOID\r
109 )\r
110{\r
111 UINTN PmCtrlReg;\r
112\r
113 //\r
114 // GPE0_EN should be disabled to avoid any GPI waking up the system from S5\r
115 //\r
116 IoWrite16 ((UINTN)mAcpiBoardInfo.PmGpeEnBase, 0);\r
117\r
118 //\r
119 // Clear Power Button Status\r
120 //\r
121 IoWrite16((UINTN) mAcpiBoardInfo.PmEvtBase, BIT8);\r
122\r
123 //\r
124 // Transform system into S5 sleep state\r
125 //\r
126 PmCtrlReg = (UINTN)mAcpiBoardInfo.PmCtrlRegBase;\r
127 IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (7 << 10));\r
128 IoOr16 (PmCtrlReg, BIT13);\r
129 CpuDeadLoop ();\r
130\r
131 ASSERT (FALSE);\r
132}\r
133\r
134/**\r
135 Calling this function causes the system to enter a power state for capsule\r
136 update.\r
137\r
138 Reset update should not return, if it returns, it means the system does\r
139 not support capsule update.\r
140\r
141**/\r
142VOID\r
143EFIAPI\r
144EnterS3WithImmediateWake (\r
145 VOID\r
146 )\r
147{\r
148 AcpiPmControl (5);\r
149 ASSERT (FALSE);\r
150}\r
151\r
152/**\r
153 This function causes a systemwide reset. The exact type of the reset is\r
154 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
155 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
156 the platform must pick a supported reset type to perform.The platform may\r
157 optionally log the parameters from any non-normal reset that occurs.\r
158\r
159 @param[in] DataSize The size, in bytes, of ResetData.\r
160 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
161 followed by the EFI_GUID.\r
162**/\r
163VOID\r
164EFIAPI\r
165ResetPlatformSpecific (\r
166 IN UINTN DataSize,\r
167 IN VOID *ResetData\r
168 )\r
169{\r
170 ResetCold ();\r
171}\r