FirmwareVolumePei.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*++ @file
  2. Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
  3. Portions copyright (c) 2011, Apple Inc. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "PiPei.h"
  7. #include <Ppi/EmuThunk.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/PeimEntryPoint.h>
  10. #include <Library/HobLib.h>
  11. #include <Library/PeiServicesLib.h>
  12. #include <Library/PeiServicesTablePointerLib.h>
  13. #include <Library/PcdLib.h>
  14. EFI_STATUS
  15. EFIAPI
  16. PeimInitializeFirmwareVolumePei (
  17. IN EFI_PEI_FILE_HANDLE FileHandle,
  18. IN CONST EFI_PEI_SERVICES **PeiServices
  19. )
  20. /*++
  21. Routine Description:
  22. Perform a call-back into the SEC simulator to get address of the Firmware Hub
  23. Arguments:
  24. FfsHeader - Ffs Header available to every PEIM
  25. PeiServices - General purpose services available to every PEIM.
  26. Returns:
  27. None
  28. **/
  29. {
  30. EFI_STATUS Status;
  31. EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
  32. EMU_THUNK_PPI *Thunk;
  33. EFI_PHYSICAL_ADDRESS FdBase;
  34. EFI_PHYSICAL_ADDRESS FdFixUp;
  35. EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
  36. UINT64 FdSize;
  37. UINTN Index;
  38. DEBUG ((DEBUG_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
  39. //
  40. // Get the Fwh Information PPI
  41. //
  42. Status = PeiServicesLocatePpi (
  43. &gEmuThunkPpiGuid, // GUID
  44. 0, // INSTANCE
  45. &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
  46. (VOID **)&Thunk // PPI
  47. );
  48. ASSERT_EFI_ERROR (Status);
  49. Index = 0;
  50. do {
  51. //
  52. // Get information about all the FD's in the system
  53. //
  54. Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);
  55. if (!EFI_ERROR (Status)) {
  56. //
  57. // Assume the FD starts with an FV header
  58. //
  59. FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FdBase;
  60. //
  61. // Make an FV Hob for the first FV in the FD
  62. //
  63. BuildFvHob (FdBase, FvHeader->FvLength);
  64. if (Index == 0) {
  65. //
  66. // Assume the first FD was produced by the NT32.DSC
  67. // All these strange offests are needed to keep in
  68. // sync with the FlashMap and NT32.dsc file
  69. //
  70. BuildResourceDescriptorHob (
  71. EFI_RESOURCE_FIRMWARE_DEVICE,
  72. (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
  73. FdBase,
  74. (
  75. FvHeader->FvLength +
  76. PcdGet32 (PcdFlashNvStorageVariableSize) +
  77. PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
  78. PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
  79. PcdGet32 (PcdEmuFlashNvStorageEventLogSize)
  80. )
  81. );
  82. //
  83. // Hard code the address of the spare block and variable services.
  84. // Assume it's a hard coded offset from FV0 in FD0.
  85. //
  86. FdSize =
  87. PcdGet32 (PcdFlashNvStorageVariableSize) +
  88. PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
  89. PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
  90. PcdGet32 (PcdEmuFlashNvStorageEventLogSize);
  91. BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);
  92. } else {
  93. //
  94. // For other FD's just map them in.
  95. //
  96. BuildResourceDescriptorHob (
  97. EFI_RESOURCE_FIRMWARE_DEVICE,
  98. (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
  99. FdBase,
  100. FdSize
  101. );
  102. }
  103. }
  104. Index++;
  105. } while (!EFI_ERROR (Status));
  106. return Status;
  107. }