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