3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #ifndef _BIOS_GRAPHICS_OUTPUT_H
15 #define _BIOS_GRAPHICS_OUTPUT_H
20 // Driver Consumed Protocol Prototypes
22 #include <Protocol/DevicePath.h>
23 #include <Protocol/PciIo.h>
24 #include <Protocol/DriverBinding.h>
25 #include <Protocol/ComponentName.h>
26 #include <Protocol/ComponentName2.h>
27 #include <Protocol/UgaDraw.h>
28 #include <Protocol/VgaMiniPort.h>
29 #include <Protocol/Legacy8259.h>
30 #include <Protocol/EdidActive.h>
31 #include <Protocol/EdidDiscovered.h>
32 #include <Protocol/DevicePath.h>
33 #include <Protocol/LegacyBios.h>
35 #include <Library/UefiLib.h>
36 #include <Library/DebugLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/DevicePathLib.h>
41 #include <IndustryStandard/Pci22.h>
43 #include "VesaBiosExtensions.h"
46 // Packed format support: The number of bits reserved for each of the colors and the actual
47 // position of RGB in the frame buffer is specified in the VBE Mode information
50 UINT8 Position
; // Position of the color
51 UINT8 Mask
; // The number of bits expressed as a mask
52 } BIOS_VIDEO_COLOR_PLACEMENT
;
55 // BIOS Graphics Output Graphical Mode Data
59 UINT16 BytesPerScanLine
;
60 VOID
*LinearFrameBuffer
;
61 UINTN FrameBufferSize
;
62 UINT32 HorizontalResolution
;
63 UINT32 VerticalResolution
;
66 BIOS_VIDEO_COLOR_PLACEMENT Red
;
67 BIOS_VIDEO_COLOR_PLACEMENT Green
;
68 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
69 BIOS_VIDEO_COLOR_PLACEMENT Reserved
;
70 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
71 EFI_PIXEL_BITMASK PixelBitMask
;
72 } BIOS_VIDEO_MODE_DATA
;
75 // BIOS video child handle private data Structure
77 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
84 // Consumed Protocols inherited from parent controller.
86 EFI_PCI_IO_PROTOCOL
*PciIo
;
87 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
88 THUNK_CONTEXT
*ThunkContext
;
93 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
94 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
95 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
96 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
101 BOOLEAN VgaCompatible
;
102 BOOLEAN ProduceGraphicsOutput
;
105 // Graphics Output Protocol related fields
107 BOOLEAN HardwareNeedsStarting
;
108 BIOS_VIDEO_MODE_DATA
*ModeData
;
110 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
111 UINT8
*VgaFrameBuffer
;
114 // VESA Bios Extensions related fields
116 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
117 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
118 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
119 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
120 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
121 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
122 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
123 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
127 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
130 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
131 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
132 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
134 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
139 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
140 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
141 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
144 // Driver Binding Protocol functions
147 Test to see if Bios Video could be supported on the Controller.
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 path
153 @retval EFI_SUCCESS This driver supports this device.
154 @retval other This driver does not support this device.
159 BiosVideoDriverBindingSupported (
160 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
161 IN EFI_HANDLE Controller
,
162 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
167 Install Graphics Output Protocol onto VGA device handles
169 @param This Pointer to driver binding protocol
170 @param Controller Controller handle to connect
171 @param RemainingDevicePath A pointer to the remaining portion of a device path
178 BiosVideoDriverBindingStart (
179 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
180 IN EFI_HANDLE Controller
,
181 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
186 Stop this driver on Controller
188 @param This Protocol instance pointer.
189 @param Controller Handle of device to stop driver on
190 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
191 children is zero stop the entire bus driver.
192 @param ChildHandleBuffer List of Child Handles to Stop.
194 @retval EFI_SUCCESS This driver is removed Controller.
195 @retval other This driver was not removed from this device.
200 BiosVideoDriverBindingStop (
201 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
202 IN EFI_HANDLE Controller
,
203 IN UINTN NumberOfChildren
,
204 IN EFI_HANDLE
*ChildHandleBuffer
209 // Private worker functions
214 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
216 @retval EFI_SUCCESS VBE device found
220 BiosVideoCheckForVbe (
221 BIOS_VIDEO_DEV
*BiosVideoPrivate
228 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
230 @retval EFI_SUCCESS Standard VGA device found
234 BiosVideoCheckForVga (
235 BIOS_VIDEO_DEV
*BiosVideoPrivate
240 Collect the resource from destroyed bios video device.
242 @param BiosVideoPrivate Video child device private data structure
246 BiosVideoDeviceReleaseResource (
247 BIOS_VIDEO_DEV
*BiosVideoChildPrivate
252 // BIOS Graphics Output Protocol functions
256 Graphics Output protocol interface to get video mode
259 @param This - Protocol instance pointer.
260 @param ModeNumber - The mode number to return information on.
261 @param SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
262 @param Info - Caller allocated buffer that returns information about ModeNumber.
264 @return EFI_SUCCESS - Mode information returned.
265 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
266 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
267 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
282 Graphics Output protocol interface to set video mode
285 @param This - Protocol instance pointer.
286 @param ModeNumber - The mode number to be set.
288 @return EFI_SUCCESS - Graphics mode was changed.
289 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
290 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
295 BiosVideoGraphicsOutputSetMode (
296 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
303 Graphics Output protocol instance to block transfer for VBE device
306 @param This - Pointer to Graphics Output protocol instance
307 @param BltBuffer - The data to transfer to screen
308 @param BltOperation - The operation to perform
309 @param SourceX - The X coordinate of the source for BltOperation
310 @param SourceY - The Y coordinate of the source for BltOperation
311 @param DestinationX - The X coordinate of the destination for BltOperation
312 @param DestinationY - The Y coordinate of the destination for BltOperation
313 @param Width - The width of a rectangle in the blt rectangle in pixels
314 @param Height - The height of a rectangle in the blt rectangle in pixels
315 @param Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
316 If a Delta of 0 is used, the entire BltBuffer will be operated on.
317 If a subrectangle of the BltBuffer is used, then Delta represents
318 the number of bytes in a row of the BltBuffer.
320 @return EFI_INVALID_PARAMETER - Invalid parameter passed in
321 EFI_SUCCESS - Blt operation success
326 BiosVideoGraphicsOutputVbeBlt (
327 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
328 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
329 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
332 IN UINTN DestinationX
,
333 IN UINTN DestinationY
,
341 Grahpics Output protocol instance to block transfer for VGA device
343 @param This Pointer to Grahpics 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 BltOperation
349 @param DestinationY The Y coordinate of the destination for BltOperation
350 @param Width The width of a rectangle in the blt rectangle in pixels
351 @param Height The height of a rectangle in the blt rectangle in pixels
352 @param Delta Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
353 If a Delta of 0 is used, the entire BltBuffer will be operated on.
354 If a subrectangle of the BltBuffer is used, then Delta represents
355 the number of bytes in a row of the BltBuffer.
357 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
358 @retval EFI_SUCCESS Blt operation success
363 BiosVideoGraphicsOutputVgaBlt (
364 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
365 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
366 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
369 IN UINTN DestinationX
,
370 IN UINTN DestinationY
,
378 // BIOS VGA Mini Port Protocol functions
381 VgaMiniPort protocol interface to set mode
383 @param This Pointer to VgaMiniPort protocol instance
384 @param ModeNumber The index of the mode
386 @retval EFI_UNSUPPORTED The requested mode is not supported
387 @retval EFI_SUCCESS The requested mode is set successfully
392 BiosVideoVgaMiniPortSetMode (
393 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
399 Judge whether this device is VGA device.
401 @param PciIo Parent PciIo protocol instance pointer
403 @retval TRUE Is vga device
404 @retval FALSE Is no vga device
408 IN EFI_PCI_IO_PROTOCOL
*PciIo
414 // Standard VGA Definitions
416 #define VGA_HORIZONTAL_RESOLUTION 640
417 #define VGA_VERTICAL_RESOLUTION 480
418 #define VGA_NUMBER_OF_BIT_PLANES 4
419 #define VGA_PIXELS_PER_BYTE 8
420 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
421 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
423 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
424 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
426 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
428 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
430 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
432 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
433 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
434 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
435 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
436 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
438 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
440 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
441 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
442 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
443 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
444 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
445 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
446 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
448 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
450 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
452 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
455 Initialize legacy environment for BIOS INI caller.
457 @param ThunkContext the instance pointer of THUNK_CONTEXT
460 InitializeBiosIntCaller (
461 THUNK_CONTEXT
*ThunkContext
465 Initialize interrupt redirection code and entries, because
466 IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
467 Or the interrupt will lost when we do thunk.
468 NOTE: We do not reset 8259 vector base, because it will cause pending
471 @param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.
475 InitializeInterruptRedirection (
476 IN EFI_LEGACY_8259_PROTOCOL
*Legacy8259
480 Thunk to 16-bit real mode and execute a software interrupt with a vector
481 of BiosInt. Regs will contain the 16-bit register context on entry and
484 @param This Protocol instance pointer.
485 @param BiosInt Processor interrupt vector to invoke
486 @param Reg Register contexted passed into (and returned) from thunk to 16-bit mode
488 @retval TRUE Thunk completed, and there were no BIOS errors in the target code.
490 @retval FALSE There was a BIOS erro in the target code.
495 IN BIOS_VIDEO_DEV
*BiosDev
,
497 IN EFI_IA32_REGISTER_SET
*Regs