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