]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibRouter / Tpm2DeviceLibRouterPei.c
... / ...
CommitLineData
1/** @file\r
2 This library is TPM2 device router. Platform can register multi TPM2 instance to it\r
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
6Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>\r
7SPDX-License-Identifier: BSD-2-Clause-Patent\r
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
18EFI_GUID mInternalTpm2DeviceInterfaceGuid = {\r
19 0x349cf818, 0xc0ba, 0x4c43, { 0x92, 0x9a, 0xc8, 0xa1, 0xb1, 0xb3, 0xd2, 0x55 }\r
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
32 EFI_HOB_GUID_TYPE *Hob;\r
33\r
34 Hob = GetFirstGuidHob (&mInternalTpm2DeviceInterfaceGuid);\r
35 if (Hob == NULL) {\r
36 return NULL;\r
37 }\r
38\r
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
52 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.\r
53**/\r
54EFI_STATUS\r
55EFIAPI\r
56Tpm2SubmitCommand (\r
57 IN UINT32 InputParameterBlockSize,\r
58 IN UINT8 *InputParameterBlock,\r
59 IN OUT UINT32 *OutputParameterBlockSize,\r
60 IN UINT8 *OutputParameterBlock\r
61 )\r
62{\r
63 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
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
91 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
92\r
93 Tpm2DeviceInterface = InternalGetTpm2DeviceInterface ();\r
94 if (Tpm2DeviceInterface == NULL) {\r
95 return EFI_UNSUPPORTED;\r
96 }\r
97\r
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
113 IN TPM2_DEVICE_INTERFACE *Tpm2Device\r
114 )\r
115{\r
116 TPM2_DEVICE_INTERFACE *Tpm2DeviceInterface;\r
117\r
118 if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)) {\r
119 DEBUG ((DEBUG_WARN, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));\r
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
128 DEBUG ((DEBUG_INFO, "Tpm2RegisterTpm2DeviceLib - Override\n"));\r
129 CopyMem (Tpm2DeviceInterface, Tpm2Device, sizeof (*Tpm2Device));\r
130 return EFI_SUCCESS;\r
131 } else {\r
132 Tpm2Device = BuildGuidDataHob (&mInternalTpm2DeviceInterfaceGuid, Tpm2Device, sizeof (*Tpm2Device));\r
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