/** This service abstracts the capability to add an entry to the Event Log. @param[in] This Indicates the calling context @param[in] TCGLogData Pointer to the start of the data buffer containing the TCG_PCR_EVENT data structure. All fields in this structure are properly filled by the caller. @param[in, out] EventNumber The event number of the event just logged @param[in] Flags Indicate additional flags. Only one flag has been defined at this time, which is 0x01 and means the extend operation should not be performed. All other bits are reserved. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES Insufficient memory in the event log to complete this action. **/ EFI_STATUS EFIAPI TcgDxeLogEvent ( IN EFI_TCG_PROTOCOL *This, IN TCG_PCR_EVENT *TCGLogData, IN OUT UINT32 *EventNumber, IN UINT32 Flags ) { TCG_DXE_DATA *TcgData; if (TCGLogData == NULL){ return EFI_INVALID_PARAMETER; } TcgData = TCG_DXE_DATA_FROM_THIS (This); if (TcgData->BsCap.TPMDeactivatedFlag || (!TcgData->BsCap.TPMPresentFlag)) { return EFI_DEVICE_ERROR; } return TcgDxeLogEventI ( TcgData, (TCG_PCR_EVENT_HDR*)TCGLogData, TCGLogData->Event ); }
/** Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and add an entry to the Event Log. @param[in] TcgData TCG_DXE_DATA structure. @param[in] HashData Physical address of the start of the data buffer to be hashed, extended, and logged. @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. @param[in] NewEventData Pointer to the new event data. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event. @retval EFI_DEVICE_ERROR The command was unsuccessful. **/ EFI_STATUS EFIAPI TcgDxeHashLogExtendEventI ( IN TCG_DXE_DATA *TcgData, IN UINT8 *HashData, IN UINT64 HashDataLen, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData ) { EFI_STATUS Status; if (HashDataLen > 0) { Status = TpmCommHashAll ( HashData, (UINTN) HashDataLen, &NewEventHdr->Digest ); ASSERT_EFI_ERROR (Status); } Status = TpmCommExtend ( TcgData->TpmHandle, &NewEventHdr->Digest, NewEventHdr->PCRIndex, NULL ); if (!EFI_ERROR (Status)) { Status = TcgDxeLogEventI (TcgData, NewEventHdr, NewEventData); } return Status; }
/** Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and add an entry to the Event Log. @param[in] TcgData TCG_DXE_DATA structure. @param[in] HashData Physical address of the start of the data buffer to be hashed, extended, and logged. @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. @param[in] NewEventData Pointer to the new event data. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event. @retval EFI_DEVICE_ERROR The command was unsuccessful. **/ EFI_STATUS EFIAPI TcgDxeHashLogExtendEventI ( IN TCG_DXE_DATA *TcgData, IN UINT8 *HashData, IN UINT64 HashDataLen, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData ) { EFI_STATUS Status; if (!TcgData->BsCap.TPMPresentFlag) { return EFI_DEVICE_ERROR; } if (HashDataLen > 0 || HashData != NULL) { Status = TpmCommHashAll ( HashData, (UINTN) HashDataLen, &NewEventHdr->Digest ); if (EFI_ERROR(Status)) { DEBUG ((DEBUG_ERROR, "TpmCommHashAll Failed. %x\n", Status)); goto Done; } } Status = TpmCommExtend ( TcgData->TpmHandle, &NewEventHdr->Digest, NewEventHdr->PCRIndex, NULL ); if (!EFI_ERROR (Status)) { Status = TcgDxeLogEventI (TcgData, NewEventHdr, NewEventData); } Done: if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_TIMEOUT)) { DEBUG ((EFI_D_ERROR, "TcgDxeHashLogExtendEventI - %r. Disable TPM.\n", Status)); TcgData->BsCap.TPMPresentFlag = FALSE; REPORT_STATUS_CODE ( EFI_ERROR_CODE | EFI_ERROR_MINOR, (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR) ); Status = EFI_DEVICE_ERROR; } return Status; }
/** Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and add an entry to the Event Log. @param[in] TcgData TCG_DXE_DATA structure. @param[in] HashData Physical address of the start of the data buffer to be hashed, extended, and logged. @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure. @param[in] NewEventData Pointer to the new event data. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event. @retval EFI_DEVICE_ERROR The command was unsuccessful. **/ EFI_STATUS EFIAPI TcgDxeHashLogExtendEventI ( IN TCG_DXE_DATA *TcgData, IN UINT8 *HashData, IN UINT64 HashDataLen, IN OUT TCG_PCR_EVENT_HDR *NewEventHdr, IN UINT8 *NewEventData ) { EFI_STATUS Status; if (HashData == NULL && HashDataLen > 0) { return EFI_INVALID_PARAMETER; } if (HashDataLen > 0 || HashData != NULL) { Status = TpmCommHashAll ( HashData, (UINTN) HashDataLen, &NewEventHdr->Digest ); if (EFI_ERROR(Status)) { DEBUG ((DEBUG_ERROR, "TpmCommHashAll Failed. %x\n", Status)); return Status; } } Status = TpmCommExtend ( TcgData->TpmHandle, &NewEventHdr->Digest, NewEventHdr->PCRIndex, NULL ); if (!EFI_ERROR (Status)) { Status = TcgDxeLogEventI (TcgData, NewEventHdr, NewEventData); } return Status; }
/** Initialize the Event Log and log events passed from the PEI phase. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_OUT_OF_RESOURCES Out of memory. **/ EFI_STATUS EFIAPI SetupEventLog ( VOID ) { EFI_STATUS Status; TCG_PCR_EVENT *TcgEvent; EFI_PEI_HOB_POINTERS GuidHob; EFI_PHYSICAL_ADDRESS Lasa; if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) { Lasa = mTcgClientAcpiTemplate.Lasa; Status = gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)), &Lasa ); if (EFI_ERROR (Status)) { return Status; } mTcgClientAcpiTemplate.Lasa = Lasa; // // To initialize them as 0xFF is recommended // because the OS can know the last entry for that. // SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF); mTcgClientAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } else { Lasa = mTcgServerAcpiTemplate.Lasa; Status = gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)), &Lasa ); if (EFI_ERROR (Status)) { return Status; } mTcgServerAcpiTemplate.Lasa = Lasa; // // To initialize them as 0xFF is recommended // because the OS can know the last entry for that. // SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF); mTcgServerAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen); } GuidHob.Raw = GetHobList (); while (!EFI_ERROR (Status) && (GuidHob.Raw = GetNextGuidHob (&gTcgEventEntryHobGuid, GuidHob.Raw)) != NULL) { TcgEvent = GET_GUID_HOB_DATA (GuidHob.Guid); GuidHob.Raw = GET_NEXT_HOB (GuidHob); Status = TcgDxeLogEventI ( &mTcgDxeData, (TCG_PCR_EVENT_HDR*)TcgEvent, TcgEvent->Event ); } return Status; }