]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c
ShellPkg: Add checking for memory allocation and pointer returns from functions.
[mirror_edk2.git] / MdeModulePkg / Universal / ResetSystemRuntimeDxe / ResetSystem.c
1 /** @file
2 Reset Architectural Protocol implementation
3
4 Copyright (c) 2006 - 2010, 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 handle onto which the Reset Architectural Protocol is installed
20 //
21 EFI_HANDLE mResetHandle = NULL;
22
23 /**
24 The driver's entry point.
25
26 It initializes the Reset Architectural Protocol.
27
28 @param[in] ImageHandle The firmware allocated handle for the EFI image.
29 @param[in] SystemTable A pointer to the EFI System Table.
30
31 @retval EFI_SUCCESS The entry point is executed successfully.
32 @retval other Cannot install ResetArch protocol.
33
34 **/
35 EFI_STATUS
36 EFIAPI
37 InitializeResetSystem (
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41 {
42 EFI_STATUS Status;
43
44 //
45 // Make sure the Reset Architectural Protocol is not already installed in the system
46 //
47 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);
48
49 //
50 // Hook the runtime service table
51 //
52 gRT->ResetSystem = ResetSystem;
53
54 //
55 // Now install the Reset RT AP on a new handle
56 //
57 Status = gBS->InstallMultipleProtocolInterfaces (
58 &mResetHandle,
59 &gEfiResetArchProtocolGuid,
60 NULL,
61 NULL
62 );
63 ASSERT_EFI_ERROR (Status);
64
65 return Status;
66 }
67
68 /**
69 Reset system for capsule update.
70
71 @param[in] CapsuleDataPtr Pointer to the capsule block descriptors.
72
73 **/
74 VOID
75 CapsuleReset (
76 IN UINTN CapsuleDataPtr
77 )
78 {
79 //
80 // This implementation assumes that we're using a variable
81 // to indicate capsule updates.
82 //
83 gRT->SetVariable (
84 EFI_CAPSULE_VARIABLE_NAME,
85 &gEfiCapsuleVendorGuid,
86 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
87 sizeof (UINTN),
88 (VOID *) &CapsuleDataPtr
89 );
90
91 EnterS3WithImmediateWake ();
92
93 //
94 // Should not return
95 //
96 CpuDeadLoop ();
97 }
98
99 /**
100 Put the system into S3 power state.
101 **/
102 VOID
103 DoS3 (
104 VOID
105 )
106 {
107 EnterS3WithImmediateWake ();
108
109 //
110 // Should not return
111 //
112 CpuDeadLoop ();
113 }
114
115 /**
116 Resets the entire platform.
117
118 @param[in] ResetType The type of reset to perform.
119 @param[in] ResetStatus The status code for the reset.
120 @param[in] DataSize The size, in bytes, of WatchdogData.
121 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
122 EfiResetShutdown the data buffer starts with a Null-terminated
123 string, optionally followed by additional binary data.
124
125 **/
126 VOID
127 EFIAPI
128 ResetSystem (
129 IN EFI_RESET_TYPE ResetType,
130 IN EFI_STATUS ResetStatus,
131 IN UINTN DataSize,
132 IN VOID *ResetData OPTIONAL
133 )
134 {
135 EFI_STATUS Status;
136 UINTN Size;
137 UINTN CapsuleDataPtr;
138
139 switch (ResetType) {
140 case EfiResetWarm:
141
142 //
143 //Check if there are pending capsules to process
144 //
145 Size = sizeof (CapsuleDataPtr);
146 Status = EfiGetVariable (
147 EFI_CAPSULE_VARIABLE_NAME,
148 &gEfiCapsuleVendorGuid,
149 NULL,
150 &Size,
151 (VOID *) &CapsuleDataPtr
152 );
153
154 if (Status == EFI_SUCCESS) {
155 //
156 //Process capsules across a system reset.
157 //
158 DoS3();
159 }
160
161 ResetWarm ();
162
163 break;
164
165 case EfiResetCold:
166 ResetCold ();
167 break;
168
169 case EfiResetShutdown:
170 ResetShutdown ();
171 return ;
172
173 default:
174 return ;
175 }
176
177 //
178 // Given we should have reset getting here would be bad
179 //
180 ASSERT (FALSE);
181 }