]>
Commit | Line | Data |
---|---|---|
c1d93242 | 1 | /** @file\r |
07309c3d | 2 | This library is TPM2 device router. Platform can register multi TPM2 instance to it\r |
c1d93242 JY |
3 | via PcdTpmInstanceGuid. Platform need make choice that which one will be final one.\r |
4 | At most one TPM2 instance can be finally registered, and other will return unsupported.\r | |
5 | \r | |
b3548d32 | 6 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r |
c1d93242 JY |
7 | This program and the accompanying materials\r |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Library/BaseLib.h>\r | |
18 | #include <Library/BaseMemoryLib.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/PcdLib.h>\r | |
21 | #include <Library/Tpm2DeviceLib.h>\r | |
22 | \r | |
23 | TPM2_DEVICE_INTERFACE mInternalTpm2DeviceInterface;\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 | |
b3548d32 | 35 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
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 | if (mInternalTpm2DeviceInterface.Tpm2SubmitCommand == NULL) {\r | |
47 | return EFI_UNSUPPORTED;\r | |
48 | }\r | |
49 | return mInternalTpm2DeviceInterface.Tpm2SubmitCommand (\r | |
50 | InputParameterBlockSize,\r | |
51 | InputParameterBlock,\r | |
52 | OutputParameterBlockSize,\r | |
53 | OutputParameterBlock\r | |
54 | );\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | This service requests use TPM2.\r | |
59 | \r | |
60 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
61 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
62 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
63 | **/\r | |
64 | EFI_STATUS\r | |
65 | EFIAPI\r | |
66 | Tpm2RequestUseTpm (\r | |
67 | VOID\r | |
68 | )\r | |
69 | {\r | |
70 | if (mInternalTpm2DeviceInterface.Tpm2RequestUseTpm == NULL) {\r | |
71 | return EFI_UNSUPPORTED;\r | |
72 | }\r | |
73 | return mInternalTpm2DeviceInterface.Tpm2RequestUseTpm ();\r | |
74 | }\r | |
75 | \r | |
76 | /**\r | |
77 | This service register TPM2 device.\r | |
78 | \r | |
79 | @param Tpm2Device TPM2 device\r | |
80 | \r | |
81 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
82 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
83 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
84 | **/\r | |
85 | EFI_STATUS\r | |
86 | EFIAPI\r | |
87 | Tpm2RegisterTpm2DeviceLib (\r | |
88 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
89 | )\r | |
90 | {\r | |
91 | if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)){\r | |
f0f1a3cb | 92 | DEBUG ((DEBUG_WARN, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));\r |
c1d93242 JY |
93 | return EFI_UNSUPPORTED;\r |
94 | }\r | |
95 | \r | |
96 | CopyMem (&mInternalTpm2DeviceInterface, Tpm2Device, sizeof(mInternalTpm2DeviceInterface));\r | |
97 | return EFI_SUCCESS;\r | |
98 | }\r |