Clean up the following module msa files, they are edkmodule package ftwlit, Crc32Sect...
[mirror_edk2.git] / EdkUnixPkg / Dxe / PlatformBds / 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 "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 = EFI_FIRMWARE_REVISION;
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 if (EFI_ERROR (Status)) {
129 return Status;
130 }
131
132 return EFI_SUCCESS;
133 }
134
135 VOID
136 PlatformBdsConnectSequence (
137 VOID
138 )
139 /*++
140
141 Routine Description:
142
143 Connect with predeined platform connect sequence,
144 the OEM/IBV can customize with their own connect sequence.
145
146 Arguments:
147
148 None.
149
150 Returns:
151
152 None.
153
154 --*/
155 {
156 UINTN Index;
157
158 Index = 0;
159
160 //
161 // Here we can get the customized platform connect sequence
162 // Notes: we can connect with new variable which record the
163 // last time boots connect device path sequence
164 //
165 while (gPlatformConnectSequence[Index] != NULL) {
166 //
167 // Build the platform boot option
168 //
169 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
170 Index++;
171 }
172
173 }
174
175 VOID
176 PlatformBdsGetDriverOption (
177 IN OUT LIST_ENTRY *BdsDriverLists
178 )
179 /*++
180
181 Routine Description:
182
183 Load the predefined driver option, OEM/IBV can customize this
184 to load their own drivers
185
186 Arguments:
187
188 BdsDriverLists - The header of the driver option link list.
189
190 Returns:
191
192 None.
193
194 --*/
195 {
196 UINTN Index;
197
198 Index = 0;
199
200 //
201 // Here we can get the customized platform driver option
202 //
203 while (gPlatformDriverOption[Index] != NULL) {
204 //
205 // Build the platform boot option
206 //
207 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
208 Index++;
209 }
210
211 }
212
213 VOID
214 PlatformBdsDiagnostics (
215 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
216 IN BOOLEAN QuietBoot
217 )
218 /*++
219
220 Routine Description:
221
222 Perform the platform diagnostic, such like test memory. OEM/IBV also
223 can customize this fuction to support specific platform diagnostic.
224
225 Arguments:
226
227 MemoryTestLevel - The memory test intensive level
228
229 QuietBoot - Indicate if need to enable the quiet boot
230
231 Returns:
232
233 None.
234
235 --*/
236 {
237 EFI_STATUS Status;
238
239 //
240 // Here we can decide if we need to show
241 // the diagnostics screen
242 // Notes: this quiet boot code should be remove
243 // from the graphic lib
244 //
245 if (QuietBoot) {
246 EnableQuietBoot (&gEfiDefaultBmpLogoGuid);
247 //
248 // Perform system diagnostic
249 //
250 Status = BdsMemoryTest (MemoryTestLevel);
251 if (EFI_ERROR (Status)) {
252 DisableQuietBoot ();
253 }
254
255 return ;
256 }
257 //
258 // Perform system diagnostic
259 //
260 Status = BdsMemoryTest (MemoryTestLevel);
261 }
262
263 VOID
264 PlatformBdsPolicyBehavior (
265 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,
266 IN OUT LIST_ENTRY *DriverOptionList,
267 IN OUT LIST_ENTRY *BootOptionList
268 )
269 /*++
270
271 Routine Description:
272
273 The function will excute with as the platform policy, current policy
274 is driven by boot mode. IBV/OEM can customize this code for their specific
275 policy action.
276
277 Arguments:
278
279 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
280
281 DriverOptionList - The header of the driver option link list
282
283 BootOptionList - The header of the boot option link list
284
285 Returns:
286
287 None.
288
289 --*/
290 {
291 EFI_STATUS Status;
292 UINT16 Timeout;
293
294 //
295 // Init the time out value
296 //
297 Timeout = BdsLibGetTimeout ();
298
299 //
300 // Load the driver option as the driver option list
301 //
302 PlatformBdsGetDriverOption (DriverOptionList);
303
304 //
305 // Get current Boot Mode
306 //
307 PrivateData->BootMode = GetBootModeHob();
308
309 //
310 // Go the different platform policy with different boot mode
311 // Notes: this part code can be change with the table policy
312 //
313 switch (PrivateData->BootMode) {
314
315 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
316 case BOOT_WITH_MINIMAL_CONFIGURATION:
317 //
318 // In no-configuration boot mode, we can connect the
319 // console directly.
320 //
321 BdsLibConnectAllDefaultConsoles ();
322 PlatformBdsDiagnostics (IGNORE, TRUE);
323
324 //
325 // Perform some platform specific connect sequence
326 //
327 PlatformBdsConnectSequence ();
328
329 //
330 // Notes: current time out = 0 can not enter the
331 // front page
332 //
333 PlatformBdsEnterFrontPage (Timeout, FALSE);
334
335 //
336 // Check the boot option with the boot option list
337 //
338 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
339 break;
340
341 case BOOT_ON_FLASH_UPDATE:
342 //
343 // Boot with the specific configuration
344 //
345 PlatformBdsConnectConsole (gPlatformConsole);
346 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
347 BdsLibConnectAll ();
348 ProcessCapsules (BOOT_ON_FLASH_UPDATE);
349 break;
350
351 case BOOT_IN_RECOVERY_MODE:
352 //
353 // In recovery mode, just connect platform console
354 // and show up the front page
355 //
356 PlatformBdsConnectConsole (gPlatformConsole);
357 PlatformBdsDiagnostics (EXTENSIVE, FALSE);
358
359 //
360 // In recovery boot mode, we still enter to the
361 // frong page now
362 //
363 PlatformBdsEnterFrontPage (Timeout, FALSE);
364 break;
365
366 case BOOT_WITH_FULL_CONFIGURATION:
367 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
368 case BOOT_WITH_DEFAULT_SETTINGS:
369 default:
370 //
371 // Connect platform console
372 //
373 Status = PlatformBdsConnectConsole (gPlatformConsole);
374 if (EFI_ERROR (Status)) {
375 //
376 // Here OEM/IBV can customize with defined action
377 //
378 PlatformBdsNoConsoleAction ();
379 }
380
381 PlatformBdsDiagnostics (IGNORE, TRUE);
382
383 //
384 // Perform some platform specific connect sequence
385 //
386 PlatformBdsConnectSequence ();
387
388 //
389 // Give one chance to enter the setup if we
390 // have the time out
391 //
392 PlatformBdsEnterFrontPage (Timeout, FALSE);
393
394 //
395 // Here we have enough time to do the enumeration of boot device
396 //
397 BdsLibEnumerateAllBootOption (BootOptionList);
398 break;
399 }
400
401 return ;
402
403 }
404
405 EFI_STATUS
406 PlatformBdsNoConsoleAction (
407 VOID
408 )
409 /*++
410
411 Routine Description:
412
413 This function is remained for IBV/OEM to do some platform action,
414 if there no console device can be connected.
415
416 Arguments:
417
418 None.
419
420 Returns:
421
422 EFI_SUCCESS - Direct return success now.
423
424 --*/
425 {
426 return EFI_SUCCESS;
427 }