2 Graphics Output Protocol functions for the QEMU video controller.
4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The 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.
16 #include <IndustryStandard/VmwareSvga.h>
21 QemuVideoCompleteModeInfo (
22 IN QEMU_VIDEO_MODE_DATA
*ModeData
,
23 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
27 if (ModeData
->ColorDepth
== 8) {
28 Info
->PixelFormat
= PixelBitMask
;
29 Info
->PixelInformation
.RedMask
= PIXEL_RED_MASK
;
30 Info
->PixelInformation
.GreenMask
= PIXEL_GREEN_MASK
;
31 Info
->PixelInformation
.BlueMask
= PIXEL_BLUE_MASK
;
32 Info
->PixelInformation
.ReservedMask
= 0;
33 } else if (ModeData
->ColorDepth
== 24) {
34 Info
->PixelFormat
= PixelBitMask
;
35 Info
->PixelInformation
.RedMask
= PIXEL24_RED_MASK
;
36 Info
->PixelInformation
.GreenMask
= PIXEL24_GREEN_MASK
;
37 Info
->PixelInformation
.BlueMask
= PIXEL24_BLUE_MASK
;
38 Info
->PixelInformation
.ReservedMask
= 0;
39 } else if (ModeData
->ColorDepth
== 32) {
40 DEBUG ((EFI_D_INFO
, "PixelBlueGreenRedReserved8BitPerColor\n"));
41 Info
->PixelFormat
= PixelBlueGreenRedReserved8BitPerColor
;
43 Info
->PixelsPerScanLine
= Info
->HorizontalResolution
;
49 QemuVideoCompleteModeData (
50 IN QEMU_VIDEO_PRIVATE_DATA
*Private
,
51 OUT EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
54 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
55 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*FrameBufDesc
;
56 QEMU_VIDEO_MODE_DATA
*ModeData
;
58 ModeData
= &Private
->ModeData
[Mode
->Mode
];
60 QemuVideoCompleteModeInfo (ModeData
, Info
);
62 Private
->PciIo
->GetBarAttributes (
66 (VOID
**) &FrameBufDesc
69 Mode
->FrameBufferBase
= FrameBufDesc
->AddrRangeMin
;
70 Mode
->FrameBufferSize
= Info
->HorizontalResolution
* Info
->VerticalResolution
;
71 Mode
->FrameBufferSize
= Mode
->FrameBufferSize
* ((ModeData
->ColorDepth
+ 7) / 8);
72 DEBUG ((EFI_D_INFO
, "FrameBufferBase: 0x%Lx, FrameBufferSize: 0x%Lx\n",
73 Mode
->FrameBufferBase
, (UINT64
)Mode
->FrameBufferSize
));
75 FreePool (FrameBufDesc
);
81 QemuVideoVmwareSvgaCompleteModeData (
82 IN QEMU_VIDEO_PRIVATE_DATA
*Private
,
83 OUT EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
87 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
88 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*FrameBufDesc
;
89 UINT32 BytesPerLine
, FbOffset
, BytesPerPixel
;
92 CopyMem (Info
, &Private
->VmwareSvgaModeInfo
[Mode
->Mode
], sizeof (*Info
));
93 BytesPerPixel
= Private
->ModeData
[Mode
->Mode
].ColorDepth
/ 8;
94 BytesPerLine
= Info
->PixelsPerScanLine
* BytesPerPixel
;
96 FbOffset
= VmwareSvgaRead (Private
, VmwareSvgaRegFbOffset
);
98 Status
= Private
->PciIo
->GetBarAttributes (
102 (VOID
**) &FrameBufDesc
104 if (EFI_ERROR (Status
)) {
105 return EFI_DEVICE_ERROR
;
108 Mode
->FrameBufferBase
= FrameBufDesc
->AddrRangeMin
+ FbOffset
;
109 Mode
->FrameBufferSize
= BytesPerLine
* Info
->VerticalResolution
;
111 FreePool (FrameBufDesc
);
117 // Graphics Output Protocol Member Functions
121 QemuVideoGraphicsOutputQueryMode (
122 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
123 IN UINT32 ModeNumber
,
124 OUT UINTN
*SizeOfInfo
,
125 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
131 Graphics Output protocol interface to query video mode
134 This - Protocol instance pointer.
135 ModeNumber - The mode number to return information on.
136 Info - Caller allocated buffer that returns information about ModeNumber.
137 SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
140 EFI_SUCCESS - Mode information returned.
141 EFI_BUFFER_TOO_SMALL - The Info buffer was too small.
142 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
143 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
144 EFI_INVALID_PARAMETER - One of the input args was NULL.
148 QEMU_VIDEO_PRIVATE_DATA
*Private
;
149 QEMU_VIDEO_MODE_DATA
*ModeData
;
151 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
153 if (Info
== NULL
|| SizeOfInfo
== NULL
|| ModeNumber
>= This
->Mode
->MaxMode
) {
154 return EFI_INVALID_PARAMETER
;
157 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
159 return EFI_OUT_OF_RESOURCES
;
162 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
164 if (Private
->Variant
== QEMU_VIDEO_VMWARE_SVGA
) {
165 CopyMem (*Info
, &Private
->VmwareSvgaModeInfo
[ModeNumber
], sizeof (**Info
));
167 ModeData
= &Private
->ModeData
[ModeNumber
];
168 (*Info
)->HorizontalResolution
= ModeData
->HorizontalResolution
;
169 (*Info
)->VerticalResolution
= ModeData
->VerticalResolution
;
170 QemuVideoCompleteModeInfo (ModeData
, *Info
);
178 QemuVideoGraphicsOutputSetMode (
179 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
186 Graphics Output protocol interface to set video mode
189 This - Protocol instance pointer.
190 ModeNumber - The mode number to be set.
193 EFI_SUCCESS - Graphics mode was changed.
194 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
195 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
199 QEMU_VIDEO_PRIVATE_DATA
*Private
;
200 QEMU_VIDEO_MODE_DATA
*ModeData
;
201 RETURN_STATUS Status
;
202 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
204 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
206 if (ModeNumber
>= This
->Mode
->MaxMode
) {
207 return EFI_UNSUPPORTED
;
210 ModeData
= &Private
->ModeData
[ModeNumber
];
212 switch (Private
->Variant
) {
213 case QEMU_VIDEO_CIRRUS_5430
:
214 case QEMU_VIDEO_CIRRUS_5446
:
215 InitializeCirrusGraphicsMode (Private
, &QemuVideoCirrusModes
[ModeData
->InternalModeIndex
]);
217 case QEMU_VIDEO_BOCHS_MMIO
:
218 case QEMU_VIDEO_BOCHS
:
219 InitializeBochsGraphicsMode (Private
, &QemuVideoBochsModes
[ModeData
->InternalModeIndex
]);
221 case QEMU_VIDEO_VMWARE_SVGA
:
222 InitializeVmwareSvgaGraphicsMode (
224 &QemuVideoBochsModes
[ModeData
->InternalModeIndex
]
229 return EFI_DEVICE_ERROR
;
232 This
->Mode
->Mode
= ModeNumber
;
233 This
->Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
234 This
->Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
235 This
->Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
237 if (Private
->Variant
== QEMU_VIDEO_VMWARE_SVGA
) {
238 QemuVideoVmwareSvgaCompleteModeData (Private
, This
->Mode
);
240 QemuVideoCompleteModeData (Private
, This
->Mode
);
244 // Re-initialize the frame buffer configure when mode changes.
246 Status
= FrameBufferBltConfigure (
247 (VOID
*) (UINTN
) This
->Mode
->FrameBufferBase
,
249 Private
->FrameBufferBltConfigure
,
250 &Private
->FrameBufferBltConfigureSize
252 if (Status
== RETURN_BUFFER_TOO_SMALL
) {
254 // Frame buffer configure may be larger in new mode.
256 if (Private
->FrameBufferBltConfigure
!= NULL
) {
257 FreePool (Private
->FrameBufferBltConfigure
);
259 Private
->FrameBufferBltConfigure
=
260 AllocatePool (Private
->FrameBufferBltConfigureSize
);
261 ASSERT (Private
->FrameBufferBltConfigure
!= NULL
);
264 // Create the configuration for FrameBufferBltLib
266 Status
= FrameBufferBltConfigure (
267 (VOID
*) (UINTN
) This
->Mode
->FrameBufferBase
,
269 Private
->FrameBufferBltConfigure
,
270 &Private
->FrameBufferBltConfigureSize
273 ASSERT (Status
== RETURN_SUCCESS
);
276 // Per UEFI Spec, need to clear the visible portions of the output display to black.
278 ZeroMem (&Black
, sizeof (Black
));
279 Status
= FrameBufferBlt (
280 Private
->FrameBufferBltConfigure
,
285 This
->Mode
->Info
->HorizontalResolution
, This
->Mode
->Info
->VerticalResolution
,
288 ASSERT_RETURN_ERROR (Status
);
295 QemuVideoGraphicsOutputBlt (
296 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
297 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
298 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
301 IN UINTN DestinationX
,
302 IN UINTN DestinationY
,
311 Graphics Output protocol instance to block transfer for CirrusLogic device
315 This - Pointer to Graphics Output protocol instance
316 BltBuffer - The data to transfer to screen
317 BltOperation - The operation to perform
318 SourceX - The X coordinate of the source for BltOperation
319 SourceY - The Y coordinate of the source for BltOperation
320 DestinationX - The X coordinate of the destination for BltOperation
321 DestinationY - The Y coordinate of the destination for BltOperation
322 Width - The width of a rectangle in the blt rectangle in pixels
323 Height - The height of a rectangle in the blt rectangle in pixels
324 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
325 If a Delta of 0 is used, the entire BltBuffer will be operated on.
326 If a subrectangle of the BltBuffer is used, then Delta represents
327 the number of bytes in a row of the BltBuffer.
331 EFI_INVALID_PARAMETER - Invalid parameter passed in
332 EFI_SUCCESS - Blt operation success
338 QEMU_VIDEO_PRIVATE_DATA
*Private
;
340 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
342 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
343 // We would not want a timer based event (Cursor, ...) to come in while we are
344 // doing this operation.
346 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
348 switch (BltOperation
) {
349 case EfiBltVideoToBltBuffer
:
350 case EfiBltBufferToVideo
:
351 case EfiBltVideoFill
:
352 case EfiBltVideoToVideo
:
353 Status
= FrameBufferBlt (
354 Private
->FrameBufferBltConfigure
,
368 Status
= EFI_INVALID_PARAMETER
;
372 gBS
->RestoreTPL (OriginalTPL
);
378 QemuVideoGraphicsOutputConstructor (
379 QEMU_VIDEO_PRIVATE_DATA
*Private
383 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
386 GraphicsOutput
= &Private
->GraphicsOutput
;
387 GraphicsOutput
->QueryMode
= QemuVideoGraphicsOutputQueryMode
;
388 GraphicsOutput
->SetMode
= QemuVideoGraphicsOutputSetMode
;
389 GraphicsOutput
->Blt
= QemuVideoGraphicsOutputBlt
;
392 // Initialize the private data
394 Status
= gBS
->AllocatePool (
396 sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
),
397 (VOID
**) &Private
->GraphicsOutput
.Mode
399 if (EFI_ERROR (Status
)) {
403 Status
= gBS
->AllocatePool (
405 sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
),
406 (VOID
**) &Private
->GraphicsOutput
.Mode
->Info
408 if (EFI_ERROR (Status
)) {
411 Private
->GraphicsOutput
.Mode
->MaxMode
= (UINT32
) Private
->MaxMode
;
412 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
413 Private
->FrameBufferBltConfigure
= NULL
;
414 Private
->FrameBufferBltConfigureSize
= 0;
417 // Initialize the hardware
419 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, 0);
420 if (EFI_ERROR (Status
)) {
426 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].HorizontalResolution
,
427 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].VerticalResolution
433 FreePool (Private
->GraphicsOutput
.Mode
->Info
);
436 FreePool (Private
->GraphicsOutput
.Mode
);
437 Private
->GraphicsOutput
.Mode
= NULL
;
443 QemuVideoGraphicsOutputDestructor (
444 QEMU_VIDEO_PRIVATE_DATA
*Private
458 if (Private
->FrameBufferBltConfigure
!= NULL
) {
459 FreePool (Private
->FrameBufferBltConfigure
);
462 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
463 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
464 gBS
->FreePool (Private
->GraphicsOutput
.Mode
->Info
);
466 gBS
->FreePool (Private
->GraphicsOutput
.Mode
);