2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2014, 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 VOID
*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 (
811 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &mHiiDatabase
);
812 if (EFI_ERROR (Status
)) {
816 Status
= gBS
->LocateProtocol (&gEfiHiiFontProtocolGuid
, NULL
, (VOID
**) &mHiiFont
);
821 // Body of the STO functions
825 Reset the text output device hardware and optionally run diagnostics.
827 Implements SIMPLE_TEXT_OUTPUT.Reset().
828 If ExtendeVerification is TRUE, then perform dependent Graphics Console
829 device reset, and set display mode to mode 0.
830 If ExtendedVerification is FALSE, only set display mode to mode 0.
832 @param This Protocol instance pointer.
833 @param ExtendedVerification Indicates that the driver may perform a more
834 exhaustive verification operation of the device
837 @retval EFI_SUCCESS The text output device was reset.
838 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
844 GraphicsConsoleConOutReset (
845 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
846 IN BOOLEAN ExtendedVerification
850 Status
= This
->SetMode (This
, 0);
851 if (EFI_ERROR (Status
)) {
854 Status
= This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
860 Write a Unicode string to the output device.
862 Implements SIMPLE_TEXT_OUTPUT.OutputString().
863 The Unicode string will be converted to Glyphs and will be
864 sent to the Graphics Console.
866 @param This Protocol instance pointer.
867 @param WString The NULL-terminated Unicode string to be displayed
868 on the output device(s). All output devices must
869 also support the Unicode drawing defined in this file.
871 @retval EFI_SUCCESS The string was output to the device.
872 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
874 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
876 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
877 characters in the Unicode string could not be
878 rendered and were skipped.
883 GraphicsConsoleConOutOutputString (
884 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
888 GRAPHICS_CONSOLE_DEV
*Private
;
889 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
890 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
899 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
900 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
905 INT32 OriginAttribute
;
908 if (This
->Mode
->Mode
== -1) {
910 // If current mode is not valid, return error.
912 return EFI_UNSUPPORTED
;
915 Status
= EFI_SUCCESS
;
917 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
921 Mode
= This
->Mode
->Mode
;
922 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
923 GraphicsOutput
= Private
->GraphicsOutput
;
924 UgaDraw
= Private
->UgaDraw
;
926 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
927 MaxRow
= Private
->ModeData
[Mode
].Rows
;
928 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
929 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
930 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
931 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
932 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
935 // The Attributes won't change when during the time OutputString is called
937 GetTextColors (This
, &Foreground
, &Background
);
946 OriginAttribute
= This
->Mode
->Attribute
;
948 while (*WString
!= L
'\0') {
950 if (*WString
== CHAR_BACKSPACE
) {
952 // If the cursor is at the left edge of the display, then move the cursor
955 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
956 This
->Mode
->CursorRow
--;
957 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
958 This
->OutputString (This
, SpaceStr
);
960 This
->Mode
->CursorRow
--;
961 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
962 } else if (This
->Mode
->CursorColumn
> 0) {
964 // If the cursor is not at the left edge of the display, then move the cursor
967 This
->Mode
->CursorColumn
--;
968 This
->OutputString (This
, SpaceStr
);
970 This
->Mode
->CursorColumn
--;
975 } else if (*WString
== CHAR_LINEFEED
) {
977 // If the cursor is at the bottom of the display, then scroll the display one
978 // row, and do not update the cursor position. Otherwise, move the cursor
981 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
982 if (GraphicsOutput
!= NULL
) {
984 // Scroll Screen Up One Row
986 GraphicsOutput
->Blt (
991 DeltaY
+ EFI_GLYPH_HEIGHT
,
1000 // Print Blank Line at last line
1002 GraphicsOutput
->Blt (
1014 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1016 // Scroll Screen Up One Row
1023 DeltaY
+ EFI_GLYPH_HEIGHT
,
1032 // Print Blank Line at last line
1036 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1048 This
->Mode
->CursorRow
++;
1053 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1055 // Move the cursor to the beginning of the current row.
1057 This
->Mode
->CursorColumn
= 0;
1060 } else if (*WString
== WIDE_CHAR
) {
1062 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1065 } else if (*WString
== NARROW_CHAR
) {
1067 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1072 // Print the character at the current cursor position and move the cursor
1073 // right one column. If this moves the cursor past the right edge of the
1074 // display, then the line should wrap to the beginning of the next line. This
1075 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1076 // bottom of the display, and the line wraps, then the display will be scrolled
1078 // If wide char is going to be displayed, need to display one character at a time
1079 // Or, need to know the display length of a certain string.
1081 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1082 // Count is used to determine how many characters are used regardless of their attributes
1084 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1085 if (WString
[Count
] == CHAR_NULL
||
1086 WString
[Count
] == CHAR_BACKSPACE
||
1087 WString
[Count
] == CHAR_LINEFEED
||
1088 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1089 WString
[Count
] == WIDE_CHAR
||
1090 WString
[Count
] == NARROW_CHAR
) {
1094 // Is the wide attribute on?
1096 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
1098 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1102 // This is the end-case where if we are at column 79 and about to print a wide character
1103 // We should prevent this from happening because we will wrap inappropriately. We should
1104 // not print this character until the next line.
1106 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1113 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1114 if (EFI_ERROR (Status
)) {
1118 // At the end of line, output carriage return and line feed
1121 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1122 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1123 This
->Mode
->CursorColumn
-= 2;
1124 This
->OutputString (This
, SpaceStr
);
1127 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1129 This
->OutputString (This
, mCrLfString
);
1135 This
->Mode
->Attribute
= OriginAttribute
;
1140 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1143 gBS
->RestoreTPL (OldTpl
);
1149 Verifies that all characters in a Unicode string can be output to the
1152 Implements SIMPLE_TEXT_OUTPUT.TestString().
1153 If one of the characters in the *Wstring is neither valid valid Unicode
1154 drawing characters, not ASCII code, then this function will return
1157 @param This Protocol instance pointer.
1158 @param WString The NULL-terminated Unicode string to be examined for the output
1161 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1162 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1163 rendered by one or more of the output devices mapped
1169 GraphicsConsoleConOutTestString (
1170 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1177 EFI_IMAGE_OUTPUT
*Blt
;
1182 while (WString
[Count
] != 0) {
1183 Status
= mHiiFont
->GetGlyph (
1196 if (EFI_ERROR (Status
)) {
1197 return EFI_UNSUPPORTED
;
1206 Returns information for an available text mode that the output device(s)
1209 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1210 It returnes information for an available text mode that the Graphics Console supports.
1211 In this driver,we only support text mode 80x25, which is defined as mode 0.
1213 @param This Protocol instance pointer.
1214 @param ModeNumber The mode number to return information on.
1215 @param Columns The returned columns of the requested mode.
1216 @param Rows The returned rows of the requested mode.
1218 @retval EFI_SUCCESS The requested mode information is returned.
1219 @retval EFI_UNSUPPORTED The mode number is not valid.
1224 GraphicsConsoleConOutQueryMode (
1225 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1226 IN UINTN ModeNumber
,
1231 GRAPHICS_CONSOLE_DEV
*Private
;
1235 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1236 return EFI_UNSUPPORTED
;
1239 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1240 Status
= EFI_SUCCESS
;
1242 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1244 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1245 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1247 if (*Columns
<= 0 || *Rows
<= 0) {
1248 Status
= EFI_UNSUPPORTED
;
1254 gBS
->RestoreTPL (OldTpl
);
1260 Sets the output device(s) to a specified mode.
1262 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1263 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1265 @param This Protocol instance pointer.
1266 @param ModeNumber The text mode to set.
1268 @retval EFI_SUCCESS The requested text mode is set.
1269 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1270 Graphics Console device error.
1271 @retval EFI_UNSUPPORTED The text mode number is not valid.
1276 GraphicsConsoleConOutSetMode (
1277 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1282 GRAPHICS_CONSOLE_DEV
*Private
;
1283 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1284 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1285 UINT32 HorizontalResolution
;
1286 UINT32 VerticalResolution
;
1287 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1288 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1293 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1295 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1296 GraphicsOutput
= Private
->GraphicsOutput
;
1297 UgaDraw
= Private
->UgaDraw
;
1300 // Make sure the requested mode number is supported
1302 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1303 Status
= EFI_UNSUPPORTED
;
1307 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1309 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1310 Status
= EFI_UNSUPPORTED
;
1315 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1317 if (Private
->LineBuffer
!= NULL
) {
1319 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1321 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1323 // Clear the current text window on the current graphics console
1325 This
->ClearScreen (This
);
1326 Status
= EFI_SUCCESS
;
1330 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1331 // so erase the cursor, and free the LineBuffer for the current mode
1335 FreePool (Private
->LineBuffer
);
1339 // Attempt to allocate a line buffer for the requested mode number
1341 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1343 if (NewLineBuffer
== NULL
) {
1345 // The new line buffer could not be allocated, so return an error.
1346 // No changes to the state of the current console have been made, so the current console is still valid
1348 Status
= EFI_OUT_OF_RESOURCES
;
1353 // Assign the current line buffer to the newly allocated line buffer
1355 Private
->LineBuffer
= NewLineBuffer
;
1357 if (GraphicsOutput
!= NULL
) {
1358 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1360 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1362 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1363 if (EFI_ERROR (Status
)) {
1365 // The mode set operation failed
1371 // The current graphics mode is correct, so simply clear the entire display
1373 Status
= GraphicsOutput
->Blt (
1375 &mGraphicsEfiColors
[0],
1382 ModeData
->GopHeight
,
1386 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1388 // Get the current UGA Draw mode information
1390 Status
= UgaDraw
->GetMode (
1392 &HorizontalResolution
,
1393 &VerticalResolution
,
1397 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1399 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1401 Status
= UgaDraw
->SetMode (
1404 ModeData
->GopHeight
,
1408 if (EFI_ERROR (Status
)) {
1410 // The mode set operation failed
1416 // The current graphics mode is correct, so simply clear the entire display
1418 Status
= UgaDraw
->Blt (
1420 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1427 ModeData
->GopHeight
,
1434 // The new mode is valid, so commit the mode change
1436 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1439 // Move the text cursor to the upper left hand corner of the display and flush it
1441 This
->Mode
->CursorColumn
= 0;
1442 This
->Mode
->CursorRow
= 0;
1446 Status
= EFI_SUCCESS
;
1449 gBS
->RestoreTPL (OldTpl
);
1455 Sets the background and foreground colors for the OutputString () and
1456 ClearScreen () functions.
1458 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1460 @param This Protocol instance pointer.
1461 @param Attribute The attribute to set. Bits 0..3 are the foreground
1462 color, and bits 4..6 are the background color.
1463 All other bits are undefined and must be zero.
1465 @retval EFI_SUCCESS The requested attribute is set.
1466 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1467 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1472 GraphicsConsoleConOutSetAttribute (
1473 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1479 if ((Attribute
| 0x7F) != 0x7F) {
1480 return EFI_UNSUPPORTED
;
1483 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1487 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1491 This
->Mode
->Attribute
= (INT32
) Attribute
;
1495 gBS
->RestoreTPL (OldTpl
);
1502 Clears the output device(s) display to the currently selected background
1505 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1507 @param This Protocol instance pointer.
1509 @retval EFI_SUCCESS The operation completed successfully.
1510 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1511 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1516 GraphicsConsoleConOutClearScreen (
1517 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1521 GRAPHICS_CONSOLE_DEV
*Private
;
1522 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1523 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1524 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1525 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1526 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1529 if (This
->Mode
->Mode
== -1) {
1531 // If current mode is not valid, return error.
1533 return EFI_UNSUPPORTED
;
1536 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1538 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1539 GraphicsOutput
= Private
->GraphicsOutput
;
1540 UgaDraw
= Private
->UgaDraw
;
1541 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1543 GetTextColors (This
, &Foreground
, &Background
);
1544 if (GraphicsOutput
!= NULL
) {
1545 Status
= GraphicsOutput
->Blt (
1554 ModeData
->GopHeight
,
1557 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1558 Status
= UgaDraw
->Blt (
1560 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1567 ModeData
->GopHeight
,
1571 Status
= EFI_UNSUPPORTED
;
1574 This
->Mode
->CursorColumn
= 0;
1575 This
->Mode
->CursorRow
= 0;
1579 gBS
->RestoreTPL (OldTpl
);
1586 Sets the current coordinates of the cursor position.
1588 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1590 @param This Protocol instance pointer.
1591 @param Column The position to set the cursor to. Must be greater than or
1592 equal to zero and less than the number of columns and rows
1594 @param Row The position to set the cursor to. Must be greater than or
1595 equal to zero and less than the number of columns and rows
1598 @retval EFI_SUCCESS The operation completed successfully.
1599 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1600 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1601 cursor position is invalid for the current mode.
1606 GraphicsConsoleConOutSetCursorPosition (
1607 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1612 GRAPHICS_CONSOLE_DEV
*Private
;
1613 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1617 if (This
->Mode
->Mode
== -1) {
1619 // If current mode is not valid, return error.
1621 return EFI_UNSUPPORTED
;
1624 Status
= EFI_SUCCESS
;
1626 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1628 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1629 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1631 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1632 Status
= EFI_UNSUPPORTED
;
1636 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1637 Status
= EFI_SUCCESS
;
1643 This
->Mode
->CursorColumn
= (INT32
) Column
;
1644 This
->Mode
->CursorRow
= (INT32
) Row
;
1649 gBS
->RestoreTPL (OldTpl
);
1656 Makes the cursor visible or invisible.
1658 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1660 @param This Protocol instance pointer.
1661 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1662 the cursor is set to be invisible.
1664 @retval EFI_SUCCESS The operation completed successfully.
1665 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
1671 GraphicsConsoleConOutEnableCursor (
1672 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1678 if (This
->Mode
->Mode
== -1) {
1680 // If current mode is not valid, return error.
1682 return EFI_UNSUPPORTED
;
1685 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1689 This
->Mode
->CursorVisible
= Visible
;
1693 gBS
->RestoreTPL (OldTpl
);
1698 Gets Graphics Console devcie's foreground color and background color.
1700 @param This Protocol instance pointer.
1701 @param Foreground Returned text foreground color.
1702 @param Background Returned text background color.
1704 @retval EFI_SUCCESS It returned always.
1709 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1710 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1711 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1716 Attribute
= This
->Mode
->Attribute
& 0x7F;
1718 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1719 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1725 Draw Unicode string on the Graphics Console device's screen.
1727 @param This Protocol instance pointer.
1728 @param UnicodeWeight One Unicode string to be displayed.
1729 @param Count The count of Unicode string.
1731 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1732 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1734 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1738 DrawUnicodeWeightAtCursorN (
1739 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1740 IN CHAR16
*UnicodeWeight
,
1745 GRAPHICS_CONSOLE_DEV
*Private
;
1746 EFI_IMAGE_OUTPUT
*Blt
;
1748 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1749 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1750 EFI_HII_ROW_INFO
*RowInfoArray
;
1751 UINTN RowInfoArraySize
;
1753 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1754 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1756 return EFI_OUT_OF_RESOURCES
;
1759 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1760 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1762 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1763 if (String
== NULL
) {
1765 return EFI_OUT_OF_RESOURCES
;
1768 // Set the end character
1770 *(String
+ Count
) = L
'\0';
1772 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1773 if (FontInfo
== NULL
) {
1776 return EFI_OUT_OF_RESOURCES
;
1779 // Get current foreground and background colors.
1781 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1783 if (Private
->GraphicsOutput
!= NULL
) {
1785 // If Graphics Output protocol exists, using HII Font protocol to draw.
1787 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1789 Status
= mHiiFont
->StringToImage (
1791 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1795 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1796 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1802 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1804 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1805 // using UGA Draw protocol to draw.
1807 ASSERT (Private
->UgaDraw
!= NULL
);
1809 UgaDraw
= Private
->UgaDraw
;
1811 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1812 if (Blt
->Image
.Bitmap
== NULL
) {
1815 return EFI_OUT_OF_RESOURCES
;
1818 RowInfoArray
= NULL
;
1820 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1821 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1823 Status
= mHiiFont
->StringToImage (
1825 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1829 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1830 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1836 if (!EFI_ERROR (Status
)) {
1838 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1839 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1841 ASSERT (RowInfoArraySize
<= 1);
1843 Status
= UgaDraw
->Blt (
1845 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1846 EfiUgaBltBufferToVideo
,
1847 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1848 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1849 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1850 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1851 RowInfoArray
[0].LineWidth
,
1852 RowInfoArray
[0].LineHeight
,
1853 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1857 FreePool (RowInfoArray
);
1858 FreePool (Blt
->Image
.Bitmap
);
1860 Status
= EFI_UNSUPPORTED
;
1866 if (String
!= NULL
) {
1869 if (FontInfo
!= NULL
) {
1870 FreePool (FontInfo
);
1876 Flush the cursor on the screen.
1878 If CursorVisible is FALSE, nothing to do and return directly.
1879 If CursorVisible is TRUE,
1880 i) If the cursor shows on screen, it will be erased.
1881 ii) If the cursor does not show on screen, it will be shown.
1883 @param This Protocol instance pointer.
1885 @retval EFI_SUCCESS The cursor is erased successfully.
1890 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1893 GRAPHICS_CONSOLE_DEV
*Private
;
1894 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1897 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1898 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1899 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1900 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1901 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1905 CurrentMode
= This
->Mode
;
1907 if (!CurrentMode
->CursorVisible
) {
1911 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1912 GraphicsOutput
= Private
->GraphicsOutput
;
1913 UgaDraw
= Private
->UgaDraw
;
1916 // In this driver, only narrow character was supported.
1919 // Blt a character to the screen
1921 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1922 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1923 if (GraphicsOutput
!= NULL
) {
1924 GraphicsOutput
->Blt (
1926 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1927 EfiBltVideoToBltBuffer
,
1934 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1936 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1939 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1940 EfiUgaVideoToBltBuffer
,
1947 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1951 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1954 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1956 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1957 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1958 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1959 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1964 if (GraphicsOutput
!= NULL
) {
1965 GraphicsOutput
->Blt (
1967 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1968 EfiBltBufferToVideo
,
1975 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1977 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1980 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1981 EfiUgaBltBufferToVideo
,
1988 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1996 HII Database Protocol notification event handler.
1998 Register font package when HII Database Protocol has been installed.
2000 @param[in] Event Event whose notification function is being invoked.
2001 @param[in] Context Pointer to the notification function's context.
2005 RegisterFontPackage (
2011 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
2012 UINT32 PackageLength
;
2015 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
2018 // Locate HII Database Protocol
2020 Status
= gBS
->LocateProtocol (
2021 &gEfiHiiDatabaseProtocolGuid
,
2023 (VOID
**) &HiiDatabase
2025 if (EFI_ERROR (Status
)) {
2030 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
2032 // +--------------------------------+ <-- Package
2034 // | PackageLength(4 bytes) |
2036 // |--------------------------------| <-- SimplifiedFont
2038 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
2040 // |--------------------------------| <-- Location
2042 // | gUsStdNarrowGlyphData |
2044 // +--------------------------------+
2046 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
2047 Package
= AllocateZeroPool (PackageLength
);
2048 ASSERT (Package
!= NULL
);
2050 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
2051 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
2052 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
2053 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
2054 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
2056 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
2057 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
2060 // Add this simplified font package to a package list then install it.
2062 mHiiHandle
= HiiAddPackages (
2063 &mFontPackageListGuid
,
2068 ASSERT (mHiiHandle
!= NULL
);
2073 The user Entry Point for module GraphicsConsole. The user code starts with this function.
2075 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2076 @param[in] SystemTable A pointer to the EFI System Table.
2078 @retval EFI_SUCCESS The entry point is executed successfully.
2079 @return other Some error occurs when executing this entry point.
2084 InitializeGraphicsConsole (
2085 IN EFI_HANDLE ImageHandle
,
2086 IN EFI_SYSTEM_TABLE
*SystemTable
2092 // Register notify function on HII Database Protocol to add font package.
2094 EfiCreateProtocolNotifyEvent (
2095 &gEfiHiiDatabaseProtocolGuid
,
2097 RegisterFontPackage
,
2103 // Install driver model protocol(s).
2105 Status
= EfiLibInstallDriverBindingComponentName2 (
2108 &gGraphicsConsoleDriverBinding
,
2110 &gGraphicsConsoleComponentName
,
2111 &gGraphicsConsoleComponentName2
2113 ASSERT_EFI_ERROR (Status
);