AcpiPlatformUtils.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /** @file
  2. ACPI Platform Utilities
  3. @copyright
  4. Copyright 2017 - 2018 Intel Corporation. <BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "AcpiPlatformUtils.h"
  8. #include <IndustryStandard/Acpi.h>
  9. #include <Protocol/AcpiSystemDescriptionTable.h>
  10. #include <Protocol/FirmwareVolume2.h>
  11. #include <Library/BaseLib.h>
  12. #include <Library/UefiBootServicesTableLib.h>
  13. #include <Library/UefiRuntimeServicesTableLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/MemoryAllocationLib.h>
  16. #include <Library/BaseMemoryLib.h>
  17. #include <Library/HobLib.h>
  18. #include <Library/UefiLib.h>
  19. #include <Acpi/Mcfg.h>
  20. #include <Acpi/Hpet.h>
  21. #include <Acpi/Srat.h>
  22. #include <Acpi/Slit.h>
  23. #include <Acpi/Migt.h>
  24. #include <Acpi/Msct.h>
  25. #include <Acpi/Bdat.h>
  26. /**
  27. Locate the first instance of a protocol. If the protocol requested is an
  28. FV protocol, then it will return the first FV that contains the ACPI table
  29. storage file.
  30. @param[in] Protocol - The protocol to find.
  31. @param[in] EfiAcpiStorageGuid - EFI ACPI tables storage guid
  32. @param[out] Instance - Return pointer to the first instance of the protocol.
  33. @param[in] Type - The type of protocol to locate.
  34. @retval EFI_SUCCESS - The function completed successfully.
  35. @retval EFI_NOT_FOUND - The protocol could not be located.
  36. @retval EFI_OUT_OF_RESOURCES - There are not enough resources to find the protocol.
  37. **/
  38. EFI_STATUS
  39. LocateSupportProtocol (
  40. IN EFI_GUID *Protocol,
  41. IN EFI_GUID EfiAcpiStorageGuid,
  42. OUT VOID **Instance,
  43. IN UINT32 Type
  44. )
  45. {
  46. EFI_STATUS Status;
  47. EFI_HANDLE *HandleBuffer;
  48. UINTN NumberOfHandles;
  49. EFI_FV_FILETYPE FileType;
  50. UINT32 FvStatus;
  51. EFI_FV_FILE_ATTRIBUTES Attributes;
  52. UINTN Size;
  53. UINTN Index;
  54. FvStatus = 0;
  55. //
  56. // Locate protocol.
  57. //
  58. Status = gBS->LocateHandleBuffer (
  59. ByProtocol,
  60. Protocol,
  61. NULL,
  62. &NumberOfHandles,
  63. &HandleBuffer
  64. );
  65. if (EFI_ERROR (Status)) {
  66. //
  67. // Defined errors at this time are not found and out of resources.
  68. //
  69. return Status;
  70. }
  71. //
  72. // Looking for FV with ACPI storage file
  73. //
  74. for (Index = 0; Index < NumberOfHandles; Index++) {
  75. //
  76. // Get the protocol on this handle
  77. // This should not fail because of LocateHandleBuffer
  78. //
  79. Status = gBS->HandleProtocol (
  80. HandleBuffer[Index],
  81. Protocol,
  82. Instance
  83. );
  84. ASSERT (!EFI_ERROR (Status));
  85. if (!Type) {
  86. //
  87. // Not looking for the FV protocol, so find the first instance of the
  88. // protocol. There should not be any errors because our handle buffer
  89. // should always contain at least one or LocateHandleBuffer would have
  90. // returned not found.
  91. //
  92. break;
  93. }
  94. //
  95. // See if it has the ACPI storage file
  96. //
  97. Status = ((EFI_FIRMWARE_VOLUME2_PROTOCOL *) (*Instance))->ReadFile (
  98. *Instance,
  99. &EfiAcpiStorageGuid,
  100. NULL,
  101. &Size,
  102. &FileType,
  103. &Attributes,
  104. &FvStatus
  105. );
  106. //
  107. // If we found it, then we are done
  108. //
  109. if (!EFI_ERROR (Status)) {
  110. break;
  111. }
  112. }
  113. //
  114. // Our exit status is determined by the success of the previous operations
  115. // If the protocol was found, Instance already points to it.
  116. //
  117. //
  118. // Free any allocated buffers
  119. //
  120. gBS->FreePool (HandleBuffer);
  121. return Status;
  122. }