]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeHstiLib/HstiDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / DxeHstiLib / HstiDxe.c
CommitLineData
aaedfe3c
JY
1/** @file\r
2\r
ebe8ef86 3 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 4 SPDX-License-Identifier: BSD-2-Clause-Patent\r
aaedfe3c
JY
5\r
6**/\r
7\r
8#include "HstiDxe.h"\r
9\r
10/**\r
11 Find HSTI table in AIP protocol, and return the data.\r
12 This API will return the HSTI table with indicated Role and ImplementationID,\r
13 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
14\r
15 @param Role Role of HSTI data.\r
16 @param ImplementationID ImplementationID of HSTI data.\r
17 NULL means find the first one match Role.\r
18 @param HstiData HSTI data. This buffer is allocated by callee, and it\r
19 is the responsibility of the caller to free it after\r
20 using it.\r
21 @param HstiSize HSTI size\r
22\r
23 @return Aip The AIP protocol having this HSTI.\r
24 @return NULL There is not HSTI table with the Role and ImplementationID published in system.\r
25**/\r
26VOID *\r
27InternalHstiFindAip (\r
2f88bd3a
MK
28 IN UINT32 Role,\r
29 IN CHAR16 *ImplementationID OPTIONAL,\r
30 OUT VOID **HstiData OPTIONAL,\r
31 OUT UINTN *HstiSize OPTIONAL\r
aaedfe3c
JY
32 )\r
33{\r
34 EFI_STATUS Status;\r
35 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
36 UINTN NoHandles;\r
37 EFI_HANDLE *Handles;\r
38 UINTN Index;\r
39 EFI_GUID *InfoTypesBuffer;\r
40 UINTN InfoTypesBufferCount;\r
41 UINTN InfoTypesIndex;\r
42 EFI_ADAPTER_INFORMATION_PROTOCOL *AipCandidate;\r
43 VOID *InformationBlock;\r
44 UINTN InformationBlockSize;\r
45 ADAPTER_INFO_PLATFORM_SECURITY *Hsti;\r
46\r
47 Status = gBS->LocateHandleBuffer (\r
48 ByProtocol,\r
49 &gEfiAdapterInformationProtocolGuid,\r
50 NULL,\r
51 &NoHandles,\r
52 &Handles\r
53 );\r
54 if (EFI_ERROR (Status)) {\r
55 return NULL;\r
56 }\r
57\r
2f88bd3a
MK
58 Hsti = NULL;\r
59 Aip = NULL;\r
60 InformationBlock = NULL;\r
aaedfe3c
JY
61 InformationBlockSize = 0;\r
62 for (Index = 0; Index < NoHandles; Index++) {\r
63 Status = gBS->HandleProtocol (\r
64 Handles[Index],\r
65 &gEfiAdapterInformationProtocolGuid,\r
66 (VOID **)&Aip\r
67 );\r
68 if (EFI_ERROR (Status)) {\r
69 continue;\r
70 }\r
71\r
72 //\r
73 // Check AIP\r
74 //\r
75 Status = Aip->GetSupportedTypes (\r
76 Aip,\r
77 &InfoTypesBuffer,\r
78 &InfoTypesBufferCount\r
79 );\r
17f8c9e9 80 if (EFI_ERROR (Status) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == 0)) {\r
aaedfe3c
JY
81 continue;\r
82 }\r
83\r
84 AipCandidate = NULL;\r
85 for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) {\r
86 if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformSecurityGuid)) {\r
87 AipCandidate = Aip;\r
88 break;\r
89 }\r
90 }\r
2f88bd3a 91\r
aaedfe3c
JY
92 FreePool (InfoTypesBuffer);\r
93\r
94 if (AipCandidate == NULL) {\r
95 continue;\r
96 }\r
97\r
98 //\r
99 // Check HSTI Role\r
100 //\r
2f88bd3a 101 Aip = AipCandidate;\r
aaedfe3c
JY
102 Status = Aip->GetInformation (\r
103 Aip,\r
104 &gAdapterInfoPlatformSecurityGuid,\r
105 &InformationBlock,\r
106 &InformationBlockSize\r
107 );\r
108 if (EFI_ERROR (Status)) {\r
109 continue;\r
110 }\r
111\r
112 Hsti = InformationBlock;\r
9095d37b 113 if ((Hsti->Role == Role) &&\r
2f88bd3a
MK
114 ((ImplementationID == NULL) || (StrCmp (ImplementationID, Hsti->ImplementationID) == 0)))\r
115 {\r
aaedfe3c
JY
116 break;\r
117 } else {\r
118 Hsti = NULL;\r
119 FreePool (InformationBlock);\r
120 continue;\r
121 }\r
122 }\r
2f88bd3a 123\r
aaedfe3c
JY
124 FreePool (Handles);\r
125\r
126 if (Hsti == NULL) {\r
127 return NULL;\r
128 }\r
129\r
130 if (HstiData != NULL) {\r
131 *HstiData = InformationBlock;\r
132 }\r
2f88bd3a 133\r
aaedfe3c
JY
134 if (HstiSize != NULL) {\r
135 *HstiSize = InformationBlockSize;\r
136 }\r
2f88bd3a 137\r
aaedfe3c
JY
138 return Aip;\r
139}\r
140\r
141/**\r
142 Return if input HSTI data follows HSTI specification.\r
143\r
144 @param HstiData HSTI data\r
145 @param HstiSize HSTI size\r
146\r
147 @retval TRUE HSTI data follows HSTI specification.\r
148 @retval FALSE HSTI data does not follow HSTI specification.\r
149**/\r
150BOOLEAN\r
151InternalHstiIsValidTable (\r
2f88bd3a
MK
152 IN VOID *HstiData,\r
153 IN UINTN HstiSize\r
aaedfe3c
JY
154 )\r
155{\r
156 ADAPTER_INFO_PLATFORM_SECURITY *Hsti;\r
157 UINTN Index;\r
158 CHAR16 *ErrorString;\r
159 CHAR16 ErrorChar;\r
160 UINTN ErrorStringSize;\r
161 UINTN ErrorStringLength;\r
162\r
163 Hsti = HstiData;\r
164\r
165 //\r
166 // basic check for header\r
167 //\r
168 if (HstiData == NULL) {\r
5f289f3a 169 DEBUG ((DEBUG_ERROR, "HstiData == NULL\n"));\r
aaedfe3c
JY
170 return FALSE;\r
171 }\r
2f88bd3a
MK
172\r
173 if (HstiSize < sizeof (ADAPTER_INFO_PLATFORM_SECURITY)) {\r
5f289f3a 174 DEBUG ((DEBUG_ERROR, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));\r
aaedfe3c
JY
175 return FALSE;\r
176 }\r
2f88bd3a
MK
177\r
178 if (((HstiSize - sizeof (ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < Hsti->SecurityFeaturesSize) {\r
5f289f3a 179 DEBUG ((DEBUG_ERROR, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));\r
aaedfe3c
JY
180 return FALSE;\r
181 }\r
182\r
183 //\r
184 // Check Version\r
185 //\r
186 if (Hsti->Version != PLATFORM_SECURITY_VERSION_VNEXTCS) {\r
5f289f3a 187 DEBUG ((DEBUG_ERROR, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));\r
aaedfe3c
JY
188 return FALSE;\r
189 }\r
190\r
191 //\r
192 // Check Role\r
193 //\r
194 if ((Hsti->Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) ||\r
2f88bd3a
MK
195 (Hsti->Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM))\r
196 {\r
5f289f3a
MK
197 DEBUG ((DEBUG_ERROR, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));\r
198 DEBUG ((DEBUG_ERROR, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));\r
aaedfe3c
JY
199 return FALSE;\r
200 }\r
201\r
202 //\r
203 // Check ImplementationID\r
204 //\r
2f88bd3a 205 for (Index = 0; Index < sizeof (Hsti->ImplementationID)/sizeof (Hsti->ImplementationID[0]); Index++) {\r
aaedfe3c
JY
206 if (Hsti->ImplementationID[Index] == 0) {\r
207 break;\r
208 }\r
209 }\r
2f88bd3a
MK
210\r
211 if (Index == sizeof (Hsti->ImplementationID)/sizeof (Hsti->ImplementationID[0])) {\r
5f289f3a 212 DEBUG ((DEBUG_ERROR, "ImplementationID has no NUL CHAR\n"));\r
aaedfe3c
JY
213 return FALSE;\r
214 }\r
215\r
2f88bd3a
MK
216 ErrorStringSize = HstiSize - sizeof (ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3;\r
217 ErrorString = (CHAR16 *)((UINTN)Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3);\r
aaedfe3c
JY
218\r
219 //\r
220 // basic check for ErrorString\r
221 //\r
222 if (ErrorStringSize == 0) {\r
5f289f3a 223 DEBUG ((DEBUG_ERROR, "ErrorStringSize == 0\n"));\r
aaedfe3c
JY
224 return FALSE;\r
225 }\r
2f88bd3a 226\r
aaedfe3c 227 if ((ErrorStringSize & BIT0) != 0) {\r
5f289f3a 228 DEBUG ((DEBUG_ERROR, "(ErrorStringSize & BIT0) != 0\n"));\r
aaedfe3c
JY
229 return FALSE;\r
230 }\r
231\r
232 //\r
233 // ErrorString might not be CHAR16 aligned.\r
234 //\r
2f88bd3a 235 CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar));\r
aaedfe3c
JY
236 for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) {\r
237 ErrorString++;\r
2f88bd3a 238 CopyMem (&ErrorChar, ErrorString, sizeof (ErrorChar));\r
aaedfe3c
JY
239 }\r
240\r
241 //\r
242 // check the length of ErrorString\r
243 //\r
244 if (ErrorChar != 0) {\r
5f289f3a 245 DEBUG ((DEBUG_ERROR, "ErrorString has no NUL CHAR\n"));\r
aaedfe3c
JY
246 return FALSE;\r
247 }\r
2f88bd3a 248\r
aaedfe3c 249 if (ErrorStringLength == (ErrorStringSize/2)) {\r
5f289f3a 250 DEBUG ((DEBUG_ERROR, "ErrorString Length incorrect\n"));\r
aaedfe3c
JY
251 return FALSE;\r
252 }\r
253\r
254 return TRUE;\r
255}\r
256\r
257/**\r
258 Publish HSTI table in AIP protocol.\r
259\r
260 One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.\r
261\r
262 If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,\r
263 SecurityFeaturesRequired field will be ignored.\r
264\r
265 @param Hsti HSTI data\r
266 @param HstiSize HSTI size\r
267\r
268 @retval EFI_SUCCESS The HSTI data is published in AIP protocol.\r
269 @retval EFI_ALREADY_STARTED There is already HSTI table with Role and ImplementationID published in system.\r
270 @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.\r
271 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.\r
272**/\r
273EFI_STATUS\r
274EFIAPI\r
275HstiLibSetTable (\r
2f88bd3a
MK
276 IN VOID *Hsti,\r
277 IN UINTN HstiSize\r
aaedfe3c
JY
278 )\r
279{\r
2f88bd3a
MK
280 EFI_STATUS Status;\r
281 EFI_HANDLE Handle;\r
282 HSTI_AIP_PRIVATE_DATA *HstiAip;\r
283 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
284 UINT32 Role;\r
285 CHAR16 *ImplementationID;\r
286 UINT32 SecurityFeaturesSize;\r
287 UINT8 *SecurityFeaturesRequired;\r
aaedfe3c
JY
288\r
289 if (!InternalHstiIsValidTable (Hsti, HstiSize)) {\r
290 return EFI_VOLUME_CORRUPTED;\r
291 }\r
292\r
2f88bd3a 293 Role = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->Role;\r
aaedfe3c 294 ImplementationID = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->ImplementationID;\r
2f88bd3a 295 Aip = InternalHstiFindAip (Role, ImplementationID, NULL, NULL);\r
aaedfe3c
JY
296 if (Aip != NULL) {\r
297 return EFI_ALREADY_STARTED;\r
298 }\r
299\r
2f88bd3a 300 HstiAip = AllocateZeroPool (sizeof (HSTI_AIP_PRIVATE_DATA));\r
aaedfe3c
JY
301 if (HstiAip == NULL) {\r
302 return EFI_OUT_OF_RESOURCES;\r
303 }\r
2f88bd3a 304\r
aaedfe3c 305 HstiAip->Hsti = AllocateCopyPool (HstiSize, Hsti);\r
d3858e10 306 if (HstiAip->Hsti == NULL) {\r
aaedfe3c
JY
307 FreePool (HstiAip);\r
308 return EFI_OUT_OF_RESOURCES;\r
309 }\r
2f88bd3a 310\r
aaedfe3c 311 if (Role != PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) {\r
2f88bd3a
MK
312 SecurityFeaturesRequired = (UINT8 *)HstiAip->Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY);\r
313 SecurityFeaturesSize = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->SecurityFeaturesSize;\r
aaedfe3c
JY
314 ZeroMem (SecurityFeaturesRequired, SecurityFeaturesSize);\r
315 }\r
316\r
317 HstiAip->Signature = HSTI_AIP_PRIVATE_SIGNATURE;\r
2f88bd3a
MK
318 CopyMem (&HstiAip->Aip, &mAdapterInformationProtocol, sizeof (EFI_ADAPTER_INFORMATION_PROTOCOL));\r
319 HstiAip->HstiSize = HstiSize;\r
aaedfe3c 320 HstiAip->HstiMaxSize = HstiSize;\r
9095d37b 321\r
aaedfe3c
JY
322 Handle = NULL;\r
323 Status = gBS->InstallMultipleProtocolInterfaces (\r
324 &Handle,\r
325 &gEfiAdapterInformationProtocolGuid,\r
326 &HstiAip->Aip,\r
327 NULL\r
328 );\r
329 if (EFI_ERROR (Status)) {\r
330 FreePool (HstiAip->Hsti);\r
331 FreePool (HstiAip);\r
332 }\r
333\r
334 return Status;\r
335}\r
336\r
337/**\r
338 Search HSTI table in AIP protocol, and return the data.\r
339 This API will return the HSTI table with indicated Role and ImplementationID,\r
340 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
341\r
342 @param Role Role of HSTI data.\r
343 @param ImplementationID ImplementationID of HSTI data.\r
344 NULL means find the first one match Role.\r
345 @param Hsti HSTI data. This buffer is allocated by callee, and it\r
346 is the responsibility of the caller to free it after\r
347 using it.\r
348 @param HstiSize HSTI size\r
349\r
350 @retval EFI_SUCCESS The HSTI data in AIP protocol is returned.\r
351 @retval EFI_NOT_FOUND There is not HSTI table with the Role and ImplementationID published in system.\r
352**/\r
353EFI_STATUS\r
354EFIAPI\r
355HstiLibGetTable (\r
2f88bd3a
MK
356 IN UINT32 Role,\r
357 IN CHAR16 *ImplementationID OPTIONAL,\r
358 OUT VOID **Hsti,\r
359 OUT UINTN *HstiSize\r
aaedfe3c
JY
360 )\r
361{\r
2f88bd3a 362 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
aaedfe3c
JY
363\r
364 Aip = InternalHstiFindAip (Role, ImplementationID, Hsti, HstiSize);\r
365 if (Aip == NULL) {\r
366 return EFI_NOT_FOUND;\r
367 }\r
2f88bd3a 368\r
aaedfe3c
JY
369 return EFI_SUCCESS;\r
370}\r
371\r
372/**\r
373 Record FeaturesVerified in published HSTI table.\r
374 This API will update the HSTI table with indicated Role and ImplementationID,\r
375 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
376\r
377 @param Role Role of HSTI data.\r
378 @param ImplementationID ImplementationID of HSTI data.\r
379 NULL means find the first one match Role.\r
380 @param ByteIndex Byte index of FeaturesVerified of HSTI data.\r
381 @param BitMask Bit mask of FeaturesVerified of HSTI data.\r
382 @param Set TRUE means to set the FeaturesVerified bit.\r
383 FALSE means to clear the FeaturesVerified bit.\r
384\r
385 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.\r
386 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
387 @retval EFI_UNSUPPORTED The ByteIndex is invalid.\r
388**/\r
389EFI_STATUS\r
390InternalHstiRecordFeaturesVerified (\r
2f88bd3a
MK
391 IN UINT32 Role,\r
392 IN CHAR16 *ImplementationID OPTIONAL,\r
393 IN UINT32 ByteIndex,\r
394 IN UINT8 Bit,\r
395 IN BOOLEAN Set\r
aaedfe3c
JY
396 )\r
397{\r
2f88bd3a
MK
398 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
399 ADAPTER_INFO_PLATFORM_SECURITY *Hsti;\r
400 UINTN HstiSize;\r
401 UINT8 *SecurityFeaturesVerified;\r
402 EFI_STATUS Status;\r
aaedfe3c 403\r
6a39a6a1 404 Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);\r
aaedfe3c
JY
405 if (Aip == NULL) {\r
406 return EFI_NOT_STARTED;\r
407 }\r
408\r
409 if (ByteIndex >= Hsti->SecurityFeaturesSize) {\r
410 return EFI_UNSUPPORTED;\r
411 }\r
412\r
2f88bd3a 413 SecurityFeaturesVerified = (UINT8 *)((UINTN)Hsti + sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 2);\r
aaedfe3c
JY
414\r
415 if (Set) {\r
416 SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] | (Bit));\r
417 } else {\r
418 SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] & (~Bit));\r
419 }\r
420\r
421 Status = Aip->SetInformation (\r
422 Aip,\r
423 &gAdapterInfoPlatformSecurityGuid,\r
424 Hsti,\r
425 HstiSize\r
426 );\r
357c4825 427 FreePool (Hsti);\r
aaedfe3c
JY
428 return Status;\r
429}\r
430\r
431/**\r
432 Set FeaturesVerified in published HSTI table.\r
433 This API will update the HSTI table with indicated Role and ImplementationID,\r
434 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
435\r
436 @param Role Role of HSTI data.\r
437 @param ImplementationID ImplementationID of HSTI data.\r
438 NULL means find the first one match Role.\r
439 @param ByteIndex Byte index of FeaturesVerified of HSTI data.\r
440 @param BitMask Bit mask of FeaturesVerified of HSTI data.\r
441\r
442 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.\r
443 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
444 @retval EFI_UNSUPPORTED The ByteIndex is invalid.\r
445**/\r
446EFI_STATUS\r
447EFIAPI\r
448HstiLibSetFeaturesVerified (\r
2f88bd3a
MK
449 IN UINT32 Role,\r
450 IN CHAR16 *ImplementationID OPTIONAL,\r
451 IN UINT32 ByteIndex,\r
452 IN UINT8 BitMask\r
aaedfe3c
JY
453 )\r
454{\r
455 return InternalHstiRecordFeaturesVerified (\r
456 Role,\r
457 ImplementationID,\r
458 ByteIndex,\r
459 BitMask,\r
460 TRUE\r
461 );\r
462}\r
463\r
464/**\r
465 Clear FeaturesVerified in published HSTI table.\r
466 This API will update the HSTI table with indicated Role and ImplementationID,\r
467 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
468\r
469 @param Role Role of HSTI data.\r
470 @param ImplementationID ImplementationID of HSTI data.\r
471 NULL means find the first one match Role.\r
472 @param ByteIndex Byte index of FeaturesVerified of HSTI data.\r
473 @param BitMask Bit mask of FeaturesVerified of HSTI data.\r
474\r
475 @retval EFI_SUCCESS The FeaturesVerified of HSTI data updated in AIP protocol.\r
476 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
477 @retval EFI_UNSUPPORTED The ByteIndex is invalid.\r
478**/\r
479EFI_STATUS\r
480EFIAPI\r
481HstiLibClearFeaturesVerified (\r
2f88bd3a
MK
482 IN UINT32 Role,\r
483 IN CHAR16 *ImplementationID OPTIONAL,\r
484 IN UINT32 ByteIndex,\r
485 IN UINT8 BitMask\r
aaedfe3c
JY
486 )\r
487{\r
488 return InternalHstiRecordFeaturesVerified (\r
489 Role,\r
490 ImplementationID,\r
491 ByteIndex,\r
492 BitMask,\r
493 FALSE\r
494 );\r
495}\r
496\r
497/**\r
498 Record ErrorString in published HSTI table.\r
499 This API will update the HSTI table with indicated Role and ImplementationID,\r
500 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
501\r
502 @param Role Role of HSTI data.\r
503 @param ImplementationID ImplementationID of HSTI data.\r
504 NULL means find the first one match Role.\r
505 @param ErrorString ErrorString of HSTI data.\r
506 @param Append TRUE means to append the ErrorString to HSTI table.\r
507 FALSE means to set the ErrorString in HSTI table.\r
508\r
509 @retval EFI_SUCCESS The ErrorString of HSTI data is published in AIP protocol.\r
510 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
511 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
512**/\r
513EFI_STATUS\r
514InternalHstiRecordErrorString (\r
2f88bd3a
MK
515 IN UINT32 Role,\r
516 IN CHAR16 *ImplementationID OPTIONAL,\r
517 IN CHAR16 *ErrorString,\r
518 IN BOOLEAN Append\r
aaedfe3c
JY
519 )\r
520{\r
2f88bd3a
MK
521 EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
522 ADAPTER_INFO_PLATFORM_SECURITY *Hsti;\r
523 UINTN HstiSize;\r
524 UINTN StringSize;\r
525 VOID *NewHsti;\r
526 UINTN NewHstiSize;\r
527 UINTN Offset;\r
528 EFI_STATUS Status;\r
aaedfe3c 529\r
6a39a6a1 530 Aip = InternalHstiFindAip (Role, ImplementationID, (VOID **)&Hsti, &HstiSize);\r
aaedfe3c
JY
531 if (Aip == NULL) {\r
532 return EFI_NOT_STARTED;\r
533 }\r
534\r
535 if (Append) {\r
2f88bd3a 536 Offset = HstiSize - sizeof (CHAR16);\r
aaedfe3c 537 } else {\r
2f88bd3a 538 Offset = sizeof (ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3;\r
aaedfe3c 539 }\r
2f88bd3a 540\r
aaedfe3c
JY
541 StringSize = StrSize (ErrorString);\r
542\r
543 NewHstiSize = Offset + StringSize;\r
2f88bd3a 544 NewHsti = AllocatePool (NewHstiSize);\r
aaedfe3c
JY
545 if (NewHsti == NULL) {\r
546 return EFI_OUT_OF_RESOURCES;\r
547 }\r
548\r
549 CopyMem (NewHsti, Hsti, Offset);\r
550 CopyMem ((UINT8 *)NewHsti + Offset, ErrorString, StringSize);\r
551\r
552 Status = Aip->SetInformation (\r
553 Aip,\r
554 &gAdapterInfoPlatformSecurityGuid,\r
555 NewHsti,\r
556 NewHstiSize\r
557 );\r
357c4825
SZ
558 FreePool (Hsti);\r
559 FreePool (NewHsti);\r
aaedfe3c
JY
560 return Status;\r
561}\r
562\r
563/**\r
564 Append ErrorString in published HSTI table.\r
565 This API will update the HSTI table with indicated Role and ImplementationID,\r
566 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
567\r
568 @param Role Role of HSTI data.\r
569 @param ImplementationID ImplementationID of HSTI data.\r
570 NULL means find the first one match Role.\r
571 @param ErrorString ErrorString of HSTI data.\r
572\r
573 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.\r
574 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
575 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
576**/\r
577EFI_STATUS\r
578EFIAPI\r
579HstiLibAppendErrorString (\r
2f88bd3a
MK
580 IN UINT32 Role,\r
581 IN CHAR16 *ImplementationID OPTIONAL,\r
582 IN CHAR16 *ErrorString\r
aaedfe3c
JY
583 )\r
584{\r
585 return InternalHstiRecordErrorString (\r
586 Role,\r
587 ImplementationID,\r
588 ErrorString,\r
589 TRUE\r
590 );\r
591}\r
592\r
593/**\r
594 Set a new ErrorString in published HSTI table.\r
595 This API will update the HSTI table with indicated Role and ImplementationID,\r
596 NULL ImplementationID means to find the first HSTI table with indicated Role.\r
597\r
598 @param Role Role of HSTI data.\r
599 @param ImplementationID ImplementationID of HSTI data.\r
600 NULL means find the first one match Role.\r
601 @param ErrorString ErrorString of HSTI data.\r
602\r
603 @retval EFI_SUCCESS The ErrorString of HSTI data is updated in AIP protocol.\r
604 @retval EFI_NOT_STARTED There is not HSTI table with the Role and ImplementationID published in system.\r
605 @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
606**/\r
607EFI_STATUS\r
608EFIAPI\r
609HstiLibSetErrorString (\r
2f88bd3a
MK
610 IN UINT32 Role,\r
611 IN CHAR16 *ImplementationID OPTIONAL,\r
612 IN CHAR16 *ErrorString\r
aaedfe3c
JY
613 )\r
614{\r
615 return InternalHstiRecordErrorString (\r
616 Role,\r
617 ImplementationID,\r
618 ErrorString,\r
619 FALSE\r
620 );\r
621}\r