]>
Commit | Line | Data |
---|---|---|
c1d93242 JY |
1 | /** @file\r |
2 | Ihis library is TPM2 TREE protocol lib.\r | |
3 | \r | |
4 | Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. 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 | #include <Library/BaseLib.h>\r | |
16 | #include <Library/BaseMemoryLib.h>\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | #include <Library/Tpm2DeviceLib.h>\r | |
20 | #include <Protocol/TrEEProtocol.h>\r | |
21 | #include <IndustryStandard/Tpm20.h>\r | |
22 | \r | |
23 | EFI_TREE_PROTOCOL *mTreeProtocol = NULL; \r | |
24 | \r | |
25 | /**\r | |
26 | This service enables the sending of commands to the TPM2.\r | |
27 | \r | |
28 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
29 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
30 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
31 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
32 | \r | |
33 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
34 | @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.\r | |
35 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small. \r | |
36 | **/\r | |
37 | EFI_STATUS\r | |
38 | EFIAPI\r | |
39 | Tpm2SubmitCommand (\r | |
40 | IN UINT32 InputParameterBlockSize,\r | |
41 | IN UINT8 *InputParameterBlock,\r | |
42 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
43 | IN UINT8 *OutputParameterBlock\r | |
44 | )\r | |
45 | {\r | |
46 | EFI_STATUS Status;\r | |
47 | TPM2_RESPONSE_HEADER *Header;\r | |
48 | \r | |
49 | if (mTreeProtocol == NULL) {\r | |
50 | Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);\r | |
51 | if (EFI_ERROR (Status)) {\r | |
52 | //\r | |
53 | // TrEE protocol is not installed. So, TPM2 is not present.\r | |
54 | //\r | |
55 | DEBUG ((EFI_D_ERROR, "Tpm2SubmitCommand - TrEE - %r\n", Status));\r | |
56 | return EFI_NOT_FOUND;\r | |
57 | }\r | |
58 | }\r | |
59 | //\r | |
60 | // Assume when TrEE Protocol is ready, RequestUseTpm already done.\r | |
61 | //\r | |
62 | Status = mTreeProtocol->SubmitCommand (\r | |
63 | mTreeProtocol,\r | |
64 | InputParameterBlockSize,\r | |
65 | InputParameterBlock,\r | |
66 | *OutputParameterBlockSize,\r | |
67 | OutputParameterBlock\r | |
68 | );\r | |
69 | if (EFI_ERROR (Status)) {\r | |
70 | return Status;\r | |
71 | }\r | |
72 | Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;\r | |
73 | *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);\r | |
74 | \r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r | |
77 | \r | |
78 | /**\r | |
79 | This service requests use TPM2.\r | |
80 | \r | |
81 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
82 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
83 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
84 | **/\r | |
85 | EFI_STATUS\r | |
86 | EFIAPI\r | |
87 | Tpm2RequestUseTpm (\r | |
88 | VOID\r | |
89 | )\r | |
90 | {\r | |
91 | EFI_STATUS Status;\r | |
92 | \r | |
93 | if (mTreeProtocol == NULL) {\r | |
94 | Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);\r | |
95 | if (EFI_ERROR (Status)) {\r | |
96 | //\r | |
97 | // TrEE protocol is not installed. So, TPM2 is not present.\r | |
98 | //\r | |
99 | DEBUG ((EFI_D_ERROR, "Tpm2RequestUseTpm - TrEE - %r\n", Status));\r | |
100 | return EFI_NOT_FOUND;\r | |
101 | }\r | |
102 | }\r | |
103 | //\r | |
104 | // Assume when TrEE Protocol is ready, RequestUseTpm already done.\r | |
105 | //\r | |
106 | return EFI_SUCCESS;\r | |
107 | }\r | |
108 | \r | |
109 | /**\r | |
110 | This service register TPM2 device.\r | |
111 | \r | |
112 | @param Tpm2Device TPM2 device\r | |
113 | \r | |
114 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
115 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
116 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
117 | **/\r | |
118 | EFI_STATUS\r | |
119 | EFIAPI\r | |
120 | Tpm2RegisterTpm2DeviceLib (\r | |
121 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
122 | )\r | |
123 | {\r | |
124 | return EFI_UNSUPPORTED;\r | |
125 | }\r |