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 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
| 0xFF) != 0xFF) {
1480 return EFI_UNSUPPORTED
;
1483 if (This
->Mode
->Mode
== -1) {
1485 // If current mode is not valid, return error.
1487 return EFI_UNSUPPORTED
;
1490 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1494 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1498 This
->Mode
->Attribute
= (INT32
) Attribute
;
1502 gBS
->RestoreTPL (OldTpl
);
1509 Clears the output device(s) display to the currently selected background
1512 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1514 @param This Protocol instance pointer.
1516 @retval EFI_SUCCESS The operation completed successfully.
1517 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1518 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1523 GraphicsConsoleConOutClearScreen (
1524 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1528 GRAPHICS_CONSOLE_DEV
*Private
;
1529 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1530 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1531 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1532 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1533 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1536 if (This
->Mode
->Mode
== -1) {
1538 // If current mode is not valid, return error.
1540 return EFI_UNSUPPORTED
;
1543 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1545 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1546 GraphicsOutput
= Private
->GraphicsOutput
;
1547 UgaDraw
= Private
->UgaDraw
;
1548 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1550 GetTextColors (This
, &Foreground
, &Background
);
1551 if (GraphicsOutput
!= NULL
) {
1552 Status
= GraphicsOutput
->Blt (
1561 ModeData
->GopHeight
,
1564 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1565 Status
= UgaDraw
->Blt (
1567 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1574 ModeData
->GopHeight
,
1578 Status
= EFI_UNSUPPORTED
;
1581 This
->Mode
->CursorColumn
= 0;
1582 This
->Mode
->CursorRow
= 0;
1586 gBS
->RestoreTPL (OldTpl
);
1593 Sets the current coordinates of the cursor position.
1595 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1597 @param This Protocol instance pointer.
1598 @param Column The position to set the cursor to. Must be greater than or
1599 equal to zero and less than the number of columns and rows
1601 @param Row The position to set the cursor to. Must be greater than or
1602 equal to zero and less than the number of columns and rows
1605 @retval EFI_SUCCESS The operation completed successfully.
1606 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1607 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1608 cursor position is invalid for the current mode.
1613 GraphicsConsoleConOutSetCursorPosition (
1614 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1619 GRAPHICS_CONSOLE_DEV
*Private
;
1620 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1624 if (This
->Mode
->Mode
== -1) {
1626 // If current mode is not valid, return error.
1628 return EFI_UNSUPPORTED
;
1631 Status
= EFI_SUCCESS
;
1633 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1635 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1636 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1638 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1639 Status
= EFI_UNSUPPORTED
;
1643 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1644 Status
= EFI_SUCCESS
;
1650 This
->Mode
->CursorColumn
= (INT32
) Column
;
1651 This
->Mode
->CursorRow
= (INT32
) Row
;
1656 gBS
->RestoreTPL (OldTpl
);
1663 Makes the cursor visible or invisible.
1665 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1667 @param This Protocol instance pointer.
1668 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1669 the cursor is set to be invisible.
1671 @retval EFI_SUCCESS The operation completed successfully.
1672 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
1678 GraphicsConsoleConOutEnableCursor (
1679 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1685 if (This
->Mode
->Mode
== -1) {
1687 // If current mode is not valid, return error.
1689 return EFI_UNSUPPORTED
;
1692 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1696 This
->Mode
->CursorVisible
= Visible
;
1700 gBS
->RestoreTPL (OldTpl
);
1705 Gets Graphics Console devcie's foreground color and background color.
1707 @param This Protocol instance pointer.
1708 @param Foreground Returned text foreground color.
1709 @param Background Returned text background color.
1711 @retval EFI_SUCCESS It returned always.
1716 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1717 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1718 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1723 Attribute
= This
->Mode
->Attribute
& 0x7F;
1725 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1726 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1732 Draw Unicode string on the Graphics Console device's screen.
1734 @param This Protocol instance pointer.
1735 @param UnicodeWeight One Unicode string to be displayed.
1736 @param Count The count of Unicode string.
1738 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1739 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1741 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1745 DrawUnicodeWeightAtCursorN (
1746 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1747 IN CHAR16
*UnicodeWeight
,
1752 GRAPHICS_CONSOLE_DEV
*Private
;
1753 EFI_IMAGE_OUTPUT
*Blt
;
1755 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1756 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1757 EFI_HII_ROW_INFO
*RowInfoArray
;
1758 UINTN RowInfoArraySize
;
1760 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1761 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1763 return EFI_OUT_OF_RESOURCES
;
1766 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1767 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1769 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1770 if (String
== NULL
) {
1772 return EFI_OUT_OF_RESOURCES
;
1775 // Set the end character
1777 *(String
+ Count
) = L
'\0';
1779 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1780 if (FontInfo
== NULL
) {
1783 return EFI_OUT_OF_RESOURCES
;
1786 // Get current foreground and background colors.
1788 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1790 if (Private
->GraphicsOutput
!= NULL
) {
1792 // If Graphics Output protocol exists, using HII Font protocol to draw.
1794 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1796 Status
= mHiiFont
->StringToImage (
1798 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1802 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1803 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1809 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1811 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1812 // using UGA Draw protocol to draw.
1814 ASSERT (Private
->UgaDraw
!= NULL
);
1816 UgaDraw
= Private
->UgaDraw
;
1818 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1819 if (Blt
->Image
.Bitmap
== NULL
) {
1822 return EFI_OUT_OF_RESOURCES
;
1825 RowInfoArray
= NULL
;
1827 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1828 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1830 Status
= mHiiFont
->StringToImage (
1832 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1836 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1837 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1843 if (!EFI_ERROR (Status
)) {
1845 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1846 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1848 ASSERT (RowInfoArraySize
<= 1);
1850 Status
= UgaDraw
->Blt (
1852 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1853 EfiUgaBltBufferToVideo
,
1854 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1855 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1856 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1857 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1858 RowInfoArray
[0].LineWidth
,
1859 RowInfoArray
[0].LineHeight
,
1860 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1864 FreePool (RowInfoArray
);
1865 FreePool (Blt
->Image
.Bitmap
);
1867 Status
= EFI_UNSUPPORTED
;
1873 if (String
!= NULL
) {
1876 if (FontInfo
!= NULL
) {
1877 FreePool (FontInfo
);
1883 Flush the cursor on the screen.
1885 If CursorVisible is FALSE, nothing to do and return directly.
1886 If CursorVisible is TRUE,
1887 i) If the cursor shows on screen, it will be erased.
1888 ii) If the cursor does not show on screen, it will be shown.
1890 @param This Protocol instance pointer.
1892 @retval EFI_SUCCESS The cursor is erased successfully.
1897 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1900 GRAPHICS_CONSOLE_DEV
*Private
;
1901 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1904 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1905 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1906 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1907 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1908 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1912 CurrentMode
= This
->Mode
;
1914 if (!CurrentMode
->CursorVisible
) {
1918 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1919 GraphicsOutput
= Private
->GraphicsOutput
;
1920 UgaDraw
= Private
->UgaDraw
;
1923 // In this driver, only narrow character was supported.
1926 // Blt a character to the screen
1928 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1929 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1930 if (GraphicsOutput
!= NULL
) {
1931 GraphicsOutput
->Blt (
1933 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1934 EfiBltVideoToBltBuffer
,
1941 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1943 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1946 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1947 EfiUgaVideoToBltBuffer
,
1954 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1958 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1961 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1963 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1964 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1965 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1966 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1971 if (GraphicsOutput
!= NULL
) {
1972 GraphicsOutput
->Blt (
1974 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1975 EfiBltBufferToVideo
,
1982 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1984 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1987 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1988 EfiUgaBltBufferToVideo
,
1995 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
2003 HII Database Protocol notification event handler.
2005 Register font package when HII Database Protocol has been installed.
2007 @param[in] Event Event whose notification function is being invoked.
2008 @param[in] Context Pointer to the notification function's context.
2012 RegisterFontPackage (
2018 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
2019 UINT32 PackageLength
;
2022 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
2025 // Locate HII Database Protocol
2027 Status
= gBS
->LocateProtocol (
2028 &gEfiHiiDatabaseProtocolGuid
,
2030 (VOID
**) &HiiDatabase
2032 if (EFI_ERROR (Status
)) {
2037 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
2039 // +--------------------------------+ <-- Package
2041 // | PackageLength(4 bytes) |
2043 // |--------------------------------| <-- SimplifiedFont
2045 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
2047 // |--------------------------------| <-- Location
2049 // | gUsStdNarrowGlyphData |
2051 // +--------------------------------+
2053 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
2054 Package
= AllocateZeroPool (PackageLength
);
2055 ASSERT (Package
!= NULL
);
2057 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
2058 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
2059 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
2060 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
2061 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
2063 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
2064 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
2067 // Add this simplified font package to a package list then install it.
2069 mHiiHandle
= HiiAddPackages (
2070 &mFontPackageListGuid
,
2075 ASSERT (mHiiHandle
!= NULL
);
2080 The user Entry Point for module GraphicsConsole. The user code starts with this function.
2082 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2083 @param[in] SystemTable A pointer to the EFI System Table.
2085 @retval EFI_SUCCESS The entry point is executed successfully.
2086 @return other Some error occurs when executing this entry point.
2091 InitializeGraphicsConsole (
2092 IN EFI_HANDLE ImageHandle
,
2093 IN EFI_SYSTEM_TABLE
*SystemTable
2099 // Register notify function on HII Database Protocol to add font package.
2101 EfiCreateProtocolNotifyEvent (
2102 &gEfiHiiDatabaseProtocolGuid
,
2104 RegisterFontPackage
,
2110 // Install driver model protocol(s).
2112 Status
= EfiLibInstallDriverBindingComponentName2 (
2115 &gGraphicsConsoleDriverBinding
,
2117 &gGraphicsConsoleComponentName
,
2118 &gGraphicsConsoleComponentName2
2120 ASSERT_EFI_ERROR (Status
);