]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2CommandLib/Tpm2Test.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SecurityPkg / Library / Tpm2CommandLib / Tpm2Test.c
1 /** @file
2 Implement TPM2 Test related command.
3
4 Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <IndustryStandard/UefiTcgPlatform.h>
10 #include <Library/Tpm2CommandLib.h>
11 #include <Library/Tpm2DeviceLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/BaseLib.h>
14 #include <Library/DebugLib.h>
15
16 #pragma pack(1)
17
18 typedef struct {
19 TPM2_COMMAND_HEADER Header;
20 TPMI_YES_NO FullTest;
21 } TPM2_SELF_TEST_COMMAND;
22
23 typedef struct {
24 TPM2_RESPONSE_HEADER Header;
25 } TPM2_SELF_TEST_RESPONSE;
26
27 #pragma pack()
28
29 /**
30 This command causes the TPM to perform a test of its capabilities.
31 If the fullTest is YES, the TPM will test all functions.
32 If fullTest = NO, the TPM will only test those functions that have not previously been tested.
33
34 @param[in] FullTest YES if full test to be performed
35 NO if only test of untested functions required
36
37 @retval EFI_SUCCESS Operation completed successfully.
38 @retval EFI_DEVICE_ERROR Unexpected device behavior.
39 **/
40 EFI_STATUS
41 EFIAPI
42 Tpm2SelfTest (
43 IN TPMI_YES_NO FullTest
44 )
45 {
46 EFI_STATUS Status;
47 TPM2_SELF_TEST_COMMAND Cmd;
48 TPM2_SELF_TEST_RESPONSE Res;
49 UINT32 ResultBufSize;
50
51 Cmd.Header.tag = SwapBytes16 (TPM_ST_NO_SESSIONS);
52 Cmd.Header.paramSize = SwapBytes32 (sizeof (Cmd));
53 Cmd.Header.commandCode = SwapBytes32 (TPM_CC_SelfTest);
54 Cmd.FullTest = FullTest;
55
56 ResultBufSize = sizeof (Res);
57 Status = Tpm2SubmitCommand (sizeof (Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
58
59 return Status;
60 }