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.
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/LegacyBios.h>
39 #include <Library/UefiLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/BaseMemoryLib.h>
44 #include <IndustryStandard/Pci22.h>
46 #include "VesaBiosExtensions.h"
48 // Driver Produced Protocol Prototypes
50 //#include EFI_PROTOCOL_DEFINITION (DriverBinding)
51 //#include EFI_PROTOCOL_DEFINITION (ComponentName)
52 //#include EFI_PROTOCOL_DEFINITION (ComponentName2)
53 //#include EFI_PROTOCOL_DEFINITION (UgaDraw)
54 //#include EFI_PROTOCOL_DEFINITION (VgaMiniPort)
57 // Packed format support: The number of bits reserved for each of the colors and the actual
58 // position of RGB in the frame buffer is specified in the VBE Mode information
61 UINT8 Position
; // Position of the color
62 UINT8 Mask
; // The number of bits expressed as a mask
63 } BIOS_VIDEO_COLOR_PLACEMENT
;
66 // BIOS UGA Draw Graphical Mode Data
70 UINT16 BytesPerScanLine
;
71 VOID
*LinearFrameBuffer
;
72 UINT32 HorizontalResolution
;
73 UINT32 VerticalResolution
;
77 BIOS_VIDEO_COLOR_PLACEMENT Red
;
78 BIOS_VIDEO_COLOR_PLACEMENT Green
;
79 BIOS_VIDEO_COLOR_PLACEMENT Blue
;
80 } BIOS_VIDEO_MODE_DATA
;
83 // BIOS UGA Device Structure
85 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
94 EFI_PCI_IO_PROTOCOL
*PciIo
;
95 //EFI_LEGACY_BIOS_THUNK_PROTOCOL *LegacyBios;
100 EFI_UGA_DRAW_PROTOCOL UgaDraw
;
101 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort
;
106 EFI_EVENT ExitBootServicesEvent
;
107 BOOLEAN VgaCompatible
;
108 BOOLEAN ProduceUgaDraw
;
111 // UGA Draw related fields
113 BOOLEAN HardwareNeedsStarting
;
116 BIOS_VIDEO_MODE_DATA
*ModeData
;
118 EFI_UGA_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_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_UGA_DRAW_THIS(a) CR (a, BIOS_VIDEO_DEV, UgaDraw, 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)
144 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding
;
145 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName
;
146 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2
;
149 // Driver Binding Protocol functions
153 BiosVideoDriverBindingSupported (
154 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
155 IN EFI_HANDLE Controller
,
156 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
166 This - Pointer to driver binding protocol
167 Controller - Controller handle to connect
168 RemainingDevicePath - A pointer to the remaining portion of a device path
173 EFI_STATUS - EFI_SUCCESS:This controller can be managed by this driver,
174 Otherwise, this controller cannot be managed by this driver
181 BiosVideoDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
190 Install UGA Draw Protocol onto VGA device handles
194 This - Pointer to driver binding protocol
195 Controller - Controller handle to connect
196 RemainingDevicePath - A pointer to the remaining portion of a device path
207 BiosVideoDriverBindingStop (
208 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
209 IN EFI_HANDLE Controller
,
210 IN UINTN NumberOfChildren
,
211 IN EFI_HANDLE
*ChildHandleBuffer
221 This - Pointer to driver binding protocol
222 Controller - Controller handle to connect
223 NumberOfChilren - Number of children handle created by this driver
224 ChildHandleBuffer - Buffer containing child handle created
228 EFI_SUCCESS - Driver disconnected successfully from controller
229 EFI_UNSUPPORTED - Cannot find BIOS_VIDEO_DEV structure
235 // Private worker functions
238 BiosVideoCheckForVbe (
239 BIOS_VIDEO_DEV
*BiosVideoPrivate
249 BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
253 EFI_SUCCESS - VBE device found
259 BiosVideoCheckForVga (
260 BIOS_VIDEO_DEV
*BiosVideoPrivate
270 BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
274 EFI_SUCCESS - Standard VGA device found
280 // BIOS UGA Draw Protocol functions
284 BiosVideoUgaDrawGetMode (
285 IN EFI_UGA_DRAW_PROTOCOL
*This
,
286 OUT UINT32
*HorizontalResolution
,
287 OUT UINT32
*VerticalResolution
,
288 OUT UINT32
*ColorDepth
,
289 OUT UINT32
*RefreshRate
295 UGA protocol interface to get video mode
299 This - Pointer to UGA draw protocol instance
300 HorizontalResolution - Horizontal Resolution, in pixels
301 VerticalResolution - Vertical Resolution, in pixels
302 ColorDepth - Bit number used to represent color value of a pixel
303 RefreshRate - Refresh rate, in Hertz
307 EFI_DEVICE_ERROR - Hardware need starting
308 EFI_INVALID_PARAMETER - Invalid parameter passed in
309 EFI_SUCCESS - Video mode query successfully
316 BiosVideoUgaDrawSetMode (
317 IN EFI_UGA_DRAW_PROTOCOL
*This
,
318 IN UINT32 HorizontalResolution
,
319 IN UINT32 VerticalResolution
,
320 IN UINT32 ColorDepth
,
321 IN UINT32 RefreshRate
327 UGA draw protocol interface to set video mode
331 This - Pointer to UGA draw protocol instance
332 HorizontalResolution - Horizontal Resolution, in pixels
333 VerticalResolution - Vertical Resolution, in pixels
334 ColorDepth - Bit number used to represent color value of a pixel
335 RefreshRate - Refresh rate, in Hertz
339 EFI_DEVICE_ERROR - Device error
340 EFI_SUCCESS - Video mode set successfully
341 EFI_UNSUPPORTED - Cannot support this video mode
348 BiosVideoUgaDrawVbeBlt (
349 IN EFI_UGA_DRAW_PROTOCOL
*This
,
350 IN EFI_UGA_PIXEL
*BltBuffer
, OPTIONAL
351 IN EFI_UGA_BLT_OPERATION BltOperation
,
354 IN UINTN DestinationX
,
355 IN UINTN DestinationY
,
364 UGA draw protocol instance to block transfer for VBE device
368 This - Pointer to UGA draw protocol instance
369 BltBuffer - The data to transfer to screen
370 BltOperation - The operation to perform
371 SourceX - The X coordinate of the source for BltOperation
372 SourceY - The Y coordinate of the source for BltOperation
373 DestinationX - The X coordinate of the destination for BltOperation
374 DestinationY - The Y coordinate of the destination for BltOperation
375 Width - The width of a rectangle in the blt rectangle in pixels
376 Height - The height of a rectangle in the blt rectangle in pixels
377 Delta - Not used for EfiUgaVideoFill and EfiUgaVideoToVideo operation.
378 If a Delta of 0 is used, the entire BltBuffer will be operated on.
379 If a subrectangle of the BltBuffer is used, then Delta represents
380 the number of bytes in a row of the BltBuffer.
384 EFI_INVALID_PARAMETER - Invalid parameter passed in
385 EFI_SUCCESS - Blt operation success
392 BiosVideoUgaDrawVgaBlt (
393 IN EFI_UGA_DRAW_PROTOCOL
*This
,
394 IN EFI_UGA_PIXEL
*BltBuffer
, OPTIONAL
395 IN EFI_UGA_BLT_OPERATION BltOperation
,
398 IN UINTN DestinationX
,
399 IN UINTN DestinationY
,
408 UGA draw protocol instance to block transfer for VGA device
412 This - Pointer to UGA draw protocol instance
413 BltBuffer - The data to transfer to screen
414 BltOperation - The operation to perform
415 SourceX - The X coordinate of the source for BltOperation
416 SourceY - The Y coordinate of the source for BltOperation
417 DestinationX - The X coordinate of the destination for BltOperation
418 DestinationY - The Y coordinate of the destination for BltOperation
419 Width - The width of a rectangle in the blt rectangle in pixels
420 Height - The height of a rectangle in the blt rectangle in pixels
421 Delta - Not used for EfiUgaVideoFill and EfiUgaVideoToVideo operation.
422 If a Delta of 0 is used, the entire BltBuffer will be operated on.
423 If a subrectangle of the BltBuffer is used, then Delta represents
424 the number of bytes in a row of the BltBuffer.
428 EFI_INVALID_PARAMETER - Invalid parameter passed in
429 EFI_SUCCESS - Blt operation success
435 // BIOS VGA Mini Port Protocol functions
439 BiosVideoVgaMiniPortSetMode (
440 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
447 VgaMiniPort protocol interface to set mode
451 This - Pointer to VgaMiniPort protocol instance
452 ModeNumber - The index of the mode
456 EFI_UNSUPPORTED - The requested mode is not supported
457 EFI_SUCCESS - The requested mode is set successfully
465 IN EFI_PCI_IO_PROTOCOL
*PciIo
471 // Standard VGA Definitions
473 #define VGA_HORIZONTAL_RESOLUTION 640
474 #define VGA_VERTICAL_RESOLUTION 480
475 #define VGA_NUMBER_OF_BIT_PLANES 4
476 #define VGA_PIXELS_PER_BYTE 8
477 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
478 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
480 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
481 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
483 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
485 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
487 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
489 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
490 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
491 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
492 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
493 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
495 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
497 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
498 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
499 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
500 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
501 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
502 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
503 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
505 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
507 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
509 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08