]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.c
de5293ee9eeb908be19fb00ffb637d84513ae2d3
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibRouter / Tpm2DeviceLibRouterDxe.c
1 /** @file
2 This library is TPM2 device router. Platform can register multi TPM2 instance to it
3 via PcdTpmInstanceGuid. Platform need make choice that which one will be final one.
4 At most one TPM2 instance can be finally registered, and other will return unsupported.
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/PcdLib.h>
15 #include <Library/Tpm2DeviceLib.h>
16
17 TPM2_DEVICE_INTERFACE mInternalTpm2DeviceInterface;
18
19 /**
20 This service enables the sending of commands to the TPM2.
21
22 @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
23 @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
24 @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
25 @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
26
27 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
28 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
29 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
30 **/
31 EFI_STATUS
32 EFIAPI
33 Tpm2SubmitCommand (
34 IN UINT32 InputParameterBlockSize,
35 IN UINT8 *InputParameterBlock,
36 IN OUT UINT32 *OutputParameterBlockSize,
37 IN UINT8 *OutputParameterBlock
38 )
39 {
40 if (mInternalTpm2DeviceInterface.Tpm2SubmitCommand == NULL) {
41 return EFI_UNSUPPORTED;
42 }
43
44 return mInternalTpm2DeviceInterface.Tpm2SubmitCommand (
45 InputParameterBlockSize,
46 InputParameterBlock,
47 OutputParameterBlockSize,
48 OutputParameterBlock
49 );
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 Tpm2RequestUseTpm (
62 VOID
63 )
64 {
65 if (mInternalTpm2DeviceInterface.Tpm2RequestUseTpm == NULL) {
66 return EFI_UNSUPPORTED;
67 }
68
69 return mInternalTpm2DeviceInterface.Tpm2RequestUseTpm ();
70 }
71
72 /**
73 This service register TPM2 device.
74
75 @param Tpm2Device TPM2 device
76
77 @retval EFI_SUCCESS This TPM2 device is registered successfully.
78 @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
79 @retval EFI_ALREADY_STARTED System already register this TPM2 device.
80 **/
81 EFI_STATUS
82 EFIAPI
83 Tpm2RegisterTpm2DeviceLib (
84 IN TPM2_DEVICE_INTERFACE *Tpm2Device
85 )
86 {
87 if (!CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &Tpm2Device->ProviderGuid)) {
88 DEBUG ((DEBUG_WARN, "WARNING: Tpm2RegisterTpm2DeviceLib - does not support %g registration\n", &Tpm2Device->ProviderGuid));
89 return EFI_UNSUPPORTED;
90 }
91
92 CopyMem (&mInternalTpm2DeviceInterface, Tpm2Device, sizeof (mInternalTpm2DeviceInterface));
93 return EFI_SUCCESS;
94 }