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 | Runtime.c\r |
15 | \r |
16 | Abstract:\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 |
46 | Revision 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 |
64 | RUNTIME_IMAGE_RELOCATION_DATA mRuntimeImageBuffer[MAX_RUNTIME_IMAGE_NUM];\r |
65 | RUNTIME_NOTIFY_EVENT_DATA mRuntimeEventBuffer[MAX_RUNTIME_EVENT_NUM];\r |
66 | UINTN mRuntimeImageNumber;\r |
67 | UINTN mRuntimeEventNumber;\r |
68 | \r |
69 | //\r |
70 | // The handle onto which the Runtime Architectural Protocol instance is installed\r |
71 | //\r |
72 | EFI_HANDLE mRuntimeHandle = NULL;\r |
73 | \r |
74 | //\r |
75 | // The Runtime Architectural Protocol instance produced by this driver\r |
76 | //\r |
77 | EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {\r |
78 | RuntimeDriverRegisterImage,\r |
79 | RuntimeDriverRegisterEvent\r |
80 | };\r |
81 | \r |
82 | //\r |
83 | // Global Variables\r |
84 | //\r |
85 | LIST_ENTRY mRelocationList = INITIALIZE_LIST_HEAD_VARIABLE(mRelocationList);\r |
86 | LIST_ENTRY mEventList = INITIALIZE_LIST_HEAD_VARIABLE(mEventList);\r |
87 | BOOLEAN mEfiVirtualMode = FALSE;\r |
88 | EFI_GUID mLocalEfiUgaIoProtocolGuid = EFI_UGA_IO_PROTOCOL_GUID;\r |
89 | EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;\r |
90 | UINTN mVirtualMapDescriptorSize;\r |
91 | UINTN mVirtualMapMaxIndex;\r |
92 | \r |
93 | EFI_LOADED_IMAGE_PROTOCOL *mMyLoadedImage;\r |
94 | \r |
045f4521 |
95 | #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r |
96 | STATIC EFI_GUID mEfiCapsuleHeaderGuid = EFI_CAPSULE_GUID;\r |
97 | #endif\r |
878ddf1f |
98 | //\r |
99 | // Worker Functions\r |
100 | //\r |
101 | VOID\r |
102 | RuntimeDriverCalculateEfiHdrCrc (\r |
103 | IN OUT EFI_TABLE_HEADER *Hdr\r |
104 | )\r |
105 | /*++\r |
106 | \r |
107 | Routine 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 |
113 | Arguments:\r |
114 | \r |
115 | Hdr - Pointer to an EFI standard header\r |
116 | \r |
117 | Returns:\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 |
132 | EFI_STATUS\r |
133 | EFIAPI\r |
134 | RuntimeDriverRegisterImage (\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 |
142 | Routine 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 |
153 | Arguments:\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 |
169 | Returns: \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 |
197 | EFI_STATUS\r |
198 | EFIAPI\r |
199 | RuntimeDriverRegisterEvent (\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 |
209 | Routine 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 |
219 | Arguments:\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 |
234 | Returns: \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 |
256 | EFI_STATUS\r |
257 | EFIAPI\r |
258 | RuntimeDriverConvertPointer (\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 |
338 | EFI_STATUS\r |
339 | RuntimeDriverConvertInternalPointer (\r |
340 | IN OUT VOID **ConvertAddress\r |
341 | )\r |
342 | {\r |
343 | return RuntimeDriverConvertPointer (0x0, ConvertAddress);\r |
344 | }\r |
345 | \r |
346 | EFI_STATUS\r |
347 | EFIAPI\r |
348 | RuntimeDriverSetVirtualAddressMap (\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 |
2ce31132 |
355 | EFI_STATUS Status;\r |
878ddf1f |
356 | RUNTIME_NOTIFY_EVENT_DATA *RuntimeEvent;\r |
357 | RUNTIME_IMAGE_RELOCATION_DATA *RuntimeImage;\r |
358 | LIST_ENTRY *Link;\r |
359 | UINTN Index;\r |
360 | UINTN Index1;\r |
361 | EFI_DRIVER_OS_HANDOFF_HEADER *DriverOsHandoffHeader;\r |
362 | EFI_DRIVER_OS_HANDOFF *DriverOsHandoff;\r |
2ce31132 |
363 | EFI_PHYSICAL_ADDRESS VirtImageBase;\r |
045f4521 |
364 | #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r |
365 | EFI_CAPSULE_TABLE *CapsuleTable; \r |
366 | #endif\r |
878ddf1f |
367 | \r |
368 | //\r |
369 | // Can only switch to virtual addresses once the memory map is locked down,\r |
370 | // and can only set it once\r |
371 | //\r |
372 | if (!EfiAtRuntime () || mEfiVirtualMode) {\r |
373 | return EFI_UNSUPPORTED;\r |
374 | }\r |
375 | //\r |
376 | // Only understand the original descriptor format\r |
377 | //\r |
378 | if (DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION || DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR)) {\r |
379 | return EFI_INVALID_PARAMETER;\r |
380 | }\r |
381 | //\r |
382 | // BugBug: Add code here to verify the memory map. We should\r |
383 | // cache a copy of the system memory map in the EFI System Table\r |
384 | // as a GUID pointer pair.\r |
385 | //\r |
386 | //\r |
387 | // Make sure all virtual translations are satisfied\r |
388 | //\r |
389 | mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;\r |
390 | \r |
391 | //\r |
392 | // BugBug :The following code does not work hence commented out.\r |
393 | // Need to be replaced by something that works.\r |
394 | //\r |
395 | // VirtEntry = VirtualMap;\r |
396 | // for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r |
397 | // if (((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) &&\r |
398 | // (VirtEntry->VirtualStart != 0) ) {\r |
399 | // return EFI_NO_MAPPING;\r |
400 | // }\r |
401 | // VirtEntry = NextMemoryDescriptor(VirtEntry, DescriptorSize);\r |
402 | // }\r |
403 | //\r |
404 | // We are now committed to go to virtual mode, so lets get to it!\r |
405 | //\r |
406 | mEfiVirtualMode = TRUE;\r |
407 | \r |
408 | //\r |
409 | // ConvertPointer() needs this mVirtualMap to do the conversion. So set up\r |
410 | // globals we need to parse the virtual address map.\r |
411 | //\r |
412 | mVirtualMapDescriptorSize = DescriptorSize;\r |
413 | mVirtualMap = VirtualMap;\r |
414 | \r |
415 | //\r |
416 | // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.\r |
417 | // The core call RuntimeDriverRegisterEvent() for\r |
418 | // every runtime event and we stored them in the mEventList\r |
419 | //\r |
420 | //\r |
421 | // Currently the bug in StatusCode/RuntimeLib has been fixed, it will\r |
422 | // check whether in Runtime or not (this is judged by looking at\r |
423 | // mEfiAtRuntime global So this ReportStatusCode will work\r |
424 | //\r |
425 | REPORT_STATUS_CODE (\r |
426 | EFI_PROGRESS_CODE,\r |
427 | (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP)\r |
428 | );\r |
429 | \r |
430 | //\r |
431 | // BugBug - Commented out for now because the status code driver is not\r |
432 | // ready for runtime yet. The Status Code driver calls data hub with does\r |
433 | // a bunch of Boot Service things (locks, AllocatePool) and hangs somewhere\r |
434 | // on the way.\r |
435 | //\r |
436 | // ReportStatusCode (\r |
437 | // EfiProgressCode, EfiMaxErrorSeverity,\r |
438 | // 0x03, 0x01, 12, // ReadyToBoot Progress code\r |
439 | // 0x00, 30, L"ConvertPointer"\r |
440 | // );\r |
441 | //\r |
442 | for (Link = mEventList.ForwardLink; Link != &mEventList; Link = Link->ForwardLink) {\r |
443 | RuntimeEvent = _CR (Link, RUNTIME_NOTIFY_EVENT_DATA, Link);\r |
444 | if ((RuntimeEvent->Type & EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {\r |
445 | RuntimeEvent->NotifyFunction (\r |
446 | RuntimeEvent->Event,\r |
447 | RuntimeEvent->NotifyContext\r |
448 | );\r |
449 | }\r |
450 | }\r |
451 | //\r |
452 | // Relocate runtime images. Runtime images loaded before the runtime AP was\r |
453 | // started will not be relocated, since they would not have gotten registered.\r |
454 | // This includes the code in this file.\r |
455 | //\r |
456 | for (Link = mRelocationList.ForwardLink; Link != &mRelocationList; Link = Link->ForwardLink) {\r |
457 | RuntimeImage = _CR (Link, RUNTIME_IMAGE_RELOCATION_DATA, Link);\r |
458 | if (RuntimeImage->Valid) {\r |
2ce31132 |
459 | \r |
460 | VirtImageBase = RuntimeImage->ImageBase;\r |
461 | Status = RuntimeDriverConvertPointer (0, (VOID **) &VirtImageBase);\r |
462 | ASSERT_EFI_ERROR (Status);\r |
463 | \r |
464 | PeCoffLoaderRelocateImageForRuntime (\r |
465 | RuntimeImage->ImageBase,\r |
466 | VirtImageBase,\r |
467 | RuntimeImage->ImageSize,\r |
468 | RuntimeImage->RelocationData\r |
469 | );\r |
470 | \r |
471 | FlushCpuCache (RuntimeImage->ImageBase, (UINT64)RuntimeImage->ImageSize);\r |
878ddf1f |
472 | }\r |
473 | }\r |
474 | //\r |
475 | // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()\r |
476 | // and recompute the CRC-32\r |
477 | //\r |
478 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetTime);\r |
479 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetTime);\r |
480 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetWakeupTime);\r |
481 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetWakeupTime);\r |
482 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ResetSystem);\r |
483 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextHighMonotonicCount);\r |
484 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetVariable);\r |
485 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetVariable);\r |
486 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextVariableName);\r |
045f4521 |
487 | #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r |
488 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryVariableInfo);\r |
489 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->UpdateCapsule);\r |
490 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryCapsuleCapabilities);\r |
491 | #endif\r |
878ddf1f |
492 | RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);\r |
493 | \r |
494 | //\r |
495 | // Convert the UGA OS Handoff Table if it is present in the Configuration Table\r |
496 | //\r |
497 | for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r |
498 | if (CompareGuid (&mLocalEfiUgaIoProtocolGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r |
499 | DriverOsHandoffHeader = gST->ConfigurationTable[Index].VendorTable;\r |
500 | for (Index1 = 0; Index1 < DriverOsHandoffHeader->NumberOfEntries; Index1++) {\r |
501 | DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)\r |
502 | (\r |
503 | (UINTN) DriverOsHandoffHeader +\r |
504 | DriverOsHandoffHeader->HeaderSize +\r |
505 | Index1 *\r |
506 | DriverOsHandoffHeader->SizeOfEntries\r |
507 | );\r |
508 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->DevicePath);\r |
509 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->PciRomImage);\r |
510 | }\r |
511 | \r |
512 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r |
513 | }\r |
045f4521 |
514 | #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r |
515 | if (CompareGuid (&mEfiCapsuleHeaderGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r |
516 | CapsuleTable = gST->ConfigurationTable[Index].VendorTable;\r |
517 | for (Index1 = 0; Index1 < CapsuleTable->CapsuleArrayNumber; Index1++) {\r |
518 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &CapsuleTable->CapsulePtr[Index1]);\r |
519 | } \r |
520 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r |
521 | }\r |
522 | #endif\r |
878ddf1f |
523 | }\r |
524 | //\r |
525 | // Convert the runtime fields of the EFI System Table and recompute the CRC-32\r |
526 | //\r |
527 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->FirmwareVendor);\r |
528 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->ConfigurationTable);\r |
529 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->RuntimeServices);\r |
530 | RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);\r |
531 | \r |
532 | //\r |
533 | // At this point, gRT and gST are physical pointers, but the contents of these tables\r |
534 | // have been converted to runtime.\r |
535 | //\r |
536 | //\r |
537 | // mVirtualMap is only valid during SetVirtualAddressMap() call\r |
538 | //\r |
539 | mVirtualMap = NULL;\r |
540 | \r |
541 | return EFI_SUCCESS;\r |
542 | }\r |
543 | \r |
544 | EFI_STATUS\r |
545 | EFIAPI\r |
546 | RuntimeDriverInitialize (\r |
547 | IN EFI_HANDLE ImageHandle,\r |
548 | IN EFI_SYSTEM_TABLE *SystemTable\r |
549 | )\r |
550 | /*++\r |
551 | \r |
552 | Routine Description:\r |
553 | Install Runtime AP. This code includes the EfiDriverLib, but it functions at\r |
554 | RT in physical mode. The only Lib services are gBS, gRT, and the DEBUG and\r |
555 | ASSERT macros (they do ReportStatusCode).\r |
556 | \r |
557 | Arguments:\r |
558 | (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r |
559 | \r |
560 | Returns:\r |
561 | \r |
562 | EFI_SUCEESS - Runtime Driver Architectural Protocol Installed\r |
563 | \r |
564 | Other - Return value from gBS->InstallMultipleProtocolInterfaces\r |
565 | \r |
566 | --*/\r |
567 | {\r |
568 | EFI_STATUS Status;\r |
569 | \r |
570 | //\r |
571 | // This image needs to be exclued from relocation for virtual mode, so cache\r |
572 | // a copy of the Loaded Image protocol to test later.\r |
573 | //\r |
574 | Status = gBS->HandleProtocol (\r |
575 | ImageHandle,\r |
576 | &gEfiLoadedImageProtocolGuid,\r |
577 | (VOID **) &mMyLoadedImage\r |
578 | );\r |
579 | ASSERT_EFI_ERROR (Status);\r |
580 | \r |
581 | //\r |
582 | // Initialize the table used to compute 32-bit CRCs\r |
583 | //\r |
584 | RuntimeDriverInitializeCrc32Table ();\r |
585 | \r |
586 | //\r |
587 | // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r |
588 | //\r |
589 | gBS->CalculateCrc32 = RuntimeDriverCalculateCrc32;\r |
590 | gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;\r |
591 | gRT->ConvertPointer = RuntimeDriverConvertPointer;\r |
592 | \r |
593 | //\r |
594 | // Install the Runtime Architectural Protocol onto a new handle\r |
595 | //\r |
596 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
597 | &mRuntimeHandle,\r |
598 | &gEfiRuntimeArchProtocolGuid,\r |
599 | &mRuntime,\r |
600 | NULL\r |
601 | );\r |
602 | ASSERT_EFI_ERROR (Status);\r |
603 | \r |
604 | mRuntimeImageNumber = 0;\r |
605 | mRuntimeEventNumber = 0;\r |
606 | \r |
607 | return Status;\r |
608 | }\r |