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