]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibTcg2 / Tpm2DeviceLibTcg2.c
1 /** @file
2 This library is TPM2 TCG2 protocol lib.
3
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Library/BaseLib.h>
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/Tpm2DeviceLib.h>
14 #include <Protocol/Tcg2Protocol.h>
15 #include <IndustryStandard/Tpm20.h>
16
17 EFI_TCG2_PROTOCOL *mTcg2Protocol = NULL;
18
19 /**
20 This service enables the sending of commands to the TPM2.
21
22 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
23 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
24 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
25 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
26
27 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
28 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
29 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
30 **/
31 EFI_STATUS
32 EFIAPI
33 Tpm2SubmitCommand (
34 IN UINT32 InputParameterBlockSize,
35 IN UINT8 *InputParameterBlock,
36 IN OUT UINT32 *OutputParameterBlockSize,
37 IN UINT8 *OutputParameterBlock
38 )
39 {
40 EFI_STATUS Status;
41 TPM2_RESPONSE_HEADER *Header;
42
43 if (mTcg2Protocol == NULL) {
44 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **)&mTcg2Protocol);
45 if (EFI_ERROR (Status)) {
46 //
47 // Tcg2 protocol is not installed. So, TPM2 is not present.
48 //
49 DEBUG ((DEBUG_ERROR, "Tpm2SubmitCommand - Tcg2 - %r\n", Status));
50 return EFI_NOT_FOUND;
51 }
52 }
53
54 //
55 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
56 //
57 Status = mTcg2Protocol->SubmitCommand (
58 mTcg2Protocol,
59 InputParameterBlockSize,
60 InputParameterBlock,
61 *OutputParameterBlockSize,
62 OutputParameterBlock
63 );
64 if (EFI_ERROR (Status)) {
65 return Status;
66 }
67
68 Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;
69 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
70
71 return EFI_SUCCESS;
72 }
73
74 /**
75 This service requests use TPM2.
76
77 @retval EFI_SUCCESS Get the control of TPM2 chip.
78 @retval EFI_NOT_FOUND TPM2 not found.
79 @retval EFI_DEVICE_ERROR Unexpected device behavior.
80 **/
81 EFI_STATUS
82 EFIAPI
83 Tpm2RequestUseTpm (
84 VOID
85 )
86 {
87 EFI_STATUS Status;
88
89 if (mTcg2Protocol == NULL) {
90 Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **)&mTcg2Protocol);
91 if (EFI_ERROR (Status)) {
92 //
93 // Tcg2 protocol is not installed. So, TPM2 is not present.
94 //
95 DEBUG ((DEBUG_ERROR, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status));
96 return EFI_NOT_FOUND;
97 }
98 }
99
100 //
101 // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.
102 //
103 return EFI_SUCCESS;
104 }
105
106 /**
107 This service register TPM2 device.
108
109 @param Tpm2Device TPM2 device
110
111 @retval EFI_SUCCESS This TPM2 device is registered successfully.
112 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
113 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
114 **/
115 EFI_STATUS
116 EFIAPI
117 Tpm2RegisterTpm2DeviceLib (
118 IN TPM2_DEVICE_INTERFACE *Tpm2Device
119 )
120 {
121 return EFI_UNSUPPORTED;
122 }