]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/PlatformBdsDxe/BdsPlatform.c
remove the wrong comments.
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / BdsPlatform.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 BdsPlatform.c
15
16 Abstract:
17
18 This file include all platform action which can be customized
19 by IBV/OEM.
20
21 --*/
22
23 #include "Generic/Bds.h"
24 #include "BdsPlatform.h"
25 #include "Generic/BdsString.h"
26 #include "Generic/Language.h"
27 #include "Generic/FrontPage.h"
28
29 CHAR16 mFirmwareVendor[] = L"TianoCore.org";
30
31 EFI_EVENT mReadyToBootEvent;
32
33 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
34 { EfiACPIReclaimMemory, 0 },
35 { EfiACPIMemoryNVS, 0 },
36 { EfiReservedMemoryType, 0 },
37 { EfiRuntimeServicesData, 0 },
38 { EfiRuntimeServicesCode, 0 },
39 { EfiBootServicesCode, 0 },
40 { EfiBootServicesData, 0 },
41 { EfiLoaderCode, 0 },
42 { EfiLoaderData, 0 },
43 { EfiMaxMemoryType, 0 }
44 };
45
46 VOID
47 BdsSetMemoryTypeInformationVariable (
48 VOID
49 )
50 {
51 EFI_STATUS Status;
52 EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;
53 EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;
54 UINTN VariableSize;
55 BOOLEAN UpdateRequired;
56 UINTN Index;
57 UINTN Index1;
58 UINT32 Previous;
59 UINT32 Current;
60 UINT32 Next;
61 EFI_HOB_GUID_TYPE *Hob;
62
63 UpdateRequired = FALSE;
64
65 //
66 // Retrieve the current memory usage statistics. If they are not found, then
67 // no adjustments can be made to the Memory Type Information variable.
68 //
69 Status = EfiGetSystemConfigurationTable (&gEfiMemoryTypeInformationGuid, (VOID **)&CurrentMemoryTypeInformation);
70 if (EFI_ERROR (Status)) {
71 return;
72 }
73
74 //
75 // Get the Memory Type Information settings from a previous boot if they exist.
76 //
77 PreviousMemoryTypeInformation = BdsLibGetVariableAndSize (
78 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
79 &gEfiMemoryTypeInformationGuid,
80 &VariableSize
81 );
82
83 //
84 // If the previous Memory Type Information is not available, then set defaults
85 //
86 if (PreviousMemoryTypeInformation == NULL) {
87 Hob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);
88
89 if (Hob != NULL) {
90 PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (Hob);
91 VariableSize = GET_GUID_HOB_DATA_SIZE (Hob);
92 ASSERT (VariableSize == sizeof (mDefaultMemoryTypeInformation));
93 CopyMem (mDefaultMemoryTypeInformation, PreviousMemoryTypeInformation, VariableSize);
94 } else {
95 PreviousMemoryTypeInformation = mDefaultMemoryTypeInformation;
96 VariableSize = sizeof (mDefaultMemoryTypeInformation);
97 }
98 UpdateRequired = TRUE;
99 }
100
101 //
102 // Use a hueristic to adjust the Memory Type Information for the next boot
103 //
104 for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
105
106 Current = 0;
107 for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {
108 if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
109 Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;
110 break;
111 }
112 }
113
114 if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {
115 continue;
116 }
117
118 Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;
119
120 if (Current > Previous) {
121 Next = Current + (Current >> 2);
122 } else if (Current < (Previous >> 1)) {
123 Next = Previous - (Previous >> 2);
124 } else {
125 Next = Previous;
126 }
127 if (Next > 0 && Next <= 16) {
128 Next = 16;
129 }
130
131 if (Next != Previous) {
132 PreviousMemoryTypeInformation[Index].NumberOfPages = Next;
133 UpdateRequired = TRUE;
134 }
135 }
136
137 //
138 // If any changes were made to the Memory Type Information settings, then set the new variable value
139 //
140 if (UpdateRequired) {
141 Status = gRT->SetVariable (
142 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
143 &gEfiMemoryTypeInformationGuid,
144 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
145 VariableSize,
146 PreviousMemoryTypeInformation
147 );
148 }
149
150 return;
151 }
152
153
154 /*++
155
156 Routine Description:
157
158 This routine is a notification function for legayc boot or exit boot
159 service event. It will adjust the memory information for different
160 memory type and save them into the variables for next boot
161
162 Arguments:
163
164 Event - The event that triggered this notification function
165 Context - Pointer to the notification functions context
166
167 Returns:
168
169 None.
170
171 --*/
172 VOID
173 EFIAPI
174 BdsReadyToBootEvent (
175 EFI_EVENT Event,
176 VOID *Context
177 )
178 {
179 BdsSetMemoryTypeInformationVariable ();
180 }
181
182 //
183 // BDS Platform Functions
184 //
185 VOID
186 PlatformBdsInit (
187 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData
188 )
189 /*++
190
191 Routine Description:
192
193 Platform Bds init. Incude the platform firmware vendor, revision
194 and so crc check.
195
196 Arguments:
197
198 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
199
200 Returns:
201
202 None.
203
204 --*/
205 {
206 //
207 // set firmwarevendor, here can be IBV/OEM customize
208 //
209 gST->FirmwareVendor = AllocateRuntimeCopyPool (
210 sizeof (mFirmwareVendor),
211 &mFirmwareVendor
212 );
213 ASSERT (gST->FirmwareVendor != NULL);
214
215 gST->FirmwareRevision = FIRMWARE_REVISION;
216
217 //
218 // Fixup Tasble CRC after we updated Firmware Vendor and Revision
219 //
220 gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
221
222 //
223 // Create Ready To Boot event
224 //
225 EfiCreateEventReadyToBootEx (
226 TPL_CALLBACK,
227 BdsReadyToBootEvent,
228 NULL,
229 &mReadyToBootEvent
230 );
231
232 //
233 // Initialize the platform specific string and language
234 //
235 InitializeStringSupport ();
236 InitializeLanguage (TRUE);
237 InitializeFrontPage (FALSE);
238
239 }
240
241 EFI_STATUS
242 PlatformBdsConnectConsole (
243 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
244 )
245 /*++
246
247 Routine Description:
248
249 Connect the predefined platform default console device. Always try to find
250 and enable the vga device if have.
251
252 Arguments:
253
254 PlatformConsole - Predfined platform default console device array.
255
256 Returns:
257
258 EFI_SUCCESS - Success connect at least one ConIn and ConOut
259 device, there must have one ConOut device is
260 active vga device.
261
262 EFI_STATUS - Return the status of
263 BdsLibConnectAllDefaultConsoles ()
264
265 --*/
266 {
267 EFI_STATUS Status;
268 UINTN Index;
269
270 Index = 0;
271 Status = EFI_SUCCESS;
272
273 //
274 // Have chance to connect the platform default console,
275 // the platform default console is the minimue device group
276 // the platform should support
277 //
278 while (PlatformConsole[Index].DevicePath != NULL) {
279 //
280 // Update the console variable with the connect type
281 //
282 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
283 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
284 }
285
286 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
287 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
288 }
289
290 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
291 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
292 }
293
294 Index++;
295 }
296 //
297 // Connect the all the default console with current cosole variable
298 //
299 Status = BdsLibConnectAllDefaultConsoles ();
300 if (EFI_ERROR (Status)) {
301 return Status;
302 }
303
304 return EFI_SUCCESS;
305 }
306
307 VOID
308 PlatformBdsConnectSequence (
309 VOID
310 )
311 /*++
312
313 Routine Description:
314
315 Connect with predeined platform connect sequence,
316 the OEM/IBV can customize with their own connect sequence.
317
318 Arguments:
319
320 None.
321
322 Returns:
323
324 None.
325
326 --*/
327 {
328 UINTN Index;
329
330 Index = 0;
331
332 //
333 // Here we can get the customized platform connect sequence
334 // Notes: we can connect with new variable which record the
335 // last time boots connect device path sequence
336 //
337 while (gPlatformConnectSequence[Index] != NULL) {
338 //
339 // Build the platform boot option
340 //
341 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
342 Index++;
343 }
344
345 }
346
347 VOID
348 PlatformBdsGetDriverOption (
349 IN OUT LIST_ENTRY *BdsDriverLists
350 )
351 /*++
352
353 Routine Description:
354
355 Load the predefined driver option, OEM/IBV can customize this
356 to load their own drivers
357
358 Arguments:
359
360 BdsDriverLists - The header of the driver option link list.
361
362 Returns:
363
364 None.
365
366 --*/
367 {
368 UINTN Index;
369
370 Index = 0;
371
372 //
373 // Here we can get the customized platform driver option
374 //
375 while (gPlatformDriverOption[Index] != NULL) {
376 //
377 // Build the platform boot option
378 //
379 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
380 Index++;
381 }
382
383 }
384
385 VOID
386 PlatformBdsDiagnostics (
387 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
388 IN BOOLEAN QuietBoot
389 )
390 /*++
391
392 Routine Description:
393
394 Perform the platform diagnostic, such like test memory. OEM/IBV also
395 can customize this fuction to support specific platform diagnostic.
396
397 Arguments:
398
399 MemoryTestLevel - The memory test intensive level
400
401 QuietBoot - Indicate if need to enable the quiet boot
402
403 Returns:
404
405 None.
406
407 --*/
408 {
409 EFI_STATUS Status;
410
411 //
412 // Here we can decide if we need to show
413 // the diagnostics screen
414 // Notes: this quiet boot code should be remove
415 // from the graphic lib
416 //
417 if (QuietBoot) {
418 EnableQuietBoot (&gEfiDefaultBmpLogoGuid);
419 //
420 // Perform system diagnostic
421 //
422 Status = BdsMemoryTest (MemoryTestLevel);
423 if (EFI_ERROR (Status)) {
424 DisableQuietBoot ();
425 }
426
427 return ;
428 }
429 //
430 // Perform system diagnostic
431 //
432 Status = BdsMemoryTest (MemoryTestLevel);
433 }
434
435 VOID
436 PlatformBdsPolicyBehavior (
437 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,
438 IN OUT LIST_ENTRY *DriverOptionList,
439 IN OUT LIST_ENTRY *BootOptionList
440 )
441 /*++
442
443 Routine Description:
444
445 The function will excute with as the platform policy, current policy
446 is driven by boot mode. IBV/OEM can customize this code for their specific
447 policy action.
448
449 Arguments:
450
451 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
452
453 DriverOptionList - The header of the driver option link list
454
455 BootOptionList - The header of the boot option link list
456
457 Returns:
458
459 None.
460
461 --*/
462 {
463 EFI_STATUS Status;
464 UINT16 Timeout;
465
466 //
467 // Init the time out value
468 //
469 Timeout = BdsLibGetTimeout ();
470
471 //
472 // Load the driver option as the driver option list
473 //
474 PlatformBdsGetDriverOption (DriverOptionList);
475
476 //
477 // Get current Boot Mode
478 //
479 PrivateData->BootMode = GetBootModeHob();
480
481 //
482 // Go the different platform policy with different boot mode
483 // Notes: this part code can be change with the table policy
484 //
485 switch (PrivateData->BootMode) {
486
487 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
488 case BOOT_WITH_MINIMAL_CONFIGURATION:
489 //
490 // In no-configuration boot mode, we can connect the
491 // console directly.
492 //
493 BdsLibConnectAllDefaultConsoles ();
494 PlatformBdsDiagnostics (IGNORE, TRUE);
495
496 //
497 // Perform some platform specific connect sequence
498 //
499 PlatformBdsConnectSequence ();
500
501 //
502 // Notes: current time out = 0 can not enter the
503 // front page
504 //
505 PlatformBdsEnterFrontPage (Timeout, FALSE);
506
507 //
508 // Check the boot option with the boot option list
509 //
510 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
511 break;
512
513 case BOOT_ON_FLASH_UPDATE:
514 //
515 // Boot with the specific configuration
516 //
517 PlatformBdsConnectConsole (gPlatformConsole);
518 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
519 BdsLibConnectAll ();
520 ProcessCapsules (BOOT_ON_FLASH_UPDATE);
521 break;
522
523 case BOOT_IN_RECOVERY_MODE:
524 //
525 // In recovery mode, just connect platform console
526 // and show up the front page
527 //
528 PlatformBdsConnectConsole (gPlatformConsole);
529 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
530
531 //
532 // In recovery boot mode, we still enter to the
533 // frong page now
534 //
535 PlatformBdsEnterFrontPage (Timeout, FALSE);
536 break;
537
538 case BOOT_WITH_FULL_CONFIGURATION:
539 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
540 case BOOT_WITH_DEFAULT_SETTINGS:
541 default:
542 //
543 // Connect platform console
544 //
545 Status = PlatformBdsConnectConsole (gPlatformConsole);
546 if (EFI_ERROR (Status)) {
547 //
548 // Here OEM/IBV can customize with defined action
549 //
550 PlatformBdsNoConsoleAction ();
551 }
552
553 PlatformBdsDiagnostics (IGNORE, TRUE);
554
555 //
556 // Perform some platform specific connect sequence
557 //
558 PlatformBdsConnectSequence ();
559
560 //
561 // Give one chance to enter the setup if we
562 // have the time out
563 //
564 PlatformBdsEnterFrontPage (Timeout, FALSE);
565
566 //
567 // Here we have enough time to do the enumeration of boot device
568 //
569 BdsLibEnumerateAllBootOption (BootOptionList);
570 break;
571 }
572
573 return ;
574
575 }
576
577 VOID
578 PlatformBdsBootSuccess (
579 IN BDS_COMMON_OPTION *Option
580 )
581 /*++
582
583 Routine Description:
584
585 Hook point after a boot attempt succeeds. We don't expect a boot option to
586 return, so the UEFI 2.0 specification defines that you will default to an
587 interactive mode and stop processing the BootOrder list in this case. This
588 is alos a platform implementation and can be customized by IBV/OEM.
589
590 Arguments:
591
592 Option - Pointer to Boot Option that succeeded to boot.
593
594 Returns:
595
596 None.
597
598 --*/
599 {
600 CHAR16 *TmpStr;
601
602 //
603 // If Boot returned with EFI_SUCCESS and there is not in the boot device
604 // select loop then we need to pop up a UI and wait for user input.
605 //
606 TmpStr = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));
607 if (TmpStr != NULL) {
608 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
609 FreePool (TmpStr);
610 }
611 }
612
613 VOID
614 PlatformBdsBootFail (
615 IN BDS_COMMON_OPTION *Option,
616 IN EFI_STATUS Status,
617 IN CHAR16 *ExitData,
618 IN UINTN ExitDataSize
619 )
620 /*++
621
622 Routine Description:
623
624 Hook point after a boot attempt fails.
625
626 Arguments:
627
628 Option - Pointer to Boot Option that failed to boot.
629
630 Status - Status returned from failed boot.
631
632 ExitData - Exit data returned from failed boot.
633
634 ExitDataSize - Exit data size returned from failed boot.
635
636 Returns:
637
638 None.
639
640 --*/
641 {
642 CHAR16 *TmpStr;
643
644 //
645 // If Boot returned with failed status then we need to pop up a UI and wait
646 // for user input.
647 //
648 TmpStr = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));
649 if (TmpStr != NULL) {
650 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
651 FreePool (TmpStr);
652 }
653
654 }
655
656 EFI_STATUS
657 PlatformBdsNoConsoleAction (
658 VOID
659 )
660 /*++
661
662 Routine Description:
663
664 This function is remained for IBV/OEM to do some platform action,
665 if there no console device can be connected.
666
667 Arguments:
668
669 None.
670
671 Returns:
672
673 EFI_SUCCESS - Direct return success now.
674
675 --*/
676 {
677 return EFI_SUCCESS;
678 }