CbSupportDxe.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /** @file
  2. This driver will report some MMIO/IO resources to dxe core, extract smbios and acpi
  3. tables from coreboot and install.
  4. Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "CbSupportDxe.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. CbReserveResourceInGcd (
  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. EFI_D_ERROR,
  39. "Failed to add memory space :0x%lx 0x%lx\n",
  40. BaseAddress,
  41. Length
  42. ));
  43. }
  44. ASSERT_EFI_ERROR (Status);
  45. Status = gDS->AllocateMemorySpace (
  46. EfiGcdAllocateAddress,
  47. GcdType,
  48. Alignment,
  49. Length,
  50. &BaseAddress,
  51. ImageHandle,
  52. NULL
  53. );
  54. ASSERT_EFI_ERROR (Status);
  55. } else {
  56. Status = gDS->AddIoSpace (
  57. GcdType,
  58. BaseAddress,
  59. Length
  60. );
  61. ASSERT_EFI_ERROR (Status);
  62. Status = gDS->AllocateIoSpace (
  63. EfiGcdAllocateAddress,
  64. GcdType,
  65. Alignment,
  66. Length,
  67. &BaseAddress,
  68. ImageHandle,
  69. NULL
  70. );
  71. ASSERT_EFI_ERROR (Status);
  72. }
  73. return Status;
  74. }
  75. /**
  76. Main entry for the Coreboot Support DXE module.
  77. @param[in] ImageHandle The firmware allocated handle for the EFI image.
  78. @param[in] SystemTable A pointer to the EFI System Table.
  79. @retval EFI_SUCCESS The entry point is executed successfully.
  80. @retval other Some error occurs when executing this entry point.
  81. **/
  82. EFI_STATUS
  83. EFIAPI
  84. CbDxeEntryPoint (
  85. IN EFI_HANDLE ImageHandle,
  86. IN EFI_SYSTEM_TABLE *SystemTable
  87. )
  88. {
  89. EFI_STATUS Status;
  90. EFI_HOB_GUID_TYPE *GuidHob;
  91. SYSTEM_TABLE_INFO *pSystemTableInfo;
  92. FRAME_BUFFER_INFO *FbInfo;
  93. Status = EFI_SUCCESS;
  94. //
  95. // Report MMIO/IO Resources
  96. //
  97. Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFEC00000, SIZE_4KB, 0, SystemTable); // IOAPIC
  98. ASSERT_EFI_ERROR (Status);
  99. Status = CbReserveResourceInGcd (TRUE, EfiGcdMemoryTypeMemoryMappedIo, 0xFED00000, SIZE_1KB, 0, SystemTable); // HPET
  100. ASSERT_EFI_ERROR (Status);
  101. //
  102. // Find the system table information guid hob
  103. //
  104. GuidHob = GetFirstGuidHob (&gUefiSystemTableInfoGuid);
  105. ASSERT (GuidHob != NULL);
  106. pSystemTableInfo = (SYSTEM_TABLE_INFO *)GET_GUID_HOB_DATA (GuidHob);
  107. //
  108. // Install Acpi Table
  109. //
  110. if (pSystemTableInfo->AcpiTableBase != 0 && pSystemTableInfo->AcpiTableSize != 0) {
  111. DEBUG ((EFI_D_ERROR, "Install Acpi Table at 0x%lx, length 0x%x\n", pSystemTableInfo->AcpiTableBase, pSystemTableInfo->AcpiTableSize));
  112. Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, (VOID *)(UINTN)pSystemTableInfo->AcpiTableBase);
  113. ASSERT_EFI_ERROR (Status);
  114. }
  115. //
  116. // Install Smbios Table
  117. //
  118. if (pSystemTableInfo->SmbiosTableBase != 0 && pSystemTableInfo->SmbiosTableSize != 0) {
  119. DEBUG ((EFI_D_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", pSystemTableInfo->SmbiosTableBase, pSystemTableInfo->SmbiosTableSize));
  120. Status = gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID *)(UINTN)pSystemTableInfo->SmbiosTableBase);
  121. ASSERT_EFI_ERROR (Status);
  122. }
  123. //
  124. // Find the frame buffer information and update PCDs
  125. //
  126. GuidHob = GetFirstGuidHob (&gUefiFrameBufferInfoGuid);
  127. if (GuidHob != NULL) {
  128. FbInfo = (FRAME_BUFFER_INFO *)GET_GUID_HOB_DATA (GuidHob);
  129. Status = PcdSet32S (PcdVideoHorizontalResolution, FbInfo->HorizontalResolution);
  130. ASSERT_EFI_ERROR (Status);
  131. Status = PcdSet32S (PcdVideoVerticalResolution, FbInfo->VerticalResolution);
  132. ASSERT_EFI_ERROR (Status);
  133. Status = PcdSet32S (PcdSetupVideoHorizontalResolution, FbInfo->HorizontalResolution);
  134. ASSERT_EFI_ERROR (Status);
  135. Status = PcdSet32S (PcdSetupVideoVerticalResolution, FbInfo->VerticalResolution);
  136. ASSERT_EFI_ERROR (Status);
  137. }
  138. return EFI_SUCCESS;
  139. }