Pkg-Module: CorebootPayloadPkg
[mirror_edk2.git] / CorebootPayloadPkg / Library / ResetSystemLib / ResetSystemLib.c
1 /** @file
2 Reset System Library functions for coreboot
3
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/IoLib.h>
19 #include <Library/HobLib.h>
20
21 #include <Guid/AcpiBoardInfoGuid.h>
22
23 VOID
24 AcpiPmControl (
25 UINTN SuspendType
26 )
27 {
28 EFI_HOB_GUID_TYPE *GuidHob;
29 ACPI_BOARD_INFO *pAcpiBoardInfo;
30 UINTN PmCtrlReg = 0;
31
32 ASSERT (SuspendType <= 7);
33 //
34 // Find the acpi board information guid hob
35 //
36 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
37 ASSERT (GuidHob != NULL);
38 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
39
40 PmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;
41 IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (SuspendType << 10));
42 IoOr16 (PmCtrlReg, BIT13);
43 CpuDeadLoop ();
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 EFI_HOB_GUID_TYPE *GuidHob;
62 ACPI_BOARD_INFO *pAcpiBoardInfo;
63
64 //
65 // Find the acpi board information guid hob
66 //
67 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
68 ASSERT (GuidHob != NULL);
69 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
70
71 IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
72 CpuDeadLoop ();
73 }
74
75 /**
76 Calling this function causes a system-wide initialization. The processors
77 are set to their initial state, and pending cycles are not corrupted.
78
79 System reset should not return, if it returns, it means the system does
80 not support warm reset.
81 **/
82 VOID
83 EFIAPI
84 ResetWarm (
85 VOID
86 )
87 {
88 EFI_HOB_GUID_TYPE *GuidHob;
89 ACPI_BOARD_INFO *pAcpiBoardInfo;
90
91 //
92 // Find the acpi board information guid hob
93 //
94 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
95 ASSERT (GuidHob != NULL);
96 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
97
98 IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
99 CpuDeadLoop ();
100 }
101
102 /**
103 Calling this function causes the system to enter a power state equivalent
104 to the ACPI G2/S5 or G3 states.
105
106 System shutdown should not return, if it returns, it means the system does
107 not support shut down reset.
108 **/
109 VOID
110 EFIAPI
111 ResetShutdown (
112 VOID
113 )
114 {
115 AcpiPmControl (7);
116 ASSERT (FALSE);
117 }
118
119
120 /**
121 Calling this function causes the system to enter a power state for capsule
122 update.
123
124 Reset update should not return, if it returns, it means the system does
125 not support capsule update.
126
127 **/
128 VOID
129 EFIAPI
130 EnterS3WithImmediateWake (
131 VOID
132 )
133 {
134 AcpiPmControl (5);
135 ASSERT (FALSE);
136 }