]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file \r |
2 | This module implements TCG EFI Protocol.\r | |
3 | \r | |
627c3961 | 4 | Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r |
0c18794e | 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 <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 | |
49 | typedef 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 | |
56 | typedef 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 | |
82 | typedef 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 | |
94 | EFI_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 | |
115 | EFI_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 | |
150 | UINTN mBootAttempts = 0;\r | |
151 | CHAR16 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 | |
175 | EFI_STATUS\r | |
176 | EFIAPI\r | |
177 | TcgDxeStatusCheck (\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 | |
234 | EFI_STATUS\r | |
235 | EFIAPI\r | |
236 | TcgDxeHashAll (\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 | |
f5af77a8 | 265 | if (*HashedDataResult == NULL) {\r |
266 | *HashedDataResult = AllocatePool ((UINTN) *HashedDataLen);\r | |
267 | } \r | |
268 | \r | |
0c18794e | 269 | return TpmCommHashAll (\r |
270 | HashData,\r | |
271 | (UINTN) HashDataLen,\r | |
272 | (TPM_DIGEST*)*HashedDataResult\r | |
273 | );\r | |
274 | default:\r | |
275 | return EFI_UNSUPPORTED;\r | |
276 | }\r | |
277 | }\r | |
278 | \r | |
279 | /**\r | |
280 | Add a new entry to the Event Log.\r | |
281 | \r | |
282 | @param[in] TcgData TCG_DXE_DATA structure.\r | |
283 | @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. \r | |
284 | @param[in] NewEventData Pointer to the new event data. \r | |
285 | \r | |
286 | @retval EFI_SUCCESS The new event log entry was added.\r | |
287 | @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.\r | |
288 | \r | |
289 | **/\r | |
290 | EFI_STATUS\r | |
291 | EFIAPI\r | |
292 | TcgDxeLogEventI (\r | |
293 | IN TCG_DXE_DATA *TcgData,\r | |
294 | IN TCG_PCR_EVENT_HDR *NewEventHdr,\r | |
295 | IN UINT8 *NewEventData\r | |
296 | )\r | |
297 | {\r | |
298 | if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r | |
299 | TcgData->LastEvent = (UINT8*)(UINTN)TcgData->TcgClientAcpiTable->Lasa;\r | |
300 | return TpmCommLogEvent (\r | |
301 | &TcgData->LastEvent,\r | |
302 | &TcgData->EventLogSize,\r | |
303 | (UINTN)TcgData->TcgClientAcpiTable->Laml,\r | |
304 | NewEventHdr,\r | |
305 | NewEventData\r | |
306 | );\r | |
307 | } else {\r | |
308 | TcgData->LastEvent = (UINT8*)(UINTN)TcgData->TcgServerAcpiTable->Lasa;\r | |
309 | return TpmCommLogEvent (\r | |
310 | &TcgData->LastEvent,\r | |
311 | &TcgData->EventLogSize,\r | |
312 | (UINTN)TcgData->TcgServerAcpiTable->Laml,\r | |
313 | NewEventHdr,\r | |
314 | NewEventData\r | |
315 | );\r | |
316 | }\r | |
317 | }\r | |
318 | \r | |
319 | /**\r | |
320 | This service abstracts the capability to add an entry to the Event Log.\r | |
321 | \r | |
322 | @param[in] This Indicates the calling context\r | |
323 | @param[in] TCGLogData Pointer to the start of the data buffer containing \r | |
324 | the TCG_PCR_EVENT data structure. All fields in \r | |
325 | this structure are properly filled by the caller.\r | |
326 | @param[in, out] EventNumber The event number of the event just logged\r | |
327 | @param[in] Flags Indicate additional flags. Only one flag has been \r | |
328 | defined at this time, which is 0x01 and means the \r | |
329 | extend operation should not be performed. All \r | |
330 | other bits are reserved. \r | |
331 | \r | |
332 | @retval EFI_SUCCESS Operation completed successfully.\r | |
333 | @retval EFI_OUT_OF_RESOURCES Insufficient memory in the event log to complete this action.\r | |
334 | \r | |
335 | **/\r | |
336 | EFI_STATUS\r | |
337 | EFIAPI\r | |
338 | TcgDxeLogEvent (\r | |
339 | IN EFI_TCG_PROTOCOL *This,\r | |
340 | IN TCG_PCR_EVENT *TCGLogData,\r | |
341 | IN OUT UINT32 *EventNumber,\r | |
342 | IN UINT32 Flags\r | |
343 | )\r | |
344 | {\r | |
345 | TCG_DXE_DATA *TcgData;\r | |
346 | \r | |
347 | TcgData = TCG_DXE_DATA_FROM_THIS (This);\r | |
348 | \r | |
349 | if (TcgData->BsCap.TPMDeactivatedFlag) {\r | |
350 | return EFI_DEVICE_ERROR;\r | |
351 | }\r | |
352 | return TcgDxeLogEventI (\r | |
353 | TcgData,\r | |
354 | (TCG_PCR_EVENT_HDR*)TCGLogData,\r | |
355 | TCGLogData->Event\r | |
356 | );\r | |
357 | }\r | |
358 | \r | |
359 | /**\r | |
360 | This service is a proxy for commands to the TPM.\r | |
361 | \r | |
362 | @param[in] This Indicates the calling context\r | |
363 | @param[in] TpmInputParameterBlockSize Size of the TPM input parameter block\r | |
364 | @param[in] TpmInputParameterBlock Pointer to the TPM input parameter block\r | |
365 | @param[in] TpmOutputParameterBlockSize Size of the TPM output parameter block\r | |
366 | @param[in] TpmOutputParameterBlock Pointer to the TPM output parameter block\r | |
367 | \r | |
368 | @retval EFI_SUCCESS Operation completed successfully.\r | |
369 | @retval EFI_INVALID_PARAMETER Invalid ordinal.\r | |
370 | @retval EFI_UNSUPPORTED Current Task Priority Level >= EFI_TPL_CALLBACK.\r | |
371 | @retval EFI_TIMEOUT The TIS timed-out.\r | |
372 | \r | |
373 | **/\r | |
374 | EFI_STATUS\r | |
375 | EFIAPI\r | |
376 | TcgDxePassThroughToTpm (\r | |
377 | IN EFI_TCG_PROTOCOL *This,\r | |
378 | IN UINT32 TpmInputParameterBlockSize,\r | |
379 | IN UINT8 *TpmInputParameterBlock,\r | |
380 | IN UINT32 TpmOutputParameterBlockSize,\r | |
381 | IN UINT8 *TpmOutputParameterBlock\r | |
382 | )\r | |
383 | {\r | |
384 | TCG_DXE_DATA *TcgData;\r | |
385 | \r | |
386 | TcgData = TCG_DXE_DATA_FROM_THIS (This);\r | |
387 | \r | |
388 | return TisPcExecute (\r | |
389 | TcgData->TpmHandle,\r | |
390 | "%r%/%r",\r | |
391 | TpmInputParameterBlock,\r | |
392 | (UINTN) TpmInputParameterBlockSize,\r | |
393 | TpmOutputParameterBlock,\r | |
394 | (UINTN) TpmOutputParameterBlockSize\r | |
395 | );\r | |
396 | }\r | |
397 | \r | |
398 | /**\r | |
399 | Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,\r | |
400 | and add an entry to the Event Log.\r | |
401 | \r | |
402 | @param[in] TcgData TCG_DXE_DATA structure.\r | |
403 | @param[in] HashData Physical address of the start of the data buffer \r | |
404 | to be hashed, extended, and logged.\r | |
405 | @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r | |
406 | @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. \r | |
407 | @param[in] NewEventData Pointer to the new event data. \r | |
408 | \r | |
409 | @retval EFI_SUCCESS Operation completed successfully.\r | |
410 | @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.\r | |
411 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
412 | \r | |
413 | **/\r | |
414 | EFI_STATUS\r | |
415 | EFIAPI\r | |
416 | TcgDxeHashLogExtendEventI (\r | |
417 | IN TCG_DXE_DATA *TcgData,\r | |
418 | IN UINT8 *HashData,\r | |
419 | IN UINT64 HashDataLen,\r | |
420 | IN OUT TCG_PCR_EVENT_HDR *NewEventHdr,\r | |
421 | IN UINT8 *NewEventData\r | |
422 | )\r | |
423 | {\r | |
424 | EFI_STATUS Status;\r | |
425 | \r | |
426 | if (HashDataLen > 0) {\r | |
427 | Status = TpmCommHashAll (\r | |
428 | HashData,\r | |
429 | (UINTN) HashDataLen,\r | |
430 | &NewEventHdr->Digest\r | |
431 | );\r | |
432 | ASSERT_EFI_ERROR (Status);\r | |
433 | }\r | |
434 | \r | |
435 | Status = TpmCommExtend (\r | |
436 | TcgData->TpmHandle,\r | |
437 | &NewEventHdr->Digest,\r | |
438 | NewEventHdr->PCRIndex,\r | |
439 | NULL\r | |
440 | );\r | |
441 | if (!EFI_ERROR (Status)) {\r | |
442 | Status = TcgDxeLogEventI (TcgData, NewEventHdr, NewEventData);\r | |
443 | }\r | |
444 | \r | |
445 | return Status;\r | |
446 | }\r | |
447 | \r | |
448 | /**\r | |
449 | This service abstracts the capability to do a hash operation on a data buffer,\r | |
450 | extend a specific TPM PCR with the hash result, and add an entry to the Event Log\r | |
451 | \r | |
452 | @param[in] This Indicates the calling context\r | |
453 | @param[in] HashData Physical address of the start of the data buffer \r | |
454 | to be hashed, extended, and logged.\r | |
455 | @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData\r | |
456 | @param[in] AlgorithmId Identification of the Algorithm to use for the hashing operation\r | |
457 | @param[in, out] TCGLogData The physical address of the start of the data \r | |
458 | buffer containing the TCG_PCR_EVENT data structure.\r | |
459 | @param[in, out] EventNumber The event number of the event just logged.\r | |
460 | @param[out] EventLogLastEntry Physical address of the first byte of the entry \r | |
461 | just placed in the Event Log. If the Event Log was \r | |
462 | empty when this function was called then this physical \r | |
463 | address will be the same as the physical address of \r | |
464 | the start of the Event Log.\r | |
465 | \r | |
466 | @retval EFI_SUCCESS Operation completed successfully.\r | |
467 | @retval EFI_UNSUPPORTED AlgorithmId != TPM_ALG_SHA.\r | |
468 | @retval EFI_UNSUPPORTED Current TPL >= EFI_TPL_CALLBACK.\r | |
469 | @retval EFI_DEVICE_ERROR The command was unsuccessful.\r | |
470 | \r | |
471 | **/\r | |
472 | EFI_STATUS\r | |
473 | EFIAPI\r | |
474 | TcgDxeHashLogExtendEvent (\r | |
475 | IN EFI_TCG_PROTOCOL *This,\r | |
476 | IN EFI_PHYSICAL_ADDRESS HashData,\r | |
477 | IN UINT64 HashDataLen,\r | |
478 | IN TPM_ALGORITHM_ID AlgorithmId,\r | |
479 | IN OUT TCG_PCR_EVENT *TCGLogData,\r | |
480 | IN OUT UINT32 *EventNumber,\r | |
481 | OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry\r | |
482 | )\r | |
483 | {\r | |
484 | TCG_DXE_DATA *TcgData;\r | |
485 | \r | |
486 | TcgData = TCG_DXE_DATA_FROM_THIS (This);\r | |
487 | \r | |
488 | if (TcgData->BsCap.TPMDeactivatedFlag) {\r | |
489 | return EFI_DEVICE_ERROR;\r | |
490 | }\r | |
491 | \r | |
492 | if (AlgorithmId != TPM_ALG_SHA) {\r | |
493 | return EFI_UNSUPPORTED;\r | |
494 | }\r | |
495 | \r | |
496 | return TcgDxeHashLogExtendEventI (\r | |
497 | TcgData,\r | |
498 | (UINT8 *) (UINTN) HashData,\r | |
499 | HashDataLen,\r | |
500 | (TCG_PCR_EVENT_HDR*)TCGLogData,\r | |
501 | TCGLogData->Event\r | |
502 | );\r | |
503 | }\r | |
504 | \r | |
505 | TCG_DXE_DATA mTcgDxeData = {\r | |
506 | {\r | |
507 | TcgDxeStatusCheck,\r | |
508 | TcgDxeHashAll,\r | |
509 | TcgDxeLogEvent,\r | |
510 | TcgDxePassThroughToTpm,\r | |
511 | TcgDxeHashLogExtendEvent\r | |
512 | },\r | |
513 | {\r | |
514 | sizeof (mTcgDxeData.BsCap),\r | |
515 | { 1, 2, 0, 0 },\r | |
516 | { 1, 2, 0, 0 },\r | |
517 | 1,\r | |
518 | TRUE,\r | |
519 | FALSE\r | |
520 | },\r | |
521 | &mTcgClientAcpiTemplate,\r | |
522 | &mTcgServerAcpiTemplate,\r | |
523 | 0,\r | |
524 | NULL,\r | |
525 | NULL\r | |
526 | };\r | |
527 | \r | |
528 | /**\r | |
529 | Initialize the Event Log and log events passed from the PEI phase.\r | |
530 | \r | |
531 | @retval EFI_SUCCESS Operation completed successfully.\r | |
532 | @retval EFI_OUT_OF_RESOURCES Out of memory.\r | |
533 | \r | |
534 | **/\r | |
535 | EFI_STATUS\r | |
536 | EFIAPI\r | |
537 | SetupEventLog (\r | |
538 | VOID\r | |
539 | )\r | |
540 | {\r | |
541 | EFI_STATUS Status;\r | |
542 | TCG_PCR_EVENT *TcgEvent;\r | |
543 | EFI_PEI_HOB_POINTERS GuidHob;\r | |
544 | EFI_PHYSICAL_ADDRESS Lasa;\r | |
545 | \r | |
546 | if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r | |
547 | Lasa = mTcgClientAcpiTemplate.Lasa;\r | |
548 | \r | |
549 | Status = gBS->AllocatePages (\r | |
550 | AllocateMaxAddress,\r | |
551 | EfiACPIMemoryNVS,\r | |
552 | EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r | |
553 | &Lasa\r | |
554 | );\r | |
555 | if (EFI_ERROR (Status)) {\r | |
556 | return Status;\r | |
557 | }\r | |
558 | mTcgClientAcpiTemplate.Lasa = Lasa;\r | |
559 | //\r | |
560 | // To initialize them as 0xFF is recommended \r | |
561 | // because the OS can know the last entry for that.\r | |
562 | //\r | |
563 | SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r | |
564 | mTcgClientAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r | |
565 | \r | |
566 | } else {\r | |
567 | Lasa = mTcgServerAcpiTemplate.Lasa;\r | |
568 | \r | |
569 | Status = gBS->AllocatePages (\r | |
570 | AllocateMaxAddress,\r | |
571 | EfiACPIMemoryNVS,\r | |
572 | EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r | |
573 | &Lasa\r | |
574 | );\r | |
575 | if (EFI_ERROR (Status)) {\r | |
576 | return Status;\r | |
577 | }\r | |
578 | mTcgServerAcpiTemplate.Lasa = Lasa;\r | |
579 | //\r | |
580 | // To initialize them as 0xFF is recommended \r | |
581 | // because the OS can know the last entry for that.\r | |
582 | //\r | |
583 | SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r | |
584 | mTcgServerAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r | |
585 | }\r | |
586 | \r | |
587 | GuidHob.Raw = GetHobList ();\r | |
588 | while (!EFI_ERROR (Status) && \r | |
589 | (GuidHob.Raw = GetNextGuidHob (&gTcgEventEntryHobGuid, GuidHob.Raw)) != NULL) {\r | |
590 | TcgEvent = GET_GUID_HOB_DATA (GuidHob.Guid);\r | |
591 | GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r | |
592 | Status = TcgDxeLogEventI (\r | |
593 | &mTcgDxeData,\r | |
594 | (TCG_PCR_EVENT_HDR*)TcgEvent,\r | |
595 | TcgEvent->Event\r | |
596 | );\r | |
597 | }\r | |
598 | \r | |
599 | return Status;\r | |
600 | }\r | |
601 | \r | |
602 | /**\r | |
603 | Measure and log an action string, and extend the measurement result into PCR[5].\r | |
604 | \r | |
605 | @param[in] String A specific string that indicates an Action event. \r | |
606 | \r | |
607 | @retval EFI_SUCCESS Operation completed successfully.\r | |
608 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
609 | \r | |
610 | **/\r | |
611 | EFI_STATUS\r | |
612 | EFIAPI\r | |
613 | TcgMeasureAction (\r | |
614 | IN CHAR8 *String\r | |
615 | )\r | |
616 | {\r | |
617 | TCG_PCR_EVENT_HDR TcgEvent;\r | |
618 | \r | |
619 | TcgEvent.PCRIndex = 5;\r | |
620 | TcgEvent.EventType = EV_EFI_ACTION;\r | |
621 | TcgEvent.EventSize = (UINT32)AsciiStrLen (String);\r | |
622 | return TcgDxeHashLogExtendEventI (\r | |
623 | &mTcgDxeData,\r | |
624 | (UINT8*)String,\r | |
625 | TcgEvent.EventSize,\r | |
626 | &TcgEvent,\r | |
627 | (UINT8 *) String\r | |
628 | );\r | |
629 | }\r | |
630 | \r | |
631 | /**\r | |
632 | Measure and log EFI handoff tables, and extend the measurement result into PCR[1].\r | |
633 | \r | |
634 | @retval EFI_SUCCESS Operation completed successfully.\r | |
635 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
636 | \r | |
637 | **/\r | |
638 | EFI_STATUS\r | |
639 | EFIAPI\r | |
640 | MeasureHandoffTables (\r | |
641 | VOID\r | |
642 | )\r | |
643 | {\r | |
644 | EFI_STATUS Status;\r | |
645 | SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r | |
646 | TCG_PCR_EVENT_HDR TcgEvent;\r | |
647 | EFI_HANDOFF_TABLE_POINTERS HandoffTables;\r | |
648 | \r | |
649 | Status = EfiGetSystemConfigurationTable (\r | |
650 | &gEfiSmbiosTableGuid,\r | |
651 | (VOID **) &SmbiosTable\r | |
652 | );\r | |
653 | \r | |
654 | if (!EFI_ERROR (Status)) {\r | |
655 | ASSERT (SmbiosTable != NULL);\r | |
656 | \r | |
657 | TcgEvent.PCRIndex = 1;\r | |
658 | TcgEvent.EventType = EV_EFI_HANDOFF_TABLES;\r | |
659 | TcgEvent.EventSize = sizeof (HandoffTables);\r | |
660 | \r | |
661 | HandoffTables.NumberOfTables = 1;\r | |
662 | HandoffTables.TableEntry[0].VendorGuid = gEfiSmbiosTableGuid;\r | |
663 | HandoffTables.TableEntry[0].VendorTable = SmbiosTable;\r | |
664 | \r | |
665 | DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTable->TableAddress));\r | |
666 | DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", SmbiosTable->TableLength));\r | |
667 | \r | |
668 | Status = TcgDxeHashLogExtendEventI (\r | |
669 | &mTcgDxeData,\r | |
670 | (UINT8*)(UINTN)SmbiosTable->TableAddress,\r | |
671 | SmbiosTable->TableLength,\r | |
672 | &TcgEvent,\r | |
673 | (UINT8*)&HandoffTables\r | |
674 | );\r | |
675 | }\r | |
676 | \r | |
677 | return Status;\r | |
678 | }\r | |
679 | \r | |
680 | /**\r | |
681 | Measure and log Separator event, and extend the measurement result into a specific PCR.\r | |
682 | \r | |
683 | @param[in] PCRIndex PCR index. \r | |
684 | \r | |
685 | @retval EFI_SUCCESS Operation completed successfully.\r | |
686 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
687 | \r | |
688 | **/\r | |
689 | EFI_STATUS\r | |
690 | EFIAPI\r | |
691 | MeasureSeparatorEvent (\r | |
692 | IN TPM_PCRINDEX PCRIndex\r | |
693 | )\r | |
694 | {\r | |
695 | TCG_PCR_EVENT_HDR TcgEvent;\r | |
696 | UINT32 EventData;\r | |
697 | \r | |
698 | EventData = 0;\r | |
699 | TcgEvent.PCRIndex = PCRIndex;\r | |
700 | TcgEvent.EventType = EV_SEPARATOR;\r | |
701 | TcgEvent.EventSize = (UINT32)sizeof (EventData);\r | |
702 | return TcgDxeHashLogExtendEventI (\r | |
703 | &mTcgDxeData,\r | |
704 | (UINT8 *)&EventData,\r | |
705 | sizeof (EventData),\r | |
706 | &TcgEvent,\r | |
707 | (UINT8 *)&EventData\r | |
708 | );\r | |
709 | }\r | |
710 | \r | |
711 | /**\r | |
712 | Read an EFI Variable.\r | |
713 | \r | |
714 | This function allocates a buffer to return the contents of the variable. The caller is\r | |
715 | responsible for freeing the buffer.\r | |
716 | \r | |
717 | @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r | |
718 | @param[in] VendorGuid A unique identifier for the vendor.\r | |
719 | @param[out] VarSize The size of the variable data. \r | |
720 | \r | |
721 | @return A pointer to the buffer to return the contents of the variable.Otherwise NULL.\r | |
722 | \r | |
723 | **/\r | |
724 | VOID *\r | |
725 | EFIAPI\r | |
726 | ReadVariable (\r | |
727 | IN CHAR16 *VarName,\r | |
728 | IN EFI_GUID *VendorGuid,\r | |
729 | OUT UINTN *VarSize\r | |
730 | )\r | |
731 | {\r | |
732 | EFI_STATUS Status;\r | |
733 | VOID *VarData;\r | |
734 | \r | |
735 | *VarSize = 0;\r | |
736 | Status = gRT->GetVariable (\r | |
737 | VarName,\r | |
738 | VendorGuid,\r | |
739 | NULL,\r | |
740 | VarSize,\r | |
741 | NULL\r | |
742 | );\r | |
743 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
744 | return NULL;\r | |
745 | }\r | |
746 | \r | |
747 | VarData = AllocatePool (*VarSize);\r | |
748 | if (VarData != NULL) {\r | |
749 | Status = gRT->GetVariable (\r | |
750 | VarName,\r | |
751 | VendorGuid,\r | |
752 | NULL,\r | |
753 | VarSize,\r | |
754 | VarData\r | |
755 | );\r | |
756 | if (EFI_ERROR (Status)) {\r | |
757 | FreePool (VarData);\r | |
758 | VarData = NULL;\r | |
759 | *VarSize = 0;\r | |
760 | }\r | |
761 | }\r | |
762 | return VarData;\r | |
763 | }\r | |
764 | \r | |
765 | /**\r | |
766 | Measure and log an EFI variable, and extend the measurement result into a specific PCR.\r | |
767 | \r | |
768 | @param[in] PCRIndex PCR Index. \r | |
769 | @param[in] EventType Event type. \r | |
770 | @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r | |
771 | @param[in] VendorGuid A unique identifier for the vendor.\r | |
772 | @param[in] VarData The content of the variable data. \r | |
773 | @param[in] VarSize The size of the variable data. \r | |
774 | \r | |
775 | @retval EFI_SUCCESS Operation completed successfully.\r | |
776 | @retval EFI_OUT_OF_RESOURCES Out of memory.\r | |
777 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
778 | \r | |
779 | **/\r | |
780 | EFI_STATUS\r | |
781 | EFIAPI\r | |
782 | MeasureVariable (\r | |
783 | IN TPM_PCRINDEX PCRIndex,\r | |
784 | IN TCG_EVENTTYPE EventType,\r | |
785 | IN CHAR16 *VarName,\r | |
786 | IN EFI_GUID *VendorGuid,\r | |
787 | IN VOID *VarData,\r | |
788 | IN UINTN VarSize\r | |
789 | )\r | |
790 | {\r | |
791 | EFI_STATUS Status;\r | |
792 | TCG_PCR_EVENT_HDR TcgEvent;\r | |
793 | UINTN VarNameLength;\r | |
794 | EFI_VARIABLE_DATA *VarLog;\r | |
795 | \r | |
796 | VarNameLength = StrLen (VarName);\r | |
797 | TcgEvent.PCRIndex = PCRIndex;\r | |
798 | TcgEvent.EventType = EventType;\r | |
799 | TcgEvent.EventSize = (UINT32)(sizeof (*VarLog) + VarNameLength * sizeof (*VarName) + VarSize\r | |
800 | - sizeof (VarLog->UnicodeName) - sizeof (VarLog->VariableData));\r | |
801 | \r | |
802 | VarLog = (EFI_VARIABLE_DATA*)AllocatePool (TcgEvent.EventSize);\r | |
803 | if (VarLog == NULL) {\r | |
804 | return EFI_OUT_OF_RESOURCES;\r | |
805 | }\r | |
806 | \r | |
807 | VarLog->VariableName = *VendorGuid;\r | |
808 | VarLog->UnicodeNameLength = VarNameLength;\r | |
809 | VarLog->VariableDataLength = VarSize;\r | |
810 | CopyMem (\r | |
811 | VarLog->UnicodeName,\r | |
812 | VarName,\r | |
813 | VarNameLength * sizeof (*VarName)\r | |
814 | );\r | |
815 | CopyMem (\r | |
816 | (CHAR16 *)VarLog->UnicodeName + VarNameLength,\r | |
817 | VarData,\r | |
818 | VarSize\r | |
819 | );\r | |
820 | \r | |
821 | Status = TcgDxeHashLogExtendEventI (\r | |
822 | &mTcgDxeData,\r | |
823 | (UINT8*)VarData,\r | |
824 | VarSize,\r | |
825 | &TcgEvent,\r | |
826 | (UINT8*)VarLog\r | |
827 | );\r | |
828 | FreePool (VarLog);\r | |
829 | return Status;\r | |
830 | }\r | |
831 | \r | |
832 | /**\r | |
833 | Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].\r | |
834 | \r | |
835 | @param[in] VarName A Null-terminated string that is the name of the vendor's variable.\r | |
836 | @param[in] VendorGuid A unique identifier for the vendor.\r | |
837 | @param[out] VarSize The size of the variable data. \r | |
838 | @param[out] VarData Pointer to the content of the variable. \r | |
839 | \r | |
840 | @retval EFI_SUCCESS Operation completed successfully.\r | |
841 | @retval EFI_OUT_OF_RESOURCES Out of memory.\r | |
842 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
843 | \r | |
844 | **/\r | |
845 | EFI_STATUS\r | |
846 | EFIAPI\r | |
847 | ReadAndMeasureBootVariable (\r | |
848 | IN CHAR16 *VarName,\r | |
849 | IN EFI_GUID *VendorGuid,\r | |
850 | OUT UINTN *VarSize,\r | |
851 | OUT VOID **VarData\r | |
852 | )\r | |
853 | {\r | |
854 | EFI_STATUS Status;\r | |
855 | \r | |
856 | *VarData = ReadVariable (VarName, VendorGuid, VarSize);\r | |
857 | if (*VarData == NULL) {\r | |
858 | return EFI_NOT_FOUND;\r | |
859 | }\r | |
860 | \r | |
861 | Status = MeasureVariable (\r | |
862 | 5,\r | |
863 | EV_EFI_VARIABLE_BOOT,\r | |
864 | VarName,\r | |
865 | VendorGuid,\r | |
866 | *VarData,\r | |
867 | *VarSize\r | |
868 | );\r | |
869 | return Status;\r | |
870 | }\r | |
871 | \r | |
872 | /**\r | |
873 | Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.\r | |
874 | \r | |
875 | The EFI boot variables are BootOrder and Boot#### variables.\r | |
876 | \r | |
877 | @retval EFI_SUCCESS Operation completed successfully.\r | |
878 | @retval EFI_OUT_OF_RESOURCES Out of memory.\r | |
879 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
880 | \r | |
881 | **/\r | |
882 | EFI_STATUS\r | |
883 | EFIAPI\r | |
884 | MeasureAllBootVariables (\r | |
885 | VOID\r | |
886 | )\r | |
887 | {\r | |
888 | EFI_STATUS Status;\r | |
889 | UINT16 *BootOrder;\r | |
890 | UINTN BootCount;\r | |
891 | UINTN Index;\r | |
892 | VOID *BootVarData;\r | |
893 | UINTN Size;\r | |
894 | \r | |
895 | Status = ReadAndMeasureBootVariable (\r | |
896 | mBootVarName,\r | |
897 | &gEfiGlobalVariableGuid,\r | |
898 | &BootCount,\r | |
899 | (VOID **) &BootOrder\r | |
900 | );\r | |
901 | if (Status == EFI_NOT_FOUND) {\r | |
902 | return EFI_SUCCESS;\r | |
903 | }\r | |
904 | ASSERT (BootOrder != NULL);\r | |
905 | \r | |
906 | if (EFI_ERROR (Status)) {\r | |
907 | FreePool (BootOrder);\r | |
908 | return Status;\r | |
909 | }\r | |
910 | \r | |
911 | BootCount /= sizeof (*BootOrder);\r | |
912 | for (Index = 0; Index < BootCount; Index++) {\r | |
913 | UnicodeSPrint (mBootVarName, sizeof (mBootVarName), L"Boot%04x", BootOrder[Index]);\r | |
914 | Status = ReadAndMeasureBootVariable (\r | |
915 | mBootVarName,\r | |
916 | &gEfiGlobalVariableGuid,\r | |
917 | &Size,\r | |
918 | &BootVarData\r | |
919 | );\r | |
920 | if (!EFI_ERROR (Status)) {\r | |
921 | FreePool (BootVarData);\r | |
922 | }\r | |
923 | }\r | |
924 | \r | |
925 | FreePool (BootOrder);\r | |
926 | return EFI_SUCCESS;\r | |
927 | }\r | |
928 | \r | |
929 | /**\r | |
930 | Ready to Boot Event notification handler.\r | |
931 | \r | |
932 | Sequence of OS boot events is measured in this event notification handler.\r | |
933 | \r | |
934 | @param[in] Event Event whose notification function is being invoked\r | |
935 | @param[in] Context Pointer to the notification function's context\r | |
936 | \r | |
937 | **/\r | |
938 | VOID\r | |
939 | EFIAPI\r | |
940 | OnReadyToBoot (\r | |
941 | IN EFI_EVENT Event,\r | |
942 | IN VOID *Context\r | |
943 | )\r | |
944 | {\r | |
945 | EFI_STATUS Status;\r | |
946 | TPM_PCRINDEX PcrIndex;\r | |
947 | \r | |
948 | if (mBootAttempts == 0) {\r | |
949 | \r | |
950 | //\r | |
951 | // Measure handoff tables.\r | |
952 | //\r | |
953 | Status = MeasureHandoffTables ();\r | |
954 | if (EFI_ERROR (Status)) {\r | |
955 | DEBUG ((EFI_D_ERROR, "HOBs not Measured. Error!\n"));\r | |
956 | }\r | |
957 | \r | |
958 | //\r | |
959 | // Measure BootOrder & Boot#### variables.\r | |
960 | //\r | |
961 | Status = MeasureAllBootVariables ();\r | |
962 | if (EFI_ERROR (Status)) {\r | |
963 | DEBUG ((EFI_D_ERROR, "Boot Variables not Measured. Error!\n"));\r | |
964 | }\r | |
965 | \r | |
966 | //\r | |
967 | // 1. This is the first boot attempt.\r | |
968 | //\r | |
969 | Status = TcgMeasureAction (\r | |
970 | EFI_CALLING_EFI_APPLICATION\r | |
971 | );\r | |
972 | ASSERT_EFI_ERROR (Status);\r | |
973 | \r | |
974 | //\r | |
975 | // 2. Draw a line between pre-boot env and entering post-boot env.\r | |
976 | //\r | |
977 | for (PcrIndex = 0; PcrIndex < 8; PcrIndex++) {\r | |
978 | Status = MeasureSeparatorEvent (PcrIndex);\r | |
979 | ASSERT_EFI_ERROR (Status);\r | |
980 | }\r | |
981 | \r | |
982 | //\r | |
983 | // 3. Measure GPT. It would be done in SAP driver.\r | |
984 | //\r | |
985 | \r | |
986 | //\r | |
987 | // 4. Measure PE/COFF OS loader. It would be done in SAP driver.\r | |
988 | //\r | |
989 | \r | |
990 | //\r | |
991 | // 5. Read & Measure variable. BootOrder already measured.\r | |
992 | //\r | |
993 | } else {\r | |
994 | //\r | |
995 | // 6. Not first attempt, meaning a return from last attempt\r | |
996 | //\r | |
997 | Status = TcgMeasureAction (\r | |
998 | EFI_RETURNING_FROM_EFI_APPLICATOIN\r | |
999 | );\r | |
1000 | ASSERT_EFI_ERROR (Status);\r | |
1001 | }\r | |
1002 | \r | |
1003 | DEBUG ((EFI_D_INFO, "TPM TcgDxe Measure Data when ReadyToBoot\n"));\r | |
1004 | //\r | |
1005 | // Increase boot attempt counter.\r | |
1006 | //\r | |
1007 | mBootAttempts++;\r | |
1008 | }\r | |
1009 | \r | |
1010 | /**\r | |
1011 | Install TCG ACPI Table when ACPI Table Protocol is available.\r | |
1012 | \r | |
0f7f6d23 | 1013 | A system's firmware uses an ACPI table to identify the system's TCG capabilities \r |
0c18794e | 1014 | to the Post-Boot environment. The information in this ACPI table is not guaranteed \r |
1015 | to be valid until the Host Platform transitions from pre-boot state to post-boot state. \r | |
1016 | \r | |
1017 | @param[in] Event Event whose notification function is being invoked\r | |
1018 | @param[in] Context Pointer to the notification function's context\r | |
1019 | **/\r | |
1020 | VOID\r | |
1021 | EFIAPI\r | |
1022 | InstallAcpiTable (\r | |
1023 | IN EFI_EVENT Event,\r | |
1024 | IN VOID* Context\r | |
1025 | )\r | |
1026 | {\r | |
1027 | UINTN TableKey;\r | |
1028 | EFI_STATUS Status;\r | |
1029 | EFI_ACPI_TABLE_PROTOCOL *AcpiTable;\r | |
1030 | UINT8 Checksum;\r | |
1031 | \r | |
1032 | Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTable);\r | |
1033 | if (EFI_ERROR (Status)) {\r | |
1034 | return;\r | |
1035 | }\r | |
1036 | \r | |
1037 | if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r | |
1038 | \r | |
1039 | //\r | |
1040 | // The ACPI table must be checksumed before calling the InstallAcpiTable() \r | |
1041 | // service of the ACPI table protocol to install it.\r | |
1042 | //\r | |
1043 | Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgClientAcpiTemplate, sizeof (mTcgClientAcpiTemplate));\r | |
1044 | mTcgClientAcpiTemplate.Header.Checksum = Checksum;\r | |
1045 | \r | |
1046 | Status = AcpiTable->InstallAcpiTable (\r | |
1047 | AcpiTable,\r | |
1048 | &mTcgClientAcpiTemplate,\r | |
1049 | sizeof (mTcgClientAcpiTemplate),\r | |
1050 | &TableKey\r | |
1051 | );\r | |
1052 | } else {\r | |
1053 | \r | |
1054 | //\r | |
1055 | // The ACPI table must be checksumed before calling the InstallAcpiTable() \r | |
1056 | // service of the ACPI table protocol to install it.\r | |
1057 | //\r | |
1058 | Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgServerAcpiTemplate, sizeof (mTcgServerAcpiTemplate));\r | |
1059 | mTcgServerAcpiTemplate.Header.Checksum = Checksum;\r | |
1060 | \r | |
1061 | Status = AcpiTable->InstallAcpiTable (\r | |
1062 | AcpiTable,\r | |
1063 | &mTcgServerAcpiTemplate,\r | |
1064 | sizeof (mTcgServerAcpiTemplate),\r | |
1065 | &TableKey\r | |
1066 | );\r | |
1067 | }\r | |
1068 | ASSERT_EFI_ERROR (Status);\r | |
1069 | }\r | |
1070 | \r | |
1071 | /**\r | |
1072 | Exit Boot Services Event notification handler.\r | |
1073 | \r | |
1074 | Measure invocation and success of ExitBootServices.\r | |
1075 | \r | |
1076 | @param[in] Event Event whose notification function is being invoked\r | |
1077 | @param[in] Context Pointer to the notification function's context\r | |
1078 | \r | |
1079 | **/\r | |
1080 | VOID\r | |
1081 | EFIAPI\r | |
1082 | OnExitBootServices (\r | |
1083 | IN EFI_EVENT Event,\r | |
1084 | IN VOID *Context\r | |
1085 | )\r | |
1086 | {\r | |
1087 | EFI_STATUS Status;\r | |
1088 | \r | |
1089 | //\r | |
1090 | // Measure invocation of ExitBootServices,\r | |
1091 | //\r | |
1092 | Status = TcgMeasureAction (\r | |
1093 | EFI_EXIT_BOOT_SERVICES_INVOCATION\r | |
1094 | );\r | |
1095 | ASSERT_EFI_ERROR (Status);\r | |
1096 | \r | |
1097 | //\r | |
1098 | // Measure success of ExitBootServices\r | |
1099 | //\r | |
1100 | Status = TcgMeasureAction (\r | |
1101 | EFI_EXIT_BOOT_SERVICES_SUCCEEDED\r | |
1102 | );\r | |
1103 | ASSERT_EFI_ERROR (Status);\r | |
1104 | }\r | |
1105 | \r | |
1106 | /**\r | |
1107 | Get TPM Deactivated state.\r | |
1108 | \r | |
1109 | @param[out] TPMDeactivatedFlag Returns TPM Deactivated state. \r | |
1110 | \r | |
1111 | @retval EFI_SUCCESS Operation completed successfully.\r | |
1112 | @retval EFI_DEVICE_ERROR The operation was unsuccessful.\r | |
1113 | \r | |
1114 | **/\r | |
1115 | EFI_STATUS\r | |
1116 | GetTpmStatus (\r | |
1117 | OUT BOOLEAN *TPMDeactivatedFlag\r | |
1118 | )\r | |
1119 | {\r | |
1120 | EFI_STATUS Status;\r | |
1121 | TPM_STCLEAR_FLAGS VFlags;\r | |
1122 | \r | |
1123 | Status = TpmCommGetFlags (\r | |
1124 | mTcgDxeData.TpmHandle,\r | |
1125 | TPM_CAP_FLAG_VOLATILE,\r | |
1126 | &VFlags,\r | |
1127 | sizeof (VFlags)\r | |
1128 | );\r | |
1129 | if (!EFI_ERROR (Status)) {\r | |
1130 | *TPMDeactivatedFlag = VFlags.deactivated;\r | |
1131 | }\r | |
1132 | \r | |
1133 | return Status;\r | |
1134 | }\r | |
1135 | \r | |
1136 | /**\r | |
1137 | The driver's entry point.\r | |
1138 | \r | |
1139 | It publishes EFI TCG Protocol.\r | |
1140 | \r | |
1141 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
1142 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1143 | \r | |
1144 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
1145 | @retval other Some error occurs when executing this entry point.\r | |
1146 | \r | |
1147 | **/\r | |
1148 | EFI_STATUS\r | |
1149 | EFIAPI\r | |
1150 | DriverEntry (\r | |
1151 | IN EFI_HANDLE ImageHandle,\r | |
1152 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1153 | )\r | |
1154 | {\r | |
1155 | EFI_STATUS Status;\r | |
1156 | EFI_EVENT Event;\r | |
1157 | VOID *Registration;\r | |
1158 | \r | |
1159 | mTcgDxeData.TpmHandle = (TIS_TPM_HANDLE)(UINTN)TPM_BASE_ADDRESS;\r | |
1160 | Status = TisPcRequestUseTpm (mTcgDxeData.TpmHandle);\r | |
1161 | if (EFI_ERROR (Status)) {\r | |
1162 | DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));\r | |
1163 | return Status;\r | |
1164 | }\r | |
1165 | \r | |
1166 | Status = GetTpmStatus (&mTcgDxeData.BsCap.TPMDeactivatedFlag);\r | |
1167 | if (EFI_ERROR (Status)) {\r | |
1168 | DEBUG ((\r | |
1169 | EFI_D_ERROR,\r | |
1170 | "Line %d in file " __FILE__ ":\n "\r | |
1171 | "DriverEntry: TPM not working properly\n",\r | |
1172 | __LINE__\r | |
1173 | ));\r | |
1174 | return Status;\r | |
1175 | }\r | |
1176 | \r | |
1177 | Status = gBS->InstallProtocolInterface (\r | |
1178 | &ImageHandle,\r | |
1179 | &gEfiTcgProtocolGuid,\r | |
1180 | EFI_NATIVE_INTERFACE,\r | |
1181 | &mTcgDxeData.TcgProtocol\r | |
1182 | );\r | |
0c18794e | 1183 | if (!EFI_ERROR (Status) && !mTcgDxeData.BsCap.TPMDeactivatedFlag) {\r |
1184 | //\r | |
1185 | // Setup the log area and copy event log from hob list to it\r | |
1186 | //\r | |
1187 | Status = SetupEventLog ();\r | |
1188 | ASSERT_EFI_ERROR (Status);\r | |
1189 | \r | |
1190 | //\r | |
1191 | // Measure handoff tables, Boot#### variables etc.\r | |
1192 | //\r | |
1193 | Status = EfiCreateEventReadyToBootEx (\r | |
1194 | TPL_CALLBACK,\r | |
1195 | OnReadyToBoot,\r | |
1196 | NULL,\r | |
1197 | &Event\r | |
1198 | );\r | |
1199 | \r | |
1200 | Status = gBS->CreateEventEx (\r | |
1201 | EVT_NOTIFY_SIGNAL,\r | |
1202 | TPL_NOTIFY,\r | |
1203 | OnExitBootServices,\r | |
1204 | NULL,\r | |
1205 | &gEfiEventExitBootServicesGuid,\r | |
1206 | &Event\r | |
1207 | );\r | |
1208 | }\r | |
1209 | \r | |
627c3961 | 1210 | //\r |
1211 | // Install ACPI Table\r | |
1212 | //\r | |
1213 | EfiCreateProtocolNotifyEvent (&gEfiAcpiTableProtocolGuid, TPL_CALLBACK, InstallAcpiTable, NULL, &Registration);\r | |
1214 | \r | |
0c18794e | 1215 | return Status;\r |
1216 | }\r |