]>
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 |
289b714b | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
c1d93242 JY |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/BaseMemoryLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/PcdLib.h>\r | |
15 | #include <Library/Tpm2DeviceLib.h>\r | |
16 | \r | |
17 | TPM2_DEVICE_INTERFACE mInternalTpm2DeviceInterface;\r | |
18 | \r | |
19 | /**\r | |
20 | This service enables the sending of commands to the TPM2.\r | |
21 | \r | |
22 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
23 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
24 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
25 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
26 | \r | |
27 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
28 | @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 | 29 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r |
c1d93242 JY |
30 | **/\r |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | Tpm2SubmitCommand (\r | |
34 | IN UINT32 InputParameterBlockSize,\r | |
35 | IN UINT8 *InputParameterBlock,\r | |
36 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
37 | IN UINT8 *OutputParameterBlock\r | |
38 | )\r | |
39 | {\r | |
40 | if (mInternalTpm2DeviceInterface.Tpm2SubmitCommand == NULL) {\r | |
41 | return EFI_UNSUPPORTED;\r | |
42 | }\r | |
43 | return mInternalTpm2DeviceInterface.Tpm2SubmitCommand (\r | |
44 | InputParameterBlockSize,\r | |
45 | InputParameterBlock,\r | |
46 | OutputParameterBlockSize,\r | |
47 | OutputParameterBlock\r | |
48 | );\r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
52 | This service requests use TPM2.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
55 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
56 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
57 | **/\r | |
58 | EFI_STATUS\r | |
59 | EFIAPI\r | |
60 | Tpm2RequestUseTpm (\r | |
61 | VOID\r | |
62 | )\r | |
63 | {\r | |
64 | if (mInternalTpm2DeviceInterface.Tpm2RequestUseTpm == NULL) {\r | |
65 | return EFI_UNSUPPORTED;\r | |
66 | }\r | |
67 | return mInternalTpm2DeviceInterface.Tpm2RequestUseTpm ();\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
71 | This service register TPM2 device.\r | |
72 | \r | |
73 | @param Tpm2Device TPM2 device\r | |
74 | \r | |
75 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
76 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
77 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
78 | **/\r | |
79 | EFI_STATUS\r | |
80 | EFIAPI\r | |
81 | Tpm2RegisterTpm2DeviceLib (\r | |
82 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
83 | )\r | |
84 | {\r | |
85 | if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)){\r | |
f0f1a3cb | 86 | DEBUG ((DEBUG_WARN, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));\r |
c1d93242 JY |
87 | return EFI_UNSUPPORTED;\r |
88 | }\r | |
89 | \r | |
90 | CopyMem (&mInternalTpm2DeviceInterface, Tpm2Device, sizeof(mInternalTpm2DeviceInterface));\r | |
91 | return EFI_SUCCESS;\r | |
92 | }\r |