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