3 Copyright (c) 2006 - 2010, 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
;
92 // Original PCI attributes
94 UINT64 OriginalPciAttributes
;
99 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
100 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
101 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
102 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
107 BOOLEAN VgaCompatible
;
108 BOOLEAN ProduceGraphicsOutput
;
111 // Graphics Output Protocol related fields
113 BOOLEAN HardwareNeedsStarting
;
116 BIOS_VIDEO_MODE_DATA
*ModeData
;
118 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
119 UINT8
*VgaFrameBuffer
;
122 // VESA Bios Extensions related fields
124 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
125 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
126 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
127 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
128 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
129 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
130 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
131 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
135 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
137 EFI_EVENT ExitBootServicesEvent
;
140 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
141 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
142 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
144 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
149 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
150 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
151 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
154 // Driver Binding Protocol functions
160 @param This Pointer to driver binding protocol
161 @param Controller Controller handle to connect
162 @param RemainingDevicePath A pointer to the remaining portion of a device
165 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
166 driver, Otherwise, this controller cannot be
167 managed by this driver
172 BiosVideoDriverBindingSupported (
173 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
174 IN EFI_HANDLE Controller
,
175 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
180 Install Graphics Output Protocol onto VGA device handles.
182 @param This Pointer to driver binding protocol
183 @param Controller Controller handle to connect
184 @param RemainingDevicePath A pointer to the remaining portion of a device
192 BiosVideoDriverBindingStart (
193 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
194 IN EFI_HANDLE Controller
,
195 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
202 @param This Pointer to driver binding protocol
203 @param Controller Controller handle to connect
204 @param NumberOfChildren Number of children handle created by this driver
205 @param ChildHandleBuffer Buffer containing child handle created
207 @retval EFI_SUCCESS Driver disconnected successfully from controller
208 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
213 BiosVideoDriverBindingStop (
214 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
215 IN EFI_HANDLE Controller
,
216 IN UINTN NumberOfChildren
,
217 IN EFI_HANDLE
*ChildHandleBuffer
221 // Private worker functions
225 Check for VBE device.
227 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
229 @retval EFI_SUCCESS VBE device found
233 BiosVideoCheckForVbe (
234 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
239 Check for VGA device.
241 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
243 @retval EFI_SUCCESS Standard VGA device found
247 BiosVideoCheckForVga (
248 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
255 Release resource for biso video instance.
257 @param BiosVideoPrivate Video child device private data structure
261 BiosVideoDeviceReleaseResource (
262 BIOS_VIDEO_DEV
*BiosVideoPrivate
266 // BIOS Graphics Output Protocol functions
270 Graphics Output protocol interface to get video mode.
272 @param This Protocol instance pointer.
273 @param ModeNumber The mode number to return information on.
274 @param SizeOfInfo A pointer to the size, in bytes, of the Info
276 @param Info Caller allocated buffer that returns information
279 @retval EFI_SUCCESS Mode information returned.
280 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
281 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
283 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
284 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
289 BiosVideoGraphicsOutputQueryMode (
290 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
291 IN UINT32 ModeNumber
,
292 OUT UINTN
*SizeOfInfo
,
293 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
298 Graphics Output protocol interface to set video mode.
300 @param This Protocol instance pointer.
301 @param ModeNumber The mode number to be set.
303 @retval EFI_SUCCESS Graphics mode was changed.
304 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
306 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
311 BiosVideoGraphicsOutputSetMode (
312 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
318 Graphics Output protocol instance to block transfer for VBE device.
320 @param This Pointer to Graphics Output protocol instance
321 @param BltBuffer The data to transfer to screen
322 @param BltOperation The operation to perform
323 @param SourceX The X coordinate of the source for BltOperation
324 @param SourceY The Y coordinate of the source for BltOperation
325 @param DestinationX The X coordinate of the destination for
327 @param DestinationY The Y coordinate of the destination for
329 @param Width The width of a rectangle in the blt rectangle in
331 @param Height The height of a rectangle in the blt rectangle in
333 @param Delta Not used for EfiBltVideoFill and
334 EfiBltVideoToVideo operation. If a Delta of 0 is
335 used, the entire BltBuffer will be operated on. If
336 a subrectangle of the BltBuffer is used, then
337 Delta represents the number of bytes in a row of
340 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
341 @retval EFI_SUCCESS Blt operation success
346 BiosVideoGraphicsOutputVbeBlt (
347 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
348 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
349 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
352 IN UINTN DestinationX
,
353 IN UINTN DestinationY
,
361 Grahpics Output protocol instance to block transfer for VGA device.
363 @param This Pointer to Grahpics Output protocol instance
364 @param BltBuffer The data to transfer to screen
365 @param BltOperation The operation to perform
366 @param SourceX The X coordinate of the source for BltOperation
367 @param SourceY The Y coordinate of the source for BltOperation
368 @param DestinationX The X coordinate of the destination for
370 @param DestinationY The Y coordinate of the destination for
372 @param Width The width of a rectangle in the blt rectangle in
374 @param Height The height of a rectangle in the blt rectangle in
376 @param Delta Not used for EfiBltVideoFill and
377 EfiBltVideoToVideo operation. If a Delta of 0 is
378 used, the entire BltBuffer will be operated on. If
379 a subrectangle of the BltBuffer is used, then
380 Delta represents the number of bytes in a row of
383 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
384 @retval EFI_SUCCESS Blt operation success
389 BiosVideoGraphicsOutputVgaBlt (
390 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
391 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
392 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
395 IN UINTN DestinationX
,
396 IN UINTN DestinationY
,
403 // BIOS VGA Mini Port Protocol functions
407 VgaMiniPort protocol interface to set mode.
409 @param This Pointer to VgaMiniPort protocol instance
410 @param ModeNumber The index of the mode
412 @retval EFI_UNSUPPORTED The requested mode is not supported
413 @retval EFI_SUCCESS The requested mode is set successfully
418 BiosVideoVgaMiniPortSetMode (
419 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
424 Event handler for Exit Boot Service.
426 @param Event The event that be siganlled when exiting boot service.
427 @param Context Pointer to instance of BIOS_VIDEO_DEV.
432 BiosVideoNotifyExitBootServices (
438 // Standard VGA Definitions
440 #define VGA_HORIZONTAL_RESOLUTION 640
441 #define VGA_VERTICAL_RESOLUTION 480
442 #define VGA_NUMBER_OF_BIT_PLANES 4
443 #define VGA_PIXELS_PER_BYTE 8
444 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
445 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
447 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
448 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
450 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
452 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
454 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
456 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
457 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
458 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
459 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
460 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
462 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
464 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
465 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
466 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
467 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
468 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
469 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
470 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
472 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
474 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
476 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
479 Install child handles if the Handle supports MBR format.
481 @param This Calling context.
482 @param ParentHandle Parent Handle
483 @param ParentPciIo Parent PciIo interface
484 @param ParentLegacyBios Parent LegacyBios interface
485 @param ParentDevicePath Parent Device Path
486 @param RemainingDevicePath Remaining Device Path
487 @param OriginalPciAttributes Original PCI Attributes
489 @retval EFI_SUCCESS If a child handle was added
490 @retval other A child handle was not added
494 BiosVideoChildHandleInstall (
495 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
496 IN EFI_HANDLE ParentHandle
,
497 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
498 IN EFI_LEGACY_BIOS_PROTOCOL
*ParentLegacyBios
,
499 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
500 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
,
501 IN UINT64 OriginalPciAttributes
505 Deregister an video child handle and free resources.
507 @param This Protocol instance pointer.
508 @param Controller Video controller handle
509 @param Handle Video child handle
515 BiosVideoChildHandleUninstall (
516 EFI_DRIVER_BINDING_PROTOCOL
*This
,
517 EFI_HANDLE Controller
,
522 Release resource for biso video instance.
524 @param BiosVideoPrivate Video child device private data structure
528 BiosVideoDeviceReleaseResource (
529 BIOS_VIDEO_DEV
*BiosVideoPrivate