]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPeim.c
OvmfPkg/Tcg2ConfigPei: trivial coding style updates
[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 This program and the accompanying materials are licensed and made available
12 under the terms and conditions of the BSD License which accompanies this
13 distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
15
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
17 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 **/
19
20
21 #include <PiPei.h>
22
23 #include <Guid/TpmInstance.h>
24 #include <Library/DebugLib.h>
25 #include <Library/PeiServicesLib.h>
26 #include <Library/Tpm2DeviceLib.h>
27 #include <Ppi/TpmInitialized.h>
28
29 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {
30 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
31 &gEfiTpmDeviceSelectedGuid,
32 NULL
33 };
34
35 STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
36 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
37 &gPeiTpmInitializationDonePpiGuid,
38 NULL
39 };
40
41 /**
42 The entry point for Tcg2 configuration driver.
43
44 @param FileHandle Handle of the file being invoked.
45 @param PeiServices Describes the list of possible PEI Services.
46 **/
47 EFI_STATUS
48 EFIAPI
49 Tcg2ConfigPeimEntryPoint (
50 IN EFI_PEI_FILE_HANDLE FileHandle,
51 IN CONST EFI_PEI_SERVICES **PeiServices
52 )
53 {
54 UINTN Size;
55 EFI_STATUS Status;
56
57 DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));
58
59 Status = Tpm2RequestUseTpm ();
60 if (!EFI_ERROR (Status)) {
61 DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));
62 Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);
63 Status = PcdSetPtrS (
64 PcdTpmInstanceGuid,
65 &Size,
66 &gEfiTpmDeviceInstanceTpm20DtpmGuid
67 );
68 ASSERT_EFI_ERROR (Status);
69 } else {
70 DEBUG ((DEBUG_INFO, "%a: no TPM2 detected\n", __FUNCTION__));
71 //
72 // If no TPM2 was detected, we still need to install
73 // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing
74 // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have
75 // to install the PPI in its place, in order to unblock any dependent
76 // PEIMs.
77 //
78 Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
79 ASSERT_EFI_ERROR (Status);
80 }
81
82 //
83 // Selection done
84 //
85 Status = PeiServicesInstallPpi (&mTpmSelectedPpi);
86 ASSERT_EFI_ERROR (Status);
87
88 return Status;
89 }