]>
Commit | Line | Data |
---|---|---|
88266859 JY |
1 | /** @file\r |
2 | Produce FMP instance for Microcode.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "MicrocodeUpdate.h"\r | |
16 | \r | |
17 | //\r | |
18 | // MicrocodeFmp driver private data\r | |
19 | //\r | |
20 | MICROCODE_FMP_PRIVATE_DATA *mMicrocodeFmpPrivate = NULL;\r | |
21 | \r | |
22 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r | |
23 | FmpGetImageInfo,\r | |
24 | FmpGetImage,\r | |
25 | FmpSetImage,\r | |
26 | FmpCheckImage,\r | |
27 | FmpGetPackageInfo,\r | |
28 | FmpSetPackageInfo\r | |
29 | };\r | |
30 | \r | |
31 | /**\r | |
32 | Initialize Microcode Descriptor.\r | |
33 | \r | |
34 | @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r | |
35 | \r | |
36 | @return EFI_SUCCESS Microcode Descriptor is initialized.\r | |
37 | **/\r | |
38 | EFI_STATUS\r | |
39 | InitializeMicrocodeDescriptor (\r | |
40 | IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r | |
41 | );\r | |
42 | \r | |
43 | /**\r | |
44 | Returns information about the current firmware image(s) of the device.\r | |
45 | \r | |
46 | This function allows a copy of the current firmware image to be created and saved.\r | |
47 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
48 | \r | |
49 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
50 | @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r | |
51 | On input, this is the size of the buffer allocated by the caller.\r | |
52 | On output, it is the size of the buffer returned by the firmware\r | |
53 | if the buffer was large enough, or the size of the buffer needed\r | |
54 | to contain the image(s) information if the buffer was too small.\r | |
55 | @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r | |
56 | information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r | |
57 | @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r | |
58 | associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
59 | @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r | |
60 | descriptors or firmware images within this device.\r | |
61 | @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r | |
62 | of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r | |
63 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
64 | The format is vendor specific and new version must have a greater value\r | |
65 | than the old version. If PackageVersion is not supported, the value is\r | |
66 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r | |
67 | is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r | |
68 | that package version update is in progress.\r | |
69 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r | |
70 | package version name. The buffer is allocated by this function with\r | |
71 | AllocatePool(), and it is the caller's responsibility to free it with a call\r | |
72 | to FreePool().\r | |
73 | \r | |
74 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
75 | @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r | |
76 | needed to hold the image(s) information is returned in ImageInfoSize.\r | |
77 | @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r | |
78 | @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r | |
79 | \r | |
80 | **/\r | |
81 | EFI_STATUS\r | |
82 | EFIAPI\r | |
83 | FmpGetImageInfo (\r | |
84 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
85 | IN OUT UINTN *ImageInfoSize,\r | |
86 | IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r | |
87 | OUT UINT32 *DescriptorVersion,\r | |
88 | OUT UINT8 *DescriptorCount,\r | |
89 | OUT UINTN *DescriptorSize,\r | |
90 | OUT UINT32 *PackageVersion,\r | |
91 | OUT CHAR16 **PackageVersionName\r | |
92 | )\r | |
93 | {\r | |
94 | MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r | |
95 | UINTN Index;\r | |
96 | \r | |
97 | MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r | |
98 | \r | |
99 | if(ImageInfoSize == NULL) {\r | |
100 | return EFI_INVALID_PARAMETER;\r | |
101 | }\r | |
102 | \r | |
103 | if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount) {\r | |
104 | *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r | |
105 | return EFI_BUFFER_TOO_SMALL;\r | |
106 | }\r | |
107 | \r | |
108 | if (ImageInfo == NULL ||\r | |
109 | DescriptorVersion == NULL ||\r | |
110 | DescriptorCount == NULL ||\r | |
111 | DescriptorSize == NULL ||\r | |
112 | PackageVersion == NULL ||\r | |
113 | PackageVersionName == NULL) {\r | |
114 | return EFI_INVALID_PARAMETER;\r | |
115 | }\r | |
116 | \r | |
117 | *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount;\r | |
118 | *DescriptorSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r | |
119 | *DescriptorCount = MicrocodeFmpPrivate->DescriptorCount;\r | |
120 | *DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r | |
121 | \r | |
122 | //\r | |
123 | // supports 1 ImageInfo descriptor\r | |
124 | //\r | |
125 | CopyMem(&ImageInfo[0], MicrocodeFmpPrivate->ImageDescriptor, sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * MicrocodeFmpPrivate->DescriptorCount);\r | |
126 | for (Index = 0; Index < MicrocodeFmpPrivate->DescriptorCount; Index++) {\r | |
127 | if ((ImageInfo[Index].AttributesSetting & IMAGE_ATTRIBUTE_IN_USE) != 0) {\r | |
128 | ImageInfo[Index].LastAttemptVersion = MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion;\r | |
129 | ImageInfo[Index].LastAttemptStatus = MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus;\r | |
130 | }\r | |
131 | }\r | |
132 | \r | |
133 | //\r | |
134 | // package version\r | |
135 | //\r | |
136 | *PackageVersion = MicrocodeFmpPrivate->PackageVersion;\r | |
137 | if (MicrocodeFmpPrivate->PackageVersionName != NULL) {\r | |
138 | *PackageVersionName = AllocateCopyPool(StrSize(MicrocodeFmpPrivate->PackageVersionName), MicrocodeFmpPrivate->PackageVersionName);\r | |
139 | }\r | |
140 | \r | |
141 | return EFI_SUCCESS;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Retrieves a copy of the current firmware image of the device.\r | |
146 | \r | |
147 | This function allows a copy of the current firmware image to be created and saved.\r | |
148 | The saved copy could later been used, for example, in firmware image recovery or rollback.\r | |
149 | \r | |
150 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
151 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
152 | The number is between 1 and DescriptorCount.\r | |
153 | @param[in,out] Image Points to the buffer where the current image is copied to.\r | |
154 | @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r | |
155 | On return, points to the length of the image, in bytes.\r | |
156 | \r | |
157 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
158 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r | |
159 | image. The current buffer size needed to hold the image is returned\r | |
160 | in ImageSize.\r | |
161 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
162 | @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r | |
163 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
164 | @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r | |
165 | \r | |
166 | **/\r | |
167 | EFI_STATUS\r | |
168 | EFIAPI\r | |
169 | FmpGetImage (\r | |
170 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
171 | IN UINT8 ImageIndex,\r | |
172 | IN OUT VOID *Image,\r | |
173 | IN OUT UINTN *ImageSize\r | |
174 | )\r | |
175 | {\r | |
176 | MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r | |
2ed65824 | 177 | MICROCODE_INFO *MicrocodeInfo;\r |
88266859 JY |
178 | \r |
179 | if (Image == NULL || ImageSize == NULL) {\r | |
180 | return EFI_INVALID_PARAMETER;\r | |
181 | }\r | |
182 | \r | |
183 | MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r | |
184 | \r | |
185 | if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || ImageSize == NULL || Image == NULL) {\r | |
186 | return EFI_INVALID_PARAMETER;\r | |
187 | }\r | |
188 | \r | |
2ed65824 JY |
189 | MicrocodeInfo = &MicrocodeFmpPrivate->MicrocodeInfo[ImageIndex - 1];\r |
190 | \r | |
191 | if (*ImageSize < MicrocodeInfo->TotalSize) {\r | |
192 | *ImageSize = MicrocodeInfo->TotalSize;\r | |
193 | return EFI_BUFFER_TOO_SMALL;\r | |
194 | }\r | |
195 | \r | |
196 | *ImageSize = MicrocodeInfo->TotalSize;\r | |
197 | CopyMem (Image, MicrocodeInfo->MicrocodeEntryPoint, MicrocodeInfo->TotalSize);\r | |
198 | return EFI_SUCCESS;\r | |
88266859 JY |
199 | }\r |
200 | \r | |
201 | /**\r | |
202 | Updates the firmware image of the device.\r | |
203 | \r | |
204 | This function updates the hardware with the new firmware image.\r | |
205 | This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r | |
206 | If the firmware image is updatable, the function should perform the following minimal validations\r | |
207 | before proceeding to do the firmware image update.\r | |
208 | - Validate the image authentication if image has attribute\r | |
209 | IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r | |
210 | EFI_SECURITY_VIOLATION if the validation fails.\r | |
211 | - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r | |
212 | the image is unsupported. The function can optionally provide more detailed information on\r | |
213 | why the image is not a supported image.\r | |
214 | - Validate the data from VendorCode if not null. Image validation must be performed before\r | |
215 | VendorCode data validation. VendorCode data is ignored or considered invalid if image\r | |
216 | validation failed. The function returns EFI_ABORTED if the data is invalid.\r | |
217 | \r | |
218 | VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r | |
219 | the caller did not specify the policy or use the default policy. As an example, vendor can implement\r | |
220 | a policy to allow an option to force a firmware image update when the abort reason is due to the new\r | |
221 | firmware image version is older than the current firmware image version or bad image checksum.\r | |
222 | Sensitive operations such as those wiping the entire firmware image and render the device to be\r | |
223 | non-functional should be encoded in the image itself rather than passed with the VendorCode.\r | |
224 | AbortReason enables vendor to have the option to provide a more detailed description of the abort\r | |
225 | reason to the caller.\r | |
226 | \r | |
227 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
228 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
229 | The number is between 1 and DescriptorCount.\r | |
230 | @param[in] Image Points to the new image.\r | |
231 | @param[in] ImageSize Size of the new image in bytes.\r | |
232 | @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r | |
233 | Null indicates the caller did not specify the policy or use the default policy.\r | |
234 | @param[in] Progress A function used by the driver to report the progress of the firmware update.\r | |
235 | @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r | |
236 | details for the aborted operation. The buffer is allocated by this function\r | |
237 | with AllocatePool(), and it is the caller's responsibility to free it with a\r | |
238 | call to FreePool().\r | |
239 | \r | |
240 | @retval EFI_SUCCESS The device was successfully updated with the new image.\r | |
241 | @retval EFI_ABORTED The operation is aborted.\r | |
242 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
243 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
244 | @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r | |
245 | \r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | FmpSetImage (\r | |
250 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
251 | IN UINT8 ImageIndex,\r | |
252 | IN CONST VOID *Image,\r | |
253 | IN UINTN ImageSize,\r | |
254 | IN CONST VOID *VendorCode,\r | |
255 | IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r | |
256 | OUT CHAR16 **AbortReason\r | |
257 | )\r | |
258 | {\r | |
259 | EFI_STATUS Status;\r | |
260 | EFI_STATUS VarStatus;\r | |
261 | MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate;\r | |
262 | \r | |
263 | if (Image == NULL || AbortReason == NULL) {\r | |
264 | return EFI_INVALID_PARAMETER;\r | |
265 | }\r | |
266 | \r | |
267 | MicrocodeFmpPrivate = MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(This);\r | |
268 | *AbortReason = NULL;\r | |
269 | \r | |
270 | if (ImageIndex == 0 || ImageIndex > MicrocodeFmpPrivate->DescriptorCount || Image == NULL) {\r | |
271 | return EFI_INVALID_PARAMETER;\r | |
272 | }\r | |
273 | \r | |
2ed65824 | 274 | Status = MicrocodeWrite(MicrocodeFmpPrivate, (VOID *)Image, ImageSize, &MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, &MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus, AbortReason);\r |
88266859 JY |
275 | DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r |
276 | VarStatus = gRT->SetVariable(\r | |
277 | MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r | |
278 | &gEfiCallerIdGuid,\r | |
279 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
280 | sizeof(MicrocodeFmpPrivate->LastAttempt),\r | |
281 | &MicrocodeFmpPrivate->LastAttempt\r | |
282 | );\r | |
283 | DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r | |
284 | \r | |
285 | if (!EFI_ERROR(Status)) {\r | |
286 | InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r | |
287 | }\r | |
288 | \r | |
289 | return Status;\r | |
290 | }\r | |
291 | \r | |
292 | /**\r | |
293 | Checks if the firmware image is valid for the device.\r | |
294 | \r | |
295 | This function allows firmware update application to validate the firmware image without\r | |
296 | invoking the SetImage() first.\r | |
297 | \r | |
298 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
299 | @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r | |
300 | The number is between 1 and DescriptorCount.\r | |
301 | @param[in] Image Points to the new image.\r | |
302 | @param[in] ImageSize Size of the new image in bytes.\r | |
303 | @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r | |
304 | if available, additional information if the image is invalid.\r | |
305 | \r | |
306 | @retval EFI_SUCCESS The image was successfully checked.\r | |
307 | @retval EFI_INVALID_PARAMETER The Image was NULL.\r | |
308 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
309 | @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r | |
310 | \r | |
311 | **/\r | |
312 | EFI_STATUS\r | |
313 | EFIAPI\r | |
314 | FmpCheckImage (\r | |
315 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
316 | IN UINT8 ImageIndex,\r | |
317 | IN CONST VOID *Image,\r | |
318 | IN UINTN ImageSize,\r | |
319 | OUT UINT32 *ImageUpdatable\r | |
320 | )\r | |
321 | {\r | |
322 | return EFI_UNSUPPORTED;\r | |
323 | }\r | |
324 | \r | |
325 | /**\r | |
326 | Returns information about the firmware package.\r | |
327 | \r | |
328 | This function returns package information.\r | |
329 | \r | |
330 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
331 | @param[out] PackageVersion A version number that represents all the firmware images in the device.\r | |
332 | The format is vendor specific and new version must have a greater value\r | |
333 | than the old version. If PackageVersion is not supported, the value is\r | |
334 | 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r | |
335 | comparison is to be performed using PackageVersionName. A value of\r | |
336 | 0xFFFFFFFD indicates that package version update is in progress.\r | |
337 | @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r | |
338 | the package version name. The buffer is allocated by this function with\r | |
339 | AllocatePool(), and it is the caller's responsibility to free it with a\r | |
340 | call to FreePool().\r | |
341 | @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r | |
342 | package version name. A value of 0 indicates the device does not support\r | |
343 | update of package version name. Length is the number of Unicode characters,\r | |
344 | including the terminating null character.\r | |
345 | @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r | |
346 | Definitions' for possible returned values of this parameter. A value of 1\r | |
347 | indicates the attribute is supported and the current setting value is\r | |
348 | indicated in AttributesSetting. A value of 0 indicates the attribute is not\r | |
349 | supported and the current setting value in AttributesSetting is meaningless.\r | |
350 | @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r | |
351 | values of this parameter\r | |
352 | \r | |
353 | @retval EFI_SUCCESS The package information was successfully returned.\r | |
354 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
355 | \r | |
356 | **/\r | |
357 | EFI_STATUS\r | |
358 | EFIAPI\r | |
359 | FmpGetPackageInfo (\r | |
360 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
361 | OUT UINT32 *PackageVersion,\r | |
362 | OUT CHAR16 **PackageVersionName,\r | |
363 | OUT UINT32 *PackageVersionNameMaxLen,\r | |
364 | OUT UINT64 *AttributesSupported,\r | |
365 | OUT UINT64 *AttributesSetting\r | |
366 | )\r | |
367 | {\r | |
368 | return EFI_UNSUPPORTED;\r | |
369 | }\r | |
370 | \r | |
371 | /**\r | |
372 | Updates information about the firmware package.\r | |
373 | \r | |
374 | This function updates package information.\r | |
375 | This function returns EFI_UNSUPPORTED if the package information is not updatable.\r | |
376 | VendorCode enables vendor to implement vendor-specific package information update policy.\r | |
377 | Null if the caller did not specify this policy or use the default policy.\r | |
378 | \r | |
379 | @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r | |
380 | @param[in] Image Points to the authentication image.\r | |
381 | Null if authentication is not required.\r | |
382 | @param[in] ImageSize Size of the authentication image in bytes.\r | |
383 | 0 if authentication is not required.\r | |
384 | @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r | |
385 | image update policy.\r | |
386 | Null indicates the caller did not specify this policy or use\r | |
387 | the default policy.\r | |
388 | @param[in] PackageVersion The new package version.\r | |
389 | @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r | |
390 | the package version name.\r | |
391 | The string length is equal to or less than the value returned in\r | |
392 | PackageVersionNameMaxLen.\r | |
393 | \r | |
394 | @retval EFI_SUCCESS The device was successfully updated with the new package\r | |
395 | information.\r | |
396 | @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r | |
397 | returned in PackageVersionNameMaxLen.\r | |
398 | @retval EFI_UNSUPPORTED The operation is not supported.\r | |
399 | @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r | |
400 | \r | |
401 | **/\r | |
402 | EFI_STATUS\r | |
403 | EFIAPI\r | |
404 | FmpSetPackageInfo (\r | |
405 | IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r | |
406 | IN CONST VOID *Image,\r | |
407 | IN UINTN ImageSize,\r | |
408 | IN CONST VOID *VendorCode,\r | |
409 | IN UINT32 PackageVersion,\r | |
410 | IN CONST CHAR16 *PackageVersionName\r | |
411 | )\r | |
412 | {\r | |
413 | return EFI_UNSUPPORTED;\r | |
414 | }\r | |
415 | \r | |
416 | /**\r | |
417 | Initialize Microcode Descriptor.\r | |
418 | \r | |
419 | @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r | |
420 | \r | |
421 | @return EFI_SUCCESS Microcode Descriptor is initialized.\r | |
422 | **/\r | |
423 | EFI_STATUS\r | |
424 | InitializeMicrocodeDescriptor (\r | |
425 | IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r | |
426 | )\r | |
427 | {\r | |
2ed65824 | 428 | UINT8 CurrentMicrocodeCount;\r |
88266859 | 429 | \r |
2ed65824 | 430 | CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, 0, NULL, NULL);\r |
88266859 JY |
431 | \r |
432 | if (CurrentMicrocodeCount > MicrocodeFmpPrivate->DescriptorCount) {\r | |
433 | if (MicrocodeFmpPrivate->ImageDescriptor != NULL) {\r | |
434 | FreePool(MicrocodeFmpPrivate->ImageDescriptor);\r | |
435 | MicrocodeFmpPrivate->ImageDescriptor = NULL;\r | |
436 | }\r | |
2ed65824 JY |
437 | if (MicrocodeFmpPrivate->MicrocodeInfo != NULL) {\r |
438 | FreePool(MicrocodeFmpPrivate->MicrocodeInfo);\r | |
439 | MicrocodeFmpPrivate->MicrocodeInfo = NULL;\r | |
440 | }\r | |
88266859 JY |
441 | } else {\r |
442 | ZeroMem(MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r | |
2ed65824 | 443 | ZeroMem(MicrocodeFmpPrivate->MicrocodeInfo, MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r |
88266859 JY |
444 | }\r |
445 | \r | |
446 | MicrocodeFmpPrivate->DescriptorCount = CurrentMicrocodeCount;\r | |
447 | \r | |
448 | if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r | |
449 | MicrocodeFmpPrivate->ImageDescriptor = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR));\r | |
450 | if (MicrocodeFmpPrivate->ImageDescriptor == NULL) {\r | |
451 | return EFI_OUT_OF_RESOURCES;\r | |
452 | }\r | |
453 | }\r | |
2ed65824 JY |
454 | if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r |
455 | MicrocodeFmpPrivate->MicrocodeInfo = AllocateZeroPool(MicrocodeFmpPrivate->DescriptorCount * sizeof(MICROCODE_INFO));\r | |
456 | if (MicrocodeFmpPrivate->MicrocodeInfo == NULL) {\r | |
457 | return EFI_OUT_OF_RESOURCES;\r | |
458 | }\r | |
459 | }\r | |
88266859 | 460 | \r |
2ed65824 | 461 | CurrentMicrocodeCount = (UINT8)GetMicrocodeInfo (MicrocodeFmpPrivate, MicrocodeFmpPrivate->DescriptorCount, MicrocodeFmpPrivate->ImageDescriptor, MicrocodeFmpPrivate->MicrocodeInfo);\r |
88266859 JY |
462 | ASSERT(CurrentMicrocodeCount == MicrocodeFmpPrivate->DescriptorCount);\r |
463 | \r | |
464 | return EFI_SUCCESS;\r | |
465 | }\r | |
466 | \r | |
467 | /**\r | |
468 | Initialize MicrocodeFmpDriver private data structure.\r | |
469 | \r | |
470 | @param[in] MicrocodeFmpPrivate private data structure to be initialized.\r | |
471 | \r | |
472 | @return EFI_SUCCESS private data is initialized.\r | |
473 | **/\r | |
474 | EFI_STATUS\r | |
475 | InitializePrivateData (\r | |
476 | IN MICROCODE_FMP_PRIVATE_DATA *MicrocodeFmpPrivate\r | |
477 | )\r | |
478 | {\r | |
479 | EFI_STATUS Status;\r | |
480 | EFI_STATUS VarStatus;\r | |
481 | UINTN VarSize;\r | |
2ed65824 | 482 | BOOLEAN Result;\r |
88266859 JY |
483 | \r |
484 | MicrocodeFmpPrivate->Signature = MICROCODE_FMP_PRIVATE_DATA_SIGNATURE;\r | |
485 | MicrocodeFmpPrivate->Handle = NULL;\r | |
486 | CopyMem(&MicrocodeFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r | |
487 | \r | |
488 | MicrocodeFmpPrivate->PackageVersion = 0x1;\r | |
489 | MicrocodeFmpPrivate->PackageVersionName = L"Microcode";\r | |
490 | \r | |
491 | MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r | |
492 | MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r | |
493 | VarSize = sizeof(MicrocodeFmpPrivate->LastAttempt);\r | |
494 | VarStatus = gRT->GetVariable(\r | |
495 | MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r | |
496 | &gEfiCallerIdGuid,\r | |
497 | NULL,\r | |
498 | &VarSize,\r | |
499 | &MicrocodeFmpPrivate->LastAttempt\r | |
500 | );\r | |
501 | DEBUG((DEBUG_INFO, "GetLastAttemp - %r\n", VarStatus));\r | |
502 | DEBUG((DEBUG_INFO, "GetLastAttemp Version - 0x%x, State - 0x%x\n", MicrocodeFmpPrivate->LastAttempt.LastAttemptVersion, MicrocodeFmpPrivate->LastAttempt.LastAttemptStatus));\r | |
503 | \r | |
2ed65824 JY |
504 | Result = GetMicrocodeRegion(&MicrocodeFmpPrivate->MicrocodePatchAddress, &MicrocodeFmpPrivate->MicrocodePatchRegionSize);\r |
505 | if (!Result) {\r | |
506 | DEBUG((DEBUG_ERROR, "Fail to get Microcode Region\n"));\r | |
507 | return EFI_NOT_FOUND;\r | |
508 | }\r | |
509 | \r | |
88266859 JY |
510 | Status = InitializeMicrocodeDescriptor(MicrocodeFmpPrivate);\r |
511 | \r | |
512 | return Status;\r | |
513 | }\r | |
514 | \r | |
515 | /**\r | |
516 | Microcode FMP module entrypoint\r | |
517 | \r | |
518 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
519 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
520 | \r | |
521 | @return EFI_SUCCESS Microcode FMP module is initialized.\r | |
522 | **/\r | |
523 | EFI_STATUS\r | |
524 | EFIAPI\r | |
525 | MicrocodeFmpMain (\r | |
526 | IN EFI_HANDLE ImageHandle,\r | |
527 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
528 | )\r | |
529 | {\r | |
530 | EFI_STATUS Status;\r | |
531 | \r | |
532 | //\r | |
533 | // Initialize MicrocodeFmpPrivateData\r | |
534 | //\r | |
535 | mMicrocodeFmpPrivate = AllocateZeroPool (sizeof(MICROCODE_FMP_PRIVATE_DATA));\r | |
536 | if (mMicrocodeFmpPrivate == NULL) {\r | |
537 | return EFI_OUT_OF_RESOURCES;\r | |
538 | }\r | |
539 | \r | |
540 | Status = InitializePrivateData(mMicrocodeFmpPrivate);\r | |
541 | if (EFI_ERROR(Status)) {\r | |
542 | FreePool(mMicrocodeFmpPrivate);\r | |
543 | mMicrocodeFmpPrivate = NULL;\r | |
544 | return Status;\r | |
545 | }\r | |
546 | \r | |
547 | //\r | |
548 | // Install FMP protocol.\r | |
549 | //\r | |
550 | Status = gBS->InstallProtocolInterface (\r | |
551 | &mMicrocodeFmpPrivate->Handle,\r | |
552 | &gEfiFirmwareManagementProtocolGuid,\r | |
553 | EFI_NATIVE_INTERFACE,\r | |
554 | &mMicrocodeFmpPrivate->Fmp\r | |
555 | );\r | |
556 | if (EFI_ERROR (Status)) {\r | |
557 | FreePool(mMicrocodeFmpPrivate);\r | |
558 | mMicrocodeFmpPrivate = NULL;\r | |
559 | return Status;\r | |
560 | }\r | |
561 | \r | |
562 | return Status;\r | |
563 | }\r |