]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Tcg/Tcg2Config/Tpm12Support.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Tcg / Tcg2Config / Tpm12Support.c
CommitLineData
fc72a6ce
LE
1/** @file\r
2 Implement the InternalTpm12Detect() function on top of the Tpm12DeviceLib\r
3 class.\r
4\r
5 Copyright (C) 2020, Red Hat, Inc.\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8**/\r
9\r
10#include <Library/BaseLib.h>\r
11#include <Library/Tpm12DeviceLib.h>\r
12\r
13#include "Tpm12Support.h"\r
14\r
15#pragma pack (1)\r
16typedef struct {\r
ac0a286f
MK
17 TPM_RSP_COMMAND_HDR Hdr;\r
18 TPM_CURRENT_TICKS CurrentTicks;\r
fc72a6ce
LE
19} TPM_RSP_GET_TICKS;\r
20#pragma pack ()\r
21\r
22/**\r
23 Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks\r
24\r
25 Sending a TPM1.2 command to a TPM2 should return a TPM1.2\r
26 header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)\r
27\r
28 @retval EFI_SUCCESS TPM version 1.2 probing successful.\r
29\r
30 @return Error codes propagated from Tpm12SubmitCommand().\r
31**/\r
32STATIC\r
33EFI_STATUS\r
34TestTpm12 (\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 TPM_RQU_COMMAND_HDR Command;\r
39 TPM_RSP_GET_TICKS Response;\r
40 UINT32 Length;\r
41\r
42 Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
43 Command.paramSize = SwapBytes32 (sizeof (Command));\r
44 Command.ordinal = SwapBytes32 (TPM_ORD_GetTicks);\r
45\r
46 Length = sizeof (Response);\r
ac0a286f
MK
47 Status = Tpm12SubmitCommand (\r
48 sizeof (Command),\r
49 (UINT8 *)&Command,\r
50 &Length,\r
51 (UINT8 *)&Response\r
52 );\r
fc72a6ce
LE
53 if (EFI_ERROR (Status)) {\r
54 return Status;\r
55 }\r
56\r
57 return EFI_SUCCESS;\r
58}\r
59\r
60/**\r
61 Detect the presence of a TPM with interface version 1.2.\r
62\r
63 @retval EFI_SUCCESS TPM-1.2 available. The Tpm12RequestUseTpm() and\r
64 Tpm12SubmitCommand(TPM_ORD_GetTicks) operations\r
65 (from the Tpm12DeviceLib class) have succeeded.\r
66\r
67 @return Error codes propagated from Tpm12RequestUseTpm() and\r
68 Tpm12SubmitCommand().\r
69**/\r
70EFI_STATUS\r
71InternalTpm12Detect (\r
72 VOID\r
73 )\r
74{\r
ac0a286f 75 EFI_STATUS Status;\r
fc72a6ce
LE
76\r
77 Status = Tpm12RequestUseTpm ();\r
78 if (EFI_ERROR (Status)) {\r
79 return Status;\r
80 }\r
81\r
82 return TestTpm12 ();\r
83}\r