Add a lock to protect the critical region in Service APIs for gEfiSimpleTextOutProtoc...
[mirror_edk2.git] / EdkModulePkg / Universal / Console / GraphicsConsole / Dxe / GraphicsConsole.c
CommitLineData
7a2729d4 1/**@file\r
2 This is the main routine for initializing the Graphics Console support routines.\r
3Remaining Tasks\r
4 Add all standard Glyphs from EFI 1.02 Specification\r
5 Implement optimal automatic Mode creation algorithm\r
6 Solve palette issues for mixed graphics and text\r
7 When does this protocol reset the palette?\r
8 \r
0fe0b10e 9Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
878ddf1f 10All rights reserved. This program and the accompanying materials \r
11are licensed and made available under the terms and conditions of the BSD License \r
12which accompanies this distribution. The full text of the license may be found at \r
13http://opensource.org/licenses/bsd-license.php \r
14 \r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
17\r
7a2729d4 18**/\r
878ddf1f 19\r
20#include "GraphicsConsole.h"\r
21\r
92dda53e 22STATIC\r
878ddf1f 23EFI_STATUS\r
24GetTextColors (\r
25 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
406adcd1 26 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
27 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background\r
878ddf1f 28 );\r
29\r
92dda53e 30STATIC\r
878ddf1f 31EFI_STATUS\r
32DrawUnicodeWeightAtCursorN (\r
33 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
34 IN CHAR16 *UnicodeWeight,\r
35 IN UINTN Count\r
36 );\r
37\r
92dda53e 38STATIC\r
878ddf1f 39EFI_STATUS\r
40EraseCursor (\r
41 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This\r
42 );\r
43\r
44//\r
45// Globals\r
46//\r
47GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = {\r
48 GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
406adcd1 49 (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,\r
878ddf1f 50 (EFI_UGA_DRAW_PROTOCOL *) NULL,\r
51 {\r
52 GraphicsConsoleConOutReset,\r
53 GraphicsConsoleConOutOutputString,\r
54 GraphicsConsoleConOutTestString,\r
55 GraphicsConsoleConOutQueryMode,\r
56 GraphicsConsoleConOutSetMode,\r
57 GraphicsConsoleConOutSetAttribute,\r
58 GraphicsConsoleConOutClearScreen,\r
59 GraphicsConsoleConOutSetCursorPosition,\r
60 GraphicsConsoleConOutEnableCursor,\r
61 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL\r
62 },\r
63 {\r
64 0,\r
65 0,\r
66 EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),\r
67 0,\r
68 0,\r
69 TRUE\r
70 },\r
71 {\r
72 { 80, 25, 0, 0, 0, 0 }, // Mode 0\r
3bc85e36 73 { 80, 50, 0, 0, 0, 0 }, // Mode 1 \r
878ddf1f 74 { 0, 0, 0, 0, 0, 0 } // Mode 2\r
75 },\r
406adcd1 76 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
878ddf1f 77 (EFI_HII_HANDLE) 0\r
78};\r
79\r
80EFI_HII_PROTOCOL *mHii;\r
81\r
82static CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
83\r
406adcd1 84static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
878ddf1f 85 //\r
86 // B G R\r
87 //\r
7a2729d4 88 {0x00, 0x00, 0x00, 0x00}, // BLACK\r
89 {0x98, 0x00, 0x00, 0x00}, // BLUE\r
90 {0x00, 0x98, 0x00, 0x00}, // GREEN\r
91 {0x98, 0x98, 0x00, 0x00}, // CYAN\r
92 {0x00, 0x00, 0x98, 0x00}, // RED\r
93 {0x98, 0x00, 0x98, 0x00}, // MAGENTA\r
94 {0x00, 0x98, 0x98, 0x00}, // BROWN\r
95 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY\r
96 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK\r
97 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ?\r
98 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ?\r
99 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN\r
100 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED\r
101 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA\r
102 {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN\r
103 {0xff, 0xff, 0xff, 0x00} // WHITE\r
878ddf1f 104};\r
105\r
106static EFI_NARROW_GLYPH mCursorGlyph = {\r
107 0x0000,\r
108 0x00,\r
109 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }\r
110};\r
111\r
878ddf1f 112EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {\r
113 GraphicsConsoleControllerDriverSupported,\r
114 GraphicsConsoleControllerDriverStart,\r
115 GraphicsConsoleControllerDriverStop,\r
61fb1657 116 0xa,\r
878ddf1f 117 NULL,\r
118 NULL\r
119};\r
120\r
121EFI_STATUS\r
122EFIAPI\r
123GraphicsConsoleControllerDriverSupported (\r
124 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
125 IN EFI_HANDLE Controller,\r
126 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
127 )\r
128{\r
129 EFI_STATUS Status;\r
406adcd1 130 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
878ddf1f 131 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
132 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
133\r
406adcd1 134 UgaDraw = NULL;\r
878ddf1f 135 //\r
136 // Open the IO Abstraction(s) needed to perform the supported test\r
137 //\r
138 Status = gBS->OpenProtocol (\r
139 Controller,\r
406adcd1 140 &gEfiGraphicsOutputProtocolGuid,\r
141 (VOID **) &GraphicsOutput,\r
878ddf1f 142 This->DriverBindingHandle,\r
143 Controller,\r
144 EFI_OPEN_PROTOCOL_BY_DRIVER\r
145 );\r
406adcd1 146 \r
878ddf1f 147 if (EFI_ERROR (Status)) {\r
406adcd1 148 GraphicsOutput = NULL;\r
149 //\r
150 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol\r
151 //\r
152 Status = gBS->OpenProtocol (\r
153 Controller,\r
154 &gEfiUgaDrawProtocolGuid,\r
155 (VOID **) &UgaDraw,\r
156 This->DriverBindingHandle,\r
157 Controller,\r
158 EFI_OPEN_PROTOCOL_BY_DRIVER\r
159 );\r
160 if (EFI_ERROR (Status)) {\r
161 return Status;\r
162 }\r
878ddf1f 163 }\r
406adcd1 164\r
878ddf1f 165 //\r
166 // We need to ensure that we do not layer on top of a virtual handle.\r
167 // We need to ensure that the handles produced by the conspliter do not\r
168 // get used.\r
169 //\r
170 Status = gBS->OpenProtocol (\r
171 Controller,\r
172 &gEfiDevicePathProtocolGuid,\r
173 (VOID **) &DevicePath,\r
174 This->DriverBindingHandle,\r
175 Controller,\r
176 EFI_OPEN_PROTOCOL_BY_DRIVER\r
177 );\r
178 if (!EFI_ERROR (Status)) {\r
179 gBS->CloseProtocol (\r
180 Controller,\r
181 &gEfiDevicePathProtocolGuid,\r
182 This->DriverBindingHandle,\r
183 Controller\r
184 );\r
185 } else {\r
186 goto Error;\r
187 }\r
188 //\r
189 // Does Hii Exist? If not, we aren't ready to run\r
190 //\r
191 Status = EfiLocateHiiProtocol ();\r
192\r
193 //\r
194 // Close the I/O Abstraction(s) used to perform the supported test\r
195 //\r
196Error:\r
406adcd1 197 if (GraphicsOutput != NULL) {\r
198 gBS->CloseProtocol (\r
199 Controller,\r
200 &gEfiGraphicsOutputProtocolGuid,\r
201 This->DriverBindingHandle,\r
202 Controller\r
203 );\r
204 } else {\r
205 gBS->CloseProtocol (\r
206 Controller,\r
207 &gEfiUgaDrawProtocolGuid,\r
208 This->DriverBindingHandle,\r
209 Controller\r
210 );\r
211 }\r
878ddf1f 212 return Status;\r
213}\r
214\r
215EFI_STATUS\r
216EFIAPI\r
217GraphicsConsoleControllerDriverStart (\r
218 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
219 IN EFI_HANDLE Controller,\r
220 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
221 )\r
222/*++\r
223\r
224 Routine Description:\r
225\r
226 Start the controller.\r
227\r
228 Arguments:\r
229\r
230 This - A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
231 Controller - The handle of the controller to start.\r
232 RemainingDevicePath - A pointer to the remaining portion of a devcie path.\r
233\r
234 Returns:\r
235\r
236 EFI_SUCCESS - Return successfully.\r
237 EFI_OUT_OF_RESOURCES - Out of resources.\r
238\r
239--*/\r
240{\r
241 EFI_STATUS Status;\r
242 GRAPHICS_CONSOLE_DEV *Private;\r
243 EFI_HII_PACKAGES *Package;\r
244 EFI_HII_FONT_PACK *FontPack;\r
245 UINTN NarrowFontSize;\r
246 UINT32 HorizontalResolution;\r
247 UINT32 VerticalResolution;\r
248 UINT32 ColorDepth;\r
249 UINT32 RefreshRate;\r
250 UINTN MaxMode;\r
251 UINTN Columns;\r
252 UINTN Rows;\r
253 UINT8 *Location;\r
406adcd1 254 UINT32 ModeNumber;\r
255 UINTN SizeOfInfo;\r
256 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
257 \r
258 ModeNumber = 0;\r
259\r
878ddf1f 260 //\r
261 // Initialize the Graphics Console device instance\r
262 //\r
263 Private = AllocateCopyPool (\r
264 sizeof (GRAPHICS_CONSOLE_DEV),\r
265 &mGraphicsConsoleDevTemplate\r
266 );\r
267 if (Private == NULL) {\r
268 return EFI_OUT_OF_RESOURCES;\r
269 }\r
270\r
271 Private->SimpleTextOutput.Mode = &(Private->SimpleTextOutputMode);\r
272\r
273 Status = gBS->OpenProtocol (\r
274 Controller,\r
406adcd1 275 &gEfiGraphicsOutputProtocolGuid,\r
276 (VOID **) &Private->GraphicsOutput,\r
878ddf1f 277 This->DriverBindingHandle,\r
278 Controller,\r
279 EFI_OPEN_PROTOCOL_BY_DRIVER\r
280 );\r
406adcd1 281 if (EFI_ERROR(Status)) {\r
282 Private->GraphicsOutput = NULL;\r
283\r
284 Status = gBS->OpenProtocol (\r
285 Controller,\r
286 &gEfiUgaDrawProtocolGuid,\r
287 (VOID **) &Private->UgaDraw,\r
288 This->DriverBindingHandle,\r
289 Controller,\r
290 EFI_OPEN_PROTOCOL_BY_DRIVER\r
291 );\r
292 if (EFI_ERROR (Status)) {\r
293 goto Error;\r
294 }\r
878ddf1f 295 }\r
406adcd1 296\r
878ddf1f 297 //\r
298 // Get the HII protocol. If Supported() succeeds, do we really\r
299 // need to get HII protocol again?\r
300 //\r
301 Status = EfiLocateHiiProtocol ();\r
302 if (EFI_ERROR (Status)) {\r
303 goto Error;\r
304 }\r
305\r
306 NarrowFontSize = ReturnNarrowFontSize ();\r
307\r
308 FontPack = AllocateZeroPool (sizeof (EFI_HII_FONT_PACK) + NarrowFontSize);\r
309 ASSERT (FontPack);\r
310\r
311 FontPack->Header.Length = (UINT32) (sizeof (EFI_HII_FONT_PACK) + NarrowFontSize);\r
312 FontPack->Header.Type = EFI_HII_FONT;\r
313 FontPack->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
314\r
315 Location = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8));\r
316 CopyMem (Location, UsStdNarrowGlyphData, NarrowFontSize);\r
317\r
318 //\r
319 // Register our Fonts into the global database\r
320 //\r
321 Package = PreparePackages (1, NULL, FontPack);\r
322 mHii->NewPack (mHii, Package, &(Private->HiiHandle));\r
323 gBS->FreePool (Package);\r
324\r
325 //\r
326 // Free the font database\r
327 //\r
328 gBS->FreePool (FontPack);\r
329\r
330 //\r
331 // If the current mode information can not be retrieved, then attemp to set the default mode\r
332 // of 800x600, 32 bit colot, 60 Hz refresh.\r
333 //\r
334 HorizontalResolution = 800;\r
335 VerticalResolution = 600;\r
406adcd1 336\r
337 if (Private->GraphicsOutput != NULL) {\r
878ddf1f 338 //\r
406adcd1 339 // The console is build on top of Graphics Output Protocol, find the mode number for 800x600\r
878ddf1f 340 //\r
406adcd1 341 for (ModeNumber = 0; ModeNumber < Private->GraphicsOutput->Mode->MaxMode; ModeNumber++) {\r
342 Status = Private->GraphicsOutput->QueryMode (\r
343 Private->GraphicsOutput,\r
344 ModeNumber,\r
345 &SizeOfInfo,\r
346 &Info\r
347 );\r
348 if (!EFI_ERROR (Status)) {\r
349 if ((Info->HorizontalResolution == 800) &&\r
e313deb9 350 (Info->VerticalResolution == 600)) {\r
406adcd1 351 Status = Private->GraphicsOutput->SetMode (Private->GraphicsOutput, ModeNumber);\r
352 if (!EFI_ERROR (Status)) {\r
353 gBS->FreePool (Info);\r
354 break;\r
355 }\r
356 }\r
357 gBS->FreePool (Info);\r
358 }\r
359 }\r
360\r
361 if (EFI_ERROR (Status) || (ModeNumber == Private->GraphicsOutput->Mode->MaxMode)) {\r
362 //\r
363 // Set default mode failed or device don't support default mode, then get the current mode information\r
364 //\r
365 HorizontalResolution = Private->GraphicsOutput->Mode->Info->HorizontalResolution;\r
366 VerticalResolution = Private->GraphicsOutput->Mode->Info->VerticalResolution;\r
367 ModeNumber = Private->GraphicsOutput->Mode->Mode;\r
368 }\r
369 } else {\r
370 //\r
371 // The console is build on top of UGA Draw Protocol\r
372 //\r
373 ColorDepth = 32;\r
374 RefreshRate = 60;\r
375 Status = Private->UgaDraw->SetMode (\r
878ddf1f 376 Private->UgaDraw,\r
406adcd1 377 HorizontalResolution,\r
378 VerticalResolution,\r
379 ColorDepth,\r
380 RefreshRate\r
878ddf1f 381 );\r
382 if (EFI_ERROR (Status)) {\r
406adcd1 383 //\r
384 // Get the current mode information from the UGA Draw Protocol\r
385 //\r
386 Status = Private->UgaDraw->GetMode (\r
387 Private->UgaDraw,\r
388 &HorizontalResolution,\r
389 &VerticalResolution,\r
390 &ColorDepth,\r
391 &RefreshRate\r
392 );\r
393 if (EFI_ERROR (Status)) {\r
394 goto Error;\r
395 }\r
878ddf1f 396 }\r
397 }\r
406adcd1 398\r
878ddf1f 399 //\r
400 // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
401 //\r
402 Columns = HorizontalResolution / GLYPH_WIDTH;\r
403 Rows = VerticalResolution / GLYPH_HEIGHT;\r
404\r
405 //\r
406 // See if the mode is too small to support the required 80x25 text mode\r
407 //\r
408 if (Columns < 80 || Rows < 25) {\r
409 goto Error;\r
410 }\r
411 //\r
412 // Add Mode #0 that must be 80x25\r
413 //\r
414 MaxMode = 0;\r
406adcd1 415 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
416 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
417 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
878ddf1f 418 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * GLYPH_WIDTH)) >> 1;\r
419 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (25 * GLYPH_HEIGHT)) >> 1;\r
420 MaxMode++;\r
421\r
422 //\r
423 // If it is possible to support Mode #1 - 80x50, than add it as an active mode\r
424 //\r
425 if (Rows >= 50) {\r
406adcd1 426 Private->ModeData[MaxMode].GopWidth = HorizontalResolution;\r
427 Private->ModeData[MaxMode].GopHeight = VerticalResolution;\r
428 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
878ddf1f 429 Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * GLYPH_WIDTH)) >> 1;\r
430 Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * GLYPH_HEIGHT)) >> 1;\r
431 MaxMode++;\r
432 }\r
433 //\r
434 // If the graphics mode is 800x600, than add a text mode that uses the entire display\r
435 //\r
436 if (HorizontalResolution == 800 && VerticalResolution == 600) {\r
437\r
438 if (MaxMode < 2) {\r
439 Private->ModeData[MaxMode].Columns = 0;\r
440 Private->ModeData[MaxMode].Rows = 0;\r
406adcd1 441 Private->ModeData[MaxMode].GopWidth = 800;\r
442 Private->ModeData[MaxMode].GopHeight = 600;\r
443 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
878ddf1f 444 Private->ModeData[MaxMode].DeltaX = 0;\r
445 Private->ModeData[MaxMode].DeltaY = 0;\r
446 MaxMode++;\r
447 }\r
448\r
449 Private->ModeData[MaxMode].Columns = 800 / GLYPH_WIDTH;\r
450 Private->ModeData[MaxMode].Rows = 600 / GLYPH_HEIGHT;\r
406adcd1 451 Private->ModeData[MaxMode].GopWidth = 800;\r
452 Private->ModeData[MaxMode].GopHeight = 600;\r
453 Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
878ddf1f 454 Private->ModeData[MaxMode].DeltaX = (800 % GLYPH_WIDTH) >> 1;\r
455 Private->ModeData[MaxMode].DeltaY = (600 % GLYPH_HEIGHT) >> 1;\r
456 MaxMode++;\r
457 }\r
458 //\r
459 // Update the maximum number of modes\r
460 //\r
461 Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;\r
462\r
463 //\r
464 // Determine the number of text modes that this protocol can support\r
465 //\r
466 Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
467 if (EFI_ERROR (Status)) {\r
468 goto Error;\r
469 }\r
470\r
2ce31132 471 DEBUG_CODE_BEGIN ();\r
878ddf1f 472 GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
2ce31132 473 DEBUG_CODE_END ();\r
878ddf1f 474\r
475 //\r
476 // Install protocol interfaces for the Graphics Console device.\r
477 //\r
478 Status = gBS->InstallMultipleProtocolInterfaces (\r
479 &Controller,\r
480 &gEfiSimpleTextOutProtocolGuid,\r
481 &Private->SimpleTextOutput,\r
482 NULL\r
483 );\r
484\r
485Error:\r
486 if (EFI_ERROR (Status)) {\r
487 //\r
406adcd1 488 // Close the GOP or UGA IO Protocol\r
878ddf1f 489 //\r
406adcd1 490 if (Private->GraphicsOutput != NULL) {\r
491 gBS->CloseProtocol (\r
492 Controller,\r
493 &gEfiGraphicsOutputProtocolGuid,\r
494 This->DriverBindingHandle,\r
495 Controller\r
496 );\r
497 } else {\r
498 gBS->CloseProtocol (\r
499 Controller,\r
500 &gEfiUgaDrawProtocolGuid,\r
501 This->DriverBindingHandle,\r
502 Controller\r
503 );\r
504 }\r
878ddf1f 505\r
506 //\r
507 // Free private data\r
508 //\r
509 if (Private != NULL) {\r
510 gBS->FreePool (Private->LineBuffer);\r
511 gBS->FreePool (Private);\r
512 }\r
513 }\r
514\r
515 return Status;\r
516}\r
517\r
518EFI_STATUS\r
519EFIAPI\r
520GraphicsConsoleControllerDriverStop (\r
521 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
522 IN EFI_HANDLE Controller,\r
523 IN UINTN NumberOfChildren,\r
524 IN EFI_HANDLE *ChildHandleBuffer\r
525 )\r
526{\r
527 EFI_STATUS Status;\r
528 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOutput;\r
529 GRAPHICS_CONSOLE_DEV *Private;\r
530\r
531 Status = gBS->OpenProtocol (\r
532 Controller,\r
533 &gEfiSimpleTextOutProtocolGuid,\r
534 (VOID **) &SimpleTextOutput,\r
535 This->DriverBindingHandle,\r
536 Controller,\r
537 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
538 );\r
539 if (EFI_ERROR (Status)) {\r
540 return EFI_NOT_STARTED;\r
541 }\r
542\r
543 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput);\r
544\r
545 Status = gBS->UninstallProtocolInterface (\r
546 Controller,\r
547 &gEfiSimpleTextOutProtocolGuid,\r
548 &Private->SimpleTextOutput\r
549 );\r
550\r
551 if (!EFI_ERROR (Status)) {\r
552 //\r
406adcd1 553 // Close the GOP or UGA IO Protocol\r
878ddf1f 554 //\r
406adcd1 555 if (Private->GraphicsOutput != NULL) {\r
556 gBS->CloseProtocol (\r
557 Controller,\r
558 &gEfiGraphicsOutputProtocolGuid,\r
559 This->DriverBindingHandle,\r
560 Controller\r
561 );\r
562 } else {\r
563 gBS->CloseProtocol (\r
564 Controller,\r
565 &gEfiUgaDrawProtocolGuid,\r
566 This->DriverBindingHandle,\r
567 Controller\r
568 );\r
569 }\r
878ddf1f 570\r
571 //\r
572 // Remove the font pack\r
573 //\r
574 mHii->RemovePack (mHii, Private->HiiHandle);\r
575\r
576 //\r
577 // Free our instance data\r
578 //\r
579 if (Private != NULL) {\r
580 gBS->FreePool (Private->LineBuffer);\r
581 gBS->FreePool (Private);\r
582 }\r
583 }\r
584\r
585 return Status;\r
586}\r
587\r
588EFI_STATUS\r
589EfiLocateHiiProtocol (\r
590 VOID\r
591 )\r
592/*++\r
593\r
594 Routine Description:\r
595 Find if the HII protocol is available. If yes, locate the HII protocol\r
596\r
597 Arguments:\r
598\r
599 Returns:\r
600\r
601--*/\r
602{\r
603 EFI_HANDLE Handle;\r
604 UINTN Size;\r
605 EFI_STATUS Status;\r
606\r
607 //\r
608 // There should only be one - so buffer size is this\r
609 //\r
610 Size = sizeof (EFI_HANDLE);\r
611\r
612 Status = gBS->LocateHandle (\r
613 ByProtocol,\r
614 &gEfiHiiProtocolGuid,\r
615 NULL,\r
616 &Size,\r
617 &Handle\r
618 );\r
619\r
620 if (EFI_ERROR (Status)) {\r
621 return Status;\r
622 }\r
623\r
624 Status = gBS->HandleProtocol (\r
625 Handle,\r
626 &gEfiHiiProtocolGuid,\r
627 (VOID **)&mHii\r
628 );\r
629\r
630 return Status;\r
631}\r
632//\r
633// Body of the STO functions\r
634//\r
635EFI_STATUS\r
636EFIAPI\r
637GraphicsConsoleConOutReset (\r
638 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
639 IN BOOLEAN ExtendedVerification\r
640 )\r
641/*++\r
642 Routine Description:\r
643 \r
644 Implements SIMPLE_TEXT_OUTPUT.Reset().\r
645 If ExtendeVerification is TRUE, then perform dependent Graphics Console \r
646 device reset, and set display mode to mode 0.\r
647 If ExtendedVerification is FALSE, only set display mode to mode 0.\r
648 \r
649 Arguments:\r
650 \r
651 This - Indicates the calling context.\r
652 \r
653 ExtendedVerification - Indicates that the driver may perform a more exhaustive\r
654 verification operation of the device during reset.\r
655 \r
656 Returns:\r
657 \r
658 EFI_SUCCESS\r
659 The reset operation succeeds. \r
660 \r
661 EFI_DEVICE_ERROR\r
662 The Graphics Console is not functioning correctly \r
663 \r
664--*/\r
665{\r
666 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
667 return This->SetMode (This, 0);\r
668}\r
669\r
670EFI_STATUS\r
671EFIAPI\r
672GraphicsConsoleConOutOutputString (\r
673 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
674 IN CHAR16 *WString\r
675 )\r
676/*++\r
677 Routine Description:\r
678 \r
679 Implements SIMPLE_TEXT_OUTPUT.OutputString().\r
680 The Unicode string will be converted to Glyphs and will be \r
681 sent to the Graphics Console.\r
682 \r
683 \r
684 Arguments:\r
685 \r
686 This - Indicates the calling context.\r
687 \r
688 WString - The Null-terminated Unicode string to be displayed on \r
689 the Graphics Console.\r
690 \r
691 Returns:\r
692 \r
693 EFI_SUCCESS\r
694 The string is output successfully. \r
695 \r
696 EFI_DEVICE_ERROR\r
697 The Graphics Console failed to send the string out.\r
698 \r
699 EFI_WARN_UNKNOWN_GLYPH\r
700 Indicates that some of the characters in the Unicode string could not \r
701 be rendered and are skipped. \r
702 \r
703--*/\r
704{\r
705 GRAPHICS_CONSOLE_DEV *Private;\r
406adcd1 706 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
878ddf1f 707 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
708 INTN Mode;\r
709 UINTN MaxColumn;\r
710 UINTN MaxRow;\r
711 UINTN Width;\r
712 UINTN Height;\r
713 UINTN Delta;\r
714 EFI_STATUS Status;\r
715 BOOLEAN Warning;\r
406adcd1 716 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
717 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
878ddf1f 718 UINTN DeltaX;\r
719 UINTN DeltaY;\r
720 UINTN Count;\r
721 UINTN Index;\r
722 INT32 OriginAttribute;\r
0fe0b10e 723 EFI_TPL OldTpl;\r
406adcd1 724 CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
878ddf1f 725\r
0fe0b10e 726 Status = EFI_SUCCESS;\r
727\r
728 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
878ddf1f 729 //\r
730 // Current mode\r
731 //\r
732 Mode = This->Mode->Mode;\r
733 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
406adcd1 734 GraphicsOutput = Private->GraphicsOutput;\r
878ddf1f 735 UgaDraw = Private->UgaDraw;\r
736\r
737 MaxColumn = Private->ModeData[Mode].Columns;\r
738 MaxRow = Private->ModeData[Mode].Rows;\r
739 DeltaX = Private->ModeData[Mode].DeltaX;\r
740 DeltaY = Private->ModeData[Mode].DeltaY;\r
741 Width = MaxColumn * GLYPH_WIDTH;\r
742 Height = (MaxRow - 1) * GLYPH_HEIGHT;\r
406adcd1 743 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
878ddf1f 744\r
745 //\r
746 // The Attributes won't change when during the time OutputString is called\r
747 //\r
748 GetTextColors (This, &Foreground, &Background);\r
749\r
750 EraseCursor (This);\r
751\r
752 Warning = FALSE;\r
753\r
754 //\r
755 // Backup attribute\r
756 //\r
757 OriginAttribute = This->Mode->Attribute;\r
758\r
759 while (*WString) {\r
760\r
761 if (*WString == CHAR_BACKSPACE) {\r
762 //\r
763 // If the cursor is at the left edge of the display, then move the cursor\r
764 // one row up.\r
765 //\r
766 if (This->Mode->CursorColumn == 0 && This->Mode->CursorRow > 0) {\r
767 This->Mode->CursorRow--;\r
768 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
769 This->OutputString (This, SpaceStr);\r
770 EraseCursor (This);\r
771 This->Mode->CursorRow--;\r
772 This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
773 } else if (This->Mode->CursorColumn > 0) {\r
774 //\r
775 // If the cursor is not at the left edge of the display, then move the cursor\r
776 // left one column.\r
777 //\r
778 This->Mode->CursorColumn--;\r
779 This->OutputString (This, SpaceStr);\r
780 EraseCursor (This);\r
781 This->Mode->CursorColumn--;\r
782 }\r
783\r
784 WString++;\r
785\r
786 } else if (*WString == CHAR_LINEFEED) {\r
787 //\r
788 // If the cursor is at the bottom of the display, then scroll the display one\r
789 // row, and do not update the cursor position. Otherwise, move the cursor\r
790 // down one row.\r
791 //\r
792 if (This->Mode->CursorRow == (INT32) (MaxRow - 1)) {\r
406adcd1 793 if (GraphicsOutput != NULL) {\r
794 //\r
795 // Scroll Screen Up One Row\r
796 //\r
797 GraphicsOutput->Blt (\r
798 GraphicsOutput,\r
799 NULL,\r
800 EfiBltVideoToVideo,\r
801 DeltaX,\r
802 DeltaY + GLYPH_HEIGHT,\r
803 DeltaX,\r
804 DeltaY,\r
805 Width,\r
806 Height,\r
807 Delta\r
808 );\r
878ddf1f 809\r
406adcd1 810 //\r
811 // Print Blank Line at last line\r
812 //\r
813 GraphicsOutput->Blt (\r
814 GraphicsOutput,\r
815 &Background,\r
816 EfiBltVideoFill,\r
817 0,\r
818 0,\r
819 DeltaX,\r
820 DeltaY + Height,\r
821 Width,\r
822 GLYPH_HEIGHT,\r
823 Delta\r
824 );\r
825 } else {\r
826 //\r
827 // Scroll Screen Up One Row\r
828 //\r
829 UgaDraw->Blt (\r
830 UgaDraw,\r
831 NULL,\r
832 EfiUgaVideoToVideo,\r
833 DeltaX,\r
834 DeltaY + GLYPH_HEIGHT,\r
835 DeltaX,\r
836 DeltaY,\r
837 Width,\r
838 Height,\r
839 Delta\r
840 );\r
878ddf1f 841\r
406adcd1 842 //\r
843 // Print Blank Line at last line\r
844 //\r
845 UgaDraw->Blt (\r
846 UgaDraw,\r
847 (EFI_UGA_PIXEL *) (UINTN) &Background,\r
848 EfiUgaVideoFill,\r
849 0,\r
850 0,\r
851 DeltaX,\r
852 DeltaY + Height,\r
853 Width,\r
854 GLYPH_HEIGHT,\r
855 Delta\r
856 );\r
857 }\r
878ddf1f 858 } else {\r
859 This->Mode->CursorRow++;\r
860 }\r
861\r
862 WString++;\r
863\r
864 } else if (*WString == CHAR_CARRIAGE_RETURN) {\r
865 //\r
866 // Move the cursor to the beginning of the current row.\r
867 //\r
868 This->Mode->CursorColumn = 0;\r
869 WString++;\r
870\r
871 } else if (*WString == WIDE_CHAR) {\r
872\r
873 This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;\r
874 WString++;\r
875\r
876 } else if (*WString == NARROW_CHAR) {\r
877\r
878 This->Mode->Attribute &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);\r
879 WString++;\r
880\r
881 } else {\r
882 //\r
883 // Print the character at the current cursor position and move the cursor\r
884 // right one column. If this moves the cursor past the right edge of the\r
885 // display, then the line should wrap to the beginning of the next line. This\r
886 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the\r
887 // bottom of the display, and the line wraps, then the display will be scrolled\r
888 // one line.\r
889 // If wide char is going to be displayed, need to display one character at a time\r
890 // Or, need to know the display length of a certain string.\r
891 //\r
892 // Index is used to determine how many character width units (wide = 2, narrow = 1)\r
893 // Count is used to determine how many characters are used regardless of their attributes\r
894 //\r
895 for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {\r
896 if (WString[Count] == CHAR_NULL) {\r
897 break;\r
898 }\r
899\r
900 if (WString[Count] == CHAR_BACKSPACE) {\r
901 break;\r
902 }\r
903\r
904 if (WString[Count] == CHAR_LINEFEED) {\r
905 break;\r
906 }\r
907\r
908 if (WString[Count] == CHAR_CARRIAGE_RETURN) {\r
909 break;\r
910 }\r
911\r
912 if (WString[Count] == WIDE_CHAR) {\r
913 break;\r
914 }\r
915\r
916 if (WString[Count] == NARROW_CHAR) {\r
917 break;\r
918 }\r
919 //\r
920 // Is the wide attribute on?\r
921 //\r
922 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {\r
923 //\r
924 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop\r
925 //\r
926 Index++;\r
927 //\r
928 // This is the end-case where if we are at column 79 and about to print a wide character\r
929 // We should prevent this from happening because we will wrap inappropriately. We should\r
930 // not print this character until the next line.\r
931 //\r
932 if ((This->Mode->CursorColumn + Index + 1) > MaxColumn) {\r
933 Index++;\r
934 break;\r
935 }\r
936 }\r
937 }\r
938\r
939 Status = DrawUnicodeWeightAtCursorN (This, WString, Count);\r
940 if (EFI_ERROR (Status)) {\r
941 Warning = TRUE;\r
942 }\r
943 //\r
944 // At the end of line, output carriage return and line feed\r
945 //\r
946 WString += Count;\r
947 This->Mode->CursorColumn += (INT32) Index;\r
948 if (This->Mode->CursorColumn > (INT32) MaxColumn) {\r
949 This->Mode->CursorColumn -= 2;\r
950 This->OutputString (This, SpaceStr);\r
951 }\r
952\r
953 if (This->Mode->CursorColumn >= (INT32) MaxColumn) {\r
954 EraseCursor (This);\r
955 This->OutputString (This, mCrLfString);\r
956 EraseCursor (This);\r
957 }\r
958 }\r
959 }\r
960\r
961 This->Mode->Attribute = OriginAttribute;\r
962\r
963 EraseCursor (This);\r
964\r
965 if (Warning) {\r
0fe0b10e 966 Status = EFI_WARN_UNKNOWN_GLYPH;\r
878ddf1f 967 }\r
968\r
0fe0b10e 969 gBS->RestoreTPL (OldTpl);\r
970 return Status;\r
971\r
878ddf1f 972}\r
973\r
974EFI_STATUS\r
975EFIAPI\r
976GraphicsConsoleConOutTestString (\r
977 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
978 IN CHAR16 *WString\r
979 )\r
980/*++\r
981 Routine Description:\r
982 \r
983 Implements SIMPLE_TEXT_OUTPUT.TestString().\r
984 If one of the characters in the *Wstring is\r
985 neither valid valid Unicode drawing characters,\r
986 not ASCII code, then this function will return\r
987 EFI_UNSUPPORTED.\r
988 \r
989 \r
990 Arguments:\r
991 \r
992 This - Indicates the calling context.\r
993 \r
994 WString - The Null-terminated Unicode string to be tested.\r
995 \r
996 Returns:\r
997 \r
998 EFI_SUCCESS\r
999 The Graphics Console is capable of rendering the output string. \r
1000 \r
1001 EFI_UNSUPPORTED\r
1002 Some of the characters in the Unicode string cannot be rendered. \r
1003 \r
1004--*/\r
1005{\r
1006 EFI_STATUS Status;\r
1007 UINT16 GlyphWidth;\r
1008 UINT32 GlyphStatus;\r
1009 UINT16 Count;\r
878ddf1f 1010 GLYPH_UNION *Glyph;\r
1011\r
878ddf1f 1012 GlyphStatus = 0;\r
1013 Count = 0;\r
1014\r
1015 while (WString[Count]) {\r
1016 Status = mHii->GetGlyph (\r
1017 mHii,\r
1018 WString,\r
1019 &Count,\r
1020 (UINT8 **) &Glyph,\r
1021 &GlyphWidth,\r
1022 &GlyphStatus\r
1023 );\r
1024\r
1025 if (EFI_ERROR (Status)) {\r
1026 return EFI_UNSUPPORTED;\r
1027 }\r
1028 }\r
1029\r
1030 return EFI_SUCCESS;\r
1031}\r
1032\r
1033EFI_STATUS\r
1034EFIAPI\r
1035GraphicsConsoleConOutQueryMode (\r
1036 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1037 IN UINTN ModeNumber,\r
1038 OUT UINTN *Columns,\r
1039 OUT UINTN *Rows\r
1040 )\r
1041/*++\r
1042 Routine Description:\r
1043 \r
1044 Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
1045 It returnes information for an available text mode\r
1046 that the Graphics Console supports.\r
1047 In this driver,we only support text mode 80x25, which is\r
1048 defined as mode 0.\r
1049 \r
1050 \r
1051 Arguments:\r
1052 \r
1053 This - Indicates the calling context.\r
1054 \r
1055 ModeNumber - The mode number to return information on.\r
1056 \r
1057 Columns - The returned columns of the requested mode.\r
1058 \r
1059 Rows - The returned rows of the requested mode. \r
1060 \r
1061 Returns:\r
1062 \r
1063 EFI_SUCCESS\r
1064 The requested mode information is returned. \r
1065 \r
1066 EFI_UNSUPPORTED\r
1067 The mode number is not valid. \r
1068 \r
1069--*/\r
1070{\r
1071 GRAPHICS_CONSOLE_DEV *Private;\r
0fe0b10e 1072 EFI_STATUS Status;\r
1073 EFI_TPL OldTpl;\r
878ddf1f 1074\r
1075 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
1076 return EFI_UNSUPPORTED;\r
1077 }\r
1078\r
0fe0b10e 1079 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
1080 Status = EFI_SUCCESS;\r
1081 \r
878ddf1f 1082 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1083\r
1084 *Columns = Private->ModeData[ModeNumber].Columns;\r
1085 *Rows = Private->ModeData[ModeNumber].Rows;\r
1086\r
1087 if (*Columns <= 0 && *Rows <= 0) {\r
0fe0b10e 1088 Status = EFI_UNSUPPORTED;\r
1089 goto Done;\r
878ddf1f 1090\r
1091 }\r
1092\r
0fe0b10e 1093Done:\r
1094 gBS->RestoreTPL (OldTpl);\r
1095 return Status;\r
878ddf1f 1096}\r
1097\r
1098EFI_STATUS\r
1099EFIAPI\r
1100GraphicsConsoleConOutSetMode (\r
1101 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1102 IN UINTN ModeNumber\r
1103 )\r
1104/*++\r
1105 Routine Description:\r
1106 \r
1107 Implements SIMPLE_TEXT_OUTPUT.SetMode().\r
1108 Set the Graphics Console to a specified mode.\r
1109 In this driver, we only support mode 0. \r
1110 \r
1111 Arguments:\r
1112 \r
1113 This - Indicates the calling context.\r
1114 \r
1115 ModeNumber - The text mode to set.\r
1116 \r
1117 Returns:\r
1118 \r
1119 EFI_SUCCESS\r
1120 The requested text mode is set.\r
1121 \r
1122 EFI_DEVICE_ERROR\r
1123 The requested text mode cannot be set because of Graphics Console device error.\r
1124 \r
1125 EFI_UNSUPPORTED\r
1126 The text mode number is not valid. \r
1127 \r
1128--*/\r
1129{\r
0fe0b10e 1130 EFI_STATUS Status;\r
1131 GRAPHICS_CONSOLE_DEV *Private;\r
1132 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
1133 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *NewLineBuffer;\r
1134 UINT32 HorizontalResolution;\r
1135 UINT32 VerticalResolution;\r
1136 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
1137 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
1138 UINT32 ColorDepth;\r
1139 UINT32 RefreshRate;\r
1140 EFI_TPL OldTpl;\r
1141\r
1142 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
878ddf1f 1143\r
1144 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
406adcd1 1145 GraphicsOutput = Private->GraphicsOutput;\r
878ddf1f 1146 UgaDraw = Private->UgaDraw;\r
1147 ModeData = &(Private->ModeData[ModeNumber]);\r
1148\r
e313deb9 1149 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
0fe0b10e 1150 Status = EFI_UNSUPPORTED;\r
1151 goto Done;\r
e313deb9 1152 }\r
1153\r
878ddf1f 1154 //\r
1155 // Make sure the requested mode number is supported\r
1156 //\r
1157 if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
0fe0b10e 1158 Status = EFI_UNSUPPORTED;\r
1159 goto Done;\r
878ddf1f 1160 }\r
1161\r
1162 if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
0fe0b10e 1163 Status = EFI_UNSUPPORTED;\r
1164 goto Done;\r
878ddf1f 1165 }\r
1166 //\r
1167 // Attempt to allocate a line buffer for the requested mode number\r
1168 //\r
1169 Status = gBS->AllocatePool (\r
1170 EfiBootServicesData,\r
406adcd1 1171 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * GLYPH_WIDTH * GLYPH_HEIGHT,\r
878ddf1f 1172 (VOID **) &NewLineBuffer\r
1173 );\r
1174 if (EFI_ERROR (Status)) {\r
1175 //\r
1176 // The new line buffer could not be allocated, so return an error.\r
1177 // No changes to the state of the current console have been made, so the current console is still valid\r
1178 //\r
0fe0b10e 1179 goto Done;\r
878ddf1f 1180 }\r
1181 //\r
1182 // If the mode has been set at least one other time, then LineBuffer will not be NULL\r
1183 //\r
1184 if (Private->LineBuffer != NULL) {\r
1185 //\r
1186 // Clear the current text window on the current graphics console\r
1187 //\r
1188 This->ClearScreen (This);\r
1189\r
1190 //\r
1191 // If the new mode is the same as the old mode, then just return EFI_SUCCESS\r
1192 //\r
1193 if ((INT32) ModeNumber == This->Mode->Mode) {\r
1194 gBS->FreePool (NewLineBuffer);\r
0fe0b10e 1195 Status = EFI_SUCCESS;\r
1196 goto Done;\r
878ddf1f 1197 }\r
1198 //\r
1199 // Otherwise, the size of the text console and/or the UGA mode will be changed,\r
1200 // so turn off the cursor, and free the LineBuffer for the current mode\r
1201 //\r
1202 This->EnableCursor (This, FALSE);\r
1203\r
1204 gBS->FreePool (Private->LineBuffer);\r
1205 }\r
1206 //\r
1207 // Assign the current line buffer to the newly allocated line buffer\r
1208 //\r
1209 Private->LineBuffer = NewLineBuffer;\r
1210\r
406adcd1 1211 if (GraphicsOutput != NULL) {\r
1212 if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) {\r
878ddf1f 1213 //\r
406adcd1 1214 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
878ddf1f 1215 //\r
406adcd1 1216 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber);\r
1217 if (EFI_ERROR (Status)) {\r
1218 //\r
1219 // The mode set operation failed\r
1220 //\r
0fe0b10e 1221 goto Done;\r
406adcd1 1222 }\r
1223 } else {\r
1224 //\r
1225 // The current graphics mode is correct, so simply clear the entire display\r
1226 //\r
1227 Status = GraphicsOutput->Blt (\r
1228 GraphicsOutput,\r
1229 &mEfiColors[0],\r
1230 EfiBltVideoFill,\r
1231 0,\r
1232 0,\r
1233 0,\r
1234 0,\r
1235 ModeData->GopWidth,\r
1236 ModeData->GopHeight,\r
1237 0\r
1238 );\r
878ddf1f 1239 }\r
1240 } else {\r
1241 //\r
406adcd1 1242 // Get the current UGA Draw mode information\r
878ddf1f 1243 //\r
406adcd1 1244 Status = UgaDraw->GetMode (\r
878ddf1f 1245 UgaDraw,\r
406adcd1 1246 &HorizontalResolution,\r
1247 &VerticalResolution,\r
1248 &ColorDepth,\r
1249 &RefreshRate\r
878ddf1f 1250 );\r
406adcd1 1251 if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {\r
1252 //\r
1253 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode\r
1254 //\r
1255 Status = UgaDraw->SetMode (\r
1256 UgaDraw,\r
1257 ModeData->GopWidth,\r
1258 ModeData->GopHeight,\r
1259 32,\r
1260 60\r
1261 );\r
1262 if (EFI_ERROR (Status)) {\r
1263 //\r
1264 // The mode set operation failed\r
1265 //\r
0fe0b10e 1266 goto Done;\r
406adcd1 1267 }\r
1268 } else {\r
1269 //\r
1270 // The current graphics mode is correct, so simply clear the entire display\r
1271 //\r
1272 Status = UgaDraw->Blt (\r
1273 UgaDraw,\r
1274 (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],\r
1275 EfiUgaVideoFill,\r
1276 0,\r
1277 0,\r
1278 0,\r
1279 0,\r
1280 ModeData->GopWidth,\r
1281 ModeData->GopHeight,\r
1282 0\r
1283 );\r
1284 }\r
878ddf1f 1285 }\r
406adcd1 1286\r
878ddf1f 1287 //\r
1288 // The new mode is valid, so commit the mode change\r
1289 //\r
1290 This->Mode->Mode = (INT32) ModeNumber;\r
1291\r
1292 //\r
1293 // Move the text cursor to the upper left hand corner of the displat and enable it\r
1294 //\r
1295 This->SetCursorPosition (This, 0, 0);\r
1296 This->EnableCursor (This, TRUE);\r
1297\r
0fe0b10e 1298 Status = EFI_SUCCESS;\r
1299\r
1300Done:\r
1301 gBS->RestoreTPL (OldTpl);\r
1302 return Status;\r
878ddf1f 1303}\r
1304\r
1305EFI_STATUS\r
1306EFIAPI\r
1307GraphicsConsoleConOutSetAttribute (\r
1308 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1309 IN UINTN Attribute\r
1310 )\r
1311/*++\r
1312 Routine Description:\r
1313 \r
1314 Implements SIMPLE_TEXT_OUTPUT.SetAttribute(). \r
1315 \r
1316 Arguments:\r
1317 \r
1318 This - Indicates the calling context.\r
1319 \r
1320 Attrubute - The attribute to set. Only bit0..6 are valid, all other bits\r
1321 are undefined and must be zero.\r
1322 \r
1323 Returns:\r
1324 \r
1325 EFI_SUCCESS\r
1326 The requested attribute is set. \r
1327 \r
1328 EFI_DEVICE_ERROR\r
1329 The requested attribute cannot be set due to Graphics Console port error.\r
1330 \r
1331 EFI_UNSUPPORTED\r
1332 The attribute requested is not defined by EFI spec. \r
1333 \r
1334--*/\r
1335{\r
0fe0b10e 1336 EFI_TPL OldTpl;\r
1337 \r
878ddf1f 1338 if ((Attribute | 0xFF) != 0xFF) {\r
1339 return EFI_UNSUPPORTED;\r
1340 }\r
1341\r
1342 if ((INT32) Attribute == This->Mode->Attribute) {\r
1343 return EFI_SUCCESS;\r
1344 }\r
1345\r
0fe0b10e 1346 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
1347\r
878ddf1f 1348 EraseCursor (This);\r
1349\r
1350 This->Mode->Attribute = (INT32) Attribute;\r
1351\r
1352 EraseCursor (This);\r
1353\r
0fe0b10e 1354 gBS->RestoreTPL (OldTpl);\r
1355\r
878ddf1f 1356 return EFI_SUCCESS;\r
1357}\r
1358\r
1359EFI_STATUS\r
1360EFIAPI\r
1361GraphicsConsoleConOutClearScreen (\r
1362 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This\r
1363 )\r
1364/*++\r
1365 Routine Description:\r
1366 \r
1367 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().\r
1368 It clears the Graphics Console's display to the \r
1369 currently selected background color.\r
1370 \r
1371 \r
1372 Arguments:\r
1373 \r
1374 This - Indicates the calling context.\r
1375\r
1376 Returns:\r
1377 \r
1378 EFI_SUCCESS\r
1379 The operation completed successfully.\r
1380 \r
1381 EFI_DEVICE_ERROR\r
1382 The Graphics Console cannot be cleared due to Graphics Console device error. \r
1383 \r
1384 EFI_UNSUPPORTED\r
1385 The Graphics Console is not in a valid text mode. \r
1386 \r
1387--*/\r
1388{\r
0fe0b10e 1389 EFI_STATUS Status;\r
1390 GRAPHICS_CONSOLE_DEV *Private;\r
1391 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
406adcd1 1392 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
0fe0b10e 1393 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
406adcd1 1394 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
1395 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
0fe0b10e 1396 EFI_TPL OldTpl;\r
1397\r
1398 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
878ddf1f 1399\r
1400 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
406adcd1 1401 GraphicsOutput = Private->GraphicsOutput;\r
878ddf1f 1402 UgaDraw = Private->UgaDraw;\r
1403 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1404\r
1405 GetTextColors (This, &Foreground, &Background);\r
406adcd1 1406 if (GraphicsOutput != NULL) {\r
1407 Status = GraphicsOutput->Blt (\r
1408 GraphicsOutput,\r
1409 &Background,\r
1410 EfiBltVideoFill,\r
1411 0,\r
1412 0,\r
1413 0,\r
1414 0,\r
1415 ModeData->GopWidth,\r
1416 ModeData->GopHeight,\r
1417 0\r
1418 );\r
1419 } else {\r
1420 Status = UgaDraw->Blt (\r
1421 UgaDraw,\r
1422 (EFI_UGA_PIXEL *) (UINTN) &Background,\r
1423 EfiUgaVideoFill,\r
1424 0,\r
1425 0,\r
1426 0,\r
1427 0,\r
1428 ModeData->GopWidth,\r
1429 ModeData->GopHeight,\r
1430 0\r
1431 );\r
1432 }\r
878ddf1f 1433\r
1434 This->Mode->CursorColumn = 0;\r
1435 This->Mode->CursorRow = 0;\r
1436\r
1437 EraseCursor (This);\r
1438\r
0fe0b10e 1439 gBS->RestoreTPL (OldTpl);\r
1440\r
878ddf1f 1441 return Status;\r
1442}\r
1443\r
1444EFI_STATUS\r
1445EFIAPI\r
1446GraphicsConsoleConOutSetCursorPosition (\r
1447 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1448 IN UINTN Column,\r
1449 IN UINTN Row\r
1450 )\r
1451/*++\r
1452 Routine Description:\r
1453 \r
1454 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition(). \r
1455 \r
1456 Arguments:\r
1457 \r
1458 This - Indicates the calling context.\r
1459 \r
1460 Column - The row to set cursor to.\r
1461 \r
1462 Row - The column to set cursor to. \r
1463\r
1464 Returns:\r
1465 \r
1466 EFI_SUCCESS\r
1467 The operation completed successfully.\r
1468 \r
1469 EFI_DEVICE_ERROR\r
1470 The request fails due to Graphics Console device error. \r
1471 \r
1472 EFI_UNSUPPORTED\r
1473 The Graphics Console is not in a valid text mode, or the cursor position\r
1474 is invalid for current mode. \r
1475 \r
1476--*/\r
1477{\r
1478 GRAPHICS_CONSOLE_DEV *Private;\r
1479 GRAPHICS_CONSOLE_MODE_DATA *ModeData;\r
0fe0b10e 1480 EFI_STATUS Status;\r
1481 EFI_TPL OldTpl;\r
1482\r
1483 Status = EFI_SUCCESS;\r
1484\r
1485 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
878ddf1f 1486\r
1487 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1488 ModeData = &(Private->ModeData[This->Mode->Mode]);\r
1489\r
1490 if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {\r
0fe0b10e 1491 Status = EFI_UNSUPPORTED;\r
1492 goto Done;\r
878ddf1f 1493 }\r
1494\r
1495 if (((INT32) Column == This->Mode->CursorColumn) && ((INT32) Row == This->Mode->CursorRow)) {\r
0fe0b10e 1496 Status = EFI_SUCCESS;\r
1497 goto Done;\r
878ddf1f 1498 }\r
1499\r
1500 EraseCursor (This);\r
1501\r
1502 This->Mode->CursorColumn = (INT32) Column;\r
1503 This->Mode->CursorRow = (INT32) Row;\r
1504\r
1505 EraseCursor (This);\r
1506\r
0fe0b10e 1507Done:\r
1508 gBS->RestoreTPL (OldTpl);\r
1509\r
1510 return Status;\r
878ddf1f 1511}\r
1512\r
1513EFI_STATUS\r
1514EFIAPI\r
1515GraphicsConsoleConOutEnableCursor (\r
1516 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1517 IN BOOLEAN Visible\r
1518 )\r
1519/*++\r
1520 Routine Description:\r
1521 \r
1522 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().\r
1523 In this driver, the cursor cannot be hidden. \r
1524 \r
1525 Arguments:\r
1526 \r
1527 This - Indicates the calling context.\r
1528 \r
1529 Visible - If TRUE, the cursor is set to be visible,\r
1530 If FALSE, the cursor is set to be invisible. \r
1531\r
1532 Returns:\r
1533 \r
1534 EFI_SUCCESS\r
1535 The request is valid.\r
1536 \r
1537 EFI_UNSUPPORTED\r
1538 The Graphics Console does not support a hidden cursor. \r
1539 \r
1540--*/\r
1541{\r
0fe0b10e 1542 EFI_TPL OldTpl;\r
1543 \r
1544 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
1545 \r
878ddf1f 1546 EraseCursor (This);\r
1547\r
1548 This->Mode->CursorVisible = Visible;\r
1549\r
1550 EraseCursor (This);\r
1551\r
0fe0b10e 1552 gBS->RestoreTPL (OldTpl);\r
878ddf1f 1553 return EFI_SUCCESS;\r
1554}\r
1555\r
92dda53e 1556STATIC\r
878ddf1f 1557EFI_STATUS\r
1558GetTextColors (\r
1559 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
406adcd1 1560 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
1561 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background\r
878ddf1f 1562 )\r
1563{\r
1564 INTN Attribute;\r
1565\r
1566 Attribute = This->Mode->Attribute & 0x7F;\r
1567\r
1568 *Foreground = mEfiColors[Attribute & 0x0f];\r
1569 *Background = mEfiColors[Attribute >> 4];\r
1570\r
1571 return EFI_SUCCESS;\r
1572}\r
1573\r
92dda53e 1574STATIC\r
878ddf1f 1575EFI_STATUS\r
1576DrawUnicodeWeightAtCursorN (\r
1577 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,\r
1578 IN CHAR16 *UnicodeWeight,\r
1579 IN UINTN Count\r
1580 )\r
1581{\r
1582 GRAPHICS_CONSOLE_DEV *Private;\r
1583 EFI_STATUS Status;\r
1584 EFI_STATUS ReturnStatus;\r
1585 GLYPH_UNION *Glyph;\r
1586 GLYPH_UNION GlyphData;\r
1587 INTN GlyphX;\r
1588 INTN GlyphY;\r
406adcd1 1589 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
878ddf1f 1590 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
406adcd1 1591 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
1592 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
878ddf1f 1593 UINTN Index;\r
1594 UINTN ArrayIndex;\r
1595 UINTN Counts;\r
1596 UINT16 GlyphWidth;\r
1597 UINT32 GlyphStatus;\r
1598\r
1599 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
1600\r
1601 ReturnStatus = EFI_SUCCESS;\r
1602 GlyphStatus = 0;\r
1603 GlyphWidth = 0x08;\r
1604\r
1605 GetTextColors (This, &Foreground, &Background);\r
1606\r
1607 Index = 0;\r
1608 ArrayIndex = 0;\r
1609 while (Index < Count) {\r
1610 if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {\r
1611 GlyphStatus = WIDE_CHAR;\r
1612 } else {\r
1613 GlyphStatus = NARROW_CHAR;\r
1614 }\r
1615\r
1616 Status = mHii->GetGlyph (\r
1617 mHii,\r
1618 UnicodeWeight,\r
1619 (UINT16 *) &Index,\r
1620 (UINT8 **) &Glyph,\r
1621 &GlyphWidth,\r
1622 &GlyphStatus\r
1623 );\r
1624 if (EFI_ERROR (Status)) {\r
1625 ReturnStatus = Status;\r
1626 }\r
1627\r
1628 Counts = 0;\r
1629\r
1630 CopyMem (&GlyphData, Glyph, sizeof (GLYPH_UNION));\r
1631\r
1632 do {\r
1633 //\r
1634 // We are creating the second half of the wide character's BLT buffer\r
1635 //\r
1636 if (GlyphWidth == 0x10 && Counts == 1) {\r
1637 CopyMem (&GlyphData.NarrowGlyph.GlyphCol1, &Glyph->WideGlyph.GlyphCol2, sizeof (Glyph->WideGlyph.GlyphCol2));\r
1638 }\r
1639\r
1640 Counts++;\r
1641\r
1642 if (GlyphWidth == 0x10) {\r
1643 mHii->GlyphToBlt (\r
1644 mHii,\r
1645 (UINT8 *) &GlyphData,\r
1646 Foreground,\r
1647 Background,\r
1648 Count * 2,\r
1649 GLYPH_WIDTH,\r
1650 GLYPH_HEIGHT,\r
1651 &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]\r
1652 );\r
1653 } else {\r
1654 mHii->GlyphToBlt (\r
1655 mHii,\r
1656 (UINT8 *) &GlyphData,\r
1657 Foreground,\r
1658 Background,\r
1659 Count,\r
1660 GLYPH_WIDTH,\r
1661 GLYPH_HEIGHT,\r
1662 &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]\r
1663 );\r
1664 }\r
1665\r
1666 ArrayIndex++;\r
1667\r
1668 } while (Counts < 2 && GlyphWidth == 0x10);\r
1669\r
1670 }\r
1671 //\r
1672 // If we are printing Wide characters, treat the BLT as if it is twice as many characters\r
1673 //\r
1674 if (GlyphWidth == 0x10) {\r
1675 Count = Count * 2;\r
1676 }\r
1677 //\r
1678 // Blt a character to the screen\r
1679 //\r
1680 GlyphX = This->Mode->CursorColumn * GLYPH_WIDTH;\r
1681 GlyphY = This->Mode->CursorRow * GLYPH_HEIGHT;\r
406adcd1 1682 GraphicsOutput = Private->GraphicsOutput;\r
878ddf1f 1683 UgaDraw = Private->UgaDraw;\r
406adcd1 1684 if (GraphicsOutput != NULL) {\r
1685 GraphicsOutput->Blt (\r
1686 GraphicsOutput,\r
1687 Private->LineBuffer,\r
1688 EfiBltBufferToVideo,\r
1689 0,\r
1690 0,\r
1691 GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,\r
1692 GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,\r
1693 GLYPH_WIDTH * Count,\r
1694 GLYPH_HEIGHT,\r
1695 GLYPH_WIDTH * Count * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
1696 );\r
1697 } else {\r
1698 UgaDraw->Blt (\r
1699 UgaDraw,\r
1700 (EFI_UGA_PIXEL *) (UINTN) Private->LineBuffer,\r
1701 EfiUgaBltBufferToVideo,\r
1702 0,\r
1703 0,\r
1704 GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,\r
1705 GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,\r
1706 GLYPH_WIDTH * Count,\r
1707 GLYPH_HEIGHT,\r
1708 GLYPH_WIDTH * Count * sizeof (EFI_UGA_PIXEL)\r
1709 );\r
1710 }\r
878ddf1f 1711\r
1712 return ReturnStatus;\r
1713}\r
1714\r
92dda53e 1715STATIC\r
878ddf1f 1716EFI_STATUS\r
1717EraseCursor (\r
1718 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This\r
1719 )\r
1720{\r
1721 GRAPHICS_CONSOLE_DEV *Private;\r
1722 EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode;\r
1723 INTN GlyphX;\r
1724 INTN GlyphY;\r
406adcd1 1725 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
878ddf1f 1726 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
406adcd1 1727 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;\r
1728 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;\r
1729 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[GLYPH_HEIGHT][GLYPH_WIDTH];\r
878ddf1f 1730 UINTN X;\r
1731 UINTN Y;\r
1732\r
1733 CurrentMode = This->Mode;\r
1734\r
1735 if (!CurrentMode->CursorVisible) {\r
1736 return EFI_SUCCESS;\r
1737 }\r
1738\r
1739 Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
406adcd1 1740 GraphicsOutput = Private->GraphicsOutput;\r
878ddf1f 1741 UgaDraw = Private->UgaDraw;\r
1742\r
1743 //\r
1744 // BUGBUG - we need to think about what to do with wide and narrow character deletions.\r
1745 //\r
1746 //\r
1747 // Blt a character to the screen\r
1748 //\r
1749 GlyphX = (CurrentMode->CursorColumn * GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;\r
1750 GlyphY = (CurrentMode->CursorRow * GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;\r
406adcd1 1751 if (GraphicsOutput != NULL) {\r
1752 GraphicsOutput->Blt (\r
1753 GraphicsOutput,\r
1754 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1755 EfiBltVideoToBltBuffer,\r
1756 GlyphX,\r
1757 GlyphY,\r
1758 0,\r
1759 0,\r
1760 GLYPH_WIDTH,\r
1761 GLYPH_HEIGHT,\r
1762 GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
1763 );\r
1764 } else {\r
1765 UgaDraw->Blt (\r
1766 UgaDraw,\r
1767 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1768 EfiUgaVideoToBltBuffer,\r
1769 GlyphX,\r
1770 GlyphY,\r
1771 0,\r
1772 0,\r
1773 GLYPH_WIDTH,\r
1774 GLYPH_HEIGHT,\r
1775 GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
1776 );\r
1777 }\r
878ddf1f 1778\r
1779 GetTextColors (This, &Foreground.Pixel, &Background.Pixel);\r
1780\r
1781 //\r
1782 // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
1783 //\r
1784 for (Y = 0; Y < GLYPH_HEIGHT; Y++) {\r
1785 for (X = 0; X < GLYPH_WIDTH; X++) {\r
1786 if ((mCursorGlyph.GlyphCol1[Y] & (1 << X)) != 0) {\r
1787 BltChar[Y][GLYPH_WIDTH - X - 1].Raw ^= Foreground.Raw;\r
1788 }\r
1789 }\r
1790 }\r
1791\r
406adcd1 1792 if (GraphicsOutput != NULL) {\r
1793 GraphicsOutput->Blt (\r
1794 GraphicsOutput,\r
1795 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
1796 EfiBltBufferToVideo,\r
1797 0,\r
1798 0,\r
1799 GlyphX,\r
1800 GlyphY,\r
1801 GLYPH_WIDTH,\r
1802 GLYPH_HEIGHT,\r
1803 GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
1804 );\r
1805 } else {\r
1806 UgaDraw->Blt (\r
1807 UgaDraw,\r
1808 (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
1809 EfiUgaBltBufferToVideo,\r
1810 0,\r
1811 0,\r
1812 GlyphX,\r
1813 GlyphY,\r
1814 GLYPH_WIDTH,\r
1815 GLYPH_HEIGHT,\r
1816 GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
1817 );\r
1818 }\r
878ddf1f 1819\r
1820 return EFI_SUCCESS;\r
1821}\r