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
168 Install Graphics Output Protocol onto VGA device handles.
170 @param This Pointer to driver binding protocol
171 @param Controller Controller handle to connect
172 @param RemainingDevicePath A pointer to the remaining portion of a device
180 BiosVideoDriverBindingStart (
181 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
182 IN EFI_HANDLE Controller
,
183 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
189 @param This Pointer to driver binding protocol
190 @param Controller Controller handle to connect
191 @param NumberOfChildren Number of children handle created by this driver
192 @param ChildHandleBuffer Buffer containing child handle created
194 @retval EFI_SUCCESS Driver disconnected successfully from controller
195 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
200 BiosVideoDriverBindingStop (
201 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
202 IN EFI_HANDLE Controller
,
203 IN UINTN NumberOfChildren
,
204 IN EFI_HANDLE
*ChildHandleBuffer
208 // Private worker functions
212 Check for VBE device.
214 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
216 @retval EFI_SUCCESS VBE device found
220 BiosVideoCheckForVbe (
221 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
225 Check for VGA device.
227 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
229 @retval EFI_SUCCESS Standard VGA device found
233 BiosVideoCheckForVga (
234 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
238 Release resource for BIOS video instance.
240 @param BiosVideoPrivate Video child device private data structure
244 BiosVideoDeviceReleaseResource (
245 BIOS_VIDEO_DEV
*BiosVideoPrivate
249 // BIOS Graphics Output Protocol functions
253 Graphics Output protocol interface to get video mode.
255 @param This Protocol instance pointer.
256 @param ModeNumber The mode number to return information on.
257 @param SizeOfInfo A pointer to the size, in bytes, of the Info
259 @param Info Caller allocated buffer that returns information
262 @retval EFI_SUCCESS Mode information returned.
263 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
264 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
266 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
267 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
272 BiosVideoGraphicsOutputQueryMode (
273 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
274 IN UINT32 ModeNumber
,
275 OUT UINTN
*SizeOfInfo
,
276 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
280 Graphics Output protocol interface to set video mode.
282 @param This Protocol instance pointer.
283 @param ModeNumber The mode number to be set.
285 @retval EFI_SUCCESS Graphics mode was changed.
286 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
288 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
293 BiosVideoGraphicsOutputSetMode (
294 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
299 Graphics Output protocol instance to block transfer for VBE device.
301 @param This Pointer to Graphics Output protocol instance
302 @param BltBuffer The data to transfer to screen
303 @param BltOperation The operation to perform
304 @param SourceX The X coordinate of the source for BltOperation
305 @param SourceY The Y coordinate of the source for BltOperation
306 @param DestinationX The X coordinate of the destination for
308 @param DestinationY The Y coordinate of the destination for
310 @param Width The width of a rectangle in the blt rectangle in
312 @param Height The height of a rectangle in the blt rectangle in
314 @param Delta Not used for EfiBltVideoFill and
315 EfiBltVideoToVideo operation. If a Delta of 0 is
316 used, the entire BltBuffer will be operated on. If
317 a subrectangle of the BltBuffer is used, then
318 Delta represents the number of bytes in a row of
321 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
322 @retval EFI_SUCCESS Blt operation success
327 BiosVideoGraphicsOutputVbeBlt (
328 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
329 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
330 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
333 IN UINTN DestinationX
,
334 IN UINTN DestinationY
,
341 Graphics Output protocol instance to block transfer for VGA device.
343 @param This Pointer to Graphics Output protocol instance
344 @param BltBuffer The data to transfer to screen
345 @param BltOperation The operation to perform
346 @param SourceX The X coordinate of the source for BltOperation
347 @param SourceY The Y coordinate of the source for BltOperation
348 @param DestinationX The X coordinate of the destination for
350 @param DestinationY The Y coordinate of the destination for
352 @param Width The width of a rectangle in the blt rectangle in
354 @param Height The height of a rectangle in the blt rectangle in
356 @param Delta Not used for EfiBltVideoFill and
357 EfiBltVideoToVideo operation. If a Delta of 0 is
358 used, the entire BltBuffer will be operated on. If
359 a subrectangle of the BltBuffer is used, then
360 Delta represents the number of bytes in a row of
363 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
364 @retval EFI_SUCCESS Blt operation success
369 BiosVideoGraphicsOutputVgaBlt (
370 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
371 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
372 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
375 IN UINTN DestinationX
,
376 IN UINTN DestinationY
,
383 // BIOS VGA Mini Port Protocol functions
387 VgaMiniPort protocol interface to set mode.
389 @param This Pointer to VgaMiniPort protocol instance
390 @param ModeNumber The index of the mode
392 @retval EFI_UNSUPPORTED The requested mode is not supported
393 @retval EFI_SUCCESS The requested mode is set successfully
398 BiosVideoVgaMiniPortSetMode (
399 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
404 Event handler for Exit Boot Service.
406 @param Event The event that be signalled when exiting boot service.
407 @param Context Pointer to instance of BIOS_VIDEO_DEV.
412 BiosVideoNotifyExitBootServices (
418 // Standard VGA Definitions
420 #define VGA_HORIZONTAL_RESOLUTION 640
421 #define VGA_VERTICAL_RESOLUTION 480
422 #define VGA_NUMBER_OF_BIT_PLANES 4
423 #define VGA_PIXELS_PER_BYTE 8
424 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
425 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
427 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
428 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
430 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
432 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
434 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
436 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
437 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
438 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
439 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
440 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
442 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
444 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
445 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
446 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
447 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
448 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
449 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
450 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
452 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
454 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
456 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
459 Install child handles if the Handle supports MBR format.
461 @param This Calling context.
462 @param ParentHandle Parent Handle
463 @param ParentPciIo Parent PciIo interface
464 @param ParentLegacyBios Parent LegacyBios interface
465 @param ParentDevicePath Parent Device Path
466 @param RemainingDevicePath Remaining Device Path
468 @retval EFI_SUCCESS If a child handle was added
469 @retval other A child handle was not added
473 BiosVideoChildHandleInstall (
474 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
475 IN EFI_HANDLE ParentHandle
,
476 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
477 IN EFI_LEGACY_BIOS_PROTOCOL
*ParentLegacyBios
,
478 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
479 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
483 Deregister an video child handle and free resources.
485 @param This Protocol instance pointer.
486 @param Controller Video controller handle
487 @param Handle Video child handle
493 BiosVideoChildHandleUninstall (
494 EFI_DRIVER_BINDING_PROTOCOL
*This
,
495 EFI_HANDLE Controller
,
500 Release resource for BIOS video instance.
502 @param BiosVideoPrivate Video child device private data structure
506 BiosVideoDeviceReleaseResource (
507 BIOS_VIDEO_DEV
*BiosVideoPrivate
511 Check if all video child handles have been uninstalled.
513 @param Controller Video controller handle
515 @return TRUE Child handles exist.
516 @return FALSE All video child handles have been uninstalled.
521 IN EFI_HANDLE Controller