+++ /dev/null
-/** @file\r
- VGA Class Driver that managers VGA devices and produces Simple Text Output Protocol.\r
-\r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#include "VgaClass.h"\r
-\r
-//\r
-// EFI Driver Binding Protocol for the VGA Class Driver\r
-//\r
-EFI_DRIVER_BINDING_PROTOCOL gVgaClassDriverBinding = {\r
- VgaClassDriverBindingSupported,\r
- VgaClassDriverBindingStart,\r
- VgaClassDriverBindingStop,\r
- 0xa,\r
- NULL,\r
- NULL\r
-};\r
-\r
-//\r
-// Local variables\r
-//\r
-CHAR16 CrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
-\r
-//\r
-// This list is used to define the valid extend chars.\r
-// It also provides a mapping from Unicode to PCANSI or\r
-// ASCII. The ASCII mapping we just made up.\r
-//\r
-//\r
-UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {\r
- {\r
- BOXDRAW_HORIZONTAL,\r
- 0xc4,\r
- L'-'\r
- },\r
- {\r
- BOXDRAW_VERTICAL,\r
- 0xb3,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOWN_RIGHT,\r
- 0xda,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_DOWN_LEFT,\r
- 0xbf,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_UP_RIGHT,\r
- 0xc0,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_UP_LEFT,\r
- 0xd9,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_RIGHT,\r
- 0xc3,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_LEFT,\r
- 0xb4,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOWN_HORIZONTAL,\r
- 0xc2,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_UP_HORIZONTAL,\r
- 0xc1,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_HORIZONTAL,\r
- 0xc5,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_HORIZONTAL,\r
- 0xcd,\r
- L'-'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_VERTICAL,\r
- 0xba,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOWN_RIGHT_DOUBLE,\r
- 0xd5,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_DOWN_DOUBLE_RIGHT,\r
- 0xd6,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_DOWN_RIGHT,\r
- 0xc9,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_DOWN_LEFT_DOUBLE,\r
- 0xb8,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_DOWN_DOUBLE_LEFT,\r
- 0xb7,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_DOWN_LEFT,\r
- 0xbb,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_UP_RIGHT_DOUBLE,\r
- 0xd4,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_UP_DOUBLE_RIGHT,\r
- 0xd3,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_UP_RIGHT,\r
- 0xc8,\r
- L'\\'\r
- },\r
- {\r
- BOXDRAW_UP_LEFT_DOUBLE,\r
- 0xbe,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_UP_DOUBLE_LEFT,\r
- 0xbd,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_UP_LEFT,\r
- 0xbc,\r
- L'/'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_RIGHT_DOUBLE,\r
- 0xc6,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_DOUBLE_RIGHT,\r
- 0xc7,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_VERTICAL_RIGHT,\r
- 0xcc,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_LEFT_DOUBLE,\r
- 0xb5,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_DOUBLE_LEFT,\r
- 0xb6,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_VERTICAL_LEFT,\r
- 0xb9,\r
- L'|'\r
- },\r
- {\r
- BOXDRAW_DOWN_HORIZONTAL_DOUBLE,\r
- 0xd1,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_DOWN_DOUBLE_HORIZONTAL,\r
- 0xd2,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_DOWN_HORIZONTAL,\r
- 0xcb,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_UP_HORIZONTAL_DOUBLE,\r
- 0xcf,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_UP_DOUBLE_HORIZONTAL,\r
- 0xd0,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_UP_HORIZONTAL,\r
- 0xca,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE,\r
- 0xd8,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL,\r
- 0xd7,\r
- L'+'\r
- },\r
- {\r
- BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL,\r
- 0xce,\r
- L'+'\r
- },\r
-\r
- {\r
- BLOCKELEMENT_FULL_BLOCK,\r
- 0xdb,\r
- L'*'\r
- },\r
- {\r
- BLOCKELEMENT_LIGHT_SHADE,\r
- 0xb0,\r
- L'+'\r
- },\r
-\r
- {\r
- GEOMETRICSHAPE_UP_TRIANGLE,\r
- 0x1e,\r
- L'^'\r
- },\r
- {\r
- GEOMETRICSHAPE_RIGHT_TRIANGLE,\r
- 0x10,\r
- L'>'\r
- },\r
- {\r
- GEOMETRICSHAPE_DOWN_TRIANGLE,\r
- 0x1f,\r
- L'v'\r
- },\r
- {\r
- GEOMETRICSHAPE_LEFT_TRIANGLE,\r
- 0x11,\r
- L'<'\r
- },\r
-\r
- {\r
- ARROW_LEFT,\r
- 0x3c,\r
- L'<'\r
- },\r
-\r
- {\r
- ARROW_UP,\r
- 0x18,\r
- L'^'\r
- },\r
-\r
- {\r
- ARROW_RIGHT,\r
- 0x3e,\r
- L'>'\r
- },\r
-\r
- {\r
- ARROW_DOWN,\r
- 0x19,\r
- L'v'\r
- },\r
-\r
- {\r
- 0x0000,\r
- 0x00,\r
- 0x00\r
- }\r
-};\r
-\r
-/**\r
- Entrypoint of this VGA Class Driver.\r
-\r
- This function is the entrypoint of this VGA Class Driver. It installs Driver Binding\r
- Protocols together with Component Name Protocols.\r
-\r
- @param ImageHandle The firmware allocated handle for the EFI image.\r
- @param SystemTable A pointer to the EFI System Table.\r
-\r
- @retval EFI_SUCCESS The entry point is executed successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeVgaClass(\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Install driver model protocol(s).\r
- //\r
- Status = EfiLibInstallDriverBindingComponentName2 (\r
- ImageHandle,\r
- SystemTable,\r
- &gVgaClassDriverBinding,\r
- ImageHandle,\r
- &gVgaClassComponentName,\r
- &gVgaClassComponentName2\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Internal worker function to program CRTC register via PCI I/O Protocol.\r
-\r
- @param VgaClassDev device instance object\r
- @param Address Address of register to write\r
- @param Data Data to write to register.\r
-\r
-**/\r
-VOID\r
-WriteCrtc (\r
- IN VGA_CLASS_DEV *VgaClassDev,\r
- IN UINT16 Address,\r
- IN UINT8 Data\r
- )\r
-{\r
- VgaClassDev->PciIo->Io.Write (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthUint8,\r
- VgaClassDev->VgaMiniPort->CrtcAddressRegisterBar,\r
- VgaClassDev->VgaMiniPort->CrtcAddressRegisterOffset,\r
- 1,\r
- &Address\r
- );\r
-\r
- VgaClassDev->PciIo->Io.Write (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthUint8,\r
- VgaClassDev->VgaMiniPort->CrtcDataRegisterBar,\r
- VgaClassDev->VgaMiniPort->CrtcDataRegisterOffset,\r
- 1,\r
- &Data\r
- );\r
-}\r
-\r
-/**\r
- Internal worker function to set cursor's position to VgaClass device\r
-\r
- @param VgaClassDev Private data structure for device instance.\r
- @param Column Colomn of position to set cursor to.\r
- @param Row Row of position to set cursor to.\r
- @param MaxColumn Max value of column.\r
-\r
-**/\r
-VOID\r
-SetVideoCursorPosition (\r
- IN VGA_CLASS_DEV *VgaClassDev,\r
- IN UINTN Column,\r
- IN UINTN Row,\r
- IN UINTN MaxColumn\r
- )\r
-{\r
- Column = Column & 0xff;\r
- Row = Row & 0xff;\r
- MaxColumn = MaxColumn & 0xff;\r
-\r
- WriteCrtc (\r
- VgaClassDev,\r
- CRTC_CURSOR_LOCATION_HIGH,\r
- (UINT8) ((Row * MaxColumn + Column) >> 8)\r
- );\r
- WriteCrtc (\r
- VgaClassDev,\r
- CRTC_CURSOR_LOCATION_LOW,\r
- (UINT8) ((Row * MaxColumn + Column) & 0xff)\r
- );\r
-}\r
-\r
-/**\r
- Internal worker function to detect if a Unicode char is for Box Drawing text graphics.\r
-\r
- @param Graphic Unicode char to test.\r
- @param PcAnsi Pointer to PCANSI equivalent of Graphic for output.\r
- If NULL, then PCANSI value is not returned.\r
- @param Ascii Pointer to ASCII equivalent of Graphic for output.\r
- If NULL, then ASCII value is not returned.\r
-\r
- @retval TRUE Gpaphic is a supported Unicode Box Drawing character.\r
- @retval FALSE Gpaphic is not a supported Unicode Box Drawing character.\r
-\r
-**/\r
-BOOLEAN\r
-LibIsValidTextGraphics (\r
- IN CHAR16 Graphic,\r
- OUT CHAR8 *PcAnsi, OPTIONAL\r
- OUT CHAR8 *Ascii OPTIONAL\r
- )\r
-{\r
- UNICODE_TO_CHAR *Table;\r
-\r
- //\r
- // Unicode drawing code charts are all in the 0x25xx range, arrows are 0x21xx.\r
- // So first filter out values not in these 2 ranges.\r
- //\r
- if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {\r
- return FALSE;\r
- }\r
-\r
- //\r
- // Search UnicodeToPcAnsiOrAscii table for matching entry.\r
- //\r
- for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {\r
- if (Graphic == Table->Unicode) {\r
- if (PcAnsi != NULL) {\r
- *PcAnsi = Table->PcAnsi;\r
- }\r
-\r
- if (Ascii != NULL) {\r
- *Ascii = Table->Ascii;\r
- }\r
-\r
- return TRUE;\r
- }\r
- }\r
-\r
- //\r
- // If value is not found in UnicodeToPcAnsiOrAscii table, then return FALSE.\r
- //\r
- return FALSE;\r
-}\r
-\r
-/**\r
- Internal worker function to check whether input value is an ASCII char.\r
-\r
- @param Char Character to check.\r
-\r
- @retval TRUE Input value is an ASCII char.\r
- @retval FALSE Input value is not an ASCII char.\r
-\r
-**/\r
-BOOLEAN\r
-IsValidAscii (\r
- IN CHAR16 Char\r
- )\r
-{\r
- if ((Char >= 0x20) && (Char <= 0x7f)) {\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- Internal worker function to check whether input value is a unicode control char.\r
-\r
- @param Char Character to check.\r
-\r
- @retval TRUE Input value is a unicode control char.\r
- @retval FALSE Input value is not a unicode control char.\r
-\r
-**/\r
-BOOLEAN\r
-IsValidEfiCntlChar (\r
- IN CHAR16 Char\r
- )\r
-{\r
- if (Char == CHAR_NULL || Char == CHAR_BACKSPACE || Char == CHAR_LINEFEED || Char == CHAR_CARRIAGE_RETURN) {\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- Tests to see if this driver supports a given controller.\r
-\r
- This function implments EFI_DRIVER_BINDING_PROTOCOL.Supported().\r
- It Checks if this driver supports the controller specified. Any Controller\r
- with VgaMiniPort Protocol and Pci I/O protocol can be supported.\r
-\r
- @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
- @param ControllerHandle Handle of device to test\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver supports this device.\r
- @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
- @retval EFI_UNSUPPORTED This driver does not support this device.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassDriverBindingSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Checks if Abstraction(s) needed to perform the supported test\r
- //\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiVgaMiniPortProtocolGuid,\r
- NULL,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Open the IO Abstraction(s) needed to perform the supported test\r
- //\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiPciIoProtocolGuid,\r
- NULL,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Starts the device controller.\r
-\r
- This function implments EFI_DRIVER_BINDING_PROTOCOL.Start().\r
- It starts the device specified by Controller with the driver based on PCI I/O Protocol\r
- and VgaMiniPort Protocol. It creates context for device instance and install EFI_SIMPLE_TEXT_OUT_PROTOCOL.\r
-\r
- @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
- @param ControllerHandle Handle of device to bind driver to\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS The device was started.\r
- @retval other Fail to start the device.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassDriverBindingStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_VGA_MINI_PORT_PROTOCOL *VgaMiniPort;\r
- EFI_PCI_IO_PROTOCOL *PciIo;\r
- VGA_CLASS_DEV *VgaClassPrivate;\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
-\r
- Status = gBS->HandleProtocol (\r
- Controller,\r
- &gEfiDevicePathProtocolGuid,\r
- (VOID **) &DevicePath\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Report that VGA Class driver is being enabled\r
- //\r
- REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
- EFI_PROGRESS_CODE,\r
- EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_PC_ENABLE,\r
- DevicePath\r
- );\r
-\r
- //\r
- // Open the PCI I/O Protocol\r
- //\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiPciIoProtocolGuid,\r
- (VOID **) &PciIo,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Open the VGA Mini Port Protocol\r
- //\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiVgaMiniPortProtocolGuid,\r
- (VOID **) &VgaMiniPort,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Allocate the private device structure\r
- //\r
- VgaClassPrivate = AllocateZeroPool (sizeof (VGA_CLASS_DEV));\r
- ASSERT (VgaClassPrivate != NULL);\r
-\r
- //\r
- // Initialize the private device structure\r
- //\r
- VgaClassPrivate->Signature = VGA_CLASS_DEV_SIGNATURE;\r
- VgaClassPrivate->Handle = Controller;\r
- VgaClassPrivate->VgaMiniPort = VgaMiniPort;\r
- VgaClassPrivate->PciIo = PciIo;\r
-\r
- VgaClassPrivate->SimpleTextOut.Reset = VgaClassReset;\r
- VgaClassPrivate->SimpleTextOut.OutputString = VgaClassOutputString;\r
- VgaClassPrivate->SimpleTextOut.TestString = VgaClassTestString;\r
- VgaClassPrivate->SimpleTextOut.ClearScreen = VgaClassClearScreen;\r
- VgaClassPrivate->SimpleTextOut.SetAttribute = VgaClassSetAttribute;\r
- VgaClassPrivate->SimpleTextOut.SetCursorPosition = VgaClassSetCursorPosition;\r
- VgaClassPrivate->SimpleTextOut.EnableCursor = VgaClassEnableCursor;\r
- VgaClassPrivate->SimpleTextOut.QueryMode = VgaClassQueryMode;\r
- VgaClassPrivate->SimpleTextOut.SetMode = VgaClassSetMode;\r
-\r
- VgaClassPrivate->SimpleTextOut.Mode = &VgaClassPrivate->SimpleTextOutputMode;\r
- VgaClassPrivate->SimpleTextOutputMode.MaxMode = VgaMiniPort->MaxMode;\r
- VgaClassPrivate->DevicePath = DevicePath;\r
-\r
- //\r
- // Initialize the VGA device.\r
- //\r
- Status = VgaClassPrivate->SimpleTextOut.SetAttribute (\r
- &VgaClassPrivate->SimpleTextOut,\r
- EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK)\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ErrorExit;\r
- }\r
-\r
- Status = VgaClassPrivate->SimpleTextOut.Reset (\r
- &VgaClassPrivate->SimpleTextOut,\r
- FALSE\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ErrorExit;\r
- }\r
-\r
- Status = VgaClassPrivate->SimpleTextOut.EnableCursor (\r
- &VgaClassPrivate->SimpleTextOut,\r
- TRUE\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto ErrorExit;\r
- }\r
-\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &Controller,\r
- &gEfiSimpleTextOutProtocolGuid,\r
- &VgaClassPrivate->SimpleTextOut,\r
- NULL\r
- );\r
-\r
- return Status;\r
-\r
-ErrorExit:\r
- REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
- EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
- EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_EC_CONTROLLER_ERROR,\r
- DevicePath\r
- );\r
-\r
- return Status;\r
-\r
-}\r
-\r
-/**\r
- Starts the device controller.\r
-\r
- This function implments EFI_DRIVER_BINDING_PROTOCOL.Stop().\r
- It stops this driver on Controller. Support stopping any child handles\r
- created by this driver.\r
-\r
- @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
- @param ControllerHandle A handle to the device being stopped.\r
- @param NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
- @param ChildHandleBuffer An array of child handles to be freed.\r
-\r
- @retval EFI_SUCCESS This driver is removed ControllerHandle\r
- @retval other This driver was not removed from this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassDriverBindingStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE Controller,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
- VGA_CLASS_DEV *VgaClassPrivate;\r
-\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiSimpleTextOutProtocolGuid,\r
- (VOID **) &SimpleTextOut,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- VgaClassPrivate = VGA_CLASS_DEV_FROM_THIS (SimpleTextOut);\r
-\r
- //\r
- // Report that VGA Class driver is being disabled\r
- //\r
- REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
- EFI_PROGRESS_CODE,\r
- EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_PC_DISABLE,\r
- VgaClassPrivate->DevicePath\r
- );\r
-\r
- Status = gBS->UninstallProtocolInterface (\r
- Controller,\r
- &gEfiSimpleTextOutProtocolGuid,\r
- &VgaClassPrivate->SimpleTextOut\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- //\r
- // Release PCI I/O and VGA Mini Port Protocols on the controller handle.\r
- //\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiPciIoProtocolGuid,\r
- This->DriverBindingHandle,\r
- Controller\r
- );\r
-\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiVgaMiniPortProtocolGuid,\r
- This->DriverBindingHandle,\r
- Controller\r
- );\r
-\r
- FreePool (VgaClassPrivate);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Resets the text output device hardware.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().\r
- It resets the text output device hardware. The cursor position is set to (0, 0),\r
- and the screen is cleared to the default background color for the output device.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param ExtendedVerification Indicates that the driver may perform a more exhaustive\r
- verification operation of the device during reset.\r
-\r
- @retval EFI_SUCCESS The text output device was reset.\r
- @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and could not be reset.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassReset (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN BOOLEAN ExtendedVerification\r
- )\r
-{\r
- EFI_STATUS Status;\r
- VGA_CLASS_DEV *VgaClassPrivate;\r
-\r
- VgaClassPrivate = VGA_CLASS_DEV_FROM_THIS (This);\r
-\r
- REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
- EFI_PROGRESS_CODE,\r
- EFI_PERIPHERAL_LOCAL_CONSOLE | EFI_P_PC_RESET,\r
- VgaClassPrivate->DevicePath\r
- );\r
-\r
- This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
-\r
- Status = This->SetMode (This, 0);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- return This->ClearScreen (This);\r
-}\r
-\r
-/**\r
- Writes a Unicode string to the output device.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().\r
- It writes a Unicode string to the output device. This is the most basic output mechanism\r
- on an output device.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param String The Null-terminated Unicode string to be displayed on the output device(s).\r
-\r
- @retval EFI_SUCCESS The string was output to the device.\r
- @retval EFI_DEVICE_ERROR The device reported an error while attempting to output the text.\r
- @retval EFI_UNSUPPORTED The output device's mode is not currently in a defined text mode.\r
- @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the characters in\r
- the Unicode string could not be rendered and were skipped.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassOutputString (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN CHAR16 *String\r
- )\r
-{\r
- EFI_STATUS Status;\r
- VGA_CLASS_DEV *VgaClassDev;\r
- EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;\r
- UINTN MaxColumn;\r
- UINTN MaxRow;\r
- UINT32 VideoChar;\r
- CHAR8 GraphicChar;\r
-\r
- VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
- Mode = This->Mode;\r
-\r
- Status = This->QueryMode (\r
- This,\r
- Mode->Mode,\r
- &MaxColumn,\r
- &MaxRow\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Parse each character of the string to output\r
- //\r
- for (; *String != CHAR_NULL; String++) {\r
-\r
- switch (*String) {\r
- case CHAR_BACKSPACE:\r
- if (Mode->CursorColumn > 0) {\r
- Mode->CursorColumn--;\r
- }\r
- break;\r
-\r
- case CHAR_LINEFEED:\r
- if (Mode->CursorRow == (INT32) (MaxRow - 1)) {\r
- //\r
- // Scroll the screen by copying the contents\r
- // of the VGA display up one line\r
- //\r
- VgaClassDev->PciIo->CopyMem (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthUint32,\r
- VgaClassDev->VgaMiniPort->VgaMemoryBar,\r
- VgaClassDev->VgaMiniPort->VgaMemoryOffset,\r
- VgaClassDev->VgaMiniPort->VgaMemoryBar,\r
- VgaClassDev->VgaMiniPort->VgaMemoryOffset + MaxColumn * 2,\r
- ((MaxRow - 1) * MaxColumn) >> 1\r
- );\r
-\r
- //\r
- // Print Blank Line of spaces with the current color attributes\r
- //\r
- VideoChar = (Mode->Attribute << 8) | ' ';\r
- VideoChar = (VideoChar << 16) | VideoChar;\r
- VgaClassDev->PciIo->Mem.Write (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthFillUint32,\r
- VgaClassDev->VgaMiniPort->VgaMemoryBar,\r
- VgaClassDev->VgaMiniPort->VgaMemoryOffset + (MaxRow - 1) * MaxColumn * 2,\r
- MaxColumn >> 1,\r
- &VideoChar\r
- );\r
- }\r
-\r
- if (Mode->CursorRow < (INT32) (MaxRow - 1)) {\r
- Mode->CursorRow++;\r
- }\r
- break;\r
-\r
- case CHAR_CARRIAGE_RETURN:\r
- Mode->CursorColumn = 0;\r
- break;\r
-\r
- default:\r
- if (!LibIsValidTextGraphics (*String, &GraphicChar, NULL)) {\r
- //\r
- // If this character is not ,Box Drawing text graphics, then convert it to ASCII.\r
- //\r
- GraphicChar = (CHAR8) *String;\r
- if (!IsValidAscii (GraphicChar)) {\r
- //\r
- // If not valid ASCII char, convert it to "?"\r
- //\r
- GraphicChar = '?';\r
- }\r
- }\r
-\r
- VideoChar = (Mode->Attribute << 8) | GraphicChar;\r
- VgaClassDev->PciIo->Mem.Write (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthUint16,\r
- VgaClassDev->VgaMiniPort->VgaMemoryBar,\r
- VgaClassDev->VgaMiniPort->VgaMemoryOffset + ((Mode->CursorRow * MaxColumn + Mode->CursorColumn) * 2),\r
- 1,\r
- &VideoChar\r
- );\r
-\r
- if (Mode->CursorColumn >= (INT32) (MaxColumn - 1)) {\r
- This->OutputString (This, CrLfString);\r
- } else {\r
- Mode->CursorColumn++;\r
- }\r
- break;\r
- }\r
- }\r
-\r
- SetVideoCursorPosition (\r
- VgaClassDev,\r
- (UINTN) Mode->CursorColumn,\r
- (UINTN) Mode->CursorRow,\r
- MaxColumn\r
- );\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Verifies that all characters in a Unicode string can be output to the target device.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().\r
- It verifies that all characters in a Unicode string can be output to the target device.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param String The Null-terminated Unicode string to be examined for the output device(s).\r
-\r
- @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r
- @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered by\r
- one or more of the output devices mapped by the EFI handle.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassTestString (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN CHAR16 *String\r
- )\r
-{\r
- while (*String != CHAR_NULL) {\r
- if (!(IsValidAscii (*String) || IsValidEfiCntlChar (*String) || LibIsValidTextGraphics (*String, NULL, NULL))) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- String++;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Clears the output device(s) display to the currently selected background color.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().\r
- The ClearScreen() function clears the output device(s) display to the currently\r
- selected background color. The cursor position is set to (0, 0).\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
-\r
- @retval EFI_SUCESS The operation completed successfully.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
- @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassClearScreen (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
- )\r
-{\r
- EFI_STATUS Status;\r
- VGA_CLASS_DEV *VgaClassDev;\r
- UINTN MaxRow;\r
- UINTN MaxColumn;\r
- UINT32 VideoChar;\r
-\r
- VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
-\r
- Status = This->QueryMode (\r
- This,\r
- This->Mode->Mode,\r
- &MaxColumn,\r
- &MaxRow\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- VideoChar = (This->Mode->Attribute << 8) | ' ';\r
- VideoChar = (VideoChar << 16) | VideoChar;\r
- VgaClassDev->PciIo->Mem.Write (\r
- VgaClassDev->PciIo,\r
- EfiPciIoWidthFillUint32,\r
- VgaClassDev->VgaMiniPort->VgaMemoryBar,\r
- VgaClassDev->VgaMiniPort->VgaMemoryOffset,\r
- (MaxRow * MaxColumn) >> 1,\r
- &VideoChar\r
- );\r
-\r
- This->SetCursorPosition (This, 0, 0);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Sets the background and foreground colors for theOutputString() and ClearScreen() functions.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().\r
- It sets the background and foreground colors for the OutputString() and ClearScreen() functions.\r
- The color mask can be set even when the device is in an invalid text mode.\r
- Devices supporting a different number of text colors are required to emulate the above colors\r
- to the best of the device's capabilities.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param Attribute The attribute to set.\r
- Bits 0..3 are the foreground color,\r
- and bits 4..6 are the background color.\r
-\r
- @retval EFI_SUCCESS The requested attributes were set.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassSetAttribute (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN UINTN Attribute\r
- )\r
-{\r
- if (Attribute <= EFI_MAX_ATTRIBUTE) {\r
- This->Mode->Attribute = (INT32) Attribute;\r
- return EFI_SUCCESS;\r
- }\r
-\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- Sets the current coordinates of the cursor position.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().\r
- It sets the current coordinates of the cursor position.\r
- The upper left corner of the screen is defined as coordinate (0, 0).\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param Column Column of position to set the cursor to.\r
- @param Row Row of position to set the cursor to.\r
-\r
- @retval EFI_SUCCESS The operation completed successfully.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
- @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the cursor\r
- position is invalid for the current mode.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassSetCursorPosition (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN UINTN Column,\r
- IN UINTN Row\r
- )\r
-{\r
- EFI_STATUS Status;\r
- VGA_CLASS_DEV *VgaClassDev;\r
- UINTN MaxColumn;\r
- UINTN MaxRow;\r
-\r
- VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
-\r
- Status = This->QueryMode (\r
- This,\r
- This->Mode->Mode,\r
- &MaxColumn,\r
- &MaxRow\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- if (Column >= MaxColumn || Row >= MaxRow) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- SetVideoCursorPosition (VgaClassDev, Column, Row, MaxColumn);\r
-\r
- This->Mode->CursorColumn = (INT32) Column;\r
- This->Mode->CursorRow = (INT32) Row;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Makes the cursor visible or invisible.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.EnableCursor().\r
- It makes the cursor visible or invisible.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param Visible If TRUE, the cursor is set to be visible.\r
- If FALSE, the cursor is set to be invisible.\r
-\r
- @retval EFI_SUCESS The operation completed successfully.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request or the\r
- device does not support changing the cursor mode.\r
- @retval EFI_UNSUPPORTED The output device does not support visibility control of the cursor.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassEnableCursor (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN BOOLEAN Visible\r
- )\r
-{\r
- VGA_CLASS_DEV *VgaClassDev;\r
-\r
- VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
- if (Visible) {\r
- if (This->Mode->Mode == 1) {\r
- //\r
- // 80 * 50\r
- //\r
- WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x06);\r
- WriteCrtc (VgaClassDev, CRTC_CURSOR_END, 0x07);\r
- } else {\r
- //\r
- // 80 * 25\r
- //\r
- WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x0e);\r
- WriteCrtc (VgaClassDev, CRTC_CURSOR_END, 0x0f);\r
- }\r
- } else {\r
- WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x20);\r
- }\r
-\r
- This->Mode->CursorVisible = Visible;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Returns information for an available text mode that the output device(s) supports.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().\r
- It returns information for an available text mode that the output device(s) supports.\r
- It is required that all output devices support at least 80x25 text mode. This mode is defined to be mode 0.\r
- If the output devices support 80x50, that is defined to be mode 1.\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param ModeNumber The mode number to return information on.\r
- @param Columns Columen in current mode number\r
- @param Rows Row in current mode number.\r
-\r
- @retval EFI_SUCCESS The requested mode information was returned.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
- @retval EFI_UNSUPPORTED The mode number was not valid.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassQueryMode (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN UINTN ModeNumber,\r
- OUT UINTN *Columns,\r
- OUT UINTN *Rows\r
- )\r
-{\r
- if ((INT32) ModeNumber >= This->Mode->MaxMode) {\r
- *Columns = 0;\r
- *Rows = 0;\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- switch (ModeNumber) {\r
- case 0:\r
- *Columns = 80;\r
- *Rows = 25;\r
- break;\r
-\r
- case 1:\r
- *Columns = 80;\r
- *Rows = 50;\r
- break;\r
-\r
- default:\r
- *Columns = 0;\r
- *Rows = 0;\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Sets the output device(s) to a specified mode.\r
-\r
- This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().\r
- It sets the output device(s) to the requested mode.\r
- On success the device is in the geometry for the requested mode,\r
- and the device has been cleared to the current background color with the cursor at (0,0).\r
-\r
- @param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
- @param ModeNumber The text mode to set.\r
-\r
- @retval EFI_SUCCESS The requested text mode was set.\r
- @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
- @retval EFI_UNSUPPORTED The mode number was not valid.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-VgaClassSetMode (\r
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
- IN UINTN ModeNumber\r
- )\r
-{\r
- VGA_CLASS_DEV *VgaClassDev;\r
-\r
- VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
-\r
- if ((INT32) ModeNumber >= This->Mode->MaxMode) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- This->ClearScreen (This);\r
-\r
- This->Mode->Mode = (INT32) ModeNumber;\r
-\r
- return VgaClassDev->VgaMiniPort->SetMode (VgaClassDev->VgaMiniPort, ModeNumber);\r
-}\r