PhysicalPresencePei.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @file
  2. This driver produces PEI_LOCK_PHYSICAL_PRESENCE_PPI to indicate
  3. whether TPM need be locked or not. It can be replaced by a platform
  4. specific driver.
  5. Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <PiPei.h>
  9. #include <Ppi/LockPhysicalPresence.h>
  10. #include <Ppi/ReadOnlyVariable2.h>
  11. #include <Guid/PhysicalPresenceData.h>
  12. #include <Library/PcdLib.h>
  13. #include <Library/PeiServicesLib.h>
  14. /**
  15. This interface returns whether TPM physical presence needs be locked or not.
  16. @param[in] PeiServices The pointer to the PEI Services Table.
  17. @retval TRUE The TPM physical presence should be locked.
  18. @retval FALSE The TPM physical presence cannot be locked.
  19. **/
  20. BOOLEAN
  21. EFIAPI
  22. LockTpmPhysicalPresence (
  23. IN CONST EFI_PEI_SERVICES **PeiServices
  24. );
  25. //
  26. // Global defintions for lock physical presence PPI and its descriptor.
  27. //
  28. PEI_LOCK_PHYSICAL_PRESENCE_PPI mLockPhysicalPresencePpi = {
  29. LockTpmPhysicalPresence
  30. };
  31. EFI_PEI_PPI_DESCRIPTOR mLockPhysicalPresencePpiList = {
  32. EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  33. &gPeiLockPhysicalPresencePpiGuid,
  34. &mLockPhysicalPresencePpi
  35. };
  36. /**
  37. This interface returns whether TPM physical presence needs be locked or not.
  38. @param[in] PeiServices The pointer to the PEI Services Table.
  39. @retval TRUE The TPM physical presence should be locked.
  40. @retval FALSE The TPM physical presence cannot be locked.
  41. **/
  42. BOOLEAN
  43. EFIAPI
  44. LockTpmPhysicalPresence (
  45. IN CONST EFI_PEI_SERVICES **PeiServices
  46. )
  47. {
  48. EFI_STATUS Status;
  49. EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
  50. UINTN DataSize;
  51. EFI_PHYSICAL_PRESENCE TcgPpData;
  52. //
  53. // The CRTM has sensed the physical presence assertion of the user. For example,
  54. // the user has pressed the startup button or inserted a USB dongle. The details
  55. // of the implementation are vendor-specific. Here we read a PCD value to indicate
  56. // whether operator physical presence.
  57. //
  58. if (!PcdGetBool (PcdTpmPhysicalPresence)) {
  59. return TRUE;
  60. }
  61. //
  62. // Check the pending TPM requests. Lock TPM physical presence if there is no TPM
  63. // request.
  64. //
  65. Status = PeiServicesLocatePpi (
  66. &gEfiPeiReadOnlyVariable2PpiGuid,
  67. 0,
  68. NULL,
  69. (VOID **)&Variable
  70. );
  71. if (!EFI_ERROR (Status)) {
  72. DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
  73. Status = Variable->GetVariable (
  74. Variable,
  75. PHYSICAL_PRESENCE_VARIABLE,
  76. &gEfiPhysicalPresenceGuid,
  77. NULL,
  78. &DataSize,
  79. &TcgPpData
  80. );
  81. if (!EFI_ERROR (Status)) {
  82. if (TcgPpData.PPRequest != 0) {
  83. return FALSE;
  84. }
  85. }
  86. }
  87. //
  88. // Lock TPM physical presence by default.
  89. //
  90. return TRUE;
  91. }
  92. /**
  93. Entry point of this module.
  94. It installs lock physical presence PPI.
  95. @param[in] FileHandle Handle of the file being invoked.
  96. @param[in] PeiServices Describes the list of possible PEI Services.
  97. @return Status of install lock physical presence PPI.
  98. **/
  99. EFI_STATUS
  100. EFIAPI
  101. PeimEntry (
  102. IN EFI_PEI_FILE_HANDLE FileHandle,
  103. IN CONST EFI_PEI_SERVICES **PeiServices
  104. )
  105. {
  106. return PeiServicesInstallPpi (&mLockPhysicalPresencePpiList);
  107. }