]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
enhanced Dhcp4Dxe module to clean active configure data when Dhcp4->Stop() and Dhcp4...
[mirror_edk2.git] / MdeModulePkg / Universal / CapsuleRuntimeDxe / CapsuleService.c
... / ...
CommitLineData
1/** @file\r
2 Capsule Runtime Driver produces two UEFI capsule runtime services.\r
3 (UpdateCapsule, QueryCapsuleCapabilities)\r
4 It installs the Capsule Architectural Protocol defined in PI1.0a to signify \r
5 the capsule runtime services are ready.\r
6\r
7Copyright (c) 2006 - 2010, Intel Corporation. <BR>\r
8All rights reserved. This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include <Uefi.h>\r
19\r
20#include <Protocol/Capsule.h>\r
21#include <Guid/CapsuleVendor.h>\r
22\r
23#include <Library/DebugLib.h>\r
24#include <Library/PcdLib.h>\r
25#include <Library/CapsuleLib.h>\r
26#include <Library/UefiDriverEntryPoint.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/UefiRuntimeServicesTableLib.h>\r
29#include <Library/UefiRuntimeLib.h>\r
30\r
31//\r
32// Handle for the installation of Capsule Architecture Protocol.\r
33//\r
34EFI_HANDLE mNewHandle = NULL;\r
35\r
36/**\r
37 Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended\r
38 consumption, the firmware may process the capsule immediately. If the payload should persist\r
39 across a system reset, the reset value returned from EFI_QueryCapsuleCapabilities must\r
40 be passed into ResetSystem() and will cause the capsule to be processed by the firmware as\r
41 part of the reset process.\r
42\r
43 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r
44 being passed into update capsule.\r
45 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in\r
46 CaspuleHeaderArray.\r
47 @param ScatterGatherList Physical pointer to a set of\r
48 EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the\r
49 location in physical memory of a set of capsules.\r
50\r
51 @retval EFI_SUCCESS Valid capsule was passed. If\r
52 CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the\r
53 capsule has been successfully processed by the firmware.\r
54 @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.\r
55 @retval EFI_INVALID_PARAMETER CapsuleSize is NULL, or an incompatible set of flags were\r
56 set in the capsule header.\r
57 @retval EFI_INVALID_PARAMETER CapsuleCount is Zero.\r
58 @retval EFI_INVALID_PARAMETER For across reset capsule image, ScatterGatherList is NULL.\r
59 @retval EFI_UNSUPPORTED CapsuleImage is not recognized by the firmware.\r
60\r
61**/\r
62EFI_STATUS\r
63EFIAPI\r
64UpdateCapsule (\r
65 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
66 IN UINTN CapsuleCount,\r
67 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
68 )\r
69{\r
70 UINTN ArrayNumber;\r
71 EFI_STATUS Status;\r
72 EFI_CAPSULE_HEADER *CapsuleHeader;\r
73 BOOLEAN NeedReset;\r
74 BOOLEAN InitiateReset;\r
75 \r
76 //\r
77 // Capsule Count can't be less than one.\r
78 //\r
79 if (CapsuleCount < 1) {\r
80 return EFI_INVALID_PARAMETER;\r
81 }\r
82\r
83 NeedReset = FALSE;\r
84 InitiateReset = FALSE;\r
85 CapsuleHeader = NULL;\r
86\r
87 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
88 //\r
89 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r
90 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
91 //\r
92 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
93 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
94 return EFI_INVALID_PARAMETER;\r
95 }\r
96 //\r
97 // A capsule which has the CAPSULE_FLAGS_INITIATE_RESET flag must have\r
98 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
99 //\r
100 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
101 return EFI_INVALID_PARAMETER;\r
102 }\r
103 //\r
104 // Check Capsule image without populate flag by firmware support capsule function \r
105 //\r
106 if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
107 (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
108 return EFI_UNSUPPORTED;\r
109 }\r
110 }\r
111\r
112 //\r
113 // Walk through all capsules, record whether there is a capsule needs reset\r
114 // or initiate reset. And then process capsules which has no reset flag directly.\r
115 //\r
116 for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
117 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
118 //\r
119 // Here should be in the boot-time for non-reset capsule image\r
120 // Platform specific update for the non-reset capsule image.\r
121 //\r
122 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) == 0) {\r
123 if (EfiAtRuntime ()) { \r
124 Status = EFI_UNSUPPORTED;\r
125 } else {\r
126 Status = ProcessCapsuleImage(CapsuleHeader);\r
127 }\r
128 if (EFI_ERROR(Status)) {\r
129 return Status;\r
130 }\r
131 } else {\r
132 NeedReset = TRUE;\r
133 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_INITIATE_RESET) != 0) {\r
134 InitiateReset = TRUE;\r
135 }\r
136 }\r
137 }\r
138 \r
139 //\r
140 // After launching all capsules who has no reset flag, if no more capsules claims\r
141 // for a system reset just return.\r
142 //\r
143 if (!NeedReset) {\r
144 return EFI_SUCCESS;\r
145 }\r
146\r
147 //\r
148 // ScatterGatherList is only referenced if the capsules are defined to persist across\r
149 // system reset. \r
150 //\r
151 if (ScatterGatherList == (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) {\r
152 return EFI_INVALID_PARAMETER;\r
153 }\r
154\r
155 //\r
156 // Check if the platform supports update capsule across a system reset\r
157 //\r
158 if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r
159 return EFI_UNSUPPORTED;\r
160 }\r
161\r
162 //\r
163 // ScatterGatherList is only referenced if the capsules are defined to persist across\r
164 // system reset. Set its value into NV storage to let pre-boot driver to pick it up \r
165 // after coming through a system reset.\r
166 //\r
167 Status = EfiSetVariable (\r
168 EFI_CAPSULE_VARIABLE_NAME,\r
169 &gEfiCapsuleVendorGuid,\r
170 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
171 sizeof (UINTN),\r
172 (VOID *) &ScatterGatherList\r
173 );\r
174 if (!EFI_ERROR (Status) && InitiateReset) {\r
175 //\r
176 // Firmware that encounters a capsule which has the CAPSULE_FLAGS_INITIATE_RESET Flag set in its header\r
177 // will initiate a reset of the platform which is compatible with the passed-in capsule request and will \r
178 // not return back to the caller.\r
179 //\r
180 EfiResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
181 }\r
182 return Status;\r
183}\r
184\r
185/**\r
186 Returns if the capsule can be supported via UpdateCapsule().\r
187\r
188 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r
189 being passed into update capsule.\r
190 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in\r
191 CaspuleHeaderArray.\r
192 @param MaxiumCapsuleSize On output the maximum size that UpdateCapsule() can\r
193 support as an argument to UpdateCapsule() via\r
194 CapsuleHeaderArray and ScatterGatherList.\r
195 @param ResetType Returns the type of reset required for the capsule update.\r
196\r
197 @retval EFI_SUCCESS Valid answer returned.\r
198 @retval EFI_UNSUPPORTED The capsule image is not supported on this platform, and\r
199 MaximumCapsuleSize and ResetType are undefined.\r
200 @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL, or ResetTyep is NULL,\r
201 Or CapsuleCount is Zero, or CapsuleImage is not valid.\r
202\r
203**/\r
204EFI_STATUS\r
205EFIAPI\r
206QueryCapsuleCapabilities (\r
207 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
208 IN UINTN CapsuleCount,\r
209 OUT UINT64 *MaxiumCapsuleSize,\r
210 OUT EFI_RESET_TYPE *ResetType\r
211 )\r
212{\r
213 UINTN ArrayNumber;\r
214 EFI_CAPSULE_HEADER *CapsuleHeader;\r
215\r
216 //\r
217 // Capsule Count can't be less than one.\r
218 //\r
219 if (CapsuleCount < 1) {\r
220 return EFI_INVALID_PARAMETER;\r
221 }\r
222 \r
223 //\r
224 // Check whether input parameter is valid\r
225 //\r
226 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r
227 return EFI_INVALID_PARAMETER;\r
228 }\r
229\r
230 CapsuleHeader = NULL;\r
231\r
232 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
233 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
234 //\r
235 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r
236 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
237 //\r
238 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
239 return EFI_INVALID_PARAMETER;\r
240 }\r
241 //\r
242 // A capsule which has the CAPSULE_FLAGS_INITIATE_RESET flag must have\r
243 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r
244 //\r
245 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET)) == CAPSULE_FLAGS_INITIATE_RESET) {\r
246 return EFI_INVALID_PARAMETER;\r
247 }\r
248 //\r
249 // Check Capsule image without populate flag is supported by firmware\r
250 //\r
251 if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r
252 (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r
253 return EFI_UNSUPPORTED;\r
254 }\r
255 }\r
256\r
257 //\r
258 // Assume that capsules have the same flags on reseting or not.\r
259 //\r
260 CapsuleHeader = CapsuleHeaderArray[0];\r
261 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
262 //\r
263 //Check if the platform supports update capsule across a system reset\r
264 //\r
265 if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r
266 return EFI_UNSUPPORTED;\r
267 }\r
268 *ResetType = EfiResetWarm; \r
269 } else {\r
270 //\r
271 // For non-reset capsule image.\r
272 //\r
273 *ResetType = EfiResetCold;\r
274 }\r
275 \r
276 //\r
277 // The support max capsule image size\r
278 //\r
279 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {\r
280 *MaxiumCapsuleSize = PcdGet32(PcdMaxSizePopulateCapsule);\r
281 } else {\r
282 *MaxiumCapsuleSize = PcdGet32(PcdMaxSizeNonPopulateCapsule);\r
283 }\r
284\r
285 return EFI_SUCCESS;\r
286}\r
287\r
288\r
289/**\r
290\r
291 This code installs UEFI capsule runtime service.\r
292\r
293 @param ImageHandle The firmware allocated handle for the EFI image. \r
294 @param SystemTable A pointer to the EFI System Table.\r
295\r
296 @retval EFI_SUCCESS UEFI Capsule Runtime Services are installed successfully. \r
297\r
298**/\r
299EFI_STATUS\r
300EFIAPI\r
301CapsuleServiceInitialize (\r
302 IN EFI_HANDLE ImageHandle,\r
303 IN EFI_SYSTEM_TABLE *SystemTable\r
304 )\r
305{\r
306 EFI_STATUS Status;\r
307 \r
308 //\r
309 // Install capsule runtime services into UEFI runtime service tables.\r
310 //\r
311 gRT->UpdateCapsule = UpdateCapsule;\r
312 gRT->QueryCapsuleCapabilities = QueryCapsuleCapabilities;\r
313\r
314 //\r
315 // Install the Capsule Architectural Protocol on a new handle\r
316 // to signify the capsule runtime services are ready.\r
317 //\r
318 Status = gBS->InstallMultipleProtocolInterfaces (\r
319 &mNewHandle,\r
320 &gEfiCapsuleArchProtocolGuid,\r
321 NULL,\r
322 NULL\r
323 );\r
324 ASSERT_EFI_ERROR (Status);\r
325\r
326 return Status;\r
327}\r