2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "GraphicsConsole.h"
12 // Graphics Console Device Private Data template
14 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
15 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
16 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
17 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
19 GraphicsConsoleConOutReset
,
20 GraphicsConsoleConOutOutputString
,
21 GraphicsConsoleConOutTestString
,
22 GraphicsConsoleConOutQueryMode
,
23 GraphicsConsoleConOutSetMode
,
24 GraphicsConsoleConOutSetAttribute
,
25 GraphicsConsoleConOutClearScreen
,
26 GraphicsConsoleConOutSetCursorPosition
,
27 GraphicsConsoleConOutEnableCursor
,
28 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
33 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
38 (GRAPHICS_CONSOLE_MODE_DATA
*) NULL
,
39 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
42 GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData
[] = {
45 // New modes can be added here.
46 // The last entry is specific for full screen mode.
51 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
52 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
53 EFI_HII_HANDLE mHiiHandle
;
54 VOID
*mHiiRegistration
;
56 EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
58 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
60 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mGraphicsEfiColors
[16] = {
64 {0x00, 0x00, 0x00, 0x00}, // BLACK
65 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
66 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
67 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
68 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
69 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
70 {0x00, 0x98, 0x98, 0x00}, // BROWN
71 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
72 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
73 {0xff, 0x00, 0x00, 0x00}, // BLUE
74 {0x00, 0xff, 0x00, 0x00}, // LIME
75 {0xff, 0xff, 0x00, 0x00}, // CYAN
76 {0x00, 0x00, 0xff, 0x00}, // RED
77 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
78 {0x00, 0xff, 0xff, 0x00}, // YELLOW
79 {0xff, 0xff, 0xff, 0x00} // WHITE
82 EFI_NARROW_GLYPH mCursorGlyph
= {
85 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
88 CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
90 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
91 GraphicsConsoleControllerDriverSupported
,
92 GraphicsConsoleControllerDriverStart
,
93 GraphicsConsoleControllerDriverStop
,
100 Test to see if Graphics Console could be supported on the Controller.
102 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
103 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
104 if PcdUgaConsumeSupport is set to FALSE.)
106 @param This Protocol instance pointer.
107 @param Controller Handle of device to test.
108 @param RemainingDevicePath Optional parameter use to pick a specific child
111 @retval EFI_SUCCESS This driver supports this device.
112 @retval other This driver does not support this device.
117 GraphicsConsoleControllerDriverSupported (
118 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
119 IN EFI_HANDLE Controller
,
120 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
124 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
125 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
126 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
128 GraphicsOutput
= NULL
;
131 // Open the IO Abstraction(s) needed to perform the supported test
133 Status
= gBS
->OpenProtocol (
135 &gEfiGraphicsOutputProtocolGuid
,
136 (VOID
**) &GraphicsOutput
,
137 This
->DriverBindingHandle
,
139 EFI_OPEN_PROTOCOL_BY_DRIVER
142 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
144 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
146 Status
= gBS
->OpenProtocol (
148 &gEfiUgaDrawProtocolGuid
,
150 This
->DriverBindingHandle
,
152 EFI_OPEN_PROTOCOL_BY_DRIVER
155 if (EFI_ERROR (Status
)) {
160 // We need to ensure that we do not layer on top of a virtual handle.
161 // We need to ensure that the handles produced by the conspliter do not
164 Status
= gBS
->OpenProtocol (
166 &gEfiDevicePathProtocolGuid
,
167 (VOID
**) &DevicePath
,
168 This
->DriverBindingHandle
,
170 EFI_OPEN_PROTOCOL_BY_DRIVER
172 if (!EFI_ERROR (Status
)) {
175 &gEfiDevicePathProtocolGuid
,
176 This
->DriverBindingHandle
,
184 // Does Hii Exist? If not, we aren't ready to run
186 Status
= EfiLocateHiiProtocol ();
189 // Close the I/O Abstraction(s) used to perform the supported test
192 if (GraphicsOutput
!= NULL
) {
195 &gEfiGraphicsOutputProtocolGuid
,
196 This
->DriverBindingHandle
,
199 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
202 &gEfiUgaDrawProtocolGuid
,
203 This
->DriverBindingHandle
,
211 Initialize all the text modes which the graphics console supports.
213 It returns information for available text modes that the graphics can support.
215 @param[in] HorizontalResolution The size of video screen in pixels in the X dimension.
216 @param[in] VerticalResolution The size of video screen in pixels in the Y dimension.
217 @param[in] GopModeNumber The graphics mode number which graphis console is based on.
218 @param[out] TextModeCount The total number of text modes that graphics console supports.
219 @param[out] TextModeData The buffer to the text modes column and row information.
220 Caller is responsible to free it when it's non-NULL.
222 @retval EFI_SUCCESS The supporting mode information is returned.
223 @retval EFI_INVALID_PARAMETER The parameters are invalid.
227 InitializeGraphicsConsoleTextMode (
228 IN UINT32 HorizontalResolution
,
229 IN UINT32 VerticalResolution
,
230 IN UINT32 GopModeNumber
,
231 OUT UINTN
*TextModeCount
,
232 OUT GRAPHICS_CONSOLE_MODE_DATA
**TextModeData
237 GRAPHICS_CONSOLE_MODE_DATA
*ModeBuffer
;
238 GRAPHICS_CONSOLE_MODE_DATA
*NewModeBuffer
;
244 if ((TextModeCount
== NULL
) || (TextModeData
== NULL
)) {
245 return EFI_INVALID_PARAMETER
;
248 Count
= sizeof (mGraphicsConsoleModeData
) / sizeof (GRAPHICS_CONSOLE_MODE_DATA
);
251 // Compute the maximum number of text Rows and Columns that this current graphics mode can support.
252 // To make graphics console work well, MaxColumns and MaxRows should not be zero.
254 MaxColumns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
255 MaxRows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
258 // According to UEFI spec, all output devices support at least 80x25 text mode.
260 ASSERT ((MaxColumns
>= 80) && (MaxRows
>= 25));
263 // Add full screen mode to the last entry.
265 mGraphicsConsoleModeData
[Count
- 1].Columns
= MaxColumns
;
266 mGraphicsConsoleModeData
[Count
- 1].Rows
= MaxRows
;
269 // Get defined mode buffer pointer.
271 ModeBuffer
= mGraphicsConsoleModeData
;
274 // Here we make sure that the final mode exposed does not include the duplicated modes,
275 // and does not include the invalid modes which exceed the max column and row.
276 // Reserve 2 modes for 80x25, 80x50 of graphics console.
278 NewModeBuffer
= AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA
) * (Count
+ 2));
279 ASSERT (NewModeBuffer
!= NULL
);
282 // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.
286 NewModeBuffer
[ValidCount
].Columns
= 80;
287 NewModeBuffer
[ValidCount
].Rows
= 25;
288 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
289 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
290 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
291 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
292 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
295 if ((MaxColumns
>= 80) && (MaxRows
>= 50)) {
296 NewModeBuffer
[ValidCount
].Columns
= 80;
297 NewModeBuffer
[ValidCount
].Rows
= 50;
298 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
299 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
301 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
302 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
303 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
307 // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.
309 for (Index
= 0; Index
< Count
; Index
++) {
310 if ((ModeBuffer
[Index
].Columns
== 0) || (ModeBuffer
[Index
].Rows
== 0) ||
311 (ModeBuffer
[Index
].Columns
> MaxColumns
) || (ModeBuffer
[Index
].Rows
> MaxRows
)) {
313 // Skip the pre-defined mode which is invalid or exceeds the max column and row.
317 for (ValidIndex
= 0; ValidIndex
< ValidCount
; ValidIndex
++) {
318 if ((ModeBuffer
[Index
].Columns
== NewModeBuffer
[ValidIndex
].Columns
) &&
319 (ModeBuffer
[Index
].Rows
== NewModeBuffer
[ValidIndex
].Rows
)) {
321 // Skip the duplicated mode.
326 if (ValidIndex
== ValidCount
) {
327 NewModeBuffer
[ValidCount
].Columns
= ModeBuffer
[Index
].Columns
;
328 NewModeBuffer
[ValidCount
].Rows
= ModeBuffer
[Index
].Rows
;
329 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
330 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
331 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
332 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
333 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
339 for (Index
= 0; Index
< ValidCount
; Index
++) {
340 DEBUG ((EFI_D_INFO
, "Graphics - Mode %d, Column = %d, Row = %d\n",
341 Index
, NewModeBuffer
[Index
].Columns
, NewModeBuffer
[Index
].Rows
));
346 // Return valid mode count and mode information buffer.
348 *TextModeCount
= ValidCount
;
349 *TextModeData
= NewModeBuffer
;
354 Start this driver on Controller by opening Graphics Output protocol or
355 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
356 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
358 @param This Protocol instance pointer.
359 @param Controller Handle of device to bind driver to
360 @param RemainingDevicePath Optional parameter use to pick a specific child
363 @retval EFI_SUCCESS This driver is added to Controller.
364 @retval other This driver does not support this device.
369 GraphicsConsoleControllerDriverStart (
370 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
371 IN EFI_HANDLE Controller
,
372 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
376 GRAPHICS_CONSOLE_DEV
*Private
;
377 UINT32 HorizontalResolution
;
378 UINT32 VerticalResolution
;
384 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
;
386 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
391 // Initialize the Graphics Console device instance
393 Private
= AllocateCopyPool (
394 sizeof (GRAPHICS_CONSOLE_DEV
),
395 &mGraphicsConsoleDevTemplate
397 if (Private
== NULL
) {
398 return EFI_OUT_OF_RESOURCES
;
401 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
403 Status
= gBS
->OpenProtocol (
405 &gEfiGraphicsOutputProtocolGuid
,
406 (VOID
**) &Private
->GraphicsOutput
,
407 This
->DriverBindingHandle
,
409 EFI_OPEN_PROTOCOL_BY_DRIVER
412 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
413 Status
= gBS
->OpenProtocol (
415 &gEfiUgaDrawProtocolGuid
,
416 (VOID
**) &Private
->UgaDraw
,
417 This
->DriverBindingHandle
,
419 EFI_OPEN_PROTOCOL_BY_DRIVER
423 if (EFI_ERROR (Status
)) {
427 HorizontalResolution
= PcdGet32 (PcdVideoHorizontalResolution
);
428 VerticalResolution
= PcdGet32 (PcdVideoVerticalResolution
);
430 if (Private
->GraphicsOutput
!= NULL
) {
432 // The console is build on top of Graphics Output Protocol, find the mode number
433 // for the user-defined mode; if there are multiple video devices,
434 // graphic console driver will set all the video devices to the same mode.
436 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
438 // Find the highest resolution which GOP supports.
440 MaxMode
= Private
->GraphicsOutput
->Mode
->MaxMode
;
442 for (ModeIndex
= 0; ModeIndex
< MaxMode
; ModeIndex
++) {
443 Status
= Private
->GraphicsOutput
->QueryMode (
444 Private
->GraphicsOutput
,
449 if (!EFI_ERROR (Status
)) {
450 if ((Info
->HorizontalResolution
> HorizontalResolution
) ||
451 ((Info
->HorizontalResolution
== HorizontalResolution
) && (Info
->VerticalResolution
> VerticalResolution
))) {
452 HorizontalResolution
= Info
->HorizontalResolution
;
453 VerticalResolution
= Info
->VerticalResolution
;
454 ModeNumber
= ModeIndex
;
459 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
460 Status
= EFI_UNSUPPORTED
;
465 // Use user-defined resolution
467 Status
= CheckModeSupported (
468 Private
->GraphicsOutput
,
469 HorizontalResolution
,
473 if (EFI_ERROR (Status
)) {
475 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
477 HorizontalResolution
= 800;
478 VerticalResolution
= 600;
479 Status
= CheckModeSupported (
480 Private
->GraphicsOutput
,
481 HorizontalResolution
,
485 Mode
= Private
->GraphicsOutput
->Mode
;
486 if (EFI_ERROR (Status
) && Mode
->MaxMode
!= 0) {
488 // Set default mode failed or device don't support default mode, then get the current mode information
490 HorizontalResolution
= Mode
->Info
->HorizontalResolution
;
491 VerticalResolution
= Mode
->Info
->VerticalResolution
;
492 ModeNumber
= Mode
->Mode
;
496 if (ModeNumber
!= Private
->GraphicsOutput
->Mode
->Mode
) {
498 // Current graphics mode is not set or is not set to the mode which we has found,
499 // set the new graphic mode.
501 Status
= Private
->GraphicsOutput
->SetMode (Private
->GraphicsOutput
, ModeNumber
);
502 if (EFI_ERROR (Status
)) {
504 // The mode set operation failed
509 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
511 // At first try to set user-defined resolution
515 Status
= Private
->UgaDraw
->SetMode (
517 HorizontalResolution
,
522 if (EFI_ERROR (Status
)) {
524 // Try to set 800*600 which is required by UEFI/EFI spec
526 Status
= Private
->UgaDraw
->SetMode (
533 if (EFI_ERROR (Status
)) {
534 Status
= Private
->UgaDraw
->GetMode (
536 &HorizontalResolution
,
541 if (EFI_ERROR (Status
)) {
548 DEBUG ((EFI_D_INFO
, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution
, VerticalResolution
));
551 // Initialize the mode which GraphicsConsole supports.
553 Status
= InitializeGraphicsConsoleTextMode (
554 HorizontalResolution
,
561 if (EFI_ERROR (Status
)) {
566 // Update the maximum number of modes
568 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
571 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
572 if (EFI_ERROR (Status
)) {
575 Status
= GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
576 if (EFI_ERROR (Status
)) {
582 // Install protocol interfaces for the Graphics Console device.
584 Status
= gBS
->InstallMultipleProtocolInterfaces (
586 &gEfiSimpleTextOutProtocolGuid
,
587 &Private
->SimpleTextOutput
,
592 if (EFI_ERROR (Status
)) {
594 // Close the GOP and UGA Draw Protocol
596 if (Private
->GraphicsOutput
!= NULL
) {
599 &gEfiGraphicsOutputProtocolGuid
,
600 This
->DriverBindingHandle
,
603 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
606 &gEfiUgaDrawProtocolGuid
,
607 This
->DriverBindingHandle
,
612 if (Private
->LineBuffer
!= NULL
) {
613 FreePool (Private
->LineBuffer
);
616 if (Private
->ModeData
!= NULL
) {
617 FreePool (Private
->ModeData
);
630 Stop this driver on Controller by removing Simple Text Out protocol
631 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
632 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
635 @param This Protocol instance pointer.
636 @param Controller Handle of device to stop driver on
637 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
638 children is zero stop the entire bus driver.
639 @param ChildHandleBuffer List of Child Handles to Stop.
641 @retval EFI_SUCCESS This driver is removed Controller.
642 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
644 @retval other This driver was not removed from this device.
649 GraphicsConsoleControllerDriverStop (
650 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
651 IN EFI_HANDLE Controller
,
652 IN UINTN NumberOfChildren
,
653 IN EFI_HANDLE
*ChildHandleBuffer
657 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
658 GRAPHICS_CONSOLE_DEV
*Private
;
660 Status
= gBS
->OpenProtocol (
662 &gEfiSimpleTextOutProtocolGuid
,
663 (VOID
**) &SimpleTextOutput
,
664 This
->DriverBindingHandle
,
666 EFI_OPEN_PROTOCOL_GET_PROTOCOL
668 if (EFI_ERROR (Status
)) {
669 return EFI_NOT_STARTED
;
672 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
674 Status
= gBS
->UninstallProtocolInterface (
676 &gEfiSimpleTextOutProtocolGuid
,
677 &Private
->SimpleTextOutput
680 if (!EFI_ERROR (Status
)) {
682 // Close the GOP or UGA IO Protocol
684 if (Private
->GraphicsOutput
!= NULL
) {
687 &gEfiGraphicsOutputProtocolGuid
,
688 This
->DriverBindingHandle
,
691 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
694 &gEfiUgaDrawProtocolGuid
,
695 This
->DriverBindingHandle
,
700 if (Private
->LineBuffer
!= NULL
) {
701 FreePool (Private
->LineBuffer
);
704 if (Private
->ModeData
!= NULL
) {
705 FreePool (Private
->ModeData
);
709 // Free our instance data
718 Check if the current specific mode supported the user defined resolution
719 for the Graphics Console device based on Graphics Output Protocol.
721 If yes, set the graphic devcice's current mode to this specific mode.
723 @param GraphicsOutput Graphics Output Protocol instance pointer.
724 @param HorizontalResolution User defined horizontal resolution
725 @param VerticalResolution User defined vertical resolution.
726 @param CurrentModeNumber Current specific mode to be check.
728 @retval EFI_SUCCESS The mode is supported.
729 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
731 @retval other The specific mode does not support user defined
732 resolution or failed to set the current mode to the
733 specific mode on graphics device.
738 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
739 IN UINT32 HorizontalResolution
,
740 IN UINT32 VerticalResolution
,
741 OUT UINT32
*CurrentModeNumber
747 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
750 Status
= EFI_SUCCESS
;
751 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
753 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
754 Status
= GraphicsOutput
->QueryMode (
760 if (!EFI_ERROR (Status
)) {
761 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
762 (Info
->VerticalResolution
== VerticalResolution
)) {
763 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== HorizontalResolution
) &&
764 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== VerticalResolution
)) {
766 // If video device has been set to this mode, we do not need to SetMode again
771 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
772 if (!EFI_ERROR (Status
)) {
782 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
783 Status
= EFI_UNSUPPORTED
;
786 *CurrentModeNumber
= ModeNumber
;
792 Locate HII Database protocol and HII Font protocol.
794 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
795 are located successfully.
796 @return other Failed to locate HII Database protocol or
801 EfiLocateHiiProtocol (
807 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &mHiiDatabase
);
808 if (EFI_ERROR (Status
)) {
812 Status
= gBS
->LocateProtocol (&gEfiHiiFontProtocolGuid
, NULL
, (VOID
**) &mHiiFont
);
817 // Body of the STO functions
821 Reset the text output device hardware and optionally run diagnostics.
823 Implements SIMPLE_TEXT_OUTPUT.Reset().
824 If ExtendeVerification is TRUE, then perform dependent Graphics Console
825 device reset, and set display mode to mode 0.
826 If ExtendedVerification is FALSE, only set display mode to mode 0.
828 @param This Protocol instance pointer.
829 @param ExtendedVerification Indicates that the driver may perform a more
830 exhaustive verification operation of the device
833 @retval EFI_SUCCESS The text output device was reset.
834 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
840 GraphicsConsoleConOutReset (
841 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
842 IN BOOLEAN ExtendedVerification
846 Status
= This
->SetMode (This
, 0);
847 if (EFI_ERROR (Status
)) {
850 Status
= This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
856 Write a Unicode string to the output device.
858 Implements SIMPLE_TEXT_OUTPUT.OutputString().
859 The Unicode string will be converted to Glyphs and will be
860 sent to the Graphics Console.
862 @param This Protocol instance pointer.
863 @param WString The NULL-terminated Unicode string to be displayed
864 on the output device(s). All output devices must
865 also support the Unicode drawing defined in this file.
867 @retval EFI_SUCCESS The string was output to the device.
868 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
870 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
872 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
873 characters in the Unicode string could not be
874 rendered and were skipped.
879 GraphicsConsoleConOutOutputString (
880 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
884 GRAPHICS_CONSOLE_DEV
*Private
;
885 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
886 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
895 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
896 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
901 INT32 OriginAttribute
;
904 if (This
->Mode
->Mode
== -1) {
906 // If current mode is not valid, return error.
908 return EFI_UNSUPPORTED
;
911 Status
= EFI_SUCCESS
;
913 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
917 Mode
= This
->Mode
->Mode
;
918 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
919 GraphicsOutput
= Private
->GraphicsOutput
;
920 UgaDraw
= Private
->UgaDraw
;
922 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
923 MaxRow
= Private
->ModeData
[Mode
].Rows
;
924 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
925 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
926 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
927 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
928 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
931 // The Attributes won't change when during the time OutputString is called
933 GetTextColors (This
, &Foreground
, &Background
);
942 OriginAttribute
= This
->Mode
->Attribute
;
944 while (*WString
!= L
'\0') {
946 if (*WString
== CHAR_BACKSPACE
) {
948 // If the cursor is at the left edge of the display, then move the cursor
951 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
952 This
->Mode
->CursorRow
--;
953 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
954 This
->OutputString (This
, SpaceStr
);
956 This
->Mode
->CursorRow
--;
957 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
958 } else if (This
->Mode
->CursorColumn
> 0) {
960 // If the cursor is not at the left edge of the display, then move the cursor
963 This
->Mode
->CursorColumn
--;
964 This
->OutputString (This
, SpaceStr
);
966 This
->Mode
->CursorColumn
--;
971 } else if (*WString
== CHAR_LINEFEED
) {
973 // If the cursor is at the bottom of the display, then scroll the display one
974 // row, and do not update the cursor position. Otherwise, move the cursor
977 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
978 if (GraphicsOutput
!= NULL
) {
980 // Scroll Screen Up One Row
982 GraphicsOutput
->Blt (
987 DeltaY
+ EFI_GLYPH_HEIGHT
,
996 // Print Blank Line at last line
998 GraphicsOutput
->Blt (
1010 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1012 // Scroll Screen Up One Row
1019 DeltaY
+ EFI_GLYPH_HEIGHT
,
1028 // Print Blank Line at last line
1032 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1044 This
->Mode
->CursorRow
++;
1049 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1051 // Move the cursor to the beginning of the current row.
1053 This
->Mode
->CursorColumn
= 0;
1056 } else if (*WString
== WIDE_CHAR
) {
1058 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1061 } else if (*WString
== NARROW_CHAR
) {
1063 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1068 // Print the character at the current cursor position and move the cursor
1069 // right one column. If this moves the cursor past the right edge of the
1070 // display, then the line should wrap to the beginning of the next line. This
1071 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1072 // bottom of the display, and the line wraps, then the display will be scrolled
1074 // If wide char is going to be displayed, need to display one character at a time
1075 // Or, need to know the display length of a certain string.
1077 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1078 // Count is used to determine how many characters are used regardless of their attributes
1080 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1081 if (WString
[Count
] == CHAR_NULL
||
1082 WString
[Count
] == CHAR_BACKSPACE
||
1083 WString
[Count
] == CHAR_LINEFEED
||
1084 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1085 WString
[Count
] == WIDE_CHAR
||
1086 WString
[Count
] == NARROW_CHAR
) {
1090 // Is the wide attribute on?
1092 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
1094 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1098 // This is the end-case where if we are at column 79 and about to print a wide character
1099 // We should prevent this from happening because we will wrap inappropriately. We should
1100 // not print this character until the next line.
1102 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1109 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1110 if (EFI_ERROR (Status
)) {
1114 // At the end of line, output carriage return and line feed
1117 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1118 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1119 This
->Mode
->CursorColumn
-= 2;
1120 This
->OutputString (This
, SpaceStr
);
1123 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1125 This
->OutputString (This
, mCrLfString
);
1131 This
->Mode
->Attribute
= OriginAttribute
;
1136 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1139 gBS
->RestoreTPL (OldTpl
);
1145 Verifies that all characters in a Unicode string can be output to the
1148 Implements SIMPLE_TEXT_OUTPUT.TestString().
1149 If one of the characters in the *Wstring is neither valid valid Unicode
1150 drawing characters, not ASCII code, then this function will return
1153 @param This Protocol instance pointer.
1154 @param WString The NULL-terminated Unicode string to be examined for the output
1157 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1158 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1159 rendered by one or more of the output devices mapped
1165 GraphicsConsoleConOutTestString (
1166 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1173 EFI_IMAGE_OUTPUT
*Blt
;
1178 while (WString
[Count
] != 0) {
1179 Status
= mHiiFont
->GetGlyph (
1192 if (EFI_ERROR (Status
)) {
1193 return EFI_UNSUPPORTED
;
1202 Returns information for an available text mode that the output device(s)
1205 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1206 It returnes information for an available text mode that the Graphics Console supports.
1207 In this driver,we only support text mode 80x25, which is defined as mode 0.
1209 @param This Protocol instance pointer.
1210 @param ModeNumber The mode number to return information on.
1211 @param Columns The returned columns of the requested mode.
1212 @param Rows The returned rows of the requested mode.
1214 @retval EFI_SUCCESS The requested mode information is returned.
1215 @retval EFI_UNSUPPORTED The mode number is not valid.
1220 GraphicsConsoleConOutQueryMode (
1221 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1222 IN UINTN ModeNumber
,
1227 GRAPHICS_CONSOLE_DEV
*Private
;
1231 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1232 return EFI_UNSUPPORTED
;
1235 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1236 Status
= EFI_SUCCESS
;
1238 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1240 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1241 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1243 if (*Columns
<= 0 || *Rows
<= 0) {
1244 Status
= EFI_UNSUPPORTED
;
1250 gBS
->RestoreTPL (OldTpl
);
1256 Sets the output device(s) to a specified mode.
1258 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1259 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1261 @param This Protocol instance pointer.
1262 @param ModeNumber The text mode to set.
1264 @retval EFI_SUCCESS The requested text mode is set.
1265 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1266 Graphics Console device error.
1267 @retval EFI_UNSUPPORTED The text mode number is not valid.
1272 GraphicsConsoleConOutSetMode (
1273 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1278 GRAPHICS_CONSOLE_DEV
*Private
;
1279 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1280 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1281 UINT32 HorizontalResolution
;
1282 UINT32 VerticalResolution
;
1283 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1284 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1289 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1291 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1292 GraphicsOutput
= Private
->GraphicsOutput
;
1293 UgaDraw
= Private
->UgaDraw
;
1296 // Make sure the requested mode number is supported
1298 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1299 Status
= EFI_UNSUPPORTED
;
1303 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1305 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1306 Status
= EFI_UNSUPPORTED
;
1311 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1313 if (Private
->LineBuffer
!= NULL
) {
1315 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1317 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1319 // Clear the current text window on the current graphics console
1321 This
->ClearScreen (This
);
1322 Status
= EFI_SUCCESS
;
1326 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1327 // so erase the cursor, and free the LineBuffer for the current mode
1331 FreePool (Private
->LineBuffer
);
1335 // Attempt to allocate a line buffer for the requested mode number
1337 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1339 if (NewLineBuffer
== NULL
) {
1341 // The new line buffer could not be allocated, so return an error.
1342 // No changes to the state of the current console have been made, so the current console is still valid
1344 Status
= EFI_OUT_OF_RESOURCES
;
1349 // Assign the current line buffer to the newly allocated line buffer
1351 Private
->LineBuffer
= NewLineBuffer
;
1353 if (GraphicsOutput
!= NULL
) {
1354 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1356 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1358 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1359 if (EFI_ERROR (Status
)) {
1361 // The mode set operation failed
1367 // The current graphics mode is correct, so simply clear the entire display
1369 Status
= GraphicsOutput
->Blt (
1371 &mGraphicsEfiColors
[0],
1378 ModeData
->GopHeight
,
1382 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1384 // Get the current UGA Draw mode information
1386 Status
= UgaDraw
->GetMode (
1388 &HorizontalResolution
,
1389 &VerticalResolution
,
1393 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1395 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1397 Status
= UgaDraw
->SetMode (
1400 ModeData
->GopHeight
,
1404 if (EFI_ERROR (Status
)) {
1406 // The mode set operation failed
1412 // The current graphics mode is correct, so simply clear the entire display
1414 Status
= UgaDraw
->Blt (
1416 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1423 ModeData
->GopHeight
,
1430 // The new mode is valid, so commit the mode change
1432 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1435 // Move the text cursor to the upper left hand corner of the display and flush it
1437 This
->Mode
->CursorColumn
= 0;
1438 This
->Mode
->CursorRow
= 0;
1442 Status
= EFI_SUCCESS
;
1445 gBS
->RestoreTPL (OldTpl
);
1451 Sets the background and foreground colors for the OutputString () and
1452 ClearScreen () functions.
1454 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1456 @param This Protocol instance pointer.
1457 @param Attribute The attribute to set. Bits 0..3 are the foreground
1458 color, and bits 4..6 are the background color.
1459 All other bits are undefined and must be zero.
1461 @retval EFI_SUCCESS The requested attribute is set.
1462 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1463 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1468 GraphicsConsoleConOutSetAttribute (
1469 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1475 if ((Attribute
| 0x7F) != 0x7F) {
1476 return EFI_UNSUPPORTED
;
1479 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1483 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1487 This
->Mode
->Attribute
= (INT32
) Attribute
;
1491 gBS
->RestoreTPL (OldTpl
);
1498 Clears the output device(s) display to the currently selected background
1501 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1503 @param This Protocol instance pointer.
1505 @retval EFI_SUCCESS The operation completed successfully.
1506 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1507 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1512 GraphicsConsoleConOutClearScreen (
1513 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1517 GRAPHICS_CONSOLE_DEV
*Private
;
1518 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1519 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1520 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1521 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1522 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1525 if (This
->Mode
->Mode
== -1) {
1527 // If current mode is not valid, return error.
1529 return EFI_UNSUPPORTED
;
1532 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1534 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1535 GraphicsOutput
= Private
->GraphicsOutput
;
1536 UgaDraw
= Private
->UgaDraw
;
1537 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1539 GetTextColors (This
, &Foreground
, &Background
);
1540 if (GraphicsOutput
!= NULL
) {
1541 Status
= GraphicsOutput
->Blt (
1550 ModeData
->GopHeight
,
1553 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1554 Status
= UgaDraw
->Blt (
1556 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1563 ModeData
->GopHeight
,
1567 Status
= EFI_UNSUPPORTED
;
1570 This
->Mode
->CursorColumn
= 0;
1571 This
->Mode
->CursorRow
= 0;
1575 gBS
->RestoreTPL (OldTpl
);
1582 Sets the current coordinates of the cursor position.
1584 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1586 @param This Protocol instance pointer.
1587 @param Column The position to set the cursor to. Must be greater than or
1588 equal to zero and less than the number of columns and rows
1590 @param Row The position to set the cursor to. Must be greater than or
1591 equal to zero and less than the number of columns and rows
1594 @retval EFI_SUCCESS The operation completed successfully.
1595 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1596 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1597 cursor position is invalid for the current mode.
1602 GraphicsConsoleConOutSetCursorPosition (
1603 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1608 GRAPHICS_CONSOLE_DEV
*Private
;
1609 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1613 if (This
->Mode
->Mode
== -1) {
1615 // If current mode is not valid, return error.
1617 return EFI_UNSUPPORTED
;
1620 Status
= EFI_SUCCESS
;
1622 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1624 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1625 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1627 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1628 Status
= EFI_UNSUPPORTED
;
1632 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1633 Status
= EFI_SUCCESS
;
1639 This
->Mode
->CursorColumn
= (INT32
) Column
;
1640 This
->Mode
->CursorRow
= (INT32
) Row
;
1645 gBS
->RestoreTPL (OldTpl
);
1652 Makes the cursor visible or invisible.
1654 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1656 @param This Protocol instance pointer.
1657 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1658 the cursor is set to be invisible.
1660 @retval EFI_SUCCESS The operation completed successfully.
1661 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
1667 GraphicsConsoleConOutEnableCursor (
1668 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1674 if (This
->Mode
->Mode
== -1) {
1676 // If current mode is not valid, return error.
1678 return EFI_UNSUPPORTED
;
1681 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1685 This
->Mode
->CursorVisible
= Visible
;
1689 gBS
->RestoreTPL (OldTpl
);
1694 Gets Graphics Console devcie's foreground color and background color.
1696 @param This Protocol instance pointer.
1697 @param Foreground Returned text foreground color.
1698 @param Background Returned text background color.
1700 @retval EFI_SUCCESS It returned always.
1705 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1706 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1707 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1712 Attribute
= This
->Mode
->Attribute
& 0x7F;
1714 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1715 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1721 Draw Unicode string on the Graphics Console device's screen.
1723 @param This Protocol instance pointer.
1724 @param UnicodeWeight One Unicode string to be displayed.
1725 @param Count The count of Unicode string.
1727 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1728 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1730 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1734 DrawUnicodeWeightAtCursorN (
1735 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1736 IN CHAR16
*UnicodeWeight
,
1741 GRAPHICS_CONSOLE_DEV
*Private
;
1742 EFI_IMAGE_OUTPUT
*Blt
;
1744 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1745 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1746 EFI_HII_ROW_INFO
*RowInfoArray
;
1747 UINTN RowInfoArraySize
;
1749 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1750 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1752 return EFI_OUT_OF_RESOURCES
;
1755 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1756 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1758 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1759 if (String
== NULL
) {
1761 return EFI_OUT_OF_RESOURCES
;
1764 // Set the end character
1766 *(String
+ Count
) = L
'\0';
1768 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1769 if (FontInfo
== NULL
) {
1772 return EFI_OUT_OF_RESOURCES
;
1775 // Get current foreground and background colors.
1777 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1779 if (Private
->GraphicsOutput
!= NULL
) {
1781 // If Graphics Output protocol exists, using HII Font protocol to draw.
1783 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1785 Status
= mHiiFont
->StringToImage (
1787 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1791 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1792 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1798 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1800 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1801 // using UGA Draw protocol to draw.
1803 ASSERT (Private
->UgaDraw
!= NULL
);
1805 UgaDraw
= Private
->UgaDraw
;
1807 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1808 if (Blt
->Image
.Bitmap
== NULL
) {
1811 return EFI_OUT_OF_RESOURCES
;
1814 RowInfoArray
= NULL
;
1816 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1817 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1819 Status
= mHiiFont
->StringToImage (
1821 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1825 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1826 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1832 if (!EFI_ERROR (Status
)) {
1834 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1835 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1837 ASSERT (RowInfoArraySize
<= 1);
1839 Status
= UgaDraw
->Blt (
1841 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1842 EfiUgaBltBufferToVideo
,
1843 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1844 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1845 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1846 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1847 RowInfoArray
[0].LineWidth
,
1848 RowInfoArray
[0].LineHeight
,
1849 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1853 FreePool (RowInfoArray
);
1854 FreePool (Blt
->Image
.Bitmap
);
1856 Status
= EFI_UNSUPPORTED
;
1862 if (String
!= NULL
) {
1865 if (FontInfo
!= NULL
) {
1866 FreePool (FontInfo
);
1872 Flush the cursor on the screen.
1874 If CursorVisible is FALSE, nothing to do and return directly.
1875 If CursorVisible is TRUE,
1876 i) If the cursor shows on screen, it will be erased.
1877 ii) If the cursor does not show on screen, it will be shown.
1879 @param This Protocol instance pointer.
1881 @retval EFI_SUCCESS The cursor is erased successfully.
1886 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1889 GRAPHICS_CONSOLE_DEV
*Private
;
1890 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1893 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1894 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1895 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1896 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1897 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1901 CurrentMode
= This
->Mode
;
1903 if (!CurrentMode
->CursorVisible
) {
1907 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1908 GraphicsOutput
= Private
->GraphicsOutput
;
1909 UgaDraw
= Private
->UgaDraw
;
1912 // In this driver, only narrow character was supported.
1915 // Blt a character to the screen
1917 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1918 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1919 if (GraphicsOutput
!= NULL
) {
1920 GraphicsOutput
->Blt (
1922 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1923 EfiBltVideoToBltBuffer
,
1930 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1932 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1935 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1936 EfiUgaVideoToBltBuffer
,
1943 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1947 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1950 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1952 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1953 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1954 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1955 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1960 if (GraphicsOutput
!= NULL
) {
1961 GraphicsOutput
->Blt (
1963 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1964 EfiBltBufferToVideo
,
1971 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1973 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1976 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1977 EfiUgaBltBufferToVideo
,
1984 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1992 HII Database Protocol notification event handler.
1994 Register font package when HII Database Protocol has been installed.
1996 @param[in] Event Event whose notification function is being invoked.
1997 @param[in] Context Pointer to the notification function's context.
2001 RegisterFontPackage (
2007 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
2008 UINT32 PackageLength
;
2011 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
2014 // Locate HII Database Protocol
2016 Status
= gBS
->LocateProtocol (
2017 &gEfiHiiDatabaseProtocolGuid
,
2019 (VOID
**) &HiiDatabase
2021 if (EFI_ERROR (Status
)) {
2026 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
2028 // +--------------------------------+ <-- Package
2030 // | PackageLength(4 bytes) |
2032 // |--------------------------------| <-- SimplifiedFont
2034 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
2036 // |--------------------------------| <-- Location
2038 // | gUsStdNarrowGlyphData |
2040 // +--------------------------------+
2042 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
2043 Package
= AllocateZeroPool (PackageLength
);
2044 ASSERT (Package
!= NULL
);
2046 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
2047 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
2048 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
2049 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
2050 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
2052 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
2053 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
2056 // Add this simplified font package to a package list then install it.
2058 mHiiHandle
= HiiAddPackages (
2059 &mFontPackageListGuid
,
2064 ASSERT (mHiiHandle
!= NULL
);
2069 The user Entry Point for module GraphicsConsole. The user code starts with this function.
2071 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2072 @param[in] SystemTable A pointer to the EFI System Table.
2074 @retval EFI_SUCCESS The entry point is executed successfully.
2075 @return other Some error occurs when executing this entry point.
2080 InitializeGraphicsConsole (
2081 IN EFI_HANDLE ImageHandle
,
2082 IN EFI_SYSTEM_TABLE
*SystemTable
2088 // Register notify function on HII Database Protocol to add font package.
2090 EfiCreateProtocolNotifyEvent (
2091 &gEfiHiiDatabaseProtocolGuid
,
2093 RegisterFontPackage
,
2099 // Install driver model protocol(s).
2101 Status
= EfiLibInstallDriverBindingComponentName2 (
2104 &gGraphicsConsoleDriverBinding
,
2106 &gGraphicsConsoleComponentName
,
2107 &gGraphicsConsoleComponentName2
2109 ASSERT_EFI_ERROR (Status
);