1 /*++
2 
3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 
24 Module Name:
25 
26   BdsPlatform.h
27 
28 Abstract:
29 
30   Head file for BDS Platform specific code
31 
32 --*/
33 
34 #ifndef _BDS_PLATFORM_H
35 #define _BDS_PLATFORM_H
36 
37 #include <FrameworkDxe.h>
38 
39 #include <Protocol/FirmwareVolume2.h>
40 #include <Protocol/DevicePath.h>
41 #include <Protocol/SimpleNetwork.h>
42 #include <Protocol/PciRootBridgeIo.h>
43 #include <Protocol/LoadFile.h>
44 #include <Protocol/LegacyBios.h>
45 #include <Protocol/PciIo.h>
46 #include <Protocol/SmmAccess2.h>
47 #include <Protocol/DxeSmmReadyToLock.h>
48 #include <Protocol/UserManager.h>
49 #include <Protocol/DeferredImageLoad.h>
50 #include <Protocol/AcpiS3Save.h>
51 #include <Protocol/ExitPmAuth.h>
52 #include <Protocol/MmioDevice.h>
53 #include <Protocol/I2cBusMcg.h>
54 #include <Protocol/I2cHostMcg.h>
55 #include <Guid/CapsuleVendor.h>
56 #include <Guid/MemoryTypeInformation.h>
57 #include <Guid/GlobalVariable.h>
58 
59 
60 #include <Library/DebugLib.h>
61 #include <Library/BaseMemoryLib.h>
62 #include <Library/UefiBootServicesTableLib.h>
63 #include <Library/UefiRuntimeServicesTableLib.h>
64 #include <Library/MemoryAllocationLib.h>
65 #include <Library/BaseLib.h>
66 #include <Library/PcdLib.h>
67 #include <Library/IoLib.h>
68 #include <Library/GenericBdsLib.h>
69 #include <Library/PlatformBdsLib.h>
70 #include <Library/DevicePathLib.h>
71 #include <Library/UefiLib.h>
72 #include <Library/HobLib.h>
73 #include <Library/PrintLib.h>
74 #include <Library/PerformanceLib.h>
75 #include <Library/ReportStatusCodeLib.h>
76 
77 #include <IndustryStandard/Pci.h>
78 
79 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformRootBridges [];
80 extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole [];
81 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformAllPossiblePciVgaConsole [];
82 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformConnectSequence [];
83 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformDriverOption [];
84 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformBootOption [];
85 extern EFI_DEVICE_PATH_PROTOCOL  *gUserAuthenticationDevice[];
86 extern BDS_CONSOLE_CONNECT_ENTRY gPlatformSimpleConsole [];
87 extern EFI_DEVICE_PATH_PROTOCOL  *gPlatformSimpleBootOption [];
88 
89 extern BOOLEAN mEnumBootDevice;
90 
91 
92 //
93 // the short form device path for Usb keyboard
94 //
95 #define CLASS_HID           3
96 #define SUBCLASS_BOOT       1
97 #define PROTOCOL_KEYBOARD   1
98 
99 #define PCI_DEVICE_PATH_NODE(Func, Dev) \
100   { \
101     HARDWARE_DEVICE_PATH, \
102     HW_PCI_DP, \
103     { \
104       (UINT8) (sizeof (PCI_DEVICE_PATH)), \
105       (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
106     }, \
107     (Func), \
108     (Dev) \
109   }
110 
111 #define PNPID_DEVICE_PATH_NODE(PnpId) \
112   { \
113     { \
114       ACPI_DEVICE_PATH, \
115       ACPI_DP, \
116       { \
117         (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
118         (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
119       } \
120     }, \
121     EISA_PNP_ID((PnpId)), \
122     0 \
123   }
124 
125 #define gUart(BaudRate, DataBits, Parity, StopBits) \
126   { \
127     { \
128       MESSAGING_DEVICE_PATH, \
129       MSG_UART_DP, \
130       { \
131         (UINT8) (sizeof (UART_DEVICE_PATH)), \
132         (UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) \
133       } \
134     }, \
135     0, \
136     (BaudRate), \
137     (DataBits), \
138     (Parity), \
139     (StopBits) \
140   }
141 
142 #define gPcAnsiTerminal \
143   { \
144     { \
145       MESSAGING_DEVICE_PATH, \
146       MSG_VENDOR_DP, \
147       { \
148         (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \
149         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
150       } \
151     }, \
152     DEVICE_PATH_MESSAGING_PC_ANSI \
153   }
154 
155 #define gUsbKeyboardMouse \
156   { \
157     { \
158       MESSAGING_DEVICE_PATH, \
159       MSG_USB_CLASS_DP, \
160       (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)), \
161       (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8) \
162     }, \
163     0xffff, \
164     0xffff, \
165     CLASS_HID, \
166     SUBCLASS_BOOT, \
167     PROTOCOL_KEYBOARD \
168   }
169 
170 #define gEndEntire \
171   { \
172     END_DEVICE_PATH_TYPE, \
173     END_ENTIRE_DEVICE_PATH_SUBTYPE, \
174     { \
175       END_DEVICE_PATH_LENGTH, \
176       0 \
177     } \
178   }
179 
180 #define gPciRootBridge \
181   PNPID_DEVICE_PATH_NODE(0x0A03)
182 
183 #define gPnpPs2Keyboard \
184   PNPID_DEVICE_PATH_NODE(0x0303)
185 
186 #define gPnp16550ComPort \
187   PNPID_DEVICE_PATH_NODE(0x0501)
188 
189 #define gPciePort0Bridge \
190   PCI_DEVICE_PATH_NODE(0, 0x1C)
191 
192 #define gPciePort1Bridge \
193   PCI_DEVICE_PATH_NODE(1, 0x1C)
194 
195 #define gPciePort2Bridge \
196   PCI_DEVICE_PATH_NODE(2, 0x1C)
197 
198 #define gPciePort3Bridge \
199   PCI_DEVICE_PATH_NODE(3, 0x1C)
200 
201 #define gPciIsaBridge \
202   PCI_DEVICE_PATH_NODE(0, 0x1f)
203 
204 //
205 // Platform Root Bridge
206 //
207 typedef struct {
208   ACPI_HID_DEVICE_PATH      PciRootBridge;
209   EFI_DEVICE_PATH_PROTOCOL  End;
210 } PLATFORM_ROOT_BRIDGE_DEVICE_PATH;
211 
212 //
213 // Below is the platform console device path
214 //
215 typedef struct {
216   ACPI_HID_DEVICE_PATH      PciRootBridge;
217   PCI_DEVICE_PATH           IsaBridge;
218   ACPI_HID_DEVICE_PATH      Keyboard;
219   EFI_DEVICE_PATH_PROTOCOL  End;
220 } PLATFORM_ISA_KEYBOARD_DEVICE_PATH;
221 
222 typedef struct {
223   VENDOR_DEVICE_PATH             VendorDevicePath;
224   EFI_DEVICE_PATH_PROTOCOL       End;
225 } HII_VENDOR_DEVICE_PATH;
226 
227 typedef struct {
228   USB_CLASS_DEVICE_PATH           UsbClass;
229   EFI_DEVICE_PATH_PROTOCOL        End;
230 } USB_CLASS_FORMAT_DEVICE_PATH;
231 
232 typedef struct {
233   ACPI_HID_DEVICE_PATH      PciRootBridge;
234   PCI_DEVICE_PATH           OnboardVga;
235   EFI_DEVICE_PATH_PROTOCOL  End;
236 } PLATFORM_ONBOARD_VGA_DEVICE_PATH;
237 
238 typedef struct {
239   ACPI_HID_DEVICE_PATH      PciRootBridge;
240   PCI_DEVICE_PATH           AgpBridge;
241   PCI_DEVICE_PATH           AgpDevice;
242   EFI_DEVICE_PATH_PROTOCOL  End;
243 } PLATFORM_OFFBOARD_VGA_DEVICE_PATH;
244 
245 typedef struct {
246   ACPI_HID_DEVICE_PATH      PciRootBridge;
247   PCI_DEVICE_PATH           IsaBridge;
248   ACPI_HID_DEVICE_PATH      IsaSerial;
249   UART_DEVICE_PATH          Uart;
250   VENDOR_DEVICE_PATH        TerminalType;
251   EFI_DEVICE_PATH_PROTOCOL  End;
252 } PLATFORM_ISA_SERIAL_DEVICE_PATH;
253 
254 //
255 // Below is the boot option device path
256 //
257 typedef struct {
258   BBS_BBS_DEVICE_PATH             LegacyHD;
259   EFI_DEVICE_PATH_PROTOCOL        End;
260 } LEGACY_HD_DEVICE_PATH;
261 
262 //
263 // Below is the platform IDE device path
264 //
265 typedef struct {
266   ACPI_HID_DEVICE_PATH      PciRootBridge;
267   PCI_DEVICE_PATH           IsaBridge;
268   ATAPI_DEVICE_PATH         Ide;
269   EFI_DEVICE_PATH_PROTOCOL  End;
270 } PLATFORM_IDE_DEVICE_PATH;
271 
272 //
273 // Floppy device path definition
274 //
275 typedef struct {
276   ACPI_HID_DEVICE_PATH      PciRootBridge;
277   PCI_DEVICE_PATH           IsaBridge;
278   ACPI_HID_DEVICE_PATH      Floppy;
279   EFI_DEVICE_PATH_PROTOCOL  End;
280 } PLATFORM_FLOPPY_DEVICE_PATH;
281 
282 //
283 // Below is the platform USB controller device path for
284 // USB disk as user authentication device.
285 //
286 typedef struct {
287   ACPI_HID_DEVICE_PATH      PciRootBridge;
288   PCI_DEVICE_PATH           PciDevice;
289   EFI_DEVICE_PATH_PROTOCOL  End;
290 } PLATFORM_USB_DEVICE_PATH;
291 
292 //
293 // Below is the platform PCI device path
294 //
295 typedef struct {
296   ACPI_HID_DEVICE_PATH      PciRootBridge;
297   PCI_DEVICE_PATH           PciDevice;
298   EFI_DEVICE_PATH_PROTOCOL  End;
299 } PLATFORM_PCI_DEVICE_PATH;
300 
301 typedef enum {
302   PMIC_Equal         = 0, // =		0
303   PMIC_Greater_Than,	  // >		1
304   PMIC_Smaller_Than,	  // <		2
305   PMIC_Greater_Equal,	  // >=		3
306   PMIC_Smaller_Equal,	  // <=		4
307   PMIC_Any				  // don't care 5
308 } PMIC_Condition_list;
309 
310 typedef enum {
311   PMIC_White_List	= 0,  //White list
312   PMIC_Black_List	= 1   //Black list
313 } PMIC_Compliance_mode;
314 
315 typedef struct {
316   UINT8		Cond_Choice;	// PMIC_Condition_list
317   UINT8		Cond_Number;		// the number
318 }PMIC_Condition_Item;
319 
320 typedef struct {
321   PMIC_Condition_Item   					PMIC_BoardID;
322   PMIC_Condition_Item   					PMIC_FabID;
323   PMIC_Condition_Item   					Soc_Stepping;//define PMIC type, 1:Dialog , 2:Rohm
324   PMIC_Condition_Item   					PMIC_VendID;
325   PMIC_Condition_Item   					PMIC_RevID;
326   PMIC_Compliance_mode 				        mode;        //if 1, blacklist; if 0, white list.
327 } PMIC_Compliance_Item;
328 
329 //
330 // Platform BDS Functions
331 //
332 VOID
333 PlatformBdsGetDriverOption (
334   IN LIST_ENTRY                   *BdsDriverLists
335   );
336 
337 VOID
338 PlatformBdsPredictBootOption (
339   IN  LIST_ENTRY                     *BdsBootOptionList
340   );
341 
342 EFI_STATUS
343 PlatformBdsShowProgress (
344   EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,
345   EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,
346   CHAR16                        *Title,
347   EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,
348   UINTN                         Progress,
349   UINTN                         PreviousValue
350   );
351 
352 VOID
353 PlatformBdsConnectSequence (
354   VOID
355   );
356 
357 EFI_STATUS
358 PlatformBdsConnectConsole (
359   IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole
360   );
361 
362 EFI_STATUS
363 PlatformBdsNoConsoleAction (
364   VOID
365   );
366 
367 VOID
368 PlatformBdsEnterFrontPage (
369   IN UINT16                 TimeoutDefault,
370   IN BOOLEAN                ConnectAllHappened
371   );
372 
373 VOID
374 EFIAPI
375 PlatformBdsUserIdentify (
376   OUT EFI_USER_PROFILE_HANDLE        *User,
377   OUT BOOLEAN                        *DeferredImage
378   );
379 
380 VOID
381 EFIAPI
382 PlatformBdsConnectAuthDevice (
383   VOID
384   );
385 
386 VOID
387 PlatformBdsEnterFrontPageWithHotKey (
388   IN UINT16                       TimeoutDefault,
389   IN BOOLEAN                      ConnectAllHappened
390   );
391 
392  EFI_STATUS
393  ShowProgress (
394    IN UINT16					   TimeoutDefault
395    );
396 
397  EFI_STATUS
398  InitializeFrontPage (
399    IN BOOLEAN						  InitializeHiiData
400    );
401 
402  VOID
403  UpdateFrontPageStrings (
404    VOID
405    );
406 
407 
408  EFI_STATUS
409  InitBMPackage  (
410    VOID
411    );
412 
413 
414  VOID
415  FreeBMPackage  (
416    VOID
417    );
418 
419 
420  EFI_STATUS
421  CallFrontPage (
422    VOID
423    );
424 
425 
426  VOID
427  CallBootManager (
428    VOID
429    );
430 
431 VOID
432 CallDeviceManager (
433   VOID
434   );
435 
436 VOID
437 BdsStartBootMaint (
438   VOID
439   );
440 
441 CHAR16 *
442 GetStringById (
443   IN  EFI_STRING_ID   Id
444   );
445 
446 EFI_STATUS
447 WaitForSingleEvent (
448   IN EFI_EVENT                  Event,
449   IN UINT64                     Timeout OPTIONAL
450   );
451 
452 EFI_STATUS
453 BdsLibDeleteOptionFromHandle (
454   IN  EFI_HANDLE                 Handle
455   );
456 
457 EFI_STATUS
458 BdsDeleteAllInvalidEfiBootOption (
459   VOID
460   );
461 
462 
463 #define ONE_SECOND  10000000
464 #define FRONT_PAGE_KEY_CONTINUE        0x1000
465 #define FRONT_PAGE_KEY_LANGUAGE        0x1234
466 #define FRONT_PAGE_KEY_BOOT_MANAGER    0x1064
467 #define FRONT_PAGE_KEY_DEVICE_MANAGER  0x8567
468 #define FRONT_PAGE_KEY_BOOT_MAINTAIN   0x9876
469 
470 #define PORT_A_DVO                     0           // ; DVO A
471 #define PORT_B_DVO                     1           // ; DVO B
472 #define PORT_C_DVO                     2           // ; DVO C
473 #define PORT_D_DVO                     3           // ; DVO D
474 #define PORT_LVDS                      4           // ; Integrated LVDS port
475 #define PORT_ANALOG_TV                 5           // ; Integrated TV port
476 #define PORT_CRT                       6           // ; integrated Analog port
477 #define PORT_B_DP                      7           // ; DisplayPort B
478 #define PORT_C_DP                      8           // ; DisplayPort C
479 #define PORT_D_DP                      9           // ; DisplayPort D
480 #define PORT_A_DP                      10          // ; DisplayPort A (for eDP on ILK)
481 #define PORT_B_HDMI                    11          // ; HDMI B
482 #define PORT_C_HDMI                    12          // ; HDMI C
483 #define PORT_D_HDMI                    13          // ; HDMI D
484 #define PORT_B_DVI                     14          // ; DVI B
485 #define PORT_C_DVI                     15          // ; DVI C
486 #define PORT_D_DVI                     16          // ; DVI D
487 #define PORT_MIPI_A                    21          // ; MIPI
488 #define PORT_MIPI_B                    22
489 #define PORT_MIPI_C                    23
490 
491 
492 extern BOOLEAN gConnectAllHappened;
493 extern UINTN gCallbackKey;
494 
495 VOID
496 BdsBootDeviceSelect (
497   VOID
498 );
499 VOID FastBoot(VOID);
500 
501 extern BOOLEAN    mModeInitialized;
502 
503 //
504 // Boot video resolution and text mode.
505 //
506 extern UINT32     mBootHorizontalResolution    ;
507 extern UINT32     mBootVerticalResolution      ;
508 extern UINT32     mBootTextModeColumn          ;
509 extern UINT32     mBootTextModeRow             ;
510 
511 //
512 // BIOS setup video resolution and text mode.
513 //
514 extern UINT32     mSetupTextModeColumn         ;
515 extern UINT32     mSetupTextModeRow            ;
516 extern UINT32     mSetupHorizontalResolution   ;
517 extern UINT32     mSetupVerticalResolution     ;
518 extern EFI_STATUS BdsSetConsoleMode (BOOLEAN);
519 #endif // _BDS_PLATFORM_H
520