]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Library/EdkUefiRuntimeLib/Common/RuntimeLib.c
Update library constructor definition.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Common / 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
16Abstract:\r
17\r
18 Light weight lib to support Tiano drivers.\r
19\r
20--*/\r
21\r
22#include <RuntimeLibInternal.h>\r
23\r
24//\r
25// Driver Lib Module Globals\r
26//\r
27STATIC EFI_EVENT mRuntimeNotifyEvent;\r
28STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r
29STATIC BOOLEAN mEfiGoneVirtual = FALSE;\r
30STATIC BOOLEAN mEfiAtRuntime = FALSE;\r
31\r
32EFI_RUNTIME_SERVICES *mRT = NULL;\r
33\r
34VOID\r
35EFIAPI\r
36RuntimeDriverExitBootServices (\r
37 IN EFI_EVENT Event,\r
38 IN VOID *Context\r
39 )\r
40/*++\r
41\r
42Routine Description:\r
43\r
44 Set AtRuntime flag as TRUE after ExitBootServices\r
45\r
46Arguments:\r
47\r
48 Event - The Event that is being processed\r
49 \r
50 Context - Event Context\r
51\r
52Returns: \r
53\r
54 None\r
55\r
56--*/\r
57{\r
58 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
59 UINTN Index;\r
60\r
61 for (Index = 0; \r
62 _gDriverExitBootServicesEvent[Index] != NULL;\r
63 Index++) {\r
64 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
65 ChildNotifyEventHandler (Event, NULL);\r
66 }\r
67\r
68 mEfiAtRuntime = TRUE;\r
69}\r
70\r
71STATIC\r
72VOID\r
73EFIAPI\r
74RuntimeLibVirtualNotifyEvent (\r
75 IN EFI_EVENT Event,\r
76 IN VOID *Context\r
77 )\r
78/*++\r
79\r
80Routine Description:\r
81\r
82 Fixup internal data so that EFI can be call in virtual mode.\r
83 Call the passed in Child Notify event and convert any pointers in \r
84 lib to virtual mode.\r
85\r
86Arguments:\r
87\r
88 Event - The Event that is being processed\r
89 \r
90 Context - Event Context\r
91\r
92Returns: \r
93\r
94 None\r
95\r
96--*/\r
97{\r
98 UINTN Index;\r
99 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
100\r
101 for (Index = 0; \r
102 _gDriverSetVirtualAddressMapEvent[Index] != NULL;\r
103 Index++) {\r
104 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];\r
105 ChildNotifyEventHandler (Event, NULL);\r
106 }\r
107\r
108 //\r
109 // Update global for Runtime Services Table and IO\r
110 //\r
111 EfiConvertInternalPointer ((VOID **) &mRT);\r
112\r
113 //\r
114 // Clear out BootService globals\r
115 //\r
116 gBS = NULL;\r
117 gST = NULL;\r
118 mEfiGoneVirtual = TRUE;\r
119}\r
120\r
121EFI_STATUS\r
a5e465a7 122EFIAPI\r
878ddf1f 123RuntimeDriverLibConstruct (\r
124 IN EFI_HANDLE ImageHandle,\r
125 IN EFI_SYSTEM_TABLE *SystemTable\r
126 )\r
127/*++\r
128\r
129Routine Description:\r
130\r
131 Intialize runtime Driver Lib if it has not yet been initialized. \r
132\r
133Arguments:\r
134\r
135 ImageHandle - The firmware allocated handle for the EFI image.\r
136 \r
137 SystemTable - A pointer to the EFI System Table.\r
138\r
139 GoVirtualChildEvent - Caller can register a virtual notification event.\r
140\r
141Returns: \r
142\r
143 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
144\r
145--*/\r
146{\r
147 EFI_STATUS Status;\r
148\r
149 mRT = SystemTable->RuntimeServices;\r
150\r
151 //\r
152 // Register our ExitBootServices () notify function\r
153 //\r
154 Status = gBS->CreateEvent (\r
155 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
156 EFI_TPL_NOTIFY,\r
157 RuntimeDriverExitBootServices,\r
158 NULL,\r
159 &mRuntimeNotifyEvent\r
160 );\r
161\r
162 ASSERT_EFI_ERROR (Status);\r
163\r
164 //\r
165 // Register SetVirtualAddressMap () notify function\r
166 // \r
167 Status = gBS->CreateEvent (\r
168 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
169 EFI_TPL_NOTIFY,\r
170 RuntimeLibVirtualNotifyEvent,\r
171 NULL,\r
172 &mEfiVirtualNotifyEvent\r
173 );\r
174\r
175 ASSERT_EFI_ERROR (Status);\r
176\r
177 return EFI_SUCCESS;\r
178}\r
179\r
180EFI_STATUS\r
a5e465a7 181EFIAPI\r
878ddf1f 182RuntimeDriverLibDeconstruct (\r
183 VOID\r
184 )\r
185/*++\r
186\r
187Routine Description:\r
188\r
189 This routine will free some resources which have been allocated in\r
190 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
191 it must call this routine to free the allocated resource before the exiting.\r
192\r
193Arguments:\r
194\r
195 None\r
196\r
197Returns: \r
198\r
199 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
200 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
201\r
202--*/\r
203{\r
204 EFI_STATUS Status;\r
205\r
206 //\r
207 // Close our ExitBootServices () notify function\r
208 //\r
209 Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
210 ASSERT_EFI_ERROR (Status);\r
211\r
212 //\r
213 // Close SetVirtualAddressMap () notify function\r
214 //\r
215 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
216 ASSERT_EFI_ERROR (Status);\r
217\r
218 return EFI_SUCCESS;\r
219}\r
220\r
221BOOLEAN\r
222EfiAtRuntime (\r
223 VOID\r
224 )\r
225/*++\r
226\r
227Routine Description:\r
228 Return TRUE if ExitBootServices () has been called\r
229\r
230Arguments:\r
231 NONE\r
232\r
233Returns: \r
234 TRUE - If ExitBootServices () has been called\r
235\r
236--*/\r
237{\r
238 return mEfiAtRuntime;\r
239}\r
240\r
241BOOLEAN\r
242EfiGoneVirtual (\r
243 VOID\r
244 )\r
245/*++\r
246\r
247Routine Description:\r
248 Return TRUE if SetVirtualAddressMap () has been called\r
249\r
250Arguments:\r
251 NONE\r
252\r
253Returns: \r
254 TRUE - If SetVirtualAddressMap () has been called\r
255\r
256--*/\r
257{\r
258 return mEfiGoneVirtual;\r
259}\r
260\r