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