]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 #include "Tpm2DeviceLibDTpm.h"
20
21 /**
22 Dump PTP register information.
23
24 @param[in] Register Pointer to PTP register.
25 **/
26 VOID
27 DumpPtpInfo (
28 IN VOID *Register
29 );
30
31 /**
32 This service enables the sending of commands to the TPM2.
33
34 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
35 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
36 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
37 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
38
39 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
40 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
41 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
42 **/
43 EFI_STATUS
44 EFIAPI
45 DTpm2SubmitCommand (
46 IN UINT32 InputParameterBlockSize,
47 IN UINT8 *InputParameterBlock,
48 IN OUT UINT32 *OutputParameterBlockSize,
49 IN UINT8 *OutputParameterBlock
50 );
51
52 /**
53 This service requests use TPM2.
54
55 @retval EFI_SUCCESS Get the control of TPM2 chip.
56 @retval EFI_NOT_FOUND TPM2 not found.
57 @retval EFI_DEVICE_ERROR Unexpected device behavior.
58 **/
59 EFI_STATUS
60 EFIAPI
61 DTpm2RequestUseTpm (
62 VOID
63 );
64
65 TPM2_DEVICE_INTERFACE mDTpm2InternalTpm2Device = {
66 TPM_DEVICE_INTERFACE_TPM20_DTPM,
67 DTpm2SubmitCommand,
68 DTpm2RequestUseTpm,
69 };
70
71 /**
72 The function register DTPM2.0 instance and caches current active TPM interface type.
73
74 @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
75 **/
76 EFI_STATUS
77 EFIAPI
78 Tpm2InstanceLibDTpmConstructor (
79 VOID
80 )
81 {
82 EFI_STATUS Status;
83
84 Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
85 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
86 //
87 // Unsupported means platform policy does not need this instance enabled.
88 //
89 if (Status == EFI_SUCCESS) {
90 Status = InternalTpm2DeviceLibDTpmCommonConstructor ();
91 DumpPtpInfo ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
92 }
93
94 return EFI_SUCCESS;
95 }
96
97 return Status;
98 }