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