3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _BIOS_GRAPHICS_OUTPUT_H_
10 #define _BIOS_GRAPHICS_OUTPUT_H_
12 #include <FrameworkDxe.h>
14 #include <Protocol/PciIo.h>
15 #include <Protocol/EdidActive.h>
16 #include <Protocol/DevicePath.h>
17 #include <Protocol/EdidDiscovered.h>
18 #include <Protocol/LegacyBios.h>
19 #include <Protocol/VgaMiniPort.h>
20 #include <Protocol/GraphicsOutput.h>
21 #include <Protocol/EdidOverride.h>
23 #include <Guid/StatusCodeDataTypeId.h>
24 #include <Guid/LegacyBios.h>
25 #include <Guid/EventGroup.h>
27 #include <Library/PcdLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/MemoryAllocationLib.h>
37 #include <IndustryStandard/Pci.h>
38 #include "VesaBiosExtensions.h"
41 // Packed format support: The number of bits reserved for each of the colors and the actual
42 // position of RGB in the frame buffer is specified in the VBE Mode information
45 UINT8 Position
; // Position of the color
46 UINT8 Mask
; // The number of bits expressed as a mask
47 } BIOS_VIDEO_COLOR_PLACEMENT
;
50 // BIOS Graphics Output Graphical Mode Data
54 UINT16 BytesPerScanLine
;
55 VOID
*LinearFrameBuffer
;
56 UINTN FrameBufferSize
;
57 UINT32 HorizontalResolution
;
58 UINT32 VerticalResolution
;
62 BIOS_VIDEO_COLOR_PLACEMENT Red
;
63 BIOS_VIDEO_COLOR_PLACEMENT Green
;
64 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
65 BIOS_VIDEO_COLOR_PLACEMENT Reserved
;
66 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
67 EFI_PIXEL_BITMASK PixelBitMask
;
68 } BIOS_VIDEO_MODE_DATA
;
71 // BIOS video child handle private data Structure
73 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
82 EFI_PCI_IO_PROTOCOL
*PciIo
;
83 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
88 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
89 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
90 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
91 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
96 BOOLEAN VgaCompatible
;
97 BOOLEAN ProduceGraphicsOutput
;
100 // Graphics Output Protocol related fields
102 BOOLEAN HardwareNeedsStarting
;
105 BIOS_VIDEO_MODE_DATA
*ModeData
;
107 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
108 UINT8
*VgaFrameBuffer
;
111 // VESA Bios Extensions related fields
113 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
114 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
115 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
116 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
117 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
118 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
119 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
120 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
124 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
126 EFI_EVENT ExitBootServicesEvent
;
129 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
130 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
131 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
133 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
138 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
139 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
140 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
143 // Driver Binding Protocol functions
149 @param This Pointer to driver binding protocol
150 @param Controller Controller handle to connect
151 @param RemainingDevicePath A pointer to the remaining portion of a device
154 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
155 driver, Otherwise, this controller cannot be
156 managed by this driver
161 BiosVideoDriverBindingSupported (
162 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
163 IN EFI_HANDLE Controller
,
164 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
169 Install Graphics Output Protocol onto VGA device handles.
171 @param This Pointer to driver binding protocol
172 @param Controller Controller handle to connect
173 @param RemainingDevicePath A pointer to the remaining portion of a device
181 BiosVideoDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
191 @param This Pointer to driver binding protocol
192 @param Controller Controller handle to connect
193 @param NumberOfChildren Number of children handle created by this driver
194 @param ChildHandleBuffer Buffer containing child handle created
196 @retval EFI_SUCCESS Driver disconnected successfully from controller
197 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
202 BiosVideoDriverBindingStop (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN UINTN NumberOfChildren
,
206 IN EFI_HANDLE
*ChildHandleBuffer
210 // Private worker functions
214 Check for VBE device.
216 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
218 @retval EFI_SUCCESS VBE device found
222 BiosVideoCheckForVbe (
223 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
228 Check for VGA device.
230 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
232 @retval EFI_SUCCESS Standard VGA device found
236 BiosVideoCheckForVga (
237 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
244 Release resource for biso video instance.
246 @param BiosVideoPrivate Video child device private data structure
250 BiosVideoDeviceReleaseResource (
251 BIOS_VIDEO_DEV
*BiosVideoPrivate
255 // BIOS Graphics Output Protocol functions
259 Graphics Output protocol interface to get video mode.
261 @param This Protocol instance pointer.
262 @param ModeNumber The mode number to return information on.
263 @param SizeOfInfo A pointer to the size, in bytes, of the Info
265 @param Info Caller allocated buffer that returns information
268 @retval EFI_SUCCESS Mode information returned.
269 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
270 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
272 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
273 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
278 BiosVideoGraphicsOutputQueryMode (
279 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
280 IN UINT32 ModeNumber
,
281 OUT UINTN
*SizeOfInfo
,
282 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
287 Graphics Output protocol interface to set video mode.
289 @param This Protocol instance pointer.
290 @param ModeNumber The mode number to be set.
292 @retval EFI_SUCCESS Graphics mode was changed.
293 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
295 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
300 BiosVideoGraphicsOutputSetMode (
301 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
307 Graphics Output protocol instance to block transfer for VBE device.
309 @param This Pointer to Graphics Output protocol instance
310 @param BltBuffer The data to transfer to screen
311 @param BltOperation The operation to perform
312 @param SourceX The X coordinate of the source for BltOperation
313 @param SourceY The Y coordinate of the source for BltOperation
314 @param DestinationX The X coordinate of the destination for
316 @param DestinationY The Y coordinate of the destination for
318 @param Width The width of a rectangle in the blt rectangle in
320 @param Height The height of a rectangle in the blt rectangle in
322 @param Delta Not used for EfiBltVideoFill and
323 EfiBltVideoToVideo operation. If a Delta of 0 is
324 used, the entire BltBuffer will be operated on. If
325 a subrectangle of the BltBuffer is used, then
326 Delta represents the number of bytes in a row of
329 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
330 @retval EFI_SUCCESS Blt operation success
335 BiosVideoGraphicsOutputVbeBlt (
336 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
337 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
338 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
341 IN UINTN DestinationX
,
342 IN UINTN DestinationY
,
350 Grahpics Output protocol instance to block transfer for VGA device.
352 @param This Pointer to Grahpics Output protocol instance
353 @param BltBuffer The data to transfer to screen
354 @param BltOperation The operation to perform
355 @param SourceX The X coordinate of the source for BltOperation
356 @param SourceY The Y coordinate of the source for BltOperation
357 @param DestinationX The X coordinate of the destination for
359 @param DestinationY The Y coordinate of the destination for
361 @param Width The width of a rectangle in the blt rectangle in
363 @param Height The height of a rectangle in the blt rectangle in
365 @param Delta Not used for EfiBltVideoFill and
366 EfiBltVideoToVideo operation. If a Delta of 0 is
367 used, the entire BltBuffer will be operated on. If
368 a subrectangle of the BltBuffer is used, then
369 Delta represents the number of bytes in a row of
372 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
373 @retval EFI_SUCCESS Blt operation success
378 BiosVideoGraphicsOutputVgaBlt (
379 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
380 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
381 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
384 IN UINTN DestinationX
,
385 IN UINTN DestinationY
,
392 // BIOS VGA Mini Port Protocol functions
396 VgaMiniPort protocol interface to set mode.
398 @param This Pointer to VgaMiniPort protocol instance
399 @param ModeNumber The index of the mode
401 @retval EFI_UNSUPPORTED The requested mode is not supported
402 @retval EFI_SUCCESS The requested mode is set successfully
407 BiosVideoVgaMiniPortSetMode (
408 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
413 Event handler for Exit Boot Service.
415 @param Event The event that be siganlled when exiting boot service.
416 @param Context Pointer to instance of BIOS_VIDEO_DEV.
421 BiosVideoNotifyExitBootServices (
427 // Standard VGA Definitions
429 #define VGA_HORIZONTAL_RESOLUTION 640
430 #define VGA_VERTICAL_RESOLUTION 480
431 #define VGA_NUMBER_OF_BIT_PLANES 4
432 #define VGA_PIXELS_PER_BYTE 8
433 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
434 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
436 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
437 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
439 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
441 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
443 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
445 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
446 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
447 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
448 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
449 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
451 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
453 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
454 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
455 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
456 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
457 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
458 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
459 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
461 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
463 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
465 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
468 Install child handles if the Handle supports MBR format.
470 @param This Calling context.
471 @param ParentHandle Parent Handle
472 @param ParentPciIo Parent PciIo interface
473 @param ParentLegacyBios Parent LegacyBios interface
474 @param ParentDevicePath Parent Device Path
475 @param RemainingDevicePath Remaining Device Path
477 @retval EFI_SUCCESS If a child handle was added
478 @retval other A child handle was not added
482 BiosVideoChildHandleInstall (
483 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
484 IN EFI_HANDLE ParentHandle
,
485 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
486 IN EFI_LEGACY_BIOS_PROTOCOL
*ParentLegacyBios
,
487 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
488 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
492 Deregister an video child handle and free resources.
494 @param This Protocol instance pointer.
495 @param Controller Video controller handle
496 @param Handle Video child handle
502 BiosVideoChildHandleUninstall (
503 EFI_DRIVER_BINDING_PROTOCOL
*This
,
504 EFI_HANDLE Controller
,
509 Release resource for biso video instance.
511 @param BiosVideoPrivate Video child device private data structure
515 BiosVideoDeviceReleaseResource (
516 BIOS_VIDEO_DEV
*BiosVideoPrivate
520 Check if all video child handles have been uninstalled.
522 @param Controller Video controller handle
524 @return TRUE Child handles exist.
525 @return FALSE All video child handles have been uninstalled.
530 IN EFI_HANDLE Controller