3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The
8 full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _BIOS_GRAPHICS_OUTPUT_H_
17 #define _BIOS_GRAPHICS_OUTPUT_H_
19 #include <FrameworkDxe.h>
21 #include <Protocol/PciIo.h>
22 #include <Protocol/EdidActive.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/EdidDiscovered.h>
25 #include <Protocol/LegacyBios.h>
26 #include <Protocol/VgaMiniPort.h>
27 #include <Protocol/GraphicsOutput.h>
28 #include <Protocol/EdidOverride.h>
30 #include <Guid/StatusCodeDataTypeId.h>
31 #include <Guid/LegacyBios.h>
32 #include <Guid/EventGroup.h>
34 #include <Library/PcdLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/ReportStatusCodeLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/UefiLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/MemoryAllocationLib.h>
44 #include <IndustryStandard/Pci.h>
45 #include "VesaBiosExtensions.h"
48 // Packed format support: The number of bits reserved for each of the colors and the actual
49 // position of RGB in the frame buffer is specified in the VBE Mode information
52 UINT8 Position
; // Position of the color
53 UINT8 Mask
; // The number of bits expressed as a mask
54 } BIOS_VIDEO_COLOR_PLACEMENT
;
57 // BIOS Graphics Output Graphical Mode Data
61 UINT16 BytesPerScanLine
;
62 VOID
*LinearFrameBuffer
;
63 UINTN FrameBufferSize
;
64 UINT32 HorizontalResolution
;
65 UINT32 VerticalResolution
;
69 BIOS_VIDEO_COLOR_PLACEMENT Red
;
70 BIOS_VIDEO_COLOR_PLACEMENT Green
;
71 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
72 BIOS_VIDEO_COLOR_PLACEMENT Reserved
;
73 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
74 EFI_PIXEL_BITMASK PixelBitMask
;
75 } BIOS_VIDEO_MODE_DATA
;
78 // BIOS video child handle private data Structure
80 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
89 EFI_PCI_IO_PROTOCOL
*PciIo
;
90 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
95 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
96 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
97 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
98 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
103 BOOLEAN VgaCompatible
;
104 BOOLEAN ProduceGraphicsOutput
;
107 // Graphics Output Protocol related fields
109 BOOLEAN HardwareNeedsStarting
;
112 BIOS_VIDEO_MODE_DATA
*ModeData
;
114 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
115 UINT8
*VgaFrameBuffer
;
118 // VESA Bios Extensions related fields
120 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
121 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
122 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
123 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
124 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
125 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
126 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
127 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
131 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
133 EFI_EVENT ExitBootServicesEvent
;
136 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
137 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
138 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
140 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
145 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
146 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
147 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
150 // Driver Binding Protocol functions
156 @param This Pointer to driver binding protocol
157 @param Controller Controller handle to connect
158 @param RemainingDevicePath A pointer to the remaining portion of a device
161 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
162 driver, Otherwise, this controller cannot be
163 managed by this driver
168 BiosVideoDriverBindingSupported (
169 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
170 IN EFI_HANDLE Controller
,
171 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
176 Install Graphics Output Protocol onto VGA device handles.
178 @param This Pointer to driver binding protocol
179 @param Controller Controller handle to connect
180 @param RemainingDevicePath A pointer to the remaining portion of a device
188 BiosVideoDriverBindingStart (
189 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
190 IN EFI_HANDLE Controller
,
191 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
198 @param This Pointer to driver binding protocol
199 @param Controller Controller handle to connect
200 @param NumberOfChildren Number of children handle created by this driver
201 @param ChildHandleBuffer Buffer containing child handle created
203 @retval EFI_SUCCESS Driver disconnected successfully from controller
204 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
209 BiosVideoDriverBindingStop (
210 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
211 IN EFI_HANDLE Controller
,
212 IN UINTN NumberOfChildren
,
213 IN EFI_HANDLE
*ChildHandleBuffer
217 // Private worker functions
221 Check for VBE device.
223 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
225 @retval EFI_SUCCESS VBE device found
229 BiosVideoCheckForVbe (
230 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
235 Check for VGA device.
237 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
239 @retval EFI_SUCCESS Standard VGA device found
243 BiosVideoCheckForVga (
244 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
251 Release resource for biso video instance.
253 @param BiosVideoPrivate Video child device private data structure
257 BiosVideoDeviceReleaseResource (
258 BIOS_VIDEO_DEV
*BiosVideoPrivate
262 // BIOS Graphics Output Protocol functions
266 Graphics Output protocol interface to get video mode.
268 @param This Protocol instance pointer.
269 @param ModeNumber The mode number to return information on.
270 @param SizeOfInfo A pointer to the size, in bytes, of the Info
272 @param Info Caller allocated buffer that returns information
275 @retval EFI_SUCCESS Mode information returned.
276 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
277 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
279 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
280 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
285 BiosVideoGraphicsOutputQueryMode (
286 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
287 IN UINT32 ModeNumber
,
288 OUT UINTN
*SizeOfInfo
,
289 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
294 Graphics Output protocol interface to set video mode.
296 @param This Protocol instance pointer.
297 @param ModeNumber The mode number to be set.
299 @retval EFI_SUCCESS Graphics mode was changed.
300 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
302 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
307 BiosVideoGraphicsOutputSetMode (
308 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
314 Graphics Output protocol instance to block transfer for VBE device.
316 @param This Pointer to Graphics Output protocol instance
317 @param BltBuffer The data to transfer to screen
318 @param BltOperation The operation to perform
319 @param SourceX The X coordinate of the source for BltOperation
320 @param SourceY The Y coordinate of the source for BltOperation
321 @param DestinationX The X coordinate of the destination for
323 @param DestinationY The Y coordinate of the destination for
325 @param Width The width of a rectangle in the blt rectangle in
327 @param Height The height of a rectangle in the blt rectangle in
329 @param Delta Not used for EfiBltVideoFill and
330 EfiBltVideoToVideo operation. If a Delta of 0 is
331 used, the entire BltBuffer will be operated on. If
332 a subrectangle of the BltBuffer is used, then
333 Delta represents the number of bytes in a row of
336 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
337 @retval EFI_SUCCESS Blt operation success
342 BiosVideoGraphicsOutputVbeBlt (
343 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
344 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
345 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
348 IN UINTN DestinationX
,
349 IN UINTN DestinationY
,
357 Grahpics Output protocol instance to block transfer for VGA device.
359 @param This Pointer to Grahpics Output protocol instance
360 @param BltBuffer The data to transfer to screen
361 @param BltOperation The operation to perform
362 @param SourceX The X coordinate of the source for BltOperation
363 @param SourceY The Y coordinate of the source for BltOperation
364 @param DestinationX The X coordinate of the destination for
366 @param DestinationY The Y coordinate of the destination for
368 @param Width The width of a rectangle in the blt rectangle in
370 @param Height The height of a rectangle in the blt rectangle in
372 @param Delta Not used for EfiBltVideoFill and
373 EfiBltVideoToVideo operation. If a Delta of 0 is
374 used, the entire BltBuffer will be operated on. If
375 a subrectangle of the BltBuffer is used, then
376 Delta represents the number of bytes in a row of
379 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
380 @retval EFI_SUCCESS Blt operation success
385 BiosVideoGraphicsOutputVgaBlt (
386 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
387 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
388 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
391 IN UINTN DestinationX
,
392 IN UINTN DestinationY
,
399 // BIOS VGA Mini Port Protocol functions
403 VgaMiniPort protocol interface to set mode.
405 @param This Pointer to VgaMiniPort protocol instance
406 @param ModeNumber The index of the mode
408 @retval EFI_UNSUPPORTED The requested mode is not supported
409 @retval EFI_SUCCESS The requested mode is set successfully
414 BiosVideoVgaMiniPortSetMode (
415 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
420 Event handler for Exit Boot Service.
422 @param Event The event that be siganlled when exiting boot service.
423 @param Context Pointer to instance of BIOS_VIDEO_DEV.
428 BiosVideoNotifyExitBootServices (
434 // Standard VGA Definitions
436 #define VGA_HORIZONTAL_RESOLUTION 640
437 #define VGA_VERTICAL_RESOLUTION 480
438 #define VGA_NUMBER_OF_BIT_PLANES 4
439 #define VGA_PIXELS_PER_BYTE 8
440 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
441 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
443 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
444 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
446 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
448 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
450 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
452 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
453 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
454 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
455 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
456 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
458 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
460 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
461 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
462 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
463 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
464 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
465 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
466 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
468 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
470 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
472 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
475 Install child handles if the Handle supports MBR format.
477 @param This Calling context.
478 @param ParentHandle Parent Handle
479 @param ParentPciIo Parent PciIo interface
480 @param ParentLegacyBios Parent LegacyBios interface
481 @param ParentDevicePath Parent Device Path
482 @param RemainingDevicePath Remaining Device Path
484 @retval EFI_SUCCESS If a child handle was added
485 @retval other A child handle was not added
489 BiosVideoChildHandleInstall (
490 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
491 IN EFI_HANDLE ParentHandle
,
492 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
493 IN EFI_LEGACY_BIOS_PROTOCOL
*ParentLegacyBios
,
494 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
495 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
499 Deregister an video child handle and free resources.
501 @param This Protocol instance pointer.
502 @param Controller Video controller handle
503 @param Handle Video child handle
509 BiosVideoChildHandleUninstall (
510 EFI_DRIVER_BINDING_PROTOCOL
*This
,
511 EFI_HANDLE Controller
,
516 Release resource for biso video instance.
518 @param BiosVideoPrivate Video child device private data structure
522 BiosVideoDeviceReleaseResource (
523 BIOS_VIDEO_DEV
*BiosVideoPrivate
527 Check if all video child handles have been uninstalled.
529 @param Controller Video controller handle
531 @return TRUE Child handles exist.
532 @return FALSE All video child handles have been uninstalled.
537 IN EFI_HANDLE Controller