2 This file include all platform action which can be customized by IBV/OEM.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "PlatformBootManager.h"
10 #include "PlatformConsole.h"
11 #include <Guid/SerialPortLibVendor.h>
13 #define PCI_DEVICE_PATH_NODE(Func, Dev) \
16 HARDWARE_DEVICE_PATH, \
19 (UINT8) (sizeof (PCI_DEVICE_PATH)), \
20 (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
27 #define PNPID_DEVICE_PATH_NODE(PnpId) \
33 (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
34 (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
37 EISA_PNP_ID((PnpId)), \
41 #define gPnp16550ComPort \
42 PNPID_DEVICE_PATH_NODE(0x0501)
44 #define gPnpPs2Keyboard \
45 PNPID_DEVICE_PATH_NODE(0x0303)
47 #define gPcAnsiTerminal \
50 MESSAGING_DEVICE_PATH, \
53 (UINT8) (sizeof (VENDOR_DEVICE_PATH)), \
54 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
57 DEVICE_PATH_MESSAGING_PC_ANSI \
60 ACPI_HID_DEVICE_PATH gPnpPs2KeyboardDeviceNode
= gPnpPs2Keyboard
;
61 ACPI_HID_DEVICE_PATH gPnp16550ComPortDeviceNode
= gPnp16550ComPort
;
62 VENDOR_DEVICE_PATH gTerminalTypeDeviceNode
= gPcAnsiTerminal
;
64 BOOLEAN mDetectDisplayOnly
;
67 Add IsaKeyboard to ConIn.
69 @param[in] DeviceHandle Handle of the LPC Bridge device.
71 @retval EFI_SUCCESS IsaKeyboard on the LPC bridge have been added to ConIn.
72 @return Error codes, due to EFI_DEVICE_PATH_PROTOCOL missing
76 PrepareLpcBridgeDevicePath (
77 IN EFI_HANDLE DeviceHandle
81 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
84 Status
= gBS
->HandleProtocol (
86 &gEfiDevicePathProtocolGuid
,
89 if (EFI_ERROR (Status
)) {
96 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnpPs2KeyboardDeviceNode
);
97 EfiBootManagerUpdateConsoleVariable (ConIn
, DevicePath
, NULL
);
102 Return the GOP device path in the platform.
104 @param[in] PciDevicePath - Device path for the PCI graphics device.
105 @param[out] GopDevicePath - Return the device path with GOP installed.
107 @retval EFI_SUCCESS - PCI VGA is added to ConOut.
108 @retval EFI_INVALID_PARAMETER - The device path parameter is invalid.
109 @retval EFI_STATUS - No GOP device found.
113 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
114 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
119 EFI_HANDLE PciDeviceHandle
;
120 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
121 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
122 UINTN GopHandleCount
;
123 EFI_HANDLE
*GopHandleBuffer
;
125 if ((PciDevicePath
== NULL
) || (GopDevicePath
== NULL
)) {
126 return EFI_INVALID_PARAMETER
;
130 // Initialize the GopDevicePath to be PciDevicePath
132 *GopDevicePath
= PciDevicePath
;
133 TempPciDevicePath
= PciDevicePath
;
135 Status
= gBS
->LocateDevicePath (
136 &gEfiDevicePathProtocolGuid
,
140 if (EFI_ERROR (Status
)) {
144 gBS
->ConnectController (PciDeviceHandle
, NULL
, NULL
, FALSE
);
146 Status
= gBS
->LocateHandleBuffer (
148 &gEfiGraphicsOutputProtocolGuid
,
153 if (!EFI_ERROR (Status
)) {
155 // Add all the child handles as possible Console Device
157 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
158 Status
= gBS
->HandleProtocol (GopHandleBuffer
[Index
], &gEfiDevicePathProtocolGuid
, (VOID
*)&TempDevicePath
);
159 if (EFI_ERROR (Status
)) {
166 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
170 // In current implementation, we only enable one of the child handles
171 // as console device, i.e. sotre one of the child handle's device
172 // path to variable "ConOut"
173 // In future, we could select all child handles to be console device
175 *GopDevicePath
= TempDevicePath
;
178 // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()
179 // Add the integrity GOP device path.
181 EfiBootManagerUpdateConsoleVariable (ConOut
, NULL
, PciDevicePath
);
182 EfiBootManagerUpdateConsoleVariable (ConOut
, TempDevicePath
, NULL
);
186 gBS
->FreePool (GopHandleBuffer
);
193 Add PCI VGA to ConOut, ConIn, ErrOut.
195 @param[in] DeviceHandle - Handle of PciIo protocol.
197 @retval EFI_SUCCESS - PCI VGA is added to ConOut.
198 @retval EFI_STATUS - No PCI VGA device is added.
202 PreparePciVgaDevicePath (
203 IN EFI_HANDLE DeviceHandle
207 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
208 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
211 Status
= gBS
->HandleProtocol (
213 &gEfiDevicePathProtocolGuid
,
216 if (EFI_ERROR (Status
)) {
220 GetGopDevicePath (DevicePath
, &GopDevicePath
);
221 DevicePath
= GopDevicePath
;
223 EfiBootManagerUpdateConsoleVariable (ConOut
, DevicePath
, NULL
);
229 For every PCI instance execute a callback function.
231 @param[in] Id - The protocol GUID for callback
232 @param[in] CallBackFunction - The callback function
234 @retval EFI_STATUS - Callback function failed.
239 VisitAllInstancesOfProtocol (
241 IN SIMPLE_PROTOCOL_INSTANCE_CALLBACK CallBackFunction
246 EFI_HANDLE
*HandleBuffer
;
251 // Start to check all the PciIo to find all possible device
255 Status
= gBS
->LocateHandleBuffer (
262 if (EFI_ERROR (Status
)) {
266 for (Index
= 0; Index
< HandleCount
; Index
++) {
267 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], Id
, &Instance
);
268 if (EFI_ERROR (Status
)) {
272 Status
= (*CallBackFunction
)(
278 gBS
->FreePool (HandleBuffer
);
284 Do platform specific PCI Device check and add them to
285 ConOut, ConIn, ErrOut.
287 @param[in] Handle - Handle of PCI device instance
288 @param[in] Instance - The instance of PCI device
290 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
291 @retval EFI_STATUS - PCI Device check or Console variable update fail.
296 DetectAndPreparePlatformPciDevicePath (
297 IN EFI_HANDLE Handle
,
302 EFI_PCI_IO_PROTOCOL
*PciIo
;
305 PciIo
= (EFI_PCI_IO_PROTOCOL
*)Instance
;
308 // Check for all PCI device
310 Status
= PciIo
->Pci
.Read (
314 sizeof (Pci
) / sizeof (UINT32
),
317 if (EFI_ERROR (Status
)) {
321 Status
= PciIo
->Attributes (
323 EfiPciIoAttributeOperationEnable
,
324 EFI_PCI_DEVICE_ENABLE
,
327 ASSERT_EFI_ERROR (Status
);
329 if (!mDetectDisplayOnly
) {
331 // Here we decide whether it is LPC Bridge
333 if ((IS_PCI_LPC (&Pci
)) ||
334 ((IS_PCI_ISA_PDECODE (&Pci
)) &&
335 (Pci
.Hdr
.VendorId
== 0x8086)
340 // Add IsaKeyboard to ConIn,
341 // add IsaSerial to ConOut, ConIn, ErrOut
343 DEBUG ((DEBUG_INFO
, "Found LPC Bridge device\n"));
344 PrepareLpcBridgeDevicePath (Handle
);
350 // Enable all display devices
352 if (IS_PCI_DISPLAY (&Pci
)) {
354 // Add them to ConOut.
356 DEBUG ((DEBUG_INFO
, "Found PCI Display device\n"));
357 EfiBootManagerConnectVideoController (Handle
);
365 For every Serial Io instance, add it to ConOut, ConIn, ErrOut.
367 @param[in] Handle - The Serial Io device handle
368 @param[in] Instance - The instance of the SerialIo protocol
370 @retval EFI_STATUS - Callback function failed.
375 AddDevicePathForOneSerialIoInstance (
376 IN EFI_HANDLE Handle
,
381 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
384 Status
= gBS
->HandleProtocol (
386 &gEfiDevicePathProtocolGuid
,
389 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
391 EfiBootManagerUpdateConsoleVariable (ConOut
, DevicePath
, NULL
);
392 EfiBootManagerUpdateConsoleVariable (ConIn
, DevicePath
, NULL
);
393 EfiBootManagerUpdateConsoleVariable (ErrOut
, DevicePath
, NULL
);
398 Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
400 @param[in] DetectDisplayOnly - Only detect display device if it's TRUE.
402 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
403 @retval EFI_STATUS - PCI Device check or Console variable update fail.
407 DetectAndPreparePlatformPciDevicePaths (
408 BOOLEAN DetectDisplayOnly
413 mDetectDisplayOnly
= DetectDisplayOnly
;
415 EfiBootManagerUpdateConsoleVariable (
417 (EFI_DEVICE_PATH_PROTOCOL
*)&gUsbClassKeyboardDevicePath
,
421 VisitAllInstancesOfProtocol (
422 &gEfiSerialIoProtocolGuid
,
423 AddDevicePathForOneSerialIoInstance
426 Status
= VisitAllInstancesOfProtocol (
427 &gEfiPciIoProtocolGuid
,
428 DetectAndPreparePlatformPciDevicePath
434 The function will connect one root bridge
436 @param[in] Handle - The root bridge handle
437 @param[in] Instance - The instance of the root bridge
439 @return EFI_SUCCESS Connect RootBridge successfully.
444 ConnectOneRootBridge (
445 IN EFI_HANDLE Handle
,
451 Status
= gBS
->ConnectController (Handle
, NULL
, NULL
, FALSE
);
452 if (EFI_ERROR (Status
)) {
460 Platform console init. Include the platform firmware vendor, revision
466 PlatformConsoleInit (
470 VisitAllInstancesOfProtocol (
471 &gEfiPciRootBridgeIoProtocolGuid
,
476 // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
478 DetectAndPreparePlatformPciDevicePaths (FALSE
);