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