]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe/MicrocodeUpdate.h
UefiCpuPkg/MicrocodeUpdate: Add MicrocodeUpdate component.
[mirror_edk2.git] / UefiCpuPkg / Feature / Capsule / MicrocodeUpdateDxe / MicrocodeUpdate.h
CommitLineData
88266859
JY
1/** @file\r
2 Microcode update header file.\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#ifndef _MICROCODE_FMP_H_\r
16#define _MICROCODE_FMP_H_\r
17\r
18#include <PiDxe.h>\r
19\r
20#include <Guid/SystemResourceTable.h>\r
21#include <Guid/MicrocodeFmp.h>\r
22\r
23#include <Protocol/FirmwareManagement.h>\r
24\r
25#include <Library/BaseLib.h>\r
26#include <Library/BaseMemoryLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/MemoryAllocationLib.h>\r
29#include <Library/PcdLib.h>\r
30#include <Library/UefiBootServicesTableLib.h>\r
31#include <Library/UefiLib.h>\r
32#include <Library/UefiRuntimeServicesTableLib.h>\r
33#include <Library/UefiDriverEntryPoint.h>\r
34#include <Library/DevicePathLib.h>\r
35#include <Library/HobLib.h>\r
36#include <Library/MicrocodeFlashAccessLib.h>\r
37\r
38#include <Register/Cpuid.h>\r
39#include <Register/Msr.h>\r
40#include <Register/Microcode.h>\r
41\r
42#define MICROCODE_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('M', 'C', 'U', 'F')\r
43\r
44//\r
45// Microcode FMP private data structure.\r
46//\r
47\r
48typedef struct {\r
49 UINT32 LastAttemptVersion;\r
50 UINT32 LastAttemptStatus;\r
51} MICROCODE_FMP_LAST_ATTEMPT_VARIABLE;\r
52\r
53struct _MICROCODE_FMP_PRIVATE_DATA {\r
54 UINT32 Signature;\r
55 EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp;\r
56 EFI_HANDLE Handle;\r
57 UINT8 DescriptorCount;\r
58 EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;\r
59 UINT32 PackageVersion;\r
60 CHAR16 *PackageVersionName;\r
61 MICROCODE_FMP_LAST_ATTEMPT_VARIABLE LastAttempt;\r
62};\r
63\r
64typedef struct _MICROCODE_FMP_PRIVATE_DATA MICROCODE_FMP_PRIVATE_DATA;\r
65\r
66#define MICROCODE_FMP_LAST_ATTEMPT_VARIABLE_NAME L"MicrocodeLastAttempVar"\r
67\r
68/**\r
69 Returns a pointer to the MICROCODE_FMP_PRIVATE_DATA structure from the input a as Fmp.\r
70\r
71 If the signatures matches, then a pointer to the data structure that contains\r
72 a specified field of that data structure is returned.\r
73\r
74 @param a Pointer to the field specified by ServiceBinding within\r
75 a data structure of type MICROCODE_FMP_PRIVATE_DATA.\r
76\r
77**/\r
78#define MICROCODE_FMP_PRIVATE_DATA_FROM_FMP(a) \\r
79 CR ( \\r
80 (a), \\r
81 MICROCODE_FMP_PRIVATE_DATA, \\r
82 Fmp, \\r
83 MICROCODE_FMP_PRIVATE_DATA_SIGNATURE \\r
84 )\r
85\r
86/**\r
87 Get current Microcode information.\r
88\r
89 @param[out] ImageDescriptor Microcode ImageDescriptor\r
90 @param[in] DescriptorCount The count of Microcode ImageDescriptor allocated.\r
91\r
92 @return Microcode count\r
93**/\r
94UINTN\r
95GetMicrocodeInfo (\r
96 OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor, OPTIONAL\r
97 IN UINTN DescriptorCount OPTIONAL\r
98 );\r
99\r
100/**\r
101 Read Microcode.\r
102\r
103 @param[in] ImageIndex The index of Microcode image.\r
104 @param[in, out] Image The Microcode image buffer.\r
105 @param[in, out] ImageSize The size of Microcode image buffer in bytes.\r
106\r
107 @retval EFI_SUCCESS The Microcode image is read.\r
108 @retval EFI_NOT_FOUND The Microcode image is not found.\r
109**/\r
110EFI_STATUS\r
111MicrocodeRead (\r
112 IN UINTN ImageIndex,\r
113 IN OUT VOID *Image,\r
114 IN OUT UINTN *ImageSize\r
115 );\r
116\r
117/**\r
118 Write Microcode.\r
119\r
120 @param[in] ImageIndex The index of Microcode image.\r
121 @param[in] Image The Microcode image buffer.\r
122 @param[in] ImageSize The size of Microcode image buffer in bytes.\r
123 @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
124 @param[out] LastAttemptStatus The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
125 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
126 details for the aborted operation. The buffer is allocated by this function\r
127 with AllocatePool(), and it is the caller's responsibility to free it with a\r
128 call to FreePool().\r
129\r
130 @retval EFI_SUCCESS The Microcode image is written.\r
131 @retval EFI_VOLUME_CORRUPTED The Microcode image is corrupt.\r
132 @retval EFI_INCOMPATIBLE_VERSION The Microcode image version is incorrect.\r
133 @retval EFI_SECURITY_VIOLATION The Microcode image fails to load.\r
134 @retval EFI_WRITE_PROTECTED The flash device is read only.\r
135**/\r
136EFI_STATUS\r
137MicrocodeWrite (\r
138 IN UINTN ImageIndex,\r
139 IN VOID *Image,\r
140 IN UINTN ImageSize,\r
141 OUT UINT32 *LastAttemptVersion,\r
142 OUT UINT32 *LastAttemptStatus,\r
143 OUT CHAR16 **AbortReason\r
144 );\r
145\r
146/**\r
147 Returns information about the current firmware image(s) of the device.\r
148\r
149 This function allows a copy of the current firmware image to be created and saved.\r
150 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
151\r
152 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
153 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r
154 On input, this is the size of the buffer allocated by the caller.\r
155 On output, it is the size of the buffer returned by the firmware\r
156 if the buffer was large enough, or the size of the buffer needed\r
157 to contain the image(s) information if the buffer was too small.\r
158 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r
159 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
160 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r
161 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
162 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r
163 descriptors or firmware images within this device.\r
164 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r
165 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
166 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
167 The format is vendor specific and new version must have a greater value\r
168 than the old version. If PackageVersion is not supported, the value is\r
169 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
170 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
171 that package version update is in progress.\r
172 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
173 package version name. The buffer is allocated by this function with\r
174 AllocatePool(), and it is the caller's responsibility to free it with a call\r
175 to FreePool().\r
176\r
177 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
178 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r
179 needed to hold the image(s) information is returned in ImageInfoSize.\r
180 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r
181 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r
182\r
183**/\r
184EFI_STATUS\r
185EFIAPI\r
186FmpGetImageInfo (\r
187 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
188 IN OUT UINTN *ImageInfoSize,\r
189 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r
190 OUT UINT32 *DescriptorVersion,\r
191 OUT UINT8 *DescriptorCount,\r
192 OUT UINTN *DescriptorSize,\r
193 OUT UINT32 *PackageVersion,\r
194 OUT CHAR16 **PackageVersionName\r
195 );\r
196\r
197/**\r
198 Retrieves a copy of the current firmware image of the device.\r
199\r
200 This function allows a copy of the current firmware image to be created and saved.\r
201 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
202\r
203 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
204 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
205 The number is between 1 and DescriptorCount.\r
206 @param[in,out] Image Points to the buffer where the current image is copied to.\r
207 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r
208 On return, points to the length of the image, in bytes.\r
209\r
210 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
211 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r
212 image. The current buffer size needed to hold the image is returned\r
213 in ImageSize.\r
214 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
215 @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r
216 @retval EFI_UNSUPPORTED The operation is not supported.\r
217 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
218\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222FmpGetImage (\r
223 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
224 IN UINT8 ImageIndex,\r
225 IN OUT VOID *Image,\r
226 IN OUT UINTN *ImageSize\r
227 );\r
228\r
229/**\r
230 Updates the firmware image of the device.\r
231\r
232 This function updates the hardware with the new firmware image.\r
233 This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
234 If the firmware image is updatable, the function should perform the following minimal validations\r
235 before proceeding to do the firmware image update.\r
236 - Validate the image authentication if image has attribute\r
237 IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
238 EFI_SECURITY_VIOLATION if the validation fails.\r
239 - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
240 the image is unsupported. The function can optionally provide more detailed information on\r
241 why the image is not a supported image.\r
242 - Validate the data from VendorCode if not null. Image validation must be performed before\r
243 VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
244 validation failed. The function returns EFI_ABORTED if the data is invalid.\r
245\r
246 VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
247 the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
248 a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
249 firmware image version is older than the current firmware image version or bad image checksum.\r
250 Sensitive operations such as those wiping the entire firmware image and render the device to be\r
251 non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
252 AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
253 reason to the caller.\r
254\r
255 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
256 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
257 The number is between 1 and DescriptorCount.\r
258 @param[in] Image Points to the new image.\r
259 @param[in] ImageSize Size of the new image in bytes.\r
260 @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.\r
261 Null indicates the caller did not specify the policy or use the default policy.\r
262 @param[in] Progress A function used by the driver to report the progress of the firmware update.\r
263 @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more\r
264 details for the aborted operation. The buffer is allocated by this function\r
265 with AllocatePool(), and it is the caller's responsibility to free it with a\r
266 call to FreePool().\r
267\r
268 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
269 @retval EFI_ABORTED The operation is aborted.\r
270 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
271 @retval EFI_UNSUPPORTED The operation is not supported.\r
272 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
273\r
274**/\r
275EFI_STATUS\r
276EFIAPI\r
277FmpSetImage (\r
278 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
279 IN UINT8 ImageIndex,\r
280 IN CONST VOID *Image,\r
281 IN UINTN ImageSize,\r
282 IN CONST VOID *VendorCode,\r
283 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,\r
284 OUT CHAR16 **AbortReason\r
285 );\r
286\r
287/**\r
288 Checks if the firmware image is valid for the device.\r
289\r
290 This function allows firmware update application to validate the firmware image without\r
291 invoking the SetImage() first.\r
292\r
293 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
294 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
295 The number is between 1 and DescriptorCount.\r
296 @param[in] Image Points to the new image.\r
297 @param[in] ImageSize Size of the new image in bytes.\r
298 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
299 if available, additional information if the image is invalid.\r
300\r
301 @retval EFI_SUCCESS The image was successfully checked.\r
302 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
303 @retval EFI_UNSUPPORTED The operation is not supported.\r
304 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
305\r
306**/\r
307EFI_STATUS\r
308EFIAPI\r
309FmpCheckImage (\r
310 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
311 IN UINT8 ImageIndex,\r
312 IN CONST VOID *Image,\r
313 IN UINTN ImageSize,\r
314 OUT UINT32 *ImageUpdatable\r
315 );\r
316\r
317/**\r
318 Returns information about the firmware package.\r
319\r
320 This function returns package information.\r
321\r
322 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
323 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
324 The format is vendor specific and new version must have a greater value\r
325 than the old version. If PackageVersion is not supported, the value is\r
326 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
327 comparison is to be performed using PackageVersionName. A value of\r
328 0xFFFFFFFD indicates that package version update is in progress.\r
329 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
330 the package version name. The buffer is allocated by this function with\r
331 AllocatePool(), and it is the caller's responsibility to free it with a\r
332 call to FreePool().\r
333 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
334 package version name. A value of 0 indicates the device does not support\r
335 update of package version name. Length is the number of Unicode characters,\r
336 including the terminating null character.\r
337 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
338 Definitions' for possible returned values of this parameter. A value of 1\r
339 indicates the attribute is supported and the current setting value is\r
340 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
341 supported and the current setting value in AttributesSetting is meaningless.\r
342 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
343 values of this parameter\r
344\r
345 @retval EFI_SUCCESS The package information was successfully returned.\r
346 @retval EFI_UNSUPPORTED The operation is not supported.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351FmpGetPackageInfo (\r
352 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
353 OUT UINT32 *PackageVersion,\r
354 OUT CHAR16 **PackageVersionName,\r
355 OUT UINT32 *PackageVersionNameMaxLen,\r
356 OUT UINT64 *AttributesSupported,\r
357 OUT UINT64 *AttributesSetting\r
358 );\r
359\r
360/**\r
361 Updates information about the firmware package.\r
362\r
363 This function updates package information.\r
364 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
365 VendorCode enables vendor to implement vendor-specific package information update policy.\r
366 Null if the caller did not specify this policy or use the default policy.\r
367\r
368 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
369 @param[in] Image Points to the authentication image.\r
370 Null if authentication is not required.\r
371 @param[in] ImageSize Size of the authentication image in bytes.\r
372 0 if authentication is not required.\r
373 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
374 image update policy.\r
375 Null indicates the caller did not specify this policy or use\r
376 the default policy.\r
377 @param[in] PackageVersion The new package version.\r
378 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
379 the package version name.\r
380 The string length is equal to or less than the value returned in\r
381 PackageVersionNameMaxLen.\r
382\r
383 @retval EFI_SUCCESS The device was successfully updated with the new package\r
384 information.\r
385 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
386 returned in PackageVersionNameMaxLen.\r
387 @retval EFI_UNSUPPORTED The operation is not supported.\r
388 @retval EFI_SECURITY_VIOLATIO The operation could not be performed due to an authentication failure.\r
389\r
390**/\r
391EFI_STATUS\r
392EFIAPI\r
393FmpSetPackageInfo (\r
394 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
395 IN CONST VOID *Image,\r
396 IN UINTN ImageSize,\r
397 IN CONST VOID *VendorCode,\r
398 IN UINT32 PackageVersion,\r
399 IN CONST CHAR16 *PackageVersionName\r
400 );\r
401\r
402#endif\r
403\r