MdeModulePkg/ResetSystem: Remove unnecessary global variable
[mirror_edk2.git] / MdeModulePkg / Universal / ResetSystemRuntimeDxe / ResetSystem.c
1 /** @file
2 Reset Architectural Protocol implementation
3
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "ResetSystem.h"
17
18 /**
19 The driver's entry point.
20
21 It initializes the Reset Architectural Protocol.
22
23 @param[in] ImageHandle The firmware allocated handle for the EFI image.
24 @param[in] SystemTable A pointer to the EFI System Table.
25
26 @retval EFI_SUCCESS The entry point is executed successfully.
27 @retval other Cannot install ResetArch protocol.
28
29 **/
30 EFI_STATUS
31 EFIAPI
32 InitializeResetSystem (
33 IN EFI_HANDLE ImageHandle,
34 IN EFI_SYSTEM_TABLE *SystemTable
35 )
36 {
37 EFI_STATUS Status;
38 EFI_HANDLE Handle;
39
40 //
41 // Make sure the Reset Architectural Protocol is not already installed in the system
42 //
43 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);
44
45 //
46 // Hook the runtime service table
47 //
48 gRT->ResetSystem = ResetSystem;
49
50 //
51 // Now install the Reset RT AP on a new handle
52 //
53 Handle = NULL;
54 Status = gBS->InstallMultipleProtocolInterfaces (
55 &Handle,
56 &gEfiResetArchProtocolGuid,
57 NULL,
58 NULL
59 );
60 ASSERT_EFI_ERROR (Status);
61
62 return Status;
63 }
64
65 /**
66 Put the system into S3 power state.
67 **/
68 VOID
69 DoS3 (
70 VOID
71 )
72 {
73 EnterS3WithImmediateWake ();
74
75 //
76 // Should not return
77 //
78 CpuDeadLoop ();
79 }
80
81 /**
82 Resets the entire platform.
83
84 @param[in] ResetType The type of reset to perform.
85 @param[in] ResetStatus The status code for the reset.
86 @param[in] DataSize The size, in bytes, of ResetData.
87 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
88 EfiResetShutdown the data buffer starts with a Null-terminated
89 string, optionally followed by additional binary data.
90 The string is a description that the caller may use to further
91 indicate the reason for the system reset. ResetData is only
92 valid if ResetStatus is something other than EFI_SUCCESS
93 unless the ResetType is EfiResetPlatformSpecific
94 where a minimum amount of ResetData is always required.
95 **/
96 VOID
97 EFIAPI
98 ResetSystem (
99 IN EFI_RESET_TYPE ResetType,
100 IN EFI_STATUS ResetStatus,
101 IN UINTN DataSize,
102 IN VOID *ResetData OPTIONAL
103 )
104 {
105 EFI_STATUS Status;
106 UINTN Size;
107 UINTN CapsuleDataPtr;
108
109 //
110 // Indicate reset system runtime service is called.
111 //
112 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));
113
114 switch (ResetType) {
115 case EfiResetWarm:
116
117 //
118 //Check if there are pending capsules to process
119 //
120 Size = sizeof (CapsuleDataPtr);
121 Status = EfiGetVariable (
122 EFI_CAPSULE_VARIABLE_NAME,
123 &gEfiCapsuleVendorGuid,
124 NULL,
125 &Size,
126 (VOID *) &CapsuleDataPtr
127 );
128
129 if (Status == EFI_SUCCESS) {
130 //
131 //Process capsules across a system reset.
132 //
133 DoS3();
134 }
135
136 ResetWarm ();
137
138 break;
139
140 case EfiResetCold:
141 ResetCold ();
142 break;
143
144 case EfiResetShutdown:
145 ResetShutdown ();
146 return ;
147
148 case EfiResetPlatformSpecific:
149 ResetPlatformSpecific (DataSize, ResetData);
150 return;
151
152 default:
153 return ;
154 }
155
156 //
157 // Given we should have reset getting here would be bad
158 //
159 ASSERT (FALSE);
160 }