1 /** @file 2 Header file for GraphicsConsole driver. 3 4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #ifndef _GRAPHICS_CONSOLE_H_ 16 #define _GRAPHICS_CONSOLE_H_ 17 18 #include <Uefi.h> 19 #include <Protocol/SimpleTextOut.h> 20 #include <Protocol/GraphicsOutput.h> 21 #include <Protocol/UgaDraw.h> 22 #include <Protocol/DevicePath.h> 23 #include <Library/DebugLib.h> 24 #include <Library/UefiDriverEntryPoint.h> 25 #include <Library/UefiLib.h> 26 #include <Library/BaseMemoryLib.h> 27 #include <Library/MemoryAllocationLib.h> 28 #include <Library/UefiBootServicesTableLib.h> 29 #include <Library/HiiLib.h> 30 #include <Library/BaseLib.h> 31 #include <Library/PcdLib.h> 32 33 #include <Guid/MdeModuleHii.h> 34 35 #include <Protocol/HiiFont.h> 36 #include <Protocol/HiiDatabase.h> 37 38 39 extern EFI_COMPONENT_NAME_PROTOCOL gGraphicsConsoleComponentName; 40 extern EFI_COMPONENT_NAME2_PROTOCOL gGraphicsConsoleComponentName2; 41 extern EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding; 42 extern EFI_NARROW_GLYPH gUsStdNarrowGlyphData[]; 43 44 extern UINT32 mNarrowFontSize; 45 46 typedef union { 47 EFI_NARROW_GLYPH NarrowGlyph; 48 EFI_WIDE_GLYPH WideGlyph; 49 } GLYPH_UNION; 50 51 // 52 // Device Structure 53 // 54 #define GRAPHICS_CONSOLE_DEV_SIGNATURE SIGNATURE_32 ('g', 's', 't', 'o') 55 56 typedef struct { 57 UINTN Columns; 58 UINTN Rows; 59 INTN DeltaX; 60 INTN DeltaY; 61 UINT32 GopWidth; 62 UINT32 GopHeight; 63 UINT32 GopModeNumber; 64 } GRAPHICS_CONSOLE_MODE_DATA; 65 66 typedef struct { 67 UINTN Signature; 68 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; 69 EFI_UGA_DRAW_PROTOCOL *UgaDraw; 70 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput; 71 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode; 72 GRAPHICS_CONSOLE_MODE_DATA *ModeData; 73 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer; 74 } GRAPHICS_CONSOLE_DEV; 75 76 #define GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS(a) \ 77 CR (a, GRAPHICS_CONSOLE_DEV, SimpleTextOutput, GRAPHICS_CONSOLE_DEV_SIGNATURE) 78 79 80 // 81 // EFI Component Name Functions 82 // 83 /** 84 Retrieves a Unicode string that is the user readable name of the driver. 85 86 This function retrieves the user readable name of a driver in the form of a 87 Unicode string. If the driver specified by This has a user readable name in 88 the language specified by Language, then a pointer to the driver name is 89 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified 90 by This does not support the language specified by Language, 91 then EFI_UNSUPPORTED is returned. 92 93 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 94 EFI_COMPONENT_NAME_PROTOCOL instance. 95 96 @param Language[in] A pointer to a Null-terminated ASCII string 97 array indicating the language. This is the 98 language of the driver name that the caller is 99 requesting, and it must match one of the 100 languages specified in SupportedLanguages. The 101 number of languages supported by a driver is up 102 to the driver writer. Language is specified 103 in RFC 4646 or ISO 639-2 language code format. 104 105 @param DriverName[out] A pointer to the Unicode string to return. 106 This Unicode string is the name of the 107 driver specified by This in the language 108 specified by Language. 109 110 @retval EFI_SUCCESS The Unicode string for the Driver specified by 111 This and the language specified by Language was 112 returned in DriverName. 113 114 @retval EFI_INVALID_PARAMETER Language is NULL. 115 116 @retval EFI_INVALID_PARAMETER DriverName is NULL. 117 118 @retval EFI_UNSUPPORTED The driver specified by This does not support 119 the language specified by Language. 120 121 **/ 122 EFI_STATUS 123 EFIAPI 124 GraphicsConsoleComponentNameGetDriverName ( 125 IN EFI_COMPONENT_NAME_PROTOCOL *This, 126 IN CHAR8 *Language, 127 OUT CHAR16 **DriverName 128 ); 129 130 131 /** 132 Retrieves a Unicode string that is the user readable name of the controller 133 that is being managed by a driver. 134 135 This function retrieves the user readable name of the controller specified by 136 ControllerHandle and ChildHandle in the form of a Unicode string. If the 137 driver specified by This has a user readable name in the language specified by 138 Language, then a pointer to the controller name is returned in ControllerName, 139 and EFI_SUCCESS is returned. If the driver specified by This is not currently 140 managing the controller specified by ControllerHandle and ChildHandle, 141 then EFI_UNSUPPORTED is returned. If the driver specified by This does not 142 support the language specified by Language, then EFI_UNSUPPORTED is returned. 143 144 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or 145 EFI_COMPONENT_NAME_PROTOCOL instance. 146 147 @param ControllerHandle[in] The handle of a controller that the driver 148 specified by This is managing. This handle 149 specifies the controller whose name is to be 150 returned. 151 152 @param ChildHandle[in] The handle of the child controller to retrieve 153 the name of. This is an optional parameter that 154 may be NULL. It will be NULL for device 155 drivers. It will also be NULL for a bus drivers 156 that wish to retrieve the name of the bus 157 controller. It will not be NULL for a bus 158 driver that wishes to retrieve the name of a 159 child controller. 160 161 @param Language[in] A pointer to a Null-terminated ASCII string 162 array indicating the language. This is the 163 language of the driver name that the caller is 164 requesting, and it must match one of the 165 languages specified in SupportedLanguages. The 166 number of languages supported by a driver is up 167 to the driver writer. Language is specified in 168 RFC 4646 or ISO 639-2 language code format. 169 170 @param ControllerName[out] A pointer to the Unicode string to return. 171 This Unicode string is the name of the 172 controller specified by ControllerHandle and 173 ChildHandle in the language specified by 174 Language from the point of view of the driver 175 specified by This. 176 177 @retval EFI_SUCCESS The Unicode string for the user readable name in 178 the language specified by Language for the 179 driver specified by This was returned in 180 DriverName. 181 182 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 183 184 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 185 EFI_HANDLE. 186 187 @retval EFI_INVALID_PARAMETER Language is NULL. 188 189 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 190 191 @retval EFI_UNSUPPORTED The driver specified by This is not currently 192 managing the controller specified by 193 ControllerHandle and ChildHandle. 194 195 @retval EFI_UNSUPPORTED The driver specified by This does not support 196 the language specified by Language. 197 198 **/ 199 EFI_STATUS 200 EFIAPI 201 GraphicsConsoleComponentNameGetControllerName ( 202 IN EFI_COMPONENT_NAME_PROTOCOL *This, 203 IN EFI_HANDLE ControllerHandle, 204 IN EFI_HANDLE ChildHandle OPTIONAL, 205 IN CHAR8 *Language, 206 OUT CHAR16 **ControllerName 207 ); 208 209 210 /** 211 Reset the text output device hardware and optionally run diagnostics. 212 213 Implements SIMPLE_TEXT_OUTPUT.Reset(). 214 If ExtendeVerification is TRUE, then perform dependent Graphics Console 215 device reset, and set display mode to mode 0. 216 If ExtendedVerification is FALSE, only set display mode to mode 0. 217 218 @param This Protocol instance pointer. 219 @param ExtendedVerification Indicates that the driver may perform a more 220 exhaustive verification operation of the device 221 during reset. 222 223 @retval EFI_SUCCESS The text output device was reset. 224 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and 225 could not be reset. 226 227 **/ 228 EFI_STATUS 229 EFIAPI 230 GraphicsConsoleConOutReset ( 231 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 232 IN BOOLEAN ExtendedVerification 233 ); 234 235 /** 236 Write a Unicode string to the output device. 237 238 Implements SIMPLE_TEXT_OUTPUT.OutputString(). 239 The Unicode string will be converted to Glyphs and will be 240 sent to the Graphics Console. 241 242 @param This Protocol instance pointer. 243 @param WString The NULL-terminated Unicode string to be displayed 244 on the output device(s). All output devices must 245 also support the Unicode drawing defined in this file. 246 247 @retval EFI_SUCCESS The string was output to the device. 248 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output 249 the text. 250 @retval EFI_UNSUPPORTED The output device's mode is not currently in a 251 defined text mode. 252 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the 253 characters in the Unicode string could not be 254 rendered and were skipped. 255 256 **/ 257 EFI_STATUS 258 EFIAPI 259 GraphicsConsoleConOutOutputString ( 260 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 261 IN CHAR16 *WString 262 ); 263 264 /** 265 Verifies that all characters in a Unicode string can be output to the 266 target device. 267 268 Implements SIMPLE_TEXT_OUTPUT.TestString(). 269 If one of the characters in the *Wstring is neither valid valid Unicode 270 drawing characters, not ASCII code, then this function will return 271 EFI_UNSUPPORTED 272 273 @param This Protocol instance pointer. 274 @param WString The NULL-terminated Unicode string to be examined for the output 275 device(s). 276 277 @retval EFI_SUCCESS The device(s) are capable of rendering the output string. 278 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be 279 rendered by one or more of the output devices mapped 280 by the EFI handle. 281 282 **/ 283 EFI_STATUS 284 EFIAPI 285 GraphicsConsoleConOutTestString ( 286 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 287 IN CHAR16 *WString 288 ); 289 290 /** 291 Returns information for an available text mode that the output device(s) 292 supports 293 294 Implements SIMPLE_TEXT_OUTPUT.QueryMode(). 295 It returnes information for an available text mode that the Graphics Console supports. 296 In this driver,we only support text mode 80x25, which is defined as mode 0. 297 298 @param This Protocol instance pointer. 299 @param ModeNumber The mode number to return information on. 300 @param Columns The returned columns of the requested mode. 301 @param Rows The returned rows of the requested mode. 302 303 @retval EFI_SUCCESS The requested mode information is returned. 304 @retval EFI_UNSUPPORTED The mode number is not valid. 305 306 **/ 307 EFI_STATUS 308 EFIAPI 309 GraphicsConsoleConOutQueryMode ( 310 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 311 IN UINTN ModeNumber, 312 OUT UINTN *Columns, 313 OUT UINTN *Rows 314 ); 315 316 317 /** 318 Sets the output device(s) to a specified mode. 319 320 Implements SIMPLE_TEXT_OUTPUT.SetMode(). 321 Set the Graphics Console to a specified mode. In this driver, we only support mode 0. 322 323 @param This Protocol instance pointer. 324 @param ModeNumber The text mode to set. 325 326 @retval EFI_SUCCESS The requested text mode is set. 327 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of 328 Graphics Console device error. 329 @retval EFI_UNSUPPORTED The text mode number is not valid. 330 331 **/ 332 EFI_STATUS 333 EFIAPI 334 GraphicsConsoleConOutSetMode ( 335 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 336 IN UINTN ModeNumber 337 ); 338 339 /** 340 Sets the background and foreground colors for the OutputString () and 341 ClearScreen () functions. 342 343 Implements SIMPLE_TEXT_OUTPUT.SetAttribute(). 344 345 @param This Protocol instance pointer. 346 @param Attribute The attribute to set. Bits 0..3 are the foreground 347 color, and bits 4..6 are the background color. 348 All other bits are undefined and must be zero. 349 350 @retval EFI_SUCCESS The requested attribute is set. 351 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error. 352 @retval EFI_UNSUPPORTED The attribute requested is not defined. 353 354 **/ 355 EFI_STATUS 356 EFIAPI 357 GraphicsConsoleConOutSetAttribute ( 358 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 359 IN UINTN Attribute 360 ); 361 362 /** 363 Clears the output device(s) display to the currently selected background 364 color. 365 366 Implements SIMPLE_TEXT_OUTPUT.ClearScreen(). 367 368 @param This Protocol instance pointer. 369 370 @retval EFI_SUCCESS The operation completed successfully. 371 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request. 372 @retval EFI_UNSUPPORTED The output device is not in a valid text mode. 373 374 **/ 375 EFI_STATUS 376 EFIAPI 377 GraphicsConsoleConOutClearScreen ( 378 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This 379 ); 380 381 /** 382 Sets the current coordinates of the cursor position. 383 384 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition(). 385 386 @param This Protocol instance pointer. 387 @param Column The position to set the cursor to. Must be greater than or 388 equal to zero and less than the number of columns and rows 389 by QueryMode (). 390 @param Row The position to set the cursor to. Must be greater than or 391 equal to zero and less than the number of columns and rows 392 by QueryMode (). 393 394 @retval EFI_SUCCESS The operation completed successfully. 395 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request. 396 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the 397 cursor position is invalid for the current mode. 398 399 **/ 400 EFI_STATUS 401 EFIAPI 402 GraphicsConsoleConOutSetCursorPosition ( 403 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 404 IN UINTN Column, 405 IN UINTN Row 406 ); 407 408 409 /** 410 Makes the cursor visible or invisible. 411 412 Implements SIMPLE_TEXT_OUTPUT.EnableCursor(). 413 414 @param This Protocol instance pointer. 415 @param Visible If TRUE, the cursor is set to be visible, If FALSE, 416 the cursor is set to be invisible. 417 418 @retval EFI_SUCCESS The operation completed successfully. 419 420 **/ 421 EFI_STATUS 422 EFIAPI 423 GraphicsConsoleConOutEnableCursor ( 424 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 425 IN BOOLEAN Visible 426 ); 427 428 /** 429 Test to see if Graphics Console could be supported on the Controller. 430 431 Graphics Console could be supported if Graphics Output Protocol or UGA Draw 432 Protocol exists on the Controller. (UGA Draw Protocol could be skipped 433 if PcdUgaConsumeSupport is set to FALSE.) 434 435 @param This Protocol instance pointer. 436 @param Controller Handle of device to test. 437 @param RemainingDevicePath Optional parameter use to pick a specific child 438 device to start. 439 440 @retval EFI_SUCCESS This driver supports this device. 441 @retval other This driver does not support this device. 442 443 **/ 444 EFI_STATUS 445 EFIAPI 446 GraphicsConsoleControllerDriverSupported ( 447 IN EFI_DRIVER_BINDING_PROTOCOL *This, 448 IN EFI_HANDLE Controller, 449 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 450 ); 451 452 453 /** 454 Start this driver on Controller by opening Graphics Output protocol or 455 UGA Draw protocol, and installing Simple Text Out protocol on Controller. 456 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.) 457 458 @param This Protocol instance pointer. 459 @param Controller Handle of device to bind driver to 460 @param RemainingDevicePath Optional parameter use to pick a specific child 461 device to start. 462 463 @retval EFI_SUCCESS This driver is added to Controller. 464 @retval other This driver does not support this device. 465 466 **/ 467 EFI_STATUS 468 EFIAPI 469 GraphicsConsoleControllerDriverStart ( 470 IN EFI_DRIVER_BINDING_PROTOCOL *This, 471 IN EFI_HANDLE Controller, 472 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 473 ); 474 475 /** 476 Stop this driver on Controller by removing Simple Text Out protocol 477 and closing the Graphics Output Protocol or UGA Draw protocol on Controller. 478 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.) 479 480 481 @param This Protocol instance pointer. 482 @param Controller Handle of device to stop driver on 483 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of 484 children is zero stop the entire bus driver. 485 @param ChildHandleBuffer List of Child Handles to Stop. 486 487 @retval EFI_SUCCESS This driver is removed Controller. 488 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the 489 Controller. 490 @retval other This driver was not removed from this device. 491 492 **/ 493 EFI_STATUS 494 EFIAPI 495 GraphicsConsoleControllerDriverStop ( 496 IN EFI_DRIVER_BINDING_PROTOCOL *This, 497 IN EFI_HANDLE Controller, 498 IN UINTN NumberOfChildren, 499 IN EFI_HANDLE *ChildHandleBuffer 500 ); 501 502 503 /** 504 Locate HII Database protocol and HII Font protocol. 505 506 @retval EFI_SUCCESS HII Database protocol and HII Font protocol 507 are located successfully. 508 @return other Failed to locate HII Database protocol or 509 HII Font protocol. 510 511 **/ 512 EFI_STATUS 513 EfiLocateHiiProtocol ( 514 VOID 515 ); 516 517 518 /** 519 Gets Graphics Console devcie's foreground color and background color. 520 521 @param This Protocol instance pointer. 522 @param Foreground Returned text foreground color. 523 @param Background Returned text background color. 524 525 @retval EFI_SUCCESS It returned always. 526 527 **/ 528 EFI_STATUS 529 GetTextColors ( 530 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 531 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground, 532 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background 533 ); 534 535 /** 536 Draw Unicode string on the Graphics Console device's screen. 537 538 @param This Protocol instance pointer. 539 @param UnicodeWeight One Unicode string to be displayed. 540 @param Count The count of Unicode string. 541 542 @retval EFI_OUT_OF_RESOURCES If no memory resource to use. 543 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw 544 protocol exist. 545 @retval EFI_SUCCESS Drawing Unicode string implemented successfully. 546 547 **/ 548 EFI_STATUS 549 DrawUnicodeWeightAtCursorN ( 550 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 551 IN CHAR16 *UnicodeWeight, 552 IN UINTN Count 553 ); 554 555 /** 556 Flush the cursor on the screen. 557 558 If CursorVisible is FALSE, nothing to do and return directly. 559 If CursorVisible is TRUE, 560 i) If the cursor shows on screen, it will be erased. 561 ii) If the cursor does not show on screen, it will be shown. 562 563 @param This Protocol instance pointer. 564 565 @retval EFI_SUCCESS The cursor is erased successfully. 566 567 **/ 568 EFI_STATUS 569 FlushCursor ( 570 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This 571 ); 572 573 /** 574 Check if the current specific mode supported the user defined resolution 575 for the Graphics Console device based on Graphics Output Protocol. 576 577 If yes, set the graphic device's current mode to this specific mode. 578 579 @param GraphicsOutput Graphics Output Protocol instance pointer. 580 @param HorizontalResolution User defined horizontal resolution 581 @param VerticalResolution User defined vertical resolution. 582 @param CurrentModeNumber Current specific mode to be check. 583 584 @retval EFI_SUCCESS The mode is supported. 585 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics 586 device supported. 587 @retval other The specific mode does not support user defined 588 resolution or failed to set the current mode to the 589 specific mode on graphics device. 590 591 **/ 592 EFI_STATUS 593 CheckModeSupported ( 594 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput, 595 IN UINT32 HorizontalResolution, 596 IN UINT32 VerticalResolution, 597 OUT UINT32 *CurrentModeNumber 598 ); 599 600 #endif 601