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.
21 #ifndef _BIOS_GRAPHICS_OUTPUT_H
22 #define _BIOS_GRAPHICS_OUTPUT_H
27 // Driver Consumed Protocol Prototypes
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/PciIo.h>
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/ComponentName.h>
33 #include <Protocol/ComponentName2.h>
34 #include <Protocol/UgaDraw.h>
35 #include <Protocol/VgaMiniPort.h>
36 #include <Protocol/Legacy8259.h>
37 #include <Protocol/EdidActive.h>
38 #include <Protocol/EdidDiscovered.h>
39 #include <Protocol/DevicePath.h>
40 #include <Protocol/LegacyBios.h>
42 #include <Library/UefiLib.h>
43 #include <Library/DebugLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/BaseMemoryLib.h>
46 #include <Library/DevicePathLib.h>
48 #include <IndustryStandard/Pci22.h>
50 #include "VesaBiosExtensions.h"
53 // Packed format support: The number of bits reserved for each of the colors and the actual
54 // position of RGB in the frame buffer is specified in the VBE Mode information
57 UINT8 Position
; // Position of the color
58 UINT8 Mask
; // The number of bits expressed as a mask
59 } BIOS_VIDEO_COLOR_PLACEMENT
;
62 // BIOS Graphics Output Graphical Mode Data
66 UINT16 BytesPerScanLine
;
67 VOID
*LinearFrameBuffer
;
68 UINTN FrameBufferSize
;
69 UINT32 HorizontalResolution
;
70 UINT32 VerticalResolution
;
73 BIOS_VIDEO_COLOR_PLACEMENT Red
;
74 BIOS_VIDEO_COLOR_PLACEMENT Green
;
75 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
76 BIOS_VIDEO_COLOR_PLACEMENT Reserved
;
77 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
78 EFI_PIXEL_BITMASK PixelBitMask
;
79 } BIOS_VIDEO_MODE_DATA
;
82 // BIOS video child handle private data Structure
84 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
93 EFI_PCI_IO_PROTOCOL
*PciIo
;
94 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
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
;
109 EFI_EVENT ExitBootServicesEvent
;
112 // Graphics Output Protocol related fields
114 BOOLEAN HardwareNeedsStarting
;
115 BIOS_VIDEO_MODE_DATA
*ModeData
;
117 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
118 UINT8
*VgaFrameBuffer
;
121 // VESA Bios Extensions related fields
123 UINTN NumberOfPagesBelow1MB
; // Number of 4KB pages in PagesBelow1MB
124 EFI_PHYSICAL_ADDRESS PagesBelow1MB
; // Buffer for all VBE Information Blocks
125 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK
*VbeInformationBlock
; // 0x200 bytes. Must be allocated below 1MB
126 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK
*VbeModeInformationBlock
; // 0x100 bytes. Must be allocated below 1MB
127 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK
*VbeEdidDataBlock
; // 0x80 bytes. Must be allocated below 1MB
128 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK
*VbeCrtcInformationBlock
; // 59 bytes. Must be allocated below 1MB
129 UINTN VbeSaveRestorePages
; // Number of 4KB pages in VbeSaveRestoreBuffer
130 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer
; // Must be allocated below 1MB
134 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
137 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
138 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
139 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
141 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
146 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
147 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
148 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
151 // Driver Binding Protocol functions
155 BiosVideoDriverBindingSupported (
156 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
157 IN EFI_HANDLE Controller
,
158 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
164 GC_TODO: Add function description
168 This - GC_TODO: add argument description
169 Controller - GC_TODO: add argument description
170 RemainingDevicePath - GC_TODO: add argument description
174 GC_TODO: add return values
181 BiosVideoDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
190 GC_TODO: Add function description
194 This - GC_TODO: add argument description
195 Controller - GC_TODO: add argument description
196 RemainingDevicePath - GC_TODO: add argument description
200 GC_TODO: add return values
207 BiosVideoDriverBindingStop (
208 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
209 IN EFI_HANDLE Controller
,
210 IN UINTN NumberOfChildren
,
211 IN EFI_HANDLE
*ChildHandleBuffer
217 GC_TODO: Add function description
221 This - GC_TODO: add argument description
222 Controller - GC_TODO: add argument description
223 NumberOfChildren - GC_TODO: add argument description
224 ChildHandleBuffer - GC_TODO: add argument description
228 GC_TODO: add return values
234 // Private worker functions
237 BiosVideoCheckForVbe (
238 BIOS_VIDEO_DEV
*BiosVideoPrivate
244 GC_TODO: Add function description
248 BiosVideoPrivate - GC_TODO: add argument description
252 GC_TODO: add return values
258 BiosVideoCheckForVga (
259 BIOS_VIDEO_DEV
*BiosVideoPrivate
265 GC_TODO: Add function description
269 BiosVideoPrivate - GC_TODO: add argument description
273 GC_TODO: add return values
280 DeRegisterVideoChildHandle (
281 EFI_DRIVER_BINDING_PROTOCOL
*This
,
282 EFI_HANDLE Controller
,
289 Deregister an video child handle and free resources
293 This - Protocol instance pointer.
294 Controller - Video controller handle
295 Handle - Video child handle
305 BiosVideoDeviceReleaseResource (
306 BIOS_VIDEO_DEV
*BiosVideoChildPrivate
311 Release resources of a video child device before stopping it.
315 BiosVideoChildPrivate - Video child device private data structure
325 // BIOS Graphics Output Protocol functions
329 BiosVideoGraphicsOutputQueryMode (
330 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
331 IN UINT32 ModeNumber
,
332 OUT UINTN
*SizeOfInfo
,
333 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
339 Graphics Output protocol interface to get video mode
342 This - Protocol instance pointer.
343 ModeNumber - The mode number to return information on.
344 Info - Caller allocated buffer that returns information about ModeNumber.
345 SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
348 EFI_SUCCESS - Mode information returned.
349 EFI_BUFFER_TOO_SMALL - The Info buffer was too small.
350 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
351 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
352 EFI_INVALID_PARAMETER - One of the input args was NULL.
359 BiosVideoGraphicsOutputSetMode (
360 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
367 Graphics Output protocol interface to set video mode
370 This - Protocol instance pointer.
371 ModeNumber - The mode number to be set.
374 EFI_SUCCESS - Graphics mode was changed.
375 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
376 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
383 BiosVideoGraphicsOutputVbeBlt (
384 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
385 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
386 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
389 IN UINTN DestinationX
,
390 IN UINTN DestinationY
,
399 Graphics Output protocol instance to block transfer for VBE device
403 This - Pointer to Graphics Output protocol instance
404 BltBuffer - The data to transfer to screen
405 BltOperation - The operation to perform
406 SourceX - The X coordinate of the source for BltOperation
407 SourceY - The Y coordinate of the source for BltOperation
408 DestinationX - The X coordinate of the destination for BltOperation
409 DestinationY - The Y coordinate of the destination for BltOperation
410 Width - The width of a rectangle in the blt rectangle in pixels
411 Height - The height of a rectangle in the blt rectangle in pixels
412 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
413 If a Delta of 0 is used, the entire BltBuffer will be operated on.
414 If a subrectangle of the BltBuffer is used, then Delta represents
415 the number of bytes in a row of the BltBuffer.
419 EFI_INVALID_PARAMETER - Invalid parameter passed in
420 EFI_SUCCESS - Blt operation success
427 BiosVideoGraphicsOutputVgaBlt (
428 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
429 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
430 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
433 IN UINTN DestinationX
,
434 IN UINTN DestinationY
,
443 Grahpics Output protocol instance to block transfer for VGA device
447 This - Pointer to Grahpics Output protocol instance
448 BltBuffer - The data to transfer to screen
449 BltOperation - The operation to perform
450 SourceX - The X coordinate of the source for BltOperation
451 SourceY - The Y coordinate of the source for BltOperation
452 DestinationX - The X coordinate of the destination for BltOperation
453 DestinationY - The Y coordinate of the destination for BltOperation
454 Width - The width of a rectangle in the blt rectangle in pixels
455 Height - The height of a rectangle in the blt rectangle in pixels
456 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
457 If a Delta of 0 is used, the entire BltBuffer will be operated on.
458 If a subrectangle of the BltBuffer is used, then Delta represents
459 the number of bytes in a row of the BltBuffer.
463 EFI_INVALID_PARAMETER - Invalid parameter passed in
464 EFI_SUCCESS - Blt operation success
470 // BIOS VGA Mini Port Protocol functions
474 BiosVideoVgaMiniPortSetMode (
475 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
482 VgaMiniPort protocol interface to set mode
486 This - Pointer to VgaMiniPort protocol instance
487 ModeNumber - The index of the mode
491 EFI_UNSUPPORTED - The requested mode is not supported
492 EFI_SUCCESS - The requested mode is set successfully
500 IN EFI_PCI_IO_PROTOCOL
*PciIo
506 // Standard VGA Definitions
508 #define VGA_HORIZONTAL_RESOLUTION 640
509 #define VGA_VERTICAL_RESOLUTION 480
510 #define VGA_NUMBER_OF_BIT_PLANES 4
511 #define VGA_PIXELS_PER_BYTE 8
512 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
513 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
515 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
516 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
518 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
520 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
522 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
524 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
525 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
526 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
527 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
528 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
530 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
532 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
533 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
534 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
535 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
536 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
537 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
538 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
540 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
542 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
544 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
547 InitializeBiosIntCaller (
548 IN BIOS_VIDEO_DEV
*BiosDev
552 InitializeInterruptRedirection (
553 IN BIOS_VIDEO_DEV
*BiosDev
559 IN BIOS_VIDEO_DEV
*BiosDev
,
561 IN EFI_IA32_REGISTER_SET
*Regs