2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "GraphicsConsole.h"
18 // Graphics Console Device Private Data template
20 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
21 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
22 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
23 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
25 GraphicsConsoleConOutReset
,
26 GraphicsConsoleConOutOutputString
,
27 GraphicsConsoleConOutTestString
,
28 GraphicsConsoleConOutQueryMode
,
29 GraphicsConsoleConOutSetMode
,
30 GraphicsConsoleConOutSetAttribute
,
31 GraphicsConsoleConOutClearScreen
,
32 GraphicsConsoleConOutSetCursorPosition
,
33 GraphicsConsoleConOutEnableCursor
,
34 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
39 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
44 (GRAPHICS_CONSOLE_MODE_DATA
*) NULL
,
45 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
48 GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData
[] = {
51 // New modes can be added here.
52 // The last entry is specific for full screen mode.
57 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
58 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
59 EFI_HII_HANDLE mHiiHandle
;
60 EFI_EVENT mHiiRegistration
;
62 EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
64 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
66 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mGraphicsEfiColors
[16] = {
70 {0x00, 0x00, 0x00, 0x00}, // BLACK
71 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
72 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
73 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
74 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
75 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
76 {0x00, 0x98, 0x98, 0x00}, // BROWN
77 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
78 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
79 {0xff, 0x00, 0x00, 0x00}, // BLUE
80 {0x00, 0xff, 0x00, 0x00}, // LIME
81 {0xff, 0xff, 0x00, 0x00}, // CYAN
82 {0x00, 0x00, 0xff, 0x00}, // RED
83 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
84 {0x00, 0xff, 0xff, 0x00}, // YELLOW
85 {0xff, 0xff, 0xff, 0x00} // WHITE
88 EFI_NARROW_GLYPH mCursorGlyph
= {
91 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
94 CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
96 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
97 GraphicsConsoleControllerDriverSupported
,
98 GraphicsConsoleControllerDriverStart
,
99 GraphicsConsoleControllerDriverStop
,
106 Test to see if Graphics Console could be supported on the Controller.
108 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
109 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
110 if PcdUgaConsumeSupport is set to FALSE.)
112 @param This Protocol instance pointer.
113 @param Controller Handle of device to test.
114 @param RemainingDevicePath Optional parameter use to pick a specific child
117 @retval EFI_SUCCESS This driver supports this device.
118 @retval other This driver does not support this device.
123 GraphicsConsoleControllerDriverSupported (
124 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
125 IN EFI_HANDLE Controller
,
126 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
130 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
131 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
132 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
134 GraphicsOutput
= NULL
;
137 // Open the IO Abstraction(s) needed to perform the supported test
139 Status
= gBS
->OpenProtocol (
141 &gEfiGraphicsOutputProtocolGuid
,
142 (VOID
**) &GraphicsOutput
,
143 This
->DriverBindingHandle
,
145 EFI_OPEN_PROTOCOL_BY_DRIVER
148 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
150 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
152 Status
= gBS
->OpenProtocol (
154 &gEfiUgaDrawProtocolGuid
,
156 This
->DriverBindingHandle
,
158 EFI_OPEN_PROTOCOL_BY_DRIVER
161 if (EFI_ERROR (Status
)) {
166 // We need to ensure that we do not layer on top of a virtual handle.
167 // We need to ensure that the handles produced by the conspliter do not
170 Status
= gBS
->OpenProtocol (
172 &gEfiDevicePathProtocolGuid
,
173 (VOID
**) &DevicePath
,
174 This
->DriverBindingHandle
,
176 EFI_OPEN_PROTOCOL_BY_DRIVER
178 if (!EFI_ERROR (Status
)) {
181 &gEfiDevicePathProtocolGuid
,
182 This
->DriverBindingHandle
,
190 // Does Hii Exist? If not, we aren't ready to run
192 Status
= EfiLocateHiiProtocol ();
195 // Close the I/O Abstraction(s) used to perform the supported test
198 if (GraphicsOutput
!= NULL
) {
201 &gEfiGraphicsOutputProtocolGuid
,
202 This
->DriverBindingHandle
,
205 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
208 &gEfiUgaDrawProtocolGuid
,
209 This
->DriverBindingHandle
,
217 Initialize all the text modes which the graphics console supports.
219 It returns information for available text modes that the graphics can support.
221 @param[in] HorizontalResolution The size of video screen in pixels in the X dimension.
222 @param[in] VerticalResolution The size of video screen in pixels in the Y dimension.
223 @param[in] GopModeNumber The graphics mode number which graphis console is based on.
224 @param[out] TextModeCount The total number of text modes that graphics console supports.
225 @param[out] TextModeData The buffer to the text modes column and row information.
226 Caller is responsible to free it when it's non-NULL.
228 @retval EFI_SUCCESS The supporting mode information is returned.
229 @retval EFI_INVALID_PARAMETER The parameters are invalid.
233 InitializeGraphicsConsoleTextMode (
234 IN UINT32 HorizontalResolution
,
235 IN UINT32 VerticalResolution
,
236 IN UINT32 GopModeNumber
,
237 OUT UINTN
*TextModeCount
,
238 OUT GRAPHICS_CONSOLE_MODE_DATA
**TextModeData
243 GRAPHICS_CONSOLE_MODE_DATA
*ModeBuffer
;
244 GRAPHICS_CONSOLE_MODE_DATA
*NewModeBuffer
;
250 if ((TextModeCount
== NULL
) || (TextModeData
== NULL
)) {
251 return EFI_INVALID_PARAMETER
;
254 Count
= sizeof (mGraphicsConsoleModeData
) / sizeof (GRAPHICS_CONSOLE_MODE_DATA
);
257 // Compute the maximum number of text Rows and Columns that this current graphics mode can support.
258 // To make graphics console work well, MaxColumns and MaxRows should not be zero.
260 MaxColumns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
261 MaxRows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
264 // According to UEFI spec, all output devices support at least 80x25 text mode.
266 ASSERT ((MaxColumns
>= 80) && (MaxRows
>= 25));
269 // Add full screen mode to the last entry.
271 mGraphicsConsoleModeData
[Count
- 1].Columns
= MaxColumns
;
272 mGraphicsConsoleModeData
[Count
- 1].Rows
= MaxRows
;
275 // Get defined mode buffer pointer.
277 ModeBuffer
= mGraphicsConsoleModeData
;
280 // Here we make sure that the final mode exposed does not include the duplicated modes,
281 // and does not include the invalid modes which exceed the max column and row.
282 // Reserve 2 modes for 80x25, 80x50 of graphics console.
284 NewModeBuffer
= AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA
) * (Count
+ 2));
285 ASSERT (NewModeBuffer
!= NULL
);
288 // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.
292 NewModeBuffer
[ValidCount
].Columns
= 80;
293 NewModeBuffer
[ValidCount
].Rows
= 25;
294 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
295 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
296 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
297 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
298 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
301 if ((MaxColumns
>= 80) && (MaxRows
>= 50)) {
302 NewModeBuffer
[ValidCount
].Columns
= 80;
303 NewModeBuffer
[ValidCount
].Rows
= 50;
304 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
305 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
307 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
308 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
309 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
313 // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.
315 for (Index
= 0; Index
< Count
; Index
++) {
316 if ((ModeBuffer
[Index
].Columns
== 0) || (ModeBuffer
[Index
].Rows
== 0) ||
317 (ModeBuffer
[Index
].Columns
> MaxColumns
) || (ModeBuffer
[Index
].Rows
> MaxRows
)) {
319 // Skip the pre-defined mode which is invalid or exceeds the max column and row.
323 for (ValidIndex
= 0; ValidIndex
< ValidCount
; ValidIndex
++) {
324 if ((ModeBuffer
[Index
].Columns
== NewModeBuffer
[ValidIndex
].Columns
) &&
325 (ModeBuffer
[Index
].Rows
== NewModeBuffer
[ValidIndex
].Rows
)) {
327 // Skip the duplicated mode.
332 if (ValidIndex
== ValidCount
) {
333 NewModeBuffer
[ValidCount
].Columns
= ModeBuffer
[Index
].Columns
;
334 NewModeBuffer
[ValidCount
].Rows
= ModeBuffer
[Index
].Rows
;
335 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
336 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
337 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
338 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
339 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
345 for (Index
= 0; Index
< ValidCount
; Index
++) {
346 DEBUG ((EFI_D_INFO
, "Graphics - Mode %d, Column = %d, Row = %d\n",
347 Index
, NewModeBuffer
[Index
].Columns
, NewModeBuffer
[Index
].Rows
));
352 // Return valid mode count and mode information buffer.
354 *TextModeCount
= ValidCount
;
355 *TextModeData
= NewModeBuffer
;
360 Start this driver on Controller by opening Graphics Output protocol or
361 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
362 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
364 @param This Protocol instance pointer.
365 @param Controller Handle of device to bind driver to
366 @param RemainingDevicePath Optional parameter use to pick a specific child
369 @retval EFI_SUCCESS This driver is added to Controller.
370 @retval other This driver does not support this device.
375 GraphicsConsoleControllerDriverStart (
376 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
377 IN EFI_HANDLE Controller
,
378 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
382 GRAPHICS_CONSOLE_DEV
*Private
;
383 UINT32 HorizontalResolution
;
384 UINT32 VerticalResolution
;
390 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
;
392 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
397 // Initialize the Graphics Console device instance
399 Private
= AllocateCopyPool (
400 sizeof (GRAPHICS_CONSOLE_DEV
),
401 &mGraphicsConsoleDevTemplate
403 if (Private
== NULL
) {
404 return EFI_OUT_OF_RESOURCES
;
407 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
409 Status
= gBS
->OpenProtocol (
411 &gEfiGraphicsOutputProtocolGuid
,
412 (VOID
**) &Private
->GraphicsOutput
,
413 This
->DriverBindingHandle
,
415 EFI_OPEN_PROTOCOL_BY_DRIVER
418 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
419 Status
= gBS
->OpenProtocol (
421 &gEfiUgaDrawProtocolGuid
,
422 (VOID
**) &Private
->UgaDraw
,
423 This
->DriverBindingHandle
,
425 EFI_OPEN_PROTOCOL_BY_DRIVER
429 if (EFI_ERROR (Status
)) {
433 HorizontalResolution
= PcdGet32 (PcdVideoHorizontalResolution
);
434 VerticalResolution
= PcdGet32 (PcdVideoVerticalResolution
);
436 if (Private
->GraphicsOutput
!= NULL
) {
438 // The console is build on top of Graphics Output Protocol, find the mode number
439 // for the user-defined mode; if there are multiple video devices,
440 // graphic console driver will set all the video devices to the same mode.
442 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
444 // Find the highest resolution which GOP supports.
446 MaxMode
= Private
->GraphicsOutput
->Mode
->MaxMode
;
448 for (ModeIndex
= 0; ModeIndex
< MaxMode
; ModeIndex
++) {
449 Status
= Private
->GraphicsOutput
->QueryMode (
450 Private
->GraphicsOutput
,
455 if (!EFI_ERROR (Status
)) {
456 if ((Info
->HorizontalResolution
> HorizontalResolution
) ||
457 ((Info
->HorizontalResolution
== HorizontalResolution
) && (Info
->VerticalResolution
> VerticalResolution
))) {
458 HorizontalResolution
= Info
->HorizontalResolution
;
459 VerticalResolution
= Info
->VerticalResolution
;
460 ModeNumber
= ModeIndex
;
465 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
466 Status
= EFI_UNSUPPORTED
;
471 // Use user-defined resolution
473 Status
= CheckModeSupported (
474 Private
->GraphicsOutput
,
475 HorizontalResolution
,
479 if (EFI_ERROR (Status
)) {
481 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
483 Status
= CheckModeSupported (
484 Private
->GraphicsOutput
,
489 Mode
= Private
->GraphicsOutput
->Mode
;
490 if (EFI_ERROR (Status
) && Mode
->MaxMode
!= 0) {
492 // Set default mode failed or device don't support default mode, then get the current mode information
494 HorizontalResolution
= Mode
->Info
->HorizontalResolution
;
495 VerticalResolution
= Mode
->Info
->VerticalResolution
;
496 ModeNumber
= Mode
->Mode
;
500 if (ModeNumber
!= Private
->GraphicsOutput
->Mode
->Mode
) {
502 // Current graphics mode is not set or is not set to the mode which we has found,
503 // set the new graphic mode.
505 Status
= Private
->GraphicsOutput
->SetMode (Private
->GraphicsOutput
, ModeNumber
);
506 if (EFI_ERROR (Status
)) {
508 // The mode set operation failed
513 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
515 // At first try to set user-defined resolution
519 Status
= Private
->UgaDraw
->SetMode (
521 HorizontalResolution
,
526 if (EFI_ERROR (Status
)) {
528 // Try to set 800*600 which is required by UEFI/EFI spec
530 Status
= Private
->UgaDraw
->SetMode (
537 if (EFI_ERROR (Status
)) {
538 Status
= Private
->UgaDraw
->GetMode (
540 &HorizontalResolution
,
545 if (EFI_ERROR (Status
)) {
552 DEBUG ((EFI_D_INFO
, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution
, VerticalResolution
));
555 // Initialize the mode which GraphicsConsole supports.
557 Status
= InitializeGraphicsConsoleTextMode (
558 HorizontalResolution
,
565 if (EFI_ERROR (Status
)) {
570 // Update the maximum number of modes
572 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
575 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
576 if (EFI_ERROR (Status
)) {
579 Status
= GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
580 if (EFI_ERROR (Status
)) {
586 // Install protocol interfaces for the Graphics Console device.
588 Status
= gBS
->InstallMultipleProtocolInterfaces (
590 &gEfiSimpleTextOutProtocolGuid
,
591 &Private
->SimpleTextOutput
,
596 if (EFI_ERROR (Status
)) {
598 // Close the GOP and UGA Draw Protocol
600 if (Private
->GraphicsOutput
!= NULL
) {
603 &gEfiGraphicsOutputProtocolGuid
,
604 This
->DriverBindingHandle
,
607 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
610 &gEfiUgaDrawProtocolGuid
,
611 This
->DriverBindingHandle
,
616 if (Private
->LineBuffer
!= NULL
) {
617 FreePool (Private
->LineBuffer
);
620 if (Private
->ModeData
!= NULL
) {
621 FreePool (Private
->ModeData
);
634 Stop this driver on Controller by removing Simple Text Out protocol
635 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
636 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
639 @param This Protocol instance pointer.
640 @param Controller Handle of device to stop driver on
641 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
642 children is zero stop the entire bus driver.
643 @param ChildHandleBuffer List of Child Handles to Stop.
645 @retval EFI_SUCCESS This driver is removed Controller.
646 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
648 @retval other This driver was not removed from this device.
653 GraphicsConsoleControllerDriverStop (
654 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
655 IN EFI_HANDLE Controller
,
656 IN UINTN NumberOfChildren
,
657 IN EFI_HANDLE
*ChildHandleBuffer
661 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
662 GRAPHICS_CONSOLE_DEV
*Private
;
664 Status
= gBS
->OpenProtocol (
666 &gEfiSimpleTextOutProtocolGuid
,
667 (VOID
**) &SimpleTextOutput
,
668 This
->DriverBindingHandle
,
670 EFI_OPEN_PROTOCOL_GET_PROTOCOL
672 if (EFI_ERROR (Status
)) {
673 return EFI_NOT_STARTED
;
676 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
678 Status
= gBS
->UninstallProtocolInterface (
680 &gEfiSimpleTextOutProtocolGuid
,
681 &Private
->SimpleTextOutput
684 if (!EFI_ERROR (Status
)) {
686 // Close the GOP or UGA IO Protocol
688 if (Private
->GraphicsOutput
!= NULL
) {
691 &gEfiGraphicsOutputProtocolGuid
,
692 This
->DriverBindingHandle
,
695 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
698 &gEfiUgaDrawProtocolGuid
,
699 This
->DriverBindingHandle
,
704 if (Private
->LineBuffer
!= NULL
) {
705 FreePool (Private
->LineBuffer
);
708 if (Private
->ModeData
!= NULL
) {
709 FreePool (Private
->ModeData
);
713 // Free our instance data
722 Check if the current specific mode supported the user defined resolution
723 for the Graphics Console device based on Graphics Output Protocol.
725 If yes, set the graphic devcice's current mode to this specific mode.
727 @param GraphicsOutput Graphics Output Protocol instance pointer.
728 @param HorizontalResolution User defined horizontal resolution
729 @param VerticalResolution User defined vertical resolution.
730 @param CurrentModeNumber Current specific mode to be check.
732 @retval EFI_SUCCESS The mode is supported.
733 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
735 @retval other The specific mode does not support user defined
736 resolution or failed to set the current mode to the
737 specific mode on graphics device.
742 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
743 IN UINT32 HorizontalResolution
,
744 IN UINT32 VerticalResolution
,
745 OUT UINT32
*CurrentModeNumber
751 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
754 Status
= EFI_SUCCESS
;
755 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
757 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
758 Status
= GraphicsOutput
->QueryMode (
764 if (!EFI_ERROR (Status
)) {
765 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
766 (Info
->VerticalResolution
== VerticalResolution
)) {
767 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== HorizontalResolution
) &&
768 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== VerticalResolution
)) {
770 // If video device has been set to this mode, we do not need to SetMode again
775 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
776 if (!EFI_ERROR (Status
)) {
786 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
787 Status
= EFI_UNSUPPORTED
;
790 *CurrentModeNumber
= ModeNumber
;
796 Locate HII Database protocol and HII Font protocol.
798 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
799 are located successfully.
800 @return other Failed to locate HII Database protocol or
805 EfiLocateHiiProtocol (
814 // There should only be one - so buffer size is this
816 Size
= sizeof (EFI_HANDLE
);
818 Status
= gBS
->LocateHandle (
820 &gEfiHiiDatabaseProtocolGuid
,
826 if (EFI_ERROR (Status
)) {
830 Status
= gBS
->HandleProtocol (
832 &gEfiHiiDatabaseProtocolGuid
,
833 (VOID
**) &mHiiDatabase
836 if (EFI_ERROR (Status
)) {
840 Status
= gBS
->HandleProtocol (
842 &gEfiHiiFontProtocolGuid
,
849 // Body of the STO functions
853 Reset the text output device hardware and optionally run diagnostics.
855 Implements SIMPLE_TEXT_OUTPUT.Reset().
856 If ExtendeVerification is TRUE, then perform dependent Graphics Console
857 device reset, and set display mode to mode 0.
858 If ExtendedVerification is FALSE, only set display mode to mode 0.
860 @param This Protocol instance pointer.
861 @param ExtendedVerification Indicates that the driver may perform a more
862 exhaustive verification operation of the device
865 @retval EFI_SUCCESS The text output device was reset.
866 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
872 GraphicsConsoleConOutReset (
873 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
874 IN BOOLEAN ExtendedVerification
878 Status
= This
->SetMode (This
, 0);
879 if (EFI_ERROR (Status
)) {
882 Status
= This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
888 Write a Unicode string to the output device.
890 Implements SIMPLE_TEXT_OUTPUT.OutputString().
891 The Unicode string will be converted to Glyphs and will be
892 sent to the Graphics Console.
894 @param This Protocol instance pointer.
895 @param WString The NULL-terminated Unicode string to be displayed
896 on the output device(s). All output devices must
897 also support the Unicode drawing defined in this file.
899 @retval EFI_SUCCESS The string was output to the device.
900 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
902 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
904 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
905 characters in the Unicode string could not be
906 rendered and were skipped.
911 GraphicsConsoleConOutOutputString (
912 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
916 GRAPHICS_CONSOLE_DEV
*Private
;
917 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
918 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
927 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
928 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
933 INT32 OriginAttribute
;
936 if (This
->Mode
->Mode
== -1) {
938 // If current mode is not valid, return error.
940 return EFI_UNSUPPORTED
;
943 Status
= EFI_SUCCESS
;
945 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
949 Mode
= This
->Mode
->Mode
;
950 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
951 GraphicsOutput
= Private
->GraphicsOutput
;
952 UgaDraw
= Private
->UgaDraw
;
954 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
955 MaxRow
= Private
->ModeData
[Mode
].Rows
;
956 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
957 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
958 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
959 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
960 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
963 // The Attributes won't change when during the time OutputString is called
965 GetTextColors (This
, &Foreground
, &Background
);
974 OriginAttribute
= This
->Mode
->Attribute
;
976 while (*WString
!= L
'\0') {
978 if (*WString
== CHAR_BACKSPACE
) {
980 // If the cursor is at the left edge of the display, then move the cursor
983 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
984 This
->Mode
->CursorRow
--;
985 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
986 This
->OutputString (This
, SpaceStr
);
988 This
->Mode
->CursorRow
--;
989 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
990 } else if (This
->Mode
->CursorColumn
> 0) {
992 // If the cursor is not at the left edge of the display, then move the cursor
995 This
->Mode
->CursorColumn
--;
996 This
->OutputString (This
, SpaceStr
);
998 This
->Mode
->CursorColumn
--;
1003 } else if (*WString
== CHAR_LINEFEED
) {
1005 // If the cursor is at the bottom of the display, then scroll the display one
1006 // row, and do not update the cursor position. Otherwise, move the cursor
1009 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
1010 if (GraphicsOutput
!= NULL
) {
1012 // Scroll Screen Up One Row
1014 GraphicsOutput
->Blt (
1019 DeltaY
+ EFI_GLYPH_HEIGHT
,
1028 // Print Blank Line at last line
1030 GraphicsOutput
->Blt (
1042 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1044 // Scroll Screen Up One Row
1051 DeltaY
+ EFI_GLYPH_HEIGHT
,
1060 // Print Blank Line at last line
1064 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1076 This
->Mode
->CursorRow
++;
1081 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1083 // Move the cursor to the beginning of the current row.
1085 This
->Mode
->CursorColumn
= 0;
1088 } else if (*WString
== WIDE_CHAR
) {
1090 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1093 } else if (*WString
== NARROW_CHAR
) {
1095 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1100 // Print the character at the current cursor position and move the cursor
1101 // right one column. If this moves the cursor past the right edge of the
1102 // display, then the line should wrap to the beginning of the next line. This
1103 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1104 // bottom of the display, and the line wraps, then the display will be scrolled
1106 // If wide char is going to be displayed, need to display one character at a time
1107 // Or, need to know the display length of a certain string.
1109 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1110 // Count is used to determine how many characters are used regardless of their attributes
1112 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1113 if (WString
[Count
] == CHAR_NULL
||
1114 WString
[Count
] == CHAR_BACKSPACE
||
1115 WString
[Count
] == CHAR_LINEFEED
||
1116 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1117 WString
[Count
] == WIDE_CHAR
||
1118 WString
[Count
] == NARROW_CHAR
) {
1122 // Is the wide attribute on?
1124 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
1126 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1130 // This is the end-case where if we are at column 79 and about to print a wide character
1131 // We should prevent this from happening because we will wrap inappropriately. We should
1132 // not print this character until the next line.
1134 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1141 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1142 if (EFI_ERROR (Status
)) {
1146 // At the end of line, output carriage return and line feed
1149 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1150 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1151 This
->Mode
->CursorColumn
-= 2;
1152 This
->OutputString (This
, SpaceStr
);
1155 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1157 This
->OutputString (This
, mCrLfString
);
1163 This
->Mode
->Attribute
= OriginAttribute
;
1168 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1171 gBS
->RestoreTPL (OldTpl
);
1177 Verifies that all characters in a Unicode string can be output to the
1180 Implements SIMPLE_TEXT_OUTPUT.TestString().
1181 If one of the characters in the *Wstring is neither valid valid Unicode
1182 drawing characters, not ASCII code, then this function will return
1185 @param This Protocol instance pointer.
1186 @param WString The NULL-terminated Unicode string to be examined for the output
1189 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1190 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1191 rendered by one or more of the output devices mapped
1197 GraphicsConsoleConOutTestString (
1198 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1205 EFI_IMAGE_OUTPUT
*Blt
;
1210 while (WString
[Count
] != 0) {
1211 Status
= mHiiFont
->GetGlyph (
1224 if (EFI_ERROR (Status
)) {
1225 return EFI_UNSUPPORTED
;
1234 Returns information for an available text mode that the output device(s)
1237 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1238 It returnes information for an available text mode that the Graphics Console supports.
1239 In this driver,we only support text mode 80x25, which is defined as mode 0.
1241 @param This Protocol instance pointer.
1242 @param ModeNumber The mode number to return information on.
1243 @param Columns The returned columns of the requested mode.
1244 @param Rows The returned rows of the requested mode.
1246 @retval EFI_SUCCESS The requested mode information is returned.
1247 @retval EFI_UNSUPPORTED The mode number is not valid.
1252 GraphicsConsoleConOutQueryMode (
1253 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1254 IN UINTN ModeNumber
,
1259 GRAPHICS_CONSOLE_DEV
*Private
;
1263 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1264 return EFI_UNSUPPORTED
;
1267 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1268 Status
= EFI_SUCCESS
;
1270 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1272 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1273 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1275 if (*Columns
<= 0 || *Rows
<= 0) {
1276 Status
= EFI_UNSUPPORTED
;
1282 gBS
->RestoreTPL (OldTpl
);
1288 Sets the output device(s) to a specified mode.
1290 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1291 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1293 @param This Protocol instance pointer.
1294 @param ModeNumber The text mode to set.
1296 @retval EFI_SUCCESS The requested text mode is set.
1297 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1298 Graphics Console device error.
1299 @retval EFI_UNSUPPORTED The text mode number is not valid.
1304 GraphicsConsoleConOutSetMode (
1305 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1310 GRAPHICS_CONSOLE_DEV
*Private
;
1311 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1312 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1313 UINT32 HorizontalResolution
;
1314 UINT32 VerticalResolution
;
1315 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1316 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1321 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1323 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1324 GraphicsOutput
= Private
->GraphicsOutput
;
1325 UgaDraw
= Private
->UgaDraw
;
1328 // Make sure the requested mode number is supported
1330 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1331 Status
= EFI_UNSUPPORTED
;
1335 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1337 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1338 Status
= EFI_UNSUPPORTED
;
1343 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1345 if (Private
->LineBuffer
!= NULL
) {
1347 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1349 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1351 // Clear the current text window on the current graphics console
1353 This
->ClearScreen (This
);
1354 Status
= EFI_SUCCESS
;
1358 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1359 // so erase the cursor, and free the LineBuffer for the current mode
1363 FreePool (Private
->LineBuffer
);
1367 // Attempt to allocate a line buffer for the requested mode number
1369 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1371 if (NewLineBuffer
== NULL
) {
1373 // The new line buffer could not be allocated, so return an error.
1374 // No changes to the state of the current console have been made, so the current console is still valid
1376 Status
= EFI_OUT_OF_RESOURCES
;
1381 // Assign the current line buffer to the newly allocated line buffer
1383 Private
->LineBuffer
= NewLineBuffer
;
1385 if (GraphicsOutput
!= NULL
) {
1386 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1388 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1390 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1391 if (EFI_ERROR (Status
)) {
1393 // The mode set operation failed
1399 // The current graphics mode is correct, so simply clear the entire display
1401 Status
= GraphicsOutput
->Blt (
1403 &mGraphicsEfiColors
[0],
1410 ModeData
->GopHeight
,
1414 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1416 // Get the current UGA Draw mode information
1418 Status
= UgaDraw
->GetMode (
1420 &HorizontalResolution
,
1421 &VerticalResolution
,
1425 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1427 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1429 Status
= UgaDraw
->SetMode (
1432 ModeData
->GopHeight
,
1436 if (EFI_ERROR (Status
)) {
1438 // The mode set operation failed
1444 // The current graphics mode is correct, so simply clear the entire display
1446 Status
= UgaDraw
->Blt (
1448 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1455 ModeData
->GopHeight
,
1462 // The new mode is valid, so commit the mode change
1464 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1467 // Move the text cursor to the upper left hand corner of the display and flush it
1469 This
->Mode
->CursorColumn
= 0;
1470 This
->Mode
->CursorRow
= 0;
1474 Status
= EFI_SUCCESS
;
1477 gBS
->RestoreTPL (OldTpl
);
1483 Sets the background and foreground colors for the OutputString () and
1484 ClearScreen () functions.
1486 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1488 @param This Protocol instance pointer.
1489 @param Attribute The attribute to set. Bits 0..3 are the foreground
1490 color, and bits 4..6 are the background color.
1491 All other bits are undefined and must be zero.
1493 @retval EFI_SUCCESS The requested attribute is set.
1494 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1495 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1500 GraphicsConsoleConOutSetAttribute (
1501 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1507 if ((Attribute
| 0xFF) != 0xFF) {
1508 return EFI_UNSUPPORTED
;
1511 if (This
->Mode
->Mode
== -1) {
1513 // If current mode is not valid, return error.
1515 return EFI_UNSUPPORTED
;
1518 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1522 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1526 This
->Mode
->Attribute
= (INT32
) Attribute
;
1530 gBS
->RestoreTPL (OldTpl
);
1537 Clears the output device(s) display to the currently selected background
1540 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1542 @param This Protocol instance pointer.
1544 @retval EFI_SUCCESS The operation completed successfully.
1545 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1546 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1551 GraphicsConsoleConOutClearScreen (
1552 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1556 GRAPHICS_CONSOLE_DEV
*Private
;
1557 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1558 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1559 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1560 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1561 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1564 if (This
->Mode
->Mode
== -1) {
1566 // If current mode is not valid, return error.
1568 return EFI_UNSUPPORTED
;
1571 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1573 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1574 GraphicsOutput
= Private
->GraphicsOutput
;
1575 UgaDraw
= Private
->UgaDraw
;
1576 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1578 GetTextColors (This
, &Foreground
, &Background
);
1579 if (GraphicsOutput
!= NULL
) {
1580 Status
= GraphicsOutput
->Blt (
1589 ModeData
->GopHeight
,
1592 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1593 Status
= UgaDraw
->Blt (
1595 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1602 ModeData
->GopHeight
,
1606 Status
= EFI_UNSUPPORTED
;
1609 This
->Mode
->CursorColumn
= 0;
1610 This
->Mode
->CursorRow
= 0;
1614 gBS
->RestoreTPL (OldTpl
);
1621 Sets the current coordinates of the cursor position.
1623 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1625 @param This Protocol instance pointer.
1626 @param Column The position to set the cursor to. Must be greater than or
1627 equal to zero and less than the number of columns and rows
1629 @param Row The position to set the cursor to. Must be greater than or
1630 equal to zero and less than the number of columns and rows
1633 @retval EFI_SUCCESS The operation completed successfully.
1634 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1635 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1636 cursor position is invalid for the current mode.
1641 GraphicsConsoleConOutSetCursorPosition (
1642 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1647 GRAPHICS_CONSOLE_DEV
*Private
;
1648 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1652 if (This
->Mode
->Mode
== -1) {
1654 // If current mode is not valid, return error.
1656 return EFI_UNSUPPORTED
;
1659 Status
= EFI_SUCCESS
;
1661 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1663 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1664 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1666 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1667 Status
= EFI_UNSUPPORTED
;
1671 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1672 Status
= EFI_SUCCESS
;
1678 This
->Mode
->CursorColumn
= (INT32
) Column
;
1679 This
->Mode
->CursorRow
= (INT32
) Row
;
1684 gBS
->RestoreTPL (OldTpl
);
1691 Makes the cursor visible or invisible.
1693 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1695 @param This Protocol instance pointer.
1696 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1697 the cursor is set to be invisible.
1699 @retval EFI_SUCCESS The operation completed successfully.
1700 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
1706 GraphicsConsoleConOutEnableCursor (
1707 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1713 if (This
->Mode
->Mode
== -1) {
1715 // If current mode is not valid, return error.
1717 return EFI_UNSUPPORTED
;
1720 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1724 This
->Mode
->CursorVisible
= Visible
;
1728 gBS
->RestoreTPL (OldTpl
);
1733 Gets Graphics Console devcie's foreground color and background color.
1735 @param This Protocol instance pointer.
1736 @param Foreground Returned text foreground color.
1737 @param Background Returned text background color.
1739 @retval EFI_SUCCESS It returned always.
1744 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1745 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1746 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1751 Attribute
= This
->Mode
->Attribute
& 0x7F;
1753 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1754 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1760 Draw Unicode string on the Graphics Console device's screen.
1762 @param This Protocol instance pointer.
1763 @param UnicodeWeight One Unicode string to be displayed.
1764 @param Count The count of Unicode string.
1766 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1767 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1769 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1773 DrawUnicodeWeightAtCursorN (
1774 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1775 IN CHAR16
*UnicodeWeight
,
1780 GRAPHICS_CONSOLE_DEV
*Private
;
1781 EFI_IMAGE_OUTPUT
*Blt
;
1783 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1784 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1785 EFI_HII_ROW_INFO
*RowInfoArray
;
1786 UINTN RowInfoArraySize
;
1788 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1789 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1791 return EFI_OUT_OF_RESOURCES
;
1794 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1795 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1797 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1798 if (String
== NULL
) {
1800 return EFI_OUT_OF_RESOURCES
;
1803 // Set the end character
1805 *(String
+ Count
) = L
'\0';
1807 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1808 if (FontInfo
== NULL
) {
1811 return EFI_OUT_OF_RESOURCES
;
1814 // Get current foreground and background colors.
1816 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1818 if (Private
->GraphicsOutput
!= NULL
) {
1820 // If Graphics Output protocol exists, using HII Font protocol to draw.
1822 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1824 Status
= mHiiFont
->StringToImage (
1826 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1830 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1831 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1837 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1839 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1840 // using UGA Draw protocol to draw.
1842 ASSERT (Private
->UgaDraw
!= NULL
);
1844 UgaDraw
= Private
->UgaDraw
;
1846 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1847 if (Blt
->Image
.Bitmap
== NULL
) {
1850 return EFI_OUT_OF_RESOURCES
;
1853 RowInfoArray
= NULL
;
1855 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1856 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1858 Status
= mHiiFont
->StringToImage (
1860 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1864 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1865 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1871 if (!EFI_ERROR (Status
)) {
1873 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1874 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1876 ASSERT (RowInfoArraySize
<= 1);
1878 Status
= UgaDraw
->Blt (
1880 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1881 EfiUgaBltBufferToVideo
,
1882 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1883 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1884 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1885 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1886 RowInfoArray
[0].LineWidth
,
1887 RowInfoArray
[0].LineHeight
,
1888 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1892 FreePool (RowInfoArray
);
1893 FreePool (Blt
->Image
.Bitmap
);
1895 Status
= EFI_UNSUPPORTED
;
1901 if (String
!= NULL
) {
1904 if (FontInfo
!= NULL
) {
1905 FreePool (FontInfo
);
1911 Flush the cursor on the screen.
1913 If CursorVisible is FALSE, nothing to do and return directly.
1914 If CursorVisible is TRUE,
1915 i) If the cursor shows on screen, it will be erased.
1916 ii) If the cursor does not show on screen, it will be shown.
1918 @param This Protocol instance pointer.
1920 @retval EFI_SUCCESS The cursor is erased successfully.
1925 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1928 GRAPHICS_CONSOLE_DEV
*Private
;
1929 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1932 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1933 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1934 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1935 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1936 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1940 CurrentMode
= This
->Mode
;
1942 if (!CurrentMode
->CursorVisible
) {
1946 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1947 GraphicsOutput
= Private
->GraphicsOutput
;
1948 UgaDraw
= Private
->UgaDraw
;
1951 // In this driver, only narrow character was supported.
1954 // Blt a character to the screen
1956 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1957 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1958 if (GraphicsOutput
!= NULL
) {
1959 GraphicsOutput
->Blt (
1961 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1962 EfiBltVideoToBltBuffer
,
1969 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1971 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1974 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1975 EfiUgaVideoToBltBuffer
,
1982 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1986 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1989 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1991 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1992 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1993 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1994 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1999 if (GraphicsOutput
!= NULL
) {
2000 GraphicsOutput
->Blt (
2002 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
2003 EfiBltBufferToVideo
,
2010 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
2012 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
2015 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
2016 EfiUgaBltBufferToVideo
,
2023 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
2031 HII Database Protocol notification event handler.
2033 Register font package when HII Database Protocol has been installed.
2035 @param[in] Event Event whose notification function is being invoked.
2036 @param[in] Context Pointer to the notification function's context.
2040 RegisterFontPackage (
2046 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
2047 UINT32 PackageLength
;
2050 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
2053 // Locate HII Database Protocol
2055 Status
= gBS
->LocateProtocol (
2056 &gEfiHiiDatabaseProtocolGuid
,
2058 (VOID
**) &HiiDatabase
2060 ASSERT_EFI_ERROR (Status
);
2063 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
2065 // +--------------------------------+ <-- Package
2067 // | PackageLength(4 bytes) |
2069 // |--------------------------------| <-- SimplifiedFont
2071 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
2073 // |--------------------------------| <-- Location
2075 // | gUsStdNarrowGlyphData |
2077 // +--------------------------------+
2079 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
2080 Package
= AllocateZeroPool (PackageLength
);
2081 ASSERT (Package
!= NULL
);
2083 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
2084 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
2085 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
2086 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
2087 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
2089 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
2090 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
2093 // Add this simplified font package to a package list then install it.
2095 mHiiHandle
= HiiAddPackages (
2096 &mFontPackageListGuid
,
2101 ASSERT (mHiiHandle
!= NULL
);
2106 The user Entry Point for module GraphicsConsole. The user code starts with this function.
2108 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2109 @param[in] SystemTable A pointer to the EFI System Table.
2111 @retval EFI_SUCCESS The entry point is executed successfully.
2112 @return other Some error occurs when executing this entry point.
2117 InitializeGraphicsConsole (
2118 IN EFI_HANDLE ImageHandle
,
2119 IN EFI_SYSTEM_TABLE
*SystemTable
2125 // Register notify function on HII Database Protocol to add font package.
2127 EfiCreateProtocolNotifyEvent (
2128 &gEfiHiiDatabaseProtocolGuid
,
2130 RegisterFontPackage
,
2136 // Install driver model protocol(s).
2138 Status
= EfiLibInstallDriverBindingComponentName2 (
2141 &gGraphicsConsoleDriverBinding
,
2143 &gGraphicsConsoleComponentName
,
2144 &gGraphicsConsoleComponentName2
2146 ASSERT_EFI_ERROR (Status
);