]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
435cbf62985d67e7597e94bc3ec011b1ce08324e
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibDTpm / Tpm2InstanceLibDTpm.c
1 /** @file
2 This library is TPM2 DTPM instance.
3 It can be registered to Tpm2 Device router, to be active TPM2 engine,
4 based on platform setting.
5
6 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/Tpm2DeviceLib.h>
15 #include <Library/PcdLib.h>
16
17 #include <Guid/TpmInstance.h>
18
19 /**
20 Return PTP interface type.
21
22 @param[in] Register Pointer to PTP register.
23
24 @return PTP interface type.
25 **/
26 TPM2_PTP_INTERFACE_TYPE
27 Tpm2GetPtpInterface (
28 IN VOID *Register
29 );
30
31 /**
32 Return PTP CRB interface IdleByPass state.
33
34 @param[in] Register Pointer to PTP register.
35
36 @return PTP CRB interface IdleByPass state.
37 **/
38 UINT8
39 Tpm2GetIdleByPass (
40 IN VOID *Register
41 );
42
43 /**
44 Dump PTP register information.
45
46 @param[in] Register Pointer to PTP register.
47 **/
48 VOID
49 DumpPtpInfo (
50 IN VOID *Register
51 );
52
53 /**
54 This service enables the sending of commands to the TPM2.
55
56 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
57 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
58 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
59 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
60
61 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
62 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
63 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
64 **/
65 EFI_STATUS
66 EFIAPI
67 DTpm2SubmitCommand (
68 IN UINT32 InputParameterBlockSize,
69 IN UINT8 *InputParameterBlock,
70 IN OUT UINT32 *OutputParameterBlockSize,
71 IN UINT8 *OutputParameterBlock
72 );
73
74 /**
75 This service requests use TPM2.
76
77 @retval EFI_SUCCESS Get the control of TPM2 chip.
78 @retval EFI_NOT_FOUND TPM2 not found.
79 @retval EFI_DEVICE_ERROR Unexpected device behavior.
80 **/
81 EFI_STATUS
82 EFIAPI
83 DTpm2RequestUseTpm (
84 VOID
85 );
86
87 TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {
88 TPM_DEVICE_INTERFACE_TPM20_DTPM,
89 DTpm2SubmitCommand,
90 DTpm2RequestUseTpm,
91 };
92
93 /**
94 The function register DTPM2.0 instance and caches current active TPM interface type.
95
96 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system dose not surpport registr DTPM2.0 instance
97 **/
98 EFI_STATUS
99 EFIAPI
100 Tpm2InstanceLibDTpmConstructor (
101 VOID
102 )
103 {
104 EFI_STATUS Status;
105 TPM2_PTP_INTERFACE_TYPE PtpInterface;
106 UINT8 IdleByPass;
107
108 Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
109 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
110 //
111 // Unsupported means platform policy does not need this instance enabled.
112 //
113 if (Status == EFI_SUCCESS) {
114 //
115 // Cache current active TpmInterfaceType only when needed
116 //
117 if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
118 PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
119 PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
120 }
121
122 if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
123 IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
124 PcdSet8S(PcdCRBIdleByPass, IdleByPass);
125 }
126
127 DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
128 }
129 return EFI_SUCCESS;
130 }
131 return Status;
132 }