PeiServicesTablePointer.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /** @file
  2. PEI Services Table Pointer Library.
  3. This library is used for PEIM which does executed from flash device directly but
  4. executed in memory.
  5. Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
  6. Portiions copyrigth (c) 2011, Apple Inc. All rights reserved.
  7. SPDX-License-Identifier: BSD-2-Clause-Patent
  8. **/
  9. #include <PiPei.h>
  10. #include <Library/PeiServicesTablePointerLib.h>
  11. #include <Library/DebugLib.h>
  12. #include <Ppi/MemoryDiscovered.h>
  13. CONST EFI_PEI_SERVICES **gPeiServices = NULL;
  14. /**
  15. Caches a pointer PEI Services Table.
  16. Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
  17. in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
  18. Pre-EFI Initialization Core Interface Specification.
  19. If PeiServicesTablePointer is NULL, then ASSERT().
  20. @param PeiServicesTablePointer The address of PeiServices pointer.
  21. **/
  22. VOID
  23. EFIAPI
  24. SetPeiServicesTablePointer (
  25. IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer
  26. )
  27. {
  28. ASSERT (PeiServicesTablePointer != NULL);
  29. ASSERT (*PeiServicesTablePointer != NULL);
  30. gPeiServices = PeiServicesTablePointer;
  31. }
  32. /**
  33. Retrieves the cached value of the PEI Services Table pointer.
  34. Returns the cached value of the PEI Services Table pointer in a CPU specific manner
  35. as specified in the CPU binding section of the Platform Initialization Pre-EFI
  36. Initialization Core Interface Specification.
  37. If the cached PEI Services Table pointer is NULL, then ASSERT().
  38. @return The pointer to PeiServices.
  39. **/
  40. CONST EFI_PEI_SERVICES **
  41. EFIAPI
  42. GetPeiServicesTablePointer (
  43. VOID
  44. )
  45. {
  46. ASSERT (gPeiServices != NULL);
  47. ASSERT (*gPeiServices != NULL);
  48. return gPeiServices;
  49. }
  50. /**
  51. Notification service to be called when gEmuThunkPpiGuid is installed.
  52. @param PeiServices Indirect reference to the PEI Services Table.
  53. @param NotifyDescriptor Address of the notification descriptor data structure. Type
  54. EFI_PEI_NOTIFY_DESCRIPTOR is defined above.
  55. @param Ppi Address of the PPI that was installed.
  56. @retval EFI_STATUS This function will install a PPI to PPI database. The status
  57. code will be the code for (*PeiServices)->InstallPpi.
  58. **/
  59. EFI_STATUS
  60. EFIAPI
  61. PeiServicesTablePointerNotifyCallback (
  62. IN EFI_PEI_SERVICES **PeiServices,
  63. IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
  64. IN VOID *Ppi
  65. )
  66. {
  67. gPeiServices = (CONST EFI_PEI_SERVICES **)PeiServices;
  68. return EFI_SUCCESS;
  69. }
  70. EFI_PEI_NOTIFY_DESCRIPTOR mNotifyOnThunkList = {
  71. (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
  72. &gEfiPeiMemoryDiscoveredPpiGuid,
  73. PeiServicesTablePointerNotifyCallback
  74. };
  75. /**
  76. Constructor register notification on when PPI updates. If PPI is
  77. alreay installed registering the notify will cause the handle to
  78. run.
  79. @param FileHandle The handle of FFS header the loaded driver.
  80. @param PeiServices The pointer to the PEI services.
  81. @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
  82. **/
  83. EFI_STATUS
  84. EFIAPI
  85. PeiServicesTablePointerLibConstructor (
  86. IN EFI_PEI_FILE_HANDLE FileHandle,
  87. IN CONST EFI_PEI_SERVICES **PeiServices
  88. )
  89. {
  90. EFI_STATUS Status;
  91. gPeiServices = (CONST EFI_PEI_SERVICES **)PeiServices;
  92. // register to be told when PeiServices pointer is updated
  93. Status = (*PeiServices)->NotifyPpi (PeiServices, &mNotifyOnThunkList);
  94. ASSERT_EFI_ERROR (Status);
  95. return Status;
  96. }
  97. /**
  98. Perform CPU specific actions required to migrate the PEI Services Table
  99. pointer from temporary RAM to permanent RAM.
  100. For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes
  101. immediately preceding the Interrupt Descriptor Table (IDT) in memory.
  102. For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes
  103. immediately preceding the Interrupt Descriptor Table (IDT) in memory.
  104. For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in
  105. a dedicated CPU register. This means that there is no memory storage
  106. associated with storing the PEI Services Table pointer, so no additional
  107. migration actions are required for Itanium or ARM CPUs.
  108. **/
  109. VOID
  110. EFIAPI
  111. MigratePeiServicesTablePointer (
  112. VOID
  113. )
  114. {
  115. //
  116. // PEI Services Table pointer is cached in the global variable. No additional
  117. // migration actions are required.
  118. //
  119. return;
  120. }