/** @file
TIS (TPM Interface Specification) functions used by TPM Dxe driver.
Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <IndustryStandard/Tpm12.h>
#include <Library/TimerLib.h>
#include <Library/TpmCommLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
/**
Send command to TPM for execution.
@param[in] TisReg TPM register space base address.
@param[in] TpmBuffer Buffer for TPM command data.
@param[in] DataLength TPM command data length.
@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_TIMEOUT The register can't run into the expected status in time.
**/
)
{
return Status;
}
Index = 0;
while (Index < DataLength) {
return EFI_TIMEOUT;
}
Index++;
}
}
//
// Ensure the Tpm status STS_EXPECT change from 1 to 0
//
);
return Status;
}
/**
Receive response data of last command from TPM.
@param[in] TisReg TPM register space base address.
@param[out] TpmBuffer Buffer for response data.
@param[out] RespSize Response data length.
@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_TIMEOUT The register can't run into the expected status in time.
@retval EFI_DEVICE_ERROR Unexpected device status.
@retval EFI_BUFFER_TOO_SMALL Response data is too long.
**/
)
{
//
// Wait for the command completion
//
0,
);
return EFI_TIMEOUT;
}
//
// Read the response data header and check it
//
Index = 0;
BurstCount = 0;
while (Index < sizeof (TPM_RSP_COMMAND_HDR)) {
return EFI_TIMEOUT;
}
for (; BurstCount > 0 ; BurstCount--) {
Index++;
if (Index == sizeof (TPM_RSP_COMMAND_HDR))
break;
}
}
//
// Check the reponse data header (tag,parasize and returncode )
//
*RespSize = ResponseSize;
if (ResponseSize == sizeof (TPM_RSP_COMMAND_HDR)) {
return EFI_SUCCESS;
}
if (ResponseSize < sizeof (TPM_RSP_COMMAND_HDR)) {
return EFI_DEVICE_ERROR;
}
if (ResponseSize > TPMCMDBUFLENGTH) {
return EFI_BUFFER_TOO_SMALL;
}
//
// Continue reading the remaining data
//
while (Index < ResponseSize) {
for (; BurstCount > 0 ; BurstCount--) {
Index++;
if (Index == ResponseSize) {
return EFI_SUCCESS;
}
}
return EFI_DEVICE_ERROR;
}
}
return EFI_SUCCESS;
}
/**
Format TPM command data according to the format control character.
@param[in] FmtChar Format control character.
@param[in, out] ap List of arguments.
@param[in] TpmBuffer Buffer for TPM command data.
@param[out] DataLength TPM command data length.
@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_INVALID_PARAMETER Invalid format control character.
@retval EFI_BUFFER_TOO_SMALL Buffer too small for command data.
**/
)
{
switch (FmtChar) {
case 'b':
break;
case 'w':
break;
case 'd':
break;
case 'h':
break;
case 'r':
break;
case '\0':
return EFI_INVALID_PARAMETER;
default:
return EFI_INVALID_PARAMETER;
}
return EFI_BUFFER_TOO_SMALL;
}
return EFI_SUCCESS;
}
/**
Format reponse data according to the format control character.
@param[in] FmtChar Format control character.
@param[in, out] ap List of arguments.
@param[out] TpmBuffer Buffer for reponse data.
@param[in, out] DataIndex Data offset in reponse data buffer.
@param[in] RespSize Response data length.
@param[out] DataFinished Reach the end of Response data.
@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_INVALID_PARAMETER Invalid format control character.
@retval EFI_BUFFER_TOO_SMALL Buffer too small for command data.
**/
)
{
switch (FmtChar) {
case 'b':
break;
case 'w':
break;
case 'd':
break;
case 'h':
break;
case 'r':
break;
}
*DataFinished = TRUE;
return EFI_SUCCESS;
}
return EFI_SUCCESS;
case '\0':
return EFI_INVALID_PARAMETER;
default:
return EFI_WARN_UNKNOWN_GLYPH;
}
*DataFinished = TRUE;
return EFI_SUCCESS;
}
return EFI_BUFFER_TOO_SMALL;
switch (FmtChar) {
case 'w':
break;
case 'd':
break;
case 'h':
break;
}
return EFI_SUCCESS;
}
/**
Send formatted command to TPM for execution and return formatted data from response.
@param[in] TisReg TPM Handle.
@param[in] Fmt Format control string.
@param[in] ... The variable argument list.
@retval EFI_SUCCESS Operation completed successfully.
@retval EFI_TIMEOUT The register can't run into the expected status in time.
**/
...
)
{
//
// Put the formatted command to the TpmCommandBuf
//
BufSize = 0;
while (*Fmt != '\0') {
if (*Fmt == '/') break;
goto Error;
}
Fmt++;
}
//
// Send the command to TPM
//
//
//
goto Error;
}
Fmt++;
//
// Receive the response data from TPM
//
//
//
goto Error;
}
//
// Get the formatted data from the TpmCommandBuf.
//
BufSize =0;
while (*Fmt != '\0') {
if (*Fmt == '%') {
Fmt++;
}
goto Error;
}
if (DataFinished) {
return EFI_SUCCESS;
}
Fmt++;
}
return Status;
}