X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FLibrary%2FGenericBdsLib%2FBdsConsole.c;h=167ad69c6486f6f98a1589c6fb7cd8fd05c98d17;hp=fe6d436a561530ae3bce967e3c7da385e625fdf1;hb=0a6f48249a601f88af124ae1ff6814b195b699c3;hpb=641b4a46284c0a3c2392b2cebea375da7542265f diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c index fe6d436a56..167ad69c64 100644 --- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c +++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c @@ -1,7 +1,7 @@ /** @file BDS Lib functions which contain all the code to connect console device -Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2018, 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 @@ -13,14 +13,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "InternalBdsLib.h" -#include /** Check if we need to save the EFI variable with "ConVarName" as name as NV type If ConVarName is NULL, then ASSERT(). - + @param ConVarName The name of the EFI variable. @retval TRUE Set the EFI variable as NV type. @@ -34,7 +33,7 @@ IsNvNeed ( CHAR16 *Ptr; ASSERT (ConVarName != NULL); - + Ptr = ConVarName; // @@ -48,7 +47,7 @@ IsNvNeed ( if (((INTN)((UINTN)Ptr - (UINTN)ConVarName) / sizeof (CHAR16)) <= 3) { return TRUE; } - + if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) { return FALSE; } else { @@ -60,20 +59,20 @@ IsNvNeed ( Fill console handle in System Table if there are no valid console handle in. Firstly, check the validation of console handle in System Table. If it is invalid, - update it by the first console device handle from EFI console variable. + update it by the first console device handle from EFI console variable. @param VarName The name of the EFI console variable. @param ConsoleGuid Specified Console protocol GUID. - @param ConsoleHandle On IN, console handle in System Table to be checked. - On OUT, new console hanlde in system table. - @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked. - On OUT, new console protocol on new console hanlde in system table. + @param ConsoleHandle On IN, console handle in System Table to be checked. + On OUT, new console handle in system table. + @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked. + On OUT, new console protocol on new console handle in system table. @retval TRUE System Table has been updated. @retval FALSE System Table hasn't been updated. **/ -BOOLEAN +BOOLEAN UpdateSystemTableConsole ( IN CHAR16 *VarName, IN EFI_GUID *ConsoleGuid, @@ -109,7 +108,7 @@ UpdateSystemTableConsole ( return FALSE; } } - + // // Get all possible consoles device path from EFI variable // @@ -136,7 +135,7 @@ UpdateSystemTableConsole ( FreePool (FullDevicePath); ASSERT (FALSE); } - + // // Find console device handle by device path instance // @@ -181,114 +180,6 @@ UpdateSystemTableConsole ( return FALSE; } -/** - Connect the console device base on the variable ConVarName, if - device path of the ConVarName is multi-instance device path and - anyone of the instances is connected success, this function will - return success. - Dispatch service is called basing on input when the handle associate - with one device path node can not be created successfully. Since in - some cases we assume driver dependency does not exist and do not - need to call this service. - - @param ConVarName Console related variable name, ConIn, ConOut, - ErrOut. - @param NeedDispatch Whether requires dispatch service during connection - - @retval EFI_NOT_FOUND There is not any console devices connected - success - @retval EFI_SUCCESS Success connect any one instance of the console - device path base on the variable ConVarName. - -**/ -EFI_STATUS -ConnectConsoleVariableInternal ( - IN CHAR16 *ConVarName, - IN BOOLEAN NeedDispatch - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; - UINTN VariableSize; - EFI_DEVICE_PATH_PROTOCOL *Instance; - EFI_DEVICE_PATH_PROTOCOL *Next; - EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; - UINTN Size; - BOOLEAN DeviceExist; - - Status = EFI_SUCCESS; - DeviceExist = FALSE; - - // - // Check if the console variable exist - // - StartDevicePath = BdsLibGetVariableAndSize ( - ConVarName, - &gEfiGlobalVariableGuid, - &VariableSize - ); - if (StartDevicePath == NULL) { - return EFI_UNSUPPORTED; - } - - CopyOfDevicePath = StartDevicePath; - do { - // - // Check every instance of the console variable - // - Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); - if (Instance == NULL) { - FreePool (StartDevicePath); - return EFI_UNSUPPORTED; - } - - Next = Instance; - while (!IsDevicePathEndType (Next)) { - Next = NextDevicePathNode (Next); - } - - SetDevicePathEndNode (Next); - // - // Connect the USB console - // USB console device path is a short-form device path that - // starts with the first element being a USB WWID - // or a USB Class device path - // - if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && - ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) - || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) - )) { - Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance); - if (!EFI_ERROR (Status)) { - DeviceExist = TRUE; - } - } else { - // - // Connect the instance device path - // - Status = ConnectDevicePathInternal (Instance, NeedDispatch); - - if (EFI_ERROR (Status)) { - // - // Delete the instance from the console varialbe - // - BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance); - } else { - DeviceExist = TRUE; - } - } - FreePool(Instance); - } while (CopyOfDevicePath != NULL); - - FreePool (StartDevicePath); - - if (!DeviceExist) { - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; -} - /** This function update console variable based on ConVarName, it can add or remove one specific console device path from the variable @@ -393,17 +284,16 @@ BdsLibUpdateConsoleVariable ( // Finally, Update the variable of the default console by NewDevicePath // DevicePathSize = GetDevicePathSize (NewDevicePath); - Status = gRT->SetVariable ( - ConVarName, - &gEfiGlobalVariableGuid, - Attributes, - DevicePathSize, - NewDevicePath - ); + Status = SetVariableAndReportStatusCodeOnError ( + ConVarName, + &gEfiGlobalVariableGuid, + Attributes, + DevicePathSize, + NewDevicePath + ); if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) { Status = EFI_SUCCESS; } - ASSERT_EFI_ERROR (Status); if (VarConsole == NewDevicePath) { if (VarConsole != NULL) { @@ -447,35 +337,86 @@ BdsLibConnectConsoleVariable ( IN CHAR16 *ConVarName ) { - return ConnectConsoleVariableInternal(ConVarName, TRUE); -} + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; + UINTN VariableSize; + EFI_DEVICE_PATH_PROTOCOL *Instance; + EFI_DEVICE_PATH_PROTOCOL *Next; + EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; + UINTN Size; + BOOLEAN DeviceExist; -/** - Connect the console device base on the variable ConVarName, if - device path of the ConVarName is multi-instance device path and - anyone of the instances is connected success, then this function - will return success. - Dispatch service is not called when the handle associate with one - device path node can not be created successfully. Here no driver - dependency is assumed exist, so need not to call this service. + Status = EFI_SUCCESS; + DeviceExist = FALSE; + // + // Check if the console variable exist + // + StartDevicePath = BdsLibGetVariableAndSize ( + ConVarName, + &gEfiGlobalVariableGuid, + &VariableSize + ); + if (StartDevicePath == NULL) { + return EFI_UNSUPPORTED; + } - @param ConVarName Console related variable name, ConIn, ConOut, - ErrOut. + CopyOfDevicePath = StartDevicePath; + do { + // + // Check every instance of the console variable + // + Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); + if (Instance == NULL) { + FreePool (StartDevicePath); + return EFI_UNSUPPORTED; + } - @retval EFI_NOT_FOUND There is not any console devices connected - success - @retval EFI_SUCCESS Success connect any one instance of the console - device path base on the variable ConVarName. + Next = Instance; + while (!IsDevicePathEndType (Next)) { + Next = NextDevicePathNode (Next); + } -**/ -EFI_STATUS -EFIAPI -BdsLibConnectConsoleVariableWithOutDispatch ( - IN CHAR16 *ConVarName - ) -{ - return ConnectConsoleVariableInternal(ConVarName, FALSE); + SetDevicePathEndNode (Next); + // + // Connect the USB console + // USB console device path is a short-form device path that + // starts with the first element being a USB WWID + // or a USB Class device path + // + if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) + || (DevicePathSubType (Instance) == MSG_USB_WWID_DP) + )) { + Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance); + if (!EFI_ERROR (Status)) { + DeviceExist = TRUE; + } + } else { + // + // Connect the instance device path + // + Status = BdsLibConnectDevicePath (Instance); + + if (EFI_ERROR (Status)) { + // + // Delete the instance from the console varialbe + // + BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance); + } else { + DeviceExist = TRUE; + } + } + FreePool(Instance); + } while (CopyOfDevicePath != NULL); + + FreePool (StartDevicePath); + + if (!DeviceExist) { + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; } /** @@ -700,247 +641,6 @@ BdsLibConnectAllDefaultConsolesWithOutConIn ( } -/** - Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer - is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt - buffer is passed in it will be used if it is big enough. - - @param BmpImage Pointer to BMP file - @param BmpImageSize Number of bytes in BmpImage - @param GopBlt Buffer containing GOP version of BmpImage. - @param GopBltSize Size of GopBlt in bytes. - @param PixelHeight Height of GopBlt/BmpImage in pixels - @param PixelWidth Width of GopBlt/BmpImage in pixels - - @retval EFI_SUCCESS GopBlt and GopBltSize are returned. - @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image - @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. - GopBltSize will contain the required size. - @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. - -**/ -EFI_STATUS -ConvertBmpToGopBlt ( - IN VOID *BmpImage, - IN UINTN BmpImageSize, - IN OUT VOID **GopBlt, - IN OUT UINTN *GopBltSize, - OUT UINTN *PixelHeight, - OUT UINTN *PixelWidth - ) -{ - UINT8 *Image; - UINT8 *ImageHeader; - BMP_IMAGE_HEADER *BmpHeader; - BMP_COLOR_MAP *BmpColorMap; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; - UINT64 BltBufferSize; - UINTN Index; - UINTN Height; - UINTN Width; - UINTN ImageIndex; - UINT32 DataSizePerLine; - BOOLEAN IsAllocated; - UINT32 ColorMapNum; - - if (sizeof (BMP_IMAGE_HEADER) > BmpImageSize) { - return EFI_INVALID_PARAMETER; - } - - BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; - - if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { - return EFI_UNSUPPORTED; - } - - // - // Doesn't support compress. - // - if (BmpHeader->CompressionType != 0) { - return EFI_UNSUPPORTED; - } - - // - // Only support BITMAPINFOHEADER format. - // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER - // - if (BmpHeader->HeaderSize != sizeof (BMP_IMAGE_HEADER) - OFFSET_OF(BMP_IMAGE_HEADER, HeaderSize)) { - return EFI_UNSUPPORTED; - } - - // - // The data size in each line must be 4 byte alignment. - // - DataSizePerLine = ((BmpHeader->PixelWidth * BmpHeader->BitPerPixel + 31) >> 3) & (~0x3); - BltBufferSize = MultU64x32 (DataSizePerLine, BmpHeader->PixelHeight); - if (BltBufferSize > (UINT32) ~0) { - return EFI_INVALID_PARAMETER; - } - - if ((BmpHeader->Size != BmpImageSize) || - (BmpHeader->Size < BmpHeader->ImageOffset) || - (BmpHeader->Size - BmpHeader->ImageOffset != BmpHeader->PixelHeight * DataSizePerLine)) { - return EFI_INVALID_PARAMETER; - } - - // - // Calculate Color Map offset in the image. - // - Image = BmpImage; - BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); - if (BmpHeader->ImageOffset < sizeof (BMP_IMAGE_HEADER)) { - return EFI_INVALID_PARAMETER; - } - - if (BmpHeader->ImageOffset > sizeof (BMP_IMAGE_HEADER)) { - switch (BmpHeader->BitPerPixel) { - case 1: - ColorMapNum = 2; - break; - case 4: - ColorMapNum = 16; - break; - case 8: - ColorMapNum = 256; - break; - default: - ColorMapNum = 0; - break; - } - if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) != sizeof (BMP_COLOR_MAP) * ColorMapNum) { - return EFI_INVALID_PARAMETER; - } - } - - // - // Calculate graphics image data address in the image - // - Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; - ImageHeader = Image; - - // - // Calculate the BltBuffer needed size. - // - BltBufferSize = MultU64x32 ((UINT64) BmpHeader->PixelWidth, BmpHeader->PixelHeight); - // - // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow - // - if (BltBufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { - return EFI_UNSUPPORTED; - } - BltBufferSize = MultU64x32 (BltBufferSize, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - - IsAllocated = FALSE; - if (*GopBlt == NULL) { - // - // GopBlt is not allocated by caller. - // - *GopBltSize = (UINTN) BltBufferSize; - *GopBlt = AllocatePool (*GopBltSize); - IsAllocated = TRUE; - if (*GopBlt == NULL) { - return EFI_OUT_OF_RESOURCES; - } - } else { - // - // GopBlt has been allocated by caller. - // - if (*GopBltSize < (UINTN) BltBufferSize) { - *GopBltSize = (UINTN) BltBufferSize; - return EFI_BUFFER_TOO_SMALL; - } - } - - *PixelWidth = BmpHeader->PixelWidth; - *PixelHeight = BmpHeader->PixelHeight; - - // - // Convert image from BMP to Blt buffer format - // - BltBuffer = *GopBlt; - for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { - Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; - for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { - switch (BmpHeader->BitPerPixel) { - case 1: - // - // Convert 1-bit (2 colors) BMP to 24-bit color - // - for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { - Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; - Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; - Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; - Blt++; - Width++; - } - - Blt--; - Width--; - break; - - case 4: - // - // Convert 4-bit (16 colors) BMP Palette to 24-bit color - // - Index = (*Image) >> 4; - Blt->Red = BmpColorMap[Index].Red; - Blt->Green = BmpColorMap[Index].Green; - Blt->Blue = BmpColorMap[Index].Blue; - if (Width < (BmpHeader->PixelWidth - 1)) { - Blt++; - Width++; - Index = (*Image) & 0x0f; - Blt->Red = BmpColorMap[Index].Red; - Blt->Green = BmpColorMap[Index].Green; - Blt->Blue = BmpColorMap[Index].Blue; - } - break; - - case 8: - // - // Convert 8-bit (256 colors) BMP Palette to 24-bit color - // - Blt->Red = BmpColorMap[*Image].Red; - Blt->Green = BmpColorMap[*Image].Green; - Blt->Blue = BmpColorMap[*Image].Blue; - break; - - case 24: - // - // It is 24-bit BMP. - // - Blt->Blue = *Image++; - Blt->Green = *Image++; - Blt->Red = *Image; - break; - - default: - // - // Other bit format BMP is not supported. - // - if (IsAllocated) { - FreePool (*GopBlt); - *GopBlt = NULL; - } - return EFI_UNSUPPORTED; - break; - }; - - } - - ImageIndex = (UINTN) (Image - ImageHeader); - if ((ImageIndex % 4) != 0) { - // - // Bmp Image starts each row on a 32-bit boundary! - // - Image = Image + (4 - (ImageIndex % 4)); - } - } - - return EFI_SUCCESS; -} - /** Use SystemTable Conout to stop video based Simple Text Out consoles from going to the video device. Put up LogoFile on every video device that is a console. @@ -1091,17 +791,17 @@ EnableQuietBoot ( Attribute = EfiBadgingDisplayAttributeCenter; } else { Attribute = EfiBadgingDisplayAttributeCustomized; - } + } } if (Blt != NULL) { FreePool (Blt); } Blt = NULL; - Status = ConvertBmpToGopBlt ( + Status = TranslateBmpToGopBlt ( ImageData, ImageSize, - (VOID **) &Blt, + &Blt, &BltSize, &Height, &Width @@ -1268,7 +968,7 @@ Done: Status = EFI_SUCCESS; } else { // - // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. + // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. // if (Blt != NULL) { FreePool (Blt); @@ -1334,7 +1034,7 @@ Done: } /** - Use SystemTable Conout to turn on video based Simple Text Out consoles. The + Use SystemTable Conout to turn on video based Simple Text Out consoles. The Simple Text Out screens will now be synced up with all non video output devices @retval EFI_SUCCESS UGA devices are back in text mode and synced up.