3 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The
8 full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Protocol/PciIo.h>
20 #include <Protocol/DevicePath.h>
21 #include <Protocol/GraphicsOutput.h>
22 #include <Protocol/EdidActive.h>
23 #include <Protocol/EdidDiscovered.h>
25 #include <Guid/StatusCodeDataTypeId.h>
26 #include <Guid/EventGroup.h>
27 #include <Guid/FrameBufferInfoGuid.h>
29 #include <Library/PcdLib.h>
30 #include <Library/HobLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/ReportStatusCodeLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/MemoryAllocationLib.h>
40 #include <IndustryStandard/Pci.h>
43 // Packed format support: The number of bits reserved for each of the colors and the actual
44 // position of RGB in the frame buffer is specified in the VBE Mode information
47 UINT8 Position
; // Position of the color
48 UINT8 Mask
; // The number of bits expressed as a mask
49 } FB_VIDEO_COLOR_PLACEMENT
;
52 // BIOS Graphics Output Graphical Mode Data
56 UINT16 BytesPerScanLine
;
57 VOID
*LinearFrameBuffer
;
58 UINTN FrameBufferSize
;
59 UINT32 HorizontalResolution
;
60 UINT32 VerticalResolution
;
64 FB_VIDEO_COLOR_PLACEMENT Red
;
65 FB_VIDEO_COLOR_PLACEMENT Green
;
66 FB_VIDEO_COLOR_PLACEMENT Blue
;
67 FB_VIDEO_COLOR_PLACEMENT Reserved
;
68 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
69 EFI_PIXEL_BITMASK PixelBitMask
;
73 // BIOS video child handle private data Structure
75 #define FB_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
84 EFI_PCI_IO_PROTOCOL
*PciIo
;
89 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
90 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
91 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
94 // Graphics Output Protocol related fields
98 FB_VIDEO_MODE_DATA
*ModeData
;
100 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
105 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
109 #define FB_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, FB_VIDEO_DEV, PciIo, FB_VIDEO_DEV_SIGNATURE)
110 #define FB_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, FB_VIDEO_DEV, GraphicsOutput, FB_VIDEO_DEV_SIGNATURE)
112 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
117 extern EFI_DRIVER_BINDING_PROTOCOL gFbGopDriverBinding
;
118 extern EFI_COMPONENT_NAME_PROTOCOL gFbGopComponentName
;
119 extern EFI_COMPONENT_NAME2_PROTOCOL gFbGopComponentName2
;
122 // Driver Binding Protocol functions
128 @param This Pointer to driver binding protocol
129 @param Controller Controller handle to connect
130 @param RemainingDevicePath A pointer to the remaining portion of a device
133 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
134 driver, Otherwise, this controller cannot be
135 managed by this driver
140 FbGopDriverBindingSupported (
141 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
142 IN EFI_HANDLE Controller
,
143 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
148 Install Graphics Output Protocol onto VGA device handles.
150 @param This Pointer to driver binding protocol
151 @param Controller Controller handle to connect
152 @param RemainingDevicePath A pointer to the remaining portion of a device
160 FbGopDriverBindingStart (
161 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
162 IN EFI_HANDLE Controller
,
163 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
170 @param This Pointer to driver binding protocol
171 @param Controller Controller handle to connect
172 @param NumberOfChildren Number of children handle created by this driver
173 @param ChildHandleBuffer Buffer containing child handle created
175 @retval EFI_SUCCESS Driver disconnected successfully from controller
176 @retval EFI_UNSUPPORTED Cannot find FB_VIDEO_DEV structure
181 FbGopDriverBindingStop (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN UINTN NumberOfChildren
,
185 IN EFI_HANDLE
*ChildHandleBuffer
189 // Private worker functions
193 Check for VBE device.
195 @param FbGopPrivate Pointer to FB_VIDEO_DEV structure
197 @retval EFI_SUCCESS VBE device found
202 IN OUT FB_VIDEO_DEV
*FbGopPrivate
208 Release resource for biso video instance.
210 @param FbGopPrivate Video child device private data structure
214 FbGopDeviceReleaseResource (
215 FB_VIDEO_DEV
*FbGopPrivate
219 // BIOS Graphics Output Protocol functions
223 Graphics Output protocol interface to get video mode.
225 @param This Protocol instance pointer.
226 @param ModeNumber The mode number to return information on.
227 @param SizeOfInfo A pointer to the size, in bytes, of the Info
229 @param Info Caller allocated buffer that returns information
232 @retval EFI_SUCCESS Mode information returned.
233 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
234 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
236 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
237 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
242 FbGopGraphicsOutputQueryMode (
243 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
244 IN UINT32 ModeNumber
,
245 OUT UINTN
*SizeOfInfo
,
246 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
251 Graphics Output protocol interface to set video mode.
253 @param This Protocol instance pointer.
254 @param ModeNumber The mode number to be set.
256 @retval EFI_SUCCESS Graphics mode was changed.
257 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
259 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
264 FbGopGraphicsOutputSetMode (
265 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
271 Graphics Output protocol instance to block transfer for VBE device.
273 @param This Pointer to Graphics Output protocol instance
274 @param BltBuffer The data to transfer to screen
275 @param BltOperation The operation to perform
276 @param SourceX The X coordinate of the source for BltOperation
277 @param SourceY The Y coordinate of the source for BltOperation
278 @param DestinationX The X coordinate of the destination for
280 @param DestinationY The Y coordinate of the destination for
282 @param Width The width of a rectangle in the blt rectangle in
284 @param Height The height of a rectangle in the blt rectangle in
286 @param Delta Not used for EfiBltVideoFill and
287 EfiBltVideoToVideo operation. If a Delta of 0 is
288 used, the entire BltBuffer will be operated on. If
289 a subrectangle of the BltBuffer is used, then
290 Delta represents the number of bytes in a row of
293 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
294 @retval EFI_SUCCESS Blt operation success
299 FbGopGraphicsOutputVbeBlt (
300 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
301 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
302 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
305 IN UINTN DestinationX
,
306 IN UINTN DestinationY
,
314 Grahpics Output protocol instance to block transfer for VGA device.
316 @param This Pointer to Grahpics Output protocol instance
317 @param BltBuffer The data to transfer to screen
318 @param BltOperation The operation to perform
319 @param SourceX The X coordinate of the source for BltOperation
320 @param SourceY The Y coordinate of the source for BltOperation
321 @param DestinationX The X coordinate of the destination for
323 @param DestinationY The Y coordinate of the destination for
325 @param Width The width of a rectangle in the blt rectangle in
327 @param Height The height of a rectangle in the blt rectangle in
329 @param Delta Not used for EfiBltVideoFill and
330 EfiBltVideoToVideo operation. If a Delta of 0 is
331 used, the entire BltBuffer will be operated on. If
332 a subrectangle of the BltBuffer is used, then
333 Delta represents the number of bytes in a row of
336 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
337 @retval EFI_SUCCESS Blt operation success
342 FbGopGraphicsOutputVgaBlt (
343 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
344 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
345 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
348 IN UINTN DestinationX
,
349 IN UINTN DestinationY
,
356 Install child handles if the Handle supports MBR format.
358 @param This Calling context.
359 @param ParentHandle Parent Handle
360 @param ParentPciIo Parent PciIo interface
361 @param ParentLegacyBios Parent LegacyBios interface
362 @param ParentDevicePath Parent Device Path
363 @param RemainingDevicePath Remaining Device Path
365 @retval EFI_SUCCESS If a child handle was added
366 @retval other A child handle was not added
370 FbGopChildHandleInstall (
371 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
372 IN EFI_HANDLE ParentHandle
,
373 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
374 IN VOID
*ParentLegacyBios
,
375 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
376 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
380 Deregister an video child handle and free resources.
382 @param This Protocol instance pointer.
383 @param Controller Video controller handle
384 @param Handle Video child handle
390 FbGopChildHandleUninstall (
391 EFI_DRIVER_BINDING_PROTOCOL
*This
,
392 EFI_HANDLE Controller
,
397 Release resource for biso video instance.
399 @param FbGopPrivate Video child device private data structure
403 FbGopDeviceReleaseResource (
404 FB_VIDEO_DEV
*FbGopPrivate
408 Check if all video child handles have been uninstalled.
410 @param Controller Video controller handle
412 @return TRUE Child handles exist.
413 @return FALSE All video child handles have been uninstalled.
418 IN EFI_HANDLE Controller