3 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Protocol/PciIo.h>
13 #include <Protocol/DevicePath.h>
14 #include <Protocol/GraphicsOutput.h>
15 #include <Protocol/EdidActive.h>
16 #include <Protocol/EdidDiscovered.h>
18 #include <Guid/StatusCodeDataTypeId.h>
19 #include <Guid/EventGroup.h>
20 #include <Guid/FrameBufferInfoGuid.h>
22 #include <Library/PcdLib.h>
23 #include <Library/HobLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/ReportStatusCodeLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/DevicePathLib.h>
31 #include <Library/MemoryAllocationLib.h>
33 #include <IndustryStandard/Pci.h>
36 // Packed format support: The number of bits reserved for each of the colors and the actual
37 // position of RGB in the frame buffer is specified in the VBE Mode information
40 UINT8 Position
; // Position of the color
41 UINT8 Mask
; // The number of bits expressed as a mask
42 } FB_VIDEO_COLOR_PLACEMENT
;
45 // BIOS Graphics Output Graphical Mode Data
49 UINT16 BytesPerScanLine
;
50 VOID
*LinearFrameBuffer
;
51 UINTN FrameBufferSize
;
52 UINT32 HorizontalResolution
;
53 UINT32 VerticalResolution
;
57 FB_VIDEO_COLOR_PLACEMENT Red
;
58 FB_VIDEO_COLOR_PLACEMENT Green
;
59 FB_VIDEO_COLOR_PLACEMENT Blue
;
60 FB_VIDEO_COLOR_PLACEMENT Reserved
;
61 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
62 EFI_PIXEL_BITMASK PixelBitMask
;
66 // BIOS video child handle private data Structure
68 #define FB_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
77 EFI_PCI_IO_PROTOCOL
*PciIo
;
82 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
83 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
84 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
87 // Graphics Output Protocol related fields
91 FB_VIDEO_MODE_DATA
*ModeData
;
93 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*VbeFrameBuffer
;
98 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
102 #define FB_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, FB_VIDEO_DEV, PciIo, FB_VIDEO_DEV_SIGNATURE)
103 #define FB_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, FB_VIDEO_DEV, GraphicsOutput, FB_VIDEO_DEV_SIGNATURE)
105 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
110 extern EFI_DRIVER_BINDING_PROTOCOL gFbGopDriverBinding
;
111 extern EFI_COMPONENT_NAME_PROTOCOL gFbGopComponentName
;
112 extern EFI_COMPONENT_NAME2_PROTOCOL gFbGopComponentName2
;
115 // Driver Binding Protocol functions
121 @param This Pointer to driver binding protocol
122 @param Controller Controller handle to connect
123 @param RemainingDevicePath A pointer to the remaining portion of a device
126 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
127 driver, Otherwise, this controller cannot be
128 managed by this driver
133 FbGopDriverBindingSupported (
134 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
135 IN EFI_HANDLE Controller
,
136 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
141 Install Graphics Output Protocol onto VGA device handles.
143 @param This Pointer to driver binding protocol
144 @param Controller Controller handle to connect
145 @param RemainingDevicePath A pointer to the remaining portion of a device
153 FbGopDriverBindingStart (
154 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
155 IN EFI_HANDLE Controller
,
156 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
163 @param This Pointer to driver binding protocol
164 @param Controller Controller handle to connect
165 @param NumberOfChildren Number of children handle created by this driver
166 @param ChildHandleBuffer Buffer containing child handle created
168 @retval EFI_SUCCESS Driver disconnected successfully from controller
169 @retval EFI_UNSUPPORTED Cannot find FB_VIDEO_DEV structure
174 FbGopDriverBindingStop (
175 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
176 IN EFI_HANDLE Controller
,
177 IN UINTN NumberOfChildren
,
178 IN EFI_HANDLE
*ChildHandleBuffer
182 // Private worker functions
186 Check for VBE device.
188 @param FbGopPrivate Pointer to FB_VIDEO_DEV structure
190 @retval EFI_SUCCESS VBE device found
195 IN OUT FB_VIDEO_DEV
*FbGopPrivate
201 Release resource for bios video instance.
203 @param FbGopPrivate Video child device private data structure
207 FbGopDeviceReleaseResource (
208 FB_VIDEO_DEV
*FbGopPrivate
212 // BIOS Graphics Output Protocol functions
216 Graphics Output protocol interface to get video mode.
218 @param This Protocol instance pointer.
219 @param ModeNumber The mode number to return information on.
220 @param SizeOfInfo A pointer to the size, in bytes, of the Info
222 @param Info Caller allocated buffer that returns information
225 @retval EFI_SUCCESS Mode information returned.
226 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
227 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
229 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
230 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
235 FbGopGraphicsOutputQueryMode (
236 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
237 IN UINT32 ModeNumber
,
238 OUT UINTN
*SizeOfInfo
,
239 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
244 Graphics Output protocol interface to set video mode.
246 @param This Protocol instance pointer.
247 @param ModeNumber The mode number to be set.
249 @retval EFI_SUCCESS Graphics mode was changed.
250 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
252 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
257 FbGopGraphicsOutputSetMode (
258 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
* This
,
264 Graphics Output protocol instance to block transfer for VBE device.
266 @param This Pointer to Graphics Output protocol instance
267 @param BltBuffer The data to transfer to screen
268 @param BltOperation The operation to perform
269 @param SourceX The X coordinate of the source for BltOperation
270 @param SourceY The Y coordinate of the source for BltOperation
271 @param DestinationX The X coordinate of the destination for
273 @param DestinationY The Y coordinate of the destination for
275 @param Width The width of a rectangle in the blt rectangle in
277 @param Height The height of a rectangle in the blt rectangle in
279 @param Delta Not used for EfiBltVideoFill and
280 EfiBltVideoToVideo operation. If a Delta of 0 is
281 used, the entire BltBuffer will be operated on. If
282 a subrectangle of the BltBuffer is used, then
283 Delta represents the number of bytes in a row of
286 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
287 @retval EFI_SUCCESS Blt operation success
292 FbGopGraphicsOutputVbeBlt (
293 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
294 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
295 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
298 IN UINTN DestinationX
,
299 IN UINTN DestinationY
,
307 Graphics Output protocol instance to block transfer for VGA device.
309 @param This Pointer to Graphics Output protocol instance
310 @param BltBuffer The data to transfer to screen
311 @param BltOperation The operation to perform
312 @param SourceX The X coordinate of the source for BltOperation
313 @param SourceY The Y coordinate of the source for BltOperation
314 @param DestinationX The X coordinate of the destination for
316 @param DestinationY The Y coordinate of the destination for
318 @param Width The width of a rectangle in the blt rectangle in
320 @param Height The height of a rectangle in the blt rectangle in
322 @param Delta Not used for EfiBltVideoFill and
323 EfiBltVideoToVideo operation. If a Delta of 0 is
324 used, the entire BltBuffer will be operated on. If
325 a subrectangle of the BltBuffer is used, then
326 Delta represents the number of bytes in a row of
329 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
330 @retval EFI_SUCCESS Blt operation success
335 FbGopGraphicsOutputVgaBlt (
336 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
337 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
338 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
341 IN UINTN DestinationX
,
342 IN UINTN DestinationY
,
349 Install child handles if the Handle supports MBR format.
351 @param This Calling context.
352 @param ParentHandle Parent Handle
353 @param ParentPciIo Parent PciIo interface
354 @param ParentLegacyBios Parent LegacyBios interface
355 @param ParentDevicePath Parent Device Path
356 @param RemainingDevicePath Remaining Device Path
358 @retval EFI_SUCCESS If a child handle was added
359 @retval other A child handle was not added
363 FbGopChildHandleInstall (
364 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
365 IN EFI_HANDLE ParentHandle
,
366 IN EFI_PCI_IO_PROTOCOL
*ParentPciIo
,
367 IN VOID
*ParentLegacyBios
,
368 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
369 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
373 Deregister an video child handle and free resources.
375 @param This Protocol instance pointer.
376 @param Controller Video controller handle
377 @param Handle Video child handle
383 FbGopChildHandleUninstall (
384 EFI_DRIVER_BINDING_PROTOCOL
*This
,
385 EFI_HANDLE Controller
,
390 Release resource for bios video instance.
392 @param FbGopPrivate Video child device private data structure
396 FbGopDeviceReleaseResource (
397 FB_VIDEO_DEV
*FbGopPrivate
401 Check if all video child handles have been uninstalled.
403 @param Controller Video controller handle
405 @return TRUE Child handles exist.
406 @return FALSE All video child handles have been uninstalled.
411 IN EFI_HANDLE Controller