]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Library/EdkUefiRuntimeLib/Ipf/RuntimeLib.c
Update library constructor definition.
[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
16Abstract:\r
17\r
18 Light weight lib to support Tiano drivers.\r
19\r
20--*/\r
21\r
22#include <SalApi.h>\r
23#include <RuntimeLibInternal.h>\r
24\r
25//\r
26// Driver Lib Module Globals\r
27//\r
28\r
29STATIC EFI_EVENT mRuntimeNotifyEvent;\r
30STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r
31\r
32STATIC EFI_PLABEL mPlabel;\r
33STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;\r
34\r
35EFI_RUNTIME_SERVICES *mRT = NULL;\r
36\r
37STATIC\r
38VOID\r
39EFIAPI\r
40RuntimeDriverExitBootServices (\r
41 IN EFI_EVENT Event,\r
42 IN VOID *Context\r
43 )\r
44/*++\r
45\r
46Routine Description:\r
47\r
48 Set AtRuntime flag as TRUE after ExitBootServices\r
49\r
50Arguments:\r
51\r
52 Event - The Event that is being processed\r
53 \r
54 Context - Event Context\r
55\r
56Returns: \r
57\r
58 None\r
59\r
60--*/\r
61{\r
62 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
63 UINTN Index;\r
64\r
65 for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r
66 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r
67 ChildNotifyEventHandler (Event, NULL);\r
68 }\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; _gDriverSetVirtualAddressMapEvent[Index] != NULL; Index++) {\r
102 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];\r
103 ChildNotifyEventHandler (Event, NULL);\r
104 }\r
105\r
106 mRT->ConvertPointer (0x0, (VOID **) &mPlabel.EntryPoint);\r
107 mRT->ConvertPointer (EFI_IPF_GP_POINTER, (VOID **) &mPlabel.GP);\r
108\r
109 SetEsalVirtualEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
110\r
111 //\r
112 // Clear out BootService globals\r
113 //\r
114 gBS = NULL;\r
115 gST = NULL;\r
116 mRT = NULL;\r
117}\r
118\r
119EFI_STATUS\r
a5e465a7 120EFIAPI\r
878ddf1f 121RuntimeDriverLibConstruct (\r
122 IN EFI_HANDLE ImageHandle,\r
123 IN EFI_SYSTEM_TABLE *SystemTable\r
124 )\r
125/*++\r
126\r
127Routine Description:\r
128\r
129 Intialize runtime Driver Lib if it has not yet been initialized. \r
130\r
131Arguments:\r
132\r
133 ImageHandle - The firmware allocated handle for the EFI image.\r
134 \r
135 SystemTable - A pointer to the EFI System Table.\r
136\r
137 GoVirtualChildEvent - Caller can register a virtual notification event.\r
138\r
139Returns: \r
140\r
141 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
142\r
143--*/\r
144{\r
145 EFI_PLABEL *Plabel;\r
146 EFI_STATUS Status;\r
147\r
148 mRT = SystemTable->RuntimeServices;\r
149\r
150 //\r
151 // The protocol contains a function pointer, which is an indirect procedure call.\r
152 // An indirect procedure call goes through a plabel, and pointer to a function is\r
153 // a pointer to a plabel. To implement indirect procedure calls that can work in\r
154 // both physical and virtual mode, two plabels are required (one physical and one\r
155 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it\r
156 // away. We cache it in a module global, so we can register the vitrual version.\r
157 //\r
158 Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);\r
159 ASSERT_EFI_ERROR (Status);\r
160\r
161 Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;\r
162\r
163 mPlabel.EntryPoint = Plabel->EntryPoint;\r
164 mPlabel.GP = Plabel->GP;\r
165\r
166 SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
167\r
168 //\r
169 // Register our ExitBootServices () notify function\r
170 //\r
171\r
172 Status = gBS->CreateEvent (\r
173 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
174 EFI_TPL_NOTIFY,\r
175 RuntimeDriverExitBootServices,\r
176 NULL,\r
177 &mRuntimeNotifyEvent\r
178 );\r
179 ASSERT_EFI_ERROR (Status);\r
180\r
181 //\r
182 // Register SetVirtualAddressMap () notify function\r
183 //\r
184 \r
185 Status = gBS->CreateEvent (\r
186 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
187 EFI_TPL_NOTIFY,\r
188 RuntimeLibVirtualNotifyEvent,\r
189 NULL,\r
190 mEfiVirtualNotifyEvent\r
191 );\r
192 ASSERT_EFI_ERROR (Status);\r
193\r
194 return EFI_SUCCESS;\r
195}\r
196\r
197EFI_STATUS\r
a5e465a7 198EFIAPI\r
878ddf1f 199RuntimeDriverLibDeconstruct (\r
200 VOID\r
201 )\r
202/*++\r
203\r
204Routine Description:\r
205\r
206 This routine will free some resources which have been allocated in\r
207 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
208 it must call this routine to free the allocated resource before the exiting.\r
209\r
210Arguments:\r
211\r
212 None\r
213\r
214Returns: \r
215\r
216 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
217 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
218\r
219--*/\r
220{\r
221 EFI_STATUS Status;\r
222\r
223 //\r
224 // Close our ExitBootServices () notify function\r
225 //\r
226 Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
227 ASSERT_EFI_ERROR (Status);\r
228\r
229 //\r
230 // Close SetVirtualAddressMap () notify function\r
231 //\r
232 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
233 ASSERT_EFI_ERROR (Status);\r
234\r
235 return EFI_SUCCESS;\r
236}\r
237\r
238BOOLEAN\r
239EfiAtRuntime (\r
240 VOID\r
241 )\r
242/*++\r
243\r
244Routine Description:\r
245 Return TRUE if ExitBootService () has been called\r
246\r
247Arguments:\r
248 NONE\r
249\r
250Returns: \r
251 TRUE - If ExitBootService () has been called\r
252\r
253--*/\r
254{\r
255 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
256 SAL_RETURN_REGS ReturnReg;\r
257\r
258 ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 0, 0, 0, 0, 0, 0, 0);\r
259\r
260 return (BOOLEAN) (ReturnReg.r9 == 1);\r
261}\r
262\r
263BOOLEAN\r
264EfiGoneVirtual (\r
265 VOID\r
266 )\r
267/*++\r
268\r
269Routine Description:\r
270 Return TRUE if SetVirtualAddressMap () has been called\r
271\r
272Arguments:\r
273 NONE\r
274\r
275Returns: \r
276 TRUE - If SetVirtualAddressMap () has been called\r
277\r
278--*/\r
279{\r
280 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
281 SAL_RETURN_REGS ReturnReg;\r
282\r
283 ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);\r
284\r
285 return (BOOLEAN) (ReturnReg.r9 == 1);\r
286}\r