]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module 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 | 25 | STATIC EFI_EVENT mRuntimeNotifyEvent;\r |
26 | STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r | |
27 | STATIC EFI_PLABEL mPlabel;\r | |
878ddf1f | 28 | STATIC EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;\r |
29 | \r | |
e8a3bee0 | 30 | EFI_RUNTIME_SERVICES *mRT;\r |
878ddf1f | 31 | \r |
32 | STATIC\r | |
33 | VOID\r | |
34 | EFIAPI\r | |
35 | RuntimeDriverExitBootServices (\r | |
36 | IN EFI_EVENT Event,\r | |
37 | IN VOID *Context\r | |
38 | )\r | |
39 | /*++\r | |
40 | \r | |
41 | Routine Description:\r | |
42 | \r | |
43 | Set AtRuntime flag as TRUE after ExitBootServices\r | |
44 | \r | |
45 | Arguments:\r | |
46 | \r | |
47 | Event - The Event that is being processed\r | |
48 | \r | |
49 | Context - Event Context\r | |
50 | \r | |
51 | Returns: \r | |
52 | \r | |
53 | None\r | |
54 | \r | |
55 | --*/\r | |
56 | {\r | |
57 | EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r | |
58 | UINTN Index;\r | |
59 | \r | |
60 | for (Index = 0; _gDriverExitBootServicesEvent[Index] != NULL; Index++) {\r | |
61 | ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];\r | |
62 | ChildNotifyEventHandler (Event, NULL);\r | |
63 | }\r | |
e8a3bee0 | 64 | \r |
65 | //\r | |
66 | // Clear out BootService globals\r | |
67 | //\r | |
68 | gBS = NULL;\r | |
878ddf1f | 69 | }\r |
70 | \r | |
71 | STATIC\r | |
72 | VOID\r | |
73 | EFIAPI\r | |
74 | RuntimeLibVirtualNotifyEvent (\r | |
75 | IN EFI_EVENT Event,\r | |
76 | IN VOID *Context\r | |
77 | )\r | |
78 | /*++\r | |
79 | \r | |
80 | Routine 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 | |
86 | Arguments:\r | |
87 | \r | |
88 | Event - The Event that is being processed\r | |
89 | \r | |
90 | Context - Event Context\r | |
91 | \r | |
92 | Returns: \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 | |
878ddf1f | 110 | }\r |
111 | \r | |
112 | EFI_STATUS\r | |
a5e465a7 | 113 | EFIAPI\r |
878ddf1f | 114 | RuntimeDriverLibConstruct (\r |
115 | IN EFI_HANDLE ImageHandle,\r | |
116 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
117 | )\r | |
118 | /*++\r | |
119 | \r | |
120 | Routine Description:\r | |
121 | \r | |
122 | Intialize runtime Driver Lib if it has not yet been initialized. \r | |
123 | \r | |
124 | Arguments:\r | |
125 | \r | |
126 | ImageHandle - The firmware allocated handle for the EFI image.\r | |
127 | \r | |
128 | SystemTable - A pointer to the EFI System Table.\r | |
129 | \r | |
130 | GoVirtualChildEvent - Caller can register a virtual notification event.\r | |
131 | \r | |
132 | Returns: \r | |
133 | \r | |
134 | EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r | |
135 | \r | |
136 | --*/\r | |
137 | {\r | |
138 | EFI_PLABEL *Plabel;\r | |
139 | EFI_STATUS Status;\r | |
140 | \r | |
141 | mRT = SystemTable->RuntimeServices;\r | |
142 | \r | |
143 | //\r | |
144 | // The protocol contains a function pointer, which is an indirect procedure call.\r | |
145 | // An indirect procedure call goes through a plabel, and pointer to a function is\r | |
146 | // a pointer to a plabel. To implement indirect procedure calls that can work in\r | |
147 | // both physical and virtual mode, two plabels are required (one physical and one\r | |
148 | // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it\r | |
149 | // away. We cache it in a module global, so we can register the vitrual version.\r | |
150 | //\r | |
151 | Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, &mEsalBootService);\r | |
152 | ASSERT_EFI_ERROR (Status);\r | |
153 | \r | |
154 | Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;\r | |
155 | \r | |
156 | mPlabel.EntryPoint = Plabel->EntryPoint;\r | |
157 | mPlabel.GP = Plabel->GP;\r | |
158 | \r | |
159 | SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r | |
160 | \r | |
161 | //\r | |
162 | // Register our ExitBootServices () notify function\r | |
163 | //\r | |
164 | \r | |
165 | Status = gBS->CreateEvent (\r | |
166 | EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r | |
167 | EFI_TPL_NOTIFY,\r | |
168 | RuntimeDriverExitBootServices,\r | |
169 | NULL,\r | |
170 | &mRuntimeNotifyEvent\r | |
171 | );\r | |
172 | ASSERT_EFI_ERROR (Status);\r | |
173 | \r | |
174 | //\r | |
175 | // Register SetVirtualAddressMap () notify function\r | |
176 | //\r | |
177 | \r | |
178 | Status = gBS->CreateEvent (\r | |
179 | EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r | |
180 | EFI_TPL_NOTIFY,\r | |
181 | RuntimeLibVirtualNotifyEvent,\r | |
182 | NULL,\r | |
183 | mEfiVirtualNotifyEvent\r | |
184 | );\r | |
185 | ASSERT_EFI_ERROR (Status);\r | |
186 | \r | |
187 | return EFI_SUCCESS;\r | |
188 | }\r | |
189 | \r | |
190 | EFI_STATUS\r | |
a5e465a7 | 191 | EFIAPI\r |
878ddf1f | 192 | RuntimeDriverLibDeconstruct (\r |
193 | VOID\r | |
194 | )\r | |
195 | /*++\r | |
196 | \r | |
197 | Routine Description:\r | |
198 | \r | |
199 | This routine will free some resources which have been allocated in\r | |
200 | EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r | |
201 | it must call this routine to free the allocated resource before the exiting.\r | |
202 | \r | |
203 | Arguments:\r | |
204 | \r | |
205 | None\r | |
206 | \r | |
207 | Returns: \r | |
208 | \r | |
209 | EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r | |
210 | EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r | |
211 | \r | |
212 | --*/\r | |
213 | {\r | |
214 | EFI_STATUS Status;\r | |
215 | \r | |
216 | //\r | |
217 | // Close our ExitBootServices () notify function\r | |
218 | //\r | |
219 | Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r | |
220 | ASSERT_EFI_ERROR (Status);\r | |
221 | \r | |
222 | //\r | |
223 | // Close SetVirtualAddressMap () notify function\r | |
224 | //\r | |
225 | Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r | |
226 | ASSERT_EFI_ERROR (Status);\r | |
227 | \r | |
228 | return EFI_SUCCESS;\r | |
229 | }\r | |
230 | \r | |
231 | BOOLEAN\r | |
e8a3bee0 | 232 | EFIAPI\r |
878ddf1f | 233 | EfiAtRuntime (\r |
234 | VOID\r | |
235 | )\r | |
236 | /*++\r | |
237 | \r | |
238 | Routine Description:\r | |
239 | Return TRUE if ExitBootService () has been called\r | |
240 | \r | |
241 | Arguments:\r | |
242 | NONE\r | |
243 | \r | |
244 | Returns: \r | |
245 | TRUE - If ExitBootService () has been called\r | |
246 | \r | |
247 | --*/\r | |
248 | {\r | |
249 | EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r | |
250 | SAL_RETURN_REGS ReturnReg;\r | |
251 | \r | |
252 | ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 0, 0, 0, 0, 0, 0, 0);\r | |
253 | \r | |
254 | return (BOOLEAN) (ReturnReg.r9 == 1);\r | |
255 | }\r | |
256 | \r | |
257 | BOOLEAN\r | |
e8a3bee0 | 258 | EFIAPI\r |
878ddf1f | 259 | EfiGoneVirtual (\r |
260 | VOID\r | |
261 | )\r | |
262 | /*++\r | |
263 | \r | |
264 | Routine Description:\r | |
265 | Return TRUE if SetVirtualAddressMap () has been called\r | |
266 | \r | |
267 | Arguments:\r | |
268 | NONE\r | |
269 | \r | |
270 | Returns: \r | |
271 | TRUE - If SetVirtualAddressMap () has been called\r | |
272 | \r | |
273 | --*/\r | |
274 | {\r | |
275 | EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r | |
276 | SAL_RETURN_REGS ReturnReg;\r | |
277 | \r | |
278 | ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);\r | |
279 | \r | |
280 | return (BOOLEAN) (ReturnReg.r9 == 1);\r | |
281 | }\r | |
e8a3bee0 | 282 | \r |