AutoScanPei.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*++ @file
  2. Copyright (c) 2006 - 2018, 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 <Ppi/MemoryDiscovered.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/PeimEntryPoint.h>
  11. #include <Library/BaseLib.h>
  12. #include <Library/BaseMemoryLib.h>
  13. #include <Library/HobLib.h>
  14. #include <Library/PeiServicesLib.h>
  15. #include <Library/PeiServicesTablePointerLib.h>
  16. EFI_STATUS
  17. EFIAPI
  18. PeimInitializeAutoScanPei (
  19. IN EFI_PEI_FILE_HANDLE FileHandle,
  20. IN CONST EFI_PEI_SERVICES **PeiServices
  21. )
  22. /*++
  23. Routine Description:
  24. Perform a call-back into the SEC simulator to get a memory value
  25. Arguments:
  26. FfsHeader - General purpose data available to every PEIM
  27. PeiServices - General purpose services available to every PEIM.
  28. Returns:
  29. None
  30. **/
  31. {
  32. EFI_STATUS Status;
  33. EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
  34. EMU_THUNK_PPI *Thunk;
  35. UINT64 MemorySize;
  36. EFI_PHYSICAL_ADDRESS MemoryBase;
  37. UINTN Index;
  38. EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
  39. DEBUG ((DEBUG_ERROR, "Emu Autoscan PEIM Loaded\n"));
  40. //
  41. // Get the PEI UNIX Autoscan PPI
  42. //
  43. Status = PeiServicesLocatePpi (
  44. &gEmuThunkPpiGuid, // GUID
  45. 0, // INSTANCE
  46. &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
  47. (VOID **)&Thunk // PPI
  48. );
  49. ASSERT_EFI_ERROR (Status);
  50. Index = 0;
  51. do {
  52. Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize);
  53. if (!EFI_ERROR (Status)) {
  54. Attributes =
  55. (
  56. EFI_RESOURCE_ATTRIBUTE_PRESENT |
  57. EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
  58. EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
  59. EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
  60. EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
  61. EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
  62. );
  63. if (Index == 0) {
  64. //
  65. // Register the memory with the PEI Core
  66. //
  67. Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);
  68. ASSERT_EFI_ERROR (Status);
  69. Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
  70. }
  71. BuildResourceDescriptorHob (
  72. EFI_RESOURCE_SYSTEM_MEMORY,
  73. Attributes,
  74. MemoryBase,
  75. MemorySize
  76. );
  77. }
  78. Index++;
  79. } while (!EFI_ERROR (Status));
  80. //
  81. // Build the CPU hob with 57-bit addressing and 16-bits of IO space.
  82. //
  83. BuildCpuHob (57, 16);
  84. return Status;
  85. }