BlSupportDxe.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** @file
  2. This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi
  3. tables from bootloader.
  4. Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "BlSupportDxe.h"
  8. /**
  9. Reserve MMIO/IO resource in GCD
  10. @param IsMMIO Flag of whether it is mmio resource or io resource.
  11. @param GcdType Type of the space.
  12. @param BaseAddress Base address of the space.
  13. @param Length Length of the space.
  14. @param Alignment Align with 2^Alignment
  15. @param ImageHandle Handle for the image of this driver.
  16. @retval EFI_SUCCESS Reserve successful
  17. **/
  18. EFI_STATUS
  19. ReserveResourceInGcd (
  20. IN BOOLEAN IsMMIO,
  21. IN UINTN GcdType,
  22. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  23. IN UINT64 Length,
  24. IN UINTN Alignment,
  25. IN EFI_HANDLE ImageHandle
  26. )
  27. {
  28. EFI_STATUS Status;
  29. if (IsMMIO) {
  30. Status = gDS->AddMemorySpace (
  31. GcdType,
  32. BaseAddress,
  33. Length,
  34. EFI_MEMORY_UC
  35. );
  36. if (EFI_ERROR (Status)) {
  37. DEBUG ((
  38. DEBUG_WARN,
  39. "Failed to add memory space :0x%lx 0x%lx\n",
  40. BaseAddress,
  41. Length
  42. ));
  43. }
  44. Status = gDS->AllocateMemorySpace (
  45. EfiGcdAllocateAddress,
  46. GcdType,
  47. Alignment,
  48. Length,
  49. &BaseAddress,
  50. ImageHandle,
  51. NULL
  52. );
  53. } else {
  54. Status = gDS->AddIoSpace (
  55. GcdType,
  56. BaseAddress,
  57. Length
  58. );
  59. if (EFI_ERROR (Status)) {
  60. DEBUG ((
  61. DEBUG_WARN,
  62. "Failed to add IO space :0x%lx 0x%lx\n",
  63. BaseAddress,
  64. Length
  65. ));
  66. }
  67. Status = gDS->AllocateIoSpace (
  68. EfiGcdAllocateAddress,
  69. GcdType,
  70. Alignment,
  71. Length,
  72. &BaseAddress,
  73. ImageHandle,
  74. NULL
  75. );
  76. }
  77. return Status;
  78. }
  79. /**
  80. Main entry for the bootloader support DXE module.
  81. @param[in] ImageHandle The firmware allocated handle for the EFI image.
  82. @param[in] SystemTable A pointer to the EFI System Table.
  83. @retval EFI_SUCCESS The entry point is executed successfully.
  84. @retval other Some error occurs when executing this entry point.
  85. **/
  86. EFI_STATUS
  87. EFIAPI
  88. BlDxeEntryPoint (
  89. IN EFI_HANDLE ImageHandle,
  90. IN EFI_SYSTEM_TABLE *SystemTable
  91. )
  92. {
  93. EFI_STATUS Status;
  94. EFI_HOB_GUID_TYPE *GuidHob;
  95. EFI_PEI_GRAPHICS_INFO_HOB *GfxInfo;
  96. ACPI_BOARD_INFO *AcpiBoardInfo;
  97. Status = EFI_SUCCESS;
  98. //
  99. // Report MMIO/IO Resources
  100. //
  101. ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, ImageHandle); // IOAPIC
  102. ReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, ImageHandle); // HPET
  103. //
  104. // Find the frame buffer information and update PCDs
  105. //
  106. GuidHob = GetFirstGuidHob (&gEfiGraphicsInfoHobGuid);
  107. if (GuidHob != NULL) {
  108. GfxInfo = (EFI_PEI_GRAPHICS_INFO_HOB *)GET_GUID_HOB_DATA (GuidHob);
  109. Status = PcdSet32S (PcdVideoHorizontalResolution, GfxInfo->GraphicsMode.HorizontalResolution);
  110. ASSERT_EFI_ERROR (Status);
  111. Status = PcdSet32S (PcdVideoVerticalResolution, GfxInfo->GraphicsMode.VerticalResolution);
  112. ASSERT_EFI_ERROR (Status);
  113. Status = PcdSet32S (PcdSetupVideoHorizontalResolution, GfxInfo->GraphicsMode.HorizontalResolution);
  114. ASSERT_EFI_ERROR (Status);
  115. Status = PcdSet32S (PcdSetupVideoVerticalResolution, GfxInfo->GraphicsMode.VerticalResolution);
  116. ASSERT_EFI_ERROR (Status);
  117. }
  118. //
  119. // Set PcdPciExpressBaseAddress and PcdPciExpressBaseSize by HOB info
  120. //
  121. GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
  122. if (GuidHob != NULL) {
  123. AcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
  124. Status = PcdSet64S (PcdPciExpressBaseAddress, AcpiBoardInfo->PcieBaseAddress);
  125. ASSERT_EFI_ERROR (Status);
  126. Status = PcdSet64S (PcdPciExpressBaseSize, AcpiBoardInfo->PcieBaseSize);
  127. ASSERT_EFI_ERROR (Status);
  128. }
  129. return EFI_SUCCESS;
  130. }