]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 TPM
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 #include <PiPei.h>
15
16 #include <Guid/TpmInstance.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PeiServicesLib.h>
19 #include <Library/Tpm2DeviceLib.h>
20 #include <Ppi/TpmInitialized.h>
21
22 #include "Tpm12Support.h"
23
24 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {
25 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
26 &gEfiTpmDeviceSelectedGuid,
27 NULL
28 };
29
30 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
31 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
32 &gPeiTpmInitializationDonePpiGuid,
33 NULL
34 };
35
36 /**
37 The entry point for Tcg2 configuration driver.
38
39 @param FileHandle Handle of the file being invoked.
40 @param PeiServices Describes the list of possible PEI Services.
41 **/
42 EFI_STATUS
43 EFIAPI
44 Tcg2ConfigPeimEntryPoint (
45 IN EFI_PEI_FILE_HANDLE FileHandle,
46 IN CONST EFI_PEI_SERVICES **PeiServices
47 )
48 {
49 UINTN Size;
50 EFI_STATUS Status;
51
52 DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));
53
54 Status = InternalTpm12Detect ();
55 if (!EFI_ERROR (Status)) {
56 DEBUG ((DEBUG_INFO, "%a: TPM1.2 detected\n", __FUNCTION__));
57 Size = sizeof (gEfiTpmDeviceInstanceTpm12Guid);
58 Status = PcdSetPtrS (
59 PcdTpmInstanceGuid,
60 &Size,
61 &gEfiTpmDeviceInstanceTpm12Guid
62 );
63 ASSERT_EFI_ERROR (Status);
64 } else {
65 Status = Tpm2RequestUseTpm ();
66 if (!EFI_ERROR (Status)) {
67 DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));
68 Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);
69 Status = PcdSetPtrS (
70 PcdTpmInstanceGuid,
71 &Size,
72 &gEfiTpmDeviceInstanceTpm20DtpmGuid
73 );
74 ASSERT_EFI_ERROR (Status);
75 } else {
76 DEBUG ((DEBUG_INFO, "%a: no TPM detected\n", __FUNCTION__));
77 //
78 // If no TPM2 was detected, we still need to install
79 // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing
80 // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have
81 // to install the PPI in its place, in order to unblock any dependent
82 // PEIMs.
83 //
84 Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
85 ASSERT_EFI_ERROR (Status);
86 }
87 }
88
89 //
90 // Selection done
91 //
92 Status = PeiServicesInstallPpi (&mTpmSelectedPpi);
93 ASSERT_EFI_ERROR (Status);
94
95 return Status;
96 }