Move registration and processing of ExitBootServices() events into UefiDriverEntryPoi...
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Ipf / RuntimeLib.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 RuntimeLib.c\r
15\r
878ddf1f 16--*/\r
17\r
18#include <SalApi.h>\r
19#include <RuntimeLibInternal.h>\r
20\r
21//\r
22// Driver Lib Module Globals\r
23//\r
24\r
e8a3bee0 25STATIC EFI_EVENT mRuntimeNotifyEvent;\r
26STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r
878ddf1f 27\r
e8a3bee0 28EFI_RUNTIME_SERVICES *mRT;\r
878ddf1f 29\r
30STATIC\r
31VOID\r
32EFIAPI\r
33RuntimeDriverExitBootServices (\r
34 IN EFI_EVENT Event,\r
35 IN VOID *Context\r
36 )\r
37/*++\r
38\r
39Routine Description:\r
40\r
41 Set AtRuntime flag as TRUE after ExitBootServices\r
42\r
43Arguments:\r
44\r
45 Event - The Event that is being processed\r
46 \r
47 Context - Event Context\r
48\r
49Returns: \r
50\r
51 None\r
52\r
53--*/\r
54{\r
55 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
56 UINTN Index;\r
57\r
58 for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
59 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
60 ChildNotifyEventHandler (Event, NULL);\r
61 }\r
e8a3bee0 62\r
63 //\r
64 // Clear out BootService globals\r
65 //\r
66 gBS = NULL;\r
878ddf1f 67}\r
68\r
69STATIC\r
70VOID\r
71EFIAPI\r
72RuntimeLibVirtualNotifyEvent (\r
73 IN EFI_EVENT Event,\r
74 IN VOID *Context\r
75 )\r
76/*++\r
77\r
78Routine Description:\r
79\r
80 Fixup internal data so that EFI can be call in virtual mode.\r
81 Call the passed in Child Notify event and convert any pointers in \r
82 lib to virtual mode.\r
83\r
84Arguments:\r
85\r
86 Event - The Event that is being processed\r
87 \r
88 Context - Event Context\r
89\r
90Returns: \r
91\r
92 None\r
93\r
94--*/\r
95{\r
96 UINTN Index;\r
97 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
98\r
99 for (Index = 0; _gDriverSetVirtualAddressMapEvent[Index] != NULL; Index++) {\r
100 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];\r
101 ChildNotifyEventHandler (Event, NULL);\r
102 }\r
103\r
c25aaa00 104 //\r
105 // Update global for Runtime Services Table\r
106 //\r
107 EfiConvertPointer (0, (VOID **) &mRT);\r
878ddf1f 108}\r
109\r
110EFI_STATUS\r
a5e465a7 111EFIAPI\r
878ddf1f 112RuntimeDriverLibConstruct (\r
113 IN EFI_HANDLE ImageHandle,\r
114 IN EFI_SYSTEM_TABLE *SystemTable\r
115 )\r
116/*++\r
117\r
118Routine Description:\r
119\r
120 Intialize runtime Driver Lib if it has not yet been initialized. \r
121\r
122Arguments:\r
123\r
124 ImageHandle - The firmware allocated handle for the EFI image.\r
125 \r
126 SystemTable - A pointer to the EFI System Table.\r
127\r
128 GoVirtualChildEvent - Caller can register a virtual notification event.\r
129\r
130Returns: \r
131\r
132 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
133\r
134--*/\r
135{\r
878ddf1f 136 EFI_STATUS Status;\r
137\r
138 mRT = SystemTable->RuntimeServices;\r
139\r
878ddf1f 140 //\r
141 // Register our ExitBootServices () notify function\r
142 //\r
143\r
144 Status = gBS->CreateEvent (\r
145 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
146 EFI_TPL_NOTIFY,\r
147 RuntimeDriverExitBootServices,\r
148 NULL,\r
149 &mRuntimeNotifyEvent\r
150 );\r
151 ASSERT_EFI_ERROR (Status);\r
152\r
153 //\r
154 // Register SetVirtualAddressMap () notify function\r
155 //\r
156 \r
157 Status = gBS->CreateEvent (\r
158 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
159 EFI_TPL_NOTIFY,\r
160 RuntimeLibVirtualNotifyEvent,\r
161 NULL,\r
8572fea9 162 &mEfiVirtualNotifyEvent\r
878ddf1f 163 );\r
164 ASSERT_EFI_ERROR (Status);\r
165\r
166 return EFI_SUCCESS;\r
167}\r
168\r
169EFI_STATUS\r
a5e465a7 170EFIAPI\r
878ddf1f 171RuntimeDriverLibDeconstruct (\r
172 VOID\r
173 )\r
174/*++\r
175\r
176Routine Description:\r
177\r
178 This routine will free some resources which have been allocated in\r
179 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
180 it must call this routine to free the allocated resource before the exiting.\r
181\r
182Arguments:\r
183\r
184 None\r
185\r
186Returns: \r
187\r
188 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
189 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
190\r
191--*/\r
192{\r
193 EFI_STATUS Status;\r
194\r
195 //\r
196 // Close our ExitBootServices () notify function\r
197 //\r
198 Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
199 ASSERT_EFI_ERROR (Status);\r
200\r
201 //\r
202 // Close SetVirtualAddressMap () notify function\r
203 //\r
204 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
205 ASSERT_EFI_ERROR (Status);\r
206\r
207 return EFI_SUCCESS;\r
208}\r
209\r
210BOOLEAN\r
e8a3bee0 211EFIAPI\r
878ddf1f 212EfiAtRuntime (\r
213 VOID\r
214 )\r
215/*++\r
216\r
217Routine Description:\r
218 Return TRUE if ExitBootService () has been called\r
219\r
220Arguments:\r
221 NONE\r
222\r
223Returns: \r
224 TRUE - If ExitBootService () has been called\r
225\r
226--*/\r
227{\r
228 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
229 SAL_RETURN_REGS ReturnReg;\r
230\r
231 ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 0, 0, 0, 0, 0, 0, 0);\r
232\r
233 return (BOOLEAN) (ReturnReg.r9 == 1);\r
234}\r
235\r
236BOOLEAN\r
e8a3bee0 237EFIAPI\r
878ddf1f 238EfiGoneVirtual (\r
239 VOID\r
240 )\r
241/*++\r
242\r
243Routine Description:\r
244 Return TRUE if SetVirtualAddressMap () has been called\r
245\r
246Arguments:\r
247 NONE\r
248\r
249Returns: \r
250 TRUE - If SetVirtualAddressMap () has been called\r
251\r
252--*/\r
253{\r
254 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
255 SAL_RETURN_REGS ReturnReg;\r
256\r
257 ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);\r
258\r
259 return (BOOLEAN) (ReturnReg.r9 == 1);\r
260}\r
e8a3bee0 261\r