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