Check comments, format and fix some typo.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
1 /** @file
2 This is the main routine for initializing the Graphics Console support routines.
3
4 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
5 All rights reserved. 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
9
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.
12
13 **/
14
15 #include "GraphicsConsole.h"
16
17 //
18 // Graphics Console Device Private Data template
19 //
20 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = {
21 GRAPHICS_CONSOLE_DEV_SIGNATURE,
22 (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,
23 (EFI_UGA_DRAW_PROTOCOL *) NULL,
24 {
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
35 },
36 {
37 0,
38 0,
39 EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),
40 0,
41 0,
42 TRUE
43 },
44 {
45 { 80, 25, 0, 0, 0, 0 }, // Mode 0
46 { 80, 50, 0, 0, 0, 0 }, // Mode 1
47 { 100,31, 0, 0, 0, 0 }, // Mode 2
48 { 0, 0, 0, 0, 0, 0 } // Mode 3
49 },
50 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,
51 (EFI_HII_HANDLE ) 0
52 };
53
54 EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;
55 EFI_HII_FONT_PROTOCOL *mHiiFont;
56 BOOLEAN mFirstAccessFlag = TRUE;
57
58 EFI_GUID mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
59
60 CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };
61
62 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
63 //
64 // B G R reserved
65 //
66 {0x00, 0x00, 0x00, 0x00}, // BLACK
67 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
68 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
69 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
70 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
71 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
72 {0x00, 0x98, 0x98, 0x00}, // BROWN
73 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
74 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
75 {0xff, 0x00, 0x00, 0x00}, // BLUE
76 {0x00, 0xff, 0x00, 0x00}, // LIME
77 {0xff, 0xff, 0x00, 0x00}, // CYAN
78 {0x00, 0x00, 0xff, 0x00}, // RED
79 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
80 {0x00, 0xff, 0xff, 0x00}, // YELLOW
81 {0xff, 0xff, 0xff, 0x00} // WHITE
82 };
83
84 EFI_NARROW_GLYPH mCursorGlyph = {
85 0x0000,
86 0x00,
87 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
88 };
89
90 CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 };
91
92 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {
93 GraphicsConsoleControllerDriverSupported,
94 GraphicsConsoleControllerDriverStart,
95 GraphicsConsoleControllerDriverStop,
96 0xa,
97 NULL,
98 NULL
99 };
100
101 /**
102 Gets Graphics Console devcie's foreground color and background color.
103
104 @param This Protocol instance pointer.
105 @param Foreground Returned text foreground color.
106 @param Background Returned text background color.
107
108 @retval EFI_SUCCESS It returned always.
109
110 **/
111 EFI_STATUS
112 GetTextColors (
113 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
114 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
115 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background
116 );
117
118 /**
119 Draw Unicode string on the Graphics Console device's screen.
120
121 @param This Protocol instance pointer.
122 @param UnicodeWeight One Unicode string to be displayed.
123 @param Count The count of Unicode string.
124
125 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
126 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
127 protocol exist.
128 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
129
130 **/
131 EFI_STATUS
132 DrawUnicodeWeightAtCursorN (
133 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
134 IN CHAR16 *UnicodeWeight,
135 IN UINTN Count
136 );
137
138 /**
139 Erase the cursor on the screen.
140
141 @param This Protocol instance pointer.
142
143 @retval EFI_SUCCESS The cursor is erased successfully.
144
145 **/
146 EFI_STATUS
147 EraseCursor (
148 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
149 );
150
151 /**
152 Check if the current specific mode supported the user defined resolution
153 for the Graphics Console device based on Graphics Output Protocol.
154
155 If yes, set the graphic device's current mode to this specific mode.
156
157 @param GraphicsOutput Graphics Output Protocol instance pointer.
158 @param HorizontalResolution User defined horizontal resolution
159 @param VerticalResolution User defined vertical resolution.
160 @param CurrentModeNumber Current specific mode to be check.
161
162 @retval EFI_SUCCESS The mode is supported.
163 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
164 device supported.
165 @retval other The specific mode does not support user defined
166 resolution or failed to set the current mode to the
167 specific mode on graphics device.
168
169 **/
170 EFI_STATUS
171 CheckModeSupported (
172 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
173 IN UINT32 HorizontalResolution,
174 IN UINT32 VerticalResolution,
175 OUT UINT32 *CurrentModeNumber
176 );
177
178
179 /**
180 Test to see if Graphics Console could be supported on the Controller.
181
182 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
183 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
184 if PcdUgaConsumeSupport is set to FALSE.)
185
186 @param This Protocol instance pointer.
187 @param Controller Handle of device to test.
188 @param RemainingDevicePath Optional parameter use to pick a specific child
189 device to start.
190
191 @retval EFI_SUCCESS This driver supports this device.
192 @retval other This driver does not support this device.
193
194 **/
195 EFI_STATUS
196 EFIAPI
197 GraphicsConsoleControllerDriverSupported (
198 IN EFI_DRIVER_BINDING_PROTOCOL *This,
199 IN EFI_HANDLE Controller,
200 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
201 )
202 {
203 EFI_STATUS Status;
204 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
205 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
206 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
207
208 GraphicsOutput = NULL;
209 UgaDraw = NULL;
210 //
211 // Open the IO Abstraction(s) needed to perform the supported test
212 //
213 Status = gBS->OpenProtocol (
214 Controller,
215 &gEfiGraphicsOutputProtocolGuid,
216 (VOID **) &GraphicsOutput,
217 This->DriverBindingHandle,
218 Controller,
219 EFI_OPEN_PROTOCOL_BY_DRIVER
220 );
221
222 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
223 //
224 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
225 //
226 Status = gBS->OpenProtocol (
227 Controller,
228 &gEfiUgaDrawProtocolGuid,
229 (VOID **) &UgaDraw,
230 This->DriverBindingHandle,
231 Controller,
232 EFI_OPEN_PROTOCOL_BY_DRIVER
233 );
234 }
235 if (EFI_ERROR (Status)) {
236 return Status;
237 }
238
239 //
240 // We need to ensure that we do not layer on top of a virtual handle.
241 // We need to ensure that the handles produced by the conspliter do not
242 // get used.
243 //
244 Status = gBS->OpenProtocol (
245 Controller,
246 &gEfiDevicePathProtocolGuid,
247 (VOID **) &DevicePath,
248 This->DriverBindingHandle,
249 Controller,
250 EFI_OPEN_PROTOCOL_BY_DRIVER
251 );
252 if (!EFI_ERROR (Status)) {
253 gBS->CloseProtocol (
254 Controller,
255 &gEfiDevicePathProtocolGuid,
256 This->DriverBindingHandle,
257 Controller
258 );
259 } else {
260 goto Error;
261 }
262
263 //
264 // Does Hii Exist? If not, we aren't ready to run
265 //
266 Status = EfiLocateHiiProtocol ();
267
268 //
269 // Close the I/O Abstraction(s) used to perform the supported test
270 //
271 Error:
272 if (GraphicsOutput != NULL) {
273 gBS->CloseProtocol (
274 Controller,
275 &gEfiGraphicsOutputProtocolGuid,
276 This->DriverBindingHandle,
277 Controller
278 );
279 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
280 gBS->CloseProtocol (
281 Controller,
282 &gEfiUgaDrawProtocolGuid,
283 This->DriverBindingHandle,
284 Controller
285 );
286 }
287 return Status;
288 }
289
290
291 /**
292 Start this driver on Controller by opening Graphics Output protocol or
293 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
294 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
295
296 @param This Protocol instance pointer.
297 @param Controller Handle of device to bind driver to
298 @param RemainingDevicePath Optional parameter use to pick a specific child
299 device to start.
300
301 @retval EFI_SUCCESS This driver is added to Controller.
302 @retval other This driver does not support this device.
303
304 **/
305 EFI_STATUS
306 EFIAPI
307 GraphicsConsoleControllerDriverStart (
308 IN EFI_DRIVER_BINDING_PROTOCOL *This,
309 IN EFI_HANDLE Controller,
310 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
311 )
312 {
313 EFI_STATUS Status;
314 GRAPHICS_CONSOLE_DEV *Private;
315 UINT32 NarrowFontSize;
316 UINT32 HorizontalResolution;
317 UINT32 VerticalResolution;
318 UINT32 ColorDepth;
319 UINT32 RefreshRate;
320 UINTN MaxMode;
321 UINTN Columns;
322 UINTN Rows;
323 UINT32 ModeNumber;
324 EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont;
325 UINT32 PackageLength;
326 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
327 UINT8 *Package;
328 UINT8 *Location;
329 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
330 ModeNumber = 0;
331
332 //
333 // Initialize the Graphics Console device instance
334 //
335 Private = AllocateCopyPool (
336 sizeof (GRAPHICS_CONSOLE_DEV),
337 &mGraphicsConsoleDevTemplate
338 );
339 if (Private == NULL) {
340 return EFI_OUT_OF_RESOURCES;
341 }
342
343 Private->SimpleTextOutput.Mode = &(Private->SimpleTextOutputMode);
344
345 Status = gBS->OpenProtocol (
346 Controller,
347 &gEfiGraphicsOutputProtocolGuid,
348 (VOID **) &Private->GraphicsOutput,
349 This->DriverBindingHandle,
350 Controller,
351 EFI_OPEN_PROTOCOL_BY_DRIVER
352 );
353
354 if (EFI_ERROR(Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
355 Status = gBS->OpenProtocol (
356 Controller,
357 &gEfiUgaDrawProtocolGuid,
358 (VOID **) &Private->UgaDraw,
359 This->DriverBindingHandle,
360 Controller,
361 EFI_OPEN_PROTOCOL_BY_DRIVER
362 );
363 }
364
365 if (EFI_ERROR (Status)) {
366 goto Error;
367 }
368
369 NarrowFontSize = ReturnNarrowFontSize ();
370
371 if (mFirstAccessFlag) {
372 //
373 // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.
374 // Looks ugly. Might be updated when font tool is ready.
375 //
376 // +--------------------------------+ <-- Package
377 // | |
378 // | PackageLength(4 bytes) |
379 // | |
380 // |--------------------------------| <-- SimplifiedFont
381 // | |
382 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
383 // | |
384 // |--------------------------------| <-- Location
385 // | |
386 // | gUsStdNarrowGlyphData |
387 // | |
388 // +--------------------------------+
389
390 PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + NarrowFontSize + 4;
391 Package = AllocateZeroPool (PackageLength);
392 if (Package == NULL) {
393 return EFI_OUT_OF_RESOURCES;
394 }
395 WriteUnaligned32((UINT32 *) Package,PackageLength);
396 SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *) (Package + 4);
397 SimplifiedFont->Header.Length = (UINT32) (PackageLength - 4);
398 SimplifiedFont->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS;
399 SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));
400
401 Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);
402 CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize);
403
404 //
405 // Add this simplified font package to a package list then install it.
406 //
407 PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);
408 Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));
409 ASSERT_EFI_ERROR (Status);
410 FreePool (PackageList);
411 FreePool (Package);
412
413 mFirstAccessFlag = FALSE;
414 }
415 //
416 // If the current mode information can not be retrieved, then attempt to set the default mode
417 // of 800x600, 32 bit color, 60 Hz refresh.
418 //
419 HorizontalResolution = 800;
420 VerticalResolution = 600;
421
422 if (Private->GraphicsOutput != NULL) {
423 //
424 // The console is build on top of Graphics Output Protocol, find the mode number
425 // for the user-defined mode; if there are multiple video devices,
426 // graphic console driver will set all the video devices to the same mode.
427 //
428 Status = CheckModeSupported (
429 Private->GraphicsOutput,
430 CURRENT_HORIZONTAL_RESOLUTION,
431 CURRENT_VERTICAL_RESOLUTION,
432 &ModeNumber
433 );
434 if (!EFI_ERROR(Status)) {
435 //
436 // Update default mode to current mode
437 //
438 HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;
439 VerticalResolution = CURRENT_VERTICAL_RESOLUTION;
440 } else {
441 //
442 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
443 //
444 Status = CheckModeSupported (
445 Private->GraphicsOutput,
446 800,
447 600,
448 &ModeNumber
449 );
450 }
451
452 Mode = Private->GraphicsOutput->Mode;
453
454 if (EFI_ERROR (Status) || (Mode->MaxMode)) {
455 //
456 // Set default mode failed or device don't support default mode, then get the current mode information
457 //
458 HorizontalResolution = Mode->Info->HorizontalResolution;
459 VerticalResolution = Mode->Info->VerticalResolution;
460 ModeNumber = Mode->Mode;
461 }
462 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
463 //
464 // At first try to set user-defined resolution
465 //
466 ColorDepth = 32;
467 RefreshRate = 60;
468 Status = Private->UgaDraw->SetMode (
469 Private->UgaDraw,
470 CURRENT_HORIZONTAL_RESOLUTION,
471 CURRENT_VERTICAL_RESOLUTION,
472 ColorDepth,
473 RefreshRate
474 );
475 if (!EFI_ERROR (Status)) {
476 HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;
477 VerticalResolution = CURRENT_VERTICAL_RESOLUTION;
478 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
479 //
480 // Try to set 800*600 which is required by UEFI/EFI spec
481 //
482 Status = Private->UgaDraw->SetMode (
483 Private->UgaDraw,
484 HorizontalResolution,
485 VerticalResolution,
486 ColorDepth,
487 RefreshRate
488 );
489 if (EFI_ERROR (Status)) {
490 Status = Private->UgaDraw->GetMode (
491 Private->UgaDraw,
492 &HorizontalResolution,
493 &VerticalResolution,
494 &ColorDepth,
495 &RefreshRate
496 );
497 if (EFI_ERROR (Status)) {
498 goto Error;
499 }
500 }
501 } else {
502 Status = EFI_UNSUPPORTED;
503 goto Error;
504 }
505 }
506
507 //
508 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
509 //
510 Columns = HorizontalResolution / EFI_GLYPH_WIDTH;
511 Rows = VerticalResolution / EFI_GLYPH_HEIGHT;
512
513 //
514 // See if the mode is too small to support the required 80x25 text mode
515 //
516 if (Columns < 80 || Rows < 25) {
517 goto Error;
518 }
519 //
520 // Add Mode #0 that must be 80x25
521 //
522 MaxMode = 0;
523 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
524 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
525 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
526 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;
527 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;
528 MaxMode++;
529
530 //
531 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
532 //
533 if (Rows >= 50) {
534 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
535 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
536 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
537 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;
538 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;
539 MaxMode++;
540 }
541
542 //
543 // If it is not to support Mode #1 - 80x50, then skip it
544 //
545 if (MaxMode < 2) {
546 Private->ModeData[MaxMode].Columns = 0;
547 Private->ModeData[MaxMode].Rows = 0;
548 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
549 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
550 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
551 Private->ModeData[MaxMode].DeltaX = 0;
552 Private->ModeData[MaxMode].DeltaY = 0;
553 MaxMode++;
554 }
555
556 //
557 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
558 //
559 if (Columns >= 100 && Rows >= 31) {
560 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
561 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
562 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
563 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;
564 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;
565 MaxMode++;
566 }
567
568 //
569 // Add Mode #3 that uses the entire display for user-defined mode
570 //
571 if (HorizontalResolution > 800 && VerticalResolution > 600) {
572 Private->ModeData[MaxMode].Columns = HorizontalResolution/EFI_GLYPH_WIDTH;
573 Private->ModeData[MaxMode].Rows = VerticalResolution/EFI_GLYPH_HEIGHT;
574 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
575 Private->ModeData[MaxMode].GopHeight = VerticalResolution;
576 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
577 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;
578 Private->ModeData[MaxMode].DeltaY = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;
579 MaxMode++;
580 }
581
582 //
583 // Update the maximum number of modes
584 //
585 Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;
586
587 //
588 // Determine the number of text modes that this protocol can support
589 //
590 Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);
591 if (EFI_ERROR (Status)) {
592 goto Error;
593 }
594
595 DEBUG_CODE_BEGIN ();
596 GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");
597 DEBUG_CODE_END ();
598
599 //
600 // Install protocol interfaces for the Graphics Console device.
601 //
602 Status = gBS->InstallMultipleProtocolInterfaces (
603 &Controller,
604 &gEfiSimpleTextOutProtocolGuid,
605 &Private->SimpleTextOutput,
606 NULL
607 );
608
609 Error:
610 if (EFI_ERROR (Status)) {
611 //
612 // Close the GOP and UGA Draw Protocol
613 //
614 if (Private->GraphicsOutput != NULL) {
615 gBS->CloseProtocol (
616 Controller,
617 &gEfiGraphicsOutputProtocolGuid,
618 This->DriverBindingHandle,
619 Controller
620 );
621 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
622 gBS->CloseProtocol (
623 Controller,
624 &gEfiUgaDrawProtocolGuid,
625 This->DriverBindingHandle,
626 Controller
627 );
628 }
629
630 //
631 // Free private data
632 //
633 if (Private != NULL) {
634 if (Private->LineBuffer != NULL) {
635 FreePool (Private->LineBuffer);
636 }
637 FreePool (Private);
638 }
639 }
640
641 return Status;
642 }
643
644 /**
645 Stop this driver on Controller by removing Simple Text Out protocol
646 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
647 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
648
649
650 @param This Protocol instance pointer.
651 @param Controller Handle of device to stop driver on
652 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
653 children is zero stop the entire bus driver.
654 @param ChildHandleBuffer List of Child Handles to Stop.
655
656 @retval EFI_SUCCESS This driver is removed Controller.
657 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
658 Controller.
659 @retval other This driver was not removed from this device.
660
661 **/
662 EFI_STATUS
663 EFIAPI
664 GraphicsConsoleControllerDriverStop (
665 IN EFI_DRIVER_BINDING_PROTOCOL *This,
666 IN EFI_HANDLE Controller,
667 IN UINTN NumberOfChildren,
668 IN EFI_HANDLE *ChildHandleBuffer
669 )
670 {
671 EFI_STATUS Status;
672 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOutput;
673 GRAPHICS_CONSOLE_DEV *Private;
674
675 Status = gBS->OpenProtocol (
676 Controller,
677 &gEfiSimpleTextOutProtocolGuid,
678 (VOID **) &SimpleTextOutput,
679 This->DriverBindingHandle,
680 Controller,
681 EFI_OPEN_PROTOCOL_GET_PROTOCOL
682 );
683 if (EFI_ERROR (Status)) {
684 return EFI_NOT_STARTED;
685 }
686
687 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);
688
689 Status = gBS->UninstallProtocolInterface (
690 Controller,
691 &gEfiSimpleTextOutProtocolGuid,
692 &Private->SimpleTextOutput
693 );
694
695 if (!EFI_ERROR (Status)) {
696 //
697 // Close the GOP or UGA IO Protocol
698 //
699 if (Private->GraphicsOutput != NULL) {
700 gBS->CloseProtocol (
701 Controller,
702 &gEfiGraphicsOutputProtocolGuid,
703 This->DriverBindingHandle,
704 Controller
705 );
706 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
707 gBS->CloseProtocol (
708 Controller,
709 &gEfiUgaDrawProtocolGuid,
710 This->DriverBindingHandle,
711 Controller
712 );
713 }
714
715 //
716 // Remove the font pack
717 //
718 if (Private->HiiHandle != NULL) {
719 HiiLibRemovePackages (Private->HiiHandle);
720 mFirstAccessFlag = TRUE;
721 }
722
723 //
724 // Free our instance data
725 //
726 if (Private != NULL) {
727 FreePool (Private->LineBuffer);
728 FreePool (Private);
729 }
730 }
731
732 return Status;
733 }
734
735 /**
736 Check if the current specific mode supported the user defined resolution
737 for the Graphics Console device based on Graphics Output Protocol.
738
739 If yes, set the graphic devcice's current mode to this specific mode.
740
741 @param GraphicsOutput Graphics Output Protocol instance pointer.
742 @param HorizontalResolution User defined horizontal resolution
743 @param VerticalResolution User defined vertical resolution.
744 @param CurrentModeNumber Current specific mode to be check.
745
746 @retval EFI_SUCCESS The mode is supported.
747 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
748 device supported.
749 @retval other The specific mode does not support user defined
750 resolution or failed to set the current mode to the
751 specific mode on graphics device.
752
753 **/
754 EFI_STATUS
755 CheckModeSupported (
756 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
757 IN UINT32 HorizontalResolution,
758 IN UINT32 VerticalResolution,
759 OUT UINT32 *CurrentModeNumber
760 )
761 {
762 UINT32 ModeNumber;
763 EFI_STATUS Status;
764 UINTN SizeOfInfo;
765 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
766 UINT32 MaxMode;
767
768 Status = EFI_SUCCESS;
769 MaxMode = GraphicsOutput->Mode->MaxMode;
770
771 for (ModeNumber = 0; ModeNumber < MaxMode; ModeNumber++) {
772 Status = GraphicsOutput->QueryMode (
773 GraphicsOutput,
774 ModeNumber,
775 &SizeOfInfo,
776 &Info
777 );
778 if (!EFI_ERROR (Status)) {
779 if ((Info->HorizontalResolution == HorizontalResolution) &&
780 (Info->VerticalResolution == VerticalResolution)) {
781 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
782 if (!EFI_ERROR (Status)) {
783 FreePool (Info);
784 break;
785 }
786 }
787 FreePool (Info);
788 }
789 }
790
791 if (ModeNumber == GraphicsOutput->Mode->MaxMode) {
792 Status = EFI_UNSUPPORTED;
793 }
794
795 *CurrentModeNumber = ModeNumber;
796 return Status;
797 }
798
799
800 /**
801 Locate HII Database protocol and HII Font protocol.
802
803 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
804 are located successfully.
805 @return other Failed to locate HII Database protocol or
806 HII Font protocol.
807
808 **/
809 EFI_STATUS
810 EfiLocateHiiProtocol (
811 VOID
812 )
813 {
814 EFI_HANDLE Handle;
815 UINTN Size;
816 EFI_STATUS Status;
817
818 //
819 // There should only be one - so buffer size is this
820 //
821 Size = sizeof (EFI_HANDLE);
822
823 Status = gBS->LocateHandle (
824 ByProtocol,
825 &gEfiHiiDatabaseProtocolGuid,
826 NULL,
827 &Size,
828 (VOID **) &Handle
829 );
830
831 if (EFI_ERROR (Status)) {
832 return Status;
833 }
834
835 Status = gBS->HandleProtocol (
836 Handle,
837 &gEfiHiiDatabaseProtocolGuid,
838 (VOID **) &mHiiDatabase
839 );
840
841 if (EFI_ERROR (Status)) {
842 return Status;
843 }
844
845 Status = gBS->HandleProtocol (
846 Handle,
847 &gEfiHiiFontProtocolGuid,
848 (VOID **) &mHiiFont
849 );
850 return Status;
851 }
852
853 //
854 // Body of the STO functions
855 //
856
857 /**
858 Reset the text output device hardware and optionally run diagnostics.
859
860 Implements SIMPLE_TEXT_OUTPUT.Reset().
861 If ExtendeVerification is TRUE, then perform dependent Graphics Console
862 device reset, and set display mode to mode 0.
863 If ExtendedVerification is FALSE, only set display mode to mode 0.
864
865 @param This Protocol instance pointer.
866 @param ExtendedVerification Indicates that the driver may perform a more
867 exhaustive verification operation of the device
868 during reset.
869
870 @retval EFI_SUCCESS The text output device was reset.
871 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
872 could not be reset.
873
874 **/
875 EFI_STATUS
876 EFIAPI
877 GraphicsConsoleConOutReset (
878 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
879 IN BOOLEAN ExtendedVerification
880 )
881 {
882 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
883 return This->SetMode (This, 0);
884 }
885
886
887 /**
888 Write a Unicode string to the output device.
889
890 Implements SIMPLE_TEXT_OUTPUT.OutputString().
891 The Unicode string will be converted to Glyphs and will be
892 sent to the Graphics Console.
893
894 @param This Protocol instance pointer.
895 @param WString The NULL-terminated Unicode string to be displayed
896 on the output device(s). All output devices must
897 also support the Unicode drawing defined in this file.
898
899 @retval EFI_SUCCESS The string was output to the device.
900 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
901 the text.
902 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
903 defined text mode.
904 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
905 characters in the Unicode string could not be
906 rendered and were skipped.
907
908 **/
909 EFI_STATUS
910 EFIAPI
911 GraphicsConsoleConOutOutputString (
912 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
913 IN CHAR16 *WString
914 )
915 {
916 GRAPHICS_CONSOLE_DEV *Private;
917 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
918 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
919 INTN Mode;
920 UINTN MaxColumn;
921 UINTN MaxRow;
922 UINTN Width;
923 UINTN Height;
924 UINTN Delta;
925 EFI_STATUS Status;
926 BOOLEAN Warning;
927 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
928 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
929 UINTN DeltaX;
930 UINTN DeltaY;
931 UINTN Count;
932 UINTN Index;
933 INT32 OriginAttribute;
934 EFI_TPL OldTpl;
935
936 Status = EFI_SUCCESS;
937
938 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
939 //
940 // Current mode
941 //
942 Mode = This->Mode->Mode;
943 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
944 GraphicsOutput = Private->GraphicsOutput;
945 UgaDraw = Private->UgaDraw;
946
947 MaxColumn = Private->ModeData[Mode].Columns;
948 MaxRow = Private->ModeData[Mode].Rows;
949 DeltaX = Private->ModeData[Mode].DeltaX;
950 DeltaY = Private->ModeData[Mode].DeltaY;
951 Width = MaxColumn * EFI_GLYPH_WIDTH;
952 Height = (MaxRow - 1) * EFI_GLYPH_HEIGHT;
953 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
954
955 //
956 // The Attributes won't change when during the time OutputString is called
957 //
958 GetTextColors (This, &Foreground, &Background);
959
960 EraseCursor (This);
961
962 Warning = FALSE;
963
964 //
965 // Backup attribute
966 //
967 OriginAttribute = This->Mode->Attribute;
968
969 while (*WString != L'\0') {
970
971 if (*WString == CHAR_BACKSPACE) {
972 //
973 // If the cursor is at the left edge of the display, then move the cursor
974 // one row up.
975 //
976 if (This->Mode->CursorColumn == 0 && This->Mode->CursorRow > 0) {
977 This->Mode->CursorRow--;
978 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
979 This->OutputString (This, SpaceStr);
980 EraseCursor (This);
981 This->Mode->CursorRow--;
982 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
983 } else if (This->Mode->CursorColumn > 0) {
984 //
985 // If the cursor is not at the left edge of the display, then move the cursor
986 // left one column.
987 //
988 This->Mode->CursorColumn--;
989 This->OutputString (This, SpaceStr);
990 EraseCursor (This);
991 This->Mode->CursorColumn--;
992 }
993
994 WString++;
995
996 } else if (*WString == CHAR_LINEFEED) {
997 //
998 // If the cursor is at the bottom of the display, then scroll the display one
999 // row, and do not update the cursor position. Otherwise, move the cursor
1000 // down one row.
1001 //
1002 if (This->Mode->CursorRow == (INT32) (MaxRow - 1)) {
1003 if (GraphicsOutput != NULL) {
1004 //
1005 // Scroll Screen Up One Row
1006 //
1007 GraphicsOutput->Blt (
1008 GraphicsOutput,
1009 NULL,
1010 EfiBltVideoToVideo,
1011 DeltaX,
1012 DeltaY + EFI_GLYPH_HEIGHT,
1013 DeltaX,
1014 DeltaY,
1015 Width,
1016 Height,
1017 Delta
1018 );
1019
1020 //
1021 // Print Blank Line at last line
1022 //
1023 GraphicsOutput->Blt (
1024 GraphicsOutput,
1025 &Background,
1026 EfiBltVideoFill,
1027 0,
1028 0,
1029 DeltaX,
1030 DeltaY + Height,
1031 Width,
1032 EFI_GLYPH_HEIGHT,
1033 Delta
1034 );
1035 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1036 //
1037 // Scroll Screen Up One Row
1038 //
1039 UgaDraw->Blt (
1040 UgaDraw,
1041 NULL,
1042 EfiUgaVideoToVideo,
1043 DeltaX,
1044 DeltaY + EFI_GLYPH_HEIGHT,
1045 DeltaX,
1046 DeltaY,
1047 Width,
1048 Height,
1049 Delta
1050 );
1051
1052 //
1053 // Print Blank Line at last line
1054 //
1055 UgaDraw->Blt (
1056 UgaDraw,
1057 (EFI_UGA_PIXEL *) (UINTN) &Background,
1058 EfiUgaVideoFill,
1059 0,
1060 0,
1061 DeltaX,
1062 DeltaY + Height,
1063 Width,
1064 EFI_GLYPH_HEIGHT,
1065 Delta
1066 );
1067 }
1068 } else {
1069 This->Mode->CursorRow++;
1070 }
1071
1072 WString++;
1073
1074 } else if (*WString == CHAR_CARRIAGE_RETURN) {
1075 //
1076 // Move the cursor to the beginning of the current row.
1077 //
1078 This->Mode->CursorColumn = 0;
1079 WString++;
1080
1081 } else if (*WString == WIDE_CHAR) {
1082
1083 This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;
1084 WString++;
1085
1086 } else if (*WString == NARROW_CHAR) {
1087
1088 This->Mode->Attribute &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);
1089 WString++;
1090
1091 } else {
1092 //
1093 // Print the character at the current cursor position and move the cursor
1094 // right one column. If this moves the cursor past the right edge of the
1095 // display, then the line should wrap to the beginning of the next line. This
1096 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1097 // bottom of the display, and the line wraps, then the display will be scrolled
1098 // one line.
1099 // If wide char is going to be displayed, need to display one character at a time
1100 // Or, need to know the display length of a certain string.
1101 //
1102 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1103 // Count is used to determine how many characters are used regardless of their attributes
1104 //
1105 for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {
1106 if (WString[Count] == CHAR_NULL ||
1107 WString[Count] == CHAR_BACKSPACE ||
1108 WString[Count] == CHAR_LINEFEED ||
1109 WString[Count] == CHAR_CARRIAGE_RETURN ||
1110 WString[Count] == WIDE_CHAR ||
1111 WString[Count] == NARROW_CHAR) {
1112 break;
1113 }
1114 //
1115 // Is the wide attribute on?
1116 //
1117 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {
1118 //
1119 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1120 //
1121 Index++;
1122 //
1123 // This is the end-case where if we are at column 79 and about to print a wide character
1124 // We should prevent this from happening because we will wrap inappropriately. We should
1125 // not print this character until the next line.
1126 //
1127 if ((This->Mode->CursorColumn + Index + 1) > MaxColumn) {
1128 Index++;
1129 break;
1130 }
1131 }
1132 }
1133
1134 Status = DrawUnicodeWeightAtCursorN (This, WString, Count);
1135 if (EFI_ERROR (Status)) {
1136 Warning = TRUE;
1137 }
1138 //
1139 // At the end of line, output carriage return and line feed
1140 //
1141 WString += Count;
1142 This->Mode->CursorColumn += (INT32) Index;
1143 if (This->Mode->CursorColumn > (INT32) MaxColumn) {
1144 This->Mode->CursorColumn -= 2;
1145 This->OutputString (This, SpaceStr);
1146 }
1147
1148 if (This->Mode->CursorColumn >= (INT32) MaxColumn) {
1149 EraseCursor (This);
1150 This->OutputString (This, mCrLfString);
1151 EraseCursor (This);
1152 }
1153 }
1154 }
1155
1156 This->Mode->Attribute = OriginAttribute;
1157
1158 EraseCursor (This);
1159
1160 if (Warning) {
1161 Status = EFI_WARN_UNKNOWN_GLYPH;
1162 }
1163
1164 gBS->RestoreTPL (OldTpl);
1165 return Status;
1166
1167 }
1168
1169 /**
1170 Verifies that all characters in a Unicode string can be output to the
1171 target device.
1172
1173 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1174 If one of the characters in the *Wstring is neither valid valid Unicode
1175 drawing characters, not ASCII code, then this function will return
1176 EFI_UNSUPPORTED
1177
1178 @param This Protocol instance pointer.
1179 @param WString The NULL-terminated Unicode string to be examined for the output
1180 device(s).
1181
1182 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1183 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1184 rendered by one or more of the output devices mapped
1185 by the EFI handle.
1186
1187 **/
1188 EFI_STATUS
1189 EFIAPI
1190 GraphicsConsoleConOutTestString (
1191 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1192 IN CHAR16 *WString
1193 )
1194 {
1195 EFI_STATUS Status;
1196 UINT16 Count;
1197
1198 EFI_IMAGE_OUTPUT *Blt;
1199
1200 Blt = NULL;
1201 Count = 0;
1202
1203 while (WString[Count] != 0) {
1204 Status = mHiiFont->GetGlyph (
1205 mHiiFont,
1206 WString[Count],
1207 NULL,
1208 &Blt,
1209 NULL
1210 );
1211 if (Blt != NULL) {
1212 FreePool (Blt);
1213 Blt = NULL;
1214 }
1215 Count++;
1216
1217 if (EFI_ERROR (Status)) {
1218 return EFI_UNSUPPORTED;
1219 }
1220 }
1221
1222 return EFI_SUCCESS;
1223 }
1224
1225
1226 /**
1227 Returns information for an available text mode that the output device(s)
1228 supports
1229
1230 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1231 It returnes information for an available text mode that the Graphics Console supports.
1232 In this driver,we only support text mode 80x25, which is defined as mode 0.
1233
1234 @param This Protocol instance pointer.
1235 @param ModeNumber The mode number to return information on.
1236 @param Columns The returned columns of the requested mode.
1237 @param Rows The returned rows of the requested mode.
1238
1239 @retval EFI_SUCCESS The requested mode information is returned.
1240 @retval EFI_UNSUPPORTED The mode number is not valid.
1241
1242 **/
1243 EFI_STATUS
1244 EFIAPI
1245 GraphicsConsoleConOutQueryMode (
1246 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1247 IN UINTN ModeNumber,
1248 OUT UINTN *Columns,
1249 OUT UINTN *Rows
1250 )
1251 {
1252 GRAPHICS_CONSOLE_DEV *Private;
1253 EFI_STATUS Status;
1254 EFI_TPL OldTpl;
1255
1256 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {
1257 return EFI_UNSUPPORTED;
1258 }
1259
1260 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1261 Status = EFI_SUCCESS;
1262
1263 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1264
1265 *Columns = Private->ModeData[ModeNumber].Columns;
1266 *Rows = Private->ModeData[ModeNumber].Rows;
1267
1268 if (*Columns <= 0 && *Rows <= 0) {
1269 Status = EFI_UNSUPPORTED;
1270 goto Done;
1271
1272 }
1273
1274 Done:
1275 gBS->RestoreTPL (OldTpl);
1276 return Status;
1277 }
1278
1279
1280 /**
1281 Sets the output device(s) to a specified mode.
1282
1283 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1284 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1285
1286 @param This Protocol instance pointer.
1287 @param ModeNumber The text mode to set.
1288
1289 @retval EFI_SUCCESS The requested text mode is set.
1290 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1291 Graphics Console device error.
1292 @retval EFI_UNSUPPORTED The text mode number is not valid.
1293
1294 **/
1295 EFI_STATUS
1296 EFIAPI
1297 GraphicsConsoleConOutSetMode (
1298 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1299 IN UINTN ModeNumber
1300 )
1301 {
1302 EFI_STATUS Status;
1303 GRAPHICS_CONSOLE_DEV *Private;
1304 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1305 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;
1306 UINT32 HorizontalResolution;
1307 UINT32 VerticalResolution;
1308 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1309 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1310 UINT32 ColorDepth;
1311 UINT32 RefreshRate;
1312 EFI_TPL OldTpl;
1313
1314 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1315
1316 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1317 GraphicsOutput = Private->GraphicsOutput;
1318 UgaDraw = Private->UgaDraw;
1319 ModeData = &(Private->ModeData[ModeNumber]);
1320
1321 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {
1322 Status = EFI_UNSUPPORTED;
1323 goto Done;
1324 }
1325
1326 //
1327 // Make sure the requested mode number is supported
1328 //
1329 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {
1330 Status = EFI_UNSUPPORTED;
1331 goto Done;
1332 }
1333
1334 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {
1335 Status = EFI_UNSUPPORTED;
1336 goto Done;
1337 }
1338 //
1339 // Attempt to allocate a line buffer for the requested mode number
1340 //
1341 NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);
1342
1343 if (NewLineBuffer == NULL) {
1344 //
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
1347 //
1348 Status = EFI_OUT_OF_RESOURCES;
1349 goto Done;
1350 }
1351 //
1352 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1353 //
1354 if (Private->LineBuffer != NULL) {
1355 //
1356 // Clear the current text window on the current graphics console
1357 //
1358 This->ClearScreen (This);
1359
1360 //
1361 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1362 //
1363 if ((INT32) ModeNumber == This->Mode->Mode) {
1364 FreePool (NewLineBuffer);
1365 Status = EFI_SUCCESS;
1366 goto Done;
1367 }
1368 //
1369 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1370 // so erase the cursor, and free the LineBuffer for the current mode
1371 //
1372 EraseCursor (This);
1373
1374 FreePool (Private->LineBuffer);
1375 }
1376 //
1377 // Assign the current line buffer to the newly allocated line buffer
1378 //
1379 Private->LineBuffer = NewLineBuffer;
1380
1381 if (GraphicsOutput != NULL) {
1382 if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) {
1383 //
1384 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1385 //
1386 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber);
1387 if (EFI_ERROR (Status)) {
1388 //
1389 // The mode set operation failed
1390 //
1391 goto Done;
1392 }
1393 } else {
1394 //
1395 // The current graphics mode is correct, so simply clear the entire display
1396 //
1397 Status = GraphicsOutput->Blt (
1398 GraphicsOutput,
1399 &mEfiColors[0],
1400 EfiBltVideoFill,
1401 0,
1402 0,
1403 0,
1404 0,
1405 ModeData->GopWidth,
1406 ModeData->GopHeight,
1407 0
1408 );
1409 }
1410 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1411 //
1412 // Get the current UGA Draw mode information
1413 //
1414 Status = UgaDraw->GetMode (
1415 UgaDraw,
1416 &HorizontalResolution,
1417 &VerticalResolution,
1418 &ColorDepth,
1419 &RefreshRate
1420 );
1421 if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {
1422 //
1423 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1424 //
1425 Status = UgaDraw->SetMode (
1426 UgaDraw,
1427 ModeData->GopWidth,
1428 ModeData->GopHeight,
1429 32,
1430 60
1431 );
1432 if (EFI_ERROR (Status)) {
1433 //
1434 // The mode set operation failed
1435 //
1436 goto Done;
1437 }
1438 } else {
1439 //
1440 // The current graphics mode is correct, so simply clear the entire display
1441 //
1442 Status = UgaDraw->Blt (
1443 UgaDraw,
1444 (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],
1445 EfiUgaVideoFill,
1446 0,
1447 0,
1448 0,
1449 0,
1450 ModeData->GopWidth,
1451 ModeData->GopHeight,
1452 0
1453 );
1454 }
1455 }
1456
1457 //
1458 // The new mode is valid, so commit the mode change
1459 //
1460 This->Mode->Mode = (INT32) ModeNumber;
1461
1462 //
1463 // Move the text cursor to the upper left hand corner of the display and enable it
1464 //
1465 This->SetCursorPosition (This, 0, 0);
1466
1467 Status = EFI_SUCCESS;
1468
1469 Done:
1470 gBS->RestoreTPL (OldTpl);
1471 return Status;
1472 }
1473
1474
1475 /**
1476 Sets the background and foreground colors for the OutputString () and
1477 ClearScreen () functions.
1478
1479 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1480
1481 @param This Protocol instance pointer.
1482 @param Attribute The attribute to set. Bits 0..3 are the foreground
1483 color, and bits 4..6 are the background color.
1484 All other bits are undefined and must be zero.
1485
1486 @retval EFI_SUCCESS The requested attribute is set.
1487 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1488 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1489
1490 **/
1491 EFI_STATUS
1492 EFIAPI
1493 GraphicsConsoleConOutSetAttribute (
1494 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1495 IN UINTN Attribute
1496 )
1497 {
1498 EFI_TPL OldTpl;
1499
1500 if ((Attribute | 0xFF) != 0xFF) {
1501 return EFI_UNSUPPORTED;
1502 }
1503
1504 if ((INT32) Attribute == This->Mode->Attribute) {
1505 return EFI_SUCCESS;
1506 }
1507
1508 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1509
1510 EraseCursor (This);
1511
1512 This->Mode->Attribute = (INT32) Attribute;
1513
1514 EraseCursor (This);
1515
1516 gBS->RestoreTPL (OldTpl);
1517
1518 return EFI_SUCCESS;
1519 }
1520
1521
1522 /**
1523 Clears the output device(s) display to the currently selected background
1524 color.
1525
1526 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1527
1528 @param This Protocol instance pointer.
1529
1530 @retval EFI_SUCCESS The operation completed successfully.
1531 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1532 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1533
1534 **/
1535 EFI_STATUS
1536 EFIAPI
1537 GraphicsConsoleConOutClearScreen (
1538 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
1539 )
1540 {
1541 EFI_STATUS Status;
1542 GRAPHICS_CONSOLE_DEV *Private;
1543 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1544 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1545 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1546 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
1547 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
1548 EFI_TPL OldTpl;
1549
1550 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1551
1552 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1553 GraphicsOutput = Private->GraphicsOutput;
1554 UgaDraw = Private->UgaDraw;
1555 ModeData = &(Private->ModeData[This->Mode->Mode]);
1556
1557 GetTextColors (This, &Foreground, &Background);
1558 if (GraphicsOutput != NULL) {
1559 Status = GraphicsOutput->Blt (
1560 GraphicsOutput,
1561 &Background,
1562 EfiBltVideoFill,
1563 0,
1564 0,
1565 0,
1566 0,
1567 ModeData->GopWidth,
1568 ModeData->GopHeight,
1569 0
1570 );
1571 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1572 Status = UgaDraw->Blt (
1573 UgaDraw,
1574 (EFI_UGA_PIXEL *) (UINTN) &Background,
1575 EfiUgaVideoFill,
1576 0,
1577 0,
1578 0,
1579 0,
1580 ModeData->GopWidth,
1581 ModeData->GopHeight,
1582 0
1583 );
1584 } else {
1585 Status = EFI_UNSUPPORTED;
1586 }
1587
1588 This->Mode->CursorColumn = 0;
1589 This->Mode->CursorRow = 0;
1590
1591 EraseCursor (This);
1592
1593 gBS->RestoreTPL (OldTpl);
1594
1595 return Status;
1596 }
1597
1598
1599 /**
1600 Sets the current coordinates of the cursor position.
1601
1602 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1603
1604 @param This Protocol instance pointer.
1605 @param Column The position to set the cursor to. Must be greater than or
1606 equal to zero and less than the number of columns and rows
1607 by QueryMode ().
1608 @param Row The position to set the cursor to. Must be greater than or
1609 equal to zero and less than the number of columns and rows
1610 by QueryMode ().
1611
1612 @retval EFI_SUCCESS The operation completed successfully.
1613 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1614 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1615 cursor position is invalid for the current mode.
1616
1617 **/
1618 EFI_STATUS
1619 EFIAPI
1620 GraphicsConsoleConOutSetCursorPosition (
1621 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1622 IN UINTN Column,
1623 IN UINTN Row
1624 )
1625 {
1626 GRAPHICS_CONSOLE_DEV *Private;
1627 GRAPHICS_CONSOLE_MODE_DATA *ModeData;
1628 EFI_STATUS Status;
1629 EFI_TPL OldTpl;
1630
1631 Status = EFI_SUCCESS;
1632
1633 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1634
1635 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1636 ModeData = &(Private->ModeData[This->Mode->Mode]);
1637
1638 if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {
1639 Status = EFI_UNSUPPORTED;
1640 goto Done;
1641 }
1642
1643 if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {
1644 Status = EFI_SUCCESS;
1645 goto Done;
1646 }
1647
1648 EraseCursor (This);
1649
1650 This->Mode->CursorColumn = (INT32) Column;
1651 This->Mode->CursorRow = (INT32) Row;
1652
1653 EraseCursor (This);
1654
1655 Done:
1656 gBS->RestoreTPL (OldTpl);
1657
1658 return Status;
1659 }
1660
1661
1662 /**
1663 Makes the cursor visible or invisible.
1664
1665 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1666
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.
1670
1671 @retval EFI_SUCCESS The operation completed successfully.
1672
1673 **/
1674 EFI_STATUS
1675 EFIAPI
1676 GraphicsConsoleConOutEnableCursor (
1677 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1678 IN BOOLEAN Visible
1679 )
1680 {
1681 EFI_TPL OldTpl;
1682
1683 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1684
1685 EraseCursor (This);
1686
1687 This->Mode->CursorVisible = Visible;
1688
1689 EraseCursor (This);
1690
1691 gBS->RestoreTPL (OldTpl);
1692 return EFI_SUCCESS;
1693 }
1694
1695 /**
1696 Gets Graphics Console devcie's foreground color and background color.
1697
1698 @param This Protocol instance pointer.
1699 @param Foreground Returned text foreground color.
1700 @param Background Returned text background color.
1701
1702 @retval EFI_SUCCESS It returned always.
1703
1704 **/
1705 EFI_STATUS
1706 GetTextColors (
1707 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1708 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
1709 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background
1710 )
1711 {
1712 INTN Attribute;
1713
1714 Attribute = This->Mode->Attribute & 0x7F;
1715
1716 *Foreground = mEfiColors[Attribute & 0x0f];
1717 *Background = mEfiColors[Attribute >> 4];
1718
1719 return EFI_SUCCESS;
1720 }
1721
1722 /**
1723 Draw Unicode string on the Graphics Console device's screen.
1724
1725 @param This Protocol instance pointer.
1726 @param UnicodeWeight One Unicode string to be displayed.
1727 @param Count The count of Unicode string.
1728
1729 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1730 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1731 protocol exist.
1732 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1733
1734 **/
1735 EFI_STATUS
1736 DrawUnicodeWeightAtCursorN (
1737 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
1738 IN CHAR16 *UnicodeWeight,
1739 IN UINTN Count
1740 )
1741 {
1742 EFI_STATUS Status;
1743 GRAPHICS_CONSOLE_DEV *Private;
1744 EFI_IMAGE_OUTPUT *Blt;
1745 EFI_STRING String;
1746 EFI_FONT_DISPLAY_INFO *FontInfo;
1747 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1748 EFI_HII_ROW_INFO *RowInfoArray;
1749 UINTN RowInfoArraySize;
1750
1751 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1752 Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
1753 if (Blt == NULL) {
1754 return EFI_OUT_OF_RESOURCES;
1755 }
1756
1757 Blt->Width = (UINT16) (Private->ModeData[This->Mode->Mode].GopWidth);
1758 Blt->Height = (UINT16) (Private->ModeData[This->Mode->Mode].GopHeight);
1759
1760 String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);
1761 if (String == NULL) {
1762 FreePool (Blt);
1763 return EFI_OUT_OF_RESOURCES;
1764 }
1765 //
1766 // Set the end character
1767 //
1768 *(String + Count) = L'\0';
1769
1770 FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));
1771 if (FontInfo == NULL) {
1772 FreePool (Blt);
1773 FreePool (String);
1774 return EFI_OUT_OF_RESOURCES;
1775 }
1776 //
1777 // Get current foreground and background colors.
1778 //
1779 GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);
1780
1781 if (Private->GraphicsOutput != NULL) {
1782 //
1783 // If Graphics Output protocol exists, using HII Font protocol to draw.
1784 //
1785 Blt->Image.Screen = Private->GraphicsOutput;
1786
1787 Status = mHiiFont->StringToImage (
1788 mHiiFont,
1789 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,
1790 String,
1791 FontInfo,
1792 &Blt,
1793 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
1794 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
1795 NULL,
1796 NULL,
1797 NULL
1798 );
1799
1800 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1801 //
1802 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1803 // using UGA Draw protocol to draw.
1804 //
1805 ASSERT (Private->UgaDraw!= NULL);
1806
1807 UgaDraw = Private->UgaDraw;
1808
1809 Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
1810 if (Blt->Image.Bitmap == NULL) {
1811 FreePool (Blt);
1812 FreePool (String);
1813 return EFI_OUT_OF_RESOURCES;
1814 }
1815
1816 RowInfoArray = NULL;
1817 //
1818 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1819 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1820 //
1821 Status = mHiiFont->StringToImage (
1822 mHiiFont,
1823 EFI_HII_IGNORE_IF_NO_GLYPH,
1824 String,
1825 FontInfo,
1826 &Blt,
1827 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
1828 This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
1829 &RowInfoArray,
1830 &RowInfoArraySize,
1831 NULL
1832 );
1833
1834 if (!EFI_ERROR (Status)) {
1835 //
1836 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1837 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1838 //
1839 ASSERT (RowInfoArraySize <= 1);
1840
1841 Status = UgaDraw->Blt (
1842 UgaDraw,
1843 (EFI_UGA_PIXEL *) Blt->Image.Bitmap,
1844 EfiUgaBltBufferToVideo,
1845 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
1846 (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
1847 This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,
1848 (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,
1849 RowInfoArray[0].LineWidth,
1850 RowInfoArray[0].LineHeight,
1851 Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1852 );
1853 }
1854
1855 FreePool (RowInfoArray);
1856 FreePool (Blt->Image.Bitmap);
1857 } else {
1858 Status = EFI_UNSUPPORTED;
1859 }
1860
1861 if (Blt != NULL) {
1862 FreePool (Blt);
1863 }
1864 if (String != NULL) {
1865 FreePool (String);
1866 }
1867 if (FontInfo != NULL) {
1868 FreePool (FontInfo);
1869 }
1870 return Status;
1871 }
1872
1873 /**
1874 Erase the cursor on the screen.
1875
1876 @param This Protocol instance pointer.
1877
1878 @retval EFI_SUCCESS The cursor is erased successfully.
1879
1880 **/
1881 EFI_STATUS
1882 EraseCursor (
1883 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
1884 )
1885 {
1886 GRAPHICS_CONSOLE_DEV *Private;
1887 EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode;
1888 INTN GlyphX;
1889 INTN GlyphY;
1890 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1891 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1892 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;
1893 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;
1894 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];
1895 UINTN PosX;
1896 UINTN PosY;
1897
1898 CurrentMode = This->Mode;
1899
1900 if (!CurrentMode->CursorVisible) {
1901 return EFI_SUCCESS;
1902 }
1903
1904 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
1905 GraphicsOutput = Private->GraphicsOutput;
1906 UgaDraw = Private->UgaDraw;
1907
1908 //
1909 // In this driver, only narrow character was supported.
1910 //
1911 //
1912 // Blt a character to the screen
1913 //
1914 GlyphX = (CurrentMode->CursorColumn * EFI_GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;
1915 GlyphY = (CurrentMode->CursorRow * EFI_GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;
1916 if (GraphicsOutput != NULL) {
1917 GraphicsOutput->Blt (
1918 GraphicsOutput,
1919 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,
1920 EfiBltVideoToBltBuffer,
1921 GlyphX,
1922 GlyphY,
1923 0,
1924 0,
1925 EFI_GLYPH_WIDTH,
1926 EFI_GLYPH_HEIGHT,
1927 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1928 );
1929 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1930 UgaDraw->Blt (
1931 UgaDraw,
1932 (EFI_UGA_PIXEL *) (UINTN) BltChar,
1933 EfiUgaVideoToBltBuffer,
1934 GlyphX,
1935 GlyphY,
1936 0,
1937 0,
1938 EFI_GLYPH_WIDTH,
1939 EFI_GLYPH_HEIGHT,
1940 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
1941 );
1942 }
1943
1944 GetTextColors (This, &Foreground.Pixel, &Background.Pixel);
1945
1946 //
1947 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1948 //
1949 for (PosY = 0; PosY < EFI_GLYPH_HEIGHT; PosY++) {
1950 for (PosX = 0; PosX < EFI_GLYPH_WIDTH; PosX++) {
1951 if ((mCursorGlyph.GlyphCol1[PosY] & (BIT0 << PosX)) != 0) {
1952 BltChar[PosY][EFI_GLYPH_WIDTH - PosX - 1].Raw ^= Foreground.Raw;
1953 }
1954 }
1955 }
1956
1957 if (GraphicsOutput != NULL) {
1958 GraphicsOutput->Blt (
1959 GraphicsOutput,
1960 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,
1961 EfiBltBufferToVideo,
1962 0,
1963 0,
1964 GlyphX,
1965 GlyphY,
1966 EFI_GLYPH_WIDTH,
1967 EFI_GLYPH_HEIGHT,
1968 EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1969 );
1970 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
1971 UgaDraw->Blt (
1972 UgaDraw,
1973 (EFI_UGA_PIXEL *) (UINTN) BltChar,
1974 EfiUgaBltBufferToVideo,
1975 0,
1976 0,
1977 GlyphX,
1978 GlyphY,
1979 EFI_GLYPH_WIDTH,
1980 EFI_GLYPH_HEIGHT,
1981 EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)
1982 );
1983 }
1984
1985 return EFI_SUCCESS;
1986 }
1987
1988 /**
1989 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1990
1991 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1992 @param[in] SystemTable A pointer to the EFI System Table.
1993
1994 @retval EFI_SUCCESS The entry point is executed successfully.
1995 @return other Some error occurs when executing this entry point.
1996
1997 **/
1998 EFI_STATUS
1999 EFIAPI
2000 InitializeGraphicsConsole (
2001 IN EFI_HANDLE ImageHandle,
2002 IN EFI_SYSTEM_TABLE *SystemTable
2003 )
2004 {
2005 EFI_STATUS Status;
2006
2007 //
2008 // Install driver model protocol(s).
2009 //
2010 Status = EfiLibInstallDriverBindingComponentName2 (
2011 ImageHandle,
2012 SystemTable,
2013 &gGraphicsConsoleDriverBinding,
2014 ImageHandle,
2015 &gGraphicsConsoleComponentName,
2016 &gGraphicsConsoleComponentName2
2017 );
2018 ASSERT_EFI_ERROR (Status);
2019
2020 return Status;
2021 }
2022
2023