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