]>
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 | |
07309c3d | 6 | Copyright (c) 2013 - 2016, 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/HobLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | #include <Library/Tpm2DeviceLib.h>\r | |
23 | \r | |
24 | EFI_GUID mInternalTpm2DeviceInterfaceGuid = {\r | |
859b0db4 | 25 | 0x349cf818, 0xc0ba, 0x4c43, { 0x92, 0x9a, 0xc8, 0xa1, 0xb1, 0xb3, 0xd2, 0x55 }\r |
c1d93242 JY |
26 | };\r |
27 | \r | |
28 | /**\r | |
29 | This function get TPM2.0 interface.\r | |
30 | \r | |
31 | @retval TPM2.0 interface.\r | |
32 | **/\r | |
33 | TPM2_DEVICE_INTERFACE *\r | |
34 | InternalGetTpm2DeviceInterface (\r | |
35 | VOID\r | |
36 | )\r | |
37 | {\r | |
38 | EFI_HOB_GUID_TYPE *Hob;\r | |
39 | \r | |
40 | Hob = GetFirstGuidHob (&mInternalTpm2DeviceInterfaceGuid);\r | |
41 | if (Hob == NULL) {\r | |
42 | return NULL;\r | |
43 | }\r | |
44 | return (TPM2_DEVICE_INTERFACE *)(Hob + 1);\r | |
45 | }\r | |
46 | \r | |
47 | /**\r | |
48 | This service enables the sending of commands to the TPM2.\r | |
49 | \r | |
50 | @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r | |
51 | @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r | |
52 | @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r | |
53 | @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r | |
54 | \r | |
55 | @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r | |
56 | @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.\r | |
57 | @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small. \r | |
58 | **/\r | |
59 | EFI_STATUS\r | |
60 | EFIAPI\r | |
61 | Tpm2SubmitCommand (\r | |
62 | IN UINT32 InputParameterBlockSize,\r | |
63 | IN UINT8 *InputParameterBlock,\r | |
64 | IN OUT UINT32 *OutputParameterBlockSize,\r | |
65 | IN UINT8 *OutputParameterBlock\r | |
66 | )\r | |
67 | {\r | |
68 | TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r | |
69 | \r | |
70 | Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r | |
71 | if (Tpm2DeviceInterface == NULL) {\r | |
72 | return EFI_UNSUPPORTED;\r | |
73 | }\r | |
74 | \r | |
75 | return Tpm2DeviceInterface->Tpm2SubmitCommand (\r | |
76 | InputParameterBlockSize,\r | |
77 | InputParameterBlock,\r | |
78 | OutputParameterBlockSize,\r | |
79 | OutputParameterBlock\r | |
80 | );\r | |
81 | }\r | |
82 | \r | |
83 | /**\r | |
84 | This service requests use TPM2.\r | |
85 | \r | |
86 | @retval EFI_SUCCESS Get the control of TPM2 chip.\r | |
87 | @retval EFI_NOT_FOUND TPM2 not found.\r | |
88 | @retval EFI_DEVICE_ERROR Unexpected device behavior.\r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | Tpm2RequestUseTpm (\r | |
93 | VOID\r | |
94 | )\r | |
95 | {\r | |
96 | TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r | |
97 | \r | |
98 | Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r | |
99 | if (Tpm2DeviceInterface == NULL) {\r | |
100 | return EFI_UNSUPPORTED;\r | |
101 | }\r | |
102 | return Tpm2DeviceInterface->Tpm2RequestUseTpm ();\r | |
103 | }\r | |
104 | \r | |
105 | /**\r | |
106 | This service register TPM2 device.\r | |
107 | \r | |
108 | @param Tpm2Device TPM2 device\r | |
109 | \r | |
110 | @retval EFI_SUCCESS This TPM2 device is registered successfully.\r | |
111 | @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r | |
112 | @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r | |
113 | **/\r | |
114 | EFI_STATUS\r | |
115 | EFIAPI\r | |
116 | Tpm2RegisterTpm2DeviceLib (\r | |
117 | IN TPM2_DEVICE_INTERFACE *Tpm2Device\r | |
118 | )\r | |
119 | {\r | |
120 | TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r | |
121 | \r | |
122 | if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)){\r | |
123 | DEBUG ((EFI_D_ERROR, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));\r | |
124 | return EFI_UNSUPPORTED;\r | |
125 | }\r | |
126 | \r | |
127 | Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r | |
128 | if (Tpm2DeviceInterface != NULL) {\r | |
129 | //\r | |
130 | // In PEI phase, there will be shadow driver dispatched again.\r | |
131 | //\r | |
33985e3b | 132 | DEBUG ((EFI_D_INFO, "Tpm2RegisterTpm2DeviceLib - Override\n"));\r |
c1d93242 JY |
133 | CopyMem (Tpm2DeviceInterface, Tpm2Device, sizeof(*Tpm2Device));\r |
134 | return EFI_SUCCESS;\r | |
135 | } else {\r | |
136 | Tpm2Device = BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid, Tpm2Device, sizeof(*Tpm2Device));\r | |
137 | if (Tpm2Device != NULL) {\r | |
138 | return EFI_SUCCESS;\r | |
139 | } else {\r | |
140 | return EFI_OUT_OF_RESOURCES;\r | |
141 | }\r | |
142 | }\r | |
143 | }\r |