TcgConfigDriver.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /** @file
  2. The module entry point for Tcg configuration module.
  3. Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "TcgConfigImpl.h"
  7. #include <Guid/TpmInstance.h>
  8. /**
  9. The entry point for Tcg configuration driver.
  10. @param[in] ImageHandle The image handle of the driver.
  11. @param[in] SystemTable The system table.
  12. @retval EFI_ALREADY_STARTED The driver already exists in system.
  13. @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
  14. @retval EFI_SUCCESS All the related protocols are installed on the driver.
  15. @retval Others Fail to install protocols as indicated.
  16. **/
  17. EFI_STATUS
  18. EFIAPI
  19. TcgConfigDriverEntryPoint (
  20. IN EFI_HANDLE ImageHandle,
  21. IN EFI_SYSTEM_TABLE *SystemTable
  22. )
  23. {
  24. EFI_STATUS Status;
  25. TCG_CONFIG_PRIVATE_DATA *PrivateData;
  26. EFI_TCG_PROTOCOL *TcgProtocol;
  27. if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
  28. DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n"));
  29. return EFI_UNSUPPORTED;
  30. }
  31. Status = Tpm12RequestUseTpm ();
  32. if (EFI_ERROR (Status)) {
  33. DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));
  34. return Status;
  35. }
  36. Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);
  37. if (EFI_ERROR (Status)) {
  38. TcgProtocol = NULL;
  39. }
  40. Status = gBS->OpenProtocol (
  41. ImageHandle,
  42. &gEfiCallerIdGuid,
  43. NULL,
  44. ImageHandle,
  45. ImageHandle,
  46. EFI_OPEN_PROTOCOL_TEST_PROTOCOL
  47. );
  48. if (!EFI_ERROR (Status)) {
  49. return EFI_ALREADY_STARTED;
  50. }
  51. //
  52. // Create a private data structure.
  53. //
  54. PrivateData = AllocateCopyPool (sizeof (TCG_CONFIG_PRIVATE_DATA), &mTcgConfigPrivateDateTemplate);
  55. if (PrivateData == NULL) {
  56. return EFI_OUT_OF_RESOURCES;
  57. }
  58. PrivateData->Configuration = AllocatePool (sizeof (TCG_CONFIGURATION));
  59. if (PrivateData->Configuration == NULL) {
  60. Status = EFI_OUT_OF_RESOURCES;
  61. goto ErrorExit;
  62. }
  63. PrivateData->TcgProtocol = TcgProtocol;
  64. //
  65. // Install TCG configuration form
  66. //
  67. Status = InstallTcgConfigForm (PrivateData);
  68. if (EFI_ERROR (Status)) {
  69. goto ErrorExit;
  70. }
  71. //
  72. // Install private GUID.
  73. //
  74. Status = gBS->InstallMultipleProtocolInterfaces (
  75. &ImageHandle,
  76. &gEfiCallerIdGuid,
  77. PrivateData,
  78. NULL
  79. );
  80. if (EFI_ERROR (Status)) {
  81. goto ErrorExit;
  82. }
  83. return EFI_SUCCESS;
  84. ErrorExit:
  85. if (PrivateData != NULL) {
  86. UninstallTcgConfigForm (PrivateData);
  87. }
  88. return Status;
  89. }
  90. /**
  91. Unload the Tcg configuration form.
  92. @param[in] ImageHandle The driver's image handle.
  93. @retval EFI_SUCCESS The Tcg configuration form is unloaded.
  94. @retval Others Failed to unload the form.
  95. **/
  96. EFI_STATUS
  97. EFIAPI
  98. TcgConfigDriverUnload (
  99. IN EFI_HANDLE ImageHandle
  100. )
  101. {
  102. EFI_STATUS Status;
  103. TCG_CONFIG_PRIVATE_DATA *PrivateData;
  104. Status = gBS->HandleProtocol (
  105. ImageHandle,
  106. &gEfiCallerIdGuid,
  107. (VOID **) &PrivateData
  108. );
  109. if (EFI_ERROR (Status)) {
  110. return Status;
  111. }
  112. ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);
  113. gBS->UninstallMultipleProtocolInterfaces (
  114. ImageHandle,
  115. &gEfiCallerIdGuid,
  116. PrivateData,
  117. NULL
  118. );
  119. UninstallTcgConfigForm (PrivateData);
  120. return EFI_SUCCESS;
  121. }