]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TcgDxe/TcgDxe.c
Change related:
[mirror_edk2.git] / SecurityPkg / Tcg / TcgDxe / TcgDxe.c
CommitLineData
0c18794e 1/** @file \r
2 This module implements TCG EFI Protocol.\r
3 \r
4Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16#include <IndustryStandard/Tpm12.h>\r
17#include <IndustryStandard/Acpi.h>\r
18#include <IndustryStandard/PeImage.h>\r
19#include <IndustryStandard/SmBios.h>\r
20\r
21#include <Guid/GlobalVariable.h>\r
22#include <Guid/SmBios.h>\r
23#include <Guid/HobList.h>\r
24#include <Guid/TcgEventHob.h>\r
25#include <Guid/EventGroup.h>\r
26#include <Protocol/DevicePath.h>\r
27#include <Protocol/TcgService.h>\r
28#include <Protocol/AcpiTable.h>\r
29\r
30#include <Library/DebugLib.h>\r
31#include <Library/BaseMemoryLib.h>\r
32#include <Library/UefiRuntimeServicesTableLib.h>\r
33#include <Library/UefiDriverEntryPoint.h>\r
34#include <Library/HobLib.h>\r
35#include <Library/UefiBootServicesTableLib.h>\r
36#include <Library/BaseLib.h>\r
37#include <Library/MemoryAllocationLib.h>\r
38#include <Library/PrintLib.h>\r
39#include <Library/TpmCommLib.h>\r
40#include <Library/PcdLib.h>\r
41#include <Library/UefiLib.h>\r
42\r
43#include "TpmComm.h"\r
44\r
45#define EFI_TCG_LOG_AREA_SIZE 0x10000\r
46\r
47#pragma pack (1)\r
48\r
49typedef struct _EFI_TCG_CLIENT_ACPI_TABLE {\r
50 EFI_ACPI_DESCRIPTION_HEADER Header;\r
51 UINT16 PlatformClass;\r
52 UINT32 Laml;\r
53 EFI_PHYSICAL_ADDRESS Lasa;\r
54} EFI_TCG_CLIENT_ACPI_TABLE;\r
55\r
56typedef struct _EFI_TCG_SERVER_ACPI_TABLE {\r
57 EFI_ACPI_DESCRIPTION_HEADER Header;\r
58 UINT16 PlatformClass;\r
59 UINT16 Reserved0;\r
60 UINT64 Laml;\r
61 EFI_PHYSICAL_ADDRESS Lasa;\r
62 UINT16 SpecRev;\r
63 UINT8 DeviceFlags;\r
64 UINT8 InterruptFlags;\r
65 UINT8 Gpe;\r
66 UINT8 Reserved1[3];\r
67 UINT32 GlobalSysInt;\r
68 EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE BaseAddress;\r
69 UINT32 Reserved2;\r
70 EFI_ACPI_3_0_GENERIC_ADDRESS_STRUCTURE ConfigAddress;\r
71 UINT8 PciSegNum;\r
72 UINT8 PciBusNum;\r
73 UINT8 PciDevNum;\r
74 UINT8 PciFuncNum;\r
75} EFI_TCG_SERVER_ACPI_TABLE;\r
76\r
77#pragma pack ()\r
78\r
79#define TCG_DXE_DATA_FROM_THIS(this) \\r
80 BASE_CR (this, TCG_DXE_DATA, TcgProtocol)\r
81\r
82typedef struct _TCG_DXE_DATA {\r
83 EFI_TCG_PROTOCOL TcgProtocol;\r
84 TCG_EFI_BOOT_SERVICE_CAPABILITY BsCap;\r
85 EFI_TCG_CLIENT_ACPI_TABLE *TcgClientAcpiTable;\r
86 EFI_TCG_SERVER_ACPI_TABLE *TcgServerAcpiTable;\r
87 UINTN EventLogSize;\r
88 UINT8 *LastEvent;\r
89 TIS_TPM_HANDLE TpmHandle;\r
90} TCG_DXE_DATA;\r
91\r
92\r
93\r
94EFI_TCG_CLIENT_ACPI_TABLE mTcgClientAcpiTemplate = {\r
95 {\r
96 EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE,\r
97 sizeof (mTcgClientAcpiTemplate),\r
98 0x02 //Revision\r
99 //\r
100 // Compiler initializes the remaining bytes to 0\r
101 // These fields should be filled in in production\r
102 //\r
103 },\r
104 0, // 0 for PC Client Platform Class\r
105 0, // Log Area Max Length\r
106 (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1) // Log Area Start Address\r
107};\r
108\r
109//\r
110// The following EFI_TCG_SERVER_ACPI_TABLE default setting is just one example,\r
111// the TPM device connectes to LPC, and also defined the ACPI _UID as 0xFF,\r
112// this _UID can be changed and should match with the _UID setting of the TPM \r
113// ACPI device object \r
114//\r
115EFI_TCG_SERVER_ACPI_TABLE mTcgServerAcpiTemplate = {\r
116 {\r
117 EFI_ACPI_3_0_TRUSTED_COMPUTING_PLATFORM_ALLIANCE_CAPABILITIES_TABLE_SIGNATURE,\r
118 sizeof (mTcgServerAcpiTemplate),\r
119 0x02 //Revision\r
120 //\r
121 // Compiler initializes the remaining bytes to 0\r
122 // These fields should be filled in in production\r
123 //\r
124 },\r
125 1, // 1 for Server Platform Class\r
126 0, // Reserved\r
127 0, // Log Area Max Length\r
128 (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1), // Log Area Start Address\r
129 0x0100, // TCG Specification revision 1.0\r
130 2, // Device Flags\r
131 0, // Interrupt Flags\r
132 0, // GPE\r
133 {0}, // Reserved 3 bytes\r
134 0, // Global System Interrupt\r
135 {\r
136 EFI_ACPI_3_0_SYSTEM_MEMORY,\r
137 0,\r
138 0,\r
139 EFI_ACPI_3_0_BYTE,\r
140 TPM_BASE_ADDRESS // Base Address\r
141 },\r
142 0, // Reserved\r
143 {0}, // Configuration Address\r
144 0xFF, // ACPI _UID value of the device, can be changed for different platforms\r
145 0, // ACPI _UID value of the device, can be changed for different platforms\r
146 0, // ACPI _UID value of the device, can be changed for different platforms\r
147 0 // ACPI _UID value of the device, can be changed for different platforms\r
148};\r
149\r
150UINTN mBootAttempts = 0;\r
151CHAR16 mBootVarName[] = L"BootOrder";\r
152\r
153/**\r
154 This service provides EFI protocol capability information, state information \r
155 about the TPM, and Event Log state information.\r
156\r
157 @param[in] This Indicates the calling context\r
158 @param[out] ProtocolCapability The callee allocates memory for a TCG_BOOT_SERVICE_CAPABILITY \r
159 structure and fills in the fields with the EFI protocol \r
160 capability information and the current TPM state information.\r
161 @param[out] TCGFeatureFlags This is a pointer to the feature flags. No feature \r
162 flags are currently defined so this parameter \r
163 MUST be set to 0. However, in the future, \r
164 feature flags may be defined that, for example, \r
165 enable hash algorithm agility.\r
166 @param[out] EventLogLocation This is a pointer to the address of the event log in memory.\r
167 @param[out] EventLogLastEntry If the Event Log contains more than one entry, \r
168 this is a pointer to the address of the start of \r
169 the last entry in the event log in memory. \r
170\r
171 @retval EFI_SUCCESS Operation completed successfully.\r
172 @retval EFI_INVALID_PARAMETER ProtocolCapability does not match TCG capability.\r
173 \r
174**/\r
175EFI_STATUS\r
176EFIAPI\r
177TcgDxeStatusCheck (\r
178 IN EFI_TCG_PROTOCOL *This,\r
179 OUT TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability,\r
180 OUT UINT32 *TCGFeatureFlags,\r
181 OUT EFI_PHYSICAL_ADDRESS *EventLogLocation,\r
182 OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry\r
183 )\r
184{\r
185 TCG_DXE_DATA *TcgData;\r
186\r
187 TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
188\r
189 if (ProtocolCapability != NULL) {\r
190 *ProtocolCapability = TcgData->BsCap;\r
191 }\r
192\r
193 if (TCGFeatureFlags != NULL) {\r
194 *TCGFeatureFlags = 0;\r
195 }\r
196\r
197 if (EventLogLocation != NULL) {\r
198 if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r
199 *EventLogLocation = TcgData->TcgClientAcpiTable->Lasa;\r
200 } else {\r
201 *EventLogLocation = TcgData->TcgServerAcpiTable->Lasa;\r
202 }\r
203 }\r
204\r
205 if (EventLogLastEntry != NULL) {\r
206 if (TcgData->BsCap.TPMDeactivatedFlag) {\r
207 *EventLogLastEntry = (EFI_PHYSICAL_ADDRESS)(UINTN)0;\r
208 } else {\r
209 *EventLogLastEntry = (EFI_PHYSICAL_ADDRESS)(UINTN)TcgData->LastEvent;\r
210 }\r
211 }\r
212\r
213 return EFI_SUCCESS;\r
214}\r
215\r
216/**\r
217 This service abstracts the capability to do a hash operation on a data buffer.\r
218 \r
219 @param[in] This Indicates the calling context\r
220 @param[in] HashData Pointer to the data buffer to be hashed\r
221 @param[in] HashDataLen Length of the data buffer to be hashed\r
222 @param[in] AlgorithmId Identification of the Algorithm to use for the hashing operation\r
223 @param[in, out] HashedDataLen Resultant length of the hashed data\r
224 @param[in, out] HashedDataResult Resultant buffer of the hashed data \r
225 \r
226 @retval EFI_SUCCESS Operation completed successfully.\r
227 @retval EFI_INVALID_PARAMETER HashDataLen is NULL.\r
228 @retval EFI_INVALID_PARAMETER HashDataLenResult is NULL.\r
229 @retval EFI_OUT_OF_RESOURCES Cannot allocate buffer of size *HashedDataLen.\r
230 @retval EFI_UNSUPPORTED AlgorithmId not supported.\r
231 @retval EFI_BUFFER_TOO_SMALL *HashedDataLen < sizeof (TCG_DIGEST).\r
232 \r
233**/\r
234EFI_STATUS\r
235EFIAPI\r
236TcgDxeHashAll (\r
237 IN EFI_TCG_PROTOCOL *This,\r
238 IN UINT8 *HashData,\r
239 IN UINT64 HashDataLen,\r
240 IN TCG_ALGORITHM_ID AlgorithmId,\r
241 IN OUT UINT64 *HashedDataLen,\r
242 IN OUT UINT8 **HashedDataResult\r
243 )\r
244{\r
245 if (HashedDataLen == NULL || HashedDataResult == NULL) {\r
246 return EFI_INVALID_PARAMETER;\r
247 }\r
248\r
249 switch (AlgorithmId) {\r
250 case TPM_ALG_SHA:\r
251 if (*HashedDataLen == 0) {\r
252 *HashedDataLen = sizeof (TPM_DIGEST);\r
253 *HashedDataResult = AllocatePool ((UINTN) *HashedDataLen);\r
254 if (*HashedDataResult == NULL) {\r
255 return EFI_OUT_OF_RESOURCES;\r
256 }\r
257 }\r
258\r
259 if (*HashedDataLen < sizeof (TPM_DIGEST)) {\r
260 *HashedDataLen = sizeof (TPM_DIGEST);\r
261 return EFI_BUFFER_TOO_SMALL;\r
262 }\r
263 *HashedDataLen = sizeof (TPM_DIGEST);\r
264\r
265 return TpmCommHashAll (\r
266 HashData,\r
267 (UINTN) HashDataLen,\r
268 (TPM_DIGEST*)*HashedDataResult\r
269 );\r
270 default:\r
271 return EFI_UNSUPPORTED;\r
272 }\r
273}\r
274\r
275/**\r
276 Add a new entry to the Event Log.\r
277\r
278 @param[in] TcgData TCG_DXE_DATA structure.\r
279 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. \r
280 @param[in] NewEventData Pointer to the new event data. \r
281 \r
282 @retval EFI_SUCCESS The new event log entry was added.\r
283 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.\r
284\r
285**/\r
286EFI_STATUS\r
287EFIAPI\r
288TcgDxeLogEventI (\r
289 IN TCG_DXE_DATA *TcgData,\r
290 IN TCG_PCR_EVENT_HDR *NewEventHdr,\r
291 IN UINT8 *NewEventData\r
292 )\r
293{\r
294 if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r
295 TcgData->LastEvent = (UINT8*)(UINTN)TcgData->TcgClientAcpiTable->Lasa;\r
296 return TpmCommLogEvent (\r
297 &TcgData->LastEvent,\r
298 &TcgData->EventLogSize,\r
299 (UINTN)TcgData->TcgClientAcpiTable->Laml,\r
300 NewEventHdr,\r
301 NewEventData\r
302 );\r
303 } else {\r
304 TcgData->LastEvent = (UINT8*)(UINTN)TcgData->TcgServerAcpiTable->Lasa;\r
305 return TpmCommLogEvent (\r
306 &TcgData->LastEvent,\r
307 &TcgData->EventLogSize,\r
308 (UINTN)TcgData->TcgServerAcpiTable->Laml,\r
309 NewEventHdr,\r
310 NewEventData\r
311 );\r
312 }\r
313}\r
314\r
315/**\r
316 This service abstracts the capability to add an entry to the Event Log.\r
317\r
318 @param[in] This Indicates the calling context\r
319 @param[in] TCGLogData Pointer to the start of the data buffer containing \r
320 the TCG_PCR_EVENT data structure. All fields in \r
321 this structure are properly filled by the caller.\r
322 @param[in, out] EventNumber The event number of the event just logged\r
323 @param[in] Flags Indicate additional flags. Only one flag has been \r
324 defined at this time, which is 0x01 and means the \r
325 extend operation should not be performed. All \r
326 other bits are reserved. \r
327 \r
328 @retval EFI_SUCCESS Operation completed successfully.\r
329 @retval EFI_OUT_OF_RESOURCES Insufficient memory in the event log to complete this action.\r
330 \r
331**/\r
332EFI_STATUS\r
333EFIAPI\r
334TcgDxeLogEvent (\r
335 IN EFI_TCG_PROTOCOL *This,\r
336 IN TCG_PCR_EVENT *TCGLogData,\r
337 IN OUT UINT32 *EventNumber,\r
338 IN UINT32 Flags\r
339 )\r
340{\r
341 TCG_DXE_DATA *TcgData;\r
342\r
343 TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
344 \r
345 if (TcgData->BsCap.TPMDeactivatedFlag) {\r
346 return EFI_DEVICE_ERROR;\r
347 }\r
348 return TcgDxeLogEventI (\r
349 TcgData,\r
350 (TCG_PCR_EVENT_HDR*)TCGLogData,\r
351 TCGLogData->Event\r
352 );\r
353}\r
354\r
355/**\r
356 This service is a proxy for commands to the TPM.\r
357\r
358 @param[in] This Indicates the calling context\r
359 @param[in] TpmInputParameterBlockSize Size of the TPM input parameter block\r
360 @param[in] TpmInputParameterBlock Pointer to the TPM input parameter block\r
361 @param[in] TpmOutputParameterBlockSize Size of the TPM output parameter block\r
362 @param[in] TpmOutputParameterBlock Pointer to the TPM output parameter block\r
363\r
364 @retval EFI_SUCCESS Operation completed successfully.\r
365 @retval EFI_INVALID_PARAMETER Invalid ordinal.\r
366 @retval EFI_UNSUPPORTED Current Task Priority Level >= EFI_TPL_CALLBACK.\r
367 @retval EFI_TIMEOUT The TIS timed-out.\r
368 \r
369**/\r
370EFI_STATUS\r
371EFIAPI\r
372TcgDxePassThroughToTpm (\r
373 IN EFI_TCG_PROTOCOL *This,\r
374 IN UINT32 TpmInputParameterBlockSize,\r
375 IN UINT8 *TpmInputParameterBlock,\r
376 IN UINT32 TpmOutputParameterBlockSize,\r
377 IN UINT8 *TpmOutputParameterBlock\r
378 )\r
379{\r
380 TCG_DXE_DATA *TcgData;\r
381\r
382 TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
383\r
384 return TisPcExecute (\r
385 TcgData->TpmHandle,\r
386 "%r%/%r",\r
387 TpmInputParameterBlock,\r
388 (UINTN) TpmInputParameterBlockSize,\r
389 TpmOutputParameterBlock,\r
390 (UINTN) TpmOutputParameterBlockSize\r
391 );\r
392}\r
393\r
394/**\r
395 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,\r
396 and add an entry to the Event Log.\r
397\r
398 @param[in] TcgData TCG_DXE_DATA structure.\r
399 @param[in] HashData Physical address of the start of the data buffer \r
400 to be hashed, extended, and logged.\r
401 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
402 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. \r
403 @param[in] NewEventData Pointer to the new event data. \r
404\r
405 @retval EFI_SUCCESS Operation completed successfully.\r
406 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.\r
407 @retval EFI_DEVICE_ERROR The command was unsuccessful.\r
408\r
409**/\r
410EFI_STATUS\r
411EFIAPI\r
412TcgDxeHashLogExtendEventI (\r
413 IN TCG_DXE_DATA *TcgData,\r
414 IN UINT8 *HashData,\r
415 IN UINT64 HashDataLen,\r
416 IN OUT TCG_PCR_EVENT_HDR *NewEventHdr,\r
417 IN UINT8 *NewEventData\r
418 )\r
419{\r
420 EFI_STATUS Status;\r
421\r
422 if (HashDataLen > 0) {\r
423 Status = TpmCommHashAll (\r
424 HashData,\r
425 (UINTN) HashDataLen,\r
426 &NewEventHdr->Digest\r
427 );\r
428 ASSERT_EFI_ERROR (Status);\r
429 }\r
430\r
431 Status = TpmCommExtend (\r
432 TcgData->TpmHandle,\r
433 &NewEventHdr->Digest,\r
434 NewEventHdr->PCRIndex,\r
435 NULL\r
436 );\r
437 if (!EFI_ERROR (Status)) {\r
438 Status = TcgDxeLogEventI (TcgData, NewEventHdr, NewEventData);\r
439 }\r
440\r
441 return Status;\r
442}\r
443\r
444/**\r
445 This service abstracts the capability to do a hash operation on a data buffer,\r
446 extend a specific TPM PCR with the hash result, and add an entry to the Event Log\r
447\r
448 @param[in] This Indicates the calling context\r
449 @param[in] HashData Physical address of the start of the data buffer \r
450 to be hashed, extended, and logged.\r
451 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r
452 @param[in] AlgorithmId Identification of the Algorithm to use for the hashing operation\r
453 @param[in, out] TCGLogData The physical address of the start of the data \r
454 buffer containing the TCG_PCR_EVENT data structure.\r
455 @param[in, out] EventNumber The event number of the event just logged.\r
456 @param[out] EventLogLastEntry Physical address of the first byte of the entry \r
457 just placed in the Event Log. If the Event Log was \r
458 empty when this function was called then this physical \r
459 address will be the same as the physical address of \r
460 the start of the Event Log.\r
461\r
462 @retval EFI_SUCCESS Operation completed successfully.\r
463 @retval EFI_UNSUPPORTED AlgorithmId != TPM_ALG_SHA.\r
464 @retval EFI_UNSUPPORTED Current TPL >= EFI_TPL_CALLBACK.\r
465 @retval EFI_DEVICE_ERROR The command was unsuccessful.\r
466 \r
467**/\r
468EFI_STATUS\r
469EFIAPI\r
470TcgDxeHashLogExtendEvent (\r
471 IN EFI_TCG_PROTOCOL *This,\r
472 IN EFI_PHYSICAL_ADDRESS HashData,\r
473 IN UINT64 HashDataLen,\r
474 IN TPM_ALGORITHM_ID AlgorithmId,\r
475 IN OUT TCG_PCR_EVENT *TCGLogData,\r
476 IN OUT UINT32 *EventNumber,\r
477 OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry\r
478 )\r
479{\r
480 TCG_DXE_DATA *TcgData;\r
481\r
482 TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
483 \r
484 if (TcgData->BsCap.TPMDeactivatedFlag) {\r
485 return EFI_DEVICE_ERROR;\r
486 }\r
487 \r
488 if (AlgorithmId != TPM_ALG_SHA) {\r
489 return EFI_UNSUPPORTED;\r
490 }\r
491\r
492 return TcgDxeHashLogExtendEventI (\r
493 TcgData,\r
494 (UINT8 *) (UINTN) HashData,\r
495 HashDataLen,\r
496 (TCG_PCR_EVENT_HDR*)TCGLogData,\r
497 TCGLogData->Event\r
498 );\r
499}\r
500\r
501TCG_DXE_DATA mTcgDxeData = {\r
502 {\r
503 TcgDxeStatusCheck,\r
504 TcgDxeHashAll,\r
505 TcgDxeLogEvent,\r
506 TcgDxePassThroughToTpm,\r
507 TcgDxeHashLogExtendEvent\r
508 },\r
509 {\r
510 sizeof (mTcgDxeData.BsCap),\r
511 { 1, 2, 0, 0 },\r
512 { 1, 2, 0, 0 },\r
513 1,\r
514 TRUE,\r
515 FALSE\r
516 },\r
517 &mTcgClientAcpiTemplate,\r
518 &mTcgServerAcpiTemplate,\r
519 0,\r
520 NULL,\r
521 NULL\r
522};\r
523\r
524/**\r
525 Initialize the Event Log and log events passed from the PEI phase.\r
526\r
527 @retval EFI_SUCCESS Operation completed successfully.\r
528 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
529\r
530**/\r
531EFI_STATUS\r
532EFIAPI\r
533SetupEventLog (\r
534 VOID\r
535 )\r
536{\r
537 EFI_STATUS Status;\r
538 TCG_PCR_EVENT *TcgEvent;\r
539 EFI_PEI_HOB_POINTERS GuidHob;\r
540 EFI_PHYSICAL_ADDRESS Lasa;\r
541 \r
542 if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r
543 Lasa = mTcgClientAcpiTemplate.Lasa;\r
544 \r
545 Status = gBS->AllocatePages (\r
546 AllocateMaxAddress,\r
547 EfiACPIMemoryNVS,\r
548 EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r
549 &Lasa\r
550 );\r
551 if (EFI_ERROR (Status)) {\r
552 return Status;\r
553 }\r
554 mTcgClientAcpiTemplate.Lasa = Lasa;\r
555 //\r
556 // To initialize them as 0xFF is recommended \r
557 // because the OS can know the last entry for that.\r
558 //\r
559 SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r
560 mTcgClientAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r
561 \r
562 } else {\r
563 Lasa = mTcgServerAcpiTemplate.Lasa;\r
564 \r
565 Status = gBS->AllocatePages (\r
566 AllocateMaxAddress,\r
567 EfiACPIMemoryNVS,\r
568 EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r
569 &Lasa\r
570 );\r
571 if (EFI_ERROR (Status)) {\r
572 return Status;\r
573 }\r
574 mTcgServerAcpiTemplate.Lasa = Lasa;\r
575 //\r
576 // To initialize them as 0xFF is recommended \r
577 // because the OS can know the last entry for that.\r
578 //\r
579 SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r
580 mTcgServerAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r
581 }\r
582\r
583 GuidHob.Raw = GetHobList ();\r
584 while (!EFI_ERROR (Status) && \r
585 (GuidHob.Raw = GetNextGuidHob (&gTcgEventEntryHobGuid, GuidHob.Raw)) != NULL) {\r
586 TcgEvent = GET_GUID_HOB_DATA (GuidHob.Guid);\r
587 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
588 Status = TcgDxeLogEventI (\r
589 &mTcgDxeData,\r
590 (TCG_PCR_EVENT_HDR*)TcgEvent,\r
591 TcgEvent->Event\r
592 );\r
593 }\r
594\r
595 return Status;\r
596}\r
597\r
598/**\r
599 Measure and log an action string, and extend the measurement result into PCR[5].\r
600\r
601 @param[in] String A specific string that indicates an Action event. \r
602 \r
603 @retval EFI_SUCCESS Operation completed successfully.\r
604 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
605\r
606**/\r
607EFI_STATUS\r
608EFIAPI\r
609TcgMeasureAction (\r
610 IN CHAR8 *String\r
611 )\r
612{\r
613 TCG_PCR_EVENT_HDR TcgEvent;\r
614\r
615 TcgEvent.PCRIndex = 5;\r
616 TcgEvent.EventType = EV_EFI_ACTION;\r
617 TcgEvent.EventSize = (UINT32)AsciiStrLen (String);\r
618 return TcgDxeHashLogExtendEventI (\r
619 &mTcgDxeData,\r
620 (UINT8*)String,\r
621 TcgEvent.EventSize,\r
622 &TcgEvent,\r
623 (UINT8 *) String\r
624 );\r
625}\r
626\r
627/**\r
628 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].\r
629\r
630 @retval EFI_SUCCESS Operation completed successfully.\r
631 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
632\r
633**/\r
634EFI_STATUS\r
635EFIAPI\r
636MeasureHandoffTables (\r
637 VOID\r
638 )\r
639{\r
640 EFI_STATUS Status;\r
641 SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r
642 TCG_PCR_EVENT_HDR TcgEvent;\r
643 EFI_HANDOFF_TABLE_POINTERS HandoffTables;\r
644\r
645 Status = EfiGetSystemConfigurationTable (\r
646 &gEfiSmbiosTableGuid,\r
647 (VOID **) &SmbiosTable\r
648 );\r
649\r
650 if (!EFI_ERROR (Status)) {\r
651 ASSERT (SmbiosTable != NULL);\r
652\r
653 TcgEvent.PCRIndex = 1;\r
654 TcgEvent.EventType = EV_EFI_HANDOFF_TABLES;\r
655 TcgEvent.EventSize = sizeof (HandoffTables);\r
656\r
657 HandoffTables.NumberOfTables = 1;\r
658 HandoffTables.TableEntry[0].VendorGuid = gEfiSmbiosTableGuid;\r
659 HandoffTables.TableEntry[0].VendorTable = SmbiosTable;\r
660\r
661 DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTable->TableAddress));\r
662 DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", SmbiosTable->TableLength));\r
663\r
664 Status = TcgDxeHashLogExtendEventI (\r
665 &mTcgDxeData,\r
666 (UINT8*)(UINTN)SmbiosTable->TableAddress,\r
667 SmbiosTable->TableLength,\r
668 &TcgEvent,\r
669 (UINT8*)&HandoffTables\r
670 );\r
671 }\r
672\r
673 return Status;\r
674}\r
675\r
676/**\r
677 Measure and log Separator event, and extend the measurement result into a specific PCR.\r
678\r
679 @param[in] PCRIndex PCR index. \r
680\r
681 @retval EFI_SUCCESS Operation completed successfully.\r
682 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
683\r
684**/\r
685EFI_STATUS\r
686EFIAPI\r
687MeasureSeparatorEvent (\r
688 IN TPM_PCRINDEX PCRIndex\r
689 )\r
690{\r
691 TCG_PCR_EVENT_HDR TcgEvent;\r
692 UINT32 EventData;\r
693\r
694 EventData = 0;\r
695 TcgEvent.PCRIndex = PCRIndex;\r
696 TcgEvent.EventType = EV_SEPARATOR;\r
697 TcgEvent.EventSize = (UINT32)sizeof (EventData);\r
698 return TcgDxeHashLogExtendEventI (\r
699 &mTcgDxeData,\r
700 (UINT8 *)&EventData,\r
701 sizeof (EventData),\r
702 &TcgEvent,\r
703 (UINT8 *)&EventData\r
704 );\r
705}\r
706\r
707/**\r
708 Read an EFI Variable.\r
709\r
710 This function allocates a buffer to return the contents of the variable. The caller is\r
711 responsible for freeing the buffer.\r
712\r
713 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r
714 @param[in] VendorGuid A unique identifier for the vendor.\r
715 @param[out] VarSize The size of the variable data. \r
716\r
717 @return A pointer to the buffer to return the contents of the variable.Otherwise NULL.\r
718\r
719**/\r
720VOID *\r
721EFIAPI\r
722ReadVariable (\r
723 IN CHAR16 *VarName,\r
724 IN EFI_GUID *VendorGuid,\r
725 OUT UINTN *VarSize\r
726 )\r
727{\r
728 EFI_STATUS Status;\r
729 VOID *VarData;\r
730\r
731 *VarSize = 0;\r
732 Status = gRT->GetVariable (\r
733 VarName,\r
734 VendorGuid,\r
735 NULL,\r
736 VarSize,\r
737 NULL\r
738 );\r
739 if (Status != EFI_BUFFER_TOO_SMALL) {\r
740 return NULL;\r
741 }\r
742\r
743 VarData = AllocatePool (*VarSize);\r
744 if (VarData != NULL) {\r
745 Status = gRT->GetVariable (\r
746 VarName,\r
747 VendorGuid,\r
748 NULL,\r
749 VarSize,\r
750 VarData\r
751 );\r
752 if (EFI_ERROR (Status)) {\r
753 FreePool (VarData);\r
754 VarData = NULL;\r
755 *VarSize = 0;\r
756 }\r
757 }\r
758 return VarData;\r
759}\r
760\r
761/**\r
762 Measure and log an EFI variable, and extend the measurement result into a specific PCR.\r
763\r
764 @param[in] PCRIndex PCR Index. \r
765 @param[in] EventType Event type. \r
766 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r
767 @param[in] VendorGuid A unique identifier for the vendor.\r
768 @param[in] VarData The content of the variable data. \r
769 @param[in] VarSize The size of the variable data. \r
770 \r
771 @retval EFI_SUCCESS Operation completed successfully.\r
772 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
773 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
774\r
775**/\r
776EFI_STATUS\r
777EFIAPI\r
778MeasureVariable (\r
779 IN TPM_PCRINDEX PCRIndex,\r
780 IN TCG_EVENTTYPE EventType,\r
781 IN CHAR16 *VarName,\r
782 IN EFI_GUID *VendorGuid,\r
783 IN VOID *VarData,\r
784 IN UINTN VarSize\r
785 )\r
786{\r
787 EFI_STATUS Status;\r
788 TCG_PCR_EVENT_HDR TcgEvent;\r
789 UINTN VarNameLength;\r
790 EFI_VARIABLE_DATA *VarLog;\r
791\r
792 VarNameLength = StrLen (VarName);\r
793 TcgEvent.PCRIndex = PCRIndex;\r
794 TcgEvent.EventType = EventType;\r
795 TcgEvent.EventSize = (UINT32)(sizeof (*VarLog) + VarNameLength * sizeof (*VarName) + VarSize\r
796 - sizeof (VarLog->UnicodeName) - sizeof (VarLog->VariableData));\r
797\r
798 VarLog = (EFI_VARIABLE_DATA*)AllocatePool (TcgEvent.EventSize);\r
799 if (VarLog == NULL) {\r
800 return EFI_OUT_OF_RESOURCES;\r
801 }\r
802\r
803 VarLog->VariableName = *VendorGuid;\r
804 VarLog->UnicodeNameLength = VarNameLength;\r
805 VarLog->VariableDataLength = VarSize;\r
806 CopyMem (\r
807 VarLog->UnicodeName,\r
808 VarName,\r
809 VarNameLength * sizeof (*VarName)\r
810 );\r
811 CopyMem (\r
812 (CHAR16 *)VarLog->UnicodeName + VarNameLength,\r
813 VarData,\r
814 VarSize\r
815 );\r
816\r
817 Status = TcgDxeHashLogExtendEventI (\r
818 &mTcgDxeData,\r
819 (UINT8*)VarData,\r
820 VarSize,\r
821 &TcgEvent,\r
822 (UINT8*)VarLog\r
823 );\r
824 FreePool (VarLog);\r
825 return Status;\r
826}\r
827\r
828/**\r
829 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].\r
830\r
831 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r
832 @param[in] VendorGuid A unique identifier for the vendor.\r
833 @param[out] VarSize The size of the variable data. \r
834 @param[out] VarData Pointer to the content of the variable. \r
835 \r
836 @retval EFI_SUCCESS Operation completed successfully.\r
837 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
838 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
839\r
840**/\r
841EFI_STATUS\r
842EFIAPI\r
843ReadAndMeasureBootVariable (\r
844 IN CHAR16 *VarName,\r
845 IN EFI_GUID *VendorGuid,\r
846 OUT UINTN *VarSize,\r
847 OUT VOID **VarData\r
848 )\r
849{\r
850 EFI_STATUS Status;\r
851\r
852 *VarData = ReadVariable (VarName, VendorGuid, VarSize);\r
853 if (*VarData == NULL) {\r
854 return EFI_NOT_FOUND;\r
855 }\r
856\r
857 Status = MeasureVariable (\r
858 5,\r
859 EV_EFI_VARIABLE_BOOT,\r
860 VarName,\r
861 VendorGuid,\r
862 *VarData,\r
863 *VarSize\r
864 );\r
865 return Status;\r
866}\r
867\r
868/**\r
869 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.\r
870\r
871 The EFI boot variables are BootOrder and Boot#### variables.\r
872\r
873 @retval EFI_SUCCESS Operation completed successfully.\r
874 @retval EFI_OUT_OF_RESOURCES Out of memory.\r
875 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
876\r
877**/\r
878EFI_STATUS\r
879EFIAPI\r
880MeasureAllBootVariables (\r
881 VOID\r
882 )\r
883{\r
884 EFI_STATUS Status;\r
885 UINT16 *BootOrder;\r
886 UINTN BootCount;\r
887 UINTN Index;\r
888 VOID *BootVarData;\r
889 UINTN Size;\r
890\r
891 Status = ReadAndMeasureBootVariable (\r
892 mBootVarName,\r
893 &gEfiGlobalVariableGuid,\r
894 &BootCount,\r
895 (VOID **) &BootOrder\r
896 );\r
897 if (Status == EFI_NOT_FOUND) {\r
898 return EFI_SUCCESS;\r
899 }\r
900 ASSERT (BootOrder != NULL);\r
901\r
902 if (EFI_ERROR (Status)) {\r
903 FreePool (BootOrder);\r
904 return Status;\r
905 }\r
906\r
907 BootCount /= sizeof (*BootOrder);\r
908 for (Index = 0; Index < BootCount; Index++) {\r
909 UnicodeSPrint (mBootVarName, sizeof (mBootVarName), L"Boot%04x", BootOrder[Index]);\r
910 Status = ReadAndMeasureBootVariable (\r
911 mBootVarName,\r
912 &gEfiGlobalVariableGuid,\r
913 &Size,\r
914 &BootVarData\r
915 );\r
916 if (!EFI_ERROR (Status)) {\r
917 FreePool (BootVarData);\r
918 }\r
919 }\r
920\r
921 FreePool (BootOrder);\r
922 return EFI_SUCCESS;\r
923}\r
924\r
925/**\r
926 Ready to Boot Event notification handler.\r
927\r
928 Sequence of OS boot events is measured in this event notification handler.\r
929\r
930 @param[in] Event Event whose notification function is being invoked\r
931 @param[in] Context Pointer to the notification function's context\r
932\r
933**/\r
934VOID\r
935EFIAPI\r
936OnReadyToBoot (\r
937 IN EFI_EVENT Event,\r
938 IN VOID *Context\r
939 )\r
940{\r
941 EFI_STATUS Status;\r
942 TPM_PCRINDEX PcrIndex;\r
943\r
944 if (mBootAttempts == 0) {\r
945\r
946 //\r
947 // Measure handoff tables.\r
948 //\r
949 Status = MeasureHandoffTables ();\r
950 if (EFI_ERROR (Status)) {\r
951 DEBUG ((EFI_D_ERROR, "HOBs not Measured. Error!\n"));\r
952 }\r
953\r
954 //\r
955 // Measure BootOrder & Boot#### variables.\r
956 //\r
957 Status = MeasureAllBootVariables ();\r
958 if (EFI_ERROR (Status)) {\r
959 DEBUG ((EFI_D_ERROR, "Boot Variables not Measured. Error!\n"));\r
960 }\r
961\r
962 //\r
963 // 1. This is the first boot attempt.\r
964 //\r
965 Status = TcgMeasureAction (\r
966 EFI_CALLING_EFI_APPLICATION\r
967 );\r
968 ASSERT_EFI_ERROR (Status);\r
969\r
970 //\r
971 // 2. Draw a line between pre-boot env and entering post-boot env.\r
972 //\r
973 for (PcrIndex = 0; PcrIndex < 8; PcrIndex++) {\r
974 Status = MeasureSeparatorEvent (PcrIndex);\r
975 ASSERT_EFI_ERROR (Status);\r
976 }\r
977\r
978 //\r
979 // 3. Measure GPT. It would be done in SAP driver.\r
980 //\r
981\r
982 //\r
983 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.\r
984 //\r
985\r
986 //\r
987 // 5. Read & Measure variable. BootOrder already measured.\r
988 //\r
989 } else {\r
990 //\r
991 // 6. Not first attempt, meaning a return from last attempt\r
992 //\r
993 Status = TcgMeasureAction (\r
994 EFI_RETURNING_FROM_EFI_APPLICATOIN\r
995 );\r
996 ASSERT_EFI_ERROR (Status);\r
997 }\r
998\r
999 DEBUG ((EFI_D_INFO, "TPM TcgDxe Measure Data when ReadyToBoot\n"));\r
1000 //\r
1001 // Increase boot attempt counter.\r
1002 //\r
1003 mBootAttempts++;\r
1004}\r
1005\r
1006/**\r
1007 Install TCG ACPI Table when ACPI Table Protocol is available.\r
1008\r
0f7f6d23 1009 A system's firmware uses an ACPI table to identify the system's TCG capabilities \r
0c18794e 1010 to the Post-Boot environment. The information in this ACPI table is not guaranteed \r
1011 to be valid until the Host Platform transitions from pre-boot state to post-boot state. \r
1012\r
1013 @param[in] Event Event whose notification function is being invoked\r
1014 @param[in] Context Pointer to the notification function's context\r
1015**/\r
1016VOID\r
1017EFIAPI\r
1018InstallAcpiTable (\r
1019 IN EFI_EVENT Event,\r
1020 IN VOID* Context\r
1021 )\r
1022{\r
1023 UINTN TableKey;\r
1024 EFI_STATUS Status;\r
1025 EFI_ACPI_TABLE_PROTOCOL *AcpiTable;\r
1026 UINT8 Checksum;\r
1027\r
1028 Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTable);\r
1029 if (EFI_ERROR (Status)) {\r
1030 return;\r
1031 }\r
1032\r
1033 if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r
1034 \r
1035 //\r
1036 // The ACPI table must be checksumed before calling the InstallAcpiTable() \r
1037 // service of the ACPI table protocol to install it.\r
1038 //\r
1039 Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgClientAcpiTemplate, sizeof (mTcgClientAcpiTemplate));\r
1040 mTcgClientAcpiTemplate.Header.Checksum = Checksum;\r
1041\r
1042 Status = AcpiTable->InstallAcpiTable (\r
1043 AcpiTable,\r
1044 &mTcgClientAcpiTemplate,\r
1045 sizeof (mTcgClientAcpiTemplate),\r
1046 &TableKey\r
1047 );\r
1048 } else {\r
1049\r
1050 //\r
1051 // The ACPI table must be checksumed before calling the InstallAcpiTable() \r
1052 // service of the ACPI table protocol to install it.\r
1053 //\r
1054 Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgServerAcpiTemplate, sizeof (mTcgServerAcpiTemplate));\r
1055 mTcgServerAcpiTemplate.Header.Checksum = Checksum;\r
1056\r
1057 Status = AcpiTable->InstallAcpiTable (\r
1058 AcpiTable,\r
1059 &mTcgServerAcpiTemplate,\r
1060 sizeof (mTcgServerAcpiTemplate),\r
1061 &TableKey\r
1062 );\r
1063 }\r
1064 ASSERT_EFI_ERROR (Status);\r
1065}\r
1066\r
1067/**\r
1068 Exit Boot Services Event notification handler.\r
1069\r
1070 Measure invocation and success of ExitBootServices.\r
1071\r
1072 @param[in] Event Event whose notification function is being invoked\r
1073 @param[in] Context Pointer to the notification function's context\r
1074\r
1075**/\r
1076VOID\r
1077EFIAPI\r
1078OnExitBootServices (\r
1079 IN EFI_EVENT Event,\r
1080 IN VOID *Context\r
1081 )\r
1082{\r
1083 EFI_STATUS Status;\r
1084\r
1085 //\r
1086 // Measure invocation of ExitBootServices,\r
1087 //\r
1088 Status = TcgMeasureAction (\r
1089 EFI_EXIT_BOOT_SERVICES_INVOCATION\r
1090 );\r
1091 ASSERT_EFI_ERROR (Status);\r
1092\r
1093 //\r
1094 // Measure success of ExitBootServices\r
1095 //\r
1096 Status = TcgMeasureAction (\r
1097 EFI_EXIT_BOOT_SERVICES_SUCCEEDED\r
1098 );\r
1099 ASSERT_EFI_ERROR (Status);\r
1100}\r
1101\r
1102/**\r
1103 Get TPM Deactivated state.\r
1104\r
1105 @param[out] TPMDeactivatedFlag Returns TPM Deactivated state. \r
1106\r
1107 @retval EFI_SUCCESS Operation completed successfully.\r
1108 @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r
1109\r
1110**/\r
1111EFI_STATUS\r
1112GetTpmStatus (\r
1113 OUT BOOLEAN *TPMDeactivatedFlag\r
1114 )\r
1115{\r
1116 EFI_STATUS Status;\r
1117 TPM_STCLEAR_FLAGS VFlags;\r
1118\r
1119 Status = TpmCommGetFlags (\r
1120 mTcgDxeData.TpmHandle,\r
1121 TPM_CAP_FLAG_VOLATILE,\r
1122 &VFlags,\r
1123 sizeof (VFlags)\r
1124 );\r
1125 if (!EFI_ERROR (Status)) {\r
1126 *TPMDeactivatedFlag = VFlags.deactivated;\r
1127 }\r
1128\r
1129 return Status;\r
1130}\r
1131\r
1132/**\r
1133 The driver's entry point.\r
1134\r
1135 It publishes EFI TCG Protocol.\r
1136\r
1137 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
1138 @param[in] SystemTable A pointer to the EFI System Table.\r
1139 \r
1140 @retval EFI_SUCCESS The entry point is executed successfully.\r
1141 @retval other Some error occurs when executing this entry point.\r
1142\r
1143**/\r
1144EFI_STATUS\r
1145EFIAPI\r
1146DriverEntry (\r
1147 IN EFI_HANDLE ImageHandle,\r
1148 IN EFI_SYSTEM_TABLE *SystemTable\r
1149 )\r
1150{\r
1151 EFI_STATUS Status;\r
1152 EFI_EVENT Event;\r
1153 VOID *Registration;\r
1154\r
1155 mTcgDxeData.TpmHandle = (TIS_TPM_HANDLE)(UINTN)TPM_BASE_ADDRESS;\r
1156 Status = TisPcRequestUseTpm (mTcgDxeData.TpmHandle);\r
1157 if (EFI_ERROR (Status)) {\r
1158 DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));\r
1159 return Status;\r
1160 }\r
1161\r
1162 Status = GetTpmStatus (&mTcgDxeData.BsCap.TPMDeactivatedFlag);\r
1163 if (EFI_ERROR (Status)) {\r
1164 DEBUG ((\r
1165 EFI_D_ERROR,\r
1166 "Line %d in file " __FILE__ ":\n "\r
1167 "DriverEntry: TPM not working properly\n",\r
1168 __LINE__\r
1169 ));\r
1170 return Status;\r
1171 }\r
1172\r
1173 Status = gBS->InstallProtocolInterface (\r
1174 &ImageHandle,\r
1175 &gEfiTcgProtocolGuid,\r
1176 EFI_NATIVE_INTERFACE,\r
1177 &mTcgDxeData.TcgProtocol\r
1178 );\r
1179 //\r
1180 // Install ACPI Table\r
1181 //\r
1182 EfiCreateProtocolNotifyEvent (&gEfiAcpiTableProtocolGuid, TPL_CALLBACK, InstallAcpiTable, NULL, &Registration);\r
1183 \r
1184 if (!EFI_ERROR (Status) && !mTcgDxeData.BsCap.TPMDeactivatedFlag) {\r
1185 //\r
1186 // Setup the log area and copy event log from hob list to it\r
1187 //\r
1188 Status = SetupEventLog ();\r
1189 ASSERT_EFI_ERROR (Status);\r
1190\r
1191 //\r
1192 // Measure handoff tables, Boot#### variables etc.\r
1193 //\r
1194 Status = EfiCreateEventReadyToBootEx (\r
1195 TPL_CALLBACK,\r
1196 OnReadyToBoot,\r
1197 NULL,\r
1198 &Event\r
1199 );\r
1200\r
1201 Status = gBS->CreateEventEx (\r
1202 EVT_NOTIFY_SIGNAL,\r
1203 TPL_NOTIFY,\r
1204 OnExitBootServices,\r
1205 NULL,\r
1206 &gEfiEventExitBootServicesGuid,\r
1207 &Event\r
1208 );\r
1209 }\r
1210\r
1211 return Status;\r
1212}\r