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>
34 #include <Library/UefiLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/DevicePathLib.h>
40 #include <IndustryStandard/Pci.h>
42 #include "VesaBiosExtensions.h"
45 // Packed format support: The number of bits reserved for each of the colors and the actual
46 // position of RGB in the frame buffer is specified in the VBE Mode information
49 UINT8 Position
; // Position of the color
50 UINT8 Mask
; // The number of bits expressed as a mask
51 } BIOS_VIDEO_COLOR_PLACEMENT
;
54 // BIOS Graphics Output Graphical Mode Data
58 UINT16 BytesPerScanLine
;
59 VOID
*LinearFrameBuffer
;
60 UINTN FrameBufferSize
;
61 UINT32 HorizontalResolution
;
62 UINT32 VerticalResolution
;
65 BIOS_VIDEO_COLOR_PLACEMENT Red
;
66 BIOS_VIDEO_COLOR_PLACEMENT Green
;
67 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
68 BIOS_VIDEO_COLOR_PLACEMENT Reserved
;
69 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
70 EFI_PIXEL_BITMASK PixelBitMask
;
71 } BIOS_VIDEO_MODE_DATA
;
74 // BIOS video child handle private data Structure
76 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
83 // Consumed Protocols inherited from parent controller.
85 EFI_PCI_IO_PROTOCOL
*PciIo
;
86 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
87 THUNK_CONTEXT
*ThunkContext
;
92 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
93 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
94 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
95 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
100 BOOLEAN VgaCompatible
;
101 BOOLEAN ProduceGraphicsOutput
;
104 // Graphics Output Protocol related fields
106 BOOLEAN HardwareNeedsStarting
;
107 BIOS_VIDEO_MODE_DATA
*ModeData
;
109 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
110 UINT8
*VgaFrameBuffer
;
113 // VESA Bios Extensions related fields
115 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
116 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
117 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
118 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
119 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
120 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
121 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
122 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
126 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
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
135 #define EFI_SEGMENT(_Adr) (UINT16) ((UINT16) (((UINTN) (_Adr)) >> 4) & 0xf000)
136 #define EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xffff)
141 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
142 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
143 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
146 // Driver Binding Protocol functions
149 Test to see if Bios Video could be supported on the Controller.
151 @param This Pointer to driver binding protocol
152 @param Controller Controller handle to connect
153 @param RemainingDevicePath A pointer to the remaining portion of a device path
155 @retval EFI_SUCCESS This driver supports this device.
156 @retval other This driver does not support this device.
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 path
180 BiosVideoDriverBindingStart (
181 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
182 IN EFI_HANDLE Controller
,
183 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
188 Stop this driver on Controller
190 @param This Protocol instance pointer.
191 @param Controller Handle of device to stop driver on
192 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
193 children is zero stop the entire bus driver.
194 @param ChildHandleBuffer List of Child Handles to Stop.
196 @retval EFI_SUCCESS This driver is removed Controller.
197 @retval other This driver was not removed from this device.
202 BiosVideoDriverBindingStop (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN UINTN NumberOfChildren
,
206 IN EFI_HANDLE
*ChildHandleBuffer
211 // Private worker functions
216 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
218 @retval EFI_SUCCESS VBE device found
222 BiosVideoCheckForVbe (
223 BIOS_VIDEO_DEV
*BiosVideoPrivate
230 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
232 @retval EFI_SUCCESS Standard VGA device found
236 BiosVideoCheckForVga (
237 BIOS_VIDEO_DEV
*BiosVideoPrivate
242 Collect the resource from destroyed bios video device.
244 @param BiosVideoPrivate Video child device private data structure
248 BiosVideoDeviceReleaseResource (
249 BIOS_VIDEO_DEV
*BiosVideoChildPrivate
254 // BIOS Graphics Output Protocol functions
258 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 buffer.
264 @param Info - Caller allocated buffer that returns information about ModeNumber.
266 @return EFI_SUCCESS - Mode information returned.
267 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
268 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
269 EFI_INVALID_PARAMETER - One of the input args was NULL.
274 BiosVideoGraphicsOutputQueryMode (
275 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
276 IN UINT32 ModeNumber
,
277 OUT UINTN
*SizeOfInfo
,
278 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
284 Graphics Output protocol interface to set video mode
287 @param This - Protocol instance pointer.
288 @param ModeNumber - The mode number to be set.
290 @return EFI_SUCCESS - Graphics mode was changed.
291 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
292 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
297 BiosVideoGraphicsOutputSetMode (
298 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
305 Graphics Output protocol instance to block transfer for VBE device
308 @param This - Pointer to Graphics Output protocol instance
309 @param BltBuffer - The data to transfer to screen
310 @param BltOperation - The operation to perform
311 @param SourceX - The X coordinate of the source for BltOperation
312 @param SourceY - The Y coordinate of the source for BltOperation
313 @param DestinationX - The X coordinate of the destination for BltOperation
314 @param DestinationY - The Y coordinate of the destination for BltOperation
315 @param Width - The width of a rectangle in the blt rectangle in pixels
316 @param Height - The height of a rectangle in the blt rectangle in pixels
317 @param Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
318 If a Delta of 0 is used, the entire BltBuffer will be operated on.
319 If a subrectangle of the BltBuffer is used, then Delta represents
320 the number of bytes in a row of the BltBuffer.
322 @return EFI_INVALID_PARAMETER - Invalid parameter passed in
323 EFI_SUCCESS - Blt operation success
328 BiosVideoGraphicsOutputVbeBlt (
329 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
330 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
331 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
334 IN UINTN DestinationX
,
335 IN UINTN DestinationY
,
343 Grahpics Output protocol instance to block transfer for VGA device
345 @param This Pointer to Grahpics Output protocol instance
346 @param BltBuffer The data to transfer to screen
347 @param BltOperation The operation to perform
348 @param SourceX The X coordinate of the source for BltOperation
349 @param SourceY The Y coordinate of the source for BltOperation
350 @param DestinationX The X coordinate of the destination for BltOperation
351 @param DestinationY The Y coordinate of the destination for BltOperation
352 @param Width The width of a rectangle in the blt rectangle in pixels
353 @param Height The height of a rectangle in the blt rectangle in pixels
354 @param Delta Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
355 If a Delta of 0 is used, the entire BltBuffer will be operated on.
356 If a subrectangle of the BltBuffer is used, then Delta represents
357 the number of bytes in a row of the BltBuffer.
359 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
360 @retval EFI_SUCCESS Blt operation success
365 BiosVideoGraphicsOutputVgaBlt (
366 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
367 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
368 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
371 IN UINTN DestinationX
,
372 IN UINTN DestinationY
,
380 // BIOS VGA Mini Port Protocol functions
383 VgaMiniPort protocol interface to set mode
385 @param This Pointer to VgaMiniPort protocol instance
386 @param ModeNumber The index of the mode
388 @retval EFI_UNSUPPORTED The requested mode is not supported
389 @retval EFI_SUCCESS The requested mode is set successfully
394 BiosVideoVgaMiniPortSetMode (
395 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
401 Judge whether this device is VGA device.
403 @param PciIo Parent PciIo protocol instance pointer
405 @retval TRUE Is vga device
406 @retval FALSE Is no vga device
410 IN EFI_PCI_IO_PROTOCOL
*PciIo
416 // Standard VGA Definitions
418 #define VGA_HORIZONTAL_RESOLUTION 640
419 #define VGA_VERTICAL_RESOLUTION 480
420 #define VGA_NUMBER_OF_BIT_PLANES 4
421 #define VGA_PIXELS_PER_BYTE 8
422 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
423 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
425 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
426 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
428 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
430 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
432 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
434 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
435 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
436 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
437 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
438 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
440 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
442 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
443 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
444 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
445 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
446 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
447 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
448 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
450 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
452 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
454 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
457 Initialize legacy environment for BIOS INI caller.
459 @param ThunkContext the instance pointer of THUNK_CONTEXT
462 InitializeBiosIntCaller (
463 THUNK_CONTEXT
*ThunkContext
467 Initialize interrupt redirection code and entries, because
468 IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
469 Or the interrupt will lost when we do thunk.
470 NOTE: We do not reset 8259 vector base, because it will cause pending
473 @param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.
477 InitializeInterruptRedirection (
478 IN EFI_LEGACY_8259_PROTOCOL
*Legacy8259
482 Thunk to 16-bit real mode and execute a software interrupt with a vector
483 of BiosInt. Regs will contain the 16-bit register context on entry and
486 @param This Protocol instance pointer.
487 @param BiosInt Processor interrupt vector to invoke
488 @param Reg Register contexted passed into (and returned) from thunk to 16-bit mode
490 @retval TRUE Thunk completed, and there were no BIOS errors in the target code.
492 @retval FALSE There was a BIOS erro in the target code.
497 IN BIOS_VIDEO_DEV
*BiosDev
,
499 IN IA32_REGISTER_SET
*Regs