]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.c
6b793bf6be75298a771f6b8bc8d4ea3fcd3bd6d0
[mirror_edk2.git] / SecurityPkg / Library / Tpm12DeviceLibTcg / Tpm12DeviceLibTcg.c
1 /** @file
2 Ihis library is TPM12 TCG protocol lib.
3
4 Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Uefi.h>
16 #include <Library/BaseLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/Tpm12DeviceLib.h>
21 #include <Protocol/TcgService.h>
22 #include <IndustryStandard/Tpm12.h>
23
24 EFI_TCG_PROTOCOL *mTcgProtocol = NULL;
25
26 /**
27 This service enables the sending of commands to the TPM12.
28
29 @param[in] InputParameterBlockSize Size of the TPM12 input parameter block.
30 @param[in] InputParameterBlock Pointer to the TPM12 input parameter block.
31 @param[in,out] OutputParameterBlockSize Size of the TPM12 output parameter block.
32 @param[in] OutputParameterBlock Pointer to the TPM12 output parameter block.
33
34 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
35 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
36 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
37 **/
38 EFI_STATUS
39 EFIAPI
40 Tpm12SubmitCommand (
41 IN UINT32 InputParameterBlockSize,
42 IN UINT8 *InputParameterBlock,
43 IN OUT UINT32 *OutputParameterBlockSize,
44 IN UINT8 *OutputParameterBlock
45 )
46 {
47 EFI_STATUS Status;
48 TPM_RSP_COMMAND_HDR *Header;
49
50 if (mTcgProtocol == NULL) {
51 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);
52 if (EFI_ERROR (Status)) {
53 //
54 // TCG protocol is not installed. So, TPM12 is not present.
55 //
56 DEBUG ((EFI_D_ERROR, "Tpm12SubmitCommand - TCG - %r\n", Status));
57 return EFI_NOT_FOUND;
58 }
59 }
60 //
61 // Assume when TCG Protocol is ready, RequestUseTpm already done.
62 //
63 Status = mTcgProtocol->PassThroughToTpm (
64 mTcgProtocol,
65 InputParameterBlockSize,
66 InputParameterBlock,
67 *OutputParameterBlockSize,
68 OutputParameterBlock
69 );
70 if (EFI_ERROR (Status)) {
71 return Status;
72 }
73 Header = (TPM_RSP_COMMAND_HDR *)OutputParameterBlock;
74 *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
75
76 return EFI_SUCCESS;
77 }
78
79 /**
80 This service requests use TPM12.
81
82 @retval EFI_SUCCESS Get the control of TPM12 chip.
83 @retval EFI_NOT_FOUND TPM12 not found.
84 @retval EFI_DEVICE_ERROR Unexpected device behavior.
85 **/
86 EFI_STATUS
87 EFIAPI
88 Tpm12RequestUseTpm (
89 VOID
90 )
91 {
92 EFI_STATUS Status;
93
94 if (mTcgProtocol == NULL) {
95 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &mTcgProtocol);
96 if (EFI_ERROR (Status)) {
97 //
98 // TCG protocol is not installed. So, TPM12 is not present.
99 //
100 DEBUG ((EFI_D_ERROR, "Tpm12RequestUseTpm - TCG - %r\n", Status));
101 return EFI_NOT_FOUND;
102 }
103 }
104 //
105 // Assume when TCG Protocol is ready, RequestUseTpm already done.
106 //
107 return EFI_SUCCESS;
108 }