]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/Runtime/RuntimeDxe/Runtime.c
1)Add a new module CapsuleRuntime under EdkModulePkg\Universal\Capsule\RuntimeDxe...
[mirror_edk2.git] / EdkModulePkg / Universal / Runtime / RuntimeDxe / Runtime.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 Runtime.c\r
15\r
16Abstract:\r
17\r
18 Runtime Architectural Protocol as defined in the DXE CIS\r
19\r
20 This code is used to produce the EFI runtime virtual switch over\r
21\r
22 THIS IS VERY DANGEROUS CODE BE VERY CAREFUL IF YOU CHANGE IT\r
23\r
24 The transition for calling EFI Runtime functions in physical mode to calling\r
25 them in virtual mode is very very complex. Every pointer in needs to be \r
26 converted from physical mode to virtual mode. Be very careful walking linked\r
27 lists! Then to make it really hard the code it's self needs be relocated into\r
28 the new virtual address space.\r
29\r
30 So here is the concept. The code in this module will never ever be called in\r
31 virtual mode. This is the code that collects the information needed to convert\r
32 to virtual mode (DXE core registers runtime stuff with this code). Since this \r
33 code is used to fixup all runtime images, it CAN NOT fix it's self up. So some\r
34 code has to stay behind and that is us.\r
35\r
36 Also you need to be careful about when you allocate memory, as once we are in \r
37 runtime (including our EVT_SIGNAL_EXIT_BOOT_SERVICES event) you can no longer \r
38 allocate memory.\r
39\r
40 Any runtime driver that gets loaded before us will not be callable in virtual \r
41 mode. This is due to the fact that the DXE core can not register the info \r
42 needed with us. This is good, since it keeps the code in this file from \r
43 getting registered.\r
44\r
45\r
46Revision History:\r
47\r
48 - Move the CalculateCrc32 function from Runtime Arch Protocol to Boot Service.\r
49 Runtime Arch Protocol definition no longer contains CalculateCrc32. Boot Service\r
50 Table now contains an item named CalculateCrc32.\r
51\r
52--*/\r
53\r
54\r
55#include "Runtime.h"\r
56\r
57//\r
58// This is a only short term solution.\r
59// There is a change coming to the Runtime AP that\r
60// will make it so the Runtime driver will not have to allocate any buffers. \r
61//\r
62#define MAX_RUNTIME_IMAGE_NUM (64)\r
63#define MAX_RUNTIME_EVENT_NUM (64)\r
64RUNTIME_IMAGE_RELOCATION_DATA mRuntimeImageBuffer[MAX_RUNTIME_IMAGE_NUM];\r
65RUNTIME_NOTIFY_EVENT_DATA mRuntimeEventBuffer[MAX_RUNTIME_EVENT_NUM];\r
66UINTN mRuntimeImageNumber;\r
67UINTN mRuntimeEventNumber;\r
68\r
69//\r
70// The handle onto which the Runtime Architectural Protocol instance is installed\r
71//\r
72EFI_HANDLE mRuntimeHandle = NULL;\r
73\r
74//\r
75// The Runtime Architectural Protocol instance produced by this driver\r
76//\r
77EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {\r
78 RuntimeDriverRegisterImage,\r
79 RuntimeDriverRegisterEvent\r
80};\r
81\r
82//\r
83// Global Variables\r
84//\r
85LIST_ENTRY mRelocationList = INITIALIZE_LIST_HEAD_VARIABLE(mRelocationList);\r
86LIST_ENTRY mEventList = INITIALIZE_LIST_HEAD_VARIABLE(mEventList);\r
87BOOLEAN mEfiVirtualMode = FALSE;\r
88EFI_GUID mLocalEfiUgaIoProtocolGuid = EFI_UGA_IO_PROTOCOL_GUID;\r
89EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;\r
90UINTN mVirtualMapDescriptorSize;\r
91UINTN mVirtualMapMaxIndex;\r
92\r
93EFI_LOADED_IMAGE_PROTOCOL *mMyLoadedImage;\r
94\r
045f4521 95#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
96STATIC EFI_GUID mEfiCapsuleHeaderGuid = EFI_CAPSULE_GUID;\r
97#endif\r
878ddf1f 98//\r
99// Worker Functions\r
100//\r
101VOID\r
102RuntimeDriverCalculateEfiHdrCrc (\r
103 IN OUT EFI_TABLE_HEADER *Hdr\r
104 )\r
105/*++\r
106\r
107Routine Description:\r
108\r
109 Calcualte the 32-bit CRC in a EFI table using the Runtime Drivers\r
110 internal function. The EFI Boot Services Table can not be used because\r
111 the EFI Boot Services Table was destroyed at ExitBootServices()\r
112\r
113Arguments:\r
114\r
115 Hdr - Pointer to an EFI standard header\r
116\r
117Returns:\r
118\r
119 None\r
120\r
121--*/\r
122{\r
123 UINT32 Crc;\r
124\r
125 Hdr->CRC32 = 0;\r
126\r
127 Crc = 0;\r
128 RuntimeDriverCalculateCrc32 ((UINT8 *) Hdr, Hdr->HeaderSize, &Crc);\r
129 Hdr->CRC32 = Crc;\r
130}\r
131\r
132EFI_STATUS\r
133EFIAPI\r
134RuntimeDriverRegisterImage (\r
135 IN EFI_RUNTIME_ARCH_PROTOCOL *This,\r
136 IN EFI_PHYSICAL_ADDRESS ImageBase,\r
137 IN UINTN ImageSize,\r
138 IN VOID *RelocationData\r
139 )\r
140/*++\r
141\r
142Routine Description:\r
143\r
144 When a SetVirtualAddressMap() is performed all the runtime images loaded by \r
145 DXE must be fixed up with the new virtual address map. To facilitate this the \r
146 Runtime Architectural Protocol needs to be informed of every runtime driver \r
147 that is registered. All the runtime images loaded by DXE should be registered \r
148 with this service by the DXE Core when ExitBootServices() is called. The \r
149 images that are registered with this service must have successfully been \r
150 loaded into memory with the Boot Service LoadImage(). As a result, no \r
151 parameter checking needs to be performed.\r
152\r
153Arguments:\r
154\r
155 This - The EFI_RUNTIME_ARCH_PROTOCOL instance. \r
156\r
157 ImageBase - Start of image that has been loaded in memory. It is either \r
158 a pointer to the DOS or PE header of the image.\r
159\r
160 ImageSize - Size of the image in bytes.\r
161\r
162 RelocationData - Information about the fixups that were performed on ImageBase \r
163 when it was loaded into memory. This information is needed \r
164 when the virtual mode fix-ups are reapplied so that data that \r
165 has been programmatically updated will not be fixed up. If \r
166 code updates a global variable the code is responsible for \r
167 fixing up the variable for virtual mode.\r
168\r
169Returns: \r
170\r
171 EFI_SUCCESS - The ImageBase has been registered.\r
172\r
173--*/\r
174{\r
175 RUNTIME_IMAGE_RELOCATION_DATA *RuntimeImage;\r
176\r
177 if (mMyLoadedImage->ImageBase == (VOID *) (UINTN) ImageBase) {\r
178 //\r
179 // We don't want to relocate our selves, as we only run in physical mode.\r
180 //\r
181 return EFI_SUCCESS;\r
182 }\r
183\r
184 RuntimeImage = &mRuntimeImageBuffer[mRuntimeImageNumber];\r
185 mRuntimeImageNumber++;\r
186 ASSERT (mRuntimeImageNumber < MAX_RUNTIME_IMAGE_NUM);\r
187\r
188 RuntimeImage->Valid = TRUE;\r
189 RuntimeImage->ImageBase = ImageBase;\r
190 RuntimeImage->ImageSize = ImageSize;\r
191 RuntimeImage->RelocationData = RelocationData;\r
192\r
193 InsertTailList (&mRelocationList, &RuntimeImage->Link);\r
194 return EFI_SUCCESS;\r
195}\r
196\r
197EFI_STATUS\r
198EFIAPI\r
199RuntimeDriverRegisterEvent (\r
200 IN EFI_RUNTIME_ARCH_PROTOCOL *This,\r
201 IN UINT32 Type,\r
202 IN EFI_TPL NotifyTpl,\r
203 IN EFI_EVENT_NOTIFY NotifyFunction,\r
204 IN VOID *NotifyContext,\r
205 IN EFI_EVENT *Event\r
206 )\r
207/*++\r
208\r
209Routine Description:\r
210\r
211 This function is used to support the required runtime events. Currently only \r
212 runtime events of type EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE needs to be \r
213 registered with this service. All the runtime events that exist in the DXE \r
214 Core should be registered with this service when ExitBootServices() is called. \r
215 All the events that are registered with this service must have been created \r
216 with the Boot Service CreateEvent(). As a result, no parameter checking needs \r
217 to be performed.\r
218\r
219Arguments:\r
220\r
221 This - The EFI_RUNTIME_ARCH_PROTOCOL instance. \r
222\r
223 Type - The same as Type passed into CreateEvent().\r
224\r
225 NotifyTpl - The same as NotifyTpl passed into CreateEvent().\r
226\r
227 NotifyFunction - The same as NotifyFunction passed into CreateEvent().\r
228\r
229 NotifyContext - The same as NotifyContext passed into CreateEvent().\r
230\r
231 Event - The EFI_EVENT returned by CreateEvent(). Event must be in \r
232 runtime memory.\r
233\r
234Returns: \r
235\r
236 EFI_SUCCESS - The Event has been registered.\r
237\r
238--*/\r
239{\r
240 RUNTIME_NOTIFY_EVENT_DATA *RuntimeEvent;\r
241\r
242 RuntimeEvent = &mRuntimeEventBuffer[mRuntimeEventNumber];\r
243 mRuntimeEventNumber++;\r
244 ASSERT (mRuntimeEventNumber < MAX_RUNTIME_EVENT_NUM);\r
245\r
246 RuntimeEvent->Type = Type;\r
247 RuntimeEvent->NotifyTpl = NotifyTpl;\r
248 RuntimeEvent->NotifyFunction = NotifyFunction;\r
249 RuntimeEvent->NotifyContext = NotifyContext;\r
250 RuntimeEvent->Event = Event;\r
251\r
252 InsertTailList (&mEventList, &RuntimeEvent->Link);\r
253 return EFI_SUCCESS;\r
254}\r
255\r
256EFI_STATUS\r
257EFIAPI\r
258RuntimeDriverConvertPointer (\r
259 IN UINTN DebugDisposition,\r
260 IN OUT VOID **ConvertAddress\r
261 )\r
262{\r
263 UINTN Address;\r
264 VOID *PlabelConvertAddress;\r
265 UINT64 VirtEndOfRange;\r
266 EFI_MEMORY_DESCRIPTOR *VirtEntry;\r
267 UINTN Index;\r
268\r
269 //\r
270 // Make sure ConvertAddress is a valid pointer\r
271 //\r
272 if (ConvertAddress == NULL) {\r
273 return EFI_INVALID_PARAMETER;\r
274 }\r
275 //\r
276 // Get the address to convert\r
277 //\r
278 Address = (UINTN) *ConvertAddress;\r
279\r
280 //\r
281 // If this is a null pointer, return if it's allowed\r
282 //\r
283 if (Address == 0) {\r
284 if (DebugDisposition & EFI_OPTIONAL_POINTER) {\r
285 return EFI_SUCCESS;\r
286 }\r
287\r
288 return EFI_INVALID_PARAMETER;\r
289 }\r
290\r
291 PlabelConvertAddress = NULL;\r
292 VirtEntry = mVirtualMap;\r
293 for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r
294 //\r
295 // To prevent the inclusion of 64-bit math functions a UINTN was placed in\r
296 // front of VirtEntry->NumberOfPages to cast it to a 32-bit thing on IA-32\r
297 // platforms. If you get this ASSERT remove the UINTN and do a 64-bit\r
298 // multiply.\r
299 //\r
300 ASSERT ((VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));\r
301\r
302 if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {\r
303 if (Address >= VirtEntry->PhysicalStart) {\r
304 VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN) VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);\r
305 if (Address < VirtEndOfRange) {\r
306 //\r
307 // Compute new address\r
308 //\r
309 *ConvertAddress = (VOID *) (Address - (UINTN) VirtEntry->PhysicalStart + (UINTN) VirtEntry->VirtualStart);\r
310 return EFI_SUCCESS;\r
311 } else if (Address < (VirtEndOfRange + 0x200000)) {\r
312 //\r
313 // On Itanium GP defines a window +/- 2 MB inside an image.\r
314 // The compiler may asign a GP value outside of the image. Thus\r
315 // it could fall out side of any of our valid regions\r
316 //\r
317 PlabelConvertAddress = (VOID *) (Address - (UINTN) VirtEntry->PhysicalStart + (UINTN) VirtEntry->VirtualStart);\r
318 }\r
319 }\r
320 }\r
321\r
322 VirtEntry = NextMemoryDescriptor (VirtEntry, mVirtualMapDescriptorSize);\r
323 }\r
324\r
325 if (DebugDisposition & EFI_IPF_GP_POINTER) {\r
326 //\r
327 // If it's an IPF GP and the GP was outside the image handle that case.\r
328 //\r
329 if (PlabelConvertAddress != NULL) {\r
330 *ConvertAddress = PlabelConvertAddress;\r
331 return EFI_SUCCESS;\r
332 }\r
333 }\r
334\r
335 return EFI_NOT_FOUND;\r
336}\r
337\r
338EFI_STATUS\r
339RuntimeDriverConvertInternalPointer (\r
340 IN OUT VOID **ConvertAddress\r
341 )\r
342{\r
343 return RuntimeDriverConvertPointer (0x0, ConvertAddress);\r
344}\r
345\r
346EFI_STATUS\r
347EFIAPI\r
348RuntimeDriverSetVirtualAddressMap (\r
349 IN UINTN MemoryMapSize,\r
350 IN UINTN DescriptorSize,\r
351 IN UINT32 DescriptorVersion,\r
352 IN EFI_MEMORY_DESCRIPTOR *VirtualMap\r
353 )\r
354{\r
355 RUNTIME_NOTIFY_EVENT_DATA *RuntimeEvent;\r
356 RUNTIME_IMAGE_RELOCATION_DATA *RuntimeImage;\r
357 LIST_ENTRY *Link;\r
358 UINTN Index;\r
359 UINTN Index1;\r
360 EFI_DRIVER_OS_HANDOFF_HEADER *DriverOsHandoffHeader;\r
361 EFI_DRIVER_OS_HANDOFF *DriverOsHandoff;\r
045f4521 362#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
363 EFI_CAPSULE_TABLE *CapsuleTable; \r
364#endif\r
878ddf1f 365\r
366 //\r
367 // Can only switch to virtual addresses once the memory map is locked down,\r
368 // and can only set it once\r
369 //\r
370 if (!EfiAtRuntime () || mEfiVirtualMode) {\r
371 return EFI_UNSUPPORTED;\r
372 }\r
373 //\r
374 // Only understand the original descriptor format\r
375 //\r
376 if (DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION || DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR)) {\r
377 return EFI_INVALID_PARAMETER;\r
378 }\r
379 //\r
380 // BugBug: Add code here to verify the memory map. We should\r
381 // cache a copy of the system memory map in the EFI System Table\r
382 // as a GUID pointer pair.\r
383 //\r
384 //\r
385 // Make sure all virtual translations are satisfied\r
386 //\r
387 mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;\r
388\r
389 //\r
390 // BugBug :The following code does not work hence commented out.\r
391 // Need to be replaced by something that works.\r
392 //\r
393 // VirtEntry = VirtualMap;\r
394 // for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r
395 // if (((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) &&\r
396 // (VirtEntry->VirtualStart != 0) ) {\r
397 // return EFI_NO_MAPPING;\r
398 // }\r
399 // VirtEntry = NextMemoryDescriptor(VirtEntry, DescriptorSize);\r
400 // }\r
401 //\r
402 // We are now committed to go to virtual mode, so lets get to it!\r
403 //\r
404 mEfiVirtualMode = TRUE;\r
405\r
406 //\r
407 // ConvertPointer() needs this mVirtualMap to do the conversion. So set up\r
408 // globals we need to parse the virtual address map.\r
409 //\r
410 mVirtualMapDescriptorSize = DescriptorSize;\r
411 mVirtualMap = VirtualMap;\r
412\r
413 //\r
414 // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.\r
415 // The core call RuntimeDriverRegisterEvent() for\r
416 // every runtime event and we stored them in the mEventList\r
417 //\r
418 //\r
419 // Currently the bug in StatusCode/RuntimeLib has been fixed, it will\r
420 // check whether in Runtime or not (this is judged by looking at\r
421 // mEfiAtRuntime global So this ReportStatusCode will work\r
422 //\r
423 REPORT_STATUS_CODE (\r
424 EFI_PROGRESS_CODE,\r
425 (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP)\r
426 );\r
427\r
428 //\r
429 // BugBug - Commented out for now because the status code driver is not\r
430 // ready for runtime yet. The Status Code driver calls data hub with does\r
431 // a bunch of Boot Service things (locks, AllocatePool) and hangs somewhere\r
432 // on the way.\r
433 //\r
434 // ReportStatusCode (\r
435 // EfiProgressCode, EfiMaxErrorSeverity,\r
436 // 0x03, 0x01, 12, // ReadyToBoot Progress code\r
437 // 0x00, 30, L"ConvertPointer"\r
438 // );\r
439 //\r
440 for (Link = mEventList.ForwardLink; Link != &mEventList; Link = Link->ForwardLink) {\r
441 RuntimeEvent = _CR (Link, RUNTIME_NOTIFY_EVENT_DATA, Link);\r
442 if ((RuntimeEvent->Type & EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {\r
443 RuntimeEvent->NotifyFunction (\r
444 RuntimeEvent->Event,\r
445 RuntimeEvent->NotifyContext\r
446 );\r
447 }\r
448 }\r
449 //\r
450 // Relocate runtime images. Runtime images loaded before the runtime AP was\r
451 // started will not be relocated, since they would not have gotten registered.\r
452 // This includes the code in this file.\r
453 //\r
454 for (Link = mRelocationList.ForwardLink; Link != &mRelocationList; Link = Link->ForwardLink) {\r
455 RuntimeImage = _CR (Link, RUNTIME_IMAGE_RELOCATION_DATA, Link);\r
456 if (RuntimeImage->Valid) {\r
457 RelocatePeImageForRuntime (RuntimeImage);\r
458 }\r
459 }\r
460 //\r
461 // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()\r
462 // and recompute the CRC-32\r
463 //\r
464 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetTime);\r
465 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetTime);\r
466 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetWakeupTime);\r
467 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetWakeupTime);\r
468 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ResetSystem);\r
469 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextHighMonotonicCount);\r
470 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetVariable);\r
471 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetVariable);\r
472 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextVariableName);\r
045f4521 473#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
474 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryVariableInfo);\r
475 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->UpdateCapsule);\r
476 RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryCapsuleCapabilities);\r
477#endif\r
878ddf1f 478 RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);\r
479\r
480 //\r
481 // Convert the UGA OS Handoff Table if it is present in the Configuration Table\r
482 //\r
483 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
484 if (CompareGuid (&mLocalEfiUgaIoProtocolGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
485 DriverOsHandoffHeader = gST->ConfigurationTable[Index].VendorTable;\r
486 for (Index1 = 0; Index1 < DriverOsHandoffHeader->NumberOfEntries; Index1++) {\r
487 DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)\r
488 (\r
489 (UINTN) DriverOsHandoffHeader +\r
490 DriverOsHandoffHeader->HeaderSize +\r
491 Index1 *\r
492 DriverOsHandoffHeader->SizeOfEntries\r
493 );\r
494 RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->DevicePath);\r
495 RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->PciRomImage);\r
496 }\r
497\r
498 RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r
499 }\r
045f4521 500#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
501 if (CompareGuid (&mEfiCapsuleHeaderGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
502 CapsuleTable = gST->ConfigurationTable[Index].VendorTable;\r
503 for (Index1 = 0; Index1 < CapsuleTable->CapsuleArrayNumber; Index1++) {\r
504 RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &CapsuleTable->CapsulePtr[Index1]);\r
505 } \r
506 RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r
507 }\r
508#endif\r
878ddf1f 509 }\r
510 //\r
511 // Convert the runtime fields of the EFI System Table and recompute the CRC-32\r
512 //\r
513 RuntimeDriverConvertInternalPointer ((VOID **) &gST->FirmwareVendor);\r
514 RuntimeDriverConvertInternalPointer ((VOID **) &gST->ConfigurationTable);\r
515 RuntimeDriverConvertInternalPointer ((VOID **) &gST->RuntimeServices);\r
516 RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);\r
517\r
518 //\r
519 // At this point, gRT and gST are physical pointers, but the contents of these tables\r
520 // have been converted to runtime.\r
521 //\r
522 //\r
523 // mVirtualMap is only valid during SetVirtualAddressMap() call\r
524 //\r
525 mVirtualMap = NULL;\r
526\r
527 return EFI_SUCCESS;\r
528}\r
529\r
530EFI_STATUS\r
531EFIAPI\r
532RuntimeDriverInitialize (\r
533 IN EFI_HANDLE ImageHandle,\r
534 IN EFI_SYSTEM_TABLE *SystemTable\r
535 )\r
536/*++\r
537\r
538Routine Description:\r
539 Install Runtime AP. This code includes the EfiDriverLib, but it functions at\r
540 RT in physical mode. The only Lib services are gBS, gRT, and the DEBUG and\r
541 ASSERT macros (they do ReportStatusCode).\r
542\r
543Arguments:\r
544 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
545\r
546Returns:\r
547\r
548 EFI_SUCEESS - Runtime Driver Architectural Protocol Installed\r
549\r
550 Other - Return value from gBS->InstallMultipleProtocolInterfaces\r
551\r
552--*/\r
553{\r
554 EFI_STATUS Status;\r
555\r
556 //\r
557 // This image needs to be exclued from relocation for virtual mode, so cache\r
558 // a copy of the Loaded Image protocol to test later.\r
559 //\r
560 Status = gBS->HandleProtocol (\r
561 ImageHandle,\r
562 &gEfiLoadedImageProtocolGuid,\r
563 (VOID **) &mMyLoadedImage\r
564 );\r
565 ASSERT_EFI_ERROR (Status);\r
566\r
567 //\r
568 // Initialize the table used to compute 32-bit CRCs\r
569 //\r
570 RuntimeDriverInitializeCrc32Table ();\r
571\r
572 //\r
573 // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r
574 //\r
575 gBS->CalculateCrc32 = RuntimeDriverCalculateCrc32;\r
576 gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;\r
577 gRT->ConvertPointer = RuntimeDriverConvertPointer;\r
578\r
579 //\r
580 // Install the Runtime Architectural Protocol onto a new handle\r
581 //\r
582 Status = gBS->InstallMultipleProtocolInterfaces (\r
583 &mRuntimeHandle,\r
584 &gEfiRuntimeArchProtocolGuid,\r
585 &mRuntime,\r
586 NULL\r
587 );\r
588 ASSERT_EFI_ERROR (Status);\r
589\r
590 mRuntimeImageNumber = 0;\r
591 mRuntimeEventNumber = 0;\r
592\r
593 return Status;\r
594}\r