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