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