2 Graphics Output Protocol functions for the QEMU video controller.
4 Copyright (c) 2007 - 2017, 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
;
203 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
205 if (ModeNumber
>= This
->Mode
->MaxMode
) {
206 return EFI_UNSUPPORTED
;
209 ModeData
= &Private
->ModeData
[ModeNumber
];
211 switch (Private
->Variant
) {
212 case QEMU_VIDEO_CIRRUS_5430
:
213 case QEMU_VIDEO_CIRRUS_5446
:
214 InitializeCirrusGraphicsMode (Private
, &QemuVideoCirrusModes
[ModeData
->InternalModeIndex
]);
216 case QEMU_VIDEO_BOCHS_MMIO
:
217 case QEMU_VIDEO_BOCHS
:
218 InitializeBochsGraphicsMode (Private
, &QemuVideoBochsModes
[ModeData
->InternalModeIndex
]);
220 case QEMU_VIDEO_VMWARE_SVGA
:
221 InitializeVmwareSvgaGraphicsMode (
223 &QemuVideoBochsModes
[ModeData
->InternalModeIndex
]
228 return EFI_DEVICE_ERROR
;
231 This
->Mode
->Mode
= ModeNumber
;
232 This
->Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
233 This
->Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
234 This
->Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
236 if (Private
->Variant
== QEMU_VIDEO_VMWARE_SVGA
) {
237 QemuVideoVmwareSvgaCompleteModeData (Private
, This
->Mode
);
239 QemuVideoCompleteModeData (Private
, This
->Mode
);
243 // Re-initialize the frame buffer configure when mode changes.
245 Status
= FrameBufferBltConfigure (
246 (VOID
*) (UINTN
) This
->Mode
->FrameBufferBase
,
248 Private
->FrameBufferBltConfigure
,
249 &Private
->FrameBufferBltConfigureSize
251 if (Status
== RETURN_BUFFER_TOO_SMALL
) {
253 // Frame buffer configure may be larger in new mode.
255 if (Private
->FrameBufferBltConfigure
!= NULL
) {
256 FreePool (Private
->FrameBufferBltConfigure
);
258 Private
->FrameBufferBltConfigure
=
259 AllocatePool (Private
->FrameBufferBltConfigureSize
);
260 ASSERT (Private
->FrameBufferBltConfigure
!= NULL
);
263 // Create the configuration for FrameBufferBltLib
265 Status
= FrameBufferBltConfigure (
266 (VOID
*) (UINTN
) This
->Mode
->FrameBufferBase
,
268 Private
->FrameBufferBltConfigure
,
269 &Private
->FrameBufferBltConfigureSize
272 ASSERT (Status
== RETURN_SUCCESS
);
279 QemuVideoGraphicsOutputBlt (
280 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
281 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
282 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
285 IN UINTN DestinationX
,
286 IN UINTN DestinationY
,
295 Graphics Output protocol instance to block transfer for CirrusLogic device
299 This - Pointer to Graphics Output protocol instance
300 BltBuffer - The data to transfer to screen
301 BltOperation - The operation to perform
302 SourceX - The X coordinate of the source for BltOperation
303 SourceY - The Y coordinate of the source for BltOperation
304 DestinationX - The X coordinate of the destination for BltOperation
305 DestinationY - The Y coordinate of the destination for BltOperation
306 Width - The width of a rectangle in the blt rectangle in pixels
307 Height - The height of a rectangle in the blt rectangle in pixels
308 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
309 If a Delta of 0 is used, the entire BltBuffer will be operated on.
310 If a subrectangle of the BltBuffer is used, then Delta represents
311 the number of bytes in a row of the BltBuffer.
315 EFI_INVALID_PARAMETER - Invalid parameter passed in
316 EFI_SUCCESS - Blt operation success
322 QEMU_VIDEO_PRIVATE_DATA
*Private
;
324 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
326 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
327 // We would not want a timer based event (Cursor, ...) to come in while we are
328 // doing this operation.
330 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
332 switch (BltOperation
) {
333 case EfiBltVideoToBltBuffer
:
334 case EfiBltBufferToVideo
:
335 case EfiBltVideoFill
:
336 case EfiBltVideoToVideo
:
337 Status
= FrameBufferBlt (
338 Private
->FrameBufferBltConfigure
,
352 Status
= EFI_INVALID_PARAMETER
;
356 gBS
->RestoreTPL (OriginalTPL
);
362 QemuVideoGraphicsOutputConstructor (
363 QEMU_VIDEO_PRIVATE_DATA
*Private
367 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
370 GraphicsOutput
= &Private
->GraphicsOutput
;
371 GraphicsOutput
->QueryMode
= QemuVideoGraphicsOutputQueryMode
;
372 GraphicsOutput
->SetMode
= QemuVideoGraphicsOutputSetMode
;
373 GraphicsOutput
->Blt
= QemuVideoGraphicsOutputBlt
;
376 // Initialize the private data
378 Status
= gBS
->AllocatePool (
380 sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
),
381 (VOID
**) &Private
->GraphicsOutput
.Mode
383 if (EFI_ERROR (Status
)) {
387 Status
= gBS
->AllocatePool (
389 sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
),
390 (VOID
**) &Private
->GraphicsOutput
.Mode
->Info
392 if (EFI_ERROR (Status
)) {
395 Private
->GraphicsOutput
.Mode
->MaxMode
= (UINT32
) Private
->MaxMode
;
396 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
397 Private
->FrameBufferBltConfigure
= NULL
;
398 Private
->FrameBufferBltConfigureSize
= 0;
401 // Initialize the hardware
403 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, 0);
404 if (EFI_ERROR (Status
)) {
410 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].HorizontalResolution
,
411 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].VerticalResolution
417 FreePool (Private
->GraphicsOutput
.Mode
->Info
);
420 FreePool (Private
->GraphicsOutput
.Mode
);
421 Private
->GraphicsOutput
.Mode
= NULL
;
427 QemuVideoGraphicsOutputDestructor (
428 QEMU_VIDEO_PRIVATE_DATA
*Private
442 if (Private
->FrameBufferBltConfigure
!= NULL
) {
443 FreePool (Private
->FrameBufferBltConfigure
);
446 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
447 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
448 gBS
->FreePool (Private
->GraphicsOutput
.Mode
->Info
);
450 gBS
->FreePool (Private
->GraphicsOutput
.Mode
);