]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/x64/RuntimeLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / x64 / RuntimeLib.c
Content-type: text/html ]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/x64/RuntimeLib.c


500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 6) line 1, <$fd> line 972.
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2005 - 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 "Tiano.h"\r
23#include "EfiRuntimeLib.h"\r
24#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
25#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
26#include EFI_GUID_DEFINITION (StatusCodeCallerId)\r
27#include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)\r
28\r
29//\r
30// Driver Lib Module Globals\r
31//\r
32static EFI_RUNTIME_SERVICES *mRT;\r
33static EFI_EVENT mRuntimeNotifyEvent = NULL;\r
34static EFI_EVENT mEfiVirtualNotifyEvent = NULL;\r
35static BOOLEAN mRuntimeLibInitialized = FALSE;\r
36static BOOLEAN mEfiGoneVirtual = FALSE;\r
37\r
38//\r
39// Runtime Global, but you should use the Lib functions\r
40//\r
41EFI_CPU_IO_PROTOCOL *gCpuIo;\r
42BOOLEAN mEfiAtRuntime = FALSE;\r
43FVB_ENTRY *mFvbEntry;\r
44\r
45#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
46static EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;\r
47#endif\r
48\r
49EFI_STATUS\r
50EfiConvertPointer (\r
51 IN UINTN DebugDisposition,\r
52 IN OUT VOID *Address\r
53 )\r
54/*++\r
55\r
56Routine Description:\r
57\r
58 Determines the new virtual address that is to be used on subsequent memory accesses.\r
59\r
60Arguments:\r
61\r
62 DebugDisposition - Supplies type information for the pointer being converted.\r
63 Address - A pointer to a pointer that is to be fixed to be the value needed\r
64 for the new virtual address mappings being applied.\r
65\r
66Returns:\r
67\r
68 Status code\r
69\r
70--*/\r
71{\r
72 return mRT->ConvertPointer (DebugDisposition, Address);\r
73}\r
74\r
75EFI_STATUS\r
76EfiConvertInternalPointer (\r
77 IN OUT VOID *Address\r
78 )\r
79/*++\r
80\r
81Routine Description:\r
82\r
83 Call EfiConvertPointer() to convert internal pointer.\r
84\r
85Arguments:\r
86\r
87 Address - A pointer to a pointer that is to be fixed to be the value needed\r
88 for the new virtual address mappings being applied.\r
89\r
90Returns:\r
91\r
92 Status code\r
93\r
94--*/\r
95{\r
96 return EfiConvertPointer (EFI_INTERNAL_POINTER, Address);\r
97}\r
98\r
99VOID\r
100EFIAPI\r
101EfiRuntimeLibFvbVirtualNotifyEvent (\r
102 IN EFI_EVENT Event,\r
103 IN VOID *Context\r
104 )\r
105/*++\r
106\r
107Routine Description:\r
108\r
109 Convert all pointers in mFvbEntry after ExitBootServices.\r
110\r
111Arguments:\r
112\r
113 Event - The Event that is being processed\r
114 \r
115 Context - Event Context\r
116\r
117Returns:\r
118\r
119 None\r
120\r
121--*/\r
122{\r
123 UINTN Index;\r
124 if (mFvbEntry != NULL) {\r
125 for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
126 if (NULL != mFvbEntry[Index].Fvb) {\r
127 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
128 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
129 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetVolumeAttributes);\r
130 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->SetVolumeAttributes);\r
131 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Read);\r
132 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Write);\r
133 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
134 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb);\r
135 }\r
136\r
137 if (NULL != mFvbEntry[Index].FvbExtension) {\r
138 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
139 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension);\r
140 }\r
141 }\r
142\r
143 EfiConvertInternalPointer ((VOID **) &mFvbEntry);\r
144 }\r
145}\r
146\r
147VOID\r
148EFIAPI\r
149RuntimeDriverExitBootServices (\r
150 IN EFI_EVENT Event,\r
151 IN VOID *Context\r
152 )\r
153/*++\r
154\r
155Routine Description:\r
156\r
157 Set AtRuntime flag as TRUE after ExitBootServices\r
158\r
159Arguments:\r
160\r
161 Event - The Event that is being processed\r
162 \r
163 Context - Event Context\r
164\r
165Returns: \r
166\r
167 None\r
168\r
169--*/\r
170{\r
171 mEfiAtRuntime = TRUE;\r
172}\r
173\r
174extern BOOLEAN gEfiFvbInitialized;\r
175\r
176VOID\r
177EFIAPI\r
178EfiRuntimeLibVirtualNotifyEvent (\r
179 IN EFI_EVENT Event,\r
180 IN VOID *Context\r
181 )\r
182/*++\r
183\r
184Routine Description:\r
185\r
186 Fixup internal data so that EFI can be call in virtual mode.\r
187 Call the passed in Child Notify event and convert any pointers in \r
188 lib to virtual mode.\r
189\r
190Arguments:\r
191\r
192 Event - The Event that is being processed\r
193 \r
194 Context - Event Context\r
195\r
196Returns: \r
197\r
198 None\r
199\r
200--*/\r
201{\r
202 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
203\r
204 if (Context != NULL) {\r
205 ChildNotifyEventHandler = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
206 ChildNotifyEventHandler (Event, NULL);\r
207 }\r
208\r
209 if (gEfiFvbInitialized) {\r
210 EfiRuntimeLibFvbVirtualNotifyEvent (Event, Context);\r
211 }\r
212 //\r
213 // Update global for Runtime Services Table and IO\r
214 //\r
215 EfiConvertInternalPointer ((VOID **) &gCpuIo);\r
216#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
217 if (gStatusCode != NULL) {\r
218 EfiConvertInternalPointer ((VOID **) &gStatusCode->ReportStatusCode);\r
219 EfiConvertInternalPointer ((VOID **) &gStatusCode);\r
220 }\r
221#endif\r
222 EfiConvertInternalPointer ((VOID **) &mRT);\r
223\r
224 //\r
225 // Clear out BootService globals\r
226 //\r
227 gBS = NULL;\r
228 gST = NULL;\r
229 mEfiGoneVirtual = TRUE;\r
230}\r
231\r
232EFI_STATUS\r
233EfiInitializeRuntimeDriverLib (\r
234 IN EFI_HANDLE ImageHandle,\r
235 IN EFI_SYSTEM_TABLE *SystemTable,\r
236 IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
237 )\r
238/*++\r
239\r
240Routine Description:\r
241\r
242 Intialize runtime Driver Lib if it has not yet been initialized. \r
243\r
244Arguments:\r
245\r
246 ImageHandle - The firmware allocated handle for the EFI image.\r
247 \r
248 SystemTable - A pointer to the EFI System Table.\r
249\r
250 GoVirtualChildEvent - Caller can register a virtual notification event.\r
251\r
252Returns: \r
253\r
254 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
255\r
256--*/\r
257{\r
258 EFI_STATUS Status;\r
259\r
260 if (mRuntimeLibInitialized) {\r
261 return EFI_ALREADY_STARTED;\r
262 }\r
263\r
264 mRuntimeLibInitialized = TRUE;\r
265\r
266 gST = SystemTable;\r
267 ASSERT (gST != NULL);\r
268\r
269 gBS = SystemTable->BootServices;\r
270 ASSERT (gBS != NULL);\r
271 mRT = SystemTable->RuntimeServices;\r
272 ASSERT (mRT != NULL);\r
273\r
274 Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
275 ASSERT_EFI_ERROR (Status);\r
276\r
277#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
278 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
279 if (EFI_ERROR (Status)) {\r
280 gStatusCode = NULL;\r
281 }\r
282#endif\r
283\r
284 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &gCpuIo);\r
285 if (EFI_ERROR (Status)) {\r
286 gCpuIo = NULL;\r
287 }\r
288\r
289 //\r
290 // Register our ExitBootServices () notify function\r
291 //\r
292 Status = gBS->CreateEvent (\r
293 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
294 EFI_TPL_NOTIFY,\r
295 RuntimeDriverExitBootServices,\r
296 NULL,\r
297 &mRuntimeNotifyEvent\r
298 );\r
299 ASSERT_EFI_ERROR (Status);\r
300\r
301 //\r
302 // Register SetVirtualAddressMap () notify function\r
303 //\r
304 Status = gBS->CreateEvent (\r
305 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
306 EFI_TPL_NOTIFY,\r
307 EfiRuntimeLibVirtualNotifyEvent,\r
308 (VOID *) (UINTN) GoVirtualChildEvent,\r
309 &mEfiVirtualNotifyEvent\r
310 );\r
311 ASSERT_EFI_ERROR (Status);\r
312\r
313 return EFI_SUCCESS;\r
314}\r
315\r
316EFI_STATUS\r
317EfiShutdownRuntimeDriverLib (\r
318 VOID\r
319 )\r
320/*++\r
321\r
322Routine Description:\r
323\r
324 This routine will free some resources which have been allocated in\r
325 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
326 it must call this routine to free the allocated resource before the exiting.\r
327\r
328Arguments:\r
329\r
330 None\r
331\r
332Returns: \r
333\r
334 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
335 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
336\r
337--*/\r
338{\r
339 EFI_STATUS Status;\r
340\r
341 if (!mRuntimeLibInitialized) {\r
342 //\r
343 // You must call EfiInitializeRuntimeDriverLib() first\r
344 //\r
345 return EFI_UNSUPPORTED;\r
346 }\r
347\r
348 mRuntimeLibInitialized = FALSE;\r
349\r
350 //\r
351 // Close our ExitBootServices () notify function\r
352 //\r
353 if (mRuntimeNotifyEvent != NULL) {\r
354 Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
355 ASSERT_EFI_ERROR (Status);\r
356 }\r
357\r
358 //\r
359 // Close SetVirtualAddressMap () notify function\r
360 //\r
361 if (mEfiVirtualNotifyEvent != NULL) {\r
362 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
363 ASSERT_EFI_ERROR (Status);\r
364 }\r
365\r
366 return EFI_SUCCESS;\r
367}\r
368\r
369EFI_STATUS\r
370EfiInitializeSmmDriverLib (\r
371 IN EFI_HANDLE ImageHandle,\r
372 IN EFI_SYSTEM_TABLE *SystemTable\r
373 )\r
374/*++\r
375\r
376Routine Description:\r
377\r
378 Intialize runtime Driver Lib if it has not yet been initialized. \r
379\r
380Arguments:\r
381\r
382 ImageHandle - The firmware allocated handle for the EFI image.\r
383 \r
384 SystemTable - A pointer to the EFI System Table.\r
385\r
386Returns: \r
387\r
388 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
389\r
390--*/\r
391{\r
392 EFI_STATUS Status;\r
393\r
394 if (mRuntimeLibInitialized) {\r
395 return EFI_ALREADY_STARTED;\r
396 }\r
397\r
398 mRuntimeLibInitialized = TRUE;\r
399\r
400 gST = SystemTable;\r
401 ASSERT (gST != NULL);\r
402\r
403 gBS = SystemTable->BootServices;\r
404 ASSERT (gBS != NULL);\r
405 mRT = SystemTable->RuntimeServices;\r
406 ASSERT (mRT != NULL);\r
407\r
408#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
409 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
410 if (EFI_ERROR (Status)) {\r
411 gStatusCode = NULL;\r
412 }\r
413#endif\r
414\r
415 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &gCpuIo);\r
416 if (EFI_ERROR (Status)) {\r
417 gCpuIo = NULL;\r
418 }\r
419\r
420 return EFI_SUCCESS;\r
421}\r
422\r
423BOOLEAN\r
424EfiAtRuntime (\r
425 VOID\r
426 )\r
427/*++\r
428\r
429Routine Description:\r
430 Return TRUE if ExitBootServices () has been called\r
431\r
432Arguments:\r
433 NONE\r
434\r
435Returns: \r
436 TRUE - If ExitBootServices () has been called\r
437\r
438--*/\r
439{\r
440 return mEfiAtRuntime;\r
441}\r
442\r
443BOOLEAN\r
444EfiGoneVirtual (\r
445 VOID\r
446 )\r
447/*++\r
448\r
449Routine Description:\r
450 Return TRUE if SetVirtualAddressMap () has been called\r
451\r
452Arguments:\r
453 NONE\r
454\r
455Returns: \r
456 TRUE - If SetVirtualAddressMap () has been called\r
457\r
458--*/\r
459{\r
460 return mEfiGoneVirtual;\r
461}\r
462//\r
463// The following functions hide the mRT local global from the call to\r
464// runtime service in the EFI system table.\r
465//\r
466EFI_STATUS\r
467EfiGetTime (\r
468 OUT EFI_TIME *Time,\r
469 OUT EFI_TIME_CAPABILITIES *Capabilities\r
470 )\r
471/*++\r
472\r
473Routine Description:\r
474\r
475 Returns the current time and date information, and the time-keeping \r
476 capabilities of the hardware platform.\r
477\r
478Arguments:\r
479\r
480 Time - A pointer to storage to receive a snapshot of the current time.\r
481