]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
99d571d9fa6d170032a59be10cbfdeaf75757904
[mirror_edk2.git] / OvmfPkg / Tcg / Tcg2Config / Tcg2ConfigPeim.c
1 /** @file
2 Set TPM device type
3
4 In SecurityPkg, this module initializes the TPM device type based on a UEFI
5 variable and/or hardware detection. In OvmfPkg, the module only performs TPM2
6 hardware detection.
7
8 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
9 Copyright (C) 2018, Red Hat, Inc.
10
11 SPDX-License-Identifier: BSD-2-Clause-Patent
12 **/
13
14
15 #include <PiPei.h>
16
17 #include <Guid/TpmInstance.h>
18 #include <Library/DebugLib.h>
19 #include <Library/PeiServicesLib.h>
20 #include <Library/Tpm2DeviceLib.h>
21 #include <Ppi/TpmInitialized.h>
22
23 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {
24 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
25 &gEfiTpmDeviceSelectedGuid,
26 NULL
27 };
28
29 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
30 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
31 &gPeiTpmInitializationDonePpiGuid,
32 NULL
33 };
34
35 /**
36 The entry point for Tcg2 configuration driver.
37
38 @param FileHandle Handle of the file being invoked.
39 @param PeiServices Describes the list of possible PEI Services.
40 **/
41 EFI_STATUS
42 EFIAPI
43 Tcg2ConfigPeimEntryPoint (
44 IN EFI_PEI_FILE_HANDLE FileHandle,
45 IN CONST EFI_PEI_SERVICES **PeiServices
46 )
47 {
48 UINTN Size;
49 EFI_STATUS Status;
50
51 DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));
52
53 Status = Tpm2RequestUseTpm ();
54 if (!EFI_ERROR (Status)) {
55 DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));
56 Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);
57 Status = PcdSetPtrS (
58 PcdTpmInstanceGuid,
59 &Size,
60 &gEfiTpmDeviceInstanceTpm20DtpmGuid
61 );
62 ASSERT_EFI_ERROR (Status);
63 } else {
64 DEBUG ((DEBUG_INFO, "%a: no TPM2 detected\n", __FUNCTION__));
65 //
66 // If no TPM2 was detected, we still need to install
67 // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing
68 // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have
69 // to install the PPI in its place, in order to unblock any dependent
70 // PEIMs.
71 //
72 Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
73 ASSERT_EFI_ERROR (Status);
74 }
75
76 //
77 // Selection done
78 //
79 Status = PeiServicesInstallPpi (&mTpmSelectedPpi);
80 ASSERT_EFI_ERROR (Status);
81
82 return Status;
83 }