]>
Commit | Line | Data |
---|---|---|
13d40edd | 1 | /** @file\r |
58612f24 | 2 | Capsule Runtime Driver produces two UEFI capsule runtime services.\r |
5d69642d | 3 | (UpdateCapsule, QueryCapsuleCapabilities)\r |
de5b0df9 | 4 | It installs the Capsule Architectural Protocol defined in PI1.0a to signify \r |
109e9a61 | 5 | the capsule runtime services are ready.\r |
74fea867 | 6 | \r |
3f42faa7 | 7 | Copyright (c) 2006 - 2009, Intel Corporation. <BR>\r |
74fea867 | 8 | All rights reserved. This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
13d40edd | 16 | **/\r |
74fea867 | 17 | \r |
109e9a61 LG |
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 | |
74fea867 | 30 | \r |
3f42faa7 | 31 | //\r |
32 | // Handle for the installation of Capsule Architecture Protocol.\r | |
33 | //\r | |
34 | EFI_HANDLE mNewHandle = NULL;\r | |
35 | \r | |
5d69642d LG |
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 | |
3f42faa7 | 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 | |
5d69642d LG |
59 | @retval EFI_UNSUPPORTED CapsuleImage is not recognized by the firmware.\r |
60 | \r | |
61 | **/\r | |
74fea867 | 62 | EFI_STATUS\r |
63 | EFIAPI\r | |
64 | UpdateCapsule (\r | |
65 | IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r | |
66 | IN UINTN CapsuleCount,\r | |
67 | IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r | |
68 | )\r | |
74fea867 | 69 | {\r |
74fea867 | 70 | UINTN ArrayNumber;\r |
74fea867 | 71 | EFI_STATUS Status;\r |
74fea867 | 72 | EFI_CAPSULE_HEADER *CapsuleHeader;\r |
409d47b4 | 73 | BOOLEAN NeedReset;\r |
3f42faa7 | 74 | BOOLEAN InitiateReset;\r |
5d69642d LG |
75 | \r |
76 | //\r | |
77 | // Capsule Count can't be less than one.\r | |
78 | //\r | |
74fea867 | 79 | if (CapsuleCount < 1) {\r |
80 | return EFI_INVALID_PARAMETER;\r | |
81 | }\r | |
3f42faa7 | 82 | \r |
409d47b4 | 83 | NeedReset = FALSE;\r |
3f42faa7 | 84 | InitiateReset = FALSE;\r |
409d47b4 | 85 | CapsuleHeader = NULL;\r |
74fea867 | 86 | \r |
87 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
d12f75fe LG |
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 | |
74fea867 | 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 | |
d12f75fe | 96 | //\r |
3f42faa7 | 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 | |
6ee65722 LG |
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 | |
74fea867 | 110 | }\r |
111 | \r | |
d12f75fe | 112 | //\r |
3f42faa7 | 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 | |
5d69642d | 115 | //\r |
409d47b4 LG |
116 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r |
117 | CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r | |
d12f75fe | 118 | //\r |
409d47b4 LG |
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 | |
d12f75fe | 121 | //\r |
409d47b4 LG |
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 | |
d12f75fe | 129 | return Status;\r |
74fea867 | 130 | }\r |
409d47b4 LG |
131 | } else {\r |
132 | NeedReset = TRUE;\r | |
3f42faa7 | 133 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_INITIATE_RESET) != 0) {\r |
134 | InitiateReset = TRUE;\r | |
135 | }\r | |
74fea867 | 136 | }\r |
74fea867 | 137 | }\r |
409d47b4 LG |
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 | |
74fea867 | 146 | \r |
147 | //\r | |
409d47b4 LG |
148 | // ScatterGatherList is only referenced if the capsules are defined to persist across\r |
149 | // system reset. \r | |
74fea867 | 150 | //\r |
409d47b4 LG |
151 | if (ScatterGatherList == (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) {\r |
152 | return EFI_INVALID_PARAMETER;\r | |
74fea867 | 153 | }\r |
154 | \r | |
155 | //\r | |
409d47b4 | 156 | // Check if the platform supports update capsule across a system reset\r |
74fea867 | 157 | //\r |
409d47b4 LG |
158 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r |
159 | return EFI_UNSUPPORTED;\r | |
74fea867 | 160 | }\r |
161 | \r | |
409d47b4 LG |
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 = gRT->SetVariable (\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 | |
3f42faa7 | 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 | gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r | |
181 | }\r | |
409d47b4 | 182 | return Status;\r |
74fea867 | 183 | }\r |
184 | \r | |
5d69642d LG |
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 | |
74fea867 | 196 | \r |
5d69642d LG |
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 | |
74fea867 | 202 | \r |
5d69642d | 203 | **/\r |
74fea867 | 204 | EFI_STATUS\r |
205 | EFIAPI\r | |
206 | QueryCapsuleCapabilities (\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 | |
74fea867 | 212 | {\r |
213 | UINTN ArrayNumber;\r | |
214 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
215 | \r | |
5d69642d LG |
216 | //\r |
217 | // Capsule Count can't be less than one.\r | |
218 | //\r | |
74fea867 | 219 | if (CapsuleCount < 1) {\r |
220 | return EFI_INVALID_PARAMETER;\r | |
221 | }\r | |
5d69642d LG |
222 | \r |
223 | //\r | |
3f42faa7 | 224 | // Check whether input parameter is valid\r |
5d69642d | 225 | //\r |
74fea867 | 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 | |
d12f75fe LG |
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 | |
74fea867 | 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 | |
d12f75fe | 241 | //\r |
3f42faa7 | 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 | |
5d69642d | 249 | // Check Capsule image without populate flag is supported by firmware\r |
6ee65722 LG |
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 | |
74fea867 | 255 | }\r |
256 | \r | |
257 | //\r | |
5d69642d | 258 | // Assume that capsules have the same flags on reseting or not.\r |
74fea867 | 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 | |
109e9a61 | 265 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {\r |
74fea867 | 266 | return EFI_UNSUPPORTED;\r |
267 | }\r | |
5c526736 | 268 | *ResetType = EfiResetWarm; \r |
74fea867 | 269 | } else {\r |
5d69642d LG |
270 | //\r |
271 | // For non-reset capsule image.\r | |
272 | //\r | |
74fea867 | 273 | *ResetType = EfiResetCold;\r |
5c526736 LG |
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 | |
97b2c9b5 | 280 | *MaxiumCapsuleSize = PcdGet32(PcdMaxSizePopulateCapsule);\r |
5c526736 | 281 | } else {\r |
97b2c9b5 | 282 | *MaxiumCapsuleSize = PcdGet32(PcdMaxSizeNonPopulateCapsule);\r |
74fea867 | 283 | }\r |
5c526736 | 284 | \r |
74fea867 | 285 | return EFI_SUCCESS;\r |
286 | }\r | |
287 | \r | |
288 | \r | |
5d69642d LG |
289 | /**\r |
290 | \r | |
109e9a61 | 291 | This code installs UEFI capsule runtime service.\r |
5d69642d LG |
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 | |
74fea867 | 299 | EFI_STATUS\r |
300 | EFIAPI\r | |
301 | CapsuleServiceInitialize (\r | |
302 | IN EFI_HANDLE ImageHandle,\r | |
303 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
304 | )\r | |
74fea867 | 305 | {\r |
306 | EFI_STATUS Status;\r | |
5d69642d LG |
307 | \r |
308 | //\r | |
309 | // Install capsule runtime services into UEFI runtime service tables.\r | |
310 | //\r | |
109e9a61 LG |
311 | gRT->UpdateCapsule = UpdateCapsule;\r |
312 | gRT->QueryCapsuleCapabilities = QueryCapsuleCapabilities;\r | |
74fea867 | 313 | \r |
314 | //\r | |
5d69642d LG |
315 | // Install the Capsule Architectural Protocol on a new handle\r |
316 | // to signify the capsule runtime services are ready.\r | |
74fea867 | 317 | //\r |
74fea867 | 318 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
3f42faa7 | 319 | &mNewHandle,\r |
74fea867 | 320 | &gEfiCapsuleArchProtocolGuid,\r |
321 | NULL,\r | |
322 | NULL\r | |
323 | );\r | |
324 | ASSERT_EFI_ERROR (Status);\r | |
325 | \r | |
3f42faa7 | 326 | return Status;\r |
74fea867 | 327 | }\r |