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