1 /*++
2
3 Copyright (c) 1999 - 2015, Intel Corporation. All rights reserved
4
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 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
16 #include <Uefi.h>
17 #include <PiPei.h>
18 #include <Ppi/PttPassThruPpi.h>
19 #include <Library/BaseLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
25
26
27
28
29
30
31 PTT_PASS_THRU_PPI *SecPttPassThruPpi = NULL;
32
33 /**
34 The constructor function caches the pointer to PEI services.
35
36 The constructor function caches the pointer to PEI services.
37 It will always return EFI_SUCCESS.
38
39 @param FfsHeader Pointer to FFS header the loaded driver.
40 @param PeiServices Pointer to the PEI services.
41
42 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
43
44 **/
45 EFI_STATUS
46 EFIAPI
Tpm2DeviceLibConstructor(VOID)47 Tpm2DeviceLibConstructor (
48 VOID
49 )
50 {
51 EFI_STATUS Status = EFI_SUCCESS;
52
53 Status = PeiServicesLocatePpi (&gPttPassThruPpiGuid, 0, NULL, (VOID **) &SecPttPassThruPpi);
54 if (EFI_ERROR (Status)) {
55 // Locate the PPI failed
56 SecPttPassThruPpi = NULL;
57 }
58 return Status;
59 }
60
61 /**
62 This service enables the sending of commands to the TPM2.
63
64 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
65 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
66 @param[in] OutputParameterBlockSize Size of the TPM2 output parameter block.
67 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
68
69 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
70 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
71 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
72 **/
73 EFI_STATUS
74 EFIAPI
Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize,IN UINT8 * InputParameterBlock,IN OUT UINT32 * OutputParameterBlockSize,IN UINT8 * OutputParameterBlock)75 Tpm2SubmitCommand (
76 IN UINT32 InputParameterBlockSize,
77 IN UINT8 *InputParameterBlock,
78 IN OUT UINT32 *OutputParameterBlockSize,
79 IN UINT8 *OutputParameterBlock
80 )
81 {
82 EFI_STATUS Status = EFI_SUCCESS;
83
84 if(NULL == InputParameterBlock || NULL == OutputParameterBlock || 0 == InputParameterBlockSize) {
85 DEBUG ((EFI_D_ERROR, "Buffer == NULL or InputParameterBlockSize == 0\n"));
86 Status = EFI_INVALID_PARAMETER;
87 return Status;
88 }
89
90 if (NULL == SecPttPassThruPpi) {
91 // Don't locate PPI by calling Tpm2DeviceLibConstructor() function??
92 Status = EFI_DEVICE_ERROR;
93 return Status;
94 }
95
96 Status = SecPttPassThruPpi->Tpm2SubmitCommand (
97 SecPttPassThruPpi,
98 InputParameterBlockSize,
99 InputParameterBlock,
100 OutputParameterBlockSize,
101 OutputParameterBlock
102 );
103
104 return Status;
105 }
106
107 /**
108 This service requests use TPM2.
109
110 @retval EFI_SUCCESS Get the control of TPM2 chip.
111 @retval EFI_NOT_FOUND TPM2 not found.
112 @retval EFI_DEVICE_ERROR Unexpected device behavior.
113 **/
114 EFI_STATUS
115 EFIAPI
Tpm2RequestUseTpm(VOID)116 Tpm2RequestUseTpm (
117 VOID
118 )
119 {
120 EFI_STATUS Status = EFI_SUCCESS;
121
122 if (NULL == SecPttPassThruPpi) {
123 // Don't locate PPI by calling Tpm2DeviceLibConstructor() function??
124 Status = EFI_DEVICE_ERROR;
125 return Status;
126 }
127
128 Status = SecPttPassThruPpi->Tpm2RequestUseTpm (SecPttPassThruPpi);
129
130 return Status;
131 }
132
133 /**
134 This service register TPM2 device.
135
136 @Param Tpm2Device TPM2 device
137
138 @retval EFI_SUCCESS This TPM2 device is registered successfully.
139 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
140 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
141 **/
142 EFI_STATUS
143 EFIAPI
Tpm2RegisterTpm2DeviceLib(IN PTT_TPM2_DEVICE_INTERFACE * Tpm2Device)144 Tpm2RegisterTpm2DeviceLib (
145 IN PTT_TPM2_DEVICE_INTERFACE *Tpm2Device
146 )
147 {
148 return EFI_UNSUPPORTED;
149 }
150
151
152