2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "GraphicsConsole.h"
18 // Graphics Console Device Private Data template
20 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
21 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
22 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
23 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
25 GraphicsConsoleConOutReset
,
26 GraphicsConsoleConOutOutputString
,
27 GraphicsConsoleConOutTestString
,
28 GraphicsConsoleConOutQueryMode
,
29 GraphicsConsoleConOutSetMode
,
30 GraphicsConsoleConOutSetAttribute
,
31 GraphicsConsoleConOutClearScreen
,
32 GraphicsConsoleConOutSetCursorPosition
,
33 GraphicsConsoleConOutEnableCursor
,
34 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
39 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
44 (GRAPHICS_CONSOLE_MODE_DATA
*) NULL
,
45 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
48 GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData
[] = {
51 // New modes can be added here.
52 // The last entry is specific for full screen mode.
57 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
58 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
59 EFI_HII_HANDLE mHiiHandle
;
60 EFI_EVENT mHiiRegistration
;
62 EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
64 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
66 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mGraphicsEfiColors
[16] = {
70 {0x00, 0x00, 0x00, 0x00}, // BLACK
71 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
72 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
73 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
74 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
75 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
76 {0x00, 0x98, 0x98, 0x00}, // BROWN
77 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
78 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
79 {0xff, 0x00, 0x00, 0x00}, // BLUE
80 {0x00, 0xff, 0x00, 0x00}, // LIME
81 {0xff, 0xff, 0x00, 0x00}, // CYAN
82 {0x00, 0x00, 0xff, 0x00}, // RED
83 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
84 {0x00, 0xff, 0xff, 0x00}, // YELLOW
85 {0xff, 0xff, 0xff, 0x00} // WHITE
88 EFI_NARROW_GLYPH mCursorGlyph
= {
91 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
94 CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
96 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
97 GraphicsConsoleControllerDriverSupported
,
98 GraphicsConsoleControllerDriverStart
,
99 GraphicsConsoleControllerDriverStop
,
106 Test to see if Graphics Console could be supported on the Controller.
108 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
109 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
110 if PcdUgaConsumeSupport is set to FALSE.)
112 @param This Protocol instance pointer.
113 @param Controller Handle of device to test.
114 @param RemainingDevicePath Optional parameter use to pick a specific child
117 @retval EFI_SUCCESS This driver supports this device.
118 @retval other This driver does not support this device.
123 GraphicsConsoleControllerDriverSupported (
124 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
125 IN EFI_HANDLE Controller
,
126 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
130 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
131 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
132 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
134 GraphicsOutput
= NULL
;
137 // Open the IO Abstraction(s) needed to perform the supported test
139 Status
= gBS
->OpenProtocol (
141 &gEfiGraphicsOutputProtocolGuid
,
142 (VOID
**) &GraphicsOutput
,
143 This
->DriverBindingHandle
,
145 EFI_OPEN_PROTOCOL_BY_DRIVER
148 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
150 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
152 Status
= gBS
->OpenProtocol (
154 &gEfiUgaDrawProtocolGuid
,
156 This
->DriverBindingHandle
,
158 EFI_OPEN_PROTOCOL_BY_DRIVER
161 if (EFI_ERROR (Status
)) {
166 // We need to ensure that we do not layer on top of a virtual handle.
167 // We need to ensure that the handles produced by the conspliter do not
170 Status
= gBS
->OpenProtocol (
172 &gEfiDevicePathProtocolGuid
,
173 (VOID
**) &DevicePath
,
174 This
->DriverBindingHandle
,
176 EFI_OPEN_PROTOCOL_BY_DRIVER
178 if (!EFI_ERROR (Status
)) {
181 &gEfiDevicePathProtocolGuid
,
182 This
->DriverBindingHandle
,
190 // Does Hii Exist? If not, we aren't ready to run
192 Status
= EfiLocateHiiProtocol ();
195 // Close the I/O Abstraction(s) used to perform the supported test
198 if (GraphicsOutput
!= NULL
) {
201 &gEfiGraphicsOutputProtocolGuid
,
202 This
->DriverBindingHandle
,
205 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
208 &gEfiUgaDrawProtocolGuid
,
209 This
->DriverBindingHandle
,
217 Initialize all the text modes which the graphics console supports.
219 It returns information for available text modes that the graphics can support.
221 @param[in] HorizontalResolution The size of video screen in pixels in the X dimension.
222 @param[in] VerticalResolution The size of video screen in pixels in the Y dimension.
223 @param[in] GopModeNumber The graphics mode number which graphis console is based on.
224 @param[out] TextModeCount The total number of text modes that graphics console supports.
225 @param[out] TextModeData The buffer to the text modes column and row information.
226 Caller is responsible to free it when it's non-NULL.
228 @retval EFI_SUCCESS The supporting mode information is returned.
229 @retval EFI_INVALID_PARAMETER The parameters are invalid.
233 InitializeGraphicsConsoleTextMode (
234 IN UINT32 HorizontalResolution
,
235 IN UINT32 VerticalResolution
,
236 IN UINT32 GopModeNumber
,
237 OUT UINTN
*TextModeCount
,
238 OUT GRAPHICS_CONSOLE_MODE_DATA
**TextModeData
243 GRAPHICS_CONSOLE_MODE_DATA
*ModeBuffer
;
244 GRAPHICS_CONSOLE_MODE_DATA
*NewModeBuffer
;
250 if ((TextModeCount
== NULL
) || (TextModeData
== NULL
)) {
251 return EFI_INVALID_PARAMETER
;
254 Count
= sizeof (mGraphicsConsoleModeData
) / sizeof (GRAPHICS_CONSOLE_MODE_DATA
);
257 // Compute the maximum number of text Rows and Columns that this current graphics mode can support.
258 // To make graphics console work well, MaxColumns and MaxRows should not be zero.
260 MaxColumns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
261 MaxRows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
264 // According to UEFI spec, all output devices support at least 80x25 text mode.
266 ASSERT ((MaxColumns
>= 80) && (MaxRows
>= 25));
269 // Add full screen mode to the last entry.
271 mGraphicsConsoleModeData
[Count
- 1].Columns
= MaxColumns
;
272 mGraphicsConsoleModeData
[Count
- 1].Rows
= MaxRows
;
275 // Get defined mode buffer pointer.
277 ModeBuffer
= mGraphicsConsoleModeData
;
280 // Here we make sure that the final mode exposed does not include the duplicated modes,
281 // and does not include the invalid modes which exceed the max column and row.
282 // Reserve 2 modes for 80x25, 80x50 of graphics console.
284 NewModeBuffer
= AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA
) * (Count
+ 2));
285 ASSERT (NewModeBuffer
!= NULL
);
288 // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.
292 NewModeBuffer
[ValidCount
].Columns
= 80;
293 NewModeBuffer
[ValidCount
].Rows
= 25;
294 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
295 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
296 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
297 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
298 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
301 if ((MaxColumns
>= 80) && (MaxRows
>= 50)) {
302 NewModeBuffer
[ValidCount
].Columns
= 80;
303 NewModeBuffer
[ValidCount
].Rows
= 50;
304 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
305 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
307 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
308 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
309 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
313 // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.
315 for (Index
= 0; Index
< Count
; Index
++) {
316 if ((ModeBuffer
[Index
].Columns
== 0) || (ModeBuffer
[Index
].Rows
== 0) ||
317 (ModeBuffer
[Index
].Columns
> MaxColumns
) || (ModeBuffer
[Index
].Rows
> MaxRows
)) {
319 // Skip the pre-defined mode which is invalid or exceeds the max column and row.
323 for (ValidIndex
= 0; ValidIndex
< ValidCount
; ValidIndex
++) {
324 if ((ModeBuffer
[Index
].Columns
== NewModeBuffer
[ValidIndex
].Columns
) &&
325 (ModeBuffer
[Index
].Rows
== NewModeBuffer
[ValidIndex
].Rows
)) {
327 // Skip the duplicated mode.
332 if (ValidIndex
== ValidCount
) {
333 NewModeBuffer
[ValidCount
].Columns
= ModeBuffer
[Index
].Columns
;
334 NewModeBuffer
[ValidCount
].Rows
= ModeBuffer
[Index
].Rows
;
335 NewModeBuffer
[ValidCount
].GopWidth
= HorizontalResolution
;
336 NewModeBuffer
[ValidCount
].GopHeight
= VerticalResolution
;
337 NewModeBuffer
[ValidCount
].GopModeNumber
= GopModeNumber
;
338 NewModeBuffer
[ValidCount
].DeltaX
= (HorizontalResolution
- (NewModeBuffer
[ValidCount
].Columns
* EFI_GLYPH_WIDTH
)) >> 1;
339 NewModeBuffer
[ValidCount
].DeltaY
= (VerticalResolution
- (NewModeBuffer
[ValidCount
].Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
345 for (Index
= 0; Index
< ValidCount
; Index
++) {
346 DEBUG ((EFI_D_INFO
, "Graphics - Mode %d, Column = %d, Row = %d\n",
347 Index
, NewModeBuffer
[Index
].Columns
, NewModeBuffer
[Index
].Rows
));
352 // Return valid mode count and mode information buffer.
354 *TextModeCount
= ValidCount
;
355 *TextModeData
= NewModeBuffer
;
360 Start this driver on Controller by opening Graphics Output protocol or
361 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
362 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
364 @param This Protocol instance pointer.
365 @param Controller Handle of device to bind driver to
366 @param RemainingDevicePath Optional parameter use to pick a specific child
369 @retval EFI_SUCCESS This driver is added to Controller.
370 @retval other This driver does not support this device.
375 GraphicsConsoleControllerDriverStart (
376 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
377 IN EFI_HANDLE Controller
,
378 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
382 GRAPHICS_CONSOLE_DEV
*Private
;
383 UINT32 HorizontalResolution
;
384 UINT32 VerticalResolution
;
390 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
;
392 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
397 // Initialize the Graphics Console device instance
399 Private
= AllocateCopyPool (
400 sizeof (GRAPHICS_CONSOLE_DEV
),
401 &mGraphicsConsoleDevTemplate
403 if (Private
== NULL
) {
404 return EFI_OUT_OF_RESOURCES
;
407 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
409 Status
= gBS
->OpenProtocol (
411 &gEfiGraphicsOutputProtocolGuid
,
412 (VOID
**) &Private
->GraphicsOutput
,
413 This
->DriverBindingHandle
,
415 EFI_OPEN_PROTOCOL_BY_DRIVER
418 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
419 Status
= gBS
->OpenProtocol (
421 &gEfiUgaDrawProtocolGuid
,
422 (VOID
**) &Private
->UgaDraw
,
423 This
->DriverBindingHandle
,
425 EFI_OPEN_PROTOCOL_BY_DRIVER
429 if (EFI_ERROR (Status
)) {
433 HorizontalResolution
= PcdGet32 (PcdVideoHorizontalResolution
);
434 VerticalResolution
= PcdGet32 (PcdVideoVerticalResolution
);
436 if (Private
->GraphicsOutput
!= NULL
) {
438 // The console is build on top of Graphics Output Protocol, find the mode number
439 // for the user-defined mode; if there are multiple video devices,
440 // graphic console driver will set all the video devices to the same mode.
442 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
444 // Find the highest resolution which GOP supports.
446 MaxMode
= Private
->GraphicsOutput
->Mode
->MaxMode
;
448 for (ModeIndex
= 0; ModeIndex
< MaxMode
; ModeIndex
++) {
449 Status
= Private
->GraphicsOutput
->QueryMode (
450 Private
->GraphicsOutput
,
455 if (!EFI_ERROR (Status
)) {
456 if ((Info
->HorizontalResolution
>= HorizontalResolution
) &&
457 (Info
->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 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
502 // At first try to set user-defined resolution
506 Status
= Private
->UgaDraw
->SetMode (
508 HorizontalResolution
,
513 if (EFI_ERROR (Status
)) {
515 // Try to set 800*600 which is required by UEFI/EFI spec
517 Status
= Private
->UgaDraw
->SetMode (
524 if (EFI_ERROR (Status
)) {
525 Status
= Private
->UgaDraw
->GetMode (
527 &HorizontalResolution
,
532 if (EFI_ERROR (Status
)) {
537 Status
= EFI_UNSUPPORTED
;
543 // Initialize the mode which GraphicsConsole supports.
545 Status
= InitializeGraphicsConsoleTextMode (
546 HorizontalResolution
,
553 if (EFI_ERROR (Status
)) {
558 // Update the maximum number of modes
560 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
563 // Determine the number of text modes that this protocol can support
565 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
566 if (EFI_ERROR (Status
)) {
571 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
575 // Install protocol interfaces for the Graphics Console device.
577 Status
= gBS
->InstallMultipleProtocolInterfaces (
579 &gEfiSimpleTextOutProtocolGuid
,
580 &Private
->SimpleTextOutput
,
585 if (EFI_ERROR (Status
)) {
587 // Close the GOP and UGA Draw Protocol
589 if (Private
->GraphicsOutput
!= NULL
) {
592 &gEfiGraphicsOutputProtocolGuid
,
593 This
->DriverBindingHandle
,
596 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
599 &gEfiUgaDrawProtocolGuid
,
600 This
->DriverBindingHandle
,
605 if (Private
->LineBuffer
!= NULL
) {
606 FreePool (Private
->LineBuffer
);
609 if (Private
->ModeData
!= NULL
) {
610 FreePool (Private
->ModeData
);
623 Stop this driver on Controller by removing Simple Text Out protocol
624 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
625 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
628 @param This Protocol instance pointer.
629 @param Controller Handle of device to stop driver on
630 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
631 children is zero stop the entire bus driver.
632 @param ChildHandleBuffer List of Child Handles to Stop.
634 @retval EFI_SUCCESS This driver is removed Controller.
635 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
637 @retval other This driver was not removed from this device.
642 GraphicsConsoleControllerDriverStop (
643 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
644 IN EFI_HANDLE Controller
,
645 IN UINTN NumberOfChildren
,
646 IN EFI_HANDLE
*ChildHandleBuffer
650 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
651 GRAPHICS_CONSOLE_DEV
*Private
;
653 Status
= gBS
->OpenProtocol (
655 &gEfiSimpleTextOutProtocolGuid
,
656 (VOID
**) &SimpleTextOutput
,
657 This
->DriverBindingHandle
,
659 EFI_OPEN_PROTOCOL_GET_PROTOCOL
661 if (EFI_ERROR (Status
)) {
662 return EFI_NOT_STARTED
;
665 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
667 Status
= gBS
->UninstallProtocolInterface (
669 &gEfiSimpleTextOutProtocolGuid
,
670 &Private
->SimpleTextOutput
673 if (!EFI_ERROR (Status
)) {
675 // Close the GOP or UGA IO Protocol
677 if (Private
->GraphicsOutput
!= NULL
) {
680 &gEfiGraphicsOutputProtocolGuid
,
681 This
->DriverBindingHandle
,
684 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
687 &gEfiUgaDrawProtocolGuid
,
688 This
->DriverBindingHandle
,
693 if (Private
->LineBuffer
!= NULL
) {
694 FreePool (Private
->LineBuffer
);
697 if (Private
->ModeData
!= NULL
) {
698 FreePool (Private
->ModeData
);
702 // Free our instance data
711 Check if the current specific mode supported the user defined resolution
712 for the Graphics Console device based on Graphics Output Protocol.
714 If yes, set the graphic devcice's current mode to this specific mode.
716 @param GraphicsOutput Graphics Output Protocol instance pointer.
717 @param HorizontalResolution User defined horizontal resolution
718 @param VerticalResolution User defined vertical resolution.
719 @param CurrentModeNumber Current specific mode to be check.
721 @retval EFI_SUCCESS The mode is supported.
722 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
724 @retval other The specific mode does not support user defined
725 resolution or failed to set the current mode to the
726 specific mode on graphics device.
731 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
732 IN UINT32 HorizontalResolution
,
733 IN UINT32 VerticalResolution
,
734 OUT UINT32
*CurrentModeNumber
740 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
743 Status
= EFI_SUCCESS
;
744 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
746 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
747 Status
= GraphicsOutput
->QueryMode (
753 if (!EFI_ERROR (Status
)) {
754 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
755 (Info
->VerticalResolution
== VerticalResolution
)) {
756 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== HorizontalResolution
) &&
757 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== VerticalResolution
)) {
759 // If video device has been set to this mode, we do not need to SetMode again
763 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
764 if (!EFI_ERROR (Status
)) {
774 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
775 Status
= EFI_UNSUPPORTED
;
778 *CurrentModeNumber
= ModeNumber
;
784 Locate HII Database protocol and HII Font protocol.
786 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
787 are located successfully.
788 @return other Failed to locate HII Database protocol or
793 EfiLocateHiiProtocol (
802 // There should only be one - so buffer size is this
804 Size
= sizeof (EFI_HANDLE
);
806 Status
= gBS
->LocateHandle (
808 &gEfiHiiDatabaseProtocolGuid
,
814 if (EFI_ERROR (Status
)) {
818 Status
= gBS
->HandleProtocol (
820 &gEfiHiiDatabaseProtocolGuid
,
821 (VOID
**) &mHiiDatabase
824 if (EFI_ERROR (Status
)) {
828 Status
= gBS
->HandleProtocol (
830 &gEfiHiiFontProtocolGuid
,
837 // Body of the STO functions
841 Reset the text output device hardware and optionally run diagnostics.
843 Implements SIMPLE_TEXT_OUTPUT.Reset().
844 If ExtendeVerification is TRUE, then perform dependent Graphics Console
845 device reset, and set display mode to mode 0.
846 If ExtendedVerification is FALSE, only set display mode to mode 0.
848 @param This Protocol instance pointer.
849 @param ExtendedVerification Indicates that the driver may perform a more
850 exhaustive verification operation of the device
853 @retval EFI_SUCCESS The text output device was reset.
854 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
860 GraphicsConsoleConOutReset (
861 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
862 IN BOOLEAN ExtendedVerification
865 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
866 return This
->SetMode (This
, 0);
871 Write a Unicode string to the output device.
873 Implements SIMPLE_TEXT_OUTPUT.OutputString().
874 The Unicode string will be converted to Glyphs and will be
875 sent to the Graphics Console.
877 @param This Protocol instance pointer.
878 @param WString The NULL-terminated Unicode string to be displayed
879 on the output device(s). All output devices must
880 also support the Unicode drawing defined in this file.
882 @retval EFI_SUCCESS The string was output to the device.
883 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
885 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
887 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
888 characters in the Unicode string could not be
889 rendered and were skipped.
894 GraphicsConsoleConOutOutputString (
895 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
899 GRAPHICS_CONSOLE_DEV
*Private
;
900 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
901 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
910 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
911 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
916 INT32 OriginAttribute
;
919 Status
= EFI_SUCCESS
;
921 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
925 Mode
= This
->Mode
->Mode
;
926 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
927 GraphicsOutput
= Private
->GraphicsOutput
;
928 UgaDraw
= Private
->UgaDraw
;
930 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
931 MaxRow
= Private
->ModeData
[Mode
].Rows
;
932 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
933 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
934 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
935 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
936 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
939 // The Attributes won't change when during the time OutputString is called
941 GetTextColors (This
, &Foreground
, &Background
);
950 OriginAttribute
= This
->Mode
->Attribute
;
952 while (*WString
!= L
'\0') {
954 if (*WString
== CHAR_BACKSPACE
) {
956 // If the cursor is at the left edge of the display, then move the cursor
959 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
960 This
->Mode
->CursorRow
--;
961 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
962 This
->OutputString (This
, SpaceStr
);
964 This
->Mode
->CursorRow
--;
965 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
966 } else if (This
->Mode
->CursorColumn
> 0) {
968 // If the cursor is not at the left edge of the display, then move the cursor
971 This
->Mode
->CursorColumn
--;
972 This
->OutputString (This
, SpaceStr
);
974 This
->Mode
->CursorColumn
--;
979 } else if (*WString
== CHAR_LINEFEED
) {
981 // If the cursor is at the bottom of the display, then scroll the display one
982 // row, and do not update the cursor position. Otherwise, move the cursor
985 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
986 if (GraphicsOutput
!= NULL
) {
988 // Scroll Screen Up One Row
990 GraphicsOutput
->Blt (
995 DeltaY
+ EFI_GLYPH_HEIGHT
,
1004 // Print Blank Line at last line
1006 GraphicsOutput
->Blt (
1018 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1020 // Scroll Screen Up One Row
1027 DeltaY
+ EFI_GLYPH_HEIGHT
,
1036 // Print Blank Line at last line
1040 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1052 This
->Mode
->CursorRow
++;
1057 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1059 // Move the cursor to the beginning of the current row.
1061 This
->Mode
->CursorColumn
= 0;
1064 } else if (*WString
== WIDE_CHAR
) {
1066 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1069 } else if (*WString
== NARROW_CHAR
) {
1071 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1076 // Print the character at the current cursor position and move the cursor
1077 // right one column. If this moves the cursor past the right edge of the
1078 // display, then the line should wrap to the beginning of the next line. This
1079 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1080 // bottom of the display, and the line wraps, then the display will be scrolled
1082 // If wide char is going to be displayed, need to display one character at a time
1083 // Or, need to know the display length of a certain string.
1085 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1086 // Count is used to determine how many characters are used regardless of their attributes
1088 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1089 if (WString
[Count
] == CHAR_NULL
||
1090 WString
[Count
] == CHAR_BACKSPACE
||
1091 WString
[Count
] == CHAR_LINEFEED
||
1092 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1093 WString
[Count
] == WIDE_CHAR
||
1094 WString
[Count
] == NARROW_CHAR
) {
1098 // Is the wide attribute on?
1100 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
1102 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1106 // This is the end-case where if we are at column 79 and about to print a wide character
1107 // We should prevent this from happening because we will wrap inappropriately. We should
1108 // not print this character until the next line.
1110 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1117 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1118 if (EFI_ERROR (Status
)) {
1122 // At the end of line, output carriage return and line feed
1125 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1126 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1127 This
->Mode
->CursorColumn
-= 2;
1128 This
->OutputString (This
, SpaceStr
);
1131 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1133 This
->OutputString (This
, mCrLfString
);
1139 This
->Mode
->Attribute
= OriginAttribute
;
1144 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1147 gBS
->RestoreTPL (OldTpl
);
1153 Verifies that all characters in a Unicode string can be output to the
1156 Implements SIMPLE_TEXT_OUTPUT.TestString().
1157 If one of the characters in the *Wstring is neither valid valid Unicode
1158 drawing characters, not ASCII code, then this function will return
1161 @param This Protocol instance pointer.
1162 @param WString The NULL-terminated Unicode string to be examined for the output
1165 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1166 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1167 rendered by one or more of the output devices mapped
1173 GraphicsConsoleConOutTestString (
1174 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1181 EFI_IMAGE_OUTPUT
*Blt
;
1186 while (WString
[Count
] != 0) {
1187 Status
= mHiiFont
->GetGlyph (
1200 if (EFI_ERROR (Status
)) {
1201 return EFI_UNSUPPORTED
;
1210 Returns information for an available text mode that the output device(s)
1213 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1214 It returnes information for an available text mode that the Graphics Console supports.
1215 In this driver,we only support text mode 80x25, which is defined as mode 0.
1217 @param This Protocol instance pointer.
1218 @param ModeNumber The mode number to return information on.
1219 @param Columns The returned columns of the requested mode.
1220 @param Rows The returned rows of the requested mode.
1222 @retval EFI_SUCCESS The requested mode information is returned.
1223 @retval EFI_UNSUPPORTED The mode number is not valid.
1228 GraphicsConsoleConOutQueryMode (
1229 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1230 IN UINTN ModeNumber
,
1235 GRAPHICS_CONSOLE_DEV
*Private
;
1239 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1240 return EFI_UNSUPPORTED
;
1243 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1244 Status
= EFI_SUCCESS
;
1246 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1248 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1249 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1251 if (*Columns
<= 0 || *Rows
<= 0) {
1252 Status
= EFI_UNSUPPORTED
;
1258 gBS
->RestoreTPL (OldTpl
);
1264 Sets the output device(s) to a specified mode.
1266 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1267 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1269 @param This Protocol instance pointer.
1270 @param ModeNumber The text mode to set.
1272 @retval EFI_SUCCESS The requested text mode is set.
1273 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1274 Graphics Console device error.
1275 @retval EFI_UNSUPPORTED The text mode number is not valid.
1280 GraphicsConsoleConOutSetMode (
1281 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1286 GRAPHICS_CONSOLE_DEV
*Private
;
1287 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1288 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1289 UINT32 HorizontalResolution
;
1290 UINT32 VerticalResolution
;
1291 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1292 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1297 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1299 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1300 GraphicsOutput
= Private
->GraphicsOutput
;
1301 UgaDraw
= Private
->UgaDraw
;
1302 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1305 // Make sure the requested mode number is supported
1307 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1308 Status
= EFI_UNSUPPORTED
;
1312 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1313 Status
= EFI_UNSUPPORTED
;
1317 // Attempt to allocate a line buffer for the requested mode number
1319 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1321 if (NewLineBuffer
== NULL
) {
1323 // The new line buffer could not be allocated, so return an error.
1324 // No changes to the state of the current console have been made, so the current console is still valid
1326 Status
= EFI_OUT_OF_RESOURCES
;
1330 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1332 if (Private
->LineBuffer
!= NULL
) {
1334 // Clear the current text window on the current graphics console
1336 This
->ClearScreen (This
);
1339 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1341 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1342 FreePool (NewLineBuffer
);
1343 Status
= EFI_SUCCESS
;
1347 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1348 // so erase the cursor, and free the LineBuffer for the current mode
1352 FreePool (Private
->LineBuffer
);
1355 // Assign the current line buffer to the newly allocated line buffer
1357 Private
->LineBuffer
= NewLineBuffer
;
1359 if (GraphicsOutput
!= NULL
) {
1360 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1362 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1364 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1365 if (EFI_ERROR (Status
)) {
1367 // The mode set operation failed
1373 // The current graphics mode is correct, so simply clear the entire display
1375 Status
= GraphicsOutput
->Blt (
1377 &mGraphicsEfiColors
[0],
1384 ModeData
->GopHeight
,
1388 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1390 // Get the current UGA Draw mode information
1392 Status
= UgaDraw
->GetMode (
1394 &HorizontalResolution
,
1395 &VerticalResolution
,
1399 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1401 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1403 Status
= UgaDraw
->SetMode (
1406 ModeData
->GopHeight
,
1410 if (EFI_ERROR (Status
)) {
1412 // The mode set operation failed
1418 // The current graphics mode is correct, so simply clear the entire display
1420 Status
= UgaDraw
->Blt (
1422 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1429 ModeData
->GopHeight
,
1436 // The new mode is valid, so commit the mode change
1438 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1441 // Move the text cursor to the upper left hand corner of the display and flush it
1443 This
->Mode
->CursorColumn
= 0;
1444 This
->Mode
->CursorRow
= 0;
1448 Status
= EFI_SUCCESS
;
1451 gBS
->RestoreTPL (OldTpl
);
1457 Sets the background and foreground colors for the OutputString () and
1458 ClearScreen () functions.
1460 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1462 @param This Protocol instance pointer.
1463 @param Attribute The attribute to set. Bits 0..3 are the foreground
1464 color, and bits 4..6 are the background color.
1465 All other bits are undefined and must be zero.
1467 @retval EFI_SUCCESS The requested attribute is set.
1468 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1469 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1474 GraphicsConsoleConOutSetAttribute (
1475 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1481 if ((Attribute
| 0xFF) != 0xFF) {
1482 return EFI_UNSUPPORTED
;
1485 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1489 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1493 This
->Mode
->Attribute
= (INT32
) Attribute
;
1497 gBS
->RestoreTPL (OldTpl
);
1504 Clears the output device(s) display to the currently selected background
1507 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1509 @param This Protocol instance pointer.
1511 @retval EFI_SUCCESS The operation completed successfully.
1512 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1513 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1518 GraphicsConsoleConOutClearScreen (
1519 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1523 GRAPHICS_CONSOLE_DEV
*Private
;
1524 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1525 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1526 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1527 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1528 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1531 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1533 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1534 GraphicsOutput
= Private
->GraphicsOutput
;
1535 UgaDraw
= Private
->UgaDraw
;
1536 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1538 GetTextColors (This
, &Foreground
, &Background
);
1539 if (GraphicsOutput
!= NULL
) {
1540 Status
= GraphicsOutput
->Blt (
1549 ModeData
->GopHeight
,
1552 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1553 Status
= UgaDraw
->Blt (
1555 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1562 ModeData
->GopHeight
,
1566 Status
= EFI_UNSUPPORTED
;
1569 This
->Mode
->CursorColumn
= 0;
1570 This
->Mode
->CursorRow
= 0;
1574 gBS
->RestoreTPL (OldTpl
);
1581 Sets the current coordinates of the cursor position.
1583 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1585 @param This Protocol instance pointer.
1586 @param Column The position to set the cursor to. Must be greater than or
1587 equal to zero and less than the number of columns and rows
1589 @param Row The position to set the cursor to. Must be greater than or
1590 equal to zero and less than the number of columns and rows
1593 @retval EFI_SUCCESS The operation completed successfully.
1594 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1595 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1596 cursor position is invalid for the current mode.
1601 GraphicsConsoleConOutSetCursorPosition (
1602 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1607 GRAPHICS_CONSOLE_DEV
*Private
;
1608 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1612 Status
= EFI_SUCCESS
;
1614 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1616 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1617 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1619 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1620 Status
= EFI_UNSUPPORTED
;
1624 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1625 Status
= EFI_SUCCESS
;
1631 This
->Mode
->CursorColumn
= (INT32
) Column
;
1632 This
->Mode
->CursorRow
= (INT32
) Row
;
1637 gBS
->RestoreTPL (OldTpl
);
1644 Makes the cursor visible or invisible.
1646 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1648 @param This Protocol instance pointer.
1649 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1650 the cursor is set to be invisible.
1652 @retval EFI_SUCCESS The operation completed successfully.
1657 GraphicsConsoleConOutEnableCursor (
1658 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1664 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1668 This
->Mode
->CursorVisible
= Visible
;
1672 gBS
->RestoreTPL (OldTpl
);
1677 Gets Graphics Console devcie's foreground color and background color.
1679 @param This Protocol instance pointer.
1680 @param Foreground Returned text foreground color.
1681 @param Background Returned text background color.
1683 @retval EFI_SUCCESS It returned always.
1688 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1689 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1690 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1695 Attribute
= This
->Mode
->Attribute
& 0x7F;
1697 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1698 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1704 Draw Unicode string on the Graphics Console device's screen.
1706 @param This Protocol instance pointer.
1707 @param UnicodeWeight One Unicode string to be displayed.
1708 @param Count The count of Unicode string.
1710 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1711 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1713 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1717 DrawUnicodeWeightAtCursorN (
1718 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1719 IN CHAR16
*UnicodeWeight
,
1724 GRAPHICS_CONSOLE_DEV
*Private
;
1725 EFI_IMAGE_OUTPUT
*Blt
;
1727 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1728 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1729 EFI_HII_ROW_INFO
*RowInfoArray
;
1730 UINTN RowInfoArraySize
;
1732 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1733 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1735 return EFI_OUT_OF_RESOURCES
;
1738 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1739 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1741 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1742 if (String
== NULL
) {
1744 return EFI_OUT_OF_RESOURCES
;
1747 // Set the end character
1749 *(String
+ Count
) = L
'\0';
1751 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1752 if (FontInfo
== NULL
) {
1755 return EFI_OUT_OF_RESOURCES
;
1758 // Get current foreground and background colors.
1760 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1762 if (Private
->GraphicsOutput
!= NULL
) {
1764 // If Graphics Output protocol exists, using HII Font protocol to draw.
1766 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1768 Status
= mHiiFont
->StringToImage (
1770 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1774 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1775 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1781 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1783 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1784 // using UGA Draw protocol to draw.
1786 ASSERT (Private
->UgaDraw
!= NULL
);
1788 UgaDraw
= Private
->UgaDraw
;
1790 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1791 if (Blt
->Image
.Bitmap
== NULL
) {
1794 return EFI_OUT_OF_RESOURCES
;
1797 RowInfoArray
= NULL
;
1799 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1800 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1802 Status
= mHiiFont
->StringToImage (
1804 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1808 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1809 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1815 if (!EFI_ERROR (Status
)) {
1817 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1818 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1820 ASSERT (RowInfoArraySize
<= 1);
1822 Status
= UgaDraw
->Blt (
1824 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1825 EfiUgaBltBufferToVideo
,
1826 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1827 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1828 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1829 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1830 RowInfoArray
[0].LineWidth
,
1831 RowInfoArray
[0].LineHeight
,
1832 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1836 FreePool (RowInfoArray
);
1837 FreePool (Blt
->Image
.Bitmap
);
1839 Status
= EFI_UNSUPPORTED
;
1845 if (String
!= NULL
) {
1848 if (FontInfo
!= NULL
) {
1849 FreePool (FontInfo
);
1855 Flush the cursor on the screen.
1857 If CursorVisible is FALSE, nothing to do and return directly.
1858 If CursorVisible is TRUE,
1859 i) If the cursor shows on screen, it will be erased.
1860 ii) If the cursor does not show on screen, it will be shown.
1862 @param This Protocol instance pointer.
1864 @retval EFI_SUCCESS The cursor is erased successfully.
1869 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1872 GRAPHICS_CONSOLE_DEV
*Private
;
1873 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1876 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1877 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1878 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1879 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1880 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1884 CurrentMode
= This
->Mode
;
1886 if (!CurrentMode
->CursorVisible
) {
1890 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1891 GraphicsOutput
= Private
->GraphicsOutput
;
1892 UgaDraw
= Private
->UgaDraw
;
1895 // In this driver, only narrow character was supported.
1898 // Blt a character to the screen
1900 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1901 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1902 if (GraphicsOutput
!= NULL
) {
1903 GraphicsOutput
->Blt (
1905 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1906 EfiBltVideoToBltBuffer
,
1913 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1915 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1918 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1919 EfiUgaVideoToBltBuffer
,
1926 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1930 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1933 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1935 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1936 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1937 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1938 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1943 if (GraphicsOutput
!= NULL
) {
1944 GraphicsOutput
->Blt (
1946 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1947 EfiBltBufferToVideo
,
1954 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1956 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1959 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1960 EfiUgaBltBufferToVideo
,
1967 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1975 HII Database Protocol notification event handler.
1977 Register font package when HII Database Protocol has been installed.
1979 @param[in] Event Event whose notification function is being invoked.
1980 @param[in] Context Pointer to the notification function's context.
1984 RegisterFontPackage (
1990 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
1991 UINT32 PackageLength
;
1994 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1997 // Locate HII Database Protocol
1999 Status
= gBS
->LocateProtocol (
2000 &gEfiHiiDatabaseProtocolGuid
,
2002 (VOID
**) &HiiDatabase
2004 ASSERT_EFI_ERROR (Status
);
2007 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
2009 // +--------------------------------+ <-- Package
2011 // | PackageLength(4 bytes) |
2013 // |--------------------------------| <-- SimplifiedFont
2015 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
2017 // |--------------------------------| <-- Location
2019 // | gUsStdNarrowGlyphData |
2021 // +--------------------------------+
2023 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
2024 Package
= AllocateZeroPool (PackageLength
);
2025 ASSERT (Package
!= NULL
);
2027 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
2028 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
2029 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
2030 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
2031 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
2033 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
2034 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
2037 // Add this simplified font package to a package list then install it.
2039 mHiiHandle
= HiiAddPackages (
2040 &mFontPackageListGuid
,
2045 ASSERT (mHiiHandle
!= NULL
);
2050 The user Entry Point for module GraphicsConsole. The user code starts with this function.
2052 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2053 @param[in] SystemTable A pointer to the EFI System Table.
2055 @retval EFI_SUCCESS The entry point is executed successfully.
2056 @return other Some error occurs when executing this entry point.
2061 InitializeGraphicsConsole (
2062 IN EFI_HANDLE ImageHandle
,
2063 IN EFI_SYSTEM_TABLE
*SystemTable
2069 // Register notify function on HII Database Protocol to add font package.
2071 EfiCreateProtocolNotifyEvent (
2072 &gEfiHiiDatabaseProtocolGuid
,
2074 RegisterFontPackage
,
2080 // Install driver model protocol(s).
2082 Status
= EfiLibInstallDriverBindingComponentName2 (
2085 &gGraphicsConsoleDriverBinding
,
2087 &gGraphicsConsoleComponentName
,
2088 &gGraphicsConsoleComponentName2
2090 ASSERT_EFI_ERROR (Status
);