X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FUniversal%2FBdsDxe%2FBootMaint%2FConsoleOption.c;h=e79b3f6a3013cee3c68181d0d93782344fd1f708;hp=da0a8389fa43ebbd9596d5d819fc738272f33d70;hb=6b008b74fbc9fdef1359c3807fc5d043f34a2046;hpb=5c08e1173703234cc2913757f237ee916087498a diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c index da0a8389fa..e79b3f6a30 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/ConsoleOption.c @@ -1,7 +1,7 @@ /** @file handles console redirection from boot manager -Copyright (c) 2004 - 2008, Intel Corporation.
+Copyright (c) 2004 - 2010, Intel Corporation.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -14,6 +14,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "BootMaint.h" +/** + Check whether the device path node is ISA Serial Node. + + @param Acpi Device path node to be checked + + @retval TRUE It's ISA Serial Node. + @retval FALSE It's NOT ISA Serial Node. + +**/ +BOOLEAN +IsIsaSerialNode ( + IN ACPI_HID_DEVICE_PATH *Acpi + ) +{ + return (BOOLEAN) ( + (DevicePathType (Acpi) == ACPI_DEVICE_PATH) && + (DevicePathSubType (Acpi) == ACPI_DP) && + (ReadUnaligned32 (&Acpi->HID) == EISA_PNP_ID (0x0501)) + ); +} + /** Update Com Ports attributes from DevicePath @@ -51,20 +72,16 @@ ChangeTerminalDevicePath ( UART_DEVICE_PATH *Uart; UART_DEVICE_PATH *Uart1; UINTN Com; - UINT32 Match; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; - Match = EISA_PNP_ID (0x0501); Node = DevicePath; Node = NextDevicePathNode (Node); Com = 0; while (!IsDevicePathEnd (Node)) { - if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) { - Acpi = (ACPI_HID_DEVICE_PATH *) Node; - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { - CopyMem (&Com, &Acpi->UID, sizeof (UINT32)); - } + Acpi = (ACPI_HID_DEVICE_PATH *) Node; + if (IsIsaSerialNode (Acpi)) { + CopyMem (&Com, &Acpi->UID, sizeof (UINT32)); } NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com); @@ -165,20 +182,16 @@ ChangeVariableDevicePath ( ACPI_HID_DEVICE_PATH *Acpi; UART_DEVICE_PATH *Uart; UINTN Com; - UINT32 Match; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; - Match = EISA_PNP_ID (0x0501); Node = DevicePath; Node = NextDevicePathNode (Node); Com = 0; while (!IsDevicePathEnd (Node)) { - if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) { - Acpi = (ACPI_HID_DEVICE_PATH *) Node; - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { - CopyMem (&Com, &Acpi->UID, sizeof (UINT32)); - } + Acpi = (ACPI_HID_DEVICE_PATH *) Node; + if (IsIsaSerialNode (Acpi)) { + CopyMem (&Com, &Acpi->UID, sizeof (UINT32)); } if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { @@ -234,29 +247,33 @@ RetrieveUartUid ( IN OUT UINT32 *AcpiUid ) { - UINT32 Match; - UINT8 *Ptr; + EFI_STATUS Status; ACPI_HID_DEVICE_PATH *Acpi; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - gBS->HandleProtocol ( - Handle, - &gEfiDevicePathProtocolGuid, - (VOID **) &DevicePath - ); - Ptr = (UINT8 *) DevicePath; - - while (*Ptr != END_DEVICE_PATH_TYPE) { - Ptr++; + Status = gBS->HandleProtocol ( + Handle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath + ); + if (EFI_ERROR (Status)) { + return FALSE; } - Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH); - Acpi = (ACPI_HID_DEVICE_PATH *) Ptr; - Match = EISA_PNP_ID (0x0501); + Acpi = NULL; + for (; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) { + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MSG_UART_DP)) { + break; + } + // + // Acpi points to the node before the Uart node + // + Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath; + } - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { + if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) { if (AcpiUid != NULL) { - *AcpiUid = Acpi->UID; + CopyMem (AcpiUid, &Acpi->UID, sizeof (UINT32)); } return TRUE; } else { @@ -339,7 +356,6 @@ LocateSerialIo ( VOID ) { - UINT8 *Ptr; UINTN Index; UINTN Index2; UINTN NoHandles; @@ -347,8 +363,8 @@ LocateSerialIo ( EFI_STATUS Status; ACPI_HID_DEVICE_PATH *Acpi; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINT32 Match; EFI_SERIAL_IO_PROTOCOL *SerialIo; + EFI_DEVICE_PATH_PROTOCOL *Node; EFI_DEVICE_PATH_PROTOCOL *OutDevicePath; EFI_DEVICE_PATH_PROTOCOL *InpDevicePath; EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath; @@ -390,16 +406,19 @@ LocateSerialIo ( &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath ); - Ptr = (UINT8 *) DevicePath; - while (*Ptr != END_DEVICE_PATH_TYPE) { - Ptr++; - } - Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH); - Acpi = (ACPI_HID_DEVICE_PATH *) Ptr; - Match = EISA_PNP_ID (0x0501); + Acpi = NULL; + for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) { + if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { + break; + } + // + // Acpi points to the node before Uart node + // + Acpi = (ACPI_HID_DEVICE_PATH *) Node; + } - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { + if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) { NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT); if (NewMenuEntry == NULL) { FreePool (Handles); @@ -547,23 +566,19 @@ UpdateComAttributeFromVariable ( ACPI_HID_DEVICE_PATH *Acpi; UART_DEVICE_PATH *Uart; UART_DEVICE_PATH *Uart1; - UINT32 Match; UINTN TerminalNumber; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; UINTN Index; - Match = EISA_PNP_ID (0x0501); Node = DevicePath; Node = NextDevicePathNode (Node); TerminalNumber = 0; for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { while (!IsDevicePathEnd (Node)) { - if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) { - Acpi = (ACPI_HID_DEVICE_PATH *) Node; - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { - CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32)); - } + Acpi = (ACPI_HID_DEVICE_PATH *) Node; + if (IsIsaSerialNode (Acpi)) { + CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32)); } if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { @@ -755,6 +770,7 @@ GetConsoleMenu ( NewMenuEntry->OptionNumber = Index2; NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst); + ASSERT (NewConsoleContext->DevicePath != NULL); NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath); if (NULL == NewMenuEntry->DisplayString) { NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath); @@ -836,47 +852,61 @@ IsTerminalDevicePath ( OUT UINTN *Com ) { - UINT8 *Ptr; - BOOLEAN IsTerminal; - VENDOR_DEVICE_PATH *Vendor; - ACPI_HID_DEVICE_PATH *Acpi; - UINT32 Match; - EFI_GUID TempGuid; + BOOLEAN IsTerminal; + EFI_DEVICE_PATH_PROTOCOL *Node; + VENDOR_DEVICE_PATH *Vendor; + UART_DEVICE_PATH *Uart; + ACPI_HID_DEVICE_PATH *Acpi; IsTerminal = FALSE; - // - // Parse the Device Path, should be change later!!! - // - Ptr = (UINT8 *) DevicePath; - while (*Ptr != END_DEVICE_PATH_TYPE) { - Ptr++; + Uart = NULL; + Vendor = NULL; + Acpi = NULL; + for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) { + // + // Vendor points to the node before the End node + // + Vendor = (VENDOR_DEVICE_PATH *) Node; + + if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) { + Uart = (UART_DEVICE_PATH *) Node; + } + + if (Uart == NULL) { + // + // Acpi points to the node before the UART node + // + Acpi = (ACPI_HID_DEVICE_PATH *) Node; + } } - Ptr = Ptr - sizeof (VENDOR_DEVICE_PATH); - Vendor = (VENDOR_DEVICE_PATH *) Ptr; + if (Vendor == NULL || + DevicePathType (Vendor) != MESSAGING_DEVICE_PATH || + DevicePathSubType (Vendor) != MSG_VENDOR_DP || + Uart == NULL) { + return FALSE; + } // // There are four kinds of Terminal types // check to see whether this devicepath // is one of that type // - CopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID)); - - if (CompareGuid (&TempGuid, &TerminalTypeGuid[0])) { - *Termi = PC_ANSI; + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[0])) { + *Termi = TerminalTypePcAnsi; IsTerminal = TRUE; } else { - if (CompareGuid (&TempGuid, &TerminalTypeGuid[1])) { - *Termi = VT_100; + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[1])) { + *Termi = TerminalTypeVt100; IsTerminal = TRUE; } else { - if (CompareGuid (&TempGuid, &TerminalTypeGuid[2])) { - *Termi = VT_100_PLUS; + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[2])) { + *Termi = TerminalTypeVt100Plus; IsTerminal = TRUE; } else { - if (CompareGuid (&TempGuid, &TerminalTypeGuid[3])) { - *Termi = VT_UTF8; + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[3])) { + *Termi = TerminalTypeVtUtf8; IsTerminal = TRUE; } else { IsTerminal = FALSE; @@ -889,10 +919,7 @@ IsTerminalDevicePath ( return FALSE; } - Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH); - Acpi = (ACPI_HID_DEVICE_PATH *) Ptr; - Match = EISA_PNP_ID (0x0501); - if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) { + if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) { CopyMem (Com, &Acpi->UID, sizeof (UINT32)); } else { return FALSE; @@ -918,25 +945,20 @@ GetConsoleOutMode ( UINTN Mode; UINTN MaxMode; EFI_STATUS Status; - CONSOLE_OUT_MODE *ModeInfo; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; ConOut = gST->ConOut; MaxMode = (UINTN) (ConOut->Mode->MaxMode); - ModeInfo = EfiLibGetVariable (VAR_CON_OUT_MODE, &gEfiGenericPlatformVariableGuid); - - if (ModeInfo != NULL) { - CurrentCol = ModeInfo->Column; - CurrentRow = ModeInfo->Row; - for (Mode = 0; Mode < MaxMode; Mode++) { - Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row); - if (!EFI_ERROR(Status)) { - if (CurrentCol == Col && CurrentRow == Row) { - CallbackData->BmmFakeNvData.ConsoleOutMode = (UINT16) Mode; - break; - } + + CurrentCol = PcdGet32 (PcdConOutColumn); + CurrentRow = PcdGet32 (PcdConOutRow); + for (Mode = 0; Mode < MaxMode; Mode++) { + Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row); + if (!EFI_ERROR(Status)) { + if (CurrentCol == Col && CurrentRow == Row) { + CallbackData->BmmFakeNvData.ConsoleOutMode = (UINT16) Mode; + break; } } - FreePool (ModeInfo); } }