3 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
4 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
223 BiosVideoCheckForVbe (
224 IN OUT BIOS_VIDEO_DEV
*BiosVideoPrivate
231 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
233 @retval EFI_SUCCESS Standard VGA device found
238 BiosVideoCheckForVga (
239 BIOS_VIDEO_DEV
*BiosVideoPrivate
244 Collect the resource from destroyed bios video device.
246 @param BiosVideoPrivate Video child device private data structure
250 BiosVideoDeviceReleaseResource (
251 BIOS_VIDEO_DEV
*BiosVideoChildPrivate
256 // BIOS Graphics Output Protocol functions
260 Graphics Output protocol interface to get video mode
263 @param This - Protocol instance pointer.
264 @param ModeNumber - The mode number to return information on.
265 @param SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
266 @param Info - Caller allocated buffer that returns information about ModeNumber.
268 @return EFI_SUCCESS - Mode information returned.
269 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
270 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
271 EFI_INVALID_PARAMETER - One of the input args was NULL.
276 BiosVideoGraphicsOutputQueryMode (
277 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
278 IN UINT32 ModeNumber
,
279 OUT UINTN
*SizeOfInfo
,
280 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
286 Graphics Output protocol interface to set video mode
289 @param This - Protocol instance pointer.
290 @param ModeNumber - The mode number to be set.
292 @return EFI_SUCCESS - Graphics mode was changed.
293 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
294 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
299 BiosVideoGraphicsOutputSetMode (
300 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
307 Graphics Output protocol instance to block transfer for VBE device
310 @param This - Pointer to Graphics Output protocol instance
311 @param BltBuffer - The data to transfer to screen
312 @param BltOperation - The operation to perform
313 @param SourceX - The X coordinate of the source for BltOperation
314 @param SourceY - The Y coordinate of the source for BltOperation
315 @param DestinationX - The X coordinate of the destination for BltOperation
316 @param DestinationY - The Y coordinate of the destination for BltOperation
317 @param Width - The width of a rectangle in the blt rectangle in pixels
318 @param Height - The height of a rectangle in the blt rectangle in pixels
319 @param Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
320 If a Delta of 0 is used, the entire BltBuffer will be operated on.
321 If a subrectangle of the BltBuffer is used, then Delta represents
322 the number of bytes in a row of the BltBuffer.
324 @return EFI_INVALID_PARAMETER - Invalid parameter passed in
325 EFI_SUCCESS - Blt operation success
330 BiosVideoGraphicsOutputVbeBlt (
331 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
332 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
333 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
336 IN UINTN DestinationX
,
337 IN UINTN DestinationY
,
345 Grahpics Output protocol instance to block transfer for VGA device
347 @param This Pointer to Grahpics Output protocol instance
348 @param BltBuffer The data to transfer to screen
349 @param BltOperation The operation to perform
350 @param SourceX The X coordinate of the source for BltOperation
351 @param SourceY The Y coordinate of the source for BltOperation
352 @param DestinationX The X coordinate of the destination for BltOperation
353 @param DestinationY The Y coordinate of the destination for BltOperation
354 @param Width The width of a rectangle in the blt rectangle in pixels
355 @param Height The height of a rectangle in the blt rectangle in pixels
356 @param Delta Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
357 If a Delta of 0 is used, the entire BltBuffer will be operated on.
358 If a subrectangle of the BltBuffer is used, then Delta represents
359 the number of bytes in a row of the BltBuffer.
361 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
362 @retval EFI_SUCCESS Blt operation success
367 BiosVideoGraphicsOutputVgaBlt (
368 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
369 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
370 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
373 IN UINTN DestinationX
,
374 IN UINTN DestinationY
,
382 // BIOS VGA Mini Port Protocol functions
385 VgaMiniPort protocol interface to set mode
387 @param This Pointer to VgaMiniPort protocol instance
388 @param ModeNumber The index of the mode
390 @retval EFI_UNSUPPORTED The requested mode is not supported
391 @retval EFI_SUCCESS The requested mode is set successfully
396 BiosVideoVgaMiniPortSetMode (
397 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
403 Judge whether this device is VGA device.
405 @param PciIo Parent PciIo protocol instance pointer
407 @retval TRUE Is vga device
408 @retval FALSE Is no vga device
412 IN EFI_PCI_IO_PROTOCOL
*PciIo
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 Initialize legacy environment for BIOS INI caller.
461 @param ThunkContext the instance pointer of THUNK_CONTEXT
464 InitializeBiosIntCaller (
465 THUNK_CONTEXT
*ThunkContext
469 Initialize interrupt redirection code and entries, because
470 IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
471 Or the interrupt will lost when we do thunk.
472 NOTE: We do not reset 8259 vector base, because it will cause pending
475 @param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.
479 InitializeInterruptRedirection (
480 IN EFI_LEGACY_8259_PROTOCOL
*Legacy8259
484 Thunk to 16-bit real mode and execute a software interrupt with a vector
485 of BiosInt. Regs will contain the 16-bit register context on entry and
488 @param This Protocol instance pointer.
489 @param BiosInt Processor interrupt vector to invoke
490 @param Reg Register contexted passed into (and returned) from thunk to 16-bit mode
492 @retval TRUE Thunk completed, and there were no BIOS errors in the target code.
494 @retval FALSE There was a BIOS erro in the target code.
499 IN BIOS_VIDEO_DEV
*BiosDev
,
501 IN IA32_REGISTER_SET
*Regs