]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/Nt32BdsLib/BdsPlatform.c
Update Nt32 platform to use dynamic HII pcd to save console output mode.
[mirror_edk2.git] / Nt32Pkg / Library / Nt32BdsLib / BdsPlatform.c
1 /**@file
2
3 Copyright (c) 2004 - 2006, 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 "BdsPlatform.h"
24
25 CHAR16 mFirmwareVendor[] = L"TianoCore.org";
26 WIN_NT_SYSTEM_CONFIGURATION mSystemConfigData;
27
28 VOID
29 SetupVariableInit (
30 VOID
31 )
32 {
33 EFI_STATUS Status;
34 UINTN Size;
35
36 Size = sizeof (mSystemConfigData);
37 Status = gRT->GetVariable (
38 L"Setup",
39 &gEfiWinNtSystemConfigGuid,
40 NULL,
41 &Size,
42 (VOID *) &mSystemConfigData
43 );
44
45 if (EFI_ERROR (Status)) {
46 //
47 // SetupVariable is corrupt
48 //
49 mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);
50 mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);
51
52 Status = gRT->SetVariable (
53 L"Setup",
54 &gEfiWinNtSystemConfigGuid,
55 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
56 sizeof (mSystemConfigData),
57 (VOID *) &mSystemConfigData
58 );
59 if (EFI_ERROR (Status)) {
60 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));
61 }
62 }
63 }
64
65 //
66 // BDS Platform Functions
67 //
68 VOID
69 PlatformBdsInit (
70 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData
71 )
72 /*++
73
74 Routine Description:
75
76 Platform Bds init. Include the platform firmware vendor, revision
77 and so crc check.
78
79 Arguments:
80
81 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
82
83 Returns:
84
85 None.
86
87 --*/
88 {
89 //
90 // set firmwarevendor, here can be IBV/OEM customize
91 //
92 gST->FirmwareVendor = AllocateRuntimeCopyPool (
93 sizeof (mFirmwareVendor),
94 &mFirmwareVendor
95 );
96 ASSERT (gST->FirmwareVendor != NULL);
97
98 gST->FirmwareRevision = 0;
99
100 //
101 // Fixup Tasble CRC after we updated Firmware Vendor and Revision
102 //
103 gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
104
105 SetupVariableInit ();
106 }
107
108 EFI_STATUS
109 PlatformBdsConnectConsole (
110 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
111 )
112 /*++
113
114 Routine Description:
115
116 Connect the predefined platform default console device. Always try to find
117 and enable the vga device if have.
118
119 Arguments:
120
121 PlatformConsole - Predfined platform default console device array.
122
123 Returns:
124
125 EFI_SUCCESS - Success connect at least one ConIn and ConOut
126 device, there must have one ConOut device is
127 active vga device.
128
129 EFI_STATUS - Return the status of
130 BdsLibConnectAllDefaultConsoles ()
131
132 --*/
133 {
134 EFI_STATUS Status;
135 UINTN Index;
136
137 Index = 0;
138 Status = EFI_SUCCESS;
139
140 //
141 // Have chance to connect the platform default console,
142 // the platform default console is the minimue device group
143 // the platform should support
144 //
145 while (PlatformConsole[Index].DevicePath != NULL) {
146 //
147 // Update the console variable with the connect type
148 //
149 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
150 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
151 }
152
153 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
154 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
155 }
156
157 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
158 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
159 }
160
161 Index++;
162 }
163 //
164 // Connect the all the default console with current cosole variable
165 //
166 Status = BdsLibConnectAllDefaultConsoles ();
167
168 return Status;
169 }
170
171 VOID
172 PlatformBdsConnectSequence (
173 VOID
174 )
175 /*++
176
177 Routine Description:
178
179 Connect with predeined platform connect sequence,
180 the OEM/IBV can customize with their own connect sequence.
181
182 Arguments:
183
184 None.
185
186 Returns:
187
188 None.
189
190 --*/
191 {
192 UINTN Index;
193
194 Index = 0;
195
196 //
197 // Here we can get the customized platform connect sequence
198 // Notes: we can connect with new variable which record the
199 // last time boots connect device path sequence
200 //
201 while (gPlatformConnectSequence[Index] != NULL) {
202 //
203 // Build the platform boot option
204 //
205 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
206 Index++;
207 }
208
209 //
210 // Jst use the simple policy to connect all devices
211 //
212 BdsLibConnectAll ();
213 }
214
215 VOID
216 PlatformBdsGetDriverOption (
217 IN OUT LIST_ENTRY *BdsDriverLists
218 )
219 /*++
220
221 Routine Description:
222
223 Load the predefined driver option, OEM/IBV can customize this
224 to load their own drivers
225
226 Arguments:
227
228 BdsDriverLists - The header of the driver option link list.
229
230 Returns:
231
232 None.
233
234 --*/
235 {
236 UINTN Index;
237
238 Index = 0;
239
240 //
241 // Here we can get the customized platform driver option
242 //
243 while (gPlatformDriverOption[Index] != NULL) {
244 //
245 // Build the platform boot option
246 //
247 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
248 Index++;
249 }
250
251 }
252
253 VOID
254 PlatformBdsDiagnostics (
255 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
256 IN BOOLEAN QuietBoot
257 )
258 /*++
259
260 Routine Description:
261
262 Perform the platform diagnostic, such like test memory. OEM/IBV also
263 can customize this fuction to support specific platform diagnostic.
264
265 Arguments:
266
267 MemoryTestLevel - The memory test intensive level
268
269 QuietBoot - Indicate if need to enable the quiet boot
270
271 Returns:
272
273 None.
274
275 --*/
276 {
277 EFI_STATUS Status;
278
279 //
280 // Here we can decide if we need to show
281 // the diagnostics screen
282 // Notes: this quiet boot code should be remove
283 // from the graphic lib
284 //
285 if (QuietBoot) {
286 EnableQuietBoot (&gEfiDefaultBmpLogoGuid);
287 //
288 // Perform system diagnostic
289 //
290 Status = BdsMemoryTest (MemoryTestLevel);
291 if (EFI_ERROR (Status)) {
292 DisableQuietBoot ();
293 }
294
295 return ;
296 }
297 //
298 // Perform system diagnostic
299 //
300 Status = BdsMemoryTest (MemoryTestLevel);
301 }
302
303 VOID
304 PlatformBdsPolicyBehavior (
305 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,
306 IN OUT LIST_ENTRY *DriverOptionList,
307 IN OUT LIST_ENTRY *BootOptionList
308 )
309 /*++
310
311 Routine Description:
312
313 The function will excute with as the platform policy, current policy
314 is driven by boot mode. IBV/OEM can customize this code for their specific
315 policy action.
316
317 Arguments:
318
319 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
320
321 DriverOptionList - The header of the driver option link list
322
323 BootOptionList - The header of the boot option link list
324
325 Returns:
326
327 None.
328
329 --*/
330 {
331 EFI_STATUS Status;
332 UINT16 Timeout;
333
334 //
335 // Init the time out value
336 //
337 Timeout = BdsLibGetTimeout ();
338
339 //
340 // Load the driver option as the driver option list
341 //
342 PlatformBdsGetDriverOption (DriverOptionList);
343
344 //
345 // Get current Boot Mode
346 //
347 Status = BdsLibGetBootMode (&PrivateData->BootMode);
348
349 //
350 // Go the different platform policy with different boot mode
351 // Notes: this part code can be change with the table policy
352 //
353 switch (PrivateData->BootMode) {
354
355 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
356 case BOOT_WITH_MINIMAL_CONFIGURATION:
357 //
358 // In no-configuration boot mode, we can connect the
359 // console directly.
360 //
361 BdsLibConnectAllDefaultConsoles ();
362 PlatformBdsDiagnostics ((EXTENDMEM_COVERAGE_LEVEL)IGNORE, TRUE);
363
364 //
365 // Perform some platform specific connect sequence
366 //
367 PlatformBdsConnectSequence ();
368
369 //
370 // Notes: current time out = 0 can not enter the
371 // front page
372 //
373 PlatformBdsEnterFrontPage (Timeout, FALSE);
374
375 //
376 // Check the boot option with the boot option list
377 //
378 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
379 break;
380
381 case BOOT_ON_FLASH_UPDATE:
382 //
383 // Boot with the specific configuration
384 //
385 PlatformBdsConnectConsole (gPlatformConsole);
386 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
387 BdsLibConnectAll ();
388 ProcessCapsules (BOOT_ON_FLASH_UPDATE);
389 break;
390
391 case BOOT_IN_RECOVERY_MODE:
392 //
393 // In recovery mode, just connect platform console
394 // and show up the front page
395 //
396 PlatformBdsConnectConsole (gPlatformConsole);
397 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
398
399 //
400 // In recovery boot mode, we still enter to the
401 // frong page now
402 //
403 PlatformBdsEnterFrontPage (Timeout, FALSE);
404 break;
405
406 case BOOT_WITH_FULL_CONFIGURATION:
407 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
408 case BOOT_WITH_DEFAULT_SETTINGS:
409 default:
410 //
411 // Connect platform console
412 //
413 Status = PlatformBdsConnectConsole (gPlatformConsole);
414 if (EFI_ERROR (Status)) {
415 //
416 // Here OEM/IBV can customize with defined action
417 //
418 PlatformBdsNoConsoleAction ();
419 }
420
421 PlatformBdsDiagnostics ((EXTENDMEM_COVERAGE_LEVEL)IGNORE, TRUE);
422
423 //
424 // Perform some platform specific connect sequence
425 //
426 PlatformBdsConnectSequence ();
427
428 //
429 // Give one chance to enter the setup if we
430 // have the time out
431 //
432 PlatformBdsEnterFrontPage (Timeout, FALSE);
433
434 //
435 // Here we have enough time to do the enumeration of boot device
436 //
437 BdsLibEnumerateAllBootOption (BootOptionList);
438 break;
439 }
440
441 return ;
442
443 }
444
445 VOID
446 PlatformBdsBootSuccess (
447 IN BDS_COMMON_OPTION *Option
448 )
449 /*++
450
451 Routine Description:
452
453 Hook point after a boot attempt succeeds. We don't expect a boot option to
454 return, so the EFI 1.0 specification defines that you will default to an
455 interactive mode and stop processing the BootOrder list in this case. This
456 is alos a platform implementation and can be customized by IBV/OEM.
457
458 Arguments:
459
460 Option - Pointer to Boot Option that succeeded to boot.
461
462 Returns:
463
464 None.
465
466 --*/
467 {
468 CHAR16 *TmpStr;
469
470 //
471 // If Boot returned with EFI_SUCCESS and there is not in the boot device
472 // select loop then we need to pop up a UI and wait for user input.
473 //
474 TmpStr = Option->StatusString;
475 if (TmpStr != NULL) {
476 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
477 FreePool (TmpStr);
478 }
479 }
480
481 VOID
482 PlatformBdsBootFail (
483 IN BDS_COMMON_OPTION *Option,
484 IN EFI_STATUS Status,
485 IN CHAR16 *ExitData,
486 IN UINTN ExitDataSize
487 )
488 /*++
489
490 Routine Description:
491
492 Hook point after a boot attempt fails.
493
494 Arguments:
495
496 Option - Pointer to Boot Option that failed to boot.
497
498 Status - Status returned from failed boot.
499
500 ExitData - Exit data returned from failed boot.
501
502 ExitDataSize - Exit data size returned from failed boot.
503
504 Returns:
505
506 None.
507
508 --*/
509 {
510 CHAR16 *TmpStr;
511
512 //
513 // If Boot returned with failed status then we need to pop up a UI and wait
514 // for user input.
515 //
516 TmpStr = Option->StatusString;
517 if (TmpStr != NULL) {
518 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
519 FreePool (TmpStr);
520 }
521
522 }
523
524 EFI_STATUS
525 PlatformBdsNoConsoleAction (
526 VOID
527 )
528 /*++
529
530 Routine Description:
531
532 This function is remained for IBV/OEM to do some platform action,
533 if there no console device can be connected.
534
535 Arguments:
536
537 None.
538
539 Returns:
540
541 EFI_SUCCESS - Direct return success now.
542
543 --*/
544 {
545 return EFI_SUCCESS;
546 }
547
548 EFI_STATUS
549 EFIAPI
550 PlatformBdsLockNonUpdatableFlash (
551 VOID
552 )
553 {
554 return EFI_SUCCESS;
555 }