]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibRouter / Tpm2DeviceLibRouterPei.c
CommitLineData
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 6Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
289b714b 7SPDX-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/HobLib.h>\r
14#include <Library/DebugLib.h>\r
15#include <Library/PcdLib.h>\r
16#include <Library/Tpm2DeviceLib.h>\r
17\r
c411b485 18EFI_GUID mInternalTpm2DeviceInterfaceGuid = {\r
859b0db4 19 0x349cf818, 0xc0ba, 0x4c43, { 0x92, 0x9a, 0xc8, 0xa1, 0xb1, 0xb3, 0xd2, 0x55 }\r
c1d93242
JY
20};\r
21\r
22/**\r
23 This function get TPM2.0 interface.\r
24\r
25 @retval TPM2.0 interface.\r
26**/\r
27TPM2_DEVICE_INTERFACE *\r
28InternalGetTpm2DeviceInterface (\r
29 VOID\r
30 )\r
31{\r
c411b485 32 EFI_HOB_GUID_TYPE *Hob;\r
c1d93242
JY
33\r
34 Hob = GetFirstGuidHob (&mInternalTpm2DeviceInterfaceGuid);\r
35 if (Hob == NULL) {\r
36 return NULL;\r
37 }\r
c411b485 38\r
c1d93242
JY
39 return (TPM2_DEVICE_INTERFACE *)(Hob + 1);\r
40}\r
41\r
42/**\r
43 This service enables the sending of commands to the TPM2.\r
44\r
45 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.\r
46 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.\r
47 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.\r
48 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.\r
49\r
50 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.\r
51 @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 52 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r
c1d93242
JY
53**/\r
54EFI_STATUS\r
55EFIAPI\r
56Tpm2SubmitCommand (\r
c411b485
MK
57 IN UINT32 InputParameterBlockSize,\r
58 IN UINT8 *InputParameterBlock,\r
59 IN OUT UINT32 *OutputParameterBlockSize,\r
60 IN UINT8 *OutputParameterBlock\r
c1d93242
JY
61 )\r
62{\r
c411b485 63 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
c1d93242
JY
64\r
65 Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r
66 if (Tpm2DeviceInterface == NULL) {\r
67 return EFI_UNSUPPORTED;\r
68 }\r
69\r
70 return Tpm2DeviceInterface->Tpm2SubmitCommand (\r
71 InputParameterBlockSize,\r
72 InputParameterBlock,\r
73 OutputParameterBlockSize,\r
74 OutputParameterBlock\r
75 );\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
85EFI_STATUS\r
86EFIAPI\r
87Tpm2RequestUseTpm (\r
88 VOID\r
89 )\r
90{\r
c411b485 91 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
c1d93242
JY
92\r
93 Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r
94 if (Tpm2DeviceInterface == NULL) {\r
95 return EFI_UNSUPPORTED;\r
96 }\r
c411b485 97\r
c1d93242
JY
98 return Tpm2DeviceInterface->Tpm2RequestUseTpm ();\r
99}\r
100\r
101/**\r
102 This service register TPM2 device.\r
103\r
104 @param Tpm2Device TPM2 device\r
105\r
106 @retval EFI_SUCCESS This TPM2 device is registered successfully.\r
107 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.\r
108 @retval EFI_ALREADY_STARTED System already register this TPM2 device.\r
109**/\r
110EFI_STATUS\r
111EFIAPI\r
112Tpm2RegisterTpm2DeviceLib (\r
c411b485 113 IN TPM2_DEVICE_INTERFACE *Tpm2Device\r
c1d93242
JY
114 )\r
115{\r
c411b485 116 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
c1d93242 117\r
c411b485 118 if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)) {\r
f0f1a3cb 119 DEBUG ((DEBUG_WARN, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));\r
c1d93242
JY
120 return EFI_UNSUPPORTED;\r
121 }\r
122\r
123 Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r
124 if (Tpm2DeviceInterface != NULL) {\r
125 //\r
126 // In PEI phase, there will be shadow driver dispatched again.\r
127 //\r
e905fbb0 128 DEBUG ((DEBUG_INFO, "Tpm2RegisterTpm2DeviceLib - Override\n"));\r
c411b485 129 CopyMem (Tpm2DeviceInterface, Tpm2Device, sizeof (*Tpm2Device));\r
c1d93242
JY
130 return EFI_SUCCESS;\r
131 } else {\r
c411b485 132 Tpm2Device = BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid, Tpm2Device, sizeof (*Tpm2Device));\r
c1d93242
JY
133 if (Tpm2Device != NULL) {\r
134 return EFI_SUCCESS;\r
135 } else {\r
136 return EFI_OUT_OF_RESOURCES;\r
137 }\r
138 }\r
139}\r